mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
KVM: Make device name configurable
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@google.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Link: https://patch.msgid.link/20260930173441.66762-2-seiden@linux.ibm.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
4e0ab192f2
commit
0d22ab9505
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
* Yaniv Kamay <yaniv@qumranet.com>
|
||||
*/
|
||||
|
||||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
|
||||
#include <kvm/iodev.h>
|
||||
|
||||
#include <linux/kvm_host.h>
|
||||
|
|
@ -1023,7 +1025,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;
|
||||
|
|
@ -4125,9 +4127,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);
|
||||
}
|
||||
|
||||
|
|
@ -4340,9 +4342,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)
|
||||
|
|
@ -5155,7 +5157,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);
|
||||
|
|
@ -5532,7 +5534,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;
|
||||
|
|
@ -5600,8 +5602,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,
|
||||
};
|
||||
|
||||
|
|
@ -5635,7 +5637,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;
|
||||
}
|
||||
|
|
@ -5682,7 +5684,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);
|
||||
}
|
||||
|
||||
|
|
@ -6093,7 +6095,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;
|
||||
}
|
||||
|
|
@ -6380,7 +6382,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];
|
||||
|
|
@ -6525,7 +6527,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)
|
||||
|
|
@ -6578,7 +6580,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user