From: Nathan Lynch <nathan.lynch@amd.com>
To: <sashiko-reviews@lists.linux.dev>,
Nathan Lynch via B4 Relay
<devnull+nathan.lynch.amd.com@kernel.org>
Cc: <Frank.Li@kernel.org>, <dmaengine@vger.kernel.org>,
<linux-pci@vger.kernel.org>, <vkoul@kernel.org>
Subject: Re: [PATCH v2 06/23] dmaengine: sdxi: Allocate DMA pools
Date: Tue, 26 May 2026 19:05:00 -0500 [thread overview]
Message-ID: <877bop90pf.fsf@amd.com> (raw)
In-Reply-To: <20260513013053.5F1E1C2BCB0@smtp.kernel.org>
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Unnecessary use of `__packed` attribute on naturally aligned DMA structures reduces their assumed alignment to 1 byte, risking torn reads/writes.
> - [Medium] `cxt_ctl_pool` has a hardcoded alignment of 64 bytes instead of `max(size, SMP_CACHE_BYTES)`, leading to potential cacheline sharing.
> --
>
> commit 12aa7b8ec291c34d27a87b91722b70b67d211aa3
> Author: Nathan Lynch <nathan.lynch@amd.com>
>
> dmaengine: sdxi: Allocate DMA pools
>
> This commit introduces C structures for SDXI context control, context status,
> and completion status blocks. It also creates a DMA pool for each of these
> objects as well as write indexes, aiming to align them to avoid cacheline
> sharing.
>
>> diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
>> index 6a2204ff7fdee..851e73597c22b 100644
>> --- a/drivers/dma/sdxi/device.c
>> +++ b/drivers/dma/sdxi/device.c
>
> [ ... ]
>
>> @@ -211,6 +214,43 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)
>> return 0;
>> }
>>
>> +static int sdxi_device_init(struct sdxi_dev *sdxi)
>> +{
>> + struct device *dev = sdxi->dev;
>> + size_t size, align;
>> + int err;
>> +
>> + size = sizeof(__le64);
>> + align = max(size, SMP_CACHE_BYTES);
>> + sdxi->write_index_pool = dmam_pool_create("Write_Index", dev, size,
>> + align, 0);
>> + if (!sdxi->write_index_pool)
>> + return -ENOMEM;
>> +
>> + size = sizeof(struct sdxi_cxt_sts);
>> + align = max(size, SMP_CACHE_BYTES);
>> + sdxi->cxt_sts_pool = dmam_pool_create("CXT_STS", dev, size, align, 0);
>> + if (!sdxi->cxt_sts_pool)
>> + return -ENOMEM;
>> +
>> + size = align = sizeof(struct sdxi_cxt_ctl);
>> + sdxi->cxt_ctl_pool = dmam_pool_create("CXT_CTL", dev, size, align, 0);
>
> The commit message states that frequently-updated objects are aligned to avoid
> cacheline sharing. Does hardcoding the alignment to sizeof(struct sdxi_cxt_ctl)
> risk cacheline sharing on architectures where SMP_CACHE_BYTES is 128?
>
> Should this use max(size, SMP_CACHE_BYTES) like the other pools?
No, sdxi_cxt_ctl is not one of the control structures we expect to be
frequently updated, but I suppose this could be made more clear in the
commit message or comments.
>
>> + if (!sdxi->cxt_ctl_pool)
>> + return -ENOMEM;
>
> [ ... ]
>
>> diff --git a/drivers/dma/sdxi/hw.h b/drivers/dma/sdxi/hw.h
>> index df520ca7792bf..846c671c423f5 100644
>> --- a/drivers/dma/sdxi/hw.h
>> +++ b/drivers/dma/sdxi/hw.h
>
> [ ... ]
>
>> +/* SDXI 1.0 Table 3-4: Context Control (CXT_CTL) */
>> +struct sdxi_cxt_ctl {
>> + __le64 ds_ring_ptr;
>> + __le32 ds_ring_sz;
>> + __u8 rsvd_0[4];
>> + __le64 cxt_sts_ptr;
>> + __le64 write_index_ptr;
>> + __u8 rsvd_1[32];
>> +} __packed;
>
> These structures appear to be naturally aligned and padded properly. Does
> applying the __packed attribute without an explicit __aligned() attribute
> force the compiler to assume 1-byte alignment?
>
> Could this lead to the compiler synthesizing multiple byte-wise or narrower
> memory accesses for 32-bit or 64-bit fields when they are read or written,
> potentially causing torn reads or writes if the hardware lacks native
> unaligned access support?
Valid -- I'll add the aligned attributes throughout (I want to continue
using packed to prevent inadvertent padding).
>> +static_assert(sizeof(struct sdxi_cxt_ctl) == 64);
>> +
>> +/* SDXI 1.0 Table 3-5: Context Status (CXT_STS) */
>> +struct sdxi_cxt_sts {
>> + __u8 state;
>> + __u8 misc0;
>> + __u8 rsvd_0[6];
>> + __le64 read_index;
>> +} __packed;
>> +static_assert(sizeof(struct sdxi_cxt_sts) == 16);
>> +
>> +/* SDXI 1.0 Table 6-4: CST_BLK (Completion Status Block) */
>> +struct sdxi_cst_blk {
>> + __le64 signal;
>> + __le32 flags;
>> + __u8 rsvd_0[20];
>> +} __packed;
>> +static_assert(sizeof(struct sdxi_cst_blk) == 32);
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260511-sdxi-base-v2-0-889cfed17e3f@amd.com?part=6
next prev parent reply other threads:[~2026-05-27 0:05 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 19:16 [PATCH v2 00/23] dmaengine: Smart Data Accelerator Interface (SDXI) basic support Nathan Lynch via B4 Relay
2026-05-11 19:16 ` [PATCH v2 01/23] PCI: Add SNIA SDXI accelerator sub-class Nathan Lynch via B4 Relay
2026-05-11 20:48 ` Frank Li
2026-05-12 23:50 ` sashiko-bot
2026-05-26 23:44 ` Nathan Lynch
2026-05-11 19:16 ` [PATCH v2 02/23] MAINTAINERS: Add entry for SDXI driver Nathan Lynch via B4 Relay
2026-05-11 19:16 ` [PATCH v2 03/23] dmaengine: sdxi: Add PCI initialization Nathan Lynch via B4 Relay
2026-05-11 21:22 ` Frank Li
2026-05-13 0:05 ` sashiko-bot
2026-05-26 23:28 ` Nathan Lynch
2026-05-11 19:16 ` [PATCH v2 04/23] dmaengine: sdxi: Feature discovery and initial configuration Nathan Lynch via B4 Relay
2026-05-11 21:30 ` Frank Li
2026-05-13 0:33 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 05/23] dmaengine: sdxi: Configure context tables Nathan Lynch via B4 Relay
2026-05-13 1:12 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 06/23] dmaengine: sdxi: Allocate DMA pools Nathan Lynch via B4 Relay
2026-05-13 1:30 ` sashiko-bot
2026-05-27 0:05 ` Nathan Lynch [this message]
2026-05-11 19:16 ` [PATCH v2 07/23] dmaengine: sdxi: Allocate administrative context Nathan Lynch via B4 Relay
2026-05-13 2:20 ` sashiko-bot
2026-05-27 0:07 ` Nathan Lynch
2026-05-11 19:16 ` [PATCH v2 08/23] dmaengine: sdxi: Install " Nathan Lynch via B4 Relay
2026-05-13 3:17 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 09/23] dmaengine: sdxi: Start functions on probe, stop on remove Nathan Lynch via B4 Relay
2026-05-13 3:35 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 10/23] dmaengine: sdxi: Complete administrative context jump start Nathan Lynch via B4 Relay
2026-05-13 3:54 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 11/23] dmaengine: sdxi: Add client context alloc and release APIs Nathan Lynch via B4 Relay
2026-05-13 4:46 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 12/23] dmaengine: sdxi: Add descriptor ring management Nathan Lynch via B4 Relay
2026-05-13 5:21 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 13/23] dmaengine: sdxi: Add unit tests for descriptor ring reservations Nathan Lynch via B4 Relay
2026-05-13 5:48 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 14/23] dmaengine: sdxi: Attach descriptor ring state to contexts Nathan Lynch via B4 Relay
2026-05-13 19:31 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 15/23] dmaengine: sdxi: Per-context access key (AKey) table entry allocator Nathan Lynch via B4 Relay
2026-05-13 19:54 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 16/23] dmaengine: sdxi: Generic descriptor manipulation helpers Nathan Lynch via B4 Relay
2026-05-13 20:21 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 17/23] dmaengine: sdxi: Add completion status block API Nathan Lynch via B4 Relay
2026-05-13 20:38 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 18/23] dmaengine: sdxi: Encode context start, stop, and sync descriptors Nathan Lynch via B4 Relay
2026-05-11 19:16 ` [PATCH v2 19/23] dmaengine: sdxi: Provide context start and stop APIs Nathan Lynch via B4 Relay
2026-05-13 21:18 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 20/23] dmaengine: sdxi: Encode nop, copy, and interrupt descriptors Nathan Lynch via B4 Relay
2026-05-13 21:33 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 21/23] dmaengine: sdxi: Add unit tests for descriptor encoding Nathan Lynch via B4 Relay
2026-05-13 21:55 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 22/23] dmaengine: sdxi: MSI/MSI-X vector allocation and mapping Nathan Lynch via B4 Relay
2026-05-13 22:17 ` sashiko-bot
2026-05-11 19:16 ` [PATCH v2 23/23] dmaengine: sdxi: Add DMA engine provider Nathan Lynch via B4 Relay
2026-05-11 20:47 ` Frank Li
2026-05-11 22:28 ` Lynch, Nathan
2026-05-13 20:01 ` Frank Li
2026-05-13 22:57 ` 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=877bop90pf.fsf@amd.com \
--to=nathan.lynch@amd.com \
--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