lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e81f5b86-f5ce-2a2b-bc05-5ef73fc318b5@linux.ibm.com>
Date:   Tue, 30 Aug 2022 09:43:24 -0400
From:   Anthony Krowiak <akrowiak@...ux.ibm.com>
To:     Kevin Tian <kevin.tian@...el.com>,
        Zhenyu Wang <zhenyuw@...ux.intel.com>,
        Zhi Wang <zhi.a.wang@...el.com>,
        Jani Nikula <jani.nikula@...ux.intel.com>,
        Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
        Rodrigo Vivi <rodrigo.vivi@...el.com>,
        Tvrtko Ursulin <tvrtko.ursulin@...ux.intel.com>,
        David Airlie <airlied@...ux.ie>,
        Daniel Vetter <daniel@...ll.ch>,
        Eric Farman <farman@...ux.ibm.com>,
        Matthew Rosato <mjrosato@...ux.ibm.com>,
        Halil Pasic <pasic@...ux.ibm.com>,
        Vineeth Vijayan <vneethv@...ux.ibm.com>,
        Peter Oberparleiter <oberpar@...ux.ibm.com>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Jason Herne <jjherne@...ux.ibm.com>,
        Harald Freudenberger <freude@...ux.ibm.com>,
        Diana Craciun <diana.craciun@....nxp.com>,
        Alex Williamson <alex.williamson@...hat.com>,
        Cornelia Huck <cohuck@...hat.com>,
        Longfang Liu <liulongfang@...wei.com>,
        Shameer Kolothum <shameerali.kolothum.thodi@...wei.com>,
        Jason Gunthorpe <jgg@...pe.ca>,
        Yishai Hadas <yishaih@...dia.com>,
        Eric Auger <eric.auger@...hat.com>,
        Kirti Wankhede <kwankhede@...dia.com>,
        Leon Romanovsky <leon@...nel.org>,
        Abhishek Sahu <abhsahu@...dia.com>,
        intel-gvt-dev@...ts.freedesktop.org,
        intel-gfx@...ts.freedesktop.org, dri-devel@...ts.freedesktop.org,
        linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org,
        kvm@...r.kernel.org
Cc:     Yi Liu <yi.l.liu@...el.com>
Subject: Re: [PATCH 09/15] vfio/ap: Use the new device life cycle helpers

Reviewed-by: Tony Krowiak <akrowiak@...ux.ibm.com>

On 8/27/22 1:10 PM, Kevin Tian wrote:
> From: Yi Liu <yi.l.liu@...el.com>
>
> and manage available_instances inside @init/@...ease.
>
> Signed-off-by: Yi Liu <yi.l.liu@...el.com>
> Signed-off-by: Kevin Tian <kevin.tian@...el.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,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ