All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Til Kaiser" <mail@tk154.de>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net v3 3/4] net: mvpp2: refill RX buffers before XDP or skb use
Date: Sat, 06 Jun 2026 12:15:05 +0000	[thread overview]
Message-ID: <20260606121506.13F201F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260605121332.147397-4-mail@tk154.de>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Incomplete DMA sync when recycling an XDP-modified page during SKB allocation failure.

Pre-existing issues:
- [High] Variable swap leading to invalid memory access in mvpp2_buff_hdr_pool_put().
- [High] Acquiring a spinlock with preemption disabled causes a sleep-in-atomic bug on PREEMPT_RT.
--

commit 9aeeec1a49aec085a29bfd1f85e72ffb42da9a5c
Author: Til Kaiser <mail@tk154.de>

net: mvpp2: refill RX buffers before XDP or skb use

This patch adjusts the RX error path to prevent returning a buffer to the
hardware BM pool if it has already been handed to XDP or attached to an skb.
It refills the BM pool earlier so that if allocation fails, the original
still-owned buffer can safely be returned to the hardware pool.

> diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> index 3372ed27cc8d6..481daafdc1cbc 100644
> --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
> +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c

[ ... ]

> @@ -4008,8 +4008,21 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
>  			skb = slab_build_skb(data);
>  		if (!skb) {
>  			netdev_warn(port->dev, "skb build failed\n");
> -			goto err_drop_frame;
> +			if (pp) {
> +				page_pool_put_page(pp, virt_to_head_page(data),
> +						   rx_bytes + MVPP2_MH_SIZE,
> +						   true);

[Severity: High]
Does this truncate the DMA sync size if the packet length was modified by XDP?

Earlier in mvpp2_rx(), an XDP program might have been executed which could
reduce the packet length using helpers like bpf_xdp_adjust_tail, updating
rx_bytes to a smaller value.

If build_skb() subsequently fails here, we use this reduced rx_bytes for the
page pool DMA sync. Because the sync does not cover the tail of the buffer
that the CPU may have fetched into its cache, can this lead to memory
corruption when the hardware DMA writes a new packet and the dirty CPU cache
lines are evicted over it?

In mvpp2_run_xdp(), this appears to be handled properly by calculating
max(sync, len).

> +			} else {
> +				dma_unmap_single_attrs(dev->dev.parent, dma_addr,
> +						       bm_pool->buf_size,
> +						       DMA_FROM_DEVICE,
> +						       DMA_ATTR_SKIP_CPU_SYNC);
> +				mvpp2_frag_free(bm_pool, pp, data);
> +			}
> +			goto err_drop_frame_retired;
>  		}

[ ... ]

> @@ -4048,13 +4052,14 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi,
>  		continue;
>  
>  err_drop_frame:
> -		dev->stats.rx_errors++;
> -		mvpp2_rx_error(port, rx_desc);
>  		/* Return the buffer to the pool */
>  		if (rx_status & MVPP2_RXD_BUF_HDR)
>  			mvpp2_buff_hdr_pool_put(port, rx_desc, pool, rx_status);

[Severity: High]
This is a pre-existing issue, but does mvpp2_buff_hdr_pool_put() swap the
physical and DMA addresses?

Looking at mvpp2_buff_hdr_pool_put():

static void mvpp2_buff_hdr_pool_put(...)
{
        ...
        phys_addr = mvpp2_rxdesc_dma_addr_get(port, rx_desc);
        dma_addr = mvpp2_rxdesc_cookie_get(port, rx_desc);

        do {
                buff_hdr = (struct mvpp2_buff_hdr *)phys_to_virt(phys_addr);

It appears phys_addr is initialized with the DMA address, and dma_addr with
the physical address. Because of this swap, we call phys_to_virt() on a DMA
address. On systems where the DMA address and physical address differ (like
when an IOMMU is active), could this cause an invalid memory access?

>  		else
>  			mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr);

[Severity: High]
This is also a pre-existing issue, but does mvpp2_bm_pool_put() acquire a
spinlock while preemption is disabled?

Looking at mvpp2_bm_pool_put():

static inline void mvpp2_bm_pool_put(...)
{
        unsigned int thread = mvpp2_cpu_to_thread(port->priv, get_cpu());
        unsigned long flags = 0;

        if (test_bit(thread, &port->priv->lock_map))
                spin_lock_irqsave(&port->bm_lock[thread], flags);

Since get_cpu() executes preempt_disable(), we conditionally attempt to
acquire the bm_lock spinlock immediately after. On PREEMPT_RT kernels, where
standard spinlocks are mapped to sleepable rt_mutexes, won't this cause a
sleep-in-atomic bug when this code path is hit?

> +err_drop_frame_retired:
> +		dev->stats.rx_errors++;
> +		mvpp2_rx_error(port, rx_desc);
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260605121332.147397-1-mail@tk154.de?part=3

  reply	other threads:[~2026-06-06 12:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 16:46 [PATCH net v2 0/4] net: mvpp2: fix XDP RX buffer handling Til Kaiser
2026-06-02 16:46 ` [PATCH net v2 1/4] net: mvpp2: sync RX data at the hardware packet offset Til Kaiser
2026-06-03 16:55   ` sashiko-bot
2026-06-02 16:46 ` [PATCH net v2 2/4] net: mvpp2: limit XDP frame size to the RX buffer Til Kaiser
2026-06-03 16:55   ` sashiko-bot
2026-06-02 16:46 ` [PATCH net v2 3/4] net: mvpp2: do not return retired RX buffers to BM Til Kaiser
2026-06-03 16:55   ` sashiko-bot
2026-06-04 15:45   ` Jakub Kicinski
2026-06-02 16:46 ` [PATCH net v2 4/4] net: mvpp2: build skb from XDP-adjusted data on XDP_PASS Til Kaiser
2026-06-03 16:55   ` sashiko-bot
2026-06-03 13:55 ` [PATCH net v2 0/4] net: mvpp2: fix XDP RX buffer handling Alexander Lobakin
2026-06-04 11:30   ` Marcin Wojtas
2026-06-05 12:13 ` [PATCH net v3 " Til Kaiser
2026-06-05 12:13   ` [PATCH net v3 1/4] net: mvpp2: sync RX data at the hardware packet offset Til Kaiser
2026-06-06 12:15     ` sashiko-bot
2026-06-05 12:13   ` [PATCH net v3 2/4] net: mvpp2: limit XDP frame size to the RX buffer Til Kaiser
2026-06-05 12:13   ` [PATCH net v3 3/4] net: mvpp2: refill RX buffers before XDP or skb use Til Kaiser
2026-06-06 12:15     ` sashiko-bot [this message]
2026-06-05 12:13   ` [PATCH net v3 4/4] net: mvpp2: build skb from XDP-adjusted data on XDP_PASS Til Kaiser
2026-06-06 12:15     ` sashiko-bot

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=20260606121506.13F201F00898@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mail@tk154.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.