linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] KVM: arm64: fix warnings in W=1 build
@ 2024-07-12 11:03 Sebastian Ott
  2024-07-12 11:03 ` [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds Sebastian Ott
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sebastian Ott @ 2024-07-12 11:03 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Catalin Marinas, Will Deacon, Zenghui Yu

Building arch/arm64/kvm/ with W=1 spills out a lot of warnings. When
changing stuff I try to use as much tooling as possible to make sure
that I don't screw up - having a clean baseline imho helps with that.

With the first 2 patches applied make W=1 arch/arm64/kvm/ runs without
warnings for me (fedora userspace, kvm-arm/next). Patch 3 gets rid
of sparse lock warnings in arch/arm64/kvm/vgic/.

Sebastian Ott (3):
  KVM: arm64: fix override-init warnings in W=1 builds
  KVM: arm64: fix kdoc warnings in W=1 builds
  KVM: arm64: vgic: fix unexpected unlock sparse warnings

 arch/arm64/kvm/arm.c             |  1 +
 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 +++++
 arch/arm64/kvm/vgic/vgic-irqfd.c |  7 ++++---
 arch/arm64/kvm/vgic/vgic-its.c   | 18 +++++++++++-------
 arch/arm64/kvm/vgic/vgic-v3.c    |  2 +-
 arch/arm64/kvm/vgic/vgic.c       |  2 +-
 arch/arm64/kvm/vgic/vgic.h       |  2 +-
 10 files changed, 32 insertions(+), 19 deletions(-)

-- 
2.42.0



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

* [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-12 11:03 [PATCH 0/3] KVM: arm64: fix warnings in W=1 build Sebastian Ott
@ 2024-07-12 11:03 ` Sebastian Ott
  2024-07-12 21:55   ` Marc Zyngier
  2024-07-12 11:03 ` [PATCH 2/3] KVM: arm64: fix kdoc " Sebastian Ott
  2024-07-12 11:03 ` [PATCH 3/3] KVM: arm64: vgic: fix unexpected unlock sparse warnings Sebastian Ott
  2 siblings, 1 reply; 9+ messages in thread
From: Sebastian Ott @ 2024-07-12 11:03 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Catalin Marinas, Will Deacon, Zenghui Yu

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@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");
+
 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] = {
 	[ESR_ELx_EC_CP15_32]		= kvm_hyp_handle_cp15_32,
 	[ESR_ELx_EC_SYS64]		= kvm_hyp_handle_sysreg,
 	[ESR_ELx_EC_SVE]		= kvm_hyp_handle_fpsimd,
@@ -212,8 +211,7 @@ static const exit_handler_fn hyp_exit_handlers[] = {
 	[ESR_ELx_EC_MOPS]		= kvm_hyp_handle_mops,
 };
 
-static const exit_handler_fn pvm_exit_handlers[] = {
-	[0 ... ESR_ELx_EC_MAX]		= NULL,
+static const exit_handler_fn pvm_exit_handlers[ESR_ELx_EC_MAX + 1] = {
 	[ESR_ELx_EC_SYS64]		= kvm_handle_pvm_sys64,
 	[ESR_ELx_EC_SVE]		= kvm_handle_pvm_restricted,
 	[ESR_ELx_EC_FP_ASIMD]		= kvm_hyp_handle_fpsimd,
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 77010b76c150..4e4ff2bd51c9 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -415,8 +415,7 @@ static bool kvm_hyp_handle_sysreg_vhe(struct kvm_vcpu *vcpu, u64 *exit_code)
 	return kvm_hyp_handle_sysreg(vcpu, exit_code);
 }
 
-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] = {
 	[ESR_ELx_EC_CP15_32]		= kvm_hyp_handle_cp15_32,
 	[ESR_ELx_EC_SYS64]		= kvm_hyp_handle_sysreg_vhe,
 	[ESR_ELx_EC_SVE]		= kvm_hyp_handle_fpsimd,
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index c90324060436..00fb6f1e9a48 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2255,6 +2255,9 @@ static bool access_zcr_el2(struct kvm_vcpu *vcpu,
 	return true;
 }
 
+__diag_push();
+__diag_ignore_all("-Woverride-init", "Allow field overrides in sys_reg_descs");
+
 /*
  * Architected system registers.
  * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2
@@ -2803,6 +2806,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
 	EL2_REG(SP_EL2, NULL, reset_unknown, 0),
 };
 
+__diag_pop();
+
 static bool kvm_supported_tlbi_s12_op(struct kvm_vcpu *vpcu, u32 instr)
 {
 	struct kvm *kvm = vpcu->kvm;
-- 
2.42.0



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

* [PATCH 2/3] KVM: arm64: fix kdoc warnings in W=1 builds
  2024-07-12 11:03 [PATCH 0/3] KVM: arm64: fix warnings in W=1 build Sebastian Ott
  2024-07-12 11:03 ` [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds Sebastian Ott
@ 2024-07-12 11:03 ` Sebastian Ott
  2024-07-12 11:03 ` [PATCH 3/3] KVM: arm64: vgic: fix unexpected unlock sparse warnings Sebastian Ott
  2 siblings, 0 replies; 9+ messages in thread
From: Sebastian Ott @ 2024-07-12 11:03 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Catalin Marinas, Will Deacon, Zenghui Yu

Fix kdoc warnings by adding missing function parameter
descriptions or by conversion to a normal comment.

Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
 arch/arm64/kvm/arm.c             |  1 +
 arch/arm64/kvm/vgic/vgic-irqfd.c |  7 ++++---
 arch/arm64/kvm/vgic/vgic-its.c   | 18 +++++++++++-------
 arch/arm64/kvm/vgic/vgic-v3.c    |  2 +-
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index c818818398a5..2cbc23dd554d 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -164,6 +164,7 @@ static int kvm_arm_default_max_vcpus(void)
 /**
  * kvm_arch_init_vm - initializes a VM data structure
  * @kvm:	pointer to the KVM struct
+ * @type:	kvm device type
  */
 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 {
diff --git a/arch/arm64/kvm/vgic/vgic-irqfd.c b/arch/arm64/kvm/vgic/vgic-irqfd.c
index 8c711deb25aa..c314c016659a 100644
--- a/arch/arm64/kvm/vgic/vgic-irqfd.c
+++ b/arch/arm64/kvm/vgic/vgic-irqfd.c
@@ -9,7 +9,7 @@
 #include <kvm/arm_vgic.h>
 #include "vgic.h"
 
-/**
+/*
  * vgic_irqfd_set_irq: inject the IRQ corresponding to the
  * irqchip routing entry
  *
@@ -75,7 +75,8 @@ static void kvm_populate_msi(struct kvm_kernel_irq_routing_entry *e,
 	msi->flags = e->msi.flags;
 	msi->devid = e->msi.devid;
 }
-/**
+
+/*
  * kvm_set_msi: inject the MSI corresponding to the
  * MSI routing entry
  *
@@ -98,7 +99,7 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
 	return vgic_its_inject_msi(kvm, &msi);
 }
 
-/**
+/*
  * kvm_arch_set_irq_inatomic: fast-path for irqfd injection
  */
 int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 40bb43f20bf3..ba945ba78cc7 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -2040,6 +2040,7 @@ typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *entry,
  * @start_id: the ID of the first entry in the table
  * (non zero for 2d level tables)
  * @fn: function to apply on each entry
+ * @opaque: pointer to opaque data
  *
  * Return: < 0 on error, 0 if last element was identified, 1 otherwise
  * (the last element may not be found on second level tables)
@@ -2079,7 +2080,7 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz,
 	return 1;
 }
 
-/**
+/*
  * vgic_its_save_ite - Save an interrupt translation entry at @gpa
  */
 static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev,
@@ -2099,6 +2100,8 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev,
 
 /**
  * vgic_its_restore_ite - restore an interrupt translation entry
+ *
+ * @its: its handle
  * @event_id: id used for indexing
  * @ptr: pointer to the ITE entry
  * @opaque: pointer to the its_device
@@ -2231,6 +2234,7 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)
  * @its: ITS handle
  * @dev: ITS device
  * @ptr: GPA
+ * @dte_esz: device table entry size
  */
 static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev,
 			     gpa_t ptr, int dte_esz)
@@ -2313,7 +2317,7 @@ static int vgic_its_device_cmp(void *priv, const struct list_head *a,
 		return 1;
 }
 
-/**
+/*
  * vgic_its_save_device_tables - Save the device table and all ITT
  * into guest RAM
  *
@@ -2386,7 +2390,7 @@ static int handle_l1_dte(struct vgic_its *its, u32 id, void *addr,
 	return ret;
 }
 
-/**
+/*
  * vgic_its_restore_device_tables - Restore the device table and all ITT
  * from guest RAM to internal data structs
  */
@@ -2478,7 +2482,7 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
 	return 1;
 }
 
-/**
+/*
  * vgic_its_save_collection_table - Save the collection table into
  * guest RAM
  */
@@ -2518,7 +2522,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its)
 	return ret;
 }
 
-/**
+/*
  * vgic_its_restore_collection_table - reads the collection table
  * in guest memory and restores the ITS internal state. Requires the
  * BASER registers to be restored before.
@@ -2556,7 +2560,7 @@ static int vgic_its_restore_collection_table(struct vgic_its *its)
 	return ret;
 }
 
-/**
+/*
  * vgic_its_save_tables_v0 - Save the ITS tables into guest ARM
  * according to v0 ABI
  */
@@ -2571,7 +2575,7 @@ static int vgic_its_save_tables_v0(struct vgic_its *its)
 	return vgic_its_save_collection_table(its);
 }
 
-/**
+/*
  * vgic_its_restore_tables_v0 - Restore the ITS tables from guest RAM
  * to internal data structs according to V0 ABI
  *
diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c
index ed6e412cd74b..3eecdd2f4b8f 100644
--- a/arch/arm64/kvm/vgic/vgic-v3.c
+++ b/arch/arm64/kvm/vgic/vgic-v3.c
@@ -370,7 +370,7 @@ static void map_all_vpes(struct kvm *kvm)
 						dist->its_vm.vpes[i]->irq));
 }
 
-/**
+/*
  * vgic_v3_save_pending_tables - Save the pending tables into guest RAM
  * kvm lock and all vcpu lock must be held
  */
-- 
2.42.0



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

* [PATCH 3/3] KVM: arm64: vgic: fix unexpected unlock sparse warnings
  2024-07-12 11:03 [PATCH 0/3] KVM: arm64: fix warnings in W=1 build Sebastian Ott
  2024-07-12 11:03 ` [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds Sebastian Ott
  2024-07-12 11:03 ` [PATCH 2/3] KVM: arm64: fix kdoc " Sebastian Ott
@ 2024-07-12 11:03 ` Sebastian Ott
  2 siblings, 0 replies; 9+ messages in thread
From: Sebastian Ott @ 2024-07-12 11:03 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
	Catalin Marinas, Will Deacon, Zenghui Yu

Get rid of unexpected unlock sparse warnings in vgic code
by adding an annotation to vgic_queue_irq_unlock().

arch/arm64/kvm/vgic/vgic.c:334:17: warning: context imbalance in 'vgic_queue_irq_unlock' - unexpected unlock
arch/arm64/kvm/vgic/vgic.c:419:5: warning: context imbalance in 'kvm_vgic_inject_irq' - different lock contexts for basic block

Signed-off-by: Sebastian Ott <sebott@redhat.com>
---
 arch/arm64/kvm/vgic/vgic.c | 2 +-
 arch/arm64/kvm/vgic/vgic.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
index f07b3ddff7d4..974849ea7101 100644
--- a/arch/arm64/kvm/vgic/vgic.c
+++ b/arch/arm64/kvm/vgic/vgic.c
@@ -313,7 +313,7 @@ static bool vgic_validate_injection(struct vgic_irq *irq, bool level, void *owne
  * with all locks dropped.
  */
 bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq,
-			   unsigned long flags)
+			   unsigned long flags) __releases(&irq->irq_lock)
 {
 	struct kvm_vcpu *vcpu;
 
diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h
index 6106ebd5ba42..480b5c7e2031 100644
--- a/arch/arm64/kvm/vgic/vgic.h
+++ b/arch/arm64/kvm/vgic/vgic.h
@@ -186,7 +186,7 @@ bool vgic_get_phys_line_level(struct vgic_irq *irq);
 void vgic_irq_set_phys_pending(struct vgic_irq *irq, bool pending);
 void vgic_irq_set_phys_active(struct vgic_irq *irq, bool active);
 bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq,
-			   unsigned long flags);
+			   unsigned long flags) __releases(&irq->irq_lock);
 void vgic_kick_vcpus(struct kvm *kvm);
 void vgic_irq_handle_resampling(struct vgic_irq *irq,
 				bool lr_deactivated, bool lr_pending);
-- 
2.42.0



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

* Re: [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-12 11:03 ` [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds Sebastian Ott
@ 2024-07-12 21:55   ` Marc Zyngier
  2024-07-15  9:35     ` Mark Rutland
  2024-07-15 10:28     ` Sebastian Ott
  0 siblings, 2 replies; 9+ messages in thread
From: Marc Zyngier @ 2024-07-12 21:55 UTC (permalink / raw)
  To: Sebastian Ott
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, James Morse,
	Suzuki K Poulose, Catalin Marinas, Will Deacon, Zenghui Yu

On Fri, 12 Jul 2024 12:03:30 +0100,
Sebastian Ott <sebott@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@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.


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

* Re: [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-12 21:55   ` Marc Zyngier
@ 2024-07-15  9:35     ` Mark Rutland
  2024-07-15 10:43       ` Sebastian Ott
  2024-07-15 10:28     ` Sebastian Ott
  1 sibling, 1 reply; 9+ messages in thread
From: Mark Rutland @ 2024-07-15  9:35 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Sebastian Ott, linux-arm-kernel, kvmarm, linux-kernel,
	Oliver Upton, James Morse, Suzuki K Poulose, Catalin Marinas,
	Will Deacon, Zenghui Yu

On Fri, Jul 12, 2024 at 10:55:16PM +0100, Marc Zyngier wrote:
> On Fri, 12 Jul 2024 12:03:30 +0100,
> Sebastian Ott <sebott@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@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.

IMO this would be a lot more palatable if this were an attribute on the
struct or assignment, like we asked for in the past:

  https://lore.kernel.org/lkml/20190809083251.GA48423@lakrids.cambridge.arm.com/

Having something that we could put specifically on the default assignment would
make this a lot more legible and better capture the intent.

Mark.


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

* Re: [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-12 21:55   ` Marc Zyngier
  2024-07-15  9:35     ` Mark Rutland
@ 2024-07-15 10:28     ` Sebastian Ott
  2024-07-15 14:40       ` Marc Zyngier
  1 sibling, 1 reply; 9+ messages in thread
From: Sebastian Ott @ 2024-07-15 10:28 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, James Morse,
	Suzuki K Poulose, Catalin Marinas, Will Deacon, Zenghui Yu

On Fri, 12 Jul 2024, Marc Zyngier wrote:
> On Fri, 12 Jul 2024 12:03:30 +0100,
> Sebastian Ott <sebott@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@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 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*.

I'm not claiming that it's an improvement to the code. But yea, I see your
point. How about disabling that flag in the makefile?

Thanks,
Sebastian



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

* Re: [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-15  9:35     ` Mark Rutland
@ 2024-07-15 10:43       ` Sebastian Ott
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastian Ott @ 2024-07-15 10:43 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Marc Zyngier, linux-arm-kernel, kvmarm, linux-kernel,
	Oliver Upton, James Morse, Suzuki K Poulose, Catalin Marinas,
	Will Deacon, Zenghui Yu

On Mon, 15 Jul 2024, Mark Rutland wrote:
> On Fri, Jul 12, 2024 at 10:55:16PM +0100, Marc Zyngier wrote:
>> On Fri, 12 Jul 2024 12:03:30 +0100,
>> Sebastian Ott <sebott@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@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.
>
> IMO this would be a lot more palatable if this were an attribute on the
> struct or assignment, like we asked for in the past:
>
>  https://lore.kernel.org/lkml/20190809083251.GA48423@lakrids.cambridge.arm.com/
>
> Having something that we could put specifically on the default assignment would
> make this a lot more legible and better capture the intent.

Yea, I double checked in the gcc doc - there seems to be no other means to
silence this per var or assignment. We can disable that in the makefile
for the whole file or dir or we keep it as it is.

Thanks,
Sebastian



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

* Re: [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds
  2024-07-15 10:28     ` Sebastian Ott
@ 2024-07-15 14:40       ` Marc Zyngier
  0 siblings, 0 replies; 9+ messages in thread
From: Marc Zyngier @ 2024-07-15 14:40 UTC (permalink / raw)
  To: Sebastian Ott
  Cc: linux-arm-kernel, kvmarm, linux-kernel, Oliver Upton, James Morse,
	Suzuki K Poulose, Catalin Marinas, Will Deacon, Zenghui Yu

On Mon, 15 Jul 2024 11:28:06 +0100,
Sebastian Ott <sebott@redhat.com> wrote:
> 
> On Fri, 12 Jul 2024, Marc Zyngier wrote:
> > On Fri, 12 Jul 2024 12:03:30 +0100,
> > Sebastian Ott <sebott@redhat.com> wrote:
> >> 
> >> -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*.
> 
> I'm not claiming that it's an improvement to the code.

<rant>
Silencing pointless warnings should never have priority over keeping
the code maintainable and understandable. I hope we can agree we are
not in the business of making the kernel *worse* than it already is on
that front, right?
</rant>

I like good tooling as much as the next kernel tinkerer. But W=1 is,
in its current form, quite the opposite. Mark posted a link to a 5
year old thread, showing a number of ways compilers could use extra
annotation to lift the multiple initialisation ambiguity. This
approach has seen no traction, which is a bit sad.

> But yea, I see your point. How about disabling that flag in the
> makefile?

Yes, that'd be a reasonable workaround until someone fixes the
toolchains. I see that Loongarch is already doing it for the exact
same purpose.

Thanks,

	M.

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


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

end of thread, other threads:[~2024-07-15 14:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 11:03 [PATCH 0/3] KVM: arm64: fix warnings in W=1 build Sebastian Ott
2024-07-12 11:03 ` [PATCH 1/3] KVM: arm64: fix override-init warnings in W=1 builds Sebastian Ott
2024-07-12 21:55   ` Marc Zyngier
2024-07-15  9:35     ` Mark Rutland
2024-07-15 10:43       ` Sebastian Ott
2024-07-15 10:28     ` Sebastian Ott
2024-07-15 14:40       ` Marc Zyngier
2024-07-12 11:03 ` [PATCH 2/3] KVM: arm64: fix kdoc " Sebastian Ott
2024-07-12 11:03 ` [PATCH 3/3] KVM: arm64: vgic: fix unexpected unlock sparse warnings Sebastian Ott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).