[PATCH v4 2/4] kvm: Add KVM_PFN_ERR_SIGPENDING

Peter Xu posted 4 patches 3 years, 5 months ago
[PATCH v4 2/4] kvm: Add KVM_PFN_ERR_SIGPENDING
Posted by Peter Xu 3 years, 5 months ago
Add a new pfn error to show that we've got a pending signal to handle
during hva_to_pfn_slow() procedure (of -EINTR retval).

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/linux/kvm_host.h | 10 ++++++++++
 virt/kvm/kvm_main.c      |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 32f259fa5801..92baa930b891 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -96,6 +96,7 @@
 #define KVM_PFN_ERR_FAULT	(KVM_PFN_ERR_MASK)
 #define KVM_PFN_ERR_HWPOISON	(KVM_PFN_ERR_MASK + 1)
 #define KVM_PFN_ERR_RO_FAULT	(KVM_PFN_ERR_MASK + 2)
+#define KVM_PFN_ERR_SIGPENDING	(KVM_PFN_ERR_MASK + 3)
 
 /*
  * error pfns indicate that the gfn is in slot but faild to
@@ -106,6 +107,15 @@ static inline bool is_error_pfn(kvm_pfn_t pfn)
 	return !!(pfn & KVM_PFN_ERR_MASK);
 }
 
+/*
+ * KVM_PFN_ERR_SIGPENDING indicates that fetching the PFN was interrupted
+ * by a pending signal.  Note, the signal may or may not be fatal.
+ */
+static inline bool is_sigpending_pfn(kvm_pfn_t pfn)
+{
+	return pfn == KVM_PFN_ERR_SIGPENDING;
+}
+
 /*
  * error_noslot pfns indicate that the gfn can not be
  * translated to pfn - it is not in slot or failed to
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e30f1b4ecfa5..e20a59dcda32 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2667,6 +2667,8 @@ kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
 	npages = hva_to_pfn_slow(addr, async, write_fault, writable, &pfn);
 	if (npages == 1)
 		return pfn;
+	if (npages == -EINTR)
+		return KVM_PFN_ERR_SIGPENDING;
 
 	mmap_read_lock(current->mm);
 	if (npages == -EHWPOISON ||
-- 
2.37.3
Re: [PATCH v4 2/4] kvm: Add KVM_PFN_ERR_SIGPENDING
Posted by Sean Christopherson 3 years, 5 months ago
Uber nit, s/kvm/KVM for the shortlog,

On Tue, Oct 11, 2022, Peter Xu wrote:
> Add a new pfn error to show that we've got a pending signal to handle

Please avoid pronouns in changelogs and comments, they're unnecessarily ambiguous.
E.g. 

  Add a new pfn error to capture that hva_to_pfn_slow() failed due to a
  pending signal.  The new error will be used in future patches to
  propagate -EINTR back to userspace instead of returning -EFAULT.
 

> during hva_to_pfn_slow() procedure (of -EINTR retval).
> 
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---

Nits aside,

Reviewed-by: Sean Christopherson <seanjc@google.com>