From nobody Tue Feb 10 14:42:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1677147961; cv=none; d=zohomail.com; s=zohoarc; b=Kn3g2iHwbNK9omKngz00D4tmMdbRWcnNR07P0pWDvNr7PDNsN5ahi2BQQomKYJTFBcSCe756CQfiBIXzZm+xhYFYvuzbFF+sySJ1oi6R2FO1PLKFmKp6FBJHkEAd2XKUAXUhzOhMVwBR4RP5rXK39kIa7NJRpRAPvRJOKv/u51s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677147961; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=3UnhBlJ7YOgsoT/Z//gez5GN4UW4QVUF00a2DHaaF80=; b=YzQc1sJZlFosmtQiEm6tf08uXANifG/SFCuLLcGvlRL79JvUXrvZ/QHndT64nglPy3Tqsp6sXKWF3Qscw8xObL269n6hCnRWXq4aNMxRM1M6xHauXld0NB3f7xLnpPB2Ulg9C7tMstXXQfOPZEBkXamMH7mprpb6eqXWhuUbtDY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677147961364338.908881636914; Thu, 23 Feb 2023 02:26:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pV8k0-0007Qg-Du; Thu, 23 Feb 2023 05:22:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pV8jg-0007F5-Gk for qemu-devel@nongnu.org; Thu, 23 Feb 2023 05:22:00 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pV8je-0002jJ-U1 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 05:22:00 -0500 Received: by mail-pj1-x1029.google.com with SMTP id x20-20020a17090a8a9400b00233ba727724so3614273pjn.1 for ; Thu, 23 Feb 2023 02:21:58 -0800 (PST) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id c20-20020a170902c1d400b00196217f1219sm4107734plc.70.2023.02.23.02.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 02:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3UnhBlJ7YOgsoT/Z//gez5GN4UW4QVUF00a2DHaaF80=; b=F1SHQLeLp+ozLM9LoBFmvNS1mGt4Dd/rEARBxj1yysv0P6odpCNC+rPbeSgCvMzMcR j4g4WXIZkHNcuFcy2UpZRe28YhVu4pqrttnMiUtoKnVwqXR5MKKnsX9IWz4PAcDwYNym 6iDVY7G19/WMVfgqGdTnxQLZMZqy5DhqatO6BiMZJlyvz1m6N7HgFTvM4xVxmTaSFVRS zhq1h4aaJGwLZJJfoTC9ghJacWY7sMoIYXKFEpWUEpFVHTCvXXkulPCq5qCH2Cb2mUhl Tq9zWkS/Bp3zB/tAQKyC7hf+rArhQvXjvv9A37zZaC4Aq0E4gLYE7fRw9dsI01sbkP+u WqZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3UnhBlJ7YOgsoT/Z//gez5GN4UW4QVUF00a2DHaaF80=; b=BzVQb1pNnT+C+C586lfffkdPGwwDjklaR9zbmPx3LwbmKjZgHpDYRL8sUFySNEOVS/ Ln6d6vTqSq2nIcaOupQvmgWEdBHQ2X96eMldNI3TDQPi8DMmGL3US7pdCV7yHMshiC9f M8JdALdJVY2tweMe6+i/GxgWvqoKS4xhui4syk3wABPaADc1L/S8kuUTCEvN7z48vGTT CcUD4Naf1Dl4w7OXtNQwO8KApSTH/nWxlTLf4AWPKSQFTQFR+/c5cUAw0u/pbBzUNUtX vJIIjzukT8iyOmneI/PFkWUYeTEEaTK3kkGozPjWC5FrHR3iDvzUItQQoagrINzY7Wfe 37IQ== X-Gm-Message-State: AO0yUKUwajFwv/feJBAofjQcDCUsDC6StC10tU9XDgMTcwyLSqcC144B s/CFg+J0dDxlhcDpjj0wXYwtZ/1eJuiT0Ues X-Google-Smtp-Source: AK7set9wjSaD2FT4esh0TXW76WhvPbitz/1OhXh/JJ7Ufj2SwrFQNbgLL9CBdaU9ckVw0NE/b4ahmg== X-Received: by 2002:a17:902:f98f:b0:196:790a:8bae with SMTP id ky15-20020a170902f98f00b00196790a8baemr9709955plb.43.1677147717649; Thu, 23 Feb 2023 02:21:57 -0800 (PST) From: Akihiko Odaki To: Cc: Jason Wang , Dmitry Fleytman , Thomas Huth , Laurent Vivier , Paolo Bonzini , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, "Michael S . Tsirkin" , Yan Vugenfirer , Yuri Benditovich , Sriram Yagnaraman , Alexander Bulekov , Akihiko Odaki Subject: [PATCH v6 22/34] hw/net/net_tx_pkt: Automatically determine if virtio-net header is used Date: Thu, 23 Feb 2023 19:20:06 +0900 Message-Id: <20230223102018.141748-23-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230223102018.141748-1-akihiko.odaki@daynix.com> References: <20230223102018.141748-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::1029; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1677147963008100001 Content-Type: text/plain; charset="utf-8" The new function qemu_get_using_vnet_hdr() allows to automatically determine if virtio-net header is used. Signed-off-by: Akihiko Odaki --- hw/net/e1000e_core.c | 3 +-- hw/net/net_tx_pkt.c | 19 ++++++++++--------- hw/net/net_tx_pkt.h | 3 +-- hw/net/vmxnet3.c | 6 ++---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 38d374fba3..954a007151 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -3376,8 +3376,7 @@ e1000e_core_pci_realize(E1000ECore *core, qemu_add_vm_change_state_handler(e1000e_vm_state_change, core); =20 for (i =3D 0; i < E1000E_NUM_QUEUES; i++) { - net_tx_pkt_init(&core->tx[i].tx_pkt, core->owner, - E1000E_MAX_TX_FRAGS, core->has_vnet); + net_tx_pkt_init(&core->tx[i].tx_pkt, core->owner, E1000E_MAX_TX_FR= AGS); } =20 net_rx_pkt_init(&core->rx_pkt, core->has_vnet); diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index 8a23899a4d..cf46c8457f 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -35,7 +35,6 @@ struct NetTxPkt { PCIDevice *pci_dev; =20 struct virtio_net_hdr virt_hdr; - bool has_virt_hdr; =20 struct iovec *raw; uint32_t raw_frags; @@ -59,7 +58,7 @@ struct NetTxPkt { }; =20 void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev, - uint32_t max_frags, bool has_virt_hdr) + uint32_t max_frags) { struct NetTxPkt *p =3D g_malloc0(sizeof *p); =20 @@ -71,10 +70,8 @@ void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *p= ci_dev, =20 p->max_payload_frags =3D max_frags; p->max_raw_frags =3D max_frags; - p->has_virt_hdr =3D has_virt_hdr; p->vec[NET_TX_PKT_VHDR_FRAG].iov_base =3D &p->virt_hdr; - p->vec[NET_TX_PKT_VHDR_FRAG].iov_len =3D - p->has_virt_hdr ? sizeof p->virt_hdr : 0; + p->vec[NET_TX_PKT_VHDR_FRAG].iov_len =3D sizeof p->virt_hdr; p->vec[NET_TX_PKT_L2HDR_FRAG].iov_base =3D &p->l2_hdr; p->vec[NET_TX_PKT_L3HDR_FRAG].iov_base =3D &p->l3_hdr; =20 @@ -617,9 +614,11 @@ static bool net_tx_pkt_do_sw_fragmentation(struct NetT= xPkt *pkt, =20 bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc) { + bool using_vnet_hdr =3D qemu_get_using_vnet_hdr(nc->peer); + assert(pkt); =20 - if (!pkt->has_virt_hdr && + if (!using_vnet_hdr && pkt->virt_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { net_tx_pkt_do_sw_csum(pkt); } @@ -636,11 +635,13 @@ bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientS= tate *nc) } } =20 - if (pkt->has_virt_hdr || + if (using_vnet_hdr || pkt->virt_hdr.gso_type =3D=3D VIRTIO_NET_HDR_GSO_NONE) { + int index =3D using_vnet_hdr ? + NET_TX_PKT_VHDR_FRAG : NET_TX_PKT_L2HDR_FRAG; net_tx_pkt_fix_ip6_payload_len(pkt); - net_tx_pkt_sendv(pkt, nc, pkt->vec, - pkt->payload_frags + NET_TX_PKT_PL_START_FRAG); + net_tx_pkt_sendv(pkt, nc, pkt->vec + index, + pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - index); return true; } =20 diff --git a/hw/net/net_tx_pkt.h b/hw/net/net_tx_pkt.h index 2e38a5fa69..8d3faa42fb 100644 --- a/hw/net/net_tx_pkt.h +++ b/hw/net/net_tx_pkt.h @@ -32,10 +32,9 @@ struct NetTxPkt; * @pkt: packet pointer * @pci_dev: PCI device processing this packet * @max_frags: max tx ip fragments - * @has_virt_hdr: device uses virtio header. */ void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev, - uint32_t max_frags, bool has_virt_hdr); + uint32_t max_frags); =20 /** * Clean all tx packet resources. diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index d7d492ac5a..eab8fa4d0b 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -1521,8 +1521,7 @@ static void vmxnet3_activate_device(VMXNET3State *s) =20 /* Preallocate TX packet wrapper */ VMW_CFPRN("Max TX fragments is %u", s->max_tx_frags); - net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s), - s->max_tx_frags, s->peer_has_vhdr); + net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s), s->max_tx_frags); net_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr); =20 /* Read rings memory locations for RX queues */ @@ -2402,8 +2401,7 @@ static int vmxnet3_post_load(void *opaque, int versio= n_id) { VMXNET3State *s =3D opaque; =20 - net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s), - s->max_tx_frags, s->peer_has_vhdr); + net_tx_pkt_init(&s->tx_pkt, PCI_DEVICE(s), s->max_tx_frags); net_rx_pkt_init(&s->rx_pkt, s->peer_has_vhdr); =20 if (s->msix_used) { --=20 2.39.1