From nobody Mon Feb 9 08:53:49 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6D5933122A for ; Thu, 13 Nov 2025 23:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763077084; cv=none; b=NVjHnSNqTynw7Jq033o7FGlqUlw/e/ZTyK2rR6xoBMkqxxQARUvxVeqvpF6XLkTz0bFkp9YAdL449gWY/wOklAsQeP4E1ovci7y1ZZ57abJhfE78kgAY0PBwcIgeqT2a98Nx6He/8TgGJZsmfBby8RDuQj1IEWylbUlM7mpH0Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763077084; c=relaxed/simple; bh=wtycuEY2azLWihklz9eK2sJ+qOCuV2/E3a/PpTiKFK0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AvMDvPKe3WgaXMKE6eKB36qnTFJmybr+Ch0Yt6cA2WMkPPsrdFsg8xTcmrcOSk0HtqxZpScf7Pf/zw0n+SDteMozAuXOfnPvvSwk2fOFjTvWuwM9hAgxIzpc9tdASnrqEeBTWbjf6+Oimhfailj/4PnLc/Vgmx9Mvu6j09/uXnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cQVN2nz7; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cQVN2nz7" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7a998ab7f87so2273848b3a.3 for ; Thu, 13 Nov 2025 15:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763077082; x=1763681882; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qQ9BLihijeePl6z+R4l/kmqIlHBheOPmGQ6Y3DB6Ymg=; b=cQVN2nz7S1maOalLN4zPYFyQa11qddOWTK0E3vSaLWiDmyr5JZS5f/1RsIih1VNZSc WbdVFp+2/DxnRGLbH5SZ/jx16KQgTEv76c4sih9CrWxLbsUHUzWPW3UMYeRbI5slo3KX aVM5hwt9pFXo0AYL37dLbUs24WEN6eheF1L5Em+08nVSO4eJIChy6QQVJQGGorjxIWxo TAAB8zyLs//0darEYn98b0ldcuCAyxyWHzzmoacQXFdIn0bD4JEZcc083Dp5/wIOrVdi 2iPQU7yu4YzXzwamef96CMT5XvnOsf+5QeekNNACzC+DKv9cU3YVSUZaTH9cfvXZlZja Gbyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763077082; x=1763681882; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qQ9BLihijeePl6z+R4l/kmqIlHBheOPmGQ6Y3DB6Ymg=; b=wlAIsnswAZ7nUmLw754I3BrCAohLozz/q5P38N4NUK1IceHcmFgFbP15HmQpzzzwsI qdlb7yKmdJLoDv81+pOIKF8+ApIh7Yjvgmrsv71aXoyPsW4jQH6pKcT04zJmhTjCd1J8 jdxkS301gBgnm3mFHLI5FxtyB+i6bRNMUKqtv/jU/pknJN0mnpscYcDkSjngY4SjlyS9 cbV2ENBX4/1koCKvm9rdjmTSN+fRXMNED4520G6U9jgSsjC4v9oeK1Fdr+wfmgUJzGB1 /T39sR5NkI2mAAqxFVFFNFL9XKefQQuhVGfjJcQ+GjowNLqhx2QRKz+UzWrm49+LkkVZ 4A7g== X-Forwarded-Encrypted: i=1; AJvYcCXEc/6G4FVCkPkwlYQT1qpG4chHKI4x6V7qmsNC0J1XHdtXEwDIaN2tG6WGSaUDgtytvDwnTm0mCBS2tJU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk6CrmfclFwxEC/PmjKHY3nrbWewo1KH5yXTNyfc3ngpuYmRX/ bjYXlpaU/qE5ni/oFfwIsDSk8jjJzW0Jgr9aK6JQj8HAsVJ1U121oIHZesUk/kVJgjmANyU16nJ HM+ectA== X-Google-Smtp-Source: AGHT+IFp21U8vXtIEaH8PM9ybXHA3sulW7mjYFjo/+rs+93pjrmeK1XzGOkdPLFjeJExEkEYzWZo81FNomQ= X-Received: from pfm8.prod.google.com ([2002:a05:6a00:728:b0:76b:f0d4:ac71]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a28:b0:7ab:4fce:fa1c with SMTP id d2e1a72fcca58-7ba39ce323emr1304351b3a.1.1763077082235; Thu, 13 Nov 2025 15:38:02 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 15:37:45 -0800 In-Reply-To: <20251113233746.1703361-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251113233746.1703361-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251113233746.1703361-9-seanjc@google.com> Subject: [PATCH v5 8/9] KVM: VMX: Disable L1TF L1 data cache flush if CONFIG_CPU_MITIGATIONS=n From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Josh Poimboeuf Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pawan Gupta , Brendan Jackman Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable support for flushing the L1 data cache to mitigate L1TF if CPU mitigations are disabled for the entire kernel. KVM's mitigation of L1TF is in no way special enough to justify ignoring CONFIG_CPU_MITIGATIONS=3Dn. Deliberately use CPU_MITIGATIONS instead of the more precise MITIGATION_L1TF, as MITIGATION_L1TF only controls the default behavior, i.e. CONFIG_MITIGATION_L1TF=3Dn doesn't completely disable L1TF mitigations in the kernel. Keep the vmentry_l1d_flush module param to avoid breaking existing setups, and leverage the .set path to alert the user to the fact that vmentry_l1d_flush will be ignored. Don't bother validating the incoming value; if an admin misconfigures vmentry_l1d_flush, the fact that the bad configuration won't be detected when running with CONFIG_CPU_MITIGATIONS=3Dn is likely the least of their worries. Reviewed-by: Brendan Jackman Signed-off-by: Sean Christopherson --- arch/x86/include/asm/hardirq.h | 4 +-- arch/x86/kvm/vmx/vmx.c | 56 ++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h index f00c09ffe6a9..6b6d472baa0b 100644 --- a/arch/x86/include/asm/hardirq.h +++ b/arch/x86/include/asm/hardirq.h @@ -5,7 +5,7 @@ #include =20 typedef struct { -#if IS_ENABLED(CONFIG_KVM_INTEL) +#if IS_ENABLED(CONFIG_CPU_MITIGATIONS) && IS_ENABLED(CONFIG_KVM_INTEL) u8 kvm_cpu_l1tf_flush_l1d; #endif unsigned int __nmi_count; /* arch dependent */ @@ -68,7 +68,7 @@ extern u64 arch_irq_stat(void); DECLARE_PER_CPU_CACHE_HOT(u16, __softirq_pending); #define local_softirq_pending_ref __softirq_pending =20 -#if IS_ENABLED(CONFIG_KVM_INTEL) +#if IS_ENABLED(CONFIG_CPU_MITIGATIONS) && IS_ENABLED(CONFIG_KVM_INTEL) /* * This function is called from noinstr interrupt contexts * and must be inlined to not get instrumentation. diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b39e083671bc..ae6b102b1570 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -203,6 +203,7 @@ module_param(pt_mode, int, S_IRUGO); =20 struct x86_pmu_lbr __ro_after_init vmx_lbr_caps; =20 +#ifdef CONFIG_CPU_MITIGATIONS static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush); static DEFINE_STATIC_KEY_FALSE(vmx_l1d_flush_cond); static DEFINE_MUTEX(vmx_l1d_flush_mutex); @@ -225,7 +226,7 @@ static const struct { #define L1D_CACHE_ORDER 4 static void *vmx_l1d_flush_pages; =20 -static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) +static int __vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) { struct page *page; unsigned int i; @@ -302,6 +303,16 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_stat= e l1tf) return 0; } =20 +static int vmx_setup_l1d_flush(void) +{ + /* + * Hand the parameter mitigation value in which was stored in the pre + * module init parser. If no parameter was given, it will contain + * 'auto' which will be turned into the default 'cond' mitigation mode. + */ + return __vmx_setup_l1d_flush(vmentry_l1d_flush_param); +} + static void vmx_cleanup_l1d_flush(void) { if (vmx_l1d_flush_pages) { @@ -349,7 +360,7 @@ static int vmentry_l1d_flush_set(const char *s, const s= truct kernel_param *kp) } =20 mutex_lock(&vmx_l1d_flush_mutex); - ret =3D vmx_setup_l1d_flush(l1tf); + ret =3D __vmx_setup_l1d_flush(l1tf); mutex_unlock(&vmx_l1d_flush_mutex); return ret; } @@ -376,6 +387,9 @@ static noinstr void vmx_l1d_flush(struct kvm_vcpu *vcpu) { int size =3D PAGE_SIZE << L1D_CACHE_ORDER; =20 + if (!static_branch_unlikely(&vmx_l1d_should_flush)) + return; + /* * This code is only executed when the flush mode is 'cond' or * 'always' @@ -433,6 +447,31 @@ static noinstr void vmx_l1d_flush(struct kvm_vcpu *vcp= u) : "eax", "ebx", "ecx", "edx"); } =20 +#else /* CONFIG_CPU_MITIGATIONS*/ +static int vmx_setup_l1d_flush(void) +{ + l1tf_vmx_mitigation =3D VMENTER_L1D_FLUSH_NEVER; + return 0; +} +static void vmx_cleanup_l1d_flush(void) +{ + l1tf_vmx_mitigation =3D VMENTER_L1D_FLUSH_AUTO; +} +static __always_inline void vmx_l1d_flush(struct kvm_vcpu *vcpu) +{ + +} +static int vmentry_l1d_flush_set(const char *s, const struct kernel_param = *kp) +{ + pr_warn_once("Kernel compiled without mitigations, ignoring vmentry_l1d_f= lush\n"); + return 0; +} +static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) +{ + return sysfs_emit(s, "never\n"); +} +#endif + static const struct kernel_param_ops vmentry_l1d_flush_ops =3D { .set =3D vmentry_l1d_flush_set, .get =3D vmentry_l1d_flush_get, @@ -7350,8 +7389,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vc= pu *vcpu, =20 guest_state_enter_irqoff(); =20 - if (static_branch_unlikely(&vmx_l1d_should_flush)) - vmx_l1d_flush(vcpu); + vmx_l1d_flush(vcpu); =20 vmx_disable_fb_clear(vmx); =20 @@ -8716,14 +8754,8 @@ int __init vmx_init(void) if (r) return r; =20 - /* - * Must be called after common x86 init so enable_ept is properly set - * up. Hand the parameter mitigation value in which was stored in - * the pre module init parser. If no parameter was given, it will - * contain 'auto' which will be turned into the default 'cond' - * mitigation mode. - */ - r =3D vmx_setup_l1d_flush(vmentry_l1d_flush_param); + /* Must be called after common x86 init so enable_ept is setup. */ + r =3D vmx_setup_l1d_flush(); if (r) goto err_l1d_flush; =20 --=20 2.52.0.rc1.455.g30608eb744-goog