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: <b400d536-632e-9212-a06d-6e41af8a6fe5@linux.microsoft.com>
Date:   Wed, 4 Aug 2021 00:57:03 +0530
From:   Praveen Kumar <kumarpraveen@...ux.microsoft.com>
To:     Wei Liu <wei.liu@...nel.org>,
        Linux on Hyper-V List <linux-hyperv@...r.kernel.org>
Cc:     virtualization@...ts.linux-foundation.org,
        Linux Kernel List <linux-kernel@...r.kernel.org>,
        Michael Kelley <mikelley@...rosoft.com>,
        Vineeth Pillai <viremana@...ux.microsoft.com>,
        Sunil Muthuswamy <sunilmut@...rosoft.com>,
        Nuno Das Neves <nunodasneves@...ux.microsoft.com>,
        pasha.tatashin@...een.com, "K. Y. Srinivasan" <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Dexuan Cui <decui@...rosoft.com>
Subject: Re: [RFC v1 8/8] mshv: add vfio bridge device

On 09-07-2021 17:13, Wei Liu wrote:
> +
> +static int mshv_vfio_set_group(struct mshv_device *dev, long attr, u64 arg)
> +{
> +	struct mshv_vfio *mv = dev->private;
> +	struct vfio_group *vfio_group;
> +	struct mshv_vfio_group *mvg;
> +	int32_t __user *argp = (int32_t __user *)(unsigned long)arg;
> +	struct fd f;
> +	int32_t fd;
> +	int ret;
> +
> +	switch (attr) {
> +	case MSHV_DEV_VFIO_GROUP_ADD:
> +		if (get_user(fd, argp))
> +			return -EFAULT;
> +
> +		f = fdget(fd);
> +		if (!f.file)
> +			return -EBADF;
> +
> +		vfio_group = mshv_vfio_group_get_external_user(f.file);
> +		fdput(f);
> +
> +		if (IS_ERR(vfio_group))
> +			return PTR_ERR(vfio_group);
> +
> +		mutex_lock(&mv->lock);
> +
> +		list_for_each_entry(mvg, &mv->group_list, node) {
> +			if (mvg->vfio_group == vfio_group) {
> +				mutex_unlock(&mv->lock);
> +				mshv_vfio_group_put_external_user(vfio_group);
> +				return -EEXIST;
> +			}
> +		}
> +
> +		mvg = kzalloc(sizeof(*mvg), GFP_KERNEL_ACCOUNT);
> +		if (!mvg) {
> +			mutex_unlock(&mv->lock);
> +			mshv_vfio_group_put_external_user(vfio_group);
> +			return -ENOMEM;
> +		}
> +
> +		list_add_tail(&mvg->node, &mv->group_list);
> +		mvg->vfio_group = vfio_group;
> +
> +		mutex_unlock(&mv->lock);
> +
> +		return 0;
> +
> +	case MSHV_DEV_VFIO_GROUP_DEL:
> +		if (get_user(fd, argp))
> +			return -EFAULT;
> +
> +		f = fdget(fd);
> +		if (!f.file)
> +			return -EBADF;

Can we move these both checks above switch statement and do fdput accordingly under both case statement accordingly?

> +
> +		ret = -ENOENT;
> +
> +		mutex_lock(&mv->lock);
> +
> +		list_for_each_entry(mvg, &mv->group_list, node) {
> +			if (!mshv_vfio_external_group_match_file(mvg->vfio_group,
> +								 f.file))
> +				continue;
> +
> +			list_del(&mvg->node);
> +			mshv_vfio_group_put_external_user(mvg->vfio_group);
> +			kfree(mvg);
> +			ret = 0;
> +			break;
> +		}
> +
> +		mutex_unlock(&mv->lock);
> +
> +		fdput(f);
> +
> +		return ret;
> +	}
> +
> +	return -ENXIO;
> +}
> +
> +static int mshv_vfio_set_attr(struct mshv_device *dev,
> +			      struct mshv_device_attr *attr)
> +{
> +	switch (attr->group) {
> +	case MSHV_DEV_VFIO_GROUP:
> +		return mshv_vfio_set_group(dev, attr->attr, attr->addr);
> +	}
> +
> +	return -ENXIO;
> +}
> +
> +static int mshv_vfio_has_attr(struct mshv_device *dev,
> +			      struct mshv_device_attr *attr)
> +{
> +	switch (attr->group) {
> +	case MSHV_DEV_VFIO_GROUP:
> +		switch (attr->attr) {
> +		case MSHV_DEV_VFIO_GROUP_ADD:
> +		case MSHV_DEV_VFIO_GROUP_DEL:
> +			return 0;
> +		}
> +
> +		break;

do we need this break statement ? If not, lets remove it.
> +	}
> +
> +	return -ENXIO;
> +}
> +
> +static void mshv_vfio_destroy(struct mshv_device *dev)
> +{
> +	struct mshv_vfio *mv = dev->private;
> +	struct mshv_vfio_group *mvg, *tmp;
> +
> +	list_for_each_entry_safe(mvg, tmp, &mv->group_list, node) {
> +		mshv_vfio_group_put_external_user(mvg->vfio_group);
> +		list_del(&mvg->node);
> +		kfree(mvg);
> +	}
> +
> +	kfree(mv);
> +	kfree(dev);

We are freeing up dev. Please ignore my comment in caller patch. Thanks.

> +}
> +
> +static int mshv_vfio_create(struct mshv_device *dev, u32 type);
> +
> +static struct mshv_device_ops mshv_vfio_ops = {
> +	.name = "mshv-vfio",
> +	.create = mshv_vfio_create,
> +	.destroy = mshv_vfio_destroy,
> +	.set_attr = mshv_vfio_set_attr,
> +	.has_attr = mshv_vfio_has_attr,
> +};

Regards,

~Praveen.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ