From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54062C433E0 for ; Wed, 24 Feb 2021 06:46:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCB2764D99 for ; Wed, 24 Feb 2021 06:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234211AbhBXGqL (ORCPT ); Wed, 24 Feb 2021 01:46:11 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:12682 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbhBXGqH (ORCPT ); Wed, 24 Feb 2021 01:46:07 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 23 Feb 2021 22:45:26 -0800 Received: from mtl-vdi-166.wap.labs.mlnx (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 24 Feb 2021 06:45:24 +0000 Date: Wed, 24 Feb 2021 08:45:20 +0200 From: Eli Cohen To: "Michael S. Tsirkin" CC: Jason Wang , Si-Wei Liu , , , Subject: Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero Message-ID: <20210224064520.GA204317@mtl-vdi-166.wap.labs.mlnx> References: <1613735698-3328-1-git-send-email-si-wei.liu@oracle.com> <605e7d2d-4f27-9688-17a8-d57191752ee7@redhat.com> <20210222023040-mutt-send-email-mst@kernel.org> <22fe5923-635b-59f0-7643-2fd5876937c2@oracle.com> <20210223082536-mutt-send-email-mst@kernel.org> <3ff5fd23-1db0-2f95-4cf9-711ef403fb62@oracle.com> <7e6291a4-30b1-6b59-a2bf-713e7b56826d@redhat.com> <20210224000528-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20210224000528-mutt-send-email-mst@kernel.org> User-Agent: Mutt/1.9.5 (bf161cf53efb) (2018-04-13) X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1614149126; bh=s2r48334Ejcwu9RFL4dtdY7OXJJFkr9ocmkzw7NkgFw=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To:User-Agent:X-Originating-IP:X-ClientProxiedBy; b=ZDMP9uViUqNa0GXqr19gOOJlVWkmf8byWl2nRGkRRWeSDKB6I7QUvXTODkg/YJ4Ct 7zXzet1bWU1ZWTd742MM5o7llK1BgP9i7pgnRW6JnK4Ku/90UnuJLgdWI6/63OuOsQ gjshtJdCskCuGf8tDy0ZpVpVzJGNH/ysf/OoDvNVCFkFn0Dwss1TRJf+R+oYe/+NmV SOl2jjBGgM8v6exuIpOs+lmj8dqTnoMV/TMUbUXj4vbbdScOxtwMUNTaoSX50wVbrj rcbNEqR6ald2ashMIZ+1W5BOtVLIdfpmm/XOhtBFm8ZVrT/lWw7HOa582AprbipBph i5vW/JJihlPWQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote: > On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote: > >=20 > > On 2021/2/24 3:35 =E4=B8=8A=E5=8D=88, Si-Wei Liu wrote: > > >=20 > > >=20 > > > On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote: > > > > On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote: > > > > > On 2021/2/23 9:12 =E4=B8=8A=E5=8D=88, Si-Wei Liu wrote: > > > > > >=20 > > > > > > On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote: > > > > > > > On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote: > > > > > > > > On 2021/2/19 7:54 =E4=B8=8B=E5=8D=88, Si-Wei Liu wrote: > > > > > > > > > Commit 452639a64ad8 ("vdpa: make sure set_features is inv= oked > > > > > > > > > for legacy") made an exception for legacy guests to reset > > > > > > > > > features to 0, when config space is accessed before featu= res > > > > > > > > > are set. We should relieve the verify_min_features() chec= k > > > > > > > > > and allow features reset to 0 for this case. > > > > > > > > >=20 > > > > > > > > > It's worth noting that not just legacy guests could acces= s > > > > > > > > > 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 co= nfig > > > > > > > > > space before virtio features are set. > > > > > > > > This looks like a spec violation: > > > > > > > >=20 > > > > > > > > " > > > > > > > >=20 > > > > > > > > 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. > > > > > > > > " > > > > > > > >=20 > > > > > > > > Do we really want to workaround this? > > > > > > > >=20 > > > > > > > > Thanks > > > > > > > And also: > > > > > > >=20 > > > > > > > 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 wr= ite) > > > > > > > the device-specific configuration > > > > > > > fields to check that it can support the device before accepti= ng 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 sti= ll set: > > > > > > > otherwise, the device does not > > > > > > > support our subset of features and the device is unusable. > > > > > > > 7. Perform device-specific setup, including discovery of virt= queues > > > > > > > for the device, optional per-bus setup, > > > > > > > reading and possibly writing the device=E2=80=99s virtio conf= iguration > > > > > > > space, and population of virtqueues. > > > > > > > 8. Set the DRIVER_OK status bit. At this point the device is = =E2=80=9Clive=E2=80=9D. > > > > > > >=20 > > > > > > >=20 > > > > > > > so accessing config space before FEATURES_OK is a spec > > > > > > > violation, right? > > > > > > It is, but it's not relevant to what this commit tries to addre= ss. I > > > > > > thought the legacy guest still needs to be supported. > > > > > >=20 > > > > > > Having said, a separate patch has to be posted to fix the guest= driver > > > > > > issue where this discrepancy is introduced to > > > > > > virtnet_validate() (since > > > > > > commit fe36cbe067). But it's not technically related to this pa= tch. > > > > > >=20 > > > > > > -Siwei > > > > >=20 > > > > > I think it's a bug to read config space in validate, we should > > > > > move it to > > > > > virtnet_probe(). > > > > >=20 > > > > > Thanks > > > > I take it back, reading but not writing seems to be explicitly > > > > allowed by spec. > > > > So our way to detect a legacy guest is bogus, need to think what is > > > > the best way to handle this. > > > Then maybe revert commit fe36cbe067 and friends, and have QEMU detect > > > legacy guest? Supposedly only config space write access needs to be > > > guarded before setting FEATURES_OK. > >=20 > >=20 > > I agree. My understanding is that all vDPA must be modern device (since > > VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional device. > >=20 > > Thanks >=20 > Well mlx5 has some code to handle legacy guests ... > Eli, could you comment? Is that support unused right now? >=20 If you mean support for version 1.0, well the knob is there but it's not set in the firmware I use. Note sure if we will support this. >=20 > >=20 > > >=20 > > > -Siwie > > >=20 > > > > > > >=20 > > > > > > > > > Rejecting reset to 0 > > > > > > > > > prematurely causes correct MTU and link status unable to = load > > > > > > > > > for the very first config space access, rendering issues = like > > > > > > > > > guest showing inaccurate MTU value, or failure to reject > > > > > > > > > out-of-range MTU. > > > > > > > > >=20 > > > > > > > > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for > > > > > > > > > supported mlx5 devices") > > > > > > > > > Signed-off-by: Si-Wei Liu > > > > > > > > > --- > > > > > > > > > =C2=A0=C2=A0=C2=A0 drivers/vdpa/mlx5/net/mlx5_vnet.c | 15= +-------------- > > > > > > > > > =C2=A0=C2=A0=C2=A0 1 file changed, 1 insertion(+), 14 del= etions(-) > > > > > > > > >=20 > > > > > > > > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > b/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > index 7c1f789..540dd67 100644 > > > > > > > > > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c > > > > > > > > > @@ -1490,14 +1490,6 @@ static u64 > > > > > > > > > mlx5_vdpa_get_features(struct vdpa_device *vdev) > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return mvdev->= mlx_features; > > > > > > > > > =C2=A0=C2=A0=C2=A0 } > > > > > > > > > -static int verify_min_features(struct mlx5_vdpa_dev *mvd= ev, > > > > > > > > > u64 features) > > > > > > > > > -{ > > > > > > > > > -=C2=A0=C2=A0=C2=A0 if (!(features & BIT_ULL(VIRTIO_F_ACC= ESS_PLATFORM))) > > > > > > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return -EOPNO= TSUPP; > > > > > > > > > - > > > > > > > > > -=C2=A0=C2=A0=C2=A0 return 0; > > > > > > > > > -} > > > > > > > > > - > > > > > > > > > =C2=A0=C2=A0=C2=A0 static int setup_virtqueues(struct mlx= 5_vdpa_net *ndev) > > > > > > > > > =C2=A0=C2=A0=C2=A0 { > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int err; > > > > > > > > > @@ -1558,18 +1550,13 @@ static int > > > > > > > > > mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 > > > > > > > > > features) > > > > > > > > > =C2=A0=C2=A0=C2=A0 { > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct mlx5_vd= pa_dev *mvdev =3D to_mvdev(vdev); > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct mlx5_vd= pa_net *ndev =3D to_mlx5_vdpa_ndev(mvdev); > > > > > > > > > -=C2=A0=C2=A0=C2=A0 int err; > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 print_features= (mvdev, features, true); > > > > > > > > > -=C2=A0=C2=A0=C2=A0 err =3D verify_min_features(mvdev, fe= atures); > > > > > > > > > -=C2=A0=C2=A0=C2=A0 if (err) > > > > > > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return err; > > > > > > > > > - > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ndev->mvdev.ac= tual_features =3D features & > > > > > > > > > ndev->mvdev.mlx_features; > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ndev->config.m= tu =3D cpu_to_mlx5vdpa16(mvdev, ndev->mtu); > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ndev->config.s= tatus |=3D cpu_to_mlx5vdpa16(mvdev, > > > > > > > > > VIRTIO_NET_S_LINK_UP); > > > > > > > > > -=C2=A0=C2=A0=C2=A0 return err; > > > > > > > > > +=C2=A0=C2=A0=C2=A0 return 0; > > > > > > > > > =C2=A0=C2=A0=C2=A0 } > > > > > > > > > =C2=A0=C2=A0=C2=A0 static void mlx5_vdpa_set_config_cb(st= ruct vdpa_device > > > > > > > > > *vdev, struct vdpa_callback *cb) > > >=20 >=20