From: Jason Gunthorpe <jgg@nvidia.com> To: "Liu, Yi L" <yi.l.liu@intel.com> Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>, "hch@lst.de" <hch@lst.de>, "jasowang@redhat.com" <jasowang@redhat.com>, "joro@8bytes.org" <joro@8bytes.org>, "jean-philippe@linaro.org" <jean-philippe@linaro.org>, "Tian, Kevin" <kevin.tian@intel.com>, "parav@mellanox.com" <parav@mellanox.com>, "lkml@metux.net" <lkml@metux.net>, "pbonzini@redhat.com" <pbonzini@redhat.com>, "lushenming@huawei.com" <lushenming@huawei.com>, "eric.auger@redhat.com" <eric.auger@redhat.com>, "corbet@lwn.net" <corbet@lwn.net>, "Raj, Ashok" <ashok.raj@intel.com>, "yi.l.liu@linux.intel.com" <yi.l.liu@linux.intel.com>, "Tian, Jun J" <jun.j.tian@intel.com>, "Wu, Hao" <hao.wu@intel.com>, "Jiang, Dave" <dave.jiang@intel.com>, "jacob.jun.pan@linux.intel.com" <jacob.jun.pan@linux.intel.com>, "kwankhede@nvidia.com" <kwankhede@nvidia.com>, "robin.murphy@arm.com" <robin.murphy@arm.com>, "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "iommu@lists.linux-foundation.org" <iommu@lists.linux-foundation.org>, "dwmw2@infradead.org" <dwmw2@infradead.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>, "david@gibson.dropbear.id.au" <david@gibson.dropbear.id.au>, "nicolinc@nvidia.com" <nicolinc@nvidia.com> Subject: Re: [RFC 02/20] vfio: Add device class for /dev/vfio/devices Date: Wed, 3 Nov 2021 10:25:47 -0300 [thread overview] Message-ID: <20211103132547.GM2744544@nvidia.com> (raw) In-Reply-To: <PH0PR11MB565808A9C9974A0D0D72B738C38B9@PH0PR11MB5658.namprd11.prod.outlook.com> On Tue, Nov 02, 2021 at 09:53:29AM +0000, Liu, Yi L wrote: > > vfio_uninit_group_dev(&mdev_state->vdev); > > kfree(mdev_state->pages); > > kfree(mdev_state->vconfig); > > kfree(mdev_state); > > > > pages/vconfig would logically be in a release function > > I see. So the criteria is: the pointer fields pointing to a memory buffer > allocated by the device driver should be logically be free in a release > function. right? Often yes, that is usually a good idea >I can see there are such fields in struct vfio_pci_core_device > and mdev_state (both mbochs and mdpy). So we may go with your option #2. > Is it? otherwise, needs to add release callback for all the related drivers. Yes, that is the approx trade off > > On the other hand ccw needs to rcu free the vfio_device, so that would > > have to be global overhead with this api design. > > not quite get. why ccw is special here? could you elaborate? I added a rcu usage to it in order to fix a race +static inline struct vfio_ccw_private *vfio_ccw_get_priv(struct subchannel *sch) +{ + struct vfio_ccw_private *private; + + rcu_read_lock(); + private = dev_get_drvdata(&sch->dev); + if (private && !vfio_device_try_get(&private->vdev)) + private = NULL; + rcu_read_unlock(); + return private; +} Jason
WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe via iommu <iommu@lists.linux-foundation.org> To: "Liu, Yi L" <yi.l.liu@intel.com> Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "jasowang@redhat.com" <jasowang@redhat.com>, "kwankhede@nvidia.com" <kwankhede@nvidia.com>, "hch@lst.de" <hch@lst.de>, "jean-philippe@linaro.org" <jean-philippe@linaro.org>, "Jiang, Dave" <dave.jiang@intel.com>, "Raj, Ashok" <ashok.raj@intel.com>, "corbet@lwn.net" <corbet@lwn.net>, "Tian, Kevin" <kevin.tian@intel.com>, "parav@mellanox.com" <parav@mellanox.com>, "alex.williamson@redhat.com" <alex.williamson@redhat.com>, "lkml@metux.net" <lkml@metux.net>, "david@gibson.dropbear.id.au" <david@gibson.dropbear.id.au>, "dwmw2@infradead.org" <dwmw2@infradead.org>, "Tian, Jun J" <jun.j.tian@intel.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "lushenming@huawei.com" <lushenming@huawei.com>, "iommu@lists.linux-foundation.org" <iommu@lists.linux-foundation.org>, "pbonzini@redhat.com" <pbonzini@redhat.com>, "robin.murphy@arm.com" <robin.murphy@arm.com> Subject: Re: [RFC 02/20] vfio: Add device class for /dev/vfio/devices Date: Wed, 3 Nov 2021 10:25:47 -0300 [thread overview] Message-ID: <20211103132547.GM2744544@nvidia.com> (raw) In-Reply-To: <PH0PR11MB565808A9C9974A0D0D72B738C38B9@PH0PR11MB5658.namprd11.prod.outlook.com> On Tue, Nov 02, 2021 at 09:53:29AM +0000, Liu, Yi L wrote: > > vfio_uninit_group_dev(&mdev_state->vdev); > > kfree(mdev_state->pages); > > kfree(mdev_state->vconfig); > > kfree(mdev_state); > > > > pages/vconfig would logically be in a release function > > I see. So the criteria is: the pointer fields pointing to a memory buffer > allocated by the device driver should be logically be free in a release > function. right? Often yes, that is usually a good idea >I can see there are such fields in struct vfio_pci_core_device > and mdev_state (both mbochs and mdpy). So we may go with your option #2. > Is it? otherwise, needs to add release callback for all the related drivers. Yes, that is the approx trade off > > On the other hand ccw needs to rcu free the vfio_device, so that would > > have to be global overhead with this api design. > > not quite get. why ccw is special here? could you elaborate? I added a rcu usage to it in order to fix a race +static inline struct vfio_ccw_private *vfio_ccw_get_priv(struct subchannel *sch) +{ + struct vfio_ccw_private *private; + + rcu_read_lock(); + private = dev_get_drvdata(&sch->dev); + if (private && !vfio_device_try_get(&private->vdev)) + private = NULL; + rcu_read_unlock(); + return private; +} Jason _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2021-11-03 13:25 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-25 6:28 [RFC 02/20] vfio: Add device class for /dev/vfio/devices Liu, Yi L 2021-10-25 12:53 ` Jason Gunthorpe 2021-10-25 12:53 ` Jason Gunthorpe via iommu 2021-10-29 9:47 ` Liu, Yi L 2021-10-29 9:47 ` Liu, Yi L 2021-11-01 12:50 ` Jason Gunthorpe 2021-11-01 12:50 ` Jason Gunthorpe via iommu 2021-11-02 9:53 ` Liu, Yi L 2021-11-02 9:53 ` Liu, Yi L 2021-11-03 13:25 ` Jason Gunthorpe [this message] 2021-11-03 13:25 ` Jason Gunthorpe via iommu 2021-11-11 12:32 ` Liu, Yi L 2021-11-11 12:32 ` Liu, Yi L -- strict thread matches above, loose matches on Subject: below -- 2021-09-19 6:38 [RFC 00/20] Introduce /dev/iommu for userspace I/O address space management Liu Yi L 2021-09-19 6:38 ` [RFC 02/20] vfio: Add device class for /dev/vfio/devices Liu Yi L 2021-09-19 6:38 ` Liu Yi L 2021-09-21 15:57 ` Jason Gunthorpe 2021-09-21 15:57 ` Jason Gunthorpe via iommu 2021-09-21 23:56 ` Tian, Kevin 2021-09-21 23:56 ` Tian, Kevin 2021-09-22 0:55 ` Jason Gunthorpe 2021-09-22 0:55 ` Jason Gunthorpe via iommu 2021-09-22 1:07 ` Tian, Kevin 2021-09-22 1:07 ` Tian, Kevin 2021-09-22 12:31 ` Jason Gunthorpe 2021-09-22 12:31 ` Jason Gunthorpe via iommu 2021-09-22 3:22 ` Tian, Kevin 2021-09-22 3:22 ` Tian, Kevin 2021-09-22 12:50 ` Jason Gunthorpe 2021-09-22 12:50 ` Jason Gunthorpe via iommu 2021-09-22 14:09 ` Tian, Kevin 2021-09-22 14:09 ` Tian, Kevin 2021-09-21 19:56 ` Alex Williamson 2021-09-21 19:56 ` Alex Williamson 2021-09-22 0:56 ` Tian, Kevin 2021-09-22 0:56 ` Tian, Kevin 2021-09-29 2:08 ` David Gibson 2021-09-29 2:08 ` David Gibson 2021-09-29 19:05 ` Alex Williamson 2021-09-29 19:05 ` Alex Williamson 2021-09-30 2:43 ` David Gibson 2021-09-30 2:43 ` David Gibson 2021-10-20 12:39 ` Liu, Yi L 2021-10-20 12:39 ` Liu, Yi L
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211103132547.GM2744544@nvidia.com \ --to=jgg@nvidia.com \ --cc=alex.williamson@redhat.com \ --cc=ashok.raj@intel.com \ --cc=baolu.lu@linux.intel.com \ --cc=corbet@lwn.net \ --cc=dave.jiang@intel.com \ --cc=david@gibson.dropbear.id.au \ --cc=dwmw2@infradead.org \ --cc=eric.auger@redhat.com \ --cc=hao.wu@intel.com \ --cc=hch@lst.de \ --cc=iommu@lists.linux-foundation.org \ --cc=jacob.jun.pan@linux.intel.com \ --cc=jasowang@redhat.com \ --cc=jean-philippe@linaro.org \ --cc=joro@8bytes.org \ --cc=jun.j.tian@intel.com \ --cc=kevin.tian@intel.com \ --cc=kvm@vger.kernel.org \ --cc=kwankhede@nvidia.com \ --cc=linux-kernel@vger.kernel.org \ --cc=lkml@metux.net \ --cc=lushenming@huawei.com \ --cc=nicolinc@nvidia.com \ --cc=parav@mellanox.com \ --cc=pbonzini@redhat.com \ --cc=robin.murphy@arm.com \ --cc=yi.l.liu@intel.com \ --cc=yi.l.liu@linux.intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.