Skip to contentSkip to conversation

kvm: rework memory prefault

PATCH In review Arnd Bergmann 3 participants 5 messages May 26

Subsystems (6)
x86 KVM s390 KVM x86 +2 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kvm: rework memory prefault

From: Arnd Bergmann <[email protected]>

When both s390 and arm64 KVM modules are enabled on s390, the latter fails to link against the s390 version of kvm_arch_vcpu_pre_fault_memory():

ERROR: modpost: "kvm_arch_vcpu_pre_fault_memory" [arch/s390/kvm/arm64/kvm-arm64.ko] undefined!

Change the logic to reference this based on a target specific macro rather than a global Kconfig symbol.

Fixes f67bba50ef56 ("KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild")
Fixes 927ce4dee94f ("KVM: s390: Implement KVM_PRE_FAULT_MEMORY")

---
This is not yet an actual problem, but will be when both the experimental 'sae' branch and the 7.2 contents from current linux-next are merged.

Not sure who should carry this patch in the meantime, but it would be possible to add it to kvm-next already in preparation for the upcoming sae support.

---
 arch/s390/include/asm/kvm_host_s390.h | 4 ++++
 arch/s390/kvm/s390/Kconfig            | 1 -
 arch/x86/include/asm/kvm_host.h       | 4 ++++
 arch/x86/kvm/Kconfig                  | 1 -
 include/linux/kvm_host.h              | 5 -----
 virt/kvm/Kconfig                      | 3 ---
 virt/kvm/kvm_main.c                   | 4 ++--
 7 files changed, 10 insertions(+), 12 deletions(-)
arch/s390/include/asm/kvm_host_s390.h +4 -0
index d4bf6d0df49f..9532dc680c5a 100644
@@ -742,6 +742,10 @@ static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
 #define __KVM_HAVE_ARCH_VM_FREE
 void kvm_arch_free_vm(struct kvm *kvm);
 
+#define __KVM_HAVE_ARCH_PRE_FAULT_MEMORY
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
+				    struct kvm_pre_fault_memory *range);
+
 struct zpci_kvm_hook {
 	int (*kvm_register)(void *opaque, struct kvm *kvm);
 	void (*kvm_unregister)(void *opaque);
arch/s390/kvm/s390/Kconfig +0 -1
index 5777663e44b9..263ff29b9c9c 100644
@@ -18,7 +18,6 @@ config KVM_S390
 	select KVM_VFIO
 	select VIRT_XFER_TO_GUEST_WORK
 	select KVM_MMU_LOCKLESS_AGING
-	select KVM_GENERIC_PRE_FAULT_MEMORY
 	help
 	  Support hosting paravirtualized s390 guest machines using the SIE
 	  virtualization capability on the mainframe. This should work
arch/x86/include/asm/kvm_host.h +4 -0
index 809b285161d9..dfb8d7e67db9 100644
@@ -2077,6 +2077,10 @@ extern struct kvm_x86_ops kvm_x86_ops;
 int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops);
 void kvm_x86_vendor_exit(void);
 
+#define __KVM_HAVE_ARCH_PRE_FAULT_MEMORY
+long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
+				    struct kvm_pre_fault_memory *range);
+
 #define __KVM_HAVE_ARCH_VM_ALLOC
 static inline struct kvm *kvm_arch_alloc_vm(void)
 {
arch/x86/kvm/Kconfig +0 -1
index a6824b6fbf10..1856dc502b07 100644
@@ -45,7 +45,6 @@ config KVM_X86
 	select KVM_VFIO
 	select HAVE_KVM_PM_NOTIFIER if PM
 	select KVM_GENERIC_HARDWARE_ENABLING
-	select KVM_GENERIC_PRE_FAULT_MEMORY
 	select KVM_WERROR if WERROR
 	select KVM_GUEST_MEMFD if X86_64
 
include/linux/kvm_host.h +0 -5
index 690e34587414..70a1174df996 100644
@@ -2605,9 +2605,4 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t gfn, void __user *src, long npages
 void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);
 #endif
 
-#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
-long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
-				    struct kvm_pre_fault_memory *range);
-#endif
-
 #endif
virt/kvm/Kconfig +0 -3
index c4a983e41765..fefdf5d44646 100644
@@ -65,9 +65,6 @@ config HAVE_KVM_INVALID_WAKEUPS
 config KVM_GENERIC_DIRTYLOG_READ_PROTECT
        bool
 
-config KVM_GENERIC_PRE_FAULT_MEMORY
-       bool
-
 config KVM_COMPAT
        def_bool y
        depends on KVM && COMPAT && !(S390 || ARM64 || RISCV)
virt/kvm/kvm_main.c +2 -2
index 0d36e4d264f5..10f0748ad077 100644
@@ -4309,7 +4309,7 @@ static int kvm_vcpu_ioctl_get_stats_fd(struct kvm_vcpu *vcpu)
 	return fd;
 }
 
-#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
+#ifdef __KVM_HAVE_ARCH_PRE_FAULT_MEMORY
 static int kvm_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
 				     struct kvm_pre_fault_memory *range)
 {
@@ -4608,7 +4608,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
 		r = kvm_vcpu_ioctl_get_stats_fd(vcpu);
 		break;
 	}
-#ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
+#ifdef __KVM_HAVE_ARCH_PRE_FAULT_MEMORY
 	case KVM_PRE_FAULT_MEMORY: {
 		struct kvm_pre_fault_memory range;
 
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 s390: kvm: arm64: add HAS_IOMEM dependency

From: Arnd Bergmann <[email protected]>

The arm64 kvm driver can only be enabled when MMIO support is part of the host kernel:

arch/s390/kvm/arm64/../../../../virt/kvm/arm64/mmio.c:120:27: error: 'struct kvm_vcpu' has no member named 'mmio_needed'

s390 does not support MMIO if PCI is disabled, but in practice one would not actually need kvm support in those configurations either.

---
This is currently needed for randconfig build testing the 'sae' branch, it is not yet in linux-next

---
 arch/s390/kvm/arm64/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/s390/kvm/arm64/Kconfig +1 -0
index 42a1be50f6e1..65b9dc25fe62 100644
@@ -3,6 +3,7 @@
 config KVM_ARM64
 	def_tristate y
 	prompt "Kernel-based Virtual Machine (KVM) support for arm64 guests"
+	depends on HAS_IOMEM
 	select KVM
 	select KVM_VFIO
 	select IRQ_BYPASS_MANAGER
Signature · 1 line
2.39.5
reviewer
#2 lore raw

Re: [PATCH 2/2] s390: kvm: arm64: add HAS_IOMEM dependency

Quoted 33 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The arm64 kvm driver can only be enabled when MMIO support is part of the host kernel:

arch/s390/kvm/arm64/../../../../virt/kvm/arm64/mmio.c:120:27: error: 'struct kvm_vcpu' has no member named 'mmio_needed'

s390 does not support MMIO if PCI is disabled, but in practice one would not actually need kvm support in those configurations either.

---
This is currently needed for randconfig build testing the 'sae' branch, it is not yet in linux-next

---
 arch/s390/kvm/arm64/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/s390/kvm/arm64/Kconfig +1 -0
index 42a1be50f6e1..65b9dc25fe62 100644
@@ -3,6 +3,7 @@
 config KVM_ARM64
 	def_tristate y
 	prompt "Kernel-based Virtual Machine (KVM) support for arm64 guests"
+	depends on HAS_IOMEM
 	select KVM
 	select KVM_VFIO
 	select IRQ_BYPASS_MANAGER
Signature · 1 line
2.39.5

Thank you,

I would squash this in v3 into the patch that creates this config:
KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

if that is OK for you.

Steffen

#3 lore raw

Re: [PATCH 2/2] s390: kvm: arm64: add HAS_IOMEM dependency

Quoted 5 lines · Steffen Eiden

I would squash this in v3 into the patch that creates this config:
KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild

if that is OK for you.

Yes, please do.

Arnd

reviewer
#4 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

When both s390 and arm64 KVM modules are enabled on s390, the latter fails to link against the s390 version of kvm_arch_vcpu_pre_fault_memory():

Quoted 8 lines

ERROR: modpost: "kvm_arch_vcpu_pre_fault_memory" [arch/s390/kvm/arm64/kvm-arm64.ko] undefined!

Change the logic to reference this based on a target specific macro rather than a global Kconfig symbol.

Fixes f67bba50ef56 ("KVM: s390: arm64: Enable KVM_ARM64 config and Kbuild")
Fixes 927ce4dee94f ("KVM: s390: Implement KVM_PRE_FAULT_MEMORY")

Thanks for looking into this.

An alternative solution could be for the kvm-arm64 module to just implement the function as well. The s390 implementation is purely gmap based and has no dependencies to s390-kvm beside that. arm on s390 kvm could use the exact same implementation as well.

I guess this is probably dead code as (I assume) qemu-aarch64 does not use the feature. But I saw some proposals regarding this feature for KVM/arm64 on the list.

Quoted 9 lines

---
This is not yet an actual problem, but will be when both the experimental 'sae' branch and the 7.2 contents from current linux-next are merged.

Not sure who should carry this patch in the meantime, but it would be possible to add it to kvm-next already in preparation for the upcoming sae support.

I would prefer if you put it in next now. Less patches to carry around.

But If that is not feasible I can add it to series 1 once Claudios patches are in 7.2.

Steffen