@@ -862,6 +862,7 @@ struct kvm {
/* Protected by slots_locks (for writes) and RCU (for reads) */
struct xarray mem_attr_array;
#endif
+ struct kvm_dtb dtb;
char stats_id[KVM_STATS_NAME_SIZE];
};
@@ -14,7 +14,7 @@
#include <linux/ioctl.h>
#include <asm/kvm.h>
-#define KVM_API_VERSION 12
+#define KVM_API_VERSION 13
/*
* Backwards-compatible definitions.
@@ -43,6 +43,11 @@ struct kvm_userspace_memory_region2 {
__u64 pad2[14];
};
+struct kvm_dtb {
+ __u64 guest_phys_addr;
+ __u64 size;
+};
+
/*
* The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for
* userspace, other bits are reserved for kvm internal use which are defined
@@ -1190,11 +1195,12 @@ struct kvm_vfio_spapr_tce {
#define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64)
#define KVM_SET_USER_MEMORY_REGION2 _IOW(KVMIO, 0x49, \
struct kvm_userspace_memory_region2)
+#define KVM_SET_DTB_ADDRESS _IOW(KVMIO, 0x50, struct kvm_dtb)
/* enable ucontrol for s390 */
-#define KVM_S390_UCAS_MAP _IOW(KVMIO, 0x50, struct kvm_s390_ucas_mapping)
-#define KVM_S390_UCAS_UNMAP _IOW(KVMIO, 0x51, struct kvm_s390_ucas_mapping)
-#define KVM_S390_VCPU_FAULT _IOW(KVMIO, 0x52, unsigned long)
+#define KVM_S390_UCAS_MAP _IOW(KVMIO, 0x55, struct kvm_s390_ucas_mapping)
+#define KVM_S390_UCAS_UNMAP _IOW(KVMIO, 0x56, struct kvm_s390_ucas_mapping)
+#define KVM_S390_VCPU_FAULT _IOW(KVMIO, 0x57, unsigned long)
/* Device model IOC */
#define KVM_CREATE_IRQCHIP _IO(KVMIO, 0x60)
@@ -5121,6 +5121,14 @@ static long kvm_vm_ioctl(struct file *filp,
r = kvm_vm_ioctl_set_memory_region(kvm, &mem);
break;
}
+ case KVM_SET_DTB_ADDRESS: {
+ r = 0;
+ if (copy_from_user(&kvm->dtb, argp, sizeof(struct kvm_dtb))) {
+ r = -EFAULT;
+ goto out;
+ }
+ break;
+ }
case KVM_GET_DIRTY_LOG: {
struct kvm_dirty_log log;
Some hypervisors, such as Gunyah, require access to the guest's device tree blob (DTB) in order to inspect and/or modify it before starting the guest. The userspace virtual machine monitor (e.g. QEMU) is responsible for loading the guest's DTB into memory at a guest physical address, but the hypervisor backend must be informed of that address and size. To support this use case, introduce a new ioctl: KVM_SET_DTB_ADDRESS. This allows userspace to provide the guest physical address and size of the DTB via a `struct kvm_dtb`, which is now stored in `struct kvm`. The ioctl allows platform-specific backends like Gunyah to retrieve the DTB location when configuring the VM. This patch also increments the KVM API version to 13 to reflect the addition of this new ioctl. Signed-off-by: Karim Manaouil <karim.manaouil@linaro.org> --- include/linux/kvm_host.h | 1 + include/uapi/linux/kvm.h | 14 ++++++++++---- virt/kvm/kvm_main.c | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-)