Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp381445pxb; Wed, 24 Feb 2021 04:57:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXY/IUpOe0NqCDBWvnIC3RbHmXtcuum0sSZyN7HvWgrlmW3mUuT7XuyKKlglB6lOmWnI6P X-Received: by 2002:aa7:cf16:: with SMTP id a22mr800012edy.288.1614171427068; Wed, 24 Feb 2021 04:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614171427; cv=none; d=google.com; s=arc-20160816; b=RQ38XqP46DkDbcPqvSQASX9/rIk67cbEUcWRoeQ9FDySYlIcBouRGVvwFGy2A1Bf59 TpMK4/zqZwV5awtY1OMiiAYDIpfs4acRu3VSeHyKoOM1dkO6LFaLXIXszCXpBWS6NHa9 hXF46jaOtusGxK62bW4lPseqs0MdWfHpvidmwW0L5LL1XJdLZkqfRUUzkWsIXdhDijZ/ 9QBXpCUzoLy0Qz+fkopqcTGSKLq3hHVQyjkMpAfIbSXTOO96kdYldBx6n4ma+fDOByZV DffOWC6StyTskfvF6Qxxqgc60mUSipI1bPDKhwQIA2GVugJaKEEC3O/VytdM1dYURP7X iXiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=WEMCQHrPqcokXXMTAZl9vTeV117JjMq3Q1wMaZ1rQFs=; b=Iskt/44rnm2Ah1ecSvoTEQADekj90gsGYK+JpJnAxrY496jkCn95vpPqSOqTHQH49S p7xX98JntB8wPg5cIJB7aDwXsETAbYU1lEnF5RUUqsX6xTiWSsVWX/IuTqXMrY6/48q0 EAPs1fPaQ+w8PiHz1rfdubUTkHbgvmCYA7ajPWmwk3uqd2CsaPl3MdiPoPX6PkLqFstj 6GKTL7KaNiCyCzNToRBgnmM3cBfBsIiSV6dkvNFWCsmY/AxthEbZKfawpU/UOKU92M9N 03NZ5Pont9ez+hRf3oXYK38PC7dMFUpkGx3Llt/kjlTl5mXIpb3C9SG7SCyHcX3Mb3w8 37sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=hgVDXqBO; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn26si1189737ejc.525.2021.02.24.04.56.40; Wed, 24 Feb 2021 04:57:07 -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=@nvidia.com header.s=n1 header.b=hgVDXqBO; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234362AbhBXHSk (ORCPT + 99 others); Wed, 24 Feb 2021 02:18:40 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:9727 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234409AbhBXHSW (ORCPT ); Wed, 24 Feb 2021 02:18:22 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Tue, 23 Feb 2021 23:17:36 -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 07:17:34 +0000 Date: Wed, 24 Feb 2021 09:17:31 +0200 From: Eli Cohen To: Jason Wang CC: "Michael S. Tsirkin" , Si-Wei Liu , , , Subject: Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero Message-ID: <20210224071731.GA206832@mtl-vdi-166.wap.labs.mlnx> References: <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> <20210224064520.GA204317@mtl-vdi-166.wap.labs.mlnx> <20210224014700-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: User-Agent: Mutt/1.9.5 (bf161cf53efb) (2018-04-13) X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1614151056; bh=WEMCQHrPqcokXXMTAZl9vTeV117JjMq3Q1wMaZ1rQFs=; 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=hgVDXqBO9aiSgOBaTt+7F7NMXfxb3s9ciYCcLZiQObQrMTNcp10Q0TlAlr0Cwob4V yEuVXgEHstyDFUV2uhw3siFRTvgU/gHynpgfOqGy1OGEA7r/GDFUiykIHH3e/EMQ2t RiYFA3GHtwoyRjL23tOC/jbPErz7v5tweXo03QHMrx++xoPXACOoFcnlezZ4Y7MQaS UFMm1ovlJAHnRGuQJi8sqkbJP/NXbe5jKJsZOmOUhmbwLBP1MzRvXm0j4k66bbjIyU xBfGbCfhoIArTzSdwSdoFhRpP1C5+StLIYzoMZNgPAa2uK8Mvmz3dt4D1AumjZvEkX EIizeKHXO1xHg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2021 at 02:55:13PM +0800, Jason Wang wrote: >=20 > On 2021/2/24 2:47 =E4=B8=8B=E5=8D=88, Michael S. Tsirkin wrote: > > On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote: > > > 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: > > > > > On 2021/2/24 3:35 =E4=B8=8A=E5=8D=88, Si-Wei Liu wrote: > > > > > >=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: > > > > > > > > > On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote: > > > > > > > > > > On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wr= ote: > > > > > > > > > > > On 2021/2/19 7:54 =E4=B8=8B=E5=8D=88, Si-Wei Liu wrot= e: > > > > > > > > > > > > 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. > > > > > > > > > > > >=20 > > > > > > > > > > > > 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: > > > > > > > > > > >=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 t= o use. > > > > > > > > > > > " > > > > > > > > > > >=20 > > > > > > > > > > > Do we really want to workaround this? > > > > > > > > > > >=20 > > > > > > > > > > > Thanks > > > > > > > > > > And also: > > > > > > > > > >=20 > > > > > > > > > > The driver MUST follow this sequence to initialize a de= vice: > > > > > > > > > > 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 fe= ature 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 a= ccepting 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 unusab= le. > > > > > > > > > > 7. Perform device-specific setup, including discovery o= f virtqueues > > > > > > > > > > for the device, optional per-bus setup, > > > > > > > > > > reading and possibly writing the device=E2=80=99s virti= o configuration > > > > > > > > > > space, and population of virtqueues. > > > > > > > > > > 8. Set the DRIVER_OK status bit. At this point the devi= ce 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= address. 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 t= his patch. > > > > > > > > >=20 > > > > > > > > > -Siwei > > > > > > > > I think it's a bug to read config space in validate, we sho= uld > > > > > > > > move it to > > > > > > > > virtnet_probe(). > > > > > > > >=20 > > > > > > > > Thanks > > > > > > > I take it back, reading but not writing seems to be explicitl= y > > > > > > > allowed by spec. > > > > > > > So our way to detect a legacy guest is bogus, need to think w= hat 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 t= o be > > > > > > guarded before setting FEATURES_OK. > > > > >=20 > > > > > I agree. My understanding is that all vDPA must be modern device = (since > > > > > VIRITO_F_ACCESS_PLATFORM is mandated) instead of transitional dev= ice. > > > > >=20 > > > > > Thanks > > > > 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. > > Hmm you mean it's legacy only right now? > > Well at some point you will want advanced goodies like RSS > > and all that is gated on 1.0 ;) >=20 >=20 > So if my understanding is correct the device/firmware is legacy but requi= re > VIRTIO_F_ACCESS_PLATFORM semanic? Looks like a spec violation? >=20 I am checking this with some folks here. > Thanks >=20 >=20 > >=20 > > > > > > -Siwie > > > > > >=20 > > > > > > > > > > > > Rejecting reset to 0 > > > > > > > > > > > > prematurely causes correct MTU and link status unab= le to load > > > > > > > > > > > > for the very first config space access, rendering i= ssues like > > > > > > > > > > > > guest showing inaccurate MTU value, or failure to r= eject > > > > > > > > > > > > out-of-range MTU. > > > > > > > > > > > >=20 > > > > > > > > > > > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver fo= r > > > > > > > > > > > > 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 deletions(-) > > > > > > > > > > > >=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_de= v *mvdev, > > > > > > > > > > > > u64 features) > > > > > > > > > > > > -{ > > > > > > > > > > > > -=C2=A0=C2=A0=C2=A0 if (!(features & BIT_ULL(VIRTIO= _F_ACCESS_PLATFORM))) > > > > > > > > > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return = -EOPNOTSUPP; > > > > > > > > > > > > - > > > > > > > > > > > > -=C2=A0=C2=A0=C2=A0 return 0; > > > > > > > > > > > > -} > > > > > > > > > > > > - > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0 static int setup_virtqueues(str= uct mlx5_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, u6= 4 > > > > > > > > > > > > features) > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0 { > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct = mlx5_vdpa_dev *mvdev =3D to_mvdev(vdev); > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct = mlx5_vdpa_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_f= eatures(mvdev, features, true); > > > > > > > > > > > > -=C2=A0=C2=A0=C2=A0 err =3D verify_min_features(mvd= ev, features); > > > > > > > > > > > > -=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->m= vdev.actual_features =3D features & > > > > > > > > > > > > ndev->mvdev.mlx_features; > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ndev->c= onfig.mtu =3D cpu_to_mlx5vdpa16(mvdev, ndev->mtu); > > > > > > > > > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ndev->c= onfig.status |=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_confi= g_cb(struct vdpa_device > > > > > > > > > > > > *vdev, struct vdpa_callback *cb) >=20