[PATCH 1/2] x86/fred: Fix build with clang

Xin Li posted 2 patches 1 year, 11 months ago
[PATCH 1/2] x86/fred: Fix build with clang
Posted by Xin Li 1 year, 11 months ago
As clang doesn't allow .fill to refernece a symbol before it's defined,
use asm_fred_entrypoint_user instead of asm_fred_entrypoint_kernel.

Fixes: 5e0636a41485 ("x86/fred: FRED entry/exit and dispatch code")
Reported-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/lkml/20240126100050.GAZbOC0g3Rlr6otZcT@fat_crate.local/
Signed-off-by: Xin Li <xin3.li@intel.com>
---
 arch/x86/entry/entry_64_fred.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
index eedf98de7538..5427e0da190d 100644
--- a/arch/x86/entry/entry_64_fred.S
+++ b/arch/x86/entry/entry_64_fred.S
@@ -43,13 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user, SYM_L_GLOBAL)
 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
 SYM_CODE_END(asm_fred_entrypoint_user)
 
-.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
-
 /*
  * The new RIP value that FRED event delivery establishes is
  * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
  * ring 0, i.e., asm_fred_entrypoint_user + 256.
  */
+	.fill asm_fred_entrypoint_user + 256 - ., 1, 0xcc
 	.org asm_fred_entrypoint_user + 256
 SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
 	FRED_ENTER
-- 
2.43.0
Re: [PATCH 1/2] x86/fred: Fix build with clang
Posted by H. Peter Anvin 1 year, 11 months ago
On January 27, 2024 1:37:27 AM PST, Xin Li <xin3.li@intel.com> wrote:
>As clang doesn't allow .fill to refernece a symbol before it's defined,
>use asm_fred_entrypoint_user instead of asm_fred_entrypoint_kernel.
>
>Fixes: 5e0636a41485 ("x86/fred: FRED entry/exit and dispatch code")
>Reported-by: Borislav Petkov (AMD) <bp@alien8.de>
>Link: https://lore.kernel.org/lkml/20240126100050.GAZbOC0g3Rlr6otZcT@fat_crate.local/
>Signed-off-by: Xin Li <xin3.li@intel.com>
>---
> arch/x86/entry/entry_64_fred.S | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
>index eedf98de7538..5427e0da190d 100644
>--- a/arch/x86/entry/entry_64_fred.S
>+++ b/arch/x86/entry/entry_64_fred.S
>@@ -43,13 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user, SYM_L_GLOBAL)
> 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
> SYM_CODE_END(asm_fred_entrypoint_user)
> 
>-.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
>-
> /*
>  * The new RIP value that FRED event delivery establishes is
>  * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
>  * ring 0, i.e., asm_fred_entrypoint_user + 256.
>  */
>+	.fill asm_fred_entrypoint_user + 256 - ., 1, 0xcc
> 	.org asm_fred_entrypoint_user + 256
> SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
> 	FRED_ENTER

.fill and .org here are redundant; in fact, there two directives mean exactly the same thing except that .org implicitly subtracts the current offset.
RE: [PATCH 1/2] x86/fred: Fix build with clang
Posted by Li, Xin3 1 year, 11 months ago
> >diff --git a/arch/x86/entry/entry_64_fred.S
> >b/arch/x86/entry/entry_64_fred.S index eedf98de7538..5427e0da190d
> >100644
> >--- a/arch/x86/entry/entry_64_fred.S
> >+++ b/arch/x86/entry/entry_64_fred.S
> >@@ -43,13 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user,
> SYM_L_GLOBAL)
> > 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
> > SYM_CODE_END(asm_fred_entrypoint_user)
> >
> >-.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
> >-
> > /*
> >  * The new RIP value that FRED event delivery establishes is
> >  * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
> >  * ring 0, i.e., asm_fred_entrypoint_user + 256.
> >  */
> >+	.fill asm_fred_entrypoint_user + 256 - ., 1, 0xcc
> > 	.org asm_fred_entrypoint_user + 256
> > SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
> > 	FRED_ENTER
> 
> .fill and .org here are redundant; in fact, there two directives mean exactly the
> same thing except that .org implicitly subtracts the current offset.

Ah, right, .fill already does the job!

I will remove .org.
Re: [PATCH 1/2] x86/fred: Fix build with clang
Posted by H. Peter Anvin 1 year, 11 months ago
On 1/27/24 11:46, Li, Xin3 wrote:
>>> diff --git a/arch/x86/entry/entry_64_fred.S
>>> b/arch/x86/entry/entry_64_fred.S index eedf98de7538..5427e0da190d
>>> 100644
>>> --- a/arch/x86/entry/entry_64_fred.S
>>> +++ b/arch/x86/entry/entry_64_fred.S
>>> @@ -43,13 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user,
>> SYM_L_GLOBAL)
>>> 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
>>> SYM_CODE_END(asm_fred_entrypoint_user)
>>>
>>> -.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
>>> -
>>> /*
>>>   * The new RIP value that FRED event delivery establishes is
>>>   * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
>>>   * ring 0, i.e., asm_fred_entrypoint_user + 256.
>>>   */
>>> +	.fill asm_fred_entrypoint_user + 256 - ., 1, 0xcc
>>> 	.org asm_fred_entrypoint_user + 256
>>> SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
>>> 	FRED_ENTER
>>
>> .fill and .org here are redundant; in fact, there two directives mean exactly the
>> same thing except that .org implicitly subtracts the current offset.
> 
> Ah, right, .fill already does the job!
> 
> I will remove .org.
> 

Incidentally, was there a problem with .org ..., 0xcc?

Not a criticism, I just want to know to better understand current 
binutils limitations.

	-hpa
RE: [PATCH 1/2] x86/fred: Fix build with clang
Posted by Li, Xin3 1 year, 11 months ago
> >>> @@ -43,13 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user,
> >> SYM_L_GLOBAL)
> >>> 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
> >>> SYM_CODE_END(asm_fred_entrypoint_user)
> >>>
> >>> -.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
> >>> -
> >>> /*
> >>>   * The new RIP value that FRED event delivery establishes is
> >>>   * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
> >>>   * ring 0, i.e., asm_fred_entrypoint_user + 256.
> >>>   */
> >>> +	.fill asm_fred_entrypoint_user + 256 - ., 1, 0xcc
> >>> 	.org asm_fred_entrypoint_user + 256
> >>> SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
> >>> 	FRED_ENTER
> >>
> >> .fill and .org here are redundant; in fact, there two directives mean
> >> exactly the same thing except that .org implicitly subtracts the current offset.
> >
> > Ah, right, .fill already does the job!
> >
> > I will remove .org.
> >
> 
> Incidentally, was there a problem with .org ..., 0xcc?

Oh, it's just that I didn't know .org can be used to fill.

 
> Not a criticism, I just want to know to better understand current binutils
> limitations.
> 
> 	-hpa
[PATCH v1A 1/2] x86/fred: Fix build with clang
Posted by Xin Li 1 year, 11 months ago
Remove the .fill statement that referneces asm_fred_entrypoint_kernel()
before it's defined, which breaks clang build.

Use the .org directive instead to fill "int3" into the memory between
asm_fred_entrypoint_user() and asm_fred_entrypoint_kernel().

Fixes: 5e0636a41485 ("x86/fred: FRED entry/exit and dispatch code")
Reported-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/lkml/20240126100050.GAZbOC0g3Rlr6otZcT@fat_crate.local/
Signed-off-by: Xin Li <xin3.li@intel.com>
---

Change since v1:
* Use ".org ..., 0xcc" to fill "int3" into memory (H. Peter Anvin).
---
 arch/x86/entry/entry_64_fred.S | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
index eedf98de7538..a02bc6f3d2e6 100644
--- a/arch/x86/entry/entry_64_fred.S
+++ b/arch/x86/entry/entry_64_fred.S
@@ -43,14 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user, SYM_L_GLOBAL)
 	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
 SYM_CODE_END(asm_fred_entrypoint_user)
 
-.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
-
 /*
  * The new RIP value that FRED event delivery establishes is
  * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
  * ring 0, i.e., asm_fred_entrypoint_user + 256.
  */
-	.org asm_fred_entrypoint_user + 256
+	.org asm_fred_entrypoint_user + 256, 0xcc
 SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
 	FRED_ENTER
 	call	fred_entry_from_kernel
-- 
2.43.0
Re: [PATCH v1A 1/2] x86/fred: Fix build with clang
Posted by Borislav Petkov 1 year, 10 months ago
On Sun, Jan 28, 2024 at 10:45:21PM -0800, Xin Li wrote:
> Remove the .fill statement that referneces asm_fred_entrypoint_kernel()
> before it's defined, which breaks clang build.
> 
> Use the .org directive instead to fill "int3" into the memory between
> asm_fred_entrypoint_user() and asm_fred_entrypoint_kernel().
> 
> Fixes: 5e0636a41485 ("x86/fred: FRED entry/exit and dispatch code")
> Reported-by: Borislav Petkov (AMD) <bp@alien8.de>
> Link: https://lore.kernel.org/lkml/20240126100050.GAZbOC0g3Rlr6otZcT@fat_crate.local/
> Signed-off-by: Xin Li <xin3.li@intel.com>
> ---
> 
> Change since v1:
> * Use ".org ..., 0xcc" to fill "int3" into memory (H. Peter Anvin).
> ---
>  arch/x86/entry/entry_64_fred.S | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
> index eedf98de7538..a02bc6f3d2e6 100644
> --- a/arch/x86/entry/entry_64_fred.S
> +++ b/arch/x86/entry/entry_64_fred.S
> @@ -43,14 +43,12 @@ SYM_INNER_LABEL(asm_fred_exit_user, SYM_L_GLOBAL)
>  	_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
>  SYM_CODE_END(asm_fred_entrypoint_user)
>  
> -.fill asm_fred_entrypoint_kernel - ., 1, 0xcc
> -
>  /*
>   * The new RIP value that FRED event delivery establishes is
>   * (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
>   * ring 0, i.e., asm_fred_entrypoint_user + 256.
>   */
> -	.org asm_fred_entrypoint_user + 256
> +	.org asm_fred_entrypoint_user + 256, 0xcc
>  SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
>  	FRED_ENTER
>  	call	fred_entry_from_kernel
> -- 

Considering how we're still very early in the game, I'm going to fold
those into the respective patches and rebase so that we have as clean
a branch as possible.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette