diff options
author | Sagi Grimberg <sagi@lightbitslabs.com> | 2018-12-03 20:52:09 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-12-13 03:58:54 -0500 |
commit | d05f443554b3c7dc6d46e3ba9c3c4de468875d4f (patch) | |
tree | 6bc94110dc8dd6ea1540ec26b6b4f6c3029ea0f0 | |
parent | 950fcaecd5cc6c014bb96506fd0652a501c85276 (diff) |
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>
-rw-r--r-- | include/linux/uio.h | 3 | ||||
-rw-r--r-- | lib/iov_iter.c | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/uio.h b/include/linux/uio.h index 41d1f8d3313d..ecf584f6b82d 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/thread_info.h> | 13 | #include <linux/thread_info.h> |
14 | #include <crypto/hash.h> | ||
14 | #include <uapi/linux/uio.h> | 15 | #include <uapi/linux/uio.h> |
15 | 16 | ||
16 | struct page; | 17 | struct page; |
@@ -269,6 +270,8 @@ static inline void iov_iter_reexpand(struct iov_iter *i, size_t count) | |||
269 | size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump, struct iov_iter *i); | 270 | size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump, struct iov_iter *i); |
270 | size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); | 271 | size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); |
271 | bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); | 272 | 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); | ||
272 | 275 | ||
273 | int import_iovec(int type, const struct iovec __user * uvector, | 276 | int import_iovec(int type, const struct iovec __user * uvector, |
274 | unsigned nr_segs, unsigned fast_segs, | 277 | unsigned nr_segs, unsigned fast_segs, |
diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 63a8999a234d..1928009f506e 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <linux/vmalloc.h> | 6 | #include <linux/vmalloc.h> |
7 | #include <linux/splice.h> | 7 | #include <linux/splice.h> |
8 | #include <net/checksum.h> | 8 | #include <net/checksum.h> |
9 | #include <linux/scatterlist.h> | ||
9 | 10 | ||
10 | #define PIPE_PARANOIA /* for now */ | 11 | #define PIPE_PARANOIA /* for now */ |
11 | 12 | ||
@@ -1511,6 +1512,21 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump, | |||
1511 | } | 1512 | } |
1512 | EXPORT_SYMBOL(csum_and_copy_to_iter); | 1513 | EXPORT_SYMBOL(csum_and_copy_to_iter); |
1513 | 1514 | ||
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 | |||
1514 | int iov_iter_npages(const struct iov_iter *i, int maxpages) | 1530 | int iov_iter_npages(const struct iov_iter *i, int maxpages) |
1515 | { | 1531 | { |
1516 | size_t size = i->count; | 1532 | size_t size = i->count; |