diff mbox series

[RFC,4/5] x86/kvm: Add x86 field to find the default VMPL that IRQs should target

Message ID d8eb94631cdd98196e81119f19b9a0cae9dddc3a.1726506534.git.roy.hopkins@suse.com (mailing list archive)
State New
Headers show
Series Extend SEV-SNP SVSM support with a kvm_vcpu per VMPL | expand

Commit Message

Roy Hopkins Sept. 16, 2024, 6:17 p.m. UTC
When a CPU supports multiple VMPLs, injected interrupts need to be sent
to the correct context. This commit adds an operation that determines
the VMPL number that IRQs should be sent to in the absence of an explicit
target VMPL.

Signed-off-by: Roy Hopkins <roy.hopkins@suse.com>
---
 arch/x86/include/asm/kvm_host.h | 7 +++++++
 arch/x86/kvm/svm/sev.c          | 8 ++++++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 94e7b5a4fafe..3dd3a5ff0cec 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1537,6 +1537,13 @@  struct kvm_arch {
 	 */
 #define SPLIT_DESC_CACHE_MIN_NR_OBJECTS (SPTE_ENT_PER_PAGE + 1)
 	struct kvm_mmu_memory_cache split_desc_cache;
+
+	/*
+	 * When a system supports multiple VMPLs, injected interrupts need to be
+	 * sent to the correct context. The default VMPL that IRQs should be sent
+	 * to is indicated in this variable.
+	 */
+	unsigned int default_irq_vmpl;
 };
 
 struct kvm_vm_stat {
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 3fbb1ce5195d..ed91aa93da6e 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3983,6 +3983,14 @@  static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu)
 		 * means.
 		 */
 		kvm_release_pfn_clean(pfn);
+
+		/*
+		 * TEMP: If the newly created VMSA is for a lower VMPL then
+		 * set this VMPL to be the default for sending IRQs to.
+		 */
+		if (vcpu->vmpl > vcpu->kvm->arch.default_irq_vmpl) {
+			vcpu->kvm->arch.default_irq_vmpl = vcpu->vmpl;
+		}
 	}
 
 	return 0;