dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baoquan He" <hebaoquan@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 02/13] drm/sti: Don't use GFP_DMA when calling dma_alloc_wc()
Date: Thu, 03 Sep 2026 11:29:48 +0000	[thread overview]
Message-ID: <20260903112948.C072C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903111836.1777265-3-hebaoquan@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The `sti_cursor_atomic_check` callback incorrectly mutates persistent global plane state and frees active DMA memory during the validation-only atomic check phase. This violates the DRM atomic API contract and causes a hardware use-after-free if triggered by a TEST_ONLY commit or if the commit fails.
- [High] Missing error handling for DMA allocation failure in `sti_hqvdp_init` leads to a NULL pointer dereference later in `sti_hqvdp_atomic_update`.
--

commit ffcf141c00928add2d88a408f8402ffc52667925
Author: Baoquan He <hebaoquan@kylinos.cn>
drm/sti: Don't use GFP_DMA when calling dma_alloc_wc()

This commit removes the redundant GFP_DMA flag from dma_alloc_wc() calls
in the sti DRM driver, as the DMA core already handles zone selection based
on the device's coherent DMA mask.

> diff --git a/drivers/gpu/drm/sti/sti_cursor.c b/drivers/gpu/drm/sti/sti_cursor.c
> --- a/drivers/gpu/drm/sti/sti_cursor.c
> +++ b/drivers/gpu/drm/sti/sti_cursor.c
[ ... ]
> @@ -240,7 +240,7 @@ static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
>  		cursor->pixmap.base = dma_alloc_wc(cursor->dev,
>  						   cursor->pixmap.size,
>  						   &cursor->pixmap.paddr,
> -						   GFP_KERNEL | GFP_DMA);
> +						   GFP_KERNEL);
>  		if (!cursor->pixmap.base) {
>  			DRM_ERROR("Failed to allocate memory for pixmap\n");
>  			return -EINVAL;

[Severity: Critical]
This is a pre-existing issue, but does this mutate persistent global plane
state during the validation-only atomic check phase?

Just before this allocation, sti_cursor_atomic_check() frees the active
DMA buffer (cursor->pixmap.base). Could this cause a hardware use-after-free
if triggered by a TEST_ONLY commit while the hardware is still scanning out
the old buffer? It appears the mutation of global state here breaks the core
assumption that TEST_ONLY commits are side-effect free.

[ ... ]
> diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c
> --- a/drivers/gpu/drm/sti/sti_hqvdp.c
> +++ b/drivers/gpu/drm/sti/sti_hqvdp.c
[ ... ]
> @@ -860,7 +860,7 @@ static void sti_hqvdp_init(struct sti_hqvdp *hqvdp)
>  	size = NB_VDP_CMD * sizeof(struct sti_hqvdp_cmd);
>  	hqvdp->hqvdp_cmd = dma_alloc_wc(hqvdp->dev, size,
>  					&dma_addr,
> -					GFP_KERNEL | GFP_DMA);
> +					GFP_KERNEL);
>  	if (!hqvdp->hqvdp_cmd) {
>  		DRM_ERROR("Failed to allocate memory for VDP cmd\n");
>  		return;
>  	}

[Severity: High]
This is a pre-existing issue, but should this function return an error code
if the allocation fails instead of just returning void?

If dma_alloc_wc() fails here in sti_hqvdp_init(), the error is logged but
not propagated to the caller, leaving hqvdp->hqvdp_cmd as NULL. Could this
allow the plane to be successfully registered, resulting in a NULL pointer
dereference later when userspace attempts to use the plane?

For example, sti_hqvdp_atomic_update() dereferences the pointer
unconditionally:

sti_hqvdp_atomic_update()
   cmd = hqvdp->hqvdp_cmd + cmd_offset;
   cmd->top.config = TOP_CONFIG_PROGRESSIVE;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260903111836.1777265-1-hebaoquan@kylinos.cn?part=2

       reply	other threads:[~2026-09-03 11:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260903111836.1777265-1-hebaoquan@kylinos.cn>
     [not found] ` <20260903111836.1777265-3-hebaoquan@kylinos.cn>
2026-09-03 11:29   ` sashiko-bot [this message]
     [not found] ` <20260903111836.1777265-6-hebaoquan@kylinos.cn>
2026-09-03 11:30   ` [PATCH 05/13] fbdev: fsl-diu-fb: Don't use GFP_DMA when calling dmam_alloc_coherent() 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=20260903112948.C072C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hebaoquan@kylinos.cn \
    --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