Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdkfd: heap buffer overflow in checkpoint_mqd_v12_1() on
  SDMA queues
- [Medium] drm/amdkfd: missing multi-XCC iteration in
  checkpoint_mqd_v12_1()
--

commit b939ab2a38bf0604406a6b6f7f0e390220c671fb
Author: David Francis <[email protected]>

drm/amdkfd: Add checkpoint handler for mqd 12.1

This commit adds a CRIU checkpoint callback for GFX 12.1 and wires it to
compute and SDMA MQD managers in mqd_manager_init_v12_1().

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c
> index 0c116fc8bb532..1a3b3c7103c1f 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c
> @@ -671,6 +671,15 @@ static int debugfs_show_mqd_sdma(struct seq_file *m, 
> void *data)
>  
>  #endif
>  
> +static void checkpoint_mqd_v12_1(struct mqd_manager *mm, void *mqd, void 
> *mqd_dst, void *ctl_stack_dst)
> +{
> +     struct v12_1_compute_mqd *m;
> +
> +     m = get_mqd(mqd);
> +
> +     memcpy(mqd_dst, m, sizeof(struct v12_1_compute_mqd));
> +}

[Severity: Medium]
Does checkpoint_mqd_v12_1() need to iterate over NUM_XCC(mm->dev->xcc_mask)
at m->cp_mqd_stride_size stride, like checkpoint_mqd_v9_4_3()?

get_queue_checkpoint_info() sizes the checkpoint buffer for
mqd_mgr->mqd_size * NUM_XCC(mqd_mgr->dev->xcc_mask) bytes, and
criu_checkpoint_queues_device() expects mqd[xcc0], mqd[xcc1], ... in
mqd_dst.  Copying only a single struct v12_1_compute_mqd leaves the
remaining XCC slots zeroed when checkpointing a compute queue on a
multi-XCC GFX 12.1 partition.

[ ... ]

> @@ -813,6 +823,7 @@ struct mqd_manager *mqd_manager_init_v12_1(enum 
> KFD_MQD_TYPE type,
>               mqd->is_occupied = kfd_is_occupied_sdma;
>               mqd->mqd_size = sizeof(struct v12_1_sdma_mqd);
>               mqd->mqd_stride = kfd_mqd_stride;
> +             mqd->checkpoint_mqd = checkpoint_mqd_v12_1;
>               mqd->restore_mqd = restore_mqd_sdma_v12_1;
>  #if defined(CONFIG_DEBUG_FS)
>               mqd->debugfs_show_mqd = debugfs_show_mqd_sdma;

[Severity: High]
Can wiring checkpoint_mqd_v12_1() to KFD_MQD_TYPE_SDMA overflow the
q_private_data heap buffer in criu_checkpoint_queues_device()?

For SDMA queues, mqd->mqd_size is sizeof(struct v12_1_sdma_mqd) (512
bytes), so criu_checkpoint_queues_device() allocates 512 * NUM_XCC bytes
for mqd_dst, whereas checkpoint_mqd_v12_1() copies
sizeof(struct v12_1_compute_mqd) (4096 bytes).  Should KFD_MQD_TYPE_SDMA
use a dedicated checkpoint_mqd_sdma_v12_1() callback that copies
sizeof(struct v12_1_sdma_mqd) via get_sdma_mqd(), matching
restore_mqd_sdma_v12_1()?

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to