* [PATCH] Add class property to configure KVM device node to use
@ 2023-10-21 13:40 Daan De Meyer
2023-10-25 17:37 ` Daniel P. Berrangé
2023-11-06 15:35 ` Paolo Bonzini
0 siblings, 2 replies; 5+ messages in thread
From: Daan De Meyer @ 2023-10-21 13:40 UTC (permalink / raw)
To: qemu-devel; +Cc: kvm, Paolo Bonzini, Daan De Meyer
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>
---
accel/kvm/kvm-all.c | 25 ++++++++++++++++++++++++-
include/sysemu/kvm_int.h | 1 +
qemu-options.hx | 8 +++++++-
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 72e1d1141c..3e0b2d00e9 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -2478,7 +2478,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;
@@ -3775,6 +3775,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);
@@ -3793,6 +3811,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;
}
/**
@@ -3833,6 +3852,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);
}
diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h
index a5b9122cb8..19a5364a4b 100644
--- a/include/sysemu/kvm_int.h
+++ b/include/sysemu/kvm_int.h
@@ -124,6 +124,7 @@ struct KVMState
uint32_t xen_caps;
uint16_t xen_gnttab_max_frames;
uint16_t xen_evtchn_max_pirq;
+ char *device;
};
void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml,
diff --git a/qemu-options.hx b/qemu-options.hx
index 54a7e94970..40ad15a9da 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -188,7 +188,8 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel,
" dirty-ring-size=n (KVM dirty ring GFN count, default 0)\n"
" eager-split-size=n (KVM Eager Page Split chunk size, default 0, disabled. ARM only)\n"
" notify-vmexit=run|internal-error|disable,notify-window=n (enable notify VM exit and set notify window, x86 only)\n"
- " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL)
+ " thread=single|multi (enable multi-threaded TCG)\n"
+ " device=path (KVM device path, default /dev/kvm)\n", QEMU_ARCH_ALL)
SRST
``-accel name[,prop=value[,...]]``
This is used to enable an accelerator. Depending on the target
@@ -269,6 +270,11 @@ SRST
open up for a specified of time (i.e. notify-window).
Default: notify-vmexit=run,notify-window=0.
+ ``device=path``
+ Sets the path to the KVM device node. Defaults to ``/dev/kvm``. This
+ option can be used to pass the KVM device to use via a file descriptor
+ by setting the value to ``/dev/fdset/NN``.
+
ERST
DEF("smp", HAS_ARG, QEMU_OPTION_smp,
--
2.41.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Add class property to configure KVM device node to use
2023-10-21 13:40 [PATCH] Add class property to configure KVM device node to use Daan De Meyer
@ 2023-10-25 17:37 ` Daniel P. Berrangé
2023-10-28 12:07 ` Daan De Meyer
2023-11-06 15:35 ` Paolo Bonzini
1 sibling, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2023-10-25 17:37 UTC (permalink / raw)
To: Daan De Meyer; +Cc: qemu-devel, kvm, Paolo Bonzini
On Sat, Oct 21, 2023 at 03:40:15PM +0200, Daan De Meyer wrote:
> 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>
> ---
> accel/kvm/kvm-all.c | 25 ++++++++++++++++++++++++-
> include/sysemu/kvm_int.h | 1 +
> qemu-options.hx | 8 +++++++-
> 3 files changed, 32 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Add class property to configure KVM device node to use
2023-10-25 17:37 ` Daniel P. Berrangé
@ 2023-10-28 12:07 ` Daan De Meyer
2023-11-06 15:26 ` Daan De Meyer
0 siblings, 1 reply; 5+ messages in thread
From: Daan De Meyer @ 2023-10-28 12:07 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, kvm, Paolo Bonzini
Anything else needed before this patch can be merged?
Cheers,
Daan
On Wed, 25 Oct 2023 at 19:37, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Sat, Oct 21, 2023 at 03:40:15PM +0200, Daan De Meyer wrote:
> > 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>
> > ---
> > accel/kvm/kvm-all.c | 25 ++++++++++++++++++++++++-
> > include/sysemu/kvm_int.h | 1 +
> > qemu-options.hx | 8 +++++++-
> > 3 files changed, 32 insertions(+), 2 deletions(-)
>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
>
> With regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Add class property to configure KVM device node to use
2023-10-28 12:07 ` Daan De Meyer
@ 2023-11-06 15:26 ` Daan De Meyer
0 siblings, 0 replies; 5+ messages in thread
From: Daan De Meyer @ 2023-11-06 15:26 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, kvm, Paolo Bonzini
Ping
Daan
On Sat, 28 Oct 2023 at 14:07, Daan De Meyer <daan.j.demeyer@gmail.com> wrote:
>
> Anything else needed before this patch can be merged?
>
> Cheers,
>
> Daan
>
> On Wed, 25 Oct 2023 at 19:37, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Sat, Oct 21, 2023 at 03:40:15PM +0200, Daan De Meyer wrote:
> > > 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>
> > > ---
> > > accel/kvm/kvm-all.c | 25 ++++++++++++++++++++++++-
> > > include/sysemu/kvm_int.h | 1 +
> > > qemu-options.hx | 8 +++++++-
> > > 3 files changed, 32 insertions(+), 2 deletions(-)
> >
> > Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> >
> >
> > With regards,
> > Daniel
> > --
> > |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> > |: https://libvirt.org -o- https://fstop138.berrange.com :|
> > |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Add class property to configure KVM device node to use
2023-10-21 13:40 [PATCH] Add class property to configure KVM device node to use Daan De Meyer
2023-10-25 17:37 ` Daniel P. Berrangé
@ 2023-11-06 15:35 ` Paolo Bonzini
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2023-11-06 15:35 UTC (permalink / raw)
To: Daan De Meyer; +Cc: qemu-devel, kvm
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-06 15:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-21 13:40 [PATCH] Add class property to configure KVM device node to use Daan De Meyer
2023-10-25 17:37 ` Daniel P. Berrangé
2023-10-28 12:07 ` Daan De Meyer
2023-11-06 15:26 ` Daan De Meyer
2023-11-06 15:35 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).