Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2615709pxb; Mon, 6 Sep 2021 01:04:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhjw7DQKLGV0InpN0QT5DQfpKCx38KDG4ZudqdMNog2pPz3dAyAreFMx5YsyE0xuz0i7GS X-Received: by 2002:a17:906:781:: with SMTP id l1mr12467857ejc.289.1630915479526; Mon, 06 Sep 2021 01:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630915479; cv=none; d=google.com; s=arc-20160816; b=D8b0MvH28/vaUXzrJJK8zU2TkQJ+W5MVX/EXZ0JhmCSoQpqVEncpne9FjG5469+5N0 vZX23YWnFL4m03Z479Y0n2cT/Li6LqPsAf8C2ZkqVxlCaPkvaY9b3OrfW24mLYGR2wN4 +o+F775tBtBnIM+Ip9LaMg8MlVy2fYaqr1oD7RjgkKYSaP8nYNWcTyh9Omzg6WR3UvC9 dvhu6ZyC3syfj/BpZF0oIhhQMv45H1AtwFsjcdXHBzQQ9RLih0hNxEP926bVfsg7PnDq BcPiX+IThU50jC5SaAGeleKk+kCagG1m9jlTdPLfxyPxq2hYvgIXudLXePryW/4cNabZ DVxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NO6GFqxRcZJwYtn+Qe2gbxSZz+UC4dbKjNIIRf72XCk=; b=NE2t7BuLyOo8CBaPTVk2WMoawqcWchdqEa8V3WDAobG089tAkrQ9iFh3upWQcoWTx/ DuO9DwweYzaLw91STfXIC+jrVdzcUuSnojYUPR1tS0avXaV7gHClw/ym34L/WKzJSXg8 hDZXkHdSEGAcVUv5PdqigTI3zF0Pio8BnnF7Z0wDlsT9UnbtnaFHuGjlG3GjtUGx2gDh TKtqH/xw+qfqzMHTgL4X/piZB82IkM3bCVrUhsTwZjXYH+NYRjFE/a8UHVyNmooluXGb 5L0dO84OJ3eccD7Ml+ApiEsfcXn9LEKCVFLkGr/Sj1B4MszvTLrRMbdTb35fXXdD9any hhCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fwa0g7vR; 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 f6si6981750ejl.695.2021.09.06.01.04.13; Mon, 06 Sep 2021 01:04:39 -0700 (PDT) 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=fwa0g7vR; 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 S240430AbhIFICL (ORCPT + 99 others); Mon, 6 Sep 2021 04:02:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48392 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240206AbhIFICJ (ORCPT ); Mon, 6 Sep 2021 04:02:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630915264; 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: in-reply-to:in-reply-to:references:references; bh=NO6GFqxRcZJwYtn+Qe2gbxSZz+UC4dbKjNIIRf72XCk=; b=fwa0g7vRmDOtVPXecfHthIXPO9/riPJMjGGgv7FWltwHOTZWutGzJBrxm57RuAcnxGs0at 2wKyvJx9/mbbzJIFEQCti5fI4Qp2ja/AViat7rOOWMBJoHuIY7u27cljyWD4+g7xD+6sr4 V77+tNP7LxpqmMWTBmP6sPuuQxNIFNc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-HittdaDvOAifoFig9j7D2g-1; Mon, 06 Sep 2021 04:01:03 -0400 X-MC-Unique: HittdaDvOAifoFig9j7D2g-1 Received: by mail-wr1-f72.google.com with SMTP id q14-20020a5d574e000000b00157b0978ddeso952618wrw.5 for ; Mon, 06 Sep 2021 01:01:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NO6GFqxRcZJwYtn+Qe2gbxSZz+UC4dbKjNIIRf72XCk=; b=b6eNQwnk9emJMfXstMDwObwNXbdRXJVkWIBFt4VeK4ySSddPmgAtYGeg6fEdLVzkqs Dbfra/FXX6DYYOtVK6uNeWCQasIWCqkiVe+Ow5EjBjWzGXQWgTg9Ufo63/m3SosreFe/ VIaq52t23bDrW8yq+/HZBmPfPWqC6S/A3pY7nj/sWJo2trl+jwmuv42swbWIeHghC77+ IhhQQ+/gspBucuNyEJyccW3/CcPubhGrNezMV0ae1ptUS6mArqzJLcVo1IdL8x5hUaK8 HArUqIasfi5rO8KIvgXIx5iAW7rgvptr3508IUBrXWfn7fGGg4vXh70yM6DD1fUDLWvb JOQA== X-Gm-Message-State: AOAM532PWoLvnulbYA3excEapErasbNYRVUZhG4NQ/F8heXkbdw00kw4 raoXCp4b4q15Aq2tkIAEYLW4ilrGLBxODwHGqkT9MbN7AGdxlqeuYA4a6/c7cjwLBK08GwTkOo2 04O3q6l8pwpxq6cgfoc6CQ2CI X-Received: by 2002:a1c:4d10:: with SMTP id o16mr10145330wmh.60.1630915262559; Mon, 06 Sep 2021 01:01:02 -0700 (PDT) X-Received: by 2002:a1c:4d10:: with SMTP id o16mr10145288wmh.60.1630915262309; Mon, 06 Sep 2021 01:01:02 -0700 (PDT) Received: from redhat.com ([2.55.131.183]) by smtp.gmail.com with ESMTPSA id e3sm6259897wrc.11.2021.09.06.01.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 01:01:01 -0700 (PDT) Date: Mon, 6 Sep 2021 04:00:55 -0400 From: "Michael S. Tsirkin" To: Yongji Xie Cc: Jason Wang , Stefan Hajnoczi , Stefano Garzarella , Parav Pandit , Christoph Hellwig , Christian Brauner , Randy Dunlap , Matthew Wilcox , Al Viro , Jens Axboe , bcrl@kvack.org, Jonathan Corbet , Mika =?iso-8859-1?Q?Penttil=E4?= , Dan Carpenter , joro@8bytes.org, Greg KH , He Zhe , Liu Xiaodong , Joe Perches , Robin Murphy , Will Deacon , John Garry , songmuchun@bytedance.com, virtualization , netdev@vger.kernel.org, kvm , linux-fsdevel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel Subject: Re: [PATCH v13 05/13] vdpa: Add reset callback in vdpa_config_ops Message-ID: <20210906035338-mutt-send-email-mst@kernel.org> References: <20210831103634.33-1-xieyongji@bytedance.com> <20210831103634.33-6-xieyongji@bytedance.com> <20210906015524-mutt-send-email-mst@kernel.org> <20210906023131-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 06, 2021 at 03:06:44PM +0800, Yongji Xie wrote: > On Mon, Sep 6, 2021 at 2:37 PM Michael S. Tsirkin wrote: > > > > On Mon, Sep 06, 2021 at 02:09:25PM +0800, Yongji Xie wrote: > > > On Mon, Sep 6, 2021 at 1:56 PM Michael S. Tsirkin wrote: > > > > > > > > On Tue, Aug 31, 2021 at 06:36:26PM +0800, Xie Yongji wrote: > > > > > This adds a new callback to support device specific reset > > > > > behavior. The vdpa bus driver will call the reset function > > > > > instead of setting status to zero during resetting. > > > > > > > > > > Signed-off-by: Xie Yongji > > > > > > > > > > > > This does gloss over a significant change though: > > > > > > > > > > > > > --- > > > > > @@ -348,12 +352,12 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev) > > > > > return vdev->dma_dev; > > > > > } > > > > > > > > > > -static inline void vdpa_reset(struct vdpa_device *vdev) > > > > > +static inline int vdpa_reset(struct vdpa_device *vdev) > > > > > { > > > > > const struct vdpa_config_ops *ops = vdev->config; > > > > > > > > > > vdev->features_valid = false; > > > > > - ops->set_status(vdev, 0); > > > > > + return ops->reset(vdev); > > > > > } > > > > > > > > > > static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) > > > > > > > > > > > > Unfortunately this breaks virtio_vdpa: > > > > > > > > > > > > static void virtio_vdpa_reset(struct virtio_device *vdev) > > > > { > > > > struct vdpa_device *vdpa = vd_get_vdpa(vdev); > > > > > > > > vdpa_reset(vdpa); > > > > } > > > > > > > > > > > > and there's no easy way to fix this, kernel can't recover > > > > from a reset failure e.g. during driver unbind. > > > > > > > > > > Yes, but it should be safe with the protection of software IOTLB even > > > if the reset() fails during driver unbind. > > > > > > Thanks, > > > Yongji > > > > Hmm. I don't see it. > > What exactly will happen? What prevents device from poking at > > memory after reset? Note that dma unmap in e.g. del_vqs happens > > too late. > > But I didn't see any problems with touching the memory for virtqueues. Drivers make the assumption that after reset returns no new buffers will be consumed. For example a bunch of drivers call virtqueue_detach_unused_buf. I can't say whether block makes this assumption anywhere. Needs careful auditing. > The memory should not be freed after dma unmap? But unmap does not happen until after the reset. > And the memory for the bounce buffer should also be safe to be > accessed by userspace in this case. > > > And what about e.g. interrupts? > > E.g. we have this: > > > > /* Virtqueues are stopped, nothing can use vblk->vdev anymore. */ > > vblk->vdev = NULL; > > > > and this is no longer true at this point. > > > > You're right. But I didn't see where the interrupt handler will use > the vblk->vdev. static void virtblk_done(struct virtqueue *vq) { struct virtio_blk *vblk = vq->vdev->priv; vq->vdev is the same as vblk->vdev. > So it seems to be not too late to fix it: > > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c > b/drivers/vdpa/vdpa_user/vduse_dev.c > index 5c25ff6483ad..ea41a7389a26 100644 > --- a/drivers/vdpa/vdpa_user/vduse_dev.c > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c > @@ -665,13 +665,13 @@ static void vduse_vdpa_set_config(struct > vdpa_device *vdpa, unsigned int offset, > static int vduse_vdpa_reset(struct vdpa_device *vdpa) > { > struct vduse_dev *dev = vdpa_to_vduse(vdpa); > + int ret; > > - if (vduse_dev_set_status(dev, 0)) > - return -EIO; > + ret = vduse_dev_set_status(dev, 0); > > vduse_dev_reset(dev); > > - return 0; > + return ret; > } > > static u32 vduse_vdpa_get_generation(struct vdpa_device *vdpa) > > Thanks, > Yongji Needs some comments to explain why it's done like this. BTW device is generally wedged at this point right? E.g. if reset during initialization fails, userspace will still get the reset at some later point and be confused ... -- MST