[lkml]   [2020]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] x86/uaccess: Remove redundant likely/unlikely annotations
On Fri, May 29, 2020 at 06:54:19PM +0200, Peter Zijlstra wrote:
> On Fri, May 29, 2020 at 11:50:11AM -0500, Josh Poimboeuf wrote:
> > The nested likelys seem like overkill anyway -- user_access_begin() is
> > __always_inline and it already has unlikely(), which should be
> > propagated.
> >
> > So just remove the outer likelys?
> That fixes it. Ack!

If there are no objections to the patch, I can add it to my objtool-core
branch unless anybody else wants to take it. It only affects


From: Josh Poimboeuf <>
Subject: [PATCH] x86/uaccess: Remove redundant likely/unlikely annotations

Since user_access_begin() already has an unlikely() annotation for its
access_ok() check, "if (likely(user_access_begin))" results in nested
likely annotations. When combined with CONFIG_TRACE_BRANCH_PROFILING,
GCC converges the error/success paths of the nested ifs, using a
register value to distinguish between them.

While the code is technically uaccess safe, it complicates the
branch-profiling generated code. It also confuses objtool, because it
doesn't do register value tracking, resulting in the following warnings:

arch/x86/lib/csum-wrappers_64.o: warning: objtool: csum_and_copy_from_user()+0x2a4: call to memset() with UACCESS enabled
arch/x86/lib/csum-wrappers_64.o: warning: objtool: csum_and_copy_to_user()+0x243: return with UACCESS enabled

The outer likely annotations aren't actually needed anyway, since the
compiler propagates the error path coldness when it inlines

Fixes: 18372ef87665 ("x86_64: csum_..._copy_..._user(): switch to unsafe_..._user()")
Reported-by: Randy Dunlap <>
Acked-by: Peter Zijlstra <>
Signed-off-by: Josh Poimboeuf <>
arch/x86/lib/csum-wrappers_64.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
index a12b8629206d..ee63d7576fd2 100644
--- a/arch/x86/lib/csum-wrappers_64.c
+++ b/arch/x86/lib/csum-wrappers_64.c
@@ -27,7 +27,7 @@ csum_and_copy_from_user(const void __user *src, void *dst,
*errp = 0;

- if (!likely(user_access_begin(src, len)))
+ if (!user_access_begin(src, len))
goto out_err;

@@ -89,7 +89,7 @@ csum_and_copy_to_user(const void *src, void __user *dst,


- if (unlikely(!user_access_begin(dst, len))) {
+ if (!user_access_begin(dst, len)) {
*errp = -EFAULT;
return 0;
 \ /
  Last update: 2020-05-29 19:35    [W:0.102 / U:0.924 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site