Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steffen Eiden" <seiden@linux.ibm.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
	kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v8 07/29] KVM: Make device name configurable
Date: Fri, 18 Sep 2026 14:58:13 +0000	[thread overview]
Message-ID: <20260918145813.CEE131F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260918133107.1042730-8-seiden@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] kvm: KVM_DEV_STRING macro evaluates to literal "KVM_DEV_NAME_vcpu"
- [Low] kvm: hardcoded "kvm" strings bypass the configurable device name
--

commit d598c93c97a669f28341c88d4d371abfd9c3b335
Author: Steffen Eiden <seiden@linux.ibm.com>

KVM: Make device name configurable

Allow KVM implementations to choose alternative device names. This is
especially useful for architectures providing multiple KVM
implementations simultaneously.

[ ... ]
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 2b56fb4e85557..5926478563e88 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -45,6 +45,9 @@
>  #include <asm/kvm_host.h>
>  #include <linux/kvm_dirty_ring.h>
>  
> +#define __KVM_DEV_STRING(name, x) __stringify(name ## _ ## x)
> +#define KVM_DEV_STRING(x) __KVM_DEV_STRING(KVM_DEV_NAME, x)

[Severity: Medium]
Does KVM_DEV_STRING(vcpu) expand to the literal string "KVM_DEV_NAME_vcpu"
instead of the expected configured name?

Because the name parameter in __KVM_DEV_STRING is adjacent to the ##
token-pasting operator, the C preprocessor does not macro-expand it before
pasting. The tokens KVM_DEV_NAME, _, and vcpu are pasted into
KVM_DEV_NAME_vcpu, which __stringify converts to the literal string.

Does this need an extra level of macro indirection to evaluate the arguments
before pasting?

[ ... ]
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 891a67cb365ab..4f25e170b542c 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5596,8 +5596,8 @@ static struct file_operations kvm_chardev_ops = {
>  };
>  
>  static struct miscdevice kvm_dev = {
> -	KVM_MINOR,
> -	"kvm",
> +	KVM_DEV_MINOR,
> +	__stringify(KVM_DEV_NAME),

[Severity: Low]
Are there other hardcoded "kvm" strings that will bypass this configurable
device name when creating a VM or interacting with KVM infrastructure?

For instance, processes utilizing different KVM implementations will have
indistinguishable workqueues and anonymous inodes, reducing observability:

virt/kvm/eventfd.c:kvm_irqfd_init() {
    ...
    irqfd_cleanup_wq = alloc_workqueue("kvm-irqfd-cleanup", WQ_PERCPU, 0);
    ...
}

virt/kvm/kvm_main.c:kvm_create_vm() {
    ...
    file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
    ...
}

And also hardcoded log prefixes:

virt/kvm/kvm_main.c:kvm_shutdown() {
    ...
    pr_info("kvm: exiting hardware virtualization\n");
    ...
}

Do these strings also need to use the configured device name to ensure
concurrent KVM instances are cleanly segregated?

[Severity: Low]
This is a pre-existing issue, but does generic multiple KVM support conflict
with hardcoded core kernel singletons?

If architectures using CONFIG_KVM_GENERIC_HARDWARE_ENABLING attempt to load
multiple KVM modules simultaneously, the second module will fail to initialize.
The core hotplug subsystem returns -EBUSY when a second implementation invokes
it since the hotplug state is statically assigned:

virt/kvm/kvm_main.c:kvm_enable_virtualization() {
    ...
    r = cpuhp_setup_state(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online",
                          kvm_online_cpu, kvm_offline_cpu);
    ...
}

Also, concurrent registrations of guest info callbacks trigger a WARN_ON_ONCE
since the core kernel only maintains a single pointer:

virt/kvm/kvm_main.c:__kvm_register_perf_callbacks() {
    ...
    perf_register_guest_info_callbacks(&kvm_guest_cbs);
    ...
}

Can these singletons be adjusted to support concurrent implementations?

>  	&kvm_chardev_ops,
>  };
>  
[ ... ]
> @@ -6521,7 +6521,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,

[Severity: Medium]
With the KVM_DEV_STRING() macro evaluating to the literal string
"KVM_DEV_NAME_vcpu", will all KVM modules unconditionally attempt to create a
kmem_cache named literally "KVM_DEV_NAME_vcpu" during module initialization?

This causes duplicate slab names across multiple KVM implementations, leading
to sysfs creation warnings (SLUB: Unable to add cache KVM_DEV_NAME_vcpu to
sysfs) and broken observability in /proc/slabinfo. Although SLUB permits
duplicate names and proceeds with cache creation, this seems to break the
intended uniqueness.

>  					   SLAB_ACCOUNT,
>  					   offsetof(struct kvm_vcpu, arch),
>  					   offsetofend(struct kvm_vcpu, stats_id)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260918133107.1042730-1-seiden@linux.ibm.com?part=7

  reply	other threads:[~2026-09-18 14:58 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 13:30 [PATCH v8 00/29] KVM: s390: Introduce arm64 KVM Steffen Eiden
2026-09-18 13:30 ` [PATCH v8 01/29] KVM: Introduce file_to_kvm_<arch>() infrastructure Steffen Eiden
2026-09-18 13:45   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 02/29] KVM: Add file back-pointer to struct kvm Steffen Eiden
2026-09-18 13:56   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 03/29] KVM: x86: Use file_to_kvm_x86() in SEV Steffen Eiden
2026-09-18 14:02   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 04/29] KVM/vfio: Use file-based reference counting for KVM Steffen Eiden
2026-09-18 14:26   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 05/29] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Steffen Eiden
2026-09-18 14:30   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 06/29] KVM: Move export symbol check macros to Makefile.kvm Steffen Eiden
2026-09-18 14:37   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 07/29] KVM: Make device name configurable Steffen Eiden
2026-09-18 14:58   ` sashiko-bot [this message]
2026-09-18 13:30 ` [PATCH v8 08/29] KVM: Move architecture capability Kconfigs to header defines Steffen Eiden
2026-09-18 15:07   ` sashiko-bot
2026-09-21  7:09   ` Steffen Eiden
2026-09-18 13:30 ` [PATCH v8 09/29] KVM: Replace CONFIG_KVM_MMIO with KVM_NO_MMIO Steffen Eiden
2026-09-18 15:15   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 10/29] arm64: Use proper include variant Steffen Eiden
2026-09-18 15:16   ` sashiko-bot
2026-09-28 14:01   ` Catalin Marinas
2026-09-18 13:30 ` [PATCH v8 11/29] arm64: ptrace: Use constants for compat register numbers Steffen Eiden
2026-09-18 15:20   ` sashiko-bot
2026-09-28 14:01   ` Catalin Marinas
2026-09-18 13:30 ` [PATCH v8 12/29] arm64: sysreg: Convert SPSR_ELx to automatic register generation Steffen Eiden
2026-09-18 15:24   ` sashiko-bot
2026-09-28 15:08   ` Catalin Marinas
2026-09-28 15:36     ` Steffen Eiden
2026-09-18 13:30 ` [PATCH v8 13/29] KVM: arm64: Access elements of vcpu_gp_regs individually Steffen Eiden
2026-09-18 15:28   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 14/29] KVM: arm64: Use accessor functions for core regs Steffen Eiden
2026-09-18 15:32   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 15/29] arm64: Prepare sharing arm64 headers with s390 Steffen Eiden
2026-09-18 15:39   ` sashiko-bot
2026-09-28 15:11   ` Catalin Marinas
2026-09-18 13:30 ` [PATCH v8 16/29] arm64: Share " Steffen Eiden
2026-09-18 15:50   ` sashiko-bot
2026-09-28 16:07   ` Catalin Marinas
2026-09-28 16:23     ` Steffen Eiden
2026-09-29  4:19       ` Andreas Grapentin
2026-09-29 17:00         ` Catalin Marinas
2026-09-30  7:28           ` Steffen Eiden
2026-09-30  7:55             ` Marc Zyngier
2026-09-30  8:18               ` Will Deacon
2026-09-30  8:53               ` Steffen Eiden
2026-09-18 13:30 ` [PATCH v8 17/29] KVM: arm64: Share arm64 code " Steffen Eiden
2026-09-18 16:02   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 18/29] s390/tools: Use arm64 headers Steffen Eiden
2026-09-18 16:09   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 19/29] KVM: s390: Use arm64 code Steffen Eiden
2026-09-18 16:14   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 20/29] s390: Introduce Start Arm Execution instruction Steffen Eiden
2026-09-18 16:28   ` sashiko-bot
2026-09-28 15:53   ` Ilya Leoshkevich
2026-09-28 16:15     ` Steffen Eiden
2026-09-28 16:18       ` Ilya Leoshkevich
2026-09-18 13:30 ` [PATCH v8 21/29] KVM: s390: arm64: Introduce host definitions Steffen Eiden
2026-09-18 16:44   ` sashiko-bot
2026-09-18 13:30 ` [PATCH v8 22/29] s390/hwcaps: Report SAE support as hwcap Steffen Eiden
2026-09-18 16:49   ` sashiko-bot
2026-09-28 15:58   ` Ilya Leoshkevich
2026-09-18 13:31 ` [PATCH v8 23/29] KVM: s390: Add basic arm64 kvm module Steffen Eiden
2026-09-18 17:00   ` sashiko-bot
2026-09-28 14:15   ` Hendrik Brueckner
2026-09-28 14:22     ` Steffen Eiden
2026-09-18 13:31 ` [PATCH v8 24/29] KVM: s390: arm64: Implement required functions Steffen Eiden
2026-09-18 17:13   ` sashiko-bot
2026-09-18 13:31 ` [PATCH v8 25/29] KVM: s390: arm64: Implement vm/vcpu create destroy Steffen Eiden
2026-09-18 17:24   ` sashiko-bot
2026-09-18 13:31 ` [PATCH v8 26/29] KVM: s390: arm64: Implement vCPU IOCTLs Steffen Eiden
2026-09-18 17:45   ` sashiko-bot
2026-09-18 13:31 ` [PATCH v8 27/29] KVM: s390: arm64: Implement basic page fault handler Steffen Eiden
2026-09-18 17:55   ` sashiko-bot
2026-09-18 13:31 ` [PATCH v8 28/29] KVM: s390: arm64: Integrate arm on s390 Steffen Eiden
2026-09-18 18:11   ` sashiko-bot
2026-09-18 13:31 ` [PATCH v8 29/29] KVM: s390: Enforce no unexpected external symbol exports in s390 KVM Steffen Eiden
2026-09-18 18:19   ` sashiko-bot
2026-09-18 13:38 ` [PATCH v8 00/29] KVM: s390: Introduce arm64 KVM Steffen Eiden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918145813.CEE131F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-s390@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seiden@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox