From nobody Sun May 19 02:06:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1713829857; cv=none; d=zohomail.com; s=zohoarc; b=WrBeMH5UHrp/0dciYSb+86aSS2a7aDMOS1Rlv83tWDsmO5GQtu3TUsE0LlK9pl5YNYqJHCeDYBVPtCvM8QW0xTX4UaDPfnezt9o6xt1EQs5gcPtLSzsyR0tvAt+NjruP/dK+RBUBA8VxVnPn1UtJ0965dfC9Wc5tqjiRKXFthJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1713829857; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d9xj7HwmwuIRzsMLAZWeyWIJzUgtPFLJ8hFtN2pvdUw=; b=avYxuPXrLpk5/D0oHjxfup3di32D27Zj0q6JraoXPHovFVn4QSjfDCElvLrkPCyWiBSoEB98gEs69UYDMvWCgoXFafy6exJFTVv2Sd7wvOU5zD2A5P2M/2ZenKns9ajaYVULQCJqOltSM1LwF6TZ5vz+mGM2Y7TMiHy7MvOvvpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1713829856997389.52277319277664; Mon, 22 Apr 2024 16:50:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rz3QA-0008AF-CW; Mon, 22 Apr 2024 19:50:02 -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 1ryvQp-0004qm-Cg for qemu-devel@nongnu.org; Mon, 22 Apr 2024 11:18:11 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ryvQn-0000pM-D4 for qemu-devel@nongnu.org; Mon, 22 Apr 2024 11:18:11 -0400 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-571c2055cb1so892268a12.1 for ; Mon, 22 Apr 2024 08:18:07 -0700 (PDT) Received: from localhost (fwdproxy-lla-007.fbsv.net. [2a03:2880:30ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id p8-20020a05640243c800b00571fad0647csm2411769edc.74.2024.04.22.08.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 08:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713799086; x=1714403886; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d9xj7HwmwuIRzsMLAZWeyWIJzUgtPFLJ8hFtN2pvdUw=; b=f2pmFmsfFH/cukXxc93EedHb5wsQ74Fhg8tdvlht7YmmLPbQdrjgvE2y3gh6Q1TIO6 WIP6u4epi3gTSH39s6TirJdrtRAJ1DowPybtkmU01abnFtkOzC8gRqjysLC412ywOWze 0Fg0QI03W2DS/TWWm+h7EzsSVd/vts4GHs7QzTl7eb8TW1wyTjxDtXfV5upOAzw18E53 G3njnAJsL4tQJuWXwKFqAJRI0Yzew1XMJaGF0KcB+00In7yL1tpRdJxyi6+7AuZLEcte NiN5ghnMwgNf7GppWZVnoK9Vxju7hMCmifqLaRziuJh+qYDBIu7AbPkU+00d4wW4D4r9 TN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713799086; x=1714403886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d9xj7HwmwuIRzsMLAZWeyWIJzUgtPFLJ8hFtN2pvdUw=; b=W2QC2WBgSvqGZonAIgJgsDBCShoLt68GCClL62pq177zNO7XZaq/6ODreMbbBRAv2g U7R6qZ5OjBEDAhHxl2K6ssxql0sLnY7LQVuONLpNyCBiO3+1r7YMGIrouTd6TYwI47o4 AZsgY4JXUdraH5JVFdqas4ZcO3ohmFlBd+dkjpHBkHVljUK3sEB4Nsvq0D4s/oI8HwAc upAAHnssqy+hyOxI06O1MBo7vFR9nPp2kDO5Ultm/12CxJj4wMorp7AIh4AhWqp9tkox ODlhRgtPjXI24EyzLS2qhIuCE9qCcJ8YeSuOmtZmhH01PgizRgWCp91BEfePh8O/EZcZ r+Mw== X-Forwarded-Encrypted: i=1; AJvYcCXbmrp2UkXIr3wOl3bQEVCzaEtvgux1OO3c9gSdg7fDGjErky12YDScWp3EItViMXB7G4qvhgGb0UWilEo0QG1aRbqzQFI= X-Gm-Message-State: AOJu0YwW9jSeb73upBYQvi2C89hYO9WBDsowdJMzTLoU5iv8mObzPmj5 XWPcuSIyoq8SmefAZlQnbQxNqATNofxL8tTtFwxsdvn6l1hQgNFy X-Google-Smtp-Source: AGHT+IE0xIZcSiuCSsz7uHwpkq02z/02QgEoSLowEQ4mDuOxo6EQH/+kgcM7JeLLwXtgGDXeB3sn2Q== X-Received: by 2002:a05:6402:524c:b0:572:1574:2b88 with SMTP id t12-20020a056402524c00b0057215742b88mr1242248edd.40.1713799086256; Mon, 22 Apr 2024 08:18:06 -0700 (PDT) From: Vlad Poenaru To: stable@vger.kernel.org Cc: Breno Leitao , qemu-devel@nongnu.org, Heng Qi , Xuan Zhuo Subject: [PATCH 6.6.y] virtio_net: Do not send RSS key if it is not supported Date: Mon, 22 Apr 2024 08:18:03 -0700 Message-ID: <20240422151803.1266071-1-vlad.wing@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <2024041412-subduing-brewing-cd04@gregkh> References: <2024041412-subduing-brewing-cd04@gregkh> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=vlad.wing@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, 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-Mailman-Approved-At: Mon, 22 Apr 2024 19:50:00 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1713829858699100003 Content-Type: text/plain; charset="utf-8" From: Breno Leitao commit 059a49aa2e25c58f90b50151f109dd3c4cdb3a47 upstream. 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 =3D=3D 0. sg_buf_size =3D 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 =3D 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 Reviewed-by: Xuan Zhuo Signed-off-by: David S. Miller Signed-off-by: Vlad Poenaru --- drivers/net/virtio_net.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7cb0548d17a3..56cbe00126bb 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3570,19 +3570,34 @@ static int virtnet_get_rxfh(struct net_device *dev,= u32 *indir, u8 *key, u8 *hfu static int virtnet_set_rxfh(struct net_device *dev, const u32 *indir, cons= t u8 *key, const u8 hfunc) { struct virtnet_info *vi =3D netdev_priv(dev); + bool update =3D false; int i; =20 if (hfunc !=3D ETH_RSS_HASH_NO_CHANGE && hfunc !=3D ETH_RSS_HASH_TOP) return -EOPNOTSUPP; =20 if (indir) { + if (!vi->has_rss) + return -EOPNOTSUPP; + for (i =3D 0; i < vi->rss_indir_table_size; ++i) vi->ctrl->rss.indirection_table[i] =3D indir[i]; + update =3D true; } - if (key) + if (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, key, vi->rss_key_size); + update =3D true; + } =20 - virtnet_commit_rss_command(vi); + if (update) + virtnet_commit_rss_command(vi); =20 return 0; } @@ -4491,13 +4506,15 @@ static int virtnet_probe(struct virtio_device *vdev) if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) vi->has_rss_hash_report =3D true; =20 - if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) + if (virtio_has_feature(vdev, VIRTIO_NET_F_RSS)) { vi->has_rss =3D true; =20 - if (vi->has_rss || vi->has_rss_hash_report) { vi->rss_indir_table_size =3D 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 =3D virtio_cread8(vdev, offsetof(struct virtio_net_config, rss_max_key_size= )); =20 --=20 2.43.0