From nobody Mon Nov 25 01:32:20 2024 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 26939199FDC; Thu, 31 Oct 2024 11:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730372791; cv=none; b=otp3c+LTvyiyau7AT4la7wHtQlCqTep/GTvbRuTRPg7sNytLhvsIKoLSCDe23vTgBRLkvAMDNW5Vpj/pF4yUiev+o8fl1AIREojRFugU/slXnWyzA+Yey24lYYXnvRyhKuktbp9scOFTkImTyJz3I1Vik9SkmZVC+kFcVphgNEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730372791; c=relaxed/simple; bh=ZEwEqixcj6ft7PZBzEBsHv+EiCt+eS9FQT2H/Xqhx0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GnoHpXULLsE+xhy9DdmuDhX3oGxmSIgmS8tz5J8TZeVFVhiHVnkPzY3t5j6evFNye03a6m4KmLg5CIOk1hxK1Vv4N+XbWIYBBf/4T0tG8n4bEfzVszccD2w/2fxsLSuSpPubpocvYtLLziymY3RyjuVEvQSRJg0uOnr/BJ/kksU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5ceb03aaddeso417149a12.2; Thu, 31 Oct 2024 04:06:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730372787; x=1730977587; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h18s88CLX8JiqpfQaDviuaecMfdKomNEp9V6gWdT0T0=; b=gU3kZ9ttEuzgjtFWncBKQ3dmOBJBcEGIYQXp1mwfNUoHinEmgLVo3m1IDlQHis2/ou kakaMV8CrtpR1o23uoigGBdYbZ1nIsBGRToMTgeRw0fLQT9iP+Y0934pRVVOzvLw+ETL lLUJ+P4ZS9kYUw75EucUUgW3Z7ibR8TeF/Usd+bqf8NP6gwMGpO1ZAaHK9BpEBoIftMq +NPi06Lkon3q+OkgettvQGl3MwJy1B1Y0XtAkY7unIe2lpHGk0k2ixCNjtlVB2g7cC/g AIoCP2mYyf85kAv9jICp/RX4ScSwPkjNAF3RFWx1lDqJy+h3NVDdQ1OgDS9jmOtuU4g6 JqcQ== X-Forwarded-Encrypted: i=1; AJvYcCVh9r+87XKTMAKseahOBzJJ+u4ZaU4pG4RIzOay+OujgYnZH0Y0jJbrolAxnpBVa7tr4EAyTQlIe+8=@vger.kernel.org X-Gm-Message-State: AOJu0YzC9cp34A95l/jtPfezTQe7s2T0R+ulNP5yj2oTBHOL3ATyVQTC aWkyhzhhg9U3PvVqRyD6VgTjIzPxFcEHkFXggecK8VKhGYqa7G+H X-Google-Smtp-Source: AGHT+IFUpxA87yGLca+7yFvdoDwW9Luvv3EpQL56AAyRakTZWFo10GnD3fEzXjfeaUWDuCnDrnO/qg== X-Received: by 2002:a17:907:9713:b0:a9d:e01e:ffa9 with SMTP id a640c23a62f3a-a9de5f82589mr1641491866b.33.1730372787281; Thu, 31 Oct 2024 04:06:27 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9e564c615bsm54790366b.80.2024.10.31.04.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 04:06:26 -0700 (PDT) From: Breno Leitao Date: Thu, 31 Oct 2024 04:06:16 -0700 Subject: [PATCH v2 1/2] x86/bugs: Use cpu_smt_possible helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241031-x86_bugs_last_v2-v2-1-b7ff1dab840e@debian.org> References: <20241031-x86_bugs_last_v2-v2-0-b7ff1dab840e@debian.org> In-Reply-To: <20241031-x86_bugs_last_v2-v2-0-b7ff1dab840e@debian.org> To: Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Pawan Gupta , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Breno Leitao X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1791; i=leitao@debian.org; h=from:subject:message-id; bh=ZEwEqixcj6ft7PZBzEBsHv+EiCt+eS9FQT2H/Xqhx0I=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnI2SvRpv11buT8J7ULL6F4UFG5en8+qjkqaCK7 GMFtwLij/GJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZyNkrwAKCRA1o5Of/Hh3 bY0UD/45wgDHLM5osYntnuTrgsYRum3q3vIJg72bJdxRrSh6SmbJIUSPPsy4DpX0HKwlRFEnM4F YFDTq8K4+LUHaNbriwpDM2Q9vo8nCSUzYhGf/wOgxGDhIhw5nmmCgM4x+qO+BEKfRXNP9lT8SF1 +PIq4duBguPtEDmuCNjpdT52UkUeX0AXzLh7W+epgJES6oJIRxZIWTEI6q0tZupzD5a/6oWClIL NSvZAouj2vYUtVsYK6puP5hBTSFwHBn1Lz9GKOwE//hJGdiXdhitM0o7qmroMM/tc6c3/X+abMU sU8zb2T355kRSi6KyA+e023i6usbNVP/jZ9lA4VQKsvP5GDsreEdQmZVECDQPEWG0VX9behH1bV Q9/syoZHpcGHwuhX83o28OeNlzLaXzFqi4FLnVnXUoBcvKvpozQkdzQQXxOMnrW38wR0vhIfM2W li1/oGuL1X34WXFv5bx0I1i7c58dlv64WWlJfOrSgDYguHgVBknSk9sEN7ods7dIc/aDbfJ/3Km IsHRe1D8qQZVnw069RZBp2PtuD8mCel8vgRA8KMMB0fEDp6VKLwvCTOUOuk/4K8dkgE0A00xvcn apfoPlrezYkht4KoUMGGs9ImL7n4HjnQFIqv8I9zW3M5qMaEzrKC9kX9PmvHVXAacSayP30He6+ Sfbld3YCjY5yInQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D There is a helper function to check if SMT is available. Use this helper instead of performing the check manually. The helper function cpu_smt_possible() does exactly the same thing as was being done manually inside spectre_v2_user_select_mitigation(). Specifically, it returns false if CONFIG_SMP is disabled, otherwise it checks the cpu_smt_control global variable. This change improves code consistency and reduces duplication. Signed-off-by: Breno Leitao Reviewed-by: Pawan Gupta --- arch/x86/kernel/cpu/bugs.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 47a01d4028f60e012d1e625e1667842b52948038..ceaa5f0c742025a62aa564aaa9c= dfa1fe86e681c 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1332,16 +1332,11 @@ static void __init spectre_v2_user_select_mitigation(void) { enum spectre_v2_user_mitigation mode =3D SPECTRE_V2_USER_NONE; - bool smt_possible =3D IS_ENABLED(CONFIG_SMP); enum spectre_v2_user_cmd cmd; =20 if (!boot_cpu_has(X86_FEATURE_IBPB) && !boot_cpu_has(X86_FEATURE_STIBP)) return; =20 - if (cpu_smt_control =3D=3D CPU_SMT_FORCE_DISABLED || - cpu_smt_control =3D=3D CPU_SMT_NOT_SUPPORTED) - smt_possible =3D false; - cmd =3D spectre_v2_parse_user_cmdline(); switch (cmd) { case SPECTRE_V2_USER_CMD_NONE: @@ -1402,7 +1397,7 @@ spectre_v2_user_select_mitigation(void) * so allow for STIBP to be selected in those cases. */ if (!boot_cpu_has(X86_FEATURE_STIBP) || - !smt_possible || + !cpu_smt_possible() || (spectre_v2_in_eibrs_mode(spectre_v2_enabled) && !boot_cpu_has(X86_FEATURE_AUTOIBRS))) return; --=20 2.43.5 From nobody Mon Nov 25 01:32:20 2024 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 CCBA219A2BD; Thu, 31 Oct 2024 11:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730372793; cv=none; b=aGyuXuLLrS2Izsu1s/diLoDRzby1nIz3I4iF1VLibAYbv5vKMx1wfwQCSQ6T/d/9OyjMgKfl6PyWkfcy5bsxU8ZAdw5y32tJLxwzOxQ2q4i3GjPkareNj/lnUYRZzLNlQ5wY0SipUWB+tNdpgpWv81GMz1xpd4jWYIpsnRDzy1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730372793; c=relaxed/simple; bh=lV+EUJqfDWzyyQHAbyXR9EzAuRsGDjjqPtmGBcuuSbs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jJUP2V9w4yaDTqi03Cspt75RfDoT6H30zib6YFz+FwJA1vHsTlIP8+NtZ0FcPJmqYr3CC1QfYyHGKdvRtLZnR7MRsibwiZRxPVnbxMSyHUWEvfHSC1+U/oPe8USeGZIBycy2/Bxdvc7SWNM6NlOhPBxEaKsda/7trWsGUbe0I5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5c903f5bd0eso1368725a12.3; Thu, 31 Oct 2024 04:06:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730372789; x=1730977589; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+HKORyDDK+Axk/t+2gyImNFveSQGpvk9mihkiuMdmg=; b=GvmTF3botc6npH0fascdcEcwwfjmbF13J4li9qaufePLilnB1tqA/pJ8h04L2TicvA 3ZNV9KwH0/ewNsrcFPynKpUZpYoC0mV8Ho2CZCJJlA3qDgJuPAPwDloMhvkCjVkoZby1 VCb+G1gFaZRfJSjusd/HtnvL6cibaRXg+Wd1jBlZrUwYPrjQ2qBhpQH6UnwRlzcL0Jia SDEJ6S5RD18MAARXNdNyX0DPDPBC9zAkQ0zHMETLaDEC+6cIZ29DWLLNOScekVZyrQKQ yvfiXjMS7m7epj09d/Pt7ebw6fle543iU9zn3rNbpWact/nwnMHM1DGSIPyZEuRUhiaY lLmA== X-Forwarded-Encrypted: i=1; AJvYcCU5f2MuxMHMIkune1PQY/kKz4bfHhxPim1L2LixRM1K13P+z8cDw3zOyQlw9bC2P22P6+/YkuRHLKI=@vger.kernel.org X-Gm-Message-State: AOJu0YwhM1UeH9hUbcGVFPCP7QfR6NZXBCBPUg1m1IZ+wwgOREgzdOOU NKiTNnC6lCj+WjTeNqfQn2SxZrVphC9AYYydfCcAoxMXHKUxsQ2xqarVEohr X-Google-Smtp-Source: AGHT+IGWyWOZyNInhyM0WAt+Txz0HXH7fHoSSTd83QP6JLZTAaW+4dHTcUpMah8HS1e7GvvH59kU1A== X-Received: by 2002:a17:907:2d1e:b0:a9a:4eac:a2a5 with SMTP id a640c23a62f3a-a9e50ba7551mr283173566b.63.1730372788915; Thu, 31 Oct 2024 04:06:28 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9e564e96a9sm54840666b.97.2024.10.31.04.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 04:06:28 -0700 (PDT) From: Breno Leitao Date: Thu, 31 Oct 2024 04:06:17 -0700 Subject: [PATCH v2 2/2] x86/bugs: spectre user default must depend on MITIGATION_SPECTRE_V2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241031-x86_bugs_last_v2-v2-2-b7ff1dab840e@debian.org> References: <20241031-x86_bugs_last_v2-v2-0-b7ff1dab840e@debian.org> In-Reply-To: <20241031-x86_bugs_last_v2-v2-0-b7ff1dab840e@debian.org> To: Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Pawan Gupta , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Breno Leitao X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3259; i=leitao@debian.org; h=from:subject:message-id; bh=lV+EUJqfDWzyyQHAbyXR9EzAuRsGDjjqPtmGBcuuSbs=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBnI2Svgf4IgbrZMCTyQqKs5L+aCyzdr0oQlaAw1 5svrL2h+DSJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCZyNkrwAKCRA1o5Of/Hh3 bdjmEACZiyPRGCQTN5EybwwTJKtu3r5OUhzaMKcawpb4C/v7hpeM9x+x1Ln+uKGhXPcAkeX+c8G fOQ1k+f0TRLWig3BXlxgJT9/5Qw8OLrl27UwKJhZKzqNL4dicnyJcNWMEWuLxhk4eYyjJrB5q8K gWZUencHkUbn1vVPb+S6uOKeJ2MaoK/SbcDAXImzFISJp2/UvY+mBDuIU+Iu24/OBSIr1Yko8z1 6D9UccDSSv/BMAUSqnCDrzuj16cWU+9PBpMueHN9MDvnSQx1WYd+Hii4N/UFrbqfmUFF0w9pRZR 4uRD3AKxPkOzyzoEJuMgO7wE0Ozd01M3lWB0yc7jfGJvfTD/oA0/FwwUta6nO4AdnGEwmPHSgzK y80M+qzBa97ImZg0Nm+XoULTVV/sDWmgqQt9ACR4xbo+xNdNmMs8y262wA/RmpXHkcGE1hB+nUj hsyb4wewrK7zRnIgMreRJUdz7+OTXcYPQQi0Sdih6B9mhCRwox2++UFEe8mBDgDmzxgH70SL4bQ 7mtOMGZXfbUt7pQMO96EfPz+MUzYg1l4o6ppjeo10eT2eJ12QwfxQjdN9pQGEYSnsyHqySww3pl P1rG5vAK0l746VNt/sUDXb6t7kSLPhs1phayQv9ZripP1BDhjuC/Bsha5JnteQGA064IR1o6NCI zjkn2UcEAohLZiA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Change the default value of spectre v2 in user mode to respect the CONFIG_MITIGATION_SPECTRE_V2 config option. Currently, user mode spectre v2 is set to auto (SPECTRE_V2_USER_CMD_AUTO) by default, even if CONFIG_MITIGATION_SPECTRE_V2 is disabled. Set the spectre_v2 value to auto (SPECTRE_V2_USER_CMD_AUTO) if the Spectre v2 config (CONFIG_MITIGATION_SPECTRE_V2) is enabled, otherwise set the value to none (SPECTRE_V2_USER_CMD_NONE). Important to say the command line argument "spectre_v2_user" overwrites the default value in both cases. When CONFIG_MITIGATION_SPECTRE_V2 is not set, users have the flexibility to opt-in for specific mitigations independently. In this scenario, setting spectre_v2=3D will not enable spectre_v2_user=3D, and command line options spectre_v2_user and spectre_v2 are independent when CONFIG_MITIGATION_SPECTRE_V2=3Dn. Signed-off-by: Breno Leitao Acked-by: Josh Poimboeuf Reviewed-by: Pawan Gupta --- Documentation/admin-guide/kernel-parameters.txt | 2 ++ arch/x86/kernel/cpu/bugs.c | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 1518343bbe2237f1d577df5656339d6224b769be..f8bc02cd10ec3012c478e12e90b= ad85d9f70d9ed 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6241,6 +6241,8 @@ =20 Selecting 'on' will also enable the mitigation against user space to user space task attacks. + Selecting specific mitigation does not force enable + user mitigations. =20 Selecting 'off' will disable both the kernel and the user space protections. diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index ceaa5f0c742025a62aa564aaa9cdfa1fe86e681c..236c691c3fd2ac7d41c494d5c7f= bc844d11ae82f 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1294,9 +1294,13 @@ static __ro_after_init enum spectre_v2_mitigation_cm= d spectre_v2_cmd; static enum spectre_v2_user_cmd __init spectre_v2_parse_user_cmdline(void) { + enum spectre_v2_user_cmd mode; char arg[20]; int ret, i; =20 + mode =3D IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ? + SPECTRE_V2_USER_CMD_AUTO : SPECTRE_V2_USER_CMD_NONE; + switch (spectre_v2_cmd) { case SPECTRE_V2_CMD_NONE: return SPECTRE_V2_USER_CMD_NONE; @@ -1309,7 +1313,7 @@ spectre_v2_parse_user_cmdline(void) ret =3D cmdline_find_option(boot_command_line, "spectre_v2_user", arg, sizeof(arg)); if (ret < 0) - return SPECTRE_V2_USER_CMD_AUTO; + return mode; =20 for (i =3D 0; i < ARRAY_SIZE(v2_user_options); i++) { if (match_option(arg, ret, v2_user_options[i].option)) { @@ -1319,8 +1323,8 @@ spectre_v2_parse_user_cmdline(void) } } =20 - pr_err("Unknown user space protection option (%s). Switching to AUTO sele= ct\n", arg); - return SPECTRE_V2_USER_CMD_AUTO; + pr_err("Unknown user space protection option (%s). Switching to default\n= ", arg); + return mode; } =20 static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode) --=20 2.43.5