Re: [PATCH v2 08/10] dmaengine: idxd: read the event log size under its lock in the setup
From: Frank Li
Date: Thu Dec 03 2026 - 12:50:23 EST
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@xxxxxxxxxxxxxxx # 6.4+
> Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
> ---
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
> 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
>