From nobody Sat Feb 7 23:48:20 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5FA722097 for ; Wed, 29 Oct 2025 01:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761701093; cv=none; b=equEUVnRdbv8F0rG5i4Gw9BGzzt71Mg5eQ9kDey4NHwUdH9nkZGZu4jmEKoT2+bE3XC47O0mxrorZnL1mrfzBteVnnuy+4NTaaEu7LaItC6odRDS0h8tc10ApO9wGU5u6EL6TwTqtKdazoLbHU1MdhbjZmrGYiEwHBVWmgKtpmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761701093; c=relaxed/simple; bh=PKRuTRimF4SYTLZRofdH+Kyncm9Idj+SwpxtXEnIAdc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-type; b=fzFXVVgW38r36MWNyY1azxpK+AIDjiJKVMobG20gEV59olLYxC4KBl3TH4W+BvYriW1UvVrILR4AXevLYOPCD8hO5b721ldkqG0CB4T8EmG2LO9etTZ90bo/OLvvd3lcJrB4uNIzzFiIQgR4ym7BzKwa+IpekjXbR4NGxCkOLLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VQ1Ke5Rg; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VQ1Ke5Rg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761701090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wVSi1lcrQ2LPNL0uA8+lcsf92i/aD7113jgr/Mo2pIg=; b=VQ1Ke5RgzybAAAiefZvdfTOyHtNjsFNun75bscayY0StZQJa5cTbGcZH6t4Sb+iG5tXSeC IfWd+lU2q5K7lOiTJsyL5cOy57Svr4wt9D3wD6q+TLgqychtEYXex9OW7RFv1Ykexiep7e ecDk4fnvQlcXpQ7/g7xmDEribD6jR5A= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-ScP-ngM9N06ur7kDs7233w-1; Tue, 28 Oct 2025 21:24:49 -0400 X-MC-Unique: ScP-ngM9N06ur7kDs7233w-1 X-Mimecast-MFC-AGG-ID: ScP-ngM9N06ur7kDs7233w_1761701087 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4745618002C1; Wed, 29 Oct 2025 01:24:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.136]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F43119560B8; Wed, 29 Oct 2025 01:24:39 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net] virtio_net: fix alignment for virtio_net_hdr_v1_hash Date: Wed, 29 Oct 2025 09:24:34 +0800 Message-ID: <20251029012434.75576-1-jasowang@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" From: "Michael S. Tsirkin" Changing alignment of header would mean it's no longer safe to cast a 2 byte aligned pointer between formats. Use two 16 bit fields to make it 2 byte aligned as previously. This fixes the performance regression since commit ("virtio_net: enable gso over UDP tunnel support.") as it uses virtio_net_hdr_v1_hash_tunnel which embeds virtio_net_hdr_v1_hash. Pktgen in guest + XDP_DROP on TAP + vhost_net shows the TX PPS is recovered from 2.4Mpps to 4.45Mpps. Fixes: 56a06bd40fab ("virtio_net: enable gso over UDP tunnel support.") Cc: stable@vger.kernel.org Signed-off-by: Michael S. Tsirkin Signed-off-by: Jason Wang Acked-by: Paolo Abeni --- drivers/net/virtio_net.c | 15 +++++++++++++-- include/uapi/linux/virtio_net.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index a757cbcab87f..5e998d88db44 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2534,6 +2534,13 @@ static struct sk_buff *receive_mergeable(struct net_= device *dev, return NULL; } =20 +static inline u32 +virtio_net_hash_value(const struct virtio_net_hdr_v1_hash *hdr_hash) +{ + return __le16_to_cpu(hdr_hash->hash_value_lo) | + (__le16_to_cpu(hdr_hash->hash_value_hi) << 16); +} + static void virtio_skb_set_hash(const struct virtio_net_hdr_v1_hash *hdr_h= ash, struct sk_buff *skb) { @@ -2560,7 +2567,7 @@ static void virtio_skb_set_hash(const struct virtio_n= et_hdr_v1_hash *hdr_hash, default: rss_hash_type =3D PKT_HASH_TYPE_NONE; } - skb_set_hash(skb, __le32_to_cpu(hdr_hash->hash_value), rss_hash_type); + skb_set_hash(skb, virtio_net_hash_value(hdr_hash), rss_hash_type); } =20 static void virtnet_receive_done(struct virtnet_info *vi, struct receive_q= ueue *rq, @@ -3306,6 +3313,10 @@ static int xmit_skb(struct send_queue *sq, struct sk= _buff *skb, bool orphan) =20 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); =20 + /* Make sure it's safe to cast between formats */ + BUILD_BUG_ON(__alignof__(*hdr) !=3D __alignof__(hdr->hash_hdr)); + BUILD_BUG_ON(__alignof__(*hdr) !=3D __alignof__(hdr->hash_hdr.hdr)); + can_push =3D vi->any_header_sg && !((unsigned long)skb->data & (__alignof__(*hdr) - 1)) && !skb_header_cloned(skb) && skb_headroom(skb) >=3D hdr_len; @@ -6745,7 +6756,7 @@ static int virtnet_xdp_rx_hash(const struct xdp_md *_= ctx, u32 *hash, hash_report =3D VIRTIO_NET_HASH_REPORT_NONE; =20 *rss_type =3D virtnet_xdp_rss_type[hash_report]; - *hash =3D __le32_to_cpu(hdr_hash->hash_value); + *hash =3D virtio_net_hash_value(hdr_hash); return 0; } =20 diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_ne= t.h index 8bf27ab8bcb4..1db45b01532b 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -193,7 +193,8 @@ struct virtio_net_hdr_v1 { =20 struct virtio_net_hdr_v1_hash { struct virtio_net_hdr_v1 hdr; - __le32 hash_value; + __le16 hash_value_lo; + __le16 hash_value_hi; #define VIRTIO_NET_HASH_REPORT_NONE 0 #define VIRTIO_NET_HASH_REPORT_IPv4 1 #define VIRTIO_NET_HASH_REPORT_TCPv4 2 --=20 2.42.0