From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 31619355F36 for ; Wed, 29 Apr 2026 15:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475211; cv=none; b=M5KAJanFjRvO6rxPdNwc2+nl+tb4gKcpEWxk/82LcgStOfdpgvYw2Bn6xNKEhhfu86juWNvaiuV1W9VmsIBj6efTMf3b4zbw2m/na7y+xSUAT7FBCQTG9CAQbQV4ZpRH1gUzm4kn7hoNc9ccxUGLUXxiIo/JodjYTU6m1N6+2rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475211; c=relaxed/simple; bh=dxMeQSQAI9H8hX2jXObajzEdPFMeYDHhhrSWJaEFRwc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=foNb3ERru5yPxZYNrjt6SKubcxzNuJPIt8Y9MOJ+RRb7naVBQXSNknQnNCYWb9WmG0MLXVZ0VWOd6S6YZxR57Xy8A1XIpvuEdsLhPvkVisQIvM/5pNF6TufXtd8EHzxkvymqYC9O72xAzCvmg3LYIM33iDGmr2ORkTNyEiavxdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FAeIRGrz; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FAeIRGrz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475209; x=1809011209; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dxMeQSQAI9H8hX2jXObajzEdPFMeYDHhhrSWJaEFRwc=; b=FAeIRGrzc+vTZ5MBB7jatS+pwolhn6Qw/Huzo3xj4nNogiA3RYPJFPI5 B5zcEhlldpbYmzhXEiYYIbW0z9O9pzavucWdpoQY46vhnKR9lMVkF1sVm w5rV8TkPYCg/xars6LDos6Z5uME8dH8M7UFSN8c7b0SzcEDD3hBC/DAjb 7KJDTDZPGtAEq99SpEhHwjNUYyw658SzfyfPmt9evVYXlwYYLFZPeJvhf v/CrYe5nLp3mbA5xw+PiKWIwClwnMW5lCeX/nkBllQT3kBiXr0u3ROGaR 62M9dMbEwCZY9ODT+ra3RUbyKbxscvZb/SktfScSRxsVtPnAW04Ec1LKL A==; X-CSE-ConnectionGUID: vmy0dhZvS4Gc0L1+blVKAg== X-CSE-MsgGUID: cxwU3gpASdqBNPDza0XUOA== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424329" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424329" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: 2jPG30dGTtCWUIVVtWuQEA== X-CSE-MsgGUID: Clb9BXYzTbSLagFaLO7T8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445000" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:46 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 01/10] fs/resctrl: Use correct format specifier for printing error pointers Date: Wed, 29 Apr 2026 08:06:31 -0700 Message-ID: <79af88624ae8f8bf2d7103f52874851583a419af.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" Use correct format specifier for error pointer as coccinelle suggests: .../fs/resctrl/monitor.c:148:8-15: WARNING: Consider using %pe to print= PTR_ERR() .../fs/resctrl/monitor.c:760:9-16: WARNING: Consider using %pe to print= PTR_ERR() Signed-off-by: Reinette Chatre --- fs/resctrl/monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 9fd901c78dc6..8194fdfbea81 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -144,8 +144,8 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool fo= rce_free) arch_priv =3D mon_event_all[QOS_L3_OCCUP_EVENT_ID].arch_priv; arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(r, QOS_L3_OCCUP_EVENT_ID); if (IS_ERR(arch_mon_ctx)) { - pr_warn_ratelimited("Failed to allocate monitor context: %ld", - PTR_ERR(arch_mon_ctx)); + pr_warn_ratelimited("Failed to allocate monitor context: %pe", + arch_mon_ctx); return; } =20 @@ -752,8 +752,8 @@ static void mbm_update_one_event(struct rdt_resource *r= , struct rdt_l3_mon_domai } else { rr.arch_mon_ctx =3D resctrl_arch_mon_ctx_alloc(rr.r, evtid); if (IS_ERR(rr.arch_mon_ctx)) { - pr_warn_ratelimited("Failed to allocate monitor context: %ld", - PTR_ERR(rr.arch_mon_ctx)); + pr_warn_ratelimited("Failed to allocate monitor context: %pe", + rr.arch_mon_ctx); return; } } --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 4F28132ED3A for ; Wed, 29 Apr 2026 15:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475211; cv=none; b=BxQtBLm1+Yl5Ssjq27+PP8v53ydOyq2QRP6YF9rd4k0t6pkHSWOpLe7dItjj0qic+hsFI5XD4sCkKOqJnuba1QQWVjoSDkf5VOVZDO/kilDTWODWML6smtsaaqVwPNaeh46I0EfO2jnoC6ejhTNdV5lBqzmhFLk8UQtl6giZD7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475211; c=relaxed/simple; bh=R3jq/Tn2MlbSH1wGWOLouK4xxwRvjuiHY+8vjleDYHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SYS1DRCFN15OgpiTJ/Ig9G1ooTVYaYxFcIABlbIn1BAqOw2+fzgWkAOtTFxE0OzKZLWbJ87C9Pvf1iv0Mtj73Oyn43J5VD+Vtva3NgZpwSrQ0SyDtVr/V3UT0rb91irBrSHYOA4K7o+32jMbvTilvHilQtZCCb1fcO/0psR8IXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ek+bmTCz; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ek+bmTCz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475210; x=1809011210; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R3jq/Tn2MlbSH1wGWOLouK4xxwRvjuiHY+8vjleDYHY=; b=Ek+bmTCzTA1fniYQCu/yZtWXHtxz1+Zb2BWHKAfKvPk8RmsocVF8Myeg IRPE8T33gjBUawM++a9vXKLhuckSIr0kjJyOXUG0b6gV9wAq/i+1c0/Oo qT5G7ZFlox/7SDpxDcrsn/33JXUgs+BOBOmSae52e1Kiox/icoOXcDme3 2r17Hk+1xA67iMDlJj6xYXFChpKvTxdkoN4HS4AQyYzQtiEPPMd+SGACu An0ySPjUGMVUs2le/wOtbFS3PvcKUcTeH94qnDAwBEU9hyLKmzjL6Iwot +vSfTel1jCnGqwyrXhWh8r0/F35+nw69svnD/BoI5BkdIehxyK58X98uc w==; X-CSE-ConnectionGUID: IzHlsCDKRziS9lTtXnMhSg== X-CSE-MsgGUID: 8nOVI317R+mxJT7BHUz9XA== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424338" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424338" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: QIlayKz+TjKSgeKN/RVIfw== X-CSE-MsgGUID: x3JMnl/tSGWOeppinepJ1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445003" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:46 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 02/10] x86/resctrl: Protect against bad shift Date: Wed, 29 Apr 2026 08:06:32 -0700 Message-ID: X-Mailer: git-send-email 2.50.1 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 size of the bandwidth specifier field is enumerated from AMD hardware. resctrl uses this field width to determine the maximum bandwidth supported that is stored in resctrl_membw::max_bw to which user space allocation requests are compared for validity. resctrl_membw::max_bw is of type u32 while the register containing the bandwidth specifier field, L3QOS_BW_CONTROL_n, is 64 bits. While not an issue with current hardware it is theoretically possible that enumeration of maximum bandwidth may trigger invalid behavior if a future system can use a bandwidth specifier field larger than 32 bits. Whether this could ever represent a reasonable bandwidth value is unknown but addressing the issue will appease static checkers. Ensure resctrl can accommodate the hardware's bandwidth specifier field width with an additional check. Switch to BIT() instead of open-coding the bitshift to avoid signed integer overflow if the number of bits is a valid 31. Signed-off-by: Reinette Chatre --- Changes since v3: - Use pr_warn() instead of WARN_ON(). sashiko: https://sashiko.dev/#/patchset/cover.1775576382.git.reinette.cha= tre%40intel.com --- arch/x86/kernel/cpu/resctrl/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 7667cf7c4e94..778a2d3a26b7 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -246,7 +246,11 @@ static __init bool __rdt_get_mem_config_amd(struct rdt= _resource *r) =20 cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx); hw_res->num_closid =3D edx + 1; - r->membw.max_bw =3D 1 << eax; + if (BITS_PER_TYPE(r->membw.max_bw) <=3D eax) { + pr_warn("Unable to support hardware's maximum bandwidth\n"); + return false; + } + r->membw.max_bw =3D BIT(eax); =20 /* AMD does not use delay */ r->membw.delay_linear =3D false; --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 74EDF36E467 for ; Wed, 29 Apr 2026 15:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475210; cv=none; b=LE9Ke4MSdI4UQ/eueucXCD6xK29Hvs3AQNKGBvEQtgtCxFJl4uNQgmpq3HgXymSumXJGhk66Gq0jnrML6ned+UBDdsMljEIWtXsrV+0nmcSbgi70Jy9FA4fviqyB/cYKOBWA7pqr+paWkqq0AnHE3mMBhN+hrsK8B020qHyLiwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475210; c=relaxed/simple; bh=arnafYuhnaMZc+KiEcaSFFq8ZsggDT06JfSKTL923xY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IWmgdilm7HsWDa9U8F4x/03K+jgce/cn6BuGLhx+MzOHNYARCoaIVmsz4te2vh3OOUHdXkAj1zcME+CMlImIdhxsF0uV+rgoV9WqpgEjd94nGOXRV4djBcv1BpH9EPMfv47V7en2ItMvJ69TK2hfg1vsdwfiBA72kMI+q8e8wDo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gaXeZRRz; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gaXeZRRz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475210; x=1809011210; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=arnafYuhnaMZc+KiEcaSFFq8ZsggDT06JfSKTL923xY=; b=gaXeZRRzK9XV5dzef8pb154U3lsncu0ZVBF3I3VhqRdA79xtYf4cdelQ jUrZ+APXVUICmo5W856zs8LNU47aivKWqXQFWyqAzQJRhl54DEQOql8oO REDVb1R6L8TrUHIyIIr5SmRqm0CaQ+NGrAMhLYyE0ZBhtC887MPjJJTgR X6xWhaHg3A8kTDsS/jH7rwtMH9Lasq9wa1cdFnXaHtQo9ZOxx6tPbsc9E Ko7WlKmdWqG/HDW4WOQ1XMZBzf7kP6WTOgIn3hNoWJpcYt1dUWYmnSva5 VHwXRtYTdH3nvZD49plVkHsXfsAidszoEr/cCXfBipk8kuE2B/Ia0PLEs g==; X-CSE-ConnectionGUID: K7yb7MMkSV2oqbZnn3bZ/Q== X-CSE-MsgGUID: qe69C/sWQOGFtr9kuIYL6w== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424348" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424348" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: FxFtCcA5TW+tmR0yROpyPw== X-CSE-MsgGUID: LINvcxw0TTOQeZH40ofhOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445006" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:46 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 03/10] fs/resctrl: Change pattern used to track number of entries in enum Date: Wed, 29 Apr 2026 08:06:33 -0700 Message-ID: <4a304e6c9ed3f5d92156b8045f5dd4ddba359dfc.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" CDP_NUM_TYPES tracks the number of different configuration types that can be applied to a resource. CDP_NUM_TYPES is required to iterate over the different configurations but is not a member of enum resctrl_conf_type to avoid the warning generated with -Wswitch when CDP_NUM_TYPES lacks a case. Add a new CDP_LAST enum entry used in CDP_NUM_TYPES definition to simplify adding a new enum entry. Do this to create a cleaner pattern for tracking the number of enum entries in resctrl in preparation for other enums needing to do so. Suggested-by: Ben Horgan Signed-off-by: Reinette Chatre Reviewed-by: Ben Horgan --- Changes since v2: - Add Ben's RB tag. --- include/linux/resctrl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 006e57fd7ca5..0b28049378c8 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -69,9 +69,10 @@ enum resctrl_conf_type { CDP_NONE, CDP_CODE, CDP_DATA, + CDP_LAST =3D CDP_DATA }; =20 -#define CDP_NUM_TYPES (CDP_DATA + 1) +#define CDP_NUM_TYPES (CDP_LAST + 1) =20 /* * struct pseudo_lock_region - pseudo-lock region information --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 0C2B3377034 for ; Wed, 29 Apr 2026 15:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475212; cv=none; b=n+6o16e1cN0mB/cYxPBeDNJ2dd9vaHu4SVi+uAxrs1MDpeZQ/Qbv0eM9CF3PQNqRweIBNaeg2kXPAMgSMMRIyxJJr4KLN0QpRrOY/wDHfpMgGij8G5pbiVmawgdctgrgO5IguhlkNoNobIbhqAQyui/ZLtiQHJn6dNVLHpqOWb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475212; c=relaxed/simple; bh=UmtJaEEjPND1GwglwNpwhcFwJ4D2HpzVcTyZRXsHAY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F/JnVDg1rdnHCeDfIkx0wWzmwFry0KL1lIYaT0VGPDBGHOLLzTz8PimystB4dDl5Tko/TUbxJn0L+HvsDvGUC08soIXDsz0+6suSPWveqXOnjL/c6EmhoSmgS7l+udsxJndXPNFD2rjfCyHpMZUYgw/577hFoO7PQQhpwQFIX50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=eA5UvC4q; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="eA5UvC4q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475212; x=1809011212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UmtJaEEjPND1GwglwNpwhcFwJ4D2HpzVcTyZRXsHAY0=; b=eA5UvC4qolOpHSKau7lLJuecGrbNLhHybuxIXHz6I6H9OOCDbcXJaGDl dtvabnoe0bv161h9xk5yCMXWdhGYzL2hIx2rupBx3Th4VnfST/dlmQ1cY 0MmT0JTSnGYxQBBx2mxPzYTejFlfID7yHFHaKOkXcfkC92xv42YRW41+f 9RmZk1L1JnFEQH5DZ9hWQVK4tCniqMOLG9n22sOOooXGz4MI+l84V+kB6 0cEj7NCRzjHkKO50q7AuD40an2dvDc1tMFfXsQs+Oyn8Dja+kkQO2W4ox Z1CA1v4//Iv4nCujQnpcalIQHXFyaLv6zVqpIgaq0VfwukuZri0Ietoi/ A==; X-CSE-ConnectionGUID: KlK03I1sRzuO+ovdc440Zw== X-CSE-MsgGUID: YqgAnf/AQ6WzNc4T/Av2+A== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424357" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424357" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: 2YVJv0fLQ6WIROL78YqxBQ== X-CSE-MsgGUID: NYoze/g5SMOmApm8pvkWUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445009" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 04/10] fs/resctrl: Use accurate type for rdt_resource::rid Date: Wed, 29 Apr 2026 08:06:34 -0700 Message-ID: <0629fe256d551829c9e41304a3f4e5bc3de97532.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" Every resctrl resource has a unique ID described by enum resctrl_res_level. enum resctrl_res_level is used in all resource ID initializations and all resource ID comparisons. All functions consuming the resource ID expects an enum resctrl_res_level. Of the four structures that contain a resource ID (struct mon_data, struct mon_evt, struct rdt_domain_hdr, and struct rdt_resource) only struct rdt_resource does not use enum resctrl_res_level. Switch the type of rdt_resource::rid to be enum resctrl_res_level to make it obvious what values are valid, match the type everywhere this member is used, and obtain benefits from tools that can flag any enum misuse. Move define of RDT_NUM_RESOURCES outside the enum to enable tools to catch when a switch() on the resource ID does not handle all the resources and thus help flag which switch statements need an update when a new resource is added. Signed-off-by: Reinette Chatre Reviewed-by: Ben Horgan --- Changes since v1: - Use RDT_RESOURCE_LAST =3D RDT_RESOURCE_PERF_PKG as last entry in enum.(Be= n) Changes since v2: - Add Ben's RB tag. --- include/linux/resctrl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 0b28049378c8..99a4774735c7 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -54,11 +54,11 @@ enum resctrl_res_level { RDT_RESOURCE_MBA, RDT_RESOURCE_SMBA, RDT_RESOURCE_PERF_PKG, - - /* Must be the last */ - RDT_NUM_RESOURCES, + RDT_RESOURCE_LAST =3D RDT_RESOURCE_PERF_PKG }; =20 +#define RDT_NUM_RESOURCES (RDT_RESOURCE_LAST + 1) + /** * enum resctrl_conf_type - The type of configuration. * @CDP_NONE: No prioritisation, both code and data are controlled or moni= tored. @@ -320,7 +320,7 @@ struct resctrl_mon { * @cdp_capable: Is the CDP feature available on this resource */ struct rdt_resource { - int rid; + enum resctrl_res_level rid; bool alloc_capable; bool mon_capable; enum resctrl_scope ctrl_scope; --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 C99823750D7 for ; Wed, 29 Apr 2026 15:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475213; cv=none; b=J2kWITxtmXGLhSYqmH4ChOjaV8NfVj1EKqAwE4T9L1Uf1eBchs3LKL7kvbVBhry9emGEDovpV6vO/Wm0TDE1qig/nG7vK9FUpcs1C5Zxl671PMWxyUfzCXowoSs68YL0F4tYF1/B/GvMtbG2Qa+Yc3D0srX+0Wn1wReFQpdOYMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475213; c=relaxed/simple; bh=A21P6fI2hgZ/+eGK6RsbbZ/oeCdwqcvHzTT8GH5JBd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ghfoqTFugzCKY/z031QnNtBZOhemJovwt6Wx1VENA47J3Ijpmj1drmLxGWOKLg10PfgRdtu9Y6h6cGJEzzTutep0cNH6CUmXTG1kwPcVdTk5UNA/V1qRm/vnETgUCVxSmw50ZSe/GnIotHZUJOkKlyIo+vsu50QB3QqYZfJ3VUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mrpxT7Q0; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mrpxT7Q0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475212; x=1809011212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A21P6fI2hgZ/+eGK6RsbbZ/oeCdwqcvHzTT8GH5JBd0=; b=mrpxT7Q02EQ+/uyAuCganpOKDCaOwCdcxaCwz2FefdRE5rkDguU0/n0d XkNvGOswyb+mNEX116aJAToEhnu3DhnjCEXWCShOj5/WzObdZJ9ITp9I9 VRKwu5jJvc6ZWRypTd67oCtFsR8MkRQtkcZEQ0lm3n0rMBDA8YX6ecC59 8USi/GR9HxhzoICIC+wXTjqTQynbEGqcqHGc7ROBjDhgvrI1bHEw/VpD8 rEZHDvmavAzgl8t3F8rcs+MSKPHpcjB4xdhP/RwciGozJFo55/RhW9htF Con9QPWMItqGFrWNqqU5VBDo3BE4scXW4n/3vsHCPxnB+plavZPhvreHZ g==; X-CSE-ConnectionGUID: 6PNK6UhrTJCt58PBPk+Rng== X-CSE-MsgGUID: w6iW5i6+SfSzqWAJdxUYPA== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424367" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424367" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: HAUSJ3mWS1qiz7HZts3IVg== X-CSE-MsgGUID: bDVjghwDR9mHkQ+l7IJUNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445012" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 05/10] fs/resctrl: Pass error reading event through to user space Date: Wed, 29 Apr 2026 08:06:35 -0700 Message-ID: X-Mailer: git-send-email 2.50.1 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" Reading of event data is managed through populating a struct rmid_read with properties of event needing to be read. This data is dispatched to an appropriate CPU and upon completion any error can be found in rmid_read::er= r, or on success the event data will be in rmid_read::val. rmid_read::err is not updated in the unlikely scenario that the reading of the event was dispatched to a wrong CPU. If this ever occurs due to a bug in resctrl the user space read will return "success" but the data reported will be invalid. Ensure accurate error reporting so that if there may be an issue with how resctrl picks a CPU it could be learned with an error to user space instead of silent failure. Signed-off-by: Reinette Chatre Reviewed-by: Ben Horgan --- Changes since v1: - Add Ben's RB tag. --- fs/resctrl/monitor.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 8194fdfbea81..101b2911d582 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -453,8 +453,10 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgr= p, struct rmid_read *rr) } =20 /* Reading a single domain, must be on a CPU in that domain. */ - if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) + if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) { + rr->err =3D -EIO; return -EINVAL; + } if (rr->is_mbm_cntr) rr->err =3D resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id, rr->evt->evtid, &tval); @@ -491,8 +493,10 @@ static int __l3_mon_event_count_sum(struct rdtgroup *r= dtgrp, struct rmid_read *r } =20 /* Summing domains that share a cache, must be on a CPU for that cache. */ - if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) + if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) { + rr->err =3D -EIO; return -EINVAL; + } =20 /* * Legacy files must report the sum of an event across all --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 52529377558 for ; Wed, 29 Apr 2026 15:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475212; cv=none; b=Mo7juemGcuYLFxRRFGuDiQLdCOI2e1KrgqyjGjIoXFAhJXPWYOO5Q033Ap+cXBfbUvCpbCgORiuvV/fRmcpBlULFrUSI39IMmiOISzH8zrE2fC6dIEF4DNMlQJgoxDtZyI+OhoQttHy1Lt5F3aTSy8YHIP09floqghnpCTZ6OtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475212; c=relaxed/simple; bh=/aVegcj2Gd/PPwuq0w7v0DVXLWgC36AnHuP/93CopIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=figFtBap7QkijgUwTkvdlVeqA5VX0oS5rC1XXKSgk9nZOzt2oHjPY8WLu1P5br08B8IGEXPEdGHnV0SqapJ/UT0+t9uVMzJ2XW5hssyH678y7Y2hFqtog2jJ2xowiN1fn3X2AqXMoUKbyrGxs0UYTvbHAXO/yL3Y2K8N/EIeFdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hXYWg+yP; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hXYWg+yP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475212; x=1809011212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/aVegcj2Gd/PPwuq0w7v0DVXLWgC36AnHuP/93CopIQ=; b=hXYWg+yP93Rg/CA7n5nlM2UTp2mCahYbIc87B7jfxec6U9NN2FsF45Z+ Mx2VJspl9je4zXWPmcoJk3S1ysiS3DhCfDM3y+4JhlfxWZ2rsTCrwPmWi cjTzmFfrnIsTKtfmJamkqXqDEaeOD6/oYCU67Ho5xwltrnCWGtit3+pru EiRxQBroqdLUc5l/gs4ZGAguwjBSLXY7XE/7e8CsCUs0r6/JZLSAJCb7g 9B5WoHtMyHZe0obp4phtvi2j/PuUqAL3ry5IRRz2R1p2BgqZ/JBg4h7qI c00xW6ZPiA7xf94ACXyBa34rYIdBcnnHoEblscCxagoiyOc6gStByVdnP Q==; X-CSE-ConnectionGUID: nLNllE4cSNKC35EEck8ZUw== X-CSE-MsgGUID: p86Ud9L4SHGwsqflPe5J2A== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424376" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424376" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: OqGiyrtoRYOE/iCEjM08Ow== X-CSE-MsgGUID: MigMWvkSSqe+RsgkAqaepQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445015" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 06/10] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy Date: Wed, 29 Apr 2026 08:06:36 -0700 Message-ID: <567dc8417d4bf6254407ee3a5bc5c593999804e7.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" info/last_cmd_status is intended to contain more information if a write to any resctrl file fails. Writes to max_threshold_occupancy did not receive last_cmd_status support during initial last_cmd_status enabling. Add it now. Signed-off-by: Reinette Chatre --- Changes since v1: - Add Ben's RB tag. Changes since v2: - Switch to guard(). (Chenyu) - Drop Ben's RB tag due to significant code change. --- fs/resctrl/rdtgroup.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5dfdaa6f9d8f..5e3ea92cc243 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -12,6 +12,7 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include @@ -1238,12 +1239,20 @@ static ssize_t max_threshold_occ_write(struct kernf= s_open_file *of, unsigned int bytes; int ret; =20 + guard(mutex)(&rdtgroup_mutex); + rdt_last_cmd_clear(); + ret =3D kstrtouint(buf, 0, &bytes); - if (ret) + if (ret) { + rdt_last_cmd_puts("Invalid input\n"); return ret; + } =20 - if (bytes > resctrl_rmid_realloc_limit) + if (bytes > resctrl_rmid_realloc_limit) { + rdt_last_cmd_printf("Exceeds limit (before adjustment) of %u bytes\n", + resctrl_rmid_realloc_limit); return -EINVAL; + } =20 resctrl_rmid_realloc_threshold =3D resctrl_arch_round_mon_val(bytes); =20 --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 44C3C379979 for ; Wed, 29 Apr 2026 15:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475214; cv=none; b=rboEFicVzaeii9LNLQM5J9yOS8sir48Vpx6i9Bqgn2YPz1PpE+SeuCTtnXN4qz5zFnZ3zFz/ETo7Z6YgCdEx+NyGWZx480robFJ+TqFBkdFewwbwwMqQvR8NJMrPUI8rfn0XLrHPK7B+c239wbW6Q2TuOfazMjVKB8IyJzsCSn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475214; c=relaxed/simple; bh=DBmG70Xr4+Z1t3xjsxbRIErkOrffXvoW6wckmtG8CM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HU3hEadICwD6tWMg6NN6ZjCeOrrdHYLSI50Ecf8iifw9e919Wpps+xe6X+wD2Wfhqm9ttxU3WjMdqDM9sdEzt0PWNtzdvXC7v4q83wBLpcHYUKDNgsZwOXaDuaayVEQG/wb4TLW+A5B2jkXraEiKT4Y6OojIsaP0EIK0vcvpCh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jJVh0gh+; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jJVh0gh+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475214; x=1809011214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DBmG70Xr4+Z1t3xjsxbRIErkOrffXvoW6wckmtG8CM4=; b=jJVh0gh+Ev72c7qCumvjd5g9Rhd71bU82vn/TY6GFpFzmLugpbfYlbaF vxh48OezCTd/SptNKaAdS24rINMHFphMd4ekTLPcbHsiRjXEWrmwXvK2n uzIQWGNBEDDrJ64ebqDW7msqE6B2If55iIfgaOOwBULjP/IcQOgcThVeq Uv3IqQvgoiU7ieL34aTio2AGIgASy2w/+GsNzYmFLj8n6iM7rXtAkZzQc PWpqYeg4ReVC2VGtT5QPDNDsp91HxeuICR6LKc8cCT+0hbvhdw3XdBHcj blSncTZ6dGNsfuqVa+fyBYQo9FgFPLe3xx6WmYK/gdACmYgQ100nq2Ifk Q==; X-CSE-ConnectionGUID: rff6qwb4S8iFr1PfixNHtQ== X-CSE-MsgGUID: OiOlhTqrQDGkG+FeBGXkDA== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424387" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424387" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: Qp9d7dCgTlWGEe4eU3VudQ== X-CSE-MsgGUID: cnJdusrBQaOoudcCdPupMQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445019" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 07/10] fs/resctrl: Use accurate and symmetric exit flows Date: Wed, 29 Apr 2026 08:06:37 -0700 Message-ID: <74a640427ad531bdca4e6ff72bdaffe622d7a846.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" During schemata file write handling there is one error exit path labeled "out" that handles all cleanup and unlocking needed on exit. The staged configs cleared during an error exit may not have been used at the time of exit making the clearing of the staged configs unnecessary. Access the exit code using two labels and only clear the staged configuration if it was in use at the time of exit. Doing so makes the code flow obvious and simplifies upcoming changes that improve the handling of failures during early input parsing. Signed-off-by: Reinette Chatre --- fs/resctrl/ctrlmondata.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 9a7dfc48cb2e..8a43efe67a95 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -331,7 +331,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file= *of, if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { ret =3D -EINVAL; rdt_last_cmd_puts("Resource group is pseudo-locked\n"); - goto out; + goto out_unlock; } =20 rdt_staged_configs_clear(); @@ -341,16 +341,16 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_fi= le *of, if (!tok) { rdt_last_cmd_puts("Missing ':'\n"); ret =3D -EINVAL; - goto out; + goto out_clear_staged; } if (tok[0] =3D=3D '\0') { rdt_last_cmd_printf("Missing '%s' value\n", resname); ret =3D -EINVAL; - goto out; + goto out_clear_staged; } ret =3D rdtgroup_parse_resource(resname, tok, rdtgrp); if (ret) - goto out; + goto out_clear_staged; } =20 list_for_each_entry(s, &resctrl_schema_all, list) { @@ -365,7 +365,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file= *of, =20 ret =3D resctrl_arch_update_domains(r, rdtgrp->closid); if (ret) - goto out; + goto out_clear_staged; } =20 if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKSETUP) { @@ -378,8 +378,9 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file= *of, ret =3D rdtgroup_pseudo_lock_create(rdtgrp); } =20 -out: +out_clear_staged: rdt_staged_configs_clear(); +out_unlock: rdtgroup_kn_unlock(of->kn); return ret ?: nbytes; } --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 46B9537998B for ; Wed, 29 Apr 2026 15:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475215; cv=none; b=cL7EvIOcFRpX+qVqdGErmg2Es43Y99hH4IQJk2Ki7TlxSfgN/VB4953jOschxXd3gy/BLZjBji9NMNKaA45pSuvWwkSQ91w324no326SLvNK4BlopGAWLNnULJqIk6URNMZPPwqwiWfuuuAaojMJegRiN+c5pOzSFCJuc/rA578= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475215; c=relaxed/simple; bh=ClrkB0PcIBu61gvXQBQnJibsI5pxz5caod8xkzFYwTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FZo7Zq721egyn7GY5vxcPmOvYRkyNUmuviOC0OaZ4Ee6tVbF3fyiC0zmbdilQEQr8nNY8uhWWT3nzP9giMG/Zz5DttxXYd+sEQMIjNj5jBDFCx+4rqteMT9HHZ+90EuCEU71R8RG5YwNPzeu5OD3Qsq86NnhK6OxGzTOx7ltW/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Un5UNAZF; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Un5UNAZF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475214; x=1809011214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ClrkB0PcIBu61gvXQBQnJibsI5pxz5caod8xkzFYwTI=; b=Un5UNAZF18yqYlfdELhENuC+Py4ayKXsRQmBSA8W24oW6/vWZzKKyCFJ +8WpSoxkIYp5E5ZMGG7DZyIgNqNWRnICp5IPUQdB0mWi83nJu3H4OyGyI Y6ikVYlFghdltt4LbS0IpXqi4uSV+dS9gdPsWZlv6NPsZo/x8p3I4vh56 29QfSZPg7bMxWKZGW3G1DO0e8oEsuNn5sAlK0dFQvmlPdeBCWT4wc84hn /H1HaVTAYmNflKur1n3OyPQ3ViqV+HiXT4koTzzgOGF6L+27BM8fDUydH utIHiYTTQGn/f4YaITOB6jUn9zRNY3QjohTF4m/rdXctfkPOzOIQ2I1Ns Q==; X-CSE-ConnectionGUID: QPuRLMQqSWiXzpCwoTbtEA== X-CSE-MsgGUID: fZwQw+QBTnKwf2rBcZ5b/w== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424397" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424397" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: iNvCqRa+T5OjSPhCQ7H0gA== X-CSE-MsgGUID: Q7ACg+p/SFi4LQjilfk/gA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445022" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 08/10] fs/resctrl: Change last_cmd_status custom during input parsing Date: Wed, 29 Apr 2026 08:06:38 -0700 Message-ID: <4efad346b8e4dde0b84ff3e87c635852b6575aa2.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" A pattern of usage of last_cmd_status was introduced during its enabling in commit c377dcfbee80 ("x86/intel_rdt: Add diagnostics when writing the schemata fil= e") and since copied throughout resctrl to result in the following custom: ..._write() { /* Early parsing of input, exit on failure. */ /* Obtain rdtgroup_mutex */ rdt_last_cmd_clear(); /* Clear last_cmd_status buffer */ /* * Act on user command, failures result in detail * error message in last_cmd_status buffer via * rdt_last_cmd_puts()/rdt_last_cmd_printf(). */ /* Release rdtgroup_mutex */ } If resctrl exits with failure during early parsing of input there are two possible scenarios: - The last_cmd_status buffer is empty and a user's read of info/last_cmd_status returns "ok". - The last_cmd_status buffer contains details from an earlier ...write() failure and a user's read of info/last_cmd_status returns this outdated error description. Writing to a resctrl file is considered a "resctrl command" and the resctrl documentation states the following about the last_cmd_status file: "If the command failed, it will provide more information that can be conveyed in the error returns from file operations." Neither of the current scenarios is correct behavior. Move early input parsing to be done with rdtgroup_mutex held after the last_cmd_status buffer is cleared. Let info/last_cmd_status be accurate when an error is encountered during parsing of user command. Signed-off-by: Reinette Chatre Reviewed-by: Ben Horgan --- Changes since v1: - Add Ben's RB tag. --- fs/resctrl/ctrlmondata.c | 54 ++++++++++++++++---------- fs/resctrl/monitor.c | 60 +++++++++++++++++------------ fs/resctrl/rdtgroup.c | 82 +++++++++++++++++++++++----------------- 3 files changed, 117 insertions(+), 79 deletions(-) diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 8a43efe67a95..5d5e844429df 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -312,11 +312,6 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_fil= e *of, char *tok, *resname; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - buf[nbytes - 1] =3D '\0'; - rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { rdtgroup_kn_unlock(of->kn); @@ -324,6 +319,15 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_fil= e *of, } rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + /* * No changes to pseudo-locked region allowed. It has to be removed * and re-created instead. @@ -466,11 +470,6 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_op= en_file *of, struct rdtgroup *rdtgrp; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - buf[nbytes - 1] =3D '\0'; - rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { rdtgroup_kn_unlock(of->kn); @@ -478,6 +477,15 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_op= en_file *of, } rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + if (!strcmp(buf, "mbm_local_bytes")) { if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID)) rdtgrp->mba_mbps_event =3D QOS_L3_MBM_LOCAL_EVENT_ID; @@ -495,6 +503,7 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_ope= n_file *of, if (ret) rdt_last_cmd_printf("Unsupported event id '%s'\n", buf); =20 +out_unlock: rdtgroup_kn_unlock(of->kn); =20 return ret ?: nbytes; @@ -854,15 +863,17 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_fil= e *of, char *buf, bool enable; int ret; =20 - ret =3D kstrtobool(buf, &enable); - if (ret) - return ret; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 rdt_last_cmd_clear(); =20 + ret =3D kstrtobool(buf, &enable); + if (ret) { + rdt_last_cmd_puts("Invalid input\n"); + goto out_unlock; + } + if (!r->cache.io_alloc_capable) { rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name); ret =3D -ENODEV; @@ -1018,16 +1029,19 @@ ssize_t resctrl_io_alloc_cbm_write(struct kernfs_op= en_file *of, char *buf, u32 io_alloc_closid; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - - buf[nbytes - 1] =3D '\0'; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + if (!r->cache.io_alloc_capable) { rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name); ret =3D -ENODEV; diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 101b2911d582..1a38f3b6a1f1 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1112,13 +1112,15 @@ ssize_t resctrl_mbm_assign_on_mkdir_write(struct ke= rnfs_open_file *of, char *buf bool value; int ret; =20 - ret =3D kstrtobool(buf, &value); - if (ret) - return ret; - mutex_lock(&rdtgroup_mutex); rdt_last_cmd_clear(); =20 + ret =3D kstrtobool(buf, &value); + if (ret) { + rdt_last_cmd_puts("Invalid input\n"); + goto out_unlock; + } + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n"); ret =3D -EINVAL; @@ -1409,17 +1411,20 @@ ssize_t event_filter_write(struct kernfs_open_file = *of, char *buf, size_t nbytes u32 evt_cfg =3D 0; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - - buf[nbytes - 1] =3D '\0'; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + r =3D resctrl_arch_get_resource(mevt->rid); if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n"); @@ -1478,17 +1483,20 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs= _open_file *of, char *buf, int ret =3D 0; bool enable; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - - buf[nbytes - 1] =3D '\0'; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + if (!strcmp(buf, "default")) { enable =3D 0; } else if (!strcmp(buf, "mbm_event")) { @@ -1759,12 +1767,6 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_= file *of, char *buf, char *token, *event; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - - buf[nbytes - 1] =3D '\0'; - rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { rdtgroup_kn_unlock(of->kn); @@ -1772,10 +1774,19 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open= _file *of, char *buf, } rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + buf[nbytes - 1] =3D '\0'; + if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { rdt_last_cmd_puts("mbm_event mode is not enabled\n"); - rdtgroup_kn_unlock(of->kn); - return -EINVAL; + ret =3D -EINVAL; + goto out_unlock; } =20 while ((token =3D strsep(&buf, "\n")) !=3D NULL) { @@ -1791,6 +1802,7 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_f= ile *of, char *buf, break; } =20 +out_unlock: rdtgroup_kn_unlock(of->kn); =20 return ret ?: nbytes; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 5e3ea92cc243..755a46ef5bdb 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -512,38 +512,38 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, c= pumask_var_t newmask, static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { - cpumask_var_t tmpmask, newmask, tmpmask1; + cpumask_var_t tmpmask =3D CPUMASK_VAR_NULL, newmask =3D CPUMASK_VAR_NULL; + cpumask_var_t tmpmask1 =3D CPUMASK_VAR_NULL; struct rdtgroup *rdtgrp; int ret; =20 - 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; - } - if (!zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) { - free_cpumask_var(tmpmask); - free_cpumask_var(newmask); - return -ENOMEM; - } - rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { ret =3D -ENOENT; - goto unlock; + goto out_unlock; } =20 rdt_last_cmd_clear(); =20 + if (!buf) { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL) || + !zalloc_cpumask_var(&newmask, GFP_KERNEL) || + !zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) { + rdt_last_cmd_puts("Kernel allocation failure\n"); + ret =3D -ENOMEM; + goto out_free; + } + 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-locking in progress\n"); - goto unlock; + goto out_free; } =20 if (is_cpu_list(of)) @@ -553,7 +553,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_f= ile *of, =20 if (ret) { rdt_last_cmd_puts("Bad CPU list/mask\n"); - goto unlock; + goto out_free; } =20 /* check that user didn't specify any offline cpus */ @@ -561,7 +561,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_f= ile *of, if (!cpumask_empty(tmpmask)) { ret =3D -EINVAL; rdt_last_cmd_puts("Can only assign online CPUs\n"); - goto unlock; + goto out_free; } =20 if (rdtgrp->type =3D=3D RDTCTRL_GROUP) @@ -571,11 +571,12 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open= _file *of, else ret =3D -EINVAL; =20 -unlock: - rdtgroup_kn_unlock(of->kn); +out_free: free_cpumask_var(tmpmask); free_cpumask_var(newmask); free_cpumask_var(tmpmask1); +out_unlock: + rdtgroup_kn_unlock(of->kn); =20 return ret ?: nbytes; } @@ -1452,11 +1453,6 @@ static ssize_t rdtgroup_mode_write(struct kernfs_ope= n_file *of, enum rdtgrp_mode mode; int ret =3D 0; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - buf[nbytes - 1] =3D '\0'; - rdtgrp =3D rdtgroup_kn_lock_live(of->kn); if (!rdtgrp) { rdtgroup_kn_unlock(of->kn); @@ -1464,6 +1460,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_ope= n_file *of, } =20 rdt_last_cmd_clear(); + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out; + } + + buf[nbytes - 1] =3D '\0'; =20 mode =3D rdtgrp->mode; =20 @@ -1789,19 +1793,23 @@ static ssize_t mbm_total_bytes_config_write(struct = kernfs_open_file *of, struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); int ret; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + buf[nbytes - 1] =3D '\0'; =20 ret =3D mon_config_write(r, buf, QOS_L3_MBM_TOTAL_EVENT_ID); =20 +out_unlock: mutex_unlock(&rdtgroup_mutex); cpus_read_unlock(); =20 @@ -1815,19 +1823,23 @@ static ssize_t mbm_local_bytes_config_write(struct = kernfs_open_file *of, struct rdt_resource *r =3D rdt_kn_parent_priv(of->kn); int ret; =20 - /* Valid input requires a trailing newline */ - if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') - return -EINVAL; - cpus_read_lock(); mutex_lock(&rdtgroup_mutex); =20 rdt_last_cmd_clear(); =20 + /* Valid input requires a trailing newline */ + if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { + rdt_last_cmd_puts("Invalid input\n"); + ret =3D -EINVAL; + goto out_unlock; + } + buf[nbytes - 1] =3D '\0'; =20 ret =3D mon_config_write(r, buf, QOS_L3_MBM_LOCAL_EVENT_ID); =20 +out_unlock: mutex_unlock(&rdtgroup_mutex); cpus_read_unlock(); =20 --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 E364737AA77 for ; Wed, 29 Apr 2026 15:06:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475217; cv=none; b=hewenpfgQR+U8F2XHJTRSvz/b9m90T6JRhdUuVWDgJBEczAauPVHYMwX1SxV7I3Ebs+WSY7cVP/rkc4Z4IDqkI/Y3BbF+lCPFgFrMaZDr81cqKOuEJm0tJMVTBZCjOoXuGy4oyCzfvlUq0K43rAXZE4PEfNx74dgnMYufSCLsYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475217; c=relaxed/simple; bh=3Adg0a/ffzd9vkO8eZLWDW54/0mR9Ia0jl60u5Zyr/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S+KrswyF86MpEhP1aAraI90Ku5goy8Kmahkhcl6KsrPNNuIYnXcebflvb2o3J6hnu6eMeaGE7d0/5Pe/gvXyknUmtxw3WMfl5PK1UiHlIu5tjz0lBCMG+PyrxZqstnS/cWGyX+1Uag+KX5dn9g4W68A4KODEPp7/KnwHawd6MMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QWtaLbZo; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QWtaLbZo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475215; x=1809011215; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Adg0a/ffzd9vkO8eZLWDW54/0mR9Ia0jl60u5Zyr/s=; b=QWtaLbZolF3roHtW0T+pEaVaRjqihGGzvOqy/PjKyWu6V5hPWd+X+BWX HZq0/tFDZ6zs5tjB6mr/PgsV35cm/6MBceXEMMmDixjuLMB1o5oz/Jlli qF8OYLDTvT7TXGvN+SPBL0Y9at7gSpqJLfWQHxYQMep7L3YbB7p++w82g kHSkplWkTmSaZ8FEqbcY3kcXU5m/pJNsNqGkEj48S2nrnZ2R73knTB+Vz IW00FHeyU4fTbPYy4aZVp6BBe3YS9103J4MPmeS9Dx/ZcfdVNlfgj6UHK 6mCZCz7lQm5IyaJUJrYp8GUx38d9oDyUZ/MjZJVITpULLIzo6o1NEmDAE Q==; X-CSE-ConnectionGUID: 6XWSdb8lTuKogzX2Xb039g== X-CSE-MsgGUID: s9/xP/eIRZKo0wclZoqBRg== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424407" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424407" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 X-CSE-ConnectionGUID: yfKmjQ7USK22n0i0MiQYMg== X-CSE-MsgGUID: RvC6EU9sT6KfEWZVFoK3dA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445025" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 09/10] fs/resctrl: Communicate resource group deleted error via last_cmd_status Date: Wed, 29 Apr 2026 08:06:39 -0700 Message-ID: <9b55e2f83f4f779f02ae991da0859ae4b2b8df5d.1777419024.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.50.1 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" User space expects last_cmd_status to contain additional information if any resctrl command fails. A resctrl command may be blocked waiting on the rdtgroup_mutex waiting for another command to finish and find that once the mutex is available that the resource group has since been deleted. In this scenario the command will fail while last_cmd_status contains either "ok" if the last_cmd_status buffer is empty or an outdated error from a previous command failure if last_cmd_status buffer has content. Include clearing of last_cmd_status buffer as part of rdtgroup_kn_lock_live() that is used to obtain access and needed locking to a resource group before attempting a command on the group. With the last_cmd_status buffer ready, provide an appropriate message to user space if the resource group has been deleted. No last_cmd_status treatment is needed for the remaining failure of rdtgroup_kn_lock_live() encountering a non-existent resource group since that could only occur during an attempt to obtain a resource group lock on a file in info/ which is an invalid usage. Signed-off-by: Reinette Chatre --- Changes since v1: - Add snippet about why it is safe to dereference the kn to get to resource group name when resource group is deleted. --- fs/resctrl/ctrlmondata.c | 3 --- fs/resctrl/monitor.c | 2 -- fs/resctrl/rdtgroup.c | 20 +++++++++++--------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c index 5d5e844429df..26bbf4ecdbca 100644 --- a/fs/resctrl/ctrlmondata.c +++ b/fs/resctrl/ctrlmondata.c @@ -317,7 +317,6 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file= *of, rdtgroup_kn_unlock(of->kn); return -ENOENT; } - rdt_last_cmd_clear(); =20 /* Valid input requires a trailing newline */ if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { @@ -434,7 +433,6 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, } } else if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { if (!rdtgrp->plr->d) { - rdt_last_cmd_clear(); rdt_last_cmd_puts("Cache domain offline\n"); ret =3D -ENODEV; } else { @@ -475,7 +473,6 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_ope= n_file *of, rdtgroup_kn_unlock(of->kn); return -ENOENT; } - rdt_last_cmd_clear(); =20 /* Valid input requires a trailing newline */ if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c index 1a38f3b6a1f1..88f1fa0b9d8d 100644 --- a/fs/resctrl/monitor.c +++ b/fs/resctrl/monitor.c @@ -1632,7 +1632,6 @@ int mbm_L3_assignments_show(struct kernfs_open_file *= of, struct seq_file *s, voi goto out_unlock; } =20 - rdt_last_cmd_clear(); if (!resctrl_arch_mbm_cntr_assign_enabled(r)) { rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n"); ret =3D -EINVAL; @@ -1772,7 +1771,6 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_f= ile *of, char *buf, rdtgroup_kn_unlock(of->kn); return -ENOENT; } - rdt_last_cmd_clear(); =20 /* Valid input requires a trailing newline */ if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 755a46ef5bdb..0677e6e4102e 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -360,7 +360,6 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *= of, if (rdtgrp) { if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { if (!rdtgrp->plr->d) { - rdt_last_cmd_clear(); rdt_last_cmd_puts("Cache domain offline\n"); ret =3D -ENODEV; } else { @@ -523,8 +522,6 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_f= ile *of, goto out_unlock; } =20 - rdt_last_cmd_clear(); - if (!buf) { rdt_last_cmd_puts("Invalid input\n"); ret =3D -EINVAL; @@ -781,7 +778,6 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_= file *of, rdtgroup_kn_unlock(of->kn); return -ENOENT; } - rdt_last_cmd_clear(); =20 if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED || rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKSETUP) { @@ -1459,7 +1455,6 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open= _file *of, return -ENOENT; } =20 - rdt_last_cmd_clear(); /* Valid input requires a trailing newline */ if (nbytes =3D=3D 0 || buf[nbytes - 1] !=3D '\n') { rdt_last_cmd_puts("Invalid input\n"); @@ -1596,7 +1591,6 @@ static int rdtgroup_size_show(struct kernfs_open_file= *of, =20 if (rdtgrp->mode =3D=3D RDT_MODE_PSEUDO_LOCKED) { if (!rdtgrp->plr->d) { - rdt_last_cmd_clear(); rdt_last_cmd_puts("Cache domain offline\n"); ret =3D -ENODEV; } else { @@ -2634,10 +2628,20 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernf= s_node *kn) =20 cpus_read_lock(); mutex_lock(&rdtgroup_mutex); + rdt_last_cmd_clear(); =20 /* Was this group deleted while we waited? */ - if (rdtgrp->flags & RDT_DELETED) + if (rdtgrp->flags & RDT_DELETED) { + /* + * It is safe to dereference kn to obtain the resource group's + * name because one extra reference to kn is obtained + * during resource group creation that will be released by + * rdtgroup_remove() called by rdtgroup_kn_put(). + */ + rdt_last_cmd_printf("Resource group %s deleted. No commands possible.\n", + rdt_kn_name(rdtgrp->kn)); return NULL; + } =20 return rdtgrp; } @@ -3760,8 +3764,6 @@ static int mkdir_rdt_prepare(struct kernfs_node *pare= nt_kn, goto out_unlock; } =20 - rdt_last_cmd_clear(); - /* * Check that the parent directory for a monitor group is a "mon_groups" * directory. --=20 2.50.1 From nobody Wed Jun 10 17:15:29 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (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 DFC5C37B03C for ; Wed, 29 Apr 2026 15:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475215; cv=none; b=Tw5FlZG6jHprFucknbS2Tqq7VTz4HDoCVkiTWJ8b8g67BHjEH/nENGOM1SFalJD5xO4ntADmO3N7MiRH7zioSXsGnc7UY5946qKVd8LffC6kzpDlNrLbQwvvChNT4wzubTSSjSIccQB/8imi/rHT2qOvyNBzSX5rd58Ru6pzzhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777475215; c=relaxed/simple; bh=kmpz5ziyeYgyjq9BX9vfAEaKU1VXDjgMSNyT/xCR9+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hhEaEX4Yt9judouqnE7eJ7kKKcFi/pggi8TaR4odV+JxwcBA75oG7dvejLUQ38CYSsIBsZ7c3VdHGFLfwuhUTwkVGyX/JPLOHv1Ip9VUvjFC8k2WYE/Su/R43LWE8QspkV7ta31LG/REt75J+U7kodpkwOHTSSSVQqUz5ERhmaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XY4sGwHi; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XY4sGwHi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777475214; x=1809011214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kmpz5ziyeYgyjq9BX9vfAEaKU1VXDjgMSNyT/xCR9+Q=; b=XY4sGwHiKoxsgbobKfInFH+jVRqxlMCbMTlC8P+JBvUOTuraBMSCUlV6 /Lpw13VljskVSYCaFc89L0OHzT1kS8H5LTZbjEsK39xbcE4B/41TlRCkS rtmHNbKvVMtB8Ha2i8uwgZtDqKO1nAWwue39VneUoM4ja9DJjqADS6ccq QZgDv+kr3r2uYY+ktSLwuJ2YuCRx2lOJIZVW6muoZ7GJykXJ5LLRVkXVK Yz9s0rm72v92/rqbQrhmCJvFEFqe078d7ihFqfvFRXQ2V6PvAkn7HAQ5x Y02/gfau8yWnbLRAAXsYBYnff51AaQQW8ZQqxQn5ZdM6NxjjlKMwDDWic Q==; X-CSE-ConnectionGUID: O3tGG2gfQ26joOQZQns5wA== X-CSE-MsgGUID: iD/iCV8/Q0e3mbKvRQ2MmA== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78424417" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78424417" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:48 -0700 X-CSE-ConnectionGUID: bTNca9elQA2lKiXJoYjVVw== X-CSE-MsgGUID: s7ltYqU/THGPC5/H0bRN/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="233445028" Received: from rchatre-desk1.jf.intel.com ([10.165.154.99]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 08:06:47 -0700 From: Reinette Chatre To: tony.luck@intel.com, james.morse@arm.com, Dave.Martin@arm.com, babu.moger@amd.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com Cc: x86@kernel.org, hpa@zytor.com, ben.horgan@arm.com, fustini@kernel.org, fenghuay@nvidia.com, peternewman@google.com, linux-kernel@vger.kernel.org, patches@lists.linux.dev, reinette.chatre@intel.com Subject: [PATCH v4 10/10] fs/resctrl: Inform user space when status buffer overflowed Date: Wed, 29 Apr 2026 08:06:40 -0700 Message-ID: X-Mailer: git-send-email 2.50.1 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 fs commands are becoming more powerful with, for example, a user able to use syntax like '*' to make broad configuration changes. Such commands that span multiple domains may result in more than one message printed to the last_cmd_status buffer with more planned. Display "[truncated]" to user space when displaying the last_cmd_status buffer to communicate if it overflowed. Upon encountering this user space is expected to combine details about the failure found in info/last_cmd_sta= tus with related resctrl files to learn the accurate system state after the command failure. Signed-off-by: Reinette Chatre Reviewed-by: Ben Horgan --- Changes since v2: - Add Ben's RB tag. --- fs/resctrl/rdtgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 0677e6e4102e..5413a625ff32 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -971,10 +971,13 @@ static int rdt_last_cmd_status_show(struct kernfs_ope= n_file *of, =20 mutex_lock(&rdtgroup_mutex); len =3D seq_buf_used(&last_cmd_status); - if (len) + if (len) { seq_printf(seq, "%.*s", len, last_cmd_status_buf); - else + if (seq_buf_has_overflowed(&last_cmd_status)) + seq_puts(seq, "[truncated]\n"); + } else { seq_puts(seq, "ok\n"); + } mutex_unlock(&rdtgroup_mutex); return 0; } --=20 2.50.1