Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2791836lqz; Wed, 3 Apr 2024 08:43:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYfAW8JXwx9o9EFsH0eYFZFxgxpVELlWo/wxhZ+kLnaXXP1zn8I0Da1z1vlf5nJTc4D6AkKPs7sEIfmTbAoHlTzkRNcLkaEXpiNUKUAw== X-Google-Smtp-Source: AGHT+IHW7/FwrlExd8l802ck2h8ercYgFOK932Jtx722fu/PTIBhwsdXzKR1bqTRz2G6C19jpXnt X-Received: by 2002:a17:906:fac7:b0:a4d:b0e9:efbc with SMTP id lu7-20020a170906fac700b00a4db0e9efbcmr10104986ejb.17.1712159020655; Wed, 03 Apr 2024 08:43:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712159020; cv=pass; d=google.com; s=arc-20160816; b=dJk3xrG1zYNf6dZVxFAiifcZZnlxtLhvDV2I/B2h/Zwu5xtgKMLCGzHdhp+nzk8/fW Y0bz+GMfXRo+fjzG9nGRo951vciY/ZUGkfC134izt0/QahGH3pcOAVapVsUQT3GXPBpx fTgucf0bsErJfhXKPkX50B5UiN0GKJNsO2m6hG00AuCaD1i3PNVba4lxHAGepujbg2cJ Gl4JHvw55R71YaeskcrRKV0gfrsAzdZH3+Jn3IDskSXznpTZcgYTGAKlwMAS1D66nZNf ekEdCLve88ij8CDb7774IcnUp7Tjm3BNQycz4cCX3YiEivsE38Q40RfF9XDps9LjG2wK QMYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=WYy0xsk/6e7/EP3ZA06B/kwt1hnSoccxl0+aSYTRzhw=; fh=kSEgIa6TJbOyk8GzyazW6vSph6cuV2uAr3HWVSdT31o=; b=UVhzmfNf/h+BNBVR0ZTnVYE0uwoCD123UeZfrUQG7lkr9jBNVfUkNsAbUCx11oEvEI ERVoD4rJv+LQ6yU7489/3CCfF7DjKmdoO9pp1UAu4TX+5Qc2LObwF4FjfIhjTI+q1cz1 Nng+Yctlj8zV273hXlrcs4+tLiDvvGc8m9Tdv9ZGDSVhOimBBgFiBwBbL5kWhXZnaeLA /Yps2PXKUzxgMdTQFLKWpXRlfW5arwZTiGRDH3hVkarYN6i5+ClIQ+tqfjXpGoF2Odb+ ss3RK3jGimbh+Ea8heUY/PfQv4prmqlHj8EdPmeYlnoDWnUoqK1fA4sC0ZUgc4ABBLzw Nd0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-130115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130115-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g21-20020a1709061e1500b00a471504eb13si6603720ejj.88.2024.04.03.08.43.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 08:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-130115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130115-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 324191F227A7 for ; Wed, 3 Apr 2024 15:43:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 597B614A4F4; Wed, 3 Apr 2024 15:43:28 +0000 (UTC) Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18EA214A0A8; Wed, 3 Apr 2024 15:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712159007; cv=none; b=ttx9kH3FgkAm5EG6sw/9pk2I+GOgaY9u/FnEDGTpil0A+U+IugAgGGsJKWjLofujEOkGi8+tEtJwSmVNzsTE8xoM27u7YlAgvQRMNR/Cknu4WmDxa+H+OyBc9oT64M6zOnR6dXdk5MndoOpy+380zewz41fO9xn/ieKEsdmdCEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712159007; c=relaxed/simple; bh=X3a4pIGTWIkMI9v/XpREqOBl8ZhpS8U+c8nUeSNcENM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=udBWlt9LTjPBz/mMGq6rhWyrdAqiB4uZFbiKIQoVKTNwl9vsgk9PwTLlZHFezSN37IL8MNc1tO8yp/nQcPvqly/CIVO3Ja/j9JreZm1A66/PLdgM1uaKRO85XO//a+UkonXnVqhiPYWI8UxHOIqq7/FtYNnV78gBHqN0qUR4rik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a44665605f3so111266b.2; Wed, 03 Apr 2024 08:43:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712159003; x=1712763803; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WYy0xsk/6e7/EP3ZA06B/kwt1hnSoccxl0+aSYTRzhw=; b=Xi2a/O6o9nscxp/Q282pPlMx9MQjN5J8d2x6XYoDidEJT0rg6isayhqTnsv1PQDEDo yfVPzmKca8zqwfOMbEHEh+2YVlcinqVQYYhP13iC5ONQ0op618Zp3lg4Kl0CwcapNwaV jelLpQtbAxJECu8Q3GnxrCQWVpcBoESz3IvBYrJPzBtlg4N2EeSusYezkdMoXP1wHIZd Swk8El6gyKzdeKkMXrpxotQ6BuD187l6vaNvqgiTWh/NBwTK28AwJysxs6Bbm+qWjC7x 6wkQWQxYCu21NgV+FVg2dKRmbh1oBR8miy1r/u4TXYYkQNTmWzH1Ka2wLYeisIypcYX9 NTBQ== X-Forwarded-Encrypted: i=1; AJvYcCW4OjfHJn1dWdEL+fDt3n3y18Q+TjBfukM7GQ2RFvDLP6JtKW1EpytLT2ds9rYZy1NwNRHKM4qOPgeiSZfif7a5EhYzUNcJHDuhNaB28Tr+VWCvwq50/4kWBAtsECl1QhvVYZTbPjHyrWA7bXxBDQo5X3pezDB2FnR4vIoV X-Gm-Message-State: AOJu0Yx1OZwz3Ko389lUY1H5wUSTnPNcm5RjPDcGaF5YfaYEl5zx5rLR 1nfWtq2C2wrlegTd+lTKUaUJVu8x7REeme0ku1Ehzi1tNzyRn6f+ X-Received: by 2002:a17:907:868d:b0:a51:7d1a:e10d with SMTP id qa13-20020a170907868d00b00a517d1ae10dmr503935ejc.32.1712159002989; Wed, 03 Apr 2024 08:43:22 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id wn2-20020a170907068200b00a4e781bd30dsm3029235ejb.24.2024.04.03.08.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 08:43:22 -0700 (PDT) From: Breno Leitao To: hengqi@linux.alibaba.com, xuanzhuo@linux.alibaba.com, "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Melnychenko Cc: rbc@meta.com, riel@surriel.com, stable@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net v4] virtio_net: Do not send RSS key if it is not supported Date: Wed, 3 Apr 2024 08:43:12 -0700 Message-ID: <20240403154313.1331319-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There is a bug when setting the RSS options in virtio_net that can break the whole machine, getting the kernel into an infinite loop. Running the following command in any QEMU virtual machine with virtionet will reproduce this problem: # ethtool -X eth0 hfunc toeplitz This is how the problem happens: 1) ethtool_set_rxfh() calls virtnet_set_rxfh() 2) virtnet_set_rxfh() calls virtnet_commit_rss_command() 3) virtnet_commit_rss_command() populates 4 entries for the rss scatter-gather 4) Since the command above does not have a key, then the last scatter-gatter entry will be zeroed, since rss_key_size == 0. sg_buf_size = vi->rss_key_size; 5) This buffer is passed to qemu, but qemu is not happy with a buffer with zero length, and do the following in virtqueue_map_desc() (QEMU function): if (!sz) { virtio_error(vdev, "virtio: zero sized buffers are not allowed"); 6) virtio_error() (also QEMU function) set the device as broken vdev->broken = true; 7) Qemu bails out, and do not repond this crazy kernel. 8) The kernel is waiting for the response to come back (function virtnet_send_command()) 9) The kernel is waiting doing the following : while (!virtqueue_get_buf(vi->cvq, &tmp) && !virtqueue_is_broken(vi->cvq)) cpu_relax(); 10) None of the following functions above is true, thus, the kernel loops here forever. Keeping in mind that virtqueue_is_broken() does not look at the qemu `vdev->broken`, so, it never realizes that the vitio is broken at QEMU side. Fix it by not sending RSS commands if the feature is not available in the device. Fixes: c7114b1249fa ("drivers/net/virtio_net: Added basic RSS support.") Cc: stable@vger.kernel.org Cc: qemu-devel@nongnu.org Signed-off-by: Breno Leitao Reviewed-by: Heng Qi --- Changelog: V2: * Moved from creating a valid packet, by rejecting the request completely. V3: * Got some good feedback from and Xuan Zhuo and Heng Qi, and reworked the rejection path. V4: * Added a comment in an "if" clause, as suggested by Michael S. Tsirkin. --- drivers/net/virtio_net.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c22d1118a133..115c3c5414f2 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3807,6 +3807,7 @@ static int virtnet_set_rxfh(struct net_device *dev, struct netlink_ext_ack *extack) { struct virtnet_info *vi = netdev_priv(dev); + bool update = false; int i; if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && @@ -3814,13 +3815,28 @@ static int virtnet_set_rxfh(struct net_device *dev, return -EOPNOTSUPP; if (rxfh->indir) { + if (!vi->has_rss) + return -EOPNOTSUPP; + for (i = 0; i < vi->rss_indir_table_size; ++i) vi->ctrl->rss.indirection_table[i] = rxfh->indir[i]; + update = true; } - if (rxfh->key) + + if (rxfh->key) { + /* If either _F_HASH_REPORT or _F_RSS are negotiated, the + * device provides hash calculation capabilities, that is, + * hash_key is configured. + */ + if (!vi->has_rss && !vi->has_rss_hash_report) + return -EOPNOTSUPP; + memcpy(vi->ctrl->rss.key, rxfh->key, vi->rss_key_size); + update = true; + } - virtnet_commit_rss_command(vi); + if (update) + virtnet_commit_rss_command(vi); return 0; } @@ -4729,13 +4745,15 @@ static int virtnet_probe(struct virtio_device *vdev) if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) vi->has_rss_hash_report = true; - if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) + if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { vi->has_rss = true; - if (vi->has_rss || vi->has_rss_hash_report) { vi->rss_indir_table_size = virtio_cread16(vdev, offsetof(struct virtio_net_config, rss_max_indirection_table_length)); + } + + if (vi->has_rss || vi->has_rss_hash_report) { vi->rss_key_size = virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size)); -- 2.43.0