From: "Michael S. Tsirkin" <mst@redhat.com>
To: Wenbo Li <liwenbo.martin@bytedance.com>
Cc: jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
eperezma@redhat.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jiahui Cen <cenjiahui@bytedance.com>,
Ying Fang <fangying.tommy@bytedance.com>
Subject: Re: [PATCH v3] virtio_net: Fix mismatched buf address when unmapping for small packets
Date: Wed, 18 Sep 2024 10:58:23 -0400 [thread overview]
Message-ID: <20240918105803-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20240918132005.31174-1-liwenbo.martin@bytedance.com>
On Wed, Sep 18, 2024 at 09:20:05PM +0800, Wenbo Li wrote:
> Currently, the virtio-net driver will perform a pre-dma-mapping for
> small or mergeable RX buffer. But for small packets, a mismatched address
> without VIRTNET_RX_PAD and xdp_headroom is used for unmapping.
>
> That will result in unsynchronized buffers when SWIOTLB is enabled, for
> example, when running as a TDX guest.
>
> This patch unifies the address passed to the virtio core into the address of
> the virtnet header and fixes the mismatched buffer address.
>
> Changes from v2: unify the buf that passed to the virtio core in small
> and merge mode.
> Changes from v1: Use ctx to get xdp_headroom.
>
> Fixes: 295525e29a5b ("virtio_net: merge dma operations when filling mergeable buffers")
> Signed-off-by: Wenbo Li <liwenbo.martin@bytedance.com>
> Signed-off-by: Jiahui Cen <cenjiahui@bytedance.com>
> Signed-off-by: Ying Fang <fangying.tommy@bytedance.com>
OK but can you please adhere to the kernel coding style?
> ---
> drivers/net/virtio_net.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6f4781ec2b36..9446666c84aa 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1804,9 +1804,15 @@ static struct sk_buff *receive_small(struct net_device *dev,
> struct virtnet_rq_stats *stats)
> {
> unsigned int xdp_headroom = (unsigned long)ctx;
> - struct page *page = virt_to_head_page(buf);
> + struct page *page;
> struct sk_buff *skb;
>
> + // We passed the address of virtnet header to virtio-core,
> + // so truncate the padding.
> + buf -= VIRTNET_RX_PAD + xdp_headroom;
> +
> + page = virt_to_head_page(buf);
> +
> len -= vi->hdr_len;
> u64_stats_add(&stats->bytes, len);
>
> @@ -2422,8 +2428,9 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
> if (unlikely(!buf))
> return -ENOMEM;
>
> - virtnet_rq_init_one_sg(rq, buf + VIRTNET_RX_PAD + xdp_headroom,
> - vi->hdr_len + GOOD_PACKET_LEN);
> + buf += VIRTNET_RX_PAD + xdp_headroom;
> +
> + virtnet_rq_init_one_sg(rq, buf, vi->hdr_len + GOOD_PACKET_LEN);
>
> err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
> if (err < 0) {
> --
> 2.20.1
prev parent reply other threads:[~2024-09-18 14:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 13:20 [PATCH v3] virtio_net: Fix mismatched buf address when unmapping for small packets Wenbo Li
2024-09-18 14:58 ` Michael S. Tsirkin [this message]
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=20240918105803-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=cenjiahui@bytedance.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=fangying.tommy@bytedance.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liwenbo.martin@bytedance.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).