Skip to contentSkip to conversation

KVM: x86/tdp_mmu: Fix redundant u16 compared to 0

PATCH-next NAK Advait Dhamorikar 2 participants 3 messages Nov 11, 2024 – Nov 12, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

---
 arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
index 4508d868f1cd..b4e7b6a264d6 100644
@@ -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)	\
Signature · 1 line
2.34.1
maintainer NAK
#1 lore raw
Quoted 3 lines · 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.

Please wrap changelogs at ~75 characters.

Quoted 10 lines
---
 arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/tdp_mmu.c +0 -0
index 4508d868f1cd..b4e7b6a264d6 100644

arch/x86/kvm/mmu/tdp_mmu.c static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, · line 156

Quoted 5 lines
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
@@ -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.

#2 lore raw

Hello Sean,

Quoted 8 lines

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

Quoted 31 lines · Sean Christopherson
Quoted 3 lines · 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.

Please wrap changelogs at ~75 characters.

Quoted 10 lines
---
 arch/x86/kvm/mmu/tdp_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/tdp_mmu.c +0 -0
index 4508d868f1cd..b4e7b6a264d6 100644

arch/x86/kvm/mmu/tdp_mmu.c static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, · line 156

Quoted 5 lines
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
@@ -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.