]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
i386/xen: set domid at vm arch init
authorJoao Martins <joao.m.martins@oracle.com>
Thu, 6 Sep 2018 19:08:53 +0000 (15:08 -0400)
committerJoao Martins <joao.m.martins@oracle.com>
Tue, 19 Feb 2019 14:00:57 +0000 (09:00 -0500)
This allows to a guest be able to be searcheable by hypervisor
without relying on host-wide information (PID).

This is the earliest point we *so far* can assign a domid.
Emulated devices realize() may want to use domid to properly
set the device paths.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
linux-headers/linux/kvm.h
target/i386/trace-events
target/i386/xen-proto.h
target/i386/xen.c
target/i386/xen.h

index 8a9a648c8c704ec42f1edde0278ec403e25ecba6..e074fa6116cc8923980099ca8bd206f5a69b80c3 100644 (file)
@@ -1004,6 +1004,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_HYPERV_CPUID 167
 #define KVM_CAP_XEN_HVM_GUEST 168
 #define KVM_CAP_XEN_HVM_EVTCHN 169
+#define KVM_CAP_XEN_HVM_DOM0 170
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1498,6 +1499,9 @@ struct kvm_xen_hvm_attr {
                                __u32 padding[2];
                        };
                } evtchn;
+               struct {
+                       __s32 domid;
+               } dom;
        } u;
 };
 
@@ -1508,6 +1512,8 @@ struct kvm_xen_hvm_attr {
 #define KVM_XEN_ATTR_TYPE_VCPU_RUNSTATE     0x3
 /* Available with KVM_CAP_XEN_HVM_EVTCHN */
 #define KVM_XEN_ATTR_TYPE_EVTCHN            0x4
+/* Available with KVM_CAP_XEN_HVM_DOM0 */
+#define KVM_XEN_ATTR_TYPE_DOMID             0x5
 
 /* Secure Encrypted Virtualization command */
 enum sev_cmd_id {
index f7c47790276221538689bff409077c69884d90b1..138401a259537abd24d64322ac4c5ecd9f721f1e 100644 (file)
@@ -23,3 +23,4 @@ kvm_xen_set_vcpu_attr(int cpu, int type, uint64_t gpa) "vcpu attr cpu %d type %d
 kvm_xen_set_callback(int cpu, int virq, int vector, int via) "callback vcpu %d virq %d vector %d via %d"
 kvm_xen_evtchn_set(int flags, unsigned int port, int port_type) "flags 0x%x port %u port_type %d"
 kvm_xen_evtchn_send(int cpu, int dest, unsigned int port) "cpu %d notify_cpu %d port %u"
+kvm_xen_set_domid(unsigned int domid) "assigned with domid %u"
index 1176bdf2e9a15c788ecd5edbeaba19b9ce230f40..73283ebb2930859966831d0756a981b2733c220e 100644 (file)
@@ -34,6 +34,7 @@ typedef struct XenState {
     union {
         struct XenCallbackVector cb;
     };
+    int domid;
     int port;
     QemuMutex port_lock;
 } XenState;
index 8fbcd9a17957bc4e2209c23f0f025276a995ff47..bade717a22d6083ae2ac7d8fda338ec7b2a5054b 100644 (file)
@@ -11,6 +11,7 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
 #include "qemu/log.h"
+#include "qemu/error-report.h"
 #include "linux/kvm.h"
 #include "exec/address-spaces.h"
 #include "cpu.h"
@@ -21,6 +22,7 @@
 #include "monitor/monitor.h"
 #include "qapi/qmp/qdict.h"
 #include "qom/cpu.h"
+#include "hw/xen/xen.h"
 
 
 #define __XEN_INTERFACE_VERSION__ 0x00040400
@@ -139,12 +141,47 @@ int kvm_xen_set_hypercall_page(CPUState *env)
 
 void kvm_xen_init(XenState *xen)
 {
+    kvm_xen_set_domid(kvm_state, xen);
+
     qemu_mutex_init(&xen_global_mutex);
     qemu_mutex_init(&xen->port_lock);
 
     kvm_xen_evtchn_init(xen);
 }
 
+int kvm_xen_set_domid(KVMState *kvm_state, XenState *xen)
+{
+    struct kvm_xen_hvm_attr xhd;
+    int r;
+
+    if (xen->domid != 0) {
+        return -EEXIST;
+    }
+
+    /* Domid 0 means invalid */
+    xen->domid = 0;
+
+    xhd.type = KVM_XEN_ATTR_TYPE_DOMID;
+    if (!xen_domid)
+        xhd.u.dom.domid = -1;
+    else
+        xhd.u.dom.domid = xen_domid;
+    r = kvm_vm_ioctl(kvm_state, KVM_XEN_HVM_SET_ATTR, &xhd);
+    if (r) {
+        return -EFAULT;
+    }
+
+    r = kvm_vm_ioctl(kvm_state, KVM_XEN_HVM_GET_ATTR, &xhd);
+    if (r || !xhd.u.dom.domid) {
+        return -EFAULT;
+    }
+
+    xen->domid = xhd.u.dom.domid;
+    trace_kvm_xen_set_domid(xen->domid);
+    xen_domid = xen->domid;
+    return r;
+}
+
 void kvm_xen_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data)
 {
     do_run_on_cpu(cpu, func, RUN_ON_CPU_HOST_PTR(data), &xen_global_mutex);
index ce67bcb9e6a8610b8aa1168494bda53741b8ee14..834fe7c87c6e269530a8b594a2d7f867a6c4768e 100644 (file)
@@ -21,6 +21,7 @@
 #define XEN_CPUID_TIME             0x40000003
 #define XEN_CPUID_HVM              0x40000004
 
+int kvm_xen_set_domid(KVMState *kvm_state, XenState *xen);
 int kvm_xen_set_hypercall_page(CPUState *env);
 int kvm_xen_vcpu_init(CPUState *cs);
 int kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit);