net: remove one stac/clac pair from move_addr_to_user()
Subsystems (3)
PATCH 1/1 net: remove one stac/clac pair from move_addr_to_user()
Convert the get_user() and __put_user() code to the fast masked_user_access_begin()/unsafe_{get|put}_user() variant.
This patch increases the performance of an UDP recvfrom() receiver (netserver) on 120 bytes messages by 7 % on an AMD EPYC 7B12 64-Core Processor platform.
Presence of audit_sockaddr() makes difficult to avoid the stac/clac pair in the copy_to_user() call, this is left for a future patch.
--- net/socket.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
net/socket.c +24 -11
@@ -276,28 +276,41 @@ int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kstatic int move_addr_to_user (struct sockaddr_storage *kaddr,int klen,void __user *uaddr,int __user *ulen) { -int err;int len;BUG_ON (klen >sizeof (struct sockaddr_storage )); - err =get_user (len, ulen); -if (err) -return err; + +if (can_do_masked_user_access ()) + ulen =masked_user_access_begin (ulen); +else if (!user_access_begin (ulen,4 )) +return -EFAULT ; + +unsafe_get_user (len, ulen, efault_end); +if (len > klen) len = klen; -if (len <0 ) -return -EINVAL ; +/* +* "fromlen shall refer to the value before truncation.." +* 1003.1g +*/ +if (len >=0 ) +unsafe_put_user (klen, ulen, efault_end); + +user_access_end (); +if (len) { +if (len <0 ) +return -EINVAL ;if (audit_sockaddr (klen, kaddr))return -ENOMEM ;if (copy_to_user (uaddr, kaddr, len))return -EFAULT ; } -/* -* "fromlen shall refer to the value before truncation.." -* 1003.1g -*/ -return __put_user (klen, ulen); +return 0 ; + +efault_end: +user_access_end (); +return -EFAULT ; }static struct kmem_cache *sock_inode_cachep__ro_after_init ;
Signature · 1 line
2.51.0.536.g15c5d4f767-goog
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 25 Sep 2025 23:09:29 +0000 you wrote:
Convert the
get_user()and__put_user()code to the fast masked_user_access_begin()/unsafe_{get|put}_user() variant.This patch increases the performance of an UDP
recvfrom()receiver (netserver) on 120 bytes messages by 7 % on an AMD EPYC 7B12 64-Core Processor platform.[...]
Here is the summary with links:
- [net-next] net: remove one stac/clac pair from move_addr_to_user()
https://git.kernel.org/netdev/net-next/c/1fb0e471611d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html