Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Manali Shukla <manali.shukla@amd.com>
To: <kvm@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Cc: <pbonzini@redhat.com>, <seanjc@google.com>, <shuah@kernel.org>,
	<nikunj@amd.com>, <thomas.lendacky@amd.com>,
	<vkuznets@redhat.com>, <manali.shukla@amd.com>, <bp@alien8.de>,
	<babu.moger@amd.com>
Subject: [PATCH v4 3/4] KVM: nSVM: implement the nested idle halt intercept
Date: Tue, 22 Oct 2024 05:48:09 +0000	[thread overview]
Message-ID: <20241022054810.23369-4-manali.shukla@amd.com> (raw)
In-Reply-To: <20241022054810.23369-1-manali.shukla@amd.com>

Enable the idle HLT intercept for the L2 guest when it is available on
the platform and the L2 guest can utilize the Idle HLT intercept
feature. This is achieved by clearing the HLT intercept for the L1
hypervisor in the recalc_interrupts() function. The Idle HLT intercept
requires that the HLT intercept is cleared and the Idle HLT intercept
is set to properly enable the feature.

The nested idle halt intercept was tested by booting L1,L2 (all Linux)
and checking there are only idle-hlt vmexits happened.

Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
 arch/x86/kvm/governed_features.h | 1 +
 arch/x86/kvm/svm/nested.c        | 8 ++++++++
 arch/x86/kvm/svm/svm.c           | 4 ++++
 3 files changed, 13 insertions(+)

diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h
index ad463b1ed4e4..0154012721cb 100644
--- a/arch/x86/kvm/governed_features.h
+++ b/arch/x86/kvm/governed_features.h
@@ -17,6 +17,7 @@ KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
 KVM_GOVERNED_X86_FEATURE(VGIF)
 KVM_GOVERNED_X86_FEATURE(VNMI)
 KVM_GOVERNED_X86_FEATURE(LAM)
+KVM_GOVERNED_X86_FEATURE(IDLE_HLT)
 
 #undef KVM_GOVERNED_X86_FEATURE
 #undef KVM_GOVERNED_FEATURE
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index d5314cb7dff4..feb241110f1a 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -178,6 +178,14 @@ void recalc_intercepts(struct vcpu_svm *svm)
 	} else {
 		WARN_ON(!(c->virt_ext & VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK));
 	}
+
+	/*
+	 * Clear the HLT intercept for L2 guest when the Idle HLT intercept feature
+	 * is enabled on the platform and the guest can use the Idle HLT intercept
+	 * feature.
+	 */
+	if (guest_can_use(&svm->vcpu, X86_FEATURE_IDLE_HLT))
+		vmcb_clr_intercept(c, INTERCEPT_HLT);
 }
 
 /*
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index e86b79e975d3..38d546788fc6 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4425,6 +4425,7 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
 	kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_PFTHRESHOLD);
 	kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VGIF);
 	kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VNMI);
+	kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_IDLE_HLT);
 
 	svm_recalc_instruction_intercepts(vcpu, svm);
 
@@ -5228,6 +5229,9 @@ static __init void svm_set_cpu_caps(void)
 		if (vnmi)
 			kvm_cpu_cap_set(X86_FEATURE_VNMI);
 
+		if (cpu_feature_enabled(X86_FEATURE_IDLE_HLT))
+			kvm_cpu_cap_set(X86_FEATURE_IDLE_HLT);
+
 		/* Nested VM can receive #VMEXIT instead of triggering #GP */
 		kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK);
 	}
-- 
2.34.1


  parent reply	other threads:[~2024-10-22  5:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-22  5:48 [PATCH v4 0/4] Add support for the Idle HLT intercept feature Manali Shukla
2024-10-22  5:48 ` [PATCH v4 1/4] x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept Manali Shukla
2024-10-22  9:32   ` Borislav Petkov
2024-10-22 15:08     ` Sean Christopherson
2024-10-22  5:48 ` [PATCH v4 2/4] KVM: SVM: Add Idle HLT intercept support Manali Shukla
2024-10-22  5:48 ` Manali Shukla [this message]
2024-12-20  1:01   ` [PATCH v4 3/4] KVM: nSVM: implement the nested idle halt intercept Sean Christopherson
2024-12-30  7:05     ` Manali Shukla
2024-12-30  7:14     ` Manali Shukla
2024-10-22  5:48 ` [PATCH v4 4/4] KVM: selftests: KVM: SVM: Add Idle HLT intercept test Manali Shukla
2024-12-20  1:24   ` Sean Christopherson
2024-12-30  7:10     ` Manali Shukla
2024-11-28 15:09 ` [PATCH v4 0/4] Add support for the Idle HLT intercept feature Manali Shukla
2024-12-12 16:37   ` Manali Shukla
2024-12-23  9:13     ` Manali Shukla
2024-12-23  9:27       ` Manali Shukla

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=20241022054810.23369-4-manali.shukla@amd.com \
    --to=manali.shukla@amd.com \
    --cc=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nikunj@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=vkuznets@redhat.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