From: Willy Tarreau <w@1wt.eu>
To: Afi0 <capyenglishlite@gmail.com>
Cc: hch@lst.de, linux-kernel@vger.kernel.org, robin.murphy@arm.com
Subject: Re: [PATCH] dma: pool: fix racy refill check in dma_alloc_from_pool()
Date: Sun, 17 May 2026 10:10:41 +0200 [thread overview]
Message-ID: <agl4AVLIdIrjXFky@1wt.eu> (raw)
In-Reply-To: <CAEABq7erWVJwEa5yYi8Z042jAfPK5LdpEvDYqfX8y7OGcg4eVw@mail.gmail.com>
On Sun, May 17, 2026 at 07:43:03AM +0000, Afi0 wrote:
>
> From d5e6f7a8b9c0d5e6f7a8b9c0d5e6f7a8b9c0d5e6 Mon Sep 17 00:00:00 2001
> From: Andrii Kuchmenko <capyenglishlite@gmail.com>
> Date: Sat, 16 May 2026 12:56:00 +0000
> Subject: [PATCH] dma: pool: fix racy refill check in dma_alloc_from_pool()
>
> The availability check after gen_pool_alloc() is not synchronized with
> concurrent allocations on other CPUs:
>
> addr = gen_pool_alloc(pool, size); /* (A) alloc succeeds */
> if (!addr)
> return NULL;
> ...
> if (gen_pool_avail(pool) < atomic_pool_size) /* (B) racy read */
> schedule_work(&atomic_pool_work); /* (C) may not fire */
>
> Between (A) and (B), concurrent CPUs can drain the pool completely.
> CPU0 reads gen_pool_avail() at (B) and sees a stale non-zero value,
> decides not to schedule the refill worker. The pool remains at zero
> until an unrelated event triggers the worker. During this window all
> GFP_ATOMIC and GFP_NOWAIT callers receive NULL from dma_alloc_coherent()
> with no indication of the root cause.
>
> Drivers that do not check the return value of dma_alloc_coherent() in
> atomic context will NULL-deref (kernel oops/panic). Drivers that do
> check it will silently drop operations: packet loss in network drivers,
> I/O failure in storage drivers, device hangs in GPU/media drivers.
>
> Confirmed present in v6.14-rc3 (mainline). The pattern is unchanged
> since its introduction in commit d3f1d56c2e0e.
>
> Untrusted user trigger: indirect, via drivers that call dma_alloc_coherent()
> in atomic context on behalf of user operations (virtio-net MSG_ZEROCOPY,
> USB bulk transfers from plugdev group). Direct kernel-internal trigger
> requires driving alloc/free pressure on a DMA-capable device.
>
> Fix: remove the racy conditional check and call schedule_work()
> unconditionally on every successful allocation. schedule_work() is
> idempotent -- if the work item is already pending or running, the call
> is a no-op. The workqueue deduplicates concurrent schedule_work() calls
> naturally, so overhead is bounded to one work item per alloc burst.
> The worker itself checks whether expansion is actually needed, so
> spurious calls are harmless.
>
> Fixes: d3f1d56c2e0e ("dma-pool: add additional atomic pools")
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Afi0 <capyenglishlite@gmail.com>
^^^^^
still not working here.
willy
next prev parent reply other threads:[~2026-05-17 8:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 7:43 [PATCH] dma: pool: fix racy refill check in dma_alloc_from_pool() Afi0
2026-05-17 8:10 ` Willy Tarreau [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-05-17 8:18 Afi0
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=agl4AVLIdIrjXFky@1wt.eu \
--to=w@1wt.eu \
--cc=capyenglishlite@gmail.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.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