Skip to contentSkip to conversation

KVM: interrupt kvm_gmem_populate() on signals

PATCH In review Paolo Bonzini 2 participants 2 messages Jun 11, 2024 – Jun 12, 2024

Subsystems (2)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: interrupt kvm_gmem_populate() on signals

kvm_gmem_populate() is a potentially lengthy operation that can involve multiple calls to the firmware. Interrupt it if a signal arrives.

Fixes 1f6c06b177513 ("KVM: guest_memfd: Add interface for populating gmem pages with user data")
Cc Isaku Yamahata <[email protected]>
Cc Michael Roth <[email protected]>
---
 virt/kvm/guest_memfd.c | 5 +++++
 1 file changed, 5 insertions(+)
virt/kvm/guest_memfd.c +5 -0
index 9714add38852..3bfe1824ec2d 100644
@@ -629,6 +629,11 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
 		gfn_t gfn = start_gfn + i;
 		kvm_pfn_t pfn;
 
+		if (signal_pending(current)) {
+			ret = -EINTR;
+			break;
+		}
+
 		ret = __kvm_gmem_get_pfn(file, slot, gfn, &pfn, &max_order, false);
 		if (ret)
 			break;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines · Paolo Bonzini

kvm_gmem_populate() is a potentially lengthy operation that can involve multiple calls to the firmware. Interrupt it if a signal arrives.

What about cond_resched() in the loop? kvm_gmem_allocate() has both.

The change itself looks good for TDX because KVM_TDX_INIT_MEMREGION checks the signal. I can drop the duplicated check. Similar to cond_resched().

Signature · 1 line
Isaku Yamahata <[email protected]>