Re: [PATCH v2 1/1] x86/reboot: KVM: Guard nmi_shootdown_cpus_on_restart() with ifdeffery

From: Sean Christopherson
Date: Wed Oct 09 2024 - 15:35:34 EST


On Tue, Oct 08, 2024, Andy Shevchenko wrote:
> The nmi_shootdown_cpus_on_restart() in some cases may be not used.
> This, in particular, prevents kernel builds with clang, `make W=1`
> and CONFIG_WERROR=y:
>
> arch/x86/kernel/reboot.c:957:20: error: unused function 'nmi_shootdown_cpus_on_restart' [-Werror,-Wunused-function]
> 957 | static inline void nmi_shootdown_cpus_on_restart(void)
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Fix this by guarging the definitions with the respective KVM ifdeffery.
>
> See also commit 6863f5643dd7 ("kbuild: allow Clang to find unused static
> inline functions for W=1 build").
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> v1: suggested by Dave Hansen
> v2: rebased on top of the latest changes in the file
> arch/x86/kernel/reboot.c | 22 +++++++++++++---------
> 1 file changed, 13 insertions(+), 9 deletions(-)


Heh, I tried fixing this too, and have patches to clean things up, but I ended up
not posting them because I decided the W=1 warning was less ugly than the resulting
code in nmi_shootdown_cpus().

If we're willing to take on a bit of weirdness in nmi_shootdown_cpus(), then much
of the #ifdeffery can go away. Patches attached (lightly tested).

$ git diff --stat next..HEAD
arch/x86/kernel/reboot.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)