aboutsummaryrefslogtreecommitdiff
path: root/accel/kvm
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-10-21 15:40:15 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2024-01-18 10:43:14 +0100
commitaef158b093b9d67381f88468d39ac8dd62ae9e8b (patch)
treef09587cfc2a9e100c8e2522ab1cd91d9c8c86010 /accel/kvm
parent435262605fa2737af73b7057f525f8fe221c1006 (diff)
Add class property to configure KVM device node to use
This allows passing the KVM device node to use as a file descriptor via /dev/fdset/XX. Passing the device node to use as a file descriptor allows running qemu unprivileged even when the user running qemu is not in the kvm group on distributions where access to /dev/kvm is gated behind membership of the kvm group (as long as the process invoking qemu is able to open /dev/kvm and passes the file descriptor to qemu). Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com> Message-ID: <20231021134015.1119597-1-daan.j.demeyer@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'accel/kvm')
-rw-r--r--accel/kvm/kvm-all.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index bbc60146d1..49e755ec4a 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2349,7 +2349,7 @@ static int kvm_init(MachineState *ms)
QTAILQ_INIT(&s->kvm_sw_breakpoints);
#endif
QLIST_INIT(&s->kvm_parked_vcpus);
- s->fd = qemu_open_old("/dev/kvm", O_RDWR);
+ s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR);
if (s->fd == -1) {
fprintf(stderr, "Could not access KVM kernel module: %m\n");
ret = -errno;
@@ -3585,6 +3585,24 @@ static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
s->kvm_dirty_ring_size = value;
}
+static char *kvm_get_device(Object *obj,
+ Error **errp G_GNUC_UNUSED)
+{
+ KVMState *s = KVM_STATE(obj);
+
+ return g_strdup(s->device);
+}
+
+static void kvm_set_device(Object *obj,
+ const char *value,
+ Error **errp G_GNUC_UNUSED)
+{
+ KVMState *s = KVM_STATE(obj);
+
+ g_free(s->device);
+ s->device = g_strdup(value);
+}
+
static void kvm_accel_instance_init(Object *obj)
{
KVMState *s = KVM_STATE(obj);
@@ -3603,6 +3621,7 @@ static void kvm_accel_instance_init(Object *obj)
s->xen_version = 0;
s->xen_gnttab_max_frames = 64;
s->xen_evtchn_max_pirq = 256;
+ s->device = NULL;
}
/**
@@ -3643,6 +3662,10 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data)
object_class_property_set_description(oc, "dirty-ring-size",
"Size of KVM dirty page ring buffer (default: 0, i.e. use bitmap)");
+ object_class_property_add_str(oc, "device", kvm_get_device, kvm_set_device);
+ object_class_property_set_description(oc, "device",
+ "Path to the device node to use (default: /dev/kvm)");
+
kvm_arch_accel_class_init(oc);
}