x86/hyperv: Mark hv_ghcb_terminate() as noreturn

Message ID 20230310140251.1159036-1-gpiccoli@igalia.com
State New
Headers
Series x86/hyperv: Mark hv_ghcb_terminate() as noreturn |

Commit Message

Guilherme G. Piccoli March 10, 2023, 2:02 p.m. UTC
  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(-)
  

Comments

Josh Poimboeuf March 10, 2023, 3:24 p.m. UTC | #1
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.
  
Guilherme G. Piccoli March 10, 2023, 3:41 p.m. UTC | #2
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 =)
  

Patch

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) {}