[PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds

Marc Zyngier maz at kernel.org
Fri Jul 12 14:55:16 PDT 2024


On Fri, 12 Jul 2024 12:03:30 +0100,
Sebastian Ott <sebott at redhat.com> wrote:
> 
> Remove double initializations in cases where that's easily possible
> - like extra NULL initialization in static global structures. In the
> other cases just silence -Woverride-init.
> 
> To fix warnings like the following:
> arch/arm64/kvm/hyp/vhe/switch.c:271:43: warning: initialized field overwritten [-Woverride-init]
>   271 |         [ESR_ELx_EC_CP15_32]            = kvm_hyp_handle_cp15_32,
>       |                                           ^~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Sebastian Ott <sebott at redhat.com>
> ---
>  arch/arm64/kvm/handle_exit.c     | 5 +++++
>  arch/arm64/kvm/hyp/nvhe/switch.c | 6 ++----
>  arch/arm64/kvm/hyp/vhe/switch.c  | 3 +--
>  arch/arm64/kvm/sys_regs.c        | 5 +++++
>  4 files changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> index d7c2990e7c9e..2c049746657c 100644
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
> @@ -291,6 +291,9 @@ static int handle_svc(struct kvm_vcpu *vcpu)
>  	return 1;
>  }
>  
> +__diag_push();
> +__diag_ignore_all("-Woverride-init", "Allow field overrides in exit_handlers");

The wording you are looking for is "Silence stupid warning". I really
mean it. There is really nothing wrong with this code, and if the
compiler doesn't understand the purpose of a default initialiser, then
*maybe* it should be fixed rather than polluting the kernel with this
stuff.

> +
>  static exit_handle_fn arm_exit_handlers[] = {
>  	[0 ... ESR_ELx_EC_MAX]	= kvm_handle_unknown_ec,
>  	[ESR_ELx_EC_WFx]	= kvm_handle_wfx,
> @@ -319,6 +322,8 @@ static exit_handle_fn arm_exit_handlers[] = {
>  	[ESR_ELx_EC_PAC]	= kvm_handle_ptrauth,
>  };
>  
> +__diag_pop();
> +
>  static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
>  {
>  	u64 esr = kvm_vcpu_get_esr(vcpu);
> diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
> index 6af179c6356d..bf49afc01542 100644
> --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> @@ -200,8 +200,7 @@ static void kvm_hyp_save_fpsimd_host(struct kvm_vcpu *vcpu)
>  	}
>  }
>  
> -static const exit_handler_fn hyp_exit_handlers[] = {
> -	[0 ... ESR_ELx_EC_MAX]		= NULL,
> +static const exit_handler_fn hyp_exit_handlers[ESR_ELx_EC_MAX + 1] = {

Is this really any better? I don't think so. It makes the intent
disappear instead of making it explicit. Intent matters *a lot*.

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list