From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0B3B23093A6; Wed, 15 Apr 2026 01:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218213; cv=none; b=mB7JEYMvWVDikJXR41+DFQxz5Prz/JDBUZWuFv5GsD5m0spqfUWVroqdHWrMNocsJmJeD1MdOKFP84E16WeAteYYFNH0PscuMdNilbXnsV+DzFAJxNnOLu4cZi0oIXuf4TcpOHqgdRL4LleUvIhw8WaAGHaXw0EZrh5qyocTo78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218213; c=relaxed/simple; bh=OH+E1Lq9K6nERDXX094GRUFNVA/21b6qouU/nKLS0D0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XIfDYua4f5+qRZmdcWkrGTIKclViQWtOHChoCWKXUoeTiSKFusmU/QMcBQ0WJys3Gg44tPq3u1o3xfDAxkrT5mbP18rpVCPIDj5Bw5jxaD9iMI2W7vnMpga79vw1cZqEMYjK6vs+092knnsvS+k070RCBAxHI5aQ7NbS7xV/Rvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H8DUR98k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H8DUR98k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2099CC2BCB6; Wed, 15 Apr 2026 01:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218212; bh=OH+E1Lq9K6nERDXX094GRUFNVA/21b6qouU/nKLS0D0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=H8DUR98kYpt3WarxzAOT92vqW3+CYh7DUM/Q/UPulhWfbdhzkkq3vdtqrqe25wdSx Zj8FhFYAu8fPTb0HtWJKAJTlmiY4vhpXiUgeV8prXpQJcXizqco8e1dOEn5hSHpXfu aPYo5pz/cAZQuow18VjKwKxbf/rdLLvA4jmobglo6V6c53hfFgW16zmc4v7+aoNrM/ kbwAKxTbCe8nF0wKDutXeHrpdycKS9IWv25vuPQ7DYW9P/HcF0j3RIinZerUXZ/OYa X4rW1fqE5KJqllFNofFMWkXdiGA5tv13WcVJYE+LIQqEKHywNOxwglr2F+f7Q7Ngws W55cJm6rc/P1w== From: Drew Fustini Date: Tue, 14 Apr 2026 18:53:55 -0700 Subject: [PATCH RFC v3 01/11] dt-bindings: riscv: Add Ssqosid extension description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-1-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1218; i=fustini@kernel.org; h=from:subject:message-id; bh=OH+E1Lq9K6nERDXX094GRUFNVA/21b6qouU/nKLS0D0=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5AUvrq0da5gh5fy1/YjExqlm82UF1+LuiOhzKp+P i3gcF1oRykLgxgXg6yYIsumD3kXlniFfl0w/8U2mDmsTCBDGLg4BWAiE/4zMnxN2rOB12PH3eOr H61OSg5Y6B5zJux68InlmTscujpZOtYy/K/uV3m//GZH4GKN9i51r8Brduu+LHaO29h9uqf21KP TjzkA X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Document the ratified Supervisor-mode Quality of Service ID (Ssqosid) extension v1.0. Link: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0 Acked-by: Conor Dooley Signed-off-by: Drew Fustini --- Documentation/devicetree/bindings/riscv/extensions.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Docu= mentation/devicetree/bindings/riscv/extensions.yaml index c6ec9290fe07..1f3853a68760 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -232,6 +232,12 @@ properties: ratified at commit d70011dde6c2 ("Update to ratified state") of riscv-j-extension. =20 + - const: ssqosid + description: | + The Ssqosid extension for Quality of Service ID is ratified + as v1.0 in commit 5059e0ca641c ("Merge pull request #7 from + ved-rivos/Ratified") of riscv-ssqosid. + - const: ssstateen description: | The standard Ssstateen extension for supervisor-mode view of t= he --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A605730BBB6; Wed, 15 Apr 2026 01:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218213; cv=none; b=FqbHcUbasElcSTTA24Yy2zeK3YnbrM0vXdb3R+AgHB3IFO7BHIlo9bRyncIYIUX889QCDaLWx4lqtaAaM+y3vT65OnpkjWbI9YBdjQ9pU+ubEM6L6wr+6WyLBEkhVR/KMzUOU2DBZUhKfS1FsnqIGw/PdrewVwCIIXxCHTcuiho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218213; c=relaxed/simple; bh=cTl90YsYPY3g7JWymDyW8dKdkNX8yYPp7OJ7YZSz0gc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S1n4eQUGkeR25gHu+OqFFomOOawWKQZYAPuv2D9W98f97yQNA4/lS6INLzWouYLyKFLQPd8RT0TeV8CDPJHSzmDiU4uW0fZdxmie1lnc0HaIjTb2Tdd3VOk6wRXz+2g9wfd7gkC1oKDiA8JDSO5rWFx2PAq1Ya6cK07bEFPhEm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bw5PIoIL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bw5PIoIL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8C9CC2BCC6; Wed, 15 Apr 2026 01:56:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218213; bh=cTl90YsYPY3g7JWymDyW8dKdkNX8yYPp7OJ7YZSz0gc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bw5PIoILIKcZsvxtwd1dF2jS5RgdVNyj717Zc7f+lTCnyBMuAQWyVoveqs4sFwQYd 0go7FtEVlyCkgpk8b7nFF+RNolgwHa6b0IEN1BVAJnC046+Be+qlUACDbABoxhvuQn Ov4+uj1nZT2nyWWeBcJ49QtyBI7QNYb6I4ni8tldYNrKmXgH3Yl6mMrN4I1ejKoU9Y zXin1HpKe03uVSjZUpiILXqAjCw+abv9cuGMBQgjxxYM9ym1IcmPkjOdM1wtEx/34/ vuGO5z313l0MVM3+hYFzwOyi3S0Xue4ZCmxeQCJN3Fh3ohiRedx4EU4C+Yu3YnSVK1 ADJO/MZ2x33vg== From: Drew Fustini Date: Tue, 14 Apr 2026 18:53:56 -0700 Subject: [PATCH RFC v3 02/11] RISC-V: Detect the Ssqosid extension Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-2-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1637; i=fustini@kernel.org; h=from:subject:message-id; bh=cTl90YsYPY3g7JWymDyW8dKdkNX8yYPp7OJ7YZSz0gc=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5C0dzXz1hrO0xkvjsoo2uossnp7z++h/m2/V5vmX jVkV5AT7ChlYRDjYpAVU2TZ9CHvwhKv0K8L5r/YBjOHlQlkCAMXpwBMxGkXw2924dmCG75XCa4P v87Kc3/Jtq74oztKSrn4j23fuXCTQW8Uw//aY1+j7lx/4fPi9hu/YzPDNR69NNq36JPRH1uzV+3 5ySz8AA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Ssqosid is the RISC-V Quality-of-Service (QoS) Identifiers specification which defines the Supervisor Resource Management Configuration (srmcfg) register. Link: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0 Co-developed-by: Kornel Dul=C4=99ba Signed-off-by: Kornel Dul=C4=99ba Signed-off-by: Drew Fustini --- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 7ef8e5f55c8d..b83dae5cebb9 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -112,6 +112,7 @@ #define RISCV_ISA_EXT_ZCLSD 103 #define RISCV_ISA_EXT_ZICFILP 104 #define RISCV_ISA_EXT_ZICFISS 105 +#define RISCV_ISA_EXT_SSQOSID 106 =20 #define RISCV_ISA_EXT_XLINUXENVCFG 127 =20 diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 1734f9a4c2fd..c0717a861a3c 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -582,6 +582,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] =3D { __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_SUPERSET(ssnpm, RISCV_ISA_EXT_SSNPM, riscv_xlinuxenvcfg_e= xts), + __RISCV_ISA_EXT_DATA(ssqosid, RISCV_ISA_EXT_SSQOSID), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svade, RISCV_ISA_EXT_SVADE), __RISCV_ISA_EXT_DATA_VALIDATE(svadu, RISCV_ISA_EXT_SVADU, riscv_ext_svadu= _validate), --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 44A5E30E0DC; Wed, 15 Apr 2026 01:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218214; cv=none; b=QzxR81h64u26WYk3eOCGef4uj2cc/XUQHdnWShc1ov1qFxBn+KD53xGoSOq0/MNzbHG8KGq0HxasEnqd8rmU40H6SalBGCx+7THFW5lGxG/j72yG9PTe+RqPo7WA/oRmiPIwbptuuYAow50erWeQZG5PXZl3FSy0m/y8ajM5Zj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218214; c=relaxed/simple; bh=T0+s0E0tWZCrb0PJGYB8J4W5kypAHxHmL1V4nejdY4Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JrKJGPd1VAXjedf3Tde8p7uvGTgZB3rQJgv1wiRpAnoEAK+4LI538bMRxIphVK1jL/Pz02+1UCTlHfypH9kSSKocbQn3CnquaEjEiQtEjmVSIgOIsg7paIkAdepRMUUT+9wmpnSiazDlj/HPrcDHDc++QD9ulJPPHFfbTN2YZIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MCVJdSbO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MCVJdSbO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A48EC2BCC9; Wed, 15 Apr 2026 01:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218214; bh=T0+s0E0tWZCrb0PJGYB8J4W5kypAHxHmL1V4nejdY4Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MCVJdSbOSwjEm3SSXBb38boGpn0F+zueoAU4548Em/7noj7MEolMlop4JnZhYfWeF 7BxK7xIJnN08BHqOUi5RXJvhDDAWqVDzTC/K/Q2i59v32p3W7SkB6CNyMtD7f2h4wa L7rW/d5tAR1pArGluxez7fZNUVU7YPwaIcFTYMs8jkjOklDr2+SmamTagygP0J7TDG uGSpqHs3QAi0pbANQTfsj6MY0uBjzf+9bCCzSH/esTziPWvvGKx8yCDMzN5MIWzs7Q fynKJeKe7ykZdqjmBJDq6w/nvCmCl3pGxR3yEx2dGjvvOppOp5rkYqJTBuAHnCYlV/ piFdvsrxOSXnA== From: Drew Fustini Date: Tue, 14 Apr 2026 18:53:57 -0700 Subject: [PATCH RFC v3 03/11] RISC-V: Add support for srmcfg CSR from Ssqosid extension Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-3-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8345; i=fustini@kernel.org; h=from:subject:message-id; bh=T0+s0E0tWZCrb0PJGYB8J4W5kypAHxHmL1V4nejdY4Q=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5A0Z6vRpr2XXpce3nbgjuQeu93esXvZEi6s+VTVw Ll5lnpYSEcpC4MYF4OsmCLLpg95F5Z4hX5dMP/FNpg5rEwgQxi4OAVgImI6jAzdHMp6XTnn7vee vHheJ86JIVm1VPll2PT1Enl733DeFdnC8N+rYuaCN6bHJ//4vPCRdsn2rxu6Ny1k7LX6Wao0a/2 R6mpmAA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add support for the srmcfg CSR defined in the Ssqosid ISA extension. The CSR contains two fields: - Resource Control ID (RCID) for resource allocation - Monitoring Counter ID (MCID) for tracking resource usage Requests from a hart to shared resources are tagged with these IDs, allowing resource usage to be associated with the running task. Add a srmcfg field to thread_struct with the same format as the CSR so the scheduler can set the RCID and MCID for each task on context switch. A per-cpu cpu_srmcfg variable mirrors the CSR state to avoid redundant writes, as L1D-hot memory access is faster than a CSR read and avoids traps under virtualization. Add a per-cpu cpu_srmcfg_default variable to store the default srmcfg for each CPU, as set by resctrl CPU group assignment. On context switch, if the next task belongs to the default resource group (srmcfg =3D=3D 0), the CPU's default value is used instead. This implements resctrl resource allocation rule 2: default-group tasks on a CPU assigned to a specific group receive that group's allocations. Link: https://github.com/riscv/riscv-ssqosid/releases/tag/v1.0 Co-developed-by: Kornel Dul=C4=99ba Signed-off-by: Kornel Dul=C4=99ba Signed-off-by: Drew Fustini --- MAINTAINERS | 8 ++++++ arch/riscv/Kconfig | 17 +++++++++++++ arch/riscv/include/asm/csr.h | 6 +++++ arch/riscv/include/asm/processor.h | 3 +++ arch/riscv/include/asm/qos.h | 52 ++++++++++++++++++++++++++++++++++= ++++ arch/riscv/include/asm/switch_to.h | 3 +++ arch/riscv/kernel/Makefile | 2 ++ arch/riscv/kernel/qos/Makefile | 2 ++ arch/riscv/kernel/qos/qos.c | 8 ++++++ 9 files changed, 101 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c3fe46d7c4bc..b17f885411ba 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22778,6 +22778,14 @@ F: drivers/perf/riscv_pmu.c F: drivers/perf/riscv_pmu_legacy.c F: drivers/perf/riscv_pmu_sbi.c =20 +RISC-V QOS RESCTRL SUPPORT +M: Drew Fustini +R: yunhui cui +L: linux-riscv@lists.infradead.org +S: Supported +F: arch/riscv/include/asm/qos.h +F: arch/riscv/kernel/qos/ + RISC-V RPMI AND MPXY DRIVERS M: Rahul Pathak M: Anup Patel diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 90c531e6abf5..92d2265a0c61 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -595,6 +595,23 @@ config RISCV_ISA_SVNAPOT =20 If you don't know what to do here, say Y. =20 +config RISCV_ISA_SSQOSID + bool "Ssqosid extension support for supervisor mode Quality of Service ID" + default n + help + Adds support for the Ssqosid ISA extension (Supervisor-mode + Quality of Service ID). + + Ssqosid defines the srmcfg CSR which allows the system to tag the + running process with an RCID (Resource Control ID) and MCID + (Monitoring Counter ID). The RCID is used to determine resource + allocation. The MCID is used to track resource usage in event + counters. + + For example, a cache controller may use the RCID to apply a + cache partitioning scheme and use the MCID to track how much + cache a process, or a group of processes, is using. + config RISCV_ISA_SVPBMT bool "Svpbmt extension support for supervisor mode page-based memory type= s" depends on 64BIT && MMU diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 31b8988f4488..dc13835bd661 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -84,6 +84,11 @@ #define SATP_ASID_MASK _AC(0xFFFF, UL) #endif =20 +/* SRMCFG fields */ +#define SRMCFG_RCID_MASK _AC(0x00000FFF, UL) +#define SRMCFG_MCID_MASK _AC(0x00000FFF, UL) +#define SRMCFG_MCID_SHIFT 16 + /* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) =20 @@ -328,6 +333,7 @@ #define CSR_STVAL 0x143 #define CSR_SIP 0x144 #define CSR_SATP 0x180 +#define CSR_SRMCFG 0x181 =20 #define CSR_STIMECMP 0x14D #define CSR_STIMECMPH 0x15D diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/pr= ocessor.h index 4c3dd94d0f63..feaee2502593 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -123,6 +123,9 @@ struct thread_struct { /* A forced icache flush is not needed if migrating to the previous cpu. = */ unsigned int prev_cpu; #endif +#ifdef CONFIG_RISCV_ISA_SSQOSID + u32 srmcfg; +#endif }; =20 /* Whitelist the fstate from the task_struct for hardened usercopy */ diff --git a/arch/riscv/include/asm/qos.h b/arch/riscv/include/asm/qos.h new file mode 100644 index 000000000000..aa96bb5a153c --- /dev/null +++ b/arch/riscv/include/asm/qos.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_QOS_H +#define _ASM_RISCV_QOS_H + +#ifdef CONFIG_RISCV_ISA_SSQOSID + +#include + +#include +#include + +/* cached value of srmcfg csr for each cpu */ +DECLARE_PER_CPU(u32, cpu_srmcfg); + +/* default srmcfg value for each cpu, set via resctrl cpu assignment */ +DECLARE_PER_CPU(u32, cpu_srmcfg_default); + +static inline void __switch_to_srmcfg(struct task_struct *next) +{ + u32 thread_srmcfg; + + thread_srmcfg =3D READ_ONCE(next->thread.srmcfg); + + /* + * Tasks in the default resource group have closid=3D0 and rmid=3D0, + * so thread.srmcfg is 0. For these tasks, use this CPU's default + * srmcfg instead. This implements resctrl rule 2: a default-group + * task running on a CPU assigned to a specific group uses that + * group's allocations. + */ + if (thread_srmcfg =3D=3D 0) + thread_srmcfg =3D __this_cpu_read(cpu_srmcfg_default); + + if (thread_srmcfg !=3D __this_cpu_read(cpu_srmcfg)) { + __this_cpu_write(cpu_srmcfg, thread_srmcfg); + csr_write(CSR_SRMCFG, thread_srmcfg); + } +} + +static __always_inline bool has_srmcfg(void) +{ + return riscv_has_extension_unlikely(RISCV_ISA_EXT_SSQOSID); +} + +#else /* ! CONFIG_RISCV_ISA_SSQOSID */ + +struct task_struct; +static __always_inline bool has_srmcfg(void) { return false; } +static inline void __switch_to_srmcfg(struct task_struct *next) { } + +#endif /* CONFIG_RISCV_ISA_SSQOSID */ +#endif /* _ASM_RISCV_QOS_H */ diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/sw= itch_to.h index 0e71eb82f920..1c7ea53ec012 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 #ifdef CONFIG_FPU extern void __fstate_save(struct task_struct *save_to); @@ -119,6 +120,8 @@ do { \ __switch_to_fpu(__prev, __next); \ if (has_vector() || has_xtheadvector()) \ __switch_to_vector(__prev, __next); \ + if (has_srmcfg()) \ + __switch_to_srmcfg(__next); \ if (switch_to_should_flush_icache(__next)) \ local_flush_icache_all(); \ __switch_to_envcfg(__next); \ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index cabb99cadfb6..82157aae6401 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -128,3 +128,5 @@ obj-$(CONFIG_ACPI_NUMA) +=3D acpi_numa.o =20 obj-$(CONFIG_GENERIC_CPU_VULNERABILITIES) +=3D bugs.o obj-$(CONFIG_RISCV_USER_CFI) +=3D usercfi.o + +obj-$(CONFIG_RISCV_ISA_SSQOSID) +=3D qos/ diff --git a/arch/riscv/kernel/qos/Makefile b/arch/riscv/kernel/qos/Makefile new file mode 100644 index 000000000000..9f996263a86d --- /dev/null +++ b/arch/riscv/kernel/qos/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_RISCV_ISA_SSQOSID) +=3D qos.o diff --git a/arch/riscv/kernel/qos/qos.c b/arch/riscv/kernel/qos/qos.c new file mode 100644 index 000000000000..a3c2b910e2e0 --- /dev/null +++ b/arch/riscv/kernel/qos/qos.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include + +/* cached value of srmcfg csr for each cpu */ +DEFINE_PER_CPU(u32, cpu_srmcfg); + +/* default srmcfg value for each cpu, set via resctrl cpu assignment */ +DEFINE_PER_CPU(u32, cpu_srmcfg_default); --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D65F93101BF; Wed, 15 Apr 2026 01:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218214; cv=none; b=QZNT1bDFFq7XP7EtW7BgZ4APEmxLUKRa+EEJuHZGb8qwQE2XqTtcGrBlSkdH1Ci9cbpZVO8qPkE4eK9CQJwC2Ft3j36nrMGmjlkoj8RSqacc7iyUBTyjQVgxkFXMWPOSw/oZ5Rthe3J5Ii0aV+kv6V57YLf0fo2Qwi3oGBABJcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218214; c=relaxed/simple; bh=H1ztQgd+2H1GKQQqEH15jClagTdCx1WzvmrE8NCuARs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Egxtla2HExOu/Zsdn2l85lHfY98mybi013I2Rk/giuqb5skHVyokSNA23LTj5EEuoC3Hk3/oKyu1csB9/XfDOrlCq8L1izRv/Wvb7Mq1lz0AabW3sK7+1BLDqo6rAAF1dCWgKujU7LQsXZt05S6s+tyVEdc0c2uNAOEx44WyYPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aW8dABxF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aW8dABxF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 319B1C2BCC4; Wed, 15 Apr 2026 01:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218214; bh=H1ztQgd+2H1GKQQqEH15jClagTdCx1WzvmrE8NCuARs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aW8dABxFiClvpDtdFboVo5klhedNQrj+B6xsvX4HjE9oBtkOH9xkcmNOqRuG0RTEy tbqr7dd3sk/7qJ4TK2ciLQR+YYuL+ePx8JUw/pmG5IbZ7ppk1BwV7ZRoUgdYiWU++x 7jUl8xKoEywiMFn5SIIujvwTwqSNmPZbBGEpi4I211gT9OWWmAudUjKUcdsA5e8uYB HsCxQd5Y3MlvQOJwNsWPism5bf6bTAOjAJdAtUG0w9ujvfmoVTmEM8n7JmclmzQShj LSt6ps40cOWAsQll4k2fW4gcC/hyr9sRt0AB0H+0yD91KZYsrG/jUAvABoKTlqEgax qBBrx35g1qSRQ== From: Drew Fustini Date: Tue, 14 Apr 2026 18:53:58 -0700 Subject: [PATCH RFC v3 04/11] RISC-V: QoS: add CBQRI hardware interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-4-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=19984; i=fustini@kernel.org; h=from:subject:message-id; bh=H1ztQgd+2H1GKQQqEH15jClagTdCx1WzvmrE8NCuARs=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5CU1bHojVCP3lTekPro1cU99m2JPrfFWKx4pt0pS v07KWttRykLgxgXg6yYIsumD3kXlniFfl0w/8U2mDmsTCBDGLg4BWAib80YGY6m/Tiy/f0ZJ3uh mnuF/+/sPiTCJHg0k+9Bb1R8QaEVNwPDf8e/X7m//35mE6fAYn3+qt2OAzfUW/2Sb0b5yx2Lirk ayQMA X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add the CBQRI controller hardware interface layer. Define data structures representing CBQRI controller properties (cbqri_controller) and hardware capabilities for capacity and bandwidth controllers (riscv_cbqri_capacity_caps, riscv_cbqri_bandwidth_caps) in include/linux/riscv_qos.h. Define MMIO register offsets, field masks, and internal wrapper structs (cbqri_resctrl_res, cbqri_resctrl_dom, cbqri_config) in internal.h. Implement MMIO helpers for capacity block mask and bandwidth reservation, alloc control operations for capacity and bandwidth controllers, and probe functions to discover controller capabilities. A per-controller spinlock serializes multi-step MMIO sequences. Co-developed-by: Adrien Ricciardi Signed-off-by: Adrien Ricciardi Signed-off-by: Drew Fustini --- MAINTAINERS | 1 + arch/riscv/kernel/qos/internal.h | 81 +++++++ arch/riscv/kernel/qos/qos_resctrl.c | 432 ++++++++++++++++++++++++++++++++= ++++ include/linux/riscv_qos.h | 76 +++++++ 4 files changed, 590 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b17f885411ba..6a66d7047c51 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22785,6 +22785,7 @@ L: linux-riscv@lists.infradead.org S: Supported F: arch/riscv/include/asm/qos.h F: arch/riscv/kernel/qos/ +F: include/linux/riscv_qos.h =20 RISC-V RPMI AND MPXY DRIVERS M: Rahul Pathak diff --git a/arch/riscv/kernel/qos/internal.h b/arch/riscv/kernel/qos/inter= nal.h new file mode 100644 index 000000000000..edbcbd9471b1 --- /dev/null +++ b/arch/riscv/kernel/qos/internal.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_QOS_INTERNAL_H +#define _ASM_RISCV_QOS_INTERNAL_H + +#include +#include +#include + +#define RISCV_RESCTRL_EMPTY_CLOSID ((u32)~0) + +#define CBQRI_CC_CAPABILITIES_OFF 0 +#define CBQRI_CC_MON_CTL_OFF 8 +#define CBQRI_CC_MON_CTL_VAL_OFF 16 +#define CBQRI_CC_ALLOC_CTL_OFF 24 +#define CBQRI_CC_BLOCK_MASK_OFF 32 + +#define CBQRI_BC_CAPABILITIES_OFF 0 +#define CBQRI_BC_MON_CTL_OFF 8 +#define CBQRI_BC_MON_CTR_VAL_OFF 16 +#define CBQRI_BC_ALLOC_CTL_OFF 24 +#define CBQRI_BC_BW_ALLOC_OFF 32 + +#define CBQRI_CC_CAPABILITIES_VER_MINOR_MASK GENMASK(3, 0) +#define CBQRI_CC_CAPABILITIES_VER_MAJOR_MASK GENMASK(7, 4) + +#define CBQRI_CC_CAPABILITIES_NCBLKS_MASK GENMASK(23, 8) +#define CBQRI_CC_CAPABILITIES_FRCID_MASK GENMASK(24, 24) + +#define CBQRI_BC_CAPABILITIES_VER_MINOR_MASK GENMASK(3, 0) +#define CBQRI_BC_CAPABILITIES_VER_MAJOR_MASK GENMASK(7, 4) + +#define CBQRI_BC_CAPABILITIES_NBWBLKS_MASK GENMASK(23, 8) +#define CBQRI_BC_CAPABILITIES_MRBWB_MASK GENMASK_ULL(47, 32) + +#define CBQRI_CONTROL_REGISTERS_OP_MASK GENMASK(4, 0) +#define CBQRI_CONTROL_REGISTERS_AT_MASK GENMASK(7, 5) +#define CBQRI_CONTROL_REGISTERS_AT_DATA 0 +#define CBQRI_CONTROL_REGISTERS_AT_CODE 1 +#define CBQRI_CONTROL_REGISTERS_RCID_MASK GENMASK(19, 8) +#define CBQRI_CONTROL_REGISTERS_STATUS_MASK GENMASK_ULL(38, 32) +#define CBQRI_CONTROL_REGISTERS_BUSY_MASK GENMASK_ULL(39, 39) +#define CBQRI_CONTROL_REGISTERS_RBWB_MASK GENMASK(15, 0) + +#define CBQRI_CC_MON_CTL_OP_CONFIG_EVENT 1 +#define CBQRI_CC_MON_CTL_OP_READ_COUNTER 2 +#define CBQRI_CC_MON_CTL_STATUS_SUCCESS 1 + +#define CBQRI_CC_ALLOC_CTL_OP_CONFIG_LIMIT 1 +#define CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT 2 +#define CBQRI_CC_ALLOC_CTL_OP_FLUSH_RCID 3 +#define CBQRI_CC_ALLOC_CTL_STATUS_SUCCESS 1 + +#define CBQRI_BC_MON_CTL_OP_CONFIG_EVENT 1 +#define CBQRI_BC_MON_CTL_OP_READ_COUNTER 2 +#define CBQRI_BC_MON_CTL_STATUS_SUCCESS 1 + +#define CBQRI_BC_ALLOC_CTL_OP_CONFIG_LIMIT 1 +#define CBQRI_BC_ALLOC_CTL_OP_READ_LIMIT 2 +#define CBQRI_BC_ALLOC_CTL_STATUS_SUCCESS 1 + +int qos_resctrl_setup(void); +int qos_resctrl_online_cpu(unsigned int cpu); +int qos_resctrl_offline_cpu(unsigned int cpu); + +struct cbqri_resctrl_res { + struct rdt_resource resctrl_res; + u32 max_rcid; + u32 max_mcid; +}; + +struct cbqri_resctrl_dom { + struct rdt_ctrl_domain resctrl_ctrl_dom; + struct cbqri_controller *hw_ctrl; +}; + +struct cbqri_config { + u64 cbm; /* capacity block mask */ + u64 rbwb; /* reserved bandwidth blocks */ +}; + +#endif /* _ASM_RISCV_QOS_INTERNAL_H */ diff --git a/arch/riscv/kernel/qos/qos_resctrl.c b/arch/riscv/kernel/qos/qo= s_resctrl.c new file mode 100644 index 000000000000..6d294f2f2504 --- /dev/null +++ b/arch/riscv/kernel/qos/qos_resctrl.c @@ -0,0 +1,432 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt(fmt) "qos: resctrl: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "internal.h" + +static struct cbqri_resctrl_res cbqri_resctrl_resources[RDT_NUM_RESOURCES]; + +static bool exposed_alloc_capable; +/* CDP (code data prioritization) on x86 is AT (access type) on RISC-V */ +static bool exposed_cdp_l2_capable; +static bool exposed_cdp_l3_capable; +static bool is_cdp_l2_enabled; +static bool is_cdp_l3_enabled; + +/* used by resctrl_arch_system_num_rmid_idx() */ +static u32 max_rmid; + +LIST_HEAD(cbqri_controllers); + +static int cbqri_wait_busy_flag(struct cbqri_controller *ctrl, int reg_off= set, + u64 *regp); + +/* Set capacity block mask (cc_block_mask) */ +static void cbqri_set_cbm(struct cbqri_controller *ctrl, u64 cbm) +{ + iowrite64(cbm, ctrl->base + CBQRI_CC_BLOCK_MASK_OFF); +} + +/* Set the Rbwb (reserved bandwidth blocks) field in bc_bw_alloc */ +static void cbqri_set_rbwb(struct cbqri_controller *ctrl, u64 rbwb) +{ + u64 reg; + + reg =3D ioread64(ctrl->base + CBQRI_BC_BW_ALLOC_OFF); + reg &=3D ~CBQRI_CONTROL_REGISTERS_RBWB_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_RBWB_MASK, rbwb); + iowrite64(reg, ctrl->base + CBQRI_BC_BW_ALLOC_OFF); +} + +/* Get the Rbwb (reserved bandwidth blocks) field in bc_bw_alloc */ +static u64 cbqri_get_rbwb(struct cbqri_controller *ctrl) +{ + u64 reg; + + reg =3D ioread64(ctrl->base + CBQRI_BC_BW_ALLOC_OFF); + return FIELD_GET(CBQRI_CONTROL_REGISTERS_RBWB_MASK, reg); +} + +static int cbqri_wait_busy_flag(struct cbqri_controller *ctrl, int reg_off= set, + u64 *regp) +{ + u64 reg; + int ret; + + ret =3D readq_poll_timeout_atomic(ctrl->base + reg_offset, reg, + !FIELD_GET(CBQRI_CONTROL_REGISTERS_BUSY_MASK, reg), + 0, 1000); + if (!ret && regp) + *regp =3D reg; + + return ret; +} + +/* Perform capacity allocation control operation on capacity controller */ +static int cbqri_cc_alloc_op(struct cbqri_controller *ctrl, int operation,= int rcid, + enum resctrl_conf_type type) +{ + int reg_offset =3D CBQRI_CC_ALLOC_CTL_OFF; + int status; + u64 reg; + + reg =3D ioread64(ctrl->base + reg_offset); + reg &=3D ~CBQRI_CONTROL_REGISTERS_OP_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_OP_MASK, operation); + reg &=3D ~CBQRI_CONTROL_REGISTERS_RCID_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_RCID_MASK, rcid); + + /* CBQRI capacity AT is only supported on L2 and L3 caches for now */ + if (ctrl->type =3D=3D CBQRI_CONTROLLER_TYPE_CAPACITY && + ((ctrl->cache.cache_level =3D=3D 2 && is_cdp_l2_enabled) || + (ctrl->cache.cache_level =3D=3D 3 && is_cdp_l3_enabled))) { + reg &=3D ~CBQRI_CONTROL_REGISTERS_AT_MASK; + switch (type) { + case CDP_CODE: + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_AT_MASK, + CBQRI_CONTROL_REGISTERS_AT_CODE); + break; + case CDP_DATA: + default: + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_AT_MASK, + CBQRI_CONTROL_REGISTERS_AT_DATA); + break; + } + } + + iowrite64(reg, ctrl->base + reg_offset); + + if (cbqri_wait_busy_flag(ctrl, reg_offset, ®) < 0) { + pr_err("%s(): BUSY timeout when executing the operation\n", __func__); + return -EIO; + } + + status =3D FIELD_GET(CBQRI_CONTROL_REGISTERS_STATUS_MASK, reg); + if (status !=3D CBQRI_CC_ALLOC_CTL_STATUS_SUCCESS) { + pr_err("%s(): operation %d failed: status=3D%d\n", __func__, operation, = status); + return -EIO; + } + + return 0; +} + +/* + * Write a capacity block mask and verify the hardware accepted it by + * reading back the value after a CONFIG_LIMIT + READ_LIMIT sequence. + */ +static int cbqri_apply_cache_config(struct cbqri_resctrl_dom *hw_dom, u32 = closid, + enum resctrl_conf_type type, struct cbqri_config *cfg) +{ + struct cbqri_controller *ctrl =3D hw_dom->hw_ctrl; + int err =3D 0; + u64 reg; + + spin_lock(&ctrl->lock); + + /* Set capacity block mask (cc_block_mask) */ + cbqri_set_cbm(ctrl, cfg->cbm); + + /* Capacity config limit operation */ + err =3D cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_CONFIG_LIMIT, closi= d, type); + if (err < 0) { + pr_err("%s(): operation failed: err =3D %d\n", __func__, err); + goto out; + } + + /* Clear cc_block_mask before read limit to verify op works */ + cbqri_set_cbm(ctrl, 0); + + /* Perform a capacity read limit operation to verify blockmask */ + err =3D cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT, closid,= type); + if (err < 0) { + pr_err("%s(): operation failed: err =3D %d\n", __func__, err); + goto out; + } + + /* Read capacity blockmask to verify it matches the requested config */ + reg =3D ioread64(ctrl->base + CBQRI_CC_BLOCK_MASK_OFF); + if (reg !=3D cfg->cbm) { + pr_err("%s(): failed to verify allocation (reg:%llx !=3D cbm:%llx)\n", + __func__, reg, cfg->cbm); + err =3D -EIO; + } + +out: + spin_unlock(&ctrl->lock); + return err; +} + +/* Perform bandwidth allocation control operation on bandwidth controller = */ +static int cbqri_bc_alloc_op(struct cbqri_controller *ctrl, int operation,= int rcid) +{ + int reg_offset =3D CBQRI_BC_ALLOC_CTL_OFF; + int status; + u64 reg; + + reg =3D ioread64(ctrl->base + reg_offset); + reg &=3D ~CBQRI_CONTROL_REGISTERS_OP_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_OP_MASK, operation); + reg &=3D ~CBQRI_CONTROL_REGISTERS_RCID_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_RCID_MASK, rcid); + iowrite64(reg, ctrl->base + reg_offset); + + if (cbqri_wait_busy_flag(ctrl, reg_offset, ®) < 0) { + pr_err("%s(): BUSY timeout when executing the operation\n", __func__); + return -EIO; + } + + status =3D FIELD_GET(CBQRI_CONTROL_REGISTERS_STATUS_MASK, reg); + if (status !=3D CBQRI_BC_ALLOC_CTL_STATUS_SUCCESS) { + pr_err("%s(): operation %d failed with status =3D %d\n", + __func__, operation, status); + return -EIO; + } + + return 0; +} + +/* + * Write a bandwidth reservation and verify the hardware accepted it by + * reading back the value after a CONFIG_LIMIT + READ_LIMIT sequence. + */ +static int cbqri_apply_bw_config(struct cbqri_resctrl_dom *hw_dom, u32 clo= sid, + enum resctrl_conf_type type, struct cbqri_config *cfg) +{ + struct cbqri_controller *ctrl =3D hw_dom->hw_ctrl; + int ret =3D 0; + u64 reg; + + spin_lock(&ctrl->lock); + + /* Set reserved bandwidth blocks */ + cbqri_set_rbwb(ctrl, cfg->rbwb); + + /* Bandwidth config limit operation */ + ret =3D cbqri_bc_alloc_op(ctrl, CBQRI_BC_ALLOC_CTL_OP_CONFIG_LIMIT, closi= d); + if (ret < 0) { + pr_err("%s(): operation failed: ret =3D %d\n", __func__, ret); + goto out; + } + + /* Clear rbwb before read limit to verify op works */ + cbqri_set_rbwb(ctrl, 0); + + /* Bandwidth allocation read limit operation to verify */ + ret =3D cbqri_bc_alloc_op(ctrl, CBQRI_BC_ALLOC_CTL_OP_READ_LIMIT, closid); + if (ret < 0) + goto out; + + /* Read bandwidth allocation to verify it matches the requested config */ + reg =3D cbqri_get_rbwb(ctrl); + if (reg !=3D cfg->rbwb) { + pr_err("%s(): failed to verify allocation (reg:%llx !=3D rbwb:%llu)\n", + __func__, reg, cfg->rbwb); + ret =3D -EIO; + } + +out: + spin_unlock(&ctrl->lock); + return ret; +} + +static int cbqri_probe_feature(struct cbqri_controller *ctrl, int reg_offs= et, + int operation, int *status, bool *access_type_supported) +{ + u64 reg, saved_reg; + int at; + + /* Keep the initial register value to preserve the WPRI fields */ + reg =3D ioread64(ctrl->base + reg_offset); + saved_reg =3D reg; + + /* Execute the requested operation to find if the register is implemented= */ + reg &=3D ~CBQRI_CONTROL_REGISTERS_OP_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_OP_MASK, operation); + iowrite64(reg, ctrl->base + reg_offset); + if (cbqri_wait_busy_flag(ctrl, reg_offset, ®) < 0) { + pr_err("%s(): BUSY timeout when executing the operation\n", __func__); + return -EIO; + } + + /* Get the operation status */ + *status =3D FIELD_GET(CBQRI_CONTROL_REGISTERS_STATUS_MASK, reg); + + /* + * Check for the AT support if the register is implemented + * (if not, the status value will remain 0) + */ + if (*status !=3D 0) { + /* Set the AT field to a valid value */ + reg =3D saved_reg; + reg &=3D ~CBQRI_CONTROL_REGISTERS_AT_MASK; + reg |=3D FIELD_PREP(CBQRI_CONTROL_REGISTERS_AT_MASK, + CBQRI_CONTROL_REGISTERS_AT_CODE); + iowrite64(reg, ctrl->base + reg_offset); + if (cbqri_wait_busy_flag(ctrl, reg_offset, ®) < 0) { + pr_err("%s(): BUSY timeout when setting AT field\n", __func__); + return -EIO; + } + + /* + * If the AT field value has been reset to zero, + * then the AT support is not present + */ + at =3D FIELD_GET(CBQRI_CONTROL_REGISTERS_AT_MASK, reg); + if (at =3D=3D CBQRI_CONTROL_REGISTERS_AT_CODE) + *access_type_supported =3D true; + else + *access_type_supported =3D false; + } + + /* Restore the original register value */ + iowrite64(saved_reg, ctrl->base + reg_offset); + if (cbqri_wait_busy_flag(ctrl, reg_offset, NULL) < 0) { + pr_err("%s(): BUSY timeout when restoring the original register value\n"= , __func__); + return -EIO; + } + + return 0; +} + +static int cbqri_probe_cc(struct cbqri_controller *ctrl) +{ + int err, status; + u64 reg; + + reg =3D ioread64(ctrl->base + CBQRI_CC_CAPABILITIES_OFF); + if (reg =3D=3D 0) + return -ENODEV; + + ctrl->ver_minor =3D FIELD_GET(CBQRI_CC_CAPABILITIES_VER_MINOR_MASK, reg); + ctrl->ver_major =3D FIELD_GET(CBQRI_CC_CAPABILITIES_VER_MAJOR_MASK, reg); + ctrl->cc.supports_alloc_op_flush_rcid =3D + FIELD_GET(CBQRI_CC_CAPABILITIES_FRCID_MASK, reg); + ctrl->cc.ncblks =3D FIELD_GET(CBQRI_CC_CAPABILITIES_NCBLKS_MASK, reg); + + pr_debug("version=3D%d.%d ncblks=3D%d cache_level=3D%d\n", + ctrl->ver_major, ctrl->ver_minor, + ctrl->cc.ncblks, ctrl->cache.cache_level); + + /* Probe allocation features (monitoring not yet implemented) */ + err =3D cbqri_probe_feature(ctrl, CBQRI_CC_ALLOC_CTL_OFF, + CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT, + &status, &ctrl->cc.supports_alloc_at_code); + if (err) + return err; + + if (status =3D=3D CBQRI_CC_ALLOC_CTL_STATUS_SUCCESS) { + ctrl->alloc_capable =3D true; + exposed_alloc_capable =3D true; + } + + return 0; +} + +static int cbqri_probe_bc(struct cbqri_controller *ctrl) +{ + int err, status; + u64 reg; + + reg =3D ioread64(ctrl->base + CBQRI_BC_CAPABILITIES_OFF); + if (reg =3D=3D 0) + return -ENODEV; + + ctrl->ver_minor =3D FIELD_GET(CBQRI_BC_CAPABILITIES_VER_MINOR_MASK, reg); + ctrl->ver_major =3D FIELD_GET(CBQRI_BC_CAPABILITIES_VER_MAJOR_MASK, reg); + ctrl->bc.nbwblks =3D FIELD_GET(CBQRI_BC_CAPABILITIES_NBWBLKS_MASK, reg); + ctrl->bc.mrbwb =3D FIELD_GET(CBQRI_BC_CAPABILITIES_MRBWB_MASK, reg); + + if (!ctrl->bc.nbwblks) { + pr_err("bandwidth controller has nbwblks=3D0\n"); + return -EINVAL; + } + + pr_debug("version=3D%d.%d nbwblks=3D%d mrbwb=3D%d\n", + ctrl->ver_major, ctrl->ver_minor, + ctrl->bc.nbwblks, ctrl->bc.mrbwb); + + /* Probe allocation features (monitoring not yet implemented) */ + err =3D cbqri_probe_feature(ctrl, CBQRI_BC_ALLOC_CTL_OFF, + CBQRI_BC_ALLOC_CTL_OP_READ_LIMIT, + &status, &ctrl->bc.supports_alloc_at_code); + if (err) + return err; + + if (status =3D=3D CBQRI_BC_ALLOC_CTL_STATUS_SUCCESS) { + ctrl->alloc_capable =3D true; + exposed_alloc_capable =3D true; + } + + return 0; +} + +static int cbqri_probe_controller(struct cbqri_controller *ctrl) +{ + int err; + + pr_debug("controller info: type=3D%d addr=3D%pa size=3D%pa max-rcid=3D%u = max-mcid=3D%u\n", + ctrl->type, &ctrl->addr, &ctrl->size, + ctrl->rcid_count, ctrl->mcid_count); + + if (!ctrl->addr) { + pr_warn("%s(): controller has invalid addr=3D0x0, skipping\n", __func__); + return -EINVAL; + } + + if (!request_mem_region(ctrl->addr, ctrl->size, "cbqri_controller")) { + pr_err("%s(): request_mem_region failed for %pa\n", + __func__, &ctrl->addr); + return -EBUSY; + } + + ctrl->base =3D ioremap(ctrl->addr, ctrl->size); + if (!ctrl->base) { + pr_err("%s(): ioremap failed for %pa\n", __func__, &ctrl->addr); + err =3D -ENOMEM; + goto err_release; + } + + spin_lock_init(&ctrl->lock); + + switch (ctrl->type) { + case CBQRI_CONTROLLER_TYPE_CAPACITY: + err =3D cbqri_probe_cc(ctrl); + break; + case CBQRI_CONTROLLER_TYPE_BANDWIDTH: + err =3D cbqri_probe_bc(ctrl); + break; + default: + pr_err("unknown controller type %d\n", ctrl->type); + err =3D -ENODEV; + break; + } + + if (err) + goto err_iounmap; + + /* + * max_rmid is used by resctrl_arch_system_num_rmid_idx() + * Find the smallest mcid_count amongst all controllers. + */ + max_rmid =3D min(max_rmid, ctrl->mcid_count); + + return 0; + +err_iounmap: + iounmap(ctrl->base); + ctrl->base =3D NULL; +err_release: + release_mem_region(ctrl->addr, ctrl->size); + return err; +} diff --git a/include/linux/riscv_qos.h b/include/linux/riscv_qos.h new file mode 100644 index 000000000000..0f3daae2e84f --- /dev/null +++ b/include/linux/riscv_qos.h @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __LINUX_RISCV_QOS_H +#define __LINUX_RISCV_QOS_H + +#include +#include + +#include + +enum cbqri_controller_type { + CBQRI_CONTROLLER_TYPE_CAPACITY, + CBQRI_CONTROLLER_TYPE_BANDWIDTH, + CBQRI_CONTROLLER_TYPE_UNKNOWN +}; + +/* Capacity Controller hardware capabilities */ +struct riscv_cbqri_capacity_caps { + u16 ncblks; /* number of capacity blocks */ + + bool supports_alloc_at_code; + bool supports_alloc_op_flush_rcid; +}; + +/* Bandwidth Controller hardware capabilities */ +struct riscv_cbqri_bandwidth_caps { + u16 nbwblks; /* number of bandwidth blocks */ + u16 mrbwb; /* max reserved bw blocks */ + + bool supports_alloc_at_code; +}; + +struct cbqri_controller { + void __iomem *base; + /* + * Protects multi-step MMIO register sequences on this controller. + * CBQRI operations (e.g. CONFIG_LIMIT, READ_LIMIT) require writing + * an operation register, waiting for the busy flag to clear, then + * reading back the result. These sequences must be atomic per + * controller to prevent interleaving. + */ + spinlock_t lock; + + int ver_major; + int ver_minor; + + struct riscv_cbqri_bandwidth_caps bc; + struct riscv_cbqri_capacity_caps cc; + + bool alloc_capable; + + phys_addr_t addr; + phys_addr_t size; + enum cbqri_controller_type type; + u32 rcid_count; + u32 mcid_count; + struct list_head list; + + struct cache_controller { + u32 cache_level; + u32 cache_size; /* in bytes */ + struct cpumask cpu_mask; + /* Unique Cache ID from the PPTT table's Cache Type Structure */ + u32 cache_id; + } cache; + + struct mem_controller { + /* Proximity Domain from SRAT table Memory Affinity Controller */ + u32 prox_dom; + struct cpumask cpu_mask; + } mem; +}; + +extern struct list_head cbqri_controllers; + +#endif /* __LINUX_RISCV_QOS_H */ --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7E3AF313532; Wed, 15 Apr 2026 01:56:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218215; cv=none; b=EszF5ianPgNyjh92iOPciEkQ5ep63xiXGLnzMSECLRjNCXb4Jj4cs08WZvrFIKDWXqrnzk3Qjfc1jvxy6r4JaiuNwJ+271+JYu/im4IEwMiqMSfj3O7qBA8VWQKuva0mgPLlBm8dltZL+TVzVey2FC+wGpLOai4gQjyzBd1B7l0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218215; c=relaxed/simple; bh=W4I3+X1ieckjmz3X1WF1vjk4ckKSk0GxVxGUjTVFtBA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TaXFLhjtEc436m1xI5K5PoGmkSko5F/o2A+VQe1T5QAh9nXRHc6uNKyFbR0R/QbexSoFi+RnztCaB2zgDzijX/FDeEZSyt1/BqzkXlbrBAju6Pol7b9GUrhJ3tBUk7nHYdsVgud65pVlPJVgKkPzvQqtDNwJ4WPWwsxYK5LU/8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PKNLvZhT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PKNLvZhT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0AECC2BCB6; Wed, 15 Apr 2026 01:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218215; bh=W4I3+X1ieckjmz3X1WF1vjk4ckKSk0GxVxGUjTVFtBA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PKNLvZhTQaDAmBSK4tQoU9B+bMl9EY02u1JSVYPhfddifDz8GrEYMsV71Q7Hjr5w+ Eh9lMcZKasjWHip5fB1paqmQ2TOMc9gMEKp+cukRJS0jJuzoop0gPPu/o1ZzfNmWA6 DnF832vSkwyE54hdvVOew3lkC2YUJ+rcEVszV+PxaU5+TRbJURNzFJyQRlpNRKN+H4 PONJ5NGUjlleHHsKrgsjkhEUSOY8P2Ks3xayi4sIiCClx+j1TTxtNoi5zNSy+qWtAi Es6wj+U7t/rikFYU+qxqplGcZghBQ6Uc6Bcnng9WxnmoJ+vnFNOPouwh2QPO4xnIzP lAQW/cOkf6uMw== From: Drew Fustini Date: Tue, 14 Apr 2026 18:53:59 -0700 Subject: [PATCH RFC v3 05/11] RISC-V: QoS: add resctrl arch callbacks for CBQRI controllers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-5-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=13493; i=fustini@kernel.org; h=from:subject:message-id; bh=W4I3+X1ieckjmz3X1WF1vjk4ckKSk0GxVxGUjTVFtBA=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5Dk8dpNau/jTN8LcgeLGd6Z6WttyVqy6IRzjObU+ 9Xyc2ZM6ShlYRDjYpAVU2TZ9CHvwhKv0K8L5r/YBjOHlQlkCAMXpwBMJPIDI8OmWa83nXOU1ltU wyf8mHF9plmk7vv0/imlJ/or4nOKgtYxMjwQ9924bNec8H9Twr6oeS0vLtmxkDnleN3a+F1nrT7 EpfACAA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Implement the resctrl architecture callbacks required by the resctrl filesystem and expose them via arch/riscv/include/asm/resctrl.h. These include capability reporting, CDP enable/disable, CLOSID/RMID encoding, scheduler integration (sched_in, set_closid_rmid, sync_cpu_closid_rmid), domain config read/write (update_one, update_domains, get_config), and stub implementations for monitoring operations not yet supported on RISC-V. The function prototypes and inline stubs are declared in include/linux/riscv_qos.h alongside the implementations in arch/riscv/kernel/qos/qos_resctrl.c. Co-developed-by: Adrien Ricciardi Signed-off-by: Adrien Ricciardi Signed-off-by: Drew Fustini --- MAINTAINERS | 1 + arch/riscv/include/asm/resctrl.h | 7 + arch/riscv/kernel/qos/qos_resctrl.c | 367 ++++++++++++++++++++++++++++++++= ++++ include/linux/riscv_qos.h | 33 ++++ 4 files changed, 408 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 6a66d7047c51..af9698a16439 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22784,6 +22784,7 @@ R: yunhui cui L: linux-riscv@lists.infradead.org S: Supported F: arch/riscv/include/asm/qos.h +F: arch/riscv/include/asm/resctrl.h F: arch/riscv/kernel/qos/ F: include/linux/riscv_qos.h =20 diff --git a/arch/riscv/include/asm/resctrl.h b/arch/riscv/include/asm/resc= trl.h new file mode 100644 index 000000000000..48ad45cbe25c --- /dev/null +++ b/arch/riscv/include/asm/resctrl.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_RISCV_RESCTRL_H +#define _ASM_RISCV_RESCTRL_H + +#include + +#endif /* _ASM_RISCV_RESCTRL_H */ diff --git a/arch/riscv/kernel/qos/qos_resctrl.c b/arch/riscv/kernel/qos/qo= s_resctrl.c index 6d294f2f2504..a4a120f89840 100644 --- a/arch/riscv/kernel/qos/qos_resctrl.c +++ b/arch/riscv/kernel/qos/qos_resctrl.c @@ -2,6 +2,7 @@ =20 #define pr_fmt(fmt) "qos: resctrl: " fmt =20 +#include #include #include #include @@ -430,3 +431,369 @@ static int cbqri_probe_controller(struct cbqri_contro= ller *ctrl) release_mem_region(ctrl->addr, ctrl->size); return err; } + +bool resctrl_arch_alloc_capable(void) +{ + return exposed_alloc_capable; +} + +bool resctrl_arch_mon_capable(void) +{ + /* Monitoring not yet implemented */ + return false; +} + +bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level rid) +{ + switch (rid) { + case RDT_RESOURCE_L2: + return is_cdp_l2_enabled; + + case RDT_RESOURCE_L3: + return is_cdp_l3_enabled; + + default: + return false; + } +} + +int resctrl_arch_set_cdp_enabled(enum resctrl_res_level rid, bool enable) +{ + switch (rid) { + case RDT_RESOURCE_L2: + if (!exposed_cdp_l2_capable) + return -ENODEV; + is_cdp_l2_enabled =3D enable; + break; + + case RDT_RESOURCE_L3: + if (!exposed_cdp_l3_capable) + return -ENODEV; + is_cdp_l3_enabled =3D enable; + break; + + default: + return -ENODEV; + } + + return 0; +} + +struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l) +{ + if (l >=3D RDT_NUM_RESOURCES) + return NULL; + + return &cbqri_resctrl_resources[l].resctrl_res; +} + +bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt) +{ + return false; +} + +void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, + enum resctrl_event_id evtid) +{ + /* RISC-V can always read an rmid, nothing needs allocating */ + return NULL; +} + +void resctrl_arch_mon_ctx_free(struct rdt_resource *r, + enum resctrl_event_id evtid, void *arch_mon_ctx) +{ + /* No arch-private monitoring context to free */ +} + +void resctrl_arch_config_cntr(struct rdt_resource *r, struct rdt_l3_mon_do= main *d, + enum resctrl_event_id evtid, u32 rmid, u32 closid, + u32 cntr_id, bool assign) +{ + /* MBM counter assignment not supported */ +} + +int resctrl_arch_cntr_read(struct rdt_resource *r, struct rdt_l3_mon_domai= n *d, + u32 unused, u32 rmid, int cntr_id, + enum resctrl_event_id eventid, u64 *val) +{ + /* MBM counter assignment not supported */ + return -EOPNOTSUPP; +} + +bool resctrl_arch_mbm_cntr_assign_enabled(struct rdt_resource *r) +{ + /* MBM counter assignment not supported */ + return false; +} + +int resctrl_arch_mbm_cntr_assign_set(struct rdt_resource *r, bool enable) +{ + /* MBM counter assignment not supported */ + return 0; +} + +void resctrl_arch_reset_cntr(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, + u32 unused, u32 rmid, int cntr_id, + enum resctrl_event_id eventid) +{ + /* MBM counter assignment not supported */ +} + +bool resctrl_arch_get_io_alloc_enabled(struct rdt_resource *r) +{ + /* CBQRI does not have I/O-specific allocation */ + return false; +} + +int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable) +{ + /* CBQRI does not have I/O-specific allocation */ + return 0; +} + +/* + * Note about terminology between x86 (Intel RDT/AMD QoS) and RISC-V: + * CLOSID on x86 is RCID on RISC-V + * RMID on x86 is MCID on RISC-V + */ +u32 resctrl_arch_get_num_closid(struct rdt_resource *res) +{ + struct cbqri_resctrl_res *hw_res; + + hw_res =3D container_of(res, struct cbqri_resctrl_res, resctrl_res); + + return hw_res->max_rcid; +} + +u32 resctrl_arch_system_num_rmid_idx(void) +{ + return max_rmid; +} + +u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid) +{ + return rmid; +} + +void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid) +{ + *closid =3D RISCV_RESCTRL_EMPTY_CLOSID; + *rmid =3D idx; +} + +void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmi= d) +{ + u32 srmcfg; + + WARN_ON_ONCE((closid & SRMCFG_RCID_MASK) !=3D closid); + WARN_ON_ONCE((rmid & SRMCFG_MCID_MASK) !=3D rmid); + + srmcfg =3D rmid << SRMCFG_MCID_SHIFT; + srmcfg |=3D closid; + WRITE_ONCE(per_cpu(cpu_srmcfg_default, cpu), srmcfg); +} + +void resctrl_arch_sched_in(struct task_struct *tsk) +{ + __switch_to_srmcfg(tsk); +} + +void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32= rmid) +{ + u32 srmcfg; + + WARN_ON_ONCE((closid & SRMCFG_RCID_MASK) !=3D closid); + WARN_ON_ONCE((rmid & SRMCFG_MCID_MASK) !=3D rmid); + + srmcfg =3D rmid << SRMCFG_MCID_SHIFT; + srmcfg |=3D closid; + WRITE_ONCE(tsk->thread.srmcfg, srmcfg); +} + +void resctrl_arch_sync_cpu_closid_rmid(void *info) +{ + struct resctrl_cpu_defaults *r =3D info; + + lockdep_assert_preemption_disabled(); + + if (r) { + resctrl_arch_set_cpu_default_closid_rmid(smp_processor_id(), + r->closid, r->rmid); + } + + resctrl_arch_sched_in(current); +} + +bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid) +{ + return (READ_ONCE(tsk->thread.srmcfg) & SRMCFG_RCID_MASK) =3D=3D closid; +} + +bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid) +{ + u32 tsk_rmid; + + tsk_rmid =3D READ_ONCE(tsk->thread.srmcfg); + tsk_rmid >>=3D SRMCFG_MCID_SHIFT; + tsk_rmid &=3D SRMCFG_MCID_MASK; + + return tsk_rmid =3D=3D rmid; +} + +int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_domain_hdr *= hdr, + u32 closid, u32 rmid, enum resctrl_event_id eventid, + void *arch_priv, u64 *val, void *arch_mon_ctx) +{ + /* + * Cache occupancy and bandwidth monitoring are not yet implemented + * for RISC-V CBQRI. This will be added in a future series once the + * resctrl framework supports monitoring domains at non-L3 scopes. + */ + return -EOPNOTSUPP; +} + +void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_l3_mon_dom= ain *d, + u32 closid, u32 rmid, enum resctrl_event_id eventid) +{ + /* Monitoring not yet supported; nothing to reset */ +} + +void resctrl_arch_mon_event_config_read(void *info) +{ + /* Monitoring not yet supported; no event config */ +} + +void resctrl_arch_mon_event_config_write(void *info) +{ + /* Monitoring not yet supported; no event config */ +} + +void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_l3_mon= _domain *d) +{ + /* Monitoring not yet supported; nothing to reset */ +} + +void resctrl_arch_reset_all_ctrls(struct rdt_resource *r) +{ + /* not implemented for the RISC-V resctrl implementation */ +} + +void resctrl_arch_pre_mount(void) +{ + /* All controllers discovered at boot via late_initcall; nothing to do */ +} + +int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_ctrl_domain= *d, + u32 closid, enum resctrl_conf_type t, u32 cfg_val) +{ + struct cbqri_controller *ctrl; + struct cbqri_resctrl_dom *dom; + struct cbqri_config cfg; + int err =3D 0; + + dom =3D container_of(d, struct cbqri_resctrl_dom, resctrl_ctrl_dom); + ctrl =3D dom->hw_ctrl; + + if (!r->alloc_capable) + return -EINVAL; + + switch (r->rid) { + case RDT_RESOURCE_L2: + case RDT_RESOURCE_L3: + cfg.cbm =3D cfg_val; + err =3D cbqri_apply_cache_config(dom, closid, t, &cfg); + break; + case RDT_RESOURCE_MBA: + /* convert from percentage to bandwidth blocks */ + cfg.rbwb =3D cfg_val * ctrl->bc.nbwblks / 100; + cfg.rbwb =3D min_t(u64, cfg.rbwb, ctrl->bc.mrbwb); + err =3D cbqri_apply_bw_config(dom, closid, t, &cfg); + break; + default: + return -EINVAL; + } + + return err; +} + +int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid) +{ + struct resctrl_staged_config *cfg; + enum resctrl_conf_type t; + struct rdt_ctrl_domain *d; + int err =3D 0; + + /* Walking r->ctrl_domains, ensure it can't race with cpuhp */ + lockdep_assert_cpus_held(); + + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { + for (t =3D 0; t < CDP_NUM_TYPES; t++) { + cfg =3D &d->staged_config[t]; + if (!cfg->have_new_ctrl) + continue; + err =3D resctrl_arch_update_one(r, d, closid, t, cfg->new_ctrl); + if (err) { + pr_err("%s(): update failed (err=3D%d)\n", __func__, err); + return err; + } + } + } + return err; +} + +u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain= *d, + u32 closid, enum resctrl_conf_type type) +{ + struct cbqri_resctrl_dom *hw_dom; + struct cbqri_controller *ctrl; + u32 val; + u32 rbwb; + int err; + + hw_dom =3D container_of(d, struct cbqri_resctrl_dom, resctrl_ctrl_dom); + + ctrl =3D hw_dom->hw_ctrl; + + val =3D resctrl_get_default_ctrl(r); + + if (!r->alloc_capable) + return val; + + spin_lock(&ctrl->lock); + + switch (r->rid) { + case RDT_RESOURCE_L2: + case RDT_RESOURCE_L3: + /* Clear cc_block_mask before read limit operation */ + cbqri_set_cbm(ctrl, 0); + + /* Capacity read limit operation for RCID (closid) */ + err =3D cbqri_cc_alloc_op(ctrl, CBQRI_CC_ALLOC_CTL_OP_READ_LIMIT, closid= , type); + if (err < 0) { + pr_err("%s(): operation failed: err =3D %d\n", __func__, err); + break; + } + + /* Read capacity block mask for RCID (closid) */ + val =3D ioread64(ctrl->base + CBQRI_CC_BLOCK_MASK_OFF); + break; + + case RDT_RESOURCE_MBA: + /* Bandwidth read limit operation for RCID (closid) */ + err =3D cbqri_bc_alloc_op(ctrl, CBQRI_BC_ALLOC_CTL_OP_READ_LIMIT, closid= ); + if (err < 0) { + pr_err("%s(): operation failed: err =3D %d\n", __func__, err); + break; + } + + rbwb =3D cbqri_get_rbwb(ctrl); + val =3D DIV_ROUND_UP(rbwb * 100, ctrl->bc.nbwblks); + break; + + default: + break; + } + + spin_unlock(&ctrl->lock); + return val; +} diff --git a/include/linux/riscv_qos.h b/include/linux/riscv_qos.h index 0f3daae2e84f..1712fb12f6bc 100644 --- a/include/linux/riscv_qos.h +++ b/include/linux/riscv_qos.h @@ -3,6 +3,7 @@ #ifndef __LINUX_RISCV_QOS_H #define __LINUX_RISCV_QOS_H =20 +#include #include #include =20 @@ -73,4 +74,36 @@ struct cbqri_controller { =20 extern struct list_head cbqri_controllers; =20 +bool resctrl_arch_alloc_capable(void); +bool resctrl_arch_mon_capable(void); + +struct rdt_resource; +/* + * Note about terminology between x86 (Intel RDT/AMD QoS) and RISC-V: + * CLOSID on x86 is RCID on RISC-V + * RMID on x86 is MCID on RISC-V + * CDP on x86 is AT (access type) on RISC-V + */ +u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid); +void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid); +void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmi= d); +void resctrl_arch_sched_in(struct task_struct *tsk); +void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32= rmid); +bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid); +bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid= ); +void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, enum resctrl_even= t_id evtid); +void resctrl_arch_mon_ctx_free(struct rdt_resource *r, enum resctrl_event_= id evtid, + void *arch_mon_ctx); + +static inline unsigned int resctrl_arch_round_mon_val(unsigned int val) +{ + return val; +} + +/* Not needed for RISC-V */ +static inline void resctrl_arch_enable_mon(void) { } +static inline void resctrl_arch_disable_mon(void) { } +static inline void resctrl_arch_enable_alloc(void) { } +static inline void resctrl_arch_disable_alloc(void) { } + #endif /* __LINUX_RISCV_QOS_H */ --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5A870315D3E; Wed, 15 Apr 2026 01:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218216; cv=none; b=ZHXQEeY6B1E+fA3Lq80s+FuKc2C+1bQgUImv2/WhLl8AKCHCUxdXX3zH9GwIfVsVaP+iXLhceUOBBtTwBQYnWsBT743ojO+/f2JP/1eK/BSrKdGSQy4Kw29feyFCgK6M9JLTwhPFg5VW5k/k2VttW6o9MWHOORvj+uYvS1yZpxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218216; c=relaxed/simple; bh=Lea9qWwpGuHllOHQE9OSrkA/WuGf4SHRx3thbVsosbw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B9q6VUC1zE/UW2DIC68fUh7SWQIHmyjEGhr/s7uNdDzES8tzY36rrd3VKhXTuqojWZUWxgynPyZkp64K84hbcW05XagMRB4l/Ngh3MeeqrT+xKSAS7SUEcwI/KJRoNvKdSOou0zvSgCeqL4SXwc8FDW0vu+m/vAVw0Uo+/KqAMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XFKveISx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XFKveISx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FDC5C2BCB5; Wed, 15 Apr 2026 01:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218216; bh=Lea9qWwpGuHllOHQE9OSrkA/WuGf4SHRx3thbVsosbw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XFKveISxFV8IdtZhbDOETnR0iVSzkuTt64rFB9vLFD7PCIF9+WpIVVPuRldO3FOzl E3AXRXqSsJqgCB/TCs1inhulQhzi/34WyeiPFjC9/b8kHce1pi+lK0bD1Wo4rtAMUL TZ3Ns57QCjOZ0efUYU9/0l3J94LAPVXetQIXpPRak94AZVap8/dGSvgFcuAFLsbg+f YrhcDELM9WdTsJ3Qnh4+BajHUo7MqGsoeGLFQk3nxSmgtqPZW+bz7NlO/HD15OIG4p qs3KqLUwv6YSLIC0D4yKVD0xcamC5AjjN8xo/1Y1yYOH7P9sJ8A/dgiUPD7i1O8O4S fFCGDmcBohBEg== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:00 -0700 Subject: [PATCH RFC v3 06/11] RISC-V: QoS: add resctrl setup and domain management Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-6-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=9762; i=fustini@kernel.org; h=from:subject:message-id; bh=Lea9qWwpGuHllOHQE9OSrkA/WuGf4SHRx3thbVsosbw=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5D0M+h2zLGQmp4rL+f2pq1y1Pn8Ic7wf9sN8+XxL hxSD+0Od5SyMIhxMciKKbJs+pB3YYlX6NcF819sg5nDygQyhIGLUwAmcuo1w/+KyeqHL1/KFPc5 6+orKpmnP5WtccUdSV2ukoUKwjFeYWaMDC+t9rpuE2O7u+UBU9ZPn8DmvZHB++853VZ5ntaZ+dL 1HQMA X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add the setup and domain management layer: domain allocation (qos_new_domain), controller value initialization (qos_init_domain_ctrlval), resource struct initialization for cache and bandwidth resources, domain registration with the resctrl filesystem (qos_resctrl_add_controller_domain), and the top-level setup function (qos_resctrl_setup) that probes all controllers and calls resctrl_init(). Also add qos_resctrl_online_cpu() and qos_resctrl_offline_cpu() for CPU hotplug integration. Co-developed-by: Adrien Ricciardi Signed-off-by: Adrien Ricciardi Signed-off-by: Drew Fustini --- arch/riscv/kernel/qos/qos_resctrl.c | 295 ++++++++++++++++++++++++++++++++= +++- 1 file changed, 294 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/qos/qos_resctrl.c b/arch/riscv/kernel/qos/qo= s_resctrl.c index a4a120f89840..8d7e3b0abb75 100644 --- a/arch/riscv/kernel/qos/qos_resctrl.c +++ b/arch/riscv/kernel/qos/qos_resctrl.c @@ -675,7 +675,23 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *= r, struct rdt_l3_mon_domai =20 void resctrl_arch_reset_all_ctrls(struct rdt_resource *r) { - /* not implemented for the RISC-V resctrl implementation */ + struct cbqri_resctrl_res *hw_res; + struct rdt_ctrl_domain *d; + enum resctrl_conf_type t; + u32 default_ctrl; + int i; + + lockdep_assert_cpus_held(); + + hw_res =3D container_of(r, struct cbqri_resctrl_res, resctrl_res); + default_ctrl =3D resctrl_get_default_ctrl(r); + + list_for_each_entry(d, &r->ctrl_domains, hdr.list) { + for (i =3D 0; i < hw_res->max_rcid; i++) { + for (t =3D 0; t < CDP_NUM_TYPES; t++) + resctrl_arch_update_one(r, d, i, t, default_ctrl); + } + } } =20 void resctrl_arch_pre_mount(void) @@ -797,3 +813,280 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, s= truct rdt_ctrl_domain *d, spin_unlock(&ctrl->lock); return val; } + +static struct rdt_ctrl_domain *qos_new_domain(struct cbqri_controller *ctr= l) +{ + struct cbqri_resctrl_dom *hw_dom; + struct rdt_ctrl_domain *domain; + + hw_dom =3D kzalloc_obj(*hw_dom, GFP_KERNEL); + if (!hw_dom) + return NULL; + + /* associate this cbqri_controller with the domain */ + hw_dom->hw_ctrl =3D ctrl; + + /* the rdt_domain struct from inside the cbqri_resctrl_dom struct */ + domain =3D &hw_dom->resctrl_ctrl_dom; + + INIT_LIST_HEAD(&domain->hdr.list); + + return domain; +} + +static int qos_init_domain_ctrlval(struct rdt_resource *r, struct rdt_ctrl= _domain *d) +{ + struct cbqri_resctrl_res *hw_res; + int err =3D 0; + int i; + + hw_res =3D container_of(r, struct cbqri_resctrl_res, resctrl_res); + + for (i =3D 0; i < hw_res->max_rcid; i++) { + err =3D resctrl_arch_update_one(r, d, i, 0, resctrl_get_default_ctrl(r)); + if (err) + return err; + } + return 0; +} + +static int qos_init_cache_resource(struct cbqri_controller *ctrl, + struct cbqri_resctrl_res *cbqri_res, + enum resctrl_res_level rid, char *name, + enum resctrl_scope scope) +{ + struct rdt_resource *res =3D &cbqri_res->resctrl_res; + + /* Already initialized by a previous controller at this cache level */ + if (res->name) { + if (cbqri_res->max_rcid !=3D ctrl->rcid_count || + res->cache.cbm_len !=3D ctrl->cc.ncblks) { + pr_err("%s controllers have mismatched capabilities\n", + name); + return -EINVAL; + } + return 0; + } + + cbqri_res->max_rcid =3D ctrl->rcid_count; + cbqri_res->max_mcid =3D ctrl->mcid_count; + res->rid =3D rid; + res->name =3D name; + res->alloc_capable =3D ctrl->alloc_capable; + res->schema_fmt =3D RESCTRL_SCHEMA_BITMAP; + res->ctrl_scope =3D scope; + res->cache.cbm_len =3D ctrl->cc.ncblks; + res->cache.shareable_bits =3D resctrl_get_default_ctrl(res); + res->cache.min_cbm_bits =3D 1; + return 0; +} + +static int qos_init_membw_resource(struct cbqri_controller *ctrl, + struct cbqri_resctrl_res *cbqri_res) +{ + struct rdt_resource *res =3D &cbqri_res->resctrl_res; + + if (res->name) { + if (cbqri_res->max_rcid !=3D ctrl->rcid_count || + res->membw.max_bw !=3D DIV_ROUND_UP(ctrl->bc.mrbwb * 100, + ctrl->bc.nbwblks)) { + pr_err("MB controllers have mismatched capabilities\n"); + return -EINVAL; + } + return 0; + } + + cbqri_res->max_rcid =3D ctrl->rcid_count; + cbqri_res->max_mcid =3D ctrl->mcid_count; + res->rid =3D RDT_RESOURCE_MBA; + res->name =3D "MB"; + res->alloc_capable =3D ctrl->alloc_capable; + res->schema_fmt =3D RESCTRL_SCHEMA_RANGE; + /* + * resctrl requires a cache scope for MBA domains. Use L3 as a + * proxy until the framework supports non-cache scopes for + * bandwidth resources. + */ + res->ctrl_scope =3D RESCTRL_L3_CACHE; + res->membw.delay_linear =3D true; + res->membw.arch_needs_linear =3D true; + res->membw.throttle_mode =3D THREAD_THROTTLE_UNDEFINED; + res->membw.min_bw =3D 1; + res->membw.max_bw =3D DIV_ROUND_UP(ctrl->bc.mrbwb * 100, ctrl->bc.nbwblks= ); + res->membw.bw_gran =3D 1; + return 0; +} + +static int qos_resctrl_add_controller_domain(struct cbqri_controller *ctrl) +{ + struct rdt_ctrl_domain *domain; + struct cbqri_resctrl_res *cbqri_res =3D NULL; + struct rdt_resource *res =3D NULL; + struct list_head *pos =3D NULL; + int err; + + domain =3D qos_new_domain(ctrl); + if (!domain) + return -ENOSPC; + + switch (ctrl->type) { + case CBQRI_CONTROLLER_TYPE_CAPACITY: + cpumask_copy(&domain->hdr.cpu_mask, &ctrl->cache.cpu_mask); + domain->hdr.id =3D ctrl->cache.cache_id; + + if (ctrl->cache.cache_level =3D=3D 2) { + cbqri_res =3D &cbqri_resctrl_resources[RDT_RESOURCE_L2]; + err =3D qos_init_cache_resource(ctrl, cbqri_res, + RDT_RESOURCE_L2, "L2", + RESCTRL_L2_CACHE); + } else if (ctrl->cache.cache_level =3D=3D 3) { + cbqri_res =3D &cbqri_resctrl_resources[RDT_RESOURCE_L3]; + err =3D qos_init_cache_resource(ctrl, cbqri_res, + RDT_RESOURCE_L3, "L3", + RESCTRL_L3_CACHE); + } else { + pr_err("unknown cache level %d\n", ctrl->cache.cache_level); + err =3D -ENODEV; + } + if (err) + goto err_free_domain; + res =3D &cbqri_res->resctrl_res; + break; + + case CBQRI_CONTROLLER_TYPE_BANDWIDTH: + cpumask_copy(&domain->hdr.cpu_mask, &ctrl->mem.cpu_mask); + domain->hdr.id =3D ctrl->mem.prox_dom; + if (ctrl->alloc_capable) { + cbqri_res =3D &cbqri_resctrl_resources[RDT_RESOURCE_MBA]; + err =3D qos_init_membw_resource(ctrl, cbqri_res); + if (err) + goto err_free_domain; + res =3D &cbqri_res->resctrl_res; + } + break; + + default: + pr_err("unknown controller type %d\n", ctrl->type); + err =3D -ENODEV; + goto err_free_domain; + } + + if (!res) + goto out; + + err =3D qos_init_domain_ctrlval(res, domain); + if (err) + goto err_free_domain; + + if (resctrl_find_domain(&res->ctrl_domains, domain->hdr.id, &pos)) { + pr_err("duplicate domain id %d for resource %s\n", + domain->hdr.id, res->name); + err =3D -EEXIST; + goto err_free_domain; + } + if (pos) + list_add_tail(&domain->hdr.list, pos); + else + list_add_tail(&domain->hdr.list, &res->ctrl_domains); + + err =3D resctrl_online_ctrl_domain(res, domain); + if (err) { + pr_err("failed to online domain %d\n", domain->hdr.id); + list_del(&domain->hdr.list); + goto err_free_domain; + } + +out: + return 0; + +err_free_domain: + kfree(container_of(domain, struct cbqri_resctrl_dom, resctrl_ctrl_dom)); + return err; +} + +int qos_resctrl_setup(void) +{ + struct rdt_ctrl_domain *domain, *domain_temp; + struct cbqri_controller *ctrl; + struct cbqri_resctrl_res *res; + int err =3D 0; + int i =3D 0; + + max_rmid =3D U32_MAX; + + for (i =3D 0; i < RDT_NUM_RESOURCES; i++) { + res =3D &cbqri_resctrl_resources[i]; + INIT_LIST_HEAD(&res->resctrl_res.ctrl_domains); + INIT_LIST_HEAD(&res->resctrl_res.mon_domains); + res->resctrl_res.rid =3D i; + } + + list_for_each_entry(ctrl, &cbqri_controllers, list) { + err =3D cbqri_probe_controller(ctrl); + if (err) { + pr_err("%s(): failed (%d)\n", __func__, err); + goto err_free_controllers_list; + } + + err =3D qos_resctrl_add_controller_domain(ctrl); + if (err) { + pr_err("%s(): failed to add controller domain (%d)\n", __func__, err); + goto err_free_controllers_list; + } + + /* + * CDP (code data prioritization) on x86 is similar to + * the AT (access type) field in CBQRI. CDP only supports + * caches so this must be a CBQRI capacity controller. + */ + if (ctrl->type =3D=3D CBQRI_CONTROLLER_TYPE_CAPACITY && + ctrl->cc.supports_alloc_at_code) { + if (ctrl->cache.cache_level =3D=3D 2) + exposed_cdp_l2_capable =3D true; + else + exposed_cdp_l3_capable =3D true; + } + } + pr_debug("alloc=3D%d cdp_l2=3D%d cdp_l3=3D%d\n", + exposed_alloc_capable, + exposed_cdp_l2_capable, exposed_cdp_l3_capable); + + err =3D resctrl_init(); + if (err) + goto err_free_controllers_list; + + return 0; + +err_free_controllers_list: + for (i =3D 0; i < RDT_NUM_RESOURCES; i++) { + res =3D &cbqri_resctrl_resources[i]; + list_for_each_entry_safe(domain, domain_temp, &res->resctrl_res.ctrl_dom= ains, + hdr.list) { + resctrl_offline_ctrl_domain(&res->resctrl_res, domain); + list_del(&domain->hdr.list); + kfree(container_of(domain, struct cbqri_resctrl_dom, resctrl_ctrl_dom)); + } + } + + list_for_each_entry(ctrl, &cbqri_controllers, list) { + if (!ctrl->base) + break; + iounmap(ctrl->base); + ctrl->base =3D NULL; + release_mem_region(ctrl->addr, ctrl->size); + } + + return err; +} + +int qos_resctrl_online_cpu(unsigned int cpu) +{ + resctrl_online_cpu(cpu); + return 0; +} + +int qos_resctrl_offline_cpu(unsigned int cpu) +{ + resctrl_offline_cpu(cpu); + return 0; +} --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BB852308F2A; Wed, 15 Apr 2026 01:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218216; cv=none; b=bOBjbQcWzEILFeqFSSjV5/nJ+3Chf07ISfQVgkxHzHgHsKpWI1Y4R0pblTq7LY5VZkUsTfiXh7suJLPWlFtVSXdxaNmf37284TWj0xpTYNo14FFvYHfcI9sRhZG4nfIOjQ2RHYuJFPe7aexVr0m93cof10YFcQxpTwypNYAm6eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218216; c=relaxed/simple; bh=CSELH8cHpzjOmF3alV9G48Nrn3aORTFDw3pzNP6kshc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WHO3OSKOHjbHSteNKrv08Dj9ktbpfItAL5vGl9ZFyiJ9NYqSj25EyCA7D/ERqGT1t7hH5m80kdO9+uiSEy7DX2lB47gdSG/BigUIhrIkkOYW8964g8Xnr5mr34Cvn0+dBrx3nmdx+QsBClJjOpgkGPdHGCeJSFfNHzmstxcz52I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dEPuZPdM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dEPuZPdM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 243DDC2BCB3; Wed, 15 Apr 2026 01:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218216; bh=CSELH8cHpzjOmF3alV9G48Nrn3aORTFDw3pzNP6kshc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dEPuZPdMs1tRecUY1gZ7qQV1Da89cGCyopTPMPDWokXVkOSaUdpP/ZQqtWVHa7z29 j3YNBLkJuCuU/q7w0CBwfCLL1rrRD43/vhXi2d8R6c2pd+FrA5HSmd4HlIAAcGHqxp kYAvduGrB4NNIk0cI8phJNDQgmLkJV0Fh2LcmyKGXBj1YnoYt5wKi6ZrTywhGGi01s sKZJGS+jLULC+FicyJl3aaBFP4C65AfxE1AwgyBuQgRS5F1xbqW87npAwvydVBe8qX w/+7JO7T8c9v9uF7LV0FKn7YJ1LZCTEGIbYmBYBVTYrkN3QnAiqLA+XcAd7yEzLPcT 2/CUmvFhNINzw== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:01 -0700 Subject: [PATCH RFC v3 07/11] RISC-V: QoS: enable resctrl support for Ssqosid Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-7-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2796; i=fustini@kernel.org; h=from:subject:message-id; bh=CSELH8cHpzjOmF3alV9G48Nrn3aORTFDw3pzNP6kshc=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5DkFH7kiI/X6n//ZzzMXvRU0evlyrQ9SprrDnxb+ ONyVOfXnI5SFgYxLgZZMUWWTR/yLizxCv26YP6LbTBzWJlAhjBwcQrARO6mMfzTOXzuuVfmqRqm axwmzhZCoWw/tITNXzlkPmPffVBvyaMXDH8l311NSS3teLgztOn2jPI7712z3576pm8onTDpdvu aln0sAA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Wire up the RISC-V QoS resctrl implementation: Add a late_initcall that checks for the Ssqosid extension and, if present, calls qos_resctrl_setup() to probe CBQRI controllers and initialize the resctrl filesystem, then registers CPU hotplug callbacks. Make CONFIG_RISCV_ISA_SSQOSID select ARCH_HAS_CPU_RESCTRL and RESCTRL_FS, and depends on MISC_FILESYSTEMS. Add qos_resctrl.o to the build when CONFIG_RISCV_ISA_SSQOSID is set. Co-developed-by: Adrien Ricciardi Signed-off-by: Adrien Ricciardi Signed-off-by: Drew Fustini --- arch/riscv/Kconfig | 3 +++ arch/riscv/kernel/qos/Makefile | 2 +- arch/riscv/kernel/qos/qos.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 92d2265a0c61..b2fef15b3d4f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -597,7 +597,10 @@ config RISCV_ISA_SVNAPOT =20 config RISCV_ISA_SSQOSID bool "Ssqosid extension support for supervisor mode Quality of Service ID" + depends on MISC_FILESYSTEMS default n + select ARCH_HAS_CPU_RESCTRL + select RESCTRL_FS help Adds support for the Ssqosid ISA extension (Supervisor-mode Quality of Service ID). diff --git a/arch/riscv/kernel/qos/Makefile b/arch/riscv/kernel/qos/Makefile index 9f996263a86d..9ed0c13a854d 100644 --- a/arch/riscv/kernel/qos/Makefile +++ b/arch/riscv/kernel/qos/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_RISCV_ISA_SSQOSID) +=3D qos.o +obj-$(CONFIG_RISCV_ISA_SSQOSID) +=3D qos.o qos_resctrl.o diff --git a/arch/riscv/kernel/qos/qos.c b/arch/riscv/kernel/qos/qos.c index a3c2b910e2e0..560607abf10a 100644 --- a/arch/riscv/kernel/qos/qos.c +++ b/arch/riscv/kernel/qos/qos.c @@ -1,8 +1,40 @@ // SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +#include #include =20 +#include "internal.h" + /* cached value of srmcfg csr for each cpu */ DEFINE_PER_CPU(u32, cpu_srmcfg); =20 /* default srmcfg value for each cpu, set via resctrl cpu assignment */ DEFINE_PER_CPU(u32, cpu_srmcfg_default); + +static int __init qos_arch_late_init(void) +{ + int err; + + if (!riscv_isa_extension_available(NULL, SSQOSID)) + return -ENODEV; + + err =3D qos_resctrl_setup(); + if (err) + return err; + + err =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "qos:online", + qos_resctrl_online_cpu, + qos_resctrl_offline_cpu); + if (err < 0) { + resctrl_exit(); + return err; + } + + return 0; +} +late_initcall(qos_arch_late_init); --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7C4EF31A062; Wed, 15 Apr 2026 01:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218217; cv=none; b=NzUB9FZyzYvp+IEqlJikKkuirJHdcrGGhORA2+7RA1MOdB/d+/N9lCJHBNYqGoKZ8dqBLoFHRkaO3Y92zeNY9Maa8dMLGezPLXc8AsWtV3fm/LHsq9dSq1jk+FGYky2RuvilZEY6Mpu0FIyvtLrpiSW/cSzL+BDGopavHWUgsGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218217; c=relaxed/simple; bh=K1u9KtDv/RgUAXZ7DmVQ4g7/U7BEShgGe9dLp0XEClE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KF5OiPI9ORrZXaqdJEq0sYDB7qcyfUMsHDcbaBFwZz9/9ahUuUkdAdAHfuvx2bab3U4aIjY5wPc5LLXqsHJbEywvntXY7Xjy9Nh00l4afd6+feHiqpiYF6y9uFKJpvIuQTzQeGe20PUfcvpTU9OshuirFAqQxFvMwy4Vxqgz0yE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UNt385vl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UNt385vl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C42D6C2BCC6; Wed, 15 Apr 2026 01:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218217; bh=K1u9KtDv/RgUAXZ7DmVQ4g7/U7BEShgGe9dLp0XEClE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UNt385vlbIZ2Dqkx6XB+BnqbrzGzSEYUN2m88yHdpyXxcCsGzIG6BTUdrLo6w+OIs udV42Svr7ZiZmh1W+x/iKMz3Wiea9g3n0LuJ1lKikalo6EJVsBi5RfX5+ncBjwgSM9 tuSeGihQQEJ+WsScNlo3UMljvlsLiK0+g6bLE3wTvED+iHHglcoo6W0ntrsQxhJEzn HgL9I0AgeS97vKge4PRD+Vw2XnLORf6vvDJfL9hHAZDlJrQ9hYHS2Wb9tE3WTnpqZ7 hlFQQr+nog3wVKtqrVBIC2MuiT1P8+aTUg4+W8CqFUFk+NlU5iuulmmnx4AZIm+I+n i3XETS8Isk6Lw== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:02 -0700 Subject: [PATCH RFC v3 08/11] ACPI: PPTT: Add acpi_pptt_get_cache_size_from_id helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-8-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3731; i=fustini@kernel.org; h=from:subject:message-id; bh=K1u9KtDv/RgUAXZ7DmVQ4g7/U7BEShgGe9dLp0XEClE=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5A04VtdUsJcsRSL83MPh3Ae9F6Z9HRbIM+xv+fk3 kz5phVf1FHKwiDGxSArpsiy6UPehSVeoV8XzH+xDWYOKxPIEAYuTgGYyM7nDP9slAq03RcZRUmr R3hvlON7uNzq8PogW/PLL8TXzeTpv3uFkeH9Oocv167lySbV6z+6bPD0tFLSK157q3UX2qetFu8 5q8cLAA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add helper to look up a cache's size from its cache ID in the PPTT table. This is needed by the RISC-V RQSC parser to determine the cache size for CBQRI capacity controllers. The implementation follows the pattern established by find_acpi_cache_level_from_id() and acpi_pptt_get_cpumask_from_cache_id(): uses acpi_get_pptt(), upgrade_pptt_cache(), checks all three cache types, and uses the do/while empty-detection loop. Signed-off-by: Drew Fustini --- drivers/acpi/pptt.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/acpi.h | 8 +++++++ 2 files changed, 71 insertions(+) diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index de5f8c018333..36e375551b43 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -1063,3 +1063,66 @@ int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id= , cpumask_t *cpus) =20 return 0; } + +/** + * acpi_pptt_get_cache_size_from_id() - Get the size of the specified cache + * @cache_id: The id field of the cache + * @size: Where to store the cache size in bytes + * + * Determine the size of the cache identified by cache_id. This allows the + * property to be found even if the CPUs are offline. + * + * The PPTT table must be rev 3 or later. + * + * Return: -ENOENT if the PPTT doesn't exist, the revision isn't supported= or + * the cache cannot be found. Otherwise returns 0 and sets *size. + */ +int acpi_pptt_get_cache_size_from_id(u32 cache_id, u32 *size) +{ + int cpu; + struct acpi_table_header *table; + + table =3D acpi_get_pptt(); + if (!table) + return -ENOENT; + + if (table->revision < 3) + return -ENOENT; + + for_each_possible_cpu(cpu) { + bool empty; + int level =3D 1; + u32 acpi_cpu_id =3D get_acpi_id_for_cpu(cpu); + struct acpi_pptt_processor *cpu_node; + + cpu_node =3D acpi_find_processor_node(table, acpi_cpu_id); + if (!cpu_node) + continue; + + do { + int cache_type[] =3D {CACHE_TYPE_INST, CACHE_TYPE_DATA, CACHE_TYPE_UNIF= IED}; + + empty =3D true; + for (int i =3D 0; i < ARRAY_SIZE(cache_type); i++) { + struct acpi_pptt_cache *cache; + struct acpi_pptt_cache_v1_full *cache_v1; + + cache =3D acpi_find_cache_node(table, acpi_cpu_id, cache_type[i], + level, &cpu_node); + if (!cache) + continue; + + empty =3D false; + + cache_v1 =3D upgrade_pptt_cache(cache); + if (cache_v1 && cache_v1->cache_id =3D=3D cache_id) { + *size =3D cache->size; + return 0; + } + } + level++; + } while (!empty); + } + + return -ENOENT; +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4d2f0bed7a06..0596ec18f522 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1547,6 +1547,7 @@ int find_acpi_cpu_topology_package(unsigned int cpu); int find_acpi_cpu_topology_hetero_id(unsigned int cpu); void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus); int find_acpi_cache_level_from_id(u32 cache_id); +int acpi_pptt_get_cache_size_from_id(u32 cache_id, u32 *size); int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus); #else static inline int acpi_pptt_cpu_is_thread(unsigned int cpu) @@ -1571,10 +1572,17 @@ static inline int find_acpi_cpu_topology_hetero_id(= unsigned int cpu) } static inline void acpi_pptt_get_cpus_from_container(u32 acpi_cpu_id, cpumask_t *cpus) { } + static inline int find_acpi_cache_level_from_id(u32 cache_id) { return -ENOENT; } + +static inline int acpi_pptt_get_cache_size_from_id(u32 cache_id, u32 *size) +{ + return -ENOENT; +} + static inline int acpi_pptt_get_cpumask_from_cache_id(u32 cache_id, cpumask_t *cpus) { --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2E22331D375; Wed, 15 Apr 2026 01:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218218; cv=none; b=pmriudOb30MXnehVsebb/l3K9GuiIxuZkfwGEgDhd8Bk9Rb0FKhyFoB7UrlJhno7YJpxtjX2z9InpBVoHCIzH2sCKnaaldIl3esU56DLevS0Q4bZDk3Ak50iq7w1kOjxjP5na8LQ6NFleq+VWEVYrd8vy7MDb107unXa2/Wd8LU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218218; c=relaxed/simple; bh=0N3/ljaEoSaUAHRrhb7+qug0MyFe8aVMQaHOTujWe+c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M2YaMInZZxN9EdroZAPRN9a8KL5dqlHIOHMHb+J48KKO3wXbYrHxgBZ+c1qPy/x7996YuLCMUFZ9LAjjUDU+ze8bESaYgNC+I6r0RUikM8oj0fOd0D6jc/QwrgfblNvpLWVkwYBVgdgm2FZYjOLjzf4B8Yon0MfKZFagb5T2yEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=COednS5x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="COednS5x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FF4DC2BCB6; Wed, 15 Apr 2026 01:56:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218217; bh=0N3/ljaEoSaUAHRrhb7+qug0MyFe8aVMQaHOTujWe+c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=COednS5xkmkPeIH5UZ9fhjGZh6IFHWQ870eksHvpTxUC82DvVrVKrvMvFcSlDciKc lKjjyNUULxL+ywqyR7ZG4i6mPUZA0DG09/pbn0LpEMcHgHPfhe++uDIBaYHpndbAV1 0+Ar3lFDCCuDCMinwPXXU3RCi5Q+9OrPeL5E89boZ78CEmzCpEPmorN6WqDF9qys3F LT8RPrJ6k0mTUyCIEPKw+Rq19tvFXI406fCQX3orBB7YxsWvBXVFEoVfWfed0cMIWh 5dSS/TbpSHiw+OXbx2RTnKPotdRZ/RdjBUGrtxkKh714C49JPyOc4Gdlhb7RXE2kNG mAk5+BXpNnxJA== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:03 -0700 Subject: [PATCH RFC v3 09/11] DO NOT MERGE: include: acpi: actbl2: Add structs for RQSC table Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-9-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2611; i=fustini@kernel.org; h=from:subject:message-id; bh=0N3/ljaEoSaUAHRrhb7+qug0MyFe8aVMQaHOTujWe+c=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5AsfEfuo747Z9cOma99R+4qpVT97FPlOZ8tPXGSW XS1bPCDjlIWBjEuBlkxRZZNH/IuLPEK/bpg/ottMHNYmUCGMHBxCsBE4n8xMuybaPnTJbxsb+cl rYRpn7cL3t9+qMb203z9qt7l77/t7FVi+O/54Zqc6nT/faF/nP6Wrtnaav/ShddS1IV3bwXvMgu VPQwA X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add structs for the RQSC table which describes the properties of the RISC-V QoS controllers (CBQRI) in the system. The table also describes the topological arrangement of the QoS controllers and resources in the system. The topology is expressed in terms of the location of the resources within the system and the relation between the QoS Controller and the resource it manages. Note: This is a placeholder for RFC review purposes. The actbl2.h change must go through upstream ACPICA first and will be replaced by the auto-generated ACPICA commit once the RQSC spec is ratified. Link: https://github.com/riscv-non-isa/riscv-cbqri/releases/tag/v1.0 Link: https://github.com/riscv-non-isa/riscv-rqsc/blob/main/src/chapter2.ad= oc Signed-off-by: Drew Fustini --- include/acpi/actbl2.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 5c0b55e7b3e4..d6f272e848fa 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -55,6 +55,7 @@ #define ACPI_SIG_RGRT "RGRT" /* Regulatory Graphics Resource Tab= le */ #define ACPI_SIG_RHCT "RHCT" /* RISC-V Hart Capabilities Table */ #define ACPI_SIG_RIMT "RIMT" /* RISC-V IO Mapping Table */ +#define ACPI_SIG_RQSC "RQSC" /* RISC-V Quality of Service Contro= ller */ #define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Tabl= e */ #define ACPI_SIG_SDEI "SDEI" /* Software Delegated Exception Int= erface Table */ #define ACPI_SIG_SDEV "SDEV" /* Secure Devices table */ @@ -3351,6 +3352,41 @@ enum acpi_rgrt_image_type { ACPI_RGRT_TYPE_RESERVED =3D 2 /* 2 and greater are reserved */ }; =20 +/*************************************************************************= ****** + * + * RQSC - RISC-V Quality of Service Controller + * Version 1 + * + *************************************************************************= *****/ + +struct acpi_table_rqsc_fields_res { + u8 type; + u8 resv; + u16 length; + u16 flags; + u8 resv2; + u8 id_type; + u64 id1; + u32 id2; +}; + +struct acpi_table_rqsc_fields { + u8 type; + u8 resv; + u16 length; + u32 reg[3]; + u16 rcid; + u16 mcid; + u16 flags; + u16 nres; + struct acpi_table_rqsc_fields_res res[]; +}; + +struct acpi_table_rqsc { + struct acpi_table_header header; /* Common ACPI table header */ + u32 num; +}; + /*************************************************************************= ****** * * RHCT - RISC-V Hart Capabilities Table --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B2AB931F9A7; Wed, 15 Apr 2026 01:56:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218218; cv=none; b=e8luOtcrRJ2bYHcqPgeuaT2ThZjCdZIK8oH2Xtk3xqsFfzpe51jps9ms1sIP3iU9pu4vEsNb3/srCIE/H5JR0nHzcJSbl/q2rZVUerR5vL9R32CYZ2fra4BceVhSq4nfCxgsPZGD0eksUBfM6Flai9BHWqbyFlopk65jzbWvDT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218218; c=relaxed/simple; bh=1kH1GVpiVdCP7JW4QCcx2t8NfCAlNAc+Qj0IksSz4Vo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pmgzm7C2RiUybxOBuDQrd3OUUdBPzHp41TvFlxhLO/mH0Zl92lDqBdjhJf2cTOj4wPpYgO7I7Ks7clvcwhuPdO15yjLkQNiNPWMV9ktysEeJIGqdFuHUNBl/07VKFWvsF7boET8+UvH+5FV6e5uCB2UoIbtNkWNM7yd32EPz/Dc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s5Swiuli; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s5Swiuli" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E59AC2BCB5; Wed, 15 Apr 2026 01:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218218; bh=1kH1GVpiVdCP7JW4QCcx2t8NfCAlNAc+Qj0IksSz4Vo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=s5SwiuliF9oLykkmOqDjQh9plpUT9hBCf+TTB6spjBEmJojSRVxhTERR23+nsDF+C EjnPqysoALlwR32tNLQjecaSyZTB2CQ1mWvQQ4Cg2B4sQcCzX6ZbJ7UyUUPgsdqA4y eXPdD0S1J6AuGulMqhazLGPLDB1vEaz5ejVJxWb/PmpNdR5JexOoEHYTFn5qDJ60bN yazF1wpBUEUuszm1DDut2q+nqKSkKbd1L6CP5FpCDGDj2g7MIfZ1OFis7WSnP4qIoD I+m1ZqsuV0KE6wej8SYGa4y/ffyGB4ZUqHx9Us42tkKIBmgKuQAulTyrG2RWSzVGAz wqKxPKdL3h0vA== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:04 -0700 Subject: [PATCH RFC v3 10/11] ACPI: RISC-V: Parse RISC-V Quality of Service Controller (RQSC) table Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-10-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7087; i=fustini@kernel.org; h=from:subject:message-id; bh=1kH1GVpiVdCP7JW4QCcx2t8NfCAlNAc+Qj0IksSz4Vo=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5DM52nC5XPYb3ZaSw67n9JlUWGfWuNzkh8thW92/ ksWsOnrKGVhEONikBVTZNn0Ie/CEq/Qrwvmv9gGM4eVCWQIAxenAExEhI/hfwrXxkb5qrCkAn5L m9u37xrGJP9yf850T9/9Vsfa+11f1jP8U7+48KXHgccnQpNM7/Qxf9h5ffupW+taWFVicm0XfS2 ZyQEA X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Add parser for the ACPI RQSC table which describes the capacity and bandwidth QoS controllers in a system. For each table entry, allocate a cbqri_controller struct and populate it with the controller type, MMIO base address, RCID/MCID counts, and resource identifiers (cache ID for capacity controllers, proximity domain for bandwidth controllers). Cache controller cpumasks are resolved via acpi_pptt_get_cpumask_from_cache_id(). Bandwidth controller cpumasks are derived from the proximity domain's NUMA node. Controllers with invalid addresses or failed cpumask lookups are skipped with a warning. The populated controller list is consumed by qos_resctrl_setup() in arch/riscv/kernel/qos/ to probe the hardware and register resctrl domains. Link: https://github.com/riscv-non-isa/riscv-cbqri/releases/tag/v1.0 Link: https://github.com/riscv-non-isa/riscv-rqsc/blob/main/src/ Signed-off-by: Drew Fustini --- MAINTAINERS | 1 + arch/riscv/include/asm/acpi.h | 10 ++++ drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/rqsc.c | 136 ++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 148 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index af9698a16439..d5ec7d29bf11 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22786,6 +22786,7 @@ S: Supported F: arch/riscv/include/asm/qos.h F: arch/riscv/include/asm/resctrl.h F: arch/riscv/kernel/qos/ +F: drivers/acpi/riscv/rqsc.c F: include/linux/riscv_qos.h =20 RISC-V RPMI AND MPXY DRIVERS diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h index 6e13695120bc..62296a2a519b 100644 --- a/arch/riscv/include/asm/acpi.h +++ b/arch/riscv/include/asm/acpi.h @@ -71,6 +71,16 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, =20 void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_si= ze, u32 *cboz_size, u32 *cbop_size); + +#ifdef CONFIG_RISCV_ISA_SSQOSID +int __init acpi_parse_rqsc(struct acpi_table_header *table); +#else +static inline int acpi_parse_rqsc(struct acpi_table_header *table) +{ + return -EINVAL; +} +#endif /* CONFIG_RISCV_ISA_SSQOSID */ + #else static inline void acpi_init_rintc_map(void) { } static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile index 1284a076fa88..d7ae8729987a 100644 --- a/drivers/acpi/riscv/Makefile +++ b/drivers/acpi/riscv/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y +=3D rhct.o init.o irq.o +obj-$(CONFIG_RISCV_ISA_SSQOSID) +=3D rqsc.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) +=3D cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) +=3D cppc.o obj-$(CONFIG_ACPI_RIMT) +=3D rimt.o diff --git a/drivers/acpi/riscv/rqsc.c b/drivers/acpi/riscv/rqsc.c new file mode 100644 index 000000000000..f647051be0bf --- /dev/null +++ b/drivers/acpi/riscv/rqsc.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Tenstorrent + * Author: Drew Fustini + */ + +#define pr_fmt(fmt) "ACPI: RQSC: " fmt + +#include +#include +#include + +#define CBQRI_CTRL_SIZE 0x1000 + +int __init acpi_parse_rqsc(struct acpi_table_header *table) +{ + struct acpi_table_rqsc *rqsc; + struct acpi_table_rqsc_fields *end; + struct acpi_table_rqsc_fields *node; + int err; + int num_controllers =3D 0; + + rqsc =3D (struct acpi_table_rqsc *)table; + + end =3D ACPI_ADD_PTR(struct acpi_table_rqsc_fields, rqsc, rqsc->header.le= ngth); + + for (node =3D ACPI_ADD_PTR(struct acpi_table_rqsc_fields, rqsc, + sizeof(struct acpi_table_rqsc)); + node < end; + node =3D ACPI_ADD_PTR(struct acpi_table_rqsc_fields, node, node->len= gth) + ) { + struct cbqri_controller *ctrl; + + if (node->length < sizeof(*node)) { + pr_err("malformed RQSC entry: length %u < %zu, aborting\n", + node->length, sizeof(*node)); + err =3D -EINVAL; + goto err_free_controllers; + } + + ctrl =3D kzalloc_obj(*ctrl, GFP_KERNEL); + if (!ctrl) { + err =3D -ENOMEM; + goto err_free_controllers; + } + + ctrl->type =3D node->type; + /* reg[1] is the MMIO base address per the RQSC table layout */ + ctrl->addr =3D node->reg[1]; + ctrl->size =3D CBQRI_CTRL_SIZE; + ctrl->rcid_count =3D node->rcid; + ctrl->mcid_count =3D node->mcid; + + if (!ctrl->addr) { + pr_warn("skipping controller with invalid addr=3D0x0\n"); + kfree(ctrl); + continue; + } + + if (node->nres =3D=3D 0) { + pr_warn("controller at %pa has no resource descriptors, skipping\n", + &ctrl->addr); + kfree(ctrl); + continue; + } + + if (node->length < sizeof(*node) + sizeof(node->res[0])) { + pr_warn("controller at %pa: node too short for resource descriptor, ski= pping\n", + &ctrl->addr); + kfree(ctrl); + continue; + } + + if (node->nres > 1) + pr_warn("controller at %pa has %u resource descriptors, using first\n", + &ctrl->addr, node->nres); + + pr_debug("Found controller with type %u addr %pa size %pa rcid %u mcid %= u\n", + ctrl->type, &ctrl->addr, &ctrl->size, + ctrl->rcid_count, ctrl->mcid_count); + if (ctrl->type =3D=3D CBQRI_CONTROLLER_TYPE_CAPACITY) { + ctrl->cache.cache_id =3D (u32)node->res[0].id1; + ctrl->cache.cache_level =3D + find_acpi_cache_level_from_id(ctrl->cache.cache_id); + + if (acpi_pptt_get_cache_size_from_id(ctrl->cache.cache_id, + &ctrl->cache.cache_size)) { + pr_warn("failed to determine size for cache id 0x%x\n", + ctrl->cache.cache_id); + ctrl->cache.cache_size =3D 0; + } + + pr_debug("Cache controller has ID 0x%x level %u size %u\n", + ctrl->cache.cache_id, ctrl->cache.cache_level, + ctrl->cache.cache_size); + + /* + * For CBQRI, any cpu (technically a hart in RISC-V terms) + * can access the memory-mapped registers of any CBQRI + * controller in the system. + */ + err =3D acpi_pptt_get_cpumask_from_cache_id(ctrl->cache.cache_id, + &ctrl->cache.cpu_mask); + if (err) { + pr_warn("Failed to get cpumask for cache id 0x%x (%d), skipping\n", + ctrl->cache.cache_id, err); + kfree(ctrl); + continue; + } + + } else if (ctrl->type =3D=3D CBQRI_CONTROLLER_TYPE_BANDWIDTH) { + ctrl->mem.prox_dom =3D (u32)node->res[0].id1; + cpumask_copy(&ctrl->mem.cpu_mask, + cpumask_of_node(pxm_to_node(ctrl->mem.prox_dom))); + pr_debug("Memory controller with proximity domain %u\n", + ctrl->mem.prox_dom); + } + + /* List shared with RISC-V QoS resctrl implementation */ + list_add_tail(&ctrl->list, &cbqri_controllers); + num_controllers++; + } + + pr_info("found %d CBQRI controllers\n", num_controllers); + return 0; + +err_free_controllers: + while (!list_empty(&cbqri_controllers)) { + struct cbqri_controller *ctrl; + + ctrl =3D list_first_entry(&cbqri_controllers, struct cbqri_controller, l= ist); + list_del(&ctrl->list); + kfree(ctrl); + } + return err; +} --=20 2.43.0 From nobody Thu Apr 16 04:18:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 76833324B23; Wed, 15 Apr 2026 01:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218219; cv=none; b=MLh8iiD6peOLz1vHDNaLJOC8oXzhuMQJWEqElj8IH/UtBSafs2NdnDNtwtlysDf3IghKdjHiwCdBAvC9swtPI3bzmvd0ZHMbrrkilnuCEc7crthQMKMYBbTHHciR+mTOqKKrCEvIwKx+nHWs63sWn1PjOR7OaoCYyrvjbUH1Q8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776218219; c=relaxed/simple; bh=Av0Nv9qYcvDtXSrfBVWD8C8RBkR90ZNKGubCs7xRSJk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bj2Xlejpu1cG52J8aDSISRzvV5mNmwzL5f6PCKKIHUhJI6geq8oIvlK7bZcw3SGTusNmRJ7R7DhEVLdivGk6D6162Q2M5Y9YOxUFdh2inLt87npc+yqMnFujvOfvMLKBJ5mNXa6UEVZolaYUp1Lr8mXeQgmIvsjyayqYZBGg9n0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I7HV+sm/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I7HV+sm/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF31AC2BCC9; Wed, 15 Apr 2026 01:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776218219; bh=Av0Nv9qYcvDtXSrfBVWD8C8RBkR90ZNKGubCs7xRSJk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=I7HV+sm/tIkU114gKkjZgkZD0WSpdiA8OxGnu5ffp6iizlNtje9BW8J6MjZ7Y0ihV VNWcePI0q9B+GneSfXvMxj9PddssHjuR5bB5/UaA6K86yz3XCwAK/X478JMj/CX855 6rzZmbAQJO1ib3Ex+ojFWvM9P1a0E6GpYP7OYLkJy0hmojBkswrJ+5MJXmmSK6ZIuR tJ/xELc8UrmWN0khc+o2rPjQRAm0150vEyD0J1RyDE08D5Veeu3CGUin7EG0JrVW9X kd5dVMVW8tAdG9tJDpJQxnB1X5326gLSrm5acKChAnI22j7a5ykc/NOibX+6SEkaQ0 3GKg4EbEPsbwA== From: Drew Fustini Date: Tue, 14 Apr 2026 18:54:05 -0700 Subject: [PATCH RFC v3 11/11] ACPI: RISC-V: Add support for RISC-V Quality of Service Controller (RQSC) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-11-b3b2e7e9847a@kernel.org> References: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> In-Reply-To: <20260414-ssqosid-cbqri-rqsc-v7-0-v3-0-b3b2e7e9847a@kernel.org> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , Samuel Holland , Adrien Ricciardi , Nicolas Pitre , =?utf-8?q?Kornel_Dul=C4=99ba?= , Atish Patra , Atish Kumar Patra , Vasudevan Srinivasan , Ved Shanbhogue , Conor Dooley , yunhui cui , Chen Pei , Liu Zhiwei , Weiwei Li , guo.wenjia23@zte.com.cn, Gong Shuai , Gong Shuai , liu.qingtao2@zte.com.cn, Reinette Chatre , Tony Luck , Babu Moger , Peter Newman , Fenghua Yu , James Morse , Ben Horgan , Dave Martin , Rob Herring , Conor Dooley , Krzysztof Kozlowski , "Rafael J. Wysocki" , Len Brown , Robert Moore , Sunil V L , Drew Fustini Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, devicetree@vger.kernel.org, Paul Walmsley X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1644; i=fustini@kernel.org; h=from:subject:message-id; bh=Av0Nv9qYcvDtXSrfBVWD8C8RBkR90ZNKGubCs7xRSJk=; b=owGbwMvMwCV2+43O4ZsaG3kYT6slMWTe+5D8zXvm26QrV/ZXV+k1PNTnvF/1mvlHw+HFPWtfL p7ae0wosqOUhUGMi0FWTJFl04e8C0u8Qr8umP9iG8wcViaQIQxcnAIwkVY+RobfriYrLjDtKriy 9P1+IdfVYQcv3p9vrcOyeDHDLn+VHY8eMvwV4O5JmV1/ZuLR4JVrVt5meFP8+Jm1rlGrtVG3yAn 3zn/sAA== X-Developer-Key: i=fustini@kernel.org; a=openpgp; fpr=1B6F948213EA489734F3997035D5CD577C1E6010 Call acpi_parse_rqsc() from acpi_arch_init() to discover CBQRI controllers when an RQSC table is present. The RQSC table is optional; AE_NOT_FOUND is silenced since many systems will not have QoS controllers. Other ACPI failures are reported as errors. Link: https://github.com/riscv-non-isa/riscv-cbqri/releases/tag/v1.0 Link: https://github.com/riscv-non-isa/riscv-rqsc/blob/main/src/ Signed-off-by: Drew Fustini --- drivers/acpi/riscv/init.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index 7c00f7995e86..8a74dff42dce 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -4,12 +4,35 @@ * Author: Sunil V L */ =20 +#define pr_fmt(fmt) "ACPI: RQSC: " fmt + #include #include "init.h" =20 void __init acpi_arch_init(void) { + struct acpi_table_header *rqsc; + acpi_status status; + int rc; + riscv_acpi_init_gsi_mapping(); + if (IS_ENABLED(CONFIG_ACPI_RIMT)) riscv_acpi_rimt_init(); + + if (IS_ENABLED(CONFIG_RISCV_ISA_SSQOSID) && !acpi_disabled) { + status =3D acpi_get_table(ACPI_SIG_RQSC, 0, &rqsc); + if (status =3D=3D AE_NOT_FOUND) { + /* RQSC is optional; silence on systems without it */ + } else if (ACPI_FAILURE(status)) { + pr_err("failed to get ACPI RQSC table: %s\n", + acpi_format_exception(status)); + } else { + rc =3D acpi_parse_rqsc(rqsc); + if (rc < 0) + pr_err("failed to parse ACPI RQSC table: %d\n", + rc); + acpi_put_table(rqsc); + } + } } --=20 2.43.0