CONFIG_HAVE_KVM is currently used with three meanings:
- some architectures use it to enabled the KVM config proper, depending
on CPU capabilities (MIPS)
- some architectures use it to enable host-side code that is not part of
the KVM module (x86)
- to enable common Kconfigs required by all architectures that support
KVM, currently CONFIG_EVENTFD
These three meanings can be replaced respectively by an architecture-
specific Kconfig, by IS_ENABLED(CONFIG_KVM), or by a new Kconfig symbol
that is in turn selected by the architecture-specific "config KVM".
This is what each of the first three patches does. After this,
CONFIG_HAVE_KVM is unused and can be removed.
This fixes architectures (PPC and RISC-V) that do not have CONFIG_HAVE_KVM=y
and therefore fail to select CONFIG_EVENTFD. Patch 1 can be quickly
applied to 6.8 to fix this build failure, while the rest can be delayed
to the early -rc period or 6.9 if desired.
Paolo
Paolo Bonzini (4):
KVM: introduce CONFIG_KVM_COMMON
MIPS: introduce Kconfig for MIPS VZ
x86, vfio, gdb: replace CONFIG_HAVE_KVM with IS_ENABLED(CONFIG_KVM)
treewide: remove CONFIG_HAVE_KVM
arch/arm64/Kconfig | 1 -
arch/arm64/kvm/Kconfig | 2 +-
arch/loongarch/Kconfig | 1 -
arch/loongarch/kvm/Kconfig | 2 +-
arch/mips/Kconfig | 18 +++++++++---------
arch/mips/kvm/Kconfig | 3 ++-
arch/powerpc/kvm/Kconfig | 1 +
arch/riscv/kvm/Kconfig | 1 +
arch/s390/Kconfig | 1 -
arch/s390/kvm/Kconfig | 2 +-
arch/x86/Kconfig | 1 -
arch/x86/include/asm/hardirq.h | 2 +-
arch/x86/include/asm/idtentry.h | 2 +-
arch/x86/include/asm/irq.h | 2 +-
arch/x86/include/asm/irq_vectors.h | 2 +-
arch/x86/kernel/idt.c | 2 +-
arch/x86/kernel/irq.c | 4 ++--
arch/x86/kvm/Kconfig | 3 +--
drivers/vfio/vfio.h | 2 +-
drivers/vfio/vfio_main.c | 4 ++--
scripts/gdb/linux/constants.py.in | 6 +++++-
scripts/gdb/linux/interrupts.py | 2 +-
tools/arch/x86/include/asm/irq_vectors.h | 2 +-
virt/kvm/Kconfig | 2 +-
24 files changed, 35 insertions(+), 33 deletions(-)
--
2.39.1
CONFIG_HAVE_KVM is currently used by some architectures to either
enabled the KVM config proper, or to enable host-side code that is
not part of the KVM module. However, the "select" statement in
virt/kvm/Kconfig corresponds to a third meaning, namely to
enable common Kconfigs required by all architectures that support
KVM.
These three meanings can be replaced respectively by an
architecture-specific Kconfig, by IS_ENABLED(CONFIG_KVM), or by
a new Kconfig symbol that is in turn selected by the
architecture-specific "config KVM".
Start by introducing such a new Kconfig symbol, CONFIG_KVM_COMMON.
Unlike CONFIG_HAVE_KVM, it is selected by CONFIG_KVM, not by
architecture code.
Fixes: 8132d887a702 ("KVM: remove CONFIG_HAVE_KVM_EVENTFD", 2023-12-08)
Cc: Andrew Jones <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
---
arch/arm64/kvm/Kconfig | 1 +
arch/loongarch/kvm/Kconfig | 1 +
arch/mips/kvm/Kconfig | 1 +
arch/powerpc/kvm/Kconfig | 1 +
arch/riscv/kvm/Kconfig | 1 +
arch/s390/kvm/Kconfig | 1 +
arch/x86/kvm/Kconfig | 1 +
virt/kvm/Kconfig | 3 +++
8 files changed, 10 insertions(+)
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
index b07c60c9737d..ad5ce0454f17 100644
--- a/arch/arm64/kvm/Kconfig
+++ b/arch/arm64/kvm/Kconfig
@@ -21,6 +21,7 @@ if VIRTUALIZATION
menuconfig KVM
bool "Kernel-based Virtual Machine (KVM) support"
depends on HAVE_KVM
+ select KVM_COMMON
select KVM_GENERIC_HARDWARE_ENABLING
select KVM_GENERIC_MMU_NOTIFIER
select PREEMPT_NOTIFIERS
diff --git a/arch/loongarch/kvm/Kconfig b/arch/loongarch/kvm/Kconfig
index daba4cd5e87d..3b284b7e63ad 100644
--- a/arch/loongarch/kvm/Kconfig
+++ b/arch/loongarch/kvm/Kconfig
@@ -23,6 +23,7 @@ config KVM
depends on HAVE_KVM
select HAVE_KVM_DIRTY_RING_ACQ_REL
select HAVE_KVM_VCPU_ASYNC_IOCTL
+ select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_GENERIC_HARDWARE_ENABLING
select KVM_GENERIC_MMU_NOTIFIER
diff --git a/arch/mips/kvm/Kconfig b/arch/mips/kvm/Kconfig
index 428141b0b48f..2eb119e78b6e 100644
--- a/arch/mips/kvm/Kconfig
+++ b/arch/mips/kvm/Kconfig
@@ -21,6 +21,7 @@ config KVM
depends on MIPS_FP_SUPPORT
select EXPORT_UASM
select PREEMPT_NOTIFIERS
+ select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select HAVE_KVM_VCPU_ASYNC_IOCTL
select KVM_MMIO
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index b47196085a42..5da535e20b6a 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -20,6 +20,7 @@ if VIRTUALIZATION
config KVM
bool
select PREEMPT_NOTIFIERS
+ select KVM_COMMON
select HAVE_KVM_VCPU_ASYNC_IOCTL
select KVM_VFIO
select IRQ_BYPASS_MANAGER
diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig
index 1fd76aee3b71..55f81377d260 100644
--- a/arch/riscv/kvm/Kconfig
+++ b/arch/riscv/kvm/Kconfig
@@ -24,6 +24,7 @@ config KVM
select HAVE_KVM_IRQ_ROUTING
select HAVE_KVM_MSI
select HAVE_KVM_VCPU_ASYNC_IOCTL
+ select KVM_COMMON
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
select KVM_GENERIC_HARDWARE_ENABLING
select KVM_MMIO
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index bb6d90351119..f89bedbe63bd 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -25,6 +25,7 @@ config KVM
select HAVE_KVM_VCPU_ASYNC_IOCTL
select KVM_ASYNC_PF
select KVM_ASYNC_PF_SYNC
+ select KVM_COMMON
select HAVE_KVM_IRQCHIP
select HAVE_KVM_IRQ_ROUTING
select HAVE_KVM_INVALID_WAKEUPS
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index b07247b0b958..c8e62a371d24 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -24,6 +24,7 @@ config KVM
depends on HIGH_RES_TIMERS
depends on X86_LOCAL_APIC
select PREEMPT_NOTIFIERS
+ select KVM_COMMON
select KVM_GENERIC_MMU_NOTIFIER
select HAVE_KVM_IRQCHIP
select HAVE_KVM_PFNCACHE
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
index 6793211a0b64..cce5c03ecc92 100644
--- a/virt/kvm/Kconfig
+++ b/virt/kvm/Kconfig
@@ -3,6 +3,9 @@
config HAVE_KVM
bool
+
+config KVM_COMMON
+ bool
select EVENTFD
config HAVE_KVM_PFNCACHE
--
2.39.1
Since MIPS/KVM only supports hardware virtualization using MIPS VZ,
do not enable KVM blindly. Use a new Kconfig symbol CPU_SUPPORTS_VZ
and do not enable it for R2 processors.
Cc: Thomas Bogendoerfer <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
---
arch/mips/Kconfig | 9 +++++++++
arch/mips/kvm/Kconfig | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 797ae590ebdb..3eb3239013d9 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1250,6 +1250,7 @@ config CPU_LOONGSON64
select CPU_SUPPORTS_HIGHMEM
select CPU_SUPPORTS_HUGEPAGES
select CPU_SUPPORTS_MSA
+ select CPU_SUPPORTS_VZ
select CPU_DIEI_BROKEN if !LOONGSON3_ENHANCEMENT
select CPU_MIPSR2_IRQ_VI
select DMA_NONCOHERENT
@@ -1389,6 +1390,7 @@ config CPU_MIPS32_R5
select CPU_SUPPORTS_32BIT_KERNEL
select CPU_SUPPORTS_HIGHMEM
select CPU_SUPPORTS_MSA
+ select CPU_SUPPORTS_VZ
select HAVE_KVM
select MIPS_O32_FP64_SUPPORT
help
@@ -1405,6 +1407,7 @@ config CPU_MIPS32_R6
select CPU_SUPPORTS_32BIT_KERNEL
select CPU_SUPPORTS_HIGHMEM
select CPU_SUPPORTS_MSA
+ select CPU_SUPPORTS_VZ
select HAVE_KVM
select MIPS_O32_FP64_SUPPORT
help
@@ -1459,6 +1462,7 @@ config CPU_MIPS64_R5
select CPU_SUPPORTS_HUGEPAGES
select CPU_SUPPORTS_MSA
select MIPS_O32_FP64_SUPPORT if 32BIT || MIPS32_O32
+ select CPU_SUPPORTS_VZ
select HAVE_KVM
help
Choose this option to build a kernel for release 5 or later of the
@@ -1477,6 +1481,7 @@ config CPU_MIPS64_R6
select CPU_SUPPORTS_HUGEPAGES
select CPU_SUPPORTS_MSA
select MIPS_O32_FP64_SUPPORT if 32BIT || MIPS32_O32
+ select CPU_SUPPORTS_VZ
select HAVE_KVM
help
Choose this option to build a kernel for release 6 or later of the
@@ -1492,6 +1497,7 @@ config CPU_P5600
select CPU_SUPPORTS_HIGHMEM
select CPU_SUPPORTS_MSA
select CPU_SUPPORTS_CPUFREQ
+ select CPU_SUPPORTS_VZ
select CPU_MIPSR2_IRQ_VI
select CPU_MIPSR2_IRQ_EI
select HAVE_KVM
@@ -1614,6 +1620,7 @@ config CPU_CAVIUM_OCTEON
select USB_EHCI_BIG_ENDIAN_MMIO if CPU_BIG_ENDIAN
select USB_OHCI_BIG_ENDIAN_MMIO if CPU_BIG_ENDIAN
select MIPS_L1_CACHE_SHIFT_7
+ select CPU_SUPPORTS_VZ
select HAVE_KVM
help
The Cavium Octeon processor is a highly integrated chip containing
@@ -1969,6 +1976,8 @@ config CPU_SUPPORTS_ADDRWINCFG
config CPU_SUPPORTS_HUGEPAGES
bool
depends on !(32BIT && (PHYS_ADDR_T_64BIT || EVA))
+config CPU_SUPPORTS_VZ
+ bool
config MIPS_PGD_C0_CONTEXT
bool
depends on 64BIT
diff --git a/arch/mips/kvm/Kconfig b/arch/mips/kvm/Kconfig
index 2eb119e78b6e..1156112ffa13 100644
--- a/arch/mips/kvm/Kconfig
+++ b/arch/mips/kvm/Kconfig
@@ -17,7 +17,7 @@ if VIRTUALIZATION
config KVM
tristate "Kernel-based Virtual Machine (KVM) support"
- depends on HAVE_KVM
+ depends on CPU_SUPPORTS_VZ
depends on MIPS_FP_SUPPORT
select EXPORT_UASM
select PREEMPT_NOTIFIERS
--
2.39.1
On Thu, Jan 04, 2024 at 03:59:56PM -0500, Paolo Bonzini wrote:
> CONFIG_HAVE_KVM is currently used by some architectures to either
> enabled the KVM config proper, or to enable host-side code that is
> not part of the KVM module. However, the "select" statement in
> virt/kvm/Kconfig corresponds to a third meaning, namely to
> enable common Kconfigs required by all architectures that support
> KVM.
>
> These three meanings can be replaced respectively by an
> architecture-specific Kconfig, by IS_ENABLED(CONFIG_KVM), or by
> a new Kconfig symbol that is in turn selected by the
> architecture-specific "config KVM".
>
> Start by introducing such a new Kconfig symbol, CONFIG_KVM_COMMON.
> Unlike CONFIG_HAVE_KVM, it is selected by CONFIG_KVM, not by
> architecture code.
>
> Fixes: 8132d887a702 ("KVM: remove CONFIG_HAVE_KVM_EVENTFD", 2023-12-08)
> Cc: Andrew Jones <[email protected]>
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---
> arch/arm64/kvm/Kconfig | 1 +
> arch/loongarch/kvm/Kconfig | 1 +
> arch/mips/kvm/Kconfig | 1 +
> arch/powerpc/kvm/Kconfig | 1 +
> arch/riscv/kvm/Kconfig | 1 +
> arch/s390/kvm/Kconfig | 1 +
> arch/x86/kvm/Kconfig | 1 +
> virt/kvm/Kconfig | 3 +++
> 8 files changed, 10 insertions(+)
Reviewed-by: Andrew Jones <[email protected]>
On Thu, Jan 04, 2024, Paolo Bonzini wrote:
> CONFIG_HAVE_KVM is currently used by some architectures to either
> enabled the KVM config proper, or to enable host-side code that is
> not part of the KVM module. However, the "select" statement in
> virt/kvm/Kconfig corresponds to a third meaning, namely to
> enable common Kconfigs required by all architectures that support
> KVM.
>
> These three meanings can be replaced respectively by an
> architecture-specific Kconfig, by IS_ENABLED(CONFIG_KVM), or by
> a new Kconfig symbol that is in turn selected by the
> architecture-specific "config KVM".
>
> Start by introducing such a new Kconfig symbol, CONFIG_KVM_COMMON.
> Unlike CONFIG_HAVE_KVM, it is selected by CONFIG_KVM, not by
> architecture code.
Why? I don't get it, just have code that cares do IS_ENABLED(CONFIG_KVM). Except
for the MIPS usage of HAVE_KVM that you solved by adding CPU_SUPPORTS_VZ, I got
all the way there using just CONFIG_KVM[*].
Ah, and so does this series for the most part, the only usage of CONFIG_KVM_COMMON
is in scripts/gdb/linux/constants.py.in. Honestly, adding a Kconfig just so that
VMX's posted interrupts that arrive in the host can be printed when KVM is built
as a module is a waste of a Kconfig.
[*] https://lore.kernel.org/all/[email protected]
On Fri, Jan 5, 2024 at 8:13 PM Sean Christopherson <[email protected]> wrote:
> > Start by introducing such a new Kconfig symbol, CONFIG_KVM_COMMON.
> > Unlike CONFIG_HAVE_KVM, it is selected by CONFIG_KVM, not by
> > architecture code.
>
> Why? I don't get it, just have code that cares do IS_ENABLED(CONFIG_KVM). Except
> for the MIPS usage of HAVE_KVM that you solved by adding CPU_SUPPORTS_VZ, I got
> all the way there using just CONFIG_KVM[*].
>
> Ah, and so does this series for the most part, the only usage of CONFIG_KVM_COMMON
> is in scripts/gdb/linux/constants.py.in. Honestly, adding a Kconfig just so that
> VMX's posted interrupts that arrive in the host can be printed when KVM is built
> as a module is a waste of a Kconfig.
There is one extra thing that CONFIG_KVM_COMMON does, which is to
avoid having to select common requirements in all architectures.
I jotted this to solve the reported randconfig failure, which is why
CONFIG_KVM_COMMON only requires "select EVENTFD", but looking more
closely it should also select PREEMPT_NOTIFIERS and INTERVAL_TREE.
Both are used by virt/kvm/kvm_main.c, and loongarch + riscv both lack
INTERVAL_TREE so I do think it's a good idea to introduce this symbol
(though it requires a v2).
> [*] https://lore.kernel.org/all/[email protected]
I guess you mean
https://lore.kernel.org/all/[email protected]/.
Paolo
On Fri, Jan 05, 2024, Paolo Bonzini wrote:
> On Fri, Jan 5, 2024 at 8:13 PM Sean Christopherson <[email protected]> wrote:
> > > Start by introducing such a new Kconfig symbol, CONFIG_KVM_COMMON.
> > > Unlike CONFIG_HAVE_KVM, it is selected by CONFIG_KVM, not by
> > > architecture code.
> >
> > Why? I don't get it, just have code that cares do IS_ENABLED(CONFIG_KVM). Except
> > for the MIPS usage of HAVE_KVM that you solved by adding CPU_SUPPORTS_VZ, I got
> > all the way there using just CONFIG_KVM[*].
> >
> > Ah, and so does this series for the most part, the only usage of CONFIG_KVM_COMMON
> > is in scripts/gdb/linux/constants.py.in. Honestly, adding a Kconfig just so that
> > VMX's posted interrupts that arrive in the host can be printed when KVM is built
> > as a module is a waste of a Kconfig.
>
> There is one extra thing that CONFIG_KVM_COMMON does, which is to
> avoid having to select common requirements in all architectures.
Oooh, gotcha. FWIW, I would love to unify the "menuconfig VIRTUALIZATION" and
"config KVM" entries, but I can't think of a sane way to do that without ending
up with something like KVM_COMMON. :-/
> I jotted this to solve the reported randconfig failure, which is why
> CONFIG_KVM_COMMON only requires "select EVENTFD", but looking more
> closely it should also select PREEMPT_NOTIFIERS and INTERVAL_TREE.
> Both are used by virt/kvm/kvm_main.c, and loongarch + riscv both lack
> INTERVAL_TREE so I do think it's a good idea to introduce this symbol
> (though it requires a v2).
>
> > [*] https://lore.kernel.org/all/[email protected]
>
> I guess you mean
> https://lore.kernel.org/all/[email protected]/.
Doh, yes.