DMA Engine development
 help / color / mirror / Atom feed
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 04/10] drivers/migrate_offload: add DMA batch copy driver (dcbm)
Date: Wed, 02 Dec 2026 14:19:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-245939@kernel.org> (raw)
In-Reply-To: <20261201141259.2124188-5-daniel1.byrne@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drivers/migrate_offload: premature registration in
  offloading_param_set()
--

commit 756c8331350631160d2eb5687889ba87ecc81d24
Author: Shivank Garg <shivankg@amd.com>

drivers/migrate_offload: add DMA batch copy driver (dcbm)

This commit adds a DMAEngine-based batch folio copy driver (dcbm) that
plugs into the page migration copy-offload infrastructure, controlled via
module parameters.

> diff --git a/drivers/migrate_offload/dcbm/dcbm.c b/drivers/migrate_offload/dcbm/dcbm.c
> new file mode 100644
> index 0000000000000..bacbcc6891711
> --- /dev/null
> +++ b/drivers/migrate_offload/dcbm/dcbm.c
[ ... ]
> +static const struct migrator dma_migrator = {
> +	.name = "DCBM",
> +	.offload_copy = folios_copy_dma,
> +	.owner = THIS_MODULE,
> +};
> +
> +static unsigned long dcbm_reason_mask = MIGRATE_OFFLOAD_REASONS_ALLOWED;
> +
> +/* offloading: enable/disable DMA migration offload */
> +static int offloading_param_set(const char *val, const struct kernel_param *kp)
> +{
> +	bool enable;
> +	int ret;
> +
> +	ret = kstrtobool(val, &enable);
> +	if (ret)
> +		return ret;
> +
> +	mutex_lock(&dcbm_mutex);
> +	if (enable == offloading_enabled) {
> +		mutex_unlock(&dcbm_mutex);
> +		return 0;
> +	}
> +	if (enable) {
> +		ret = migrate_offload_register(&dma_migrator,
> +					       READ_ONCE(dcbm_reason_mask));
> +		if (ret) {
> +			mutex_unlock(&dcbm_mutex);
> +			return ret;
> +		}
> +		WRITE_ONCE(offloading_enabled, true);
> +	} else {
> +		migrate_offload_unregister(&dma_migrator);
> +		WRITE_ONCE(offloading_enabled, false);
> +	}
> +	mutex_unlock(&dcbm_mutex);
> +	return 0;
> +}
> +
> +static int offloading_param_get(char *buffer, const struct kernel_param *kp)
> +{
> +	return sysfs_emit(buffer, "%d\n", READ_ONCE(offloading_enabled));
> +}
> +
> +static const struct kernel_param_ops offloading_param_ops = {
> +	.set = offloading_param_set,
> +	.get = offloading_param_get,
> +};
> +module_param_cb(offloading, &offloading_param_ops, NULL, 0644);
> +MODULE_PARM_DESC(offloading, "Enable DMA migration offload (0/1)");
[ ... ]
> +/* reason_mask: set of MR_* reasons this migrator handles */
> +static int reason_mask_param_set(const char *val, const struct kernel_param *kp)
> +{
> +	unsigned long mask;
> +	int ret;
> +
> +	ret = migrate_offload_reason_mask_parse(val, &mask);
> +	if (ret)
> +		return ret;
> +
> +	mutex_lock(&dcbm_mutex);
> +	WRITE_ONCE(dcbm_reason_mask, mask);
> +	if (offloading_enabled)
> +		migrate_offload_set_reason_mask(&dma_migrator, mask);
> +	mutex_unlock(&dcbm_mutex);
> +	return 0;
> +}

[Severity: High]
Can registering dma_migrator directly from offloading_param_set() leave a
dangling pointer to dma_migrator and folios_copy_dma() if module loading
fails?

During load_module(), parse_args() invokes offloading_param_set() while
the module is still in MODULE_STATE_COMING, before remaining module
parameters are validated and before mod_sysfs_setup() or dcbm_init() run.
If "offloading=1" is followed by an invalid parameter (such as
"nr_dma_chan=99"), load_module() aborts and frees the module memory
without calling dcbm_exit(), causing a use-after-free on the next
offloaded page migration.

When CONFIG_DCBM_DMA=y, module_param_cb() also runs at level -1 during
start_kernel() -> parse_args() with interrupts disabled and before
mm_core_init() initializes the slab allocator, so passing
"dcbm.reason_mask=compaction,demotion" on the kernel command line calls
migrate_offload_reason_mask_parse() -> kstrdup(..., GFP_KERNEL) before
kmalloc caches exist, and "dcbm.offloading=1" calls static_call_update()
before poking_init().

In addition, because dma_migrator sets .owner = THIS_MODULE, calling
migrate_offload_register() from within dcbm pins its own module reference
count via try_module_get(THIS_MODULE), so rmmod fails with -EBUSY while
offloading is enabled and the unregister path in dcbm_exit() is never
reached.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201141259.2124188-1-daniel1.byrne@intel.com?part=4

  reply	other threads:[~2026-12-02 14:19 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 [this message]
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
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-245939@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