public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@google.com>
To: kvmarm@lists.cs.columbia.edu
Cc: alexandru.elisei@arm.com, anup@brainfault.org,
	atishp@atishpatra.org, james.morse@arm.com,
	jingzhangos@google.com, jmattson@google.com, joro@8bytes.org,
	kvm-riscv@lists.infradead.org, kvm@vger.kernel.org,
	maz@kernel.org, pbonzini@redhat.com, pshier@google.com,
	rananta@google.com, reijiw@google.com, ricarkol@google.com,
	seanjc@google.com, suzuki.poulose@arm.com, vkuznets@redhat.com,
	wanpengli@tencent.com, Oliver Upton <oupton@google.com>
Subject: [PATCH v5 05/13] KVM: Create helper for setting a system event exit
Date: Sat,  9 Apr 2022 18:45:41 +0000	[thread overview]
Message-ID: <20220409184549.1681189-6-oupton@google.com> (raw)
In-Reply-To: <20220409184549.1681189-1-oupton@google.com>

Create a helper that appropriately configures kvm_run for a system event
exit.

No functional change intended.

Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Oliver Upton <oupton@google.com>
Acked-by: Anup Patel <anup@brainfault.org>
---
 arch/arm64/kvm/psci.c     | 5 +----
 arch/riscv/kvm/vcpu_sbi.c | 5 +----
 arch/x86/kvm/x86.c        | 6 ++----
 include/linux/kvm_host.h  | 2 ++
 virt/kvm/kvm_main.c       | 8 ++++++++
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c
index f2f45a3cbe86..362d2a898b83 100644
--- a/arch/arm64/kvm/psci.c
+++ b/arch/arm64/kvm/psci.c
@@ -172,10 +172,7 @@ static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type, u64 flags)
 		tmp->arch.mp_state.mp_state = KVM_MP_STATE_STOPPED;
 	kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
 
-	memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
-	vcpu->run->system_event.type = type;
-	vcpu->run->system_event.flags = flags;
-	vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+	kvm_vcpu_set_system_event_exit(vcpu, type, flags);
 }
 
 static void kvm_psci_system_off(struct kvm_vcpu *vcpu)
diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
index a09ecb97b890..3be9730ae68b 100644
--- a/arch/riscv/kvm/vcpu_sbi.c
+++ b/arch/riscv/kvm/vcpu_sbi.c
@@ -92,10 +92,7 @@ void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
 		tmp->arch.power_off = true;
 	kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP);
 
-	memset(&run->system_event, 0, sizeof(run->system_event));
-	run->system_event.type = type;
-	run->system_event.flags = flags;
-	run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+	kvm_vcpu_set_system_event_exit(vcpu, type, flags);
 }
 
 int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0c0ca599a353..54efc1b4eb28 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10014,14 +10014,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
 		if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))
 			kvm_vcpu_reload_apic_access_page(vcpu);
 		if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) {
-			vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
-			vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH;
+			kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_CRASH, 0);
 			r = 0;
 			goto out;
 		}
 		if (kvm_check_request(KVM_REQ_HV_RESET, vcpu)) {
-			vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
-			vcpu->run->system_event.type = KVM_SYSTEM_EVENT_RESET;
+			kvm_vcpu_set_system_event_exit(vcpu, KVM_SYSTEM_EVENT_RESET, 0);
 			r = 0;
 			goto out;
 		}
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 3f9b22c4983a..f2f66dc0fa6e 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2220,6 +2220,8 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu)
 }
 #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
 
+void kvm_vcpu_set_system_event_exit(struct kvm_vcpu *vcpu, u32 type, u64 flags);
+
 /*
  * This defines how many reserved entries we want to keep before we
  * kick the vcpu to the userspace to avoid dirty ring full.  This
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e39a6f56fc47..b91f689dd091 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3208,6 +3208,14 @@ void kvm_vcpu_mark_page_dirty(struct kvm_vcpu *vcpu, gfn_t gfn)
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_mark_page_dirty);
 
+void kvm_vcpu_set_system_event_exit(struct kvm_vcpu *vcpu, u32 type, u64 flags)
+{
+	memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event));
+	vcpu->run->system_event.type = type;
+	vcpu->run->system_event.flags = flags;
+	vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
+}
+
 void kvm_sigset_activate(struct kvm_vcpu *vcpu)
 {
 	if (!vcpu->sigset_active)
-- 
2.35.1.1178.g4f1659d476-goog


  parent reply	other threads:[~2022-04-09 18:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-09 18:45 [PATCH v5 00/13] KVM: arm64: PSCI SYSTEM_SUSPEND support Oliver Upton
2022-04-09 18:45 ` [PATCH v5 01/13] KVM: arm64: Don't depend on fallthrough to hide SYSTEM_RESET2 Oliver Upton
2022-04-14  5:00   ` Reiji Watanabe
2022-04-09 18:45 ` [PATCH v5 02/13] KVM: arm64: Dedupe vCPU power off helpers Oliver Upton
2022-04-09 18:45 ` [PATCH v5 03/13] KVM: arm64: Track vCPU power state using MP state values Oliver Upton
2022-04-14  5:26   ` Reiji Watanabe
2022-04-21  3:31     ` Oliver Upton
2022-04-09 18:45 ` [PATCH v5 04/13] KVM: arm64: Rename the KVM_REQ_SLEEP handler Oliver Upton
2022-04-09 18:45 ` Oliver Upton [this message]
2022-04-14  5:40   ` [PATCH v5 05/13] KVM: Create helper for setting a system event exit Reiji Watanabe
2022-04-09 18:45 ` [PATCH v5 06/13] KVM: arm64: Return a value from check_vcpu_requests() Oliver Upton
2022-04-22  6:37   ` Reiji Watanabe
2022-04-09 18:45 ` [PATCH v5 07/13] KVM: arm64: Add support for userspace to suspend a vCPU Oliver Upton
2022-04-21  3:12   ` Reiji Watanabe
2022-04-21  3:23     ` Oliver Upton
2022-04-22  6:28       ` Reiji Watanabe
2022-04-29  3:42         ` Oliver Upton
2022-04-09 18:45 ` [PATCH v5 08/13] KVM: arm64: Implement PSCI SYSTEM_SUSPEND Oliver Upton
2022-04-22  7:02   ` Reiji Watanabe
2022-04-09 18:45 ` [PATCH v5 09/13] selftests: KVM: Rename psci_cpu_on_test to psci_test Oliver Upton
2022-04-09 18:45 ` [PATCH v5 10/13] selftests: KVM: Create helper for making SMCCC calls Oliver Upton
2022-04-09 18:45 ` [PATCH v5 11/13] selftests: KVM: Use KVM_SET_MP_STATE to power off vCPU in psci_test Oliver Upton
2022-04-09 18:45 ` [PATCH v5 12/13] selftests: KVM: Refactor psci_test to make it amenable to new tests Oliver Upton
2022-04-09 18:45 ` [PATCH v5 13/13] selftests: KVM: Test SYSTEM_SUSPEND PSCI call Oliver Upton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220409184549.1681189-6-oupton@google.com \
    --to=oupton@google.com \
    --cc=alexandru.elisei@arm.com \
    --cc=anup@brainfault.org \
    --cc=atishp@atishpatra.org \
    --cc=james.morse@arm.com \
    --cc=jingzhangos@google.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pshier@google.com \
    --cc=rananta@google.com \
    --cc=reijiw@google.com \
    --cc=ricarkol@google.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox