FAILED: patch "[PATCH] iommufd: Move vevent memory allocation outside spinlock" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 47443565d10c51366c9382dbc8597cd6c460b8a2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071621-gentleman-famine-b64d@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 47443565d10c51366c9382dbc8597cd6c460b8a2 Mon Sep 17 00:00:00 2001
From: Nicolin Chen <[email protected]>
Date: Thu, 21 May 2026 17:36:33 -0700
Subject: [PATCH] iommufd: Move vevent memory allocation outside spinlock
The veventq memory allocation happens inside the spinlock. Given its depth is decided by the user space, this leaves a vulnerability, where userspace can allocate large queues to exhaust atomic memory reserves.
Move the allocation outside the spinlock and use GFP_NOWAIT, which can fail fast under memory pressure without dipping into the GFP_ATOMIC reserves or direct-reclaiming from the threaded IRQ handler. On allocation failure, queue the lost_events_header (so userspace learns of the drop) and return -ENOMEM so the caller learns of the kernel-side memory pressure.
This is intentionally distinct from the queue-overflow path, which also queues the lost_events_header but returns 0: a full queue is an expected userspace-pacing condition rather than a kernel error.
A subsequent change will cap the upper bound of the veventq_depth.
drivers/iommu/iommufd/driver.c +8 -5
@@ -149,15 +149,18 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu, goto out_unlock_veventqs; } -spin_lock (&veventq->common.lock); -if (veventq->num_events == veventq->depth) { +/* Pre-allocate to avoid GFP_ATOMIC; use GFP_NOWAIT to avoid sleeping */ + vevent =kzalloc_flex (*vevent, event_data, data_len,GFP_NOWAIT ); +if (!vevent) { +spin_lock (&veventq->common.lock); vevent = &veventq->lost_events_header; + rc = -ENOMEM ; goto out_set_header; } - vevent =kzalloc_flex (*vevent, event_data, data_len,GFP_ATOMIC ); -if (!vevent) { - rc = -ENOMEM ; +spin_lock (&veventq->common.lock); +if (veventq->num_events == veventq->depth) { +kfree (vevent); vevent = &veventq->lost_events_header; goto out_set_header; }
Sasha Levin
maintainerPATCH 1/1 iommufd: Move vevent memory allocation outside spinlock
From: Nicolin Chen <[email protected]>
[ Upstream commit 47443565d10c51366c9382dbc8597cd6c460b8a2 ]
The veventq memory allocation happens inside the spinlock. Given its depth is decided by the user space, this leaves a vulnerability, where userspace can allocate large queues to exhaust atomic memory reserves.
Move the allocation outside the spinlock and use GFP_NOWAIT, which can fail fast under memory pressure without dipping into the GFP_ATOMIC reserves or direct-reclaiming from the threaded IRQ handler. On allocation failure, queue the lost_events_header (so userspace learns of the drop) and return -ENOMEM so the caller learns of the kernel-side memory pressure.
This is intentionally distinct from the queue-overflow path, which also queues the lost_events_header but returns 0: a full queue is an expected userspace-pacing condition rather than a kernel error.
A subsequent change will cap the upper bound of the veventq_depth.
--- drivers/iommu/iommufd/driver.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/iommu/iommufd/driver.c +8 -5
@@ -149,15 +149,18 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu, goto out_unlock_veventqs; } -spin_lock (&veventq->common.lock); -if (veventq->num_events == veventq->depth) { +/* Pre-allocate to avoid GFP_ATOMIC; use GFP_NOWAIT to avoid sleeping */ + vevent =kzalloc_flex (*vevent, event_data, data_len,GFP_NOWAIT ); +if (!vevent) { +spin_lock (&veventq->common.lock); vevent = &veventq->lost_events_header; + rc = -ENOMEM ; goto out_set_header; } - vevent =kzalloc (struct_size (vevent, event_data, data_len),GFP_ATOMIC ); -if (!vevent) { - rc = -ENOMEM ; +spin_lock (&veventq->common.lock); +if (veventq->num_events == veventq->depth) { +kfree (vevent); vevent = &veventq->lost_events_header; goto out_set_header; }
Signature · 1 line
2.53.0