Update PPC KVM support patch

This commit is contained in:
Andrew Lukoshko 2025-05-17 11:59:26 +00:00
parent 3e64271d0c
commit babc364632

View File

@ -1,31 +1,55 @@
From 524ab50336b1190547ceb8074260a1fbebfee0be Mon Sep 17 00:00:00 2001 From 3c806e795bf954e4dc28b75887a89095815325ed Mon Sep 17 00:00:00 2001
From: Sean Christopherson <seanjc@google.com> From: Andrew Lukoshko <alukoshko@almalinux.org>
Date: Mon, 6 Dec 2021 20:54:14 +0100 Date: Sat, 17 May 2025 08:48:11 +0000
Subject: [PATCH 1/3] KVM: PPC: Avoid referencing userspace memory region in Subject: [PATCH] =?UTF-8?q?Bring=20back=20KVM=20support=20for=20PPC=C2=A7?=
memslot updates MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
For PPC HV, get the number of pages directly from the new memslot instead Backport of the following upstream commits:
of computing the same from the userspace memory region, and explicitly 524ab50336b1190547ceb8074260a1fbebfee0be
check for !DELETE instead of inferring the same when toggling mmio_update. 93b71801a8274cd9511557faf04365a5de487197
The motivation for these changes is to avoid referencing the @mem param f771b55731fc82b1e8e9ef123f6f1b8d8c92bc63
so that it can be dropped in a future commit.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Message-Id: <1e97fb5198be25f98ef82e63a8d770c682264cc9.1638817639.git.maciej.szmigiero@oracle.com>
--- ---
arch/powerpc/include/asm/kvm_ppc.h | 4 ---- Documentation/virt/kvm/api.rst | 14 ++++++++++++++
arch/powerpc/kvm/book3s.c | 6 ++---- arch/powerpc/include/asm/kvm_ppc.h | 4 ----
arch/powerpc/kvm/book3s_hv.c | 12 +++--------- arch/powerpc/include/asm/setup.h | 2 ++
arch/powerpc/kvm/book3s_pr.c | 2 -- arch/powerpc/kvm/book3s.c | 6 ++----
arch/powerpc/kvm/booke.c | 2 -- arch/powerpc/kvm/book3s_64_vio_hv.c | 2 +-
arch/powerpc/kvm/powerpc.c | 4 ++-- arch/powerpc/kvm/book3s_hv.c | 12 +++---------
6 files changed, 7 insertions(+), 23 deletions(-) arch/powerpc/kvm/book3s_pr.c | 2 --
arch/powerpc/kvm/booke.c | 2 --
arch/powerpc/kvm/powerpc.c | 21 +++++++++++++++++++--
arch/powerpc/platforms/pseries/setup.c | 13 ++++++++++++-
10 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 9f2f130c6..64aca1034 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -7735,6 +7735,20 @@ indicated by the fd to the VM this is called on.
This is intended to support intra-host migration of VMs between userspace VMMs,
upgrading the VMM process without interrupting the guest.
+7.30 KVM_CAP_PPC_AIL_MODE_3
+-------------------------------
+
+:Capability: KVM_CAP_PPC_AIL_MODE_3
+:Architectures: ppc
+:Type: vm
+
+This capability indicates that the kernel supports the mode 3 setting for the
+"Address Translation Mode on Interrupt" aka "Alternate Interrupt Location"
+resource that is controlled with the H_SET_MODE hypercall.
+
+This capability allows a guest kernel to use a better-performance mode for
+handling interrupts and system calls.
+
7.31 KVM_CAP_DISABLE_QUIRKS2
----------------------------
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 5c80c4955..6874cd89d 100644 index 254a41648..e16491011 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h --- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -199,12 +199,10 @@ extern void kvmppc_core_destroy_vm(struct kvm *kvm); @@ -199,12 +199,10 @@ extern void kvmppc_core_destroy_vm(struct kvm *kvm);
@ -54,6 +78,24 @@ index 5c80c4955..6874cd89d 100644
struct kvm_memory_slot *old, struct kvm_memory_slot *old,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change); enum kvm_mr_change change);
diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index 31f315223..1868e4a07 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -27,11 +27,13 @@ void setup_panic(void);
#define ARCH_PANIC_TIMEOUT 180
#ifdef CONFIG_PPC_PSERIES
+extern bool pseries_reloc_on_exception(void);
extern bool pseries_enable_reloc_on_exc(void);
extern void pseries_disable_reloc_on_exc(void);
extern void pseries_big_endian_exceptions(void);
extern void pseries_little_endian_exceptions(void);
#else
+static inline bool pseries_reloc_on_exception(void) { return false; }
static inline bool pseries_enable_reloc_on_exc(void) { return false; }
static inline void pseries_disable_reloc_on_exc(void) {}
static inline void pseries_big_endian_exceptions(void) {}
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 64fd4b3ea..cb7b5f365 100644 index 64fd4b3ea..cb7b5f365 100644
--- a/arch/powerpc/kvm/book3s.c --- a/arch/powerpc/kvm/book3s.c
@ -82,8 +124,21 @@ index 64fd4b3ea..cb7b5f365 100644
} }
bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c
index f38dfe195..16e5872a1 100644
--- a/arch/powerpc/kvm/book3s_64_vio_hv.c
+++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
@@ -488,7 +488,7 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
/*
* used to check for invalidations in progress
*/
- mmu_seq = kvm->mmu_notifier_seq;
+ mmu_seq = kvm->mmu_invalidate_seq;
smp_rmb();
stt = kvmppc_find_table(vcpu->kvm, liobn);
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 9c3c9fd5e..7f4c188f3 100644 index 5b2530818..f6ce07b4b 100644
--- a/arch/powerpc/kvm/book3s_hv.c --- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c
@@ -4777,15 +4777,12 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot) @@ -4777,15 +4777,12 @@ static void kvmppc_core_free_memslot_hv(struct kvm_memory_slot *slot)
@ -127,7 +182,7 @@ index 9c3c9fd5e..7f4c188f3 100644
/* /*
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 7891b9d0c..c0ae926af 100644 index 48b48311a..6884c04f2 100644
--- a/arch/powerpc/kvm/book3s_pr.c --- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c +++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1892,7 +1892,6 @@ static void kvmppc_core_flush_memslot_pr(struct kvm *kvm, @@ -1892,7 +1892,6 @@ static void kvmppc_core_flush_memslot_pr(struct kvm *kvm,
@ -167,10 +222,34 @@ index b06ca6646..6cf2db284 100644
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 818815e15..f8f39a858 100644 index 818815e15..b89271923 100644
--- a/arch/powerpc/kvm/powerpc.c --- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c
@@ -686,7 +686,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, @@ -662,6 +662,23 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
r = 1;
break;
#endif
+ case KVM_CAP_PPC_AIL_MODE_3:
+ r = 0;
+ /*
+ * KVM PR, POWER7, and some POWER9s don't support AIL=3 mode.
+ * The POWER9s can support it if the guest runs in hash mode,
+ * but QEMU doesn't necessarily query the capability in time.
+ */
+ if (hv_enabled) {
+ if (kvmhv_on_pseries()) {
+ if (pseries_reloc_on_exception())
+ r = 1;
+ } else if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
+ !cpu_has_feature(CPU_FTR_P9_RADIX_PREFETCH_BUG)) {
+ r = 1;
+ }
+ }
+ break;
default:
r = 0;
break;
@@ -686,7 +703,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
struct kvm_memory_slot *new, struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
@ -179,7 +258,7 @@ index 818815e15..f8f39a858 100644
} }
void kvm_arch_commit_memory_region(struct kvm *kvm, void kvm_arch_commit_memory_region(struct kvm *kvm,
@@ -694,7 +694,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, @@ -694,7 +711,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
const struct kvm_memory_slot *new, const struct kvm_memory_slot *new,
enum kvm_mr_change change) enum kvm_mr_change change)
{ {
@ -188,32 +267,44 @@ index 818815e15..f8f39a858 100644
} }
void kvm_arch_flush_shadow_memslot(struct kvm *kvm, void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index f5c2718e2..1f7e535ab 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -367,6 +367,14 @@ static void pseries_lpar_idle(void)
pseries_idle_epilog();
}
+static bool pseries_reloc_on_exception_enabled;
+
+bool pseries_reloc_on_exception(void)
+{
+ return pseries_reloc_on_exception_enabled;
+}
+EXPORT_SYMBOL_GPL(pseries_reloc_on_exception);
+
/*
* Enable relocation on during exceptions. This has partition wide scope and
* may take a while to complete, if it takes longer than one second we will
@@ -391,6 +399,7 @@ bool pseries_enable_reloc_on_exc(void)
" on exceptions: %ld\n", rc);
return false;
}
+ pseries_reloc_on_exception_enabled = true;
return true;
}
@@ -418,7 +427,9 @@ void pseries_disable_reloc_on_exc(void)
break;
mdelay(get_longbusy_msecs(rc));
}
- if (rc != H_SUCCESS)
+ if (rc == H_SUCCESS)
+ pseries_reloc_on_exception_enabled = false;
+ else
pr_warn("Warning: Failed to disable relocation on exceptions: %ld\n",
rc);
}
-- --
2.39.5 (Apple Git-154) 2.43.5
From 8c62d250a23bbbb1ecd84d4d475e7623810275aa Mon Sep 17 00:00:00 2001
From: eabdullin <eabdullin@almalinux.org>
Date: Tue, 8 Apr 2025 10:13:43 +0300
Subject: [PATCH 3/3] powerpc/kvm: use mmu_invalidate_seq instead of
mmu_notifier_seq
---
arch/powerpc/kvm/book3s_64_vio_hv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c
index f38dfe195..16e5872a1 100644
--- a/arch/powerpc/kvm/book3s_64_vio_hv.c
+++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
@@ -488,7 +488,7 @@ long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
/*
* used to check for invalidations in progress
*/
- mmu_seq = kvm->mmu_notifier_seq;
+ mmu_seq = kvm->mmu_invalidate_seq;
smp_rmb();
stt = kvmppc_find_table(vcpu->kvm, liobn);
--
2.39.5 (Apple Git-154)