From nobody Fri Dec 19 07:16:40 2025 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.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 303821E51FA for ; Tue, 18 Feb 2025 18:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905192; cv=none; b=Wk1XYWbZUFRukpapJ5cvpzEiAekzqwjBeDTk4J9j54bM6Z0pbWhlycE6w1N4mBPsAXQR1hCJUv/x7xweQTJO+IcPZWEVnQWXLJJUhYY3bfeHd6E4OFemwWPu/tPGhORnpqqVIqbQVqYcEttaLj9HcArI1PZneuHbs05/BW0jQt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905192; c=relaxed/simple; bh=lOnH/mKyx1+Del/vxG0+xdTDX0A6bFVlFWfN1vk4eS8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GVVogYB6c12lOoEQOYRZU8L6Dpk2MZI0/XhxrP++rJ89yL+aOClVllMLeJ/zi4jluJP3lWjI6jnbwG6YsvDcpsH9Qn9VnVBafyp50C7BBDsucMVMERJ78a6C912v8qWRsjH93wQ6tdc2GMOYJyk9zIVqKJQARdmPeExakgjYVqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Sf3o3ICE; arc=none smtp.client-ip=209.85.221.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--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Sf3o3ICE" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38f4bf0d5faso1156869f8f.0 for ; Tue, 18 Feb 2025 10:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739905189; x=1740509989; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=49VdnZqF35jWIGgVq9B0arGE7pdVdeiBK4kpJ+YCfcM=; b=Sf3o3ICE14ZrxJgSjc81zDMEfiI0JSSqI/oJZjAG2BICgrxrSslVE4KiLl54eeoY4o JHCwW/4OL/h9Jo6QN6mp8IEnib6yWyw5uehgl1ZInE+8q0SrQJq6mairPud87dJ8vSKx Ooio1N1hb2Pz5SZhiHUfRSgXokzHlUjijoFWh3xJukKdCNAKesT4oGRohbEYAfc3La6l gWOoRoO3UfnYUJvM+uu+3+LJ90fZv5r3kt+YtC2DakCXnUjVpo5ERyumJ7RUVQ+DLsmh yI5zGkmmEBvEHf8luMCGwgmsFp+4ZwTgLLQugdgat0AKEoTsJNezsbKF6IrH3KBqQGQ5 YOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739905189; x=1740509989; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=49VdnZqF35jWIGgVq9B0arGE7pdVdeiBK4kpJ+YCfcM=; b=dSCxrMatqBWAosIZgco+ezXcLI38RY4x86mb6Sas3G6elNwsPpzuyHlfWIBLzgabnS dKZrTwuSQHH7ihO9OfFBtzolBg5aqwxuB4csDRsjyKytAnCm8I+sAhvo3q3jxoFXeeUh Zt0kZU9h+4aEHRDNhbZjY0JTNTnuK3TT0aFwh08pXQxtCziNG2rmJbTpDqwa0lriGean M2dbJjOj1UKeLzXxTwV+ZdBZ01+UTsCPu/tmp95FE5pYx0I0kroyhGmFGrmmf8R9PBcm ILEvt1jaVF50oYAamVLsiyPJQlzUClHje5NfsF3GFkYPNWQNVYnaFJA58JqLGY4ZtZ1J 9zUg== X-Forwarded-Encrypted: i=1; AJvYcCVEUP4wZyGIS1eMVMQpVSrsb6J/R07Zz0XN4gqYlfS93lTIXIH5/jcWGtR4V81KkJWuQPt1sS+5+lqY/4E=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0j3sPLkloHsa9EoE8iWA0z99BZntKDyq60LlPpkCPZZ4KR7od u6Q2IhQuKhAAUQS5ucP8Oxbj5PYq9puOYmFDDm2cfZDGlg1VRv0Z+uj2dinpnfy1K5tPRM6LKeL 5xzIB5+xYPQ== X-Google-Smtp-Source: AGHT+IHhKLqwSGAXXWpulCb43w7vxvu09Mncf89xWZhzkOuqLQF9FZl2NnsYRFUe7O9y/YtAfJq7psH2VIQSag== X-Received: from wmbbi18.prod.google.com ([2002:a05:600c:3d92:b0:439:7d73:d8fc]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:adf:e6c8:0:b0:38d:eaee:3b32 with SMTP id ffacd0b85a97d-38f58796874mr416328f8f.26.1739905189680; Tue, 18 Feb 2025 10:59:49 -0800 (PST) Date: Tue, 18 Feb 2025 18:59:39 +0000 In-Reply-To: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> X-Mailer: b4 0.15-dev-42535 Message-ID: <20250218-force-cpu-bug-v3-1-da3df43d1936@google.com> Subject: [PATCH v3 1/4] x86/cpu: Remove some macros about feature names From: Brendan Jackman To: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable These macros used to abstract over CONFIG_X86_FEATURE_NAMES, but that was removed in commit 7583e8fbdc49 ("x86/cpu: Remove X86_FEATURE_NAMES"). Now they are just unnecessary indirection, remove them. Signed-off-by: Brendan Jackman --- arch/x86/include/asm/cpufeature.h | 5 ----- arch/x86/kernel/cpu/common.c | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index de1ad09fe8d7..f23942108b85 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -37,13 +37,8 @@ enum cpuid_leafs NR_CPUID_WORDS, }; =20 -#define X86_CAP_FMT_NUM "%d:%d" -#define x86_cap_flag_num(flag) ((flag) >> 5), ((flag) & 31) - extern const char * const x86_cap_flags[NCAPINTS*32]; extern const char * const x86_power_flags[32]; -#define X86_CAP_FMT "%s" -#define x86_cap_flag(flag) x86_cap_flags[flag] =20 /* * In order to save room, we index into this array by doing diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 76598a93a8fa..f96a3a4829bd 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -667,8 +667,8 @@ static void filter_cpuid_features(struct cpuinfo_x86 *c= , bool warn) if (!warn) continue; =20 - pr_warn("CPU: CPU feature " X86_CAP_FMT " disabled, no CPUID level 0x%x\= n", - x86_cap_flag(df->feature), df->level); + pr_warn("CPU: CPU feature %s disabled, no CPUID level 0x%x\n", + x86_cap_flags[df->feature], df->level); } } =20 @@ -1539,9 +1539,9 @@ static void __init cpu_parse_early_param(void) =20 /* empty-string, i.e., ""-defined feature flags */ if (!x86_cap_flags[bit]) - pr_cont(" " X86_CAP_FMT_NUM, x86_cap_flag_num(bit)); + pr_cont(" %d:%d", bit >> 5, bit & 31); else - pr_cont(" " X86_CAP_FMT, x86_cap_flag(bit)); + pr_cont(" %s", x86_cap_flags[bit]); =20 setup_clear_cpu_cap(bit); taint++; @@ -1554,10 +1554,10 @@ static void __init cpu_parse_early_param(void) } =20 for (bit =3D 0; bit < 32 * NCAPINTS; bit++) { - if (!x86_cap_flag(bit)) + if (!x86_cap_flags[bit]) continue; =20 - if (strcmp(x86_cap_flag(bit), opt)) + if (strcmp(x86_cap_flags[bit], opt)) continue; =20 pr_cont(" %s", opt); --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Dec 19 07:16:40 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 231351EB5C1 for ; Tue, 18 Feb 2025 18:59:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905195; cv=none; b=L/LkgPNw63vdwAmbzzpq5baEx+sAPgMm5IkHoA8rcdfy2vwOf0vMC0yquD3Dbr+ppl67aHk6R4DOZcaJlgtC6OOtHVD1byAxUpNguJL0G2ZhDaBM8ayKiNUrTJZexN3dFxHq+9eKxcz6567AmNYQX3H9hv4cq1g9erEPxB2iwSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905195; c=relaxed/simple; bh=NFINkBrN2m68Dtkx3Nfr3I9LAK5YDzkBgvburJpx9/0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BVzpfxDTwev9iOMufuLi709aVC1I5IXPZbe07EK0VJZ9KQT/WAXP8Wzrwsib9FvnDtc0SdQyFEkgSWIRedBSi3DkYZ3ASbZk0OfR+1q35nAGjTXW9qL7XWN5rMj4Yr5UHtNouu/cS8LtRfTWZZ5mFBEoVT9GNi+mPpXsJ7b458I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TjX01HdD; arc=none smtp.client-ip=209.85.128.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--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TjX01HdD" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-439868806bbso297355e9.1 for ; Tue, 18 Feb 2025 10:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739905191; x=1740509991; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qkbFzOJ58R3pRGkmrijokUluuUu8ft2s70MHpEt0/Gw=; b=TjX01HdD3DsToVuHJDa4WLAhY73RMYo7V8aQgK1lq7ZHIp8JxjsRT7ElA4b+kkLCzI SRQ4+eEmjY1lHFOCswCRBWpUOo1FcT6VDLNmAd6nPAnwKR09wQNMwkutzJp52iEoKRDH MBVlrBgk6psOF9Omecb+xcvEfPerzXsV/BIpHQMwOFoGU4DznZxtaffuDTDpgJetR2X3 VI0em5hq/JMl7MjUYQk1FKqSo/nqmfUreDgYYPEvgqxUOrto7Ww1OjgUQbwY0BBffPn1 OCXtx0VVNUnY9M3TYrGflNERTK8rgN80Qu+DMwsFoUUbvlkg/CinKi3CaYYkOlD4HJOd Ul5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739905191; x=1740509991; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qkbFzOJ58R3pRGkmrijokUluuUu8ft2s70MHpEt0/Gw=; b=bjsITUe387lvAs5rYEVOhFG8Qxq+n4jye4Trz6GNTL0y9Yo66YyZmXVYbqDEXTFsJ2 LTW9pX/VPxdZxy0rNlspAolVhwE/STW1C2sFbVVGmqbmIWcPBwt1Zt0/lkK8rM8xKh6p 76QtJ0xGrfllh8Ulxz/OonkL726N6ero/ZFOZCq6o1pSRfjapwmc2d1aYKeJkUd1Mu+Y JrPltg7HKHf9G7wbGdxTMQ6xAEfPf0evwAOLTHzcSbhbDhR042QIMzQlZLNaL2rJb0G1 BvC8FLA7LeJbV6SbixOmmy77VPj45cNPXgYDJT+0UQ+D2jvrTY9sDlNM3WnS5XlR5ND+ QbZQ== X-Forwarded-Encrypted: i=1; AJvYcCX8+HGXX0n+HedtltMkemkPQkQavq9cs5GYEVrDkeI1nPS9wfmCGybHvIt/ACQD6e8hjBOBK0yFgZ3+hBM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw86OpQlR6HYxMXjHC2Qtmd+Ar9lDDbhOTL4uvTFK2mnyda95+s wDS1ppQ0xCiHOrvA6iWqrZR7vGvFAviy4NWfS57L0zPKncDPPzVTYX5GZjb8I+uoSVOtaLwHjQt qte+rO067lA== X-Google-Smtp-Source: AGHT+IFf4tjcTsmeHv6vxo8C5qfpFSz+rGcmnB97J0xvK8kvFs8Ha8/XW4av6zciXZGnqt+HKgZKQBfIVctZ/g== X-Received: from wmbg23.prod.google.com ([2002:a05:600c:a417:b0:439:95b9:9200]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4449:b0:439:873a:1114 with SMTP id 5b1f17b1804b1-43999ae18f9mr8268715e9.6.1739905191596; Tue, 18 Feb 2025 10:59:51 -0800 (PST) Date: Tue, 18 Feb 2025 18:59:40 +0000 In-Reply-To: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> X-Mailer: b4 0.15-dev-42535 Message-ID: <20250218-force-cpu-bug-v3-2-da3df43d1936@google.com> Subject: [PATCH v3 2/4] x86/cpu: Create helper to parse clearcpuid param From: Brendan Jackman To: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This is in preparation for a later commit that will reuse this code, to make review convenient. Factor out a helper function which does the full handling for this arg including printing info to the console. No functional change intended. Signed-off-by: Brendan Jackman --- arch/x86/kernel/cpu/common.c | 97 ++++++++++++++++++++++++----------------= ---- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index f96a3a4829bd..1241c205b9d0 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1479,56 +1479,18 @@ static void detect_nopl(void) #endif } =20 -/* - * We parse cpu parameters early because fpu__init_system() is executed - * before parse_early_param(). - */ -static void __init cpu_parse_early_param(void) +static inline void parse_clearcpuid(char *arg) { - char arg[128]; - char *argptr =3D arg, *opt; - int arglen, taint =3D 0; - -#ifdef CONFIG_X86_32 - if (cmdline_find_option_bool(boot_command_line, "no387")) -#ifdef CONFIG_MATH_EMULATION - setup_clear_cpu_cap(X86_FEATURE_FPU); -#else - pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n"); -#endif - - if (cmdline_find_option_bool(boot_command_line, "nofxsr")) - setup_clear_cpu_cap(X86_FEATURE_FXSR); -#endif - - if (cmdline_find_option_bool(boot_command_line, "noxsave")) - setup_clear_cpu_cap(X86_FEATURE_XSAVE); - - if (cmdline_find_option_bool(boot_command_line, "noxsaveopt")) - setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); - - if (cmdline_find_option_bool(boot_command_line, "noxsaves")) - setup_clear_cpu_cap(X86_FEATURE_XSAVES); - - if (cmdline_find_option_bool(boot_command_line, "nousershstk")) - setup_clear_cpu_cap(X86_FEATURE_USER_SHSTK); - - /* Minimize the gap between FRED is available and available but disabled.= */ - arglen =3D cmdline_find_option(boot_command_line, "fred", arg, sizeof(arg= )); - if (arglen !=3D 2 || strncmp(arg, "on", 2)) - setup_clear_cpu_cap(X86_FEATURE_FRED); - - arglen =3D cmdline_find_option(boot_command_line, "clearcpuid", arg, size= of(arg)); - if (arglen <=3D 0) - return; + char *opt; + int taint =3D 0; =20 pr_info("Clearing CPUID bits:"); =20 - while (argptr) { + while (arg) { bool found __maybe_unused =3D false; unsigned int bit; =20 - opt =3D strsep(&argptr, ","); + opt =3D strsep(&arg, ","); =20 /* * Handle naked numbers first for feature flags which don't @@ -1570,10 +1532,57 @@ static void __init cpu_parse_early_param(void) if (!found) pr_cont(" (unknown: %s)", opt); } - pr_cont("\n"); =20 if (taint) add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK); + + pr_cont("\n"); +} + + +/* + * Parse cpu parameters early because fpu__init_system() is executed + * before parse_early_param(). + */ +static void __init cpu_parse_early_param(void) +{ + char arg[128]; + int arglen; + +#ifdef CONFIG_X86_32 + if (cmdline_find_option_bool(boot_command_line, "no387")) +#ifdef CONFIG_MATH_EMULATION + setup_clear_cpu_cap(X86_FEATURE_FPU); +#else + pr_err("Option 'no387' required CONFIG_MATH_EMULATION enabled.\n"); +#endif + + if (cmdline_find_option_bool(boot_command_line, "nofxsr")) + setup_clear_cpu_cap(X86_FEATURE_FXSR); +#endif + + if (cmdline_find_option_bool(boot_command_line, "noxsave")) + setup_clear_cpu_cap(X86_FEATURE_XSAVE); + + if (cmdline_find_option_bool(boot_command_line, "noxsaveopt")) + setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); + + if (cmdline_find_option_bool(boot_command_line, "noxsaves")) + setup_clear_cpu_cap(X86_FEATURE_XSAVES); + + if (cmdline_find_option_bool(boot_command_line, "nousershstk")) + setup_clear_cpu_cap(X86_FEATURE_USER_SHSTK); + + /* Minimize the gap between FRED is available and available but disabled.= */ + arglen =3D cmdline_find_option(boot_command_line, "fred", arg, sizeof(arg= )); + if (arglen !=3D 2 || strncmp(arg, "on", 2)) + setup_clear_cpu_cap(X86_FEATURE_FRED); + + arglen =3D cmdline_find_option(boot_command_line, "clearcpuid", arg, size= of(arg)); + if (arglen <=3D 0) + return; + + parse_clearcpuid(arg); } =20 /* --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Dec 19 07:16:40 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 1588B1E521E for ; Tue, 18 Feb 2025 18:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905196; cv=none; b=O+CPUg/RE9cKOb65yx5T/FpSXZa+xSCCKYbL61lx77Ee81cdnK4JjnPReKjJfuvhVatnKQzD2FZrCmJvysNdVDK1B0o8o5HJm7OZoeHySXLYmjC0R3zHUnsmg7OyYNFGB6/9lrCKE2/hzzT/erAHbuGvyNzPlPLK0fJHAEOrz3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905196; c=relaxed/simple; bh=MUX8NCacaOOOA4OaGPglasYy9E+dcC18HNOKsMX/PsY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=H3S+XVwGVMHK+7P8aVGQWlf+hWVlTpCfdXg1UD13YfuyNtAr5HOebLic3goZgRUc3XaS7V4idPWJssxkwIRoPRox2mRLr3PhMlnmEdPxcvd88Xxl/DaM0vPYKkqqFd/iyHd3cWn/Zu8ImqLhohS2e8EYiuVu6mliXfArYSJ2CEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kHNLrt9Z; arc=none smtp.client-ip=209.85.221.74 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--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kHNLrt9Z" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-38f37b4a72fso35857f8f.1 for ; Tue, 18 Feb 2025 10:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739905193; x=1740509993; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=r0kpBhbfXxtZzDMHLag5RRsggHKY1KhBdZYwLBVe1gQ=; b=kHNLrt9ZK1f+vfEYV+m5R9qiMOXid3Bi9yQ0CtJkkaK8aWkFIzS9+JAfRYbXvhM1aO Yr8t1eyB8ZAGiNYWM5lKiiOd7E2mTXmzCxzzSLpqf6TiMvLpaIFskPldj2S77VL1BYpD UehPfgHBRrLKdNW2dBqXtqeNiQk+L5dYx1tj6Usc4ddQjRMkev6/bCBdEPzx2Se/57G7 yFI5akvoWxcvwqqZDFV1+TM5zscF0ewBLMP0DwpIxOFf847mepATJbniaKOD0rj9SCgx humFX9cqoLWbmdTUR1nr9n+gnY8sJm2N/vab08q2of8mQMt63HHO4+m9ivNuKr94WzdV T8Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739905193; x=1740509993; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r0kpBhbfXxtZzDMHLag5RRsggHKY1KhBdZYwLBVe1gQ=; b=SgnG9JYLxyw9QZP87ILecKgEvKKKKGfANfC2V6n7mi4flRNCRsXPzOevJtZMkp8VcH LU42DSd/0YsOfJxiWUIsg6veNwm7kXbw5F21bbKLOvW84IvMgUrCP3xS7w55DaymtxfQ 59n1RHMJnBOjqTVhSXyuxClgYP9ROoOE/dYKVLG/tK619jbhcaVlV/bDACzRDXkYWOG7 CWYKwcRmirOSQH0ms01BllHciMms3IeByWH4edry3Oo5eAg/Wvp0WqM35GAjB7r9R0aH C3CYQwvGzld9tSx940K82OowfaOSEYo6Sr7ENiAH4SUeMAxw4UTXav3CLy8plLz0kiD/ cjJg== X-Forwarded-Encrypted: i=1; AJvYcCUC9DyTHYEewv3Hwgw9ZF5LDSFmc3Abp4zn+dTavHFqpsEIlxD9H5OqKYKS0fI0QpIGT0e3ycNwhKhMOKQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8L/Uf7nfYFVAUizufW8bL/M1JOtdr3mBIkn/cqjPySSGpHqxj KHyw8hHMzUYitNAWXd2aDxBSdsqx9ZM9R81Prwerr7eRshSQisLyn0uWxiVyBmhgjH2mCOXaGFm mPX5Wt7W6EQ== X-Google-Smtp-Source: AGHT+IH8NmujlT/kHbLcbrDIh4TdqTEkbJHgI3ziVHNlXWsjC5xp2dgiGsl9Qlu/Bsx5dLWERlz6Up6uxakhtg== X-Received: from wmbfp16.prod.google.com ([2002:a05:600c:6990:b0:439:8ee3:e17b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:47a1:0:b0:38d:d274:4537 with SMTP id ffacd0b85a97d-38f57bf8a25mr729075f8f.7.1739905193562; Tue, 18 Feb 2025 10:59:53 -0800 (PST) Date: Tue, 18 Feb 2025 18:59:41 +0000 In-Reply-To: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> X-Mailer: b4 0.15-dev-42535 Message-ID: <20250218-force-cpu-bug-v3-3-da3df43d1936@google.com> Subject: [PATCH v3 3/4] x86/cpu: Add setcpuid cmdline param From: Brendan Jackman To: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In preparation for adding support to fake out CPU bugs, add a general facility to force-enable CPU flags. The flag taints the kernel and the documentation attempts to be clear that this is highly unsuitable for uses outside of kernel development and platform experimentation. The new arg is parsed just like clearcpuid, but instead of leading to setup_clear_cpu_cap() it leads to setup_force_cpu_cap(). Signed-off-by: Brendan Jackman --- Notes: I've tested this by booting a nested QEMU guest on an Intel host, which with setcpuid=3Dsvm will claim that it supports AMD virtualization. arch/x86/kernel/cpu/common.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 1241c205b9d0..245807f9351d 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1479,12 +1479,12 @@ static void detect_nopl(void) #endif } =20 -static inline void parse_clearcpuid(char *arg) +static inline void parse_set_clear_cpuid(char *arg, bool set) { char *opt; int taint =3D 0; =20 - pr_info("Clearing CPUID bits:"); + pr_info("%s CPUID bits:", set ? "Force-enabling" : "Clearing"); =20 while (arg) { bool found __maybe_unused =3D false; @@ -1505,7 +1505,10 @@ static inline void parse_clearcpuid(char *arg) else pr_cont(" %s", x86_cap_flags[bit]); =20 - setup_clear_cpu_cap(bit); + if (set) + setup_force_cpu_cap(bit); + else + setup_clear_cpu_cap(bit); taint++; } /* @@ -1523,7 +1526,10 @@ static inline void parse_clearcpuid(char *arg) continue; =20 pr_cont(" %s", opt); - setup_clear_cpu_cap(bit); + if (set) + setup_force_cpu_cap(bit); + else + setup_clear_cpu_cap(bit); taint++; found =3D true; break; @@ -1579,10 +1585,12 @@ static void __init cpu_parse_early_param(void) setup_clear_cpu_cap(X86_FEATURE_FRED); =20 arglen =3D cmdline_find_option(boot_command_line, "clearcpuid", arg, size= of(arg)); - if (arglen <=3D 0) - return; + if (arglen > 0) + parse_set_clear_cpuid(arg, false); =20 - parse_clearcpuid(arg); + arglen =3D cmdline_find_option(boot_command_line, "setcpuid", arg, sizeof= (arg)); + if (arglen > 0) + parse_set_clear_cpuid(arg, true); } =20 /* @@ -2014,15 +2022,23 @@ void print_cpu_info(struct cpuinfo_x86 *c) } =20 /* - * clearcpuid=3D was already parsed in cpu_parse_early_param(). This dummy - * function prevents it from becoming an environment variable for init. + * clearcpuid=3D and setcpuid=3D were already parsed in cpu_parse_early_pa= ram(). + * These dummy functions prevent them from becoming an environment variabl= e for + * init. */ + static __init int setup_clearcpuid(char *arg) { return 1; } __setup("clearcpuid=3D", setup_clearcpuid); =20 +static __init int setup_setcpuid(char *arg) +{ + return 1; +} +__setup("setcpuid=3D", setup_setcpuid); + DEFINE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot) =3D { .current_task =3D &init_task, .preempt_count =3D INIT_PREEMPT_COUNT, --=20 2.48.1.601.g30ceb7b040-goog From nobody Fri Dec 19 07:16:40 2025 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.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 45ADB242919 for ; Tue, 18 Feb 2025 18:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905199; cv=none; b=CA0s8yDMGJq82UU2gpt8Q3/MlYEouVU9MgBXblb8ilhvmPM6t17bJNtOItz0QxVPPVivGZtZppRG6IijpEQNJoWYxh+U4E+ywdpj6/Qa09l5L48KO4VvD/qTgaZZ68vfgpvwKtQLfah6H1Eks4O1YSlxXdpr5UzB9+Pf3/xDPYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739905199; c=relaxed/simple; bh=ZNsSiv9dPabSYV1NT5C7CVgd2F35GxWJcGw9kJ0uqVM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UcQ59KfaPnT0iVF7z49oJUY4hbtpKzJD3wRXBfIU8B4RFSgHi80SUpUh1ShngT6ggaK/1TTvqypTAyu5yonxsEBd3ToBi0YQyffgWrHUQTvLNoqAKrFFX9uKUrN/zhsOz4VtiKGmxKR81LEJR2v9zvWO9i0QGgd+vosAP7DZWZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bLEMJesN; arc=none smtp.client-ip=209.85.221.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--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bLEMJesN" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38f4cce15c8so1094755f8f.2 for ; Tue, 18 Feb 2025 10:59:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739905195; x=1740509995; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yZIMl22pvBjh9ukdMGMiL5tmUUXbduENJGKdJkiqkVE=; b=bLEMJesNLmtIC5xhJ0xY4I8UC1EnoyoO6S+ZJQ4OQGqYaLx2vml7rj45hSVNvntNDi ukAhUBImFp1Oi+RtBVrry5A+3TAb9kSO0cSsyBEkuoPXFnvbrBw4MSkH5xkEmdsWM5y7 QQquzZRBmCQNz93ZcUQcxVcsuu6RLISALvJFTG29NiANRRZpIKtP/POiEue2KSz9TrJc aqosMKrsIDgKMwxC48ormPbaRZ+BocW1UhSAfqFE8FYguBimN1YoS/rG6Xm1XAKM+3ph 3Wlkl6m6Qhfbctu0Buf0o0A/2AYwO4DdDVvRBo8lD24KYg6Arxxme/iahu6g9MlAPlCo Tx7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739905195; x=1740509995; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yZIMl22pvBjh9ukdMGMiL5tmUUXbduENJGKdJkiqkVE=; b=BlEH0cBL6yfA+t+pl9U9N3JtelhqdziUFqzRlHQSPombzYFsfioVdeiiorYFg6i/qz 36ODxbxltnYhYcFPIxz7SwfQfjttzcH73Kkq61/KK+/4gyvqoVNs3nlbqIfyS+C2AU8S n24ZgJ8uEfZJMiFTyV/Fbu+m4qzqOAFqfVibj8sSiHH2g0ZbqeRXHl/rJokHHsdOCMKI OXZUcF4WV/ggxlKMP/cXf1XeBujHP/SGqXYKawYdQjLlxTuTgSCOPQx8JOdqoUG/LG78 Z7BYWHck9X3QnNSjth7JInFGTLcKHqsS+s7NMVSeYMbUGP63IsA/DMChSpIEVfchbtgQ ke6Q== X-Forwarded-Encrypted: i=1; AJvYcCWYFpb2x/m3uL1WvwcfyJaMpgHklsl+MXy2sfxrdn0sQidZNQBD3yIwZq2uGE3ZJqM+FH+EGNZMxG+rBps=@vger.kernel.org X-Gm-Message-State: AOJu0Yyf005ZwbIra8cM24oIZkvUszcQ0pE6txoZvToatO6v0rsPhfyy GC+5+iJvUAdunqFOSbFftZNv3YyRlBT0PVvbMyhJJcyp1XQI1s2ze4hW2F1+eHQxJNd+p8+OJc8 YyLbr3hn26g== X-Google-Smtp-Source: AGHT+IG4rbFF33bwY+7Q4TkK+fVkXSPgIlC5voC/aq0j1grau+Zkp7FlsAMIN7T6jXyDoCITYekDLRF2fC5fMw== X-Received: from wmbez7.prod.google.com ([2002:a05:600c:83c7:b0:439:98eb:28cd]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1865:b0:38f:4d91:c123 with SMTP id ffacd0b85a97d-38f4d91c4abmr6491188f8f.32.1739905195685; Tue, 18 Feb 2025 10:59:55 -0800 (PST) Date: Tue, 18 Feb 2025 18:59:42 +0000 In-Reply-To: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250218-force-cpu-bug-v3-0-da3df43d1936@google.com> X-Mailer: b4 0.15-dev-42535 Message-ID: <20250218-force-cpu-bug-v3-4-da3df43d1936@google.com> Subject: [PATCH v3 4/4] x86/cpu: Enable modifying bug flags with {clear,set}cpuid From: Brendan Jackman To: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sometimes it can be very useful to run CPU vulnerability mitigations on systems where they aren't known to mitigate any real-world vulnerabilities. This can be handy for mundane reasons like debugging HW-agnostic logic on whatever machine is to hand, but also for research reasons: while some mitigations are focused on individual vulns and uarches, others are fairly general, and it's strategically useful to have an idea how they'd perform on systems where they aren't currently needed. As evidence for this being useful, a flag specifically for Retbleed was added in commit 5c9a92dec323 ("x86/bugs: Add retbleed=3Dforce"). Since CPU bugs are tracked using the same basic mechanism as features, and there are already parameters for manipulating them by hand, extend that mechanism to support bug as well as capabilities. Signed-off-by: Brendan Jackman --- Notes: With this patch and setcpuid=3Dsrso, a QEMU guest running on an Intel host will boot with Safe-RET enabled. arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/common.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index f23942108b85..e955da397e0e 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -45,6 +45,7 @@ extern const char * const x86_power_flags[32]; * X86_BUG_ - NCAPINTS*32. */ extern const char * const x86_bug_flags[NBUGINTS*32]; +#define x86_bug_flag(flag) x86_bug_flags[flag] =20 #define test_cpu_cap(c, bit) \ arch_test_bit(bit, (unsigned long *)((c)->x86_capability)) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 245807f9351d..08d984ba0347 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1494,7 +1494,8 @@ static inline void parse_set_clear_cpuid(char *arg, b= ool set) =20 /* * Handle naked numbers first for feature flags which don't - * have names. + * have names. It doesn't make sense for a bug not to have a + * name so don't handle bug flags here. */ if (!kstrtouint(opt, 10, &bit)) { if (bit < NCAPINTS * 32) { @@ -1518,11 +1519,18 @@ static inline void parse_set_clear_cpuid(char *arg,= bool set) continue; } =20 - for (bit =3D 0; bit < 32 * NCAPINTS; bit++) { - if (!x86_cap_flags[bit]) + for (bit =3D 0; bit < 32 * (NCAPINTS + NBUGINTS); bit++) { + const char *flag; + + if (bit < 32 * NCAPINTS) + flag =3D x86_cap_flags[bit]; + else + flag =3D x86_bug_flags[bit - (32 * NCAPINTS)]; + + if (!flag) continue; =20 - if (strcmp(x86_cap_flags[bit], opt)) + if (strcmp(flag, opt)) continue; =20 pr_cont(" %s", opt); --=20 2.48.1.601.g30ceb7b040-goog