drm/amdgpu: Add CWSR and second-level trap handler support
Subsystems (3)
v3 cover drm/amdgpu: Add CWSR and second-level trap handler support
Hi,
This series adds support for Second-Level Trap Handlers (SLTH) for AMDGPU user queues.
Today, the kernel provides a first-level trap handler through the existing CWSR infrastructure. This series extends that model by allowing userspace to install a second-level trap handler on a per-GPUVM basis.
When a trap occurs, execution first enters the kernel-managed first-level trap handler. The first-level trap handler then transfers control to a userspace-provided second-level trap handler. After the second-level handler finishes execution, control returns back to the original shader through the normal trap return path.
Changes since v2
================
- Fixed second-level trap address validation to correctly validate user-provided TBA/TMA GPUVM mappings.
- Simplified the L2 trap UAPI structure layout.
- Removed explicit padding fields.
- Removed obsolete padding validation checks.
- Verified VM ioctl ABI size remains unchanged:
sizeof(union drm_amdgpu_vm) = 40
- Aligned GFX12.1 trap ISA selection with existing KFD handling.
- Replaced obsolete GFX12.1 trap ISA selection with
revision-specific trap blobs:
cwsr_trap_gfx12_1_0_rev_0_hex
cwsr_trap_gfx12_1_0_rev_1_hex - Applied the GFX12.1 update consistently in:
amdgpu_cwsr.c
amdgpu_trap.c
- Additional bring-up, validation and testing.
Base Tree
=========
Series developed on top of:
11a08cd5ab25
drm/amdgpu: save VKMS modeset state from the system PM path only
Branch:
amd-staging-drm-next
Validated Patch Series
======================
63a8b1c841cf drm/amdgpu: Add CWSR infrastructure for user queues 6a009e39acd4 drm/amdgpu: Integrate CWSR with user queues 593a519d44f6 drm/amdgpu: Add CWSR userspace interfaces 5144dc590439 drm/amdgpu: Add second-level trap handler infrastructure 3756d2ce7e0b drm/amdgpu: Make first-level trap state GPUVM-owned 0c27773bb8e6 drm/amdgpu: Program trap TBA/TMA for kernel-managed VMIDs 19de9a0ed07c drm/amdgpu/uapi: Add SET/CLEAR L2 TRAP to VM ioctl
Validation Platform
===================
GPU:
Navi48 (0x746f)
Firmware:
MES_KIQ feature version: 1
MES_KIQ firmware version: 0x00000094
MES feature version: 1
MES firmware version: 0x00000094
VBIOS version: 113-G2820100-001
IGT Validation
==============
Associated IGT series:
tests/amdgpu: Add SLTH validation tests for trap handling and trap return
https://patchwork.freedesktop.org/patch/765208/?series=177473&rev=1
The IGT series adds dedicated validation coverage for:
- SLTH installation
- SLTH removal
- Trap invocation
- VGPR preservation
- Trap return handling
- Execution resume after trap
- Queue execution recovery
- GFX KQ path
- GFX UMQ path
- Compute KQ path
Validated tests:
slth-gfx-kq-vgpr-proof
slth-gfx-umq-vgpr-proof
slth-comp-kq-vgpr-proof
slth-comp-kq-returnproof
What The Tests Verify
=====================
slth-gfx-kq-vgpr-proof
- Installs a second-level trap handler.
- Dispatches a workload containing s_trap.
- Executes trap handling.
- Returns through the trap return path.
- Verifies VGPR values after execution resumes.
- Verifies the expected proof value.
slth-gfx-umq-vgpr-proof
- Installs a second-level trap handler.
- Executes through the UMQ path.
- Exercises queue recovery and resume.
- Verifies VGPR preservation.
- Verifies the expected proof value.
slth-comp-kq-vgpr-proof
- Executes SLTH through the compute KQ path.
- Verifies trap handling execution.
- Verifies VGPR preservation.
- Verifies the expected proof value.
slth-comp-kq-returnproof
- Executes trap handling.
- Exercises trap return.
- Verifies execution continues after trap return.
- Verifies the final proof value after resume.
Representative IGT Validation Flow
==================================
The validation performed by the proof-oriented tests follows:
Install SLTH
->
Dispatch shader workload
->
Execute s_trap
->
First-level trap handler executes
->
Second-level trap handler executes
->
Trap return executes
->
Execution resumes
->
Expected proof value written
->
IGT validates result
->Remove SLTH
Representative IGT Traces
=========================
For ex:
GFX KQ VGPR proof test:
[IGT] Starting subtest: slth-gfx-kq-vgpr-proof
[IGT] Installing second-level trap handler
[IGT] Dispatching proof workload
[IGT] Triggering s_trap
[IGT] Waiting for completion
[IGT] Expected proof value observed
[IGT] VGPR validation successful
[IGT] Clearing second-level trap handler
[IGT] Subtest passed
GFX UMQ VGPR proof test:
[IGT] Starting subtest: slth-gfx-umq-vgpr-proof
[IGT] Installing second-level trap handler
[IGT] Dispatching proof workload
[IGT] Triggering s_trap
[IGT] Queue restore completed
[IGT] Execution resumed
[IGT] Expected proof value observed
[IGT] VGPR validation successful
[IGT] Clearing second-level trap handler
[IGT] Subtest passed
Compute KQ VGPR proof test:
[IGT] Starting subtest: slth-comp-kq-vgpr-proof
[IGT] Installing second-level trap handler
[IGT] Dispatching proof workload
[IGT] Expected proof value observed
[IGT] VGPR validation successful
[IGT] Clearing second-level trap handler
[IGT] Subtest passed
Representative Kernel Traces
============================
SLTH installation:
amdgpu: VM ioctl SET_L2_TRAP
amdgpu: installing L2 trap handler
(tba_va=0x0000010000000000
tba_sz=8192
tma_va=0x0000010000002000
tma_sz=4096)amdgpu: updated L2 trap descriptor
(tba=0x0000010000000000
tma=0x0000010000002000)These messages confirm that the userspace-provided second-level trap handler was successfully installed and programmed into the first-level trap descriptor.
SLTH removal:
amdgpu: VM ioctl CLEAR_L2_TRAP
amdgpu: clearing L2 trap descriptor
amdgpu: updated L2 trap descriptor
(tba=0x0000000000000000
tma=0x0000000000000000)These messages confirm successful removal of the
installed second-level trap handler.
End-to-End Result
=================
The validation demonstrates that:
- Userspace can install a second-level trap handler.
- The kernel validates user-provided trap buffers.
- The first-level trap handler transfers control to the second-level trap handler.
- Trap descriptors are programmed correctly.
- The second-level trap handler executes successfully.
- Trap return resumes execution correctly.
- Queue execution continues after trap processing.
- Expected proof values are observed.
- VGPR state is preserved across trap handling.
- Userspace can successfully remove the installed second-level trap handler.
In simple terms, the series has been validated from installation of the second-level trap handler, through trap execution and trap return,
all the way to workload completion and cleanup.
Testing on Navi48 hardware confirms successful SLTH installation, trap execution, execution resume, proof validation, and SLTH removal.
Thanks,
Srini
Lijo Lazar (4):
drm/amdgpu: Add CWSR infrastructure for user queues drm/amdgpu: Integrate CWSR with user queues drm/amdgpu: Add CWSR userspace interfaces drm/amdgpu: Add second-level trap handler infrastructure
Srinivasan Shanmugam (3):
drm/amdgpu: Make first-level trap state GPUVM-owned drm/amdgpu: Program trap TBA/TMA for kernel-managed VMIDs drm/amdgpu/uapi: Add SET/CLEAR L2 TRAP to VM ioctl
drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 + drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c | 551 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 20 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 31 + drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 8 + drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 771 ++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h | 148 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 24 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 7 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 98 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 17 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 22 + drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 14 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 28 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 75 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 50 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 50 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 61 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 47 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 59 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 50 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 50 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 55 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 55 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 107 ++- include/uapi/drm/amdgpu_drm.h | 90 +++ 28 files changed, 2443 insertions(+), 62 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
Signature · 1 line
2.34.1
PATCH v3 1/7 drm/amdgpu: Add CWSR infrastructure for user queues
From: Lijo Lazar <[email protected]>
Add a helper to get the number of XCCs for a partition, defaulting to one when no partition manager is available.
Add the core CWSR handling infrastructure for user queues, including the first-level trap handler objects and save area sizing.
Calculate the control stack, wave context and debugger memory sizes required for CWSR, and provide validation for userspace supplied save area parameters. Address validation is handled separately by the caller.
Create the per-VM TMA BO using the VM root BO reservation object. This avoids recursively acquiring reservation_ww_class_mutex while the VM reservation is already held through drm_exec. The TMA BO is not pinned and is covered by the VM reservation while being added to the VM.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c | 543 +++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h | 82 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 19 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 13 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h | 22 + 7 files changed, 670 insertions(+), 14 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.o amdgpu_doorbell_mgr.o amdgpu_kms amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o amdgpu_lockdep.o \ amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_dev_coredump.o \ amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o \ - amdgpu_wb.o + amdgpu_wb.o amdgpu_cwsr.o amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -332,6 +332,7 @@ struct amdgpu_reset_context;struct amdgpu_reset_control ;struct amdgpu_coredump_info ;struct amdgpu_video_codecs ; +struct amdgpu_cwsr_isa ;enum amdgpu_cp_irq {AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP =0 ,
@@ -986,6 +987,8 @@ struct amdgpu_device {* Must be last --ends in a flexible-array member. */ struct amdgpu_kfd_dev kfd; + +struct amdgpu_cwsr_info *cwsr_info; }; static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c new file +543 -0
543 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h new file +82 -0
82 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +9 -10
@@ -764,6 +764,15 @@ MODULE_PARM_DESC(use_xgmi_p2p, "Enable XGMI P2P interface (0 = disable; 1 = enable (default))");module_param_named (use_xgmi_p2p, amdgpu_use_xgmi_p2p, int,0444 ); +/** +* DOC: cwsr_enable (int) +* CWSR(compute wave store and resume) allows the GPU to preempt shader execution in +* the middle of a compute wave. Default is 1 to enable this feature. Setting 0 +* disables it. +*/ +int cwsr_enable =1 ; +module_param (cwsr_enable, int,0444 ); +MODULE_PARM_DESC (cwsr_enable,"CWSR enable (0 = Off, 1 = On (Default))" );#ifdef CONFIG_HSA_AMD /**
@@ -787,16 +796,6 @@ module_param(hws_max_conc_proc, int, 0444);MODULE_PARM_DESC (hws_max_conc_proc,"Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))" ); -/** -* DOC: cwsr_enable (int) -* CWSR(compute wave store and resume) allows the GPU to preempt shader execution in -* the middle of a compute wave. Default is 1 to enable this feature. Setting 0 -* disables it as only in non-HWS mode. -*/ -int cwsr_enable =1 ; -module_param (cwsr_enable, int,0444 ); -MODULE_PARM_DESC (cwsr_enable,"CWSR enable (0 = Off (debugging only), 1 = On (Default))" ); -/** * DOC: max_num_of_queues_per_device (int) * Maximum number of queues per device. Valid setting is between 1 and 4096. Default
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +10 -3
@@ -178,10 +178,17 @@ struct amdgpu_bo_vm;#define AMDGPU_VA_RESERVED_TRAP_SIZE (1ULL << 16)#define AMDGPU_VA_RESERVED_TRAP_START (adev) (AMDGPU_VA_RESERVED_SEQ64_START(adev) \ - AMDGPU_VA_RESERVED_TRAP_SIZE) +/* TBD: Ideally, existing TRAP VA should do. There is a conflict with KFD mapping that needs to be +* resolved. Revisit later. +*/ +#define AMDGPU_VA_RESERVED_TRAP_UQ_SIZE (3ULL << 12) +#define AMDGPU_VA_RESERVED_TRAP_UQ_START (adev) \ + (AMDGPU_VA_RESERVED_TRAP_START(adev) - AMDGPU_VA_RESERVED_TRAP_UQ_SIZE) +#define AMDGPU_VA_RESERVED_BOTTOM (1ULL << 16) -#define AMDGPU_VA_RESERVED_TOP (AMDGPU_VA_RESERVED_TRAP_SIZE + \ - AMDGPU_VA_RESERVED_SEQ64_SIZE + \ - AMDGPU_VA_RESERVED_CSA_SIZE) +#define AMDGPU_VA_RESERVED_TOP \ + (AMDGPU_VA_RESERVED_TRAP_UQ_SIZE + AMDGPU_VA_RESERVED_TRAP_SIZE + \ + AMDGPU_VA_RESERVED_SEQ64_SIZE + AMDGPU_VA_RESERVED_CSA_SIZE)/* See vm_update_mode */ #define AMDGPU_VM_USE_CPU_FOR_GFX (1 << 0)
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.h +22 -0
@@ -227,4 +227,26 @@ amdgpu_get_next_xcp(struct amdgpu_xcp_mgr *xcp_mgr, int *from)for (i =0 , xcp =amdgpu_get_next_xcp (xcp_mgr, &i); xcp; \ ++i, xcp =amdgpu_get_next_xcp (xcp_mgr, &i)) +static inline int amdgpu_xcp_get_num_xcc(struct amdgpu_xcp_mgr *xcp_mgr, +int xcp_id) +{ +struct amdgpu_xcp *xcp; +u32 xcc_mask; +int i, r; + +if (!xcp_mgr || xcp_id ==AMDGPU_XCP_NO_PARTITION ) +return 1 ; +for_each_xcp (xcp_mgr, xcp, i) { +if (xcp->id == xcp_id) { + r =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_GFX , + &xcc_mask); +if (unlikely (r)) +return 1 ; +else +return hweight32 (xcc_mask); + } + } + +return 1 ; +}#endif
Signature · 1 line
2.34.1
PATCH v3 2/7 drm/amdgpu: Integrate CWSR with user queues
In reply to Srinivasan ShanmugamFrom: Lijo Lazar <[email protected]>
Initialize the CWSR handler during device initialization and release the associated resources during device teardown.
Add a per-file CWSR trap object for render-node user queues and map the first-level CWSR trap handler into the GPUVM associated with the file. Use the mapped TBA and TMA addresses when programming user queues.
Add user save area parameters to the MQD properties for compute queue creation and validate the parameters before using them for MQD initialization.
The CWSR parameter validation walks the VM mapping tree and updates the user queue VA mapping state. Reserve the VM root BO around the validation so the required VM reservation is held while accessing the mapping tree.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c | 8 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h | 6 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 8 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 25 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 8 +- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 14 +++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 102 +++++++++++++++++---- 10 files changed, 172 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -333,6 +333,7 @@ struct amdgpu_reset_control;struct amdgpu_coredump_info ;struct amdgpu_video_codecs ;struct amdgpu_cwsr_isa ; +struct amdgpu_cwsr_trap_obj ;enum amdgpu_cp_irq {AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP =0 ,
@@ -421,6 +422,7 @@ struct amdgpu_fpriv {struct xarray bo_list_handles;struct amdgpu_ctx_mgr ctx_mgr;struct amdgpu_userq_mgr userq_mgr; +struct amdgpu_cwsr_trap_obj *cwsr_trap;/* Eviction fence infra */ struct amdgpu_eviction_fence_mgr evf_mgr;
drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c +8 -0
@@ -395,6 +395,7 @@ int amdgpu_cwsr_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!amdgpu_cwsr_is_enabled (adev))return -EOPNOTSUPP ; +if (!vm || !trap_obj)return -EINVAL ;
@@ -403,12 +404,15 @@ int amdgpu_cwsr_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,return -ENOMEM ; bo = adev->cwsr_info->isa_bo; +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ,0 ); drm_exec_until_all_locked(&exec) { r =amdgpu_vm_lock_pd (vm, &exec,0 );if (likely (!r)) r =drm_exec_lock_obj (&exec, &bo->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) { dev_err(adev->dev, "failed to reserve for CWSR allocs: err=%d\n",
@@ -455,17 +459,21 @@ int amdgpu_cwsr_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm, }drm_exec_fini (&exec); + *trap_obj = cwsr;return 0 ; err_kmap:amdgpu_bo_kunmap (cwsr->tma_bo); + err_tma:amdgpu_bo_unref (&cwsr->tma_bo); + err_exec:drm_exec_fini (&exec);kfree (cwsr); *trap_obj =NULL ; +return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h +6 -0
@@ -79,4 +79,10 @@ uint32_t amdgpu_cwsr_size_needed(struct amdgpu_device *adev, int num_xcc);int amdgpu_cwsr_validate_params (struct amdgpu_device *adev,struct amdgpu_cwsr_params *cwsr_params,int num_xcc); +static inline bool amdgpu_cwsr_has_dbg_wa (struct amdgpu_device *adev) +{ +u32 gc_ver =amdgpu_ip_version (adev,GC_HWIP ,0 ); + +return gc_ver >=IP_VERSION (11 ,0 ,0 ) && gc_ver <=IP_VERSION (11 ,0 ,3 ); +}#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
@@ -81,6 +81,7 @@#include "amdgpu_reset.h" #include "amdgpu_virt.h" #include "amdgpu_dev_coredump.h" +#include "amdgpu_cwsr.h" #include <linux/suspend.h> #include <drm/task_barrier.h>
@@ -2547,6 +2548,14 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)amdgpu_fru_get_product_info (adev); r =amdgpu_cper_init (adev); +if (r) + goto init_failed; + + r =amdgpu_cwsr_init (adev); +if (r == -EOPNOTSUPP ) + r =0 ; +else if (r) + goto init_failed; init_failed:
@@ -2951,6 +2960,7 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) {int i, r; +amdgpu_cwsr_fini (adev);amdgpu_cper_fini (adev);if (amdgpu_sriov_vf (adev) && adev->virt.ras_init_done)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -0
@@ -49,6 +49,8 @@#include "amdgpu_userq.h" #include "amdgpu_video_codecs.h" #include "amdgpu_ras_mgr.h" +#include "amdgpu_vm.h" +#include "amdgpu_cwsr.h" void amdgpu_unregister_gpu_instance (struct amdgpu_device *adev) {
@@ -1580,6 +1582,12 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) r);amdgpu_evf_mgr_init (&fpriv->evf_mgr); + + r =amdgpu_cwsr_alloc (adev, &fpriv->vm, + &fpriv->cwsr_trap); +if (r == -EOPNOTSUPP ) + r =0 ; +amdgpu_ctx_mgr_init (&fpriv->ctx_mgr, adev); file_priv->driver_priv = fpriv;
@@ -1649,6 +1657,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, }amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_cwsr_free (adev, &fpriv->vm, &fpriv->cwsr_trap);if (pasid)amdgpu_pasid_free_delayed (pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +8 -0
@@ -533,6 +533,14 @@ struct amdgpu_mqd_prop {uint32_t cu_mask_count;uint32_t cu_flags;bool is_user_cu_masked; +bool aql_queue; +u32 queue_percentage; +/* used in gfx9 and gfx12.1 */ +u32 pm4_target_xcc; +/* cwsr params */ +u64 ctx_save_area_addr; +u32 ctx_save_area_size; +u32 ctl_stack_size; };struct amdgpu_mqd {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +25 -0
@@ -35,6 +35,7 @@#include "amdgpu_hmm.h" #include "amdgpu_userq_fence.h" #include "amdgpu_trace.h" +#include "amdgpu_cwsr.h" u32 amdgpu_userq_get_supported_ip_mask (struct amdgpu_device *adev) {
@@ -265,6 +266,30 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,return -EINVAL ; } +int amdgpu_userq_input_cwsr_params_validate ( +struct amdgpu_usermode_queue *queue, +struct amdgpu_cwsr_params *cwsr_params) +{ +struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (queue->userq_mgr); +struct amdgpu_device *adev = queue->userq_mgr->adev; +u32 cwsr_size; +int num_xcc; +int r; + + num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); + r =amdgpu_cwsr_validate_params (queue->userq_mgr->adev, cwsr_params, + num_xcc); +if (r) +return r; + cwsr_size =amdgpu_cwsr_size_needed (queue->userq_mgr->adev, num_xcc); +if (!cwsr_size) +return -EOPNOTSUPP ; + +return amdgpu_userq_input_va_validate ( + adev, queue, cwsr_params->ctx_save_area_address, cwsr_size, + &queue->userq_vas.va.cwsr); +} +static bool amdgpu_userq_buffer_va_mapped (struct amdgpu_vm *vm,u64 addr) {struct amdgpu_bo_va_mapping *mapping;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +7 -1
@@ -41,6 +41,7 @@ enum amdgpu_userq_state { };struct amdgpu_mqd_prop ; +struct amdgpu_cwsr_params ;struct amdgpu_userq_obj {void *cpu_ptr;
@@ -97,8 +98,9 @@ struct amdgpu_usermode_queue {u64 eop;u64 shadow;u64 csa; +u64 cwsr; } va; -u64 va_array[6 ]; +u64 va_array[7 ]; } userq_vas;uint32_t gang_ctx_array_index;
@@ -200,4 +202,8 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping); +int amdgpu_userq_input_cwsr_params_validate ( +struct amdgpu_usermode_queue *queue, +struct amdgpu_cwsr_params *cwsr_params); +#endif
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +14 -0
@@ -3233,6 +3233,20 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,/* set CU mask */ gfx_v12_0_compute_mqd_set_cu_mask (adev, mqd, prop); +/* If non-zero, assume cwsr is enabled */ +if (prop->ctx_save_area_addr) { + mqd->cp_hqd_persistent_state |= + (1 <<CP_HQD_PERSISTENT_STATE__QSWITCH_MODE__SHIFT ); + mqd->cp_hqd_ctx_save_base_addr_lo = +lower_32_bits (prop->ctx_save_area_addr); + mqd->cp_hqd_ctx_save_base_addr_hi = +upper_32_bits (prop->ctx_save_area_addr); + mqd->cp_hqd_ctx_save_size = prop->ctx_save_area_size; + mqd->cp_hqd_cntl_stack_size = prop->ctl_stack_size; + mqd->cp_hqd_cntl_stack_offset = prop->ctl_stack_size; + mqd->cp_hqd_wg_state_offset = prop->ctl_stack_size; + } +return 0 ; }
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +83 -19
229 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 3/7 drm/amdgpu: Add CWSR userspace interfaces
In reply to Srinivasan ShanmugamFrom: Lijo Lazar <[email protected]>
Add an ioctl to return the size information required for CWSR regions.
Add CWSR parameters to the user queue ioctl so userspace can provide the GPU virtual address and allocated size of the save/restore buffer. The parameters are supported for user compute queues.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 21 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 13 +++++++---- include/uapi/drm/amdgpu_drm.h | 27 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +21 -0
@@ -1455,6 +1455,27 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)return -EINVAL ; } } +case AMDGPU_INFO_CWSR : { +struct drm_amdgpu_info_cwsr cwsr_info; +int num_xcc, r; + + fpriv = (struct amdgpu_fpriv *)filp->driver_priv; +if (!amdgpu_cwsr_is_enabled (adev) || !fpriv->cwsr_trap) +return -EOPNOTSUPP ; + num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); + cwsr_info.ctl_stack_size = + adev->cwsr_info->xcc_ctl_stack_sz * num_xcc; + cwsr_info.dbg_mem_size = + adev->cwsr_info->xcc_dbg_mem_sz * num_xcc; + cwsr_info.min_save_area_size = +amdgpu_cwsr_size_needed (adev, num_xcc); + r =copy_to_user (out, &cwsr_info, +min ((size_t )size,sizeof (cwsr_info))) ? + -EFAULT : +0 ; +return r; + } +default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +9 -4
@@ -466,11 +466,9 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); cwsr_params.ctx_save_area_address = - userq_props->ctx_save_area_addr; + compute_mqd->ctx_save_area_va; cwsr_params.cwsr_sz = - userq_props->ctx_save_area_size; - userq_props->ctl_stack_size = - adev->cwsr_info->xcc_ctl_stack_sz * num_xcc; + compute_mqd->ctx_save_area_size; r =amdgpu_bo_reserve (queue->vm->root.bo, false);if (r) {
@@ -485,6 +483,13 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,kfree (compute_mqd); goto free_mqd; } + + userq_props->ctx_save_area_addr = + compute_mqd->ctx_save_area_va; + userq_props->ctx_save_area_size = + compute_mqd->ctx_save_area_size; + userq_props->ctl_stack_size = + adev->cwsr_info->xcc_ctl_stack_sz * num_xcc; }kfree (compute_mqd);
include/uapi/drm/amdgpu_drm.h +27 -0
@@ -470,6 +470,17 @@ struct drm_amdgpu_userq_mqd_compute_gfx11 {* to get the size. */ __u64 eop_va; +/** +* @ctx_save_area_va: Virtual address of the GPU memory for save/restore buffer. +* This must be from a separate GPU object, and use AMDGPU_INFO IOCTL +* to get the size. This includes control stack, wave context and debugger memory. +*/ +__u64 ctx_save_area_va; +/** +* @ctx_save_area_size: Total size (in bytes) allocated for save/restore buffer. +* Use AMDGPU_INFO IOCTL to get the size. +*/ +__u32 ctx_save_area_size; };/* userq signal/wait ioctl */
@@ -1289,6 +1300,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {#define AMDGPU_INFO_GPUVM_FAULT 0x23/* query FW object size and alignment */ #define AMDGPU_INFO_UQ_FW_AREAS 0x24 +/* query CWSR size and alignment */ +#define AMDGPU_INFO_CWSR 0x25#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
@@ -1668,6 +1681,20 @@ struct drm_amdgpu_info_uq_metadata { }; }; +/** +* struct drm_amdgpu_info_cwsr - cwsr information +* +* Gives cwsr related size details. User needs to allocate buffer based on this. +*/ +struct drm_amdgpu_info_cwsr { +/* Control stack size */ +__u32 ctl_stack_size; +/* Debug memory area size */ +__u32 dbg_mem_size; +/* Minimum save area size required */ +__u32 min_save_area_size; +}; +/* * Supported GPU families */
Signature · 1 line
2.34.1
PATCH v3 4/7 drm/amdgpu: Add second-level trap handler infrastructure
In reply to Srinivasan ShanmugamFrom: Lijo Lazar <[email protected]>
Expand the CWSR infrastructure to support second-level userspace trap handlers and rename it to reflect the broader trap handler scope.
Rename the CWSR files and common interfaces to amdgpu_trap while keeping CWSR-specific naming for the context save/restore functionality.
Add the basic support needed for a userspace second-level trap handler. Store the second-level TBA and TMA addresses in the first-level TMA and provide helpers to set and clear them for a GPUVM.
The first-level TMA buffer can move in memory, so do not keep it permanently mapped on the CPU. Map it only while accessing its contents and unmap it afterwards.
Check that the second-level TBA and TMA address ranges are mapped in the GPUVM before using them. Wait for GPUVM work to stop before changing the addresses and keep the VM locked while checking and updating them.
Add support for updating the debugger trap flag in the first-level TMA.
Do not expose a standalone TRAP ioctl. The second-level trap handler is controlled through SET_L2_TRAP and CLEAR_L2_TRAP operations on the VM ioctl added later in the series.
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h | 88 --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 17 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 764 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h | 143 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 13 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 7 +- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 24 +- 11 files changed, 946 insertions(+), 127 deletions(-) delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h
drivers/gpu/drm/amd/amdgpu/Makefile +1 -1
@@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.o amdgpu_doorbell_mgr.o amdgpu_kms amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o amdgpu_lockdep.o \ amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_dev_coredump.o \ amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o \ - amdgpu_wb.o amdgpu_cwsr.o + amdgpu_wb.o amdgpu_trap.o amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -4
@@ -332,8 +332,8 @@ struct amdgpu_reset_context;struct amdgpu_reset_control ;struct amdgpu_coredump_info ;struct amdgpu_video_codecs ; -struct amdgpu_cwsr_isa ; -struct amdgpu_cwsr_trap_obj ; +struct amdgpu_trap_isa ; +struct amdgpu_trap_obj ;enum amdgpu_cp_irq {AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP =0 ,
@@ -422,7 +422,7 @@ struct amdgpu_fpriv {struct xarray bo_list_handles;struct amdgpu_ctx_mgr ctx_mgr;struct amdgpu_userq_mgr userq_mgr; -struct amdgpu_cwsr_trap_obj *cwsr_trap; +struct amdgpu_trap_obj *trap_obj;/* Eviction fence infra */ struct amdgpu_eviction_fence_mgr evf_mgr;
@@ -990,7 +990,7 @@ struct amdgpu_device {*/ struct amdgpu_kfd_dev kfd; -struct amdgpu_cwsr_info *cwsr_info; +struct amdgpu_trap_info *trap_info; }; static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h deleted +0 -88
88 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
@@ -81,7 +81,7 @@#include "amdgpu_reset.h" #include "amdgpu_virt.h" #include "amdgpu_dev_coredump.h" -#include "amdgpu_cwsr.h" +#include "amdgpu_trap.h" #include <linux/suspend.h> #include <drm/task_barrier.h>
@@ -2551,7 +2551,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)if (r) goto init_failed; - r =amdgpu_cwsr_init (adev); + r =amdgpu_trap_init (adev);if (r == -EOPNOTSUPP ) r =0 ;else if (r)
@@ -2960,7 +2960,7 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) {int i, r; -amdgpu_cwsr_fini (adev); +amdgpu_trap_fini (adev);amdgpu_cper_fini (adev);if (amdgpu_sriov_vf (adev) && adev->virt.ras_init_done)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -52,6 +52,7 @@#include "amdgpu_sched.h" #include "amdgpu_xgmi.h" #include "amdgpu_userq.h" +#include "amdgpu_trap.h" #include "amdgpu_userq_fence.h" #include "../amdxcp/amdgpu_xcp_drv.h" #include "amdgpu_ualink.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -8
@@ -50,7 +50,7 @@#include "amdgpu_video_codecs.h" #include "amdgpu_ras_mgr.h" #include "amdgpu_vm.h" -#include "amdgpu_cwsr.h" +#include "amdgpu_trap.h" void amdgpu_unregister_gpu_instance (struct amdgpu_device *adev) {
@@ -1460,15 +1460,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)int num_xcc, r; fpriv = (struct amdgpu_fpriv *)filp->driver_priv; -if (!amdgpu_cwsr_is_enabled (adev) || !fpriv->cwsr_trap) +if (!amdgpu_trap_is_enabled (adev) || !fpriv->trap_obj)return -EOPNOTSUPP ; num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); cwsr_info.ctl_stack_size = - adev->cwsr_info->xcc_ctl_stack_sz * num_xcc; + adev->trap_info->cwsr.xcc_ctl_stack_sz * num_xcc; cwsr_info.dbg_mem_size = - adev->cwsr_info->xcc_dbg_mem_sz * num_xcc; + adev->trap_info->cwsr.xcc_dbg_mem_sz * num_xcc; cwsr_info.min_save_area_size = -amdgpu_cwsr_size_needed (adev, num_xcc); +amdgpu_trap_size_needed (adev, num_xcc); r =copy_to_user (out, &cwsr_info,min ((size_t )size,sizeof (cwsr_info))) ? -EFAULT :
@@ -1604,8 +1604,9 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_evf_mgr_init (&fpriv->evf_mgr); - r =amdgpu_cwsr_alloc (adev, &fpriv->vm, - &fpriv->cwsr_trap); + r =amdgpu_trap_alloc (adev, + &fpriv->vm, + &fpriv->trap_obj);if (r == -EOPNOTSUPP ) r =0 ;
@@ -1678,7 +1679,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, }amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); -amdgpu_cwsr_free (adev, &fpriv->vm, &fpriv->cwsr_trap); +amdgpu_trap_free (adev, &fpriv->vm, &fpriv->trap_obj);if (pasid)amdgpu_pasid_free_delayed (pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c new file +764 -0
764 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h new file +143 -0
143 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -7
@@ -35,7 +35,7 @@#include "amdgpu_hmm.h" #include "amdgpu_userq_fence.h" #include "amdgpu_trace.h" -#include "amdgpu_cwsr.h" +#include "amdgpu_trap.h" u32 amdgpu_userq_get_supported_ip_mask (struct amdgpu_device *adev) {
@@ -266,9 +266,8 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,return -EINVAL ; } -int amdgpu_userq_input_cwsr_params_validate ( -struct amdgpu_usermode_queue *queue, -struct amdgpu_cwsr_params *cwsr_params) +int amdgpu_userq_input_trap_params_validate (struct amdgpu_usermode_queue *queue, +struct amdgpu_trap_params *trap_params) {struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (queue->userq_mgr);struct amdgpu_device *adev = queue->userq_mgr->adev;
@@ -277,16 +276,16 @@ int amdgpu_userq_input_cwsr_params_validate(int r; num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); - r =amdgpu_cwsr_validate_params (queue->userq_mgr->adev, cwsr_params, + r =amdgpu_trap_validate_params (queue->userq_mgr->adev, trap_params, num_xcc);if (r)return r; - cwsr_size =amdgpu_cwsr_size_needed (queue->userq_mgr->adev, num_xcc); + cwsr_size =amdgpu_trap_size_needed (queue->userq_mgr->adev, num_xcc);if (!cwsr_size)return -EOPNOTSUPP ;return amdgpu_userq_input_va_validate ( - adev, queue, cwsr_params->ctx_save_area_address, cwsr_size, + adev, queue, trap_params->ctx_save_area_address, cwsr_size, &queue->userq_vas.va.cwsr); }
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -4
@@ -41,7 +41,7 @@ enum amdgpu_userq_state { };struct amdgpu_mqd_prop ; -struct amdgpu_cwsr_params ; +struct amdgpu_trap_params ;struct amdgpu_userq_obj {void *cpu_ptr;
@@ -202,8 +202,7 @@ int amdgpu_userq_input_va_validate(struct amdgpu_device *adev,void amdgpu_userq_gem_va_unmap_validate (struct amdgpu_device *adev,struct amdgpu_bo_va_mapping *mapping); -int amdgpu_userq_input_cwsr_params_validate ( -struct amdgpu_usermode_queue *queue, -struct amdgpu_cwsr_params *cwsr_params); +int amdgpu_userq_input_trap_params_validate (struct amdgpu_usermode_queue *queue, +struct amdgpu_trap_params *trap_params);#endif
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +12 -12
@@ -27,7 +27,7 @@#include "mes_userqueue.h" #include "amdgpu_userq_fence.h" #include "amdgpu_trace.h" -#include "amdgpu_cwsr.h" +#include "amdgpu_trap.h" #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -153,10 +153,10 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue) queue_input.page_table_base_addr =amdgpu_gmc_pd_addr (queue->vm->root.bo); queue_input.wptr_mc_addr = queue->wptr_obj.gpu_addr; -if (fpriv->cwsr_trap) { - queue_input.tba_addr = fpriv->cwsr_trap->tba_gpu_va_addr; - queue_input.tma_addr = fpriv->cwsr_trap->tma_gpu_va_addr; - queue_input.trap_en = !amdgpu_cwsr_has_dbg_wa (adev); +if (fpriv->trap_obj) { + queue_input.tba_addr = fpriv->trap_obj->tba_gpu_va_addr; + queue_input.tma_addr = fpriv->trap_obj->tma_gpu_va_addr; + queue_input.trap_en = !amdgpu_trap_has_dbg_wa (adev); }if (mes->use_rs64mem) {
@@ -420,7 +420,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd; -struct amdgpu_cwsr_params cwsr_params; +struct amdgpu_trap_params trap_params;if (mqd_user->mqd_size !=sizeof (*compute_mqd)) {DRM_ERROR ("Invalid compute IP MQD size\n" );
@@ -458,16 +458,16 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->tmz_queue = mqd_user->flags &AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE ; -if (amdgpu_cwsr_is_enabled (adev)) { +if (amdgpu_trap_is_enabled (adev)) {struct amdgpu_fpriv *fpriv =uq_mgr_to_fpriv (queue->userq_mgr);int num_xcc; num_xcc =amdgpu_xcp_get_num_xcc (adev->xcp_mgr, fpriv->xcp_id); - cwsr_params.ctx_save_area_address = + trap_params.ctx_save_area_address = compute_mqd->ctx_save_area_va; - cwsr_params.cwsr_sz = + trap_params.cwsr_sz = compute_mqd->ctx_save_area_size; r =amdgpu_bo_reserve (queue->vm->root.bo, false);
@@ -476,8 +476,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, goto free_mqd; } - r =amdgpu_userq_input_cwsr_params_validate ( - queue, &cwsr_params); + r =amdgpu_userq_input_trap_params_validate ( + queue, &trap_params);amdgpu_bo_unreserve (queue->vm->root.bo);if (r) {kfree (compute_mqd);
@@ -489,7 +489,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, userq_props->ctx_save_area_size = compute_mqd->ctx_save_area_size; userq_props->ctl_stack_size = - adev->cwsr_info->xcc_ctl_stack_sz * num_xcc; + adev->trap_info->cwsr.xcc_ctl_stack_sz * num_xcc; }kfree (compute_mqd);
Signature · 1 line
2.34.1
PATCH v3 5/7 drm/amdgpu: Make first-level trap state GPUVM-owned
In reply to Srinivasan ShanmugamThe first-level trap state belongs to the GPUVM because the TBA and TMA are mappings in that GPUVM.
User queues and kernel queues using the same GPUVM use the same first-level trap state. There is no need to keep a separate trap object in the file-private data.
Move the trap object into struct amdgpu_vm. Create it when the GPUVM is initialized and free it when the GPUVM is destroyed.
Create the trap state after releasing the initial VM root reservation. The trap allocation locks the VM internally, so doing this while the VM root is already reserved could lock the same reservation again.
For the same reason, free the trap state before reserving the VM root during VM cleanup.
Keep the first-level trap ISA buffer shared at the device level. The ISA is the same for all GPUVMs on the same device, while each GPUVM keeps its own trap mapping and TMA state.
Update the user queue path to get the first-level TBA and TMA from its GPUVM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 62 +++++++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 56 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +52 -10
@@ -45,6 +45,7 @@#include "amdgpu_xgmi.h" #include "amdgpu_dma_buf.h" #include "amdgpu_res_cursor.h" +#include "amdgpu_trap.h" #include "kfd_svm.h" /**
@@ -2636,6 +2637,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id) { +struct amdgpu_bo_va_mapping *mapping, *tmp;struct amdgpu_bo *root_bo;struct amdgpu_bo_vm *root;int r, i;
@@ -2644,6 +2646,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) vm->reserved_vmid[i] =NULL ; + vm->trap_obj =NULL ; +amdgpu_vm_bo_status_init (&vm->kernel);amdgpu_vm_bo_status_init (&vm->always_valid);spin_lock_init (&vm->individual_lock);
@@ -2710,10 +2714,28 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,dev_dbg (adev->dev,"Failed to create task info for VM\n" );amdgpu_bo_unreserve (vm->root.bo); + +if (amdgpu_trap_is_enabled (adev)) { + r =amdgpu_trap_alloc (adev, vm, &vm->trap_obj); +if (r) + goto error_free_trap; + } +amdgpu_bo_unref (&root_bo);return 0 ; +error_free_trap: +amdgpu_bo_reserve (root_bo, true); + +list_for_each_entry_safe (mapping, tmp, &vm->freed, list) { +list_del (&mapping->list); +amdgpu_vm_free_mapping (adev, vm, mapping,NULL ); + } + +amdgpu_vm_put_task_info (vm->task_info); +dma_fence_put (vm->last_update); + error_free_root:amdgpu_vm_pt_free_root (adev, vm);amdgpu_bo_unreserve (vm->root.bo);
@@ -2858,22 +2880,39 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_amdkfd_gpuvm_destroy_cb (adev, vm); +/* +* Free trap state before reserving root. amdgpu_trap_free() +* uses drm_exec to lock the page directory internally; calling +* it after amdgpu_bo_reserve(root) would deadlock on the same +* ww_mutex. +*/ +if (vm->trap_obj) +amdgpu_trap_free (adev, vm, &vm->trap_obj); + root =amdgpu_bo_ref (vm->root.bo);amdgpu_bo_reserve (root, true); +/* Wait for the jobs which might still use the reserved VMID */ if (vm->reserved_vmid[AMDGPU_GFXHUB (0 )]) -dma_resv_wait_timeout (root->tbo.base.resv,DMA_RESV_USAGE_READ , - false,MAX_SCHEDULE_TIMEOUT ); +dma_resv_wait_timeout (root->tbo.base.resv, +DMA_RESV_USAGE_READ , + false, +MAX_SCHEDULE_TIMEOUT ); +dma_fence_wait (vm->last_unlocked, false);dma_fence_put (vm->last_unlocked); +dma_fence_wait (vm->last_tlb_flush, false); +/* Make sure that all fence callbacks have completed */ dma_fence_lock_irqsave (vm->last_tlb_flush, flags);dma_fence_unlock_irqrestore (vm->last_tlb_flush, flags); +dma_fence_put (vm->last_tlb_flush);list_for_each_entry_safe (mapping, tmp, &vm->freed, list) { -if (mapping->flags &AMDGPU_VM_PAGE_PRT && prt_fini_needed) { +if (mapping->flags &AMDGPU_VM_PAGE_PRT && + prt_fini_needed) {amdgpu_vm_prt_fini (adev, vm); prt_fini_needed = false; }
@@ -2885,16 +2924,18 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)amdgpu_vm_pt_free_root (adev, vm);amdgpu_bo_unreserve (root);amdgpu_bo_unref (&root); +WARN_ON (vm->root.bo);amdgpu_vm_fini_entities (vm); -if (!RB_EMPTY_ROOT (&vm->va.rb_root)) { +if (!RB_EMPTY_ROOT (&vm->va.rb_root))dev_err (adev->dev,"still active bo inside vm\n" ); - } +rbtree_postorder_for_each_entry_safe (mapping, tmp, &vm->va.rb_root, rb) { -/* Don't remove the mapping here, we don't want to trigger a +/* +* Don't remove the mapping here, we don't want to trigger a * rebalance and the tree is about to be destroyed anyway. */ list_del (&mapping->list);
@@ -2903,9 +2944,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)dma_fence_put (vm->last_update); -for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++) { +for (i =0 ; i <AMDGPU_MAX_VMHUBS ; i++)amdgpu_vmid_free_spm (adev, vm, i); - }ttm_lru_bulk_move_fini (&adev->mman.bdev, &vm->lru_bulk_move);
@@ -2914,14 +2954,16 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)dev_warn (adev->dev,"VM memory stats for proc %s(%d) task %s(%d) is non-zero when fini\n" , - ti->process_name, ti->task.pid, ti->task.comm, ti->tgid); + ti->process_name, ti->task.pid, + ti->task.comm, ti->tgid); }if (vm->task_info && vm->task_info->task.pid) {int major, minor;amdgpu_vm_render_devt (adev, &major, &minor); -trace_amdgpu_deregister_pid (vm->task_info->task.pid, major, minor); +trace_amdgpu_deregister_pid (vm->task_info->task.pid, + major, minor); }amdgpu_vm_put_task_info (vm->task_info);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4 -0
@@ -43,6 +43,7 @@ struct amdgpu_bo_va;struct amdgpu_job ;struct amdgpu_bo_list_entry ;struct amdgpu_bo_vm ; +struct amdgpu_trap_obj ;/* * GPUVM handling
@@ -385,6 +386,9 @@ struct amdgpu_vm {/* cached fault info */ struct amdgpu_vm_fault_info fault_info; + +/* First-level trap state for this GPUVM; NULL if unavailable. */ +struct amdgpu_trap_obj *trap_obj; };struct amdgpu_vm_manager {
Signature · 1 line
2.34.1
PATCH v3 6/7 drm/amdgpu: Program trap TBA/TMA for kernel-managed VMIDs
In reply to Srinivasan ShanmugamUser queues get their first-level TBA and TMA from MES/KIQ when the queue is created. Kernel-managed VMIDs do not use this path, so program their trap registers from the gfxhub setup path.
Get the reserved first-level TBA and TMA virtual addresses and program them for kernel-managed VMIDs. User-queue VMIDs continue to receive their trap state through the existing MES/KIQ programming path.
The trap registers use the SRBM selector, so keep the programming under srbm_mutex and restore the VMID selector after the registers are updated.
Trap enablement differs across GPU generations. On GFX9, enable traps for user-queue VMIDs through the debug trap configuration and program kernel-managed VMIDs through the gfxhub path. On GFX9.4.3, enable the per-VMID trap control on each XCC. On generations where trap enable is encoded in SQ_SHADER_TBA_HI, program TRAP_EN together with the TBA address.
Mask the TBA and TMA address fields before writing the registers. Keep TRAP_EN disabled on the affected GFX11 ASICs to preserve the existing trap workaround.
On multi-XCC hardware, program the requested XCCs and restore the VMID selector on each XCC afterwards.
Keep the first-level trap VA layout inside amdgpu_trap. The gfxhub code only needs the final TBA and TMA addresses.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c | 9 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h | 5 ++ drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 28 ++++++-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 75 +++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 50 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 50 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 61 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 47 +++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 59 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 50 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 50 ++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 55 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 55 +++++++++++++++ 13 files changed, 576 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.c +8 -1
@@ -63,7 +63,14 @@ static inline uint64_t amdgpu_trap_tba_vaddr(struct amdgpu_device *adev)return addr; } -static inline bool amdgpu_trap_is_supported (struct amdgpu_device *adev) +void amdgpu_trap_get_l1_addr (struct amdgpu_device *adev, +u64 *tba_addr,u64 *tma_addr) +{ + *tba_addr =amdgpu_trap_tba_vaddr (adev); + *tma_addr = *tba_addr +AMDGPU_TRAP_TMA_OFFSET ; +} + +bool amdgpu_trap_is_supported (struct amdgpu_device *adev) {uint32_t gc_ver =amdgpu_ip_version (adev,GC_HWIP ,0 );
drivers/gpu/drm/amd/amdgpu/amdgpu_trap.h +5 -0
@@ -76,6 +76,11 @@ struct amdgpu_trap_usr_addr {int amdgpu_trap_init (struct amdgpu_device *adev);void amdgpu_trap_fini (struct amdgpu_device *adev); +bool amdgpu_trap_is_supported (struct amdgpu_device *adev); + +void amdgpu_trap_get_l1_addr (struct amdgpu_device *adev, +u64 *tba_addr,u64 *tma_addr); +int amdgpu_trap_alloc (struct amdgpu_device *adev,struct amdgpu_vm *vm,struct amdgpu_trap_obj **trap_obj);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +24 -4
@@ -29,6 +29,7 @@#include "amdgpu.h" #include "amdgpu_gfx.h" +#include "amdgpu_trap.h" #include "soc15.h" #include "soc15d.h" #include "amdgpu_atomfirmware.h"
@@ -2570,14 +2571,25 @@ static void gfx_v9_0_setup_rb(struct amdgpu_device *adev) }static void gfx_v9_0_debug_trap_config_init (struct amdgpu_device *adev, -uint32_t vmid_mask) +uint32_t vmid_mask) {uint32_t data; +u32 trap_config_vmid_mask; + + data =RREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_CONFIG)); + + trap_config_vmid_mask = +REG_GET_FIELD (data,SPI_GDBG_TRAP_CONFIG ,VMID_SEL ); + +/* Add the requested VMIDs to the existing trap configuration. */ + trap_config_vmid_mask |= vmid_mask; + + data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , +VMID_SEL , trap_config_vmid_mask); - data =REG_SET_FIELD (0 ,SPI_GDBG_TRAP_CONFIG , -VMID_SEL , vmid_mask); data =REG_SET_FIELD (data,SPI_GDBG_TRAP_CONFIG , -TRAP_EN ,1 ); +TRAP_EN ,1 ); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_CONFIG), data);WREG32 (SOC15_REG_OFFSET (GC ,0 , mmSPI_GDBG_TRAP_MASK),0 );
@@ -4046,6 +4058,14 @@ static int gfx_v9_0_hw_init(struct amdgpu_ip_block *ip_block)if (r)return r; +if (amdgpu_trap_is_supported (adev)) { +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 )) +gfx_v9_4_2_debug_trap_config_init (adev); +else +gfx_v9_0_debug_trap_config_init (adev, + adev->vm_manager.vmid_uq_mask_gfxhub); + } +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (9 ,4 ,2 ) && !amdgpu_sriov_vf (adev))gfx_v9_4_2_set_power_brake_sequence (adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +62 -13
103 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c +50 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c +50 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +61 -0
79 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +47 -0
65 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +59 -0
77 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c +50 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c +50 -0
68 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c +55 -0
73 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 7/7 drm/amdgpu/uapi: Add SET/CLEAR L2 TRAP to VM ioctl
In reply to Srinivasan ShanmugamAdd SET_L2_TRAP and CLEAR_L2_TRAP operations to the VM ioctl.
The second-level trap handler is set per GPUVM. All shader waves using the same GPUVM use the same second-level trap handler, regardless of the queue type.
SET_L2_TRAP sets the userspace TBA and TMA addresses for the GPUVM. The kernel checks that both address ranges are mapped in the GPUVM before using them.
CLEAR_L2_TRAP clears the second-level TBA and TMA addresses from the first-level trap descriptor.
Userspace must keep the TBA and TMA mappings valid after SET_L2_TRAP. The mappings can be removed after CLEAR_L2_TRAP completes successfully.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 36 ++++++++++++++- include/uapi/drm/amdgpu_drm.h | 63 ++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +35 -1
@@ -3056,19 +3056,53 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) }return r; } +case AMDGPU_VM_OP_UNRESERVE_VMID : {struct amdgpu_bo *root = vm->root.bo;amdgpu_bo_reserve (root, true); +/* Wait for the jobs which might still use the reserved VMID */ if (vm->reserved_vmid[AMDGPU_GFXHUB (0 )])dma_resv_wait_timeout (root->tbo.base.resv, -DMA_RESV_USAGE_READ , false, +DMA_RESV_USAGE_READ , + false,MAX_SCHEDULE_TIMEOUT ); +amdgpu_vmid_free_spm (adev, vm,AMDGPU_GFXHUB (0 ));amdgpu_bo_unreserve (root); +break ; } + +case AMDGPU_VM_OP_SET_L2_TRAP : +/* +* Install or replace the per-VM second-level trap handler. +* Applies to all shader waves using this GPUVM regardless of +* queue type. +*/ +if (!vm->trap_obj) +return -EOPNOTSUPP ; + +return amdgpu_trap_vm_set_l2_trap (adev, vm, + vm->trap_obj, + args->in.l2trap.tba_va, + args->in.l2trap.tba_sz, + args->in.l2trap.tma_va, + args->in.l2trap.tma_sz); + +case AMDGPU_VM_OP_CLEAR_L2_TRAP : +if (memchr_inv (&args->in.l2trap,0 , +sizeof (args->in.l2trap))) +return -EINVAL ; + +/* Disable the per-VM second-level trap handler. */ +if (!vm->trap_obj) +return -EOPNOTSUPP ; + +return amdgpu_trap_vm_clear_l2_trap (adev, vm, + vm->trap_obj); +default :return -EINVAL ; }
include/uapi/drm/amdgpu_drm.h +63 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1