From: Sagi Grimberg <sagi@lightbitslabs.com>
To: linux-nvme@lists.infradead.org
Cc: linux-block@vger.kernel.org, netdev@vger.kernel.org,
Christoph Hellwig <hch@lst.de>,
Keith Busch <keith.busch@intel.com>
Subject: [PATCH 03/11] datagram: introduce skb_copy_and_hash_datagram_iter helper
Date: Thu, 15 Nov 2018 09:16:15 -0800 [thread overview]
Message-ID: <20181115171626.9306-4-sagi@lightbitslabs.com> (raw)
In-Reply-To: <20181115171626.9306-1-sagi@lightbitslabs.com>
Introduce a helper to copy datagram into an iovec iterator
but also update a predefined hash. This is useful for
consumers of skb_copy_datagram_iter to also support inflight
data digest without having to finish to copy and only then
traverse the iovec and calculate the digest hash.
Signed-off-by: Sagi Grimberg <sagi@lightbitslabs.com>
---
include/linux/skbuff.h | 3 ++
net/core/datagram.c | 90 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 0ba687454267..4d89bb14c2fc 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3311,6 +3311,9 @@ int skb_copy_and_csum_datagram_msg(struct sk_buff *skb, int hlen,
struct msghdr *msg);
int skb_copy_datagram_from_iter(struct sk_buff *skb, int offset,
struct iov_iter *from, int len);
+int skb_copy_and_hash_datagram_iter(const struct sk_buff *skb, int offset,
+ struct iov_iter *to, int len,
+ struct ahash_request *hash);
int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *frm);
void skb_free_datagram(struct sock *sk, struct sk_buff *skb);
void __skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb, int len);
diff --git a/net/core/datagram.c b/net/core/datagram.c
index 57f3a6fcfc1e..9c81741c1bae 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -497,6 +497,96 @@ int skb_copy_datagram_iter(const struct sk_buff *skb, int offset,
}
EXPORT_SYMBOL(skb_copy_datagram_iter);
+/**
+ * skb_copy_and_hash_datagram_iter - Copy datagram to an iovec iterator
+ * and update a hash.
+ * @skb: buffer to copy
+ * @offset: offset in the buffer to start copying from
+ * @to: iovec iterator to copy to
+ * @len: amount of data to copy from buffer to iovec
+ * @hash: hash request to update
+ */
+int skb_copy_and_hash_datagram_iter(const struct sk_buff *skb, int offset,
+ struct iov_iter *to, int len,
+ struct ahash_request *hash)
+{
+ int start = skb_headlen(skb);
+ int i, copy = start - offset, start_off = offset, n;
+ struct sk_buff *frag_iter;
+
+ /* Copy header. */
+ if (copy > 0) {
+ if (copy > len)
+ copy = len;
+ n = hash_and_copy_to_iter(skb->data + offset, copy, to, hash);
+ offset += n;
+ if (n != copy)
+ goto short_copy;
+ if ((len -= copy) == 0)
+ return 0;
+ }
+
+ /* Copy paged appendix. Hmm... why does this look so complicated? */
+ for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
+ int end;
+ const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+
+ WARN_ON(start > offset + len);
+
+ end = start + skb_frag_size(frag);
+ if ((copy = end - offset) > 0) {
+ if (copy > len)
+ copy = len;
+ n = hash_and_copy_page_to_iter(skb_frag_page(frag),
+ frag->page_offset + offset -
+ start, copy, to, hash);
+ offset += n;
+ if (n != copy)
+ goto short_copy;
+ if (!(len -= copy))
+ return 0;
+ }
+ start = end;
+ }
+
+ skb_walk_frags(skb, frag_iter) {
+ int end;
+
+ WARN_ON(start > offset + len);
+
+ end = start + frag_iter->len;
+ if ((copy = end - offset) > 0) {
+ if (copy > len)
+ copy = len;
+ if (skb_copy_and_hash_datagram_iter(frag_iter,
+ offset - start, to, copy, hash))
+ goto fault;
+ if ((len -= copy) == 0)
+ return 0;
+ offset += copy;
+ }
+ start = end;
+ }
+ if (!len)
+ return 0;
+
+ /* This is not really a user copy fault, but rather someone
+ * gave us a bogus length on the skb. We should probably
+ * print a warning here as it may indicate a kernel bug.
+ */
+
+fault:
+ iov_iter_revert(to, offset - start_off);
+ return -EFAULT;
+
+short_copy:
+ if (iov_iter_count(to))
+ goto fault;
+
+ return 0;
+}
+EXPORT_SYMBOL(skb_copy_and_hash_datagram_iter);
+
/**
* skb_copy_datagram_from_iter - Copy a datagram from an iov_iter.
* @skb: buffer to copy
--
2.17.1
next prev parent reply other threads:[~2018-11-16 3:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 17:16 [PATCH 00/11] TCP transport binding for NVMe over Fabrics Sagi Grimberg
2018-11-15 17:16 ` [PATCH 01/11] ath6kl: add ath6kl_ prefix to crypto_type Sagi Grimberg
2018-11-15 17:16 ` [PATCH 02/11] iov_iter: introduce hash_and_copy iter helpers Sagi Grimberg
2018-11-15 17:16 ` Sagi Grimberg [this message]
2018-11-15 17:16 ` [PATCH 04/11] nvme-core: add work elements to struct nvme_ctrl Sagi Grimberg
2018-11-17 22:18 ` Max Gurtovoy
2018-11-15 17:16 ` [PATCH 05/11] nvmet: Add install_queue callout Sagi Grimberg
2018-11-17 22:36 ` Max Gurtovoy
2018-11-19 21:21 ` Sagi Grimberg
2018-11-15 17:16 ` [PATCH 06/11] nvmet: allow configfs tcp trtype configuration Sagi Grimberg
2018-11-17 22:38 ` Max Gurtovoy
2018-11-15 17:16 ` [PATCH 07/11] nvme-fabrics: allow user passing header digest Sagi Grimberg
2018-11-15 17:16 ` [PATCH 08/11] nvme-fabrics: allow user passing data digest Sagi Grimberg
2018-11-15 17:16 ` [PATCH 09/11] nvme-tcp: Add protocol header Sagi Grimberg
2018-11-15 17:16 ` [PATCH 10/11] nvmet-tcp: add NVMe over TCP target driver Sagi Grimberg
2018-11-17 20:15 ` David Miller
2018-11-17 22:48 ` Max Gurtovoy
2018-11-19 21:37 ` Sagi Grimberg
2018-11-19 21:26 ` Sagi Grimberg
2018-11-19 22:53 ` David Miller
2018-11-19 23:14 ` Sagi Grimberg
2018-11-19 23:18 ` David Miller
2018-11-19 23:24 ` Sagi Grimberg
2018-11-20 1:44 ` David Miller
2018-11-15 17:16 ` [PATCH 11/11] nvme-tcp: add NVMe over TCP host driver Sagi Grimberg
2018-11-15 17:16 ` [PATCH nvme-cli 12/11] nvme: Add TCP transport Sagi Grimberg
2018-11-15 17:16 ` [PATCH nvme-cli 13/11] fabrics: add tcp port tsas decoding Sagi Grimberg
2018-11-15 17:16 ` [PATCH nvme-cli 14/11] fabrics: add transport header and data digest Sagi Grimberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181115171626.9306-4-sagi@lightbitslabs.com \
--to=sagi@lightbitslabs.com \
--cc=hch@lst.de \
--cc=keith.busch@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).