From: Anthony Krowiak <akrowiak@linux.ibm.com>
To: Kevin Tian <kevin.tian@intel.com>,
Zhenyu Wang <zhenyuw@linux.intel.com>,
Zhi Wang <zhi.a.wang@intel.com>,
Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Eric Farman <farman@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Halil Pasic <pasic@linux.ibm.com>,
Vineeth Vijayan <vneethv@linux.ibm.com>,
Peter Oberparleiter <oberpar@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Jason Herne <jjherne@linux.ibm.com>,
Harald Freudenberger <freude@linux.ibm.com>,
Diana Craciun <diana.craciun@oss.nxp.com>,
Alex Williamson <alex.williamson@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
Longfang Liu <liulongfang@huawei.com>,
Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Yishai Hadas <yishaih@nvidia.com>,
Eric Auger <eric.auger@redhat.com>,
Kirti Wankhede <kwankhede@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
Abhishek Sahu <abhsahu@nvidia.com>,
intel-gvt-dev@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
kvm@vger.kernel.org
Cc: Yi Liu <yi.l.liu@intel.com>
Subject: Re: [PATCH 09/15] vfio/ap: Use the new device life cycle helpers
Date: Tue, 30 Aug 2022 09:43:24 -0400 [thread overview]
Message-ID: <e81f5b86-f5ce-2a2b-bc05-5ef73fc318b5@linux.ibm.com> (raw)
In-Reply-To: <20220827171037.30297-10-kevin.tian@intel.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
On 8/27/22 1:10 PM, Kevin Tian wrote:
> From: Yi Liu <yi.l.liu@intel.com>
>
> and manage available_instances inside @init/@release.
>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> Signed-off-by: Kevin Tian <kevin.tian@intel.com>
> ---
> drivers/s390/crypto/vfio_ap_ops.c | 50 ++++++++++++++++++-------------
> 1 file changed, 29 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index 6c8c41fac4e1..803aadfd0876 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -684,42 +684,44 @@ static bool vfio_ap_mdev_filter_matrix(unsigned long *apm, unsigned long *aqm,
> AP_DOMAINS);
> }
>
> -static int vfio_ap_mdev_probe(struct mdev_device *mdev)
> +static int vfio_ap_mdev_init_dev(struct vfio_device *vdev)
> {
> - struct ap_matrix_mdev *matrix_mdev;
> - int ret;
> + struct ap_matrix_mdev *matrix_mdev =
> + container_of(vdev, struct ap_matrix_mdev, vdev);
>
> if ((atomic_dec_if_positive(&matrix_dev->available_instances) < 0))
> return -EPERM;
>
> - matrix_mdev = kzalloc(sizeof(*matrix_mdev), GFP_KERNEL);
> - if (!matrix_mdev) {
> - ret = -ENOMEM;
> - goto err_dec_available;
> - }
> - vfio_init_group_dev(&matrix_mdev->vdev, &mdev->dev,
> - &vfio_ap_matrix_dev_ops);
> -
> - matrix_mdev->mdev = mdev;
> + matrix_mdev->mdev = to_mdev_device(vdev->dev);
> vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->matrix);
> matrix_mdev->pqap_hook = handle_pqap;
> vfio_ap_matrix_init(&matrix_dev->info, &matrix_mdev->shadow_apcb);
> hash_init(matrix_mdev->qtable.queues);
>
> + return 0;
> +}
> +
> +static int vfio_ap_mdev_probe(struct mdev_device *mdev)
> +{
> + struct ap_matrix_mdev *matrix_mdev;
> + int ret;
> +
> + matrix_mdev = vfio_alloc_device(ap_matrix_mdev, vdev, &mdev->dev,
> + &vfio_ap_matrix_dev_ops);
> + if (IS_ERR(matrix_mdev))
> + return PTR_ERR(matrix_mdev);
> +
> ret = vfio_register_emulated_iommu_dev(&matrix_mdev->vdev);
> if (ret)
> - goto err_list;
> + goto err_put_vdev;
> dev_set_drvdata(&mdev->dev, matrix_mdev);
> mutex_lock(&matrix_dev->mdevs_lock);
> list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
> mutex_unlock(&matrix_dev->mdevs_lock);
> return 0;
>
> -err_list:
> - vfio_uninit_group_dev(&matrix_mdev->vdev);
> - kfree(matrix_mdev);
> -err_dec_available:
> - atomic_inc(&matrix_dev->available_instances);
> +err_put_vdev:
> + vfio_put_device(&matrix_mdev->vdev);
> return ret;
> }
>
> @@ -766,6 +768,12 @@ static void vfio_ap_mdev_unlink_fr_queues(struct ap_matrix_mdev *matrix_mdev)
> }
> }
>
> +static void vfio_ap_mdev_release_dev(struct vfio_device *vdev)
> +{
> + vfio_free_device(vdev);
> + atomic_inc(&matrix_dev->available_instances);
> +}
> +
> static void vfio_ap_mdev_remove(struct mdev_device *mdev)
> {
> struct ap_matrix_mdev *matrix_mdev = dev_get_drvdata(&mdev->dev);
> @@ -779,9 +787,7 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)
> list_del(&matrix_mdev->node);
> mutex_unlock(&matrix_dev->mdevs_lock);
> mutex_unlock(&matrix_dev->guests_lock);
> - vfio_uninit_group_dev(&matrix_mdev->vdev);
> - kfree(matrix_mdev);
> - atomic_inc(&matrix_dev->available_instances);
> + vfio_put_device(&matrix_mdev->vdev);
> }
>
> static ssize_t name_show(struct mdev_type *mtype,
> @@ -1794,6 +1800,8 @@ static const struct attribute_group vfio_queue_attr_group = {
> };
>
> static const struct vfio_device_ops vfio_ap_matrix_dev_ops = {
> + .init = vfio_ap_mdev_init_dev,
> + .release = vfio_ap_mdev_release_dev,
> .open_device = vfio_ap_mdev_open_device,
> .close_device = vfio_ap_mdev_close_device,
> .ioctl = vfio_ap_mdev_ioctl,
next prev parent reply other threads:[~2022-08-30 14:13 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-27 17:10 [PATCH 00/15] Tidy up vfio_device life cycle Kevin Tian
2022-08-27 17:10 ` [PATCH 01/15] vfio: Add helpers for unifying " Kevin Tian
2022-08-30 13:42 ` Anthony Krowiak
2022-08-30 15:10 ` Jason Gunthorpe
2022-08-30 19:43 ` Anthony Krowiak
2022-08-31 6:03 ` Tian, Kevin
2022-08-27 17:10 ` [PATCH 02/15] vfio/pci: Use the new device life cycle helpers Kevin Tian
2022-08-27 17:10 ` [PATCH 03/15] vfio/mlx5: " Kevin Tian
2022-08-27 17:10 ` [PATCH 04/15] vfio/hisi_acc: " Kevin Tian
2022-08-31 7:36 ` Shameerali Kolothum Thodi
2022-08-27 17:10 ` [PATCH 05/15] vfio/mdpy: " Kevin Tian
2022-08-27 17:10 ` [PATCH 06/15] vfio/mtty: " Kevin Tian
2022-08-27 17:10 ` [PATCH 07/15] vfio/mbochs: " Kevin Tian
2022-08-27 17:10 ` [PATCH 08/15] drm/i915/gvt: " Kevin Tian
2022-08-27 17:10 ` [PATCH 09/15] vfio/ap: " Kevin Tian
2022-08-30 13:43 ` Anthony Krowiak [this message]
2022-08-27 17:10 ` [PATCH 10/15] vfio/fsl-mc: " Kevin Tian
2022-08-31 0:22 ` Jason Gunthorpe
2022-08-31 6:14 ` Tian, Kevin
2022-08-27 17:10 ` [PATCH 11/15] vfio/platform: " Kevin Tian
2022-08-27 17:10 ` [PATCH 12/15] vfio/amba: " Kevin Tian
2022-08-27 17:10 ` [PATCH 13/15] vfio/ccw: " Kevin Tian
2022-08-27 10:39 ` Tian, Kevin
2022-08-27 17:10 ` [PATCH 14/15] vfio: Rename vfio_device_put() and vfio_device_try_get() Kevin Tian
2022-08-27 17:10 ` [PATCH 15/15] vfio: Add struct device to vfio_device Kevin Tian
2022-08-30 22:18 ` Alex Williamson
2022-08-30 23:53 ` Jason Gunthorpe
2022-08-31 6:10 ` Tian, Kevin
2022-08-31 17:15 ` Alex Williamson
2022-09-01 0:46 ` Tian, Kevin
2022-09-01 2:05 ` Alex Williamson
2022-08-31 0:32 ` Jason Gunthorpe
2022-08-31 6:14 ` Tian, Kevin
2022-08-27 22:41 ` [PATCH 00/15] Tidy up vfio_device life cycle Tian, Kevin
2022-08-31 0:34 ` Jason Gunthorpe
2022-08-31 6:14 ` Tian, Kevin
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=e81f5b86-f5ce-2a2b-bc05-5ef73fc318b5@linux.ibm.com \
--to=akrowiak@linux.ibm.com \
--cc=abhsahu@nvidia.com \
--cc=agordeev@linux.ibm.com \
--cc=airlied@linux.ie \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=daniel@ffwll.ch \
--cc=diana.craciun@oss.nxp.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric.auger@redhat.com \
--cc=farman@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=jgg@ziepe.ca \
--cc=jjherne@linux.ibm.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=mjrosato@linux.ibm.com \
--cc=oberpar@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=rodrigo.vivi@intel.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=svens@linux.ibm.com \
--cc=tvrtko.ursulin@linux.intel.com \
--cc=vneethv@linux.ibm.com \
--cc=yi.l.liu@intel.com \
--cc=yishaih@nvidia.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox