Skip to content

Commit d05f443

Browse files
Sagi GrimbergChristoph Hellwig
authored andcommitted
iov_iter: introduce hash_and_copy_to_iter helper
Allow consumers that want to use iov iterator helpers and also update a predefined hash calculation online when copying data. This is useful when copying incoming network buffers to a local iterator and calculate a digest on the incoming stream. nvme-tcp host driver that will be introduced in following patches is the first consumer via skb_copy_and_hash_datagram_iter. Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sagi Grimberg <sagi@lightbitslabs.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 950fcae commit d05f443

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/uio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/kernel.h>
1313
#include <linux/thread_info.h>
14+
#include <crypto/hash.h>
1415
#include <uapi/linux/uio.h>
1516

1617
struct page;
@@ -269,6 +270,8 @@ static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
269270
size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump, struct iov_iter *i);
270271
size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
271272
bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
273+
size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp,
274+
struct iov_iter *i);
272275

273276
int import_iovec(int type, const struct iovec __user * uvector,
274277
unsigned nr_segs, unsigned fast_segs,

lib/iov_iter.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/vmalloc.h>
77
#include <linux/splice.h>
88
#include <net/checksum.h>
9+
#include <linux/scatterlist.h>
910

1011
#define PIPE_PARANOIA /* for now */
1112

@@ -1511,6 +1512,21 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump,
15111512
}
15121513
EXPORT_SYMBOL(csum_and_copy_to_iter);
15131514

1515+
size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp,
1516+
struct iov_iter *i)
1517+
{
1518+
struct ahash_request *hash = hashp;
1519+
struct scatterlist sg;
1520+
size_t copied;
1521+
1522+
copied = copy_to_iter(addr, bytes, i);
1523+
sg_init_one(&sg, addr, copied);
1524+
ahash_request_set_crypt(hash, &sg, NULL, copied);
1525+
crypto_ahash_update(hash);
1526+
return copied;
1527+
}
1528+
EXPORT_SYMBOL(hash_and_copy_to_iter);
1529+
15141530
int iov_iter_npages(const struct iov_iter *i, int maxpages)
15151531
{
15161532
size_t size = i->count;

0 commit comments

Comments
 (0)