Skip to contentSkip to conversation

KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE

PATCH Applied Miaohe Lin 3 participants 4 messages Sep 13, 2022 – Oct 22, 2022

Subsystems (3)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE

Use helper macro SPTE_ENT_PER_PAGE to get the number of spte entries per page. Minor readability improvement.

---
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
index 858bc53cfab4..45c532d00f78 100644
@@ -1645,7 +1645,7 @@ static int is_empty_shadow_page(u64 *spt)
 	u64 *pos;
 	u64 *end;
 
-	for (pos = spt, end = pos + PAGE_SIZE / sizeof(u64); pos != end; pos++)
+	for (pos = spt, end = pos + SPTE_ENT_PER_PAGE; pos != end; pos++)
 		if (is_shadow_present_pte(*pos)) {
 			printk(KERN_ERR "%s: %p %llx\n", __func__,
 			       pos, *pos);
Signature · 1 line
2.23.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Miaohe Lin

Use helper macro SPTE_ENT_PER_PAGE to get the number of spte entries per page. Minor readability improvement.

---

arch/x86/kvm/mmu/mmu.c static int is_empty_shadow_page(u64 *spt) · line 1648

Quoted 13 lines
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
index 858bc53cfab4..45c532d00f78 100644
@@ -1645,7 +1645,7 @@ static int is_empty_shadow_page(u64 *spt)
 	u64 *pos;
 	u64 *end;
 
-	for (pos = spt, end = pos + PAGE_SIZE / sizeof(u64); pos != end; pos++)
+	for (pos = spt, end = pos + SPTE_ENT_PER_PAGE; pos != end; pos++)

This is buried under MMU_DEBUG, and turning that on to compile test, which requires manually changing kernel code to enable, results in some minor warnings. Given the existence of CONFIG_KVM_WERROR=y, I think it's safe to say this code hasn't been exercised in a very long time. E.g. this is literally the first time I've actually enabled MMU_DEBUG.

This particular check seems like it would be quite useful, but the pgprintk() and rmap_printk() hooks, not so much. E.g. the knob is too coarse grained, and many of the prints now have tracepoints.

So, unless someone actually actively uses MMU_DEBUG+dbg, I'm inclined to just delete pgprintk() and rmap_printk(), and then rename MMU_WARN_ON => KVM_MMU_WARN_ON and add a Kconfig for that, e.g. CONFIG_KVM_PROVE_MMU.

Hmm, and maybe clean up this helper too, e.g. get rid of the pointer arithmetic, and take the full kvm_mmu_page so that the error message can print out things like the gfn (a host kernel pointer is going to be useless for debug).

Thoughts? Objections?

author
#2 lore raw
Quoted 8 lines · Sean Christopherson
Quoted 5 lines · Miaohe Lin

Use helper macro SPTE_ENT_PER_PAGE to get the number of spte entries per page. Minor readability improvement.

---

Many thanks for your review and comment. And sorry for late respond. A really busy week. :)

Quoted 29 lines
Quoted 9 lines
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +0 -0
index 858bc53cfab4..45c532d00f78 100644

arch/x86/kvm/mmu/mmu.c static int is_empty_shadow_page(u64 *spt) · line 1648

Quoted 5 lines
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -1645,7 +1645,7 @@ static int is_empty_shadow_page(u64 *spt)
 	u64 *pos;
 	u64 *end;
 
-	for (pos = spt, end = pos + PAGE_SIZE / sizeof(u64); pos != end; pos++)
+	for (pos = spt, end = pos + SPTE_ENT_PER_PAGE; pos != end; pos++)

This is buried under MMU_DEBUG, and turning that on to compile test, which requires manually changing kernel code to enable, results in some minor warnings. Given the existence of CONFIG_KVM_WERROR=y, I think it's safe to say this code hasn't been exercised in a very long time. E.g. this is literally the first time I've actually enabled MMU_DEBUG.

This particular check seems like it would be quite useful, but the pgprintk() and rmap_printk() hooks, not so much. E.g. the knob is too coarse grained, and many of the prints now have tracepoints.

So, unless someone actually actively uses MMU_DEBUG+dbg, I'm inclined to just delete pgprintk() and rmap_printk(), and then rename MMU_WARN_ON => KVM_MMU_WARN_ON and add a Kconfig for that, e.g. CONFIG_KVM_PROVE_MMU.

Quoted 5 lines

Hmm, and maybe clean up this helper too, e.g. get rid of the pointer arithmetic, and take the full kvm_mmu_page so that the error message can print out things like the gfn (a host kernel pointer is going to be useless for debug).

Thoughts? Objections?

I tend to agree with you. MMU_DEBUG might even be an obsolete DEBUG component. I believe above changes will improve the current code. Am I supposed to do this or will you kindly do this?

Thanks again,
Miaohe Lin