From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Richard Cochran" <richardcochran@gmail.com>,
"Russell King" <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Paolo Valerio" <pvalerio@redhat.com>,
"Nicolai Buchwitz" <nb@tipi-net.de>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>
Subject: Re: [PATCH net-next v5 11/15] net: macb: change function signatures to take contexts
Date: Fri, 31 Jul 2026 16:55:55 +0200 [thread overview]
Message-ID: <DKCUDTZK4HJS.1Q0JH3CNPYF4G@bootlin.com> (raw)
In-Reply-To: <20260724-macb-context-v5-11-569b1852bc7f@bootlin.com>
Replies to Sashiko reviews (only those that aren't about pre-existing
issues).
On this patch, only from sashiko.dev:
https://sashiko.dev/#/patchset/20260724-macb-context-v5-0-569b1852bc7f%40bootlin.com
> > @@ -186,40 +188,42 @@ static struct macb_tx_skb *macb_tx_skb(struct macb_queue *queue,
> > {
> > struct macb_txq *txq = macb_txq(queue);
> >
> > - return &txq->skb[macb_tx_ring_wrap(queue->bp, index)];
> > + return &txq->skb[macb_tx_ring_wrap(queue->bp->ctx, index)];
>
> [Severity: Medium]
> Will this continue to dynamically evaluate queue->bp->ctx instead of
> accepting the context parameter? It looks like this leaves a mixed reference
> which might defeat the refactoring goal of avoiding bugs from using bp->ctx
> instead of ctx.
The main goal of refactoring to take ctx (+ queue index) is that, on
transition states, we cannot mess up the buffers we access.
The macb_tx_skb() function is by definition a function that is only
called in places where the interface must be up and running. Changing
its signature would require passing a queue index and that means a tiny
bit more code in the 11 calling locations without any safety benefit.
> > @@ -1620,6 +1631,8 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi,
> > int budget)
> > {
> > + unsigned int q = queue - queue->bp->queues;
> > + struct macb_context *ctx = queue->bp->ctx;
> > struct macb_rxq *rxq = macb_rxq(queue);
> > struct macb *bp = queue->bp;
>
> [Severity: Medium]
> Can this cause a mismatch in size when processing descriptors later in
> the function? Since dma_unmap_single() uses bp->ctx->rx_buffer_size
> instead of ctx->rx_buffer_size:
>
> gem_rx() {
> ...
> dma_unmap_single(&bp->pdev->dev, addr,
> bp->ctx->rx_buffer_size, DMA_FROM_DEVICE);
>
> Could this lead to wrong DMA unmap sizes if a concurrent swap modifies
> bp->ctx?
I like this review: our function signature bp to ctx rework is aimed at
avoiding those exact bugs. But here, no possible issue. We don't allow
concurrent swaps.
gem_rx() can only be called when a single context exists. Only functions
which might be called at a timeframe where two contexts might be alive
need to be careful about the context they use.
> > @@ -2358,14 +2381,14 @@ static unsigned int macb_tx_map(struct macb *bp,
> > do {
> > i--;
> > tx_skb = macb_tx_skb(queue, i);
> > - desc = macb_tx_desc(queue, i);
> > + desc = macb_tx_desc(ctx, q, i);
> >
> > ctrl = (u32)tx_skb->size;
> > if (eof) {
> > ctrl |= MACB_BIT(TX_LAST);
> > eof = 0;
> > }
> > - if (unlikely(macb_tx_ring_wrap(bp, i) ==
> > + if (unlikely(macb_tx_ring_wrap(ctx, i) ==
> > bp->ctx->tx_ring_size - 1))
> > ctrl |= MACB_BIT(TX_WRAP);
>
> [Severity: Medium]
> Does mixing the explicit ctx and bp->ctx in the same bounds calculation
> create a time-of-check to time-of-use race? If the context sizes ever differ
> due to a concurrent context swap, could this lead to buffer overflows by
> failing to set TX_WRAP?
Again, same reasoning. macb_tx_map() cannot be called in a timeframe
where two contexts are alive.
I'll clarify the commit message to avoid the confusion.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-07-31 14:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 15:29 [PATCH net-next v5 00/15] net: macb: implement context swapping Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 01/15] net: macb: drop "consistent" from alloc/free function names Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 02/15] net: macb: unify device pointer naming convention Théo Lebrun
2026-07-24 19:35 ` Nicolai Buchwitz
2026-07-24 15:29 ` [PATCH net-next v5 03/15] net: macb: unify variable naming convention in at91ether functions Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 04/15] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 05/15] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 06/15] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 07/15] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-07-31 14:39 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 08/15] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 09/15] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 10/15] net: macb: change caps helpers signatures Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 11/15] net: macb: change function signatures to take contexts Théo Lebrun
2026-07-24 19:36 ` Nicolai Buchwitz
2026-07-31 14:55 ` Théo Lebrun [this message]
2026-07-24 15:29 ` [PATCH net-next v5 12/15] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 13/15] net: macb: read ISR inside bp->lock critical section Théo Lebrun
2026-07-31 15:08 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 14/15] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-07-24 19:38 ` Nicolai Buchwitz
2026-07-31 16:10 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 15/15] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
2026-07-31 16:21 ` Théo Lebrun
2026-07-30 11:52 ` [PATCH net-next v5 00/15] net: macb: implement context swapping Paolo Abeni
2026-07-30 16:17 ` Théo Lebrun
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=DKCUDTZK4HJS.1Q0JH3CNPYF4G@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=benoit.monin@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor.dooley@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=pvalerio@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.