From patchwork Fri Jan 17 15:10:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30402C02183 for ; Fri, 17 Jan 2025 15:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mm4It2ilbjn8iPFNXdh/VHiA0ksI7sibQShLq/q6s5c=; b=08lYyj0PYBoNhgelMTpoJJPs33 xJ6ScYozZeDaFUwkA7+I5hyKsaiXYq1FA+6WLBKKrQogg7EWtbDf8ekipnazqKy9HcS+/JDB6i20n fJCKdYxa7hcdQP+eNQrCI25kzt4OXU3QY4BvXF4FVhzVWq1Z1rcD3CyFNlegehW4VBc1DVuH5R9L3 zFpZL+LclU5rbLPWXyx3ZuHV/YihIrHrOS+JVWNAD+hyqN0/zShuz1Fafslng813gLk+1oVX5X+K3 8aXQD8s7rfbs8ONPgy8fQMXwXc5joka9dUTy3s9XXf0fMgAwnxB82e0Jcd3gnlnXF9Cnpipy2n0Pl nIMqAB3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo3b-00000000aAa-1rFo; Fri, 17 Jan 2025 15:14:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzr-00000000ZE6-1if6 for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 896101691; Fri, 17 Jan 2025 07:11:21 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AA433F73F; Fri, 17 Jan 2025 07:10:52 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 01/11] arm_mpam: Fix read-back of cloned resource controls under CDP emulation Date: Fri, 17 Jan 2025 15:10:11 +0000 Message-Id: <20250117151033.1517882-2-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071055_491582_281B8584 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When reading resource control values through a resctrl schemata file, the index into the configuration array in the MPAM driver is currently translated incorrectly. This means that when resctrl is mounted with the "cdp" option, the wrong array entry may be returned or an out-of-bounds array access may occur when reading back of control values for the MB resource. Fix it by translating the index for affected resources as if they were "DATA" resources. ("CODE" would also work, but because resctrl_arch_update_one() clones schemata writes across "CODE" and "DATA" for affected resources, it does not matter which one is read.) Signed-off-by: Dave Martin --- This issue was introduced by the non-upstream commit "arm_mpam: resctrl: Improve CDP emulation" (commit b097a6193546dbbd27cd19d7e16e1e750ebb030f in git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/snapshot/v6.12-rc1 ) --- drivers/platform/arm64/mpam/mpam_resctrl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 76ddbce0ea9c..30f2caec11d7 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -1097,6 +1097,14 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops = &res->class->props; + /* + * When CDP is enabled, but the resource doesn't support it, + * the control is cloned across both partids. + * Pick one at random to read: + */ + if (mpam_resctrl_hide_cdp(r->rid)) + type = CDP_DATA; + partid = resctrl_get_config_index(closid, type); cfg = &dom->comp->cfg[partid]; From patchwork Fri Jan 17 15:10:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50417C02183 for ; Fri, 17 Jan 2025 15:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y7L9yMmJ5aTCZdUcF/ir4P0mH3+A1/6Rg2eTmdlssCI=; b=ChXIjNhsAiRiN5lSoi45tel024 fdQpfuRtgq9CFFejrE5uS8XZbk2pLeTwljDDTpNTrqzyy3Y4GCDQAab6a9th8RLEII7XcM/U3faH0 pEqb9LeUivd9lG/BCJydUuZfpVsDdzaSoKTMnLNplxWym4WeYai+wjDrPPwpKsoKkcpzMaMRri6ui HgF5pUSJi6ezcmn5ouzHYZaOjuxrS//sfb2dLwSSt0i2ZvPgGy7qB8M9VRIcUATAcwQGZOW3C429I gFHc0dJoxd4sc3NDED1DYIEuxo+fo9nAKnfrhXK51Vca0EPh4IGHyYefydmwRnwChrbP/YsipsiZw Kfmh64nA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo2M-00000000ZtF-321k; Fri, 17 Jan 2025 15:13:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzr-00000000ZET-1GoX for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:56 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 801AC2247; Fri, 17 Jan 2025 07:11:22 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6159F3F73F; Fri, 17 Jan 2025 07:10:53 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 02/11] arm_mpam: Delete unused function resctrl_arch_set_rmid() Date: Fri, 17 Jan 2025 15:10:12 +0000 Message-Id: <20250117151033.1517882-3-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071055_381225_6FB702AF X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The function resctrl_arch_set_rmid() appears to have been left behind after earlier refactoring and is now unused. To avoid needing to answer awkward questions about how this function should apply partition ID namespace remappings, just get rid of it. No functional change. Signed-off-by: Dave Martin --- I'm assuming here that there are no pending branches that implement / use this function. When moving tasks between monitoring groups, resctrlfs currently extracts the CLOSID from struct rdtgroup and passes it explicitly to resctrl_arch_set_closid_rmid(), so there seems to be no need for a separate helper that doesn't overwrite the arch's control partition identifier. --- arch/arm64/include/asm/mpam.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index e5f385767174..df725d2d9d05 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -93,20 +93,6 @@ static inline u64 mpam_get_regval(struct task_struct *tsk) #endif } -static inline void resctrl_arch_set_rmid(struct task_struct *tsk, u32 rmid) -{ -#ifdef CONFIG_ARM64_MPAM - u64 regval = mpam_get_regval(tsk); - - regval &= ~MPAM1_EL1_PMG_D; - regval &= ~MPAM1_EL1_PMG_I; - regval |= FIELD_PREP(MPAM1_EL1_PMG_D, rmid); - regval |= FIELD_PREP(MPAM1_EL1_PMG_I, rmid); - - WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval); -#endif -} - static inline void mpam_thread_switch(struct task_struct *tsk) { u64 oldregval; From patchwork Fri Jan 17 15:10:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ACE6AC02183 for ; Fri, 17 Jan 2025 15:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=88/Y1T86Rk9OCGox63BDiUo9lCggyBG2Z+INGajj/wg=; b=K6s4U5rcRULkVeEyFwHmhlfO0o gixLOg81lS1S89bo6PWfH5qlWbOX6ue0muQ+RCeDC+hFkdDv2uwSX+yd00SCMvtsA8IoqWSoAEWcb YJaQ2Lsd2Tl8DsPKuaOK3oYzFe6GC4v+6d2Y4gWo1iWIPnmARwT34IEsOR4iHKpe8UI3rFhgKHiUu nfFaikv//IyBh+EiyErCC2sRiMSLnTWsj607kTZvfMpobCW6rDgqQm1Vqcr83gvhYOeIgkDFopwR/ Kcfa9bB0oypEFEWMs4sfaopUZ8Q2CjZcm58BWUkiVysDiYLBdP3aj8+VLrOzD9FewtjJBgTVYO4Aj 5VK4cICg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo4q-00000000aSE-0Qlj; Fri, 17 Jan 2025 15:16:04 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzr-00000000ZEg-27LZ for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7738522BE; Fri, 17 Jan 2025 07:11:23 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 589223F73F; Fri, 17 Jan 2025 07:10:54 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 03/11] arm_mpam: Set INTERNAL as needed when setting MSC controls Date: Fri, 17 Jan 2025 15:10:13 +0000 Message-Id: <20250117151033.1517882-4-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071055_581685_A2978916 X-CRM114-Status: GOOD ( 12.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, when an MSC implements PARTID narrowing, MPAMCFG_PART_SEL is left set to the reqPARTID while programming resource controls in an MSC. The MPAM architecture does not guarantee that any particular resource controls will be updated correctly in this scenario. Instead, MPAMCFG_PART_SEL must be written with the corresponding intPARTID and with the INTERNAL bit set before attempting to program resource controls. Only the PARTID->intPARTID mappings can be written without the INTERNAL bit set in MPAMCFG_PART_SEL. Fix it, by rewriting MPAMCFG_PART_SEL appropriately after setting the intPARTID mapping. The MPAMCFG_INTPARTID_INTERNAL flag is not currently accepted as input to the __mpam_part_sel() helper. In the interest of keeping the code clean, break this helper up. Signed-off-by: Dave Martin Signed-off-by: James Morse --- drivers/platform/arm64/mpam/mpam_devices.c | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index 9463045c0011..f965e6639e0d 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -204,15 +204,27 @@ static u64 mpam_msc_read_esr(struct mpam_msc *msc) return (esr_high << 32) | esr_low; } +static void __mpam_part_sel_raw(u32 partsel, struct mpam_msc *msc) +{ + lockdep_assert_held(&msc->part_sel_lock); + mpam_write_partsel_reg(msc, PART_SEL, partsel); +} + static void __mpam_part_sel(u8 ris_idx, u16 partid, struct mpam_msc *msc) { - u32 partsel; + u32 partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | + FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, partid); - lockdep_assert_held(&msc->part_sel_lock); + __mpam_part_sel_raw(partsel, msc); +} - partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | - FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, partid); - mpam_write_partsel_reg(msc, PART_SEL, partsel); +static void __mpam_intpart_sel(u8 ris_idx, u16 intpartid, struct mpam_msc *msc) +{ + u32 partsel = FIELD_PREP(MPAMCFG_PART_SEL_RIS, ris_idx) | + FIELD_PREP(MPAMCFG_PART_SEL_PARTID_SEL, intpartid) | + MPAMCFG_PART_SEL_INTERNAL; + + __mpam_part_sel_raw(partsel, msc); } int mpam_register_requestor(u16 partid_max, u8 pmg_max) @@ -1530,9 +1542,11 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, mutex_lock(&msc->part_sel_lock); __mpam_part_sel(ris->ris_idx, partid, msc); - if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) + if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) { mpam_write_partsel_reg(msc, INTPARTID, MPAMCFG_INTPARTID_INTERNAL | partid); + __mpam_intpart_sel(ris->ris_idx, partid, msc); + } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { if (mpam_has_feature(mpam_feat_cpor_part, cfg)) From patchwork Fri Jan 17 15:10:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD7CCC02183 for ; Fri, 17 Jan 2025 15:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pZZpMa2kWOfpgxZ4ZtPrtKZDOSbsgN9dV/rV7uXW3EQ=; b=NaVSTSW4w3xCi+Fxc/PR//Mt2X Ace2EeebcP10rZKUSNEQaliR89w172+mXqI/6XDTy4X47apn3/ehATErVXhHk+8VtD+PcC/7gu5Js APXLr9smRZYl5hKsiLDIVQ8LHRh4uPKlG8VRK4g4YjDw/QxS/yW2Bc4u/JInHJV3nXY4SmjfQPWlF SCsQDY4rGiLRSd7xwwuxi9c8/Csa6wHYMQp/0kRkuCUJJj0toYdv3bADhVII+MjW61QP40QOmgzod zNpjCVmBdGruuWeBipQc2D2V86mem4cEwy8aIbumZItx/+Dqd3JW81pjrdcqhvtKc0HUmC0Hgf1j/ nJZiNNSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo64-00000000aeH-38xs; Fri, 17 Jan 2025 15:17:20 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzs-00000000ZFA-1RF5 for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6E0C922C7; Fri, 17 Jan 2025 07:11:24 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F98B3F73F; Fri, 17 Jan 2025 07:10:55 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 04/11] fs/resctrl: Add arch hook to set up the default CLOSID Date: Fri, 17 Jan 2025 15:10:14 +0000 Message-Id: <20250117151033.1517882-5-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071056_476048_58151C88 X-CRM114-Status: GOOD ( 16.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, the resctrl core code assumes that CLOSID 0 requires no special initialisation before use. This is true on x86, but may not be true on other architectures (including Arm MPAM, in certain configurations). Since the allocation of CLOSIDs can depend on parameters such as resctrl filesystem mount options that are not available at arch driver init time, an arch hook is needed to set up the default CLOSID when the resctrl filesystem is mounted. Add a suitable arch hook resctrl_arch_init_domains(). Wire it up to arch stubs that do nothing, for now. (This is also the right thing for x86.) No functional change. Signed-off-by: Dave Martin --- arch/x86/include/asm/resctrl.h | 12 ++++++++++++ fs/resctrl/rdtgroup.c | 26 ++++++++++++++++++++++++-- include/linux/arm_mpam.h | 10 ++++++++++ include/linux/resctrl.h | 2 ++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/resctrl.h b/arch/x86/include/asm/resctrl.h index 332b0617d728..b5fbb94e756a 100644 --- a/arch/x86/include/asm/resctrl.h +++ b/arch/x86/include/asm/resctrl.h @@ -50,6 +50,18 @@ DECLARE_STATIC_KEY_FALSE(rdt_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key); DECLARE_STATIC_KEY_FALSE(rdt_mon_enable_key); +/* The default CLOSID needs no special setup on x86: */ +static inline bool resctrl_arch_default_closid_needs_init(void) +{ + return false; +} + +/* ... so this won't be needed either: */ +static inline int resctrl_arch_init_domains(struct rdt_resource *r, u32 closid) +{ + return 0; +} + static inline bool resctrl_arch_alloc_capable(void) { return rdt_alloc_capable; diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c index 30f1dd05e10b..200f92e8f619 100644 --- a/fs/resctrl/rdtgroup.c +++ b/fs/resctrl/rdtgroup.c @@ -65,6 +65,8 @@ static struct seq_buf last_cmd_status; static char last_cmd_status_buf[512]; +static int rdtgroup_init_first_alloc(struct rdtgroup *rdtgrp); + static int rdtgroup_setup_root(struct rdt_fs_context *ctx); static void rdtgroup_destroy_root(void); @@ -2542,6 +2544,9 @@ static int rdt_get_tree(struct fs_context *fc) } closid_init(); + ret = rdtgroup_init_first_alloc(&rdtgroup_default); + if (ret) + goto out_schemata_free; if (resctrl_arch_mon_capable()) flags |= RFTYPE_MON; @@ -3230,7 +3235,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid) } /* Initialize the RDT group's allocations. */ -static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) +static int __rdtgroup_init_alloc(struct rdtgroup *rdtgrp, bool first_time_init) { struct resctrl_schema *s; struct rdt_resource *r; @@ -3251,7 +3256,11 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) goto out; } - ret = resctrl_arch_update_domains(r, rdtgrp->closid); + if (first_time_init) + ret = resctrl_arch_init_domains(r, rdtgrp->closid); + else + ret = resctrl_arch_update_domains(r, rdtgrp->closid); + if (ret < 0) { rdt_last_cmd_puts("Failed to initialize allocations\n"); goto out; @@ -3265,6 +3274,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) return ret; } +static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) +{ + return __rdtgroup_init_alloc(rdtgrp, false); +} + +static int rdtgroup_init_first_alloc(struct rdtgroup *rdtgrp) +{ + if (!resctrl_arch_default_closid_needs_init()) + return 0; + + return __rdtgroup_init_alloc(rdtgrp, true); +} + static int mkdir_rdt_prepare_rmid_alloc(struct rdtgroup *rdtgrp) { int ret; diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index c00b5fc1d235..dd5f18474846 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -45,6 +45,16 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val) return val; } +static inline bool resctrl_arch_default_closid_needs_init(void) +{ + return false; +} + +static inline int resctrl_arch_init_domains(struct rdt_resource *r, u32 closid) +{ + return 0; +} + bool resctrl_arch_alloc_capable(void); bool resctrl_arch_mon_capable(void); bool resctrl_arch_is_llc_occupancy_enabled(void); diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index be9d9f4c7b81..fc00b080f1a1 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -371,6 +371,8 @@ u32 resctrl_arch_system_num_rmid_idx(void); struct rdt_domain_hdr *resctrl_arch_find_domain(struct list_head *domain_list, int id); +bool resctrl_arch_default_closid_needs_init(void); +int resctrl_arch_init_domains(struct rdt_resource *r, u32 closid); int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid); bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); From patchwork Fri Jan 17 15:10:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C80EEC02183 for ; Fri, 17 Jan 2025 15:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/SgKZT/g5qzLU/t2GhOBl1tQoCgwhOkpzHqkvoVCzRg=; b=0nF92WPZTeWQY/uNcpzgddKumQ eSVZFX+8wWmOU56//4KyfiOnecYexz7yuWys+tJPmiTnBf8/p5NfOe3DXCSOBPhGsMfySpROu+eMJ mw0hcmfRn3pspHtvGK0vABVU6T249EKHpuM9CVU0s/uJ816teaHKTA8BX1hQIsEXw/LQkzLx/ukQz GmZadVOP/QkagLYODPZEV0FBYfVnG7HejHZvXpWtJUruMnlusaFoVx8fj2P+M019SkG3d7IZw7a0x Kjz4npkCoVbAkShZzvDMjM4p2qBCjCUTa2AO+k9e2cWWBHP/otu0c7aYCYTD3FlNEkosUB8TNj7NB Ik/Lak3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo7J-00000000aq8-1Xkd; Fri, 17 Jan 2025 15:18:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzt-00000000ZFe-1FQG for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 64E1322C8; Fri, 17 Jan 2025 07:11:25 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4662E3F73F; Fri, 17 Jan 2025 07:10:56 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 05/11] arm_mpam: resctrl: Implement arch hook to set up the default CLOSID Date: Fri, 17 Jan 2025 15:10:15 +0000 Message-Id: <20250117151033.1517882-6-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071057_387471_01456501 X-CRM114-Status: GOOD ( 12.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since the allocation of CLOSIDs can now depend on parameters such as resctrl filesystem mount options that are not available at arch driver init time, all MPAM resource allocations need to be reprogrammed when resctrl is mounted. Implement resctrl_arch_init_domains() so that resctrl will now reprogram the default CLOSID's resource allocations at filesystem mount time, in the same way as when creating a new resctrl control group. Signed-off-by: Dave Martin --- drivers/platform/arm64/mpam/mpam_resctrl.c | 15 +++++++++++++-- include/linux/arm_mpam.h | 7 +------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index 30f2caec11d7..aa8a6c077918 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -1209,7 +1209,8 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, } /* TODO: this is IPI heavy */ -int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) +static int __resctrl_arch_update_domains(struct rdt_resource *r, u32 closid, + bool force) { int err = 0; enum resctrl_conf_type t; @@ -1222,7 +1223,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) list_for_each_entry(d, &r->ctrl_domains, hdr.list) { for (t = 0; t < CDP_NUM_TYPES; t++) { cfg = &d->staged_config[t]; - if (!cfg->have_new_ctrl) + if (!force && !cfg->have_new_ctrl) continue; err = resctrl_arch_update_one(r, d, closid, t, @@ -1235,6 +1236,16 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) return err; } +int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) +{ + return __resctrl_arch_update_domains(r, closid, false); +} + +int resctrl_arch_init_domains(struct rdt_resource *r, u32 closid) +{ + return __resctrl_arch_update_domains(r, closid, true); +} + void resctrl_arch_reset_resources(void) { int i, idx; diff --git a/include/linux/arm_mpam.h b/include/linux/arm_mpam.h index dd5f18474846..e6b188ab735b 100644 --- a/include/linux/arm_mpam.h +++ b/include/linux/arm_mpam.h @@ -47,12 +47,7 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val) static inline bool resctrl_arch_default_closid_needs_init(void) { - return false; -} - -static inline int resctrl_arch_init_domains(struct rdt_resource *r, u32 closid) -{ - return 0; + return true; } bool resctrl_arch_alloc_capable(void); From patchwork Fri Jan 17 15:10:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 445A7C02183 for ; Fri, 17 Jan 2025 15:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QitnK0ytXNvjWSL2ZdU07Uu+ftrgxcG/+yNwzZN9c8E=; b=nM13Xq0wvhL8G9DCIdGuOECIG0 9Nl6nbYyN+e73Bkwo1Rqs0dz1b81n74T82FMO1C7jQ/Hs2tYIQ9TfUivnSKnEh+w1wbnIrK3Wq7+a ekw/8Rrvd9fa50RtsgxR4bE1ygSSJKyR6s8rtP3SxG6FezZ5ZWNJUQLXymE2Ku6YOAxs3Lpv+jvKo 2Iec4ffOSfqst0Huk9Dy13HOiH1dFbedAVCdDNkmFREcJx2Oi7rYW5BmsmXg+GZcj5cIj5XB3RrHc zYoSzS0qH9+DH0M5g0gkV0LTMEbI/XQ+b8GvmHjE5xgiSarDSHBlnxwxSCabqlIj4U3334AoRLxvC moFrUtTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo8Y-00000000b8J-0JBi; Fri, 17 Jan 2025 15:19:54 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzu-00000000ZFe-2kuo for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:10:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 763F31476; Fri, 17 Jan 2025 07:11:26 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3DCDA3F73F; Fri, 17 Jan 2025 07:10:57 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 06/11] arm_mpam: Introduce flexible CLOSID/RMID translation Date: Fri, 17 Jan 2025 15:10:16 +0000 Message-Id: <20250117151033.1517882-7-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071058_780184_39D636F0 X-CRM114-Status: GOOD ( 29.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, the MPAM driver uses the resctrl CLOSID directly as the MPAM Partition Identifier (PARTID; possibly modified to give different PARTIDs to code and data when Code/Data Partitioning / CDP is enabled), and uses the resctrl RMID directly as the MPAM Performance Monitoring Group identifier (PMG). In preparation for using the MPAM PARTID Narrowing feature to allow more resctrl monitoring groups to be provided than the number of PMG values supported by the hardware, a more flexible remapping scheme is needed. Factor out ID translation operations in the MPAM resctrl glue code into a couple of self-contained helpers, and call them as appropriate. The translation scheme has a single parameter, partid_per_closid, which is currently hard-wired to 1. As a result, this patch should have no effect on functionality. Logic to determine / control the mapping parameters can be introduced later. The ID transformation may be visualised as follows: without CDP: +---------------------------------------------------+-----------+ | CLOSID | RMID | +---------------------------------------------------+-------+---+ | PARTID : |PMG| +-----------------------------------------------------------+---+ and with CDP, where the "CDP" field is 0 for the data sub- partition and 1 for the code sub-partition: +-----------------------------------------------+---+-----------+ | CLOSID |CDP| RMID | +-----------------------------------------------+---+-------+---+ | PARTID : |PMG| +-----------------------------------------------------------+---+ where each box represents a non-negative integer spanning some fixed range starting from zero, and horizontal concatenation denotes multiplying the value denoted by the left-hand box by the span of the right-hand box, and adding the result to the value denoted by the right-hand box; thus, most-significant fields are on the left. (Except for the span of each field not necessarily being a power of two, this is conceptually identical to concatenation and cutting of bitfields.) The dotted segment indicates the least significant part of PARTID, which spans partid_per_closid PARTIDs and discriminates monitoring groups that use the same MPAM PMG value. Signed-off-by: Dave Martin --- Changes since RFCv1: * [bugfix] Add CDP index properly in mpam_resctrl_partid_range(). (Also reported by Shaopeng Tan.) * [relaxation] Remove requirement that mpam_pmg_max + 1 is a power of two. (This constraint is redundant, due to the use of multiply/add transformations of MPAM IDs in place of shift/OR.) --- drivers/platform/arm64/mpam/mpam_resctrl.c | 211 +++++++++++---------- 1 file changed, 112 insertions(+), 99 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index aa8a6c077918..f834753a3274 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -156,6 +156,18 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid) return cdp_enabled && !resctrl_arch_get_cdp_enabled(rid); } +static unsigned int partid_per_closid = 1; + +static unsigned int mpam_num_pmg(void) +{ + return mpam_pmg_max + 1; +} + +static unsigned int mpam_num_rmid(void) +{ + return mpam_num_pmg() * partid_per_closid; +} + /* * MSC may raise an error interrupt if it sees an out or range partid/pmg, * and go on to truncate the value. Regardless of what the hardware supports, @@ -163,35 +175,73 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid) */ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) { - return mpam_partid_max + 1; + u32 res = (mpam_partid_max + 1) / partid_per_closid; + + WARN_ON(res < 1); + return res; } -u32 resctrl_arch_system_num_rmid_idx(void) +static void mpam_resctrl_partid_range(u32 closid, enum resctrl_conf_type type, + const struct rdt_resource *r, + u16 *min_partid, u16 *max_partid) { - u8 closid_shift = fls(mpam_pmg_max); - u32 num_partid = resctrl_arch_get_num_closid(NULL); + u16 base_partid = closid; + u16 span = 1; - return num_partid << closid_shift; + if (cdp_enabled) { + base_partid *= 2; + if (mpam_resctrl_hide_cdp(r->rid) || + type == CDP_NONE) + span *= 2; + else if (type == CDP_CODE) + base_partid++; + } + + *min_partid = base_partid * partid_per_closid; + if (max_partid) + *max_partid = *min_partid + (span * partid_per_closid - 1); } -u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) +static void mpam_resctrl_hwid(u32 closid, u32 rmid, + u16 *partid_d, u16 *partid_i, u8 *pmg) { - u8 closid_shift = fls(mpam_pmg_max); + const u16 pmg_hi = rmid / mpam_num_pmg(); + const u16 pmg_lo = rmid % mpam_num_pmg(); + u16 base_partid = closid; + u16 partid_stride = 0; + + if (cdp_enabled) { + base_partid *= 2; + partid_stride = 1; + } + + partid_stride *= partid_per_closid; + base_partid *= partid_per_closid; + base_partid += pmg_hi; - BUG_ON(closid_shift > 8); + *partid_d = base_partid; + if (partid_i) + *partid_i = base_partid + partid_stride; - return (closid << closid_shift) | rmid; + *pmg = pmg_lo; } -void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) +u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) +{ + return closid * mpam_num_rmid() + rmid; +} + +u32 resctrl_arch_system_num_rmid_idx(void) { - u8 closid_shift = fls(mpam_pmg_max); - u32 pmg_mask = ~(~0 << closid_shift); + u32 num_closid = resctrl_arch_get_num_closid(NULL); - BUG_ON(closid_shift > 8); + return resctrl_arch_rmid_idx_encode(num_closid, 0); +} - *closid = idx >> closid_shift; - *rmid = idx & pmg_mask; +void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) +{ + *closid = idx / mpam_num_rmid(); + *rmid = idx % mpam_num_rmid(); } void resctrl_arch_sched_in(struct task_struct *tsk) @@ -203,21 +253,14 @@ void resctrl_arch_sched_in(struct task_struct *tsk) void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid) { + u16 partid_d, partid_i; + u8 pmg; + BUG_ON(closid > U16_MAX); BUG_ON(rmid > U8_MAX); - if (!cdp_enabled) { - mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid); - } else { - /* - * When CDP is enabled, resctrl halves the closid range and we - * use odd/even partid for one closid. - */ - u32 partid_d = resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i = resctrl_get_config_index(closid, CDP_CODE); - - mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid); - } + mpam_resctrl_hwid(closid, rmid, &partid_d, &partid_i, &pmg); + mpam_set_cpu_defaults(cpu, partid_d, partid_i, pmg, pmg); } void resctrl_arch_sync_cpu_closid_rmid(void *info) @@ -236,41 +279,38 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info) void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { + u16 partid_d, partid_i; + u8 pmg; + BUG_ON(closid > U16_MAX); BUG_ON(rmid > U8_MAX); - if (!cdp_enabled) { - mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid); - } else { - u32 partid_d = resctrl_get_config_index(closid, CDP_DATA); - u32 partid_i = resctrl_get_config_index(closid, CDP_CODE); - - mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid); - } + mpam_resctrl_hwid(closid, rmid, &partid_d, &partid_i, &pmg); + mpam_set_task_partid_pmg(tsk, partid_d, partid_i, pmg, pmg); } bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid) { + u16 min_partid, max_partid; u64 regval = mpam_get_regval(tsk); u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); - if (cdp_enabled) - tsk_closid >>= 1; - - return tsk_closid == closid; + mpam_resctrl_partid_range(closid, CDP_NONE, NULL, + &min_partid, &max_partid); + return tsk_closid >= min_partid && tsk_closid <= max_partid; } /* The task's pmg is not unique, the partid must be considered too */ bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid) { + u16 partid_d; + u8 pmg; u64 regval = mpam_get_regval(tsk); - u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); - u32 tsk_rmid = FIELD_GET(MPAM1_EL1_PMG_D, regval); - - if (cdp_enabled) - tsk_closid >>= 1; + u16 tsk_partid_d = FIELD_GET(MPAM1_EL1_PARTID_D, regval); + u8 tsk_pmg = FIELD_GET(MPAM1_EL1_PMG_D, regval); - return (tsk_closid == closid) && (tsk_rmid == rmid); + mpam_resctrl_hwid(closid, rmid, &partid_d, NULL, &pmg); + return (tsk_partid_d == partid_d) && (tsk_pmg == pmg); } struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) @@ -370,6 +410,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, struct mpam_resctrl_dom *dom; u32 mon = *(u32 *)arch_mon_ctx; enum mpam_device_features type; + u16 partid_d, partid_i, pmg; resctrl_arch_rmid_read_context_check(); @@ -391,27 +432,23 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d, if (cfg.mon == USE_RMID_IDX) cfg.mon = resctrl_arch_rmid_idx_encode(closid, rmid); + mpam_resctrl_hwid(closid, rmid, &partid_d, &partid_i, &cfg.pmg); cfg.match_pmg = true; - cfg.pmg = rmid; + cfg.pmg = pmg; cfg.opts = resctrl_evt_config_to_mpam(dom->mbm_local_evt_cfg); if (irqs_disabled()) { /* Check if we can access this domain without an IPI */ err = -EIO; } else { - if (cdp_enabled) { - cfg.partid = closid << 1; - err = mpam_msmon_read(dom->comp, &cfg, type, val); - if (err) - return err; + cfg.partid = partid_d; + err = mpam_msmon_read(dom->comp, &cfg, type, val); - cfg.partid += 1; + if (partid_i != partid_d) { + cfg.partid = partid_i; err = mpam_msmon_read(dom->comp, &cfg, type, &cdp_val); if (!err) *val += cdp_val; - } else { - cfg.partid = closid; - err = mpam_msmon_read(dom->comp, &cfg, type, val); } } @@ -423,6 +460,7 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d, { struct mon_cfg cfg; struct mpam_resctrl_dom *dom; + u16 partid_d, partid_i; if (eventid != QOS_L3_MBM_LOCAL_EVENT_ID) return; @@ -433,14 +471,13 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom); - if (cdp_enabled) { - cfg.partid = closid << 1; - mpam_msmon_reset_mbwu(dom->comp, &cfg); + mpam_resctrl_hwid(closid, rmid, &partid_d, &partid_i, &cfg.pmg); - cfg.partid += 1; - mpam_msmon_reset_mbwu(dom->comp, &cfg); - } else { - cfg.partid = closid; + cfg.partid = partid_d; + mpam_msmon_reset_mbwu(dom->comp, &cfg); + + if (partid_i != partid_d) { + cfg.partid = partid_i; mpam_msmon_reset_mbwu(dom->comp, &cfg); } } @@ -1051,15 +1088,6 @@ int mpam_resctrl_setup(void) err = -EOPNOTSUPP; if (!err) { - if (!is_power_of_2(mpam_pmg_max + 1)) { - /* - * If not all the partid*pmg values are valid indexes, - * resctrl may allocate pmg that don't exist. This - * should cause an error interrupt. - */ - pr_warn("Number of PMG is not a power of 2! resctrl may misbehave"); - } - err = resctrl_init(); if (!err) WRITE_ONCE(resctrl_enabled, true); @@ -1081,7 +1109,7 @@ static void mpam_resctrl_exit(void) u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, u32 closid, enum resctrl_conf_type type) { - u32 partid; + u16 partid; struct mpam_config *cfg; struct mpam_props *cprops; struct mpam_resctrl_res *res; @@ -1097,15 +1125,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops = &res->class->props; - /* - * When CDP is enabled, but the resource doesn't support it, - * the control is cloned across both partids. - * Pick one at random to read: - */ - if (mpam_resctrl_hide_cdp(r->rid)) - type = CDP_DATA; - - partid = resctrl_get_config_index(closid, type); + mpam_resctrl_partid_range(closid, type, r, &partid, NULL); cfg = &dom->comp->cfg[partid]; switch (r->rid) { @@ -1126,7 +1146,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, return -EINVAL; } - if (!r->alloc_capable || partid >= resctrl_arch_get_num_closid(r) || + if (!r->alloc_capable || partid > mpam_partid_max || !mpam_has_feature(configured_by, cfg)) return resctrl_get_default_ctrl(r); @@ -1147,8 +1167,8 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, u32 closid, enum resctrl_conf_type t, u32 cfg_val) { - int err; - u32 partid; + int err = 0; + u16 partid, min_partid, max_partid; struct mpam_config cfg; struct mpam_props *cprops; struct mpam_resctrl_res *res; @@ -1163,8 +1183,10 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops = &res->class->props; - partid = resctrl_get_config_index(closid, t); - if (!r->alloc_capable || partid >= resctrl_arch_get_num_closid(r)) + mpam_resctrl_partid_range(closid, t, r, &min_partid, &max_partid); + if (!r->alloc_capable || + min_partid > mpam_partid_max || + max_partid > mpam_partid_max) return -EINVAL; cfg.features = 0; @@ -1190,22 +1212,13 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, return -EINVAL; } - /* - * When CDP is enabled, but the resource doesn't support it, we need to - * apply the same configuration to the other partid. - */ - if (mpam_resctrl_hide_cdp(r->rid)) { - partid = resctrl_get_config_index(closid, CDP_CODE); + for (partid = min_partid; partid <= max_partid; partid++) { err = mpam_apply_config(dom->comp, partid, &cfg); if (err) - return err; - - partid = resctrl_get_config_index(closid, CDP_DATA); - return mpam_apply_config(dom->comp, partid, &cfg); - - } else { - return mpam_apply_config(dom->comp, partid, &cfg); + break; } + + return err; } /* TODO: this is IPI heavy */ From patchwork Fri Jan 17 15:10:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3CC2C02183 for ; Fri, 17 Jan 2025 15:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ONJgNMzxClMztzX9/gp9gMBjGA6j/fpzTGTPGO/ELgc=; b=SkzMMsG1orXyFOqwT1Nb7x6B6j d1s/Dh4KT3yoAdlZS6hl7TLL11akftOPTpQEOQw0VAlTYiWmY74Uw5baNlauiSxf8YKpXakdegcAw AylwLZ7zrld5zleniRcNYCuUZJai8C2ROJuhXqD4Kw3YM6YvfgJaf9B5rvZUnvvyxNww+2s8OAmjy J3IqCdr5Np/ah9QK9HLfK7W+yVjPC3BVAgQOPbJnsoJjBiKoMC/nQoNG8aQ23Qy6XXMG71dLW0zLW Yszgbf9bigDTC4n+lGRlLFjOJzWgR7vn3xMrO5atTbztLyB89LiZ5wst+vOz3ILjQhYATYyfArCQQ vDM3mkrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYo9m-00000000bOf-2p6Y; Fri, 17 Jan 2025 15:21:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzv-00000000ZGb-1jkQ for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:11:00 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D1E41691; Fri, 17 Jan 2025 07:11:27 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4EA0C3F73F; Fri, 17 Jan 2025 07:10:58 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 07/11] arm_mpam: [NFU] Rework ID remapping to use a kernel command-line argument Date: Fri, 17 Jan 2025 15:10:17 +0000 Message-Id: <20250117151033.1517882-8-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071059_494341_96C55B70 X-CRM114-Status: GOOD ( 12.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hacking the source is an acceptable interface for experimentation, but not very convenient. Instead, add a kernel command-line parameter mpam_partid_per_closid= to specify how many PARTIDs are used to provide monitoring groups for each resctrl CLOSID. This change is not intended for upstream. Signed-off-by: Dave Martin --- drivers/platform/arm64/mpam/mpam_resctrl.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index f834753a3274..eb1ef5d2bc57 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -3,6 +3,9 @@ #define pr_fmt(fmt) "mpam: resctrl: " fmt +#undef KBUILD_MODNAME +#define KBUILD_MODNAME "mpam" + #include #include #include @@ -10,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -158,6 +162,24 @@ static bool mpam_resctrl_hide_cdp(enum resctrl_res_level rid) static unsigned int partid_per_closid = 1; +static int mpam_resctrl_partid_per_closid_set(const char *val, + const struct kernel_param *kp) +{ + /* + * 16 in an arbitrary maximum, sufficient for experimentation + * but not ridiculously large: + */ + return param_set_uint_minmax(val, kp, 1, 16); +} + +static const struct kernel_param_ops mpam_resctrl_partid_per_closid_ops = { + .set = mpam_resctrl_partid_per_closid_set, + .get = param_get_uint, +}; + +device_param_cb(partid_per_closid, &mpam_resctrl_partid_per_closid_ops, + &partid_per_closid, 0444); + static unsigned int mpam_num_pmg(void) { return mpam_pmg_max + 1; From patchwork Fri Jan 17 15:10:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9A11C02183 for ; Fri, 17 Jan 2025 15:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1tBjEEqLvWWoIr6bLTxyaV5TCWMZaIId035SXrAuM/8=; b=DHlSEjgnrOmBjjrrCES8kLrZvE gfxPaXwr60tPQufKAY1CF7inVoF6FDZV9eJwbdZCb84470b5bAhXeZt+uadk0CO9ZQV02txgAnBuz abb050D9tzNB5kn82ZY6DNBNFuFvtFpWlubRdSTmpvG6cNz/4nPn+g0l6opk/u/Ae1leS7lww3800 BOhAJ1OaZutbdPShixIx6vJQRqJI8tDO3EwSD4f2KkYHWHTucNZI2DOMGfvnlIAanwuyWNR+wFSXo v38AOlA5KcaVPpmo+rrr7WxWQswjOB2XwqW1ldv9ceI3rNJPfnneJJiLnALw2LCr7iqL7uGqsCGcw BFbD6f9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYoB1-00000000bb9-1Mr2; Fri, 17 Jan 2025 15:22:27 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzw-00000000ZFe-0gYA for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:11:01 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6427422D9; Fri, 17 Jan 2025 07:11:28 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 457D33F73F; Fri, 17 Jan 2025 07:10:59 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 08/11] arm_mpam: [NFU] Development diagnostics for MPAM ID assignments Date: Fri, 17 Jan 2025 15:10:18 +0000 Message-Id: <20250117151033.1517882-9-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071100_238940_B1441FDF X-CRM114-Status: UNSURE ( 8.16 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Purely for development purposes, add some printks to show what MPAM IDs actually get assigned and configured. This would otherwise be observable only though statistical measurements of performance (or not observable at all). This change is not intended for upstream. Signed-off-by: Dave Martin --- arch/arm64/include/asm/mpam.h | 7 +++++++ drivers/platform/arm64/mpam/mpam_devices.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/mpam.h b/arch/arm64/include/asm/mpam.h index df725d2d9d05..4ae2e635e261 100644 --- a/arch/arm64/include/asm/mpam.h +++ b/arch/arm64/include/asm/mpam.h @@ -66,6 +66,9 @@ static inline void mpam_set_cpu_defaults(int cpu, u16 partid_d, u16 partid_i, default_val |= FIELD_PREP(MPAM1_EL1_PMG_I, pmg_i); WRITE_ONCE(per_cpu(arm64_mpam_default, cpu), default_val); + + pr_info("MPAM: CPU%d -> (D=%d:%d, I=%d:%d)\n", + cpu, partid_d, pmg_d, partid_i, pmg_i); } static inline void mpam_set_task_partid_pmg(struct task_struct *tsk, @@ -81,6 +84,10 @@ static inline void mpam_set_task_partid_pmg(struct task_struct *tsk, regval |= FIELD_PREP(MPAM1_EL1_PMG_I, pmg_i); WRITE_ONCE(task_thread_info(tsk)->mpam_partid_pmg, regval); + + pr_info("MPAM: task %s[%d/%d] -> (D=%d:%d, I=%d:%d)\n", + current->comm, current->pid, current->tgid, + partid_d, pmg_d, partid_i, pmg_i); #endif } diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index f965e6639e0d..6b326506c359 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -3149,6 +3149,12 @@ int mpam_apply_config(struct mpam_component *comp, u16 partid, mpam_extend_config(comp->class, cfg); + pr_info("mpam_apply_config(): comp %d partid %d cfg={0x%x: 0x%lx, 0x%lx, %u, %u}\n", + comp->comp_id, partid, cfg->features, + (unsigned long)cfg->cpbm, + (unsigned long)cfg->mbw_pbm, + cfg->mbw_min, cfg->mbw_max); + if (!mpam_update_config(&comp->cfg[partid], cfg)) return 0; From patchwork Fri Jan 17 15:10:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D32D7C02183 for ; Fri, 17 Jan 2025 15:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RwBiR0KoJJNeOuXY8pezhnJ02fB7ERpTlTC6BUe2pNU=; b=yfqGpNDiZs2paFLMow8xYe0ZYG kkqHRtFW4xUotl6DPhtmoeb+AIqR0MSuSO6294mBvj6evCe15AhJY9LYWcu39jKZcfjW0z/S4lOHr NtKfKWuFNMZkpfj9CzmM5ouqwgkCGeO4x8YdTNAf06f2a2f9OpOyyHuscmYF/I8mRwUcL8RSsjjxz Nb4frVx8e/NocHBJCWP1VYkkEcZSeduBdugzEBkS2cbgpLFu2BMWIZZGh6C0JxLKzWlco3AnWSQWp XyRbvj5PLSRg/JUrbLyiSfu9B4peIlMqMZ0ntDmiYgBGhsXtChPRtYRmDCsIeOt4UAFtpUg5q+EMr eqTmAFQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYoCE-00000000blV-3yDT; Fri, 17 Jan 2025 15:23:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzx-00000000ZGb-2GuX for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:11:02 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5B32C1476; Fri, 17 Jan 2025 07:11:29 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C8DF3F73F; Fri, 17 Jan 2025 07:11:00 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 09/11] arm_mpam: Add control partition identifier to mpam_config Date: Fri, 17 Jan 2025 15:10:19 +0000 Message-Id: <20250117151033.1517882-10-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071101_666637_CE9675AF X-CRM114-Status: GOOD ( 17.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, MPAM PARTIDs are assigned 1:1 to resctrl control groups. This means that an MSC that implements PARTID Narrowing can simply program the PARTID value for intPARTID where needed. In order to enable multiple PARTIDs to be assigned to a single control group in a flexible manner, the PARTID value cannot be used directly for the intPARTID, so in the mpam_devices backend, Narrowing MSCs need an explicit identifier for the control / resource regulation group. Add a field cpartid to struct mpam_config to hold this identifier, and wire up the resctrl glue code to pass a suitable value. In common with the handling of other parameters, make programming of MPAMCFG_INTPARTID unconditional when applying control updates. When no cpartid is supplied, e.g., during driver startup, intPARTID is programmed with 0. (There is no architectural reset value for MPAMCFG_INTPARTID even for PARTID 0, but the architecture can be interpreted as suggesting intPARTID 0 as the default, so this is as good a choice as any.) Control updates through resctrl will always supply a cpartid, identifying the affected resctrl control partition. Signed-off-by: Dave Martin --- drivers/platform/arm64/mpam/mpam_devices.c | 10 ++++++++-- drivers/platform/arm64/mpam/mpam_internal.h | 7 +++++++ drivers/platform/arm64/mpam/mpam_resctrl.c | 16 +++++++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index 6b326506c359..4b43dfef1cdc 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -1531,6 +1531,7 @@ static void mpam_quirk_post_config_change(struct mpam_msc_ris *ris, u16 partid, static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, struct mpam_config *cfg) { + u16 intpartid = 0; u32 pri_val = 0; u16 cmax = MPAMCFG_CMAX_CMAX; u16 bwa_fract = MPAMCFG_MBW_MAX_MAX; @@ -1543,9 +1544,13 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, __mpam_part_sel(ris->ris_idx, partid, msc); if (mpam_has_feature(mpam_feat_partid_nrw, rprops)) { + if (mpam_has_feature(mpam_feat_partid_nrw, cfg)) + intpartid = cfg->cpartid; + mpam_write_partsel_reg(msc, INTPARTID, - MPAMCFG_INTPARTID_INTERNAL | partid); - __mpam_intpart_sel(ris->ris_idx, partid, msc); + MPAMCFG_INTPARTID_INTERNAL | intpartid); + + __mpam_intpart_sel(ris->ris_idx, intpartid, msc); } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { @@ -3084,6 +3089,7 @@ static mpam_features_t mpam_update_config(struct mpam_config *cfg, { mpam_features_t changes = 0; + maybe_update_config(cfg, mpam_feat_partid_nrw, newcfg, cpartid, changes); maybe_update_config(cfg, mpam_feat_cpor_part, newcfg, cpbm, changes); maybe_update_config(cfg, mpam_feat_mbw_part, newcfg, mbw_pbm, changes); maybe_update_config(cfg, mpam_feat_mbw_max, newcfg, mbw_max, changes); diff --git a/drivers/platform/arm64/mpam/mpam_internal.h b/drivers/platform/arm64/mpam/mpam_internal.h index 5af6ed60272e..965f4fea3012 100644 --- a/drivers/platform/arm64/mpam/mpam_internal.h +++ b/drivers/platform/arm64/mpam/mpam_internal.h @@ -300,6 +300,13 @@ struct mpam_config { u16 mbw_max; u16 mbw_min; + /* + * Control partition; resource regulation context for stateful controls + * Valid if features has mpam_feat_partid_nrw. + * For MSCs that implement PARTID Narrowing, this is intPARTID. + */ + u16 cpartid; + struct mpam_garbage garbage; }; diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index eb1ef5d2bc57..f1d0d9f59771 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -205,7 +205,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *ignored) static void mpam_resctrl_partid_range(u32 closid, enum resctrl_conf_type type, const struct rdt_resource *r, - u16 *min_partid, u16 *max_partid) + u16 *min_partid, u16 *max_partid, + u16 *cpartid) { u16 base_partid = closid; u16 span = 1; @@ -222,6 +223,9 @@ static void mpam_resctrl_partid_range(u32 closid, enum resctrl_conf_type type, *min_partid = base_partid * partid_per_closid; if (max_partid) *max_partid = *min_partid + (span * partid_per_closid - 1); + + if (cpartid) + *cpartid = base_partid; } static void mpam_resctrl_hwid(u32 closid, u32 rmid, @@ -318,7 +322,7 @@ bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid) u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval); mpam_resctrl_partid_range(closid, CDP_NONE, NULL, - &min_partid, &max_partid); + &min_partid, &max_partid, NULL); return tsk_closid >= min_partid && tsk_closid <= max_partid; } @@ -1147,7 +1151,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops = &res->class->props; - mpam_resctrl_partid_range(closid, type, r, &partid, NULL); + mpam_resctrl_partid_range(closid, type, r, &partid, NULL, NULL); cfg = &dom->comp->cfg[partid]; switch (r->rid) { @@ -1205,13 +1209,15 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain *d, dom = container_of(d, struct mpam_resctrl_dom, resctrl_ctrl_dom); cprops = &res->class->props; - mpam_resctrl_partid_range(closid, t, r, &min_partid, &max_partid); + cfg.features = 0; + mpam_set_feature(mpam_feat_partid_nrw, &cfg); + mpam_resctrl_partid_range(closid, t, r, &min_partid, &max_partid, + &cfg.cpartid); if (!r->alloc_capable || min_partid > mpam_partid_max || max_partid > mpam_partid_max) return -EINVAL; - cfg.features = 0; switch (r->rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: From patchwork Fri Jan 17 15:10:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED9CFC02183 for ; Fri, 17 Jan 2025 15:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7/ysBhP73KBKKeuY3njuqxvc7WsSQpiMxy9XgBQloPo=; b=zVYQ7Pp38kdAt7EjJmjZ2rCVf7 wxa80i3RQPiYYZJe0DitpNDsXjLep+cVKd/0XXPZp+9yOf9WXVKYMudsbqG/CXTNX5wzroSDrp6BL 40wW8Ba38I7/YHmZegynLdZ68wHp+61tvB8VNJfHvCqEHWNBFZ1YT1qv+wumom0m5PY1hKgcQYpjT /TZ5eTYfKHA3SeGiX2LClFSWHLH5ooL2dQC5UpQ1+/hUpsqs0Oy23tXMzRAWV1MT4V6mu4SSKfmiz kw06Hz3Af8zyOxGMGhUB6X6gCY7r49vI1nJHwVJl2iPsl6EyCR6bbx4QOgrlumAMfzqvjH+Qef/p0 QMOnM2gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYoDT-00000000c2z-2qXk; Fri, 17 Jan 2025 15:24:59 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzy-00000000ZFe-0NWD for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:11:03 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 51DB82247; Fri, 17 Jan 2025 07:11:30 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 335C03F73F; Fri, 17 Jan 2025 07:11:01 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 10/11] arm_mpam: Skip inapplicable cases when reprogramming a resctrl domain Date: Fri, 17 Jan 2025 15:10:20 +0000 Message-Id: <20250117151033.1517882-11-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071102_168846_5DC41A24 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The implementation of resctrl_arch_update_domains() currently iterates over all types of staged configuration changes passed from resctrl, irrespective of whether a given type (CDP_CODE, CDP_DATA or CDP_NONE) makes sense for the affected MPAM resource. Since resctrl will not stage any updates of inappropriate type for the resource, this is mostly harmless. When doing a forced update as a result of a call via resctrl_arch_init_domains() however, there is a need to update the cpartid (intPARTID) even if no staged configuration changes are supplied. This can result in intPARTID being repeatedly reprogrammed with different values. As well as being inefficient, the final value may not be the correct one. To program just once with the correct intPARTID, only apply the update types that actually make sense for the resource. Signed-off-by: Dave Martin --- drivers/platform/arm64/mpam/mpam_resctrl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c index f1d0d9f59771..1f31b1455f66 100644 --- a/drivers/platform/arm64/mpam/mpam_resctrl.c +++ b/drivers/platform/arm64/mpam/mpam_resctrl.c @@ -1263,6 +1263,10 @@ static int __resctrl_arch_update_domains(struct rdt_resource *r, u32 closid, list_for_each_entry(d, &r->ctrl_domains, hdr.list) { for (t = 0; t < CDP_NUM_TYPES; t++) { + if ((t == CDP_NONE) != + (!cdp_enabled || mpam_resctrl_hide_cdp(r->rid))) + continue; + cfg = &d->staged_config[t]; if (!force && !cfg->have_new_ctrl) continue; From patchwork Fri Jan 17 15:10:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 13943454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71315C02185 for ; Fri, 17 Jan 2025 15:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ti7z7aGxgyNg3NP1KGOazGTJTj9oL5Ii72aBNEkeHYA=; b=BjsIJE2JVoRvLyGja1P9dG/UjU iSdc0D6STRLTH7W+2FHxTJHdxq2jj3CnqxgTUzAr4/Pl5FcxP+DwvrdCeRGUqV4CxoyENCJBQkfJp ATqcm6szX5FmJ4QANyAqE70rrz1SX5DTh8Y9MMqeXwe1GYZEHd0bR7GG2n6VGdvlOlpWdc3uVO1N2 g2RXCeEsPcVsnrTKwLxpnwOotG6sd/kb0kXkPHRHbzCZaoJcPawozwH5KFDL8e9gJ6J/E8pDwMgm8 LhnIoPADwbyPO36ZXwGefUdbSN69C7dJqoovPLpbyxEoSjPljxX+CM+94a7ImY2HUQb4o4Z5T8gII OUVKdOzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYoEh-00000000cFn-1EGS; Fri, 17 Jan 2025 15:26:15 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYnzz-00000000ZGb-0FHO for linux-arm-kernel@lists.infradead.org; Fri, 17 Jan 2025 15:11:04 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 490781476; Fri, 17 Jan 2025 07:11:31 -0800 (PST) Received: from e133380.cambridge.arm.com (e133380.arm.com [10.1.197.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2A6C53F73F; Fri, 17 Jan 2025 07:11:02 -0800 (PST) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Zeng Heng , Shaopeng Tan , James Morse Subject: [RFC PATCH v2 11/11] arm_mpam: Detect whether the system can alias PARTIDs Date: Fri, 17 Jan 2025 15:10:21 +0000 Message-Id: <20250117151033.1517882-12-Dave.Martin@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250117151033.1517882-1-Dave.Martin@arm.com> References: <20250117151033.1517882-1-Dave.Martin@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250117_071103_193660_DCB587A9 X-CRM114-Status: GOOD ( 22.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In order to be able to assign multiple PARTIDs freely to resource control groups, it is necessary that all MSCs that are used by resctrl either implement PARTID Narrowing (so that PARTIDs can be remapped explicitly) or otherwise only have controls whose resource regulation is stateless and so whose behaviour would not be affected by splitting a control group across multiple PARTIDs. Detect this property at the RIS level and merge it up the MPAM devices tree. Export the common global result as mpam_partid_aliasing, and apply it to the PARTIDs-per-CLOSID configuration. Signed-off-by: Dave Martin --- Currently, this the logic is simple and may forbid PARTID aliasing on some systems that can support it as a result of the precise set of MSCs and controls that are exposed through resctrl. The aim is to make this logic more flexible later. --- drivers/platform/arm64/mpam/mpam_devices.c | 48 ++++++++++++++++++--- drivers/platform/arm64/mpam/mpam_internal.h | 2 + drivers/platform/arm64/mpam/mpam_resctrl.c | 12 +++++- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/drivers/platform/arm64/mpam/mpam_devices.c b/drivers/platform/arm64/mpam/mpam_devices.c index 4b43dfef1cdc..0182c922638f 100644 --- a/drivers/platform/arm64/mpam/mpam_devices.c +++ b/drivers/platform/arm64/mpam/mpam_devices.c @@ -68,6 +68,7 @@ static DEFINE_MUTEX(mpam_cpuhp_state_lock); */ u16 mpam_partid_max; u8 mpam_pmg_max; +bool mpam_partid_aliasing; /* PARTID aliasing supported */ static bool partid_max_init, partid_max_published; static DEFINE_SPINLOCK(partid_max_lock); @@ -828,6 +829,7 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) struct mpam_msc *msc = ris->vmsc->msc; struct mpam_props *props = &ris->props; struct mpam_class *class = ris->vmsc->comp->class; + bool partid_can_alias = true; lockdep_assert_held(&msc->probe_lock); lockdep_assert_held(&msc->part_sel_lock); @@ -836,6 +838,8 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) /* Cache Capacity Partitioning */ if (FIELD_GET(MPAMF_IDR_HAS_CCAP_PART, ris->idr)) { + partid_can_alias = false; + ris->ccap_idr = mpam_read_partsel_reg(msc, CCAP_IDR); props->cmax_wd = FIELD_GET(MPAMF_CCAP_IDR_CMAX_WD, ris->ccap_idr); @@ -884,14 +888,20 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) */ props->bwa_wd = min(props->bwa_wd, 16); - if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features)) + if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MAX, mbw_features)) { mpam_set_feature(mpam_feat_mbw_max, props); + partid_can_alias = false; + } - if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MIN, mbw_features)) + if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_MIN, mbw_features)) { mpam_set_feature(mpam_feat_mbw_min, props); + partid_can_alias = false; + } - if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_PROP, mbw_features)) + if (props->bwa_wd && FIELD_GET(MPAMF_MBW_IDR_HAS_PROP, mbw_features)) { mpam_set_feature(mpam_feat_mbw_prop, props); + partid_can_alias = false; + } } /* Priority partitioning */ @@ -988,17 +998,26 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) * RIS with PARTID narrowing don't have enough storage for one * configuration per PARTID. If these are in a class we could use, * reduce the supported partid_max to match the numer of intpartid. - * If the class is unknown, just ignore it. + * If the MSC won't be used for anything or implements PARTID + * Narrowing then PARTIDs can be assigned freely, so PARTID + * aliasing can be supported regardless of the resource + * controls present. */ - if (FIELD_GET(MPAMF_IDR_HAS_PARTID_NRW, ris->idr) && - class->type != MPAM_CLASS_UNKNOWN) { + if (class->type == MPAM_CLASS_UNKNOWN) + partid_can_alias = true; + else if (FIELD_GET(MPAMF_IDR_HAS_PARTID_NRW, ris->idr)) { u32 nrwidr = mpam_read_partsel_reg(msc, PARTID_NRW_IDR); u16 partid_max = FIELD_GET(MPAMF_PARTID_NRW_IDR_INTPARTID_MAX, nrwidr); mpam_set_feature(mpam_feat_partid_nrw, props); msc->partid_max = min(msc->partid_max, partid_max); + + partid_can_alias = true; } + if (partid_can_alias) + mpam_set_feature(mpam_feat_partid_aliasing, props); + mpam_mon_sel_outer_unlock(msc); } @@ -2368,6 +2387,10 @@ static void __props_mismatch(struct mpam_props *parent, mpam_clear_feature(mpam_feat_dspri_part_0_low, &parent->features); } + /* PARTID aliasing must be supported everywhere, or not at all: */ + if (!mpam_has_feature(mpam_feat_partid_aliasing, parent)) + mpam_clear_feature(mpam_feat_partid_aliasing, &parent->features); + if (alias) { /* Merge features for aliased resources */ parent->features |= child->features; @@ -2486,6 +2509,7 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) { struct mpam_class *class; struct mpam_component *comp; + bool partid_can_alias = true, comp_partid_aliasing; lockdep_assert_held(&mpam_list_lock); @@ -2495,9 +2519,19 @@ static void mpam_enable_merge_features(struct list_head *all_classes_list) mpam_enable_init_class_features(class); - list_for_each_entry(comp, &class->components, class_list) + list_for_each_entry(comp, &class->components, class_list) { mpam_enable_merge_class_features(comp); + + comp_partid_aliasing = mpam_has_feature( + mpam_feat_partid_aliasing, &class->props); + partid_can_alias = partid_can_alias && + comp_partid_aliasing; + } } + + spin_lock(&partid_max_lock); + mpam_partid_aliasing = partid_can_alias; + spin_unlock(&partid_max_lock); } static char *mpam_errcode_names[16] = { diff --git a/drivers/platform/arm64/mpam/mpam_internal.h b/drivers/platform/arm64/mpam/mpam_internal.h index 965f4fea3012..6e10e4789506 100644 --- a/drivers/platform/arm64/mpam/mpam_internal.h +++ b/drivers/platform/arm64/mpam/mpam_internal.h @@ -215,6 +215,7 @@ enum mpam_device_features { mpam_feat_msmon_mbwu_hw_nrdy, mpam_feat_msmon_capt, mpam_feat_partid_nrw, + mpam_feat_partid_aliasing, /* derived feature */ MPAM_FEATURE_LAST, }; #define MPAM_ALL_FEATURES ((1< 1) || + resctrl_arch_get_num_closid(NULL) < 1) { + pr_warn("Hardware incompatible with PARTID aliasing, limiting monitoring groups\n"); + partid_per_closid = 1; + } + if (!err) { err = resctrl_init(); if (!err)