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 hardware

The patch modifies the gfx_v9_0_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_0_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_0 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_0_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
c2e70d30 22ff907d

+66 -5
+40 -5
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
··· 50 50 #include "amdgpu_ring_mux.h" 51 51 #include "gfx_v9_4.h" 52 52 #include "gfx_v9_0.h" 53 + #include "gfx_v9_0_cleaner_shader.h" 53 54 #include "gfx_v9_4_2.h" 54 55 55 56 #include "asic_reg/pwr/pwr_10_0_offset.h" ··· 900 899 static void gfx_v9_0_kiq_set_resources(struct amdgpu_ring *kiq_ring, 901 900 uint64_t queue_mask) 902 901 { 902 + struct amdgpu_device *adev = kiq_ring->adev; 903 + u64 shader_mc_addr; 904 + 905 + /* Cleaner shader MC address */ 906 + shader_mc_addr = adev->gfx.cleaner_shader_gpu_addr >> 8; 907 + 903 908 amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6)); 904 909 amdgpu_ring_write(kiq_ring, 905 910 PACKET3_SET_RESOURCES_VMID_MASK(0) | ··· 915 908 lower_32_bits(queue_mask)); /* queue mask lo */ 916 909 amdgpu_ring_write(kiq_ring, 917 910 upper_32_bits(queue_mask)); /* queue mask hi */ 918 - amdgpu_ring_write(kiq_ring, 0); /* gws mask lo */ 919 - amdgpu_ring_write(kiq_ring, 0); /* gws mask hi */ 911 + amdgpu_ring_write(kiq_ring, lower_32_bits(shader_mc_addr)); /* cleaner shader addr lo */ 912 + amdgpu_ring_write(kiq_ring, upper_32_bits(shader_mc_addr)); /* cleaner shader addr hi */ 920 913 amdgpu_ring_write(kiq_ring, 0); /* oac mask */ 921 914 amdgpu_ring_write(kiq_ring, 0); /* gds heap base:0, gds heap size:0 */ 922 915 } ··· 2218 2211 break; 2219 2212 } 2220 2213 2214 + switch (amdgpu_ip_version(adev, GC_HWIP, 0)) { 2215 + default: 2216 + adev->gfx.enable_cleaner_shader = false; 2217 + break; 2218 + } 2219 + 2221 2220 adev->gfx.mec.num_pipe_per_mec = 4; 2222 2221 adev->gfx.mec.num_queue_per_pipe = 8; 2223 2222 ··· 2386 2373 2387 2374 gfx_v9_0_alloc_ip_dump(adev); 2388 2375 2376 + r = amdgpu_gfx_sysfs_isolation_shader_init(adev); 2377 + if (r) 2378 + return r; 2379 + 2389 2380 return 0; 2390 2381 } 2391 2382 ··· 2424 2407 (void **)&adev->gfx.rlc.cp_table_ptr); 2425 2408 } 2426 2409 gfx_v9_0_free_microcode(adev); 2410 + 2411 + amdgpu_gfx_sysfs_isolation_shader_fini(adev); 2427 2412 2428 2413 kfree(adev->gfx.ip_dump_core); 2429 2414 kfree(adev->gfx.ip_dump_compute_queues); ··· 3970 3951 { 3971 3952 int r; 3972 3953 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 3954 + 3955 + amdgpu_gfx_cleaner_shader_init(adev, adev->gfx.cleaner_shader_size, 3956 + adev->gfx.cleaner_shader_ptr); 3973 3957 3974 3958 if (!amdgpu_sriov_vf(adev)) 3975 3959 gfx_v9_0_init_golden_registers(adev); ··· 7390 7368 7391 7369 } 7392 7370 7371 + static void gfx_v9_0_ring_emit_cleaner_shader(struct amdgpu_ring *ring) 7372 + { 7373 + /* Emit the cleaner shader */ 7374 + amdgpu_ring_write(ring, PACKET3(PACKET3_RUN_CLEANER_SHADER, 0)); 7375 + amdgpu_ring_write(ring, 0); /* RESERVED field, programmed to zero */ 7376 + } 7377 + 7393 7378 static const struct amd_ip_funcs gfx_v9_0_ip_funcs = { 7394 7379 .name = "gfx_v9_0", 7395 7380 .early_init = gfx_v9_0_early_init, ··· 7446 7417 5 + /* HDP_INVL */ 7447 7418 8 + 8 + /* FENCE x2 */ 7448 7419 2 + /* SWITCH_BUFFER */ 7449 - 7, /* gfx_v9_0_emit_mem_sync */ 7420 + 7 + /* gfx_v9_0_emit_mem_sync */ 7421 + 2, /* gfx_v9_0_ring_emit_cleaner_shader */ 7450 7422 .emit_ib_size = 4, /* gfx_v9_0_ring_emit_ib_gfx */ 7451 7423 .emit_ib = gfx_v9_0_ring_emit_ib_gfx, 7452 7424 .emit_fence = gfx_v9_0_ring_emit_fence, ··· 7469 7439 .soft_recovery = gfx_v9_0_ring_soft_recovery, 7470 7440 .emit_mem_sync = gfx_v9_0_emit_mem_sync, 7471 7441 .reset = gfx_v9_0_reset_kgq, 7442 + .emit_cleaner_shader = gfx_v9_0_ring_emit_cleaner_shader, 7472 7443 }; 7473 7444 7474 7445 static const struct amdgpu_ring_funcs gfx_v9_0_sw_ring_funcs_gfx = { ··· 7502 7471 5 + /* HDP_INVL */ 7503 7472 8 + 8 + /* FENCE x2 */ 7504 7473 2 + /* SWITCH_BUFFER */ 7505 - 7, /* gfx_v9_0_emit_mem_sync */ 7474 + 7 + /* gfx_v9_0_emit_mem_sync */ 7475 + 2, /* gfx_v9_0_ring_emit_cleaner_shader */ 7506 7476 .emit_ib_size = 4, /* gfx_v9_0_ring_emit_ib_gfx */ 7507 7477 .emit_ib = gfx_v9_0_ring_emit_ib_gfx, 7508 7478 .emit_fence = gfx_v9_0_ring_emit_fence, ··· 7527 7495 .patch_cntl = gfx_v9_0_ring_patch_cntl, 7528 7496 .patch_de = gfx_v9_0_ring_patch_de_meta, 7529 7497 .patch_ce = gfx_v9_0_ring_patch_ce_meta, 7498 + .emit_cleaner_shader = gfx_v9_0_ring_emit_cleaner_shader, 7530 7499 }; 7531 7500 7532 7501 static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_compute = { ··· 7548 7515 8 + 8 + 8 + /* gfx_v9_0_ring_emit_fence x3 for user fence, vm fence */ 7549 7516 7 + /* gfx_v9_0_emit_mem_sync */ 7550 7517 5 + /* gfx_v9_0_emit_wave_limit for updating mmSPI_WCL_PIPE_PERCENT_GFX register */ 7551 - 15, /* for updating 3 mmSPI_WCL_PIPE_PERCENT_CS registers */ 7518 + 15 + /* for updating 3 mmSPI_WCL_PIPE_PERCENT_CS registers */ 7519 + 2, /* gfx_v9_0_ring_emit_cleaner_shader */ 7552 7520 .emit_ib_size = 7, /* gfx_v9_0_ring_emit_ib_compute */ 7553 7521 .emit_ib = gfx_v9_0_ring_emit_ib_compute, 7554 7522 .emit_fence = gfx_v9_0_ring_emit_fence, ··· 7568 7534 .emit_mem_sync = gfx_v9_0_emit_mem_sync, 7569 7535 .emit_wave_limit = gfx_v9_0_emit_wave_limit, 7570 7536 .reset = gfx_v9_0_reset_kcq, 7537 + .emit_cleaner_shader = gfx_v9_0_ring_emit_cleaner_shader, 7571 7538 }; 7572 7539 7573 7540 static const struct amdgpu_ring_funcs gfx_v9_0_ring_funcs_kiq = {
+26
drivers/gpu/drm/amd/amdgpu/gfx_v9_0_cleaner_shader.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright 2018 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 + /* Define the cleaner shader gfx_9_0 */ 24 + static const u32 __maybe_unused gfx_9_0_cleaner_shader_hex[] = { 25 + /* Add the cleaner shader code here */ 26 + };