All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
@ 2023-03-10 14:02 Guilherme G. Piccoli
  2023-03-10 15:24 ` Josh Poimboeuf
  0 siblings, 1 reply; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-10 14:02 UTC (permalink / raw)
  To: linux-hyperv, x86
  Cc: linux-kernel, decui, haiyangz, kys, wei.liu, tglx, mingo, bp,
	dave.hansen, hpa, thomas.lendacky, jpoimboe, peterz, kernel-dev,
	kernel, Guilherme G. Piccoli, Arnd Bergmann

Annotate the function prototype as noreturn to prevent objtool
warnings like:

vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction

As a comparison, an objdump output without the annotation:

[...]
1b63:  mov    $0x1,%esi
1b68:  xor    %edi,%edi
1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
[...]

Now, after adding the __noreturn to the function prototype:

[...]
17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
17e4:  test   %al,%al
17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
[...]  <many insns>
1bb9:  mov    $0x1,%esi
1bbe:  xor    %edi,%edi
1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function

Reported-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---


Hey folks, after getting the warning myself a quick search led me to Arnd's
thorough report - investigating a bit, this seems to be the proper solution.

Notice I didn't add the function to objtool's static list, seems this is
unnecessary in this case - lemme know otherwise!
Thanks in advance for reviews,


Guilherme


 arch/x86/include/asm/mshyperv.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 4c4c0ec3b62e..09c26e658bcc 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -212,7 +212,7 @@ int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible);
 void hv_ghcb_msr_write(u64 msr, u64 value);
 void hv_ghcb_msr_read(u64 msr, u64 *value);
 bool hv_ghcb_negotiate_protocol(void);
-void hv_ghcb_terminate(unsigned int set, unsigned int reason);
+void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
 #else
 static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
 static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
-- 
2.39.2


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

* Re: [PATCH] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 14:02 [PATCH] x86/hyperv: Mark hv_ghcb_terminate() as noreturn Guilherme G. Piccoli
@ 2023-03-10 15:24 ` Josh Poimboeuf
  2023-03-10 15:41   ` Guilherme G. Piccoli
  2023-03-10 15:44   ` [PATCH v2] " Guilherme G. Piccoli
  0 siblings, 2 replies; 14+ messages in thread
From: Josh Poimboeuf @ 2023-03-10 15:24 UTC (permalink / raw)
  To: Guilherme G. Piccoli
  Cc: linux-hyperv, x86, linux-kernel, decui, haiyangz, kys, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, peterz,
	kernel-dev, kernel, Arnd Bergmann

On Fri, Mar 10, 2023 at 11:02:52AM -0300, Guilherme G. Piccoli wrote:
> Hey folks, after getting the warning myself a quick search led me to Arnd's
> thorough report - investigating a bit, this seems to be the proper solution.
> 
> Notice I didn't add the function to objtool's static list, seems this is
> unnecessary in this case - lemme know otherwise!
> Thanks in advance for reviews,

I'd recommend also adding it to the objtool global_noreturns list,
otherwise this patch will probably trigger warnings with other non-IBT
configs, in cases where the function is called from another translation
unit, where GCC knows the function is noreturn but objtool doesn't.

We're looking at ways of eliminating global_noreturns, but it's
unfortunately still a necessary evil at this point.

Also, FWIW, I have a change coming soon which make these warnings much
easier to diagnose.

-- 
Josh

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

* Re: [PATCH] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 15:24 ` Josh Poimboeuf
@ 2023-03-10 15:41   ` Guilherme G. Piccoli
  2023-03-10 15:44   ` [PATCH v2] " Guilherme G. Piccoli
  1 sibling, 0 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-10 15:41 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: linux-hyperv, x86, linux-kernel, decui, haiyangz, kys, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, peterz,
	kernel-dev, kernel, Arnd Bergmann

On 10/03/2023 12:24, Josh Poimboeuf wrote:
> On Fri, Mar 10, 2023 at 11:02:52AM -0300, Guilherme G. Piccoli wrote: 
> I'd recommend also adding it to the objtool global_noreturns list,
> otherwise this patch will probably trigger warnings with other non-IBT
> configs, in cases where the function is called from another translation
> unit, where GCC knows the function is noreturn but objtool doesn't.
> 
> We're looking at ways of eliminating global_noreturns, but it's
> unfortunately still a necessary evil at this point.
> 

Hi Josh, thanks! Makes sense, I'll respond here with a V2 doing that.


> Also, FWIW, I have a change coming soon which make these warnings much
> easier to diagnose.
> 

Cool =)

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

* [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 15:24 ` Josh Poimboeuf
  2023-03-10 15:41   ` Guilherme G. Piccoli
@ 2023-03-10 15:44   ` Guilherme G. Piccoli
  2023-03-10 21:17     ` Michael Kelley (LINUX)
  2023-03-17 16:05     ` [PATCH v3] " Guilherme G. Piccoli
  1 sibling, 2 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-10 15:44 UTC (permalink / raw)
  To: linux-hyperv, x86
  Cc: linux-kernel, decui, haiyangz, kys, wei.liu, tglx, mingo, bp,
	dave.hansen, hpa, thomas.lendacky, jpoimboe, peterz, kernel-dev,
	kernel, Guilherme G. Piccoli, Arnd Bergmann

Annotate the function prototype as noreturn to prevent objtool
warnings like:

vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction

Also, as per Josh's suggestion, add it to the global_noreturns list.
As a comparison, an objdump output without the annotation:

[...]
1b63:  mov    $0x1,%esi
1b68:  xor    %edi,%edi
1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
[...]

Now, after adding the __noreturn to the function prototype:

[...]
17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
17e4:  test   %al,%al
17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
[...]  <many insns>
1bb9:  mov    $0x1,%esi
1bbe:  xor    %edi,%edi
1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function

Reported-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---


V2:
- Per Josh's suggestion (thanks!), added the function to the objtool global
table as well.


 arch/x86/include/asm/mshyperv.h | 2 +-
 tools/objtool/check.c           | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 4c4c0ec3b62e..09c26e658bcc 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -212,7 +212,7 @@ int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible);
 void hv_ghcb_msr_write(u64 msr, u64 value);
 void hv_ghcb_msr_read(u64 msr, u64 *value);
 bool hv_ghcb_negotiate_protocol(void);
-void hv_ghcb_terminate(unsigned int set, unsigned int reason);
+void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
 #else
 static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
 static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f937be1afe65..4b5e03f61f1f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -209,6 +209,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		"do_task_dead",
 		"ex_handler_msr_mce",
 		"fortify_panic",
+		"hv_ghcb_terminate",
 		"kthread_complete_and_exit",
 		"kthread_exit",
 		"kunit_try_catch_throw",
-- 
2.39.2


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

* RE: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 15:44   ` [PATCH v2] " Guilherme G. Piccoli
@ 2023-03-10 21:17     ` Michael Kelley (LINUX)
  2023-03-11  0:17       ` Guilherme G. Piccoli
  2023-03-16 21:24       ` Guilherme G. Piccoli
  2023-03-17 16:05     ` [PATCH v3] " Guilherme G. Piccoli
  1 sibling, 2 replies; 14+ messages in thread
From: Michael Kelley (LINUX) @ 2023-03-10 21:17 UTC (permalink / raw)
  To: Guilherme G. Piccoli, linux-hyperv, x86
  Cc: linux-kernel, Dexuan Cui, Haiyang Zhang, KY Srinivasan, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, jpoimboe,
	peterz, kernel-dev, kernel, Arnd Bergmann

From: Guilherme G. Piccoli <gpiccoli@igalia.com>
> 
> Annotate the function prototype as noreturn to prevent objtool
> warnings like:

Just curious:  Should the actual function also be updated with
__noreturn?   In similar situations, such as snp_abort(), the
__noreturn attribute is both places.   I don't know what the 
guidance is on this question.

In any case, thanks for doing this cleanup!

Michael

> 
> 
> Also, as per Josh's suggestion, add it to the global_noreturns list.
> As a comparison, an objdump output without the annotation:
>
> vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction 
> [...]
> 1b63:  mov    $0x1,%esi
> 1b68:  xor    %edi,%edi
> 1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
> 1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
> [...]
> 
> Now, after adding the __noreturn to the function prototype:
> 
> [...]
> 17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
> 17e4:  test   %al,%al
> 17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
> [...]  <many insns>
> 1bb9:  mov    $0x1,%esi
> 1bbe:  xor    %edi,%edi
> 1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function
> 
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Link: https://lore.kernel.org/all/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
> ---
> 
> 
> V2:
> - Per Josh's suggestion (thanks!), added the function to the objtool global
> table as well.
> 
> 
>  arch/x86/include/asm/mshyperv.h | 2 +-
>  tools/objtool/check.c           | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 4c4c0ec3b62e..09c26e658bcc 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -212,7 +212,7 @@ int hv_set_mem_host_visibility(unsigned long addr, int
> numpages, bool visible);
>  void hv_ghcb_msr_write(u64 msr, u64 value);
>  void hv_ghcb_msr_read(u64 msr, u64 *value);
>  bool hv_ghcb_negotiate_protocol(void);
> -void hv_ghcb_terminate(unsigned int set, unsigned int reason);
> +void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
>  #else
>  static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
>  static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index f937be1afe65..4b5e03f61f1f 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -209,6 +209,7 @@ static bool __dead_end_function(struct objtool_file *file, struct
> symbol *func,
>  		"do_task_dead",
>  		"ex_handler_msr_mce",
>  		"fortify_panic",
> +		"hv_ghcb_terminate",
>  		"kthread_complete_and_exit",
>  		"kthread_exit",
>  		"kunit_try_catch_throw",
> --
> 2.39.2


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

* Re: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 21:17     ` Michael Kelley (LINUX)
@ 2023-03-11  0:17       ` Guilherme G. Piccoli
  2023-03-16 21:24       ` Guilherme G. Piccoli
  1 sibling, 0 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-11  0:17 UTC (permalink / raw)
  To: Michael Kelley (LINUX), linux-hyperv, x86
  Cc: linux-kernel, Dexuan Cui, Haiyang Zhang, KY Srinivasan, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, jpoimboe,
	peterz, kernel-dev, kernel, Arnd Bergmann

On 10/03/2023 18:17, Michael Kelley (LINUX) wrote:
> From: Guilherme G. Piccoli <gpiccoli@igalia.com>
>>
>> Annotate the function prototype as noreturn to prevent objtool
>> warnings like:
> 
> Just curious:  Should the actual function also be updated with
> __noreturn?   In similar situations, such as snp_abort(), the
> __noreturn attribute is both places.   I don't know what the 
> guidance is on this question.
> 
> In any case, thanks for doing this cleanup!
> 
> Michael

Thanks Michael!

In my understanding (anybody please correct me if I'm wrong) any user of
this function that rely on this header will "inherit" the attribute -
hence, if this function is not used in any other header or statically
inside it's own definition file, it's not necessary.

But I'm glad in submitting a V3 with that if it's better, let me know.
Cheers,


Guilherme

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

* Re: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 21:17     ` Michael Kelley (LINUX)
  2023-03-11  0:17       ` Guilherme G. Piccoli
@ 2023-03-16 21:24       ` Guilherme G. Piccoli
  2023-03-17 13:40         ` Michael Kelley (LINUX)
  1 sibling, 1 reply; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-16 21:24 UTC (permalink / raw)
  To: Michael Kelley (LINUX), x86, jpoimboe
  Cc: linux-hyperv, linux-kernel, Dexuan Cui, Haiyang Zhang,
	KY Srinivasan, wei.liu, tglx, mingo, bp, dave.hansen, hpa,
	thomas.lendacky, peterz, kernel-dev, kernel, Arnd Bergmann

On 10/03/2023 18:17, Michael Kelley (LINUX) wrote:
> [...]
> Just curious:  Should the actual function also be updated with
> __noreturn?   In similar situations, such as snp_abort(), the
> __noreturn attribute is both places.   I don't know what the 
> guidance is on this question.
> 

Hi Michael / Josh (and all), lemme know if you want me to submit a V3
doing that. The function is not called inside this own definition file
nor exported, so I'm not sure that'd be necessary, but glad to do so if
you prefer.

Thanks,


Guilherme

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

* RE: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-16 21:24       ` Guilherme G. Piccoli
@ 2023-03-17 13:40         ` Michael Kelley (LINUX)
  2023-03-17 14:53           ` Josh Poimboeuf
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Kelley (LINUX) @ 2023-03-17 13:40 UTC (permalink / raw)
  To: Guilherme G. Piccoli, x86, jpoimboe
  Cc: linux-hyperv, linux-kernel, Dexuan Cui, Haiyang Zhang,
	KY Srinivasan, wei.liu, tglx, mingo, bp, dave.hansen, hpa,
	thomas.lendacky, peterz, kernel-dev, kernel, Arnd Bergmann

From: Guilherme G. Piccoli <gpiccoli@igalia.com> Sent: Thursday, March 16, 2023 2:24 PM
> 
> On 10/03/2023 18:17, Michael Kelley (LINUX) wrote:
> > [...]
> > Just curious:  Should the actual function also be updated with
> > __noreturn?   In similar situations, such as snp_abort(), the
> > __noreturn attribute is both places.   I don't know what the
> > guidance is on this question.
> >
> 
> Hi Michael / Josh (and all), lemme know if you want me to submit a V3
> doing that. The function is not called inside this own definition file
> nor exported, so I'm not sure that'd be necessary, but glad to do so if
> you prefer.
> 

I don't have a preference.  I was just trying to make sure the details
are all correct.  I'll defer to those with more knowledge of the
__noreturn attribute than I have.

Michael

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

* Re: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-17 13:40         ` Michael Kelley (LINUX)
@ 2023-03-17 14:53           ` Josh Poimboeuf
  2023-03-17 16:04             ` Guilherme G. Piccoli
  0 siblings, 1 reply; 14+ messages in thread
From: Josh Poimboeuf @ 2023-03-17 14:53 UTC (permalink / raw)
  To: Michael Kelley (LINUX)
  Cc: Guilherme G. Piccoli, x86, linux-hyperv, linux-kernel,
	Dexuan Cui, Haiyang Zhang, KY Srinivasan, wei.liu, tglx, mingo,
	bp, dave.hansen, hpa, thomas.lendacky, peterz, kernel-dev,
	kernel, Arnd Bergmann

On Fri, Mar 17, 2023 at 01:40:25PM +0000, Michael Kelley (LINUX) wrote:
> From: Guilherme G. Piccoli <gpiccoli@igalia.com> Sent: Thursday, March 16, 2023 2:24 PM
> > 
> > On 10/03/2023 18:17, Michael Kelley (LINUX) wrote:
> > > [...]
> > > Just curious:  Should the actual function also be updated with
> > > __noreturn?   In similar situations, such as snp_abort(), the
> > > __noreturn attribute is both places.   I don't know what the
> > > guidance is on this question.
> > >
> > 
> > Hi Michael / Josh (and all), lemme know if you want me to submit a V3
> > doing that. The function is not called inside this own definition file
> > nor exported, so I'm not sure that'd be necessary, but glad to do so if
> > you prefer.
> > 
> 
> I don't have a preference.  I was just trying to make sure the details
> are all correct.  I'll defer to those with more knowledge of the
> __noreturn attribute than I have.

It's not required, but probably good practice to put __noreturn in both
places to make it more self-documenting.

-- 
Josh

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

* Re: [PATCH v2] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-17 14:53           ` Josh Poimboeuf
@ 2023-03-17 16:04             ` Guilherme G. Piccoli
  0 siblings, 0 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-17 16:04 UTC (permalink / raw)
  To: Josh Poimboeuf, Michael Kelley (LINUX)
  Cc: x86, linux-hyperv, linux-kernel, Dexuan Cui, Haiyang Zhang,
	KY Srinivasan, wei.liu, tglx, mingo, bp, dave.hansen, hpa,
	thomas.lendacky, peterz, kernel-dev, kernel, Arnd Bergmann

On 17/03/2023 11:53, Josh Poimboeuf wrote:
> [...]
>>> Hi Michael / Josh (and all), lemme know if you want me to submit a V3
>>> doing that. The function is not called inside this own definition file
>>> nor exported, so I'm not sure that'd be necessary, but glad to do so if
>>> you prefer.
>>>
>>
>> I don't have a preference.  I was just trying to make sure the details
>> are all correct.  I'll defer to those with more knowledge of the
>> __noreturn attribute than I have.
> 
> It's not required, but probably good practice to put __noreturn in both
> places to make it more self-documenting.
> 

Thanks Josh and Michael, will submit a V3 shortly with this improvement!
Cheers,


Guilherme

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

* [PATCH v3] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-10 15:44   ` [PATCH v2] " Guilherme G. Piccoli
  2023-03-10 21:17     ` Michael Kelley (LINUX)
@ 2023-03-17 16:05     ` Guilherme G. Piccoli
  2023-03-17 16:24       ` Josh Poimboeuf
  2023-03-17 16:46       ` Michael Kelley (LINUX)
  1 sibling, 2 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-17 16:05 UTC (permalink / raw)
  To: linux-hyperv, x86
  Cc: linux-kernel, decui, haiyangz, kys, wei.liu, tglx, mingo, bp,
	dave.hansen, hpa, thomas.lendacky, peterz, kernel-dev, kernel,
	Guilherme G. Piccoli, Arnd Bergmann, Josh Poimboeuf,
	Michael Kelley

Annotate the function prototype and definition as noreturn to prevent
objtool warnings like:

vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction

Also, as per Josh's suggestion, add it to the global_noreturns list.
As a comparison, an objdump output without the annotation:

[...]
1b63:  mov    $0x1,%esi
1b68:  xor    %edi,%edi
1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
[...]

Now, after adding the __noreturn to the function prototype:

[...]
17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
17e4:  test   %al,%al
17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
[...]  <many insns>
1bb9:  mov    $0x1,%esi
1bbe:  xor    %edi,%edi
1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function

Reported-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---


V3:
- As per Michael / Josh advice (thanks!), added __noreturn to the
function definition as well.

V2:
- Per Josh's suggestion (thanks!), added the function name to the
objtool global table.

Thanks in advance for reviews/comments!
Cheers,

Guilherme


 arch/x86/hyperv/ivm.c           | 2 +-
 arch/x86/include/asm/mshyperv.h | 2 +-
 tools/objtool/check.c           | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index 1dbcbd9da74d..4f79dc76042d 100644
--- a/arch/x86/hyperv/ivm.c
+++ b/arch/x86/hyperv/ivm.c
@@ -127,7 +127,7 @@ static enum es_result hv_ghcb_hv_call(struct ghcb *ghcb, u64 exit_code,
 		return ES_OK;
 }
 
-void hv_ghcb_terminate(unsigned int set, unsigned int reason)
+void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason)
 {
 	u64 val = GHCB_MSR_TERM_REQ;
 
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 4c4c0ec3b62e..09c26e658bcc 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -212,7 +212,7 @@ int hv_set_mem_host_visibility(unsigned long addr, int numpages, bool visible);
 void hv_ghcb_msr_write(u64 msr, u64 value);
 void hv_ghcb_msr_read(u64 msr, u64 *value);
 bool hv_ghcb_negotiate_protocol(void);
-void hv_ghcb_terminate(unsigned int set, unsigned int reason);
+void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
 #else
 static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
 static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f937be1afe65..4b5e03f61f1f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -209,6 +209,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		"do_task_dead",
 		"ex_handler_msr_mce",
 		"fortify_panic",
+		"hv_ghcb_terminate",
 		"kthread_complete_and_exit",
 		"kthread_exit",
 		"kunit_try_catch_throw",
-- 
2.39.2


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

* Re: [PATCH v3] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-17 16:05     ` [PATCH v3] " Guilherme G. Piccoli
@ 2023-03-17 16:24       ` Josh Poimboeuf
  2023-03-17 19:27         ` Guilherme G. Piccoli
  2023-03-17 16:46       ` Michael Kelley (LINUX)
  1 sibling, 1 reply; 14+ messages in thread
From: Josh Poimboeuf @ 2023-03-17 16:24 UTC (permalink / raw)
  To: Guilherme G. Piccoli
  Cc: linux-hyperv, x86, linux-kernel, decui, haiyangz, kys, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, peterz,
	kernel-dev, kernel, Arnd Bergmann, Michael Kelley

On Fri, Mar 17, 2023 at 01:05:46PM -0300, Guilherme G. Piccoli wrote:
> Annotate the function prototype and definition as noreturn to prevent
> objtool warnings like:
> 
> vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction
> 
> Also, as per Josh's suggestion, add it to the global_noreturns list.
> As a comparison, an objdump output without the annotation:
> 
> [...]
> 1b63:  mov    $0x1,%esi
> 1b68:  xor    %edi,%edi
> 1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
> 1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
> [...]
> 
> Now, after adding the __noreturn to the function prototype:
> 
> [...]
> 17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
> 17e4:  test   %al,%al
> 17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
> [...]  <many insns>
> 1bb9:  mov    $0x1,%esi
> 1bbe:  xor    %edi,%edi
> 1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function
> 
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Link: https://lore.kernel.org/r/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Cc: Michael Kelley <mikelley@microsoft.com>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>

Looks good to me.  I've got some other noreturn fixes pending, so I can
add this patch to the pile unless somebody else wants to take it.

-- 
Josh

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

* RE: [PATCH v3] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-17 16:05     ` [PATCH v3] " Guilherme G. Piccoli
  2023-03-17 16:24       ` Josh Poimboeuf
@ 2023-03-17 16:46       ` Michael Kelley (LINUX)
  1 sibling, 0 replies; 14+ messages in thread
From: Michael Kelley (LINUX) @ 2023-03-17 16:46 UTC (permalink / raw)
  To: Guilherme G. Piccoli, linux-hyperv, x86
  Cc: linux-kernel, Dexuan Cui, Haiyang Zhang, KY Srinivasan, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, peterz,
	kernel-dev, kernel, Arnd Bergmann, Josh Poimboeuf

From: Guilherme G. Piccoli <gpiccoli@igalia.com> Sent: Friday, March 17, 2023 9:06 AM
> 
> Annotate the function prototype and definition as noreturn to prevent
> objtool warnings like:
> 
> vmlinux.o: warning: objtool: hyperv_init+0x55c: unreachable instruction
> 
> Also, as per Josh's suggestion, add it to the global_noreturns list.
> As a comparison, an objdump output without the annotation:
> 
> [...]
> 1b63:  mov    $0x1,%esi
> 1b68:  xor    %edi,%edi
> 1b6a:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1b6f:  jmpq   ffffffff82f217ec <hyperv_init+0x9c> # unreachable
> 1b74:  cmpq   $0xffffffffffffffff,-0x702a24(%rip)
> [...]
> 
> Now, after adding the __noreturn to the function prototype:
> 
> [...]
> 17df:  callq  ffffffff8102f6d0 <hv_ghcb_negotiate_protocol>
> 17e4:  test   %al,%al
> 17e6:  je     ffffffff82f21bb9 <hyperv_init+0x469>
> [...]  <many insns>
> 1bb9:  mov    $0x1,%esi
> 1bbe:  xor    %edi,%edi
> 1bc0:  callq  ffffffff8102f680 <hv_ghcb_terminate>
> 1bc5:  nopw   %cs:0x0(%rax,%rax,1) # end of function
> 
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Link: https://lore.kernel.org/all/9698eff1-9680-4f0a-94de-590eaa923e94@app.fastmail.com/
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Cc: Michael Kelley <mikelley@microsoft.com>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
> ---
> 
> 
> V3:
> - As per Michael / Josh advice (thanks!), added __noreturn to the
> function definition as well.
> 
> V2:
> - Per Josh's suggestion (thanks!), added the function name to the
> objtool global table.
> 
> Thanks in advance for reviews/comments!
> Cheers,
> 
> Guilherme
> 
> 
>  arch/x86/hyperv/ivm.c           | 2 +-
>  arch/x86/include/asm/mshyperv.h | 2 +-
>  tools/objtool/check.c           | 1 +
>  3 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 1dbcbd9da74d..4f79dc76042d 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -127,7 +127,7 @@ static enum es_result hv_ghcb_hv_call(struct ghcb *ghcb, u64
> exit_code,
>  		return ES_OK;
>  }
> 
> -void hv_ghcb_terminate(unsigned int set, unsigned int reason)
> +void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason)
>  {
>  	u64 val = GHCB_MSR_TERM_REQ;
> 
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 4c4c0ec3b62e..09c26e658bcc 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -212,7 +212,7 @@ int hv_set_mem_host_visibility(unsigned long addr, int
> numpages, bool visible);
>  void hv_ghcb_msr_write(u64 msr, u64 value);
>  void hv_ghcb_msr_read(u64 msr, u64 *value);
>  bool hv_ghcb_negotiate_protocol(void);
> -void hv_ghcb_terminate(unsigned int set, unsigned int reason);
> +void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
>  #else
>  static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
>  static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index f937be1afe65..4b5e03f61f1f 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -209,6 +209,7 @@ static bool __dead_end_function(struct objtool_file *file, struct
> symbol *func,
>  		"do_task_dead",
>  		"ex_handler_msr_mce",
>  		"fortify_panic",
> +		"hv_ghcb_terminate",
>  		"kthread_complete_and_exit",
>  		"kthread_exit",
>  		"kunit_try_catch_throw",
> --
> 2.39.2

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


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

* Re: [PATCH v3] x86/hyperv: Mark hv_ghcb_terminate() as noreturn
  2023-03-17 16:24       ` Josh Poimboeuf
@ 2023-03-17 19:27         ` Guilherme G. Piccoli
  0 siblings, 0 replies; 14+ messages in thread
From: Guilherme G. Piccoli @ 2023-03-17 19:27 UTC (permalink / raw)
  To: Josh Poimboeuf, Michael Kelley
  Cc: linux-hyperv, x86, linux-kernel, decui, haiyangz, kys, wei.liu,
	tglx, mingo, bp, dave.hansen, hpa, thomas.lendacky, peterz,
	kernel-dev, kernel, Arnd Bergmann

On 17/03/2023 13:24, Josh Poimboeuf wrote:
> [...]
> 
> Looks good to me.  I've got some other noreturn fixes pending, so I can
> add this patch to the pile unless somebody else wants to take it.

Thanks, that'd be great. And thanks Michael for your review =)


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

end of thread, other threads:[~2023-03-17 19:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 14:02 [PATCH] x86/hyperv: Mark hv_ghcb_terminate() as noreturn Guilherme G. Piccoli
2023-03-10 15:24 ` Josh Poimboeuf
2023-03-10 15:41   ` Guilherme G. Piccoli
2023-03-10 15:44   ` [PATCH v2] " Guilherme G. Piccoli
2023-03-10 21:17     ` Michael Kelley (LINUX)
2023-03-11  0:17       ` Guilherme G. Piccoli
2023-03-16 21:24       ` Guilherme G. Piccoli
2023-03-17 13:40         ` Michael Kelley (LINUX)
2023-03-17 14:53           ` Josh Poimboeuf
2023-03-17 16:04             ` Guilherme G. Piccoli
2023-03-17 16:05     ` [PATCH v3] " Guilherme G. Piccoli
2023-03-17 16:24       ` Josh Poimboeuf
2023-03-17 19:27         ` Guilherme G. Piccoli
2023-03-17 16:46       ` Michael Kelley (LINUX)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.