AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bob Zhou" <bobzhou2@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: keep the address of cleared PDEs with translate further
Date: Thu, 26 Nov 2026 07:52:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-234971@kernel.org> (raw)
In-Reply-To: <20261126073232.2108102-1-bobzhou2@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: cleared PDE addr passed as incr in
  amdgpu_vm_pt_clear()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] drm/amdgpu: unchecked update() return in
  amdgpu_vm_pte_update_flags() [1]
--

commit 989da6857bfdb3b7b6591cb250770217b86c1b11
Author: Bob Zhou <bobzhou2@amd.com>

drm/amdgpu: keep the address of cleared PDEs with translate further

This commit passes an address pointer into amdgpu_vm_pt_clear_flags() so
that callers receive the PDE address generated by amdgpu_gmc_get_vm_pde()
when clearing page directories.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> index a6d389c08524f..6aabd9f5291c2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c

[ ... ]

> @@ -395,7 +393,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  	struct amdgpu_bo *ancestor = &vmbo->bo;
>  	struct amdgpu_bo *bo = &vmbo->bo;
>  	unsigned int entries;
> -	uint64_t flags;
> +	uint64_t value = 0, flags;
>  	int r, idx;
>  
>  	/* Figure out our place in the hierarchy */
> @@ -430,8 +428,9 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  	if (r)
>  		goto exit;
>  
> -	flags = amdgpu_vm_pt_clear_flags(adev, vm, level);
> -	r = vm->update_funcs->update(&params, vmbo, 0, 0, entries, 0, flags);
> +	flags = amdgpu_vm_pt_clear_flags(adev, vm, level, &value);
> +	r = vm->update_funcs->update(&params, vmbo, 0, 0, entries, value,
> +				     flags);
>  	if (r)
>  		goto exit;
>  

[Severity: High]
Does this pass value as the incr argument instead of the addr argument to
vm->update_funcs->update()?

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h:struct amdgpu_vm_update_funcs {
    ...
	int (*update)(struct amdgpu_vm_update_params *p,
		      struct amdgpu_bo_vm *bo, uint64_t pe, uint64_t addr,
		      unsigned count, uint32_t incr, uint64_t flags);
    ...
}

Because addr is left at 0 and value is passed as incr, entry 0 of a
cleared PDB0 on GMC v9 with translate_further enabled is still written with
address 0, and subsequent entries increment by 0x1000 per entry (leaving
bit 12 clear on all even entries) instead of writing value to every entry,
causing GPU VM faults during page table walks.

Should value be passed as the fourth argument (addr) and 0 as the sixth
argument (incr)?

> @@ -724,7 +723,8 @@ static void amdgpu_vm_pte_update_flags(struct amdgpu_vm_update_params *params,
>  
>  	} else if (!(flags & AMDGPU_PTE_VALID) &&
>  		   !(flags & AMDGPU_PTE_PRT_FLAG(params->adev))) {
> -		flags |= amdgpu_vm_pt_clear_flags(adev, params->vm, level);
> +		flags |= amdgpu_vm_pt_clear_flags(adev, params->vm, level,
> +						  &addr);
>  	}
>  
>  	/*

[Severity: Critical]
This problem wasn't introduced by this patch, but can
amdgpu_vm_pte_update_flags() cause a NULL pointer dereference on
params->job [1] by ignoring the return value of
params->vm->update_funcs->update()?

drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c:amdgpu_vm_sdma_update() {
    ...
		if (ndw < 32) {
			r = amdgpu_vm_sdma_commit(p, NULL);
			if (r)
				return r;

			r = amdgpu_vm_sdma_alloc_job(p, count,
						     AMDGPU_KERNEL_JOB_ID_VM_UPDATE);
			if (r)
				return r;
		}
    ...
		pte = (uint64_t *)&(p->job->ibs->ptr[p->num_dw_left]);
    ...
}

When amdgpu_vm_sdma_commit() runs during amdgpu_vm_sdma_update() and the
subsequent amdgpu_vm_sdma_alloc_job() fails, p->job is left NULL.  Because
amdgpu_vm_pte_update_flags() returns void and discards the error, the loop
in amdgpu_vm_ptes_update() continues and the next call to
amdgpu_vm_sdma_update() or amdgpu_vm_sdma_commit() dereferences the NULL
p->job pointer.

[1] https://sashiko.dev/#/bug/linux-1897ae3a-7a03-49b7-b2ae-54c63b21478f

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126073232.2108102-1-bobzhou2@amd.com?part=1

  reply	other threads:[~2026-11-26  7:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  7:32 [PATCH] drm/amdgpu: keep the address of cleared PDEs with translate further Bob Zhou
2026-11-26  7:52 ` sashiko-bot [this message]
2026-11-26  9:45 ` Christian König
  -- strict thread matches above, loose matches on Subject: below --
2026-11-26 10:19 Bob Zhou
2026-11-26 10:35 ` Christian König
2026-11-26 10:40 ` sashiko-bot

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-234971@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bobzhou2@amd.com \
    --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