Skip to contentSkip to conversation

KVM: Forbid the use of tagged userspace addresses for memslots

PATCH In review Marc Zyngier 3 participants 3 messages Feb 1, 2021

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

PATCH 1/1 KVM: Forbid the use of tagged userspace addresses for memslots

commit 139bc8a6146d92822c866cf2fd410159c56b3648 upstream.

The use of a tagged address could be pretty confusing for the whole memslot infrastructure as well as the MMU notifiers.

Forbid it altogether, as it never quite worked the first place.

---
 Documentation/virt/kvm/api.txt | 3 +++
 virt/kvm/kvm_main.c            | 1 +
 2 files changed, 4 insertions(+)
Documentation/virt/kvm/api.txt +3 -0
index a18e996fa54b..7064efd3b5ea 100644
@@ -1132,6 +1132,9 @@ field userspace_addr, which must point at user addressable memory for
 the entire memory slot size.  Any object may back this memory, including
 anonymous memory, ordinary files, and hugetlbfs.
 
+On architectures that support a form of address tagging, userspace_addr must
+be an untagged address.
+
 It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
 be identical.  This allows large pages in the guest to be backed by large
 pages in the host.
virt/kvm/kvm_main.c +1 -0
index 8f3b40ec02b7..f25b5043cbca 100644
@@ -1017,6 +1017,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 	/* We can read the guest memory with __xxx_user() later on. */
 	if ((id < KVM_USER_MEM_SLOTS) &&
 	    ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
+	     (mem->userspace_addr != untagged_addr(mem->userspace_addr)) ||
 	     !access_ok((void __user *)(unsigned long)mem->userspace_addr,
 			mem->memory_size)))
 		goto out;
Signature · 1 line
2.29.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 36 lines · Marc Zyngier

commit 139bc8a6146d92822c866cf2fd410159c56b3648 upstream.

The use of a tagged address could be pretty confusing for the whole memslot infrastructure as well as the MMU notifiers.

Forbid it altogether, as it never quite worked the first place.

---
  Documentation/virt/kvm/api.txt | 3 +++
  virt/kvm/kvm_main.c            | 1 +
  2 files changed, 4 insertions(+)
Documentation/virt/kvm/api.txt +3 -0
index a18e996fa54b..7064efd3b5ea 100644
@@ -1132,6 +1132,9 @@ field userspace_addr, which must point at user addressable memory for
  the entire memory slot size.  Any object may back this memory, including
  anonymous memory, ordinary files, and hugetlbfs.
 
+On architectures that support a form of address tagging, userspace_addr must
+be an untagged address.
+
  It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
  be identical.  This allows large pages in the guest to be backed by large
  pages in the host.
virt/kvm/kvm_main.c +0 -0
index 8f3b40ec02b7..f25b5043cbca 100644

virt/kvm/kvm_main.c int __kvm_set_memory_region(struct kvm *kvm, · line 1023

Quoted 7 lines
virt/kvm/kvm_main.c +1 -0
@@ -1017,6 +1017,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
  	/* We can read the guest memory with __xxx_user() later on. */
  	if ((id < KVM_USER_MEM_SLOTS) &&
  	    ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
+	     (mem->userspace_addr != untagged_addr(mem->userspace_addr)) ||
  	     !access_ok((void __user *)(unsigned long)mem->userspace_addr,
  			mem->memory_size)))
  		goto out;

Indeed untagged_addr was added in 5.3.

Paolo

maintainer
#2 lore raw
Quoted 46 lines · Paolo Bonzini
Quoted 35 lines · Marc Zyngier

commit 139bc8a6146d92822c866cf2fd410159c56b3648 upstream.

The use of a tagged address could be pretty confusing for the whole memslot infrastructure as well as the MMU notifiers.

Forbid it altogether, as it never quite worked the first place.

---
  Documentation/virt/kvm/api.txt | 3 +++
  virt/kvm/kvm_main.c            | 1 +
  2 files changed, 4 insertions(+)
Documentation/virt/kvm/api.txt +3 -0
index a18e996fa54b..7064efd3b5ea 100644
@@ -1132,6 +1132,9 @@ field userspace_addr, which must point at user addressable memory for
  the entire memory slot size.  Any object may back this memory, including
  anonymous memory, ordinary files, and hugetlbfs.
+On architectures that support a form of address tagging, userspace_addr must
+be an untagged address.
+
  It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
  be identical.  This allows large pages in the guest to be backed by large
  pages in the host.
virt/kvm/kvm_main.c +0 -0
index 8f3b40ec02b7..f25b5043cbca 100644

virt/kvm/kvm_main.c int __kvm_set_memory_region(struct kvm *kvm, · line 1023

Quoted 7 lines
virt/kvm/kvm_main.c +1 -0
@@ -1017,6 +1017,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
  	/* We can read the guest memory with __xxx_user() later on. */
  	if ((id < KVM_USER_MEM_SLOTS) &&
  	    ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
+	     (mem->userspace_addr != untagged_addr(mem->userspace_addr)) ||
  	     !access_ok((void __user *)(unsigned long)mem->userspace_addr,
  			mem->memory_size)))
  		goto out;

Indeed untagged_addr was added in 5.3.

Quoted 1 line

Now queued up, thanks.

greg k-h