* [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()
@ 2026-11-19 9:40 Haoran Wang
2026-11-19 9:41 ` netdev-bot+sinfo
2026-11-23 9:51 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Haoran Wang @ 2026-11-19 9:40 UTC (permalink / raw)
To: David Laight
Cc: Sebastian Andrzej Siewior, netdev, linux-kernel, linux-rt-devel,
andrew+netdev, davem, edumazet, kuba, pabeni, rostedt, wanghr2026
ppm_get_cpu_entries() must not acquire a sleeping lock while preemption
is disabled: get_cpu() disables preemption, and spin_lock_bh() may sleep
on PREEMPT_RT kernels. Use raw_cpu_ptr() instead, which reads the
current CPU's per-CPU pointer without touching preempt_count.
The task is then free to migrate before taking pool->lock, so it may end
up allocating from a different CPU's pool. That is harmless: each
per-CPU pool is just a shard of the global page pod (ppod) index space,
and every read-modify-write of a pool's bitmap and next index happens
under pool->lock. The free path, ppm_unmark_entries(), re-derives the
owning pool from the global index rather than from the running CPU and
takes that same lock, so any thread can service any shard. Derive the
global index base from pool->base so it always matches the pool that
was locked.
Found by static analysis and not triggered. The bug is only reachable
on PREEMPT_RT kernels, where spin_lock_bh() is a sleeping lock: there it
would trigger a "scheduling while atomic" BUG under
CONFIG_DEBUG_ATOMIC_SLEEP, or a deadlock if pool->lock is contended.
Fixes: 47da7e62b391 ("cxgb4: add iSCSI DDP page pod manager")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
Changes since v4:
- Reword the commit message (review).
- pr_debug(): drop the running CPU that David suggested in v3; it is of
limited use, so keep only the pool-owning CPU.
- Add a Fixes: tag and record how the issue was found (netdev bot).
Changes since v3:
- Explain in the commit message why a foreign CPU's pool is harmless and
trim the PREEMPT_RT problem description (review).
- pr_debug(): label the pool-owning CPU and also print the running CPU.
Changes since v2:
- Keep the pool-owning CPU in the pr_debug() output, derived from
pool->base (suggested by Sebastian).
- Reword the commit message; spell PREEMPT_RT.
Changes since v1:
- Read the global-index base from pool->base (initialised at pool
allocation) instead of a cpu captured before the lock.
drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
index 2e3973a32..837bdf412 100644
--- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
+++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
@@ -119,16 +119,13 @@ static int ppm_get_cpu_entries(struct cxgbi_ppm *ppm, unsigned int count,
unsigned long caller_data)
{
struct cxgbi_ppm_pool *pool;
- unsigned int cpu;
int i;
if (!ppm->pool)
return -EINVAL;
- cpu = get_cpu();
- pool = per_cpu_ptr(ppm->pool, cpu);
+ pool = raw_cpu_ptr(ppm->pool);
spin_lock_bh(&pool->lock);
- put_cpu();
i = ppm_find_unused_entries(pool->bmap, ppm->pool_index_max,
pool->next, count, 0);
@@ -144,11 +141,11 @@ static int ppm_get_cpu_entries(struct cxgbi_ppm *ppm, unsigned int count,
spin_unlock_bh(&pool->lock);
- pr_debug("%s: cpu %u, idx %d + %d (%d), next %u.\n",
- __func__, cpu, i, count, i + cpu * ppm->pool_index_max,
- pool->next);
+ pr_debug("%s: pool cpu %u, idx %d + %d (%d), next %u.\n",
+ __func__, pool->base / ppm->pool_index_max,
+ i, count, i + pool->base, pool->next);
- i += cpu * ppm->pool_index_max;
+ i += pool->base;
ppm_mark_entries(ppm, i, count, caller_data);
return i;
@@ -375,6 +372,7 @@ ppm_alloc_cpu_pool(unsigned int *total, unsigned int *pcpu_ppmax)
memset(ppool, 0, alloc_sz);
spin_lock_init(&ppool->lock);
+ ppool->base = count;
count += ppmax;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()
2026-11-19 9:40 [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries() Haoran Wang
@ 2026-11-19 9:41 ` netdev-bot+sinfo
2026-11-23 9:51 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19 9:41 UTC (permalink / raw)
To: Haoran Wang
Cc: David Laight, Sebastian Andrzej Siewior, netdev, linux-kernel,
linux-rt-devel, andrew+netdev, davem, edumazet, kuba, pabeni,
rostedt
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()
2026-11-19 9:40 [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries() Haoran Wang
2026-11-19 9:41 ` netdev-bot+sinfo
@ 2026-11-23 9:51 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 9:51 UTC (permalink / raw)
To: wanghr2026
Cc: david.laight.linux, bigeasy, netdev, linux-kernel, linux-rt-devel,
andrew+netdev, davem, edumazet, kuba, pabeni, rostedt
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch makes the allocation and free paths in
drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c compute a pool's…
--
libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()
This patch replaces get_cpu()/per_cpu_ptr()/put_cpu() with raw_cpu_ptr()
in ppm_get_cpu_entries(), so spin_lock_bh() is no longer taken with
preemption disabled on PREEMPT_RT. The task can now migrate before the
lock is taken, so the global index base comes from a new pool->base
field set in ppm_alloc_cpu_pool() instead of cpu * pool_index_max.
> diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
> index 2e3973a32d9d1..837bdf4128370 100644
> --- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
> +++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
[ ... ]
> @@ -144,11 +141,11 @@ static int ppm_get_cpu_entries(struct cxgbi_ppm *ppm, unsigned int count,
>
> spin_unlock_bh(&pool->lock);
>
> - pr_debug("%s: cpu %u, idx %d + %d (%d), next %u.\n",
> - __func__, cpu, i, count, i + cpu * ppm->pool_index_max,
> - pool->next);
> + pr_debug("%s: pool cpu %u, idx %d + %d (%d), next %u.\n",
> + __func__, pool->base / ppm->pool_index_max,
> + i, count, i + pool->base, pool->next);
>
> - i += cpu * ppm->pool_index_max;
> + i += pool->base;
> ppm_mark_entries(ppm, i, count, caller_data);
>
> return i;
> @@ -375,6 +372,7 @@ ppm_alloc_cpu_pool(unsigned int *total, unsigned int *pcpu_ppmax)
>
> memset(ppool, 0, alloc_sz);
> spin_lock_init(&ppool->lock);
> + ppool->base = count;
> count += ppmax;
> }
>
[Severity: High]
Does this base still match the decode in ppm_unmark_entries() when
cpu_possible_mask is not contiguous?
count is a running counter over for_each_possible_cpu(). That makes
pool->base the CPU's position among possible CPUs times ppmax, not
cpu * ppmax.
ppm_unmark_entries() was not changed, and it still reads the quotient as
a CPU id:
drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c:ppm_unmark_entries() {
...
cpu = i / ppm->pool_index_max;
i %= ppm->pool_index_max;
pool = per_cpu_ptr(ppm->pool, cpu);
spin_lock_bh(&pool->lock);
bitmap_clear(pool->bmap, i, count);
...
}
As an example, take cpu_possible_mask = {0, 2, 3}. cpu 2 gets
base = ppmax and cpu 3 gets base = 2 * ppmax.
An index from cpu 2's pool (ppmax + k) decodes on release to cpu 1. cpu 1
is not a possible CPU, so
cxgbi_ppm_ppod_release()->ppm_unmark_entries() would take a lock and
clear bits in a per-CPU slot that was never set up.
An index from cpu 3's pool (2 * ppmax + k) would be freed into cpu 2's
bitmap. Could that clear a bit cpu 2 still has in use, so the ppod is
handed out again while the adapter still holds the first DDP tag? cpu
3's own bit would also never be cleared, so those entries would leak.
The old code was already wrong on sparse possible masks, because
cpu * pool_index_max could go past pool_rsvd. This patch changes how it
fails: it now writes into a non-possible CPU's per-CPU area and frees
into another CPU's pool. Sparse masks do happen. For example,
arch/sparc/kernel/prom_64.c sets possible CPUs by firmware cpuid.
The commit message says:
The free path, ppm_unmark_entries(), re-derives the owning pool from
the global index rather than from the running CPU and takes that same
lock, so any thread can service any shard. Derive the global index
base from pool->base so it always matches the pool that was locked.
That only holds if pool->base == cpu * pool_index_max. Would it work to
have the free path look up the pool by its stored base? Another option
is to use cpu * ppmax everywhere, including when computing the total.
The new pr_debug() in ppm_get_cpu_entries() has the same problem.
pool->base / ppm->pool_index_max gives the position in the possible
mask, not the CPU id.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179508121445.22600.6953098503196332718%40mail.zgclab.edu.cn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 9:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 9:40 [PATCH net v5] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries() Haoran Wang
2026-11-19 9:41 ` netdev-bot+sinfo
2026-11-23 9:51 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox