From nobody Tue Jun 16 14:44:09 2026 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58AAA3DFC7B for ; Thu, 11 Jun 2026 11:17:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176645; cv=none; b=DS0X4hpIEjPVKGSnVOEMVZzVoiCHARzrVJK7RDGVZnb7oPSuTHeUmIOAiDi3ehsYvAN9p4Fa1+nSO0aH7VyZShgvJwfjKDHO0dF6SsT/dJ3CCCD3KiJhR+s1WmYlSpPtrdMCsdPpeFIwt9PKpzavpCcFeZKlBFV7q/WzW3QPnno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176645; c=relaxed/simple; bh=32Jtf5jnkE1C7T9wb4lp61lkLg7DZyog4aN13wfolYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eRWwtnwFbNDsoKc8EJBf3UcynNmMiQvwi29g2kitfSctblRFzj7NjEOqhxBYhg2HQrCsjM3gjoJPqqiG9qpNqAtIyiOo7/Hvj/zpucdm9yPoGop3ZYAGeWeZZ5G4h4aHvOkSVJ0p6OqbyKUb01YepFg6lfdu0eiXSFNC21BqJ1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=AxpYAoZc; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="AxpYAoZc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781176633; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=lV7Tt9R2jPjozz2PG0uezA6r76cncCAbIsU1IZt7128=; b=AxpYAoZcUIc3oESza9xmS5Nj5QfKy64ikoorA72AbMlUm2adj4esvvZu1DxX6bN0RYR22z6ZWWUvl5CEhTitYnavdk5ktL8059pqPbVlL+Fgy2/Wn3JyU/UplRACg28SYdJ4GWX/c2nOcAmZdAkdFE5JGjgHAzxYmlVYIDKB3aM= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=qinyuntan@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0X4dSic9_1781176632; Received: from banye.tbsite.net(mailfrom:qinyuntan@linux.alibaba.com fp:SMTPD_---0X4dSic9_1781176632 cluster:ay36) by smtp.aliyun-inc.com; Thu, 11 Jun 2026 19:17:13 +0800 From: Qinyun Tan To: babu.moger@amd.com Cc: tony.luck@intel.com, reinette.chatre@intel.com, james.morse@arm.com, Dave.Martin@arm.com, tglx@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, feng.tang@linux.alibaba.com, xlpang@linux.alibaba.com, Qinyun Tan Subject: [PATCH 1/4] resctrl: Add kmode arch stubs for ARM MPAM and hide kernel_mode on non-PLZA platforms Date: Thu, 11 Jun 2026 19:17:03 +0800 Message-ID: <20260611111706.1981788-2-qinyuntan@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" fs/resctrl/rdtgroup.c calls resctrl_arch_get_kmode_support() and resctrl_arch_configure_kmode() which are only implemented under arch/x86/. ARM MPAM enables CONFIG_RESCTRL_FS but has no PLZA hardware, causing link failures on aarch64 allyesconfig: undefined reference to `resctrl_arch_configure_kmode' undefined reference to `resctrl_arch_get_kmode_support' Add empty stubs in drivers/resctrl/mpam_resctrl.c, following the same pattern used for resctrl_arch_io_alloc_enable(). Additionally, the kernel_mode file under info/ was unconditionally visible (fflags =3D RFTYPE_TOP_INFO). On platforms without PLZA (ARM MPAM, older AMD/Intel), the file shows only inherit_ctrl_and_mon with no other options, which is unnecessary. Set the initial fflags to 0 and dynamically enable the file in resctrl_kmode_init() only when resctrl_arch_get_kmode_support() registers additional modes, matching the io_alloc pattern. Signed-off-by: Qinyun Tan Reviewed-by: Xunlei Pang --- drivers/resctrl/mpam_resctrl.c | 9 +++++++++ fs/resctrl/rdtgroup.c | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index 1dd3bbd0772cd..fc2b3f508c039 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -161,6 +161,15 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_reso= urce *r) return false; } =20 +void resctrl_arch_get_kmode_support(struct resctrl_kmode_cfg *kcfg) +{ +} + +void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, + u32 rmid, bool enable) +{ +} + void resctrl_arch_pre_mount(void) { } diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index dd9c4da836983..0b2606f10e2e9 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -2602,7 +2602,7 @@ static struct rftype res_common_files[] =3D { .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D resctrl_kernel_mode_show, .write =3D resctrl_kernel_mode_write, - .fflags =3D RFTYPE_TOP_INFO, + .fflags =3D 0, }, { .name =3D "mbm_assign_on_mkdir", @@ -2968,6 +2968,9 @@ static void resctrl_kmode_init(void) resctrl_kcfg.k_rdtgrp =3D &rdtgroup_default; =20 resctrl_arch_get_kmode_support(&resctrl_kcfg); + + if (resctrl_kcfg.kmode !=3D BIT(INHERIT_CTRL_AND_MON)) + resctrl_file_fflags_init("kernel_mode", RFTYPE_TOP_INFO); } =20 void resctrl_file_fflags_init(const char *config, unsigned long fflags) --=20 2.43.7 From nobody Tue Jun 16 14:44:09 2026 Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010043.outbound.protection.outlook.com [52.101.46.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB0E42D0617; Thu, 30 Apr 2026 23:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.46.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591520; cv=fail; b=UGLQjsxxnBnpo1mHN6LOZCQ0NRXgnWQqH6HzHuT41qNqsPnxYSGHDShb6kaZetpKznqJuNaG9XCVB6ZK4rXOBe4rQO6k8yFd4Qxsnyxz3kbfh6h8og4vyly5TtJyOijrRXjEUKUoQIolhRlKs+nJuMbeMIRy340ARz/LCulyk0g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591520; c=relaxed/simple; bh=+xw9SWA5Bd7tDAFIEUCXhrowKElBsbxO096+cO62HvE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ipE5PrFQGRazmnjjaYgfl/OluK5O9bZO/lpRl01CjmyliuTumAEjV/b7COX0Jsmj3kCiSc9XpF3+7uAaCxjW9mxwmuqcvvBSoSTdN4/QrZerGrZZpytla3EJSx7oAAqv5QNPOb42mxEgp+MTvZwGDIub0XPj0z4zO+tP6VOrtS8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=vvSVY/EP; arc=fail smtp.client-ip=52.101.46.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="vvSVY/EP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=roP3cJqpSsu/ABKlMOCNvJLvwO9vS0PA/XrrVS6w30fVvjPB5iFB91K4uM6j2kswlk3/XT4GaJIB50j+FP3PZ5VXbgp7HxaSF2Sf5twR5bcAqEATxi7QxTvW8W1jIW1IPbhVGtX0bsLe6Xs3vuWD6iU4MLemm4hf6TUf0AR8gAzb2YSKaDfnWpm8OMB6B/WyKmp1Yik7XFj5YDWrbWjvX8GO6CHi63gooYTHqV+PCdzLlzvo6BmX8fQlNweveV3hXamNnb/o81jUfXIvv/NCvZFMXvJJ+h2xBoYmZ4oTxmsUOMd/ShZZc5kQjfMH+EwefkFpLQbtVlWa5PGR7BXxrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IqpyVQx2rwOKF12fTA7qNmbA84nCvVHAtwIgWLeNFBc=; b=aj0J5lpTwloRytPi1VKwZiQcLcNEHzsIzsEBJfoZCoti7MnUsNR1Z2a5oqwGosZMoOpO+FHNgO4gydGhixq+/YF31AncWuGW9fNIIGa2B9pvfdcX6ApGJAxtsCZDPaQ/RpPyUUmgBeiSJ7BmfgErHdmh3F6PVLo3Jn54BGeazbmC+vpPHaip45/zSy63rnV3TxZpFy9fBAfKv6h36UisH9jG5b8poW/ax1rj/6GvaHUJrk8mKYy51T2Y7Raczn6p2jzyMDxcIH18/CJNARPMjkpdQFJLAZjMkuYl1JFAatQQMCgjzf1WI2uVJXmUjuT/2IyR6oSfUcREBA9nsW5dyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IqpyVQx2rwOKF12fTA7qNmbA84nCvVHAtwIgWLeNFBc=; b=vvSVY/EPnyDcIfntfUOYBzvAW5KsMp/BUnFGs8jGNGZBnFbwNz1lJOgU5jPYrE1qzCxPhU2zf/Jn/VNSZAPzcUpGH3inYuR9FYvu/aIPweTKaJ2kNn0RkbI+B3CWifXvgRuVmGb0N/iqi/iLpNVcX1UzG+bsX9kXa2MnVZ7nXTc= Received: from SA0PR11CA0130.namprd11.prod.outlook.com (2603:10b6:806:131::15) by PH8PR12MB7279.namprd12.prod.outlook.com (2603:10b6:510:221::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 23:25:13 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::d8) by SA0PR11CA0130.outlook.office365.com (2603:10b6:806:131::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Thu, 30 Apr 2026 23:25:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:25:13 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:25:11 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 01/12] x86/resctrl: Support Privilege-Level Zero Association (PLZA) Date: Thu, 30 Apr 2026 18:24:46 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001509:EE_|PH8PR12MB7279:EE_ X-MS-Office365-Filtering-Correlation-Id: e2f2c3bc-f7d9-48e9-90db-08dea70fbaba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|7416014|376014|13003099007|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: 7qsGH5Rw+kprzNewzwq8S8dC52ENLv0AFXsD2P/02QP+S/UiH/VkAZyE59G0fKEbismTMb5+0CAyHzzzczU+KRHU6nFIpvXLkKeP/pmyZYNOIfwDfLhS1Pl1dYV6pWU9LL62+buESa0SgkbKEDGm6PPiQ7mWcQ9pxYpDL7nOxZa75eWntGX4kr/dgfraeKLXIZjTC25V08kX079lc5tMaQOyXqRGEuT8coS+j876bAJzRxbsWOnmCSU8lCzQ6EM+V4DfRKtge6++dioVFPQdgOSwXXTeP4sl3YcJ/THTSVOGTiL0w8XIagzt+n42bC3FgwhuTqnBlX9F+XJN+8nKDnqGr0ibmzU54TUhQfGT46Q8FwsZ8kd7ZrmJknREq7z+stj/MdrRKUe0dbuyhtZAA6lupxDeaoDnjuA/LF9W7HDCqAfH2ZgywHhWNFI4+oa/Wo4udMlS6zPYUVZyjS9OvFHWy0heA25yyg5uXm2pM1JqYaNbXM16vHmyEMSo1QDBUOTmCRJLf/Dh2ExK0V2YIYvQ1Bbi3aH0VSvo+rW+dN8XZMcrvhUUdAhyon7MJcEjGPDSdFPkQtjGgNEqleKnXKdenjVZwdoy4sSY3kbcDUZmpCfQUWjucc7N9RXbbwBQCdwGpeL2yPXxUwarTDrItLFW+E/qulFgQSMQPYCoqfTH0VPZ0ge/UO7qwU+u1+K6HFGxewIhRapVhgWA6lvFTMe+l34O3NoKfoR3xLDcDd4= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700016)(7416014)(376014)(13003099007)(18002099003)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3kjhstvzYlsnsvYq4IRFQBdVPjuMRzBC+JlVNbku4MIsk1xJ7p13EfAIsYHOxJQ683panxnDMr9XKQkQuGbfIrPm8w9zRtC6mgfl6ykXVnhPLwaj888NT3jVn1wLoEjWgGQQCSEDgbLSa2UyqRDB8x0k402YdvbZDqMYKTVS+ZyQV1Eks+cYjltCeE1lJwETCELJxXzEc65NzBlyy8IXZ+ReXeK34q/8WwcCtuRTHpEct2RRLt4fmVtqU1hw/5t6APv9Aaj/CuOT4nMMRviNALWnWmaR9Hd2wNnBfFGvIheXwnkZzPb6VmrS4vK0UsQKJNX49Rv4iNz8X9Vv8kJ/j3VNIOeXTrRrB7ro5YfHKEMQJazlguHeApwl2uQLlef66Vine7L0Ey7xv/BHocdQByQffXwD5FSZIAyQIf86fZrnBsnsEC86O7siW80PU4KG X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:25:13.1670 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2f2c3bc-f7d9-48e9-90db-08dea70fbaba X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7279 Content-Type: text/plain; charset="utf-8" Customers have identified an issue while using the QoS resource Control feature. If a memory bandwidth associated with a CLOSID is aggressively throttled, and it moves into Kernel mode, the Kernel operations are also aggressively throttled. This can stall forward progress and eventually degrade overall system performance. AMD hardware supports a feature Privilege-Level Zero Association (PLZA) to change the association of the thread as soon as it begins executing. Privilege-Level Zero Association (PLZA) allows the user to specify a CLOSID and/or RMID associated with execution in Privilege-Level Zero. When enabled on a HW thread, when the thread enters Privilege-Level Zero, transactions associated with that thread will be associated with the PLZA CLOSID and/or RMID. Otherwise, the HW thread will be associated with the CLOSID and RMID identified by PQR_ASSOC. Add PLZA support to resctrl and introduce a kernel parameter that allows enabling or disabling the feature at boot time. The GLBE feature details are documented in: AMD64 Zen6 Platform Quality of Service (PQOS) Extensions: Publication # 69193 Revision: 1.00, Issue Date: March 2026 available at https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger --- v3: Code did not change. Patch order cahnged. Added documentation link. v2: Rebased on top of the latest tip. --- Documentation/admin-guide/kernel-parameters.txt | 2 +- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/resctrl/core.c | 2 ++ arch/x86/kernel/cpu/scattered.c | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index f2ce1f4975c1..3021c920f3e1 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6463,7 +6463,7 @@ Kernel parameters rdt=3D [HW,X86,RDT] Turn on/off individual RDT features. List is: cmt, mbmtotal, mbmlocal, l3cat, l3cdp, l2cat, l2cdp, - mba, smba, bmec, abmc, sdciae, energy[:guid], + mba, smba, bmec, abmc, sdciae, plza, energy[:guid], perf[:guid]. E.g. to turn on cmt and turn off mba use: rdt=3Dcmt,!mba diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 86d17b195e79..5739281bd4c7 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -515,6 +515,7 @@ * and purposes if CLEAR_CPU_BUF_VM is set). */ #define X86_FEATURE_X2AVIC_EXT (21*32+20) /* AMD SVM x2AVIC support for 4= k vCPUs */ +#define X86_FEATURE_PLZA (21*32+21) /* Privilege-Level Zero Association */ =20 /* * BUG word(s) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 7667cf7c4e94..4a8717157e3e 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -799,6 +799,7 @@ enum { RDT_FLAG_BMEC, RDT_FLAG_ABMC, RDT_FLAG_SDCIAE, + RDT_FLAG_PLZA, }; =20 #define RDT_OPT(idx, n, f) \ @@ -826,6 +827,7 @@ static struct rdt_options rdt_options[] __ro_after_ini= t =3D { RDT_OPT(RDT_FLAG_BMEC, "bmec", X86_FEATURE_BMEC), RDT_OPT(RDT_FLAG_ABMC, "abmc", X86_FEATURE_ABMC), RDT_OPT(RDT_FLAG_SDCIAE, "sdciae", X86_FEATURE_SDCIAE), + RDT_OPT(RDT_FLAG_PLZA, "plza", X86_FEATURE_PLZA), }; #define NUM_RDT_OPTIONS ARRAY_SIZE(rdt_options) =20 diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 837d6a4b0c28..630afb233194 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -60,6 +60,7 @@ static const struct cpuid_bit cpuid_bits[] =3D { { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 }, { X86_FEATURE_ABMC, CPUID_EBX, 5, 0x80000020, 0 }, { X86_FEATURE_SDCIAE, CPUID_EBX, 6, 0x80000020, 0 }, + { X86_FEATURE_PLZA, CPUID_EBX, 9, 0x80000020, 0 }, { X86_FEATURE_TSA_SQ_NO, CPUID_ECX, 1, 0x80000021, 0 }, { X86_FEATURE_TSA_L1_NO, CPUID_ECX, 2, 0x80000021, 0 }, { X86_FEATURE_AMD_WORKLOAD_CLASS, CPUID_EAX, 22, 0x80000021, 0 }, --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012009.outbound.protection.outlook.com [52.101.53.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 347BA39A7E5; Thu, 30 Apr 2026 23:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591529; cv=fail; b=pIN3ftacFiI0A7jRiX2G2Lk0NPMc3qxm0Fq3/9cVIwSMvIy4bgEaKe7t7AHuRgQrMz2uuom8NKdD+97vO69bIjq6TuK9TGvrEBng0kiLEtWx17X7wANaExt8gRbNzNZ3mC3AYSL/kNEs8ki6/AV79X4qKkRUiAcVG103NE4lzZY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591529; c=relaxed/simple; bh=PTo+iuPBKaEYuIH58gKL3c3NkNkVEFhWLafQc3dwQ+k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pHux+jwh3ffIgUAm5pQ6oYceEh46xUYvVD+MCJK0TxreX69ZBSgH1tuF9zyCqaAuy195b09pPsqKieUFOf6Hbcy9oLZjHw8CgjoqzzkJyY23MyKVhKwH8zsFcD1vEObUvmb+k6sCu3W8d6yd2ETTQrc8n2sZ/L8T1Scvl6Vpqu4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Y8eB/Vzz; arc=fail smtp.client-ip=52.101.53.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Y8eB/Vzz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pfOu7h3hYT52h2rY3A0486EPIWbbiXnGwfLrfnLKlhaf6csC0McEFbfzr85NYiAn3YjWFpFYPt3bUz4X8LjdtxSQfZeFNpV6S+pfZeA/fLPkboSayLcWLqYVA1TVZi7BmyyUZAz9ugTKXyw5LxghPDAttUbvk7s1yil3JebM4R4AVmRosmYh8wAfWNtflHX7XJzENSn4G9TCDx45P+mOBpbtysQFGfm9OVD4UrYP7RmgJHpsPen0B50G1IAhqApNWOcaq5d2hhMYe2SSQS5WZNV//KFuLWREYmMzUmufsMG2nlUclT/oGRDOqIGTrZyCOvIAGolUSDaN9RdEsUz1ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qdjUHDOsZ9O9DGst3mIqoj92vsx2xYBm04BPwzyTFkQ=; b=q8Q4bPQZAli9BGIcwH8rx1visUIHTVmBcgx5ggprYoaN6RMSxeOBV4ocR7zfYbDyfP6ba/FC0Cee9Lr/IDClV2RXcC413tpfbyUeYfE14MqKc0Y/H2BJt4BeQOJ09JJT2x/nM+p8R/ecSvDWcm1Ve6dG5TbveK7kkH+kptv3EHYk63BOvtogiprxUbXokq/iHh5SHJx/XOfgMm3U/zp3VO4vzeUqPftlaCyHShKGuneMEGMZAkD//FVHKpNFCe42BcvlafmmDynj0NkgwNlDG1TOkPwIrrONC7NHajcGtGmYkgmBOkmMy/GXVHm4dGffBoipjOXx6+3DBcDBtWaMQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qdjUHDOsZ9O9DGst3mIqoj92vsx2xYBm04BPwzyTFkQ=; b=Y8eB/VzzXCg1+of36QfsIp8Pyi3xh2xmhR55tYjeRTPRpRHQsmqbsOpLZpixbEbW9ZO6SJFrQrG8UBIcW8RnErL/ECWkvbGHlzdk5/x1DdmF1f8GvWOJeitTuzvten95csYPxMMwBHxL95OwDAOE0diV0i+KbIUaJfUbW7OIDEg= Received: from SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) by MN0PR12MB6223.namprd12.prod.outlook.com (2603:10b6:208:3c1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22; Thu, 30 Apr 2026 23:25:22 +0000 Received: from SA2PEPF0000150A.namprd04.prod.outlook.com (2603:10b6:805:de:cafe::48) by SN6PR05CA0030.outlook.office365.com (2603:10b6:805:de::43) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.20 via Frontend Transport; Thu, 30 Apr 2026 23:25:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF0000150A.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:25:21 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:25:19 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 02/12] x86/resctrl: Add data structures and definitions for PLZA configuration Date: Thu, 30 Apr 2026 18:24:47 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF0000150A:EE_|MN0PR12MB6223:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c8c91b3-1574-429d-a6f0-08dea70fbfef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|82310400026|36860700016|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: sngKbEuAMXg7WfcsP39sRNbXfbge0F2TPlbJGQavXi60qaK8jbYpfevZeo8UzJO/vEpqSrDxdPylUJuor7lJD53jeevKq3yqDadfTZWMMeamsOBmYJI3jR9pZR8wjgcugmDFZnqrkWLeixeFII27tdusA88Yx0qCZN1NgE/R6ZYIHNe1wDbbHMhMSN5fMYdP7YlasdpxAD2hfeGH72lc0eYVxGHa2lMTyFcItCJKl8QFNwESQSJVakOj2i83DMbEVB25vBRIq7ShoN5BgCIzJqOP4IfbyiCZsIGkg0RpI/pTv8ekZTyqVA6y/OmLWti+PikUx7g3YlZmhqmyS2ejavTH9uMj10RmwlG7ilUGFmwltOkC9RP/qgbs2mJxozQ+FoWpePjn68vz/EF+QHS3bcLBodPl4NBC5VuriEdZyEQGIQASyaW/ujnzYIBaCAbnF9UDzNk5ru29PPAudKp2b3ITnodMVF0RuVOzoHf1Qhbghl2f3TpeOT+3yIJ8gTWYccVyam83YHxKpqnUH2zfikiUv3f4mqy5YL+A+apoBcF0PrjGE897eFjspEFJEl1ivWAomn9isXQN1Bb83NAXQtHTHNkLo3zG70cLXmjCU+ARJ/VG1AhOIjWD1AwkarbVmVbIKQzCzd0fb1j27JW/D9tNSI4hKo5uMB4D88kZ6o23WHwjlfDM40lJwm+gJag/mfUmCeTRwbIwx/MB6ARfKtwtXQbOKiwjlmNLKxUc3/w= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(82310400026)(36860700016)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zdmt1PfrJ9d7zfQ764mxKrV9P6LH9hFk4mZ/q0mKx8di4g1mMd/FS4Dyu8JzOlQKyfTO8TZWfxKVUsFbiry2sWtfjrRkLVBccNQ6lKDzek+FRlAlnec3YzNpaFj/AfQS9HLZvLViGL4mMQDdKiERY0hNt/20BznH6I2skh6EuHhwTmKqxQwzwIzD4olYO5e23UNixIv+bs9Qrb7V2PcTlOemlpXvvpokCLyYky0tZKjGd2IWSRv7mDGQqcrvYhY5i1ApRiigyTgkg1Q+AG+SXa7bRAp6RdPvEBMj0rr3FmUu/XHLQGegQNnmEh2CzbNizGFzbylFLCoEJsXiqNKzthN8vF72XW8J7D5q2Kd00YfUOiP9BPwKjFbAhw0ZfPqILcQUwFIum0enGafQSz7RtNl3VzoGLYWuGRwEqE1R94OqE+lz9jjdxTT1rjNlYJZW X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:25:21.9035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c8c91b3-1574-429d-a6f0-08dea70fbfef X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF0000150A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6223 Content-Type: text/plain; charset="utf-8" Privilege Level Zero Association (PLZA) is configured per logical processor via MSR_IA32_PQR_PLZA_ASSOC (0xc00003fc). Software must program RMID and CLOSID association fields and their enable bits using the layout defined for the MSR. Define MSR_IA32_PQR_PLZA_ASSOC and the RMID_EN, CLOSID_EN, and PLZA_EN bit masks in asm/msr-index.h. Add union msr_pqr_plza_assoc in arch resctrl internal.h Signed-off-by: Babu Moger --- v3: No code changes. Patch order cahnged. Improved changelog. v2: No changes. Just rebasing on top of the latest tip branch. --- arch/x86/include/asm/msr-index.h | 7 +++++++ arch/x86/kernel/cpu/resctrl/internal.h | 27 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 9dc6b610e4e2..623628d3c643 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -1287,10 +1287,17 @@ /* - AMD: */ #define MSR_IA32_MBA_BW_BASE 0xc0000200 #define MSR_IA32_SMBA_BW_BASE 0xc0000280 +#define MSR_IA32_PQR_PLZA_ASSOC 0xc00003fc #define MSR_IA32_L3_QOS_ABMC_CFG 0xc00003fd #define MSR_IA32_L3_QOS_EXT_CFG 0xc00003ff #define MSR_IA32_EVT_CFG_BASE 0xc0000400 =20 +/* Lower 32 bits of MSR_IA32_PQR_PLZA_ASSOC */ +#define RMID_EN BIT(31) +/* Upper 32 bits of MSR_IA32_PQR_PLZA_ASSOC */ +#define CLOSID_EN BIT(15) +#define PLZA_EN BIT(31) + /* AMD-V MSRs */ #define MSR_VM_CR 0xc0010114 #define MSR_VM_IGNNE 0xc0010115 diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index e3cfa0c10e92..1c2f87ffb0ea 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -222,6 +222,33 @@ union l3_qos_abmc_cfg { unsigned long full; }; =20 +/* + * PLZA is programmed by writing to MSR_IA32_PQR_PLZA_ASSOC. Bitfield + * layout for MSR_IA32_PQR_PLZA_ASSOC (Privilege Level Zero Association). + * + * @rmid : The RMID to be configured for PLZA. + * @reserved1 : Reserved. + * @rmid_en : Associate RMID or not. + * @closid : The CLOSID to be configured for PLZA. + * @reserved2 : Reserved. + * @closid_en : Associate CLOSID or not. + * @reserved3 : Reserved. + * @plza_en : Configure PLZA or not. + */ +union msr_pqr_plza_assoc { + struct { + unsigned long rmid :12, + reserved1 :19, + rmid_en : 1, + closid : 4, + reserved2 :11, + closid_en : 1, + reserved3 :15, + plza_en : 1; + } split; + unsigned long full; +}; + void rdt_ctrl_update(void *arg); =20 int rdt_get_l3_mon_config(struct rdt_resource *r); --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E944F3DCDB6 for ; Thu, 11 Jun 2026 11:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176639; cv=none; b=qqoAILNGu1OGMVdrq5Lt0fohmPiu16FGMFvmlFSUm4zTYGW4YqDUzPm0AVnSgEbv+qiGFdMyThGxRvZBiQ0k1Er8h5UJ2/Bo4w5HEbAPoY9vQ7lvTt9bQzl7J5tsG58wuci3RnonctlOFEwt2uas8ARxsibZBVvOTqgzJXg1rbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176639; c=relaxed/simple; bh=OA0Evthwk3NooeZtoIB5dyPMSs0zlf+n9V7Hqeu0RHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZ/xMELwmwjxlbJUEDj91rJVFFrrEkJesgzjd3qkNvJwEKfMenp8q4jOSLgzR+OLDndB61HWcWfP8h646ChHccYqxnADX+Yd19OQ3Q5NrqgpOu8qs8+RE7HhSF7HP6/l5BaoJUvc+cDOl+SFZLfXp/T9G8IFKtQghxZ+MVeQkv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=sUZk+56q; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="sUZk+56q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781176634; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=sMeT7cIgvaYtfqqHFROoe2LWbxCFl5qhRouPZqDaN0Q=; b=sUZk+56q4L8T2rpXgr2tei83mHwlYq/KApCDsbKiUTmUiT0gqUWIvCzufpGWiLzlb/Fej6wc0zUr97L5F/tS/dkIvVcy3VPgDeFPxlohN/pECgSeFLunv5pWcH60I42Wk/BGh2hSLXaVzlcwpp1ZMTvtlWTqVtSqcN7OrifQUaY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=qinyuntan@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0X4dSicM_1781176633; Received: from banye.tbsite.net(mailfrom:qinyuntan@linux.alibaba.com fp:SMTPD_---0X4dSicM_1781176633 cluster:ay36) by smtp.aliyun-inc.com; Thu, 11 Jun 2026 19:17:14 +0800 From: Qinyun Tan To: babu.moger@amd.com Cc: tony.luck@intel.com, reinette.chatre@intel.com, james.morse@arm.com, Dave.Martin@arm.com, tglx@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, feng.tang@linux.alibaba.com, xlpang@linux.alibaba.com, Qinyun Tan Subject: [PATCH 2/4] resctrl: Fix PLZA RMID_EN to be mode-based and relax RDTMON_GROUP constraint for assign_mon Date: Thu, 11 Jun 2026 19:17:04 +0800 Message-ID: <20260611111706.1981788-3-qinyuntan@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Two issues identified during review of the upstream v3 PLZA patches, confirmed by the patch author (Babu Moger): 1) resctrl_arch_configure_kmode() hardcodes rmid_en=3D1 for both inherit_mon and assign_mon modes. Per the AMD hardware manual (Publication #69193), RMID_EN is a source selector: when set, CPL=3D0 uses the PLZA RMID; when clear, CPL=3D0 falls back to PQR_ASSOC[RMID] (the user process's RMID). With rmid_en=3D1 in inherit_mon mode, kernel-mode traffic is always counted under the PLZA group's RMID, defeating the "inherit" semantics. Add a bool assign_rmid parameter to resctrl_arch_configure_kmode(). Set rmid_en=3D1 only for assign_mon (GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_C= PU), and rmid_en=3D0 for inherit_mon (GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU) so that kernel-mode RMID correctly inherits from PQR_ASSOC. The assign_rmid value is derived from the active kmode in all three call sites: rdtgroup_config_kmode(), rdtgroup_config_kmode_clear(), and kmode_cpus_write(). 2) global_assign_ctrl_assign_mon_per_cpu (assign_mon) forces binding to an RDTMON_GROUP, requiring users to create an extra monitor sub-group. Since the kernel-mode group is dedicated (no user tasks), the ctrl group's own RMID is clean and usable. The extra monitor group wastes a scarce RMID for no benefit. Remove the RDTMON_GROUP constraint for assign_mon so it accepts both RDTCTRL_GROUP and RDTMON_GROUP. The RDTCTRL_GROUP constraint for inherit_mon is kept (it needs only a CLOSID, not a separate RMID). Upstream confirmation: https://lore.kernel.org/all/1d7c79bf-1e40-4db7-8f66-45f234b6d87e@amd.com/ Signed-off-by: Qinyun Tan Reviewed-by: Xunlei Pang --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 9 ++-- drivers/resctrl/mpam_resctrl.c | 2 +- fs/resctrl/rdtgroup.c | 55 ++++++++++++++--------- include/linux/resctrl.h | 8 ++-- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index 5de02a45b58e2..98bc079024219 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -234,18 +234,21 @@ static void resctrl_kmode_set_one_amd(void *arg) * resctrl_arch_configure_kmode() - x86/AMD: program PLZA MSR on a CPU sub= set * @cpu_mask: CPUs to receive the update (see on_each_cpu_mask() for onlin= e subset). * @closid: CLOSID field written into the MSR with CLOSID_EN set. - * @rmid: RMID field written into the MSR with RMID_EN set. + * @rmid: RMID field written into the MSR (only used when @assign_rmid is = true). + * @assign_rmid: When true, set RMID_EN so CPL=3D0 uses the PLZA RMID; whe= n false, + * clear RMID_EN so CPL=3D0 inherits RMID from PQR_ASSOC. * @enable: Value for the PLZA_EN split field. * * Context: Do not call with IRQs off or from IRQ context except as allowe= d for * on_each_cpu_mask(); see kernel/smp.c. */ -void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, u32 rmid, bool enable) +void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, + u32 rmid, bool assign_rmid, bool enable) { union msr_pqr_plza_assoc plza =3D { 0 }; =20 plza.split.rmid =3D rmid; - plza.split.rmid_en =3D 1; + plza.split.rmid_en =3D assign_rmid ? 1 : 0; plza.split.closid =3D closid; plza.split.closid_en =3D 1; plza.split.plza_en =3D enable; diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index fc2b3f508c039..dcf0339d92e5b 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -166,7 +166,7 @@ void resctrl_arch_get_kmode_support(struct resctrl_kmod= e_cfg *kcfg) } =20 void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, - u32 rmid, bool enable) + u32 rmid, bool assign_rmid, bool enable) { } =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 0b2606f10e2e9..1d9bd34eb9cdd 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -457,6 +457,7 @@ static int rdtgroup_kmode_cpus_show(struct kernfs_open_= file *of, struct seq_file static int kmode_cpus_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, cpumask_var_t tmpmask) { + bool assign_rmid =3D (resctrl_kcfg.kmode_cur =3D=3D BIT(GLOBAL_ASSIGN_CTR= L_ASSIGN_MON_PER_CPU)); u32 closid, rmid; =20 if (rdtgrp->type =3D=3D RDTMON_GROUP) { @@ -475,18 +476,22 @@ static int kmode_cpus_write(struct rdtgroup *rdtgrp, = cpumask_var_t newmask, */ cpumask_andnot(tmpmask, cpu_online_mask, newmask); if (!cpumask_empty(tmpmask)) - resctrl_arch_configure_kmode(tmpmask, closid, rmid, false); - resctrl_arch_configure_kmode(newmask, closid, rmid, true); + resctrl_arch_configure_kmode(tmpmask, closid, rmid, + assign_rmid, false); + resctrl_arch_configure_kmode(newmask, closid, rmid, + assign_rmid, true); } else { /* CPUs dropped from this group: old & ~newmask. */ cpumask_andnot(tmpmask, &rdtgrp->kmode_cpu_mask, newmask); if (!cpumask_empty(tmpmask)) - resctrl_arch_configure_kmode(tmpmask, closid, rmid, false); + resctrl_arch_configure_kmode(tmpmask, closid, rmid, + assign_rmid, false); =20 /* CPUs newly added: newmask & ~old. */ cpumask_andnot(tmpmask, newmask, &rdtgrp->kmode_cpu_mask); if (!cpumask_empty(tmpmask)) - resctrl_arch_configure_kmode(tmpmask, closid, rmid, true); + resctrl_arch_configure_kmode(tmpmask, closid, rmid, + assign_rmid, true); } =20 cpumask_copy(&rdtgrp->kmode_cpu_mask, newmask); @@ -1305,29 +1310,32 @@ static void resctrl_kmode_files_set_visible(struct = rdtgroup *rdtgrp, bool visibl /** * rdtgroup_config_kmode() - Push @rdtgrp's kernel CLOSID/RMID to hardware * @rdtgrp: Resctrl group whose CLOSID/RMID should be programmed. + * @kmode: Kernel-mode policy being activated, as a + * BIT(&enum resctrl_kernel_modes) value. Used to determine + * the RMID_EN setting: BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU) + * sets RMID_EN so CPL=3D0 uses the PLZA RMID; other modes clear it + * so CPL=3D0 inherits the user process's RMID from PQR_ASSOC. * * Derives CLOSID/RMID from @rdtgrp->type: * - RDTMON_GROUP: parent control group's CLOSID with the monitor group'= s RMID. - * - RDTCTRL_GROUP: the control group's own CLOSID and default RMID. + * - RDTCTRL_GROUP: the control group's own CLOSID and RMID. * * Calls resctrl_arch_configure_kmode() with the kernel-mode binding enabl= ed * on the online subset of @rdtgrp->kmode_cpu_mask (or all online CPUs when * that mask is empty), and disabled on the complementary online CPUs so * stale enable bits from a previously bound group are cleared in the same - * reprogram step. The caller (resctrl_kernel_mode_write()) is responsible - * for validating that the (kmode, group type) pair is permitted before - * invoking this helper. + * reprogram step. * * Context: Caller must hold rdtgroup_mutex. * * Return: 0 on success, -EINVAL for a pseudo-locked group, -ENOMEM if * cpumask allocation fails. */ -static int rdtgroup_config_kmode(struct rdtgroup *rdtgrp) +static int rdtgroup_config_kmode(struct rdtgroup *rdtgrp, u32 kmode) { cpumask_var_t enable_mask, disable_mask; u32 closid, rmid; - bool need_disable; + bool need_disable, assign_rmid; =20 if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { rdt_last_cmd_puts("Resource group is pseudo-locked\n"); @@ -1363,11 +1371,15 @@ static int rdtgroup_config_kmode(struct rdtgroup *r= dtgrp) cpumask_andnot(disable_mask, cpu_online_mask, &rdtgrp->kmode_cpu_mask); } =20 + assign_rmid =3D (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU)); + if (!cpumask_empty(enable_mask)) - resctrl_arch_configure_kmode(enable_mask, closid, rmid, true); + resctrl_arch_configure_kmode(enable_mask, closid, rmid, + assign_rmid, true); =20 if (need_disable && !cpumask_empty(disable_mask)) - resctrl_arch_configure_kmode(disable_mask, closid, rmid, false); + resctrl_arch_configure_kmode(disable_mask, closid, rmid, + assign_rmid, false); =20 rdtgrp->kmode =3D true; resctrl_kmode_files_set_visible(rdtgrp, true); @@ -1409,6 +1421,7 @@ static int rdtgroup_config_kmode(struct rdtgroup *rdt= grp) static int rdtgroup_config_kmode_clear(struct rdtgroup *rdtgrp, int kmode) { cpumask_var_t disable_mask; + bool assign_rmid; u32 closid, rmid; =20 if (!rdtgrp) @@ -1428,12 +1441,15 @@ static int rdtgroup_config_kmode_clear(struct rdtgr= oup *rdtgrp, int kmode) rmid =3D rdtgrp->mon.rmid; } =20 + assign_rmid =3D (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU)); + if (cpumask_empty(&rdtgrp->kmode_cpu_mask)) cpumask_copy(disable_mask, cpu_online_mask); else cpumask_copy(disable_mask, &rdtgrp->kmode_cpu_mask); =20 - resctrl_arch_configure_kmode(disable_mask, closid, rmid, false); + resctrl_arch_configure_kmode(disable_mask, closid, rmid, + assign_rmid, false); free_cpumask_var(disable_mask); =20 out_clear: @@ -1665,19 +1681,14 @@ static ssize_t resctrl_kernel_mode_write(struct ker= nfs_open_file *of, =20 /* * global_assign_ctrl_assign_mon_per_cpu binds one CLOSID and RMID for - * all kernel work (Documentation/filesystems/resctrl.rst uses - * "//", i.e. an RDTMON_GROUP). + * all kernel work. Both RDTCTRL_GROUP and RDTMON_GROUP are accepted: + * a control group is sufficient (its own CLOSID and RMID are used) and + * avoids wasting an RMID on an unnecessary monitor sub-group. * * global_assign_ctrl_inherit_mon_per_cpu assigns one CLOSID globally * while leaving RMID inheritance to user contexts; that uses the * control group's CLOSID slot only, i.e. an RDTCTRL_GROUP. */ - if (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU) && - rdtgrp->type !=3D RDTMON_GROUP) { - rdt_last_cmd_puts("global_assign_ctrl_assign_mon_per_cpu requires a moni= tor group\n"); - ret =3D -EINVAL; - goto out_unlock; - } if (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU) && rdtgrp->type !=3D RDTCTRL_GROUP) { rdt_last_cmd_puts("global_assign_ctrl_inherit_mon_per_cpu requires a con= trol group\n"); @@ -1693,7 +1704,7 @@ static ssize_t resctrl_kernel_mode_write(struct kernf= s_open_file *of, } =20 if (kmode !=3D BIT(INHERIT_CTRL_AND_MON)) { - ret =3D rdtgroup_config_kmode(rdtgrp); + ret =3D rdtgroup_config_kmode(rdtgrp, kmode); if (ret) { rdt_last_cmd_puts("Kernel mode change failed\n"); goto out_unlock; diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index e2135f0d42506..256449a0c92ff 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -724,11 +724,13 @@ void resctrl_arch_get_kmode_support(struct resctrl_km= ode_cfg *kcfg); * resctrl_arch_configure_kmode() - Program MSR_IA32_PQR_PLZA_ASSOC on CPU= s in @cpu_mask * @cpu_mask: Target CPUs; on_each_cpu_mask() applies the callback on the = online subset. * @closid: CLOSID written to the MSR with CLOSID_EN set. - * @rmid: RMID written to the MSR with RMID_EN set. + * @rmid: RMID written to the MSR (only used when @assign_rmid is true). + * @assign_rmid: When true, set RMID_EN so CPL=3D0 uses the PLZA RMID; whe= n false, + * clear RMID_EN so CPL=3D0 inherits RMID from PQR_ASSOC. * @enable: PLZA_EN field value for this update. */ -void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, u32 rmid, - bool enable); +void resctrl_arch_configure_kmode(const struct cpumask *cpu_mask, u32 clos= id, + u32 rmid, bool assign_rmid, bool enable); =20 extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; --=20 2.43.7 From nobody Tue Jun 16 14:44:09 2026 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9AD83DEFE2 for ; Thu, 11 Jun 2026 11:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176639; cv=none; b=VHzXS5fxo2+IlNeBBS3JgSfUAVr6BBFYkf1LFBfGmRUJH+5BeOJ5greIpcaGcNSv9R+Ghj7F9qnY3st5GsLdg+jxUxXyb+QJnt/P5dU+BUdke7fpz44bVdiMWNGEOoibGgw1f5JIX3W+0Vw5wl4fIwFNpbeOD7VVfXRGPOIhwdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176639; c=relaxed/simple; bh=6Eusyj8LMcywIotQkV3zMiRbgkRYGWLjlX85WM/znMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QYVClmU/3TnZ/06Mz6xjS5suagUtk4wSDVOlqcPnEQ9vsh8SigomzZseEqUSY7z3gw1a/jocA0IGqzZfYfRrquGpjGR+5xlf2wrpQ5rmGzS4yVr9Q7CIzJXIP6UGyivzICpTfQZo3y1cmsXexcLiVQKlxmW2z98yCeBVfSdHT64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=VgnlVIOv; arc=none smtp.client-ip=115.124.30.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="VgnlVIOv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781176635; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=hR9769DsyxE+X4TRXckIfTw3dA8Y+cSbBBIKuvNHX98=; b=VgnlVIOviIfIsgbPqd7X4XwcG2MRm0aJPMsUKd+gRXfCFdq6esz23wV73F7wR8nolpRmdjpTKKimAuENfj5aWb5oi/zwKbbd5mN8/3TdAh94V6Q1Ww5njDpi6DgR9C8OVocg06sZQVqok06BV7fTP+K7BXdGIkWOH4Opg387Khc= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=qinyuntan@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0X4dSicl_1781176634; Received: from banye.tbsite.net(mailfrom:qinyuntan@linux.alibaba.com fp:SMTPD_---0X4dSicl_1781176634 cluster:ay36) by smtp.aliyun-inc.com; Thu, 11 Jun 2026 19:17:15 +0800 From: Qinyun Tan To: babu.moger@amd.com Cc: tony.luck@intel.com, reinette.chatre@intel.com, james.morse@arm.com, Dave.Martin@arm.com, tglx@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, feng.tang@linux.alibaba.com, xlpang@linux.alibaba.com, Qinyun Tan Subject: [PATCH 3/4] fs/resctrl: make a failed kernel-mode switch a no-op Date: Thu, 11 Jun 2026 19:17:05 +0800 Message-ID: <20260611111706.1981788-4-qinyuntan@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" resctrl_kernel_mode_write() used to tear down the previous kernel-mode (PLZA) binding via rdtgroup_config_kmode_clear() before programming the new one with rdtgroup_config_kmode(). When programming the new binding failed (e.g. -ENOMEM on cpumask allocation, or -EINVAL for a pseudo-locked target group), the old binding had already been disabled in hardware (PLZA_EN cleared on its CPUs, the old group's kmode bookkeeping reset and its kmode_cpus files hidden). This is unacceptable from a user's point of view: a user who merely tries to switch an already-working kernel_mode configuration to a new one ends up losing the original configuration as well once the new switch fails. A failed mode switch must be a no-op and leave the existing binding untouched. Make the switch atomic by performing all fallible work up front, before the old binding is released: - Move the pseudo-locked group check into resctrl_kernel_mode_write() so it runs before the old binding is torn down. - Pre-allocate the enable/disable cpumasks in the writer and pass them to rdtgroup_config_kmode(), which then can no longer fail and is turned into a void function. - Turn rdtgroup_config_kmode_clear() into a void function as well: the arch hook resctrl_arch_configure_kmode() takes a const cpumask and the CPUs to disable are always a ready-made set (the group's kmode_cpu_mask, or cpu_online_mask when it is empty), so the temporary cpumask it used to allocate is unnecessary and is removed, eliminating its only failure point. After this change rdtgroup_config_kmode_clear() (release of the old binding) is only reached once everything needed to program the new binding is already in hand, so the subsequent programming step cannot fail. On any error the function returns with hardware and resctrl_kcfg left exactly as they were, preserving the user's existing configuration. Signed-off-by: Qinyun Tan Reviewed-by: Xunlei Pang --- fs/resctrl/rdtgroup.c | 132 +++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 1d9bd34eb9cdd..cef6ab75c2b57 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1315,6 +1315,11 @@ static void resctrl_kmode_files_set_visible(struct r= dtgroup *rdtgrp, bool visibl * the RMID_EN setting: BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU) * sets RMID_EN so CPL=3D0 uses the PLZA RMID; other modes clear it * so CPL=3D0 inherits the user process's RMID from PQR_ASSOC. + * @enable_mask: Caller-provided scratch cpumask used to compute the set of + * CPUs to enable. Pre-allocated by the caller so this function + * cannot fail after the previous binding has been torn down. + * @disable_mask: Caller-provided scratch cpumask used to compute the set = of + * CPUs to disable. Same rationale as @enable_mask. * * Derives CLOSID/RMID from @rdtgrp->type: * - RDTMON_GROUP: parent control group's CLOSID with the monitor group'= s RMID. @@ -1326,30 +1331,22 @@ static void resctrl_kmode_files_set_visible(struct = rdtgroup *rdtgrp, bool visibl * stale enable bits from a previously bound group are cleared in the same * reprogram step. * - * Context: Caller must hold rdtgroup_mutex. + * All fallible work (pseudo-lock validation and cpumask allocation) is do= ne + * by the caller before the previous binding is released, so this function + * never fails and is therefore void: a failed mode switch can leave the + * existing configuration untouched. * - * Return: 0 on success, -EINVAL for a pseudo-locked group, -ENOMEM if - * cpumask allocation fails. + * Context: Caller must hold rdtgroup_mutex. @rdtgrp must not be + * pseudo-locked (validated by the caller). */ -static int rdtgroup_config_kmode(struct rdtgroup *rdtgrp, u32 kmode) +static void rdtgroup_config_kmode(struct rdtgroup *rdtgrp, u32 kmode, + struct cpumask *enable_mask, + struct cpumask *disable_mask) { - cpumask_var_t enable_mask, disable_mask; u32 closid, rmid; bool need_disable, assign_rmid; =20 - if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { - rdt_last_cmd_puts("Resource group is pseudo-locked\n"); - return -EINVAL; - } - - if (!zalloc_cpumask_var(&enable_mask, GFP_KERNEL)) - return -ENOMEM; - need_disable =3D !cpumask_empty(&rdtgrp->kmode_cpu_mask); - if (need_disable && !zalloc_cpumask_var(&disable_mask, GFP_KERNEL)) { - free_cpumask_var(enable_mask); - return -ENOMEM; - } =20 if (rdtgrp->type =3D=3D RDTMON_GROUP) { closid =3D rdtgrp->mon.parent->closid; @@ -1383,12 +1380,6 @@ static int rdtgroup_config_kmode(struct rdtgroup *rd= tgrp, u32 kmode) =20 rdtgrp->kmode =3D true; resctrl_kmode_files_set_visible(rdtgrp, true); - - free_cpumask_var(enable_mask); - if (need_disable) - free_cpumask_var(disable_mask); - - return 0; } =20 /** @@ -1409,30 +1400,24 @@ static int rdtgroup_config_kmode(struct rdtgroup *r= dtgrp, u32 kmode) * skips rdtgroup_config_kmode() entirely -- still tears down the previous= ly * bound group instead of leaving stale enable bits behind. * - * On allocation failure the function returns -ENOMEM and leaves both the - * hardware state and @rdtgrp's bookkeeping unchanged so the caller can fa= il - * the operation atomically and last_cmd_status reflects reality. + * The arch hook reads the CPU mask without modifying it, so the CPUs to + * disable are passed directly (the group's @kmode_cpu_mask, or cpu_online= _mask + * when that mask is empty) without needing a temporary cpumask. The func= tion + * therefore cannot fail. * * Context: Caller must hold rdtgroup_mutex. - * - * Return: 0 on success (including the @rdtgrp =3D=3D %NULL and INHERIT ca= ses), - * -ENOMEM if cpumask allocation fails. */ -static int rdtgroup_config_kmode_clear(struct rdtgroup *rdtgrp, int kmode) +static void rdtgroup_config_kmode_clear(struct rdtgroup *rdtgrp, int kmode) { - cpumask_var_t disable_mask; bool assign_rmid; u32 closid, rmid; =20 if (!rdtgrp) - return 0; + return; =20 if (kmode =3D=3D BIT(INHERIT_CTRL_AND_MON)) goto out_clear; =20 - if (!zalloc_cpumask_var(&disable_mask, GFP_KERNEL)) - return -ENOMEM; - if (rdtgrp->type =3D=3D RDTMON_GROUP) { closid =3D rdtgrp->mon.parent->closid; rmid =3D rdtgrp->mon.rmid; @@ -1443,20 +1428,14 @@ static int rdtgroup_config_kmode_clear(struct rdtgr= oup *rdtgrp, int kmode) =20 assign_rmid =3D (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU)); =20 - if (cpumask_empty(&rdtgrp->kmode_cpu_mask)) - cpumask_copy(disable_mask, cpu_online_mask); - else - cpumask_copy(disable_mask, &rdtgrp->kmode_cpu_mask); - - resctrl_arch_configure_kmode(disable_mask, closid, rmid, - assign_rmid, false); - free_cpumask_var(disable_mask); + resctrl_arch_configure_kmode(cpumask_empty(&rdtgrp->kmode_cpu_mask) ? + cpu_online_mask : &rdtgrp->kmode_cpu_mask, + closid, rmid, assign_rmid, false); =20 out_clear: cpumask_clear(&rdtgrp->kmode_cpu_mask); resctrl_kmode_files_set_visible(rdtgrp, false); rdtgrp->kmode =3D false; - return 0; } =20 /** @@ -1472,11 +1451,6 @@ static int rdtgroup_config_kmode_clear(struct rdtgro= up *rdtgrp, int kmode) * (&rdtgroup_default, BIT(INHERIT_CTRL_AND_MON)) so subsequent show/write * paths do not dereference @rdtgrp after the caller frees it. * - * If the underlying tear-down fails (cpumask allocation), the snapshot is - * still reset because @rdtgrp is about to disappear; stale enable bits on - * those CPUs are reported via pr_warn() and will be cleared by the next - * non-INHERIT reprogram. - * * Context: Caller must hold rdtgroup_mutex. */ static void rdtgroup_config_kmode_delete(struct rdtgroup *rdtgrp) @@ -1484,8 +1458,7 @@ static void rdtgroup_config_kmode_delete(struct rdtgr= oup *rdtgrp) if (!rdtgrp || !rdtgrp->kmode) return; =20 - if (rdtgroup_config_kmode_clear(rdtgrp, resctrl_kcfg.kmode_cur)) - pr_warn("resctrl: kernel-mode disable failed; stale enable bits may pers= ist\n"); + rdtgroup_config_kmode_clear(rdtgrp, resctrl_kcfg.kmode_cur); =20 if (resctrl_kcfg.k_rdtgrp =3D=3D rdtgrp) { resctrl_kcfg.k_rdtgrp =3D &rdtgroup_default; @@ -1565,12 +1538,15 @@ static struct rdtgroup *rdtgroup_by_kmode_path(cons= t char *ctrl_name, * Parses @buf, validates that is listed in resctrl_mode_str[] and = is * supported by the platform (resctrl_kcfg.kmode), resolves // = to * an existing rdtgroup (or picks &rdtgroup_default if no group was specif= ied - * or if the new mode is INHERIT), clears any previous binding via - * rdtgroup_config_kmode_clear(), programs hardware via + * or if the new mode is INHERIT). All fallible validation and cpumask + * allocation are performed before the previous binding is released via + * rdtgroup_config_kmode_clear(); hardware is then programmed via * rdtgroup_config_kmode() when @kmode is not BIT(INHERIT_CTRL_AND_MON), a= nd - * on success updates resctrl_kcfg.k_rdtgrp and resctrl_kcfg.kmode_cur. T= he - * display-only "group=3Dnone" form produced by show for inactive modes is - * rejected. Errors are reported in last_cmd_status. + * resctrl_kcfg.k_rdtgrp / resctrl_kcfg.kmode_cur are updated. Because ev= ery + * failure is detected up front, a failed switch is a no-op that leaves the + * user's existing configuration intact. The display-only "group=3Dnone" = form + * produced by show for inactive modes is rejected. Errors are reported in + * last_cmd_status. * * Return: @nbytes on success, negative errno with last_cmd_status set on = error. */ @@ -1580,6 +1556,8 @@ static ssize_t resctrl_kernel_mode_write(struct kernf= s_open_file *of, char *mode_str, *group_str, *slash; const char *ctrl_name, *mon_name; struct rdtgroup *rdtgrp; + cpumask_var_t enable_mask, disable_mask; + bool masks_allocated =3D false; int ret =3D 0; size_t len; u32 kmode; @@ -1696,25 +1674,47 @@ static ssize_t resctrl_kernel_mode_write(struct ker= nfs_open_file *of, goto out_unlock; } =20 - /* Release the old binding first. */ - ret =3D rdtgroup_config_kmode_clear(resctrl_kcfg.k_rdtgrp, resctrl_kcfg.k= mode_cur); - if (ret) { - rdt_last_cmd_puts("Failed to release previous kernel-mode binding\n"); - goto out_unlock; - } - + /* + * Validate and acquire everything that can fail BEFORE the old + * binding is released, so a failed mode switch is a true no-op and + * the user's existing (working) configuration is left intact. + */ if (kmode !=3D BIT(INHERIT_CTRL_AND_MON)) { - ret =3D rdtgroup_config_kmode(rdtgrp, kmode); - if (ret) { - rdt_last_cmd_puts("Kernel mode change failed\n"); + if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { + rdt_last_cmd_puts("Resource group is pseudo-locked\n"); + ret =3D -EINVAL; goto out_unlock; } + if (!zalloc_cpumask_var(&enable_mask, GFP_KERNEL)) { + ret =3D -ENOMEM; + goto out_unlock; + } + if (!zalloc_cpumask_var(&disable_mask, GFP_KERNEL)) { + free_cpumask_var(enable_mask); + ret =3D -ENOMEM; + goto out_unlock; + } + masks_allocated =3D true; } =20 + /* + * Past this point nothing can fail: the old binding is released (a + * void operation) and the new one is programmed with the pre-allocated + * masks, so the switch is atomic. + */ + rdtgroup_config_kmode_clear(resctrl_kcfg.k_rdtgrp, resctrl_kcfg.kmode_cur= ); + + if (masks_allocated) + rdtgroup_config_kmode(rdtgrp, kmode, enable_mask, disable_mask); + resctrl_kcfg.k_rdtgrp =3D rdtgrp; resctrl_kcfg.kmode_cur =3D kmode; =20 out_unlock: + if (masks_allocated) { + free_cpumask_var(enable_mask); + free_cpumask_var(disable_mask); + } mutex_unlock(&rdtgroup_mutex); cpus_read_unlock(); return ret ?: nbytes; --=20 2.43.7 From nobody Tue Jun 16 14:44:09 2026 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010067.outbound.protection.outlook.com [52.101.61.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56EB536E467; Thu, 30 Apr 2026 23:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.61.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591550; cv=fail; b=SsXVlLZ84oOujF8h2nVBaYPUXLnHnuOF7IBwtg5DX9yvvN2RnxWPYEhP+fMHL3IcbnWyB9y4N3QuOoSDUCpkxdYHCiBhYQOPiQgpscnKNt+4YwUj6hKKoCb8wfBkZjAFw9KSZXFtoaSijRXkKBJtzsWPHETxoWwq91tkPfeOVyE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591550; c=relaxed/simple; bh=+fzAWGDdSk3iFIjEm7QRiE6VwjLzVmC4qdvhuIC6IXw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BZIT1m3eP+nNhiOGMgWvXj7BY5roqklmTcYMMiGDtvS/If7WRDoWRR8SVi/BMjGtjKG7L0hpJ5dVRrwJ/s2CD0cF4eVQvofVuogiiUxBAo8Ef2g3zkUsyonj1avZCAk78h4szh2xwR69O5ykVAE/geuLj+VR67HvGa6HPIIXflU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=omacdObf; arc=fail smtp.client-ip=52.101.61.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="omacdObf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KXE6L1LNvNLWz0+EEku7pkASTK340rS4TCPOlanyZQmjPlXRkAteSBml4SFf3GBPSF6GuZO8WdfNPRjmXJ6TSwTaOkX//4PihSnk4hlhpQj1vUVv48v1k0hIi9NGzrU6MGMSZkeIHa6dTlWjGcSOvwiiNANyMDUMo1h3r3NFQ4nxW16Hb0EHKUmZ9EQfoV0UtBuHbC467agBj6EDOwvqKbmqbjNbVJIGYck6UbhzqCHRF9P2dUR5g2N9NORojxFmM7IyIl40HOtn/ikgsAYMvdfWQSeMLCaSlU52PDoBXvfEbmpg+S9vI+CThfXwbKfCegycPYIXo2Qn1eWVxJXC2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GgshtW5NfQgVlTX1TujJF7IAC2HfmaRzgd0bkFEIJbA=; b=qxFaNQY/x0hpJIQKGxO6y6S4uf0wPLaCcq3P07xqTT5o9WQ7KfsxZjgEKSPL1pSYOX5UgZdgwXwXG2WwIGHCVWMFSIwLCQGsBex3qQwRqUXItEqp6qftzEtLxyV3Oz2o3oAQPm8IVRp+tMSJxubKBESSNDYuCppIooko7QvlOX+HwFTizuxJtMP2qgaX2cnb7ou8tRWlzE1SAwDroWhCRhqkCt/R4QA/f8CmVgDvStnG4N/qv+4bP6cn8I3W97RZxY4ARCHIcTRNV3prlSUW5LZlBq3Skh1JqTliUFxRMa7+diw33LvSPNONkQXu9p2MTYTn8knQZ+uvfcT+M8fxnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GgshtW5NfQgVlTX1TujJF7IAC2HfmaRzgd0bkFEIJbA=; b=omacdObfJmRlldgoUOfv2j9Es8v4nudBmuRstfeiKl+KUfMS8csR1VRi+6CcPM9rlP5nzbebmz+N9LjFIrTgwSlp5C1sLw8XFP4wo7bLAekBn74YbbUPKziz9gvdOnQ9OdaMkH9OQEij9Gbc/uMIxB8lInIfpwys31orCTrcdls= Received: from SN6PR05CA0002.namprd05.prod.outlook.com (2603:10b6:805:de::15) by DM4PR12MB7573.namprd12.prod.outlook.com (2603:10b6:8:10f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 23:25:31 +0000 Received: from SA2PEPF0000150A.namprd04.prod.outlook.com (2603:10b6:805:de:cafe::ba) by SN6PR05CA0002.outlook.office365.com (2603:10b6:805:de::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.20 via Frontend Transport; Thu, 30 Apr 2026 23:25:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF0000150A.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:25:30 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:25:28 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 03/12] fs/resctrl: Add kernel mode (kmode) data structures and arch hook Date: Thu, 30 Apr 2026 18:24:48 -0500 Message-ID: <3996883c2d1d47e094f97bab2a2e74df3f8c55e7.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF0000150A:EE_|DM4PR12MB7573:EE_ X-MS-Office365-Filtering-Correlation-Id: ec576fc8-c67f-43c8-f3f5-08dea70fc545 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|36860700016|82310400026|56012099003|22082099003|18002099003|13003099007; X-Microsoft-Antispam-Message-Info: wJm/CiOagfxnKR6QPrWgB3BapZBFWKV29Lfgt9UtczfhY/4x2hxr/o64kmtFBuIhNEGqjE2OYiQqnanOKTof5LzfCl82aEmjGMWvEbJdKP+uLeghY+B1IgI3TtxPt0zvHeH9miyfgEEzrtBL9DE8ookk/olCH9AvllWos3ph+M9g8k7revphMKsxiMJUt79AWdF9SmYSAm97knh2rpj+eVKDq2OOTn7Cwag6uNC363hdrxvACTX3wQ1UNjCm9UHglf3FTZImJPLxduUkxKg6Id40XlGp0YXSvWx2T28pXBst5iKNdfCYOFrmhKvD5wp87zdNxjknFPMgTWOG9lLEGPbqIgwWjTLRDYexq/sDVPMdGYzWYg7qAyzLaPTlVXE3o0nH/O8eZlorKoNYcA9/l6sZLeR6cPY/ptqB5mAiFh/qGut21Bxd9KDKsZywKB/51wQ03sMUw7gQ8C7yUPEfOkLZ6GyCnTUNGP8WLNyuOTg8R/CzbruAxFxoW2g4BSYOnz5Euthhy6aHnoGblyZpWBeaWtZuNJfyWMblBlX1Wz+hM/0sb27z5wddCi8NjYU2d1MOa9C0KTTNQS4PaSmhCMacJunFY48LaVk7YRzVK+v5dTDBU+5a/NuiG1j5Y05Z1q5/Gf/862Ui86J55DLWnJTyj5/w3Ux4Owexj5REAeV4mL8QEP4ldFWyCKeVTR7h X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(36860700016)(82310400026)(56012099003)(22082099003)(18002099003)(13003099007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2VXsnR6sC+GA+MpdRwLCdDIeo5a4UVck7J20FPYb6zD1MQx8l33thoiBiwZgudNKZfkfVKd5Y8NYKmCnFTMy5grRRkN3W+soorhS6ZqmE1GzgJHtlzORn6hqKLSoK6epcjBQD2okQDi7lSbRv0piOOcc0rnAps2iH+fZo8Cy7Fwn70IAF3t28gGBvb0kS5jiz88nBtzndPnjElQ+4DiN29NuZkRYiDxZIRjqqaXj+fQ5BMWj41L0lhiJiu2Vk6tKCnppE9yQWq+O3RwiBu1gegG7TBhdMdkqw3ynnyf1mPJUtCqnNFEaYqyV14ECKB+aIoPWvZjPMPymWiaRDBVsDnjvIE18ncF2mGIIEjcmvxSbUfVauRheipvOUEeDVP6DgElhbou86neaweCILhmmHYf+LQIIhNqpT9J8qioxU0TOToPzp522tC1T1MegDCu+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:25:30.8617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec576fc8-c67f-43c8-f3f5-08dea70fc545 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF0000150A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7573 Content-Type: text/plain; charset="utf-8" Privilege-Level Zero Association (PLZA) allows the user to specify a CLOSID and/or RMID associated with execution in Privilege-Level Zero. Introduce a generic enumeration so that architecture and generic code can agree on the available policies. Introduce enum resctrl_kernel_modes with the following values: - INHERIT_CTRL_AND_MON: kernel and user tasks share the same CLOSID and RMID. This is the default and matches today's resctrl behaviour. - GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU: a CLOSID is assigned for kernel work while the RMID used for monitoring is inherited from the running user task. The default scope is all online CPUs and may be narrowed to a subset via the resctrl group interface. A CTRL_MON group can be bound to this mode. - GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU: both CLOSID and RMID are assigned to kernel work. The default scope is all online CPUs and may be narrowed per CPU via the resctrl group interface. A CTRL_MON group can be bound to this mode. - RESCTRL_KMODE_LAST: highest enumerator naming a policy mode. - RESCTRL_NUM_KERNEL_MODES: number of policy modes; use this to size static tables indexed by mode. Also add struct resctrl_kmode_cfg (the snapshot architecture code returns) in include/linux/resctrl_types.h, and declare resctrl_arch_get_kmode_support() in include/linux/resctrl.h so architecture code can advertise the supported modes. Signed-off-by: Babu Moger --- v3: Removed resctrl_kmode definition. Changed the kernel mode definitions to enum resctrl_kernel_modes. Used BIT() to set/test the features. Added details to changelog. v2: New patch to handle PLZA interfaces with /sys/fs/resctrl/info/ director= y. https://lore.kernel.org/lkml/2ab556af-095b-422b-9396-f845c6fd0342@intel= .com/ --- include/linux/resctrl.h | 13 ++++++++++ include/linux/resctrl_types.h | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 006e57fd7ca5..ce28418df00f 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -699,6 +699,19 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *= r, bool enable); */ bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r); =20 +/** + * resctrl_arch_get_kmode_support() - Advertise kernel-mode capabilities + * @kcfg: Architecture ORs BIT() flags into @kcfg->kmode for each supported + * &enum resctrl_kernel_modes value (see &struct resctrl_kmode_cfg). + * + * Used for optional features (for example PLZA on x86) that can assign CL= OSID + * and/or RMID to kernel work separately from user tasks. Generic code co= mpares + * @kcfg->kmode with the effective @kcfg->kmode_cur; when a global-assign = mode is + * active, @kcfg->k_rdtgrp identifies the active &struct rdtgroup. The def= ault mode + * is INHERIT_CTRL_AND_MON and group is default group. + */ +void resctrl_arch_get_kmode_support(struct resctrl_kmode_cfg *kcfg); + extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; =20 diff --git a/include/linux/resctrl_types.h b/include/linux/resctrl_types.h index a5f56faa18d2..3aba07764b99 100644 --- a/include/linux/resctrl_types.h +++ b/include/linux/resctrl_types.h @@ -68,4 +68,50 @@ enum resctrl_event_id { #define QOS_NUM_L3_MBM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID - QOS_L3_MBM_TOTA= L_EVENT_ID + 1) #define MBM_STATE_IDX(evt) ((evt) - QOS_L3_MBM_TOTAL_EVENT_ID) =20 +/** + * enum resctrl_kernel_modes - Kernel versus user CLOSID/RMID policy + * + * Enumeration values are contiguous indices from 0 through + * @RESCTRL_KMODE_LAST inclusive. Global-assign modes treat all online CPU= s as + * in scope by default; a subset of CPUs may be selected by using resctrl + * group's interface. + * + * @INHERIT_CTRL_AND_MON: + * User and kernel tasks use the same CLOSID and RMID. + * @GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU: + * A CLOSID may be assigned for kernel work while RMID selection for + * monitoring follows the same inheritance rules as for user contexts. + * Default scope is all online CPUs: subset of CPUs may be selected by + * using resctrl group's interface. + * @GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU: + * A single resource group (CLOSID and RMID together) may be assigned to + * kernel work. Default scope is all online CPUs: subset of CPUs may be + * selected by using resctrl group's interface. + * @RESCTRL_KMODE_LAST: + * Highest enumerator that names a policy mode. Use RESCTRL_NUM_KERNEL_MOD= ES + * to size static tables indexed by mode. + */ +enum resctrl_kernel_modes { + INHERIT_CTRL_AND_MON, + GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU, + GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU, + RESCTRL_KMODE_LAST =3D GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU, +}; + +#define RESCTRL_NUM_KERNEL_MODES (RESCTRL_KMODE_LAST + 1) + +/** + * struct resctrl_kmode_cfg - Kernel-mode policy snapshot from architecture + * @kmode: Hardware- or policy-supported modes: each enumerator from + * &enum resctrl_kernel_modes is represented by BIT(mode index). + * @kmode_cur: Effective mode(s) in the same BIT(index) form as @kmode. + * @k_rdtgrp: Resource group backing global-assign modes when applicable; + * initialized to the default group at boot. + */ +struct resctrl_kmode_cfg { + u32 kmode; + u32 kmode_cur; + struct rdtgroup *k_rdtgrp; +}; + #endif /* __LINUX_RESCTRL_TYPES_H */ --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011038.outbound.protection.outlook.com [52.101.52.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D160E3C9EDF; Thu, 30 Apr 2026 23:25:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591553; cv=fail; b=tKQ8ThxL318osdSWPxz3VJg6EWF39bcndPOGIiWaEaKzyxudBcv9L/KPAE+CgczteoJxlDKQA/ptey3T91nX+x3TS+lQSqhxFaPYriEJcTYL5G+NpGVMunGI4xBCeQZFnq9/qhfkER71Q+Bl8zxNgsu0FG4Zn13oDsBccIARgj0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591553; c=relaxed/simple; bh=JirkQJXuX33/78uB83NOASXV+k/8QaHetU+bTiDXi2s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GdmaeojKraLJvwu628dSIrnaG0TvDdAY1bPTtuJzbRZjUGs/49gKmaAe6hNk+WQNGY+TQUs4oLFYD/F7TpEmgjG9XiznhDZ10owGWDVKzo8sTLQFHTQdOSzAjwM09ZXbzBzxwzdcE+TYRbBlRJbYYmmwAHTO6Cuu31F6KlNbn7Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=oB9JMQjH; arc=fail smtp.client-ip=52.101.52.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="oB9JMQjH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u1InqwNQxUt3dvQyLIJRCEbtEP55YdtSPcqVx1KU6N22DJbh1XS5MbL+drl7ZBJD1nTS5tl0czEu7kifK7ajra/i+x/+FY5TT795nCvDiJbKf/xHBjeUvc+pIrSvNtJE/eCNgp0dCVbgmoMHJiHeGTjDliOkXpKTPQgQFiXRVmlpdR1JczoNG2ZQWiGWa3foe0nyB6xJnUlhmQdFducbk8xv6QT+md6zBYnb2WdE7g3TQKqUSphwHsW0ZjxM419VYwp8Xp9OljxuSLI2zlDuTlts/mA3ECdz/6depb/j4Jg7H64J453Lkws+s+M3hF9Y3N1sSKkjopMS0XFjQ50kag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/8GRiROUN6gQ5smbZ96DHqRS6bJj8VflOO8SC8B9InU=; b=j8wc4CPWx3nPZcCcHn1IOrmy+y01DJnuwdwN3Qxe2Du+lJVVZSqaG6p6szcfRxCKyPLs8W30yinwiJaAJPqc4heeUNXa/Ys7qqCi9ono7uS4iEimBbkTC/gYqA2xCWeeAMV0nCzz+7D6VLIkmdNSkPRnENv2yqYGExWTrCKpJk95Ai5M/Ot2nzXJD0Xca/ELe7bC7yjtVhkOhRuWg+RNiQ/VRDH8QkJEYbcq0WhiMWPbPqGpdzexwYmae4pmeugg7x1+dcO9PCd0HueOQa0REIPYQaB2+L7CwDdY+xT4tcvu5eP6wQZD0gYK6GNFI4azb074DM6v14Ukxk/ecADKUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/8GRiROUN6gQ5smbZ96DHqRS6bJj8VflOO8SC8B9InU=; b=oB9JMQjHaBW0enkb+4YzapQDrZn6z5zwq8p52iFI41qdhuYjxAFygVl4A6s92NvxyX8EMEt7uPtj4mmuQsA5DCxxkX3Kctylxi1c5E+1QyaJBSSyfxcqH6qp3uCqAVEKxXp9Ifw+CWRkw8XK8bdeDQMbmsliQW10uDLroqIb1ME= Received: from SA0PR11CA0128.namprd11.prod.outlook.com (2603:10b6:806:131::13) by DM6PR12MB4481.namprd12.prod.outlook.com (2603:10b6:5:2af::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22; Thu, 30 Apr 2026 23:25:45 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::24) by SA0PR11CA0128.outlook.office365.com (2603:10b6:806:131::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.30 via Frontend Transport; Thu, 30 Apr 2026 23:25:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:25:44 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:25:42 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 04/12] x86,fs/resctrl: Program PLZA through kmode arch hooks Date: Thu, 30 Apr 2026 18:24:49 -0500 Message-ID: <0cfd813e10072eefc8f4d84328e83bd9a6220ad4.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001509:EE_|DM6PR12MB4481:EE_ X-MS-Office365-Filtering-Correlation-Id: 04ae6fa0-030c-40d4-229c-08dea70fcd74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700016|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: PFu2rvEhLxXiP3PKfstbJg5asahrdQxeDrczrGsEBjARy+TKTHtTfbevVkKHbA4WuslaSxNIweCxKRZrw/LwEy8uiSmXGDmQktK5fdoLthPpVfTJns4JJOU2MzO9Aen12Tdq8DP7KI6mNmROyxQ6B5bq9m0h49zwRd5LIVuplQUaqjRAtmjfH9tWwqJLIeN1ArMURBFWTCWjO9dOIEOnNMUEKSOLJpwq9/WK47ouKi7ira807gA1smV3PVBnwm3usBsh+RNwmEFMQ+CDSmlYKWM9oFhhxBNatdUZTbo6/3flkRGegKPNjSYlXn58YIVAatSO/IkxoMEaz1sYO5Ctm9Dda2HUZhDRHagHnArRvm7ocB81yKtx10o5UekbX5FwM5WrFFvepBg5zBVw6mjepvhSSkL6NITuCo5dOuBSkbxcub0bTqHF4IxFOCRm86tiGAksosnuS6OpyrdklgE51jU4P+x1lB6spMSablhMgSBd8JXEbHBBF0XdCKMMdajifn24ziACgRtFZ2TQ6JsmufSnVDS9MIDU8PU5kAa9ESLUIwqJZ7vpVv4/PNg6XqzpZhH3Nk6cl6FSGBEi2jzr64B2jPmcSj8lU6XTo2cGRZpwItG6vNaSp1Bn5y985znWD2/5y/WSd+DvAm2DZlrA8JJFTq/x5e4lypY9f3kzDs3ZzDW6rIYFFUWQ/nkHZxnVoVl/FPuVZ9u9EJMV17RuMoW0Zu/BOLgD4A8ur+FsD5U= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(82310400026)(36860700016)(18002099003)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D+Mr6XZo3R0HgEHIcksRS72Ju1ADcJ35LjttcjN0u1tw3P9WBcPosgC341gAAhDuqaW80TAco15mBvVPWrmxiXQPfxQDSJ2glT20C8SUGHR3yFmCbuPv1PcIaDPrhzWz4kYFkE7a4bNSFQ8GvxTEuuLF8OgF1ZcArCjLUT5CVmpskw+IpzgE9aMRcDpah1/DAFK2+T8nV57KterJKXh5xiX/bB/yPuKd0nBgoso829Ho0t/psPs1k4LE4KjcWq52mmyK/pSfLL6RU4LK47MR3ySk95bSLCFBvCBC+LBfgiQnEBnGxJmtK/zaOUUxPgnV4bwV/E6EnvC+grb0y72LiLbpsaaJoO9APFl+jfvCWMCGPY/5ZhvpieG81OGFW8MjcaWeuUqhhVKebwl8tJIpSjRyh0ZY/TLmndKFtzwYVpMi37akawFTWz4fv6yC3kuw X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:25:44.5854 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04ae6fa0-030c-40d4-229c-08dea70fcd74 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4481 Content-Type: text/plain; charset="utf-8" AMD Privilege Level Zero Association (PLZA) exposes kernel CLOSID/RMID association through MSR_IA32_PQR_PLZA_ASSOC. Generic resctrl already tracks supported and effective kernel-mode policy in struct resctrl_kmode_cfg, but the architecture layer needs a callable entry point that can push those values into per-CPU hardware on a chosen CPU mask. Declare resctrl_arch_configure_kmode() in linux/resctrl.h with kernel-doc. Implement it on x86: add an SMP callback that writes MSR_IA32_PQR_PLZA_ASSOC on each targeted CPU, and use on_each_cpu_mask() for the broadcast. The hook is unused in this patch; later patches in the series wire it into generic resctrl when an effective kernel-mode policy is selected or a CPU mask changes. Signed-off-by: Babu Moger --- v3: Removed task based PLZA implementation so related changes are removed. Removed handling of rmid_en as it is not required. The group type assig= ned will be different so the monitoring part is already taken care. Updated the change log with details. Removed resctrl_arch_set_kmode() as arch only provides the modes suppor= ted. It is FS which decided which mode to apply. v2: Updated the commit message to include the sequence of steps to enable P= LZA. Added mode code comments for clarity. Added kmode to functin names to be generic. --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 35 +++++++++++++++++++++++ include/linux/resctrl.h | 10 +++++++ 2 files changed, 45 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cp= u/resctrl/ctrlmondata.c index b20e705606b8..68f1cf503904 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -131,3 +131,38 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *= r, bool enable) =20 return 0; } + +/* + * SMP call-function callback: each CPU writes its own MSR_IA32_PQR_PLZA_A= SSOC + * (AMD PLZA). Invoked via on_each_cpu_mask() with wait=3D1 so the on-sta= ck + * union pointed at by @arg is safe. + */ +static void resctrl_kmode_set_one_amd(void *arg) +{ + union msr_pqr_plza_assoc *plza =3D arg; + + wrmsrl(MSR_IA32_PQR_PLZA_ASSOC, plza->full); +} + +/** + * resctrl_arch_configure_kmode() - x86/AMD: program PLZA MSR on a CPU sub= set + * @cpu_mask: CPUs to receive the update (see on_each_cpu_mask() for onlin= e subset). + * @closid: CLOSID field written into the MSR with CLOSID_EN set. + * @rmid: RMID field written into the MSR with RMID_EN set. + * @enable: Value for the PLZA_EN split field. + * + * Context: Do not call with IRQs off or from IRQ context except as allowe= d for + * on_each_cpu_mask(); see kernel/smp.c. + */ +void resctrl_arch_configure_kmode(cpumask_var_t cpu_mask, u32 closid, u32 = rmid, bool enable) +{ + union msr_pqr_plza_assoc plza =3D { 0 }; + + plza.split.rmid =3D rmid; + plza.split.rmid_en =3D 1; + plza.split.closid =3D closid; + plza.split.closid_en =3D 1; + plza.split.plza_en =3D enable; + + on_each_cpu_mask(cpu_mask, resctrl_kmode_set_one_amd, &plza, 1); +} diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index ce28418df00f..570918e57e24 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -712,6 +712,16 @@ bool resctrl_arch_get_io_alloc_enabled(struct rdt_reso= urce *r); */ void resctrl_arch_get_kmode_support(struct resctrl_kmode_cfg *kcfg); =20 +/** + * resctrl_arch_configure_kmode() - Program MSR_IA32_PQR_PLZA_ASSOC on CPU= s in @cpu_mask + * @cpu_mask: Target CPUs; on_each_cpu_mask() applies the callback on the = online subset. + * @closid: CLOSID written to the MSR with CLOSID_EN set. + * @rmid: RMID written to the MSR with RMID_EN set. + * @enable: PLZA_EN field value for this update. + */ +void resctrl_arch_configure_kmode(cpumask_var_t cpu_mask, u32 closid, u32 = rmid, + bool enable); + extern unsigned int resctrl_rmid_realloc_threshold; extern unsigned int resctrl_rmid_realloc_limit; =20 --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 743303E00BA for ; Thu, 11 Jun 2026 11:17:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176648; cv=none; b=V/sMsGI4dAyt8QxtvAare5zqhxPvtaRDRLZOmeTgDZ510NaxjtuG4NYwppkmwE/gTB2WGNAl9G0OWK330g+h2fcz/CC0zYflkgMRjOwB4mrisRQ7GMnGVO4s3Ok9LZ/plKvKjf8plghGLg5amoHBfSL0pf+RQn9GB9yRrVKdQPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781176648; c=relaxed/simple; bh=q/eqcGkTGXkNiYgB7wRc9m5Ch3YUu7+tlGCU2A3hHFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fXDUJ4YRPT6Yc2LoZLmQEjSGa9+nRIepreDg/i4gi3yDIVXjK+NYuMUFQHVju15NhEH8DtEmNG8ntQGH8HINldOq1REhGnfkY71bIWqLe3Le6u+L5tSfE1iWTuZr1n7AhjyRfdKQ/BNrI2i7hAeT7d/IOcm7YERSajILzdKLTYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Wu2w3TUU; arc=none smtp.client-ip=115.124.30.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Wu2w3TUU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1781176637; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=DBs33/PI1020kI8Nuj1AY4mskWywP4UDKhySQeZWmd4=; b=Wu2w3TUUMvnYkRJyDCaD60EhK9riDBjnatieawHk8SNHm3moqYrSFbZc8XFA8t/pBX5DNoGTTsXQ9nNIpsdLei5Tbq14Rlb1CbzScJ2uYJrQsF0tESbQ5OPsW6ls9xfhyqw4dMYc3j81vvzQrUP6IpYiC8ZRhl5nN2sya6FchfU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam011083073210;MF=qinyuntan@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0X4dSidL_1781176635; Received: from banye.tbsite.net(mailfrom:qinyuntan@linux.alibaba.com fp:SMTPD_---0X4dSidL_1781176635 cluster:ay36) by smtp.aliyun-inc.com; Thu, 11 Jun 2026 19:17:16 +0800 From: Qinyun Tan To: babu.moger@amd.com Cc: tony.luck@intel.com, reinette.chatre@intel.com, james.morse@arm.com, Dave.Martin@arm.com, tglx@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, feng.tang@linux.alibaba.com, xlpang@linux.alibaba.com, Qinyun Tan Subject: [PATCH 4/4] fs/resctrl: program PLZA on a CPU that comes online under a binding Date: Thu, 11 Jun 2026 19:17:06 +0800 Message-ID: <20260611111706.1981788-5-qinyuntan@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The kernel-mode (PLZA) MSR (MSR_IA32_PQR_PLZA_ASSOC) is per-CPU and is only written when a binding is configured via info/kernel_mode or when a group's kmode_cpus mask is changed. Both paths only touch the CPUs that are online at that moment, and the CPU hotplug online callback does not reprogram it. As a result, a CPU that comes online *after* a binding is in place -- a hot-added vCPU, or a CPU that was offline at bind time -- runs with PLZA disabled even though an empty kmode_cpu_mask ("all online CPUs") or an explicit mask says it is in scope. Its CPL0 traffic then uses the default PQR_ASSOC CLOSID/RMID instead of the bound kernel-mode group, so the kernel-mode protection is silently off on that CPU while info/kernel_mode still reports the binding as active. Make resctrl_online_cpu() the single authoritative sync point: on every CPU online, idempotently drive the CPU to the state it should have under the current binding -- enable PLZA with the bound CLOSID/RMID when the CPU is in scope, otherwise explicitly clear it so stale enable bits left on a CPU that was offline while it was removed from the scope are cleared too (offline CPUs are skipped by the IPI-based reprogram paths and the MSR is not reset by a soft offline). Bail out early on platforms without kernel-mode support so the MSR is never touched there. offline needs no counterpart: a CPU's PLZA state is fully determined by this online-time sync. Signed-off-by: Qinyun Tan Reviewed-by: Xunlei Pang --- fs/resctrl/rdtgroup.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index cef6ab75c2b57..35cc0083d1b2f 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -5336,11 +5336,64 @@ int resctrl_online_mon_domain(struct rdt_resource *= r, struct rdt_domain_hdr *hdr return err; } =20 +/* + * resctrl_kmode_online_cpu() - Sync a freshly onlined CPU to its PLZA sta= te + * @cpu: The CPU that just came online. + * + * The kernel-mode (PLZA) MSR is per-CPU and is only written when a bindin= g is + * configured or its kmode_cpus mask is changed; nothing reprograms it for= a + * CPU that comes online afterwards. Make the online callback the single + * authoritative sync point: idempotently drive @cpu to the state it should + * have under the current binding. This both programs a CPU that is onlin= ed + * after a binding is in place (e.g. a hot-added vCPU, or a CPU that was + * offline at bind time) and clears stale enable bits left on a CPU that w= as + * offline while it was removed from the scope (offline CPUs are skipped by + * the IPI-based reprogram paths and the MSR is not reset by a soft offlin= e). + * + * Scope: an empty kmode_cpu_mask means "all online CPUs" (so @cpu is alwa= ys + * included), a non-empty mask means only the CPUs explicitly listed there. + * + * Context: Caller must hold rdtgroup_mutex. Runs on @cpu during the CPU + * hotplug online callback, so the MSR write lands on the right CPU and no + * cross-CPU IPI is needed. + */ +static void resctrl_kmode_online_cpu(unsigned int cpu) +{ + struct rdtgroup *rdtgrp =3D resctrl_kcfg.k_rdtgrp; + u32 closid =3D 0, rmid =3D 0; + bool assign_rmid =3D false; + bool enable =3D false; + + /* Platform without kernel-mode (PLZA) support: never touch the MSR. */ + if (!(resctrl_kcfg.kmode & ~BIT(INHERIT_CTRL_AND_MON))) + return; + + /* Compute this CPU's correct state under the active binding. */ + if (resctrl_kcfg.kmode_cur !=3D BIT(INHERIT_CTRL_AND_MON) && rdtgrp && + (cpumask_empty(&rdtgrp->kmode_cpu_mask) || + cpumask_test_cpu(cpu, &rdtgrp->kmode_cpu_mask))) { + if (rdtgrp->type =3D=3D RDTMON_GROUP) { + closid =3D rdtgrp->mon.parent->closid; + rmid =3D rdtgrp->mon.rmid; + } else { + closid =3D rdtgrp->closid; + rmid =3D rdtgrp->mon.rmid; + } + assign_rmid =3D (resctrl_kcfg.kmode_cur =3D=3D BIT(GLOBAL_ASSIGN_CTRL_AS= SIGN_MON_PER_CPU)); + enable =3D true; + } + + /* Idempotent sync: enable when in scope, otherwise clear stale bits. */ + resctrl_arch_configure_kmode(cpumask_of(cpu), closid, rmid, assign_rmid, = enable); +} + void resctrl_online_cpu(unsigned int cpu) { mutex_lock(&rdtgroup_mutex); /* The CPU is set in default rdtgroup after online. */ cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); + /* Restore the kernel-mode (PLZA) binding on a CPU that just came online.= */ + resctrl_kmode_online_cpu(cpu); mutex_unlock(&rdtgroup_mutex); } =20 --=20 2.43.7 From nobody Tue Jun 16 14:44:09 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010022.outbound.protection.outlook.com [40.93.198.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98AAA3939DB; Thu, 30 Apr 2026 23:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.22 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591561; cv=fail; b=NLuP2jAHqgMlQ1TVLxnTGLC66SNsFe49FHF3O//MOZiUQQDJqjmxDIBpiApyUYzJT19xHswsqOvE/kcfIr6XiB9qp/18NqjdcuUzdSOExQG9p58BuPdecPMS8+3AuX8oIaewC1E1jxNuPDsU5+qJPDkvFLhbb7v49HE+bcbtNqA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591561; c=relaxed/simple; bh=XL+8M0+9C8nCj3l+qFbZAKbC/2WkHr8p3nhQwUc8u74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ct7kKDgSWGBAEja1VCkomaVVcRte+qN1XN3G32woWpG2Hpf+S/YN/Ii1gCUh0DfMgfYaDuQXXLQA5dDthaWHc9BNp1+i4VYdR+xTlnIpQqB8Kq9HfhN0IeLaXGFmXhIaIc/V3cnkRQuH/0BqJzIFQhkSzcxALQRbLz4GX6uR+Bo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=glraDawX; arc=fail smtp.client-ip=40.93.198.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="glraDawX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Svp4VlLuaaH3lhygkN1cN1pix7AooOPVw7NKWm0LqwXSYwQzeVATSQY4EryUrE/yQSKs9AX0p1dFkjfln6VbhoaF3dnTyu4wFINQRPuwRG7DUg5kIImCKBialFg+hDvkN77/ARKvy6JJQBgjswdYy7Vp/bZm41aohY3QHHwpZC1LO45o+nlKlv95lJxD5veOizwKaB6flMZ9YgojQc+5w6qIYNeixqi6a6Vhxt+9+U4gjuFV1y8pB2KRkVPdJ5eGm+4/oB92FNYozfcPir3qw4zEDID6e9khnejI/5S4Rx04+2CBoez7QvV0bKHxdzejSs1W+1QJfJicZj/g9+muLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n3wNUh+EYo3ygKN3Gl//5KCo8ArGaNmrqkl36FdZWD0=; b=RktSx4Da/vkPql7YwEmDr9umkViezCRwJM8WOy3yLNtu57ginxQc79B+9aPq6dxaRFSUQNW0IyjzAvSokSpXJxin+Sz3WeLI9z0AeCX3HZBxlRMvg/c+RaIZOYZalNzn5zADn//kE6N1sMeIhPUIlsr6UrzZ7OKS2JJaLd9odEXF/6syFr22hpIaZhJuPxDUnygAl4eyBt9iw0aR7zA+8JoHiCZVd61QK7rAxqQboDueU0sOCG41VrNMCXiKMgSW/L8mggTC2cxu2E0xGC6uMVS6no2c3e80/r6UFGrFrHGPONSUzFhKksni9LV2diW5Hgv2ewWcpc6g3IsP6BBpqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n3wNUh+EYo3ygKN3Gl//5KCo8ArGaNmrqkl36FdZWD0=; b=glraDawXp8RPIWOz6h4COLFskhwHb2IZDKE0neBzklYfggHDw2k9RCWuucv6SmKT2YVoaImXo+WVPqnHwyIuPi+uL3ntFmy1FJniJRDu3TbdrpILl6Moq2RhM+K4XSUNRcn0Ak56EBbW7xKmtlenzJX5/HqIM1XzmLSWG+63vsA= Received: from SA0PR11CA0132.namprd11.prod.outlook.com (2603:10b6:806:131::17) by DS0PR12MB9058.namprd12.prod.outlook.com (2603:10b6:8:c6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 23:25:52 +0000 Received: from SA2PEPF00001508.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::b4) by SA0PR11CA0132.outlook.office365.com (2603:10b6:806:131::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.30 via Frontend Transport; Thu, 30 Apr 2026 23:25:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001508.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:25:52 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:25:50 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 05/12] x86/resctrl: Initialize supported kernel modes for PLZA Date: Thu, 30 Apr 2026 18:24:50 -0500 Message-ID: <95188117225c9235be89753edcace115cf5c2e5f.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001508:EE_|DS0PR12MB9058:EE_ X-MS-Office365-Filtering-Correlation-Id: 835987a3-3813-45f3-84b0-08dea70fd21e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|7416014|36860700016|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: RZzl7blm4TwKyZCndMxFCFy57vBCeMeu7c5JPJvUQROR5mcI4+873h9Fr91kjkhBa2LPRoezStZS/fNXbk26ismehlSNAwhudpfAUyZpSdDViip/TUeDn9XyIYL/0NmvzFouuvLnckR4hLKMiKOQumWZUvQK3zV/6+W/eXIUoIb51aKA7og2u3vqy+O4IsDxSBoNUpn9wBwDqf4eb+3B0D3bayfgD4qgutmIv68hiQ3/leSCwEmoMsUcdTamIzpHvuqneuAcR4JG4r/911gNMQueabyED5m8k//p82itg/kH+iGSoqCH2kMuirzVpWIyYHUm0GZTayC3VOpN2USH1n4D8tU1eqaWwoUG+cdojoZDcMf/+OsF9L/F+yUvzG7hS+mIrwQNpVYQtTOG15eSF821MrDyQoKc9kGD8DpawZaxl9i5x1cy0eqluwn9Kh5QjWGQu2p8mIjaztQ5+KB/npamhJyWoeqtpKQoWf/kP6fwrRFyW3EBKoRg+B+u+69Z6ZHkMoWkx7CtG3yNUjcz3+EJETRfV+t7vL4m2mCLyQ+bhW6qMp/fZHOeIpIyjL2g0EHLw1pv//s0Brd+uQTbWq7DGxnMKZgKSlnR3N+Pw7uI28//ZWJiSkusygO8c8joE9HAnwbZ9LQGnrnxM/IaeYHeAF9Szl5Bins6Ioo6TN6vEik+Et68GbpqE4gDNbPzz9uzZBiPaN3TFdtxOvgHBYEuQJCXqDeornJZTDfyjPQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(376014)(7416014)(36860700016)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DU+/1olxiBLmFYmQKT3Gf+0YBcIunlRp6hnXW7DAMhEip+50QC81od2HYvYHGLRS2Q6zShw8+Q+olIf0FYNa8bflfHo5y59zt0AXPljBSWudciz4+E4aa6JwafqIHka0VVJxDvGq/lsSfAIZdZlj1ZO0tf0nWqf9Un8054VN7HDV50/C6hTojTLzeIn4Pf241bIw6XDizZArPr1T7QlD1Fml78YlbVAXdPcqeVMdSWcaD0X0SJS8qwW8uaC5XYxfkFMIYQjVeKpEIdrfEevXPqQobGK7wzu9doNoQch8iBhm2QL99W9M5BvC3ZAETgjTILzsyDRTnp23hL5jq7OjsRhhzm1n6uaRrRHEW+W3H20vOfYxcu+CRTriYBuUHu+u0MLBZiPgQPcBeNuGr+Yh+/e2lMWpCMhzXn9deJV34frroHW03pm/ke33+Mp0UZuz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:25:52.4100 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 835987a3-3813-45f3-84b0-08dea70fd21e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001508.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9058 Content-Type: text/plain; charset="utf-8" Resctrl subsystem tracks which kernel-mode CLOSID/RMID policies the platform can offer via struct resctrl_kmode_cfg and resctrl_arch_get_kmode_support(). AMD PLZA (Privilege Level Zero Association) is the x86 feature that allows kernel traffic to use an assigned CLOSID alone or CLOSID and RMID together. Report the available kernel-modes when x86 PLZA is enabled. Signed-off-by: Babu Moger --- v3: New patch to report all the supported kernel mode by arch. --- arch/x86/kernel/cpu/resctrl/core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 4a8717157e3e..699d8bb82875 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -894,6 +894,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_eve= nt_id evt) } } =20 +/** + * resctrl_arch_get_kmode_support() - x86: record which kernel-mode polici= es hardware supports + * @kcfg: Cumulative snapshot; OR bits into @kcfg->kmode (see &struct resc= trl_kmode_cfg). + * + * When PLZA is present (CPUID X86_FEATURE_PLZA), the kernel may assign a = CLOSID + * for kernel work alone or assign CLOSID and RMID together. Advertise bo= th + * assign-style modes in @kcfg->kmode using &enum resctrl_kernel_modes ind= ices. + */ +void resctrl_arch_get_kmode_support(struct resctrl_kmode_cfg *kcfg) +{ + if (rdt_cpu_has(X86_FEATURE_PLZA)) + kcfg->kmode |=3D BIT(GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU) | + BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU); +} + static __init bool get_mem_config(void) { struct rdt_hw_resource *hw_res =3D &rdt_resources_all[RDT_RESOURCE_MBA]; --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012023.outbound.protection.outlook.com [52.101.43.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B653B0AEA; Thu, 30 Apr 2026 23:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.23 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591578; cv=fail; b=L+b2QKk+kxvg/0QEKwew8WTGmABqdac7dQQXoMbR+G4h5s8L9us/iQ3mtSwzCexp2SCXixxvfxLMHbMrRik/iRugIKyHOjLk/k0Sy+HfF5mf50NK8pJ4NiwMDPucn8lwJTLbeBmvQnzzPtRBlkoeGnBDwUbytLILj+V8MLhURbE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591578; c=relaxed/simple; bh=5AAKGHnYjfIKVbue4VAKwrYVBAcWY7Mwl3n7zrzpouc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PtxHKaDJyMBJNDpyjVjSzFKHZTXGwfK8Ps4CbqPN701MJIfzj0fsfMkfUNXlK84P8xhb1DTnvIYJtI+43nF6ny3Zrqkl9ymWceh5IVD/RA606B3TbDZKb1rXkpLbxUfnxCAMakQLUaiSgjBXZYMHPj6bjXHmrKHt5W1b2d3j3E8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=E9hn+kLh; arc=fail smtp.client-ip=52.101.43.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="E9hn+kLh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nlrImhNzAIuI4h4Ae80XfjS+MROsDTjsZROx5RoDI0foiAO4TaeqwNkCH6VeiDxlZfYyiFC1ni7RWMudYllvXCLmZqgDYOqwy0SgtZ2s6ZAiUgSVdmaXBTHs/fKl9Gha4UtLZb8x4zaaNtbDwQDaMzNWYlVSQbnbuNKuK+N9zQy0gvJfuhgBqVpoulYlpZEd/S6tsuwsNj2kYRsFntojqj9rJouam//LbW8YZ58RffcHyKsaMq39L/xj4z20OX4LOfVLlplTKmaAoYfCPnFqpl4CRowZ9+cHOJq13f7RM9EjGyXSwjP4l1BhZiiuevyb7dy0ds34jAbNWb62OwAf6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z+pnBH/811Jtj/R+PPmmdNU5aPx6LRisobZ5KRyWxns=; b=LkJWxXecf6pf5qd/XQGeRzuzRKQM/Zi75pXQB8cTjNU3B+XjNNOd25x5vwZXwJ4P1DbwmX3pRuPTLoKKOXgoskNLF7mAg4XmRV5Cuci8Zw1Dhx/OWaDI1ziyEeo6kWuiWX5gZzeoOIZDZuJi7SJJLqn66m5jcjjYGc9gHSif/y2c8QTERNh2nWpLpfjylGCry9t7QypMiakAXc2MF3+JJCFHTXRsvXLcP4o8gBrQVctyNFNX/m7E17nug41kBNHts3wPHz9MRiMOsbpoGyB5FCTImmaYQprAP+X8+de1b1PGaa61pJSI6w6m+qnOvVUmW97M31K4OlVmRzBCwHTvzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z+pnBH/811Jtj/R+PPmmdNU5aPx6LRisobZ5KRyWxns=; b=E9hn+kLhw6uQUo9IYpvDEgPhCf4xgcUMptzlFtSJ3pv777BOWW8eqbhImuNr8bsa9yI/HzQvtOL5ZFFvgkZWDXNIjv8Ybf4IZFBXVTU68ZGBHocQ/elfJ5PjbkHvJ4Zn5bxRFIl0yQBX2B4tBl5IXx/y8062/ic7rAPc1+T1AoU= Received: from SA9PR13CA0132.namprd13.prod.outlook.com (2603:10b6:806:27::17) by DS7PR12MB5838.namprd12.prod.outlook.com (2603:10b6:8:79::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22; Thu, 30 Apr 2026 23:26:05 +0000 Received: from SA2PEPF00001507.namprd04.prod.outlook.com (2603:10b6:806:27:cafe::ea) by SA9PR13CA0132.outlook.office365.com (2603:10b6:806:27::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.26 via Frontend Transport; Thu, 30 Apr 2026 23:26:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001507.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Thu, 30 Apr 2026 23:26:05 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:03 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 06/12] fs/resctrl: Initialize the global kernel-mode policy at subsystem init Date: Thu, 30 Apr 2026 18:24:51 -0500 Message-ID: <38f794ae4076a3c118e8eda08ae2bc1e69eba979.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001507:EE_|DS7PR12MB5838:EE_ X-MS-Office365-Filtering-Correlation-Id: 13e5f4da-dc43-489e-e1d0-08dea70fd9c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700016|7416014|13003099007|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: F47fDy7PisbrfCySsAScQNttUdGPaZM0ePYb3KGXnsT03x+VWdoabz84CkPvF3ia5Bt/23v/3yZj/p3HZeJ+598nD3YIGsxEJv7bzKVu8uMebbDI84ke7UFc+i/guzIYwKSgD5k81X0waASUjjuklHJr4Lzsuq8aTffuoastYfxWHZprf3IlTZGsHIom6URgBe1Hze4UPpdnRvpafOOZ4mPJxVzud8OFLEFF/GDP1v4undONellM028/LKTxxnzW3R5YLZ6bM0wJUz9ZkL719rPeTS1jQ2rkixvDunsg1tW5IoECKTIVkS6qVyswrqz/nqgnatjinhlHXEQdXuVbUxrr1KiSxLQUJ24HLyuprGVtudaC2Esp8rBb/vr5Pbfb8k7w/PyjvALW/tsFxyOHkNWDcr1t2SBHiWVLc8dbbExa5LniUZUXhOmJEQc4RqIp4oTuZEqFOs5V45M0rQFpGe2eBdAvUecHkrrSkRqaBJzg8+yqmeI0PO39T08/YfRXcyEm+OutRvpwH3uAnuG/IKO2LNfe6gthvRnjLONZZU3bFjfcGL5LL1h4FTleEHfGmwWoN61vkBB5VWDAneXfBbEZhHP2EamJGtUS7qMsMHx7rBbVb1/1SANWvBLq7sObeA95Px4jf9NxGRQfm1D/l3FaRftqRdwMSiFCfm8JYbrx25E1afMrSi3IMvVJKfH8 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(36860700016)(7416014)(13003099007)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /nMU4s4yBsCh1xBOX/traM8WWLmkjqLezmGhJQinLjQVIgN0DUXrfBOUA+jCzLVxq8YqpGm2YQ2rSgN9rm0g2FAJ7TNpHbLRkNICMfsE4m/6+HGr+P+6UCWtc1M6TSwwsO+cVEdxp1KMl0+dv+ZIksGgMWB/galt+V9g1VcPpnQ9i6D5LjdGkt09EQWxX/k9oxqaarXPoeI7Lhze0iLTVPSq+OSYlfLjLcO/SzMe50wDWQr6B3D0zS4fUmM6E/m0LqkTl6Cl2/CosfiCnL/hxBxmF8tPcwE5oylD+X4OyXIZINPPeLBPgKgN7117TlKRQSHc/FKr0laHVql3CiNZBgIU3Jan6LDdEdkl6sidjvDx0XjDx+3V04KLZ60Uf7beLH48Jjivue3K0RtLg3cGAIr/SzDj4zNw/niIc9YxSqn7sCswi0NcoIjk7TH6aYR6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:05.2445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13e5f4da-dc43-489e-e1d0-08dea70fd9c4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001507.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5838 Content-Type: text/plain; charset="utf-8" kernel_mode feature needs to add the interface that lets user space choose between INHERIT_CTRL_AND_MON, GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU and GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU. Both the generic resctrl code and the architecture layer need a single shared snapshot of the supported and effective policy plus the resource group that backs the global-assign modes; that snapshot is struct resctrl_kmode_cfg. Add the file-local resctrl_kcfg and a helper resctrl_kmode_init() that: - Adds kmode and kmode_cur with BIT(INHERIT_CTRL_AND_MON), the universally supported mode and today's behaviour; - points k_rdtgrp at rdtgroup_default so global-assign modes have a valid backing group from boot; - calls resctrl_arch_get_kmode_support() so each architecture ORs BIT() into kmode for the policies its hardware supports (on x86, AMD PLZA contributes the two global-assign modes). resctrl_kmode_init() runs from resctrl_init() once the default group has been set up. No user-visible behaviour changes yet; later patches expose kmode_cur via sysfs and act on changes. Signed-off-by: Babu Moger --- v3: Moved all the changes to resctrl FS. Updated changelog. Arch code only provides supported modes and FS decides which mode to be supported. v2: New patch to handle PLZA interfaces with /sys/fs/resctrl/info/ director= y. https://lore.kernel.org/lkml/2ab556af-095b-422b-9396-f845c6fd0342@intel= .com/ --- fs/resctrl/rdtgroup.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5dfdaa6f9d8f..a7bfc74897cc 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -76,6 +76,13 @@ static void rdtgroup_destroy_root(void); =20 struct dentry *debugfs_resctrl; =20 +/* + * Global kernel-mode resctrl policy: hardware-supported and effective mod= es + * (see struct resctrl_kmode_cfg) and the rdtgroup backing global-assign m= odes. + * Initialized from resctrl_kmode_init() during resctrl_init(). + */ +static struct resctrl_kmode_cfg resctrl_kcfg; + /* * Memory bandwidth monitoring event to use for the default CTRL_MON group * and each new CTRL_MON group created by the user. Only relevant when @@ -2206,6 +2213,23 @@ static void io_alloc_init(void) } } =20 +/* + * Baseline the global kernel-mode resctrl configuration at boot. + * + * Initialise both the supported (kmode) and effective (kmode_cur) policy + * with BIT(INHERIT_CTRL_AND_MON), point k_rdtgrp at the default resource + * group, and let the arch hook OR in any additional modes the platform + * advertises (e.g. on x86, AMD PLZA adds the two global-assign modes). + */ +static void resctrl_kmode_init(void) +{ + resctrl_kcfg.kmode =3D BIT(INHERIT_CTRL_AND_MON); + resctrl_kcfg.kmode_cur =3D BIT(INHERIT_CTRL_AND_MON); + resctrl_kcfg.k_rdtgrp =3D &rdtgroup_default; + + resctrl_arch_get_kmode_support(&resctrl_kcfg); +} + void resctrl_file_fflags_init(const char *config, unsigned long fflags) { struct rftype *rft; @@ -4560,6 +4584,8 @@ int resctrl_init(void) =20 io_alloc_init(); =20 + resctrl_kmode_init(); + ret =3D resctrl_l3_mon_resource_init(); if (ret) return ret; --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013058.outbound.protection.outlook.com [40.93.201.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B2F63C9ED0; Thu, 30 Apr 2026 23:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591580; cv=fail; b=XVTANDvO7IfsMuyrT+8You2vY1HpMY9m+SsVDouGO3YjcJ2JpAA6VgzXES9YlmQS6IFOucO2eCXAooi2q2lYKTRWgabne/Bes2OVXnQofYR9P/iCmWagGMty+4hHwiNWBQBEOaXPQXqkAdsouNrogUBYLQx6VD0NhakWVyVpfkI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591580; c=relaxed/simple; bh=bSoUgZ098PNxTQofRZp6F1LQnAKWrK+fuCqJp3SCRZ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fGgODaNHA7uY4GBpbsH8kaD4rhSL+AiXqiSOdVawdY/+UN/FaTe9HKsRaVIdPmlSanTny5HI9DjkocgOUCO9lySK4rVRb953N+ICAAV1caaae9qJTzKDTRu4/7twVdcIevVykHlfi2HiDorpj/OGPkOevx0GNanOdhn3QbxB2LQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=mUgFVv8D; arc=fail smtp.client-ip=40.93.201.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="mUgFVv8D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RywbYPhbmRRDlgNgg/gC8l1Q7oH1Oc0aGJbG780PfACUN/EqPolrwSZOmTrTX39YJMmFZExmoZKIKkC2jei4hMH1lbfFu5e738wxFu3zLunXIRErcUjWp0Lw32MzPfAJfc/gicIGkVW2aZk2RYOMMoAHYt4huWWaZDUZhJzIzaBMYPpRxPdXXh4zyOaGRWYv7dpwTgNDVkSRk4N131dDgq09hiQcy/HIs/H5gnt3uSBhm564VeZFIMcd4xdUavfPSQfmiXsg6S3V0bPWyxSM+RDSdDwOpj56zNmxxro9O6d03DlrY1d0Da7aFOlr/YNZWDOC/FkiDpq8F319GHst9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AVGMM5t4fS15YuQmxzd267AwJX0SSYcKCeBPlcpUmto=; b=nB5KaQktIPrRS74kXyEQ5ZE5RpzdxCNzR/soyMnye1DgJOdzFsFRA+fMvRZbzm83uSZw6+ri/CQ305Tg+gKcnP5feg4Ae7f6FHZDOH3hp/8iHnRvYdel99zdT5XRoq4vpJzjZVhl8UOOT8fYopFBnGsUeuF2YUqrxEv4rn4qWa0zTXIV9V17JnWuC2P7FhZKmo9PwQXHXTPad5aridgP1cba/etb/KapLOPXj56hNxQB0uh00KUw3gGJ+CQI10pduQPAJ8I6kIRoemEUM73XNOgqXAXd8rNDOEflAk4ZNrDMkn3tRel/GA8NkI+T5crslt727iwWTZTVKCKoBtwbEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AVGMM5t4fS15YuQmxzd267AwJX0SSYcKCeBPlcpUmto=; b=mUgFVv8DEGK+fgOyFxojhDAi/BIQHVh8w3DBLE95dP2yNSRcS3YCbBAftyQkoqY09SE1SwU2zODj8lHfo6cu0EuDn3vTyHXLoHW46h0Eex+r9piX9XDNm/UbgwHeS1DPPdOHoL2n3Dw/R8iSq6mb85CpnwH0vVWTZoxIGG/qUVM= Received: from SA0PR11CA0124.namprd11.prod.outlook.com (2603:10b6:806:131::9) by BY5PR12MB4050.namprd12.prod.outlook.com (2603:10b6:a03:207::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 23:26:13 +0000 Received: from SA2PEPF00001508.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::f8) by SA0PR11CA0124.outlook.office365.com (2603:10b6:806:131::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.31 via Frontend Transport; Thu, 30 Apr 2026 23:26:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001508.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:13 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:11 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 07/12] fs/resctrl: Add info/kernel_mode for kernel-mode policy introspection Date: Thu, 30 Apr 2026 18:24:52 -0500 Message-ID: <549bf0fadf1cedb5938599be58e53b7464c939b5.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001508:EE_|BY5PR12MB4050:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c2eec4c-fb5b-4e34-c239-08dea70fde83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|7416014|376014|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: hQizE9VEcD4mvmIolPQ3qofwUGvlAwT/7JWYtNGbwaBmc5401Z/ERKXpR3CbKruuenbzBF87sMcbSj0sWrM/fF8MfTvmaFvavjXb3xqpkxCLDvqXiOFBydYwpYZkeNdyckoPw5CbPNs5xfnMoym8w78cucwaoRVlxp/sDxe+OdA+LWygKEKMMQ0OQs0yjEk5zgUuKQJvPiKA/nu4WnwM3Aiwl2dkVc5TczENU9+SMKVlAwsJjkDJDyGX78Vb8T34FbI9ptccrw4MkuebXkqTqZ4sM3k33+N2D6cBAIaA1a68Zt3tl/DX9KtfGdk4g9t0F70QNg5Ix8TukYicuds+qWzzDteA+igybjYBLcRP61x0ysDwemj2hfGwCV8qAw4oxWiRT+DvQvtZ+9JC9y4aVd1BkpMoiSJYfEGjCnDTCiT1aNoSpKl7bn1/q1oDjVmvAN/a3ZurtjXCSSPN9AGVqklG3pnjlgxMasLPq1PyRQefOGy1PklilP4kvpO0Yn1gX7bSIYPh7CFujJ/t4yjKsDeMtcxsKtbVUNe7IGaOVzbdLZz1UoF1z5jldeMMmMm2FA4rJTKK82oE2ivBUKzvFvmmwuHCFZ5hYt8appCnz1vEmSnplvgkC8VcRdHSZQGjWq5pCs+DTCXhdc8eG04IqUwFd/Wgcu7831//mQQta7QZV10ewe5jFRTUiFk5KjNUHPtno6d9T1iut+dsuGzdid9w4KXF97szgjA6yL6Ac1c= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700016)(7416014)(376014)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 37UNPuGp53pGXh/sQtc9QCAfbmM2MH0cRz78sScKlYAFKRZAC2a1AFKoRg0f9z65x69p4umBwPw+CnioYcQC5eEW+nF8vPNsZIhsnWAbpiNhRZdL9WGM0aP623N81Hi7Lc1DQCKJrYem9f99kheGPqqbEQVvZ1IhVzJxB4f8tTYYFB9NxN3PvY4I1ZZld6HJm0PRgBhY1yXaycdGLNM8jZxc/ZR3A14ioeVTRiX8tQgeN/mwqvneKiPL7kZVXGj/MQdIb5nLuUSR7g0y+sDg/EC606SsEI4HHCGU8yBsBPVsmRU1T4GOHQDM0qn9yPVMV0c+NfdTZ7k4sIZKOjFlk5IkGiA2sdfitOlhcpst1UW90oG5QPGvPnNocGK20IOeioJLGTZJNhGwrd9K19OJWZTg6R8g18a7V/FnG1dVF59tn5vpXnIKsBgA/AN1UNYP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:13.2052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c2eec4c-fb5b-4e34-c239-08dea70fde83 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001508.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4050 Content-Type: text/plain; charset="utf-8" There is no user-visible way today to see which kernel-mode CLOSID/RMID policies the running kernel supports, which one is active, or which resctrl group currently owns the kernel CLOSID/RMID. Add a read-only top-level sysfs file, info/kernel_mode. It emits one line per mode advertised in resctrl_kcfg.kmode, in stable lowercase spelling derived from enum resctrl_kernel_modes, e.g.: [inherit_ctrl_and_mon:group=3D//] global_assign_ctrl_inherit_mon_per_cpu:group=3Dnone global_assign_ctrl_assign_mon_per_cpu:group=3Dnone The effective policy (resctrl_kcfg.kmode_cur) is wrapped in square brackets and its :group=3D suffix names the resctrl group currently bound to the kernel CLOSID/RMID (resctrl_kcfg.k_rdtgrp), formatted as // with empty components left blank. Inactive modes are reported as :group=3Dnone. rdtgroup_mutex is held while printing, matching other info/ show paths. Signed-off-by: Babu Moger --- v3: New patch to handle the changed interface file info/kernel_mode. Changed the group name to "none" if kmode binding is not done. Reinette suggested "uninitialized". "none" seemed more relevent. --- fs/resctrl/rdtgroup.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index a7bfc74897cc..9cdcfa64c4a2 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -988,6 +988,73 @@ static int rdt_last_cmd_status_show(struct kernfs_open= _file *of, return 0; } =20 +/* Sysfs lines for info/kernel_mode; indexed by &enum resctrl_kernel_modes= */ +static const char * const resctrl_mode_str[] =3D { + [INHERIT_CTRL_AND_MON] =3D "inherit_ctrl_and_mon", + [GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU] =3D "global_assign_ctrl_inherit_= mon_per_cpu", + [GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU] =3D "global_assign_ctrl_assign_mo= n_per_cpu", +}; + +static_assert(ARRAY_SIZE(resctrl_mode_str) =3D=3D RESCTRL_NUM_KERNEL_MODES= ); + +/** + * resctrl_kernel_mode_show() - Enumerate supported and effective kernel-m= ode policies + * @of: kernfs open file + * @seq: output seq_file + * @v: unused + * + * Emits one line per mode advertised in resctrl_kcfg.kmode (each mode is = one + * BIT(index) per &enum resctrl_kernel_modes). Every line carries a + * ":group=3D" suffix: + * + * - The effective policy (whose BIT matches resctrl_kcfg.kmode_cur) is + * wrapped in square brackets and is the resctrl group that + * currently owns the kernel CLOSID/RMID (resctrl_kcfg.k_rdtgrp), + * formatted as "//". A component is left empty when it + * does not apply: an RDTCTRL_GROUP emits "//", an RDTMON_GROUP + * under the default control group emits "//", and an RDTMON_GROUP + * under a named control group emits "//". + * + * - Other supported but inactive modes are emitted without brackets and + * is reported as "none". + * + * Context: Called under rdtgroup_mutex like other resctrl sysfs show path= s. + */ +static int resctrl_kernel_mode_show(struct kernfs_open_file *of, + struct seq_file *seq, void *v) +{ + struct rdtgroup *rdtgrp; + const char *ctrl, *mon; + int i; + + mutex_lock(&rdtgroup_mutex); + for (i =3D 0; i < RESCTRL_NUM_KERNEL_MODES; i++) { + if (!(resctrl_kcfg.kmode & BIT(i))) + continue; + + if (resctrl_kcfg.kmode_cur !=3D BIT(i)) { + seq_printf(seq, "%s:group=3Dnone\n", + resctrl_mode_str[i]); + continue; + } + + rdtgrp =3D resctrl_kcfg.k_rdtgrp; + ctrl =3D ""; + mon =3D ""; + if (rdtgrp->type =3D=3D RDTMON_GROUP) { + if (rdtgrp->mon.parent !=3D &rdtgroup_default) + ctrl =3D rdtgrp->mon.parent->kn->name; + mon =3D rdtgrp->kn->name; + } else { + ctrl =3D rdtgrp->kn->name; + } + seq_printf(seq, "[%s:group=3D%s/%s/]\n", + resctrl_mode_str[i], ctrl, mon); + } + mutex_unlock(&rdtgroup_mutex); + return 0; +} + void *rdt_kn_parent_priv(struct kernfs_node *kn) { /* @@ -1891,6 +1958,13 @@ static struct rftype res_common_files[] =3D { .seq_show =3D rdt_last_cmd_status_show, .fflags =3D RFTYPE_TOP_INFO, }, + { + .name =3D "kernel_mode", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D resctrl_kernel_mode_show, + .fflags =3D RFTYPE_TOP_INFO, + }, { .name =3D "mbm_assign_on_mkdir", .mode =3D 0644, --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012060.outbound.protection.outlook.com [40.93.195.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 562B13C552B; Thu, 30 Apr 2026 23:26:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591591; cv=fail; b=TSUS598tY379kauQDrVTL2Ta+RbiN7QPmdOFNFkbrzRKiUSA2M0T3hiHgXZ/OJr5eNHphdnsXUuafD4QOaSUR+KWvdvHKKfPTDw1OveheESwbpJ6ShwU58OsBZQi+mbao2q1EUkTHkH4QhcKAForVK/mwBFvhPlo9/TXvGBNmbQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591591; c=relaxed/simple; bh=k5KjxTZnM5kjAkqw51MLazrBGp4RofSaP1WJOMKPJd4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W/cCl2dJKhnQQ9nB8Mv0T85fyAu0VS43PgHmwKfIbEh/cXsvM3Puk4fObR5LIuZGnmZxreyhreTkv1duly2bAnjb/xFflqMpyFxBCMjfupirtsQNveqlyIY4QFFr6FgSKeqTtXzfqjCvZod6efFNyltOU2f1IXNQslwBd89chr8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=xHSWsFvs; arc=fail smtp.client-ip=40.93.195.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="xHSWsFvs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FqezkgiYua3FqFZtWCOVoDNM+hHGpAwNH1sQBYRPo7rSNj7RMbvlfHERHpuAconJkVMuz9eh+cIqO8qUE41G3neNN8YVIl3cBwSrNM2DuniA7I1X7WcWDOQnzSNuemqdgyA+Rm/55d/AVG9UMGEFo1xL/FQEUVpGEdqC0AkCs/0Ckx5ceGWBWPUmLALWRMdtSVE4A2umejCT2XTnhu/ciuwnPIcq7kAlmKilKUMZTj2bvP3CAayIDrcQ9YNOgwz+6oeZuK7/1RLnr4bkNflATFZnFY259GVpzw6vbeZ7A+ubMGh6zIMYi+4w2gAlf8f6bVHk+JnNBwtQ9E6ucLAbrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GCc7eVPivfhPvvviLvPaGT/T1TXDJFOlq2BfjKE3WjY=; b=yc6zOmJ1yrB8kzHsLzAjeZWm+fN5zIv5fltb++w3WOl6RlB0NB+7+iiVhRWOuI1iQC8GAi+lngmmGcMrTkl3gr18NHWUDa+smiq6lbUSeiW5QwbuDMo7pvZBLwgn5+gxgJ9JNbx7gU/WQqZBxl32VOiejbzaQFXNL5FVFRNia/bhBpUQWuCLfsM5l4wWws4NLRe07Hbm54UDv1Eau9+ovYt5/1+IJkxfpHteYJx5823ZUH9AGkth5D6Jnv8491AtrpKfPsrhYHXQRR+zlTNCs8oqeoyPfjr0Gaz/mH2VBOUVSNQAB7MM+Xf4nuefPscYMGpUs1TPQdbIfscCTg7oSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GCc7eVPivfhPvvviLvPaGT/T1TXDJFOlq2BfjKE3WjY=; b=xHSWsFvsxev8k+4JimUHtW0KC9i7Ur/emNqFTHMAFyyHTml+FPB7X4LqNnnKW3lsLrsLd+7CTBu2XD8Hw9z8uJkzGlRS3IDjZ1jKVHrzkjSdOneboPOhsIS7oPazgUOCT6m5cvdXHb943ZmbkJSuSWfwRtYZcFNhng1EHv3htLM= Received: from PH8PR15CA0024.namprd15.prod.outlook.com (2603:10b6:510:2d2::9) by MN0PR12MB6174.namprd12.prod.outlook.com (2603:10b6:208:3c5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.21; Thu, 30 Apr 2026 23:26:22 +0000 Received: from SA2PEPF00001505.namprd04.prod.outlook.com (2603:10b6:510:2d2:cafe::e6) by PH8PR15CA0024.outlook.office365.com (2603:10b6:510:2d2::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Thu, 30 Apr 2026 23:26:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001505.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:21 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:19 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 08/12] fs/resctrl: Make info/kernel_mode writable and identify the bound group Date: Thu, 30 Apr 2026 18:24:53 -0500 Message-ID: <768d4b603542f3202ece4294c808dbbf1a8e3008.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001505:EE_|MN0PR12MB6174:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b1c802d-e5c3-4bb5-1427-08dea70fe34f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700016|1800799024|18002099003|56012099003|22082099003|8126099003; X-Microsoft-Antispam-Message-Info: gPMxUA9Yqfs1cgFTpbL9kBuSNGledmhc1wDNixg6To167Y8s8SsjmAC+lfDkujXateeIoOpnGn0tzv5/WwQrk/JHf0liBOB5vvxyr7iLTFIVdercCpgT0mzHurDKGlOv5GrB9N/L7KMqipDMXxahFRHZfti+swt/RG3wFhJ2q4QEjLxLHXE88Pui9fpU8cGJaQ2JJIAB/iznGXEh+bGRZAX+mtgHPDuYUkyzikANGCa71rcdUiI1YHMuZsg2BeuGJn+y35EYVWuDV1DJRJPAwLiSqPnuHiaM+62/Rahu3bjnnJl8GVsTiuc+WeBObYi/WskIMRzxqwTYpczt3KB7KnbcH23VuJltQdBoRQmPhDZW9PP8/+CtZQXAax1lxcjAR20roY9Bv721C2eEQiTxU3Bx/IkYQ9WI0cG27TJR8oJxFaM21GRD3uDh3e0hoEWC25WvL5al0jVA+yAxNIwf4I7Y2szE7snUBndkrt7Nk/Ml9Xh4dRsH4koQ6H7vciTK1FHe6kJwFV+h8LyTpylOZqdrCpO4Q/oNtpyOKplthcIyqVMhAwtgrxozRghXhqdkqD74ZfhAw5B8BFcnVZrj2VAexLr9RpQ9SUbmWt0EqnDUZeIA4w0TsmP2N6Xc/DmnCM3tlOdPYGWaEOYDCFksbp9YathrV9kDxsuyT9Ln2eAePX6m2Zza2HtNHaehr5RAW4wuzMUodueZVANTD16lGGKN9tf76S3VQzRJWH+ODeQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700016)(1800799024)(18002099003)(56012099003)(22082099003)(8126099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3KvbCy5JrYByQgcuUpI5Ar2g6eS8kNTPgDb9WgpElRGq1x0a8pxaLHWKF87it0afIAfNfbVfeapXS5D0W8qq3AY1xFW/txdLVzWAIBA5FV1OfP0M4ISwojnmX2CZ0NksgjC46IBp7RN2voRbrLF1krvZ/fI6m914bpsPjs92W5MakVIPTW7PWAGULPxcFoAKib++zOz+IaVVi0rTos/9ag6tttYIb8t2QtSnHlGQ9yPdSjD4kqBlnsxbHdMS3Mp/5ehkOpEmrO7ReQ8RpjusJdjH7C/1BE74iDNCVfFMYJv1z/2b1vxf6l85HDEAmDGlpw2LmJMu5030pSQEACABzL0U2RgJV8FvNbB3+F5YNi2+UGB3Fmf7C9oi8juqpA1X5c90TeLlnU9oGzmmiF+NGf6988m+OkyxzMM4FI/koeFLDU6MjP7nMLii5K/lol/5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:21.2509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b1c802d-e5c3-4bb5-1427-08dea70fe34f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001505.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6174 Content-Type: text/plain; charset="utf-8" info/kernel_mode lists the kernel-mode CLOSID/RMID policies the kernel supports and the one currently active, but user space has no way to switch policies or rebind to a different rdtgroup, and the file does not name the group that owns the kernel CLOSID/RMID. Make info/kernel_mode writable. The format used by both read and write is one line per mode: inherit_ctrl_and_mon:group=3Dnone [global_assign_ctrl_inherit_mon_per_cpu:group=3Dg1//] global_assign_ctrl_assign_mon_per_cpu:group=3Dnone The active mode is wrapped in "[...]" and ":group=3D//" names the bound rdtgroup ("//" for the default control group). Inactive modes report ":group=3Dnone". Documented in Documentation/filesystems/resctrl.rst. The write path strims input, strips the optional "[...]", validates the mode against resctrl_kcfg.kmode, and resolves the optional ":group=3D" suffix via the new helper rdtgroup_by_kmode_path(). An omitted suffix or an INHERIT-mode write binds to the default group. On success, rdtgroup_config_kmode_clear() tears down the previous binding and rdtgroup_config_kmode() programs the new one before resctrl_kcfg.k_rdtgrp and resctrl_kcfg.kmode_cur are updated under rdtgroup_mutex. Allocation failures in the helpers are propagated so the write fails atomically. Add struct rdtgroup fields kmode and kmode_cpu_mask to track the per-group binding. Signed-off-by: Babu Moger --- v3: New patch to handle the changed interface file info/kernel_mode. --- Documentation/filesystems/resctrl.rst | 51 ++++ fs/resctrl/internal.h | 6 + fs/resctrl/rdtgroup.c | 375 +++++++++++++++++++++++++- 3 files changed, 431 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index b003bed339fd..89fbf8b4fb2a 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -522,6 +522,57 @@ conveyed in the error returns from file operations. E.= g. # cat info/last_cmd_status mask f7 has non-consecutive 1-bits =20 +"kernel_mode": + In the top level of the "info" directory, "kernel_mode" controls how + resource allocation and monitoring work in kernel mode. This is used on + some platforms to assign a dedicated CLOSID and/or RMID to kernel threads. + + Reading the file lists supported kernel modes, one per line. Each line + carries a ":group=3D" suffix that identifies the resctrl group that + owns the kernel CLOSID/RMID for that mode. The currently active mode is + wrapped in square brackets and reports the bound group as + "//", with empty components when they do not apply (a control + group emits "//", a monitor group under the default control group + emits "//"). Other supported modes are shown without brackets and + report "none" because no group is bound to them. Example:: + + # cat info/kernel_mode + [inherit_ctrl_and_mon:group=3D//] + global_assign_ctrl_inherit_mon_per_cpu:group=3Dnone + global_assign_ctrl_assign_mon_per_cpu:group=3Dnone + + Writing one line (terminated by a newline) selects the active mode and + binds it to a resctrl group. The line uses the same format that the + read path emits, "[:group=3D//]", and a surrounding + "[...]" pair (as printed for the active line) is accepted and stripped. + The ":group=3D" suffix is optional; when omitted the default group + is used. The mode must match one of the supported names exactly, + and modes not advertised by the platform cannot be set. The display-only + "group=3Dnone" form is rejected. Errors are reported in + "info/last_cmd_status". Example:: + + # echo "global_assign_ctrl_assign_mon_per_cpu:group=3Dctrl/mon1/" \ + > info/kernel_mode + # cat info/kernel_mode + inherit_ctrl_and_mon:group=3Dnone + global_assign_ctrl_inherit_mon_per_cpu:group=3Dnone + [global_assign_ctrl_assign_mon_per_cpu:group=3Dctrl1/mon1/] + + # echo "inherit_ctrl_and_mon" > info/kernel_mode + # cat info/kernel_mode + [inherit_ctrl_and_mon:group=3D//] + global_assign_ctrl_inherit_mon_per_cpu:group=3Dnone + global_assign_ctrl_assign_mon_per_cpu:group=3Dnone + + Modes: + + - "inherit_ctrl_and_mon": Kernel uses the same CLOSID and RMID as the + current user-space task (default). + - "global_assign_ctrl_inherit_mon_per_cpu": One CLOSID is assigned for all + kernel work; RMID is still inherited from user space. + - "global_assign_ctrl_assign_mon_per_cpu": One resource group (CLOSID and= RMID) + is assigned for all kernel work. + Resource alloc and monitor groups =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h index 1a9b29119f88..9435ce663f54 100644 --- a/fs/resctrl/internal.h +++ b/fs/resctrl/internal.h @@ -216,6 +216,10 @@ struct mongroup { * @mon: mongroup related data * @mode: mode of resource group * @mba_mbps_event: input monitoring event id when mba_sc is enabled + * @kmode: true if this group is currently bound as the kernel-mode + * CLOSID/RMID owner (resctrl_kcfg.k_rdtgrp) + * @kmode_cpu_mask: CPUs scoped for this group's kernel-mode binding; + * when empty, all online CPUs are used * @plr: pseudo-locked region */ struct rdtgroup { @@ -229,6 +233,8 @@ struct rdtgroup { struct mongroup mon; enum rdtgrp_mode mode; enum resctrl_event_id mba_mbps_event; + bool kmode; + struct cpumask kmode_cpu_mask; struct pseudo_lock_region *plr; }; =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 9cdcfa64c4a2..5383b4eb23ed 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1055,6 +1055,378 @@ static int resctrl_kernel_mode_show(struct kernfs_o= pen_file *of, return 0; } =20 +/** + * rdtgroup_config_kmode() - Push @rdtgrp's kernel CLOSID/RMID to hardware + * @rdtgrp: Resctrl group whose CLOSID/RMID should be programmed. + * + * Derives CLOSID/RMID from @rdtgrp->type: + * - RDTMON_GROUP: parent control group's CLOSID with the monitor group'= s RMID. + * - RDTCTRL_GROUP: the control group's own CLOSID and default RMID. + * + * Calls resctrl_arch_configure_kmode() with the kernel-mode binding enabl= ed + * on the online subset of @rdtgrp->kmode_cpu_mask (or all online CPUs when + * that mask is empty), and disabled on the complementary online CPUs so + * stale enable bits from a previously bound group are cleared in the same + * reprogram step. The caller (resctrl_kernel_mode_write()) is responsible + * for validating that the (kmode, group type) pair is permitted before + * invoking this helper. + * + * Context: Caller must hold rdtgroup_mutex. + * + * Return: 0 on success, -EINVAL for a pseudo-locked group, -ENOMEM if + * cpumask allocation fails. + */ +static int rdtgroup_config_kmode(struct rdtgroup *rdtgrp) +{ + cpumask_var_t enable_mask, disable_mask; + u32 closid, rmid; + bool need_disable; + + if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { + rdt_last_cmd_puts("Resource group is pseudo-locked\n"); + return -EINVAL; + } + + if (!zalloc_cpumask_var(&enable_mask, GFP_KERNEL)) + return -ENOMEM; + + need_disable =3D !cpumask_empty(&rdtgrp->kmode_cpu_mask); + if (need_disable && !zalloc_cpumask_var(&disable_mask, GFP_KERNEL)) { + free_cpumask_var(enable_mask); + return -ENOMEM; + } + + if (rdtgrp->type =3D=3D RDTMON_GROUP) { + closid =3D rdtgrp->mon.parent->closid; + rmid =3D rdtgrp->mon.rmid; + } else { + closid =3D rdtgrp->closid; + rmid =3D rdtgrp->mon.rmid; + } + + /* + * Empty kmode_cpu_mask: enable on every online CPU. Otherwise enable + * only CPUs in the group mask and explicitly clear on other online CPUs + * so a previously bound group's enable bits don't linger. + */ + if (!need_disable) { + cpumask_copy(enable_mask, cpu_online_mask); + } else { + cpumask_copy(enable_mask, &rdtgrp->kmode_cpu_mask); + cpumask_andnot(disable_mask, cpu_online_mask, &rdtgrp->kmode_cpu_mask); + } + + if (!cpumask_empty(enable_mask)) + resctrl_arch_configure_kmode(enable_mask, closid, rmid, true); + + if (need_disable && !cpumask_empty(disable_mask)) + resctrl_arch_configure_kmode(disable_mask, closid, rmid, false); + + rdtgrp->kmode =3D true; + + free_cpumask_var(enable_mask); + if (need_disable) + free_cpumask_var(disable_mask); + + return 0; +} + +/** + * rdtgroup_config_kmode_clear() - Tear down the kernel-mode binding on @r= dtgrp + * @rdtgrp: Resctrl group whose kernel-mode binding is being released. + * May be %NULL when no group is currently bound, in which case + * this is a no-op. + * @kmode: Kernel-mode policy currently active on @rdtgrp, as a + * BIT(&enum resctrl_kernel_modes) value. When this is + * BIT(INHERIT_CTRL_AND_MON) the hardware tear-down is skipped + * because no MSR was previously programmed. + * + * Disables the kernel-mode binding on the CPUs @rdtgrp covers (its + * @kmode_cpu_mask, or all online CPUs when that mask is empty) and resets + * the per-group bookkeeping (@kmode and @kmode_cpu_mask). This is the + * disable counterpart of rdtgroup_config_kmode() and exists so that a wri= te + * that transitions the active mode to BIT(INHERIT_CTRL_AND_MON) -- which + * skips rdtgroup_config_kmode() entirely -- still tears down the previous= ly + * bound group instead of leaving stale enable bits behind. + * + * On allocation failure the function returns -ENOMEM and leaves both the + * hardware state and @rdtgrp's bookkeeping unchanged so the caller can fa= il + * the operation atomically and last_cmd_status reflects reality. + * + * Context: Caller must hold rdtgroup_mutex. + * + * Return: 0 on success (including the @rdtgrp =3D=3D %NULL and INHERIT ca= ses), + * -ENOMEM if cpumask allocation fails. + */ +static int rdtgroup_config_kmode_clear(struct rdtgroup *rdtgrp, int kmode) +{ + cpumask_var_t disable_mask; + u32 closid, rmid; + + if (!rdtgrp) + return 0; + + if (kmode =3D=3D BIT(INHERIT_CTRL_AND_MON)) + goto out_clear; + + if (!zalloc_cpumask_var(&disable_mask, GFP_KERNEL)) + return -ENOMEM; + + if (rdtgrp->type =3D=3D RDTMON_GROUP) { + closid =3D rdtgrp->mon.parent->closid; + rmid =3D rdtgrp->mon.rmid; + } else { + closid =3D rdtgrp->closid; + rmid =3D rdtgrp->mon.rmid; + } + + if (cpumask_empty(&rdtgrp->kmode_cpu_mask)) + cpumask_copy(disable_mask, cpu_online_mask); + else + cpumask_copy(disable_mask, &rdtgrp->kmode_cpu_mask); + + resctrl_arch_configure_kmode(disable_mask, closid, rmid, false); + free_cpumask_var(disable_mask); + +out_clear: + cpumask_clear(&rdtgrp->kmode_cpu_mask); + rdtgrp->kmode =3D false; + return 0; +} + +/** + * rdtgroup_by_kmode_path() - Resolve a "//" path to an rdtgroup + * @ctrl_name: Control-group name, or "" for the default control group. + * @mon_name: Monitor-group name, or "" to select the control group itself. + * + * Matches the path syntax emitted by resctrl_kernel_mode_show(): + * "//" - the default control group + * "//" - control group @ctrl_name + * "//" - monitor group @mon_name under the default control g= roup + * "//" - monitor group @mon_name under control group @ctrl_n= ame + * + * Context: Caller must hold rdtgroup_mutex. + * + * Return: Pointer to the matching rdtgroup, &rdtgroup_default when both + * names are empty (the show form "//"), or NULL if no such group exists. + */ +static struct rdtgroup *rdtgroup_by_kmode_path(const char *ctrl_name, + const char *mon_name) +{ + struct rdtgroup *rdtg, *parent =3D NULL, *crg; + + /* Show emits "//" for the default control group; round-trip it here. */ + if (!*ctrl_name && !*mon_name) + return &rdtgroup_default; + + /* Control-group-only form: "//". */ + if (!*mon_name) { + list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) { + if (rdtg->type !=3D RDTCTRL_GROUP) + continue; + if (!strcmp(rdt_kn_name(rdtg->kn), ctrl_name)) + return rdtg; + } + return NULL; + } + + /* Monitor-group form: locate the parent control group first. */ + if (!*ctrl_name) { + parent =3D &rdtgroup_default; + } else { + list_for_each_entry(rdtg, &rdt_all_groups, rdtgroup_list) { + if (rdtg->type !=3D RDTCTRL_GROUP) + continue; + if (!strcmp(rdt_kn_name(rdtg->kn), ctrl_name)) { + parent =3D rdtg; + break; + } + } + if (!parent) + return NULL; + } + + list_for_each_entry(crg, &parent->mon.crdtgrp_list, mon.crdtgrp_list) + if (!strcmp(rdt_kn_name(crg->kn), mon_name)) + return crg; + return NULL; +} + +/** + * resctrl_kernel_mode_write() - Select kernel mode and bind group via inf= o/kernel_mode + * @of: kernfs file handle. + * @buf: One line in the same format emitted by resctrl_kernel_mode_show(), + * i.e. "[:group=3D//]" with an optional surrounding + * "[...]"; must end with a newline. The ":group=3D" suffix is + * optional -- when omitted the default control group + * (&rdtgroup_default) is used. + * @nbytes: Length of @buf. + * @off: File offset (unused). + * + * Parses @buf, validates that is listed in resctrl_mode_str[] and = is + * supported by the platform (resctrl_kcfg.kmode), resolves // = to + * an existing rdtgroup (or picks &rdtgroup_default if no group was specif= ied + * or if the new mode is INHERIT), clears any previous binding via + * rdtgroup_config_kmode_clear(), programs hardware via + * rdtgroup_config_kmode() when @kmode is not BIT(INHERIT_CTRL_AND_MON), a= nd + * on success updates resctrl_kcfg.k_rdtgrp and resctrl_kcfg.kmode_cur. T= he + * display-only "group=3Dnone" form produced by show for inactive modes is + * rejected. Errors are reported in last_cmd_status. + * + * Return: @nbytes on success, negative errno with last_cmd_status set on = error. + */ +static ssize_t resctrl_kernel_mode_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + char *mode_str, *group_str, *slash; + const char *ctrl_name, *mon_name; + struct rdtgroup *rdtgrp; + int ret =3D 0; + size_t len; + u32 kmode; + int i; + + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') + return -EINVAL; + buf[nbytes - 1] =3D '\0'; + + /* Tolerate surrounding whitespace before the bracket/mode parsing. */ + buf =3D strim(buf); + len =3D strlen(buf); + + /* Strip the optional "[...]" that show uses to mark the active line. */ + if (len >=3D 2 && buf[0] =3D=3D '[' && buf[len - 1] =3D=3D ']') { + buf[len - 1] =3D '\0'; + buf++; + len -=3D 2; + } + + /* + * Split ":group=3D"; the ":group=3D" suffix is optional + * and when omitted the default control group (&rdtgroup_default) is used. + */ + group_str =3D strstr(buf, ":group=3D"); + if (group_str) { + *group_str =3D '\0'; + group_str +=3D strlen(":group=3D"); + } + mode_str =3D buf; + + mutex_lock(&rdtgroup_mutex); + rdt_last_cmd_clear(); + + for (i =3D 0; i < RESCTRL_NUM_KERNEL_MODES; i++) + if (!strcmp(mode_str, resctrl_mode_str[i])) + break; + if (i =3D=3D RESCTRL_NUM_KERNEL_MODES) { + rdt_last_cmd_puts("Unknown kernel mode\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + if (!(resctrl_kcfg.kmode & BIT(i))) { + rdt_last_cmd_puts("Kernel mode not available\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + kmode =3D BIT(i); + + if (!group_str) { + /* No ":group=3D" suffix: fall back to the default control group. */ + rdtgrp =3D &rdtgroup_default; + } else if (!strcmp(group_str, "none")) { + /* Display-only placeholder emitted by show; not selectable. */ + rdt_last_cmd_puts("Cannot bind to 'none' group\n"); + ret =3D -EINVAL; + goto out_unlock; + } else { + /* Require exactly "//" - two '/' with the second terminating= . */ + slash =3D strchr(group_str, '/'); + if (!slash) { + rdt_last_cmd_puts("Group must be //\n"); + ret =3D -EINVAL; + goto out_unlock; + } + *slash =3D '\0'; + ctrl_name =3D group_str; + mon_name =3D slash + 1; + slash =3D strchr(mon_name, '/'); + if (!slash || slash[1] !=3D '\0') { + rdt_last_cmd_puts("Group must be //\n"); + ret =3D -EINVAL; + goto out_unlock; + } + *slash =3D '\0'; + + rdtgrp =3D rdtgroup_by_kmode_path(ctrl_name, mon_name); + if (!rdtgrp) { + rdt_last_cmd_puts("Group not found\n"); + ret =3D -EINVAL; + goto out_unlock; + } + } + + /* + * INHERIT mode binds nothing; force the bound group to the default so + * round-trips with show (which prints "group=3D//") are stable and any + * user-supplied :group=3D suffix is silently normalised. + */ + if (kmode =3D=3D BIT(INHERIT_CTRL_AND_MON)) + rdtgrp =3D &rdtgroup_default; + + /* No-op if the same mode is already active on the same group. */ + if (resctrl_kcfg.kmode_cur =3D=3D kmode && resctrl_kcfg.k_rdtgrp =3D=3D r= dtgrp) + goto out_unlock; + + /* + * global_assign_ctrl_assign_mon_per_cpu binds one CLOSID and RMID for + * all kernel work (Documentation/filesystems/resctrl.rst uses + * "//", i.e. an RDTMON_GROUP). + * + * global_assign_ctrl_inherit_mon_per_cpu assigns one CLOSID globally + * while leaving RMID inheritance to user contexts; that uses the + * control group's CLOSID slot only, i.e. an RDTCTRL_GROUP. + */ + if (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_ASSIGN_MON_PER_CPU) && + rdtgrp->type !=3D RDTMON_GROUP) { + rdt_last_cmd_puts("global_assign_ctrl_assign_mon_per_cpu requires a moni= tor group\n"); + ret =3D -EINVAL; + goto out_unlock; + } + if (kmode =3D=3D BIT(GLOBAL_ASSIGN_CTRL_INHERIT_MON_PER_CPU) && + rdtgrp->type !=3D RDTCTRL_GROUP) { + rdt_last_cmd_puts("global_assign_ctrl_inherit_mon_per_cpu requires a con= trol group\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + /* Switching to a different group: release the old binding first. */ + if (resctrl_kcfg.k_rdtgrp !=3D rdtgrp) { + ret =3D rdtgroup_config_kmode_clear(resctrl_kcfg.k_rdtgrp, + resctrl_kcfg.kmode_cur); + if (ret) { + rdt_last_cmd_puts("Failed to release previous kernel-mode binding\n"); + goto out_unlock; + } + } + + if (kmode !=3D BIT(INHERIT_CTRL_AND_MON)) { + ret =3D rdtgroup_config_kmode(rdtgrp); + if (ret) { + rdt_last_cmd_puts("Kernel mode change failed\n"); + goto out_unlock; + } + } + + resctrl_kcfg.k_rdtgrp =3D rdtgrp; + resctrl_kcfg.kmode_cur =3D kmode; + +out_unlock: + mutex_unlock(&rdtgroup_mutex); + return ret ?: nbytes; +} + void *rdt_kn_parent_priv(struct kernfs_node *kn) { /* @@ -1960,9 +2332,10 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "kernel_mode", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, .seq_show =3D resctrl_kernel_mode_show, + .write =3D resctrl_kernel_mode_write, .fflags =3D RFTYPE_TOP_INFO, }, { --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011003.outbound.protection.outlook.com [52.101.62.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14BDB184; Thu, 30 Apr 2026 23:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591608; cv=fail; b=pN1UZON3haxmeYewMTaGgkLOtTpx7gtS1QOLSo+xuRCLgB6OEoBMsPwiH84QEQIyni9qODG0rMncbnOC6P7o/rlsZiJ7m151RgPx9vnmTePIL8Pg+9ceddGLp6GYQ6SIt5sRUJdj7z17zmVU4cSt3nBrVfYkGb2UInhxldJcu0g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591608; c=relaxed/simple; bh=P8YJNUfWbUeesvB0AityU1i3s4fF3p9jUbd83cI1pvc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P63Xy8egZ4Mriw4BTOMy7a5EGAAvgSFk6i6BGHCRaq5k8b7zTgmEpVCe2aaEnOs8qQkDGnbazBTS6yJP8xAYljTI9W+iHXbvjHMqDzcfHv9c4Uop8jrr40tgSo0JlKPwuo6AWOj8ON2Z2GbmHQa2O3y7mvpgugtJY6oZykcaQu0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=CZVqAwu2; arc=fail smtp.client-ip=52.101.62.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="CZVqAwu2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WC0xqI+ZYLN7gvScrrwdBRjO6hDJ+MWoskoETdfLQJ4VFQ1O8tgpM7kofzvTRNmH/F/PWfO8wQxvMk55MNYY7y9MCS2Vf/7ETw7N85NVJh2CTxwwFPr5Xap7SO3tzs1dSol6j1ih/BLZ+EBIeHKZYA5JCgL1uTQ5qESgre9UqEn+HNCA5Qi/jHyRanTagyLqdOWnwn6Zi3blkAXuEezPQsbLUqfYRjhxWlOOV6PTpIXBSzzyyEczjJD39Aw/XifxYiEL3cLBKNUSD5OCfRY6gZXQy5eBOSY9B9c5930T9q3gV5iLlQ5DzeSHEItmEKGooLe8h7HsQQ7jcmejF4THvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=imulT87fMdq5YhOQlVEhwCcg+DzEpam9kdvK28pduw8=; b=M1gVSm7NtnusxjfJBGR62TIP4+Fbz24aUFMZAX+23hEv3kVPlCa7kcwpN7guaQAFzDleLjSSaMYVY07gUroNObO+YnsIv4n+TryW2BKPoD76tRtIppTNtNTNB7ekF1IBL9jhuz7AdZpFEm+dh3/GaAkJcbWx6uY8xd/jgJr4oUuISjB4oJu/7fg9AaZ1CJcCv/VVtlsGZdebue8JTDYdSu89DA0cZaxGfMkrhVkyC5tznMXpg222ocyaEGXubfyQ5z/auNK1/4F0RLGCz6CzjdRjuPzRoWaHGkb5FETPJerIVlUdUpZKdw4YS0pk6bE2xX9TLrmhpHUjn6p1ZAbK5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=imulT87fMdq5YhOQlVEhwCcg+DzEpam9kdvK28pduw8=; b=CZVqAwu2xymJAcHqupGuQbxSXMG3n559j7M8rwoPbRcbW2IGCzNFq3k9Qj3vnRes8AxlmlxTFqIPnuatB5cfENFujwyrl090yowjv+KO2sBbHFXDcbQfPFMbVfpQ6eHbrLBwuoJk630+Sm29rC+3SUA/aKVhuf7WQNAGcxU2Tzs= Received: from SA0PR11CA0147.namprd11.prod.outlook.com (2603:10b6:806:131::32) by SA3PR12MB9089.namprd12.prod.outlook.com (2603:10b6:806:39f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.20; Thu, 30 Apr 2026 23:26:38 +0000 Received: from SA2PEPF00001508.namprd04.prod.outlook.com (2603:10b6:806:131:cafe::b8) by SA0PR11CA0147.outlook.office365.com (2603:10b6:806:131::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.30 via Frontend Transport; Thu, 30 Apr 2026 23:26:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001508.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:34 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:32 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 09/12] fs/resctrl: Reset kernel-mode binding when its rdtgroup goes away Date: Thu, 30 Apr 2026 18:24:54 -0500 Message-ID: <280912ae2d2ee068fe5ec94aaf7e6e3f4e1c68b6.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001508:EE_|SA3PR12MB9089:EE_ X-MS-Office365-Filtering-Correlation-Id: b6976780-2417-46cb-9157-08dea70feb1f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|36860700016|1800799024|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: lVdz/E0/dFHNimEMzkyireW556FExWbgMVXGUErNd6BFW2mR9GvmqKUZ1C2P9zqO7usyy+MeL7irvlfaMqOOKzHWgF+DhvMMNyFkBNSd9cQdfgZaOwrageV+ezbvYXDQcZSlSs3k5CNO5fMtW/38wvcsEcUEGgfX2Du+bxW9bRLGo7XAvsiFElv+MrAekvB8VO2KTwXukoQVlvdgeh7JuDecV+zxdvk3V6Y646U5FtPpjxoLAaD3z/xO7mZWHXYiUnwaEBjpRL9MMiitkCM+Av9kSF7Jlu3LvxjPqE3oVy3E+b0ijOs/UB1Icr3DBMVtJhsCtwg7qwu7/T1UEPAs86/T57CUuBMu/A5CnwfzaswraDdKVPtld2uqYVsb0KBiHib6+GWtUsYICcGlDjNxrBEMxdeAwLro0kQ5lClccB7RZuj0vnmTGX7uCgYq/YPg8SO2Dln5h7Vt+of1cQ2I4jQigkfnRDSBArONMvuExBSTwP4TRunl86EQeDbCLe0EZG41I4u8vSgEsw3SSEB0JLx7UAnszgW6dzLgYTNfmAUzC/e7s0r180ulGeWh1oVrPaVMYktq0o9aNYmw2EaRUbimApxsXhLywcMDZK7+Dk1iDPREIejKRFs+Zerkesf2XCGZadADE5jMkGt9Apez1aDBUmHhyRseviuudF/a9w71bX0ZrdLL8rfVitTVH0dC72VORdtzV96M9VWOobH7/WWDVzItFg2ZAJNVO7abxdU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(36860700016)(1800799024)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 09GJuZODEEMwMRnIQnjXPHdrTfSvUR71iNBtNM6vTWgZHjT/ny9udG/OPwfCROGMeBoPKCG8MwEE365m391kVjKKTHtngp/6Zv3Q6vbfXz0AOWUApumq+mS6s3fjYS7Mr186Qrthzfv9w0VP5tOKQTy/eLRyhcqsS+cat/IbJIwXtu+3drq4ScYu+Le3gTa1SfnM7CfHM+7UZU0uYez5mMHpEj5SWGykX5JUoUyFNMVug8c9cG7Rtg1DgCcvFldcjvDp3iD1i9OldzHa6ZNYkCOvEI1PpvcAo9YmK1iMdS66vw4gu8KOR375qFDjA8HqsAKXaCk2wcqJUqMqe7ivHaYhbNNC1x7A4rIkBHuUoqzyTZ/YD8IWukG8P/3WMpEB/E1YlRJpIygpYuhbh0Izl9Tk7tAAh2VEn57AoCT6oc3WWJ4c0tVyNzYvPwpjutOY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:34.3603 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6976780-2417-46cb-9157-08dea70feb1f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001508.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9089 Content-Type: text/plain; charset="utf-8" resctrl_kcfg.k_rdtgrp records which rdtgroup currently owns the kernel CLOSID/RMID, but nothing cleared that snapshot when the group was removed. rmdir of a control or monitor group, or unmount of the resctrl filesystem, left kernel mode enabled on the CPUs the group covered and left k_rdtgrp pointing at freed memory; the next read or write = of info/kernel_mode would dereference a stale rdtgroup under rdtgroup_mutex. Add rdtgroup_config_kmode_delete() as the disable counterpart of rdtgroup_config_kmode(). It clears the kernel-mode binding on the group's kmode_cpu_mask (or all online CPUs when that mask is empty), drops the per-group kmode/kmode_cpu_mask bookkeeping, and if @rdtgrp was the bound, resets resctrl_kcfg to &rdtgroup_default, BIT(INHERIT_CTRL_AND_MON)) so subsequent sysfs operations resolve to a live group. Call it from rdtgroup_rmdir_mon(), rdtgroup_rmdir_ctrl(), and resctrl_fs_teardown(); each call site is gated on rdtgrp->kmode so groups that never participated in kernel mode pay nothing. Signed-off-by: Babu Moger --- v3: New patch to handle the kernel_mode clean up. --- fs/resctrl/rdtgroup.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5383b4eb23ed..faf390893109 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1194,6 +1194,40 @@ static int rdtgroup_config_kmode_clear(struct rdtgro= up *rdtgrp, int kmode) return 0; } =20 +/** + * rdtgroup_config_kmode_delete() - Drop @rdtgrp's kernel-mode binding + * @rdtgrp: Resctrl group whose kernel-mode binding is being removed (e.g. + * because the group is about to be rmdir'd or the filesystem is + * being torn down). No-op when %NULL or when @rdtgrp never + * carried a kernel-mode binding. + * + * Wraps rdtgroup_config_kmode_clear() to disable the hardware programming + * and reset the per-group bookkeeping. When @rdtgrp is the group current= ly + * bound in @resctrl_kcfg, the snapshot is also reset to + * (&rdtgroup_default, BIT(INHERIT_CTRL_AND_MON)) so subsequent show/write + * paths do not dereference @rdtgrp after the caller frees it. + * + * If the underlying tear-down fails (cpumask allocation), the snapshot is + * still reset because @rdtgrp is about to disappear; stale enable bits on + * those CPUs are reported via pr_warn() and will be cleared by the next + * non-INHERIT reprogram. + * + * Context: Caller must hold rdtgroup_mutex. + */ +static void rdtgroup_config_kmode_delete(struct rdtgroup *rdtgrp) +{ + if (!rdtgrp || !rdtgrp->kmode) + return; + + if (rdtgroup_config_kmode_clear(rdtgrp, resctrl_kcfg.kmode_cur)) + pr_warn("resctrl: kernel-mode disable failed; stale enable bits may pers= ist\n"); + + if (resctrl_kcfg.k_rdtgrp =3D=3D rdtgrp) { + resctrl_kcfg.k_rdtgrp =3D &rdtgroup_default; + resctrl_kcfg.kmode_cur =3D BIT(INHERIT_CTRL_AND_MON); + } +} + /** * rdtgroup_by_kmode_path() - Resolve a "//" path to an rdtgroup * @ctrl_name: Control-group name, or "" for the default control group. @@ -3635,6 +3669,7 @@ static void resctrl_fs_teardown(void) mon_put_kn_priv(); rdt_pseudo_lock_release(); rdtgroup_default.mode =3D RDT_MODE_SHAREABLE; + rdtgroup_config_kmode_delete(&rdtgroup_default); closid_exit(); schemata_list_destroy(); rdtgroup_destroy_root(); @@ -4432,6 +4467,8 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp= , cpumask_var_t tmpmask) u32 closid, rmid; int cpu; =20 + rdtgroup_config_kmode_delete(rdtgrp); + /* Give any tasks back to the parent group */ rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask); =20 @@ -4482,6 +4519,8 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgr= p, cpumask_var_t tmpmask) u32 closid, rmid; int cpu; =20 + rdtgroup_config_kmode_delete(rdtgrp); + /* Give any tasks back to the default group */ rdt_move_group_tasks(rdtgrp, &rdtgroup_default, tmpmask); =20 --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011068.outbound.protection.outlook.com [52.101.57.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F32D3B0AEA; Thu, 30 Apr 2026 23:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591614; cv=fail; b=uHb9LBFyHkD8N9HrPjHWCN5wW/iOARzyt4uQJtG45+sE11UjeWA+PgUN9u/1Dxn1G2fdOz6m88K1Y9GQsGQKtTWWxD+7AgJeyxP3EoKTsRbmgizrfaCoMSH80B6eznKFEnyCU8xBFxsRq5KjZPaIZ6owg+c3kLgbmZzLq4Xbif0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591614; c=relaxed/simple; bh=BQFVnqoPkeE7WYDMODWzEDt1iDV7DFCXt2P++YKo5es=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E2J16bcIu4pxT9zxBpbc+b5ClqtYg52oSd9sJhw72mixXpvMpqEXV8Wz6LQRS0qJPTxdLVqqEO3exnUhTXBJWeDty+vO2th0RE4Y2pZxQsYPHcnOy+dAu9E6ce/+AeH1fdCsMOSOFEpxCX4Kxz56LpGMHk6pPmZLwPpmNhEgVzg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=hXYxgSLX; arc=fail smtp.client-ip=52.101.57.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="hXYxgSLX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dGt3Y5b/v/XY19f3fDhQY/lX1YG6LuoU+8CFdJF7gFBxJdok1TOpYeHwB38otXCb8HZU8qSfCGXCY7/w/cvRN7m5lov6Hh5hbZe0pfzEn551y3D7PwZX0GvI6lfTtpAcnLS8OSM2knA5PXsMa+D1SpOZSfuWlkVLoN0KuhHO7dSn6UXfoH8K2GWuOUCW3w2Ty+27o8kxaAnZffouumqfmO0gvg127LJdB/z1iW9/V5N6J6auacyd8WHJGKxMF90V9mpGaZSr1ZyMZMYCrf73h0OowCMWopxVjW5SEhrRzGRhk5A9tIU6WJkgNaPBOA8ntpFzm6cMHws8YyyT4plqug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Io8Md5wsMSq9W5OHrWDmtXFjqgrzG2A4XN6yJ2P+EvI=; b=abVV42fQvWoXVTe/VZgL+BAnElbpIdusIZTFj5H8GzzuRne9At3BO4iZWOmW7vvwJT1qn0ZsWe0QAbtZPEXoBSQWOn0r2KAhW3sijNu8LRsr0/YXG5+VAVNYWAoU+74dOrh2WoLQFdbxDl4rCT26cGHk5kUtdz9QMQzEPmlGt9DeO4+m+BPZQUJRGxo4x57VH6Hc+D17uyHu9VEXrTvzqndz7Wzfsfv29SVZcbflWJoxEnMfVxW5bF7bZIVMcQemjzMrnE4x3dZ+rieIkaOmgSrWCCl1BvEjSAzv/kEgnkQ6k0Mc+hI8N0hadiDYhmtJGfdUAqbvlDxNvGw42cMeaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Io8Md5wsMSq9W5OHrWDmtXFjqgrzG2A4XN6yJ2P+EvI=; b=hXYxgSLXlQH2F5j4p+sKCPdEld+i5a7sNU50joiMzFBz0KMRV2maRHzO37w6EnjAETWwib6YFkLtX4Jmz8lYqzsw0TyiXqaClifj1VYc0SWux6yMpdQi9yPOzvr7cZjcxf+zBNr754OfQs1wXoDxg3cc4TmVGZ7PuzjsMyVqo9M= Received: from SN7PR04CA0227.namprd04.prod.outlook.com (2603:10b6:806:127::22) by CH1PPF68E8581EB.namprd12.prod.outlook.com (2603:10b6:61f:fc00::611) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9818.21; Thu, 30 Apr 2026 23:26:42 +0000 Received: from SA2PEPF0000150A.namprd04.prod.outlook.com (2603:10b6:806:127:cafe::97) by SN7PR04CA0227.outlook.office365.com (2603:10b6:806:127::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.30 via Frontend Transport; Thu, 30 Apr 2026 23:26:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF0000150A.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:42 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:40 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 10/12] fs/resctrl: Expose kmode_cpus / kmode_cpus_list per rdtgroup Date: Thu, 30 Apr 2026 18:24:55 -0500 Message-ID: <3c59e6133a05aa305075791f312340ae98343feb.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF0000150A:EE_|CH1PPF68E8581EB:EE_ X-MS-Office365-Filtering-Correlation-Id: 85661b72-a348-4116-aa6c-08dea70ff005 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|7416014|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: eJw45CCClITNU9dsGXZU6aRakYuKr3K18SeiMBrTYF2rgAAlPNXtnSoneOElNPYjaYwK2pZk3piTSx9PhAv7j+o/ZOFmN0qsLh7E4cuWsqa5UTs2x+g9ihEVRLWTAnhydhCSXj/jUMsWIPKYcf6717Tm1iBaAzSYYR3V62S1yar35a65oPTqh2UVZxPGvdouA/321e/R9OQAruLyxrMogrUSYyOXVc0oP4+7z4xDwDzWZ8+VQMLuv3ZSSgFZTCsCgV2DW4q5s4B7+tQN01J++CXdOW0+/tzEBzOuVe2QdrjDAUIsSq2lFqb178cNbh1eNJi7o5ecYslfcYFcRDoivOKgFQqxKuEk9+PQH1ng7v1IJpQUfckQcnOXL9VLL/silOwMeK1HaJ1Sgxx1wnBx5O81VLM2QLtuo4JsYpXOYAQfE+eqCYzAyvcX4QMz2eFbh87DhzBMOzLhfmCvwUl3iWBaGOSaqZOqo0gXcEsPmWZaeCU2z/meJC2K74/Vp9tdnIH38ruhX0UZqR9cxbXwfwqwZ2y5O6QHz/9uejMHSZrHhZRUzFBEih+xfcbBMPmPwmQwTZUq7sA1IYwRICj1rSOKIOcCWDVLwwacbTeWTtbe1cb27dQg0dM9BmmhBQsCgtep+uo/S9NfSK4trO8F1ezmG22vouG80tj/VUO9IL4oraFe/3uG8rr91uJnHjI6dMVpGGMU1vaA8k0UWywYA+9bXE3MdSbEFjoDE+0mgoo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700016)(376014)(7416014)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B0kk7CTwzBAfK83RRGIydECk4Y48ze3415Sd2tt+cSOOHybxUz0L9q9DnKH7k98fjA1xyH87WDWwHDqUN+1t7yO+eDkyFAw3f6hsjwoWoNXDAecr+4UtEIKXBtDTGSiIVAngS43n3bYh4Qr/0HELKwyLF+6WptmXlzymnsKcdvXQotC/NkF9nVE7EGv7fzCGQx9cUuE1P6CYmzI6lPo0JSn3QCM/Lk3YFKyAXoCD3p0/2tDYKop0k/UIqKfYDXwZ4tcMcohBNp0UtMa9UpyJZlaMcN0oLZUwLGLCmgwNPYGwmtdPClFJRmV8N9Ydfv+PpRnnh22C1I3h9p6m+hduQeST7wGMUYS8yScVY5S8Grp7uL3aHukgA6uQekvi8RHM+cDl9t9NFKbs+NN/XzsQ5k45FIpMru9WFhNCv9W4NaW9axpk4vmAEdI9+nAKeOYJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:42.5812 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 85661b72-a348-4116-aa6c-08dea70ff005 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF0000150A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH1PPF68E8581EB Content-Type: text/plain; charset="utf-8" rdtgrp->kmode_cpu_mask selects which CPUs of a group have the kernel-mode binding programmed, but the mask is not visible from the resctrl filesystem; user space has no way to verify the result of a write to info/kernel_mode without reading kernel memory. Add two read-only files alongside cpus / cpus_list in every rdtgroup: kmode_cpus - bitmap form of rdtgrp->kmode_cpu_mask kmode_cpus_list - range-list form of the same mask The handler returns -ENOENT for a deleted group and -ENODEV for a pseudo-locked group, mirroring rdtgroup_cpus_show(). An empty mask reads back as a bare newline, matching the "all online CPUs" semantics rdtgroup_config_kmode() applies to an empty kmode_cpu_mask. Signed-off-by: Babu Moger --- v3: New patch to add "kmode_cpus" and "kmode_cpus_list" to support kernel_modes. --- fs/resctrl/rdtgroup.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index faf390893109..e155160ba2b1 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -387,6 +387,44 @@ static int rdtgroup_cpus_show(struct kernfs_open_file = *of, return ret; } =20 +/* + * Show the per-rdtgroup kmode_cpu_mask, the set of CPUs scoped for this + * group's kernel-mode binding. Backs both the "kmode_cpus" (bitmap) and + * "kmode_cpus_list" (range list) files; the format is selected by + * is_cpu_list() based on the file's RFTYPE_FLAGS_CPUS_LIST flag. + * + * An empty mask is emitted as a bare newline. rdtgroup_config_kmode() + * treats an empty kmode_cpu_mask as "all online CPUs", so reading just + * "\n" means the binding is applied group-wide rather than restricted + * to a subset. + * + * Returns -ENOENT if the group has been deleted, and -ENODEV for + * pseudo-locked groups -- which cannot host a kernel-mode binding, so + * reporting an empty mask would be misleading (the empty form elsewhere + * means "all online CPUs"). Mirrors rdtgroup_cpus_show() for parity. + */ +static int rdtgroup_kmode_cpus_show(struct kernfs_open_file *of, struct se= q_file *s, void *v) +{ + struct rdtgroup *rdtgrp; + int ret =3D 0; + + rdtgrp =3D rdtgroup_kn_lock_live(of->kn); + + if (rdtgrp) { + if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { + ret =3D -ENODEV; + } else { + seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n", + cpumask_pr_args(&rdtgrp->kmode_cpu_mask)); + } + } else { + ret =3D -ENOENT; + } + rdtgroup_kn_unlock(of->kn); + + return ret; +} + /* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, * @@ -2547,6 +2585,21 @@ static struct rftype res_common_files[] =3D { .flags =3D RFTYPE_FLAGS_CPUS_LIST, .fflags =3D RFTYPE_BASE, }, + { + .name =3D "kmode_cpus", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D rdtgroup_kmode_cpus_show, + .fflags =3D RFTYPE_BASE, + }, + { + .name =3D "kmode_cpus_list", + .mode =3D 0444, + .kf_ops =3D &rdtgroup_kf_single_ops, + .seq_show =3D rdtgroup_kmode_cpus_show, + .flags =3D RFTYPE_FLAGS_CPUS_LIST, + .fflags =3D RFTYPE_BASE, + }, { .name =3D "tasks", .mode =3D 0644, --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012046.outbound.protection.outlook.com [40.107.200.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C25163C13E3; Thu, 30 Apr 2026 23:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591619; cv=fail; b=FpTV48+9I1dWXbLov26rEa8jZ+4PLxw3Dwb0781cQ1v+wpOg+OVkFaxbHcIKR395ce+j2QNF7o/KAlihkjQ8ZIQaax/0WqpHkXzz9d588eeHvVJAKbm6Z2sYwS8AT/pr4ePTqKYg/56xG0M6PBtSNYPzCYyCFN7n/yhdhAlrIUc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591619; c=relaxed/simple; bh=8DKmNEX+qIYLvwutredErG3GhqRC0opoO24ptXvC1Jg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ReqsowjtVAePCMOKaVqjLtWM8q6zEFb8h7mtXPNBttojY3+61FMgEbPBSOMXMwXpbnbv2kAN6xLSvLIwX/O0r1un8VvxIBZgls2EoCW0HU+FWBuRiKMc5tKMD+HFnk+8y044leoiGOkIr+YvEA4t/80z8CDzniWF/6pb/DbZfR4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=3t7dFmJZ; arc=fail smtp.client-ip=40.107.200.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3t7dFmJZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WR+gtWwnoV3XcVHzLGwv2CvXWUNi3Vy3p976eusU4pZcMilimHYapBQfI+YwdbOtUhbo168+uOEgNOLDXBy8MJoKKM0RrIxEy4gWJ1DsW2NVwC8xXJm3UQ4/1bkm1Px8+lKXpdQKmlZgOkAqtR41u11STcsJPhkuniUErCQBYINcpDHAy8+5wVJDYSVtN8gke2szQacS5L4Cp04+Y9YDn/dt6WVD4xan7qeM0bS/tHEE30B+9XxiLceCz2MD/FJfpUqzg6jvgoTbOXKU9KE6sa2AU+++Xrd6FwNSmJUZ3KQcJBbsUPG8E2mDDEVzCSwcxoxyyk0CocgS4RJwAyx2Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QHx/qGRG3odw5weuDu7/L1JxeMDiWloL5soKJGfcw/4=; b=F7b3KvqHZ7ct1IdKG3ZBITEAushm/UXHaJK6HFCd53ztlEM4OX0DvXbjRlXUR6sRgc4Si3rQXb2P6ZtBlK+peaK4jegae6KByX0sukpPV3BpMlOez9cz/7OaXS4EimTP4IxV/TTksR7ytOTiDUZ4SEvbSnSiAde+DllOB6qSBmaMs6Qr89K86jCoL0T/MU+4tBtXWEM9kfmm9FzTjjPbLDNokeljwCwcGlZqVQfEgwMH8/R+ii6jZiuJfB9ObIpVYY1c+EYWbeU/q4VABTbNsoo1fyBWRJtORogC0IsS45iE3/J0oy9bJvie09lph1k8E/OaOmM5hdsvDSCg3YuHzg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QHx/qGRG3odw5weuDu7/L1JxeMDiWloL5soKJGfcw/4=; b=3t7dFmJZ38SpslSsFbv8ooy94BJu6xXOz0P2tsNHYjGWOqfWevBvZN157TNjciRBv3zJvFCWttgL8cvlnL0JE3WT11uKEY4v6VvSHA7JLr+jGaYsiNSWcgPkuYozKxmi0z0AEgt/HNSc78MnOQ5N2IubxGMonkynHYhfOFeyUMY= Received: from SA1PR04CA0018.namprd04.prod.outlook.com (2603:10b6:806:2ce::23) by SJ5PPFB332093D3.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::99f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9818.21; Thu, 30 Apr 2026 23:26:51 +0000 Received: from SA2PEPF00001504.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::fe) by SA1PR04CA0018.outlook.office365.com (2603:10b6:806:2ce::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Thu, 30 Apr 2026 23:26:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001504.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:51 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:48 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 11/12] resctrl: Hide kmode_cpus[_list] on groups not bound to kernel-mode Date: Thu, 30 Apr 2026 18:24:56 -0500 Message-ID: <612d7a81fb179aa323c18d1c3a7f2470f2dd6a7b.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001504:EE_|SJ5PPFB332093D3:EE_ X-MS-Office365-Filtering-Correlation-Id: aab4e552-441e-47e9-1c7d-08dea70ff513 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|7416014|376014|82310400026|1800799024|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: S5ivLhBVp/bdb4zaIKsZO37V761a65JYEv0WYI7FibwNqFAI5URhYto0ID/Pga0dWRuniYO35V6ynqJb2m2cNFkh4L9OktbILJhw0HHq+GZjgdbBN+DrRQPV90y6oFKaCRZS+okEZZ1OOc4l4y7jydZl0/WTcal2qoGyGWAH6ewRyG/91k8HNy4HHxeo/BmBKCpdRgvABb5T6RIvE/yMVFQ3/Y0CJ8nnXBbxbzA5gX8o6E/RmnkK4z+B1+K9Nhvamk01gTbUmA1Yg04pdJbItOlEFFtU7807m727mw1BsXIJNaUlE7mA02POgVUWipLqQzyDfrPYnOsbVztkHMA76557kU9nsQdH2ijk46X5ooklnOAAK62T2XItkjyf/tjuaCst6jZhpsXrF9cAdezDF4a+zw1R0YBw73spIxNZyitx1E4jzTVJ9RMl4ZzzyjSRMT8/ivYhBCsd06D9X0UhdRWZlXvqu4zCgTK2D3lSo4YKxCE+sD1agb9Cj9b3RhKpanqqG0GKKRCiRQvgp3x9IqWaHIF5Z9+NIY7MMQDmoRieO2fJksHHiAUiLGLdxbUx1XWCoEytWKhL/m9sBsI3sVJ29eRyDtPJL5JZSd9mBgVkJE/cpR2OdIFnHgFLtWEpHGGp9zQSTkkNPG5yPPp6aCsI7joZGRb+gjeIoYF4Gk+kRp8r/UBD7MKiQ+VosmTz0LNvKI4CEo9nXl9lzwl7ZHeSIku1isVTMOGc0XKg2qs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(7416014)(376014)(82310400026)(1800799024)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0NgIJIZVycupNQl10zDYyMEyC3XubryCoRPMEymiVNcWk78l4vEfNxvAQnfCCd13MZyonQYhwSj2iWvXx2cpb6AskOFTQSQ6O7nogTm2HCBjUIrDxP14gw+PWypzr/PyOW/5oezrAIxnQUWirRYf5iBSk3MTNbfQ0LqeVR+rZImdjxm21p2J0/IDg42IAojGrabFyopmACcCPluUXpBiAsXnDAl5tdokJKaBKiOAk3nnOKcaVsphPilyqTxU6OT74vL0sGLw728hIlYYCddTuxpVap+7lJuhe1pBSfyuzE4r8OUUI4bxg+NWuerLg8orVZR212F3QLXTprTCOSmYmBLZYDGitj21bGYauMIsxtej76jkX6LeiiIgUL5fPkP/aC6XIm5HW77e7K+V+1QkBby6upUvq5pT26sFsiTMFY43CPBLetfIsky4vyhsB/Xy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:51.0563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aab4e552-441e-47e9-1c7d-08dea70ff513 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001504.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPFB332093D3 Content-Type: text/plain; charset="utf-8" The kmode_cpus and kmode_cpus_list files control the CPU scope of the kernel-mode binding owned by resctrl_kcfg.k_rdtgrp. On any other group they appeared as stub files, and writing to them reprogrammed hardware as if the binding were active -- corrupting the real binding. Hide both files via kernfs_show() on every rdtgroup that does not currently own the binding. The kernel-mode lifecycle hooks toggle visibility: hidden at mount on rdtgroup_default, hidden at mkdir for new groups, shown by rdtgroup_config_kmode() on the group it binds, and hidden again by rdtgroup_config_kmode_clear() (and through it, rdtgroup_config_kmode_delete()) when the binding is released. Signed-off-by: Babu Moger --- v3: New patch to hide/show "kmode_cpus" and "kmode_cpus_list" when kernel m= odes binding changes. --- fs/resctrl/rdtgroup.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index e155160ba2b1..cff306d28e79 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -1093,6 +1093,38 @@ static int resctrl_kernel_mode_show(struct kernfs_op= en_file *of, return 0; } =20 +/** + * resctrl_kmode_files_set_visible() - Toggle visibility of the per-group + * kernel-mode CPU files under @rdtgrp. + * @rdtgrp: Resctrl group whose "kmode_cpus" / "kmode_cpus_list" files + * should be hidden or shown. + * @visible: %true to expose the files, %false to hide them via + * kernfs_show(). + * + * Each file is looked up independently as a sibling under @rdtgrp->kn. + * kernfs_find_and_get() failures are intentionally ignored: this helper + * is invoked early on rdtgroup_default before its rftype files have been + * populated, and is robust against any future rdtgroup variant whose + * kernfs tree does not include these files. + * + * Context: Caller must hold rdtgroup_mutex. + */ +static void resctrl_kmode_files_set_visible(struct rdtgroup *rdtgrp, bool = visible) +{ + /* Keep in sync with res_common_files[] entries for these files. */ + static const char * const files[] =3D { "kmode_cpus", "kmode_cpus_list" }; + struct kernfs_node *kn; + int i; + + for (i =3D 0; i < ARRAY_SIZE(files); i++) { + kn =3D kernfs_find_and_get(rdtgrp->kn, files[i]); + if (!kn) + continue; + kernfs_show(kn, visible); + kernfs_put(kn); + } +} + /** * rdtgroup_config_kmode() - Push @rdtgrp's kernel CLOSID/RMID to hardware * @rdtgrp: Resctrl group whose CLOSID/RMID should be programmed. @@ -1161,6 +1193,7 @@ static int rdtgroup_config_kmode(struct rdtgroup *rdt= grp) resctrl_arch_configure_kmode(disable_mask, closid, rmid, false); =20 rdtgrp->kmode =3D true; + resctrl_kmode_files_set_visible(rdtgrp, true); =20 free_cpumask_var(enable_mask); if (need_disable) @@ -1228,6 +1261,7 @@ static int rdtgroup_config_kmode_clear(struct rdtgrou= p *rdtgrp, int kmode) =20 out_clear: cpumask_clear(&rdtgrp->kmode_cpu_mask); + resctrl_kmode_files_set_visible(rdtgrp, false); rdtgrp->kmode =3D false; return 0; } @@ -3387,6 +3421,8 @@ static int rdt_get_tree(struct fs_context *fc) if (ret) goto out_closid_exit; =20 + /* Hide before activate; the kernfs hidden flag survives kernfs_activate(= ). */ + resctrl_kmode_files_set_visible(&rdtgroup_default, false); kernfs_activate(rdtgroup_default.kn); =20 ret =3D rdtgroup_create_info_dir(rdtgroup_default.kn); @@ -4411,6 +4447,8 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *par= ent_kn, goto out_unlock; } =20 + /* Hide before activate; the kernfs hidden flag survives kernfs_activate(= ). */ + resctrl_kmode_files_set_visible(rdtgrp, false); kernfs_activate(rdtgrp->kn); =20 /* @@ -4455,6 +4493,8 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node= *parent_kn, if (ret) goto out_closid_free; =20 + /* Hide before activate; the kernfs hidden flag survives kernfs_activate(= ). */ + resctrl_kmode_files_set_visible(rdtgrp, false); kernfs_activate(rdtgrp->kn); =20 ret =3D rdtgroup_init_alloc(rdtgrp); --=20 2.43.0 From nobody Tue Jun 16 14:44:09 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010017.outbound.protection.outlook.com [52.101.201.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E812EE262; Thu, 30 Apr 2026 23:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.17 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591629; cv=fail; b=bnKMWTYSq0nlmER4eINnNX+ybnH7NEhTrnh0l1CUB2vjrnCgjScrPLTPSaFNOxdZLgTdWuzEV96nh2+m46aig3X+UIV3rM3KfOAYcgsiPIT0RA57qnPU/lTwBchDSFl8JANaoBi32VQEr7MXzvwp3v3egj+N268EXJAW0uRcuOU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777591629; c=relaxed/simple; bh=3hTgSVjKuA2QnH7wGtIOcVJuyjdpBhoY2GXCGd3nasw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fHO/Yikuyo8KxCLZS3dnweHb+ch6zvG0vgAjFII5TbXKPE38/8vShFZ/CsUfKwsaFvXE88Cd0LBg+5+jVusdu1LxGqzR9E9wEpMj19VqznuuPf2T8TECAsSvSVWOUjmkE9lWn9zhBT/ezQeZUCA4xzLwyYjaIML/4aRK7WLKogE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=RVVNG0rb; arc=fail smtp.client-ip=52.101.201.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="RVVNG0rb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Z8h3RQP0bV0R9kJm9tyJMV/Yr3UhfjfBU6ZFyvDhvSgsfeL+qHWa5GoOTdrlBDu3Al62h9gVYymgbibAJJReLsMGnGiVOOsRgGOyxL4ABNUSzXA//JH3xgbf1tAAK8hiIrYkkpNb9lJXVYs70BudiAdpwsVQOUjZKiSwJFwi9STh3O1pZOcXfrZbmiXW6JUzxqAsvMHhKpSwraPgnZDzvmczczFi6JNQRWDA5olv72CMg+2kh611OsvBWXrhJoRygWVuRf+HLKxT8CMN8K4ogPOOhOYApbbNbflM6czYq8ZsxebL2T/hir7+WE9CcfPWO99fHwqtSmDhlgfPIxHJvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LtHL3PLU3D5ejW6z0xS4bLkTtne86GrscVmnUrpCe7g=; b=Z8xTwMlkA7MGNE1KPl7eJ2dNdQOOBWTADIRae5//bxvKEN/jSoT2OQkkLky9NmD6+z2qpZdykiJPO3aE4GsnU4rOyBbdeBObJ9Ts2BFbPigPsXJ0WRW+87zoao3RHTZmMgR2mCTaMS2ihhu8/U+PPTsgciskwxkn8vacvTAQVITaD7gyKKjWAwl1OgcwE4A/GcX/08BAaH9dDX2Wun+nymtiaTdQ6mSHt1PiWQ5dfnXd0WecfeGyRGmCQkSb76bfkKgMg/2GzCYozfJyI8UnZ9TujiQafc7n9Xn3v2c1d8mA1X3YvzO1X7+++aIlMlIXx+sdmoRZvcoBEeIMPIh4Ow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lwn.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LtHL3PLU3D5ejW6z0xS4bLkTtne86GrscVmnUrpCe7g=; b=RVVNG0rb7wLYjxaxzyHKsuNcao88fsBl5Fi78IdOTDzc5SUuDv45Lb39YT6gzuQDZG8XzTLETGi5iBA26GxAirtPa484jhooDfMMbqNY+JuXj5Dd8JEk97UZ1Onbwbed701FPuIhg1R3TRuffm9/4ASIbqkOVVExQo4hw6uNTEE= Received: from PH8PR15CA0016.namprd15.prod.outlook.com (2603:10b6:510:2d2::26) by PH0PR12MB8175.namprd12.prod.outlook.com (2603:10b6:510:291::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.21; Thu, 30 Apr 2026 23:27:00 +0000 Received: from SA2PEPF00001505.namprd04.prod.outlook.com (2603:10b6:510:2d2:cafe::db) by PH8PR15CA0016.outlook.office365.com (2603:10b6:510:2d2::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Thu, 30 Apr 2026 23:27:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF00001505.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Thu, 30 Apr 2026 23:26:59 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 30 Apr 2026 18:26:57 -0500 From: Babu Moger To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 12/12] fs/resctrl: Allow user space to write kmode_cpus / kmode_cpus_list Date: Thu, 30 Apr 2026 18:24:57 -0500 Message-ID: <959cb9b930288c144ff4a2654de90e956a070dc9.1777591497.git.babu.moger@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001505:EE_|PH0PR12MB8175:EE_ X-MS-Office365-Filtering-Correlation-Id: c126eade-eb81-4b0b-ddf1-08dea70ffa27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|376014|7416014|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: o3CTlTFoOmP/wqv8rw0rQmzK+kp00TWzjsb/qMsP8Yby203r4PQfB06yrWdw6CMLOurdVsWi19Y+8f164QKmuIGHh1muf3OUH0JpPAmqTYhPMLls8J9c1ijU0EbnzM/ZKO82QhXh2XPODtTEtHEaUshqElm2zJnWYqVxbmoFBgejooginieWsStQxrfb8clEr/iHIB31ws1r0Jc9DJBioxra5VHGX2zA3UAVPziR+mT/2Dp86RAl9XXIHKgX+4ZTZZ80FylvAYqsGX7sJAgsFVjMVYAPn6+y+jv0TOQCJtiDggh6RWCEUE38NA++vlDhGP9GUjz0W4h/3Ybi2FqsgU3SZcHtmnHGfUPntTW2OyTPoSRqLKObwIYVxGcu5I1r/7pKGhy0knPaBJpdKP0n1M5gZr5aoUHgSWj/etU8lBZlskPTUFMTzrljIIMgYvy7ckO3YOrMWZouYYuYPEPGy5VnTD/aB+TVuW+oxIOv5mUsanycfQOrug0EAM1otiM3x/lMfekfTBc6NFXXGCPRzKGWKxeb0uNQ4x/Y2fmHS1farL/jFOnu37nNMcQ7LNNdr75u7uJotx1uG+8uGX/xo5Gk9mPx5zij+NmrZBX4QYm2TdOjnY1I8qtLd4/R1uR3XEghT5j4kRX1o51AgLgRg7TLjvNnrE9guf9Qa+fA78ANsxQ65k5ujjV91j5pmPtYr/TK8qfYS5tASwX/P4BymdB0pDZHoH3H8BJncLG4QcA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700016)(376014)(7416014)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aeb9/UMSJYdszxNIQ0ZmPIQ9kRhNe73u+S/z8NA4G3ZEVbpwXgHRvZH7bNvRyaCM3N3uEvuDkpnBKb7/k8Xc4Zq1ZMMI6qYj6c0LwsIlMm3hkRET/qI+yBw1E4IKvRZ6eUUtGB0SQeTXwYXqpVKF5Ap7gvUSdXEk6Oz845poDkhToszGloiuuqCscuiZ5JiLECvpclSXX0iCPMlbPYRfi9scXEKPWZYGw8EHaZp9rFtvSkYGwE9SuzaWFKjTm4T9VnrVnT8exgySU7XTdQ5PNkTdtE2axf7mb1rExLaU/+jkbhtem4EVyRkQvVHsrCvJGYKsGYV5ivZ9AzegmfTZu4gwO1gRkdIt9gx3pSn+EzYELQxn+mnMthNzaoJMuzNmiTXxAaZYf7xF37zofjeaFrN4N16KUlqyZpybcHWW6kEqm2niUT/1s6L7tbCAxjSA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2026 23:26:59.5805 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c126eade-eb81-4b0b-ddf1-08dea70ffa27 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001505.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8175 Content-Type: text/plain; charset="utf-8" The kmode_cpus and kmode_cpus_list files are read-only, so adjusting the per-group CPU scope after a bind requires a full unbind/rebind via info/kernel_mode -- reprogramming hardware on every online CPU even for a single-CPU change. Make both files writable (mode 0644). The handler validates the input (rejecting pseudo-locked groups and offline CPUs), computes the delta between rdtgrp->kmode_cpu_mask and the new mask, and reprograms hardware incrementally: only the CPUs whose enable state changes hit resctrl_arch_configure_kmode(). The new mask is then stored in rdtgrp->kmode_cpu_mask so the next rdtgroup_config_kmode() at re-bind sees it. Documentation/filesystems/resctrl.rst is updated alongside. Signed-off-by: Babu Moger --- v3: New patch to add "kmode_cpus" and "kmode_cpus_list" to support kernel_modes. --- Documentation/filesystems/resctrl.rst | 33 +++++ fs/resctrl/rdtgroup.c | 183 +++++++++++++++++++++++++- 2 files changed, 214 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesyst= ems/resctrl.rst index 89fbf8b4fb2a..aebd9a649773 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -636,6 +636,39 @@ All groups contain the following files: "cpus_list": Just like "cpus", only using ranges of CPUs instead of bitmasks. =20 +"kmode_cpus": + Visible only on the rdtgroup currently bound to the active kernel + mode (see "info/kernel_mode"); hidden on every other rdtgroup, + including the default group while INHERIT_CTRL_AND_MON is active. + + Bitmask of the logical CPUs scoped for this group's kernel-mode + binding (PLZA on x86). An empty mask is reported as a bare newline + and is interpreted by the bind path as "every online CPU". + + Writing a mask reprograms the binding incrementally: it enables on + the CPUs newly added by the write and disables on the CPUs dropped + from the previous mask. The mask must be non-empty and contain only + online CPUs; empty masks and masks naming offline CPUs are rejected + with -EINVAL. To reset the binding to "every online CPU", use + info/kernel_mode to unbind and rebind the group rather than writing + here. Writes to a group that is not the active kernel-mode binding + are rejected with -EBUSY. Reading returns -ENODEV for a + pseudo-locked group and -ENOENT for a deleted group; writes to + pseudo-locked or pseudo-lock-setup groups are rejected with + -EINVAL. Errors are reported in "info/last_cmd_status". Example:: + + # mkdir ctrl1 + # echo "global_assign_ctrl_inherit_mon_per_cpu:group=3Dctrl1//" \ + > info/kernel_mode + # echo 0-3 > ctrl1/kmode_cpus_list + # cat ctrl1/kmode_cpus + f + # cat ctrl1/kmode_cpus_list + 0-3 + +"kmode_cpus_list": + Just like "kmode_cpus", only using ranges of CPUs instead of bitmasks. + =20 When control is enabled all CTRL_MON groups will also contain: =20 diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index cff306d28e79..0eb28dbfd77f 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -425,6 +425,183 @@ static int rdtgroup_kmode_cpus_show(struct kernfs_ope= n_file *of, struct seq_file return ret; } =20 +/** + * kmode_cpus_write() - Update @rdtgrp's kmode_cpu_mask from @newmask + * @rdtgrp: Resctrl group whose kmode_cpu_mask is being updated. + * @newmask: Non-empty set of online CPUs scoped for @rdtgrp's + * kernel-mode binding. Callers must reject empty masks + * before reaching this helper. + * @tmpmask: Caller-allocated scratch cpumask used to compute the + * incremental enable/disable deltas; contents on entry are + * ignored and on return are unspecified. + * + * Compute the difference between @rdtgrp->kmode_cpu_mask and @newmask + * and call resctrl_arch_configure_kmode() only on the CPUs whose enable + * state actually changes: + * + * - Empty -> @newmask: the previous mask is the post-bind default + * "every online CPU", so disable on cpu_online_mask & ~newmask and + * enable on @newmask. + * - Non-empty -> @newmask: disable on (old & ~new), enable on + * (new & ~old). + * + * Then copy @newmask into @rdtgrp->kmode_cpu_mask so subsequent + * show/write operations and the next rdtgroup_config_kmode() at re-bind + * see the updated set. + * + * Context: Caller must hold rdtgroup_mutex (taken by + * rdtgroup_kn_lock_live()). + * + * Return: 0. + */ +static int kmode_cpus_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask, + cpumask_var_t tmpmask) +{ + u32 closid, rmid; + + if (rdtgrp->type =3D=3D RDTMON_GROUP) { + closid =3D rdtgrp->mon.parent->closid; + rmid =3D rdtgrp->mon.rmid; + } else { + closid =3D rdtgrp->closid; + rmid =3D rdtgrp->mon.rmid; + } + + if (cpumask_empty(&rdtgrp->kmode_cpu_mask)) { + /* + * Previous mask was empty, which means the binding covers + * every online CPU. Drop the CPUs that fall outside + * @newmask, then (re)assert on @newmask. + */ + cpumask_andnot(tmpmask, cpu_online_mask, newmask); + if (!cpumask_empty(tmpmask)) + resctrl_arch_configure_kmode(tmpmask, closid, rmid, false); + resctrl_arch_configure_kmode(newmask, closid, rmid, true); + } else { + /* CPUs dropped from this group: old & ~newmask. */ + cpumask_andnot(tmpmask, &rdtgrp->kmode_cpu_mask, newmask); + if (!cpumask_empty(tmpmask)) + resctrl_arch_configure_kmode(tmpmask, closid, rmid, false); + + /* CPUs newly added: newmask & ~old. */ + cpumask_andnot(tmpmask, newmask, &rdtgrp->kmode_cpu_mask); + if (!cpumask_empty(tmpmask)) + resctrl_arch_configure_kmode(tmpmask, closid, rmid, true); + } + + cpumask_copy(&rdtgrp->kmode_cpu_mask, newmask); + return 0; +} + +/** + * rdtgroup_kmode_cpus_write() - Sysfs write handler for kmode_cpus[_list] + * @of: kernfs open file (selects bitmap vs range-list parsing via + * is_cpu_list()). + * @buf: NUL-terminated input from userspace. + * @nbytes: Length of @buf, returned on success. + * @off: File offset (unused). + * + * Parses @buf into a cpumask and rejects: + * - pseudo-locked / pseudo-lock-setup groups, + * - writes to a group that is not the active kernel-mode binding + * (defensive against fds opened while the group was bound; the + * visibility layer normally hides this file on non-bound groups, + * but an open fd survives an info/kernel_mode change), + * - malformed input, + * - empty masks (use info/kernel_mode unbind/rebind to reset), + * - masks containing offline CPUs. + * + * Validated masks are passed to kmode_cpus_write() to update + * @rdtgrp->kmode_cpu_mask and reprogram hardware incrementally. + * + * Locking is via rdtgroup_kn_lock_live(), which takes rdtgroup_mutex and + * ensures the rdtgroup is still live for the duration of the write. + * + * Return: @nbytes on success, -ENOENT if the group has been deleted, + * -EINVAL for pseudo-locked groups, malformed input, empty masks, or + * offline CPUs in the requested mask, -EBUSY if the group is not the + * active kernel-mode binding, and -ENOMEM if the scratch cpumasks + * cannot be allocated. + */ +static ssize_t rdtgroup_kmode_cpus_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + cpumask_var_t tmpmask, newmask; + struct rdtgroup *rdtgrp; + int ret; + + if (!buf) + return -EINVAL; + + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) + return -ENOMEM; + if (!zalloc_cpumask_var(&newmask, GFP_KERNEL)) { + free_cpumask_var(tmpmask); + return -ENOMEM; + } + + rdtgrp =3D rdtgroup_kn_lock_live(of->kn); + if (!rdtgrp) { + ret =3D -ENOENT; + goto unlock; + } + + rdt_last_cmd_clear(); + + if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED || + rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKSETUP) { + ret =3D -EINVAL; + rdt_last_cmd_puts("Pseudo-locked group cannot host kernel-mode binding\n= "); + goto unlock; + } + + /* + * The visibility layer (kernfs_show()) prevents fresh open() on a + * non-bound group, but file descriptors opened while the group was + * bound stay valid across an info/kernel_mode change. Reject those + * stale-fd writes so they cannot corrupt the now-active binding. + */ + if (rdtgrp !=3D resctrl_kcfg.k_rdtgrp || + resctrl_kcfg.kmode_cur =3D=3D BIT(INHERIT_CTRL_AND_MON)) { + ret =3D -EBUSY; + rdt_last_cmd_puts("Group is not the active kernel-mode binding\n"); + goto unlock; + } + + if (is_cpu_list(of)) + ret =3D cpulist_parse(buf, newmask); + else + ret =3D cpumask_parse(buf, newmask); + + if (ret) { + rdt_last_cmd_puts("Bad CPU list/mask\n"); + goto unlock; + } + + if (cpumask_empty(newmask)) { + ret =3D -EINVAL; + rdt_last_cmd_puts("Empty mask not allowed; use info/kernel_mode to unbin= d\n"); + goto unlock; + } + + /* kernel-mode binding is only programmed on online CPUs. */ + cpumask_andnot(tmpmask, newmask, cpu_online_mask); + if (!cpumask_empty(tmpmask)) { + ret =3D -EINVAL; + rdt_last_cmd_puts("Can only assign online CPUs\n"); + goto unlock; + } + + ret =3D kmode_cpus_write(rdtgrp, newmask, tmpmask); + +unlock: + rdtgroup_kn_unlock(of->kn); + free_cpumask_var(tmpmask); + free_cpumask_var(newmask); + + return ret ?: nbytes; +} + /* * Update the PGR_ASSOC MSR on all cpus in @cpu_mask, * @@ -2621,15 +2798,17 @@ static struct rftype res_common_files[] =3D { }, { .name =3D "kmode_cpus", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, + .write =3D rdtgroup_kmode_cpus_write, .seq_show =3D rdtgroup_kmode_cpus_show, .fflags =3D RFTYPE_BASE, }, { .name =3D "kmode_cpus_list", - .mode =3D 0444, + .mode =3D 0644, .kf_ops =3D &rdtgroup_kf_single_ops, + .write =3D rdtgroup_kmode_cpus_write, .seq_show =3D rdtgroup_kmode_cpus_show, .flags =3D RFTYPE_FLAGS_CPUS_LIST, .fflags =3D RFTYPE_BASE, --=20 2.43.0