From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99375145B0E for ; Sun, 31 Mar 2024 20:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711916444; cv=none; b=AVBxG9S11G8H5G7/fvxyl6xw/lkUl9b2uUxLi/YC58eNXiAiSsXX8PdER3+AxlXgO2X0I57JmoGZUPQhmNAXw7RVg9yolj27gEwY8NiO+NsKHx+fgOUsYVwetoS9zoPgZcQR2OA4Hqb9LkZFqwtQYj/Jm6T/D4jad20nTRRWLqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711916444; c=relaxed/simple; bh=pw6ynhZlliocTZxNsLu4uszjDWeDXBnouTCCdjYhWiY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VJ0uQ5W2l43bCPGyg4gbLZEN7aPhAhbDeQ+QA2/mRBX5K48m23Rt+V4OMttlPtGxaB3LGlEFbSB173slwsIKmbu66Gq0tXmAJf+BEJI7IO2vJqdJuXak3xWByWTfM8EgwNe566AaEHzBbiH0z4pth7hCyp2H0ZZR31Yvp4E4jfQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dwEQXYEG; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dwEQXYEG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711916441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FRRVj/JjKizxzXFDRSo3l/T54pHZqeXumE93BFWpnkg=; b=dwEQXYEGH0YB+fDeXVH7gGwKA45ulahfDCZOP+GVq4aXoIU5LRKQjIbpWK9hOlcuVe/7K6 +Z37tFSU8ZviF/ivDUMyT7f8BkENemiKi6ER5lE2fIOWq+SrVBcFIE/7doOkAmZjVTvIMW AJ7uHenA7DeA/NRGcLTcCXQR20z5nVo= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-PH_poJfpP5uXiAoXF3C_GQ-1; Sun, 31 Mar 2024 16:20:39 -0400 X-MC-Unique: PH_poJfpP5uXiAoXF3C_GQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a466c7b0587so253960366b.0 for ; Sun, 31 Mar 2024 13:20:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711916438; x=1712521238; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FRRVj/JjKizxzXFDRSo3l/T54pHZqeXumE93BFWpnkg=; b=Fqhqhwyz9ysIQbOqOtuCdO7ls+b0uIN/98X/R/Z7ikubPNOahPKTWtwyYd1Biqba58 7jXXOCmBHTw82qXAxnc/uFzJmWK0gIfiRTH9GAcNVmZ9A0TpQGk8vQSRtZxlpABYOSJc Ydp/1td/zXL7kFR4yvNeksRo6ZV4VEaoheV+YHawJWv37TIGnJDVbu4G9kQmIFft2B46 uudhbhmZKRRdNFsqWNbIsS2/Nx5BowojJbQL8TqDF0QKUmITvg8tj+o3ULJtBQoHV6q+ gEVBTDc2pgyTx6AQbMie+nEI8xJUSQ/OfXTdtzvxPbw2FSP9eJMe3v0s0HQ0Y1A5uSmc 9ypg== X-Forwarded-Encrypted: i=1; AJvYcCXJSmjwXYWHaBC7yFQ82VjYsBVwDGjvKDP9sLMcvfksJ/HlkwI73ghvcgp5qqCDgHJ8yrgkHey7q3K41UwbUCaJUz/Z1Ma9 X-Gm-Message-State: AOJu0Yx58qzVmDmuFpIrXfbEGjEHK4jZMnABi/8hiNizh837Jrvz9th+ c+UrbK02TGtcG0apwzDv/YedM7OzMZ+UrnwBaOxtkv+RCnx9ZfeTrrPllR9hel8xf2d46nBMW3j o/F37X/IrY5413yWe7gXwSpwMx+TV9dFKcldTOZbyn0YYsIBxFmtz+w== X-Received: by 2002:a17:907:3181:b0:a4e:663a:3cf4 with SMTP id xe1-20020a170907318100b00a4e663a3cf4mr1328714ejb.6.1711916438434; Sun, 31 Mar 2024 13:20:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpknzv8VBlqoGJZhO+j/gEtYVNu8noUyOMoh3rGDewOFPJPPTVRdkL5QIIU1wPMo3a8degxA== X-Received: by 2002:a17:907:3181:b0:a4e:663a:3cf4 with SMTP id xe1-20020a170907318100b00a4e663a3cf4mr1328694ejb.6.1711916437852; Sun, 31 Mar 2024 13:20:37 -0700 (PDT) Received: from redhat.com ([2a02:14f:172:9c27:9486:684f:de6:8ab8]) by smtp.gmail.com with ESMTPSA id q2-20020a170906b28200b00a4655976025sm4495364ejz.82.2024.03.31.13.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Mar 2024 13:20:37 -0700 (PDT) Date: Sun, 31 Mar 2024 16:20:30 -0400 From: "Michael S. Tsirkin" To: Breno Leitao Cc: hengqi@linux.alibaba.com, xuanzhuo@linux.alibaba.com, Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Melnychenko , rbc@meta.com, riel@surriel.com, stable@vger.kernel.org, qemu-devel@nongnu.org, "open list:VIRTIO CORE AND NET DRIVERS" , "open list:NETWORKING DRIVERS" , open list Subject: Re: [PATCH net v3] virtio_net: Do not send RSS key if it is not supported Message-ID: <20240331160618-mutt-send-email-mst@kernel.org> References: <20240329171641.366520-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240329171641.366520-1-leitao@debian.org> On Fri, Mar 29, 2024 at 10:16:41AM -0700, Breno Leitao wrote: > 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 net has its own stable process, don't CC stable on net patches. > Cc: qemu-devel@nongnu.org > Signed-off-by: Breno Leitao > --- > 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. > > --- > drivers/net/virtio_net.c | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index c22d1118a133..c4a21ec51adf 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,24 @@ 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 (!vi->has_rss && !vi->has_rss_hash_report) > + return -EOPNOTSUPP; What's the logic here? Is it || or &&? A comment can't hurt. > + > 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 +4741,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