KVM: arm64: Use generic guest entry infrastructure
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")
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 | 26 ++++++++++++++------------ arch/arm64/kvm/guest.c | 3 ++- include/linux/entry-kvm.h | 6 +++++- 5 files changed, 23 insertions(+), 14 deletions(-)
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
PATCH 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 | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_host.h +1 -0
@@ -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
@@ -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 +2 -1
@@ -50,7 +50,8 @@ 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 , exits) +STATS_DESC_COUNTER (VCPU , exits), +STATS_DESC_COUNTER (VCPU , signal_exits), };static_assert (ARRAY_SIZE (kvm_vcpu_stats_desc) ==sizeof (struct kvm_vcpu_stat ) /sizeof (u64));
Signature · 6 lines
2.32.0.554.ge1b32706d8-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH 1/3] KVM: arm64: Record number of signal exits as a vCPU stat
Quoted 42 lines · Oliver Upton
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.
Cc Jing Zhang <[email protected]>Signed-off-by Oliver Upton <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/guest.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-)arch/arm64/include/asm/kvm_host.h +1
-0@@ -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@@ -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 +0
-0
arch/arm64/kvm/guest.c const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { · line 54
Quoted 6 lines
arch/arm64/kvm/guest.c +2
-1@@ -50,7 +50,8 @@ 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 , exits) +STATS_DESC_COUNTER (VCPU , exits), + STATS_DESC_COUNTER(VCPU, signal_exits),
How about put signal_exits before exits as the same order in kvm_vcpu_stat just for readability?
Quoted 6 lines
arch/arm64/kvm/guest.c +0
-1};static_assert (ARRAY_SIZE (kvm_vcpu_stats_desc) ==sizeof (struct kvm_vcpu_stat ) /sizeof (u64)); --2.32.0.554.ge1b32706d8-goog
Thanks,
Jing
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH 1/3] KVM: arm64: Record number of signal exits as a vCPU stat
Quoted 38 lines · Jing Zhang
Quoted 36 lines · Oliver Upton
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.
Cc Jing Zhang <[email protected]>Signed-off-by Oliver Upton <[email protected]>--- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/arm.c | 1 + arch/arm64/kvm/guest.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-)arch/arm64/include/asm/kvm_host.h +1
-0@@ -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@@ -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; }
Quoted 14 lines
arch/arm64/kvm/guest.c const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { · line 54
Quoted 12 lines
arch/arm64/kvm/arm.c +0
-0/* arch/arm64/kvm/guest.c +2
-1@@ -50,7 +50,8 @@ 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 , exits) +STATS_DESC_COUNTER (VCPU , exits), + STATS_DESC_COUNTER(VCPU, signal_exits),How about put
signal_exitsbefore exits as the same order inkvm_vcpu_statjust for readability?
Definitely.
Quoted 7 lines
Quoted 6 lines
arch/arm64/kvm/guest.c +0
-1};static_assert (ARRAY_SIZE (kvm_vcpu_stats_desc) ==sizeof (struct kvm_vcpu_stat ) /sizeof (u64)); --2.32.0.554.ge1b32706d8-goog
Reviewed-by Jing Zhang <[email protected]>
Thanks Jing!
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 2/3 entry: KVM: Allow use of generic KVM entry w/o full generic support
In reply to Oliver UptonSome 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
@@ -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
PATCH 3/3 KVM: arm64: Use generic KVM xfer to guest work function
In reply to Oliver UptonClean 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 | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-)
arch/arm64/kvm/Kconfig +1 -0
@@ -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 +14 -13
@@ -6,6 +6,7 @@#include <linux/bug.h> #include <linux/cpu_pm.h> +#include <linux/entry-kvm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kvm_host.h>
@@ -714,6 +715,13 @@ static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu)static_branch_unlikely (&arm64_mismatched_32bit_el0); } +static bool kvm_vcpu_exit_request (struct kvm_vcpu *vcpu) +{ +return kvm_request_pending (vcpu) || +need_new_vmid_gen (&vcpu->arch.hw_mmu->vmid) || +xfer_to_guest_mode_work_pending (); +} +/** * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code * @vcpu: The VCPU pointer
@@ -757,7 +765,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)/* * Check conditions before entering the guest */ -cond_resched (); +if (__xfer_to_guest_mode_work_pending ()) { + ret =xfer_to_guest_mode_handle_work (vcpu); +if (!ret) + ret =1 ; + }update_vmid (&vcpu->arch.hw_mmu->vmid);
@@ -776,16 +788,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)kvm_vgic_flush_hwstate (vcpu); -/* -* Exit if we have a signal pending so that we can deliver the -* signal to user space. -*/ -if (signal_pending (current)) { - ret = -EINTR ; - run->exit_reason =KVM_EXIT_INTR ; - ++vcpu->stat.signal_exits; - } -/* * If we're using a userspace irqchip, then check if we need * to tell a userspace irqchip about timer or PMU level
@@ -809,8 +811,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)*/ smp_store_mb (vcpu->mode,IN_GUEST_MODE ); -if (ret <=0 ||need_new_vmid_gen (&vcpu->arch.hw_mmu->vmid) || -kvm_request_pending (vcpu)) { +if (ret <=0 ||kvm_vcpu_exit_request (vcpu)) { vcpu->mode =OUTSIDE_GUEST_MODE ;isb ();/* Ensure work in x_flush_hwstate is committed */ kvm_pmu_sync_hwstate (vcpu);
Signature · 6 lines
2.32.0.554.ge1b32706d8-goog _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm