From nobody Sat Nov 23 20:04:03 2024 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=1731307309; cv=none; d=zohomail.com; s=zohoarc; b=WTA3VMyHAeq8747AbPqOJ6KUsDxRg39iB9iSvEWD7avpei2SogJsSDjySSrHqaBu0sWNLJnVSokyZUXx2nmyWnSVx7UY8RCjSDhbgadHr0QLeIsD9GN/lMnSn/ONqcZA4W4EOmcymMsKMe3VOQDa8RJWRMYt5n6lo0ARCnJEynQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307309; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pcm3TKfU601RmQ0HaOlFX8GbZkHqQu7xV7Of6HtMoeg=; b=m60JFeRzjMpC5TDig5mHCJC1cQyZcMjfoCtdO7syAk0aU5llfqTnd+U9uRh1pyIivxtVW7UYTxRlRpBF/8f60SN1XyI9nXwy+sxPID5o6mBGCZw1y66MxqwaLmhnzYeCIQACIw1onaY3QHh1iaK3Pw7CADWGuJOA4xP9mccmqfw= 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 1731307309137592.2779167355849; Sun, 10 Nov 2024 22:41:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6f-0006kB-U9; Mon, 11 Nov 2024 01:41:01 -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 1tAO6U-0006jE-IK for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:51 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6S-0000ec-LX for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:50 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20cdbe608b3so41254435ad.1 for ; Sun, 10 Nov 2024 22:40:48 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21177dc7de7sm69635665ad.47.2024.11.10.22.40.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307247; x=1731912047; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Pcm3TKfU601RmQ0HaOlFX8GbZkHqQu7xV7Of6HtMoeg=; b=EvCnIlpKLaEdDxaAhXv3vQRk0TX07Mg5SwaSNUU5EXSmvhZHG1yFxMTtIH2sO2TzYA /kcURRUpKzBBBXpCC1p1Uv+v6oPRcpSPeuj2m9augUlSvpLAPegSZbZ8zklmCMxva7hO VG4+HMu0MR14rgJNthxXX0XgRiZ1Nc69+j+KnBe//zg4Vka5HcmxuK9rITgEzHFmMN3M nvd2EwaQqA6hnaejjTdnRicMK+bRXysCGk8LETMYpXmjWGa9cy7oI0z9fzuhD1U8sp98 laPygwQZX1cl98x3v8wAP8RnLSJ5WeYPOYAX+WKlWpwslHSkBeLs2F6us+98Mq0k38hj DVtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307247; x=1731912047; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pcm3TKfU601RmQ0HaOlFX8GbZkHqQu7xV7Of6HtMoeg=; b=ie/OoBI63t/ph878rdmGbK5Sss6EKwOeWSDwpqcDJM0X7ZHQyRIuE6ZmmKbtIftXyH E9+prr7enz2nAuLkkSPTpqVr/IsNRSOa5VBOkYUcMO2uYUPKjKjsuD5EsvS+3OZREPYb A52b5cfmDQ4Po6zYuLiKiPnwwrDEzky7QwncC6VqjndZuO1gV0aZqRqwnYFntiglF+gY UCO1XCRn1Otkt/24a0aBxKLtNPGg/YputN0U/AuPMkQnP4VXQL5Kux606XZ1qsrBefIO TgsBf/v+NcObtOQxXiWH1pIrUQEMd269wWr+lyhQ4HudgXLCOme9IslU/S7k8/lcm4Il o/kQ== X-Gm-Message-State: AOJu0YwLx3o/J6ZFwooLebnzC+m5E3bGNAfAfWU0ACapvsEnivTWEeS0 9AGGdx2mOpycBY5+dvHFi7hPcH3K/1p+wbYG+RL6g+7bXpzZ0aQldKioPiAzN+U= X-Google-Smtp-Source: AGHT+IFG+NV9N7pZBuK0NILGjfQCnzQXU937TWZovCxgRrjEZt4rZSfXFO5Xyw8qXEi8aHtdEX1Apg== X-Received: by 2002:a17:903:298c:b0:20c:ee32:759f with SMTP id d9443c01a7336-211835d8bc0mr173901275ad.39.1731307247144; Sun, 10 Nov 2024 22:40:47 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:18 +0900 Subject: [PATCH v2 1/6] net: checksum: Convert data to void * MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-1-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62d.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307310721116600 Convert the data parameter of net_checksum_calculate() to void * to save unnecessary casts for callers. Signed-off-by: Akihiko Odaki --- include/net/checksum.h | 2 +- net/checksum.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/checksum.h b/include/net/checksum.h index 7dec37e56c78..188e4cca0b7f 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -30,7 +30,7 @@ uint32_t net_checksum_add_cont(int len, uint8_t *buf, int= seq); uint16_t net_checksum_finish(uint32_t sum); uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, uint8_t *addrs, uint8_t *buf); -void net_checksum_calculate(uint8_t *data, int length, int csum_flag); +void net_checksum_calculate(void *data, int length, int csum_flag); =20 static inline uint32_t net_checksum_add(int len, uint8_t *buf) diff --git a/net/checksum.c b/net/checksum.c index 1a957e4c0b10..537457d89d07 100644 --- a/net/checksum.c +++ b/net/checksum.c @@ -57,7 +57,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t pr= oto, return net_checksum_finish(sum); } =20 -void net_checksum_calculate(uint8_t *data, int length, int csum_flag) +void net_checksum_calculate(void *data, int length, int csum_flag) { int mac_hdr_len, ip_len; struct ip_header *ip; @@ -101,7 +101,7 @@ void net_checksum_calculate(uint8_t *data, int length, = int csum_flag) return; } =20 - ip =3D (struct ip_header *)(data + mac_hdr_len); + ip =3D (struct ip_header *)((uint8_t *)data + mac_hdr_len); =20 if (IP_HEADER_VERSION(ip) !=3D IP_HEADER_VERSION_4) { return; /* not IPv4 */ --=20 2.47.0 From nobody Sat Nov 23 20:04:03 2024 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=1731307309; cv=none; d=zohomail.com; s=zohoarc; b=eTQwcumWjnHY4CC1Gs15QOmDDrf5f0SmuiptmeX3NWOTky16CTi7jgDqU5qRuUkes3Id1V8RF1Rgy799hrbdteGnbyIMpfQaPPQHTqfIiL64qOxgVgvHmm7iYOdgfq7PGJuhI9ohAz0ShukpUnoF3kF6TtdrU6/Tp7LJ3wROQpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307309; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BOsglgpsLx9wpsaJb8iY+XQFXuDJKY3A8oUUKLrc94g=; b=aF2nnJ8PBf1NRFjA+wbiRK4jbfimKIr+NQWQ6ZupFaxmt8Ao05xrxCNDsGGMRNVkvC0IZKjZN46ybcZY2YMFJu7V01tL6VslajrO91w303F3zd3GB6LMhQA1DC7gWxoTHTEYWZjtyrooFYBGPcaOYyqKs3vGLubO+YwlfuWUJYY= 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 1731307309137978.7082328977565; Sun, 10 Nov 2024 22:41:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6l-0006mG-5G; Mon, 11 Nov 2024 01:41:08 -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 1tAO6X-0006jh-G6 for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:55 -0500 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6W-0000ev-1O for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:53 -0500 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so3065408a12.3 for ; Sun, 10 Nov 2024 22:40:51 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21177e41890sm69268275ad.147.2024.11.10.22.40.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:40:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307250; x=1731912050; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BOsglgpsLx9wpsaJb8iY+XQFXuDJKY3A8oUUKLrc94g=; b=oX+AzBVAZfs3QnBgqGdB7krQwGahc8jMmx3TpVp2UK0gKT/GOf2PdXlj24CYse09Id ZfD2qi4Tn8u+o2FOrb5jq//76hHy27uOFahH5iFygeix8c2LjPwm6i1OO1QuS8pHVgGA Bg4AON2wVGjN6B58kL+ZJY9dq55jp4zUYEf91FAt4YmskddiRlmiB6K3LD/ABP2dS3a6 cFII8qcja9eiWv39tEvbjs3PRbZJ7ou205/vNNwqsvMUcfJwnZgtITJabrTq8xuuBCx+ w909cPn7K1dpbHVn58Ib1bcRrHLAnf7nLyfQ6wYnfcsBEKwU8KMrk+sPacgiiySyVDJi mN6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307250; x=1731912050; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BOsglgpsLx9wpsaJb8iY+XQFXuDJKY3A8oUUKLrc94g=; b=lX87zgn82JcYXr7cwnu1jK0wdxen6hpP1BivoZooAeL25GCAFHaV8v61qBDQ8pxIVb wrwuUYCpzk9Ew8C/FyvYC+87ytu9iNT363WbYBGeGE18mkwGkQyWOevzDKHOW+9orjd3 ibliwGxBoy9O6B+mJwO2ZQ/0q8KLGhv/eUOWacRvZLcmJ3NmsEuiVfKFBiF7u7mqsqsE 1GqvPR9guiKccX4aaq4Qv06NcMvr6RRDAy1j8btQ8dv0tlk/RiaJYiZS2WTeaMfhrm9K ZSkWPqMioUhMmNoKc2mcyusPXVEHFeTHL2qy0kKvtgMo9ijXLXkfvtfGiIv1JK2JK0ty hgAQ== X-Gm-Message-State: AOJu0Ywg5fA9D3mTxXo7S/3acOm6Fs9TQMM1HmL1pnc+5CKLV3poAysA xYqtfTyyPKyrtsIB3C/xkVf6WmuXMHbOP3jEqa/rN2WljFoFGtq4zJUGBLZACzE= X-Google-Smtp-Source: AGHT+IG36MJY2TmBKfT+kmxNeZIzbpQkWmKvA7O+ozCy0TDKqUximtg9pDtUWdeM0mQQj31KTqbBCA== X-Received: by 2002:a05:6a20:394b:b0:1db:e501:682d with SMTP id adf61e73a8af0-1dc22b59d1amr18018685637.33.1731307250373; Sun, 10 Nov 2024 22:40:50 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:19 +0900 Subject: [PATCH v2 2/6] virtio-net: Fix size check in dhclient workaround MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-2-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki , qemu-stable@nongnu.org X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307310711116600 work_around_broken_dhclient() accesses IP and UDP headers to detect relevant packets and to calculate checksums, but it didn't check if the packet has size sufficient to accommodate them, causing out-of-bound access hazards. Fix this by correcting the size requirement. Fixes: 1d41b0c1ec66 ("Work around dhclient brokenness") Cc: qemu-stable@nongnu.org Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index fb84d142ee29..62e396e8d2fd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1692,8 +1692,11 @@ static void virtio_net_hdr_swap(VirtIODevice *vdev, = struct virtio_net_hdr *hdr) static void work_around_broken_dhclient(struct virtio_net_hdr *hdr, uint8_t *buf, size_t size) { + size_t csum_size =3D ETH_HLEN + sizeof(struct ip_header) + + sizeof(struct udp_header); + if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */ - (size > 27 && size < 1500) && /* normal sized MTU */ + (size >=3D csum_size && size < 1500) && /* normal sized MTU */ (buf[12] =3D=3D 0x08 && buf[13] =3D=3D 0x00) && /* ethertype =3D= =3D IPv4 */ (buf[23] =3D=3D 17) && /* ip.protocol =3D=3D UDP */ (buf[34] =3D=3D 0 && buf[35] =3D=3D 67)) { /* udp.srcport =3D=3D b= ootps */ --=20 2.47.0 From nobody Sat Nov 23 20:04:03 2024 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=1731307334; cv=none; d=zohomail.com; s=zohoarc; b=YYhoWUpAQZyx8/BTewO1+MBB2AVbgq0pq9F2Pt78VoYnAF6v6XylglwH5Jx04PGljnMUcdy+ef1pcuSKHmwwX7J+ckmayYM4Jf5VPXTyOvB7eULBJ4JwoHIekA9aYoxVUlhmk6EI6RLEBAl2qXFT9k/57tUlqAonpZEJ1Sez5c4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307334; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zpfc6hr6Bhw+kRs25skm7ehABQwj5ycjd/6KochPE+0=; b=JCu1dIFJk3NHHldmoHa4WiHWy0R4ZbUtNibmIvTgoTP5xteGM137r8net0MMxaSsz1bTTwkP/JSpREdzlhpTolWRahHUSkTYgl3wWgVuVgxIwb1xBPki7ThzML9eKm2PXNy9j233YsuszQZfAz40wliaLrJn5y2O/CDumWIkAGY= 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 1731307334240210.81864817132112; Sun, 10 Nov 2024 22:42:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6q-0006nB-U5; Mon, 11 Nov 2024 01:41:12 -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 1tAO6b-0006kF-FT for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:59 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6Z-0000fG-Km for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:57 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-71e79f73aaeso3350461b3a.3 for ; Sun, 10 Nov 2024 22:40:54 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-724078a7f2esm8312075b3a.49.2024.11.10.22.40.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:40:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307253; x=1731912053; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zpfc6hr6Bhw+kRs25skm7ehABQwj5ycjd/6KochPE+0=; b=070586pRTmnMiZtzh20a+2K+j2jjj12EOOEykEdZCWGf9wI+6KTMweBRGou7MyS/gS B3Rqmj454a0e5ikKfo8UyEup0JoVRedf7hXjn0SrSmcaCQQUcv8APD8XhJFYXBivplw9 mHImWJMf6oBQVGkFy6r4HqpcVVFcwyzBrVh4NxAn1nsct4nWPc1CeO86+5LzX88+6BS1 C+HYJ/cPDfdUBAtD0ck/0ko5n40lJeLDx2oR5sDb0OLea950/HUnlLngFwfh6eVho25U 4IF5h4k0FWZ3tC6okdzHODH5Y0dxS6n1dYKerhejC2Mg8XfH4D3rjrRSfiA3ybVeOniy VY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307253; x=1731912053; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zpfc6hr6Bhw+kRs25skm7ehABQwj5ycjd/6KochPE+0=; b=b1C+Kn9rgFXgbVC6MWSepdu0r+NdKTe+DWhNHLpFDkDbdUoV2P9JegopV6xxLKTBWc jOSEVr6D06itfyOY0wy+Zd5CVpCeQKxXtcgfOkoaSSUjSHIrXi3aoXfMNmNWgbsqjoiX NfOx1MOcBKR/MYcmOivdAE3TNoeZZhMPcSIHV280pVHvhN0mdwARj4pDq+EhxHSpyc9t W/vrq3MFBbuAoOHRGeF/Usd2AdjZ3sACW7fN4zsTLEwMsezIqSCUgZtH1ZjkXF4nnOp0 ROKSzrIyTd3/8qSpcfyHgglSrjfWnj+UMWTIlLW+ZytIefuPHVYNVJcPSb2TBlelU53H vOZg== X-Gm-Message-State: AOJu0YxayEfUbo5Es8Yn741GCqY6cFvbmC9ExP5MY1aXBg4itgQ06Fl6 wIgSAIxHEmPeZakDd8xOWf5d2BQ8Y/wop3gudB7UAwWTAXbLOzr15QgXbYne7gc= X-Google-Smtp-Source: AGHT+IGl4h4z2bcEIbZBzIwMkIIpeSCu1+s+Pb0flQINgKnXyjyGw65+pSZ+y68rivQbNAPzGi4j/Q== X-Received: by 2002:a05:6a21:c20c:b0:1dc:3a8:7fc0 with SMTP id adf61e73a8af0-1dc22b85620mr9280307637.46.1731307253394; Sun, 10 Nov 2024 22:40:53 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:20 +0900 Subject: [PATCH v2 3/6] virtio-net: Do not check for the queue before RSS MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-3-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::435; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x435.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307336663116600 virtio_net_can_receive() checks if the queue is ready, but RSS will change the queue to use so, strictly speaking, we may still be able to receive the packet even if the queue initially provided is not ready. Perform RSS before virtio_net_can_receive() to cover such a case. Fixes: 4474e37a5b3a ("virtio-net: implement RX RSS processing") Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 62e396e8d2fd..abbb22e40f9f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1906,10 +1906,6 @@ static ssize_t virtio_net_receive_rcu(NetClientState= *nc, const uint8_t *buf, size_t offset, i, guest_offset, j; ssize_t err; =20 - if (!virtio_net_can_receive(nc)) { - return -1; - } - if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss= ) { int index =3D virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >=3D 0) { @@ -1919,6 +1915,10 @@ static ssize_t virtio_net_receive_rcu(NetClientState= *nc, const uint8_t *buf, } } =20 + if (!virtio_net_can_receive(nc)) { + return -1; + } + /* hdr_len refers to the header we supply to the guest */ if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_l= en)) { return 0; --=20 2.47.0 From nobody Sat Nov 23 20:04:03 2024 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=1731307318; cv=none; d=zohomail.com; s=zohoarc; b=d0eIIAKRBvqW95YVxKJMhcGEmnN4/uDZAgPvLCq0TA3FkfT5KdXTxUYkJpd2Mju9lZ92lEb5DydY1gYkbRpAHR6ltqryKeWKmDLtzGDb6sx/XB+5RYyeBqshgjCkllND7dgGe0Jkbna77bw4hHKjFdapQeFTJYnN/G2Sxk5wuJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307318; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NDL1NP5K5bOcbgjLwqMXNqM37U/dezgHiGmS6DKu8Qk=; b=JG2CBfhcBm7QD0u5x2fTkQcMt9wOazZ4MpzaA5PnKWuNDIK9jvOlmwZbSQPUKot5cXJRdYkhQRFq3a6gdnvo0N492sTGkYSSoB7hDfcs1syWCic8zRpaB3gfGvnnISx+glegpzJX59jru/cEQAOFkcLFdqpiWONKtZI8cdaQo9E= 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 1731307318509104.81071376177022; Sun, 10 Nov 2024 22:41:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6n-0006mK-81; Mon, 11 Nov 2024 01:41:09 -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 1tAO6d-0006kb-OI for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:41:01 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6c-0000fS-13 for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:40:59 -0500 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-720c286bcd6so3489868b3a.3 for ; Sun, 10 Nov 2024 22:40:57 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7f41f65ba85sm6592719a12.73.2024.11.10.22.40.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:40:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307256; x=1731912056; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NDL1NP5K5bOcbgjLwqMXNqM37U/dezgHiGmS6DKu8Qk=; b=ycDPGvrq4KnaKIoePLh9Kj3w/H3f5HXl7HZU2nyg6/6gCFeacEzCfe910t/wDW0i7D rQoUskQj1PCfScskgqVVXqMkpEapl0UbvgAfC/ZmaLcyg1slZmsBfpovfkhbH7SynDPB 7y+7u2cErpLvmNBieRgpvksXXqgwgBrAJiV+T4yrHHGd6Ft5ZamNvJOf6TJV39Dyv5S/ 8qbRx+l6gBsFrxckJOPYOZb/uQS4fwLVjiBbYQR08rMxzSaMvTVTd/pFN4KtcPMJU+xN EIvEXxBX7WCm2vg04/54Yvf7J/Sooa/GhsYCcB/KhpQ9V6QNLhk/IFcfdReDbkPEc10/ ZEfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307256; x=1731912056; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NDL1NP5K5bOcbgjLwqMXNqM37U/dezgHiGmS6DKu8Qk=; b=Wz88dEFhPzcP6n2zd+sE/en+x2pNFOk+3zKWZFEf7bv8/Em/r72tLstiVN+R5lgy/L VZjYLtEo1lA59CvsuRKl5U5BlwzkEAg6qbm69TuOCcfSkBlw8SAGIhEtHHwXzi4QrDCq jVe8XrmoT67XJKmPuqp0smKMJj1d5nofskHcjjVg9zeQzfft0CpIpda4wtxhRE/mQQSE 11ySyhj+R9evRB/BNDV0coItVYv9Lf+LYys6H6mCABZH84M/Io6tgO6vdSpI8pJ0q6oz hxR+VR+Uzoj5cygBzswh+vvBcXk3cR4nWVzWQ6maRJ4nHYi6QUD/A0oyYXVa66PvBQTG iXhA== X-Gm-Message-State: AOJu0YwlRV63p7XGfMIW4yu8QXJDPQ3v6IkX5UZvzVjp6bACLE7g9Uwg lpaRcDPTctk6pu3uwwWIwKkqKO9tJZ+94G+yZyJvr9gQaZEcteZrzJ3G+1FHzw1OkjHikjSs702 T478= X-Google-Smtp-Source: AGHT+IEeJypxeoDWAw0eQrX+DZKq6GfD9f0nw7qWXwk9EnPz1rcpjHJJOPOt3SYzlJbuU9V83FKPYQ== X-Received: by 2002:a05:6a21:398:b0:1dc:e:e996 with SMTP id adf61e73a8af0-1dc22b63711mr15829369637.33.1731307256423; Sun, 10 Nov 2024 22:40:56 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:21 +0900 Subject: [PATCH v2 4/6] virtio-net: Fix hash reporting when the queue changes MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-4-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42b.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307320319116600 virtio_net_process_rss() fills the values used for hash reporting, but the values used to be thrown away with a recursive function call if the queue changes after RSS. Avoid the function call to keep the values. Fixes: a4c960eedcd2 ("virtio-net: Do not write hashes to peer buffer") Buglink: https://issues.redhat.com/browse/RHEL-59572 Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index abbb22e40f9f..ea5faaf16422 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1893,10 +1893,10 @@ static int virtio_net_process_rss(NetClientState *n= c, const uint8_t *buf, } =20 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *b= uf, - size_t size, bool no_rss) + size_t size) { VirtIONet *n =3D qemu_get_nic_opaque(nc); - VirtIONetQueue *q =3D virtio_net_get_subqueue(nc); + VirtIONetQueue *q; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); VirtQueueElement *elems[VIRTQUEUE_MAX_SIZE]; size_t lens[VIRTQUEUE_MAX_SIZE]; @@ -1906,12 +1906,10 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, size_t offset, i, guest_offset, j; ssize_t err; =20 - if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss= ) { + if (n->rss_data.enabled && n->rss_data.enabled_software_rss) { int index =3D virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >=3D 0) { - NetClientState *nc2 =3D - qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); - return virtio_net_receive_rcu(nc2, buf, size, true); + nc =3D qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); } } =20 @@ -1919,6 +1917,8 @@ static ssize_t virtio_net_receive_rcu(NetClientState = *nc, const uint8_t *buf, return -1; } =20 + q =3D virtio_net_get_subqueue(nc); + /* hdr_len refers to the header we supply to the guest */ if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_l= en)) { return 0; @@ -2044,7 +2044,7 @@ static ssize_t virtio_net_do_receive(NetClientState *= nc, const uint8_t *buf, { RCU_READ_LOCK_GUARD(); =20 - return virtio_net_receive_rcu(nc, buf, size, false); + return virtio_net_receive_rcu(nc, buf, size); } =20 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, --=20 2.47.0 From nobody Sat Nov 23 20:04:03 2024 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=1731307347; cv=none; d=zohomail.com; s=zohoarc; b=FbmkztAoGhYkqGoilC/FJQBifFMD4fu0bxG/lAdjz54FMK2L08TbIp4poEA21U7rOctRTNgUUYcXNb7Ia7MQT2NYlVnEssJtVPIu1XTra6Ruc+dphsy1/MJJo3VhkvgndSXE1k0UfzQ/H5veaaMGuv4Jpg+dK1o0GfJZTYTaoF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307347; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OF0blgGURLI6/qj69njTogJlHYc2TMJS/oPKbo52yMk=; b=LltCOEUBWUKjFQ8Rl85g8GJNedJp21W45UOD2r29cY5h5/rfieo9jIpSdwphDuu8lV9bIPb8ZILczY75QhbbaHzerLYo6joGAiYFhSMb4XlkeVmdoEibTV+Orfry13mo+/AQ6gwd4zgny3tE0LWW6ZuYbtzKQ46uW3olMPmYYsE= 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 173130734787596.97407486093175; Sun, 10 Nov 2024 22:42:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6r-0006nU-JC; Mon, 11 Nov 2024 01:41:13 -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 1tAO6g-0006l8-6m for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:41:03 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6e-0000fk-QD for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:41:01 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-20c7ee8fe6bso39391455ad.2 for ; Sun, 10 Nov 2024 22:41:00 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21177dc9e30sm69107265ad.43.2024.11.10.22.40.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:40:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307259; x=1731912059; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OF0blgGURLI6/qj69njTogJlHYc2TMJS/oPKbo52yMk=; b=XepsltmPcHkjJ/IhVigx3qo49MpNfWHsoTCIjqK0fkk7kYo+StqfwySqNh5A9s9pLl Oa0uTrTu2aFuU2XBxrJMSPzN++07XeeZ60DOkE7mGKnJz/ftob1jcCRFYKrudMMcg3Vt FaBZpHlD8G0G0A6KssdIiqCGl3VIpWjMM/Qsz1SL+J4TzS+lCbwPhb8jQE5O9BEB5pU4 m76pSYjJYB7Pmj7YiHD1UuB3wG3SFEwty+6+e7QEycyNNzxE5tgCh+r/+rJjfSh+J8B/ h/8OwhWa0VY7WtDeefXab9cX+CYO99MPepJcs6IRhL0/e20yr5Dvgx50hKRkqDJgDPRR T8IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307259; x=1731912059; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OF0blgGURLI6/qj69njTogJlHYc2TMJS/oPKbo52yMk=; b=YGz5UANsEbj1oFcEoL0uki2DtD93PvvpJ2Th790klvOHRqppeJSEtEKP5DtQzA4mEw HLJwlU31qrdUmFctvhJioXn4nb1VL93ToptkfY1KNp6jqgTbHZ987K6NuYfQuN0hgwaZ wVOJVf0wuV7iwB0mGgJWNrtDD8ZGEJF/27ltwxPPt3gkm14JEdaSrEK7BJdYg7UszeoD LCpRFRyuXCdymbC85hQRO3Rjc/EkXlYpbtivGdA9paOitjSlEJmMNNEOwlnuYDMgjFxW lQ87aP68hYiMQSyygbGG/ss9AfDC9LLZVkmTg4uveAnP+IV8nnER8DyjswiW6acpUeiQ RG5Q== X-Gm-Message-State: AOJu0YyN2tQLXH/KuTafvBuiabCxKpcrG4BRZ0sip2dk7mylcPIYq1Gs F5xy9ht1MdpUjHhWTqn24To0XfO36yNO9k1doP8VVzCG2En9L1diESk6DfHQoq4= X-Google-Smtp-Source: AGHT+IEwVLBpluVmTb51SVyrnEBNtvRdwK3/SBQEgV563QSLvoGy6Y71DGi2BoL/MT9yc2Ybu9yXjA== X-Received: by 2002:a17:903:2304:b0:20c:8df8:5066 with SMTP id d9443c01a7336-21183e0c466mr160734935ad.45.1731307259429; Sun, 10 Nov 2024 22:40:59 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:22 +0900 Subject: [PATCH v2 5/6] virtio-net: Initialize hash reporting values MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-5-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307348554116600 The specification says hash_report should be set to VIRTIO_NET_HASH_REPORT_NONE if VIRTIO_NET_F_HASH_REPORT is negotiated but not configured with VIRTIO_NET_CTRL_MQ_RSS_CONFIG. However, virtio_net_receive_rcu() instead wrote out the content of the extra_hdr variable, which is not uninitialized in such a case. Fix this by zeroing the extra_hdr. Fixes: e22f0603fb2f ("virtio-net: reference implementation of hash report") Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index ea5faaf16422..e75a8bb1f27a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1906,6 +1906,8 @@ static ssize_t virtio_net_receive_rcu(NetClientState = *nc, const uint8_t *buf, size_t offset, i, guest_offset, j; ssize_t err; =20 + memset(&extra_hdr, 0, sizeof(extra_hdr)); + if (n->rss_data.enabled && n->rss_data.enabled_software_rss) { int index =3D virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >=3D 0) { --=20 2.47.0 From nobody Sat Nov 23 20:04:03 2024 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=1731307308; cv=none; d=zohomail.com; s=zohoarc; b=MnFwzM27mnEhh11FDK5YL7zougo6kpxIst78W15hslpsYEmdUKdDXg4P160BMOlPOcvNXOvVRyvoMsZvhr8qtaUgps1RYKyQl1ie8hZASv6XS6ghNtx8V2ZbzUv7+5r5yNuSBSf4p5VnCRfLFimpw2lX5slmBxle/GU+Owgdnsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731307308; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UntqNh0SSDcPg0A4KG+9ffl5JXbQpD+82Atqct3kXec=; b=lKBh4xWwGozAcKeMOm5GhCfZrRRUM5bhuByUKas0zERSKKR/T9GVybNCIWlP5XBmfZOzns9LPGRWnv24G0ixOcNSsHhMVPV3Ehz3MMkvbiav0GyFLzh2b4x0IY4sqfW8dmRuJw14du4tKPLxXey+5degbFFnjQ+zxQwHnLCSJsE= 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 1731307308156199.55258371517664; Sun, 10 Nov 2024 22:41:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAO6s-0006nu-V1; Mon, 11 Nov 2024 01:41:14 -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 1tAO6k-0006mH-Vy for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:41:07 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAO6i-0000fv-Dh for qemu-devel@nongnu.org; Mon, 11 Nov 2024 01:41:05 -0500 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2e2ed2230d8so3336434a91.0 for ; Sun, 10 Nov 2024 22:41:04 -0800 (PST) Received: from localhost ([157.82.207.107]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e9a5f5e5bcsm7870354a91.15.2024.11.10.22.41.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2024 22:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1731307263; x=1731912063; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UntqNh0SSDcPg0A4KG+9ffl5JXbQpD+82Atqct3kXec=; b=aPAZHvzpBHf6Xn7AEx/wA3owP/SCzGNSN9Ac/IfK8lM9fQ9GowXRvTc8ZxlFiYCQLB v3HBTBT9l0W+MJ27/SBVs68buQsJVkebmuFmqUeHzf6AZcSjXdIusdXTXdONUI4lq6sc uF7KUmM6fR3+TL13dopHt4E7lciqLJ1qf7+v9xKZOcvCjUlNcIKgRJXnwhNc7iPqrjqV +gTAmXNYJnM6vxtHDH2mMaVtdgGxNiFxUsjOnAB9FuK7BhbrsQ669XejqeSbASTjUC0X lv3q2AEIkD/SGgJ6ZV0+xwK6SRmekROBuCwbLm2wuUhBFTp4+3aeaEEPzxK+P9dGVidJ +dwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731307263; x=1731912063; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UntqNh0SSDcPg0A4KG+9ffl5JXbQpD+82Atqct3kXec=; b=DqGVYzgSoWyS1oBctoJh4PnqPnVutIHiqW7mX6ows7Y2QJG+0WWYTYU23kKTOVvIlk CMdbjqLEYnc1qqyvq7yhQGsxRXApAIYKw0Hai4OVmbORIhSnopv/j3jNWBAMGX2JNE8O JijbkmQUBhqaehBBd3U6+b0++hNCC5bk+xSmezkwh4pCUDF3rz1KfXtVgH0OdfVJ2iU+ Vha70Rnn7bpc8PpAh8fQOmVueTbnY0CNOEj3AMpCpa7y4bKWmfVBgYm89qSShMyBoRRK oJmaTg9Qv8+UHsYuFpqEQqRA15xTNjnRSDlrom4+Ly4s+gyKt+1RiIBe5vqzK7pu0GMp c4hw== X-Gm-Message-State: AOJu0Yxuj+RSNcyToy2Um51hLhh5lOB7Z9cYDCp5dUJDN8i+hItQmEPR ddEDfJacpSt2sHiGYOHX0L2w721HYCNBoWfN1FqAdnPaivROmG8ena527Badijw= X-Google-Smtp-Source: AGHT+IEbUGTu2wZSnZqwvRKYgEq17cts1XTgibILmFWBQif5pVnKSDDx43A32MDjDu1eDosWCCaXHg== X-Received: by 2002:a17:90b:2749:b0:2e2:d7db:41fa with SMTP id 98e67ed59e1d1-2e9b1781541mr16638061a91.33.1731307263025; Sun, 10 Nov 2024 22:41:03 -0800 (PST) From: Akihiko Odaki Date: Mon, 11 Nov 2024 15:40:23 +0900 Subject: [PATCH v2 6/6] virtio-net: Copy received header to buffer MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241111-queue-v2-6-2f7883a1004f@daynix.com> References: <20241111-queue-v2-0-2f7883a1004f@daynix.com> In-Reply-To: <20241111-queue-v2-0-2f7883a1004f@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, devel@daynix.com, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1035.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_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: 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.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1731307310834116600 receive_header() used to cast the const qualifier of the pointer to the received packet away to modify the header. Avoid this by copying the received header to buffer. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 85 +++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e75a8bb1f27a..10fc43064e13 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1690,41 +1690,44 @@ static void virtio_net_hdr_swap(VirtIODevice *vdev,= struct virtio_net_hdr *hdr) * cache. */ static void work_around_broken_dhclient(struct virtio_net_hdr *hdr, - uint8_t *buf, size_t size) + size_t *hdr_len, const uint8_t *bu= f, + size_t buf_size, size_t *buf_offse= t) { size_t csum_size =3D ETH_HLEN + sizeof(struct ip_header) + sizeof(struct udp_header); =20 + buf +=3D *buf_offset; + buf_size -=3D *buf_offset; + if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */ - (size >=3D csum_size && size < 1500) && /* normal sized MTU */ + (buf_size >=3D csum_size && buf_size < 1500) && /* normal sized MT= U */ (buf[12] =3D=3D 0x08 && buf[13] =3D=3D 0x00) && /* ethertype =3D= =3D IPv4 */ (buf[23] =3D=3D 17) && /* ip.protocol =3D=3D UDP */ (buf[34] =3D=3D 0 && buf[35] =3D=3D 67)) { /* udp.srcport =3D=3D b= ootps */ - net_checksum_calculate(buf, size, CSUM_UDP); + memcpy((uint8_t *)hdr + *hdr_len, buf, csum_size); + net_checksum_calculate((uint8_t *)hdr + *hdr_len, csum_size, CSUM_= UDP); hdr->flags &=3D ~VIRTIO_NET_HDR_F_NEEDS_CSUM; + *hdr_len +=3D csum_size; + *buf_offset +=3D csum_size; } } =20 -static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_= cnt, - const void *buf, size_t size) +static size_t receive_header(VirtIONet *n, struct virtio_net_hdr *hdr, + const void *buf, size_t buf_size, + size_t *buf_offset) { - if (n->has_vnet_hdr) { - /* FIXME this cast is evil */ - void *wbuf =3D (void *)buf; - work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len, - size - n->host_hdr_len); + size_t hdr_len =3D n->guest_hdr_len; =20 - if (n->needs_vnet_hdr_swap) { - virtio_net_hdr_swap(VIRTIO_DEVICE(n), wbuf); - } - iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr)); - } else { - struct virtio_net_hdr hdr =3D { - .flags =3D 0, - .gso_type =3D VIRTIO_NET_HDR_GSO_NONE - }; - iov_from_buf(iov, iov_cnt, 0, &hdr, sizeof hdr); + memcpy(hdr, buf, sizeof(struct virtio_net_hdr)); + + *buf_offset =3D n->host_hdr_len; + work_around_broken_dhclient(hdr, &hdr_len, buf, buf_size, buf_offset); + + if (n->needs_vnet_hdr_swap) { + virtio_net_hdr_swap(VIRTIO_DEVICE(n), hdr); } + + return hdr_len; } =20 static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) @@ -1892,6 +1895,13 @@ static int virtio_net_process_rss(NetClientState *nc= , const uint8_t *buf, return (index =3D=3D new_index) ? -1 : new_index; } =20 +typedef struct Header { + struct virtio_net_hdr_v1_hash virtio_net; + struct eth_header eth; + struct ip_header ip; + struct udp_header udp; +} Header; + static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *b= uf, size_t size) { @@ -1901,15 +1911,15 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, VirtQueueElement *elems[VIRTQUEUE_MAX_SIZE]; size_t lens[VIRTQUEUE_MAX_SIZE]; struct iovec mhdr_sg[VIRTQUEUE_MAX_SIZE]; - struct virtio_net_hdr_v1_hash extra_hdr; + Header hdr; unsigned mhdr_cnt =3D 0; size_t offset, i, guest_offset, j; ssize_t err; =20 - memset(&extra_hdr, 0, sizeof(extra_hdr)); + memset(&hdr.virtio_net, 0, sizeof(hdr.virtio_net)); =20 if (n->rss_data.enabled && n->rss_data.enabled_software_rss) { - int index =3D virtio_net_process_rss(nc, buf, size, &extra_hdr); + int index =3D virtio_net_process_rss(nc, buf, size, &hdr.virtio_ne= t); if (index >=3D 0) { nc =3D qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); } @@ -1974,21 +1984,18 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, if (n->mergeable_rx_bufs) { mhdr_cnt =3D iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg), sg, elem->in_num, - offsetof(typeof(extra_hdr), hdr.num_bu= ffers), - sizeof(extra_hdr.hdr.num_buffers)); + offsetof(typeof(hdr), + virtio_net.hdr.num_buffers), + sizeof(hdr.virtio_net.hdr.num_buffers)= ); } =20 - receive_header(n, sg, elem->in_num, buf, size); - if (n->rss_data.populate_hash) { - offset =3D offsetof(typeof(extra_hdr), hash_value); - iov_from_buf(sg, elem->in_num, offset, - (char *)&extra_hdr + offset, - sizeof(extra_hdr.hash_value) + - sizeof(extra_hdr.hash_report)); - } - offset =3D n->host_hdr_len; - total +=3D n->guest_hdr_len; - guest_offset =3D n->guest_hdr_len; + guest_offset =3D n->has_vnet_hdr ? + receive_header(n, (struct virtio_net_hdr *)&hdr, + buf, size, &offset) : + n->guest_hdr_len; + + iov_from_buf(sg, elem->in_num, 0, &hdr, guest_offset); + total +=3D guest_offset; } else { guest_offset =3D 0; } @@ -2014,11 +2021,11 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, } =20 if (mhdr_cnt) { - virtio_stw_p(vdev, &extra_hdr.hdr.num_buffers, i); + virtio_stw_p(vdev, &hdr.virtio_net.hdr.num_buffers, i); iov_from_buf(mhdr_sg, mhdr_cnt, 0, - &extra_hdr.hdr.num_buffers, - sizeof extra_hdr.hdr.num_buffers); + &hdr.virtio_net.hdr.num_buffers, + sizeof hdr.virtio_net.hdr.num_buffers); } =20 for (j =3D 0; j < i; j++) { --=20 2.47.0