AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Frank Min" <Frank.Min@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 5/9] drm/amdgpu: add lsdma v8 fw loading support
Date: Fri, 04 Dec 2026 15:47:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-250130@kernel.org> (raw)
In-Reply-To: <20261204142408.988734-5-Frank.Min@amd.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/amdgpu: struct amdgpu_lsdma fields added after parent
  commit uses them
- [Medium] drm/amdgpu: missing LSDMA firmware header, payload, and ALIGN
  bounds checks
- [Medium] drm/amdgpu: sdma_v8_0_early_init() leaks SDMA fw on LSDMA
  init failure
- [Medium] drm/amdgpu: leak LSDMA firmware on probe failure before
  sdma_v8_0_sw_init()
--

commit 8d33406c65061fd80329c2978329e7275ecae49b
Author: Frank Min <Frank.Min@amd.com>

drm/amdgpu: add lsdma v8 fw loading support

This commit adds LSDMA v8 firmware loading support, including the v1.0
firmware header definition, microcode initialization and teardown helpers,
and PSP/SDMA v8.0 integration.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c
> index 1f83d9b69135b..5d093e25cac6d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.c

[ ... ]

> +	hdr = (const struct lsdma_firmware_header_v1_0 *)adev->lsdma.fw->data;
> +	switch (le16_to_cpu(hdr->header.header_version_major)) {
> +	case 1:
> +		break;
> +	default:
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	adev->lsdma.fw_version = le32_to_cpu(hdr->header.ucode_version);
> +	adev->lsdma.feature_version = le32_to_cpu(hdr->ucode_feature_version);
> +
> +	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
> +		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_LSDMA];
> +		info->ucode_id = AMDGPU_UCODE_ID_LSDMA;
> +		info->fw = adev->lsdma.fw;
> +		adev->firmware.fw_size +=
> +			ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
> +	}

[Severity: Medium]
Can a truncated or malformed LSDMA firmware image cause an out-of-bounds
read from fw->data or an out-of-bounds write into fw_buf here?

amdgpu_ucode_validate() only checks fw->size == le32_to_cpu(hdr->size_bytes),
so fw->data may be smaller than sizeof(*hdr), and neither this function nor
amdgpu_ucode_init_single_fw() checks that ucode_array_offset_bytes +
ucode_size_bytes fits within fw->size before memcpy().  In addition,
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE) and the addition into
32-bit adev->firmware.fw_size can wrap around, causing
amdgpu_ucode_create_bo() to allocate an undersized firmware BO.

[ ... ]

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h
> index f0a5eeb3529fb..79ac16e352d71 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_lsdma.h
> @@ -30,6 +30,9 @@ struct amdgpu_lsdma {
>  	struct mutex lock;
>  	const struct amdgpu_lsdma_funcs      *funcs;
>  	uint32_t inst_mask;
> +	const struct firmware *fw;
> +	uint32_t fw_version;
> +	uint32_t feature_version;
>  };

[Severity: High]
Does adding fw, fw_version, and feature_version here break git bisect with
the preceding commit "drm/amdgpu: add lsdma v8 fw query interface"?

That earlier commit already references adev->lsdma.fw_version and
adev->lsdma.feature_version in amdgpu_firmware_info() and adev->lsdma.fw in
amdgpu_debugfs_firmware_info_show(), so the tree fails to build at that
commit.  These struct fields (or this whole commit) should be ordered before
the query interface patch.

[ ... ]

> diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c
> index 58b85fbba2ca3..e39a005b0faf4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/sdma_v8_0.c
> @@ -1293,6 +1293,12 @@ static int sdma_v8_0_early_init(struct amdgpu_ip_block *ip_block)
>  		return r;
>  	}
>  
> +	r = amdgpu_lsdma_init_microcode(adev);
> +	if (r) {
> +		DRM_ERROR("Failed to init lsdma firmware!\n");
> +		return r;
> +	}
> +
>  	sdma_v8_0_set_ring_funcs(adev);
>  	amdgpu_sdma_set_vm_pte_scheds(adev, &sdma_v8_0_vm_pte_funcs);
>  	sdma_v8_0_set_irq_funcs(adev);

[Severity: Medium]
Does returning here leak the SDMA firmware loaded just above by
amdgpu_sdma_init_microcode()?

When sdma_v8_0_early_init() fails, status.sw stays false and
amdgpu_device_ip_fini() skips sdma_v8_0_sw_fini(), so
amdgpu_sdma_destroy_inst_ctx(adev, true) never runs to release
adev->sdma.instance[0].fw.

> @@ -1377,6 +1383,7 @@ static int sdma_v8_0_sw_fini(struct amdgpu_ip_block *ip_block)
>  
>  	amdgpu_sdma_sysfs_reset_mask_fini(adev);
>  	amdgpu_sdma_destroy_inst_ctx(adev, true);
> +	amdgpu_lsdma_fini_microcode(adev);
>  
>  	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT)
>  		sdma_v8_0_0_free_ucode_buffer(adev);

[Severity: Medium]
Can adev->lsdma.fw be leaked if device probe fails after
sdma_v8_0_early_init() succeeds but before sdma_v8_0_sw_init() completes?

amdgpu_device_ip_init() only sets status.sw after sw_init() returns 0, and
sdma_v8_0_ip_funcs has no early_fini callback, so amdgpu_device_ip_fini()
skips sdma_v8_0_sw_fini() on an earlier probe failure (such as another IP
block's early_init() or an error inside sdma_v8_0_sw_init()).  Moving the
microcode init into sw_init() or providing an early_fini callback would
ensure adev->lsdma.fw is released.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204142408.988734-1-Frank.Min@amd.com?part=5

  reply	other threads:[~2026-12-04 15:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:24 [PATCH 1/9] drm/amdgpu: skip vm inv for kiq ring Frank Min
2026-12-04 14:24 ` [PATCH 2/9] drm/amdgpu: disable gfx 13 pipe 1 ring Frank Min
2026-12-04 14:55   ` sashiko-bot
2026-12-04 16:05   ` Alex Deucher
2026-12-04 14:24 ` [PATCH 3/9] drm/amdgpu: update table info retrieval from discovery binary Frank Min
2026-12-04 15:14   ` sashiko-bot
2026-12-04 16:19   ` Alex Deucher
2026-12-04 14:24 ` [PATCH 4/9] drm/amdgpu: add lsdma v8 fw query interface Frank Min
2026-12-04 15:25   ` sashiko-bot
2026-12-04 16:21   ` Alex Deucher
2026-12-04 14:24 ` [PATCH 5/9] drm/amdgpu: add lsdma v8 fw loading support Frank Min
2026-12-04 15:47   ` sashiko-bot [this message]
2026-12-04 14:24 ` [PATCH 6/9] drm/amdgpu: Fix system aperture size for gfx13 Frank Min
2026-12-04 16:01   ` sashiko-bot
2026-12-04 14:24 ` [PATCH 7/9] drm/amdgpu: remove the unused ring parameter in update_spm_vmid() " Frank Min
2026-12-04 16:03   ` Alex Deucher
2026-12-04 16:11   ` sashiko-bot
2026-12-04 14:24 ` [PATCH 8/9] drm/amdgpu: enable uni-mes " Frank Min
2026-12-04 16:41   ` sashiko-bot
2026-12-04 17:24   ` Alex Deucher
2026-12-04 14:24 ` [PATCH 9/9] drm/amdgpu: fix mutex unlock position for ucode loading Frank Min
2026-12-04 16:12   ` Alex Deucher
2026-12-04 16:52   ` sashiko-bot
2026-12-04 14:41 ` [PATCH 1/9] drm/amdgpu: skip vm inv for kiq ring sashiko-bot
2026-12-04 16:16 ` Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-250130@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Min@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox