lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20190731043144.30863-1-yu.c.chen@intel.com>
Date:   Wed, 31 Jul 2019 12:31:44 +0800
From:   Chen Yu <yu.c.chen@...el.com>
To:     linux-pm@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org, yu.c.chen@...el.com,
        Len Brown <len.brown@...el.com>,
        "Wysocki, Rafael J" <rafael.j.wysocki@...el.com>,
        Rui Zhang <rui.zhang@...el.com>,
        David Box <david.e.box@...el.com>,
        "Tan, Raymond" <raymond.tan@...el.com>
Subject: [PATCH] Introducing the mask_cstate to disable specific c-states during bootup

There is request to disable specific c-states during bootup for
debug purpose. For example, deeper c-states except C1,C1E,C10
are disabled during bootup otherwise it might not boot up well
due to incorrect setting in FW.

For example, intel_idle.mask_cstate=0x3c, would disable cstate
2,3,4,5 in the table
(1<<2) | (1<<3) | (1<<4) | (1<<5)
which is C6,C7s,C8,C9 on Broxton.
This could have it come up as present, but with c-states disabled,
so user can enable those c-states later to test.

Cc: Len Brown <len.brown@...el.com>
Cc: "Wysocki, Rafael J" <rafael.j.wysocki@...el.com>
Cc: Rui Zhang <rui.zhang@...el.com>
Cc: David Box <david.e.box@...el.com>
Cc: "Tan, Raymond" <raymond.tan@...el.com>
Signed-off-by: Chen Yu <yu.c.chen@...el.com>
---
 .../admin-guide/kernel-parameters.txt         |  7 ++++
 drivers/idle/intel_idle.c                     | 36 +++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 7ccd158b3894..93a326c42877 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1733,6 +1733,13 @@
 			provided by tboot because it makes the system
 			vulnerable to DMA attacks.
 
+	intel_idle.mask_cstate=	[HW,X86]
+			Mask of C-states to be disabled during bootup. For
+			example, mask_cstate=0x3c, would disable cstate 2,3,4,5
+			in the table
+			(1<<2) | (1<<3) | (1<<4) | (1<<5)
+			which is C6,C7s,C8,C9 on Broxton.
+
 	intel_idle.max_cstate=	[KNL,HW,ACPI,X86]
 			0	disables intel_idle and fall back on acpi_idle.
 			1 to 9	specify maximum depth of C-state.
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index fa5ff77b8fe4..ed3233864b69 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -63,6 +63,8 @@ static struct cpuidle_driver intel_idle_driver = {
 /* intel_idle.max_cstate=0 disables driver */
 static int max_cstate = CPUIDLE_STATE_MAX - 1;
 
+static unsigned int mask_cstate;
+
 static unsigned int mwait_substates;
 
 #define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
@@ -1354,6 +1356,12 @@ static void __init intel_idle_cpuidle_driver_init(void)
 		if (num_substates == 0)
 			continue;
 
+		if ((1UL<<cstate) & mask_cstate) {
+			pr_info("Disable #%d[%s] by user\n",
+					cstate,
+					cpuidle_state_table[cstate].name);
+			cpuidle_state_table[cstate].disabled = 1;
+		}
 		/* if state marked as disabled, skip it */
 		if (cpuidle_state_table[cstate].disabled != 0) {
 			pr_debug("state %s is disabled\n",
@@ -1480,3 +1488,31 @@ device_initcall(intel_idle_init);
  * is the easiest way (currently) to continue doing that.
  */
 module_param(max_cstate, int, 0444);
+
+static int mask_cstate_set(const char *arg, const struct kernel_param *kp)
+{
+	int ret = 0;
+	unsigned long new_mask_cstate, max_bit;
+
+	ret = kstrtoul(arg, 0, &new_mask_cstate);
+	if (ret)
+		goto exit_mask;
+
+	max_bit = find_last_bit(&new_mask_cstate, BITS_PER_LONG);
+	if (max_bit >= CPUIDLE_STATE_MAX) {
+		ret = -EINVAL;
+		goto exit_mask;
+	}
+
+	mask_cstate = new_mask_cstate;
+	smp_mb();
+
+exit_mask:
+	return ret;
+}
+
+static const struct kernel_param_ops mask_cstate_ops = {
+	.set = mask_cstate_set,
+	.get = param_get_int,
+};
+module_param_cb(mask_cstate, &mask_cstate_ops, &mask_cstate, 0644);
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ