KVM ARM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling
@ 2020-07-29 10:28 Will Deacon
  2020-07-29 10:28 ` [PATCH v2 1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt() Will Deacon
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Will Deacon @ 2020-07-29 10:28 UTC (permalink / raw)
  To: kvmarm; +Cc: kernel-team, Will Deacon, linux-arm-kernel

Hi all,

This is version two of the patches I posted last week:

  https://lore.kernel.org/r/20200724143506.17772-1-will@kernel.org

I got my brain in a twist with exactly what is reported in HPFAR for
a stage-2 abort on a stage-1 table walk, so I don't think any of these
are serious any more.

With these changes, the early stage-2 fault handling follows:

S2 instruction abort:
  * Not in memslot, or S2 fault on S1 walk for tables in R/O memslot:
	=> inject external iabt to guest

S2 data abort:
  * Not in memslot:
    - S2 fault on S1 walk:      inject external dabt to guest
    - Cache maintenance:        skip instr
    - Syndrome valid            EXIT_MMIO
    - Syndrome invalid          EXIT_NISV
  * Write fault in R/O memslot:
    - S2 fault on S1 walk:      inject external dabt to guest
    - Access is write:
      - Syndrome valid          EXIT_MMIO
      - Syndrome invalid        EXIT_NISV (includes cache maintenance)

Everything else gets handled by handle_access_fault()/user_mem_abort().

Will

Cc: James Morse <james.morse@arm.com>
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: kernel-team@android.com

--->8

Will Deacon (4):
  KVM: arm64: Rename kvm_vcpu_dabt_isextabt()
  KVM: arm64: Handle data and instruction external aborts the same way
  KVM: arm64: Don't skip cache maintenance for read-only memslots
  KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort()

 arch/arm64/include/asm/kvm_emulate.h |  2 +-
 arch/arm64/kvm/hyp/switch.c          |  2 +-
 arch/arm64/kvm/mmio.c                |  6 ------
 arch/arm64/kvm/mmu.c                 | 26 +++++++++++++++++---------
 4 files changed, 19 insertions(+), 17 deletions(-)

-- 
2.28.0.rc0.142.g3c755180ce-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt()
  2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
@ 2020-07-29 10:28 ` Will Deacon
  2020-07-29 10:28 ` [PATCH v2 2/4] KVM: arm64: Handle data and instruction external aborts the same way Will Deacon
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2020-07-29 10:28 UTC (permalink / raw)
  To: kvmarm; +Cc: Will Deacon, Marc Zyngier, kernel-team, linux-arm-kernel

kvm_vcpu_dabt_isextabt() is not specific to data aborts and, unlike
kvm_vcpu_dabt_issext(), has nothing to do with sign extension.

Rename it to 'kvm_vcpu_abt_issea()'.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/include/asm/kvm_emulate.h | 2 +-
 arch/arm64/kvm/hyp/switch.c          | 2 +-
 arch/arm64/kvm/mmu.c                 | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 4d0f8ea600ba..26eabf987e71 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -366,7 +366,7 @@ static __always_inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vc
 	return kvm_vcpu_get_hsr(vcpu) & ESR_ELx_FSC_TYPE;
 }
 
-static __always_inline bool kvm_vcpu_dabt_isextabt(const struct kvm_vcpu *vcpu)
+static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu)
 {
 	switch (kvm_vcpu_trap_get_fault(vcpu)) {
 	case FSC_SEA:
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index db1c4487d95d..72459d955799 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -594,7 +594,7 @@ static bool __hyp_text fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
 		valid = kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_DABT_LOW &&
 			kvm_vcpu_trap_get_fault_type(vcpu) == FSC_FAULT &&
 			kvm_vcpu_dabt_isvalid(vcpu) &&
-			!kvm_vcpu_dabt_isextabt(vcpu) &&
+			!kvm_vcpu_abt_issea(vcpu) &&
 			!kvm_vcpu_dabt_iss1tw(vcpu);
 
 		if (valid) {
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index df2a8025ec8a..97394d56a5a9 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2074,7 +2074,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	is_iabt = kvm_vcpu_trap_is_iabt(vcpu);
 
 	/* Synchronous External Abort? */
-	if (kvm_vcpu_dabt_isextabt(vcpu)) {
+	if (kvm_vcpu_abt_issea(vcpu)) {
 		/*
 		 * For RAS the host kernel may handle this abort.
 		 * There is no need to pass the error into the guest.
-- 
2.28.0.rc0.142.g3c755180ce-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] KVM: arm64: Handle data and instruction external aborts the same way
  2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
  2020-07-29 10:28 ` [PATCH v2 1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt() Will Deacon
@ 2020-07-29 10:28 ` Will Deacon
  2020-07-29 10:28 ` [PATCH v2 3/4] KVM: arm64: Don't skip cache maintenance for read-only memslots Will Deacon
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2020-07-29 10:28 UTC (permalink / raw)
  To: kvmarm; +Cc: Will Deacon, Marc Zyngier, kernel-team, linux-arm-kernel

If the guest generates a synchronous external abort which is not handled
by the host, we inject it back into the guest as a virtual SError, but
only if the original fault was reported on the data side. Instruction
faults are reported as "Unsupported FSC", causing the vCPU run loop to
bail with -EFAULT.

Although synchronous external aborts from a guest are pretty unusual,
treat them the same regardless of whether they are taken as data or
instruction aborts by EL2.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/kvm/mmu.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 97394d56a5a9..96d995a1ef68 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2079,13 +2079,10 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		 * For RAS the host kernel may handle this abort.
 		 * There is no need to pass the error into the guest.
 		 */
-		if (!kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu)))
-			return 1;
-
-		if (unlikely(!is_iabt)) {
+		if (kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu)))
 			kvm_inject_vabt(vcpu);
-			return 1;
-		}
+
+		return 1;
 	}
 
 	trace_kvm_guest_fault(*vcpu_pc(vcpu), kvm_vcpu_get_hsr(vcpu),
-- 
2.28.0.rc0.142.g3c755180ce-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] KVM: arm64: Don't skip cache maintenance for read-only memslots
  2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
  2020-07-29 10:28 ` [PATCH v2 1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt() Will Deacon
  2020-07-29 10:28 ` [PATCH v2 2/4] KVM: arm64: Handle data and instruction external aborts the same way Will Deacon
@ 2020-07-29 10:28 ` Will Deacon
  2020-07-29 10:28 ` [PATCH v2 4/4] KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort() Will Deacon
  2020-07-30 15:06 ` [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Marc Zyngier
  4 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2020-07-29 10:28 UTC (permalink / raw)
  To: kvmarm; +Cc: Will Deacon, Marc Zyngier, kernel-team, linux-arm-kernel

If a guest performs cache maintenance on a read-only memslot, we should
inform userspace rather than skip the instruction altogether.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/kvm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 96d995a1ef68..4150bce3d0b6 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2121,7 +2121,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		 * So let's assume that the guest is just being
 		 * cautious, and skip the instruction.
 		 */
-		if (kvm_vcpu_dabt_is_cm(vcpu)) {
+		if (kvm_is_error_hva(hva) && kvm_vcpu_dabt_is_cm(vcpu)) {
 			kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu));
 			ret = 1;
 			goto out_unlock;
-- 
2.28.0.rc0.142.g3c755180ce-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort()
  2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
                   ` (2 preceding siblings ...)
  2020-07-29 10:28 ` [PATCH v2 3/4] KVM: arm64: Don't skip cache maintenance for read-only memslots Will Deacon
@ 2020-07-29 10:28 ` Will Deacon
  2020-07-30 15:06 ` [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Marc Zyngier
  4 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2020-07-29 10:28 UTC (permalink / raw)
  To: kvmarm; +Cc: Will Deacon, Marc Zyngier, kernel-team, linux-arm-kernel

To allow for re-injection of stage-2 faults on stage-1 page-table walks
due to either a missing or read-only memslot, move the triage logic out
of io_mem_abort() and into kvm_handle_guest_abort(), where these aborts
can be handled before anything else.

Cc: Marc Zyngier <maz@kernel.org>
Cc: Quentin Perret <qperret@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/kvm/mmio.c |  6 ------
 arch/arm64/kvm/mmu.c  | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/kvm/mmio.c b/arch/arm64/kvm/mmio.c
index 4e0366759726..58de2ae4f6bb 100644
--- a/arch/arm64/kvm/mmio.c
+++ b/arch/arm64/kvm/mmio.c
@@ -145,12 +145,6 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
 		return -ENOSYS;
 	}
 
-	/* Page table accesses IO mem: tell guest to fix its TTBR */
-	if (kvm_vcpu_dabt_iss1tw(vcpu)) {
-		kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
-		return 1;
-	}
-
 	/*
 	 * Prepare MMIO operation. First decode the syndrome data we get
 	 * from the CPU. Then try if some in-kernel emulation feels
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 4150bce3d0b6..9f5fde1243d4 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2105,12 +2105,23 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	hva = gfn_to_hva_memslot_prot(memslot, gfn, &writable);
 	write_fault = kvm_is_write_fault(vcpu);
 	if (kvm_is_error_hva(hva) || (write_fault && !writable)) {
+		/*
+		 * The guest has put either its instructions or its page-tables
+		 * somewhere it shouldn't have. Userspace won't be able to do
+		 * anything about this (there's no syndrome for a start), so
+		 * re-inject the abort back into the guest.
+		 */
 		if (is_iabt) {
-			/* Prefetch Abort on I/O address */
 			ret = -ENOEXEC;
 			goto out;
 		}
 
+		if (kvm_vcpu_dabt_iss1tw(vcpu)) {
+			kvm_inject_dabt(vcpu, kvm_vcpu_get_hfar(vcpu));
+			ret = 1;
+			goto out_unlock;
+		}
+
 		/*
 		 * Check for a cache maintenance operation. Since we
 		 * ended-up here, we know it is outside of any memory
-- 
2.28.0.rc0.142.g3c755180ce-goog

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling
  2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
                   ` (3 preceding siblings ...)
  2020-07-29 10:28 ` [PATCH v2 4/4] KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort() Will Deacon
@ 2020-07-30 15:06 ` Marc Zyngier
  4 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2020-07-30 15:06 UTC (permalink / raw)
  To: Will Deacon, kvmarm; +Cc: kernel-team, linux-arm-kernel

On Wed, 29 Jul 2020 11:28:17 +0100, Will Deacon wrote:
> This is version two of the patches I posted last week:
> 
>   https://lore.kernel.org/r/20200724143506.17772-1-will@kernel.org
> 
> I got my brain in a twist with exactly what is reported in HPFAR for
> a stage-2 abort on a stage-1 table walk, so I don't think any of these
> are serious any more.
> 
> [...]

Applied to kvm-arm64/misc-5.9, thanks!

[1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt()
      commit: c9a636f29b5f236441ff059cef0b2fe734c05afd
[2/4] KVM: arm64: Handle data and instruction external aborts the same way
      commit: 84b951a803a5464b0bff2fb1366e96f07f75b066
[3/4] KVM: arm64: Don't skip cache maintenance for read-only memslots
      commit: 54dc0d2404dd7aa0dd4e4f388a65622b68c6eaff
[4/4] KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort()
      commit: 022c8328dc8021248047b373b9f67790641b8f2d

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 10:28 [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Will Deacon
2020-07-29 10:28 ` [PATCH v2 1/4] KVM: arm64: Rename kvm_vcpu_dabt_isextabt() Will Deacon
2020-07-29 10:28 ` [PATCH v2 2/4] KVM: arm64: Handle data and instruction external aborts the same way Will Deacon
2020-07-29 10:28 ` [PATCH v2 3/4] KVM: arm64: Don't skip cache maintenance for read-only memslots Will Deacon
2020-07-29 10:28 ` [PATCH v2 4/4] KVM: arm64: Move S1PTW S2 fault logic out of io_mem_abort() Will Deacon
2020-07-30 15:06 ` [PATCH v2 0/4] KVM: arm64: Fixes to early stage-2 fault handling Marc Zyngier

KVM ARM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvmarm/0 kvmarm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvmarm kvmarm/ https://lore.kernel.org/kvmarm \
		kvmarm@lists.cs.columbia.edu
	public-inbox-index kvmarm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/edu.columbia.cs.lists.kvmarm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git