From: Willem de Bruijn <willemdebruijn.kernel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Willem de Bruijn
<willemb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH net-next v2 07/13] sock: add ee_code SO_EE_CODE_ZEROCOPY_COPIED
Date: Wed, 21 Jun 2017 16:36:46 -0400 [thread overview]
Message-ID: <20170621203652.15306-8-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20170621203652.15306-1-willemdebruijn.kernel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: Willem de Bruijn <willemb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
A send request with MSG_ZEROCOPY falls back to copying when a request
cannot be completed in zerocopy mode.
Notify processes when the call reverted to copying through a new bit
in the completion notification, so that they can optionally decline
passing the flag on subsequent calls on the same path.
Signed-off-by: Willem de Bruijn <willemb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
include/linux/skbuff.h | 2 ++
include/uapi/linux/errqueue.h | 2 ++
net/core/skbuff.c | 5 ++++-
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 1d842860f074..24479da9905c 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -416,6 +416,7 @@ struct ubuf_info {
struct {
u32 id;
u16 len;
+ u16 zerocopy:1;
u32 bytelen;
};
};
@@ -1257,6 +1258,7 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy)
struct ubuf_info *uarg = skb_zcopy(skb);
if (uarg) {
+ uarg->zerocopy = uarg->zerocopy && zerocopy;
sock_zerocopy_put(uarg);
skb_shinfo(skb)->tx_flags &= ~SKBTX_ZEROCOPY_FRAG;
}
diff --git a/include/uapi/linux/errqueue.h b/include/uapi/linux/errqueue.h
index 0f15a77c9e39..78fdf52d6b2f 100644
--- a/include/uapi/linux/errqueue.h
+++ b/include/uapi/linux/errqueue.h
@@ -23,6 +23,8 @@ struct sock_extended_err {
#define SO_EE_OFFENDER(ee) ((struct sockaddr*)((ee)+1))
+#define SO_EE_CODE_ZEROCOPY_COPIED 1
+
/**
* struct scm_timestamping - timestamps exposed through cmsg
*
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 41fedc4e651f..35a7a7b1192f 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -943,6 +943,7 @@ struct ubuf_info *sock_zerocopy_alloc(struct sock *sk, size_t size)
uarg->callback = sock_zerocopy_callback;
uarg->id = ((u32)atomic_inc_return(&sk->sk_zckey)) - 1;
uarg->len = 1;
+ uarg->zerocopy = 1;
uarg->bytelen = size;
atomic_set(&uarg->refcnt, 0);
sock_hold(sk);
@@ -1039,6 +1040,8 @@ void sock_zerocopy_callback(struct ubuf_info *uarg, bool success)
serr->ee.ee_origin = SO_EE_ORIGIN_ZEROCOPY;
serr->ee.ee_data = hi;
serr->ee.ee_info = lo;
+ if (!success)
+ serr->ee.ee_code |= SO_EE_CODE_ZEROCOPY_COPIED;
spin_lock_irqsave(&q->lock, flags);
tail = skb_peek_tail(q);
@@ -1061,7 +1064,7 @@ void sock_zerocopy_put(struct ubuf_info *uarg)
{
if (uarg && atomic_dec_and_test(&uarg->refcnt)) {
if (uarg->callback)
- uarg->callback(uarg, true);
+ uarg->callback(uarg, uarg->zerocopy);
else
consume_skb(skb_from_uarg(uarg));
}
--
2.13.1.611.g7e3b11ae1-goog
next prev parent reply other threads:[~2017-06-21 20:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 20:36 [PATCH net-next v2 00/13] socket sendmsg MSG_ZEROCOPY Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 01/13] sock: allocate skbs from optmem Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 02/13] sock: skb_copy_ubufs support for compound pages Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 04/13] sock: add SOCK_ZEROCOPY sockopt Willem de Bruijn
[not found] ` <20170621203652.15306-5-willemdebruijn.kernel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-21 20:56 ` Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 05/13] sock: enable MSG_ZEROCOPY Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 06/13] sock: MSG_ZEROCOPY notification coalescing Willem de Bruijn
[not found] ` <20170621203652.15306-1-willemdebruijn.kernel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-21 20:36 ` [PATCH net-next v2 03/13] sock: add MSG_ZEROCOPY Willem de Bruijn
2017-06-21 20:36 ` Willem de Bruijn [this message]
2017-06-21 20:36 ` [PATCH net-next v2 08/13] sock: ulimit on MSG_ZEROCOPY pages Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 09/13] tcp: enable MSG_ZEROCOPY Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 10/13] udp: " Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 11/13] raw: enable MSG_ZEROCOPY with IP_HDRINCL Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 12/13] packet: enable MSG_ZEROCOPY Willem de Bruijn
2017-06-21 20:36 ` [PATCH net-next v2 13/13] test: add msg_zerocopy test Willem de Bruijn
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=20170621203652.15306-8-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=willemb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.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).