From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01439CA5FCB for ; Wed, 30 Sep 2026 15:27:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBwAf-0008Lc-Dl; Wed, 30 Sep 2026 11:24:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBwAd-0008I9-1z; Wed, 30 Sep 2026 11:24:35 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBwAb-00021e-2n; Wed, 30 Sep 2026 11:24:34 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68UE5RSd3171022; Wed, 30 Sep 2026 15:24:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=qQRgN5/l+DZ2WdLGO 7VRsp5H6wjMjRoWTc2ZH6ZeEjw=; b=mzNPIJTmiXW1MALxgecGCEMMB2z7l5Z04 gyiyF0Wtn2Z7L8O6jckFby/1QmRlf8fswpulr2tWUeKU9+WaJOky7U1y82HDJuqM pWGzV9/6gDU3YZW6OGYzTOjuUOF33aYrkm7LqzgYg+L1rrsm0bylsjBZr6ciRMao 93Ldq6USSXsnbpfEe2q/TZxY/MpIiNKJexcKUfko5sS0SYKZW9OSks+KLhr8u7ST f1V7f4n+v6QyJvQJXLzjyriiZFGRoBfD5qcJLuZGxbLWYV+5vcxjFZMB4/PMgkL7 fScInwor0HE0quoHnDDMs7a0Qf6sSbzKSAIBTwHOFzGN6hqPVWYSQ== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gx5s5dtra-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Sep 2026 15:24:31 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68UE38sL3541488; Wed, 30 Sep 2026 15:24:30 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([172.16.1.72]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4h0hfpcetb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2026 15:24:30 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68UFOSx932637480 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Sep 2026 15:24:29 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4D4258060; Wed, 30 Sep 2026 15:24:28 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4BFF15805F; Wed, 30 Sep 2026 15:24:28 +0000 (GMT) Received: from li-479af74c-31f9-11b2-a85c-e4ddee11713b.ibm.com.com (unknown [9.61.5.156]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 30 Sep 2026 15:24:28 +0000 (GMT) From: Eric Farman To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Matthew Rosato , Cornelia Huck , Zhuoying Cai , Eric Farman Subject: [PULL 12/23] pc-bios/s390-ccw: Add dynamic net header size handling Date: Wed, 30 Sep 2026 11:24:09 -0400 Message-ID: <20260930152420.1956230-13-farman@linux.ibm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152420.1956230-1-farman@linux.ibm.com> References: <20260930152420.1956230-1-farman@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTMwMDA2MCBTYWx0ZWRfX3nVi/1qJWYjJ HvVJOH7XmQXZ/km5zVX5bD5Dk36ZQPzRB8wzuf9O8iqxdaLP2z3hSc2OD3YQbfL4jl4a1sQGpSA qcc9J3ZvBswGyEJyfPN2YDjU+FOm5ig= X-Authority-Analysis: v=2.4 cv=HJ5WhYtv c=1 sm=1 tr=0 ts=6abd29af cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=PJsyiqIXYuV6zaAqLSAA:9 X-Proofpoint-GUID: f0BHMlUfssIEeTZlnmlPzsmgNSp4P265 X-Proofpoint-ORIG-GUID: f0BHMlUfssIEeTZlnmlPzsmgNSp4P265 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTMwMDA2MCBTYWx0ZWRfX2v7BgdRyPJDk jZmlPb61b1UXVxscEpKDoyrwbX9k6+eksVDlDhi+yPB4jQjOd4ZcTcLwH0FUQEQqvB42krv8hFo 2r6A/JADZMMSDAfk5e5MafVTdZers2HJDDzF8KE9twvsjOKPEUJJo4WQA+VLLdkMYEscHak9ENX IU4rv6SQSisgtsEKBwRt6GPVws1kF3PDvsMWLwR0vxhniiMRgyLVHNIPItWVJ2EoJvue0jZB+1I evJdkIa7Wt/mk1RI/O2JgX3ShhOx5QZNlpx05PrOf6OysAzx2E7XKqwl+VB4O3RN3WOPDQsbIzE PQ9JCGeQ5/UitM6rTFH5GRj1azDSvMx6DgJ77O4ym+JLkLTRbc3VkgyBQG1MN1bAFBXbuLSEdt1 Xfu+fWJJsKjx/wgRycRnjrwSbdzVnRfaK+5FqnXe1Q6BSgFp/ACylM1MV1i8FUzc4nSX02zqAxX UrfCUkTrAZGGM4tnWKQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-30_03,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609300060 Received-SPF: pass client-ip=148.163.156.1; envelope-from=farman@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Zhuoying Cai The virtio-net device used a fixed header size that did not account for the num_buffers field used in VirtIO 1.0. Use dynamic header sizing: 10 bytes for legacy mode and 12 bytes for VirtIO 1.0. This ensures correct packet handling across different VirtIO configurations. The VirtioNetHdr and VirtioNetHdrMrgRxbuf structures replicate the same field layout as struct virtio_net_hdr and struct virtio_net_hdr_mrg_rxbuf defined in include/uapi/linux/virtio_net.h. Signed-off-by: Zhuoying Cai Acked-by: Christian Borntraeger Reviewed-by: Jared Rossi Reviewed-by: Matthew Rosato Link: https://lore.kernel.org/qemu-devel/20260924222949.147720-3-zycai@linux.ibm.com Signed-off-by: Eric Farman --- pc-bios/s390-ccw/virtio-net.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c index f58f7ffc55..7bb3f8f551 100644 --- a/pc-bios/s390-ccw/virtio-net.c +++ b/pc-bios/s390-ccw/virtio-net.c @@ -20,6 +20,7 @@ #include "s390-ccw.h" #include "virtio.h" #include "virtio-ccw.h" +#include "virtio-pci.h" #include "s390-time.h" #include "helper.h" @@ -39,11 +40,21 @@ struct VirtioNetHdr { uint16_t gso_size; uint16_t csum_start; uint16_t csum_offset; - /*uint16_t num_buffers;*/ /* Only with VIRTIO_NET_F_MRG_RXBUF or VIRTIO1 */ }; typedef struct VirtioNetHdr VirtioNetHdr; +struct VirtioNetHdrMrgRxbuf { + struct VirtioNetHdr hdr; + uint16_t num_buffers; /* Only with VIRTIO_NET_F_MRG_RXBUF or VIRTIO1 */ +}; +typedef struct VirtioNetHdrMrgRxbuf VirtioNetHdrMrgRxbuf; + +/* Header sizes for different modes */ +#define VIRTIO_NET_HDR_SIZE_LEGACY sizeof(VirtioNetHdr) +#define VIRTIO_NET_HDR_SIZE_V1 sizeof(VirtioNetHdrMrgRxbuf) + static uint16_t rx_last_idx; /* Last index in receive queue "used" ring */ +static int virtio_net_hdr_size; int virtio_net_init(void *mac_addr) { @@ -62,12 +73,16 @@ int virtio_net_init(void *mac_addr) return -1; } + virtio_net_hdr_size = vdev->guest_features[1] & VIRTIO_F_VERSION_1 + ? VIRTIO_NET_HDR_SIZE_V1 + : VIRTIO_NET_HDR_SIZE_LEGACY; + memcpy(mac_addr, vdev->config.net.mac, ETH_ALEN); for (i = 0; i < 64; i++) { - buf = malloc(ETH_MTU_SIZE + sizeof(VirtioNetHdr)); + buf = malloc(ETH_MTU_SIZE + virtio_net_hdr_size); IPL_assert(buf != NULL, "Can not allocate memory for receive buffers"); - vring_send_buf(rxvq, buf, ETH_MTU_SIZE + sizeof(VirtioNetHdr), + vring_send_buf(rxvq, buf, ETH_MTU_SIZE + virtio_net_hdr_size, VRING_DESC_F_WRITE); } vring_notify(rxvq); @@ -77,14 +92,14 @@ int virtio_net_init(void *mac_addr) int send(int fd, const void *buf, int len, int flags) { - VirtioNetHdr tx_hdr; + VirtioNetHdrMrgRxbuf tx_hdr; VDev *vdev = virtio_get_device(); VRing *txvq = &vdev->vrings[VQ_TX]; /* Set up header - we do not use anything special, so simply clear it */ memset(&tx_hdr, 0, sizeof(tx_hdr)); - vring_send_buf(txvq, &tx_hdr, sizeof(tx_hdr), VRING_DESC_F_NEXT); + vring_send_buf(txvq, &tx_hdr, virtio_net_hdr_size, VRING_DESC_F_NEXT); vring_send_buf(txvq, (void *)buf, len, VRING_HIDDEN_IS_CHAIN); while (!vr_poll(txvq)) { yield(); @@ -108,13 +123,13 @@ int recv(int fd, void *buf, int maxlen, int flags) return 0; } - len = rxvq->used->ring[rx_last_idx % rxvq->num].len - sizeof(VirtioNetHdr); + len = rxvq->used->ring[rx_last_idx % rxvq->num].len - virtio_net_hdr_size; if (len > maxlen) { puts("virtio-net: Receive buffer too small"); len = maxlen; } id = rxvq->used->ring[rx_last_idx % rxvq->num].id % rxvq->num; - pkt = (uint8_t *)(rxvq->desc[id].addr + sizeof(VirtioNetHdr)); + pkt = (uint8_t *)(rxvq->desc[id].addr + virtio_net_hdr_size); #if DEBUG_VIRTIO_NET /* Dump packet */ int i; -- 2.55.0