From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7BZQ-0001xo-Sx for qemu-devel@nongnu.org; Wed, 16 Nov 2016 20:32:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7BZN-0003s2-Q6 for qemu-devel@nongnu.org; Wed, 16 Nov 2016 20:32:56 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7BZN-0003r2-Hw for qemu-devel@nongnu.org; Wed, 16 Nov 2016 20:32:53 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAH1T77Y044735 for ; Wed, 16 Nov 2016 20:32:52 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 26rvx2xdm1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Nov 2016 20:32:51 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Nov 2016 18:32:50 -0700 Date: Thu, 17 Nov 2016 09:32:43 +0800 From: Dong Jia Shi References: <1479223805-22895-1-git-send-email-kwankhede@nvidia.com> <1479223805-22895-13-git-send-email-kwankhede@nvidia.com> <20161116063759.GD5531@bjsdjshi@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Message-Id: <20161117013243.GC6620@bjsdjshi@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v13 12/22] vfio: Add notifier callback to parent's ops structure of mdev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirti Wankhede Cc: alex.williamson@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, cjia@nvidia.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, kevin.tian@intel.com, jike.song@intel.com, bjsdjshi@linux.vnet.ibm.com, linux-kernel@vger.kernel.org * Kirti Wankhede [2016-11-16 20:47:18 +0530]: > > > On 11/16/2016 12:07 PM, Dong Jia Shi wrote: > > * Kirti Wankhede [2016-11-15 20:59:55 +0530]: > > > > Hi Kirti, > > > > [...] > > > >> diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c > >> index ffc36758cb84..4fc63db38829 100644 > >> --- a/drivers/vfio/mdev/vfio_mdev.c > >> +++ b/drivers/vfio/mdev/vfio_mdev.c > >> @@ -24,6 +24,15 @@ > >> #define DRIVER_AUTHOR "NVIDIA Corporation" > >> #define DRIVER_DESC "VFIO based driver for Mediated device" > >> > >> +static int vfio_mdev_notifier(struct notifier_block *nb, unsigned long action, > >> + void *data) > >> +{ > >> + struct mdev_device *mdev = container_of(nb, struct mdev_device, nb); > >> + struct parent_device *parent = mdev->parent; > >> + > >> + return parent->ops->notifier(mdev, action, data); > >> +} > >> + > >> static int vfio_mdev_open(void *device_data) > >> { > >> struct mdev_device *mdev = device_data; > >> @@ -36,9 +45,18 @@ static int vfio_mdev_open(void *device_data) > >> if (!try_module_get(THIS_MODULE)) > >> return -ENODEV; > >> > >> + if (likely(parent->ops->notifier)) { > >> + mdev->nb.notifier_call = vfio_mdev_notifier; > >> + if (vfio_register_notifier(&mdev->dev, &mdev->nb)) > >> + pr_err("Failed to register notifier for mdev\n"); > > I think we should just return here if the error value is not -ENOTTY. > > > > It might be the case where iommu backend module might not support > .register_notifier(). In that case vfio_register_notifier() returns > -ENOTTY and that should not fail this open() call > Changing it to: > > ret = vfio_register_notifier(&mdev->dev, &mdev->nb); > if (ret && (ret != -ENOTTY)) { > pr_err("Failed to register notifier for mdev\n"); > module_put(THIS_MODULE); > return ret; > } Nod. And we need not call vfio_unregister_notifier once error occurs in open() in this case. > > Thanks, > Kirti > -- Dong Jia