* FAILED: patch "[PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to" failed to apply to 5.12-stable tree
@ 2021-05-30 10:46 gregkh
2021-05-31 10:52 ` Zenghui Yu
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2021-05-30 10:46 UTC (permalink / raw)
To: maz, alexandru.elisei, yuzenghui; +Cc: stable
The patch below does not apply to the 5.12-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 26778aaa134a9aefdf5dbaad904054d7be9d656d Mon Sep 17 00:00:00 2001
From: Marc Zyngier <maz@kernel.org>
Date: Thu, 6 May 2021 15:20:12 +0100
Subject: [PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to
userspace
KVM currently updates PC (and the corresponding exception state)
using a two phase approach: first by setting a set of flags,
then by converting these flags into a state update when the vcpu
is about to enter the guest.
However, this creates a disconnect with userspace if the vcpu thread
returns there with any exception/PC flag set. In this case, the exposed
context is wrong, as userspace doesn't have access to these flags
(they aren't architectural). It also means that these flags are
preserved across a reset, which isn't expected.
To solve this problem, force an explicit synchronisation of the
exception state on vcpu exit to userspace. As an optimisation
for nVHE systems, only perform this when there is something pending.
Reported-by: Zenghui Yu <yuzenghui@huawei.com>
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Reviewed-by: Zenghui Yu <yuzenghui@huawei.com>
Tested-by: Zenghui Yu <yuzenghui@huawei.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org # 5.11
diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index d5b11037401d..5e9b33cbac51 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -63,6 +63,7 @@
#define __KVM_HOST_SMCCC_FUNC___pkvm_cpu_set_vector 18
#define __KVM_HOST_SMCCC_FUNC___pkvm_prot_finalize 19
#define __KVM_HOST_SMCCC_FUNC___pkvm_mark_hyp 20
+#define __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc 21
#ifndef __ASSEMBLY__
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 1cb39c0803a4..1126eae27400 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -897,6 +897,17 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
kvm_sigset_deactivate(vcpu);
+ /*
+ * In the unlikely event that we are returning to userspace
+ * with pending exceptions or PC adjustment, commit these
+ * adjustments in order to give userspace a consistent view of
+ * the vcpu state. Note that this relies on __kvm_adjust_pc()
+ * being preempt-safe on VHE.
+ */
+ if (unlikely(vcpu->arch.flags & (KVM_ARM64_PENDING_EXCEPTION |
+ KVM_ARM64_INCREMENT_PC)))
+ kvm_call_hyp(__kvm_adjust_pc, vcpu);
+
vcpu_put(vcpu);
return ret;
}
diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c
index 0812a496725f..11541b94b328 100644
--- a/arch/arm64/kvm/hyp/exception.c
+++ b/arch/arm64/kvm/hyp/exception.c
@@ -331,8 +331,8 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu)
}
/*
- * Adjust the guest PC on entry, depending on flags provided by EL1
- * for the purpose of emulation (MMIO, sysreg) or exception injection.
+ * Adjust the guest PC (and potentially exception state) depending on
+ * flags provided by the emulation code.
*/
void __kvm_adjust_pc(struct kvm_vcpu *vcpu)
{
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index f36420a80474..1632f001f4ed 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -28,6 +28,13 @@ static void handle___kvm_vcpu_run(struct kvm_cpu_context *host_ctxt)
cpu_reg(host_ctxt, 1) = __kvm_vcpu_run(kern_hyp_va(vcpu));
}
+static void handle___kvm_adjust_pc(struct kvm_cpu_context *host_ctxt)
+{
+ DECLARE_REG(struct kvm_vcpu *, vcpu, host_ctxt, 1);
+
+ __kvm_adjust_pc(kern_hyp_va(vcpu));
+}
+
static void handle___kvm_flush_vm_context(struct kvm_cpu_context *host_ctxt)
{
__kvm_flush_vm_context();
@@ -170,6 +177,7 @@ typedef void (*hcall_t)(struct kvm_cpu_context *);
static const hcall_t host_hcall[] = {
HANDLE_FUNC(__kvm_vcpu_run),
+ HANDLE_FUNC(__kvm_adjust_pc),
HANDLE_FUNC(__kvm_flush_vm_context),
HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa),
HANDLE_FUNC(__kvm_tlb_flush_vmid),
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: FAILED: patch "[PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to" failed to apply to 5.12-stable tree
2021-05-30 10:46 FAILED: patch "[PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to" failed to apply to 5.12-stable tree gregkh
@ 2021-05-31 10:52 ` Zenghui Yu
2021-05-31 11:48 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Zenghui Yu @ 2021-05-31 10:52 UTC (permalink / raw)
To: gregkh, maz, alexandru.elisei; +Cc: stable
Hi Greg,
On 2021/5/30 18:46, gregkh@linuxfoundation.org wrote:
>
> The patch below does not apply to the 5.12-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
Indeed this patch should be applied to the 5.12-stable tree, together
with other 2 patches, in order.
[1/3] f5e30680616a ("KVM: arm64: Move __adjust_pc out of line")
[2/3] 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before
returning to userspace")
[3/3] e3e880bb1518 ("KVM: arm64: Resolve all pending PC updates before
immediate exit")
Patch #1 has been applied cleanly onto linux-stable-rc/linux-5.12.y.
It's just fine. It's expected that there's no functional change with
patch #1.
Patch #2 (this patch) can be applied by manually resolving the conflict.
I can send a patch for it if Marc doesn't get enough bandwidth.
Patch #3 has been applied in a wrong way [*]. I'll reply to it so that
you can drop it from the current stable queue.
Thanks,
Zenghui
[*] https://www.spinics.net/lists/stable-commits/msg200513.html
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: FAILED: patch "[PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to" failed to apply to 5.12-stable tree
2021-05-31 10:52 ` Zenghui Yu
@ 2021-05-31 11:48 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2021-05-31 11:48 UTC (permalink / raw)
To: Zenghui Yu; +Cc: maz, alexandru.elisei, stable
On Mon, May 31, 2021 at 06:52:49PM +0800, Zenghui Yu wrote:
> Hi Greg,
>
> On 2021/5/30 18:46, gregkh@linuxfoundation.org wrote:
> >
> > The patch below does not apply to the 5.12-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
>
> Indeed this patch should be applied to the 5.12-stable tree, together
> with other 2 patches, in order.
>
> [1/3] f5e30680616a ("KVM: arm64: Move __adjust_pc out of line")
> [2/3] 26778aaa134a ("KVM: arm64: Commit pending PC adjustemnts before
> returning to userspace")
> [3/3] e3e880bb1518 ("KVM: arm64: Resolve all pending PC updates before
> immediate exit")
>
> Patch #1 has been applied cleanly onto linux-stable-rc/linux-5.12.y.
> It's just fine. It's expected that there's no functional change with
> patch #1.
That's already in the queue.
> Patch #2 (this patch) can be applied by manually resolving the conflict.
> I can send a patch for it if Marc doesn't get enough bandwidth.
I need a resolution, I couldn't figure out where to put the change in
arch/arm64/include/asm/kvm_asm.h at.
> Patch #3 has been applied in a wrong way [*]. I'll reply to it so that
> you can drop it from the current stable queue.
Ok, will go drop that one right now, thanks!
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-31 11:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-30 10:46 FAILED: patch "[PATCH] KVM: arm64: Commit pending PC adjustemnts before returning to" failed to apply to 5.12-stable tree gregkh
2021-05-31 10:52 ` Zenghui Yu
2021-05-31 11:48 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.