Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2244214pxb; Tue, 23 Feb 2021 02:07:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOOiHEsVn9sMx23JhJGefSRkGCYaruF7NQGMlsLybOPGnVygMAFWdDawOnyO4XYrduiclt X-Received: by 2002:aa7:c98c:: with SMTP id c12mr14295106edt.65.1614074875879; Tue, 23 Feb 2021 02:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614074875; cv=none; d=google.com; s=arc-20160816; b=IGp2tLzXUDydzAxUQe3e0Y6VVCgnHpzNTn9G6Pg7s9gzrsxm7IxpQK3pZ6AsGhqrzQ bzh9m8172oBQ89G8M757bbh0v/h1jCmoVHiyeKENmCjrwvM9q10zA1Ad5oa9LksYTj18 PXQv3efHlf2G11Z5ztqX6cznPVAV/4bnRlAFJR0TxDhFO/nYIhtbJOhw2g8eSCjfH9XK 5IUQpzEHWx+2EkobzeFVYwBPoZ3HL0nC/xzemZvKb3/v1oLouvfkQKM+1Hzegvo9QaZ1 OTyRVPOPbccios1w5dtOUnycVWjyousONqPjNaY2KGQfEDpwbrWiYojkfL0CUXV9J9N0 vlOQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=fq9fMMA50uXmWN63AH4eeQqewule2njQVz39u52s5qo=; b=MWnEVkT0EmDT+gJg+ARu5IAiLyBhHv7gEc8Jw1zqedait7+/BywCI4upBRU9Vikhdb Y8NpVOQn6qVXY3IJdF28ShS7km3eQ7sfsxbCYx59504E4ZzllEaOqGLlEmy5oTw0ydkX S6e2wKNN5DJmnWohaE//mcWzmUWw71irwHnoqTeiyNOFQ+HTSEXVq/CawFN29duN+w6J SHoIH/wre5UnI0qSAEFYzu/Glun2scXgH+n+TVWP3t/2zrYr71dstFPWlUiMJMqcsRPn ELV9gJmhJuPa54zasyCg3rMQv0kOkbfDezFBpjcwVx7bCErg2MQ7etpROUtAU/79rima 7D8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=deTTz0mD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t21si6628968edi.554.2021.02.23.02.07.29; Tue, 23 Feb 2021 02:07:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=deTTz0mD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231950AbhBWKEX (ORCPT + 99 others); Tue, 23 Feb 2021 05:04:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33334 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbhBWKEI (ORCPT ); Tue, 23 Feb 2021 05:04:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614074562; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fq9fMMA50uXmWN63AH4eeQqewule2njQVz39u52s5qo=; b=deTTz0mD4ZDmqsREN/FhdosC1PWGX2b8AAx2SIndzR/hKJ3XrR6iOgntVEIwJBpEIvwnk0 9uh1kLaEZIYqeRoc1VcCv0no/tQjfvyobKMfHwh79yoEI4nR9TUCUIAekviuQMB/PBVPDW a/aaZwP3LwgRFug1fBQ+6PLXvEmR9ao= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-6Xk49179MvGZSEqTLX0u8g-1; Tue, 23 Feb 2021 05:01:36 -0500 X-MC-Unique: 6Xk49179MvGZSEqTLX0u8g-1 Received: by mail-wr1-f71.google.com with SMTP id l10so7123159wry.16 for ; Tue, 23 Feb 2021 02:01:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=fq9fMMA50uXmWN63AH4eeQqewule2njQVz39u52s5qo=; b=Yi+kPQJjqHY2/Kofh65Qu+hHvBjLyOzXoY2WdO3UUzIiqV1Se6f7gF1ojdXSaoFeCG JK7DiUYnWlT0WKaGp8cXpm4rJSFuAI5D05oa4WARSv9Kiko7/s+CNYjLdhqMeG6MoaJ7 uUX97fclHEkOnjF8kre/oNdlie0W7B8s58X4hw1uL/lJsDgvMBhdLsuBmraiZZGXugyt b5DxvLrwc6zO9m8joyztkaU0Ije9NmTKbdRcnidn8HaQDoi3aXslndyQyk7R6RL34Nwg HNXmDtlJi8SA491lAgV4mTndsvEJMFBP1s0j7M4f8aOiRxiH2i1fatRexwoXgcceL828 N9BA== X-Gm-Message-State: AOAM532pu5WqLPizFmrTXbCnT0EukwFqoAmTO727aQAtHOu4JtsyQISY WlXKPrkOdQZ2cv/QKg8v//TNsJIQa5UI+A+Iz9u5rhvie1PCY8+EjBFV0HIfL9ySKh1eWR5kIO2 J9H0Ox0roVeFik6sMApstJGPn X-Received: by 2002:adf:97d5:: with SMTP id t21mr1510153wrb.139.1614074495014; Tue, 23 Feb 2021 02:01:35 -0800 (PST) X-Received: by 2002:adf:97d5:: with SMTP id t21mr1510136wrb.139.1614074494799; Tue, 23 Feb 2021 02:01:34 -0800 (PST) Received: from redhat.com (bzq-79-180-2-31.red.bezeqint.net. [79.180.2.31]) by smtp.gmail.com with ESMTPSA id z11sm2046114wmi.35.2021.02.23.02.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Feb 2021 02:01:33 -0800 (PST) Date: Tue, 23 Feb 2021 05:01:31 -0500 From: "Michael S. Tsirkin" To: Jason Wang Cc: Si-Wei Liu , elic@nvidia.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, virtio-dev@lists.oasis-open.org Subject: Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero Message-ID: <20210223045600-mutt-send-email-mst@kernel.org> References: <1613735698-3328-1-git-send-email-si-wei.liu@oracle.com> <605e7d2d-4f27-9688-17a8-d57191752ee7@redhat.com> <20210223041740-mutt-send-email-mst@kernel.org> <788a0880-0a68-20b7-5bdf-f8150b08276a@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <788a0880-0a68-20b7-5bdf-f8150b08276a@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 23, 2021 at 05:46:20PM +0800, Jason Wang wrote: > > On 2021/2/23 下午5:25, Michael S. Tsirkin wrote: > > On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote: > > > > > > On 2/21/2021 8:14 PM, Jason Wang wrote: > > > > On 2021/2/19 7:54 下午, Si-Wei Liu wrote: > > > > > Commit 452639a64ad8 ("vdpa: make sure set_features is invoked > > > > > for legacy") made an exception for legacy guests to reset > > > > > features to 0, when config space is accessed before features > > > > > are set. We should relieve the verify_min_features() check > > > > > and allow features reset to 0 for this case. > > > > > > > > > > It's worth noting that not just legacy guests could access > > > > > config space before features are set. For instance, when > > > > > feature VIRTIO_NET_F_MTU is advertised some modern driver > > > > > will try to access and validate the MTU present in the config > > > > > space before virtio features are set. > > > > > > > > This looks like a spec violation: > > > > > > > > " > > > > > > > > The following driver-read-only field, mtu only exists if > > > > VIRTIO_NET_F_MTU is set. This field specifies the maximum MTU for the > > > > driver to use. > > > > " > > > > > > > > Do we really want to workaround this? > > > Isn't the commit 452639a64ad8 itself is a workaround for legacy guest? > > > > > > I think the point is, since there's legacy guest we'd have to support, this > > > host side workaround is unavoidable. Although I agree the violating driver > > > should be fixed (yes, it's in today's upstream kernel which exists for a > > > while now). > > Oh you are right: > > > > > > static int virtnet_validate(struct virtio_device *vdev) > > { > > if (!vdev->config->get) { > > dev_err(&vdev->dev, "%s failure: config access disabled\n", > > __func__); > > return -EINVAL; > > } > > > > if (!virtnet_validate_features(vdev)) > > return -EINVAL; > > > > if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) { > > int mtu = virtio_cread16(vdev, > > offsetof(struct virtio_net_config, > > mtu)); > > if (mtu < MIN_MTU) > > __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU); > > > I wonder why not simply fail here? Back in 2016 it went like this: On Thu, Jun 02, 2016 at 05:10:59PM -0400, Aaron Conole wrote: > + if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) { > + dev->mtu = virtio_cread16(vdev, > + offsetof(struct virtio_net_config, > + mtu)); > + } > + > if (vi->any_header_sg) > dev->needed_headroom = vi->hdr_len; > One comment though: I think we should validate the mtu. If it's invalid, clear VIRTIO_NET_F_MTU and ignore. Too late at this point :) I guess it's a way to tell device "I can not live with this MTU", device can fail FEATURES_OK if it wants to. MIN_MTU is an internal linux thing and at the time I felt it's better to try to make progress. > > > } > > > > return 0; > > } > > > > And the spec says: > > > > > > The driver MUST follow this sequence to initialize a device: > > 1. Reset the device. > > 2. Set the ACKNOWLEDGE status bit: the guest OS has noticed the device. > > 3. Set the DRIVER status bit: the guest OS knows how to drive the device. > > 4. Read device feature bits, and write the subset of feature bits understood by the OS and driver to the > > device. During this step the driver MAY read (but MUST NOT write) the device-specific configuration > > fields to check that it can support the device before accepting it. > > 5. Set the FEATURES_OK status bit. The driver MUST NOT accept new feature bits after this step. > > 6. Re-read device status to ensure the FEATURES_OK bit is still set: otherwise, the device does not > > support our subset of features and the device is unusable. > > 7. Perform device-specific setup, including discovery of virtqueues for the device, optional per-bus setup, > > reading and possibly writing the device’s virtio configuration space, and population of virtqueues. > > 8. Set the DRIVER_OK status bit. At this point the device is “live”. > > > > > > Item 4 on the list explicitly allows reading config space before > > FEATURES_OK. > > > > I conclude that VIRTIO_NET_F_MTU is set means "set in device features". > > > So this probably need some clarification. "is set" is used many times in the > spec that has different implications. > > Thanks > > > > > > Generally it is worth going over feature dependent config fields > > and checking whether they should be present when device feature is set > > or when feature bit has been negotiated, and making this clear. > >