From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jingxuan Xie <jingxuanxie@deeproute.ai>, netdev@vger.kernel.org
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
John Ogness <john.ogness@linutronix.de>,
linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [RFC net v2 1/2] af_packet: prepare the virtio header before reserving an RX frame
Date: Fri, 30 Oct 2026 13:21:17 -0400 [thread overview]
Message-ID: <willemdebruijn.kernel.17d3748debf8b@gmail.com> (raw)
In-Reply-To: <20261030081704.251652-2-jingxuanxie@deeproute.ai>
Jingxuan Xie wrote:
> From: jingxuanxie <jingxuanxie@deeproute.ai>
>
> An RX virtio-header conversion can fail after packet_current_rx_frame()
> has reserved space in a TPACKET_V3 block and increased its packet count.
> Releasing the copy lock on that error path does not remove the incomplete
> record from the block.
Can you give a little more detail on the exact bug: what state does
not get reverted on error, and how problematic is this.
> Prepare the header in a local variable before reserving a frame, and copy
> it to the reserved frame only after conversion succeeds. Keep drop
> accounting, notification and copy_skb cleanup on conversion failure.
> This also keeps conversion out of the receive queue critical section.
>
> Assisted-by: LLM
> Signed-off-by: Jingxuan Xie <jingxuanxie@deeproute.ai>
> ---
> net/packet/af_packet.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 823e0911c910..7b3e1e27f777 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2273,6 +2273,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
> __u32 ts_status;
> unsigned int slot_id = 0;
> int vnet_hdr_sz = 0;
> + struct virtio_net_hdr vnet_hdr;
>
> /* struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT.
> * We may add members to them until current aligned size without forcing
> @@ -2375,6 +2376,14 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
> vnet_hdr_sz = 0;
> }
> }
> + if (vnet_hdr_sz &&
> + virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le(), true, 0)) {
> + drop_reason = SKB_DROP_REASON_PACKET_SOCK_ERROR;
> + atomic_inc(&po->tp_drops);
> + sk->sk_data_ready(sk);
> + sk_skb_reason_drop(sk, copy_skb, drop_reason);
> + goto drop_n_restore;
Probably prefer a goto drop_n_account_unlocked rather than open coding
that here.
> + }
> spin_lock(&sk->sk_receive_queue.lock);
> h.raw = packet_current_rx_frame(po, skb,
> TP_STATUS_KERNEL, (macoff+snaplen));
> @@ -2388,16 +2397,9 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
> __set_bit(slot_id, po->rx_ring.rx_owner_map);
> }
>
> - if (vnet_hdr_sz &&
> - virtio_net_hdr_from_skb(skb, h.raw + macoff -
> - sizeof(struct virtio_net_hdr),
> - vio_le(), true, 0)) {
> - if (po->tp_version <= TPACKET_V2)
> - __clear_bit(slot_id, po->rx_ring.rx_owner_map);
> - else
> - prb_clear_blk_fill_status(&po->rx_ring);
> - goto drop_n_account;
> - }
> + if (vnet_hdr_sz)
> + memcpy(h.raw + macoff - sizeof(vnet_hdr), &vnet_hdr,
> + sizeof(vnet_hdr));
>
> if (po->tp_version <= TPACKET_V2) {
> packet_increment_rx_head(po, &po->rx_ring);
> --
> 2.25.1
next prev parent reply other threads:[~2026-10-30 17:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 8:17 [RFC net v2 0/2] af_packet: retire TPACKET_V3 blocks without waiting for copiers Jingxuan Xie
2026-10-30 8:17 ` [RFC net v2 1/2] af_packet: prepare the virtio header before reserving an RX frame Jingxuan Xie
2026-10-30 17:21 ` Willem de Bruijn [this message]
2026-10-30 8:17 ` [RFC net v2 2/2] af_packet: retire TPACKET_V3 blocks without waiting for copiers Jingxuan Xie
2026-10-31 8:17 ` sashiko-bot
-- strict thread matches above, loose matches on Subject: below --
2026-10-30 8:14 [RFC net v2 0/2] " Jingxuan Xie
2026-10-30 8:14 ` [RFC net v2 1/2] af_packet: prepare the virtio header before reserving an RX frame Jingxuan Xie
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=willemdebruijn.kernel.17d3748debf8b@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jingxuanxie@deeproute.ai \
--cc=john.ogness@linutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
/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