[PATCH v9 01/24] KVM: Make device name configurable
From: Steffen Eiden
Date: Wed Sep 30 2026 - 14:39:32 EST
Allow KVM implementations to choose alternative device names. This is
especially useful for architectures providing multiple KVM
implementations simultaneously. Architectures providing multiple KVM
implementations must compile the KVM common code once per implementation
and mangle symbols.
Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Steffen Eiden <seiden@xxxxxxxxxxxxx>
---
arch/s390/kvm/gmap/trace_gmap.h | 4 +++-
arch/s390/kvm/s390/Makefile | 2 +-
include/linux/kvm_host.h | 4 ++++
include/trace/events/kvm.h | 8 +++++++-
virt/kvm/Makefile.kvm | 5 +++++
virt/kvm/async_pf.c | 5 ++++-
virt/kvm/eventfd.c | 3 ++-
virt/kvm/kvm_main.c | 32 +++++++++++++++++---------------
8 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/arch/s390/kvm/gmap/trace_gmap.h b/arch/s390/kvm/gmap/trace_gmap.h
index 15ec88bdce55..78d26dae59f9 100644
--- a/arch/s390/kvm/gmap/trace_gmap.h
+++ b/arch/s390/kvm/gmap/trace_gmap.h
@@ -4,8 +4,10 @@
#include <linux/tracepoint.h>
+#undef UNPACK_KVM
+#define UNPACK_KVM(name) name
#undef TRACE_SYSTEM
-#define TRACE_SYSTEM kvm
+#define TRACE_SYSTEM UNPACK_KVM(KVM_DEV_NAME)
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH ../gmap
#undef TRACE_INCLUDE_FILE
diff --git a/arch/s390/kvm/s390/Makefile b/arch/s390/kvm/s390/Makefile
index 762a63826423..b91334db90a2 100644
--- a/arch/s390/kvm/s390/Makefile
+++ b/arch/s390/kvm/s390/Makefile
@@ -4,7 +4,7 @@ KVM := ../../../../virt/kvm
include $(srctree)/virt/kvm/Makefile.kvm
include $(srctree)/arch/s390/kvm/gmap/Makefile
-ccflags-y := -I$(src) -I$(srctree)/arch/s390/kvm/gmap
+ccflags-y += -I$(src) -I$(srctree)/arch/s390/kvm/gmap
kvm-y += s390.o intercept.o interrupt.o priv.o sigp.o
kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 586f6e8bb81b..160e3e64ec6d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -45,6 +45,10 @@
#include <asm/kvm_host.h>
#include <linux/kvm_dirty_ring.h>
+#define __KVM_DEV_STRING(name, x) __stringify(name ## _ ## x)
+#define _KVM_DEV_STRING(name, x) __KVM_DEV_STRING(name, x)
+#define KVM_DEV_STRING(x) _KVM_DEV_STRING(KVM_DEV_NAME, x)
+
#ifndef KVM_MAX_VCPU_IDS
#define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS
#endif
diff --git a/include/trace/events/kvm.h b/include/trace/events/kvm.h
index b282e3a86769..f37582730ffc 100644
--- a/include/trace/events/kvm.h
+++ b/include/trace/events/kvm.h
@@ -4,8 +4,14 @@
#include <linux/tracepoint.h>
+#undef UNPACK_KVM
+#define UNPACK_KVM(name) name
#undef TRACE_SYSTEM
-#define TRACE_SYSTEM kvm
+#define TRACE_SYSTEM UNPACK_KVM(KVM_DEV_NAME)
+#undef TRACE_SYSTEM_VAR
+#define TRACE_SYSTEM_VAR kvm
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE kvm
#define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
diff --git a/virt/kvm/Makefile.kvm b/virt/kvm/Makefile.kvm
index d047d4cf58c9..b39f7b2a5f6e 100644
--- a/virt/kvm/Makefile.kvm
+++ b/virt/kvm/Makefile.kvm
@@ -5,6 +5,11 @@
KVM ?= ../../../virt/kvm
+KVM_DEV_NAME ?= kvm
+KVM_DEV_MINOR ?= KVM_MINOR
+
+ccflags-y +=-DKVM_DEV_NAME=$(KVM_DEV_NAME) -DKVM_DEV_MINOR=$(KVM_DEV_MINOR)
+
kvm-y := $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/binary_stats.o
kvm-$(CONFIG_KVM_VFIO) += $(KVM)/vfio.o
kvm-$(CONFIG_KVM_MMIO) += $(KVM)/coalesced_mmio.o
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index b8aaa96b799b..6b3b6353cb9d 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -21,7 +21,10 @@ static struct kmem_cache *async_pf_cache;
int kvm_async_pf_init(void)
{
- async_pf_cache = KMEM_CACHE(kvm_async_pf, 0);
+ async_pf_cache = kmem_cache_create(KVM_DEV_STRING(async_pf),
+ sizeof(struct kvm_async_pf),
+ __alignof__(struct kvm_async_pf),
+ 0, NULL);
if (!async_pf_cache)
return -ENOMEM;
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 93ad2ebc963f..f43b8b25bc85 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -711,7 +711,8 @@ bool kvm_notify_irqfd_resampler(struct kvm *kvm,
*/
int kvm_irqfd_init(void)
{
- irqfd_cleanup_wq = alloc_workqueue("kvm-irqfd-cleanup", WQ_PERCPU, 0);
+ irqfd_cleanup_wq = alloc_workqueue(__stringify(KVM_DEV_NAME) "-irqfd-cleanup",
+ WQ_PERCPU, 0);
if (!irqfd_cleanup_wq)
return -ENOMEM;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 60e614795a36..f62901b7e23d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -10,6 +10,8 @@
* Yaniv Kamay <yaniv@xxxxxxxxxxxx>
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <kvm/iodev.h>
#include <linux/kvm_host.h>
@@ -1013,7 +1015,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname)
mutex_lock(&kvm_debugfs_lock);
dent = debugfs_lookup(dir_name, kvm_debugfs_dir);
if (dent) {
- pr_warn_ratelimited("KVM: debugfs: duplicate directory %s\n", dir_name);
+ pr_warn_ratelimited("debugfs: duplicate directory %s\n", dir_name);
dput(dent);
mutex_unlock(&kvm_debugfs_lock);
return 0;
@@ -4138,9 +4140,9 @@ static struct file_operations kvm_vcpu_fops = {
*/
static int create_vcpu_fd(struct kvm_vcpu *vcpu)
{
- char name[8 + 1 + ITOA_MAX_LEN + 1];
+ char name[sizeof(__stringify(KVM_DEV_NAME) "-vcpu:") + ITOA_MAX_LEN + 1];
- snprintf(name, sizeof(name), "kvm-vcpu:%d", vcpu->vcpu_id);
+ snprintf(name, sizeof(name), __stringify(KVM_DEV_NAME) "-vcpu:%d", vcpu->vcpu_id);
return anon_inode_getfd(name, &kvm_vcpu_fops, vcpu, O_RDWR | O_CLOEXEC);
}
@@ -4353,9 +4355,9 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)
{
int fd;
struct file *file;
- char name[15 + ITOA_MAX_LEN + 1];
+ char name[sizeof(__stringify(KVM_DEV_NAME) "-vcpu-stats:") + ITOA_MAX_LEN + 1];
- snprintf(name, sizeof(name), "kvm-vcpu-stats:%d", vcpu->vcpu_id);
+ snprintf(name, sizeof(name), __stringify(KVM_DEV_NAME) "-vcpu-stats:%d", vcpu->vcpu_id);
fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0)
@@ -5168,7 +5170,7 @@ static int kvm_vm_ioctl_get_stats_fd(struct kvm *kvm)
if (fd < 0)
return fd;
- file = anon_inode_getfile_fmode("kvm-vm-stats",
+ file = anon_inode_getfile_fmode(__stringify(KVM_DEV_NAME) "-vm-stats",
&kvm_vm_stats_fops, kvm, O_RDONLY, FMODE_PREAD);
if (IS_ERR(file)) {
put_unused_fd(fd);
@@ -5545,7 +5547,7 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
goto put_fd;
}
- file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
+ file = anon_inode_getfile(__stringify(KVM_DEV_NAME) "-vm", &kvm_vm_fops, kvm, O_RDWR);
if (IS_ERR(file)) {
r = PTR_ERR(file);
goto put_kvm;
@@ -5613,8 +5615,8 @@ static struct file_operations kvm_chardev_ops = {
};
static struct miscdevice kvm_dev = {
- KVM_MINOR,
- "kvm",
+ KVM_DEV_MINOR,
+ __stringify(KVM_DEV_NAME),
&kvm_chardev_ops,
};
@@ -5648,7 +5650,7 @@ static int kvm_enable_virtualization_cpu(void)
return 0;
if (kvm_arch_enable_virtualization_cpu()) {
- pr_info("kvm: enabling virtualization on CPU%d failed\n",
+ pr_info("enabling virtualization on CPU%d failed\n",
raw_smp_processor_id());
return -EIO;
}
@@ -5695,7 +5697,7 @@ static void kvm_shutdown(void *data)
* is used for both shutdown and reboot scenarios, i.e. neither name is
* 100% comprehensive.
*/
- pr_info("kvm: exiting hardware virtualization\n");
+ pr_info("exiting hardware virtualization\n");
on_each_cpu(kvm_disable_virtualization_cpu, NULL, 1);
}
@@ -6106,7 +6108,7 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
* attached devices. Otherwise, destroy the caller's device only.
*/
if (!new_bus) {
- pr_err("kvm: failed to shrink bus, removing it completely\n");
+ pr_err("failed to shrink bus, removing it completely\n");
kvm_io_bus_destroy(bus);
return -ENOMEM;
}
@@ -6393,7 +6395,7 @@ static void kvm_init_debug(void)
const struct kvm_stats_desc *pdesc;
int i;
- kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);
+ kvm_debugfs_dir = debugfs_create_dir(__stringify(KVM_DEV_NAME), NULL);
for (i = 0; i < kvm_vm_stats_header.num_desc; ++i) {
pdesc = &kvm_vm_stats_desc[i];
@@ -6538,7 +6540,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
if (!vcpu_align)
vcpu_align = __alignof__(struct kvm_vcpu);
kvm_vcpu_cache =
- kmem_cache_create_usercopy("kvm_vcpu", vcpu_size, vcpu_align,
+ kmem_cache_create_usercopy(KVM_DEV_STRING(vcpu), vcpu_size, vcpu_align,
SLAB_ACCOUNT,
offsetof(struct kvm_vcpu, arch),
offsetofend(struct kvm_vcpu, stats_id)
@@ -6591,7 +6593,7 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
*/
r = misc_register(&kvm_dev);
if (r) {
- pr_err("kvm: misc device register failed\n");
+ pr_err("misc device register failed\n");
goto err_register;
}
--
2.53.0