Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: introduce simple gemfs

Not a fully blown gemfs, just our very own tmpfs kernel mount. Doing so
moves us away from the shmemfs shm_mnt, and gives us the much needed
flexibility to do things like set our own mount options, namely huge=
which should allow us to enable the use of transparent-huge-pages for
our shmem backed objects.

v2: various improvements suggested by Joonas

v3: move gemfs instance to i915.mm and simplify now that we have
file_setup_with_mnt

v4: fallback to tmpfs shm_mnt upon failure to setup gemfs

v5: make tmpfs fallback kinder

v5: better gemfs failure message
flags variable

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Hugh Dickins <hughd@google.com>
Cc: linux-mm@kvack.org
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171006145041.21673-3-matthew.auld@intel.com
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20171006221833.32439-2-chris@chris-wilson.co.uk

authored by

Matthew Auld and committed by
Chris Wilson
465c403c 703321b6

+128 -1
+1
drivers/gpu/drm/i915/Makefile
··· 47 47 i915_gem_tiling.o \ 48 48 i915_gem_timeline.o \ 49 49 i915_gem_userptr.o \ 50 + i915_gemfs.o \ 50 51 i915_trace_points.o \ 51 52 i915_vma.o \ 52 53 intel_breadcrumbs.o \
+5
drivers/gpu/drm/i915/i915_drv.h
··· 1511 1511 /** Usable portion of the GTT for GEM */ 1512 1512 dma_addr_t stolen_base; /* limited to low memory (32-bit) */ 1513 1513 1514 + /** 1515 + * tmpfs instance used for shmem backed objects 1516 + */ 1517 + struct vfsmount *gemfs; 1518 + 1514 1519 /** PPGTT used for aliasing the PPGTT with the GTT */ 1515 1520 struct i915_hw_ppgtt *aliasing_ppgtt; 1516 1521
+32 -1
drivers/gpu/drm/i915/i915_gem.c
··· 35 35 #include "intel_drv.h" 36 36 #include "intel_frontbuffer.h" 37 37 #include "intel_mocs.h" 38 + #include "i915_gemfs.h" 38 39 #include <linux/dma-fence-array.h> 39 40 #include <linux/kthread.h> 40 41 #include <linux/reservation.h> ··· 4257 4256 .pwrite = i915_gem_object_pwrite_gtt, 4258 4257 }; 4259 4258 4259 + static int i915_gem_object_create_shmem(struct drm_device *dev, 4260 + struct drm_gem_object *obj, 4261 + size_t size) 4262 + { 4263 + struct drm_i915_private *i915 = to_i915(dev); 4264 + unsigned long flags = VM_NORESERVE; 4265 + struct file *filp; 4266 + 4267 + drm_gem_private_object_init(dev, obj, size); 4268 + 4269 + if (i915->mm.gemfs) 4270 + filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size, 4271 + flags); 4272 + else 4273 + filp = shmem_file_setup("i915", size, flags); 4274 + 4275 + if (IS_ERR(filp)) 4276 + return PTR_ERR(filp); 4277 + 4278 + obj->filp = filp; 4279 + 4280 + return 0; 4281 + } 4282 + 4260 4283 struct drm_i915_gem_object * 4261 4284 i915_gem_object_create(struct drm_i915_private *dev_priv, u64 size) 4262 4285 { ··· 4305 4280 if (obj == NULL) 4306 4281 return ERR_PTR(-ENOMEM); 4307 4282 4308 - ret = drm_gem_object_init(&dev_priv->drm, &obj->base, size); 4283 + ret = i915_gem_object_create_shmem(&dev_priv->drm, &obj->base, size); 4309 4284 if (ret) 4310 4285 goto fail; 4311 4286 ··· 4944 4919 4945 4920 spin_lock_init(&dev_priv->fb_tracking.lock); 4946 4921 4922 + err = i915_gemfs_init(dev_priv); 4923 + if (err) 4924 + DRM_NOTE("Unable to create a private tmpfs mount, hugepage support will be disabled(%d).\n", err); 4925 + 4947 4926 return 0; 4948 4927 4949 4928 err_priorities: ··· 4986 4957 4987 4958 /* And ensure that our DESTROY_BY_RCU slabs are truly destroyed */ 4988 4959 rcu_barrier(); 4960 + 4961 + i915_gemfs_fini(dev_priv); 4989 4962 } 4990 4963 4991 4964 int i915_gem_freeze(struct drm_i915_private *dev_priv)
+52
drivers/gpu/drm/i915/i915_gemfs.c
··· 1 + /* 2 + * Copyright © 2017 Intel Corporation 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice (including the next 12 + * paragraph) shall be included in all copies or substantial portions of the 13 + * Software. 14 + * 15 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 + * IN THE SOFTWARE. 22 + * 23 + */ 24 + 25 + #include <linux/fs.h> 26 + #include <linux/mount.h> 27 + 28 + #include "i915_drv.h" 29 + #include "i915_gemfs.h" 30 + 31 + int i915_gemfs_init(struct drm_i915_private *i915) 32 + { 33 + struct file_system_type *type; 34 + struct vfsmount *gemfs; 35 + 36 + type = get_fs_type("tmpfs"); 37 + if (!type) 38 + return -ENODEV; 39 + 40 + gemfs = kern_mount(type); 41 + if (IS_ERR(gemfs)) 42 + return PTR_ERR(gemfs); 43 + 44 + i915->mm.gemfs = gemfs; 45 + 46 + return 0; 47 + } 48 + 49 + void i915_gemfs_fini(struct drm_i915_private *i915) 50 + { 51 + kern_unmount(i915->mm.gemfs); 52 + }
+34
drivers/gpu/drm/i915/i915_gemfs.h
··· 1 + /* 2 + * Copyright © 2017 Intel Corporation 3 + * 4 + * Permission is hereby granted, free of charge, to any person obtaining a 5 + * copy of this software and associated documentation files (the "Software"), 6 + * to deal in the Software without restriction, including without limitation 7 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 + * and/or sell copies of the Software, and to permit persons to whom the 9 + * Software is furnished to do so, subject to the following conditions: 10 + * 11 + * The above copyright notice and this permission notice (including the next 12 + * paragraph) shall be included in all copies or substantial portions of the 13 + * Software. 14 + * 15 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 + * IN THE SOFTWARE. 22 + * 23 + */ 24 + 25 + #ifndef __I915_GEMFS_H__ 26 + #define __I915_GEMFS_H__ 27 + 28 + struct drm_i915_private; 29 + 30 + int i915_gemfs_init(struct drm_i915_private *i915); 31 + 32 + void i915_gemfs_fini(struct drm_i915_private *i915); 33 + 34 + #endif
+4
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 83 83 kmem_cache_destroy(i915->vmas); 84 84 kmem_cache_destroy(i915->objects); 85 85 86 + i915_gemfs_fini(i915); 87 + 86 88 drm_dev_fini(&i915->drm); 87 89 put_device(&i915->drm.pdev->dev); 88 90 } ··· 244 242 i915->preempt_context = mock_context(i915, NULL); 245 243 if (!i915->preempt_context) 246 244 goto err_kernel_context; 245 + 246 + WARN_ON(i915_gemfs_init(i915)); 247 247 248 248 return i915; 249 249