Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1757982pxb; Wed, 10 Feb 2021 16:34:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIJhy/h2pXZKEBHQviQWul4Ay1GMcsmVijU31agguxx72zIo1+FgEkrtbctLqR4W/PChQT X-Received: by 2002:a17:906:fb91:: with SMTP id lr17mr5608354ejb.186.1613003682776; Wed, 10 Feb 2021 16:34:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613003682; cv=none; d=google.com; s=arc-20160816; b=gL8het+VpzNZA/Ao/MIGaHutCvGdwFfFL88s+8DWdk0ipeYvR/27CBF2GTSyITl2ij qJCPunmD/ee7AIlssAs2us07CMlhy8s3bVm4CvkMZBFCb2zEcYxnuizkSYOK/hFVcRGB a1dh0+4yusw5EKSISQ7TFamrQyjGdE3VJHsh6dSJ79CsrDismHoUQKtxKSls5rR2zyD7 c4fxwdmwJFZuo1oYIsJgu1/M8IFlUFWqaQK+d+huk4cCI/bZQfmHlw2aRJd+VjqI0szh +FEjQd4R6u+mDr2ij2R/RRHhLG5NECRSBu19htSXXqcS9LUEPkBYyfmO65R3fyQkJFEO 7p8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=LiSar9TAMcy2xRKolsSKppUgJqRDQOLGsEBTg7PEtAM=; b=p7QKI5PDUU+APHldyBziImK/G9vBTVVXJBbH1BcUHukbn9Hk6WGSk9k0oIiKaG4nUS XmeN88B7KuXHBaAJXNvYtxN7hu32CiNrTMAW7oU9nGK+R0p1bhvSMtVBEHlnCD/UZ5j5 cfuyvTp9mHIaR8qxAJ9L3qfbhTnQSzLBJ/DvwSkaPpRW1fT+uC6DTpGrSxjBgp/vKS/f 2uA1XLrotCKt7IwVFIkZqOJt5tScr3ErEbhpR+hPmZHP89bFNHlH8soM7tZ/yf6KhHA/ 3TZns5Ye9Tmz4Gn/vcKerV065wVcl7s06woS5SwnFqaUP/w5GvCuOHC8cttuHdEVqjNm cwLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MkhsLP7N; 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 g4si2394087ejc.682.2021.02.10.16.33.46; Wed, 10 Feb 2021 16:34:42 -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=MkhsLP7N; 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 S229774AbhBJEC0 (ORCPT + 99 others); Tue, 9 Feb 2021 23:02:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45583 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbhBJECY (ORCPT ); Tue, 9 Feb 2021 23:02:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612929657; 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=LiSar9TAMcy2xRKolsSKppUgJqRDQOLGsEBTg7PEtAM=; b=MkhsLP7NMCMJryY90Y/6HIs7ka6uC0gt3/mJcyvBjwK+e2blk7WErWJwBdsRZK9+tQDsOa LsFM2foQNMX9pZJHsGksqE5cB55jpAWxSVAKeCj5DiVig4kC5H2SXIFQurhJQoSQvLu+Ji T/e4cZOVHMJ+ZSxoavRTxXa/a/z8oSQ= 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-76-pat8V0wMPIeyoW0ZjqVYMg-1; Tue, 09 Feb 2021 23:00:56 -0500 X-MC-Unique: pat8V0wMPIeyoW0ZjqVYMg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C762189DF4F; Wed, 10 Feb 2021 04:00:54 +0000 (UTC) Received: from [10.72.12.223] (ovpn-12-223.pek2.redhat.com [10.72.12.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 830E219C78; Wed, 10 Feb 2021 04:00:48 +0000 (UTC) Subject: Re: [PATCH 3/3] mlx5_vdpa: defer clear_virtqueues to until DRIVER_OK To: Si-Wei Liu , mst@redhat.com, elic@nvidia.com Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org References: <1612614564-4220-1-git-send-email-si-wei.liu@oracle.com> <1612614564-4220-3-git-send-email-si-wei.liu@oracle.com> <2e2bc8d7-5d64-c28c-9aa0-1df32c7dcef3@redhat.com> <00d3ec60-3635-a5f1-15fc-21e6ce53202b@oracle.com> From: Jason Wang Message-ID: Date: Wed, 10 Feb 2021 12:00:46 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <00d3ec60-3635-a5f1-15fc-21e6ce53202b@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/2/10 上午8:26, Si-Wei Liu wrote: > > > On 2/8/2021 7:37 PM, Jason Wang wrote: >> >> On 2021/2/6 下午8:29, Si-Wei Liu wrote: >>> While virtq is stopped,  get_vq_state() is supposed to >>> be  called to  get  sync'ed  with  the latest internal >>> avail_index from device. The saved avail_index is used >>> to restate  the virtq  once device is started.  Commit >>> b35ccebe3ef7 introduced the clear_virtqueues() routine >>> to  reset  the saved  avail_index,  however, the index >>> gets cleared a bit earlier before get_vq_state() tries >>> to read it. This would cause consistency problems when >>> virtq is restarted, e.g. through a series of link down >>> and link up events. We  could  defer  the  clearing of >>> avail_index  to  until  the  device  is to be started, >>> i.e. until  VIRTIO_CONFIG_S_DRIVER_OK  is set again in >>> set_status(). >>> >>> Fixes: b35ccebe3ef7 ("vdpa/mlx5: Restore the hardware used index >>> after change map") >>> Signed-off-by: Si-Wei Liu >>> --- >>>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +- >>>   1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c >>> b/drivers/vdpa/mlx5/net/mlx5_vnet.c >>> index aa6f8cd..444ab58 100644 >>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c >>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c >>> @@ -1785,7 +1785,6 @@ static void mlx5_vdpa_set_status(struct >>> vdpa_device *vdev, u8 status) >>>       if (!status) { >>>           mlx5_vdpa_info(mvdev, "performing device reset\n"); >>>           teardown_driver(ndev); >>> -        clear_virtqueues(ndev); >>>           mlx5_vdpa_destroy_mr(&ndev->mvdev); >>>           ndev->mvdev.status = 0; >>>           ++mvdev->generation; >>> @@ -1794,6 +1793,7 @@ static void mlx5_vdpa_set_status(struct >>> vdpa_device *vdev, u8 status) >>>         if ((status ^ ndev->mvdev.status) & >>> VIRTIO_CONFIG_S_DRIVER_OK) { >>>           if (status & VIRTIO_CONFIG_S_DRIVER_OK) { >>> +            clear_virtqueues(ndev); >> >> >> Rethink about this. As mentioned in another thread, this in fact >> breaks set_vq_state().  (See vhost_virtqueue_start() -> >> vhost_vdpa_set_vring_base() in qemu codes). > I assume that the clearing for vhost-vdpa would be done via (qemu code), > > vhost_dev_start()->vhost_vdpa_dev_start()->vhost_vdpa_call(status | > VIRTIO_CONFIG_S_DRIVER_OK) > > which is _after_ vhost_virtqueue_start() gets called to restore the > avail_idx to h/w in vhost_dev_start(). What am I missing here? > > -Siwei I think not. I thought clear_virtqueues() will clear hardware index but looks not. (I guess we need a better name other than clear_virtqueues(), e.g from the name it looks like the it will clear the hardware states) Thanks > > >> >> The issue is that the avail idx is forgot, we need keep it. >> >> Thanks >> >> >>>               err = setup_driver(ndev); >>>               if (err) { >>>                   mlx5_vdpa_warn(mvdev, "failed to setup driver\n"); >> >