mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: interrupt kvm_gmem_populate() on signals
@ 2024-06-11 10:22 Paolo Bonzini
  2024-06-12 23:13 ` Isaku Yamahata
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2024-06-11 10:22 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: Isaku Yamahata, Michael Roth

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 <isaku.yamahata@intel.com>
Cc: Michael Roth <michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 virt/kvm/guest_memfd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 9714add38852..3bfe1824ec2d 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -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;
-- 
2.43.0


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

* Re: [PATCH] KVM: interrupt kvm_gmem_populate() on signals
  2024-06-11 10:22 [PATCH] KVM: interrupt kvm_gmem_populate() on signals Paolo Bonzini
@ 2024-06-12 23:13 ` Isaku Yamahata
  0 siblings, 0 replies; 2+ messages in thread
From: Isaku Yamahata @ 2024-06-12 23:13 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: linux-kernel, kvm, Isaku Yamahata, Michael Roth, isaku.yamahata

On Tue, Jun 11, 2024 at 06:22:43AM -0400,
Paolo Bonzini <pbonzini@redhat.com> wrote:

> 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().
-- 
Isaku Yamahata <isaku.yamahata@intel.com>

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

end of thread, other threads:[~2024-06-12 23:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11 10:22 [PATCH] KVM: interrupt kvm_gmem_populate() on signals Paolo Bonzini
2024-06-12 23:13 ` Isaku Yamahata

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

all inboxes | Powered by JetHome®