All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Pratik R. Sampat" <prsampat@amd.com>,
	kvm@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, seanjc@google.com,
	pbonzini@redhat.com, kim.phillips@amd.com, nikunj@amd.com,
	michael.roth@amd.com, ashish.kalra@amd.com
Subject: Re: [Patch v2 2/4] KVM: SVM: Add host support for Enhanced SMT Protection
Date: Fri, 9 Oct 2026 15:05:39 -0500	[thread overview]
Message-ID: <d72aecef-d7cf-4cd0-9c2e-b4e1922b6c99@amd.com> (raw)
In-Reply-To: <b1145255-a272-4f92-982d-ea3131463287@amd.com>

On 10/9/26 14:40, Pratik R. Sampat wrote:
> Hi Tom,
> 
> On 10/9/26 3:05 PM, Tom Lendacky wrote:
>> On 10/6/26 11:54, Pratik R. Sampat wrote:
>>> Enhanced SMT Protection (ESMTP) protects an SEV-SNP guest from SMT side
>>> channels by requiring that, while a vCPU is in guest mode, its SMT sibling
>>> thread is either idle in host mode or executing a vCPU the guest has
>>> declared to be a legal sibling. A legal sibling is another ESMTP vCPU of
>>> the same guest that carries the same VCPU_SIBLING_MASK and agrees on
>>> VCPU_ID outside that mask.
>>>
>>> Hardware enforces this at VMRUN, which no longer enters guest mode right
>>> away but stalls until the condition holds. Three new exits report that it
>>> could not be met, all of them non-fatal:
>>>
>>> ESMTP_ILLSIB: a sibling thread is running a vCPU that is not a legal
>>> sibling of this one.
>>>
>>> ESMTP_TIMEOUT: the stall exceeded the timeout programmed in the VMCB. The
>>> timer bounds how long VMRUN waits for the core to settle. A module
>>> parameter exposes an interface to program this timer.
>>>
>>> ESMTP_RETRY: If DBREQ is detected, VMRUN exits. ESMTP_RETRY indicates an
>>> internal event and the hypervisor should execute a VMRUN.
>>>
>>> Refer to the AMD64 APM Vol 2, section "AMD64 Enhanced SMT Protection".
>>>
>>> Acked-by: Borislav Petkov (AMD) <bp@alien8.de> # non-virtualization changes
>>> Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
>>> ---
>>> v1..v2
>>> * Move idle wakeup ICR programming to svm_enable_virtualization_cpu()
>>>   instead of sev_hardware_setup()
>>> * Remove cond_sched() in ESMTP exit paths
>>> * Program the IDLE_WAKEUP_ICR for all present CPU siblings
>>> * Add documentation for ESMTP timeout
>>> ---
>>>  .../admin-guide/kernel-parameters.txt         | 19 ++++++++
>>>  arch/x86/include/asm/cpufeatures.h            |  1 +
>>>  arch/x86/include/asm/msr-index.h              |  1 +
>>>  arch/x86/include/asm/svm.h                    | 12 ++++-
>>>  arch/x86/include/uapi/asm/svm.h               |  9 +++-
>>>  arch/x86/kernel/cpu/scattered.c               |  1 +
>>>  arch/x86/kvm/svm/sev.c                        | 48 ++++++++++++++++++-
>>>  arch/x86/kvm/svm/svm.c                        |  8 ++++
>>>  arch/x86/kvm/svm/svm.h                        |  2 +
>>>  9 files changed, 97 insertions(+), 4 deletions(-)
>>>

>>> --- a/arch/x86/kvm/svm/sev.c
>>> +++ b/arch/x86/kvm/svm/sev.c
>>> @@ -67,6 +67,11 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444);
>>>  static unsigned int __ro_after_init nr_ciphertext_hiding_asids;
>>>  module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 0444);
>>>  
>>> +static unsigned long esmtp_timeout_ns;
>>> +module_param(esmtp_timeout_ns, ulong, 0644);
>>> +MODULE_PARM_DESC(esmtp_timeout_ns,
>>> +		 "ESMTP VMRUN sibling-wait timeout in nanoseconds (0 disables the timer)");
>>
>> "ESMTP VMRUN sibling-wait timeout, in nanoseconds. 0 (default) disables
>> the timer."
>>
>> Not sure if that reads any better, main point is just to highlight the
>> default is 0, timer disabled.
>>
> 
> Sure, your example reads fine. As an alternative:
> "ESMTP VMRUN sibling-wait timeout in nanoseconds (default: 0, timer disabled)"

Ack

> 
>>> +

>>> +void sev_esmtp_enable_wakeup_icr(void)
>>> +{
>>> +	unsigned int cpu, sibling, shift;
>>> +	u32 core;
>>> +
>>> +	if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_ESMTP))
>>> +		return;
>>> +
>>> +	cpu = raw_smp_processor_id();
>>> +	shift = topology_get_domain_shift(TOPO_CORE_DOMAIN);
>>> +	core = per_cpu(x86_cpu_to_apicid, cpu) >> shift;
>>> +
>>> +	for_each_present_cpu(sibling) {
>>> +		u32 apicid = per_cpu(x86_cpu_to_apicid, sibling);
>>> +		u64 icr;
>>> +
>>> +		if (sibling == cpu || (apicid >> shift) != core)
>>> +			continue;
>>> +
>>> +		icr = (u64)apicid << 32;
>>> +		icr |= LOCAL_TIMER_VECTOR;
>>> +		WARN_ON_ONCE(wrmsrq_safe(MSR_AMD64_IDLE_WAKEUP_ICR, icr));
>>> +	}
>>
>> Can you use cpu_sibling_map here instead of going through every present cpu?
>>
> 
> I think cpu_sibling_map only covers the list of online CPUs. If SMT was say
> turned off and then on again the CPU that stayed online would never be
> reprogrammed with its new sibling's APIC ID. Walking the present CPUs avoids
> that, because x86_cpu_to_apicid is already valid for offline siblings.

Makes sense. I know we disable hotplug when SNP is enabled, but this runs
before that occurs.

Thanks,
Tom

> 
> I had used topology_sibling_cpumask() in v1 when Sashiko pointed out this case
> to me.
> 
> Thank you!
> Pratik
> 

  reply	other threads:[~2026-10-09 20:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06 16:54 [Patch v2 0/4] Introduce Enhanced SMT Protection for SEV-SNP Pratik R. Sampat
2026-10-06 16:54 ` [Patch v2 1/4] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
2026-10-06 17:12   ` sashiko-bot
2026-10-09 19:21   ` Tom Lendacky
2026-10-06 16:54 ` [Patch v2 2/4] KVM: SVM: Add host support for Enhanced SMT Protection Pratik R. Sampat
2026-10-06 17:08   ` sashiko-bot
2026-10-09 19:05   ` Tom Lendacky
2026-10-09 19:40     ` Pratik R. Sampat
2026-10-09 20:05       ` Tom Lendacky [this message]
2026-10-06 16:55 ` [Patch v2 3/4] x86/sev: Add guest " Pratik R. Sampat
2026-10-06 17:03   ` sashiko-bot
2026-10-09 19:18   ` Tom Lendacky
2026-10-09 19:43     ` Pratik R. Sampat
2026-10-06 16:55 ` [Patch v2 4/4] x86/hyperv: " Pratik R. Sampat

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=d72aecef-d7cf-4cd0-9c2e-b4e1922b6c99@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kim.phillips@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=prsampat@amd.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.