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=1796511814; b=H//C0ksiPyvFFuiqG0efV6nw4NJrbUvOtRWN+Tion4ROAjB7R6cP9TODWTeMQf/xKgVW R5tLskh922oioHKCYJhKfXx48zyCoUMY/MJIJMulvFP5c5Y++AW2n+6JWjJaOKJZ3p4M0 6BzxlWetjI2VncLmcvXXXKeRq0mHjF7bA5WtsPCfuKTizofjhi+FGGGvm1O9RvZW6eJ+r vCnHYY8yd+cmt8UrmMzgAw0JtmFzwrWPQtDyP4VmXOKbPyutfDP7FmP/AqRPEn7vlExSh BPa4XcokovBBtRMLNNCGKZBpcAW70mi+nIfvh1kVOR9yEXK1Sg7xgAd6sOKd+pMPfbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796511814; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=C4OgubuOYtp/HX8fxtXi5SnaCpdzAygoxeC/jnx6FC8=; b=aOj2BbIZtuNkoxqvlNOUgMKsUlBOmxFp4h/mPpCFvmbguf+okbPeDYwlaefAl0x8WUuZ Usx3siBeiy7ZLN2S8Z8LFJc+F6JhdTtSuh3nnQLxBrqMav/kl7o+I8CG/luZxAvVtlJ1v Idw6CT32QT2zWyXC2/0kTFCjiLiLHhW8XgGQzXFDo03yO+uMfEn647tlbEMzJhge0XiPS Y3ZPwyPm5kQwJgt212s9FiJYuBFGCECrAgEc7bKnkWVDA+FfWVzGPjer0X8LIZGLejYEr yqDm3UxuvRzGUbzgz2NjnxqUL4SS1HAP5Hu5Y8K1EOVbM77hW3nNclgzNC6vNJCu0dQ== 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=AGq1SQN9; 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 4622E606A31F for ; Sat, 5 Dec 2026 23:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AGq1SQN9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA1251F0092B; Sat, 5 Dec 2026 23:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796511813; bh=C4OgubuOYtp/HX8fxtXi5SnaCpdzAygoxeC/jnx6FC8=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=AGq1SQN9Ol2yG5F4hj/0Ieqt9E87HXd14RiZHX/ppjGhxQh4YiBUJKlKKwA1LNejM WB8XlWozMrvAFyoahTzjyYC4PKQ/wU+kzEfuCW4+FspzWyFSQaofTEZO/Rxt6dR5E/ AomtZRfdNntO7y0Qb0GV9hP6YdgB02/Zm0iENzIWCwDgABz6Y1uZ/U6NAz5mxSPRCf hB+8lsbTW6d/X5H+j9bL4fVRLGoXufsXuHnlLJomUz+/vDr3h7ztSpOR7ej1U5oIFB Z3i67vbtzSCxRc+1reqoGfDZsrTnnVo+GrVTENVKx+eiGtEvZ3k/7CtijckenrNOf0 +hMlD8JBYz8VA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection Reply-To: sashiko-reviews@lists.linux.dev To: "Pratik R. Sampat" , kvm@vger.kernel.org In-Reply-To: <06a05ba32a3e94f24fdf18a67be390f4f05b0582.1796503783.git.prsampat@amd.com> References: <06a05ba32a3e94f24fdf18a67be390f4f05b0582.1796503783.git.prsampat@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 23:03:33 +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 8 potential issues to consider: - [High] KVM: SVM: sev_enable_idle_wakeup_icr() uses x2APIC ICR encoding on xAPIC hosts - [High] KVM: SVM: svm_vcpu_run() drops TLB and VMCB state on SVM_EXIT_IDLE_REQUIRED - [Medium] KVM: SVM: spurious LAPIC timer IRQs from sev_enable_idle_wakeup_icr() - [Medium] KVM: SVM: unbounded retry on SVM_EXIT_IDLE_REQUIRED in svm_handle_exit() - [Medium] KVM: SVM: stale exit_int_info not cleared on SVM_EXIT_IDLE_REQUIRED - [Low] KVM: SVM: 32-bit exit_code truncation breaks SVM_EXIT_IDLE_REQUIRED tracing - [Low] kvm: svm: svm_complete_interrupts() clobbers VMCB exit_int_info and event_inj - [Low] kvm: svm: inaccurate EVENTINJ clear comment in svm_complete_interrupts() -- commit 1620d819054cdfe726666bc9ca1d59aff6c97c0e Author: Pratik R. Sampat KVM: SVM: Add host support for SMT Protection This commit adds host KVM support for AMD SEV-SNP SMT Protection (SMTP), programming MSR_AMD64_IDLE_WAKEUP_ICR when virtualization is enabled on a CPU and retrying VMRUN on SVM_EXIT_IDLE_REQUIRED exits. [ ... ] > diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/= svm.h > index e806761850921..f9f972177b082 100644 > --- a/arch/x86/include/uapi/asm/svm.h > +++ b/arch/x86/include/uapi/asm/svm.h > @@ -136,6 +136,7 @@ > #define SVM_EXIT_SW 0xf0000000ull > =20 > #define SVM_EXIT_ERR -1ull > +#define SVM_EXIT_IDLE_REQUIRED -3ull /* SMT Protection: sibling not idle= */ > =20 > #define SVM_EXIT_REASONS \ > { SVM_EXIT_READ_CR0, "read_cr0" }, \ > @@ -248,7 +249,8 @@ > { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, \ > { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ > { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ > - { SVM_EXIT_ERR, "invalid_guest_state" } > + { SVM_EXIT_ERR, "invalid_guest_state" }, \ > + { SVM_EXIT_IDLE_REQUIRED, "idle_required" } [Severity: Low] Can trace_kvm_exit() ever match this SVM_EXIT_REASONS entry? svm_get_exit_info() truncates control->exit_code (-3ull) to a u32 (0xfffffffd), and TRACE_EVENT_KVM_EXIT stores exit_reason as an unsigned int. When passed to __print_symbolic_u64(), it zero-extends to 0x00000000fffffffdULL, which never matches 0xfffffffffffffffdULL, so traces always print raw hex instead of "idle_required". > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index b90c5f14c1ac9..ad802211ec4f7 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c [ ... ] > @@ -3314,6 +3317,31 @@ int sev_cpu_init(struct svm_cpu_data *sd) > return 0; > } > =20 > +void sev_enable_idle_wakeup_icr(void) > +{ > + unsigned int cpu, sibling, shift; > + u32 core; > + > + if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_SMTP)) > + return; > + > + cpu =3D raw_smp_processor_id(); > + shift =3D topology_get_domain_shift(TOPO_CORE_DOMAIN); > + core =3D per_cpu(x86_cpu_to_apicid, cpu) >> shift; > + > + for_each_present_cpu(sibling) { > + u32 apicid =3D per_cpu(x86_cpu_to_apicid, sibling); > + u64 icr; > + > + if (sibling =3D=3D cpu || (apicid >> shift) !=3D core) > + continue; > + > + icr =3D (u64)apicid << 32; [Severity: High] Does sev_enable_idle_wakeup_icr() work on hosts running in legacy xAPIC mode? It unconditionally places apicid in bits 63:32 (x2APIC layout) without checking x2apic_mode, and sev_hardware_setup() advertises SVM_SEV_FEAT_SMTP regardless of APIC mode. In xAPIC mode, the 8-bit physical destination ID belongs in bits 63:56 (SET_XAPIC_DEST_FIELD(apicid) in ICR2) and bits 55:32 are reserved. On xAPIC hosts, the WRMSR either faults (leaving MSR_AMD64_IDLE_WAKEUP_ICR at 0 after WARN_ON_ONCE) or targets APIC ID 0 instead of the sibling, preventing hardware from kicking the guest vCPU out of guest mode and stalling the idle sibling from servicing interrupts. Format the destination according to x2apic_mode, or gate SVM_SEV_FEAT_SMTP on x2APIC mode. > + icr |=3D LOCAL_TIMER_VECTOR; > + WARN_ON_ONCE(wrmsrq_safe(MSR_AMD64_IDLE_WAKEUP_ICR, icr)); > + } > +} [Severity: Medium] Is LOCAL_TIMER_VECTOR safe to use as the wakeup IPI vector here? Every hardware idle-wakeup IPI will enter local_apic_timer_interrupt(), incrementing APIC_TIMER stats and invoking evt->event_handler(). In periodic or low-resolution tick modes (e.g. highres=3Doff), tick_handle_periodic() unconditionally runs tick_periodic() without checking dev->next_event, prematurely advancing jiffies and charging bogus CPU ticks; even in high-resolution mode, every wakeup runs hrtimer_interrupt() and reprograms the LAPIC timer. Consider using a lightweight wakeup vector without timer side effects, such as RESCHEDULE_VECTOR or POSTED_INTR_VECTOR. > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 1d45bcc04112c..6947447daa4bc 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c [ ... ] > @@ -3870,6 +3872,9 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, f= astpath_t exit_fastpath) > return 0; > } > =20 > + if (svm->vmcb->control.exit_code =3D=3D SVM_EXIT_IDLE_REQUIRED) > + return 1; > + > if (exit_fastpath !=3D EXIT_FASTPATH_NONE) > return 1; [Severity: High] Does svm_vcpu_run() drop pending TLB flushes, ERAPS clears, and dirty VMCB state when VMRUN aborts with SVM_EXIT_IDLE_REQUIRED? In svm_vcpu_run(), the post-VMRUN cleanup of flush_all_asids, vmcb->control.tlb_ctl, ERAP_CONTROL_CLEAR_RAP, and vmcb_mark_all_clean() is guarded only by !svm_is_vmrun_failure(svm->vmcb->control.exit_code), which only matches SVM_EXIT_ERR. Because SVM_EXIT_IDLE_REQUIRED aborts before entering guest mode, hardware is not guaranteed to have performed those VMCB control actions, as established by commits 60d93c27859f ("KVM: SVM: Preserve TLB control (i.e. pending TLB flush) on failed VMRUN") and e27fc915c8f5 ("KVM: SVM: Update control fields on #VMEXIT if and only if VMRUN succeeded"). On retry, pre_sev_run() and vcpu_enter_guest() have already updated sd->sev_vmcbs[asid] and last_vmentry_cpu, so cleared per-ASID and pCPU-wide TLB flushes are permanently lost, risking stale TLB translations across guests and host. [Severity: Medium] Can returning 1 unconditionally on SVM_EXIT_IDLE_REQUIRED cause a 100% CPU mutual livelock? If two SMTP-enabled vCPUs are scheduled on sibling threads of the same physical core, neither sibling is HLT-idle, so both vCPUs spin in vcpu_run() -> vcpu_enter_guest() -> VMRUN -> SVM_EXIT_IDLE_REQUIRED indefinitely with zero guest forward progress. Neither CFS SMT balancing (smt_balance() returns false when no idle core exists) nor standard per-VM SCHED_CORE (where vCPUs of the same VM share a cookie and are co-scheduled together in pick_next_task()) separates them. Consider adding backoff, yielding, or scheduler coordination on repeated SVM_EXIT_IDLE_REQUIRED exits. [Severity: Medium] Can svm_complete_interrupts() re-queue a stale event from vmcb->control.exit_int_info after SVM_EXIT_IDLE_REQUIRED? If hardware leaves exit_int_info untouched on a pre-entry abort like SVM_EXIT_IDLE_REQUIRED, svm_vcpu_run() calling svm_complete_interrupts() with control->event_inj =3D=3D 0 will read the stale exit_int_info from a p= rior exit. For example, if an AP exits with SVM_EXITINTINFO_VALID set and is then reset via SVM_VMGEXIT_AP_CREATE (kvm_vcpu_reset() -> init_vmcb() does not clear exit_int_info), a subsequent SVM_EXIT_IDLE_REQUIRED with event_inj =3D=3D 0 spuriously re-queues the pre-reset event into the freshly reset AP. Clearing vmcb->control.exit_int_info (or calling svm_cancel_injection()) on pre-entry VMRUN aborts would avoid reading stale EXITINTINFO. [Severity: Low] In commit "KVM: SVM: Re-queue events that were never injected", does svm_complete_interrupts() clobber control->exit_int_info and control->event_inj in the VMCB before svm_handle_exit() inspects them? svm_vcpu_run() calls svm_complete_interrupts() before svm_handle_exit(). When control->event_inj is non-zero, overwriting control->exit_int_info and zeroing control->event_inj in the VMCB causes dump_vmcb() on SVM_EXIT_ERR to report event_inj as 0 and misreport the staged event under exit_int_info (and trace_kvm_nested_vmexit() to log the overwritten value). Using local variables instead of mutating control->exit_int_info in the VMCB would preserve the diagnostic state. [Severity: Low] As reported by Sean Christopherson on v1 [1], the comment added to svm_complete_interrupts() in commit "KVM: SVM: Re-queue events that were never injected" inaccurately states that hardware clears EVENTINJ when it injects an event. Hardware actually clears EVENTINJ unconditionally on #VMEXIT when exiting guest mode (as documented in shutdown_interception()), whereas pre-entry exits abort VMRUN before entering guest mode and leave EVENTINJ intact. [1] https://lore.kernel.org/r/arFYHRzNFT886BME@google.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796503783.gi= t.prsampat@amd.com?part=3D2