Introduce VM ioctl KVM_CREATE_TDP_FD to create KVM TDP FD object, which
will act as an interface of KVM to export TDP page tables and communicate
with external components of KVM.
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
include/uapi/linux/kvm.h | 19 +++++++++++++++++++
virt/kvm/kvm_main.c | 19 +++++++++++++++++++
virt/kvm/tdp_fd.h | 10 ++++++++++
3 files changed, 48 insertions(+)
create mode 100644 virt/kvm/tdp_fd.h
@@ -1582,6 +1582,9 @@ struct kvm_s390_ucas_mapping {
#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr)
#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)
+/* ioctl for vm fd to create tdp fd */
+#define KVM_CREATE_TDP_FD _IOWR(KVMIO, 0xe4, struct kvm_create_tdp_fd)
+
/*
* ioctls for vcpu fds
*/
@@ -2267,4 +2270,20 @@ struct kvm_s390_zpci_op {
/* flags for kvm_s390_zpci_op->u.reg_aen.flags */
#define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0)
+/**
+ * struct kvm_create_tdp_fd - VM ioctl(KVM_CREATE_TDP_FD)
+ * Create a TDP fd object for a TDP exported by KVM.
+ *
+ * @as_id: in: Address space ID for this TDP.
+ * @mode: in: Mode of this tdp.
+ * Reserved for future usage. Currently, this field must be 0.
+ * @fd: out: fd of TDP fd object for a TDP exported by KVM.
+ * @pad: in: Reserved as 0.
+ */
+struct kvm_create_tdp_fd {
+ __u32 as_id;
+ __u32 mode;
+ __u32 fd;
+ __u32 pad;
+};
#endif /* __LINUX_KVM_H */
@@ -61,6 +61,7 @@
#include "async_pf.h"
#include "kvm_mm.h"
#include "vfio.h"
+#include "tdp_fd.h"
#include <trace/events/ipi.h>
@@ -4973,6 +4974,24 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_GET_STATS_FD:
r = kvm_vm_ioctl_get_stats_fd(kvm);
break;
+ case KVM_CREATE_TDP_FD: {
+ struct kvm_create_tdp_fd ct;
+
+ r = -EFAULT;
+ if (copy_from_user(&ct, argp, sizeof(ct)))
+ goto out;
+
+ r = kvm_create_tdp_fd(kvm, &ct);
+ if (r)
+ goto out;
+
+ r = -EFAULT;
+ if (copy_to_user(argp, &ct, sizeof(ct)))
+ goto out;
+
+ r = 0;
+ break;
+ }
default:
r = kvm_arch_vm_ioctl(filp, ioctl, arg);
}
new file mode 100644
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __TDP_FD_H
+#define __TDP_FD_H
+
+static inline int kvm_create_tdp_fd(struct kvm *kvm, struct kvm_create_tdp_fd *ct)
+{
+ return -EOPNOTSUPP;
+}
+
+#endif /* __TDP_FD_H */