Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/amdgpu/gfx9: Implement cleaner shader support for GFX9.4.3 hardware

The patch modifies the gfx_v9_4_3_kiq_set_resources function to write
the cleaner shader's memory controller address to the ring buffer. It
also adds a new function, gfx_v9_4_3_ring_emit_cleaner_shader, which
emits the PACKET3_RUN_CLEANER_SHADER packet to the ring buffer.

This patch adds support for the PACKET3_RUN_CLEANER_SHADER packet in the
gfx_v9_4_3 module. This packet is used to emit the cleaner shader, which
is used to clear GPU memory before it's reused, helping to prevent data
leakage between different processes.

Finally, the patch updates the ring function structures to include the
new gfx_v9_4_3_ring_emit_cleaner_shader function. This allows the
cleaner shader to be emitted as part of the ring's operations.

Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Suggested-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Srinivasan Shanmugam and committed by
Alex Deucher
d4c38154 c2e70d30

+78 -5
+52 -5
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
··· 37 37 #include "gc/gc_9_4_3_sh_mask.h" 38 38 39 39 #include "gfx_v9_4_3.h" 40 + #include "gfx_v9_4_3_cleaner_shader.h" 40 41 #include "amdgpu_xcp.h" 41 42 #include "amdgpu_aca.h" 42 43 ··· 170 169 static void gfx_v9_4_3_kiq_set_resources(struct amdgpu_ring *kiq_ring, 171 170 uint64_t queue_mask) 172 171 { 172 + struct amdgpu_device *adev = kiq_ring->adev; 173 + u64 shader_mc_addr; 174 + 175 + /* Cleaner shader MC address */ 176 + shader_mc_addr = adev->gfx.cleaner_shader_gpu_addr >> 8; 177 + 173 178 amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6)); 174 179 amdgpu_ring_write(kiq_ring, 175 180 PACKET3_SET_RESOURCES_VMID_MASK(0) | ··· 185 178 lower_32_bits(queue_mask)); /* queue mask lo */ 186 179 amdgpu_ring_write(kiq_ring, 187 180 upper_32_bits(queue_mask)); /* queue mask hi */ 188 - amdgpu_ring_write(kiq_ring, 0); /* gws mask lo */ 189 - amdgpu_ring_write(kiq_ring, 0); /* gws mask hi */ 181 + amdgpu_ring_write(kiq_ring, lower_32_bits(shader_mc_addr)); /* cleaner shader addr lo */ 182 + amdgpu_ring_write(kiq_ring, upper_32_bits(shader_mc_addr)); /* cleaner shader addr hi */ 190 183 amdgpu_ring_write(kiq_ring, 0); /* oac mask */ 191 184 amdgpu_ring_write(kiq_ring, 0); /* gds heap base:0, gds heap size:0 */ 192 185 } ··· 1054 1047 int i, j, k, r, ring_id, xcc_id, num_xcc; 1055 1048 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1056 1049 1050 + switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 1051 + case IP_VERSION(9, 4, 3): 1052 + adev->gfx.cleaner_shader_ptr = gfx_9_4_3_cleaner_shader_hex; 1053 + adev->gfx.cleaner_shader_size = sizeof(gfx_9_4_3_cleaner_shader_hex); 1054 + if (adev->gfx.mec_fw_version >= 153) { 1055 + adev->gfx.enable_cleaner_shader = true; 1056 + r = amdgpu_gfx_cleaner_shader_sw_init(adev, adev->gfx.cleaner_shader_size); 1057 + if (r) { 1058 + adev->gfx.enable_cleaner_shader = false; 1059 + dev_err(adev->dev, "Failed to initialize cleaner shader\n"); 1060 + } 1061 + } 1062 + break; 1063 + default: 1064 + adev->gfx.enable_cleaner_shader = false; 1065 + break; 1066 + } 1067 + 1057 1068 adev->gfx.mec.num_mec = 2; 1058 1069 adev->gfx.mec.num_pipe_per_mec = 4; 1059 1070 adev->gfx.mec.num_queue_per_pipe = 8; ··· 1165 1140 return r; 1166 1141 1167 1142 1168 - if (!amdgpu_sriov_vf(adev)) 1143 + if (!amdgpu_sriov_vf(adev)) { 1169 1144 r = amdgpu_gfx_sysfs_init(adev); 1145 + if (r) 1146 + return r; 1147 + } 1170 1148 1171 1149 gfx_v9_4_3_alloc_ip_dump(adev); 1172 1150 1173 - return r; 1151 + r = amdgpu_gfx_sysfs_isolation_shader_init(adev); 1152 + if (r) 1153 + return r; 1154 + 1155 + return 0; 1174 1156 } 1175 1157 1176 1158 static int gfx_v9_4_3_sw_fini(void *handle) ··· 1195 1163 amdgpu_gfx_kiq_fini(adev, i); 1196 1164 } 1197 1165 1166 + amdgpu_gfx_cleaner_shader_sw_fini(adev); 1167 + 1198 1168 gfx_v9_4_3_mec_fini(adev); 1199 1169 amdgpu_bo_unref(&adev->gfx.rlc.clear_state_obj); 1200 1170 gfx_v9_4_3_free_microcode(adev); 1201 1171 if (!amdgpu_sriov_vf(adev)) 1202 1172 amdgpu_gfx_sysfs_fini(adev); 1173 + amdgpu_gfx_sysfs_isolation_shader_fini(adev); 1203 1174 1204 1175 kfree(adev->gfx.ip_dump_core); 1205 1176 kfree(adev->gfx.ip_dump_compute_queues); ··· 2342 2307 { 2343 2308 int r; 2344 2309 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 2310 + 2311 + amdgpu_gfx_cleaner_shader_init(adev, adev->gfx.cleaner_shader_size, 2312 + adev->gfx.cleaner_shader_ptr); 2345 2313 2346 2314 if (!amdgpu_sriov_vf(adev)) 2347 2315 gfx_v9_4_3_init_golden_registers(adev); ··· 4603 4565 amdgpu_gfx_off_ctrl(adev, true); 4604 4566 } 4605 4567 4568 + static void gfx_v9_4_3_ring_emit_cleaner_shader(struct amdgpu_ring *ring) 4569 + { 4570 + /* Emit the cleaner shader */ 4571 + amdgpu_ring_write(ring, PACKET3(PACKET3_RUN_CLEANER_SHADER, 0)); 4572 + amdgpu_ring_write(ring, 0); /* RESERVED field, programmed to zero */ 4573 + } 4574 + 4606 4575 static const struct amd_ip_funcs gfx_v9_4_3_ip_funcs = { 4607 4576 .name = "gfx_v9_4_3", 4608 4577 .early_init = gfx_v9_4_3_early_init, ··· 4649 4604 8 + 8 + 8 + /* gfx_v9_4_3_ring_emit_fence x3 for user fence, vm fence */ 4650 4605 7 + /* gfx_v9_4_3_emit_mem_sync */ 4651 4606 5 + /* gfx_v9_4_3_emit_wave_limit for updating regSPI_WCL_PIPE_PERCENT_GFX register */ 4652 - 15, /* for updating 3 regSPI_WCL_PIPE_PERCENT_CS registers */ 4607 + 15 + /* for updating 3 regSPI_WCL_PIPE_PERCENT_CS registers */ 4608 + 2, /* gfx_v9_4_3_ring_emit_cleaner_shader */ 4653 4609 .emit_ib_size = 7, /* gfx_v9_4_3_ring_emit_ib_compute */ 4654 4610 .emit_ib = gfx_v9_4_3_ring_emit_ib_compute, 4655 4611 .emit_fence = gfx_v9_4_3_ring_emit_fence, ··· 4669 4623 .emit_mem_sync = gfx_v9_4_3_emit_mem_sync, 4670 4624 .emit_wave_limit = gfx_v9_4_3_emit_wave_limit, 4671 4625 .reset = gfx_v9_4_3_reset_kcq, 4626 + .emit_cleaner_shader = gfx_v9_4_3_ring_emit_cleaner_shader, 4672 4627 }; 4673 4628 4674 4629 static const struct amdgpu_ring_funcs gfx_v9_4_3_ring_funcs_kiq = {
+26
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3_cleaner_shader.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright 2024 Advanced Micro Devices, Inc. 4 + * 5 + * Permission is hereby granted, free of charge, to any person obtaining a 6 + * copy of this software and associated documentation files (the "Software"), 7 + * to deal in the Software without restriction, including without limitation 8 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 + * and/or sell copies of the Software, and to permit persons to whom the 10 + * Software is furnished to do so, subject to the following conditions: 11 + * 12 + * The above copyright notice and this permission notice shall be included in 13 + * all copies or substantial portions of the Software. 14 + * 15 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 + * OTHER DEALINGS IN THE SOFTWARE. 22 + */ 23 + 24 + /* Define the cleaner shader gfx_9_4_3 */ 25 + static const u32 gfx_9_4_3_cleaner_shader_hex[] = { 26 + };