From patchwork Mon Nov 11 06:40:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870284 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 lists.gnu.org (lists.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 00A8DD12D7B for ; Mon, 11 Nov 2024 06:41:47 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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); 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 proto, return net_checksum_finish(sum); } -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; } - ip = (struct ip_header *)(data + mac_hdr_len); + ip = (struct ip_header *)((uint8_t *)data + mac_hdr_len); if (IP_HEADER_VERSION(ip) != IP_HEADER_VERSION_4) { return; /* not IPv4 */ From patchwork Mon Nov 11 06:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870285 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 lists.gnu.org (lists.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 F10EDD12D78 for ; Mon, 11 Nov 2024 06:41:47 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = 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 >= csum_size && size < 1500) && /* normal sized MTU */ (buf[12] == 0x08 && buf[13] == 0x00) && /* ethertype == IPv4 */ (buf[23] == 17) && /* ip.protocol == UDP */ (buf[34] == 0 && buf[35] == 67)) { /* udp.srcport == bootps */ From patchwork Mon Nov 11 06:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870288 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 lists.gnu.org (lists.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 312F9D12D79 for ; Mon, 11 Nov 2024 06:42:14 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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; - if (!virtio_net_can_receive(nc)) { - return -1; - } - if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss) { int index = virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >= 0) { @@ -1919,6 +1915,10 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, } } + 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_len)) { return 0; From patchwork Mon Nov 11 06:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870287 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 lists.gnu.org (lists.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 4E2D6D12D78 for ; Mon, 11 Nov 2024 06:41:58 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 *nc, const uint8_t *buf, } static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, - size_t size, bool no_rss) + size_t size) { VirtIONet *n = qemu_get_nic_opaque(nc); - VirtIONetQueue *q = virtio_net_get_subqueue(nc); + VirtIONetQueue *q; VirtIODevice *vdev = 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(NetClientState *nc, const uint8_t *buf, size_t offset, i, guest_offset, j; ssize_t err; - 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 = virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >= 0) { - NetClientState *nc2 = - qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); - return virtio_net_receive_rcu(nc2, buf, size, true); + nc = qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); } } @@ -1919,6 +1917,8 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, return -1; } + q = 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_len)) { return 0; @@ -2044,7 +2044,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf, { RCU_READ_LOCK_GUARD(); - return virtio_net_receive_rcu(nc, buf, size, false); + return virtio_net_receive_rcu(nc, buf, size); } static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, From patchwork Mon Nov 11 06:40:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870289 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 lists.gnu.org (lists.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 AD8ACD12D78 for ; Mon, 11 Nov 2024 06:42:27 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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; + memset(&extra_hdr, 0, sizeof(extra_hdr)); + if (n->rss_data.enabled && n->rss_data.enabled_software_rss) { int index = virtio_net_process_rss(nc, buf, size, &extra_hdr); if (index >= 0) { From patchwork Mon Nov 11 06:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13870286 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 lists.gnu.org (lists.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 5F697D12D7A for ; Mon, 11 Nov 2024 06:41:48 +0000 (UTC) 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) 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) 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) 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 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 *buf, + size_t buf_size, size_t *buf_offset) { size_t csum_size = ETH_HLEN + sizeof(struct ip_header) + sizeof(struct udp_header); + buf += *buf_offset; + buf_size -= *buf_offset; + if ((hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && /* missing csum */ - (size >= csum_size && size < 1500) && /* normal sized MTU */ + (buf_size >= csum_size && buf_size < 1500) && /* normal sized MTU */ (buf[12] == 0x08 && buf[13] == 0x00) && /* ethertype == IPv4 */ (buf[23] == 17) && /* ip.protocol == UDP */ (buf[34] == 0 && buf[35] == 67)) { /* udp.srcport == bootps */ - 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 &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM; + *hdr_len += csum_size; + *buf_offset += csum_size; } } -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 = (void *)buf; - work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len, - size - n->host_hdr_len); + size_t hdr_len = n->guest_hdr_len; - 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 = { - .flags = 0, - .gso_type = 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 = 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; } 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 == new_index) ? -1 : new_index; } +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 *buf, size_t size) { @@ -1901,15 +1911,15 @@ static ssize_t virtio_net_receive_rcu(NetClientState *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 = 0; size_t offset, i, guest_offset, j; ssize_t err; - memset(&extra_hdr, 0, sizeof(extra_hdr)); + memset(&hdr.virtio_net, 0, sizeof(hdr.virtio_net)); if (n->rss_data.enabled && n->rss_data.enabled_software_rss) { - int index = virtio_net_process_rss(nc, buf, size, &extra_hdr); + int index = virtio_net_process_rss(nc, buf, size, &hdr.virtio_net); if (index >= 0) { nc = qemu_get_subqueue(n->nic, index % n->curr_queue_pairs); } @@ -1974,21 +1984,18 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, if (n->mergeable_rx_bufs) { mhdr_cnt = iov_copy(mhdr_sg, ARRAY_SIZE(mhdr_sg), sg, elem->in_num, - offsetof(typeof(extra_hdr), hdr.num_buffers), - sizeof(extra_hdr.hdr.num_buffers)); + offsetof(typeof(hdr), + virtio_net.hdr.num_buffers), + sizeof(hdr.virtio_net.hdr.num_buffers)); } - receive_header(n, sg, elem->in_num, buf, size); - if (n->rss_data.populate_hash) { - offset = 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 = n->host_hdr_len; - total += n->guest_hdr_len; - guest_offset = n->guest_hdr_len; + guest_offset = 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 += guest_offset; } else { guest_offset = 0; } @@ -2014,11 +2021,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, } 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); } for (j = 0; j < i; j++) {