[PATCH v5 6/6] x86/asm: Retire RIP_REL_REF()

Ard Biesheuvel posted 6 patches 8 months ago
[PATCH v5 6/6] x86/asm: Retire RIP_REL_REF()
Posted by Ard Biesheuvel 8 months ago
From: Ard Biesheuvel <ardb@kernel.org>

Now that all users have been moved into startup/ where PIC codegen is
used, RIP_REL_REF() is no longer needed. Remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/include/asm/asm.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index a9f07799e337..eef0771512de 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -120,11 +120,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
 
 	return p;
 }
-#ifndef __pic__
-#define RIP_REL_REF(var)	(*(typeof(&(var)))rip_rel_ptr(&(var)))
-#else
-#define RIP_REL_REF(var)	(var)
-#endif
 #endif
 
 /*
-- 
2.49.0.805.g082f7c87e0-goog
Re: [PATCH v5 6/6] x86/asm: Retire RIP_REL_REF()
Posted by Uros Bizjak 8 months ago

On 18. 04. 25 16:13, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@kernel.org>
> 
> Now that all users have been moved into startup/ where PIC codegen is
> used, RIP_REL_REF() is no longer needed. Remove it.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>   arch/x86/include/asm/asm.h | 5 -----
>   1 file changed, 5 deletions(-)
> 
> diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> index a9f07799e337..eef0771512de 100644
> --- a/arch/x86/include/asm/asm.h
> +++ b/arch/x86/include/asm/asm.h
> @@ -120,11 +120,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
>   
>   	return p;
>   }
> -#ifndef __pic__
> -#define RIP_REL_REF(var)	(*(typeof(&(var)))rip_rel_ptr(&(var)))
> -#else
> -#define RIP_REL_REF(var)	(var)
> -#endif
>   #endif

You can also remove rip_rel_ptr() with the whole "#ifndef __ASSEMBLER__" 
part.

Uros.
Re: [PATCH v5 6/6] x86/asm: Retire RIP_REL_REF()
Posted by Ard Biesheuvel 8 months ago
On Fri, 18 Apr 2025 at 17:51, Uros Bizjak <ubizjak@gmail.com> wrote:
>
>
>
> On 18. 04. 25 16:13, Ard Biesheuvel wrote:
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > Now that all users have been moved into startup/ where PIC codegen is
> > used, RIP_REL_REF() is no longer needed. Remove it.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> >   arch/x86/include/asm/asm.h | 5 -----
> >   1 file changed, 5 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> > index a9f07799e337..eef0771512de 100644
> > --- a/arch/x86/include/asm/asm.h
> > +++ b/arch/x86/include/asm/asm.h
> > @@ -120,11 +120,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
> >
> >       return p;
> >   }
> > -#ifndef __pic__
> > -#define RIP_REL_REF(var)     (*(typeof(&(var)))rip_rel_ptr(&(var)))
> > -#else
> > -#define RIP_REL_REF(var)     (var)
> > -#endif
> >   #endif
>
> You can also remove rip_rel_ptr() with the whole "#ifndef __ASSEMBLER__"
> part.
>

No, rip_rel_ptr() needs to be kept, unfortunately.
Re: [PATCH v5 6/6] x86/asm: Retire RIP_REL_REF()
Posted by Uros Bizjak 7 months, 2 weeks ago
On Fri, Apr 18, 2025 at 5:58 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> On Fri, 18 Apr 2025 at 17:51, Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> >
> >
> > On 18. 04. 25 16:13, Ard Biesheuvel wrote:
> > > From: Ard Biesheuvel <ardb@kernel.org>
> > >
> > > Now that all users have been moved into startup/ where PIC codegen is
> > > used, RIP_REL_REF() is no longer needed. Remove it.
> > >
> > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > > ---
> > >   arch/x86/include/asm/asm.h | 5 -----
> > >   1 file changed, 5 deletions(-)
> > >
> > > diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> > > index a9f07799e337..eef0771512de 100644
> > > --- a/arch/x86/include/asm/asm.h
> > > +++ b/arch/x86/include/asm/asm.h
> > > @@ -120,11 +120,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
> > >
> > >       return p;
> > >   }
> > > -#ifndef __pic__
> > > -#define RIP_REL_REF(var)     (*(typeof(&(var)))rip_rel_ptr(&(var)))
> > > -#else
> > > -#define RIP_REL_REF(var)     (var)
> > > -#endif
> > >   #endif
> >
> > You can also remove rip_rel_ptr() with the whole "#ifndef __ASSEMBLER__"
> > part.
> >
>
> No, rip_rel_ptr() needs to be kept, unfortunately.

Indeed, I scanned the source before your patch, where rip_rel_ptr()
was used exclusively via RIP_REL_REF.

On a related note,

asm("leaq %c1(%%rip), %0" : "=r"(p) : "i"(p));

the above asm can use %a1 generic operand modifier instead of
"%c1(%%rip)" [1], similar to d689863c1a60b9 [2], which also explains
the modifier:

--q--
The "a" asm operand modifier substitutes a memory reference, with the
actual operand treated as address. For x86_64, when a symbol is
provided, the "a" modifier emits "sym(%rip)" instead of "sym",
enabling shorter %rip-relative addressing.
--/q--

[1] https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Generic-Operand-Modifiers
[2] https://web.git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/arch/x86/include/asm?id=d689863c1a60b9936b47a34fa5c3330de374f4fc

Uros.
[tip: x86/boot] x86/asm: Retire RIP_REL_REF()
Posted by tip-bot2 for Ard Biesheuvel 8 months ago
The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     ff4c0560ab020d34baf0aa6434f66333d25ae524
Gitweb:        https://git.kernel.org/tip/ff4c0560ab020d34baf0aa6434f66333d25ae524
Author:        Ard Biesheuvel <ardb@kernel.org>
AuthorDate:    Fri, 18 Apr 2025 16:13:00 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 22 Apr 2025 09:12:01 +02:00

x86/asm: Retire RIP_REL_REF()

Now that all users have been moved into startup/ where PIC codegen is
used, RIP_REL_REF() is no longer needed. Remove it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Dionna Amalie Glaze <dionnaglaze@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kevin Loughlin <kevinloughlin@google.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Link: https://lore.kernel.org/r/20250418141253.2601348-14-ardb+git@google.com
---
 arch/x86/include/asm/asm.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index a9f0779..eef0771 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -120,11 +120,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
 
 	return p;
 }
-#ifndef __pic__
-#define RIP_REL_REF(var)	(*(typeof(&(var)))rip_rel_ptr(&(var)))
-#else
-#define RIP_REL_REF(var)	(var)
-#endif
 #endif
 
 /*