diff mbox series

[v1,2/2] drm/i915/gem: Migrate to system at dma-buf attach time

Message ID 20210701202014.910098-2-michael.j.ruhl@intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/2] drm/i915/gem: Correct the locking and pin pattern for dma-buf | expand

Commit Message

Michael J. Ruhl July 1, 2021, 8:20 p.m. UTC
From: Thomas Hellström <thomas.hellstrom@linux.intel.com>

Until we support p2p dma or as a complement to that, migrate data
to system memory at dma-buf attach time if possible.

v2:
- Rebase on dynamic exporter. Update the igt_dmabuf_import_same_driver
  selftest to migrate if we are LMEM capable.
v3:
- Migrate also in the pin() callback.
v4:
- Migrate in attach

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c           | 12 +++++++++++-
 drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c |  4 +++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Comments

kernel test robot July 2, 2021, 6:31 a.m. UTC | #1
Hi "Michael,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.13 next-20210701]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Michael-J-Ruhl/drm-i915-gem-Correct-the-locking-and-pin-pattern-for-dma-buf/20210702-042115
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-r025-20210630 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 9eb613b2de3163686b1a4bd1160f15ac56a4b083)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/d1c1ca8d45e76fc2b9ee679c170848e6c6138f6e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Michael-J-Ruhl/drm-i915-gem-Correct-the-locking-and-pin-pattern-for-dma-buf/20210702-042115
        git checkout d1c1ca8d45e76fc2b9ee679c170848e6c6138f6e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

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

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:177:7: error: implicit declaration of function 'i915_gem_object_can_migrate' [-Werror,-Wimplicit-function-declaration]
           if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM))
                ^
   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:177:7: note: did you mean 'i915_gem_object_pin_map'?
   drivers/gpu/drm/i915/gem/i915_gem_object.h:452:20: note: 'i915_gem_object_pin_map' declared here
   void *__must_check i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
                      ^
>> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:179:8: error: implicit declaration of function 'i915_gem_object_migrate' [-Werror,-Wimplicit-function-declaration]
           ret = i915_gem_object_migrate(obj, NULL, INTEL_REGION_SMEM);
                 ^
   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:179:8: note: did you mean 'i915_gem_object_can_migrate'?
   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:177:7: note: 'i915_gem_object_can_migrate' declared here
           if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM))
                ^
>> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:181:9: error: implicit declaration of function 'i915_gem_object_wait_migration' [-Werror,-Wimplicit-function-declaration]
                   ret = i915_gem_object_wait_migration(obj, 0);
                         ^
   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:181:9: note: did you mean 'i915_gem_object_can_migrate'?
   drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:177:7: note: 'i915_gem_object_can_migrate' declared here
           if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM))
                ^
   3 errors generated.


vim +/i915_gem_object_can_migrate +177 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c

   162	
   163	/**
   164	 * i915_gem_dmabuf_attach - Do any extra attach work necessary
   165	 * @dmabuf: imported dma-buf
   166	 * @attach: new attach to do work on
   167	 *
   168	 */
   169	static int i915_gem_dmabuf_attach(struct dma_buf *dmabuf,
   170					  struct dma_buf_attachment *attach)
   171	{
   172		struct drm_i915_gem_object *obj = dma_buf_to_obj(dmabuf);
   173		int ret;
   174	
   175		assert_object_held(obj);
   176	
 > 177		if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM))
   178			return -EOPNOTSUPP;
 > 179		ret = i915_gem_object_migrate(obj, NULL, INTEL_REGION_SMEM);
   180		if (!ret)
 > 181			ret = i915_gem_object_wait_migration(obj, 0);
   182		if (!ret)
   183			ret = i915_gem_object_pin_pages(obj);
   184	
   185		return ret;
   186	}
   187	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
index ccae17d5f441..280291a4a9dc 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
@@ -170,9 +170,19 @@  static int i915_gem_dmabuf_attach(struct dma_buf *dmabuf,
 				  struct dma_buf_attachment *attach)
 {
 	struct drm_i915_gem_object *obj = dma_buf_to_obj(dmabuf);
+	int ret;
 
 	assert_object_held(obj);
-	return i915_gem_object_pin_pages(obj);
+
+	if (!i915_gem_object_can_migrate(obj, INTEL_REGION_SMEM))
+		return -EOPNOTSUPP;
+	ret = i915_gem_object_migrate(obj, NULL, INTEL_REGION_SMEM);
+	if (!ret)
+		ret = i915_gem_object_wait_migration(obj, 0);
+	if (!ret)
+		ret = i915_gem_object_pin_pages(obj);
+
+	return ret;
 }
 
 static void i915_gem_dmabuf_detach(struct dma_buf *dmabuf,
diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
index 868b3469ecbd..b1e87ec08741 100644
--- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c
@@ -106,7 +106,9 @@  static int igt_dmabuf_import_same_driver(void *arg)
 	int err;
 
 	force_different_devices = true;
-	obj = i915_gem_object_create_shmem(i915, PAGE_SIZE);
+	obj = i915_gem_object_create_lmem(i915, PAGE_SIZE, 0);
+	if (IS_ERR(obj))
+		obj = i915_gem_object_create_shmem(i915, PAGE_SIZE);
 	if (IS_ERR(obj))
 		goto out_ret;