Re: [PATCH V2] drivers/uio/uio.c: DMA mapping, interrupt extensions, etc.

Previous thread: [PATCH V2] drivers/uio/uio_pci_generic.c: allow access for non-privileged processes by Tom Lyon on Thursday, April 15, 2010 - 1:51 pm. (1 message)

Next thread: [PATCH] Staging: dream: smd: smd_qmi: fix code style issues by Chihau Chau on Thursday, April 15, 2010 - 2:01 pm. (1 message)
From: Tom Lyon
Date: Thursday, April 15, 2010 - 1:55 pm

This is the second of 2 related, but independent, patches. This is for 
uio.c, the previous is for uio_pci_generic.c.

The 2 patches were previously one large patch. Changes for this version:
- uio_pci_generic.c just gets extensions so that a single fd can be used
  by non-privileged processes for interrupt control and mmaps
- All of the DMA and IOMMU related stuff move to uio.c; no longer a need
  to pass ioctls to individual uio drivers. It turns out that the code 
  is not PCI specific anyways.
- A new ioctl to pin DMA buffers to certain IO virtual addresses for KVM.
- New eventfd based interrupt notifications, including support for PCI
  specific MSI and MSI-X interrupts.
- PCI specific code to reset PCI functions before and after use

diff -ruNP linux-2.6.33/drivers/uio/uio.c uio-2.6.33/drivers/uio/uio.c
--- linux-2.6.33/drivers/uio/uio.c	2010-02-24 10:52:17.000000000 -0800
+++ uio-2.6.33/drivers/uio/uio.c	2010-04-15 12:39:02.000000000 -0700
@@ -23,6 +23,11 @@
 #include <linux/string.h>
 #include <linux/kobject.h>
 #include <linux/uio_driver.h>
+#include <linux/mmu_notifier.h>
+#include <linux/pci.h>
+#include <linux/iommu.h>
+#include <linux/eventfd.h>
+#include <linux/semaphore.h>
 
 #define UIO_MAX_DEVICES 255
 
@@ -37,8 +42,37 @@
 	struct uio_info		*info;
 	struct kobject		*map_dir;
 	struct kobject		*portio_dir;
+	struct pci_dev		*pdev;
+	int			pmaster;
+	struct semaphore	gate;
+	int			listeners;
+	atomic_t		mapcount;
+	struct msix_entry	*msix;
+	int			nvec;
+	struct iommu_domain	*domain;
+	int			cachec;
+	struct eventfd_ctx	*ev_irq;
+	struct eventfd_ctx	*ev_msi;
+	struct eventfd_ctx	**ev_msix;
 };
 
+/*
+ * Structure for keeping track of memory nailed down by the
+ * user for DMA
+ */
+struct dma_map_page {
+        struct list_head list;
+        struct page     **pages;
+	struct scatterlist *sg;
+        dma_addr_t      daddr;
+	unsigned long	vaddr;
+	int		npage;
+	int		rdwr;
+};
+
+static void uio_disable_msi(struct uio_device ...
From: Joerg Roedel
Date: Saturday, April 17, 2010 - 3:43 am

Why do you want to allow multiple opens for a device? Is it not

If userspace calls this path this will make all the addresses mapped
with DMA-API paths unusable by the device. This doesn't look like a sane
userspace interface.

For better and more in-depth review I suggest that you split up this
large patch into a series of smaler which implement specific aspects of
your work.

	Joerg

P.S.: I got these warning when applying your patches ...

Applying: drivers/uio/uio_pci_generic.c: allow access for non-privileged processes
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:86: trailing whitespace.
                        info->mem[j].name = name; 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:87: trailing whitespace.
                        info->mem[j].addr = pci_resource_start(pdev, i); 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:89: trailing whitespace.
                        info->mem[j].memtype = UIO_MEM_PHYS; 
warning: 3 lines add whitespace errors.
Applying: drivers/uio/uio.c: DMA mapping, interrupt extensions, etc.
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:315: trailing whitespace.
                ret = iommu_map_range(idev->domain, iova, 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:325: trailing whitespace.
        } 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:366: trailing whitespace.
         * adjacent pages, but noone seems to really do that. So we squash 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:368: trailing whitespace.
         * This works if (a) there is an iommu, or (b) the user allocates 
/home/joro/src/linux.trees.git/.git/rebase-apply/patch:578: trailing whitespace.
                        unsigned int cmd, unsigned long arg) 
warning: squelched 1 whitespace error
warning: 6 lines add whitespace errors.

And there are also some coding-style issues.
--

From: Tom Lyon
Date: Saturday, April 17, 2010 - 10:04 am

The current uio and uio_pci_generic allow multiple opens; I was just preserving that behavior.



--

From: Avi Kivity
Date: Saturday, April 17, 2010 - 11:34 am

Use __u64 for both, otherwise you need to rewrite the structures in the 

What units?  Size is probably too small.  Suggest unsigned type to avoid 



These three need some documentation.


-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.

--

Previous thread: [PATCH V2] drivers/uio/uio_pci_generic.c: allow access for non-privileged processes by Tom Lyon on Thursday, April 15, 2010 - 1:51 pm. (1 message)

Next thread: [PATCH] Staging: dream: smd: smd_qmi: fix code style issues by Chihau Chau on Thursday, April 15, 2010 - 2:01 pm. (1 message)