DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nathan Lynch via B4 Relay" <devnull+nathan.lynch.amd.com@kernel.org>
Cc: linux-pci@vger.kernel.org, Frank.Li@kernel.org,
	dmaengine@vger.kernel.org, vkoul@kernel.org
Subject: Re: [PATCH 08/23] dmaengine: sdxi: Install administrative context
Date: Fri, 14 Aug 2026 00:09:50 +0000	[thread overview]
Message-ID: <20260814000950.C73141F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260410-sdxi-base-v1-8-1d184cb5c60a@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Hardware retains access to freed DMA memory due to missing L1 entry invalidation during teardown.
- [Medium] Incorrect error check for `dma_pool_zalloc` allocation of `cxt->cxt_ctl`.
--

--- Patch [8]: [PATCH 08/23] dmaengine: sdxi: Install administrative context ---
commit 17401dc26aa25b16b19cf4cf87900b7c0d64a889
Author: Nathan Lynch <nathan.lynch@amd.com>

dmaengine: sdxi: Install administrative context

Serialize the context control block, akey table, and L1 entry for the
admin context, making its descriptor ring, write index, and context
status block visible to the SDXI implementation once it is activated.

> diff --git a/drivers/dma/sdxi/context.c b/drivers/dma/sdxi/context.c
> index 0a6821992776c..097d871e530fd 100644
> --- a/drivers/dma/sdxi/context.c
> +++ b/drivers/dma/sdxi/context.c

[ ... ]

> @@ -115,13 +267,23 @@ static void free_admin_cxt(void *ptr)
>  
>  int sdxi_admin_cxt_init(struct sdxi_dev *sdxi)
>  {
> +	int err;
> +	struct sdxi_sq *sq;
> +
>  	struct sdxi_cxt *cxt __free(sdxi_cxt) = sdxi_alloc_cxt(sdxi);

[Severity: Medium]
In sdxi_alloc_cxt() called here, the code handles allocation as follows:

drivers/dma/sdxi/context.c:sdxi_alloc_cxt() {
    ...
    cxt->cxt_ctl = dma_pool_zalloc(sdxi->cxt_ctl_pool, GFP_KERNEL,
                                   &cxt->cxt_ctl_dma);
    if (!cxt->cxt_ctl_dma)
        return NULL;
    ...
}

Is this the correct check for dma_pool_zalloc() failure? DMA address 0 can be
a valid address returned by the DMA API on some platforms, which would cause
this check to falsely treat a successful allocation as a failure. Should it
check if (!cxt->cxt_ctl) instead?

>  	if (!cxt)
>  		return -ENOMEM;
>  
> +	sq = cxt->sq;
> +	/* SDXI 1.0 4.1.8.4.b: Set CXT_STS.state to CXTV_RUN. */
> +	sq->cxt_sts->state = FIELD_PREP(SDXI_CXT_STS_STATE, CXTV_RUN);
>  	cxt->id = SDXI_ADMIN_CXT_ID;
>  	cxt->db = sdxi->dbs + cxt->id * sdxi->db_stride;
>  
> +	err = sdxi_publish_cxt(cxt);
> +	if (err)
> +		return err;
> +
>  	sdxi->admin_cxt = no_free_ptr(cxt);
>  
>  	return devm_add_action_or_reset(sdxi_to_dev(sdxi), free_admin_cxt, sdxi);

[Severity: High]
When an administrator unbinds the driver via sysfs or unloads the module, the
devres teardown path calls free_admin_cxt(). This ultimately calls
sdxi_free_cxt() which frees the DMA memory back to the kernel.

Since sdxi_publish_cxt() now writes the VL=1 bit and makes the memory visible
to the hardware, does the driver need to clear this bit in the L1 table entry
and stop the hardware before freeing the memory?

The driver also lacks a .remove callback in sdxi_driver (in
drivers/dma/sdxi/pci.c) to safely stop the PCI device and its DMA operations
before devres cleanup begins.

Will the active hardware continue to fetch descriptors and write statuses to
the now-freed memory pages, causing a DMA use-after-free and potential kernel
memory corruption?

>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260410-sdxi-base-v1-0-1d184cb5c60a@amd.com?part=8

  parent reply	other threads:[~2026-08-14  0:09 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 13:07 [PATCH 00/23] dmaengine: Smart Data Accelerator Interface (SDXI) basic support Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 01/23] PCI: Add SNIA SDXI accelerator sub-class Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 02/23] MAINTAINERS: Add entry for SDXI driver Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 03/23] dmaengine: sdxi: Add PCI initialization Nathan Lynch via B4 Relay
2026-04-20  6:36   ` Frank Li
2026-04-20 15:29     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 04/23] dmaengine: sdxi: Feature discovery and initial configuration Nathan Lynch via B4 Relay
2026-04-20  6:51   ` Frank Li
2026-04-20 19:31     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 05/23] dmaengine: sdxi: Configure context tables Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 06/23] dmaengine: sdxi: Allocate DMA pools Nathan Lynch via B4 Relay
2026-04-20  7:03   ` Frank Li
2026-04-20 22:16     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 07/23] dmaengine: sdxi: Allocate administrative context Nathan Lynch via B4 Relay
2026-04-20  7:11   ` Frank Li
2026-04-10 13:07 ` [PATCH 08/23] dmaengine: sdxi: Install " Nathan Lynch via B4 Relay
2026-04-20  7:16   ` Frank Li
2026-08-14  0:09   ` sashiko-bot [this message]
2026-04-10 13:07 ` [PATCH 09/23] dmaengine: sdxi: Start functions on probe, stop on remove Nathan Lynch via B4 Relay
2026-04-20  7:18   ` Frank Li
2026-04-10 13:07 ` [PATCH 10/23] dmaengine: sdxi: Complete administrative context jump start Nathan Lynch via B4 Relay
2026-04-20  7:33   ` Frank Li
2026-04-10 13:07 ` [PATCH 11/23] dmaengine: sdxi: Add client context alloc and release APIs Nathan Lynch via B4 Relay
2026-04-20  8:19   ` Frank Li
2026-05-11 17:55     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 12/23] dmaengine: sdxi: Add descriptor ring management Nathan Lynch via B4 Relay
2026-04-20  8:32   ` Frank Li
2026-04-20 22:42     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 13/23] dmaengine: sdxi: Add unit tests for descriptor ring reservations Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 14/23] dmaengine: sdxi: Attach descriptor ring state to contexts Nathan Lynch via B4 Relay
2026-04-20  8:34   ` Frank Li
2026-04-10 13:07 ` [PATCH 15/23] dmaengine: sdxi: Per-context access key (AKey) table entry allocator Nathan Lynch via B4 Relay
2026-04-20  8:39   ` Frank Li
2026-04-10 13:07 ` [PATCH 16/23] dmaengine: sdxi: Generic descriptor manipulation helpers Nathan Lynch via B4 Relay
2026-04-20  8:40   ` Frank Li
2026-04-10 13:07 ` [PATCH 17/23] dmaengine: sdxi: Add completion status block API Nathan Lynch via B4 Relay
2026-04-20  8:44   ` Frank Li
2026-04-10 13:07 ` [PATCH 18/23] dmaengine: sdxi: Encode context start, stop, and sync descriptors Nathan Lynch via B4 Relay
2026-04-20  8:48   ` Frank Li
2026-04-10 13:07 ` [PATCH 19/23] dmaengine: sdxi: Provide context start and stop APIs Nathan Lynch via B4 Relay
2026-04-20  8:50   ` Frank Li
2026-04-21 19:54     ` Lynch, Nathan
2026-04-10 13:07 ` [PATCH 20/23] dmaengine: sdxi: Encode nop, copy, and interrupt descriptors Nathan Lynch via B4 Relay
2026-04-20  8:52   ` Frank Li
2026-04-10 13:07 ` [PATCH 21/23] dmaengine: sdxi: Add unit tests for descriptor encoding Nathan Lynch via B4 Relay
2026-04-10 13:07 ` [PATCH 22/23] dmaengine: sdxi: MSI/MSI-X vector allocation and mapping Nathan Lynch via B4 Relay
2026-04-20  8:54   ` Frank Li
2026-04-10 13:07 ` [PATCH 23/23] dmaengine: sdxi: Add DMA engine provider Nathan Lynch via B4 Relay
2026-04-20  9:08   ` Frank Li
2026-04-21 20:04     ` Lynch, Nathan

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=20260814000950.C73141F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=devnull+nathan.lynch.amd.com@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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