Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6907613rwr; Tue, 25 Apr 2023 05:46:01 -0700 (PDT) X-Google-Smtp-Source: AKy350bohYSYyYRFNk1PAUl42vtS9d0gM6cDiJZj/nxR/n6WSu8IxpSqL07GhMHs/hcTCj3ZxVCg X-Received: by 2002:a17:902:ec8b:b0:1a6:9079:2bb3 with SMTP id x11-20020a170902ec8b00b001a690792bb3mr20684607plg.33.1682426760975; Tue, 25 Apr 2023 05:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682426760; cv=none; d=google.com; s=arc-20160816; b=ZVZrpxn24JdiXQIw9odr0pxVNs/tfxV8IkK1xFPRR4AUeh2NSEuCUfvmvS7J+IXmNI KK2oQfIYsO3tuxhv45YO2oBc7l0cREwExvS4DkcTLWsbEbmcRW7yvSEnZwgA9kKmyzPy 3UxF0+W55bPBiiRvy7nTgpqtrWH1XqFUV3ec6qW5iNi4m/SnaRsCgqIjULQkNlUnCt8t XSKE8RayJbY/iXxGh5TIwyXGGaFCIw2oAPCfw2HUGUubbuMM4hmNIecPmRjistPvjTKi NiDAx/Ivr+3ch6MzE2rfKBX95MnQLrIk+wnoN/4GszaDBmZZND0HGLTcdSusdgHWed+w Eemg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xUCCLfKIJcIMQQC1+iJEFgXpJl2oC+XHJLW7QTm0PdU=; b=xU7l4gdUm4oQssYMqSoo7aP/wivwEGWLGGNhaRceW24dOJYJQ2ojAeyxYJlbBSGQPS 7pZ3thFmK4ZjEpG+jBXoAac2OdfMZFvW1nE5odsNYLDtWB3tpkbyUppSqfjFMVeKxIH4 ZpZK9wtlwfPJ53AgvMPrJnCNKUt3S0B6vnal85mjeep6N8u8OetiB5sVAHNQtnfcdGzF +aL/Zir9g2uW8K06ASvYtuBssCgXd4EFEGDITllfVrjUJMtEIKTq7k+EEo94PsBNZAYF RdB92prrl0CvSvWUTSnwWw4e5gtevc0KD26/Xx4j64R4XMevkk1iVWUR6nIN/+xFUefS G7EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YoL28ba0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170903244e00b001a6e87f4336si15347973pls.275.2023.04.25.05.45.46; Tue, 25 Apr 2023 05:46:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YoL28ba0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbjDYMcz (ORCPT + 99 others); Tue, 25 Apr 2023 08:32:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234107AbjDYMcx (ORCPT ); Tue, 25 Apr 2023 08:32:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B33F133 for ; Tue, 25 Apr 2023 05:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682425921; 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=xUCCLfKIJcIMQQC1+iJEFgXpJl2oC+XHJLW7QTm0PdU=; b=YoL28ba05koO80K6LURlUTxgFY7nm+2OT6PeWfy93lNqLP/tP3tOC/aiUaymEQk0rmRpWU ctAvICSpQFzIy9oAqrIysTqThJm98f+mdRDgDOdAwThSM6gUDqYSbotkCZTh7PXR97yDQH nfkvpz8OmTLQFIZlmmDpmf9PInW8hcw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-EDFbfHTHNqy6U_msS6ZOtA-1; Tue, 25 Apr 2023 08:32:00 -0400 X-MC-Unique: EDFbfHTHNqy6U_msS6ZOtA-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-2f40f52c604so3215091f8f.0 for ; Tue, 25 Apr 2023 05:31:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682425919; x=1685017919; 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=xUCCLfKIJcIMQQC1+iJEFgXpJl2oC+XHJLW7QTm0PdU=; b=B0pdz8uxSvHJ+y5SzsvDTCFdEv8lDzQVqZkCTfs3RcIdRzs4LVrtW8oo0Dl0H3+7My 4gqI46bfBwFhguO2iPqU6x22j6VB8qNZtiPN4uOPQaPdNruBBxi4pHlnA/1ud997zuRQ rVcl5nyqCOH4ac1esqYMI3uxcYBDHmlNcbDpTIl0kKA/fgFQY1MgZ80CcQRejZz6U3Q3 npExMiGUJ8Kx2kBJY8cS0Jh9p1CVYwaSN3CPbkAfggyUgWPTun9NOLHzh5NPYqoN46hg lKVgp3yev7xHD1xc3D127n8uw474/V5hFlDpfRj8fy/i2TaWEYvo/avL49Q7UTv4HO8j k45w== X-Gm-Message-State: AAQBX9fdQ9H3zGIVBTtlLV89OdQf++fuRZi+s4ZvMIGO/kTDe7ryf4w3 +n9flcIqqw47WIjwjEQ5prPF5p3IyaohOVHS1VazcucPErZLbKmuuZqsAaqsLwnno4Ii+MWFruV 31wbxAKVILSf4ZuCaPtDcE/2I X-Received: by 2002:adf:ffcf:0:b0:301:8551:446a with SMTP id x15-20020adfffcf000000b003018551446amr12600273wrs.2.1682425918926; Tue, 25 Apr 2023 05:31:58 -0700 (PDT) X-Received: by 2002:adf:ffcf:0:b0:301:8551:446a with SMTP id x15-20020adfffcf000000b003018551446amr12600255wrs.2.1682425918573; Tue, 25 Apr 2023 05:31:58 -0700 (PDT) Received: from redhat.com ([2.55.17.255]) by smtp.gmail.com with ESMTPSA id a15-20020adfdd0f000000b003048d07f9absm1411810wrm.70.2023.04.25.05.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 05:31:57 -0700 (PDT) Date: Tue, 25 Apr 2023 08:31:54 -0400 From: "Michael S. Tsirkin" To: Alvaro Karsz Cc: Jason Wang , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH net] virtio-net: reject small vring sizes Message-ID: <20230425082150-mutt-send-email-mst@kernel.org> References: <20230417073830-mutt-send-email-mst@kernel.org> <20230417075645-mutt-send-email-mst@kernel.org> <20230423031308-mutt-send-email-mst@kernel.org> <20230423065132-mutt-send-email-mst@kernel.org> <20230425041352-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 25, 2023 at 09:41:35AM +0000, Alvaro Karsz wrote: > > So, let's add some funky flags in virtio device to block out > > features, have core compare these before and after, > > detect change, reset and retry? > > In the virtnet case, we'll decide which features to block based on the ring size. > 2 < ring < MAX_FRAGS + 2 -> BLOCK GRO + MRG_RXBUF > ring < 2 -> BLOCK GRO + MRG_RXBUF + CTRL_VQ why MRG_RXBUF? what does it matter? > So we'll need a new virtio callback instead of flags. > Furthermore, other virtio drivers may decide which features to block based on parameters different than ring size (I don't have a good example at the moment). > So maybe we should leave it to the driver to handle (during probe), and offer a virtio core function to re-negotiate the features? > > In the solution I'm working on, I expose a new virtio core function that resets the device and renegotiates the received features. > + A new virtio_config_ops callback peek_vqs_len to peek at the VQ lengths before calling find_vqs. (The callback must be called after the features negotiation) > > So, the flow is something like: > > * Super early in virtnet probe, we peek at the VQ lengths and decide if we are > using small vrings, if so, we reset and renegotiate the features. Using which APIs? What does peek_vqs_len do and why does it matter that it is super early? > * We continue normally and create the VQs. > * We check if the created rings are small. > If they are and some blocked features were negotiated anyway (may occur if > the re-negotiation fails, or if the transport has no implementation for > peek_vqs_len), we fail probe. > If the ring is small and the features are ok, we mark the virtnet device as > vring_small and fixup some variables. > > > peek_vqs_len is needed because we must know the VQ length before calling init_vqs. > > During virtnet_find_vqs we check the following: > vi->has_cvq > vi->big_packets > vi->mergeable_rx_bufs > > But these will change if the ring is small.. > > (Of course, another solution will be to re-negotiate features after init_vqs, but this will make a big mess, tons of things to clean and reconfigure) > > > The 2 < ring < MAX_FRAGS + 2 part is ready, I have tested a few cases and it is working. > > I'm considering splitting the effort into 2 series. > A 2 < ring < MAX_FRAGS + 2 series, and a follow up series with the ring < 2 case. > > I'm also thinking about sending the first series as an RFC soon, so it will be more broadly tested. > > What do you think? Lots of work spilling over to transports. And I especially don't like that it slows down boot on good path. I have the following idea: - add a blocked features value in virtio_device - before calling probe, core saves blocked features - if probe fails, checks blocked features. if any were added, reset, negotiate all features except blocked ones and do the validate/probe dance again This will mean mostly no changes to drivers: just check condition, block feature and fail probe. -- MST