[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1652241268-46732-7-git-send-email-jdamato@fastly.com>
Date: Tue, 10 May 2022 20:54:27 -0700
From: Joe Damato <jdamato@...tly.com>
To: netdev@...r.kernel.org, davem@...emloft.net, kuba@...nel.org,
linux-kernel@...r.kernel.org, x86@...nel.org,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>
Cc: Joe Damato <jdamato@...tly.com>
Subject: [RFC,net-next 6/6] net: unix: Add MSG_NTCOPY
Add a new sendmsg flag, MSG_NTCOPY, which user programs can use to signal
to the kernel that data copied into the kernel during sendmsg should be
done so using nontemporal copies, if it is supported by the architecture.
Signed-off-by: Joe Damato <jdamato@...tly.com>
---
include/linux/socket.h | 1 +
net/unix/af_unix.c | 13 +++++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 12085c9..c9b10aa 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -318,6 +318,7 @@ struct ucred {
* plain text and require encryption
*/
+#define MSG_NTCOPY 0x2000000 /* Use a non-temporal copy */
#define MSG_ZEROCOPY 0x4000000 /* Use user data in kernel path */
#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */
#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e1dd9e9..ccbd643 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1907,7 +1907,11 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
skb_put(skb, len - data_len);
skb->data_len = data_len;
skb->len = len;
- err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, len);
+ if (msg->msg_flags & MSG_NTCOPY)
+ err = skb_copy_datagram_from_iter_nocache(skb, 0, &msg->msg_iter, len);
+ else
+ err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, len);
+
if (err)
goto out_free;
@@ -2167,7 +2171,12 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
skb_put(skb, size - data_len);
skb->data_len = data_len;
skb->len = size;
- err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size);
+
+ if (msg->msg_flags & MSG_NTCOPY)
+ err = skb_copy_datagram_from_iter_nocache(skb, 0, &msg->msg_iter, size);
+ else
+ err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size);
+
if (err) {
kfree_skb(skb);
goto out_err;
--
2.7.4
Powered by blists - more mailing lists