lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231202091812.13830-1-yan.y.zhao@intel.com>
Date:   Sat,  2 Dec 2023 17:18:12 +0800
From:   Yan Zhao <yan.y.zhao@...el.com>
To:     iommu@...ts.linux.dev, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Cc:     alex.williamson@...hat.com, jgg@...dia.com, pbonzini@...hat.com,
        seanjc@...gle.com, joro@...tes.org, will@...nel.org,
        robin.murphy@....com, kevin.tian@...el.com,
        baolu.lu@...ux.intel.com, dwmw2@...radead.org, yi.l.liu@...el.com,
        Yan Zhao <yan.y.zhao@...el.com>
Subject: [RFC PATCH 07/42] KVM: Forward page fault requests to arch specific code for exported TDP

Implement .fault op of KVM TDP FD object and pass page fault requests from
importers of KVM TDP FD to KVM arch specific code.

Since the thread for importers to call .fault op is not vCPU thread and
could be a kernel thread, thread "mm" is checked and kthread_use_mm() are
called when necessary.

Signed-off-by: Yan Zhao <yan.y.zhao@...el.com>
---
 include/linux/kvm_host.h |  9 +++++++++
 virt/kvm/tdp_fd.c        | 28 +++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index f73d32eef8833..b76919eec9b72 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2346,6 +2346,8 @@ struct kvm_exported_tdp {
 #ifdef __KVM_HAVE_ARCH_EXPORTED_TDP
 int kvm_arch_exported_tdp_init(struct kvm *kvm, struct kvm_exported_tdp *tdp);
 void kvm_arch_exported_tdp_destroy(struct kvm_exported_tdp *tdp);
+int kvm_arch_fault_exported_tdp(struct kvm_exported_tdp *tdp, unsigned long gfn,
+				struct kvm_tdp_fault_type type);
 #else
 static inline int kvm_arch_exported_tdp_init(struct kvm *kvm,
 					     struct kvm_exported_tdp *tdp)
@@ -2355,6 +2357,13 @@ static inline int kvm_arch_exported_tdp_init(struct kvm *kvm,
 static inline void kvm_arch_exported_tdp_destroy(struct kvm_exported_tdp *tdp)
 {
 }
+
+static inline int kvm_arch_fault_exported_tdp(struct kvm_exported_tdp *tdp,
+					      unsigned long gfn,
+					      struct kvm_tdp_fault_type type)
+{
+	return -EOPNOTSUPP;
+}
 #endif /* __KVM_HAVE_ARCH_EXPORTED_TDP */
 
 #endif /* CONFIG_HAVE_KVM_EXPORTED_TDP */
diff --git a/virt/kvm/tdp_fd.c b/virt/kvm/tdp_fd.c
index 3271da1a4b2c1..02c9066391ebe 100644
--- a/virt/kvm/tdp_fd.c
+++ b/virt/kvm/tdp_fd.c
@@ -223,7 +223,33 @@ static void *kvm_tdp_get_metadata(struct kvm_tdp_fd *tdp_fd)
 static int kvm_tdp_fault(struct kvm_tdp_fd *tdp_fd, struct mm_struct *mm,
 			 unsigned long gfn, struct kvm_tdp_fault_type type)
 {
-	return -EOPNOTSUPP;
+	bool kthread = current->mm == NULL;
+	int ret = -EINVAL;
+
+	if (!tdp_fd || !tdp_fd->priv || !tdp_fd->priv->kvm)
+		return -EINVAL;
+
+	if (!type.read && !type.write && !type.exec)
+		return -EINVAL;
+
+	if (!mm || tdp_fd->priv->kvm->mm != mm)
+		return -EINVAL;
+
+	if (!mmget_not_zero(mm))
+		return -EPERM;
+
+	if (kthread)
+		kthread_use_mm(mm);
+	else if (current->mm != mm)
+		goto out;
+
+	ret = kvm_arch_fault_exported_tdp(tdp_fd->priv, gfn, type);
+
+	if (kthread)
+		kthread_unuse_mm(mm);
+out:
+	mmput(mm);
+	return ret;
 }
 
 static const struct kvm_exported_tdp_ops exported_tdp_ops = {
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ