From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796511650; b=ofz2gg/ql+w9ZdkX1YlrQOcxRtjj2tLC3wm4TBrDJkNCchjalmNa6MSJznFap4yW3fwg o9jAbv4h2b8LZbhJpTRhY9fyBHQef1BbSWTP1BFY42viZd2tBlB+oBllTtiYC0T9RLQFG G56L3u4/DbkDyxlh5btoWaX2bOhtULbx09NyKSxhBnHkRc3kt/euN1F5YLLpaULysuVeM 8A5ydvhveE/u3eFsXou1jttNAebIi2m2EorhHZJ+A0vfPDNhyvRKZjeqatRDVUfSNpUsd r3qj/UFLwsj/nebX5nED1ePEuhwe41JWpFEOSv14v0q7nL3ZXmodnafKQS57APJ9tuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796511650; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=3m/iJE/4aHT/oMnI3roHw68xT9Ef6GXsQDasx9TC33E=; b=g+ly6E67D1f/fdCcDMXDGFhtF39U9QPhsuf7s9C0RCLy1RhYJYGM9ot1TeeGQALdS1+B ElYhoJb/yi/8Lol3OXXi2NP+zprEY3Y+pwFd3fnUJ81cRZk7+E7UD+pS1JVqBQwMLdzT7 EN2KOdqflhSX1qpZnOKmXfD+2++Fxmq5B0RXbQIPr7V2eCW9p7Yvre9ocPUwt8q71Xgrf XOd4WRrnAC+geST1uz7EMceM0Ug6YN0ujAbzO7f0+3n1IN55Bu8D06Aue39Xi6GAFiIEb Jg9iUw5gAowgFWMHCoevCj4zMP+MnBnIJrcy2jn7PFvIl0G4WaH+Z9nQ44CHn9MnfSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Gcyy/lbJ"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28B6E606A31F for ; Sat, 5 Dec 2026 23:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Gcyy/lbJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id E76CF1F0092B; Sat, 5 Dec 2026 23:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796511650; bh=3m/iJE/4aHT/oMnI3roHw68xT9Ef6GXsQDasx9TC33E=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=Gcyy/lbJ8IvUwwwRiRvinxIKOnWzjQkyjLlzBJGUEkAZ6W9MxKKf5SAbkrU1I0e+G 8OAXIDIFA4q5gOcjMwp1MbScC1kBjwPE+DK12NesFB9gtp4r8TblRj+1UnA4IllcfS mbHnFnJia67dPhyjxKD9RLvt9C+ba3DGP7+4/Dins/atTX6tbuflj9VHwLyBJxMu1e k+PNPflGCXkXxxfcg5eGOjFbwwBLGgFyqv89WEvTXmDhcs8fOxzKyeCjCh2SofvFVG uW1RxPmx/PrguBoDIt0OGgpgyOEqFv0gUM2XW6QPaFX1yiZz7A1aCU4u3LFb97/MDN Ij13rogOdow0Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [Patch v6 3/3] KVM: SVM: Add host support for Enhanced SMT Protection Reply-To: sashiko-reviews@lists.linux.dev To: "Pratik R. Sampat" , kvm@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 23:00:49 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] KVM: SVM: sev_es_sync_vmsa() uses nonexistent sev_es_save_area fields - [High] KVM: SVM: svm_vcpu_run() clears TLB/VMCB state on ESMTP/SMTP aborts - [High] KVM: SVM: missing vcpu_id and vcpu_sibling_mask fields in sev_es_save_area - [Medium] KVM: SVM: sev_enable_idle_wakeup_icr() ignores xAPIC ICR destination format - [Medium] KVM: SVM: sev_enable_idle_wakeup_icr() misuses LOCAL_TIMER_VECTOR for kicks - [Medium] KVM: SVM: svm_complete_interrupts() may reuse stale exit_int_info on ESMTP - [Low] KVM: SVM: plain read of writable esmtp_timeout_ns in sev_es_init_vmcb() -- commit 44efccfc3cd4956b61f97b12386bb66eb255647a Author: Pratik R. Sampat KVM: SVM: Add host support for Enhanced SMT Protection This commit adds host KVM/SVM support for AMD Enhanced SMT Protection (ESMTP) on SEV-SNP guests, including feature detection, VMCB timeout configuration via a module parameter, VMSA sibling metadata, IDLE_WAKEUP_ICR programming, and exit handling for the three new ESMTP VMRUN exits. > diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h > index 72466901d791a..e30eb48688ae1 100644 > --- a/arch/x86/include/asm/svm.h > +++ b/arch/x86/include/asm/svm.h > @@ -165,7 +165,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area= { > u8 reserved_9[22]; > u64 allowed_sev_features; /* Offset 0x138 */ > u64 guest_sev_features; /* Offset 0x140 */ > - u8 reserved_10[128]; > + u64 esmtp_timeout; /* Offset 0x148 */ > + u8 reserved_10[120]; > u64 pml_addr; /* Offset 0x1c8 */ > u16 pml_index; /* Offset 0x1d0 */ > u8 reserved_11[526]; [Severity: High] Does struct sev_es_save_area in this header also need vcpu_id and vcpu_sibling_mask fields? Neither field is defined anywhere in struct sev_es_save_area, so compiling arch/x86/kvm/svm/sev.c with CONFIG_KVM_AMD_SEV=3Dy fails when sev_es_sync_vmsa() assigns them. [ ... ] > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index ad802211ec4f7..915acb2c973e5 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c [ ... ] > @@ -1035,6 +1046,15 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm) > =20 > save->sev_features =3D sev->vmsa_features; > =20 > + if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP) { > + save->vcpu_id =3D vcpu->vcpu_id; > + /* > + * All vCPUs of a guest are put into one group and can be run > + * co-resident on the sibling thread of the same core. > + */ > + save->vcpu_sibling_mask =3D U32_MAX; > + } > + > /* > * Skip FPU and AVX setup with KVM_SEV_ES_INIT to avoid > * breaking older measurements. [Severity: High] Will this build with CONFIG_KVM_AMD_SEV enabled? save is a struct sev_es_save_area *, which does not have vcpu_id or vcpu_sibling_mask members in arch/x86/include/asm/svm.h. Adding those fields at their architectural VMSA offsets will also require updating the reserved padding and the compile-time size and offset assertions in __unused_size_checks(). [ ... ] > @@ -3322,7 +3345,8 @@ void sev_enable_idle_wakeup_icr(void) > unsigned int cpu, sibling, shift; > u32 core; > =20 > - if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_SMTP)) > + if (!(sev_supported_vmsa_features & > + (SVM_SEV_FEAT_SMTP | SVM_SEV_FEAT_ESMTP))) > return; > =20 > cpu =3D raw_smp_processor_id(); [Severity: Medium] Does sev_enable_idle_wakeup_icr() handle hosts running in legacy xAPIC mode (!x2apic_enabled())? Later in this function, the ICR value is built unconditionally in x2APIC format: arch/x86/kvm/svm/sev.c:sev_enable_idle_wakeup_icr() { ... icr =3D (u64)apicid << 32; icr |=3D LOCAL_TIMER_VECTOR; WARN_ON_ONCE(wrmsrq_safe(MSR_AMD64_IDLE_WAKEUP_ICR, icr)); } In xAPIC mode, the 8-bit physical destination APIC ID lives in bits 63:56 (SET_XAPIC_DEST_FIELD(apicid) in APIC_ICR2) while bits 55:32 are reserved. When hardware writes MSR_AMD64_IDLE_WAKEUP_ICR directly to the APIC ICR on a synchronized ESMTP exit, an xAPIC host will send the wakeup IPI to APIC ID 0 instead of the SMT sibling, breaking sibling kick synchronization and delivering spurious timer IPIs to CPU 0. Formatting the destination according to x2apic_enabled() (or gating SMTP/ESMTP support on x2apic_enabled() if x2APIC is required by hardware) would avoid this. [Severity: Medium] Is LOCAL_TIMER_VECTOR safe to program into MSR_AMD64_IDLE_WAKEUP_ICR for ESMTP sibling kicks? Every synchronized ESMTP sibling VM-exit will deliver a spurious local APIC timer interrupt to the sibling CPU via sysvec_apic_timer_interrupt() -> local_apic_timer_interrupt(). On hosts in periodic or low-resolution tick mode (highres=3Doff or !CONFIG_HIGH_RES_TIMERS), tick_handle_periodic() and tick_nohz_lowres_handler() unconditionally advance jiffies and charge process time on each delivery. Even with high-resolution timers enabled, every sibling kick runs the full hrtimer_interrupt() path (acquiring cpu_base->lock, walking hrtimer queues, and reprogramming the hardware LAPIC timer) and increments APIC_TIMER stats. Can this use RESCHEDULE_VECTOR instead, which KVM already uses via sysvec_reschedule_ipi() to force a CPU out of guest mode without touching timers? [ ... ] > @@ -4865,6 +4889,10 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm,= bool init_event) > svm->vmcb->control.allowed_sev_features =3D sev->vmsa_features | > VMCB_ALLOWED_SEV_FEATURES_VALID; > =20 > + if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP) > + svm->vmcb->control.esmtp_timeout =3D mul_u64_u32_div(esmtp_timeout_ns, > + tsc_khz, 1000000); > + > /* Can't intercept CR register access, HV can't modify CR registers */ > svm_clr_intercept(svm, INTERCEPT_CR0_READ); > svm_clr_intercept(svm, INTERCEPT_CR4_READ); [Severity: Low] Should this read use READ_ONCE(esmtp_timeout_ns)? esmtp_timeout_ns is a 0644 module parameter updated via sysfs under kernel_param_lock, so an unmarked plain read here during vCPU creation, reset, or migration races with sysfs writes and triggers a KCSAN data-race report. > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 6947447daa4bc..affd0e7982d54 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -3872,8 +3872,12 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, = fastpath_t exit_fastpath) > return 0; > } > =20 > - if (svm->vmcb->control.exit_code =3D=3D SVM_EXIT_IDLE_REQUIRED) > + if (svm->vmcb->control.exit_code =3D=3D SVM_EXIT_IDLE_REQUIRED || > + svm->vmcb->control.exit_code =3D=3D SVM_EXIT_ESMTP_RETRY || > + svm->vmcb->control.exit_code =3D=3D SVM_EXIT_ESMTP_ILLSIB || > + svm->vmcb->control.exit_code =3D=3D SVM_EXIT_ESMTP_TIMEOUT) { > return 1; > + } > =20 > if (exit_fastpath !=3D EXIT_FASTPATH_NONE) > return 1; [Severity: High] Does svm_vcpu_run() drop pending TLB/ERAP flushes and VMCB dirty bits when VMRUN aborts with one of these non-entry ESMTP or SMTP exit codes? svm_vcpu_run() guards its post-VMRUN cleanup only with !svm_is_vmrun_failure(), which matches SVM_EXIT_ERR alone: arch/x86/kvm/svm/svm.c:svm_vcpu_run() { ... if (!svm_is_vmrun_failure(svm->vmcb->control.exit_code)) { this_cpu_ptr(&svm_data)->flush_all_asids =3D false; svm->vmcb->control.tlb_ctl =3D TLB_CONTROL_DO_NOTHING; if (cpu_feature_enabled(X86_FEATURE_ERAPS)) svm->vmcb->control.erap_ctl &=3D ~ERAP_CONTROL_CLEAR_RAP; vmcb_mark_all_clean(svm->vmcb); ... } Because VMRUN never entered guest mode on SVM_EXIT_IDLE_REQUIRED or SVM_EXIT_ESMTP_*, hardware does not guarantee that pending TLB flushes, RAP clears, or VMCB clean-bit updates were performed. When svm_handle_exit() returns 1 to retry VMRUN, those flushes are not re-armed (for example, pre_sev_run() skips TLB_CONTROL_FLUSH_ASID because sd->sev_vmcbs[asid] and last_vmentry_cpu were already updated), which can leave stale NPT/ASID TLB translations or stale cached VMCB state active on guest entry. Using a separate predicate in svm_vcpu_run() that covers all non-entry VMRUN exit codes would preserve pending flushes and VMCB dirty bits across retries. [Severity: Medium] Can svm_complete_interrupts() re-inject a stale event from control->exit_int_info on a non-entry ESMTP or SMTP VMRUN abort? If hardware leaves VMCB control.exit_int_info unmodified when VMRUN aborts before guest entry (as with SVM_EXIT_ERR), and control->event_inj is zero on that run (for instance after userspace cleared an injected event via KVM_SET_VCPU_EVENTS, or after a prior X86_TRAP_VC exit), svm_complete_interrupts() skips its event_inj overwrite and re-processes the stale SVM_EXITINTINFO_VALID entry from the previous VM-exit. svm_cancel_injection() already zeroes control->exit_int_info for this reason, so clearing it before VMRUN or on pre-entry aborts would prevent resurrecting old interrupts, NMIs, or exceptions. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796503783.gi= t.prsampat@amd.com?part=3D3