public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects()
@ 2022-06-14  9:32 Bo Liu
  2022-06-14 15:00 ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Bo Liu @ 2022-06-14  9:32 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel, Bo Liu

The return value type of the function rmap_can_add() is "bool", and it will
returns the result of the function kvm_mmu_memory_cache_nr_free_objects().
So we should change the return value type of
kvm_mmu_memory_cache_nr_free_objects() to "bool".

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 include/linux/kvm_host.h | 2 +-
 virt/kvm/kvm_main.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c20f2d55840c..a399a7485795 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1358,7 +1358,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm);
 
 #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
 int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min);
-int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
+bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
 void kvm_mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc);
 void *kvm_mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc);
 #endif
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a67e996cbf7f..2872569e3580 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -394,9 +394,9 @@ int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min)
 	return 0;
 }
 
-int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)
+bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)
 {
-	return mc->nobjs;
+	return !!mc->nobjs;
 }
 
 void kvm_mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
-- 
2.27.0


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

* Re: [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects()
  2022-06-14  9:32 [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects() Bo Liu
@ 2022-06-14 15:00 ` Sean Christopherson
  2022-06-14 16:31   ` David Matlack
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2022-06-14 15:00 UTC (permalink / raw)
  To: Bo Liu; +Cc: pbonzini, kvm, linux-kernel

On Tue, Jun 14, 2022, Bo Liu wrote:
> The return value type of the function rmap_can_add() is "bool", and it will
> returns the result of the function kvm_mmu_memory_cache_nr_free_objects().
> So we should change the return value type of
> kvm_mmu_memory_cache_nr_free_objects() to "bool".
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  include/linux/kvm_host.h | 2 +-
>  virt/kvm/kvm_main.c      | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index c20f2d55840c..a399a7485795 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1358,7 +1358,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm);
>  
>  #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
>  int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min);
> -int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
> +bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
>  void kvm_mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc);
>  void *kvm_mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc);
>  #endif
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index a67e996cbf7f..2872569e3580 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -394,9 +394,9 @@ int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min)
>  	return 0;
>  }
>  
> -int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)
> +bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)

Absolutely not, the name of the function is "nr_free_objects".  Renaming it to
"has_free_objects" is not a net positive IMO.  If we really care about returning
a bool then we can tweak rmap_can_add().

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 17252f39bd7c..047855d134da 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -1018,7 +1018,7 @@ static bool rmap_can_add(struct kvm_vcpu *vcpu)
        struct kvm_mmu_memory_cache *mc;

        mc = &vcpu->arch.mmu_pte_list_desc_cache;
-       return kvm_mmu_memory_cache_nr_free_objects(mc);
+       return !!kvm_mmu_memory_cache_nr_free_objects(mc);
 }

 static void rmap_remove(struct kvm *kvm, u64 *spte)

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

* Re: [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects()
  2022-06-14 15:00 ` Sean Christopherson
@ 2022-06-14 16:31   ` David Matlack
  2022-06-15  9:56     ` 答复: " Bo Liu (刘波)-浪潮信息
  0 siblings, 1 reply; 4+ messages in thread
From: David Matlack @ 2022-06-14 16:31 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: Bo Liu, Paolo Bonzini, kvm list, LKML

On Tue, Jun 14, 2022 at 8:01 AM Sean Christopherson <seanjc@google.com> wrote:
>
> On Tue, Jun 14, 2022, Bo Liu wrote:
> > The return value type of the function rmap_can_add() is "bool", and it will
> > returns the result of the function kvm_mmu_memory_cache_nr_free_objects().
> > So we should change the return value type of
> > kvm_mmu_memory_cache_nr_free_objects() to "bool".
> >
> > Signed-off-by: Bo Liu <liubo03@inspur.com>
> > ---
> >  include/linux/kvm_host.h | 2 +-
> >  virt/kvm/kvm_main.c      | 4 ++--
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> > index c20f2d55840c..a399a7485795 100644
> > --- a/include/linux/kvm_host.h
> > +++ b/include/linux/kvm_host.h
> > @@ -1358,7 +1358,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm);
> >
> >  #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE
> >  int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min);
> > -int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
> > +bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc);
> >  void kvm_mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc);
> >  void *kvm_mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc);
> >  #endif
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index a67e996cbf7f..2872569e3580 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -394,9 +394,9 @@ int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min)
> >       return 0;
> >  }
> >
> > -int kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)
> > +bool kvm_mmu_memory_cache_nr_free_objects(struct kvm_mmu_memory_cache *mc)
>
> Absolutely not, the name of the function is "nr_free_objects".  Renaming it to
> "has_free_objects" is not a net positive IMO.

Also nested eager page splitting [1] uses
kvm_mmu_memory_cache_nr_free_objects() and needs to know the number of
free objects.

[1] https://lore.kernel.org/all/20220516232138.1783324-23-dmatlack@google.com/

> If we really care about returning
> a bool then we can tweak rmap_can_add().
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 17252f39bd7c..047855d134da 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -1018,7 +1018,7 @@ static bool rmap_can_add(struct kvm_vcpu *vcpu)
>         struct kvm_mmu_memory_cache *mc;
>
>         mc = &vcpu->arch.mmu_pte_list_desc_cache;
> -       return kvm_mmu_memory_cache_nr_free_objects(mc);
> +       return !!kvm_mmu_memory_cache_nr_free_objects(mc);
>  }
>
>  static void rmap_remove(struct kvm *kvm, u64 *spte)

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

* 答复: [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects()
  2022-06-14 16:31   ` David Matlack
@ 2022-06-15  9:56     ` Bo Liu (刘波)-浪潮信息
  0 siblings, 0 replies; 4+ messages in thread
From: Bo Liu (刘波)-浪潮信息 @ 2022-06-15  9:56 UTC (permalink / raw)
  To: dmatlack@google.com
  Cc: pbonzini@redhat.com, kvm@vger.kernel.org,
	inux-kernel@vger.kernel.org

[-- Attachment #1: smime.p7m --]
[-- Type: application/pkcs7-mime, Size: 6713 bytes --]

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

end of thread, other threads:[~2022-06-15  9:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14  9:32 [PATCH] KVM: Use consistent type for return value of kvm_mmu_memory_cache_nr_free_objects() Bo Liu
2022-06-14 15:00 ` Sean Christopherson
2022-06-14 16:31   ` David Matlack
2022-06-15  9:56     ` 答复: " Bo Liu (刘波)-浪潮信息

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox