Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp393715pxb; Thu, 25 Feb 2021 05:31:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJEGE65gFjlqwagCUoDKecrmBXoHvuvYNJ7cxFqT/9WK9jegyFR74vPDAa0J2mo/+Fw3aL X-Received: by 2002:a05:6402:17e7:: with SMTP id t7mr2709420edy.44.1614259903141; Thu, 25 Feb 2021 05:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614259903; cv=none; d=google.com; s=arc-20160816; b=UQU0d0USLfuEjf1MXEcQFuA8LOSPqBHNQqF0BAYEzLYnJT1tdAY0HsKFSU9xqfNtLz 7Cw2tIK+5BSqL+NNxdmPKtPVs41ZbfYBMr0+ZN4dt5FFP96yP9Djm40f2GM6DDjFZlNt RNYoBpYAPEwcpiKlpDkXe5hAM3ewe5mCi3n9yJSHp/R/PCs5j3J5rpgeV/0vH+S3Cztj xQvKVCdVP2CqIqsVOBgSAtqPEunG6jCiKWd34vU2QXK6hbQg06NgL2varP08LAUDZIRV jEzvQLEXle10kX3pqpSxbe7/0Hu+64lIYg+QqF7CZ5dSKYw81SizIq54OJHtM2qp6Ujo DRPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=eXUvZpa0/Gfdi/WbDQrtIYaPffDzy8NMBiJQiT8MF2I=; b=pz0lhDpbhhkv7H22C417q99SOE+rvxNKfFsfzRor9G7qoOLhaK8Wd7ok7s2AOvzTtl sNu2F2SSO8nawF2BGm7ViiOsK7gX5grIOMTgrALmFAn0HQXELRYJHdfC+4Zr1WuvPvkk 8Fc3rGb64Ui9LTZX2+Rp1tjqeMCT3hmR5yNXuYb4ZsOUjt8KfqdqLLM6ScRkpO2n7Ur9 ols9A2smPy4LGub7suzncblDzv/Shg4V0f8xKsQzdAhLVdSomHpDETxKhBqS4DDQK6Bf 1wspjPC+kG9LlqrIbUNhaPKHDHx9jQyTsI4gkU25SF3DN0GfR/UcDL9HeIV4i4LflSX9 tXrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KvIsdO1i; 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 jg13si3474179ejc.661.2021.02.25.05.31.20; Thu, 25 Feb 2021 05:31:43 -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=KvIsdO1i; 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 S229561AbhBYN3W (ORCPT + 99 others); Thu, 25 Feb 2021 08:29:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47921 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233121AbhBYN2H (ORCPT ); Thu, 25 Feb 2021 08:28:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614259599; 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=eXUvZpa0/Gfdi/WbDQrtIYaPffDzy8NMBiJQiT8MF2I=; b=KvIsdO1iyg0GwYmLgzzX8/LJht8ZU6mEyir+iuBNkPLD+4hN+3p2YBJ/K0UTQkkUJW+Chd i2m5o/PcaLLi1UaJzzajWGnqDaNfdJY3LLA1+Cyk010y95d5NaG14xGhZiAylk7aGC3jHG f5F973aBnSGp6qDmmcCCH19AgNIKmWc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-CzbjGrFwMg-IyRC5cRsJ2Q-1; Thu, 25 Feb 2021 08:26:36 -0500 X-MC-Unique: CzbjGrFwMg-IyRC5cRsJ2Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CF9F801979; Thu, 25 Feb 2021 13:26:35 +0000 (UTC) Received: from gondolin (ovpn-113-228.ams2.redhat.com [10.36.113.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D170C5C234; Thu, 25 Feb 2021 13:26:30 +0000 (UTC) Date: Thu, 25 Feb 2021 14:26:28 +0100 From: Cornelia Huck To: Jason Wang Cc: "Michael S. Tsirkin" , 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: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero Message-ID: <20210225142628.3659af58.cohuck@redhat.com> In-Reply-To: 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> <20210223110430.2f098bc0.cohuck@redhat.com> <20210223115833.732d809c.cohuck@redhat.com> <8355f9b3-4cda-cd2e-98df-fed020193008@redhat.com> <20210224121234.0127ae4b.cohuck@redhat.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 25 Feb 2021 12:36:07 +0800 Jason Wang wrote: > On 2021/2/24 7:12 =E4=B8=8B=E5=8D=88, Cornelia Huck wrote: > > On Wed, 24 Feb 2021 17:29:07 +0800 > > Jason Wang wrote: > > =20 > >> On 2021/2/23 6:58 =E4=B8=8B=E5=8D=88, Cornelia Huck wrote: =20 > >>> On Tue, 23 Feb 2021 18:31:07 +0800 > >>> Jason Wang wrote: > >>>> The problem is the MTU description for example: > >>>> > >>>> "The following driver-read-only field, mtu only exists if > >>>> VIRTIO_NET_F_MTU is set." > >>>> > >>>> It looks to me need to use "if VIRTIO_NET_F_MTU is set by device". = =20 > >>> "offered by the device"? I don't think it should 'disappear' from the > >>> config space if the driver won't use it. (Same for other config space > >>> fields that are tied to feature bits.) =20 > >> > >> But what happens if e.g device doesn't offer VIRTIO_NET_F_MTU? It looks > >> to according to the spec there will be no mtu field. =20 > > I think so, yes. > > =20 > >> And a more interesting case is VIRTIO_NET_F_MQ is not offered but > >> VIRTIO_NET_F_MTU offered. To me, it means we don't have > >> max_virtqueue_pairs but it's not how the driver is wrote today. =20 > > That would be a bug, but it seems to me that the virtio-net driver > > reads max_virtqueue_pairs conditionally and handles absence of the > > feature correctly? =20 >=20 >=20 > Yes, see the avove codes: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (virtio_has_feature(vdev, = VIRTIO_NET_F_MTU)) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 int mtu =3D virtio_cread16(vdev, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 offsetof(struct virtio_net_config, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mt= u)); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if (mtu < MIN_MTU) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __virtio= _clear_bit(vdev, VIRTIO_NET_F_MTU); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >=20 Ouch, you're right. The virtio_cread accessors all operate on offsets into a structure, it's just more obvious here. > So it's probably too late to fix the driver. It is never too late to fix a driver :) It seems involved, though. We'd need different config space structures based upon which set of features has been negotiated. It's not too bad when features build upon each other and add fields at the end (this should be fine right now, if the code remembered to check for the feature), but can become ugly if an in-between field depends upon a feature. I guess we've been lucky that it seems to be an extremely uncommon configuration. >=20 >=20 > > =20 > >> =20 > >>> =20 > >>>> Otherwise readers (at least for me), may think the MTU is only valid > >>>> if driver set the bit. =20 > >>> I think it would still be 'valid' in the sense that it exists and has > >>> some value in there filled in by the device, but a driver reading it > >>> without negotiating the feature would be buggy. (Like in the kernel > >>> code above; the kernel not liking the value does not make the field > >>> invalid.) =20 > >> > >> See Michael's reply, the spec allows read the config before setting > >> features. =20 > > Yes, the period prior to finishing negotiation is obviously special. > > =20 > >> =20 > >>> Maybe a statement covering everything would be: > >>> > >>> "The following driver-read-only field mtu only exists if the device > >>> offers VIRTIO_NET_F_MTU and may be read by the driver during feature > >>> negotiation and after VIRTIO_NET_F_MTU has been successfully > >>> negotiated." > >>> =20 > >>>> =20 > >>>>> Should we add a wording clarification to the spec? =20 > >>>> I think so. =20 > >>> Some clarification would be needed for each field that depends on a > >>> feature; that would be quite verbose. Maybe we can get away with a > >>> clarifying statement? > >>> > >>> "Some config space fields may depend on a certain feature. In that > >>> case, the field exits if the device has offered the corresponding > >>> feature, =20 > >> > >> So this implies for !VIRTIO_NET_F_MQ && VIRTIO_NET_F_MTU, the config > >> will look like: > >> > >> struct virtio_net_config { > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 u8 mac[6]; > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 le16 status; > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 le16 mtu; > >> }; > >> =20 > > I agree. =20 >=20 >=20 > So consider it's probably too late to fix the driver which assumes some=20 > field are always persent, it looks to me need fix the spec do declare=20 > the fields are always existing instead. The problem with that is that it has been in the spec already, and a compliant device that did not provide the fields without the features would suddenly become non-compliant... >=20 >=20 > > =20 > >>> and may be read by the driver during feature negotiation, and > >>> accessed by the driver after the feature has been successfully > >>> negotiated. A shorthand for this is a statement that a field only > >>> exists if a certain feature bit is set." =20 > >> > >> I'm not sure using "shorthand" is good for the spec, at least we can > >> limit the its scope only to the configuration space part. =20 > > Maybe "a shorthand expression"? =20 >=20 >=20 > So the questions is should we use this for all over the spec or it will=20 > be only used in this speicifc part (device configuration). For command structures and the like, "feature is set" should always mean "feature has been negotiated"; I think config space is special because the driver can read it before feature negotiation is finished, so device configuration is probably the proper place for it.