From nobody Mon Feb 9 02:13:23 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 AAC6B32ABC6 for ; Thu, 13 Nov 2025 23:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763077074; cv=none; b=ngFtGtHxVMBRhzG29OtyvFB68hErc4w6z0SmcIhGm4A5tRtffmFEJE87doqQrH7bvxyHD7bOuGXHZ4VCWgqmPA886t8Nc4qjseEftnbee/xXVaaZhKvNB2JvMsLqZRhHQO0SEeRJXGqzR7ECkOB8FQ+uIjgt7YG+Bt3H/x3QSxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763077074; c=relaxed/simple; bh=0rvBOQb7/KjgLAdCRV+FubR5NXzYQ6DUt4LwEzP/hw8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KF5GKPGd69WnkgLc3TFXkS4FQdddpQrTKTYuxHM/yD2V+rDucdipEhT2CobxKgu6WUxctglInP3nWmj+eGv5CIhQ2lG9oh5D0tJ5DgUpUapJawglUGVmL1D0D2sOSDVonXGYronefR3YJyWwvzhlGgAoTjxRXKrXWdTSnDzubE0= 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=ut3ODSdc; arc=none smtp.client-ip=209.85.216.73 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="ut3ODSdc" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3438b1220bcso1936937a91.2 for ; Thu, 13 Nov 2025 15:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763077072; x=1763681872; 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=agrcyZXVeAoDNpOX3Y9kFCrU6uZpFNbMSLv5IvOZ2fY=; b=ut3ODSdcaarnt44PB8XxmhcCTFyM5KGtHpvLPKHMpGi82/PpdH3oQ4SLBemHXXN/pq ZMHK+HWs/SCoszR6NCVRaCvPZbDfmd88qDaf0AGOfbfeNxHG2vAjanfZ6QC2+nEX/IP2 jIBu00zfqhSAltS3NFOA8hjg5xwK3XHJzzfp5m+h4IYGmp4LCHUslJaQrUtwFbxv36zT KFTMAJCQY3OPXFzawTT+UEXK4Lh6JiFvfGJFEbCUVi5moUZh+IjrD5PkJNrR2VFbQLPe SvFZRD7vOr/UxbzzmqP2ag0e/QoC/WCMXvTInOyRx3gp4LbHTGSVfzg1FX6/0SLbJ+9e d0nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763077072; x=1763681872; 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=agrcyZXVeAoDNpOX3Y9kFCrU6uZpFNbMSLv5IvOZ2fY=; b=i7w1o2h0y1ZswKP+klU2p7sy9j31IQGiNCZiTVgxLYs5R5RFOheP8JNeYLBhxl81ue wFcsBOen3suv0xqRKmJnohsfcH3DXO9+yTOv4tk3M3hxYZDOHfylls6ub/+vCCbVxHmm E/9NCi3xQAL0PLzvCYs9ooNO+xmsXKt6G1lA/eAjExWsJgsQXhYAmL20bYOku3DRDrPo UWc3IXIWlZVzAP/IhzXX3kzbyi6MmiMVK8/iBdYyFUZ9f0RnS8pt06v1Kll6v/GdwPak SXZzXNWgiFm9k8jrw6XlCiU1o2i0ua2SNM67d/IBUyUEFmiKxfUZkdOQQMENjDtejqmy wZDA== X-Forwarded-Encrypted: i=1; AJvYcCX/aRxmf0H0nmqJHid+00Tvj8JAVTFk1xWJtovs+I+cO13GTcK67DDekxjOlhukPNx5pS1V8xHhhmaTNiw=@vger.kernel.org X-Gm-Message-State: AOJu0YxdK7CAEaA4fhhVePVb3VUtKKbcj/kUVIsogUpwsk7hZ3yBwybD RsndqAsC3eY8Bn8VeLBv98V4m755xsnMCThc3s3E4iaQptN7qAH2qCqGMJ69DoSkS+Us2cHcOa1 BiHzK3w== X-Google-Smtp-Source: AGHT+IGsIphPIOP+Qi59yhXJyxWnKWUiVNSnwW5PiF9bG5U2jX7YId16YUivlnVIwRZejZpt2zGOCzdWVj8= X-Received: from pjxg3.prod.google.com ([2002:a17:90a:dac3:b0:33b:52d6:e13e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2781:b0:341:134:a962 with SMTP id 98e67ed59e1d1-343fa638d82mr908199a91.28.1763077071969; Thu, 13 Nov 2025 15:37:51 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 15:37:39 -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-3-seanjc@google.com> Subject: [PATCH v5 2/9] x86/bugs: Use VM_CLEAR_CPU_BUFFERS in VMX as well 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" From: Pawan Gupta TSA mitigation: d8010d4ba43e ("x86/bugs: Add a Transient Scheduler Attacks mitigation") introduced VM_CLEAR_CPU_BUFFERS for guests on AMD CPUs. Currently on Intel CLEAR_CPU_BUFFERS is being used for guests which has a much broader scope (kernel->user also). Make mitigations on Intel consistent with TSA. This would help handling the guest-only mitigations better in future. Signed-off-by: Pawan Gupta [sean: make CLEAR_CPU_BUF_VM mutually exclusive with the MMIO mitigation] Acked-by: Borislav Petkov (AMD) Signed-off-by: Sean Christopherson Reviewed-by: Brendan Jackman --- arch/x86/kernel/cpu/bugs.c | 13 +++++++++---- arch/x86/kvm/vmx/vmenter.S | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index d7fa03bf51b4..c3a26532a209 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -194,7 +194,7 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_cond_l1d_flush); =20 /* * Controls CPU Fill buffer clear before VMenter. This is a subset of - * X86_FEATURE_CLEAR_CPU_BUF, and should only be enabled when KVM-only + * X86_FEATURE_CLEAR_CPU_BUF_VM, and should only be enabled when KVM-only * mitigation is required. */ DEFINE_STATIC_KEY_FALSE(cpu_buf_vm_clear); @@ -489,8 +489,8 @@ static enum rfds_mitigations rfds_mitigation __ro_after= _init =3D IS_ENABLED(CONFIG_MITIGATION_RFDS) ? RFDS_MITIGATION_AUTO : RFDS_MITIGATI= ON_OFF; =20 /* - * Set if any of MDS/TAA/MMIO/RFDS are going to enable VERW clearing - * through X86_FEATURE_CLEAR_CPU_BUF on kernel and guest entry. + * Set if any of MDS/TAA/MMIO/RFDS are going to enable VERW clearing on ex= it to + * userspace *and* on entry to KVM guests. */ static bool verw_clear_cpu_buf_mitigation_selected __ro_after_init; =20 @@ -536,6 +536,7 @@ static void __init mds_apply_mitigation(void) if (mds_mitigation =3D=3D MDS_MITIGATION_FULL || mds_mitigation =3D=3D MDS_MITIGATION_VMWERV) { setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); + setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM); if (!boot_cpu_has(X86_BUG_MSBDS_ONLY) && (mds_nosmt || smt_mitigations =3D=3D SMT_MITIGATIONS_ON)) cpu_smt_disable(false); @@ -647,6 +648,7 @@ static void __init taa_apply_mitigation(void) * present on host, enable the mitigation for UCODE_NEEDED as well. */ setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); + setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM); =20 if (taa_nosmt || smt_mitigations =3D=3D SMT_MITIGATIONS_ON) cpu_smt_disable(false); @@ -748,6 +750,7 @@ static void __init mmio_apply_mitigation(void) */ if (verw_clear_cpu_buf_mitigation_selected) { setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); + setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM); static_branch_disable(&cpu_buf_vm_clear); } else { static_branch_enable(&cpu_buf_vm_clear); @@ -839,8 +842,10 @@ static void __init rfds_update_mitigation(void) =20 static void __init rfds_apply_mitigation(void) { - if (rfds_mitigation =3D=3D RFDS_MITIGATION_VERW) + if (rfds_mitigation =3D=3D RFDS_MITIGATION_VERW) { setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); + setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF_VM); + } } =20 static __init int rfds_parse_cmdline(char *str) diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S index 93cf2ca7919a..7e7bb9b7162f 100644 --- a/arch/x86/kvm/vmx/vmenter.S +++ b/arch/x86/kvm/vmx/vmenter.S @@ -165,7 +165,7 @@ SYM_FUNC_START(__vmx_vcpu_run) mov VCPU_RAX(%_ASM_AX), %_ASM_AX =20 /* Clobbers EFLAGS.ZF */ - CLEAR_CPU_BUFFERS + VM_CLEAR_CPU_BUFFERS =20 /* Check @flags to see if vmlaunch or vmresume is needed. */ testl $VMX_RUN_VMRESUME, WORD_SIZE(%_ASM_SP) --=20 2.52.0.rc1.455.g30608eb744-goog