From faf24fb43ba3b4c67ac814b2e2606ea12206b070 Mon Sep 17 00:00:00 2001 From: Mattia Tadini Date: Sun, 15 Nov 2026 10:55:45 +0100 Subject: [PATCH] kernel: add 0132, the BC-250 per-shader-array WGP mask for KFD skillfish-cu unlocks the harvested WGPs through UMR after amdgpu has bound, so Vulkan uses 40 CUs but KFD keeps the fused 24: it counts CUs once, in gfx_v10_0_get_cu_info(). amdgpu.bc250_cc_wgp_mask writes the disabled WGPs into CC_GC_SHADER_ARRAY_CONFIG bits 31:16 and the mask into SPI_PG_ENABLE_STATIC_WGP_MASK before that count. Unset, nothing changes. From MastaG/linux-cachyos-bc250 0029 (ForceConstant, issue #14), ported onto 0114 instead of their 0011 and without their RLC_PG_ALWAYS_ON_WGP_MASK write, which 0114 leaves out on purpose. Tested on bc250-dev with a 7.3.4 test build: unset, KFD simd_count 48 as on the released kernel; with 0x1f x4, simd_count 80, registers as expected, vkpeak 10172 GFLOPS. No KFD queue in use: the board has no ROCm stack. The README's recipe section is brought up to date (49 patches, 7.3.4). --- kernel-build/README.md | 39 ++++- ...0132-mastag-0029-bc250-cc-wgp-mask.mypatch | 140 ++++++++++++++++++ 2 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 kernel-build/userpatches-350/0132-mastag-0029-bc250-cc-wgp-mask.mypatch diff --git a/kernel-build/README.md b/kernel-build/README.md index 7b3f0f01..70a58d4a 100644 --- a/kernel-build/README.md +++ b/kernel-build/README.md @@ -32,19 +32,23 @@ Build host: AMD BC-250 (Debian). Tool: https://github.com/Frogging-Family/linux- `userpatches/` is not the only set in here, and picking the wrong one gives a kernel that boots and is not the one we ship. What each directory is: -- **`userpatches-350/` — the current recipe.** 43 patches; this is what builds - `7.2.9-skillfishos`, the published kernel and the one installed on both - boards. (It built `7.2.3`, `7.2.4` and `7.2.5` before; only the upstream version changed.) Four series, and - the numbering says where each one comes from: - - `0100-0118` — Project Ariel (cachenetics): SMU/PMFW message enums, forced +- **`userpatches-350/` — the current recipe.** 49 patches; this is what builds + `7.3.4-skillfishos`, the published kernel. (It built the 7.2 series before; + 7.3.4 needed 0207/0208 rewritten and 0212 added.) The numbering says where + each patch comes from: + - `0100-0126` — Project Ariel (cachenetics): SMU/PMFW message enums, forced GFX clock and DPM levels, PMFW telemetry, the race-free GFXCLK query, the - CU unlock that does *not* touch RLC_PG, and the gfx1013 GFXOFF disable. + CU unlock that does *not* touch RLC_PG, the gfx1013 GFXOFF disable, the + 8-core telemetry. - `0130-0131` — DryhoppedIPA, the compute-queue pair. Measured on a BC-250: the Mesa half is worth +4.2% on Cyberpunk, the kernel half about +0.6% on Wukong. The +20.8% claimed upstream did not reproduce. - - `0200-0211` and `0299` — our own series, renumbered from `0001-0016` so it + - `0132` — the per-shader-array WGP mask, see below. + - `0200-0212` and `0299` — our own series, renumbered from `0001-0016` so it applies after Ariel's. - `0300` — gpu_busy_percent for gfx1013, see below. + - `0310-0313` — our ccp/PSP fixes and the display HPD fix (0313 is upstream + from 7.4: drop it there). - **`userpatches/`** — the legacy 16-patch set that built the published 7.2.0 and 7.2.2 kernels. Kept because it documents what users currently get from the APT archive. @@ -56,6 +60,25 @@ kernel that boots and is not the one we ship. What each directory is: refuses to load firmware for it, and both donor firmwares wedge the board. Not built into anything. +### 0132: the compute units ROCm can see + +`skillfish-cu` unlocks the harvested WGPs at boot through UMR, after amdgpu has +bound. Vulkan uses them (vkpeak scales to 40 CU), but KFD counts CUs once, in +`gfx_v10_0_get_cu_info()`, and keeps the fused 24: ROCm never sees the rest. + +`amdgpu.bc250_cc_wgp_mask=SE0.SH0,SE0.SH1,SE1.SH0,SE1.SH1` (four 5-bit WGP +enable masks, e.g. `0x1f,0x1f,0x1f,0x1f`) writes, per shader array and before +that count, the disabled WGPs into `CC_GC_SHADER_ARRAY_CONFIG` bits 31:16 and +the mask into `SPI_PG_ENABLE_STATIC_WGP_MASK`. Unset, nothing changes. + +From MastaG/linux-cachyos-bc250 0029 (ForceConstant, issue #14), ported onto +0114 instead of their 0011, and **without** their `RLC_PG_ALWAYS_ON_WGP_MASK` +write, for the reason 0114 gives (RLC deadlock on the first KFD queue). +Measured on bc250-dev, 7.3.4 test build: unset, KFD `simd_count` 48 and no +change from the released kernel; with `0x1f` x4, `simd_count` 80 (40 CU), the +registers read back as expected and vkpeak 10172 GFLOPS. A KFD queue in use +was not tested: the board has no ROCm stack. + ### 0300: a real gpu_busy_percent on gfx1013 Cyan Skillfish has no GFX activity metric: `gpu_metrics` reports @@ -82,7 +105,7 @@ stops itself two seconds after the last read. ### The x64 twin -The same 43 patches build `-skillfishos-x64` for machines that are not a +The same 49 patches build `-skillfishos-x64` for machines that are not a BC-250: the BC-250 patches are inert elsewhere because they hook that device. What changes is `_processor_opt="x86-64"`, the localversion, and `config-fragments/skillfish-generic-cpu.myfrag`, which **must** be in place or diff --git a/kernel-build/userpatches-350/0132-mastag-0029-bc250-cc-wgp-mask.mypatch b/kernel-build/userpatches-350/0132-mastag-0029-bc250-cc-wgp-mask.mypatch new file mode 100644 index 00000000..c1ae7f41 --- /dev/null +++ b/kernel-build/userpatches-350/0132-mastag-0029-bc250-cc-wgp-mask.mypatch @@ -0,0 +1,140 @@ +From: ForceConstant <26015318+ForceConstant@users.noreply.github.com> +Date: Fri, 13 Nov 2026 17:46:36 +0100 +Subject: [PATCH] drm/amdgpu/gfx10: BC-250 per-shader-array WGP mask + +amdgpu.bc250_cc_wgp_mask takes up to four comma-separated 5-bit WGP +enable masks, in the order SE0.SH0, SE0.SH1, SE1.SH0, SE1.SH1 (bit set = +WGP enabled; entries not given are all-on), and writes per shader array, +in gfx_v10_0_get_cu_info() before the CU enumeration: + +- CC_GC_SHADER_ARRAY_CONFIG: the disabled WGPs in INACTIVE_WGPS (bits + 31:16), where gfx_v10_0_get_wgp_active_bitmap_per_sh() reads them; +- SPI_PG_ENABLE_STATIC_WGP_MASK: the mask. + +Unlocking from userspace (UMR, after the driver bound) leaves KFD with the +fused CU count, because it enumerates CUs once, here. With this mask KFD +and RADV enumerate exactly the enabled WGPs. It takes precedence over +bc250_cc_write_mode. An unparsable value, a fifth entry or a mask above +0x1f leaves the registers as fused and logs a warning. It only acts on PCI +device 0x13FE. + +[SkillFishOS: ported from MastaG/linux-cachyos-bc250 0029 onto our +ariel-16 unlock (0114) instead of their 0011. RLC_PG_ALWAYS_ON_WGP_MASK is +NOT written, as in 0114: with RLC firmware running that write deadlocks +the RLC on the first KFD queue.] + +Link: https://github.com/MastaG/linux-cachyos-bc250/issues/14 +--- +diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +index 8f298cd45..430759957 100644 +--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c ++++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +@@ -26,6 +26,9 @@ + #include + #include + #include ++#include ++#include ++#include + + /* BC-250 40 CU unlock: clears harvest mask + opens SPI dispatch to all WGPs + * RLC_PG_ALWAYS_ON_WGP_MASK intentionally omitted — see patch4_cu_unlock.py */ +@@ -33,6 +36,38 @@ static int bc250_cc_write_mode; + module_param(bc250_cc_write_mode, int, 0444); + MODULE_PARM_DESC(bc250_cc_write_mode, + "BC-250 40CU: 0=off 1=probe-SE0SH0 2=clear-SE0SH0 3=clear-all-SAs 4=probe-all-SAs"); ++static char *bc250_cc_wgp_mask; ++module_param(bc250_cc_wgp_mask, charp, 0444); ++MODULE_PARM_DESC(bc250_cc_wgp_mask, ++ "BC-250: per-shader-array WGP enable masks SE0.SH0,SE0.SH1,SE1.SH0,SE1.SH1, e.g. 0x1d,0x1f,0x0f,0x1f"); ++ ++/* ++ * Parse up to four comma-separated 5-bit WGP enable masks (bit set = WGP ++ * enabled). Entries not given stay all-on. Returns false when the string ++ * cannot be parsed, so a typo does not unlock anything. ++ */ ++static bool bc250_parse_wgp_masks(const char *s, unsigned int masks[4]) ++{ ++ char *buf, *p, *tok; ++ bool ok = true; ++ int n = 0; ++ ++ buf = kstrdup(s, GFP_KERNEL); ++ if (!buf) ++ return false; ++ p = buf; ++ while ((tok = strsep(&p, ","))) { ++ unsigned int v; ++ ++ if (n == 4 || kstrtouint(strim(tok), 0, &v) || v > 0x1f) { ++ ok = false; ++ break; ++ } ++ masks[n++] = v; ++ } ++ kfree(buf); ++ return ok; ++} + #define BC250_PCI_DEVICE_ID 0x13FE + #include "amdgpu.h" + #include "amdgpu_gfx.h" +@@ -10171,6 +10206,51 @@ static int gfx_v10_0_get_cu_info(struct amdgpu_device *adev, + + mutex_lock(&adev->grbm_idx_mutex); + ++ /* ++ * BC-250: per-shader-array WGP mask, for boards where some of the ++ * harvested WGPs are defective. Same CC and SPI registers as the ++ * unlock below, but each shader array keeps the WGPs its mask leaves ++ * out disabled, in CC too, so KFD and RADV enumerate exactly the ++ * enabled ones. CC holds the inactive WGPs in bits 31:16, which is ++ * where gfx_v10_0_get_wgp_active_bitmap_per_sh() reads them. ++ * RLC_PG_ALWAYS_ON_WGP_MASK is not written, for the reason given in ++ * the unlock below (RLC deadlock on the first KFD queue). ++ */ ++ if (bc250_cc_wgp_mask && bc250_cc_wgp_mask[0] && ++ adev->pdev->device == BC250_PCI_DEVICE_ID) { ++ unsigned int masks[4] = {0x1f, 0x1f, 0x1f, 0x1f}; ++ int bc_se, bc_sh; ++ ++ if (!bc250_parse_wgp_masks(bc250_cc_wgp_mask, masks)) { ++ dev_warn(adev->dev, "bc250-wgp-mask: cannot parse \"%s\", left as fused\n", ++ bc250_cc_wgp_mask); ++ goto bc250_done; ++ } ++ for (bc_se = 0; bc_se < adev->gfx.config.max_shader_engines; bc_se++) { ++ for (bc_sh = 0; bc_sh < adev->gfx.config.max_sh_per_se; bc_sh++) { ++ int idx = bc_se * adev->gfx.config.max_sh_per_se + bc_sh; ++ unsigned int m = idx < 4 ? masks[idx] : 0x1f; ++ u32 cc = ((~m) & 0x1f) << ++ CC_GC_SHADER_ARRAY_CONFIG__INACTIVE_WGPS__SHIFT; ++ u32 bc_cc_orig, bc_cc_after, bc_spi_orig, bc_spi_after; ++ ++ gfx_v10_0_select_se_sh(adev, bc_se, bc_sh, 0xffffffff, 0); ++ bc_cc_orig = RREG32_SOC15(GC, 0, mmCC_GC_SHADER_ARRAY_CONFIG); ++ WREG32_SOC15(GC, 0, mmCC_GC_SHADER_ARRAY_CONFIG, cc); ++ bc_cc_after = RREG32_SOC15(GC, 0, mmCC_GC_SHADER_ARRAY_CONFIG); ++ bc_spi_orig = RREG32_SOC15(GC, 0, mmSPI_PG_ENABLE_STATIC_WGP_MASK); ++ WREG32_SOC15(GC, 0, mmSPI_PG_ENABLE_STATIC_WGP_MASK, m); ++ bc_spi_after = RREG32_SOC15(GC, 0, mmSPI_PG_ENABLE_STATIC_WGP_MASK); ++ dev_info(adev->dev, ++ "bc250-wgp-mask: se=%d sh=%d mask=0x%02x CC=0x%08x->0x%08x SPI=0x%08x->0x%08x\n", ++ bc_se, bc_sh, m, bc_cc_orig, bc_cc_after, ++ bc_spi_orig, bc_spi_after); ++ } ++ } ++ gfx_v10_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0); ++ goto bc250_done; ++ } ++ + /* ===== BC-250 40 CU UNLOCK PATCH START ===== */ + /* + * BC-250 (gfx1013 / Cyan Skillfish): VBIOS fuses 16 of 40 CUs inactive. +@@ -10222,6 +10302,7 @@ static int gfx_v10_0_get_cu_info(struct amdgpu_device *adev, + gfx_v10_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0); + } + /* ===== BC-250 40 CU UNLOCK PATCH END ===== */ ++bc250_done: + for (i = 0; i < adev->gfx.config.max_shader_engines; i++) { + for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) { + bitmap = i * adev->gfx.config.max_sh_per_se + j;