Skip to contentSkip to conversation

KVM: PPC: e500: Fix build error due to crappy KVM code

PATCH Applied Sean Christopherson 3 participants 6 messages Mar 3 – Mar 6

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

cover KVM: PPC: e500: Fix build error due to crappy KVM code

Fix an e500 build error that was introduced by the recent kmalloc_obj() conversion, but in reality is due to crappy KVM code that has existed for ~13 years.

I'm taking this through kvm-x86 fixes, because it's breaking my testing setup, and obviously no one cares about KVM e500 since PPC_WERROR is default 'y' and needs to be explicitly disabled via PPC_DISABLE_WERROR.

Sean Christopherson (2):
KVM: PPC: e500: Fix build error due to using kmalloc_obj() with wrong
type
KVM: PPC: e500: Rip out "struct tlbe_ref"

 arch/powerpc/kvm/e500.h          |  6 +--
 arch/powerpc/kvm/e500_mmu.c      |  4 +-
 arch/powerpc/kvm/e500_mmu_host.c | 91 +++++++++++++++-----------------
 3 files changed, 47 insertions(+), 54 deletions(-)

base-commit: 11439c4635edd669ae435eec308f4ab8a0804808

Signature · 1 line
2.53.0.473.g4a7958ca14-goog
author reviewer
#1 lore raw

PATCH 1/2 KVM: PPC: e500: Fix build error due to using kmalloc_obj() with wrong type

Fix a build error in kvmppc_e500_tlb_init() that was introduced by the conversion to use kzalloc_objs(), as KVM confusingly uses the size of the structure that is one and only field in tlbe_priv:

arch/powerpc/kvm/e500_mmu.c:923:33: error: assignment to 'struct tlbe_priv *'
from incompatible pointer type 'struct tlbe_ref *' [-Wincompatible-pointer-types]
923 | vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
| ^

KVM has been flawed since commit 0164c0f0c404 ("KVM: PPC: e500: clear up confusion between host and guest entries"), but the issue went unnoticed until kmalloc_obj() came along and enforced types, as "struct tlbe_priv" was just a wrapper of "struct tlbe_ref" (why on earth the two ever existed separately...).

Fixes 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Cc Kees Cook <[email protected]>
---
 arch/powerpc/kvm/e500_mmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/e500_mmu.c +2 -2
index 48580c85f23b..75ed1496ead5 100644
@@ -920,12 +920,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_offset[0] = 0;
 	vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
 
-	vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
+	vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_priv,
 					       vcpu_e500->gtlb_params[0].entries);
 	if (!vcpu_e500->gtlb_priv[0])
 		goto free_vcpu;
 
-	vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref,
+	vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_priv,
 					       vcpu_e500->gtlb_params[1].entries);
 	if (!vcpu_e500->gtlb_priv[1])
 		goto free_vcpu;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] KVM: PPC: e500: Fix build error due to using kmalloc_obj() with wrong type

Le 03/03/2026 à 20:03, Sean Christopherson a écrit :

Quoted 15 lines

Fix a build error in kvmppc_e500_tlb_init() that was introduced by the conversion to use kzalloc_objs(), as KVM confusingly uses the size of the structure that is one and only field in tlbe_priv:

   arch/powerpc/kvm/e500_mmu.c:923:33: error: assignment to 'struct tlbe_priv *'
     from incompatible pointer type 'struct tlbe_ref *' [-Wincompatible-pointer-types]
   923 |         vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
       |                                 ^

KVM has been flawed since commit 0164c0f0c404 ("KVM: PPC: e500: clear up confusion between host and guest entries"), but the issue went unnoticed until kmalloc_obj() came along and enforced types, as "struct tlbe_priv" was just a wrapper of "struct tlbe_ref" (why on earth the two ever existed separately...).

Quoted 3 lines
Fixes 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Cc Kees Cook <[email protected]>
Quoted 23 lines
---
  arch/powerpc/kvm/e500_mmu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/e500_mmu.c +2 -2
index 48580c85f23b..75ed1496ead5 100644
@@ -920,12 +920,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
  	vcpu_e500->gtlb_offset[0] = 0;
  	vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
 
-	vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
+	vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_priv,
  					       vcpu_e500->gtlb_params[0].entries);
  	if (!vcpu_e500->gtlb_priv[0])
  		goto free_vcpu;
 
-	vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref,
+	vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_priv,
  					       vcpu_e500->gtlb_params[1].entries);
  	if (!vcpu_e500->gtlb_priv[1])
  		goto free_vcpu;
author reviewer
#3 lore raw

PATCH 2/2 KVM: PPC: e500: Rip out "struct tlbe_ref"

In reply to Sean Christopherson

Complete the ~13 year journey started by commit 47bf379742bf ("kvm/ppc/e500: eliminate tlb_refs"), and actually remove "struct tlbe_ref".

No functional change intended (verified disassembly of e500_mmu.o and e500_mmu_host.o is identical before and after).

---
 arch/powerpc/kvm/e500.h          |  6 +--
 arch/powerpc/kvm/e500_mmu_host.c | 91 +++++++++++++++-----------------
 2 files changed, 45 insertions(+), 52 deletions(-)
arch/powerpc/kvm/e500.h +1 -5
index f9acf866c709..e4469ad73a2e 100644
@@ -39,15 +39,11 @@ enum vcpu_ftr {
 /* bits [6-5] MAS2_X1 and MAS2_X0 and [4-0] bits for WIMGE */
 #define E500_TLB_MAS2_ATTR	(0x7f)
 
-struct tlbe_ref {
+struct tlbe_priv {
 	kvm_pfn_t pfn;		/* valid only for TLB0, except briefly */
 	unsigned int flags;	/* E500_TLB_* */
 };
 
-struct tlbe_priv {
-	struct tlbe_ref ref;
-};
-
 #ifdef CONFIG_KVM_E500V2
 struct vcpu_id_table;
 #endif
arch/powerpc/kvm/e500_mmu_host.c +44 -47

228 lines not on this page · raw message

Signature · 1 line
2.53.0.473.g4a7958ca14-goog
author reviewer Applied
#4 lore raw
In reply to Sean Christopherson
Quoted 9 lines · Sean Christopherson

Fix an e500 build error that was introduced by the recent kmalloc_obj() conversion, but in reality is due to crappy KVM code that has existed for ~13 years.

I'm taking this through kvm-x86 fixes, because it's breaking my testing setup, and obviously no one cares about KVM e500 since PPC_WERROR is default 'y' and needs to be explicitly disabled via PPC_DISABLE_WERROR.

[...]

Applied to kvm-x86 fixes, thanks!

[1/2] KVM: PPC: e500: Fix build error due to using kmalloc_obj() with wrong type

      https://github.com/kvm-x86/linux/commit/a223ccf0af6e
[2/2] KVM: PPC: e500: Rip out "struct tlbe_ref"
      https://github.com/kvm-x86/linux/commit/3271085a7f10

--
https://github.com/kvm-x86/linux/tree/next

#5 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Sean Christopherson

Fix an e500 build error that was introduced by the recent kmalloc_obj() conversion, but in reality is due to crappy KVM code that has existed for ~13 years.

I'm taking this through kvm-x86 fixes, because it's breaking my testing setup, and obviously no one cares about KVM e500 since PPC_WERROR is default 'y' and needs to be explicitly disabled via PPC_DISABLE_WERROR.

Quoted 7 lines
Quoted 1 line

[...]

Applied to kvm-x86 fixes, thanks!

[1/2] KVM: PPC: e500: Fix build error due to using kmalloc_obj() with wrong type

       https://github.com/kvm-x86/linux/commit/a223ccf0af6e
[2/2] KVM: PPC: e500: Rip out "struct tlbe_ref"
       https://github.com/kvm-x86/linux/commit/3271085a7f10

I added this to my fixes-test, will pull it since you are taking it.

Maddy

Quoted 2 lines

--
https://github.com/kvm-x86/linux/tree/next