Skip to contentSkip to conversation

KVM: arm64: Use generic guest entry infrastructure

PATCH Applied Oliver Upton 2 participants 7 messages Aug 2, 2021 – Aug 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover KVM: arm64: Use generic guest entry infrastructure

The arm64 kernel doesn't yet support the full generic entry infrastructure. That being said, KVM/arm64 doesn't properly handle TIF_NOTIFY_RESUME and could pick this up by switching to the generic guest entry infrasturture.

Patch 1 adds a missing vCPU stat to ARM64 to record the number of signal exits to userspace.

Patch 2 unhitches entry-kvm from entry-generic, as ARM64 doesn't currently support the generic infrastructure.

Patch 3 replaces the open-coded entry handling with the generic xfer function.

This series was tested on an Ampere Mt. Jade reference system. The series cleanly applies to kvm/queue (note that this is deliberate as the generic kvm stats patches have not yet propagated to kvm-arm/queue) at the following commit:

8ad5e63649ff ("KVM: Don't take mmu_lock for range invalidation unless necessary")

v1 -> v2:
- Address Jing's comment
- Carry Jing's r-b tag

v2 -> v3:
- Roll all exit conditions into kvm_vcpu_exit_request() (Marc)
- Avoid needlessly checking for work twice (Marc)

v1: http://lore.kernel.org/r/[email protected]
v2: http://lore.kernel.org/r/[email protected]

Oliver Upton (3):
KVM: arm64: Record number of signal exits as a vCPU stat
entry: KVM: Allow use of generic KVM entry w/o full generic support
KVM: arm64: Use generic KVM xfer to guest work function

 arch/arm64/include/asm/kvm_host.h |  1 +
 arch/arm64/kvm/Kconfig            |  1 +
 arch/arm64/kvm/arm.c              | 71 +++++++++++++++++++------------
 arch/arm64/kvm/guest.c            |  1 +
 include/linux/entry-kvm.h         |  6 ++-
 5 files changed, 52 insertions(+), 28 deletions(-)
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
#1 lore raw

PATCH v3 1/3 KVM: arm64: Record number of signal exits as a vCPU stat

Most other architectures that implement KVM record a statistic indicating the number of times a vCPU has exited due to a pending signal. Add support for that stat to arm64.

---
 arch/arm64/include/asm/kvm_host.h | 1 +
 arch/arm64/kvm/arm.c              | 1 +
 arch/arm64/kvm/guest.c            | 1 +
 3 files changed, 3 insertions(+)
arch/arm64/include/asm/kvm_host.h +1 -0
index 41911585ae0c..70e129f2b574 100644
@@ -576,6 +576,7 @@ struct kvm_vcpu_stat {
 	u64 wfi_exit_stat;
 	u64 mmio_exit_user;
 	u64 mmio_exit_kernel;
+	u64 signal_exits;
 	u64 exits;
 };
 
arch/arm64/kvm/arm.c +1 -0
index e9a2b8f27792..60d0a546d7fd 100644
@@ -783,6 +783,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		if (signal_pending(current)) {
 			ret = -EINTR;
 			run->exit_reason = KVM_EXIT_INTR;
+			++vcpu->stat.signal_exits;
 		}
 
 		/*
arch/arm64/kvm/guest.c +1 -0
index 1dfb83578277..853d1e8d2e73 100644
@@ -50,6 +50,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
 	STATS_DESC_COUNTER(VCPU, wfi_exit_stat),
 	STATS_DESC_COUNTER(VCPU, mmio_exit_user),
 	STATS_DESC_COUNTER(VCPU, mmio_exit_kernel),
+	STATS_DESC_COUNTER(VCPU, signal_exits),
 	STATS_DESC_COUNTER(VCPU, exits)
 };
 static_assert(ARRAY_SIZE(kvm_vcpu_stats_desc) ==
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
#2 lore raw

PATCH v3 2/3 entry: KVM: Allow use of generic KVM entry w/o full generic support

In reply to Oliver Upton

Some architectures (e.g. arm64) have yet to adopt the generic entry infrastructure. Despite that, it would be nice to use some common plumbing for guest entry/exit handling. For example, KVM/arm64 currently does not handle TIF_NOTIFY_PENDING correctly.

Allow use of only the generic KVM entry code by tightening up the include list. No functional change intended.

---
 include/linux/entry-kvm.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/entry-kvm.h +5 -1
index 136b8d97d8c0..0d7865a0731c 100644
@@ -2,7 +2,11 @@
 #ifndef __LINUX_ENTRYKVM_H
 #define __LINUX_ENTRYKVM_H
 
-#include <linux/entry-common.h>
+#include <linux/static_call_types.h>
+#include <linux/tracehook.h>
+#include <linux/syscalls.h>
+#include <linux/seccomp.h>
+#include <linux/sched.h>
 #include <linux/tick.h>
 
 /* Transfer to guest mode work */
Signature · 6 lines
2.32.0.554.ge1b32706d8-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#3 lore raw

PATCH v3 3/3 KVM: arm64: Use generic KVM xfer to guest work function

In reply to Oliver Upton

Clean up handling of checks for pending work by switching to the generic infrastructure to do so.

We pick up handling for TIF_NOTIFY_RESUME from this switch, meaning that task work will be correctly handled.

---
 arch/arm64/kvm/Kconfig |  1 +
 arch/arm64/kvm/arm.c   | 72 ++++++++++++++++++++++++++----------------
 2 files changed, 45 insertions(+), 28 deletions(-)
arch/arm64/kvm/Kconfig +1 -0
index a4eba0908bfa..8bc1fac5fa26 100644
@@ -26,6 +26,7 @@ menuconfig KVM
 	select HAVE_KVM_ARCH_TLB_FLUSH_ALL
 	select KVM_MMIO
 	select KVM_GENERIC_DIRTYLOG_READ_PROTECT
+	select KVM_XFER_TO_GUEST_WORK
 	select SRCU
 	select KVM_VFIO
 	select HAVE_KVM_EVENTFD
arch/arm64/kvm/arm.c +44 -28

102 lines not on this page · raw message

Signature · 1 line
2.32.0.554.ge1b32706d8-goog
#4 lore raw
In reply to Oliver Upton

Friendly ping :)

--
Thanks,
Oliver

Quoted 48 lines · Oliver Upton

The arm64 kernel doesn't yet support the full generic entry infrastructure. That being said, KVM/arm64 doesn't properly handle TIF_NOTIFY_RESUME and could pick this up by switching to the generic guest entry infrasturture.

Patch 1 adds a missing vCPU stat to ARM64 to record the number of signal exits to userspace.

Patch 2 unhitches entry-kvm from entry-generic, as ARM64 doesn't currently support the generic infrastructure.

Patch 3 replaces the open-coded entry handling with the generic xfer function.

This series was tested on an Ampere Mt. Jade reference system. The series cleanly applies to kvm/queue (note that this is deliberate as the generic kvm stats patches have not yet propagated to kvm-arm/queue) at the following commit:

8ad5e63649ff ("KVM: Don't take mmu_lock for range invalidation unless necessary")

v1 -> v2:
- Address Jing's comment
- Carry Jing's r-b tag

v2 -> v3:
- Roll all exit conditions into kvm_vcpu_exit_request() (Marc)
- Avoid needlessly checking for work twice (Marc)

v1: http://lore.kernel.org/r/[email protected]
v2: http://lore.kernel.org/r/[email protected]

Oliver Upton (3):
KVM: arm64: Record number of signal exits as a vCPU stat
entry: KVM: Allow use of generic KVM entry w/o full generic support
KVM: arm64: Use generic KVM xfer to guest work function

 arch/arm64/include/asm/kvm_host.h |  1 +
 arch/arm64/kvm/Kconfig            |  1 +
 arch/arm64/kvm/arm.c              | 71 +++++++++++++++++++------------
 arch/arm64/kvm/guest.c            |  1 +
 include/linux/entry-kvm.h         |  6 ++-
 5 files changed, 52 insertions(+), 28 deletions(-)

--
2.32.0.554.ge1b32706d8-goog

maintainer
#5 lore raw
Quoted 2 lines · Oliver Upton

Friendly ping :)

Ah, thanks for reminding me of this. I'll have a look again early next week.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Applied
#6 lore raw
In reply to Oliver Upton
Quoted 9 lines · Oliver Upton

The arm64 kernel doesn't yet support the full generic entry infrastructure. That being said, KVM/arm64 doesn't properly handle TIF_NOTIFY_RESUME and could pick this up by switching to the generic guest entry infrasturture.

Patch 1 adds a missing vCPU stat to ARM64 to record the number of signal exits to userspace.

[...]

Applied to next, thanks!

[1/3] KVM: arm64: Record number of signal exits as a vCPU stat

      commit: fe5161d2c39b8c2801f0e786631460c6e8a1cae4
[2/3] entry: KVM: Allow use of generic KVM entry w/o full generic support
      commit: e1c6b9e1669e44fb7f9688e34e460b759e3b9187
[3/3] KVM: arm64: Use generic KVM xfer to guest work function
      commit: 6caa5812e2d126a0aa8a17816c1ba6f0a0c2b309

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.