diff mbox series

[RFC,net-next,6/6] net: unix: Add MSG_NTCOPY

Message ID 1652241268-46732-7-git-send-email-jdamato@fastly.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Nontemporal copies in unix socket write path | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 6409 this patch: 6409
netdev/cc_maintainers warning 5 maintainers not CCed: changbin.du@intel.com jk@codeconstruct.com.au viro@zeniv.linux.org.uk kuniyu@amazon.co.jp axboe@kernel.dk
netdev/build_clang success Errors and warnings before: 1716 this patch: 1716
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 11991 this patch: 11991
netdev/checkpatch warning WARNING: line length of 87 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns WARNING: line length of 96 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Joe Damato May 11, 2022, 3:54 a.m. UTC
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@fastly.com>
---
 include/linux/socket.h |  1 +
 net/unix/af_unix.c     | 13 +++++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;