From: Frank Li <Frank.li@oss.nxp.com>
To: Daniel Byrne <daniel1.byrne@intel.com>
Cc: Vinod Koul <vkoul@kernel.org>,
dmaengine@vger.kernel.org,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
Fenghua Yu <fenghuay@nvidia.com>, Dan Williams <djbw@kernel.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup
Date: Thu, 3 Dec 2026 11:50:10 -0600 [thread overview]
Message-ID: <axGr0kJbfS8v3uIV@SMW015318> (raw)
In-Reply-To: <20261130194721.1900266-9-daniel1.byrne@intel.com>
On Mon, Nov 30, 2026 at 11:47:19AM -0800, Daniel Byrne wrote:
> idxd_device_evl_setup() allocates the event log and its bitmap by
> evl_size(), which it reads before it takes the event log lock, and then
> gives the device evl->size, read again under the lock. event_log_size
> can be written until the device is enabled, which comes after the
> setup, and the store takes no lock. A write between the two reads gives
> the device a log larger than the memory behind it, which it writes past
> once it has logged more entries than the old size holds. A write after
> the setup changes the size by which the log is walked.
>
> Take the lock before the size is read and hold it to the end of the
> setup, write the size under the same lock, and refuse the write with
> -EBUSY once there is a log. The log keeps the size it was allocated
> with until idxd_device_evl_free() takes it away.
>
> Fixes: 244da66cda35 ("dmaengine: idxd: setup event log configuration")
> Cc: stable@vger.kernel.org # 6.4+
> Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> New in v2.
>
> drivers/dma/idxd/device.c | 8 +++++++-
> drivers/dma/idxd/sysfs.c | 10 ++++++++++
> 2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
> index 83665f7d8d6f..d1a8ccc14bb4 100644
> --- a/drivers/dma/idxd/device.c
> +++ b/drivers/dma/idxd/device.c
> @@ -773,6 +773,12 @@ static int idxd_device_evl_setup(struct idxd_device *idxd)
> if (!evl)
> return 0;
>
> + /*
> + * event_log_size_store() writes the size under this lock, and only
> + * while there is no log. So the size read here is the one the log
> + * is allocated by and the one the device is given.
> + */
> + mutex_lock(&evl->lock);
> size = evl_size(idxd);
>
> bmap = bitmap_zalloc(size, GFP_KERNEL);
> @@ -791,7 +797,6 @@ static int idxd_device_evl_setup(struct idxd_device *idxd)
> goto err_alloc;
> }
>
> - mutex_lock(&evl->lock);
> evl->log = addr;
> evl->dma = dma_addr;
> evl->log_size = size;
> @@ -818,6 +823,7 @@ static int idxd_device_evl_setup(struct idxd_device *idxd)
> err_alloc:
> bitmap_free(bmap);
> err_bmap:
> + mutex_unlock(&evl->lock);
> return rc;
> }
>
> diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
> index 6d251095c350..bcd74b1d948e 100644
> --- a/drivers/dma/idxd/sysfs.c
> +++ b/drivers/dma/idxd/sysfs.c
> @@ -1708,7 +1708,17 @@ static ssize_t event_log_size_store(struct device *dev,
> (val * evl_ent_size(idxd) > ULONG_MAX - idxd->evl->dma))
> return -EINVAL;
>
> + /*
> + * idxd_device_evl_setup() reads the size under this lock. Once a
> + * log is set up it keeps the size it was allocated with.
> + */
> + mutex_lock(&idxd->evl->lock);
> + if (idxd->evl->log) {
> + mutex_unlock(&idxd->evl->lock);
> + return -EBUSY;
> + }
> idxd->evl->size = val;
> + mutex_unlock(&idxd->evl->lock);
> return count;
> }
> static DEVICE_ATTR_RW(event_log_size);
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-12-03 17:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261130194721.1900266-1-daniel1.byrne@intel.com>
2026-11-30 19:47 ` [PATCH v2 01/10] dmaengine: idxd: don't queue EVL fault work for kernel WQs Daniel Byrne
2026-12-03 17:47 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 02/10] dmaengine: idxd: detach the user fault workqueue under the event log lock Daniel Byrne
2026-12-03 17:47 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 03/10] dmaengine: idxd: free the event log fault item when no record is copied Daniel Byrne
2026-12-03 17:47 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 04/10] dmaengine: idxd: refuse a memcpy longer than the WQ max transfer size Daniel Byrne
2026-12-03 17:48 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 05/10] dmaengine: idxd: take an mm_users reference for the completion record copy Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 06/10] dmaengine: idxd: read GENCFG before clearing the event log enable Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 07/10] dmaengine: idxd: don't sleep for a descriptor in the prep callbacks Daniel Byrne
2026-12-03 17:49 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup Daniel Byrne
2026-12-03 17:50 ` Frank Li [this message]
2026-11-30 19:47 ` [PATCH v2 09/10] dmaengine: idxd: free the queue interrupt when the percpu_ref setup fails Daniel Byrne
2026-12-03 17:44 ` Frank Li
2026-11-30 19:47 ` [PATCH v2 10/10] dmaengine: idxd: test a queue under its lock before quiescing it Daniel Byrne
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=axGr0kJbfS8v3uIV@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=daniel1.byrne@intel.com \
--cc=dave.jiang@intel.com \
--cc=djbw@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=fenghuay@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vinicius.gomes@intel.com \
--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