Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH] KVM: Fix kvm_range_has_memory_attributes() for a zero mask
@ 2026-12-01  1:21 liuqiangneo
  2026-12-01  1:29 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: liuqiangneo @ 2026-12-01  1:21 UTC (permalink / raw)
  To: pbonzini, seanjc, liuyun; +Cc: zengchi, kvm, Qiang Liu

From: Qiang Liu <liuqiang@kylinos.cn>

When asked whether a range has no attributes (attrs == 0), the loop uses
xas_next_entry(), which skips holes and may land past the current index.
Only perform the index check for attrs != 0, where it guards against a
missing entry.

No current caller passes a zero mask: both pass ~0.  This is a latent API
bug; fix it so the helper behaves consistently for all mask values.

Fixes: 277d3623d99a ("KVM: Don't treat reserved xarray entries as having memory attributes")
Signed-off-by: Qiang Liu <liuqiang@kylinos.cn>
---
 virt/kvm/kvm_main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3746682b1a72..1d55c4ee4835 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2548,7 +2548,13 @@ bool kvm_range_has_vm_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end,
 
 		WARN_ON_ONCE(!xa_to_value(entry));
 
-		if (xas.xa_index != index ||
+		/*
+		 * With @attrs == 0, xas_next_entry() can land past @index.
+		 * Skipped holes and reserved entries match; only real entries
+		 * with bits in @mask set are rejected. Checking index wrongly
+		 * rejects holes when @mask is 0.
+		 */
+		if ((attrs && xas.xa_index != index) ||
 		    (xa_to_value(entry) & mask) != attrs)
 			return false;
 	}
-- 
2.43.0


No virus found
		Checked by Hillstone Network AntiVirus


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

end of thread, other threads:[~2026-12-01  1:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  1:21 [PATCH] KVM: Fix kvm_range_has_memory_attributes() for a zero mask liuqiangneo
2026-12-01  1:29 ` sashiko-bot

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