x86/mm/encrypt: Use %a asm operand modifier to obtain %rip-relative address
PATCH 1/1 x86/mm/encrypt: Use %a asm operand modifier to obtain %rip-relative address
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".
Clang allows only "i" and "r" operand constraints with an "a" modifier, so the patch normalizes the modifier/constraint pair to "a"/"i" which is consistent between both compilers.
No functional change intended.
--- arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
arch/x86/mm/mem_encrypt_identity.c +4 -12
@@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)* We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - :"=r" (workarea_start) - :"p" (sme_workarea)); + asm ("lea %a1, %0" :"=r" (workarea_start) :"i" (sme_workarea));/* * Calculate required number of workarea bytes needed:
@@ -582,15 +580,9 @@ void __init sme_enable(struct boot_params *bp)* identity mapped, so we must obtain the address to the SME command * line argument data using rip-relative addressing. */ - asm ("lea sme_cmdline_arg(%%rip), %0" - :"=r" (cmdline_arg) - :"p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - :"=r" (cmdline_on) - :"p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - :"=r" (cmdline_off) - :"p" (sme_cmdline_off)); + asm ("lea %a1, %0" :"=r" (cmdline_arg) :"i" (sme_cmdline_arg)); + asm ("lea %a1, %0" :"=r" (cmdline_on) :"i" (sme_cmdline_on)); + asm ("lea %a1, %0" :"=r" (cmdline_off) :"i" (sme_cmdline_off));if (IS_ENABLED (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT )) active_by_default = true;
Signature · 1 line
2.41.0
Borislav Petkov
maintainerQuoted 6 lines · Uros Bizjak
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".Clang allows only "i" and "r" operand constraints with an "a" modifier, so the patch normalizes the modifier/constraint pair to "a"/"i"
s/the patch normalizes/normalize/
Quoted 22 lines
which is consistent between both compilers.
No functional change intended.
Suggested-by Linus Torvalds <[email protected]>Cc Dave Hansen <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Signed-off-by Uros Bizjak <[email protected]>--- arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)arch/x86/mm/mem_encrypt_identity.c +0
-0
arch/x86/mm/mem_encrypt_identity.c void __init sme_encrypt_kernel(struct boot_params *bp) · line 349
Quoted 7 lines
arch/x86/mm/mem_encrypt_identity.c +1
-3@@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)* We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - :"=r" (workarea_start) - :"p" (sme_workarea)); + asm ("lea %a1, %0" :"=r" (workarea_start) :"i" (sme_workarea));
Yeah, I saw that particular subthread today.
Are you sure this "a" modifier DTRT with all gcc version we support?
I.e., from 5.1 onwards...
Just making sure.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 43 lines · Borislav Petkov
Quoted 6 lines · Uros Bizjak
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".Clang allows only "i" and "r" operand constraints with an "a" modifier, so the patch normalizes the modifier/constraint pair to "a"/"i"
s/the patch normalizes/normalize/
Quoted 22 lines
which is consistent between both compilers.
No functional change intended.
Suggested-by Linus Torvalds <[email protected]>Cc Dave Hansen <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Signed-off-by Uros Bizjak <[email protected]>--- arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)arch/x86/mm/mem_encrypt_identity.c +0
-0arch/x86/mm/mem_encrypt_identity.c void __init sme_encrypt_kernel(struct boot_params *bp) · line 349
Quoted 7 lines
arch/x86/mm/mem_encrypt_identity.c +1
-3@@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)* We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - :"=r" (workarea_start) - :"p" (sme_workarea)); + asm ("lea %a1, %0" :"=r" (workarea_start) :"i" (sme_workarea));Yeah, I saw that particular subthread today.
Quoted 3 lines
Are you sure this "a" modifier DTRT with all gcc version we support?
I.e., from 5.1 onwards...
Yes [1].
[1] https://godbolt.org/z/aWe7b16rT
Thanks,
Uros.
Quoted 44 lines · Uros Bizjak
Quoted 43 lines · Borislav Petkov
Quoted 6 lines · Uros Bizjak
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".Clang allows only "i" and "r" operand constraints with an "a" modifier, so the patch normalizes the modifier/constraint pair to "a"/"i"
s/the patch normalizes/normalize/
Quoted 22 lines
which is consistent between both compilers.
No functional change intended.
Suggested-by Linus Torvalds <[email protected]>Cc Dave Hansen <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Signed-off-by Uros Bizjak <[email protected]>--- arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)arch/x86/mm/mem_encrypt_identity.c +0
-0arch/x86/mm/mem_encrypt_identity.c void __init sme_encrypt_kernel(struct boot_params *bp) · line 349
Quoted 7 lines
arch/x86/mm/mem_encrypt_identity.c +1
-3@@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)* We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - :"=r" (workarea_start) - :"p" (sme_workarea)); + asm ("lea %a1, %0" :"=r" (workarea_start) :"i" (sme_workarea));Yeah, I saw that particular subthread today.
Quoted 7 lines
Quoted 3 lines
Are you sure this "a" modifier DTRT with all gcc version we support?
I.e., from 5.1 onwards...
Yes [1].
But Clang generates RIP-relative load only starting from version 15. Clange 11 claimed to be supported.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 48 lines · Kirill A. Shutemov
Quoted 46 lines · Uros Bizjak
Quoted 45 lines · Borislav Petkov
Quoted 6 lines · Uros Bizjak
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".Clang allows only "i" and "r" operand constraints with an "a" modifier, so the patch normalizes the modifier/constraint pair to "a"/"i"
s/the patch normalizes/normalize/
Quoted 22 lines
which is consistent between both compilers.
No functional change intended.
Suggested-by Linus Torvalds <[email protected]>Cc Dave Hansen <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Borislav Petkov <[email protected]>Cc "H. Peter Anvin" <[email protected]>Signed-off-by Uros Bizjak <[email protected]>--- arch/x86/mm/mem_encrypt_identity.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)arch/x86/mm/mem_encrypt_identity.c +0
-0arch/x86/mm/mem_encrypt_identity.c void __init sme_encrypt_kernel(struct boot_params *bp) · line 349
Quoted 7 lines
arch/x86/mm/mem_encrypt_identity.c +1
-3@@ -346,9 +346,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)* We're running identity mapped, so we must obtain the address to the * SME encryption workarea using rip-relative addressing. */ - asm ("lea sme_workarea(%%rip), %0" - :"=r" (workarea_start) - :"p" (sme_workarea)); + asm ("lea %a1, %0" :"=r" (workarea_start) :"i" (sme_workarea));Yeah, I saw that particular subthread today.
Are you sure this "a" modifier DTRT with all gcc version we support?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
I.e., from 5.1 onwards...
Yes [1].
But Clang generates RIP-relative load only starting from version 15. Clange 11 claimed to be supported.
Huh, what a bummer...
The patch is retracted then.
Thanks,
Uros.