netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] scm: use masked_user_access_begin() in put_cmsg()
@ 2025-09-25 22:49 Eric Dumazet
  2025-09-30  1:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2025-09-25 22:49 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet

Use the greatest and latest uaccess construct to get an optimal code.

Before :

	lea    (%r9,%rcx,1),%r10
	movabs $<USER_PTR_MAX>,%r11
	mov    $0xfffffff2,%eax
	cmp    %rcx,%r10
	jb     ffffffff81cdc312 <put_cmsg+0x152>
	cmp    %r11,%r10
	ja     ffffffff81cdc312 <put_cmsg+0x152>
	stac
	lfence
	mov    %r9,(%rcx)

After:

	movabs $<USER_PTR_MAX>,%r9
	cmp    %r9,%rax
	cmova  %r9,%rax
	stac
	mov    %rcx,(%rax)

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/scm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/core/scm.c b/net/core/scm.c
index 072d5742440adae36757592c102657a9a93391be..66eaee783e8be8ed650a1679a15d0a41309f9f0d 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -273,7 +273,9 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
 
 		check_object_size(data, cmlen - sizeof(*cm), true);
 
-		if (!user_write_access_begin(cm, cmlen))
+		if (can_do_masked_user_access())
+			cm = masked_user_access_begin(cm);
+		else if (!user_write_access_begin(cm, cmlen))
 			goto efault;
 
 		unsafe_put_user(cmlen, &cm->cmsg_len, efault_end);
-- 
2.51.0.536.g15c5d4f767-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] scm: use masked_user_access_begin() in put_cmsg()
  2025-09-25 22:49 [PATCH net-next] scm: use masked_user_access_begin() in put_cmsg() Eric Dumazet
@ 2025-09-30  1:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-30  1:20 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 25 Sep 2025 22:49:14 +0000 you wrote:
> Use the greatest and latest uaccess construct to get an optimal code.
> 
> Before :
> 
> 	lea    (%r9,%rcx,1),%r10
> 	movabs $<USER_PTR_MAX>,%r11
> 	mov    $0xfffffff2,%eax
> 	cmp    %rcx,%r10
> 	jb     ffffffff81cdc312 <put_cmsg+0x152>
> 	cmp    %r11,%r10
> 	ja     ffffffff81cdc312 <put_cmsg+0x152>
> 	stac
> 	lfence
> 	mov    %r9,(%rcx)
> 
> [...]

Here is the summary with links:
  - [net-next] scm: use masked_user_access_begin() in put_cmsg()
    https://git.kernel.org/netdev/net-next/c/2b235765e9d4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-30  1:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25 22:49 [PATCH net-next] scm: use masked_user_access_begin() in put_cmsg() Eric Dumazet
2025-09-30  1:20 ` patchwork-bot+netdevbpf

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).