public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH-next] KVM: x86/tdp_mmu: Fix redundant u16 compared to 0
@ 2024-11-11 18:39 Advait Dhamorikar
  2024-11-11 18:55 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Advait Dhamorikar @ 2024-11-11 18:39 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, hpa
  Cc: kvm, linux-kernel, skhan, anupnewsmail, Advait Dhamorikar

An unsigned value can never be negative,
so this test will always evaluate the same way.
`_as_id` a u16 is compared to 0.

Signed-off-by: Advait Dhamorikar <advaitdhamorikar@gmail.com>
---
 arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index 4508d868f1cd..b4e7b6a264d6 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -153,7 +153,7 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm,
 	for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid);		\
 	     ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root;		\
 	     _root = tdp_mmu_next_root(_kvm, _root, _only_valid))		\
-		if (_as_id >= 0 && kvm_mmu_page_as_id(_root) != _as_id) {	\
+		if (kvm_mmu_page_as_id(_root) != _as_id) {	\
 		} else
 
 #define for_each_valid_tdp_mmu_root_yield_safe(_kvm, _root, _as_id)	\
-- 
2.34.1


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

* Re: [PATCH-next] KVM: x86/tdp_mmu: Fix redundant u16 compared to 0
  2024-11-11 18:39 [PATCH-next] KVM: x86/tdp_mmu: Fix redundant u16 compared to 0 Advait Dhamorikar
@ 2024-11-11 18:55 ` Sean Christopherson
  2024-11-12  4:17   ` Advait Dhamorikar
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2024-11-11 18:55 UTC (permalink / raw)
  To: Advait Dhamorikar
  Cc: Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, hpa, kvm, linux-kernel, skhan, anupnewsmail

On Tue, Nov 12, 2024, Advait Dhamorikar wrote:
> An unsigned value can never be negative,
> so this test will always evaluate the same way.
> `_as_id` a u16 is compared to 0.

Please wrap changelogs at ~75 characters.

> Signed-off-by: Advait Dhamorikar <advaitdhamorikar@gmail.com>
> ---
>  arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 4508d868f1cd..b4e7b6a264d6 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -153,7 +153,7 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm,
>  	for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid);		\
>  	     ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root;		\
>  	     _root = tdp_mmu_next_root(_kvm, _root, _only_valid))		\
> -		if (_as_id >= 0 && kvm_mmu_page_as_id(_root) != _as_id) {	\
> +		if (kvm_mmu_page_as_id(_root) != _as_id) {	\

NAK, the comparison is necessary as kvm_tdp_mmu_zap_leafs() deliberately invokes
for_each_valid_tdp_mmu_root_yield_safe() => __for_each_tdp_mmu_root_yield_safe()
with -1 to iterate over all address spaces.

And I don't want to drop the check for __for_each_tdp_mmu_root(), even though
there aren't any _current_ users that pass -1, as I want to keep the iterators
symmetrical.

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

* Re: [PATCH-next] KVM: x86/tdp_mmu: Fix redundant u16 compared to 0
  2024-11-11 18:55 ` Sean Christopherson
@ 2024-11-12  4:17   ` Advait Dhamorikar
  0 siblings, 0 replies; 3+ messages in thread
From: Advait Dhamorikar @ 2024-11-12  4:17 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, hpa, kvm, linux-kernel, skhan, anupnewsmail

Hello Sean,

> NAK, the comparison is necessary as kvm_tdp_mmu_zap_leafs() deliberately invokes
> for_each_valid_tdp_mmu_root_yi
> eld_safe() => __for_each_tdp_mmu_root_yield_safe()
>with -1 to iterate over all address spaces.

> And I don't want to drop the check for __for_each_tdp_mmu_root(), even though
> there aren't any _current_ users that pass -1, as I want to keep the iterators
> symmetrical.

Understood, thanks for the feedback.

Best regards,
Advait

On Tue, 12 Nov 2024 at 00:26, Sean Christopherson <seanjc@google.com> wrote:
>
> On Tue, Nov 12, 2024, Advait Dhamorikar wrote:
> > An unsigned value can never be negative,
> > so this test will always evaluate the same way.
> > `_as_id` a u16 is compared to 0.
>
> Please wrap changelogs at ~75 characters.
>
> > Signed-off-by: Advait Dhamorikar <advaitdhamorikar@gmail.com>
> > ---
> >  arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> > index 4508d868f1cd..b4e7b6a264d6 100644
> > --- a/arch/x86/kvm/mmu/tdp_mmu.c
> > +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> > @@ -153,7 +153,7 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm,
> >       for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid);                \
> >            ({ lockdep_assert_held(&(_kvm)->mmu_lock); }), _root;              \
> >            _root = tdp_mmu_next_root(_kvm, _root, _only_valid))               \
> > -             if (_as_id >= 0 && kvm_mmu_page_as_id(_root) != _as_id) {       \
> > +             if (kvm_mmu_page_as_id(_root) != _as_id) {      \
>
> NAK, the comparison is necessary as kvm_tdp_mmu_zap_leafs() deliberately invokes
> for_each_valid_tdp_mmu_root_yield_safe() => __for_each_tdp_mmu_root_yield_safe()
> with -1 to iterate over all address spaces.
>
> And I don't want to drop the check for __for_each_tdp_mmu_root(), even though
> there aren't any _current_ users that pass -1, as I want to keep the iterators
> symmetrical.

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

end of thread, other threads:[~2024-11-12  4:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-11 18:39 [PATCH-next] KVM: x86/tdp_mmu: Fix redundant u16 compared to 0 Advait Dhamorikar
2024-11-11 18:55 ` Sean Christopherson
2024-11-12  4:17   ` Advait Dhamorikar

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