From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=34.218.115.239 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336066; b=Dh4HBLmgpkh2Jtvu+H7ubnMpLQQUcCWNm7ExJDOVGBNr9blUV+pmPNeDj0pM/F14rYng m80hIg/+BalSehDlqxo8QuTMtb5cttTfEnTvHiEiPn8zt+gZDQ9/dusdWL1cQd4RExx1f ZkY2/eW1hL4Q4EvJQo2KqnhWz3Q7ALVg8+DLpGKkoAlRVw9Ry5TVZ98F11VL9kc7VYDJj z4NKo7v0jYLS5T/+8TRhoRfrlT2au/0SdZiOFmrEQnOeTVoslwmWmpof0vjULO4JQmgSR 6LwKJmOrzfb2rQMDNNC2N8cB0/L7eOt+DVWOLZHNHNGnieCG49Ser3wvd2T1w0sfjfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336066; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=/7V062uEYdpvIqtHNrDlVXSpRlcK3t2RsGrQXg+ddAE=; b=vthLb7hpWaak2GG0JwRCoU1OcUTia0ffUGH+mbhz29qWm4CGHDMKamm2Buz02jfqfp9d d6x5K+i5t4x+FR1sknOSiS29Hji+nU6JsIhEIVHFkj/Ub51EmcmYlfysyiHANa+NrJaB7 D68ihF5X1Rz154y/H20mqaQCUhCnNiwNx0lG9tPw+rc+CKACJzy6M4krMXF9IZXX73oLQ zpXFCezx5QypRQjlAyrPDslYmGzKaZOLRtDjE+DbCNzSaNCXRrs+ag93fqSF8fTHm2oDR B/7vz9M3bW51P3oQ1sbYeJoJyptSJSChW/CKsctYJBojzcTN26Jiqs6TSEhCxNHWd6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b="H/8ImiGe"; arc=none smtp.remote-ip=34.218.115.239 Received: from pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com [34.218.115.239]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0705D606A333; Thu, 3 Dec 2026 22:14:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0705D606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=H/8ImiGe DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1796336066; x=1827872066; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/7V062uEYdpvIqtHNrDlVXSpRlcK3t2RsGrQXg+ddAE=; b=H/8ImiGeD0x8S5WIzMpteQ5B6xZxXpInOld7R8jsi5xH6nAA1zjPzrOE fjG/Sw0HUDYlyjMgFlbWQYKmyewiWvP+JsF3joZtkso543MieRahCZHth C/aROazqIdFPfI8wE4VwjYWO0TkuXsfCJSdxwG6k0MibsbsgN2IV43W/3 5xHdvVDyHWGQnRbj5lNa50decHVX9T76vimEmNsIADMNzzk8/22bicNqB OUDktHJjAQwht//36M8lEMzjQjQ11NVCc91zBBOhnJu/dZMsmKW0qnW9T JPKqY798BOMe1hS40fUIo+FMUNGjx4sz0xSVDrS5fWTesa9oBq7Npdm68 A==; X-CSE-ConnectionGUID: nYe5c3CmSbewfg9ijxuq2w== X-CSE-MsgGUID: NXm+BFAVTHCqis/Kn9ATTg== X-IronPort-AV: E=Sophos;i="6.29,77,1794873600"; d="scan'208";a="35680447" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-013.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:14:25 +0000 Received: from EX19MTAUWB001.ant.amazon.com [205.251.233.104:10713] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.59.220:2525] with esmtp (Farcaster) id adf3466f-ec71-46ab-8e81-da3f17dd0860; Thu, 3 Dec 2026 22:14:24 +0000 (UTC) X-Farcaster-Flow-ID: adf3466f-ec71-46ab-8e81-da3f17dd0860 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:14:24 +0000 Received: from dev-dsk-araoof-1b-23e02486.eu-west-1.amazon.com (10.253.65.187) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:14:21 +0000 From: Ahmed Abdelraoof To: Ingo Molnar , Peter Zijlstra CC: Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , "Mel Gorman" , Valentin Schneider , "K Prateek Nayak" , Jonathan Corbet , Shuah Khan , Randy Dunlap , , , Anselm Busse , Ahmed Abdelraoof Subject: [PATCH 3/4] sched/core: Gate core scheduling on the isolation unit Date: Thu, 3 Dec 2026 22:13:06 +0000 Message-ID: <20261203221307.86078-4-araoof@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221307.86078-1-araoof@amazon.de> References: <20261203221307.86078-1-araoof@amazon.de> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWC004.ant.amazon.com (10.13.139.246) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: Anselm Busse prctl(PR_SCHED_CORE) fails with -ENODEV unless sched_smt_present is set. Once the isolation unit can be wider than the SMT siblings, core scheduling has something to isolate on systems without SMT. Add a separate sched_core_unit_present key, counted once per unit as its second CPU comes up, and gate the prctl on it. Keep sched_smt_present as it is used to report kernel suseptability to SMT related vulnerabilities (TAA, L1TF ..etc). No functional change intended. Signed-off-by: Anselm Busse Co-developed-by: Ahmed Abdelraoof Signed-off-by: Ahmed Abdelraoof --- kernel/sched/core.c | 26 ++++++++++++++++++++++++++ kernel/sched/core_sched.c | 2 +- kernel/sched/sched.h | 11 +++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b62716094445..c69f40e7b93a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8725,6 +8725,30 @@ static inline void sched_smt_present_dec(int cpu) static_branch_dec_cpuslocked(&sched_smt_present); } +#ifdef CONFIG_SCHED_CORE +DEFINE_STATIC_KEY_FALSE(sched_core_unit_present); + +/* + * Fire once per isolation unit, as its second CPU comes up and again as the + * unit shrinks back through two, which keeps the refcount balanced for any + * unit width. When the unit is SMT this tracks sched_smt_present exactly. + */ +static inline void sched_core_unit_present_inc(int cpu) +{ + if (cpumask_weight(sched_core_isolation_mask(cpu)) == 2) + static_branch_inc_cpuslocked(&sched_core_unit_present); +} + +static inline void sched_core_unit_present_dec(int cpu) +{ + if (cpumask_weight(sched_core_isolation_mask(cpu)) == 2) + static_branch_dec_cpuslocked(&sched_core_unit_present); +} +#else +static inline void sched_core_unit_present_inc(int cpu) { } +static inline void sched_core_unit_present_dec(int cpu) { } +#endif + int sched_cpu_activate(unsigned int cpu) { struct rq *rq = cpu_rq(cpu); @@ -8739,6 +8763,7 @@ int sched_cpu_activate(unsigned int cpu) * When going up, increment the number of cores with SMT present. */ sched_smt_present_inc(cpu); + sched_core_unit_present_inc(cpu); set_cpu_active(cpu, true); if (sched_smp_initialized) { @@ -8817,6 +8842,7 @@ int sched_cpu_deactivate(unsigned int cpu) * When going down, decrement the number of cores with SMT present. */ sched_smt_present_dec(cpu); + sched_core_unit_present_dec(cpu); sched_core_cpu_deactivate(cpu); diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c index d56be1c31435..ba4d608c0d80 100644 --- a/kernel/sched/core_sched.c +++ b/kernel/sched/core_sched.c @@ -136,7 +136,7 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type, struct pid *grp; int err = 0; - if (!sched_smt_active()) + if (!sched_core_unit_active()) return -ENODEV; BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 948f70af6fa6..97126c1dcb09 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1598,6 +1598,17 @@ static inline const struct cpumask *sched_core_isolation_mask(int cpu) return cpu_smt_mask(cpu); } +DECLARE_STATIC_KEY_FALSE(sched_core_unit_present); + +/* + * True once some isolation unit spans more than one CPU, i.e. once core + * scheduling has something it can actually exclude. + */ +static inline bool sched_core_unit_active(void) +{ + return static_branch_likely(&sched_core_unit_present); +} + /* * Helpers to check if the CPU's core cookie matches with the task's cookie * when core scheduling is enabled. -- 2.47.3