diff mbox series

[1/3] drm/i915: Introduce remap_io_sg() to prefault discontiguous objects

Message ID 20191223041512.3582-1-abdiel.janulgue@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [1/3] drm/i915: Introduce remap_io_sg() to prefault discontiguous objects | expand

Commit Message

Abdiel Janulgue Dec. 23, 2019, 4:15 a.m. UTC
Provide a way to set the PTE within apply_page_range for discontiguous
objects in addition to the existing method of just incrementing the pfn
for a page range.

Signed-off-by: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_drv.h |  3 ++
 drivers/gpu/drm/i915/i915_mm.c  | 67 +++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

Comments

kernel test robot Dec. 27, 2019, 9:43 a.m. UTC | #1
Hi Abdiel,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip v5.5-rc3 next-20191220]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Abdiel-Janulgue/drm-i915-Introduce-remap_io_sg-to-prefault-discontiguous-objects/20191225-032829
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-129-g341daf20-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/i915/i915_mm.c:130:32: sparse: sparse: Using plain integer as NULL pointer

vim +130 drivers/gpu/drm/i915/i915_mm.c

   114	
   115	/**
   116	 * remap_io_sg - remap an IO mapping to userspace
   117	 * @vma: user vma to map to
   118	 * @addr: target user address to start at
   119	 * @io_start: IO start
   120	 * @sgl: Start sg entry
   121	 * @size: size of map area
   122	 * @iomap: the source io_mapping
   123	 *
   124	 *  Note: this is only safe if the mm semaphore is held when called.
   125	 */
   126	int remap_io_sg(struct vm_area_struct *vma,
   127			unsigned long addr, resource_size_t io_start, struct scatterlist *sgl,
   128			unsigned long size, struct io_mapping *iomap)
   129	{
 > 130		struct remap_pfn r = { 0 };

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 95db8017f138..71a20387f931 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2015,6 +2015,9 @@  int i915_reg_read_ioctl(struct drm_device *dev, void *data,
 int remap_io_mapping(struct vm_area_struct *vma,
 		     unsigned long addr, unsigned long pfn, unsigned long size,
 		     struct io_mapping *iomap);
+int remap_io_sg(struct vm_area_struct *vma,
+		unsigned long addr, resource_size_t io_start, struct scatterlist *sgl,
+		unsigned long size, struct io_mapping *iomap);
 
 static inline int intel_hws_csb_write_index(struct drm_i915_private *i915)
 {
diff --git a/drivers/gpu/drm/i915/i915_mm.c b/drivers/gpu/drm/i915/i915_mm.c
index 318562ce64c0..4ae9ef470ad2 100644
--- a/drivers/gpu/drm/i915/i915_mm.c
+++ b/drivers/gpu/drm/i915/i915_mm.c
@@ -32,7 +32,13 @@ 
 struct remap_pfn {
 	struct mm_struct *mm;
 	unsigned long pfn;
+	unsigned long start_pfn;
+	unsigned long size;
 	pgprot_t prot;
+
+	resource_size_t io_start;
+	struct sg_dma_page_iter sgiter;
+	struct scatterlist *sgl;
 };
 
 static int remap_pfn(pte_t *pte, unsigned long addr, void *data)
@@ -46,6 +52,31 @@  static int remap_pfn(pte_t *pte, unsigned long addr, void *data)
 	return 0;
 }
 
+static int remap_io(pte_t *pte, unsigned long addr, void *data)
+{
+	struct remap_pfn *r = data;
+	struct sg_dma_page_iter *sgiter = &r->sgiter;
+	if (!r->pfn)
+		__sg_page_iter_start(&sgiter->base, r->sgl,
+				     r->size >> PAGE_SHIFT, 0);
+
+	if (__sg_page_iter_dma_next(sgiter)) {
+		dma_addr_t addr = sg_page_iter_dma_address(sgiter);
+		unsigned long pfn = (r->io_start + addr) >> PAGE_SHIFT;
+
+		if (!r->pfn)
+			r->start_pfn = pfn;
+		r->pfn = pfn;
+		/* Special PTE are not associated with any struct page */
+		set_pte_at(r->mm, addr, pte, pte_mkspecial(pfn_pte(r->pfn, r->prot)));
+
+		return 0;
+	}
+
+	GEM_WARN_ON("invalid range");
+	return -EINVAL;
+}
+
 /**
  * remap_io_mapping - remap an IO mapping to userspace
  * @vma: user vma to map to
@@ -80,3 +111,39 @@  int remap_io_mapping(struct vm_area_struct *vma,
 
 	return 0;
 }
+
+/**
+ * remap_io_sg - remap an IO mapping to userspace
+ * @vma: user vma to map to
+ * @addr: target user address to start at
+ * @io_start: IO start
+ * @sgl: Start sg entry
+ * @size: size of map area
+ * @iomap: the source io_mapping
+ *
+ *  Note: this is only safe if the mm semaphore is held when called.
+ */
+int remap_io_sg(struct vm_area_struct *vma,
+		unsigned long addr, resource_size_t io_start, struct scatterlist *sgl,
+		unsigned long size, struct io_mapping *iomap)
+{
+	struct remap_pfn r = { 0 };
+	int err;
+	GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS);
+
+	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
+	r.mm = vma->vm_mm;
+	r.size = size;
+	r.io_start = io_start;
+	r.sgl = sgl;
+	r.prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
+			  (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
+
+	err = apply_to_page_range(r.mm, addr, size, remap_io, &r);
+	if (unlikely(err)) {
+		zap_vma_ptes(vma, addr, (r.pfn - r.start_pfn) << PAGE_SHIFT);
+		return err;
+	}
+
+	return 0;
+}