From: sashiko-bot@kernel.org
To: "Daniel Byrne" <daniel1.byrne@intel.com>,
"Shivank Garg" <shivankg@amd.com>,
"Ravi Jonnalagadda" <ravis.opensrc@gmail.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>, "Zi Yan" <ziy@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>,
"Rakie Kim" <rakie.kim@sk.com>,
"Byungchul Park" <byungchul@sk.com>,
"Gregory Price" <gourry@gourry.net>,
"Ying Huang" <ying.huang@linux.alibaba.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Karim Manaouil" <kmanaouil.dev@gmail.com>,
"Frank van der Linden" <fvdl@google.com>,
"Teja Vojjala" <tejavojjala@google.com>,
"Pravin Tamkhane" <pravintamkhane@google.com>,
"Kinsey Ho" <kinseyho@google.com>, "Wei Xu" <weixugc@google.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Vinod Koul" <vkoul@kernel.org>,
"Bharata B Rao" <bharata@amd.com>,
"SeongJae Park" <sj@kernel.org>,
"David Rientjes" <rientjes@google.com>,
"Xuezheng Chu" <xuezhengchu@huawei.com>,
"Yiannis Nikolakopoulos" <yiannis@zptcorp.com>,
"Dave Hansen" <dave.hansen@intel.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"John Hubbard" <jhubbard@nvidia.com>,
"Peter Xu" <peterx@redhat.com>, "Rik van Riel" <riel@surriel.com>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Tejun Heo" <tj@kernel.org>, "Fan Ni" <nifan.cxl@gmail.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
"Nathan Lynch" <nathan.lynch@amd.com>,
"Frank Li" <Frank.li@nxp.com>, "Dan Williams" <djbw@kernel.org>,
linux-mm@kvack.org, "Mike Day" <michael.day@amd.com>,
dmaengine@vger.kernel.org,
"Vinicius Costa Gomes" <vinicius.gomes@intel.com>,
"Frank Li" <Frank.Li@kernel.org>,
"Dave Jiang" <dave.jiang@intel.com>
Subject: Re: [RFC PATCH 10/10] drivers/migrate_offload: make dcbm correct on shared, out-of-order engines
Date: Wed, 02 Dec 2026 14:19:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-245945@kernel.org> (raw)
In-Reply-To: <20261201141259.2124188-11-daniel1.byrne@intel.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drivers/migrate_offload: UAF on work->waitq in
dma_completion_callback()
- [Medium] drivers/migrate_offload: deadlock in dma_work_throttle() on
bad max_inflight
- [Medium] drivers/migrate_offload: OOB write in submit_sg_transfers()
on bad sg_elems
- [Medium] drivers/migrate_offload: UAF and channel leak on module param
parse failure
- [Medium] drivers/migrate_offload: folios_copy_dma() stalls claimed
channels on throttle
--
commit 3a2193077cc84a75579aba88a063d111f5f2b975
Author: Daniel Byrne <daniel1.byrne@intel.com>
drivers/migrate_offload: make dcbm correct on shared, out-of-order engines
This commit reworks DCBM to track completion per descriptor, pool and
group DMA channels by NUMA node, map folios individually with optional
DMA_MEMCPY_SG batching, and throttle in-flight descriptors per channel.
Link: https://lore.kernel.org/linux-mm/20260619160725.lfcxrbj5go67qy6u@wrangler/
> diff --git a/drivers/migrate_offload/dcbm/dcbm.c b/drivers/migrate_offload/dcbm/dcbm.c
> index 3df9232586ff2..03785a8221610 100644
> --- a/drivers/migrate_offload/dcbm/dcbm.c
> +++ b/drivers/migrate_offload/dcbm/dcbm.c
[ ... ]
> @@ -9,127 +9,290 @@
> +static void dma_completion_callback(void *data,
> + const struct dmaengine_result *result)
> {
> struct dma_work *work = data;
>
> - if (atomic_dec_and_test(&work->pending))
> - complete(&work->done);
> + if (!result || result->result != DMA_TRANS_NOERROR)
> + atomic_set(&work->error, -EIO);
> +
> + atomic_dec(&work->pending);
> + wake_up(&work->waitq);
> }
>
> -static int setup_sg_tables(struct dma_work *work, struct list_head **src_pos,
> - struct list_head **dst_pos, int nr)
> +static void dma_work_init(struct dma_work *work)
> {
> - struct scatterlist *sg_src, *sg_dst;
> - struct device *dev;
> - int i, ret;
> + init_waitqueue_head(&work->waitq);
> + /* Submission reference, dropped by dma_work_done_submitting(). */
> + atomic_set(&work->pending, 1);
> + atomic_set(&work->error, 0);
> +}
>
> - work->src_sgt = kmalloc_obj(*work->src_sgt, GFP_KERNEL);
> - if (!work->src_sgt)
> - return -ENOMEM;
> - work->dst_sgt = kmalloc_obj(*work->dst_sgt, GFP_KERNEL);
> - if (!work->dst_sgt) {
> - ret = -ENOMEM;
> - goto err_free_src;
> +static void dma_work_done_submitting(struct dma_work *work)
> +{
> + atomic_dec(&work->pending);
> + wake_up(&work->waitq);
> +}
> +
> +/*
> + * Throttle submission to max_inflight descriptors per channel, so a
> + * slice never outruns the channel's descriptor pool.
> + */
> +static void dma_work_throttle(struct dma_work *work)
> +{
> + unsigned int limit = READ_ONCE(max_inflight) + 1;
> +
> + wait_event(work->waitq, atomic_read(&work->pending) < limit);
> +}
[Severity: High]
Can dma_completion_callback() access work->waitq after cleanup_dma_work()
has freed works?
Unlike complete(), which holds the waitqueue lock across marking the
completion done and waking waiters, dma_completion_callback() decrements
work->pending before acquiring work->waitq.lock in wake_up():
CPU0 CPU1
folios_copy_dma()
... dma_completion_callback()
atomic_dec(&work->pending)
dma_work_wait()
wait_event(work->waitq,
!atomic_read(&work->pending))
cleanup_dma_work()
kfree(works)
wake_up(&work->waitq)
spin_lock_irqsave(&work->waitq.lock)
<-- use-after-free
[Severity: Medium]
Can dma_work_throttle() hang forever if max_inflight is set to 0 or
UINT_MAX?
max_inflight is exposed as an unvalidated uint module parameter. Because
dma_work_init() sets work->pending to 1 for the submitter reference until
submit_dma_transfers() returns, setting max_inflight to 0 makes limit 1
before any descriptor is submitted, and setting it to UINT_MAX wraps
limit to 0. In either case atomic_read(&work->pending) < limit is false
with no descriptors in flight to wake work->waitq, deadlocking the
migrating task with the folio locks and channel mutexes held.
[ ... ]
> @@ -138,71 +301,121 @@ static void cleanup_dma_work(struct dma_work *works, int actual_channels)
> +static int submit_sg_transfers(struct dma_work *work, unsigned long flags)
> +{
> + struct scatterlist *src_sg, *dst_sg;
> + unsigned int elems = READ_ONCE(sg_elems);
> + unsigned int done = 0;
> + int ret = 0;
> +
> + src_sg = kmalloc_array(2 * elems, sizeof(*src_sg), GFP_KERNEL);
> + if (!src_sg)
> + return -ENOMEM;
> + dst_sg = src_sg + elems;
> +
> + while (done < work->nr_copies) {
> + unsigned int n = min(elems, work->nr_copies - done);
> + struct dma_async_tx_descriptor *tx;
> + unsigned int i;
> +
> + sg_init_table(src_sg, n);
> + sg_init_table(dst_sg, n);
[Severity: Medium]
Can an invalid sg_elems module parameter cause an out-of-bounds write in
submit_sg_transfers()?
sg_elems is also an unvalidated uint module parameter. If sg_elems is 0,
kmalloc_array(0, ...) returns ZERO_SIZE_PTR, n is 0, and
sg_init_table(src_sg, 0) writes to src_sg[-1]. If sg_elems is at least
0x80000000, 2 * elems overflows in 32-bit unsigned arithmetic before
kmalloc_array() widens it to size_t, allocating a small buffer that
sg_init_table() and the loop below overrun.
[ ... ]
> @@ -256,34 +470,27 @@ static int folios_copy_dma(struct list_head *dst_list,
> for (i = 0; i < actual_channels; i++) {
> - if (!works[i].mapped)
> + if (!works[i].copies)
> continue;
> ret = submit_dma_transfers(&works[i]);
> + dma_work_done_submitting(&works[i]);
> + works[i].submitted = true;
> if (ret)
> - goto err_cleanup;
> + goto err_wait;
> }
[Severity: Medium]
Does calling submit_dma_transfers() sequentially across works[] stall the
remaining claimed channels whenever a slice exceeds max_inflight
descriptors?
folios_copy_dma() locks all claimed channels up front, but
submit_dma_transfers(&works[i]) blocks in dma_work_throttle() once
max_inflight descriptors are queued on channel i. On a 512-folio batch
split across 4 channels without DMA_MEMCPY_SG, channel 0 must complete 96
of its 128 descriptors in hardware before any descriptors are submitted
to channels 1..3, while channels 1..3 sit idle with their locks held and
cause concurrent batches to fail dcbm_claim_channels() with -EBUSY.
[ ... ]
> @@ -330,15 +594,23 @@ static int offloading_param_set(const char *val, const struct kernel_param *kp)
> return 0;
> }
> if (enable) {
> + ret = dcbm_get_channels();
> + if (ret) {
> + mutex_unlock(&dcbm_mutex);
> + return ret;
> + }
> ret = migrate_offload_register(&dma_migrator,
> READ_ONCE(dcbm_reason_mask));
> if (ret) {
> + dcbm_put_channels();
> mutex_unlock(&dcbm_mutex);
> return ret;
> }
> WRITE_ONCE(offloading_enabled, true);
> } else {
> migrate_offload_unregister(&dma_migrator);
> + /* No batch is in flight past unregister; channels are idle. */
> + dcbm_put_channels();
> WRITE_ONCE(offloading_enabled, false);
> }
> mutex_unlock(&dcbm_mutex);
> @@ -370,6 +642,10 @@ static int nr_dma_chan_param_set(const char *val, const struct kernel_param *kp)
> return -EINVAL;
>
> mutex_lock(&dcbm_mutex);
> + if (offloading_enabled) {
> + mutex_unlock(&dcbm_mutex);
> + return -EBUSY;
> + }
> WRITE_ONCE(nr_dma_channels, new_val);
> mutex_unlock(&dcbm_mutex);
> return 0;
[Severity: Medium]
What happens if the module is loaded with "offloading=1 nr_dma_chan=4" on
the command line?
parse_args() runs module parameter setters in command-line order before
dcbm_init(). offloading_param_set() acquires a channel and registers
dma_migrator, and then nr_dma_chan_param_set() sees offloading_enabled and
returns -EBUSY. load_module() then aborts and frees the module without
running dcbm_exit(), leaking the DMA channel and leaving dma_migrator
registered in freed module memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201141259.2124188-1-daniel1.byrne@intel.com?part=10
next prev parent reply other threads:[~2026-12-02 14:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 14:12 [RFC PATCH 00/10] mm/migrate: dcbm for Intel DSA, on top of the batch copy offload RFC v6 Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 01/10] mm/migrate: skip data copy for already-copied folios Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 02/10] mm/migrate: add batch-copy path in migrate_pages_batch Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 03/10] mm/migrate: add copy offload registration infrastructure Daniel Byrne
2026-12-02 14:19 ` sashiko-bot
2026-12-01 14:12 ` [RFC PATCH 04/10] drivers/migrate_offload: add DMA batch copy driver (dcbm) Daniel Byrne
2026-12-02 14:19 ` sashiko-bot
2026-12-01 14:12 ` [RFC PATCH 05/10] mm/migrate: give hugetlb its own bit for the content-copied marker Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 06/10] mm/migrate: keep folios with private data off the batch copy Daniel Byrne
2026-12-02 14:19 ` sashiko-bot
2026-12-01 14:12 ` [RFC PATCH 07/10] mm/migrate: no filesystem reclaim under the batch's folio locks Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 08/10] dmaengine: reintroduce DMA_MEMCPY_SG Daniel Byrne
2026-12-01 19:51 ` Frank Li
2026-12-01 14:12 ` [RFC PATCH 09/10] dmaengine: add DMA_PREP_CACHE_CONTROL Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 10/10] drivers/migrate_offload: make dcbm correct on shared, out-of-order engines Daniel Byrne
2026-12-02 14:19 ` sashiko-bot [this message]
2026-12-01 15:24 ` [RFC PATCH 00/10] mm/migrate: dcbm for Intel DSA, on top of the batch copy offload RFC v6 Dave Hansen
2026-12-01 16:05 ` Garg, Shivank
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-245945@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=Frank.li@nxp.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@kernel.org \
--cc=apopple@nvidia.com \
--cc=bharata@amd.com \
--cc=byungchul@sk.com \
--cc=daniel1.byrne@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=david@kernel.org \
--cc=djbw@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=fvdl@google.com \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=jhubbard@nvidia.com \
--cc=jic23@kernel.org \
--cc=joshua.hahnjy@gmail.com \
--cc=kinseyho@google.com \
--cc=kmanaouil.dev@gmail.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=michael.day@amd.com \
--cc=nathan.lynch@amd.com \
--cc=nifan.cxl@gmail.com \
--cc=peterx@redhat.com \
--cc=pravintamkhane@google.com \
--cc=rakie.kim@sk.com \
--cc=ravis.opensrc@gmail.com \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shivankg@amd.com \
--cc=sj@kernel.org \
--cc=surenb@google.com \
--cc=tejavojjala@google.com \
--cc=tj@kernel.org \
--cc=vbabka@kernel.org \
--cc=vinicius.gomes@intel.com \
--cc=vkoul@kernel.org \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=xuezhengchu@huawei.com \
--cc=yiannis@zptcorp.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/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