All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE
@ 2022-09-13  8:54 Miaohe Lin
  2022-10-05 23:17 ` Sean Christopherson
  2022-10-22  8:43 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Miaohe Lin @ 2022-09-13  8:54 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen
  Cc: x86, hpa, kvm, linux-kernel, linmiaohe

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

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/mmu/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 858bc53cfab4..45c532d00f78 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -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);
-- 
2.23.0


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

* Re: [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE
  2022-09-13  8:54 [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE Miaohe Lin
@ 2022-10-05 23:17 ` Sean Christopherson
  2022-10-15  2:39   ` Miaohe Lin
  2022-10-22  8:43 ` Paolo Bonzini
  1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2022-10-05 23:17 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm, linux-kernel

On Tue, Sep 13, 2022, Miaohe Lin wrote:
> Use helper macro SPTE_ENT_PER_PAGE to get the number of spte entries
> per page. Minor readability improvement.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>

>  arch/x86/kvm/mmu/mmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 858bc53cfab4..45c532d00f78 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -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?

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

* Re: [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE
  2022-10-05 23:17 ` Sean Christopherson
@ 2022-10-15  2:39   ` Miaohe Lin
  0 siblings, 0 replies; 4+ messages in thread
From: Miaohe Lin @ 2022-10-15  2:39 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm, linux-kernel

On 2022/10/6 7:17, Sean Christopherson wrote:
> On Tue, Sep 13, 2022, Miaohe Lin wrote:
>> Use helper macro SPTE_ENT_PER_PAGE to get the number of spte entries
>> per page. Minor readability improvement.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>

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

> 
>>  arch/x86/kvm/mmu/mmu.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
>> index 858bc53cfab4..45c532d00f78 100644
>> --- a/arch/x86/kvm/mmu/mmu.c
>> +++ b/arch/x86/kvm/mmu/mmu.c
>> @@ -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?

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



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

* Re: [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE
  2022-09-13  8:54 [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE Miaohe Lin
  2022-10-05 23:17 ` Sean Christopherson
@ 2022-10-22  8:43 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2022-10-22  8:43 UTC (permalink / raw)
  To: Miaohe Lin
  Cc: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel

Queued, thanks.

Paolo



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

end of thread, other threads:[~2022-10-22 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13  8:54 [PATCH] KVM: x86/mmu: use helper macro SPTE_ENT_PER_PAGE Miaohe Lin
2022-10-05 23:17 ` Sean Christopherson
2022-10-15  2:39   ` Miaohe Lin
2022-10-22  8:43 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.