All of 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 3/9] drm/amdgpu: update table info retrieval from discovery binary
Date: Fri, 04 Dec 2026 15:14:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-250072@kernel.org> (raw)
In-Reply-To: <20261204142408.988734-3-Frank.Min@amd.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] drm/amdgpu: v0/v1 discovery lookup broken by table_id scan
- [Medium] drm/amdgpu: amdgpu_discovery_table_check() ignores invalid
  headers
- [Medium] drm/amdgpu: amdgpu_discovery_refresh_nps_info() misses v2
  table_id lookup
- [Medium] drm/amdgpu: OOB read in
  amdgpu_discovery_get_table_info_from_bin()
- [Low] drm/amdgpu: commit message omits discovery table format and
  lookup rationale
- [Low] drm/amdgpu: spurious dev_err() in
  amdgpu_discovery_get_table_info()
--

commit 2a203845aec3dbcd54cbcfc1a749319c4ba689f3
Author: Frank Min <Frank.Min@amd.com>

> drm/amdgpu: update table info retrieval from discovery binary
>
> Update table info retrieval from discovery binary to align with
> discovery table update.
>
> Signed-off-by: Frank Min <Frank.Min@amd.com>
> Reviewed-By: Hawking Zhang <Hawking.Zhang@amd.com>

[Severity: Low]
Can the commit message explain what changed in the discovery table format
and why the lookup and error handling changed?  It does not mention that v2
binaries populate table_info.table_id and may omit unused entries, why v0
and v1 are also changed, or why amdgpu_discovery_table_check() returns 0.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index c52b0d9ac00b7..5997946fb1171 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -609,18 +609,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
>  					 uint16_t table_id)
>  {
>  	struct binary_header *bhdr = (struct binary_header *)discovery_bin;
> -	struct binary_header_v2 *bhdrv2;
> -
> -	switch (bhdr->version_major) {
> -	case 2:
> -		bhdrv2 = (struct binary_header_v2 *)discovery_bin;
> -		return &bhdrv2->table_list[table_id];
> -	case 1:
> +	struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
> +	uint16_t version = le16_to_cpu(bhdr->version_major);
> +	uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
> +	struct table_info *table_list;
> +	uint16_t num_tables, i;
> +	size_t table_offset;
> +
> +	switch (version) {
>  	case 0:
> -		return &bhdr->table_list[table_id];
> +	case 1:
> +		table_list = bhdr->table_list;
> +		num_tables = ARRAY_SIZE(bhdr->table_list);
> +		break;
> +	case 2:
> +		table_list = bhdrv2->table_list;
> +		num_tables = le16_to_cpu(bhdrv2->num_tables);
> +		break;
>  	default:
>  		return NULL;
>  	}
> +
> +	table_offset = (uint8_t *)table_list - discovery_bin;
> +	if (table_offset + num_tables * sizeof(*table_list) > binary_size)
> +		return NULL;

[Severity: Medium]
Can this bounds check still read past the end of discovery_bin?  It compares
against bhdr->binary_size from the binary itself (up to 65535 bytes) rather
than the allocated buffer size.

adev->discovery.bin defaults to DISCOVERY_TMR_SIZE (10 KiB), and
amdgpu_discovery_sysfs_early_init() always copies DISCOVERY_TMR_SIZE bytes
into ip_top->discovery_bin.  A v2 header with a larger binary_size and
num_tables passes this check and reads out of bounds during the scan.

In addition, case 2 reads bhdrv2->num_tables before checking that the buffer
is at least sizeof(*bhdrv2) bytes, while
amdgpu_discovery_read_binary_from_file() only enforces a 12-byte minimum.
Passing the allocated buffer size into this helper and checking both
binary_size and sizeof(*bhdrv2) against it would close both over-reads.

> +
> +	for (i = 0; i < num_tables; i++)
> +		if (le16_to_cpu(table_list[i].table_id) == table_id)
> +			return &table_list[i];
> +
> +	return NULL;
>  }

[Severity: High]
Does routing v0 and v1 headers through this table_id scan break table
lookups on every GPU with a v0 or v1 discovery binary?

In drivers/gpu/drm/amd/include/discovery.h, table_info.table_id is padding
for v1 (and v0) headers and is zero-filled, while bhdr->table_list is
indexed directly by enum table.

Every non-zero table_id (GC, HARVEST_INFO, VCN_INFO, MALL_INFO, NPS_INFO)
will therefore return NULL, leaving harvest masks and GFX/MALL/VCN
configuration unpopulated during probe because
amdgpu_discovery_set_ip_blocks() ignores those lookup failures.

Scanning all 8 entries of bhdr->table_list on older 6-slot v0/v1 binaries
also reads 16 bytes past table_list into adjacent table data.  Versions 0
and 1 should keep direct indexing (&bhdr->table_list[table_id]) with bounds
checks, reserving the table_id scan for v2.

[Severity: Medium]
Should amdgpu_discovery_refresh_nps_info() also be updated for the v2
table_id lookup?

It reads the discovery header directly from VRAM and still indexes
bhdrv2.table_list[NPS_INFO] by fixed position under case 2, which will read
the wrong entry or fail checksum verification during NPS refresh after reset
on v2 binaries with sparse or reordered tables.  It also switches on
bhdr.version_major without le16_to_cpu() and omits case 0.

[ ... ]

> @@ -633,8 +651,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
>  	*info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
>  							 table_id);
>  	if (!*info) {
> -		dev_err(adev->dev, "Invalid ip discovery table version %d\n",
> -			bhdr->version_major);
> +		dev_err(adev->dev, "Not found table for header version %d table id %d\n",
> +			bhdr->version_major, table_id);
>  		return -EINVAL;
>  	}

[Severity: Low]
Will this emit spurious dev_err() messages during normal probe on v2
binaries that omit optional tables?

Previously dev_err() only fired on unsupported header versions.  Now
amdgpu_discovery_init() probes the optional MEM_RESERVED_INFO table (whose
caller logs absence at dev_dbg()) and amdgpu_discovery_set_ip_blocks()
probes MALL_INFO and VCN_INFO, logging errors whenever they are absent.

[ ... ]

> @@ -645,15 +663,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
>  					uint8_t *discovery_bin,
>  					uint16_t table_id)
>  {
> -	int r, act_val, exp_val, table_size;
> +	int act_val, exp_val, table_size;
>  	uint16_t offset, checksum;
>  	struct table_info *info;
>  	bool check_table = true;
>  	char *table_name;
>  
> -	r = amdgpu_discovery_get_table_info(adev, &info, table_id);
> -	if (r)
> -		return r;
> +	info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
> +	if (!info)
> +		return 0;

[Severity: Medium]
Does returning 0 on NULL bypass header validation and mandatory
IP_DISCOVERY checks in amdgpu_discovery_init()?

amdgpu_discovery_get_table_info_from_bin() returns NULL for an unsupported
version_major, an out-of-bounds num_tables, and a missing IP_DISCOVERY
table, not just absent optional tables.

Because amdgpu_discovery_init() has no other check on version_major or
num_tables, it will return 0 on an invalid binary instead of freeing
adev->discovery.bin and calling amdgpu_ras_query_boot_status().

That lets amdgpu_discovery_sysfs_early_init() copy the invalid binary in
amdgpu_discovery_reg_base_init(), and on legacy ASICs leaves
adev->discovery.bin non-NULL so amdgpu_discovery_sysfs_init() leaks ip_top
and die_kset when amdgpu_discovery_sysfs_recurse() fails.

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

  reply	other threads:[~2026-12-04 15:15 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 [this message]
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
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-250072@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.