Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1949397pxb; Wed, 10 Feb 2021 23:37:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkRrr29vN0L7JhUUCuj35fPZtSf5o7+2tGknPcBl2tNv+m1nm5rehA6raXzrZJo9/r2Fu5 X-Received: by 2002:a17:906:6bda:: with SMTP id t26mr7059919ejs.50.1613029037392; Wed, 10 Feb 2021 23:37:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613029037; cv=none; d=google.com; s=arc-20160816; b=zJHePLiSC1pBjSmGSAttcVFtqn1N4ljfviIPu0bj+z71L6+zJYrZBO6KXUlltEV9wU pFdwz1TClK863jJn8mms97XtdaeA0HNLhlANKRHoSzNa9bYCYD/e8VOYWwWnKSf0nASx mvyZdhoueDNCJzdPqjtxeqRvgMClftynXbz6En7LuACRoPVpb5y3jGQASAp2btQd0mek ERrX9lRQDIOO7RU6uJgvy6JLG6MvqDqXhbsWlR/qogGZGAEa2XgzKbNozhwlnA2Bt2ze ij3TR1d6BRXpx+LUofq5l+YLFhWzUs441/ogWhZhuKjkDA6nTyYeobSXlLHbXTrCnxtN AOnA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Jb5vgiCfWSfNtEu95oNyAIE8t6IaV8AzCWh8B39PaLM=; b=eUaHqI7qUmkcwkBLO5gMZlxNbEskGf6S7Fm9KRZ53rehFtro2AKGNmbLnpbscwL2J+ fR97hPGFTPoJDTLxwaBfCLWnYvfO+9CnVqOm7yhp5xotwcBEqAJ9DkGB7uE4xYSGi3mF rEBi3l5lLn61n+lSMnIUEB8SGYQsHfQ5EV9mu258zn1DfO2mTDxEP/43vSaX4DUM2ZUw ZBU54/SI8gY4hs1qu/gVcA4cX+wNc07XtbyYufhFJPiZThUp1SUSY94112C48aXciL9k 5H+5BDksJLXQP9sqYJhmPh+I8jNlgTEhm70zT2Zw1901aOX09MgcfLf42VkXVp6fZoKm SpPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b="ZQbT/0qH"; 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 n2si1276831eju.471.2021.02.10.23.36.54; Wed, 10 Feb 2021 23:37:17 -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="ZQbT/0qH"; 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 S229501AbhBKHeY (ORCPT + 99 others); Thu, 11 Feb 2021 02:34:24 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:14672 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbhBKHd7 (ORCPT ); Thu, 11 Feb 2021 02:33:59 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 10 Feb 2021 23:33:07 -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.1473.3; Thu, 11 Feb 2021 07:33:04 +0000 Date: Thu, 11 Feb 2021 09:33:00 +0200 From: Eli Cohen To: Si-Wei Liu CC: , , , , Subject: Re: [PATCH v2 2/3] vdpa/mlx5: fix feature negotiation across device reset Message-ID: <20210211073300.GA100783@mtl-vdi-166.wap.labs.mlnx> References: <1612993680-29454-1-git-send-email-si-wei.liu@oracle.com> <1612993680-29454-3-git-send-email-si-wei.liu@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1612993680-29454-3-git-send-email-si-wei.liu@oracle.com> 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=1613028787; bh=Jb5vgiCfWSfNtEu95oNyAIE8t6IaV8AzCWh8B39PaLM=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: X-Originating-IP:X-ClientProxiedBy; b=ZQbT/0qHciVcaAPTYedUyNfyCTq1yQySYe7d5cEgMgjbum7Sk5qu8FUKKV/Df/93G dKPVBaXn6b/YoUHFVKDO/DTpNsxwsQh2N6kezZ2ezA1zfRUp5f41qvFRbXb2CE2Am1 WLIdgs0X93YKuoMRTCJGH/npjdF56/x59cxQ8mtQQ86ECuia1yLjR56cX84WSnpgGP 9GUEoxrslLL9ky/TyYAClb3hMJpkqOWBj5jHt2A2YclxL4UWy+CT6A8WUP9wdzHS7R dNix/4HpOJTmwGv+cUsSmG4+UMnc95qKh8yx6/awmHxAdymrpl1sicbzoyGcL5pssd /C3IxX5MiW8Kg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 10, 2021 at 01:47:59PM -0800, Si-Wei Liu wrote: > The mlx_features denotes the capability for which > set of virtio features is supported by device. In > principle, this field needs not be cleared during > virtio device reset, as this capability is static > and does not change across reset. > > In fact, the current code may have the assumption > that mlx_features can be reloaded from firmware > via the .get_features ops after device is reset > (via the .set_status ops), which is unfortunately > not true. The userspace VMM might save a copy > of backend capable features and won't call into > kernel again to get it on reset. This causes all > virtio features getting disabled on newly created > virtqs after device reset, while guest would hold > mismatched view of available features. For e.g., > the guest may still assume tx checksum offload > is available after reset and feature negotiation, > causing frames with bogus (incomplete) checksum > transmitted on the wire. > > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") > Signed-off-by: Si-Wei Liu Acked-by: Eli Cohen > --- > drivers/vdpa/mlx5/net/mlx5_vnet.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c > index b8416c4..7c1f789 100644 > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c > @@ -1486,16 +1486,8 @@ static u64 mlx_to_vritio_features(u16 dev_features) > static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) > { > struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); > - struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); > - u16 dev_features; > > - dev_features = MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, device_features_bits_mask); > - ndev->mvdev.mlx_features = mlx_to_vritio_features(dev_features); > - if (MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, virtio_version_1_0)) > - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_VERSION_1); > - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM); > - print_features(mvdev, ndev->mvdev.mlx_features, false); > - return ndev->mvdev.mlx_features; > + return mvdev->mlx_features; > } > > static int verify_min_features(struct mlx5_vdpa_dev *mvdev, u64 features) > @@ -1788,7 +1780,6 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status) > clear_virtqueues(ndev); > mlx5_vdpa_destroy_mr(&ndev->mvdev); > ndev->mvdev.status = 0; > - ndev->mvdev.mlx_features = 0; > ++mvdev->generation; > return; > } > @@ -1907,6 +1898,19 @@ static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx) > .free = mlx5_vdpa_free, > }; > > +static void query_virtio_features(struct mlx5_vdpa_net *ndev) > +{ > + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; > + u16 dev_features; > + > + dev_features = MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, device_features_bits_mask); > + mvdev->mlx_features = mlx_to_vritio_features(dev_features); > + if (MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, virtio_version_1_0)) > + mvdev->mlx_features |= BIT_ULL(VIRTIO_F_VERSION_1); > + mvdev->mlx_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM); > + print_features(mvdev, mvdev->mlx_features, false); > +} > + > static int query_mtu(struct mlx5_core_dev *mdev, u16 *mtu) > { > u16 hw_mtu; > @@ -2005,6 +2009,7 @@ static int mlx5v_probe(struct auxiliary_device *adev, > init_mvqs(ndev); > mutex_init(&ndev->reslock); > config = &ndev->config; > + query_virtio_features(ndev); > err = query_mtu(mdev, &ndev->mtu); > if (err) > goto err_mtu; > -- > 1.8.3.1 >