From patchwork Tue Mar 26 15:19:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13604381 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 3A6A313C831; Tue, 26 Mar 2024 15:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711466364; cv=none; b=gq9Nsj8QyeA7a952H3/8c+k0ZZTl27/ZM7tg0nqSwHeGnCIas3C1ASzSLO6jt/Y0FKT1xmW2OWLeNTFLoXRsVd9KFg1JaCIQLc9OzN3WFhzPv2syeVNz0u8Wh1FRkpz22B/aOGCopk9e6gSpfYFOB1aZs9zp+hcycBLBeUTwCsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711466364; c=relaxed/simple; bh=t/j9B4d1DAJG+x0WZEKX9sM5rtk+d1CT8qkjyuhY0Wo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SrzJKHvPnf+QA8dMtc98YyWSqPAVhx6t1gzSKtu03KHRT9V0Fmurutd4ENB/zpWdZI5AOJQ7ZiF22exTOX1Xjwd8qYaUTDz3CmHHgi8kMheS03+uF1As3DAnN4CaEGCwIO2IVggkQ4YZi3bsyTet4tbRrROFvenZVAe11nPcgto= 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.208.47 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-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56bf6591865so4899242a12.0; Tue, 26 Mar 2024 08:19:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711466361; x=1712071161; 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=tswsOTneScV35e8ze8rWgk0pT/EhtrIbNgyGirLZBUU=; b=rmcmEJ3zXU9nBLcvIa90ploL4bSOvIYEmp+9udi/U1GswxP9fON4zVd723mougbfQx K6sSp35jKMz7rAzkxDCSxI68Z0zlFAf2jbx6UuKI3w+tLHECeiVXW/cCjYJUD6PiZfw8 pFYaBMdF7HkyViaVZMyhvbiq78FG8T3Cq3L1Yf81jwQbOO6paXzUmPBuOoKHL+dxjtgB phwjXDq0vHtsFAY+qjVqkiEOX6H3dewUz5n/jFUsl35cPwnMS8WhH/gQQb0PN+B3jdY/ CQ63vD03OmhZTqLNz+O0WKKa/eSKsypgil9jjgVLck4dZjGiRQo4ukvBEE0IDCviNi7Z KpYA== X-Forwarded-Encrypted: i=1; AJvYcCWVP1f1fhiDjdp4tMQvaxjrumT3gr5tzq6+B8SJ+IWefeI3fxZlYntioOUIbSLePniiLi7PGio2Svy3nHfwwgyPznGj6sViFFoTE2N6QRoe3Giy/xt5MTsgg4V1yZMmQJBu5Ihq X-Gm-Message-State: AOJu0YyXOIIX/qFhv2wITcVhUXPsMTU61plnKD5K/3U9b4ZruDixRLvg RPTTXVIPpqvAgs9XZ0WqRrABW+TwOchl6TXJcUxWOARJrauuLuaw X-Google-Smtp-Source: AGHT+IGDFkOEbOFg6NKy2/q2daPeK0G7VvTQ5PUqeGY5wLXijc72wcmqCJ4IBXYbih5UcuyivJHFvw== X-Received: by 2002:aa7:ccd5:0:b0:56b:8d0e:1a08 with SMTP id y21-20020aa7ccd5000000b0056b8d0e1a08mr1222540edt.26.1711466361233; Tue, 26 Mar 2024 08:19:21 -0700 (PDT) Received: from localhost (fwdproxy-lla-117.fbsv.net. [2a03:2880:30ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id i23-20020a056402055700b00569731a1eb2sm4254328edx.46.2024.03.26.08.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 08:19:20 -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 Cc: rbc@meta.com, riel@surriel.com, 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 v2 1/2] virtio_net: Do not set rss_indir if RSS is not supported Date: Tue, 26 Mar 2024 08:19:08 -0700 Message-ID: <20240326151911.2155689-1-leitao@debian.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Do not set virtnet_info->rss_indir_table_size if RSS is not available for the device. Currently, rss_indir_table_size is set if either has_rss or has_rss_hash_report is available, but, it should only be set if has_rss is set. On the virtnet_set_rxfh(), return an invalid command if the request has indirection table set, but virtnet does not support RSS. Suggested-by: Heng Qi Signed-off-by: Breno Leitao --- drivers/net/virtio_net.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c22d1118a133..c640fdf28fc5 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3813,6 +3813,9 @@ static int virtnet_set_rxfh(struct net_device *dev, rxfh->hfunc != ETH_RSS_HASH_TOP) return -EOPNOTSUPP; + if (rxfh->indir && !vi->has_rss) + return -EINVAL; + if (rxfh->indir) { for (i = 0; i < vi->rss_indir_table_size; ++i) vi->ctrl->rss.indirection_table[i] = rxfh->indir[i]; @@ -4729,13 +4732,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)); From patchwork Tue Mar 26 15:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13604382 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 3F81D13C8F9; Tue, 26 Mar 2024 15:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711466367; cv=none; b=l+yGU8SfwSkve8Ca0opCfXoZK1/3URfsiAoi/ElHy1htbg+aqwVCSYJEJMewlO9qC+0cFyc1NeTaeA1CVdo7mWgJW8TPUUKioS9Za17Opjr99D5CKvWSuQMqCbWYf0vpZwlSAeV/bQ5OY9LlJU4wukjz0hHgIbFP1NFGYMl1cKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711466367; c=relaxed/simple; bh=hHinf3uw5mGBk3XfcvWhk/gfoOKl1t3aCvp3XB22w68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e9GSY+EW9f8oKZUIIonLuXyf6b7PaM4ztA/DLiATN9zE9DAPpi8DVTMQBy0l7txy4NVkk9fhikxkeo3YCJKv34e8cbBd4F70aDPfRFaMPkaxWWMfXMueCZfGq0jgNrNonXCrYeCyJ4gPThtkIvG2mcP6Wf3CQKsPclSzte6CVOw= 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.167.42 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-lf1-f42.google.com with SMTP id 2adb3069b0e04-515a97846b5so2885688e87.2; Tue, 26 Mar 2024 08:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711466363; x=1712071163; 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=JUVslbHxJBsutcvQ73cVdAnF0u3jUnm/TB9Hv1RCS88=; b=lTf7y/EveBKTZ/gEajfiO3bkUybaOiVGWCowwSiu+WYvXkM8aWYzPiXLC87HNFik8H Uxa6r6JOyPI0s99h0RE41Bs/Mcrr0aS8g5rPupuEQtupbbHSIOT+OvowXmzajeNiJdAU yRTcryR2RrqU+Iu+e+uDyiiOsYyyadDrAwowfkUoQSRKsw6Yuw9nngEa8yMlPp2m/UQj 6AwSRw3iR8y/K2o/MbrTsq6CHGmBIDqu4DWER5PURfP/LHTixZP04tnnssBUd+ympkcu Occ7ht8zmuVLJbLPaq+A6d0EXDbLtMAbj/rxWRLFpyo1xNxHArLIwa08Ndd4cJZt/W08 hh9Q== X-Forwarded-Encrypted: i=1; AJvYcCW7FGOa0oF4CfN8fJM3UKa+fOCgkwFZfWkTFEcEn8X/11/B67kUMi7v1jQgSrruBQi0oS44+77XZRlgLg/9wKLc1HVeQZYIUKdjfbL/q/DHjJ/PKAKOxWAzVZIvWddBZfMoToyOxg2rmRui2q1NhGLbYkbXYxDN7gLYD+rZ X-Gm-Message-State: AOJu0Yyh3inStF3XC/iw/ObsR0moDcvlnrS46hqs6s3HOVPPeqAvgdMe Cs2PW0kU9NWpZe5jb8T9A1xdPsflPu3X49+CQbRICDW+UYEAcW58 X-Google-Smtp-Source: AGHT+IFP2FZZbpvO9c2stqUmT05DnUhkBn3keNu/tRQhmT0rhlV567sSQvXWBoBrIb87kTJm2cF7ag== X-Received: by 2002:a05:6512:54e:b0:513:d522:b58c with SMTP id h14-20020a056512054e00b00513d522b58cmr6423792lfl.56.1711466363049; Tue, 26 Mar 2024 08:19:23 -0700 (PDT) Received: from localhost (fwdproxy-lla-000.fbsv.net. [2a03:2880:30ff::face:b00c]) by smtp.gmail.com with ESMTPSA id i16-20020a170906091000b00a4735fc654fsm4295335ejd.205.2024.03.26.08.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 08:19: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 v2 2/2] virtio_net: Do not send RSS key if it is not supported Date: Tue, 26 Mar 2024 08:19:09 -0700 Message-ID: <20240326151911.2155689-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326151911.2155689-1-leitao@debian.org> References: <20240326151911.2155689-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- drivers/net/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c640fdf28fc5..e6b0eaf08ac2 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3809,6 +3809,9 @@ static int virtnet_set_rxfh(struct net_device *dev, struct virtnet_info *vi = netdev_priv(dev); int i; + if (!vi->has_rss && !vi->has_rss_hash_report) + return -EOPNOTSUPP; + if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && rxfh->hfunc != ETH_RSS_HASH_TOP) return -EOPNOTSUPP;