* [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API
@ 2024-11-09 6:32 Gautam Menghani
2024-11-09 6:32 ` [PATCH 1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1" Gautam Menghani
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Gautam Menghani @ 2024-11-09 6:32 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, naveen, maddy, vaibhav
Cc: Gautam Menghani, linuxppc-dev, kvm, linux-kernel
Doorbell emulation for nested KVM guests in V1 API is broken because of
2 reasons:
1. L0 presenting H_EMUL_ASSIST to L1 instead of H_FAC_UNAVAIL
2. Broken plumbing for passing around doorbell state.
Fix the trap passed to L1 and the plumbing for maintaining doorbell
state.
Gautam Menghani (3):
Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1"
KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests
KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending
doorbells
arch/powerpc/kvm/book3s_hv.c | 41 ++++++++---------------------
arch/powerpc/kvm/book3s_hv_nested.c | 14 +++++++---
2 files changed, 21 insertions(+), 34 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1"
2024-11-09 6:32 [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Gautam Menghani
@ 2024-11-09 6:32 ` Gautam Menghani
2024-11-09 6:32 ` [PATCH 2/3] KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests Gautam Menghani
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Gautam Menghani @ 2024-11-09 6:32 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, naveen, maddy, vaibhav
Cc: Gautam Menghani, linuxppc-dev, kvm, linux-kernel
This reverts commit 7c3ded5735141ff4d049747c9f76672a8b737c49.
On PowerNV, when a nested guest tries to use a feature prohibited by
HFSCR, the nested hypervisor (L1) should get a H_FAC_UNAVAILABLE trap
so that L1 can emulate the feature. But with the change introduced by
commit 7c3ded573514 ("KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs
to L1") the L1 ends up getting a H_EMUL_ASSIST because of which, the L1
ends up injecting a SIGILL when L2 (nested guest) tries to use doorbells.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
arch/powerpc/kvm/book3s_hv.c | 31 ++-----------------------------
1 file changed, 2 insertions(+), 29 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index ad8dc4ccdaab..0a8f143e0a75 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2060,36 +2060,9 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
fallthrough; /* go to facility unavailable handler */
#endif
- case BOOK3S_INTERRUPT_H_FAC_UNAVAIL: {
- u64 cause = vcpu->arch.hfscr >> 56;
-
- /*
- * Only pass HFU interrupts to the L1 if the facility is
- * permitted but disabled by the L1's HFSCR, otherwise
- * the interrupt does not make sense to the L1 so turn
- * it into a HEAI.
- */
- if (!(vcpu->arch.hfscr_permitted & (1UL << cause)) ||
- (vcpu->arch.nested_hfscr & (1UL << cause))) {
- ppc_inst_t pinst;
- vcpu->arch.trap = BOOK3S_INTERRUPT_H_EMUL_ASSIST;
-
- /*
- * If the fetch failed, return to guest and
- * try executing it again.
- */
- r = kvmppc_get_last_inst(vcpu, INST_GENERIC, &pinst);
- vcpu->arch.emul_inst = ppc_inst_val(pinst);
- if (r != EMULATE_DONE)
- r = RESUME_GUEST;
- else
- r = RESUME_HOST;
- } else {
- r = RESUME_HOST;
- }
-
+ case BOOK3S_INTERRUPT_H_FAC_UNAVAIL:
+ r = RESUME_HOST;
break;
- }
case BOOK3S_INTERRUPT_HV_RM_HARD:
vcpu->arch.trap = 0;
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests
2024-11-09 6:32 [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Gautam Menghani
2024-11-09 6:32 ` [PATCH 1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1" Gautam Menghani
@ 2024-11-09 6:32 ` Gautam Menghani
2024-11-09 6:32 ` [PATCH 3/3] KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending doorbells Gautam Menghani
2024-11-17 11:56 ` [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Michael Ellerman
3 siblings, 0 replies; 5+ messages in thread
From: Gautam Menghani @ 2024-11-09 6:32 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, naveen, maddy, vaibhav
Cc: Gautam Menghani, linuxppc-dev, kvm, linux-kernel
commit 6398326b9ba1 ("KVM: PPC: Book3S HV P9: Stop using vc->dpdes")
introduced an optimization to use only vcpu->doorbell_request for SMT
emulation for Power9 and above guests, but the code for nested guests
still relies on the old way of handling doorbells, due to which an L2
guest (see [1]) cannot be booted with XICS with SMT>1. The command to
repro this issue is:
// To be run in L1
qemu-system-ppc64 \
-drive file=rhel.qcow2,format=qcow2 \
-m 20G \
-smp 8,cores=1,threads=8 \
-cpu host \
-nographic \
-machine pseries,ic-mode=xics -accel kvm
Fix the plumbing to utilize vcpu->doorbell_request instead of vcore->dpdes
for nested KVM guests on P9 and above.
[1] Terminology
1. L0 : PowerNV linux running with HV privileges
2. L1 : Pseries KVM guest running on top of L0
2. L2 : Nested KVM guest running on top of L1
Fixes: 6398326b9ba1 ("KVM: PPC: Book3S HV P9: Stop using vc->dpdes")
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
arch/powerpc/kvm/book3s_hv.c | 9 +++++++++
arch/powerpc/kvm/book3s_hv_nested.c | 14 ++++++++++----
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 0a8f143e0a75..b93a93777237 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -4282,6 +4282,15 @@ static int kvmhv_vcpu_entry_p9_nested(struct kvm_vcpu *vcpu, u64 time_limit, uns
}
hvregs.hdec_expiry = time_limit;
+ /*
+ * hvregs has the doorbell status, so zero it here which
+ * enables us to receive doorbells when H_ENTER_NESTED is
+ * in progress for this vCPU
+ */
+
+ if (vcpu->arch.doorbell_request)
+ vcpu->arch.doorbell_request = 0;
+
/*
* When setting DEC, we must always deal with irq_work_raise
* via NMI vs setting DEC. The problem occurs right as we
diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
index 05f5220960c6..125440a606ee 100644
--- a/arch/powerpc/kvm/book3s_hv_nested.c
+++ b/arch/powerpc/kvm/book3s_hv_nested.c
@@ -32,7 +32,7 @@ void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
struct kvmppc_vcore *vc = vcpu->arch.vcore;
hr->pcr = vc->pcr | PCR_MASK;
- hr->dpdes = vc->dpdes;
+ hr->dpdes = vcpu->arch.doorbell_request;
hr->hfscr = vcpu->arch.hfscr;
hr->tb_offset = vc->tb_offset;
hr->dawr0 = vcpu->arch.dawr0;
@@ -105,7 +105,7 @@ static void save_hv_return_state(struct kvm_vcpu *vcpu,
{
struct kvmppc_vcore *vc = vcpu->arch.vcore;
- hr->dpdes = vc->dpdes;
+ hr->dpdes = vcpu->arch.doorbell_request;
hr->purr = vcpu->arch.purr;
hr->spurr = vcpu->arch.spurr;
hr->ic = vcpu->arch.ic;
@@ -143,7 +143,7 @@ static void restore_hv_regs(struct kvm_vcpu *vcpu, const struct hv_guest_state *
struct kvmppc_vcore *vc = vcpu->arch.vcore;
vc->pcr = hr->pcr | PCR_MASK;
- vc->dpdes = hr->dpdes;
+ vcpu->arch.doorbell_request = hr->dpdes;
vcpu->arch.hfscr = hr->hfscr;
vcpu->arch.dawr0 = hr->dawr0;
vcpu->arch.dawrx0 = hr->dawrx0;
@@ -170,7 +170,13 @@ void kvmhv_restore_hv_return_state(struct kvm_vcpu *vcpu,
{
struct kvmppc_vcore *vc = vcpu->arch.vcore;
- vc->dpdes = hr->dpdes;
+ /*
+ * This L2 vCPU might have received a doorbell while H_ENTER_NESTED was being handled.
+ * Make sure we preserve the doorbell if it was either:
+ * a) Sent after H_ENTER_NESTED was called on this vCPU (arch.doorbell_request would be 1)
+ * b) Doorbell was not handled and L2 exited for some other reason (hr->dpdes would be 1)
+ */
+ vcpu->arch.doorbell_request = vcpu->arch.doorbell_request | hr->dpdes;
vcpu->arch.hfscr = hr->hfscr;
vcpu->arch.purr = hr->purr;
vcpu->arch.spurr = hr->spurr;
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending doorbells
2024-11-09 6:32 [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Gautam Menghani
2024-11-09 6:32 ` [PATCH 1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1" Gautam Menghani
2024-11-09 6:32 ` [PATCH 2/3] KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests Gautam Menghani
@ 2024-11-09 6:32 ` Gautam Menghani
2024-11-17 11:56 ` [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Michael Ellerman
3 siblings, 0 replies; 5+ messages in thread
From: Gautam Menghani @ 2024-11-09 6:32 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, naveen, maddy, vaibhav
Cc: Gautam Menghani, linuxppc-dev, kvm, linux-kernel
Commit 6398326b9ba1 ("KVM: PPC: Book3S HV P9: Stop using vc->dpdes")
dropped the use of vcore->dpdes for msgsndp / SMT emulation. Prior to that
commit, the below code at L1 level (see [1] for terminology) was
responsible for setting vc->dpdes for the respective L2 vCPU:
if (!nested) {
kvmppc_core_prepare_to_enter(vcpu);
if (vcpu->arch.doorbell_request) {
vc->dpdes = 1;
smp_wmb();
vcpu->arch.doorbell_request = 0;
}
L1 then sent vc->dpdes to L0 via kvmhv_save_hv_regs(), and while
servicing H_ENTER_NESTED at L0, the below condition at L0 level made sure
to abort and go back to L1 if vcpu->arch.doorbell_request = 1 so that L1
sets vc->dpdes as per above if condition:
} else if (vcpu->arch.pending_exceptions ||
vcpu->arch.doorbell_request ||
xive_interrupt_pending(vcpu)) {
vcpu->arch.ret = RESUME_HOST;
goto out;
}
This worked fine since vcpu->arch.doorbell_request was used more like a
flag and vc->dpdes was used to pass around the doorbell state. But after
Commit 6398326b9ba1 ("KVM: PPC: Book3S HV P9: Stop using vc->dpdes"),
vcpu->arch.doorbell_request is the only variable used to pass around
doorbell state.
With the plumbing for handling doorbells for nested guests updated to use
vcpu->arch.doorbell_request over vc->dpdes, the above "else if" stops
doorbells from working correctly as L0 aborts execution of L2 and
instead goes back to L1.
Remove vcpu->arch.doorbell_request from the above "else if" condition as
it is no longer needed for L0 to correctly handle the doorbell status
while running L2.
[1] Terminology
1. L0 : PowerNV linux running with HV privileges
2. L1 : Pseries KVM guest running on top of L0
2. L2 : Nested KVM guest running on top of L1
Fixes: 6398326b9ba1 ("KVM: PPC: Book3S HV P9: Stop using vc->dpdes")
Signed-off-by: Gautam Menghani <gautam@linux.ibm.com>
---
arch/powerpc/kvm/book3s_hv.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index b93a93777237..8385d4db1763 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -4894,7 +4894,6 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,
lpcr &= ~LPCR_MER;
}
} else if (vcpu->arch.pending_exceptions ||
- vcpu->arch.doorbell_request ||
xive_interrupt_pending(vcpu)) {
vcpu->arch.ret = RESUME_HOST;
goto out;
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API
2024-11-09 6:32 [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Gautam Menghani
` (2 preceding siblings ...)
2024-11-09 6:32 ` [PATCH 3/3] KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending doorbells Gautam Menghani
@ 2024-11-17 11:56 ` Michael Ellerman
3 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2024-11-17 11:56 UTC (permalink / raw)
To: mpe, npiggin, christophe.leroy, naveen, maddy, vaibhav,
Gautam Menghani
Cc: linuxppc-dev, kvm, linux-kernel
On Sat, 09 Nov 2024 12:02:54 +0530, Gautam Menghani wrote:
> Doorbell emulation for nested KVM guests in V1 API is broken because of
> 2 reasons:
> 1. L0 presenting H_EMUL_ASSIST to L1 instead of H_FAC_UNAVAIL
> 2. Broken plumbing for passing around doorbell state.
>
> Fix the trap passed to L1 and the plumbing for maintaining doorbell
> state.
>
> [...]
Applied to powerpc/topic/ppc-kvm.
[1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1"
https://git.kernel.org/powerpc/c/ed351c57432122c4499be4f4aee8711d6fa93f3b
[2/3] KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests
https://git.kernel.org/powerpc/c/0d3c6b28896f9889c8864dab469e0343a0ad1c0c
[3/3] KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending doorbells
https://git.kernel.org/powerpc/c/26686db69917399fa30e3b3135360771e90f83ec
cheers
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-17 12:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-09 6:32 [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Gautam Menghani
2024-11-09 6:32 ` [PATCH 1/3] Revert "KVM: PPC: Book3S HV Nested: Stop forwarding all HFUs to L1" Gautam Menghani
2024-11-09 6:32 ` [PATCH 2/3] KVM: PPC: Book3S HV: Stop using vc->dpdes for nested KVM guests Gautam Menghani
2024-11-09 6:32 ` [PATCH 3/3] KVM: PPC: Book3S HV: Avoid returning to nested hypervisor on pending doorbells Gautam Menghani
2024-11-17 11:56 ` [PATCH 0/3] Fix doorbell emulation for nested KVM guests in V1 API Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).