From patchwork Sun Sep 15 01:06:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=hiDR48N6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qgT17Xhz1y1T for ; Sun, 15 Sep 2024 11:08:53 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdj3-00014U-BB; Sat, 14 Sep 2024 21:06:53 -0400 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 1spdj2-0000zk-3x for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:52 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdj0-00049y-Jv for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:51 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2068bee21d8so35516785ad.2 for ; Sat, 14 Sep 2024 18:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362409; x=1726967209; 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=nyASwxYCvsAWNh9neSNt2c74xLjhwEcHZ/10RfBTDG4=; b=hiDR48N6aDcvyk8H+iKvRXOqMTDTtTV516zlxxv8hYxyJcyOXsYu6tiWaaNJd9h3RP 7zsw+slMHSUZkVWCaa/yiLOJn0CoeAjuQJfHCXtaO+hxIihgVfHTcVpVzxZw7yC1CQbd NfD8C3RstBwau952/WUZ4hLR/WaxVSN/iaiCINPi2n51s8MAu7tFp3uIZbuN/KzC2zjs vBRIWEAPQcc1qNQrKeFEKbbQ7mQ3zy4HsMmRE3l8ZY33jNyADo1rCCzI6FjK8y+8ecf/ Rm2diPTqBKyN2O5zVdlko1tfxci941+5lmHRTz1OvvmeD0P1rbgQhWL4DJfw4659Z/Zf SQZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362409; x=1726967209; 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=nyASwxYCvsAWNh9neSNt2c74xLjhwEcHZ/10RfBTDG4=; b=aLIHkFzwjIN3TJgwQS7VuQH/aZIc5BnXdx45qun3EZGo/jizSc8dRBCJiQurVsK032 ambrFsoMeI4icRFLc+ROW8apvW6bSs/9tysUHqwGfFtl5zJCArioAx8P9NxiAql/svnC kza4a3MzAwj/mNc47tMf1m38Rwe+B4PwRbvirIf8MG+joP9mttJIIfrrjaCNTVe+weKU 9qDFWhjyIfIeJQiwtUpjE5gn60GI7AROA8t314Mxhdf53jbNSU6knM+CozMOinEMbhvZ iOxTdF2hPSYIPyXZ72JYuNPCwYhKZLxjibdKln26S5IsFcIq62Ha7TUSsvX3rfcHZiwC typQ== X-Gm-Message-State: AOJu0Ywq3BRojZDGAoBYYY/ZuXhn/zPYN139J+pqhs+1Ua+YKpfEJt1b I+3ftD5UzQfZC1pvTN4Sl2Huk5TvzycZjwUmQwLIrs8haBgvHBWpngl8FbmGyNQ= X-Google-Smtp-Source: AGHT+IHgpNugcE3lXIRjZoDH3JdOq3mqlLpmE4nNvjSoxswpdwMiTt+008Pzku+Vt/Ta1svudNcKcg== X-Received: by 2002:a17:902:da8d:b0:205:6552:1099 with SMTP id d9443c01a7336-2076e31f984mr179183195ad.8.1726362409213; Sat, 14 Sep 2024 18:06:49 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-207947666a3sm14713435ad.308.2024.09.14.18.06.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:06:48 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:39 +0900 Subject: [PATCH 1/7] net: checksum: Convert data to void * MIME-Version: 1.0 Message-Id: <20240915-queue-v1-1-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 Sun Sep 15 01:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=hazzoG+D; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qf54MBGz1y2T for ; Sun, 15 Sep 2024 11:07:39 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdj7-0001Hg-2n; Sat, 14 Sep 2024 21:06:57 -0400 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 1spdj5-0001CG-Ay for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:55 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdj3-0004AD-QM for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:55 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2da4ea59658so1870841a91.0 for ; Sat, 14 Sep 2024 18:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362412; x=1726967212; 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=ZUcT+2gn0meAFPXtJKPK+LJvYH+cHREDYZFhX2vH00E=; b=hazzoG+DmJqPJF31gHwtCrE7RD1z9pCPbYQbqp8BTCK5OoAvVt2SKKz/pPoqqvAe/t MPvvImrZSIsdKKB/YHV7dL1Cd2f/oBZfmCDZwZBholHQ5jV+pnevFKeHuvg5T+KCVo/Z eaATtsZ0yOfXR4BZKeMXJebYiCx5IFHj3YoXcwiXXbMHe/DA92iIIz5EmJmZuV5eQOhk +Vry25TwSady2qDhbcHpu71dE/i/JkKsb0IYd2iE63WXZX2OYu3gGGh609uMtCOzuWNm 8p29GcrdWHuczROD1PLNsKN+ZnW3TVZDBv5Y+4X75LWGvXcdBmTdSZxWra5NyxafYbl/ J92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362412; x=1726967212; 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=ZUcT+2gn0meAFPXtJKPK+LJvYH+cHREDYZFhX2vH00E=; b=mruP3wE0Ng/IK8lF7DD0ckzqVnomn597Zb3v70hpK4T9LlBC7KphzGDhmhs5PzdSoa SqlKXr5qeIdBcstg+kCTKmPJhyfCbfSsIfVG80DhwM5VcKfqI0t+yFh6D/Ok/pJsqNJ3 wcVmGsc4XHGoNEzS752qmvxD/mtQ4rk5dE1M81CdS1L4LjtYBItYL8UU6e9/zTYlzcXI dctaep06OeL0kDgX69jiZgt5NLFxDiBcrXo37igd5RIUZxScGmkTp6e0HrlBwuOdLKlE gNyU2hjN1NGlwvzlTEyfr5zTsFTUeums9plWX/eU/qDue5KUL7eDQoqlxvIgBGJBI+M2 PH2Q== X-Gm-Message-State: AOJu0Yw+ucKuJwZJ/snUpZyXWO6oAQza1x4q2Dte9MY1DqX5sxSygYLN OuevkBuWpvI+4ZSugeh81V9WrU33Rqjm7lTKSlV3Gv/Kx5/PApKNCZI53/5nLI4= X-Google-Smtp-Source: AGHT+IHtSwK0WBC3+G8cJ73ei9TYeDv3GAf+7aPlliHpntNmlfZMyfjdFrKVVOCP7elqmYzyoitxtg== X-Received: by 2002:a17:90b:254b:b0:2d8:27c1:1d4a with SMTP id 98e67ed59e1d1-2dbb9e47368mr9939934a91.24.1726362412321; Sat, 14 Sep 2024 18:06:52 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2dbb9d98963sm4332039a91.53.2024.09.14.18.06.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:06:52 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:40 +0900 Subject: [PATCH 2/7] virtio-net: Fix size check in dhclient workaround MIME-Version: 1.0 Message-Id: <20240915-queue-v1-2-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki , qemu-stable@nongnu.org X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::102d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102d.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 8f3097270869..755530c035e4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1687,8 +1687,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 Sun Sep 15 01:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=y7Z3cg/C; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qf75pgMz1y1T for ; Sun, 15 Sep 2024 11:07:43 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdjA-0001SZ-De; Sat, 14 Sep 2024 21:07:00 -0400 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 1spdj8-0001OF-O3 for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:58 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdj7-0004AY-6k for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:06:58 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2053616fa36so39680675ad.0 for ; Sat, 14 Sep 2024 18:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362415; x=1726967215; 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=TJXuPeXYKPTzK6yFSg9nQc+Qxxmfh9dt2HenYTLinZ0=; b=y7Z3cg/CIqa7R0/Mnd7YndKuES9zJUG7tWzsIEqdhG0I427G51olZd8VYQtjpY59tX sBOyN/nOrChbGn5Rx6KSR8FhWnGZyN3yGk4pSpVtOrOFPTeWDnEOeQO6cm1g5OcQMkrg tmIHU4iOS0IyRtYz/+YX4IK5IUG0ncpn1UNMREI16f+KatAPh+UcP5PqTNt9qS6PpCkE ah5+s4ZebJr78ItB9Xjuc6F4Ck8LUEvUZkxDA7HQHdunvd//eT0ChPaq8wNQYz4E7Tsn I+ETFgHjfF8hTxOsCuqvBmrMF/X+lud6LeYkC/CYFLx0Z48T+7/7z33JUC+Mq6ggVhhP BzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362415; x=1726967215; 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=TJXuPeXYKPTzK6yFSg9nQc+Qxxmfh9dt2HenYTLinZ0=; b=k7GAXjHPVETT2kfQd68/N2QhWBpKE/AGWGeNRldgtmOqwDITK2w6KOYTyr3XNgXBc5 io8YyDEVzAy2/vNms5SnPIZ9N9KgeNyzlzB84yH9NgZHjcTfuaNyuZTXSBFX5wdWGzJX WYc0JB0TpOUUvntfDoIyMPHHlgGXRjMFPNwFT2vQWipjh1k5tDJdEC3pcqOujetkDNFd BMLVR+xR2Q1eUTV/KJkgwD0UEEMSq3kOoBZY2jYjQDGA1pggMfX4PbtiwKXA/m/2zvXi ycVYZ9NrfNmo0gzm6TylzVO08hlExeGc8Tnp0yrjhsPPMxPZMnn2/GDPm6AJemGCFu2k OGVg== X-Gm-Message-State: AOJu0YwEmQbWjlG5KDMHHqJz7LA6C5usViilQyM6pk/Yaq9I0IkOBvQs X1pwlf/P9evATC6vk5r/WLMyQ7dfiIDNK+AXRht4aP/uoCGPp/rCfhZuz7aGSv0= X-Google-Smtp-Source: AGHT+IHDdM6RtsDG5q1aX0+PPggEv7aJ/0jn74p+B27R3RskGtns6eCBBZZYcR+W+yA+2Yj8ozu0LQ== X-Received: by 2002:a17:902:e5c3:b0:205:709e:1949 with SMTP id d9443c01a7336-2076e421fd0mr180808305ad.57.1726362415315; Sat, 14 Sep 2024 18:06:55 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-207945da8d4sm14765615ad.59.2024.09.14.18.06.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:06:55 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:41 +0900 Subject: [PATCH 3/7] virtio-net: Do not check for the queue before RSS MIME-Version: 1.0 Message-Id: <20240915-queue-v1-3-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 755530c035e4..3ee1ebd88daa 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1901,10 +1901,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) { @@ -1913,6 +1909,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 Sun Sep 15 01:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=HC3NfCRD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qfF49Mmz1y1T for ; Sun, 15 Sep 2024 11:07:49 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdjG-0001cJ-1j; Sat, 14 Sep 2024 21:07:06 -0400 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 1spdjB-0001Va-Hx for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:01 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdj9-0004Aj-Ur for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:01 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-7178df70f28so2559659b3a.2 for ; Sat, 14 Sep 2024 18:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362419; x=1726967219; 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=IFsY7Jbbc9omILLrT31tgNp0GmY4wuWUF2cGaPcUD9M=; b=HC3NfCRD2SsPfbl3G+XetPINPehmnTOOPs6fnMDiV6H6LtPdh3TXLvkVXtwL1Farvr jw/XheOfAEap/qANTJ1nh5j8o0QlbXdDP5X8MSqBUnlzw8cBZH7l46NggC9mMToFK2+l 7uzwk+puHHYOzMvWasbUbRmQglolA4dpL+i3j5kO6NFp4PpHVMIAcm1uASXRXhib2A9Z kmwDnp6yP/yLtIGnBqOO+Or/F/BfqPJZOpEK3DxhVGeZHPbMgQWil2/q6JrlxI25RgRk Thq/HBqnspQwS1pXuoU8DUIST5b0P1eIp949y/i9d3jQYLp0r9benQrVtSBPe+tLWvuK qf6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362419; x=1726967219; 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=IFsY7Jbbc9omILLrT31tgNp0GmY4wuWUF2cGaPcUD9M=; b=f9OIvELEUbU7ijSP3XnDg7DVkAQmdk1CfwUBhdGHdSlQ/PaNaIbLLSuL+D1o73MIT3 P5PxGYa4U4fAtLaUV4UrYrg0yK6d1w1YdB0xbaDi2T23Gl9ea9aNzTJzhz5HCCLOQVL3 pshfGvH8hXbor+f5eMAqTAOzaxm+po8qI4eumZNDK1rN4vR+DAYbIE1SJI+GGbNrlUQl sxUpfn0/ZF42ytX+5SUx61wqCINCQ0YKdScOtqkiW37K1m3iLQOtITIkoQJPPpKDockf MC/FqW9Sj1tOMIizQW1BFG3zSAlq5j7hXwV25Z3s3KOSGlbnBQK9VJN4TRfpl0Ah/MBl pgbg== X-Gm-Message-State: AOJu0YybMxBnv3fhHFwfsFDhKp8zbrpXqXAu7F+5ydmsAlCy+0J3mkq1 il+2bVw7nYDjL+BWfOHqkKUV+9Mb8MDAWNrfuo73PORXN5ZzcpRo5N7mskGQwYI= X-Google-Smtp-Source: AGHT+IEwCBWBwXztUrVuo8Lx+gZmAjgs+7b3KjaYUYsoHJf4zsyfkri/CEswWJDJkjucmyJipw7oMQ== X-Received: by 2002:a05:6a20:ac43:b0:1cf:36f2:21e9 with SMTP id adf61e73a8af0-1cf76358fdfmr15366816637.32.1726362418537; Sat, 14 Sep 2024 18:06:58 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71944a9759esm1507734b3a.44.2024.09.14.18.06.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:06:58 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:42 +0900 Subject: [PATCH 4/7] virtio-net: Fix hash reporting when the queue changes MIME-Version: 1.0 Message-Id: <20240915-queue-v1-4-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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") Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3ee1ebd88daa..3753c6aaca83 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1888,10 +1888,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]; @@ -1901,11 +1901,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); - return virtio_net_receive_rcu(nc2, buf, size, true); + nc = qemu_get_subqueue(n->nic, index); } } @@ -1913,6 +1912,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; @@ -2038,7 +2039,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 Sun Sep 15 01:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=uEBB/O9j; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qg62f4jz1y1T for ; Sun, 15 Sep 2024 11:08:34 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdjK-0001go-On; Sat, 14 Sep 2024 21:07:10 -0400 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 1spdjF-0001ca-J2 for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:06 -0400 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 1spdjD-0004At-LF for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:04 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-71788bfe60eso2463149b3a.1 for ; Sat, 14 Sep 2024 18:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362422; x=1726967222; 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=Zri61GtPq3fqTMAS9EVk13RVqopymUiIUwzvDEJGhnU=; b=uEBB/O9jw9QeBEDxiURi1/LocWXrjdbgDsJPaeR+xbvjGjpl+g33kuMOWMZfC8xlC0 dMrxgW9IXZOZU2zy3wZ+3Rk56A9zGGj3463NGjDhhjDS00jTHNztjWF8gEzJZLVXHEGY KvsE8En46OiEwfloStPM36387zFBQ22d/tvGfGw9wkp5le0vH1vTWUeluA6OZWs4wGpE j4IQlXLtBZKJWJCoNsSYWRjRyNhppoQC/aUUJbVQd2jxPh/p1iAlnezL8etodSuCPmNH V9X5ahT+YsbcRAIyDc7vwkNHtpbRjUbra3tyye9FCjeKasRBIyq4StQ5q4icdlbjkX/L 9N5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362422; x=1726967222; 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=Zri61GtPq3fqTMAS9EVk13RVqopymUiIUwzvDEJGhnU=; b=FI9/mgzgJFRCFrrV28xfzq9A/wAtRzEJBsfaS5p8s5cor1gMZtt4N7Qi492DvA15FY 0qnvV21YNo0ggxd6Ylh15ki4FWQs8XC79iZYV03sTwQv4NUsn1zCrqUX0uKg0HTxoeOV ZZwzt4kvPTDd0AYK5E3MnSQdlMPKN95AyLJiDk6RdfJ73u94wQhkwcPU2w2BPKp4nwfN UGvUH6z66QKRNfH+As1JoOHbsXDp6q3719FL6WYTxV74TzoWT6j/F6ibN9WiyWdew8Qh 3Os0MJwN4AROj1Txf676KlYGjPSEIdG6rXUQFEEEHn81mgF+hrpHAfr9+rrI33htU2jr qePw== X-Gm-Message-State: AOJu0Yz1KkTnmDifB4XUTUtDWTrqovG5l1d7UrYCFttuvA9v96Wo97mA tmrwI0qvydB+xN6eBdRDEnHR4JIUWmsc7h5/qHMbwJdYwgr4PcYSJjvJT2E79txKJbxoUX+VLEa kjRA= X-Google-Smtp-Source: AGHT+IGK0kXQZeV5O6VAg1ns3LSG6MSEt6PMelo2BTdBVAM0YCUB0E+XNX2m/JGaLjbBBJjnGIVPaQ== X-Received: by 2002:a05:6a00:14c8:b0:714:3de8:a616 with SMTP id d2e1a72fcca58-719261e1393mr16890502b3a.19.1726362422156; Sat, 14 Sep 2024 18:07:02 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71944a98092sm1510518b3a.41.2024.09.14.18.07.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:07:01 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:43 +0900 Subject: [PATCH 5/7] virtio-net: Initialize hash reporting values MIME-Version: 1.0 Message-Id: <20240915-queue-v1-5-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none 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_NONE=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 3753c6aaca83..3fc1d10cb9e0 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1901,6 +1901,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 Sun Sep 15 01:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=bgJDcfst; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qgD620xz1y1T for ; Sun, 15 Sep 2024 11:08:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdjL-0001k8-GW; Sat, 14 Sep 2024 21:07:11 -0400 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 1spdjI-0001dg-OK for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:09 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdjH-0004B2-0O for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:08 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-20688fbaeafso24335925ad.0 for ; Sat, 14 Sep 2024 18:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362425; x=1726967225; 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=J4Fnc5bH9flclvZDSpxfqeUlOOXGOpttlfvN0QJF38M=; b=bgJDcfstcihiVU6eQQ8PLfut5KTSJv5QFpvSvlcUcWrfQb7NWGlb74OEi0+3vgCHkj Z4/NWgHRiFcHGBzx2gZfRtMWhRlSZM4nrJiNAa2kw+kHHNhvdo54QWH/CiMRaHPhOhbw FI12x4X7X8lsz4p/mTuMprvrEsnNAVhYEch7k6Qzgf4kKBLqtBk/JJsm9W9tusLrZe9L 5cSyeDTzI9hvpKg2Oz7QRSyu0y9Dr2Nn8/rTOx7F1DzFd6KY1KehUeoSb9uIpaMwiUrT 3afWHagtOddGCM/nnECoPt/BTAtr4FOXGqad/XShjo4RB4OLxnJ9ukFmt6UOmUJaghrs zSGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362425; x=1726967225; 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=J4Fnc5bH9flclvZDSpxfqeUlOOXGOpttlfvN0QJF38M=; b=GsCp12UK+4xngop01S7oh/8BgJgJqDtSodrWc4cRMVdvFlH5wX/4IvAykWTIzCE/jT CpCuMxpJsEy/4I5nDqtyp6FJaKOBRg9Z/9h+GrZUQ+wWUqs80oL7q6EmFpZSvv92Z1Q4 JtXVQ5fhKLsQvfAHPlh+/mWdJDHWl8UGhYOAsKtgmuV9soXwLXBscLPdCZMJ/0QBcOjS j5pAumKYQ4x70GJQykOxp+niVkuPkS2/36Yo2FXKidfCuxbebAeRBSchl8zzpEdQYdL2 mwRRVAoXjQD5vyPw4Oq0kg2r307JBYg3I3B5Iw0w0RTlC5IWM9ynFHa0DBjoSgAchR3q Vslw== X-Gm-Message-State: AOJu0Yw/j1uKQxeN6Q/dnfMerT5psIGxBP831zaCD0Qb+4YvoWwHJ8r3 ksUr7qn+AvlmKdcFbHFKRODbjowRWF30fFHoM3hybWxwYUJ529C6zhPLr+4L5v8= X-Google-Smtp-Source: AGHT+IFrVe47jm7gM/HMmMgsQkOB4+I/6M9uYczyr5Qzbx3rzSmV/5WZ2a3wCytqzCcCnFj8A4iN5A== X-Received: by 2002:a17:902:e54e:b0:1fd:791d:1437 with SMTP id d9443c01a7336-20781b476efmr114581055ad.6.1726362425077; Sat, 14 Sep 2024 18:07:05 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2079470eba6sm14662085ad.192.2024.09.14.18.07.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:07:04 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:44 +0900 Subject: [PATCH 6/7] virtio-net: Copy received header to buffer MIME-Version: 1.0 Message-Id: <20240915-queue-v1-6-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 3fc1d10cb9e0..ca4e22344f78 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1685,41 +1685,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) @@ -1887,6 +1890,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) { @@ -1896,15 +1906,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); } @@ -1969,21 +1979,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; } @@ -2009,11 +2016,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++) { From patchwork Sun Sep 15 01:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1985736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=cpzL3Azt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X5qfx4vBSz1y1T for ; Sun, 15 Sep 2024 11:08:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spdjQ-00021o-0S; Sat, 14 Sep 2024 21:07:16 -0400 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 1spdjL-0001jH-8y for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:11 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spdjJ-0004BC-RA for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:07:11 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2057c6c57b5so20003875ad.1 for ; Sat, 14 Sep 2024 18:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726362428; x=1726967228; 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=kQxCBgxm/ZP4fJCB6KnHjmojyAzDFXk1SCp1ExesX4Y=; b=cpzL3AztCvU2enqhlVnGyDshw67BJpJ/79jNcRAR9W6TJNnbvr4BFu1yf7qMQWIzsF OS4QEzmAFqtwMVjKlXo+qHA35dhvqyTx8i3bCIxbMJo+SsMa5fAVJpUYvAJtUK7Imvry DKbcGlpomT8cjj6ox/fk5oPyBZK53VIwljleJAQkztyepYoWHB4MYsJcOKaunOzl+jKw 7aj1BAck4aCsFzLiUJHqQS5ripKbb52EBskN2lZn2PzFetSzG2qIHjKVlq48l91K4mwr 04X1gwWvBK1ywYYRojW3JIGJYWzBCxmQJxsHu5qlyAGybX2Yog1zvPfheMepkX4Q04Kw Sr8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726362428; x=1726967228; 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=kQxCBgxm/ZP4fJCB6KnHjmojyAzDFXk1SCp1ExesX4Y=; b=HcuGwirLguZAYQzZgWKlXRYkCclqOZ3J65f9EmCBfD/CtRrSTD5f5tmGFBX4/AuGeb Px1JcEOTnjzM3lPbs/NSh0OSSAGbL4KXMGdvCbpQcRSa+32Zi+cDeXzNbopDpuOf1mf3 YLYXz+LoamSWfX77Ly/QVrjaGgUm6coV27enOL/IlY8IkTZ/Ou21d82xKYWav0tUmIbZ 5mAzUONMsqOZnKNVIjDrRZBiuouXOjwppjLefNirDJyIRmVd+E0sNHrAUPPEqylJa9YT +/6keZLnBCqPFUOYW1OpiauWji0PHHV6ouxmbytsmHsQMDw+y+W5ws5OFq8RA8vmmCVN vF4w== X-Gm-Message-State: AOJu0Yy/MKYeMveaTEqBNTPz4mhFjTnP4k+L6BbWTLkr92P9+DMY9G3N 41AMk3hj5avArBWBoKRdQcHgcSax+4mefTbIsexoNZKw52na+tc4LKnLnQItdsy1vnMhs56i9Wk NgNs= X-Google-Smtp-Source: AGHT+IE5KKFfEpJ2xzzxh14vIVXCI4ZOxNxkuiBNxATWFlg3jr0BXvZFV6v5DzGLj3Q1SPriWTyrtA== X-Received: by 2002:a17:902:d2c8:b0:206:892c:b758 with SMTP id d9443c01a7336-2074c5ff323mr250823715ad.13.1726362428486; Sat, 14 Sep 2024 18:07:08 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7db4999f05bsm1765261a12.81.2024.09.14.18.07.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:07:08 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:06:45 +0900 Subject: [PATCH 7/7] virtio-net: Fix num_buffers for version 1 MIME-Version: 1.0 Message-Id: <20240915-queue-v1-7-b49bd49b926d@daynix.com> References: <20240915-queue-v1-0-b49bd49b926d@daynix.com> In-Reply-To: <20240915-queue-v1-0-b49bd49b926d@daynix.com> To: Jason Wang , "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The specification says the device MUST set num_buffers to 1 if VIRTIO_NET_F_MRG_RXBUF has not been negotiated. Fixes: df91055db5c9 ("virtio-net: enable virtio 1.0") 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 ca4e22344f78..b4a3fb575c7c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1982,6 +1982,8 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, offsetof(typeof(hdr), virtio_net.hdr.num_buffers), sizeof(hdr.virtio_net.hdr.num_buffers)); + } else { + hdr.virtio_net.hdr.num_buffers = cpu_to_le16(1); } guest_offset = n->has_vnet_hdr ?