Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1503243

Re: [PATCH v9 12/12] docs: Sample driver to demonstrate how to use Mediated device framework.

From Alex Williamson <alex.williamson@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH v9 12/12] docs: Sample driver to demonstrate how to use Mediated device framework.
Date 2016-10-18 19:20 +0200
Message-ID <stGdr-4O9-23@gated-at.bofh.it> (permalink)
References <stnDQ-JF-5@gated-at.bofh.it> <stnDQ-JF-7@gated-at.bofh.it> <stGdr-4O9-25@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, 18 Oct 2016 10:54:11 +0800
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> * Kirti Wankhede <kwankhede@nvidia.com> [2016-10-18 02:52:12 +0530]:
> 
> ...snip...
> 
> > +static ssize_t mdev_access(struct mdev_device *mdev, char *buf,
> > +		size_t count, loff_t pos, bool is_write)
> > +{
> > +	struct mdev_state *mdev_state;
> > +	unsigned int index;
> > +	loff_t offset;
> > +	int ret = 0;
> > +
> > +	if (!mdev || !buf)
> > +		return -EINVAL;
> > +
> > +	mdev_state = mdev_get_drvdata(mdev);
> > +	if (!mdev_state) {
> > +		pr_err("%s mdev_state not found\n", __func__);
> > +		return -EINVAL;
> > +	}
> > +
> > +	mutex_lock(&mdev_state->ops_lock);
> > +
> > +	index = MTTY_VFIO_PCI_OFFSET_TO_INDEX(pos);
> > +	offset = pos & MTTY_VFIO_PCI_OFFSET_MASK;
> > +	switch (index) {
> > +	case VFIO_PCI_CONFIG_REGION_INDEX:
> > +
> > +#if defined(DEBUG)
> > +		pr_info("%s: PCI config space %s at offset 0x%llx\n",
> > +			 __func__, is_write ? "write" : "read", offset);
> > +#endif
> > +		if (is_write) {
> > +			dump_buffer(buf, count);
> > +			handle_pci_cfg_write(mdev_state, offset, buf, count);
> > +		} else {
> > +			memcpy(buf, (mdev_state->vconfig + offset), count);
> > +			dump_buffer(buf, count);  
> Dear Kirti:
> 
> Shouldn't we use copy_from_user instead of memcpy on @buf here? And I'm
> wondering if dump_buffer could really work since it tries to dereference
> a *__user* marked pointor.

I agree, the __user attribute is getting lost here and we're operating
on user buffers as if they were kernel buffers.  That's a bug.  Thanks,

Alex
 
> Otherwise, this is a good example driver. Thanks!
> 
> > +		}
> > +
> > +		break;
> > +
> > +	case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
> > +		if (!mdev_state->region_info[index].start)
> > +			mdev_read_base(mdev_state);
> > +
> > +		if (is_write) {
> > +			dump_buffer(buf, count);
> > +
> > +#if defined(DEBUG_REGS)
> > +			pr_info("%s: BAR%d  WR @0x%llx %s val:0x%02x dlab:%d\n",
> > +				__func__, index, offset, wr_reg[offset],
> > +				(u8)*buf, mdev_state->s[index].dlab);
> > +#endif
> > +			handle_bar_write(index, mdev_state, offset, buf, count);
> > +		} else {
> > +			handle_bar_read(index, mdev_state, offset, buf, count);
> > +			dump_buffer(buf, count);
> > +
> > +#if defined(DEBUG_REGS)
> > +			pr_info("%s: BAR%d  RD @0x%llx %s val:0x%02x dlab:%d\n",
> > +				__func__, index, offset, rd_reg[offset],
> > +				(u8)*buf, mdev_state->s[index].dlab);
> > +#endif
> > +		}
> > +		break;
> > +
> > +	default:
> > +		ret = -1;
> > +		goto accessfailed;
> > +	}
> > +
> > +	ret = count;
> > +
> > +
> > +accessfailed:
> > +	mutex_unlock(&mdev_state->ops_lock);
> > +
> > +	return ret;
> > +}
> > +  
> ...snip...
> 
> > +ssize_t mtty_read(struct mdev_device *mdev, char __user *buf,
> > +			size_t count, loff_t *ppos)
> > +{
> > +	return mdev_access(mdev, buf, count, *ppos, false);
> > +}
> > +
> > +ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf,
> > +			 size_t count, loff_t *ppos)
> > +{
> > +	return mdev_access(mdev, (char *)buf, count, *ppos, true);
> > +}
> > +  
> ...snip...
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v9 00/12] Add Mediated device support Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
  [PATCH v9 10/12] vfio: Add function to get device_api string from vfio_device_info.flags Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 10/12] vfio: Add function to get device_api string  from vfio_device_info.flags Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 21:40 +0200
      Re: [PATCH v9 10/12] vfio: Add function to get device_api string from  vfio_device_info.flags Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-20 22:40 +0200
        Re: [PATCH v9 10/12] vfio: Add function to get device_api string  from vfio_device_info.flags Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 23:10 +0200
          Re: [PATCH v9 10/12] vfio: Add function to get device_api string from  vfio_device_info.flags Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-20 23:20 +0200
            Re: [PATCH v9 10/12] vfio: Add function to get device_api string  from vfio_device_info.flags Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 23:30 +0200
              Re: [PATCH v9 10/12] vfio: Add function to get device_api string from  vfio_device_info.flags Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-21 05:10 +0200
                Re: [PATCH v9 10/12] vfio: Add function to get device_api string  from vfio_device_info.flags Alex Williamson <alex.williamson@redhat.com> - 2016-10-21 05:30 +0200
  [PATCH v9 02/12] vfio: VFIO based driver for Mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    RE: [PATCH v9 02/12] vfio: VFIO based driver for Mediated devices "Tian, Kevin" <kevin.tian@intel.com> - 2016-10-26 09:00 +0200
      Re: [PATCH v9 02/12] vfio: VFIO based driver for Mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-26 17:10 +0200
  [PATCH v9 08/12] vfio_pci: Updated to use vfio_set_irqs_validate_and_prepare() Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
  [PATCH v9 11/12] docs: Add Documentation for Mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 11/12] docs: Add Documentation for Mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-25 18:20 +0200
  [PATCH v9 09/12] vfio_platform: Updated to use vfio_set_irqs_validate_and_prepare() Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
  [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-19 23:10 +0200
      Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-20 22:20 +0200
        Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-24 04:40 +0200
          RE: [PATCH v9 04/12] vfio iommu: Add support for mediated devices "Tian, Kevin" <kevin.tian@intel.com> - 2016-10-26 09:30 +0200
            Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-26 17:10 +0200
      RE: [PATCH v9 04/12] vfio iommu: Add support for mediated devices "Tian, Kevin" <kevin.tian@intel.com> - 2016-10-26 10:00 +0200
        Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-26 17:30 +0200
      RE: [PATCH v9 04/12] vfio iommu: Add support for mediated devices "Tian, Kevin" <kevin.tian@intel.com> - 2016-10-26 10:00 +0200
        Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-26 17:20 +0200
    Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Jike Song <jike.song@intel.com> - 2016-10-21 10:00 +0200
      Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Alex Williamson <alex.williamson@redhat.com> - 2016-10-21 16:40 +0200
        Re: [PATCH v9 04/12] vfio iommu: Add support for mediated devices Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-24 12:40 +0200
  [PATCH v9 06/12] vfio_pci: Update vfio_pci to use vfio_info_add_capability() Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 06/12] vfio_pci: Update vfio_pci to use  vfio_info_add_capability() Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 21:30 +0200
      Re: [PATCH v9 06/12] vfio_pci: Update vfio_pci to use  vfio_info_add_capability() Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-24 23:30 +0200
        Re: [PATCH v9 06/12] vfio_pci: Update vfio_pci to use  vfio_info_add_capability() Alex Williamson <alex.williamson@redhat.com> - 2016-10-24 23:40 +0200
  [PATCH v9 03/12] vfio: Rearrange functions to get vfio_group from dev Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 03/12] vfio: Rearrange functions to get vfio_group  from dev Alex Williamson <alex.williamson@redhat.com> - 2016-10-19 19:30 +0200
  [PATCH v9 05/12] vfio: Introduce common function to add capabilities Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 05/12] vfio: Introduce common function to add  capabilities Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 21:30 +0200
      Re: [PATCH v9 05/12] vfio: Introduce common function to add  capabilities Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-24 23:30 +0200
        Re: [PATCH v9 05/12] vfio: Introduce common function to add  capabilities Alex Williamson <alex.williamson@redhat.com> - 2016-10-24 23:40 +0200
  [PATCH v9 01/12] vfio: Mediated device Core driver Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-17 23:30 +0200
    Re: [PATCH v9 01/12] vfio: Mediated device Core driver Alex Williamson <alex.williamson@redhat.com> - 2016-10-19 01:20 +0200
      Re: [PATCH v9 01/12] vfio: Mediated device Core driver Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-19 21:20 +0200
        Re: [PATCH v9 01/12] vfio: Mediated device Core driver Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 00:30 +0200
    Re: [PATCH v9 01/12] vfio: Mediated device Core driver Jike Song <jike.song@intel.com> - 2016-10-20 09:30 +0200
      Re: [PATCH v9 01/12] vfio: Mediated device Core driver Alex Williamson <alex.williamson@redhat.com> - 2016-10-20 19:20 +0200
        Re: [PATCH v9 01/12] vfio: Mediated device Core driver Jike Song <jike.song@intel.com> - 2016-10-21 04:50 +0200
    RE: [PATCH v9 01/12] vfio: Mediated device Core driver "Tian, Kevin" <kevin.tian@intel.com> - 2016-10-26 09:00 +0200
      Re: [PATCH v9 01/12] vfio: Mediated device Core driver Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-26 17:00 +0200
  Re: [PATCH v9 00/12] Add Mediated device support Alex Williamson <alex.williamson@redhat.com> - 2016-10-17 23:50 +0200
  Re: [PATCH v9 12/12] docs: Sample driver to demonstrate how to use  Mediated device framework. Alex Williamson <alex.williamson@redhat.com> - 2016-10-18 19:20 +0200
    Re: [PATCH v9 12/12] docs: Sample driver to demonstrate how to use  Mediated device framework. Kirti Wankhede <kwankhede@nvidia.com> - 2016-10-19 21:20 +0200
  Re: [PATCH v9 00/12] Add Mediated device support Jike Song <jike.song@intel.com> - 2016-10-24 09:20 +0200

csiph-web