Replace shmem memory region and object backend
Subsystems (2)
v2 cover Replace shmem memory region and object backend
This patch is a second attempt at eliminating the old shmem memory region and GEM object backend, in favour of a TTM-based one that is able to manage objects placed on both system and local memory.
Questions addressed since previous revision:
* Creating an anonymous vfs mount for shmem files in TTM
* Fixing LLC caching properties and bit 17 swizzling before setting a TTM bo's pages when calling get_pages
* Added handling of phys backend from TTM functions
* Added pread callback to TTM gem object backend
* In shmem_create_from_object, ensuring an shmem object we just got a filp for has its pages marked dirty and accessed. Otherwise, the engine won't be able to read the initial state and a GPU hung will ensue
However, one of the issues persists:
Many GPU hungs in machines of GEN <= 5. My assumption is this has something
to do with a caching pitfall, but everywhere across the TTM backend code I've tried to handle object creation and getting its pages with the same set of caching and coherency properties as in the old shmem backend.
Adrian Larumbe (1):
drm/i915: Replace shmem memory region and object backend with TTM
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)
Signature · 1 line
2.35.1
RFC PATCH v2 1/1 drm/i915: Replace shmem memory region and object backend with TTM
Remove shmem region and object backend code as they are now unnecessary. In the case of objects placed in SMEM and backed by kernel shmem files, the file pointer has to be retrieved from the ttm_tt structure, so change this as well. This means accessing an shmem-backed BO's file pointer requires getting its pages beforehand, unlike in the old shmem backend.
Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM way', also making sure its pages are put when a TTM shmem object has no struct page.
--- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +9 -3
@@ -12,6 +12,7 @@#include <asm/smp.h> #include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h"
@@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev); +struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma); -if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }
@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +24 -8
@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,struct drm_i915_private *i915 =to_i915 (dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;/* * mmap ioctl is disallowed for all discrete platforms,
@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; -/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp; +else { + ret =i915_gem_object_pin_pages_unlocked (obj); +if (ret) { + addr = ret; + goto err_pin; + } + + filp =i915_gem_ttm_get_filep (obj); +if (!filp) { + addr = -ENXIO ; + goto err; + } }if (range_overflows (args->offset, args->size, (u64 )obj->base.size)) {
@@ -96,7 +106,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, goto err; } - addr =vm_mmap (obj->base.filp,0 , args->size, + addr =vm_mmap (filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset);if (IS_ERR_VALUE (addr))
@@ -111,7 +121,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, goto err; } vma =find_vma (mm, addr); -if (vma &&__vma_matches (vma, obj->base.filp, addr, args->size)) +if (vma &&__vma_matches (vma, filp, addr, args->size)) vma->vm_page_prot =pgprot_writecombine (vm_get_page_prot (vma->vm_flags));else
@@ -120,12 +130,18 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,if (IS_ERR_VALUE (addr)) goto err; } +if (!obj->base.import_attach) +i915_gem_object_unpin_pages (obj); +i915_gem_object_put (obj); args->addr_ptr = (u64 )addr;return 0 ; err: +if (!obj->base.import_attach) +i915_gem_object_unpin_pages (obj); +err_pin:i915_gem_object_put (obj);return addr; }
drivers/gpu/drm/i915/gem/i915_gem_object.h +1 -3
@@ -72,8 +72,6 @@ __i915_gem_object_create_user(struct drm_i915_private *i915, u64 size,struct intel_memory_region **placements, unsigned int n_placements); -extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; -void __i915_gem_object_release_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages,bool needs_clflush);
@@ -592,7 +590,7 @@ i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj,int i915_gem_object_read_from_page (struct drm_i915_gem_object *obj,u64 offset,void *dst,int size); -bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +bool i915_gem_object_is_shmem (struct drm_i915_gem_object *obj);void __i915_gem_free_object_rcu (struct rcu_head *head);
drivers/gpu/drm/i915/gem/i915_gem_phys.c +27 -5
@@ -9,6 +9,7 @@#include <linux/swap.h> #include <drm/drm_cache.h> +#include <drm/ttm/ttm_tt.h> #include "gt/intel_gt.h" #include "i915_drv.h"
@@ -16,10 +17,11 @@#include "i915_gem_region.h" #include "i915_gem_tiling.h" #include "i915_scatterlist.h" +#include "gem/i915_gem_ttm.h" static int i915_gem_object_get_pages_phys (struct drm_i915_gem_object *obj) { -struct address_space *mapping = obj->base.filp->f_mapping; +struct address_space *mapping =i915_gem_ttm_get_filep (obj)->f_mapping;struct drm_i915_private *i915 =to_i915 (obj->base.dev);struct scatterlist *sg;struct sg_table *st;
@@ -28,6 +30,8 @@ static int i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj)void *dst;int i; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (GEM_WARN_ON (i915_gem_object_needs_bit17_swizzle (obj)))return -EINVAL ;
@@ -102,10 +106,17 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,__i915_gem_object_release_shmem (obj, pages, false);if (obj->mm.dirty) { -struct address_space *mapping = obj->base.filp->f_mapping; +struct address_space *mapping; +struct file *filp;void *src = vaddr;int i; + filp =i915_gem_ttm_get_filep (obj); +if (GEM_WARN_ON (filp ==NULL )) + goto free_pages; + + mapping = filp->f_mapping; +for (i =0 ; i < obj->base.size /PAGE_SIZE ; i++) {struct page *page;char *dst;
@@ -129,6 +140,7 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj, obj->mm.dirty = false; } +free_pages:sg_free_table (pages);kfree (pages);
@@ -202,13 +214,23 @@ static int i915_gem_object_shmem_to_phys(struct drm_i915_gem_object *obj)/* Perma-pin (until release) the physical set of pages */ __i915_gem_object_pin_pages (obj); -if (!IS_ERR_OR_NULL (pages)) -i915_gem_object_put_pages_shmem (obj, pages); +if (!IS_ERR_OR_NULL (pages)) { +struct ttm_buffer_object *bo =i915_gem_to_ttm (obj); + +if (GEM_WARN_ON (!bo->bdev->funcs->ttm_tt_unpopulate)) +return -EINVAL ; + +if (bo->bdev->funcs->ttm_tt_unpopulate) + bo->bdev->funcs->ttm_tt_unpopulate (bo->bdev, bo->ttm); + +if (obj->mm.rsgt) +i915_refct_sgt_put (fetch_and_zero (&obj->mm.rsgt)); + }i915_gem_object_release_memory_region (obj);return 0 ; -err_xfer: + err_xfer:if (!IS_ERR_OR_NULL (pages)) {unsigned int sg_page_sizes =i915_sg_dma_sizes (pages->sgl);
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +20 -370
435 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +252 -15
385 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_ttm.h +3 -0
@@ -92,4 +92,7 @@ static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)/* Once / if we support GGTT, this is also false for cached ttm_tts */ return mem->mem_type != I915_PL_SYSTEM; } + +struct file *i915_gem_ttm_get_filep (struct drm_i915_gem_object *obj); +#endif
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +7 -2
@@ -46,7 +46,7 @@ static enum i915_cache_level i915_ttm_cache_level(struct drm_i915_private *i915, struct ttm_resource *res, struct ttm_tt *ttm) { - return ((HAS_LLC(i915) || HAS_SNOOP(i915)) && + return ((HAS_LLC(i915)) && !i915_ttm_gtt_binds_lmem(res) && ttm->caching == ttm_cached) ? I915_CACHE_LLC :I915_CACHE_NONE ;
@@ -77,7 +77,12 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj) {struct ttm_buffer_object *bo =i915_gem_to_ttm (obj); -if (i915_ttm_cpu_maps_iomem (bo->resource) || bo->ttm->caching != ttm_cached) { +if (!i915_ttm_cpu_maps_iomem (bo->resource) && + bo->ttm->caching == ttm_uncached) { + obj->write_domain =I915_GEM_DOMAIN_CPU ; + obj->read_domains =I915_GEM_DOMAIN_CPU ; + }else if (i915_ttm_cpu_maps_iomem (bo->resource) || + bo->ttm->caching != ttm_cached) { obj->write_domain =I915_GEM_DOMAIN_WC ; obj->read_domains =I915_GEM_DOMAIN_WC ; }else {
drivers/gpu/drm/i915/gt/shmem_utils.c +54 -10
84 lines not on this page · raw message
drivers/gpu/drm/i915/intel_memory_region.c +1 -6
@@ -309,12 +309,7 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915) instance = intel_region_map[i].instance;switch (type) {case INTEL_MEMORY_SYSTEM : -if (IS_DGFX (i915)) - mem =i915_gem_ttm_system_setup (i915, type, - instance); -else - mem =i915_gem_shmem_setup (i915, type, - instance); + mem =i915_gem_ttm_system_setup (i915, type, instance);break ;case INTEL_MEMORY_STOLEN_LOCAL : mem =i915_gem_stolen_lmem_setup (i915, type, instance);
Signature · 1 line
2.35.1
Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTM
Quoted 55 lines
-----Original Message-----
From: Intel-gfx <[email protected]> On Behalf Of Adrian Larumbe
Sent: Tuesday, May 17, 2022 4:45 PM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMRemove shmem region and object backend code as they are now unnecessary.
In the case of objects placed in SMEM and backed by kernel shmem files, the file pointer has to be retrieved from thettm_ttstructure, so change this as well. This means accessing an shmem-backed BO's file pointer requires getting its pages beforehand, unlike in the old shmem backend.Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM way', also making sure its pages are put when a TTM shmem object has no struct page.
Signed-off-by Adrian Larumbe <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +1
-0@@ -12,6 +12,7 @@#include <asm/smp.h> #include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev);
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct dma_buf · line 108
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +3
-0+struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma);
Since all of the devices that will have device memory will be true for HAS_LMEM, won't your code path always go to drm_gem_prime_mmap()?
Quoted 43 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +5
-3-if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-0@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, struct drm_i915_private *i915 = to_i915(dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;/* * mmap ioctl is disallowed for all discrete platforms,
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, if (!obj)
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev, void · line 90
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-6return -ENOENT ; -/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp;
Why is this now ok? This is the imported object. And it used to give an error.
If you are importing from a different device, (i.e. an amd device is exporting the object, and you are i915 here), can you even do this?
My understanding was that mmaping was only for the exported object.
Has this changed?
Thanks,
Mike
Quoted 1,249 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +12
-0+else { + ret =i915_gem_object_pin_pages_unlocked (obj); +if (ret) { + addr = ret; + goto err_pin; + } + + filp =i915_gem_ttm_get_filep (obj); +if (!filp) { + addr = -ENXIO ; + goto err; + } }if (range_overflows(args->offset, args->size, (u64)obj->base.size)) {drivers/gpu/drm/i915/gem/i915_gem_mman.c +1
-1@@ -96,7 +106,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, goto err; } - addr =vm_mmap (obj->base.filp,0 , args->size, + addr =vm_mmap (filp,0 , args->size,PROT_READ |PROT_WRITE ,MAP_SHARED , args->offset);if (IS_ERR_VALUE(addr))drivers/gpu/drm/i915/gem/i915_gem_mman.c +1
-1@@ -111,7 +121,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, goto err; } vma =find_vma (mm, addr); -if (vma &&__vma_matches (vma, obj->base.filp, addr, args- >size)) +if (vma &&__vma_matches (vma, filp, addr, args->size)) vma->vm_page_prot =pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); elsedrivers/gpu/drm/i915/gem/i915_gem_mman.c +3
-0@@ -120,12 +130,18 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, if (IS_ERR_VALUE(addr)) goto err; } +if (!obj->base.import_attach) +i915_gem_object_unpin_pages (obj); +i915_gem_object_put (obj); args->addr_ptr = (u64 )addr;return 0 ;err:
drivers/gpu/drm/i915/gem/i915_gem_mman.c +3
-0+if (!obj->base.import_attach) +i915_gem_object_unpin_pages (obj); +err_pin:i915_gem_object_put(obj); return addr; }drivers/gpu/drm/i915/gem/i915_gem_object.h +0
-2@@ -72,8 +72,6 @@ __i915_gem_object_create_user(struct drm_i915_private *i915, u64 size, struct intel_memory_region **placements, unsigned int n_placements); -extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; -void __i915_gem_object_release_shmem(struct
drm_i915_gem_object*obj,struct sg_table *pages, bool needs_clflush);drivers/gpu/drm/i915/gem/i915_gem_object.h +1
-1@@ -592,7 +590,7 @@ i915_gem_object_invalidate_frontbuffer(structdrm_i915_gem_object *obj, int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj,u64 offset,void *dst,int size); -bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +bool i915_gem_object_is_shmem (struct drm_i915_gem_object *obj);void
__i915_gem_free_object_rcu(struct rcu_head *head);drivers/gpu/drm/i915/gem/i915_gem_phys.c +2
-0@@ -9,6 +9,7 @@#include <linux/swap.h> #include <drm/drm_cache.h> +#include <drm/ttm/ttm_tt.h> #include "gt/intel_gt.h" #include "i915_drv.h" @@ -16,10 +17,11 @@#include "i915_gem_region.h" #include "i915_gem_tiling.h" #include "i915_scatterlist.h" +#include "gem/i915_gem_ttm.h" static int
i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj)
{drivers/gpu/drm/i915/gem/i915_gem_phys.c +1
-1-struct address_space *mapping = obj->base.filp->f_mapping; + struct address_space *mapping = i915_gem_ttm_get_filep(obj)-Quoted 1 line
f_mapping;struct drm_i915_private *i915 = to_i915(obj->base.dev); struct scatterlist *sg; struct sg_table *st;drivers/gpu/drm/i915/gem/i915_gem_phys.c +10
-1@@ -28,6 +30,8 @@ static int i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj)void *dst;int i; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (GEM_WARN_ON (i915_gem_object_needs_bit17_swizzle (obj)))return -EINVAL ;@@ -102,10 +106,17 @@ i915_gem_object_put_pages_phys(structdrm_i915_gem_object *obj,__i915_gem_object_release_shmem (obj ,pages ,false );if (obj->mm.dirty) { -struct address_space *mapping = obj->base.filp->f_mapping; +struct address_space *mapping; +struct file *filp;void *src = vaddr;int i; + filp =i915_gem_ttm_get_filep (obj); +if (GEM_WARN_ON (filp ==NULL )) + goto free_pages; + + mapping = filp->f_mapping; +for (i =0 ; i < obj->base.size /PAGE_SIZE ; i++) {struct page *page;char *dst;drivers/gpu/drm/i915/gem/i915_gem_phys.c +14
-3@@ -129,6 +140,7 @@ i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj, obj->mm.dirty = false; } +free_pages:sg_free_table (pages);kfree (pages);@@ -202,13 +214,23 @@ static int i915_gem_object_shmem_to_phys(struct drm_i915_gem_object *obj)/* Perma-pin (until release) the physical set of pages */ __i915_gem_object_pin_pages (obj ); -if (!IS_ERR_OR_NULL (pages)) -i915_gem_object_put_pages_shmem (obj, pages); +if (!IS_ERR_OR_NULL (pages)) { +struct ttm_buffer_object *bo =i915_gem_to_ttm (obj); + +if (GEM_WARN_ON (!bo->bdev->funcs->ttm_tt_unpopulate)) +return -EINVAL ; + +if (bo->bdev->funcs->ttm_tt_unpopulate) + bo->bdev->funcs->ttm_tt_unpopulate (bo->bdev, bo- >ttm); + +if (obj->mm.rsgt) +i915_refct_sgt_put (fetch_and_zero (&obj->mm.rsgt)); + }i915_gem_object_release_memory_region (obj);return 0 ; -err_xfer: + err_xfer:if (!IS_ERR_OR_NULL (pages)) {unsigned int sg_page_sizes = i915_sg_dma_sizes(pages->sgl);drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2
-67@@ -11,12 +11,14 @@#include <drm/drm_cache.h> #include "gem/i915_gem_region.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_gem_tiling.h" #include "i915_gemfs.h" #include "i915_scatterlist.h" #include "i915_trace.h" +#include "i915_gem_clflush.h" /* * Move pages to appropriate lru and release the pagevec, decrementing the @@ -188,105 +190,6 @@ int shmem_sg_alloc_table(struct drm_i915_private *i915, struct sg_table *st, return ret; } -static int shmem_get_pages (struct drm_i915_gem_object *obj) -{ -struct drm_i915_private *i915 =to_i915 (obj->base.dev); -struct intel_memory_region *mem = obj->mm.region; -struct address_space *mapping = obj->base.filp->f_mapping; -const unsigned long page_count = obj->base.size /PAGE_SIZE ; -unsigned int max_segment =i915_sg_segment_size (); -struct sg_table *st; -struct sgt_iter sgt_iter; -struct page *page; -int ret; - -/* -* Assert that the object is not currently in any GPU domain. As it -* wasn't in the GTT, there shouldn't be any way it could have been in -* a GPU cache -*/ -GEM_BUG_ON (obj->read_domains &I915_GEM_GPU_DOMAINS ); -GEM_BUG_ON (obj->write_domain &I915_GEM_GPU_DOMAINS ); - -rebuild_st: - st =kmalloc (sizeof (*st),GFP_KERNEL ); -if (!st) -return -ENOMEM ; - - ret =shmem_sg_alloc_table (i915, st, obj->base.size, mem, mapping, - max_segment); -if (ret) - goto err_st; - - ret =i915_gem_gtt_prepare_pages (obj, st); -if (ret) { -/* -* DMA remapping failed? One possible cause is that -* it could not reserve enough large entries, asking -* for PAGE_SIZE chunks instead may be helpful. -*/ -if (max_segment >PAGE_SIZE ) { -for_each_sgt_page (page, sgt_iter, st) -put_page (page); -sg_free_table (st); -kfree (st); - - max_segment =PAGE_SIZE ; - goto rebuild_st; - }else { -dev_warn (i915->drm.dev, -"Failed to DMA remap %lu pages\n" , - page_count); - goto err_pages; - } - } - -if (i915_gem_object_needs_bit17_swizzle (obj)) -i915_gem_object_do_bit_17_swizzle (obj, st); - -if (i915_gem_object_can_bypass_llc (obj)) - obj->cache_dirty = true; - -__i915_gem_object_set_pages (obj, st,i915_sg_dma_sizes (st->sgl)); - -return 0 ; - -err_pages: -shmem_sg_free_table (st, mapping, false, false); -/* -* shmemfs first checks if there is enough memory to allocate the page
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-1-* and reports ENOSPC should there be insufficient, along with the usual
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-3-* ENOMEM for a genuine allocation failure. -* -* We use ENOSPC in our driver to mean that we have run out of aperture
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-28-* space and so want to translate the error from shmemfs back to our -* usual understanding of ENOMEM. -*/ -err_st: -if (ret == -ENOSPC ) - ret = -ENOMEM ; - -kfree (st); - -return ret; -} - -static int -shmem_truncate (struct drm_i915_gem_object *obj) -{ -/* -* Our goal here is to return as much of the memory as -* is possible back to the system as we are called from OOM. -* To do this we must instruct the shmfs to drop all of its -* backing pages, *now*. -*/ -shmem_truncate_range (file_inode (obj->base.filp),0 , (loff_t)-1 ); - obj->mm.madv = __I915_MADV_PURGED; - obj->mm.pages =ERR_PTR (-EFAULT ); - -return 0 ; -} -void
__shmem_writeback(size_t size, struct address_space *mapping){ struct writeback_control wbc = {drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-21@@ -329,27 +232,6 @@ void __shmem_writeback(size_t size, struct address_space *mapping) } } -static void -shmem_writeback (struct drm_i915_gem_object *obj) -{ -__shmem_writeback (obj->base.size, obj->base.filp->f_mapping); -} - -static int shmem_shrink (struct drm_i915_gem_object *obj,unsigned int flags) -{ -switch (obj->mm.madv) { -case I915_MADV_DONTNEED : -return i915_gem_object_truncate (obj); -case __I915_MADV_PURGED: -return 0 ; - } - -if (flags &I915_GEM_OBJECT_SHRINK_WRITEBACK ) -shmem_writeback (obj); - -return 0 ; -} -void
__i915_gem_object_release_shmem(structdrm_i915_gem_object*obj,
structsg_table*pages,drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-0@@ -395,220 +277,6 @@ void i915_gem_object_put_pages_shmem(struct
drm_i915_gem_object*obj, structsg_obj->mm.dirty = false; }drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-2-static void -shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table*pages)
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-144-{ -if (likely (i915_gem_object_has_struct_page (obj))) -i915_gem_object_put_pages_shmem (obj, pages); -else -i915_gem_object_put_pages_phys (obj, pages); -} - -static int -shmem_pwrite (struct drm_i915_gem_object *obj, -const struct drm_i915_gem_pwrite *arg) -{ -struct address_space *mapping = obj->base.filp->f_mapping; -char __user *user_data =u64_to_user_ptr (arg->data_ptr); -u64 remain, offset; -unsigned int pg; - -/* Caller already validated user args */ -GEM_BUG_ON (!access_ok (user_data, arg->size)); - -if (!i915_gem_object_has_struct_page (obj)) -return i915_gem_object_pwrite_phys (obj, arg); - -/* -* Before we instantiate/pin the backing store for our use, we -* can prepopulate the shmemfs filp efficiently using a write into -* the pagecache. We avoid the penalty of instantiating all the -* pages, important if the user is just writing to a few and never -* uses the object on the GPU, and using a direct write into shmemfs -* allows it to avoid the cost of retrieving a page (either swapin -* or clearing-before-use) before it is overwritten. -*/ -if (i915_gem_object_has_pages (obj)) -return -ENODEV ; - -if (obj->mm.madv !=I915_MADV_WILLNEED ) -return -EFAULT ; - -/* -* Before the pages are instantiated the object is treated as being -* in the CPU domain. The pages will be clflushed as required before -* use, and we can freely write into the pages directly. If userspace -* races pwrite with any other operation; corruption will ensue - -* that is userspace's prerogative! -*/ - - remain = arg->size; - offset = arg->offset; - pg =offset_in_page (offset); - -do { -unsigned int len, unwritten; -struct page *page; -void *data, *vaddr; -int err; -char c; - - len =PAGE_SIZE - pg; -if (len > remain) - len = remain; - -/* Prefault the user page to reduce potential recursion */ - err =__get_user (c, user_data); -if (err) -return err; - - err =__get_user (c, user_data + len -1 ); -if (err) -return err; - - err =pagecache_write_begin (obj->base.filp, mapping, - offset, len,0 , - &page, &data); -if (err <0 ) -return err; - - vaddr =kmap_atomic (page); - unwritten =__copy_from_user_inatomic (vaddr + pg, - user_data, - len); -kunmap_atomic (vaddr); - - err =pagecache_write_end (obj->base.filp, mapping, - offset, len, len - unwritten, - page, data); -if (err <0 ) -return err; - -/* We don't handle -EFAULT, leave it to the caller to check */ -if (unwritten) -return -ENODEV ; - - remain -= len; - user_data += len; - offset += len; - pg =0 ; - }while (remain); - -return 0 ; -} - -static int -shmem_pread (struct drm_i915_gem_object *obj, -const struct drm_i915_gem_pread *arg) -{ -if (!i915_gem_object_has_struct_page (obj)) -return i915_gem_object_pread_phys (obj, arg); - -return -ENODEV ; -} - -static void shmem_release (struct drm_i915_gem_object *obj) -{ -if (i915_gem_object_has_struct_page (obj)) -i915_gem_object_release_memory_region (obj); - -fput (obj->base.filp); -} - -const struct drm_i915_gem_object_ops i915_gem_shmem_ops = { - .name ="i915_gem_object_shmem" , - .flags =I915_GEM_OBJECT_IS_SHRINKABLE , - - .get_pages = shmem_get_pages, - .put_pages = shmem_put_pages, - .truncate = shmem_truncate, - .shrink = shmem_shrink, - - .pwrite = shmem_pwrite, - .pread = shmem_pread, - - .release = shmem_release, -}; - -static int __create_shmem (struct drm_i915_private *i915, -struct drm_gem_object *obj, -resource_size_t size) -{ -unsigned long flags =VM_NORESERVE ; -struct file *filp; - -drm_gem_private_object_init (&i915->drm, obj, size); - -if (i915->mm.gemfs) - filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915",size,
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-46- flags); - else - filp =shmem_file_setup ("i915" , size, flags); -if (IS_ERR (filp)) -return PTR_ERR (filp); - - obj->filp = filp; -return 0 ; -} - -static int shmem_object_init (struct intel_memory_region *mem, -struct drm_i915_gem_object *obj, -resource_size_t offset, -resource_size_t size, -resource_size_t page_size, -unsigned int flags) -{ -static struct lock_class_key lock_class; -struct drm_i915_private *i915 = mem->i915; -struct address_space *mapping; -unsigned int cache_level; -gfp_t mask; -int ret; - - ret =__create_shmem (i915, &obj->base, size); -if (ret) -return ret; - - mask =GFP_HIGHUSER | __GFP_RECLAIMABLE; -if (IS_I965GM (i915) ||IS_I965G (i915)) { -/* 965gm cannot relocate objects above 4GiB. */ - mask &= ~__GFP_HIGHMEM; - mask |= __GFP_DMA32; - } - - mapping = obj->base.filp->f_mapping; -mapping_set_gfp_mask (mapping, mask); -GEM_BUG_ON (!(mapping_gfp_mask (mapping) & __GFP_RECLAIM)); - -i915_gem_object_init (obj, &i915_gem_shmem_ops, &lock_class,0 ); - obj->mem_flags |=I915_BO_FLAG_STRUCT_PAGE ; - obj->write_domain =I915_GEM_DOMAIN_CPU ; - obj->read_domains =I915_GEM_DOMAIN_CPU ; - -if (HAS_LLC (i915)) -/* On some devices, we can have the GPU use the LLC (the CPU
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-22-* cache) for about a 10% performance improvement -* compared to uncached. Graphics requests other than -* display scanout are coherent with the CPU in -* accessing this cache. This means in this mode we -* don't need to clflush on the CPU side, and on the -* GPU side we only need to flush internal caches to -* get data visible to the CPU. -* -* However, we maintain the display planes as UC, and so -* need to rebind when first used as such. -*/ - cache_level =I915_CACHE_LLC ; - else - cache_level =I915_CACHE_NONE ; - -i915_gem_object_set_cache_coherency (obj, cache_level); - -i915_gem_object_init_memory_region (obj, mem); - -return 0 ; -} -struct
drm_i915_gem_object* i915_gem_object_create_shmem(structdrm_i915_private*i915,
resource_size_tsize)drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2
-1@@ -634,7 +302,19 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *dev_priv,GEM_BUG_ON (obj->write_domain !=I915_GEM_DOMAIN_CPU ); - file = obj->base.filp; +/* +* When using TTM as the main GEM backend, we need to pin the pages
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +5
-0+* after creating the object to access the file pointer +*/ + err =i915_gem_object_pin_pages_unlocked (obj); +if (err) { + drm_dbg(&dev_priv->drm, "%s pin-pages err=%d\n",
__func__, err);drivers/gpu/drm/i915/gem/i915_gem_shmem.c +6
-0+ goto fail_pin; + } + + file =i915_gem_ttm_get_filep (obj); +GEM_WARN_ON (file ==NULL ); +offset = 0; do { unsigned int len = min_t(typeof(size), size, PAGE_SIZE);drivers/gpu/drm/i915/gem/i915_gem_shmem.c +3
-0@@ -662,44 +342,14 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *dev_priv, offset += len; }while (size); +i915_gem_clflush_object (obj,I915_CLFLUSH_SYNC ); +i915_gem_object_unpin_pages (obj); +return obj;fail:
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +2
-0+i915_gem_object_unpin_pages (obj); +fail_pin:i915_gem_object_put(obj); return ERR_PTR(err); }drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-22- -static int init_shmem (struct intel_memory_region *mem) -{ -i915_gemfs_init (mem->i915); -intel_memory_region_set_name (mem,"system" ); - -return 0 ;/* We have fallback to the kernel mnt if gemfs init failed. */ -} - -static int release_shmem (struct intel_memory_region *mem) -{ -i915_gemfs_fini (mem->i915); -return 0 ; -} - -static const struct intel_memory_region_ops shmem_region_ops = { - .init = init_shmem, - .release = release_shmem, - .init_object = shmem_object_init, -}; - -struct intel_memory_region *i915_gem_shmem_setup(struct
drm_i915_private*i915,drivers/gpu/drm/i915/gem/i915_gem_shmem.c +0
-13- u16 type, u16 instance) -{ -return intel_memory_region_create (i915,0 , -totalram_pages () <<PAGE_SHIFT , -PAGE_SIZE ,0 ,0 , - type, instance, - &shmem_region_ops); -} - -bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj) -{ -return obj->ops == &i915_gem_shmem_ops; -}drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4
-0@@ -21,6 +21,8 @@#include "gem/i915_gem_ttm_move.h" #include "gem/i915_gem_ttm_pm.h" #include "gt/intel_gpu_commands.h" +#include "gem/i915_gem_tiling.h" +#include "gem/i915_gemfs.h" #define I915_TTM_PRIO_PURGE 0#define I915_TTM_PRIO_NO_PAGES 1@@ -37,6 +39,7 @@* @ttm: The base TTM page vector. * @dev: The struct device used for dma mapping and unmapping. * @cached_rsgt: The cached scatter-gather table. +* @bo: TTM buffer object this ttm_tt structure is bound to. * @is_shmem: Set if using shmem. * @filp: The shmem file, if using shmem backend. * @@ -50,6 +53,7 @@ struct i915_ttm_tt {struct ttm_tt ttm;struct device *dev;struct i915_refct_sgt cached_rsgt; +struct ttm_buffer_object *bo;bool is_shmem;struct file *filp;@@ -113,6 +117,10 @@ static int i915_ttm_err_to_gem(int err)static enum
ttm_cachingi915_ttm_select_tt_caching(const struct drm_i915_gem_object *obj){drivers/gpu/drm/i915/gem/i915_gem_ttm.c +4
-0+struct drm_i915_private *i915 =to_i915 (obj->base.dev); + +if (GRAPHICS_VER (i915) <=5 ) +return ttm_uncached;/*
* Objects only allowed in system get cached cpu-mappings, or when
* evicting lmem-only buffers to system for swapping. Other objects
getdrivers/gpu/drm/i915/gem/i915_gem_ttm.c +12
-1@@ -202,11 +210,22 @@ static int i915_ttm_tt_shmem_populate(structttm_device *bdev, struct address_space *mapping;gfp_t mask; - filp =shmem_file_setup ("i915-shmem-tt" , size, VM_NORESERVE); +if (i915->mm.gemfs) + filp =shmem_file_setup_with_mnt (i915->mm.gemfs, +"i915-shmem-tt" , + size, +VM_NORESERVE ); +else + filp =shmem_file_setup ("i915-shmem-tt" , size,VM_NORESERVE );if (IS_ERR (filp))return PTR_ERR (filp); mask =GFP_HIGHUSER | __GFP_RECLAIMABLE; +if (IS_I965GM (i915) ||IS_I965G (i915)) { +/* 965gm cannot relocate objects above 4GiB. */ + mask &= ~__GFP_HIGHMEM; + mask |= __GFP_DMA32; + }mapping = filp->f_mapping; mapping_set_gfp_mask(mapping, mask);drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3
-1@@ -304,12 +323,14 @@ static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo, if (!i915_tt)return NULL ; + i915_tt->bo = bo; +if (obj->flags &I915_BO_ALLOC_CPU_CLEAR && man->use_tt) page_flags |=TTM_TT_FLAG_ZERO_ALLOC ; caching =i915_ttm_select_tt_caching (obj); -if (i915_gem_object_is_shrinkable (obj) && caching == ttm_cached) { +if (i915_gem_object_is_shrinkable (obj) && (caching != ttm_write_combined)) { page_flags |= TTM_TT_FLAG_EXTERNAL |TTM_TT_FLAG_EXTERNAL_MAPPABLE; i915_tt->is_shmem = true;drivers/gpu/drm/i915/gem/i915_gem_ttm.c +8
-0@@ -352,11 +373,19 @@ static void i915_ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) { struct i915_ttm_tt *i915_tt = container_of(ttm, typeof(*i915_tt), ttm);struct sg_table *st = &i915_tt->cached_rsgt.table; +struct ttm_buffer_object *bo = i915_tt->bo; +struct drm_i915_gem_object *obj =i915_ttm_to_gem (bo); + +if (i915_tt->is_shmem) +__i915_gem_object_release_shmem (obj, st, true);if (st->sgl)dma_unmap_sgtable (i915_tt->dev, st,DMA_BIDIRECTIONAL ,0 );if (i915_tt->is_shmem) { +if (i915_gem_object_needs_bit17_swizzle (obj)) +i915_gem_object_save_bit_17_swizzle (obj, st); +i915_ttm_tt_shmem_unpopulate(ttm); } else { sg_free_table(st);drivers/gpu/drm/i915/gem/i915_gem_ttm.c +6
-0@@ -794,6 +823,12 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj, if (IS_ERR(rsgt)) return PTR_ERR(rsgt); +if (i915_gem_object_needs_bit17_swizzle (obj)) +i915_gem_object_save_bit_17_swizzle (obj, &rsgt- >table); + +if (i915_gem_object_can_bypass_llc (obj)) + obj->cache_dirty = true; +GEM_BUG_ON (obj->mm.rsgt);obj->mm.rsgt = rsgt; __i915_gem_object_set_pages(obj, &rsgt->table,drivers/gpu/drm/i915/gem/i915_gem_ttm.c +12
-9@@ -873,16 +908,19 @@ static int i915_ttm_migrate(struct drm_i915_gem_object *obj, static void i915_ttm_put_pages(struct drm_i915_gem_object *obj, struct sg_table *st) { -/* -* We're currently not called from a shrinker, so put_pages() -* typically means the object is about to destroyed, or called -* from move_notify(). So just avoid doing much for now. -* If the object is not destroyed next, The TTM eviction logic -* and shrinkers will move it out if needed. -*/ -if (obj->mm.rsgt) -i915_refct_sgt_put (fetch_and_zero (&obj->mm.rsgt)); + if (likely(i915_gem_object_has_struct_page(obj))) { +/* +* We're currently not called from a shrinker, so put_pages() +* typically means the object is about to destroyed, or called +* from move_notify(). So just avoid doing much for now. +* If the object is not destroyed next, The TTM eviction logic +* and shrinkers will move it out if needed. +*/ +if (obj->mm.rsgt) +i915_refct_sgt_put (fetch_and_zero (&obj->mm.rsgt)); + } else +i915_gem_object_put_pages_phys (obj ,st ); }/**
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +123
-0@@ -979,6 +1017,129 @@ void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj) spin_unlock(&bo->bdev->lru_lock); } +static int +i915_ttm_pread (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pread *arg) +{ +if (!i915_gem_object_has_struct_page (obj)) +return i915_gem_object_pread_phys (obj, arg); + +return -ENODEV ; +} + +static int +i915_ttm_pwrite (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *arg) +{ +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +char __user *user_data =u64_to_user_ptr (arg->data_ptr); +struct address_space *mapping; +u64 remain, offset; +struct file *filp; +unsigned int pg; +int err; + +/* Caller already validated user args */ +GEM_BUG_ON (!access_ok (user_data, arg->size)); + +if (!i915_gem_object_has_struct_page (obj)) +return i915_gem_object_pwrite_phys (obj, arg); + +/* +* We need to pin the pages in order to have access to the filp +* given by shmem, quite unlike in the legacy GEM shmem backend +* where it would be available upon object creation +*/ + err =i915_gem_object_pin_pages_unlocked (obj); +if (err) { +drm_dbg (&i915->drm,"%s pin-pages err=%d\n" , __func__, err); +return err; + } + + filp =i915_gem_ttm_get_filep (obj); +if (!filp) { + err = -ENXIO ; + goto error; + } + + mapping = filp->f_mapping; + +if (obj->mm.madv !=I915_MADV_WILLNEED ) { + err = -EFAULT ; + goto error; + } + +/* +* Before the pages are instantiated the object is treated as being +* in the CPU domain. The pages will be clflushed as required before +* use, and we can freely write into the pages directly. If userspace +* races pwrite with any other operation; corruption will ensue - +* that is userspace's prerogative! +*/ + + remain = arg->size; + offset = arg->offset; + pg =offset_in_page (offset); + +do { +unsigned int len, unwritten; +struct page *page; +void *data, *vaddr; +int err; +char c; + + len =PAGE_SIZE - pg; +if (len > remain) + len = remain; + +/* Prefault the user page to reduce potential recursion */ + err =__get_user (c, user_data); +if (err) + goto error; + + err =__get_user (c, user_data + len -1 ); +if (err) + goto error; + + err =pagecache_write_begin (obj->base.filp, mapping, + offset, len,0 , + &page, &data); +if (err <0 ) + goto error; + + vaddr =kmap_atomic (page); + unwritten =__copy_from_user_inatomic (vaddr + pg, + user_data, + len); +kunmap_atomic (vaddr); + + err =pagecache_write_end (obj->base.filp, mapping, + offset, len, len - unwritten, + page, data); +if (err <0 ) + goto error; + +/* We don't handle -EFAULT, leave it to the caller to check */ +if (unwritten) { + err = -ENODEV ; + goto error; + } + + remain -= len; + user_data += len; + offset += len; + pg =0 ; + }while (remain); + +i915_gem_object_unpin_pages (obj); + +return 0 ; + +error: +i915_gem_object_unpin_pages (obj); +return err; +} +/* * TTM-backed gem object destruction requires some clarification.
* Basically we have two possibilities here. We can either rely on thedrivers/gpu/drm/i915/gem/i915_gem_ttm.c +1
-1@@ -1120,7 +1281,7 @@ static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj)ttm_bo_unmap_virtual (i915_gem_to_ttm (obj )); } -static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = { +static const struct drm_i915_gem_object_ops i915_gem_ttm_discrete_ops = { .name ="i915_gem_object_ttm" ,.flags =
I915_GEM_OBJECT_IS_SHRINKABLE|
I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST,drivers/gpu/drm/i915/gem/i915_gem_ttm.c +17
-0@@ -1139,6 +1300,23 @@ static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = { .mmap_ops = &vm_ops_ttm, }; +static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_integrated_ops = { + .name ="i915_gem_object_ttm" , + .flags =I915_GEM_OBJECT_IS_SHRINKABLE | +I915_GEM_OBJECT_SELF_MANAGED_SHRINK_LIST , + + .get_pages = i915_ttm_get_pages, + .put_pages = i915_ttm_put_pages, + .truncate = i915_ttm_truncate, + .shrink = i915_ttm_shrink, + + .pwrite = i915_ttm_pwrite, + .pread = i915_ttm_pread, + + .adjust_lru = i915_ttm_adjust_lru, + .delayed_free = i915_ttm_delayed_free, +}; +void i915_ttm_bo_destroy (struct ttm_buffer_object *bo){ struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);drivers/gpu/drm/i915/gem/i915_gem_ttm.c +13
-0@@ -1170,6 +1348,19 @@ void i915_ttm_bo_destroy(struct ttm_buffer_object *bo) } } +/** +* intel_region_ttm_shmem_init - Initialize a memory region for TTM. +* @mem: The region to initialize. +* +* Return: 0 on success, negative error code on failure. +*/ +static int intel_region_ttm_init_shmem (struct intel_memory_region *mem) +{ +i915_gemfs_init (mem->i915); + +return 0 ;/* Don't error, we can simply fallback to the kernel mnt */ +} +/** * __i915_gem_ttm_object_init - Initialize a ttm-backed i915 gem object * @mem: The initial memory region for the object.
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +5
-1@@ -1196,7 +1387,12 @@ int __i915_gem_ttm_object_init(structintel_memory_region *mem, int ret;drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &i915_gem_ttm_obj_ops, &lock_class, flags); + +if (IS_DGFX (i915)) +i915_gem_object_init (obj, &i915_gem_ttm_discrete_ops, &lock_class, flags); +else + i915_gem_object_init(obj,
&i915_gem_ttm_obj_integrated_ops,&lock_class,drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1
-0+ flags);obj->bo_offset = offset;drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0
-1@@ -1206,8 +1402,8 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,INIT_RADIX_TREE (&obj->ttm.get_io_page.radix,GFP_KERNEL | __GFP_NOWARN);mutex_init (&obj->ttm.get_io_page.lock); - bo_type = (obj->flags & I915_BO_ALLOC_USER) ?
ttm_bo_type_device:drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1
-1- ttm_bo_type_kernel; + bo_type = (obj->ops->mmap_offset && (obj->flags &
I915_BO_ALLOC_USER)) ?drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1
-0+ ttm_bo_type_device : ttm_bo_type_kernel;obj->base.vma_node.driver_private = i915_gem_to_ttm(obj);drivers/gpu/drm/i915/gem/i915_gem_ttm.c +22
-0@@ -1247,10 +1443,32 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem, }static const struct intel_memory_region_ops ttm_system_region_ops = { + .init = intel_region_ttm_init_shmem, .init_object = __i915_gem_ttm_object_init, .release = intel_region_ttm_fini, }; +/** +* Return: filp. +*/ +struct file * +i915_gem_ttm_get_filep (struct drm_i915_gem_object *obj) +{ +struct drm_device *dev = obj->base.dev; +struct ttm_buffer_object *bo; +struct i915_ttm_tt *i915_tt; + + bo =i915_gem_to_ttm (obj); +if (!bo->ttm) { +drm_dbg (dev,"ttm has not been allocated for bo\n" ); +return NULL ; + } + + i915_tt =container_of (bo->ttm,typeof (*i915_tt), ttm); + +return i915_tt->filp; +} +struct
intel_memory_region* i915_gem_ttm_system_setup(structdrm_i915_private*i915,u16 type, u16 instance)drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0
-0@@ -1268,3 +1486,22 @@ i915_gem_ttm_system_setup(struct drm_i915_private *i915,intel_memory_region_set_name (mr,"system-ttm" );return mr;}
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +13
-0+ +bool i915_gem_object_is_shmem (struct drm_i915_gem_object *obj) +{ +struct intel_memory_region *mr =READ_ONCE (obj->mm.region); + +#ifdef CONFIG_LOCKDEP +if (i915_gem_object_migratable (obj) && +i915_gem_object_evictable (obj)) +assert_object_held (obj); +#endif + +/* Review list of placements to make sure object isn't migratable */ + if (i915_gem_object_placement_possible(obj,
INTEL_MEMORY_LOCAL))drivers/gpu/drm/i915/gem/i915_gem_ttm.c +6
-0+return false; + +return mr && (mr->type ==INTEL_MEMORY_SYSTEM && + (obj->ops == &i915_gem_ttm_obj_integrated_ops || + obj->ops == &i915_gem_ttm_discrete_ops)); +}drivers/gpu/drm/i915/gem/i915_gem_ttm.h +3
-0@@ -92,4 +92,7 @@ static inline bool i915_ttm_cpu_maps_iomem(struct ttm_resource *mem)/* Once / if we support GGTT, this is also false for cached ttm_tts */ return mem->mem_type !=I915_PL_SYSTEM ; } + +struct file *i915_gem_ttm_get_filep (struct drm_i915_gem_object *obj); +#endif
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +0
-0@@ -46,7 +46,7 @@ static enum i915_cache_leveli915_ttm_cache_level(struct
drm_i915_private*i915, structttm_resource*res,
structttm_tt*ttm)
{drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +1
-1- return ((HAS_LLC(i915) || HAS_SNOOP(i915)) && + return ((HAS_LLC(i915)) &&!i915_ttm_gtt_binds_lmem(res) && ttm->caching == ttm_cached) ? I915_CACHE_LLC : I915_CACHE_NONE;drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c +6
-1@@ -77,7 +77,12 @@ void i915_ttm_adjust_domains_after_move(struct drm_i915_gem_object *obj) { struct ttm_buffer_object *bo = i915_gem_to_ttm(obj); -if (i915_ttm_cpu_maps_iomem (bo->resource) || bo->ttm->caching != ttm_cached) { + if (!i915_ttm_cpu_maps_iomem(bo->resource) && + bo->ttm->caching == ttm_uncached) { + obj->write_domain = I915_GEM_DOMAIN_CPU; + obj->read_domains = I915_GEM_DOMAIN_CPU; + } else if (i915_ttm_cpu_maps_iomem(bo->resource) || + bo->ttm->caching != ttm_cached) { obj->write_domain = I915_GEM_DOMAIN_WC;obj->read_domains = I915_GEM_DOMAIN_WC; } else {drivers/gpu/drm/i915/gt/shmem_utils.c +3
-0@@ -10,6 +10,9 @@#include "gem/i915_gem_object.h" #include "gem/i915_gem_lmem.h" +#include "gem/i915_gem_ttm.h" + +#include "i915_drv.h" #include "shmem_utils.h" struct file *shmem_create_from_data(const char *name, void *data,
size_tlen)drivers/gpu/drm/i915/gt/shmem_utils.c +22
-5@@ -30,24 +33,65 @@ struct file *shmem_create_from_data(const char *name, void *data, size_t len)return file; } +static int shmem_flush_object (struct file *file,unsigned long num_pages) +{ +struct page *page; +unsigned long pfn; + +for (pfn =0 ; pfn < num_pages; pfn++) { + page =shmem_read_mapping_page_gfp (file->f_mapping, pfn, +GFP_KERNEL ); +if (IS_ERR (page)) +return PTR_ERR (page); + +set_page_dirty (page); +mark_page_accessed (page); +kunmap (page); +put_page (page); + } + +return 0 ; +} +struct file *shmem_create_from_object (struct drm_i915_gem_object *obj) { +struct drm_i915_private *i915 =to_i915 (obj->base.dev);struct file *file;void *ptr; +int err;if (i915_gem_object_is_shmem (obj)) { - file = obj->base.filp; -atomic_long_inc (&file->f_count); -return file; - } - ptr = i915_gem_object_pin_map_unlocked(obj,
i915_gem_object_is_lmem(obj)?drivers/gpu/drm/i915/gt/shmem_utils.c +0
-1- I915_MAP_WC :
I915_MAP_WB);drivers/gpu/drm/i915/gt/shmem_utils.c +4
-4-if (IS_ERR (ptr)) -return ERR_CAST (ptr); +GEM_BUG_ON (!i915_gem_object_has_pages (obj)); - file =shmem_create_from_data ("" , ptr, obj->base.size); -i915_gem_object_unpin_map (obj); + err =i915_gem_object_pin_pages_unlocked (obj); +if (err) { + drm_dbg(&i915->drm, "%s pin-pages err=%d\n",
__func__,drivers/gpu/drm/i915/gt/shmem_utils.c +8
-0+ err); +return ERR_PTR (err); + } + + file =i915_gem_ttm_get_filep (obj); +GEM_BUG_ON (!file); + + err = shmem_flush_object(file, obj->base.size >>
PAGE_SHIFT);drivers/gpu/drm/i915/gt/shmem_utils.c +2
-0+if (err) { + drm_dbg(&i915->drm, "shmem_flush_objectfailed\n");
drivers/gpu/drm/i915/gt/shmem_utils.c +8
-0+i915_gem_object_unpin_pages (obj); +return ERR_PTR (err); + } + +atomic_long_inc (&file->f_count); +i915_gem_object_unpin_pages (obj); + }else { + ptr = i915_gem_object_pin_map_unlocked(obj,
i915_gem_object_is_lmem(obj)?drivers/gpu/drm/i915/gt/shmem_utils.c +1
-0+ I915_MAP_WC :
I915_MAP_WB);drivers/gpu/drm/i915/gt/shmem_utils.c +6
-0+if (IS_ERR (ptr)) +return ERR_CAST (ptr); + + file =shmem_create_from_data ("" , ptr, obj->base.size); +i915_gem_object_unpin_map (obj); + }return file; }drivers/gpu/drm/i915/intel_memory_region.c +1
-6@@ -309,12 +309,7 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915) instance = intel_region_map[i].instance;switch (type) {case INTEL_MEMORY_SYSTEM : -if (IS_DGFX (i915)) - mem =i915_gem_ttm_system_setup (i915, type, - instance); -else - mem =i915_gem_shmem_setup (i915, type, - instance); + mem =i915_gem_ttm_system_setup (i915, type, instance);break; case INTEL_MEMORY_STOLEN_LOCAL: mem = i915_gem_stolen_lmem_setup(i915, type,instance);
--
2.35.1
Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTM
Quoted 63 lines · Michael J
Quoted 63 lines
-----Original Message-----
From: Intel-gfx <[email protected]> On Behalf Of Adrian Larumbe
Sent: Tuesday, May 17, 2022 4:45 PM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMRemove shmem region and object backend code as they are now unnecessary.
In the case of objects placed in SMEM and backed by kernel shmem files, the file pointer has to be retrieved from thettm_ttstructure, so change this as well. This means accessing an shmem-backed BO's file pointer requires getting its pages beforehand, unlike in the old shmem backend.Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM way', also making sure its pages are put when a TTM shmem object has no struct page.
Signed-off-by Adrian Larumbe <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +4
-0@@ -12,6 +12,7 @@#include <asm/smp.h> #include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev); +struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * · line 107
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +0
-0if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma);Since all of the devices that will have device memory will be true for
HAS_LMEM, won't your code path always go todrm_gem_prime_mmap()?
This makes me wonder, how was mapping of a dmabuf BO working before, in the case of DG2 and DG1, when an object is smem-bound, and therefore backed by shmem?
I guess in this case it might be more sensible to control for the case that it's an lmem-only object on a discrete platform as follows:
static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
{
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
struct drm_i915_private *i915 = to_i915(obj->base.dev);
struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
struct file *filp = i915_gem_ttm_get_filep(obj);
int ret;
if (obj->base.size < vma->vm_end - vma->vm_start)
return -EINVAL;
if (IS_DGFX(i915) && i915_ttm_cpu_maps_iomem(bo->resource))
return drm_gem_prime_mmap(&obj->base, vma);
if (IS_ERR(filp))
return PTR_ERR(filp);
ret = call_mmap(filp, vma);
if (ret)
return ret;
vma_set_file(vma, filp);
return 0;
}Quoted 56 lines
Quoted 43 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +5
-3-if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-0@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, struct drm_i915_private *i915 = to_i915(dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;/* * mmap ioctl is disallowed for all discrete platforms,
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, if (!obj)drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev, void · line 90
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-6return -ENOENT ; -/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp;Why is this now ok? This is the imported object. And it used to give an error.
Quoted 6 lines
If you are importing from a different device, (i.e. an amd device is exporting the object, and you are i915 here), can you even do this?
My understanding was that mmaping was only for the exported object.
Has this changed?
You're right here, I completely misunderstood how this function is meant to deal with imported objects. This arose as a consequence of the file pointer being moved into the ttm_tt structure from the base DRM object.
The way I now check for the case that it's an imported object and therefore this function should throw back an error is as follows:
/* prime objects have no backing filp to GEM mmap
* pages from.
*/
if (obj->base.import_attach) {
GEM_WARN_ON(obj->base.filp != NULL);
addr = -ENXIO;
goto err;
}I believe the import_attach member has to be set for all imported members. However, this just made me think, what would happen in the case we want to mat a BO that we have exported for another driver to use? The import_attach field would be set so my code would return with an error, even though we should be in full control of mmaping it.
Maybe by allowing the function to go forward in case the base GEM object's dma-buf operations are the same as our driver's:
i915_gem_dmabuf.c:
const struct dma_buf_ops *i915_get_dmabuf_ops(void) {
return &i915_dmabuf_ops;
}i915_gem_mman.c:
/* prime objects have no backing filp to GEM mmap
* pages from.
*/
if (obj->base.import_attach &&
obj->base.dma_buf->ops != i915_get_dmabuf_ops()) {
GEM_WARN_ON(obj->base.filp != NULL);
addr = -ENXIO;
goto err;
}Quoted 3 lines
Thanks,
Mike
Cheers,
Adrian
Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTM
Quoted 77 lines
-----Original Message-----
From: Adrian Larumbe <[email protected]>
Sent: Friday, May 27, 2022 12:08 PM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMQuoted 9 lines · Michael J
Quoted 9 lines
-----Original Message-----
From: Intel-gfx <[email protected]> On Behalf Of Adrian Larumbe
Sent: Tuesday, May 17, 2022 4:45 PM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMQuoted 3 lines
Quoted 3 lines
Remove shmem region and object backend code as they are now unnecessary.
In the case of objects placed in SMEM and backed by kernel shmem files,the
Quoted 51 lines
Quoted 51 lines
file pointer has to be retrieved from the
ttm_ttstructure, so change this as well. This means accessing an shmem-backed BO's file pointer requires getting its pages beforehand, unlike in the old shmem backend.Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM way', also making sure its pages are put when a TTM shmem object has no struct page.
Signed-off-by Adrian Larumbe <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +4
-0@@ -12,6 +12,7 @@#include <asm/smp.h> #include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev); +struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * · line 107
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +0
-0if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma);Since all of the devices that will have device memory will be true for
Quoted 7 lines
HAS_LMEM,Quoted 1 line
won't your code path always go to
drm_gem_prime_mmap()?This makes me wonder, how was mapping of a dmabuf BO working before, in the case
of DG2 and DG1, when an object is smem-bound, and therefore backed by shmem?
LMEM is a new thing. DG2 and DG1 have it available, but the initial patch sets did not support access via dma-buf.
With the TTM being used for the LMEM objects, I think that the drm_gem code was able to be used.
Quoted 6 lines
I guess in this case it might be more sensible to control for the case that it's an lmem-only object on a discrete platform as follows:
static int
i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
Quoted 12 lines
{
struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf);
struct drm_i915_private *i915 = to_i915(obj->base.dev);
struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
struct file *filp = i915_gem_ttm_get_filep(obj);
int ret;
if (obj->base.size < vma->vm_end - vma->vm_start)
return -EINVAL;
if (IS_DGFX(i915) && i915_ttm_cpu_maps_iomem(bo->resource))
return drm_gem_prime_mmap(&obj->base, vma);HAS_LMEM is roughly IS_DGFX...
As for the second part, (_maps_iomem), hmm...
If I am following this correctly drm_gem_prime_mmap() will call i915_gem_mmap, so I think that just the call (without the iomem check) is correct.
This is a newer mmap code path than the older integrated cards had, so I think that the context is HAS_LMEM (new and discrete), otherwise the old path.
Quoted 72 lines
if (IS_ERR(filp)) return PTR_ERR(filp); ret = call_mmap(filp, vma); if (ret) return ret; vma_set_file(vma, filp); return 0; }Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +5
-3-if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-0@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, struct drm_i915_private *i915 = to_i915(dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev,
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0/* * mmap ioctl is disallowed for all discrete platforms,
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev,void
Quoted 18 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 89
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-6*data, if (!obj) return -ENOENT; -/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp;Why is this now ok? This is the imported object. And it used to give an error.
If you are importing from a different device, (i.e. an amd device is exporting the object, and you are i915 here), can you even do this?
Quoted 8 lines
Quoted 3 lines
My understanding was that mmaping was only for the exported object.
Has this changed?
You're right here, I completely misunderstood how this function is meant to deal
with imported objects. This arose as a consequence of the file pointer being moved into thettm_ttstructure from the base DRM object.
Hmm, one other thing that I am seeing here for i915_gem_mmap_ioctl:
/* * mmap ioctl is disallowed for all discrete platforms, * and for all platforms with GRAPHICS_VER > 12. */ if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) > IP_VER(12, 0)) return -EOPNOTSUPP;
You need to use the i915_gem_mmap_offset_ioctl() to do mmap with the discrete (i.e. devices with LMEM).
So are we looking at the right code path?
Quoted 13 lines
The way I now check for the case that it's an imported object and therefore this
function should throw back an error is as follows:/* prime objects have no backing filp to GEM mmap
* pages from.
*/if (obj->base.import_attach) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }
Quoted 8 lines
I believe the
import_attachmember has to be set for all imported members. However, this just made me think, what would happen in the case we want
to mat a BO that we have exported for another driver to use? Theimport_attach
field would be set so my code would return with an error, even though we should
be in full control of mmaping it.
I am not following your comment.
import_attach is the BO pointer to the dmabuf attachment.
If I export a BO, I cannot set this pointer on the BO because it is for the import side only.
Quoted 9 lines
Maybe by allowing the function to go forward in case the base GEM object's dma-buf
operations are the same as our driver's:
i915_gem_dmabuf.c:const struct dma_buf_ops *i915_get_dmabuf_ops(void) { return &i915_dmabuf_ops; }
These will only get set on the exported BO.
Quoted 11 lines
i915_gem_mman.c:/* prime objects have no backing filp to GEM mmap
* pages from.
*/
if (obj->base.import_attach&&obj->base.dma_buf->ops != i915_get_dmabuf_ops()) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }
So you would never have import_attach and i915_dmabuf_ops.
Can you restate what you are trying to solve here? Maybe that will make things more clear?
Thanks,
M
Quoted 6 lines
Quoted 3 lines
Thanks,
Mike
Cheers,
Adrian
Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTM
Quoted 268 lines · Michael J
Quoted 77 lines
-----Original Message-----
From: Adrian Larumbe <[email protected]>
Sent: Friday, May 27, 2022 12:08 PM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMQuoted 9 lines · Michael J
Quoted 9 lines
-----Original Message-----
From: Intel-gfx <[email protected]> On Behalf Of Adrian Larumbe
Sent: Tuesday, May 17, 2022 4:45 PM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMQuoted 3 lines
Quoted 3 lines
Remove shmem region and object backend code as they are now unnecessary.
In the case of objects placed in SMEM and backed by kernel shmem files,the
Quoted 51 lines
Quoted 51 lines
file pointer has to be retrieved from the
ttm_ttstructure, so change this as well. This means accessing an shmem-backed BO's file pointer requires getting its pages beforehand, unlike in the old shmem backend.Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM way', also making sure its pages are put when a TTM shmem object has no struct page.
Signed-off-by Adrian Larumbe <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +4
-0@@ -12,6 +12,7 @@#include <asm/smp.h> #include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev); +struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * · line 107
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +0
-0if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma);Since all of the devices that will have device memory will be true for
Quoted 7 lines
HAS_LMEM,Quoted 1 line
won't your code path always go to
drm_gem_prime_mmap()?This makes me wonder, how was mapping of a dmabuf BO working before, in the case
of DG2 and DG1, when an object is smem-bound, and therefore backed by shmem?LMEM is a new thing. DG2 and DG1 have it available, but the initial patch sets did not support access via dma-buf.
With the TTM being used for the LMEM objects, I think that the
drm_gemcode was able to be used.Quoted 6 lines
I guess in this case it might be more sensible to control for the case that it's an lmem-only object on a discrete platform as follows:
static int
i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)Quoted 12 lines
{ struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf); struct drm_i915_private *i915 = to_i915(obj->base.dev); struct ttm_buffer_object *bo = i915_gem_to_ttm(obj); struct file *filp = i915_gem_ttm_get_filep(obj); int ret; if (obj->base.size < vma->vm_end - vma->vm_start) return -EINVAL; if (IS_DGFX(i915) && i915_ttm_cpu_maps_iomem(bo->resource)) return drm_gem_prime_mmap(&obj->base, vma);
HAS_LMEMis roughlyIS_DGFX...As for the second part, (
_maps_iomem), hmm...If I am following this correctly
drm_gem_prime_mmap()will calli915_gem_mmap, so I think that just the call (without the iomem check) is correct.This is a newer mmap code path than the older integrated cards had, so I think that the context is
HAS_LMEM(new and discrete), otherwise the old path.Quoted 72 lines
if (IS_ERR(filp)) return PTR_ERR(filp); ret = call_mmap(filp, vma); if (ret) return ret; vma_set_file(vma, filp); return 0; }Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +5
-3-if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-0@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, struct drm_i915_private *i915 = to_i915(dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev,
Quoted 3 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0/* * mmap ioctl is disallowed for all discrete platforms,
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev,void
Quoted 18 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 89
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-6*data, if (!obj) return -ENOENT; -/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp;Why is this now ok? This is the imported object. And it used to give an error.
If you are importing from a different device, (i.e. an amd device is exporting the object, and you are i915 here), can you even do this?
Quoted 8 lines
Quoted 3 lines
My understanding was that mmaping was only for the exported object.
Has this changed?
You're right here, I completely misunderstood how this function is meant to deal
with imported objects. This arose as a consequence of the file pointer being moved into thettm_ttstructure from the base DRM object.Hmm, one other thing that I am seeing here for
i915_gem_mmap_ioctl:/* * mmap ioctl is disallowed for all discrete platforms, * and for all platforms with GRAPHICS_VER > 12. */ if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) > IP_VER(12, 0)) return -EOPNOTSUPP;You need to use the
i915_gem_mmap_offset_ioctl()to do mmap with the discrete (i.e. devices with LMEM).So are we looking at the right code path?
Quoted 13 lines
The way I now check for the case that it's an imported object and therefore this
function should throw back an error is as follows:/* prime objects have no backing filp to GEM mmap
* pages from.
*/if (obj->base.import_attach) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }Quoted 8 lines
I believe the
import_attachmember has to be set for all imported members. However, this just made me think, what would happen in the case we want
to mat a BO that we have exported for another driver to use? Theimport_attach
field would be set so my code would return with an error, even though we should
be in full control of mmaping it.I am not following your comment.
import_attachis the BO pointer to the dmabuf attachment.If I export a BO, I cannot set this pointer on the BO because it is for the import side only.
Quoted 9 lines
Maybe by allowing the function to go forward in case the base GEM object's dma-buf
operations are the same as our driver's:
i915_gem_dmabuf.c:const struct dma_buf_ops *i915_get_dmabuf_ops(void) { return &i915_dmabuf_ops; }These will only get set on the exported BO.
Quoted 11 lines
i915_gem_mman.c:/* prime objects have no backing filp to GEM mmap
* pages from.
*/
if (obj->base.import_attach&&obj->base.dma_buf->ops != i915_get_dmabuf_ops()) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }
Quoted 4 lines
So you would never have
import_attachandi915_dmabuf_ops.Can you restate what you are trying to solve here? Maybe that will make things more clear?
Sorry, this is all because of a misunderstanding on my part. I thought the import_attach field would be set even for buffers that we've PRIME-exported to other drivers, but that's not the case.
Anyway, the bottom question was sourcing the file pointer for the underlying shmem file from its new location inside the i915_ttm_tt structure bound to a TTM bo, rather than obj->base.filp. The latter will now always be unset, but that doesn't mean the object is a PRIME import and therefore the legacy mmap ioctl should fail, so instead I should check the base.import_attach field instead, which would tell me that the buffer was imported, and so the ioctl must return an error.
Hope this clarifies it.
Quoted 11 lines
Thanks,
M
Quoted 6 lines
Quoted 3 lines
Thanks,
Mike
Cheers,
Adrian
Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTM
Hi Adrian,
Sorry for the delayed response, this got buried in my inbox...
Quoted 312 lines
-----Original Message-----
From: Adrian Larumbe <[email protected]>
Sent: Monday, June 6, 2022 4:20 PM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmem memory region and object backend with TTMQuoted 6 lines · Michael J
Quoted 6 lines
-----Original Message-----
From: Adrian Larumbe <[email protected]>
Sent: Friday, May 27, 2022 12:08 PM
To: Ruhl, Michael J <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmemmemory
Quoted 10 lines
Quoted 10 lines
region and object backend with TTM
Quoted 7 lines · Michael J
Quoted 7 lines
-----Original Message-----
From: Intel-gfx <[email protected]> On Behalf Of Adrian Larumbe
Sent: Tuesday, May 17, 2022 4:45 PM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: [Intel-gfx] [RFC PATCH v2 1/1] drm/i915: Replace shmemmemory
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
region and object backend with TTM
Remove shmem region and object backend code as they are now unnecessary.
In the case of objects placed in SMEM and backed by kernel shmemfiles,
Quoted 3 lines
Quoted 3 lines
the
Quoted 2 lines
Quoted 2 lines
file pointer has to be retrieved from the
ttm_ttstructure, so change this as well. This means accessing an shmem-backed BO's file pointerrequires
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
getting its pages beforehand, unlike in the old shmem backend.
Expand TTM BO creation by handling devices with no LLC so that their caching and coherency properties are set accordingly.
Adapt phys backend to put pages of original shmem object in a 'TTM
way',
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
also making sure its pages are put when a TTM shmem object has no
struct
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
page.
Signed-off-by Adrian Larumbe <[email protected]>---
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +0
-0@@ -12,6 +12,7 @@#include <asm/smp.h> Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct
Quoted 6 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +1
-0#include "gem/i915_gem_dmabuf.h" +#include "gem/i915_gem_ttm.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_scatterlist.h" @@ -94,22 +95,25 @@ static int i915_gem_dmabuf_mmap(struct
dma_bufQuoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +3
-0*dma_buf, struct vm_area_struct * {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);struct drm_i915_private *i915 =to_i915 (obj->base.dev); +struct file *filp =i915_gem_ttm_get_filep (obj);int ret; +GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->base.size < vma->vm_end - vma->vm_start)return -EINVAL ;Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * · line 107
Quoted 2 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +0
-0if (HAS_LMEM (i915))return drm_gem_prime_mmap (&obj->base, vma);Since all of the devices that will have device memory will be true for
HAS_LMEM,Quoted 1 line
won't your code path always go to
drm_gem_prime_mmap()?This makes me wonder, how was mapping of a dmabuf BO working before,
in
Quoted 8 lines
Quoted 3 lines
the case
of DG2 and DG1, when an object is smem-bound, and therefore backed by shmem?LMEM is a new thing. DG2 and DG1 have it available, but the initial patch sets did not support access via dma-buf.
With the TTM being used for the LMEM objects, I think that the
drm_gemcode
Quoted 18 lines
was able to be used.
Quoted 16 lines
I guess in this case it might be more sensible to control for the case that it's an lmem-only object on a discrete platform as follows:
static int
i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma){ struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf); struct drm_i915_private *i915 = to_i915(obj->base.dev); struct ttm_buffer_object *bo = i915_gem_to_ttm(obj); struct file *filp = i915_gem_ttm_get_filep(obj); int ret; if (obj->base.size < vma->vm_end - vma->vm_start) return -EINVAL;Quoted 8 lines
Quoted 2 lines
if (IS_DGFX(i915) && i915_ttm_cpu_maps_iomem(bo->resource)) return drm_gem_prime_mmap(&obj->base, vma);
HAS_LMEMis roughlyIS_DGFX...As for the second part, (
_maps_iomem), hmm...If I am following this correctly
drm_gem_prime_mmap()will call
i915_gem_mmap,Quoted 3 lines
so I think that just the call (without the iomem check) is correct.
This is a newer mmap code path than the older integrated cards had, so I
think that
Quoted 33 lines
the context is
HAS_LMEM(new and discrete), otherwise the old path.Quoted 31 lines
if (IS_ERR(filp)) return PTR_ERR(filp); ret = call_mmap(filp, vma); if (ret) return ret; vma_set_file(vma, filp); return 0; }Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +3
-3-if (!obj->base.filp) +if (!filp)return -ENODEV ; - ret =call_mmap (obj->base.filp, vma); + ret =call_mmap (filp, vma);if (ret)return ret; -vma_set_file (vma, obj->base.filp); +vma_set_file (vma, filp);return 0 ; }@@ -224,6 +228,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags) exp_info.priv = gem_obj; exp_info.resv = obj->base.resv;Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev,
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +2
-0+GEM_BUG_ON (obj->base.import_attach !=NULL ); +if (obj->ops->dmabuf_export) {int ret = obj->ops->dmabuf_export (obj);if (ret)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -64,7 +64,9 @@ i915_gem_mmap_ioctl(struct drm_device *dev,void
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev,
Quoted 11 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-0*data, struct drm_i915_private *i915 = to_i915(dev);struct drm_i915_gem_mmap *args = data;struct drm_i915_gem_object *obj; +struct file *filp;unsigned long addr; +int ret;/* * mmap ioctl is disallowed for all discrete platforms,
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0@@ -83,12 +85,20 @@ i915_gem_mmap_ioctl(struct drm_device *dev,void
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +0
-0*data, if (!obj) return -ENOENT;Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c i915_gem_mmap_ioctl(struct drm_device *dev, void *data, · line 89
Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_mman.c +2
-6-/* prime objects have no backing filp to GEM mmap -* pages from. -*/ -if (!obj->base.filp) { - addr = -ENXIO ; - goto err; +if (obj->base.import_attach) + filp = obj->base.filp;Why is this now ok? This is the imported object. And it used to give an
error.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If you are importing from a different device, (i.e. an amd device is
exporting
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
the object, and you are i915 here), can you even do this?
My understanding was that mmaping was only for the exported object.
Has this changed?
You're right here, I completely misunderstood how this function is meant to deal
with imported objects. This arose as a consequence of the file pointerbeing
Quoted 4 lines
Quoted 1 line
moved into the
ttm_ttstructure from the base DRM object.Hmm, one other thing that I am seeing here for
i915_gem_mmap_ioctl:Quoted 8 lines
/* * mmap ioctl is disallowed for all discrete platforms, * and for all platforms with GRAPHICS_VER > 12. */ if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) > IP_VER(12, 0)) return -EOPNOTSUPP;You need to use the
i915_gem_mmap_offset_ioctl()to do mmap with thediscrete
Quoted 19 lines
(i.e. devices with LMEM).
So are we looking at the right code path?
Quoted 15 lines
The way I now check for the case that it's an imported object and therefore this
function should throw back an error is as follows:/* prime objects have no backing filp to GEM mmap
* pages from.
*/if (obj->base.import_attach) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }I believe the
import_attachmember has to be set for all imported members. However, this just made me think, what would happen in thecase
Quoted 7 lines
Quoted 6 lines
we want
to mat a BO that we have exported for another driver to use? Theimport_attach
field would be set so my code would return with an error, even though we should
be in full control of mmaping it.Quoted 8 lines
I am not following your comment.
import_attachis the BO pointer to the dmabuf attachment.If I export a BO, I cannot set this pointer on the BO because it is for the import side only.
Quoted 1 line
Maybe by allowing the function to go forward in case the base GEM
object's
Quoted 23 lines
Quoted 8 lines
dma-buf
operations are the same as our driver's:
i915_gem_dmabuf.c:const struct dma_buf_ops *i915_get_dmabuf_ops(void) { return &i915_dmabuf_ops; }These will only get set on the exported BO.
Quoted 11 lines
i915_gem_mman.c:/* prime objects have no backing filp to GEM mmap
* pages from.
*/
if (obj->base.import_attach&&obj->base.dma_buf->ops != i915_get_dmabuf_ops()) { GEM_WARN_ON(obj->base.filp != NULL); addr = -ENXIO; goto err; }Quoted 4 lines
So you would never have
import_attachandi915_dmabuf_ops.Can you restate what you are trying to solve here? Maybe that will make things more clear?
Sorry, this is all because of a misunderstanding on my part. I thought the
import_attachfield would be set even for buffers that we've PRIME-exported to other drivers, but that's not the case.Anyway, the bottom question was sourcing the file pointer for the underlying shmem file from its new location inside the
i915_ttm_ttstructure bound to a TTM bo, rather thanobj->base.filp. The latter will now always be unset, but that doesn't mean the object is a PRIME import and therefore the legacy mmap ioctl should fail, so instead I should check the base.import_attach field instead, which would tell me that the buffer was imported, and so the ioctl must return an error.
Quoted 1 line
Hope this clarifies it.
I think so. So, with the new TTM memory handling there is a potential hole in mmap processing path.
I am not yet as familiar with the TTM code paths. Will have to spend some time there (in my spare time...). 😊
Thanks,
Mike
Quoted 11 lines
Quoted 11 lines
Thanks,
M
Quoted 6 lines
Quoted 3 lines
Thanks,
Mike
Cheers,
Adrian
Patchwork
CI[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Replace shmem memory region and object backend
In reply to Adrian Larumbe== Series Details ==
== Series Details ==
Series: Replace shmem memory region and object backend
URL : https://patchwork.freedesktop.org/series/104105/
State : warning
== Summary ==
Error: dim checkpatch faileda310d6e73af3 drm/i915: Replace shmem memory region and object backend with TTM -:41: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "obj->base.import_attach" #41: FILE: drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:101:
+ GEM_BUG_ON(obj->base.import_attach != NULL);
-:67: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "obj->base.import_attach" #67: FILE: drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c:231:
+ GEM_BUG_ON(obj->base.import_attach != NULL);
-:98: CHECK:BRACES: Unbalanced braces around else statement #98: FILE: drivers/gpu/drm/i915/gem/i915_gem_mman.c:90:
+ else {
-:201: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "obj->base.import_attach" #201: FILE: drivers/gpu/drm/i915/gem/i915_gem_phys.c:33:
+ GEM_BUG_ON(obj->base.import_attach != NULL);
-:217: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!filp" #217: FILE: drivers/gpu/drm/i915/gem/i915_gem_phys.c:115:
+ if (GEM_WARN_ON(filp == NULL))
-:650: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!file" #650: FILE: drivers/gpu/drm/i915/gem/i915_gem_shmem.c:316:
+ GEM_WARN_ON(file == NULL);
-:781: CHECK:UNNECESSARY_PARENTHESES: Unnecessary parentheses around 'caching != ttm_write_combined' #781: FILE: drivers/gpu/drm/i915/gem/i915_gem_ttm.c:333:
+ if (i915_gem_object_is_shrinkable(obj) && (caching != ttm_write_combined)) {
-:832: CHECK:BRACES: braces {} should be used on all arms of this statement #832: FILE: drivers/gpu/drm/i915/gem/i915_gem_ttm.c:912:
+ if (likely(i915_gem_object_has_struct_page(obj))) {
[...]
+ } else
[...]
-:842: CHECK:BRACES: Unbalanced braces around else statement #842: FILE: drivers/gpu/drm/i915/gem/i915_gem_ttm.c:922:
+ } else
total: 0 errors, 0 warnings, 9 checks, 1116 lines checked
Patchwork
CI[Intel-gfx] ✗ Fi.CI.SPARSE: warning for Replace shmem memory region and object backend
In reply to Adrian Larumbe== Series Details ==
== Series Details ==
Series: Replace shmem memory region and object backend
URL : https://patchwork.freedesktop.org/series/104105/
State : warning
== Summary ==
Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BAT: failure for Replace shmem memory region and object backend
In reply to Adrian Larumbe== Series Details ==
== Series Details ==
Series: Replace shmem memory region and object backend
URL : https://patchwork.freedesktop.org/series/104105/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_11668 -> Patchwork_104105v1
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_104105v1 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_104105v1, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/index.html
Participating hosts (40 -> 43)
------------------------------
Additional (3): fi-kbl-soraka bat-dg2-8 bat-adls-5
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_104105v1:
### IGT changes ###
#### Possible regressions ####
* igt@gem_close_race@basic-process:
- fi-ilk-650: [PASS][1] -> [FAIL][2] +5 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-ilk-650/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-ilk-650/igt@[email protected]
- fi-bsw-kefka: [PASS][3] -> [DMESG-FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bsw-kefka/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-kefka/igt@[email protected]
* igt@gem_close_race@basic-threads:
- fi-bwr-2160: [PASS][5] -> [FAIL][6] +5 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bwr-2160/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bwr-2160/igt@[email protected]
- fi-bsw-nick: [PASS][7] -> [DMESG-FAIL][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bsw-nick/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-nick/igt@[email protected]
- fi-bsw-n3050: [PASS][9] -> [DMESG-FAIL][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bsw-n3050/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-n3050/igt@[email protected]
* igt@gem_exec_create@basic@smem:
- fi-blb-e6850: [PASS][11] -> [FAIL][12] +2 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-blb-e6850/igt@gem_exec_create@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-blb-e6850/igt@gem_exec_create@[email protected]
* igt@gem_exec_fence@basic-await@rcs0:
- fi-blb-e6850: [PASS][13] -> [DMESG-WARN][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-blb-e6850/igt@gem_exec_fence@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-blb-e6850/igt@gem_exec_fence@[email protected]
* igt@gem_exec_fence@basic-await@vcs0:
- fi-elk-e7500: [PASS][15] -> [FAIL][16] +6 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-elk-e7500/igt@gem_exec_fence@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-elk-e7500/igt@gem_exec_fence@[email protected]
* igt@gem_exec_fence@nb-await@vcs0:
- fi-ilk-650: [PASS][17] -> [INCOMPLETE][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-ilk-650/igt@gem_exec_fence@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-ilk-650/igt@gem_exec_fence@[email protected]
* igt@gem_exec_parallel@engines@basic:
- fi-elk-e7500: [PASS][19] -> [INCOMPLETE][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-elk-e7500/igt@gem_exec_parallel@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-elk-e7500/igt@gem_exec_parallel@[email protected]
* igt@gem_exec_suspend@basic-s0@smem:
- fi-glk-j4005: [PASS][21] -> [FAIL][22] +13 similar issues
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-glk-j4005/igt@gem_exec_suspend@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-glk-j4005/igt@gem_exec_suspend@[email protected]
* igt@gem_exec_suspend@basic-s3@smem:
- fi-bxt-dsi: [PASS][23] -> [FAIL][24] +6 similar issues
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bxt-dsi/igt@gem_exec_suspend@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bxt-dsi/igt@gem_exec_suspend@[email protected]
* igt@gem_render_linear_blits@basic:
- fi-bwr-2160: [PASS][25] -> [DMESG-FAIL][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bwr-2160/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bwr-2160/igt@[email protected]
* igt@gem_sync@basic-each:
- fi-pnv-d510: [PASS][27] -> [FAIL][28] +5 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-pnv-d510/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-pnv-d510/igt@[email protected]
* igt@gem_tiled_blits@basic:
- fi-bwr-2160: [PASS][29] -> [INCOMPLETE][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-bwr-2160/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bwr-2160/igt@[email protected]
* igt@kms_frontbuffer_tracking@basic:
- fi-ivb-3770: [PASS][31] -> [FAIL][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-ivb-3770/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-ivb-3770/igt@[email protected]
- fi-snb-2600: [PASS][33] -> [FAIL][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-snb-2600/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-snb-2600/igt@[email protected]
* igt@runner@aborted:
- fi-rkl-guc: NOTRUN -> [FAIL][35]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-rkl-guc/igt@[email protected]
- fi-adl-ddr5: NOTRUN -> [FAIL][36]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-adl-ddr5/igt@[email protected]
#### Suppressed ####
The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.
* igt@runner@aborted:
- {bat-rpls-2}: [FAIL][37] ([i915#4312]) -> [FAIL][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/bat-rpls-2/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-rpls-2/igt@[email protected]
- {bat-adls-5}: NOTRUN -> [FAIL][39]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-adls-5/igt@[email protected]
- {bat-adln-1}: NOTRUN -> [FAIL][40]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-adln-1/igt@[email protected]
- {bat-adlp-6}: NOTRUN -> [FAIL][41]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-adlp-6/igt@[email protected]
Known issues
------------
Here are the changes found in Patchwork_104105v1 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_exec_fence@basic-busy@bcs0:
- fi-kbl-soraka: NOTRUN -> [SKIP][42] ([fdo#109271]) +9 similar issues
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@gem_exec_fence@[email protected]
* igt@gem_huc_copy@huc-copy:
- fi-kbl-soraka: NOTRUN -> [SKIP][43] ([fdo#109271] / [i915#2190])
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@[email protected]
* igt@gem_lmem_swapping@basic:
- fi-kbl-soraka: NOTRUN -> [SKIP][44] ([fdo#109271] / [i915#4613]) +3 similar issues
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@[email protected]
* igt@i915_selftest@live@gt_pm:
- fi-kbl-soraka: NOTRUN -> [DMESG-FAIL][45] ([i915#1886])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@i915_selftest@live@gt_pm.html
* igt@i915_selftest@live@hangcheck:
- fi-snb-2600: [PASS][46] -> [INCOMPLETE][47] ([i915#3921])
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-snb-2600/igt@i915_selftest@[email protected]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-snb-2600/igt@i915_selftest@[email protected]
* igt@kms_chamelium@common-hpd-after-suspend:
- fi-hsw-4770: NOTRUN -> [SKIP][48] ([fdo#109271] / [fdo#111827])
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-hsw-4770/igt@[email protected]
* igt@kms_chamelium@dp-edid-read:
- fi-kbl-soraka: NOTRUN -> [SKIP][49] ([fdo#109271] / [fdo#111827]) +7 similar issues
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@[email protected]
* igt@kms_frontbuffer_tracking@basic:
- fi-skl-6700k2: [PASS][50] -> [FAIL][51] ([i915#2546])
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-skl-6700k2/igt@[email protected]
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-skl-6700k2/igt@[email protected]
- fi-cfl-8700k: [PASS][52] -> [FAIL][53] ([i915#2546])
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-cfl-8700k/igt@[email protected]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-cfl-8700k/igt@[email protected]
* igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
- fi-kbl-soraka: NOTRUN -> [SKIP][54] ([fdo#109271] / [i915#533])
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-soraka/igt@[email protected]
* igt@runner@aborted:
- fi-bsw-kefka: NOTRUN -> [FAIL][55] ([i915#3690] / [i915#4312])
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-kefka/igt@[email protected]
- fi-bsw-nick: NOTRUN -> [FAIL][56] ([i915#3690] / [i915#4312])
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-nick/igt@[email protected]
- fi-bwr-2160: NOTRUN -> [FAIL][57] ([i915#4312])
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bwr-2160/igt@[email protected]
- fi-kbl-guc: NOTRUN -> [FAIL][58] ([i915#5257])
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-kbl-guc/igt@[email protected]
- fi-cfl-guc: NOTRUN -> [FAIL][59] ([i915#5257])
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-cfl-guc/igt@[email protected]
- fi-skl-guc: NOTRUN -> [FAIL][60] ([i915#5257])
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-skl-guc/igt@[email protected]
- fi-bsw-n3050: NOTRUN -> [FAIL][61] ([i915#3690] / [i915#4312])
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-bsw-n3050/igt@[email protected]
#### Possible fixes ####
* igt@i915_selftest@live@hangcheck:
- fi-hsw-4770: [INCOMPLETE][62] ([i915#4785]) -> [PASS][63]
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-hsw-4770/igt@i915_selftest@[email protected]
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-hsw-4770/igt@i915_selftest@[email protected]
#### Warnings ####
* igt@i915_suspend@basic-s3-without-i915:
- fi-rkl-11600: [FAIL][64] ([fdo#103375]) -> [INCOMPLETE][65] ([i915#5982])
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-rkl-11600/igt@[email protected]
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-rkl-11600/igt@[email protected]
* igt@runner@aborted:
- bat-dg1-5: [FAIL][66] ([i915#4312] / [i915#5257]) -> [FAIL][67] ([i915#5616])
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/bat-dg1-5/igt@[email protected]
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-dg1-5/igt@[email protected]
- fi-apl-guc: [FAIL][68] ([i915#4312]) -> [FAIL][69] ([i915#5257])
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-apl-guc/igt@[email protected]
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-apl-guc/igt@[email protected]
- bat-dg1-6: [FAIL][70] ([i915#4312] / [i915#5257]) -> [FAIL][71] ([i915#5616])
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/bat-dg1-6/igt@[email protected]
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/bat-dg1-6/igt@[email protected]
- fi-blb-e6850: [FAIL][72] ([fdo#109271] / [i915#2403] / [i915#4312]) -> [FAIL][73] ([i915#2403] / [i915#4312])
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11668/fi-blb-e6850/igt@[email protected]
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/fi-blb-e6850/igt@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#103375]: https://bugs.freedesktop.org/show_bug.cgi?id=103375
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1886]: https://gitlab.freedesktop.org/drm/intel/issues/1886
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#2403]: https://gitlab.freedesktop.org/drm/intel/issues/2403
[i915#2546]: https://gitlab.freedesktop.org/drm/intel/issues/2546
[i915#3690]: https://gitlab.freedesktop.org/drm/intel/issues/3690
[i915#3921]: https://gitlab.freedesktop.org/drm/intel/issues/3921
[i915#4312]: https://gitlab.freedesktop.org/drm/intel/issues/4312
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4785]: https://gitlab.freedesktop.org/drm/intel/issues/4785
[i915#5257]: https://gitlab.freedesktop.org/drm/intel/issues/5257
[i915#533]: https://gitlab.freedesktop.org/drm/intel/issues/533
[i915#5602]: https://gitlab.freedesktop.org/drm/intel/issues/5602
[i915#5616]: https://gitlab.freedesktop.org/drm/intel/issues/5616
[i915#5982]: https://gitlab.freedesktop.org/drm/intel/issues/5982
Build changes
-------------
* Linux: CI_DRM_11668 -> Patchwork_104105v1
CI-20190529: 20190529
CI_DRM_11668: 0aeb4ff42e2e9fd1dee49e6bb79cc81c8eafd3fc @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6477: 70cfef35851891aeaa829f5e8dcb7fd43b454bde @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_104105v1: 0aeb4ff42e2e9fd1dee49e6bb79cc81c8eafd3fc @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
23c96d51f878 drm/i915: Replace shmem memory region and object backend with TTM
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_104105v1/index.html
Quoted 16 lines · Adrian Larumbe
This patch is a second attempt at eliminating the old shmem memory region and GEM object backend, in favour of a TTM-based one that is able to manage objects placed on both system and local memory.
Questions addressed since previous revision:
* Creating an anonymous vfs mount for shmem files in TTM
* Fixing LLC caching properties and bit 17 swizzling before setting a TTM bo's pages when callingget_pages
* Added handling of phys backend from TTM functions
* Added pread callback to TTM gem object backend
* Inshmem_create_from_object, ensuring an shmem object we just got a filp for has its pages marked dirty and accessed. Otherwise, the engine won't be able to read the initial state and a GPU hung will ensue
Quoted 6 lines
However, one of the issues persists:
Many GPU hungs in machines of GEN <= 5. My assumption is this has something
to do with a caching pitfall, but everywhere across the TTM backend code I've tried to handle object creation and getting its pages with the same set of caching and coherency properties as in the old shmem backend.
Some thoughts in case it's helpful:
- We still look to be trampling the cache_level etc after object creation. AFAICT i915_ttm_adjust_gem_after_move can be called in various places after creation.
- The i915_ttm_pwrite hook won't play nice on non-llc platforms, since it doesn't force a clflush or keep track of the writes with cache_dirty. The existing ->shmem_pwrite hook only works because we are guaranteed to have not yet populated the mm.pages, and on non-llc platforms we always force a clflush in __set_pages(). In i915_ttm_pwrite we are now just calling pin_pages() and then writing through the page-cache without forcing a clflush, or ensuring that we leave cache_dirty set. Also AFAIK the whole point of shmem_pwrite was to avoid needing to populate the entire object like when calling pin_pages(). Would it make sense to just fallback to using i915_gem_shmem_pwrite, which should already take care of the required flushing?
For reference a common usage pattern is something like:
bb = gem_create() <-- assume non-llc so must be CACHE_NONE gem_write(bb, BATCH_BUFFER_END) <-- might use cached pwrite internally execbuf(bb) <-- doesn't see BATCH_BUFFER_END if we don't clflush
Quoted 19 lines
Adrian Larumbe (1):
drm/i915: Replace shmem memory region and object backend with TTMdrivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)--
2.35.1
Quoted 25 lines · Matthew Auld
Quoted 16 lines · Adrian Larumbe
This patch is a second attempt at eliminating the old shmem memory region and GEM object backend, in favour of a TTM-based one that is able to manage objects placed on both system and local memory.
Questions addressed since previous revision:
* Creating an anonymous vfs mount for shmem files in TTM
* Fixing LLC caching properties and bit 17 swizzling before setting a TTM bo's pages when callingget_pages
* Added handling of phys backend from TTM functions
* Added pread callback to TTM gem object backend
* Inshmem_create_from_object, ensuring an shmem object we just got a filp for has its pages marked dirty and accessed. Otherwise, the engine won't be able to read the initial state and a GPU hung will ensueQuoted 6 lines
However, one of the issues persists:
Many GPU hungs in machines of GEN <= 5. My assumption is this has something
to do with a caching pitfall, but everywhere across the TTM backend code I've tried to handle object creation and getting its pages with the same set of caching and coherency properties as in the old shmem backend.
Quoted 5 lines
Some thoughts in case it's helpful:
- We still look to be trampling the
cache_leveletc after object creation. AFAICTi915_ttm_adjust_gem_after_movecan be called in various places after creation.
I traced this function so that I could see everywhere it was being called when running some IGT tests and kmscube, and the only place it was setting a caching coherence value other than none was in init_status_page, where I915_CACHE_LLC is picked as the cache coherency mode even for machines that do not have it. However this code was already present before my changes and didn't seem to cause any issues, so I don't think it's involved.
Quoted 13 lines
- The
i915_ttm_pwritehook won't play nice on non-llc platforms, since it doesn't force a clflush or keep track of the writes withcache_dirty. The existing ->shmem_pwrite hook only works because we are guaranteed to have not yet populated the mm.pages, and on non-llc platforms we always force a clflush in__set_pages(). Ini915_ttm_pwritewe are now just callingpin_pages()and then writing through the page-cache without forcing a clflush, or ensuring that we leavecache_dirtyset. Also AFAIK the whole point ofshmem_pwritewas to avoid needing to populate the entire object like when callingpin_pages(). Would it make sense to just fallback to usingi915_gem_shmem_pwrite, which should already take care of the required flushing?
Quoted 5 lines
For reference a common usage pattern is something like:
bb =
gem_create()<-- assume non-llc so must beCACHE_NONEgem_write(bb, BATCH_BUFFER_END)<-- might use cached pwrite internally execbuf(bb) <-- doesn't seeBATCH_BUFFER_ENDif we don't clflush
It turns out this was the underlying issue causing machines GEN <= 5 to break in pretty much every single test. It seems that for older hardware, IGT tests would pick pwrite as the preferred method for filling BO's from UM, so my code wasn't calling clfush after getting the pages and writing the UM pointer data into the shmem file.
The way I fixed it was creating an shmem file for this and other cases when it's required by the existing code, but without getting the pages. In a way, I just cut through the usual TTM populate path and instance an shmem object so that I can avoid caching issues.
Thanks a lot for catching this one!
Quoted 18 lines
Quoted 18 lines
Adrian Larumbe (1):
drm/i915: Replace shmem memory region and object backend with TTMdrivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)--
2.35.1
Quoted 33 lines · Adrian Larumbe
Quoted 25 lines · Matthew Auld
Quoted 16 lines · Adrian Larumbe
This patch is a second attempt at eliminating the old shmem memory region and GEM object backend, in favour of a TTM-based one that is able to manage objects placed on both system and local memory.
Questions addressed since previous revision:
* Creating an anonymous vfs mount for shmem files in TTM
* Fixing LLC caching properties and bit 17 swizzling before setting a TTM bo's pages when callingget_pages
* Added handling of phys backend from TTM functions
* Added pread callback to TTM gem object backend
* Inshmem_create_from_object, ensuring an shmem object we just got a filp for has its pages marked dirty and accessed. Otherwise, the engine won't be able to read the initial state and a GPU hung will ensueQuoted 6 lines
However, one of the issues persists:
Many GPU hungs in machines of GEN <= 5. My assumption is this has something
to do with a caching pitfall, but everywhere across the TTM backend code I've tried to handle object creation and getting its pages with the same set of caching and coherency properties as in the old shmem backend.Quoted 5 lines
Some thoughts in case it's helpful:
- We still look to be trampling the
cache_leveletc after object creation. AFAICTi915_ttm_adjust_gem_after_movecan be called in various places after creation.
Quoted 6 lines
I traced this function so that I could see everywhere it was being called when running some IGT tests and kmscube, and the only place it was setting a caching coherence value other than none was in
init_status_page, whereI915_CACHE_LLCis picked as the cache coherency mode even for machines that do not have it. However this code was already present before my changes and didn't seem to cause any issues, so I don't think it's involved.
Yeah, I guess it's a different issue, but we still need to somehow ensure we never trample the cache_level etc on integrated platforms after object creation. On non-LLC platforms(not discrete) it's normal to set CACHE_LLC for certain types of buffers. And even on LLC platforms it's normal to set CACHE_NONE, like for display buffers, since the display engine is not coherent.
For reference we can have something like:
bb = gem_create() <-- assume non-llc so must be CACHE_NONE gem_set_caching(bb, CACHED) <-- should now be CACHE_LLC/L3 ptr = mmap_wb(bb); *ptr = BATCH_BUFFER_END <-- gem_after_move() resets to CACHE_NONE
execbuf(bb) <-- doesn't see the BATCH_BUFFER_END
Quoted 52 lines
Quoted 14 lines
- The
i915_ttm_pwritehook won't play nice on non-llc platforms, since it doesn't force a clflush or keep track of the writes withcache_dirty. The existing ->shmem_pwrite hook only works because we are guaranteed to have not yet populated the mm.pages, and on non-llc platforms we always force a clflush in__set_pages(). Ini915_ttm_pwritewe are now just callingpin_pages()and then writing through the page-cache without forcing a clflush, or ensuring that we leavecache_dirtyset. Also AFAIK the whole point ofshmem_pwritewas to avoid needing to populate the entire object like when callingpin_pages(). Would it make sense to just fallback to usingi915_gem_shmem_pwrite, which should already take care of the required flushing?Quoted 5 lines
For reference a common usage pattern is something like:
bb =
gem_create()<-- assume non-llc so must beCACHE_NONEgem_write(bb, BATCH_BUFFER_END)<-- might use cached pwrite internally execbuf(bb) <-- doesn't seeBATCH_BUFFER_ENDif we don't clflushIt turns out this was the underlying issue causing machines GEN <= 5 to break in pretty much every single test. It seems that for older hardware, IGT tests would pick pwrite as the preferred method for filling BO's from UM, so my code wasn't calling clfush after getting the pages and writing the UM pointer data into the shmem file.
The way I fixed it was creating an shmem file for this and other cases when it's required by the existing code, but without getting the pages. In a way, I just cut through the usual TTM populate path and instance an shmem object so that I can avoid caching issues.
Thanks a lot for catching this one!
Quoted 18 lines
Quoted 18 lines
Adrian Larumbe (1):
drm/i915: Replace shmem memory region and object backend with TTMdrivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 12 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 32 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 390 +------------------ drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 267 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_ttm.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 9 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 64 ++- drivers/gpu/drm/i915/intel_memory_region.c | 7 +- 10 files changed, 398 insertions(+), 422 deletions(-)--
2.35.1