2021-06-01 14:09:54

by Zenghui Yu

[permalink] [raw]
Subject: [PATCH v2 stable-5.12.y backport 0/2] KVM: arm64: Commit exception state on exit to userspace

As promised on the list [0], this series aims to backport 3 upstream
commits [1,2,3] into 5.12-stable tree.

Patch #1 is already in the queue and therefore not included. Patch #2 can
be applied now by manually adding the __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc
macro (please review). Patch #3 can be applied cleanly then (after #2).

I've slightly tested it on my 920 (boot test and the whole kvm-unit-tests),
on top of the latest linux-stable-rc/linux-5.12.y. Please consider taking
them for 5.12-stable.

* From v1:
- Allocate a new number for __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc
- Collect Marc's R-b tags

[0] https://lore.kernel.org/r/[email protected]
[1] https://git.kernel.org/torvalds/c/f5e30680616a
[2] https://git.kernel.org/torvalds/c/26778aaa134a
[3] https://git.kernel.org/torvalds/c/e3e880bb1518

Marc Zyngier (1):
KVM: arm64: Commit pending PC adjustemnts before returning to
userspace

Zenghui Yu (1):
KVM: arm64: Resolve all pending PC updates before immediate exit

arch/arm64/include/asm/kvm_asm.h | 1 +
arch/arm64/kvm/arm.c | 20 +++++++++++++++++---
arch/arm64/kvm/hyp/exception.c | 4 ++--
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++++++
4 files changed, 28 insertions(+), 5 deletions(-)

--
2.19.1


2021-06-01 14:10:15

by Zenghui Yu

[permalink] [raw]
Subject: [PATCH v2 stable-5.12.y backport 2/2] KVM: arm64: Resolve all pending PC updates before immediate exit

commit e3e880bb1518eb10a4b4bb4344ed614d6856f190 upstream.

Commit 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before
returning to userspace") fixed the PC updating issue by forcing an explicit
synchronisation of the exception state on vcpu exit to userspace.

However, we forgot to take into account the case where immediate_exit is
set by userspace and KVM_RUN will exit immediately. Fix it by resolving all
pending PC updates before returning to userspace.

Since __kvm_adjust_pc() relies on a loaded vcpu context, I moved the
immediate_exit checking right after vcpu_load(). We will get some overhead
if immediate_exit is true (which should hopefully be rare).

Fixes: 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before returning to userspace")
Signed-off-by: Zenghui Yu <[email protected]>
Signed-off-by: Marc Zyngier <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Cc: [email protected] # 5.11
[yuz: stable-5.12.y backport]
Signed-off-by: Zenghui Yu <[email protected]>
Reviewed-by: Marc Zyngier <[email protected]>
---
arch/arm64/kvm/arm.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index c18740a1e541..7730b81aad6d 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -715,11 +715,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
return ret;
}

- if (run->immediate_exit)
- return -EINTR;
-
vcpu_load(vcpu);

+ if (run->immediate_exit) {
+ ret = -EINTR;
+ goto out;
+ }
+
kvm_sigset_activate(vcpu);

ret = 1;
@@ -892,6 +894,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)

kvm_sigset_deactivate(vcpu);

+out:
/*
* In the unlikely event that we are returning to userspace
* with pending exceptions or PC adjustment, commit these
--
2.19.1

2021-06-09 04:30:55

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 stable-5.12.y backport 0/2] KVM: arm64: Commit exception state on exit to userspace

On Tue, Jun 01, 2021 at 10:07:36PM +0800, Zenghui Yu wrote:
> As promised on the list [0], this series aims to backport 3 upstream
> commits [1,2,3] into 5.12-stable tree.
>
> Patch #1 is already in the queue and therefore not included. Patch #2 can
> be applied now by manually adding the __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc
> macro (please review). Patch #3 can be applied cleanly then (after #2).
>
> I've slightly tested it on my 920 (boot test and the whole kvm-unit-tests),
> on top of the latest linux-stable-rc/linux-5.12.y. Please consider taking
> them for 5.12-stable.
>
> * From v1:
> - Allocate a new number for __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc
> - Collect Marc's R-b tags
>
> [0] https://lore.kernel.org/r/[email protected]
> [1] https://git.kernel.org/torvalds/c/f5e30680616a
> [2] https://git.kernel.org/torvalds/c/26778aaa134a
> [3] https://git.kernel.org/torvalds/c/e3e880bb1518
>
> Marc Zyngier (1):
> KVM: arm64: Commit pending PC adjustemnts before returning to
> userspace
>
> Zenghui Yu (1):
> KVM: arm64: Resolve all pending PC updates before immediate exit
>
> arch/arm64/include/asm/kvm_asm.h | 1 +
> arch/arm64/kvm/arm.c | 20 +++++++++++++++++---
> arch/arm64/kvm/hyp/exception.c | 4 ++--
> arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 ++++++++
> 4 files changed, 28 insertions(+), 5 deletions(-)
>
> --
> 2.19.1
>

All now queued up, thanks.,

greg k-h