Support for creating/using Stolen memory backed objects
Subsystems (4)
v16 cover Support for creating/using Stolen memory backed objects
From: Ankitprasad Sharma <[email protected]>
This patch series adds support for creating/using Stolen memory backed objects.
Despite being a unified memory architecture (UMA) some bits of memory are more equal than others. In particular we have the thorny issue of stolen memory, memory stolen from the system by the BIOS and reserved for igfx use. Stolen memory is required for some functions of the GPU and display engine, but in general it goes wasted. Whilst we cannot return it back to the system, we need to find some other method for utilising it. As we do not support direct access to the physical address in the stolen region, it behaves like a different class of memory, closer in kin to local GPU memory. This strongly suggests that we need a placement model like TTM if we are to fully utilize these discrete chunks of differing memory.
To add support for creating Stolen memory backed objects, we extend the drm_i915_gem_create structure, by adding a new flag through which user can specify the preference to allocate the object from stolen memory, which if set, an attempt will be made to allocate the object from stolen memory subject to the availability of free space in the stolen region.
This patch series adds support for clearing buffer objects via CPU/GTT. This is particularly useful for clearing out the memory from stolen region, but can also be used for other shmem allocated objects. Currently being used for buffers allocated in the stolen region. Also adding support for stealing purgable stolen pages, if we run out of stolen memory when trying to allocate an object.
v2: Added support for read/write from/to objects not backed by shmem using the pread/pwrite interface.
Also extended the current get_aperture ioctl to retrieve the total and available size of the stolen region.
v3: Removed the extended get_aperture ioctl patch 5 (to be submitted as part of other patch series), addressed comments by Chris about pread/pwrite for non shmem backed objects.
v4: Rebased to the latest drm-intel-nightly.
v5: Addressed comments, replaced patch 1/4 "Clearing buffers via blitter engine" by "Clearing buffers via CPU/GTT".
v6: Rebased to the latest drm-intel-nightly, Addressed comments, updated stolen memory purging logic by maintaining a list for purgable stolen memory objects, enabled pread/pwrite for all non-shmem backed objects without tiling restrictions.
v7: Addressed comments, compiler optimization, new patch added for correct error code propagation to the userspace.
v8: Added a new patch to the series to Migrate stolen objects before hibernation, as stolen memory is not preserved across hibernation. Added correct error propagation for shmem as well non-shmem backed object allocation.
v9: Addressed comments, use of insert_page helper function to map object page by page which can be helpful in low aperture space availability.
v10: Addressed comments, use insert_page for clearing out the stolen memory
v11: Addressed comments, 3 new patches added to support allocation from Stolen memory
1. Allow use of i915_gem_object_get_dma_address for stolen backed objects
2. Use insert_page for pwrite_fast
3. Fail the execbuff using stolen objects as batchbuffers
v12: Addressed comments, Removed patch "Fail the execbuff using stolen objects as batchbuffers"
v13: Addressed comments, Added 2 patches to detect Intel RST and disable stolen for persistent data if RST device found
1. acpi: Export acpi_bus_type
2. drm/i915: Disable use of stolen area by User when Intel RST is present
v14: Addressed comments, Added 2 base patches to the series
1. drm/i915: Add support for mapping an object page by page
2. drm/i915: Introduce i915_gem_object_get_dma_address()
v15: Addressed comments, Disabled stolen memory by default
v16: Addressed comments, Added low level rpm assertions, Enabled stolen memory
This can be verified using IGT tests: igt/gem_stolen, igt/gem_create
Ankitprasad Sharma (6):
drm/i915: Use insert_page for pwrite_fast
drm/i915: Clearing buffer objects via CPU/GTT
drm/i915: Support for creating Stolen memory backed objects drm/i915: Propagating correct error codes to the userspace drm/i915: Support for pread/pwrite from/to non shmem backed objects drm/i915: Disable use of stolen area by User when Intel RST is present
Chris Wilson (4):
drm/i915: Add support for mapping an object page by page drm/i915: Introduce i915_gem_object_get_dma_address() drm/i915: Add support for stealing purgable stolen pages drm/i915: Migrate stolen objects before hibernation
drivers/char/agp/intel-gtt.c | 9 + drivers/gpu/drm/i915/i915_debugfs.c | 6 +- drivers/gpu/drm/i915/i915_dma.c | 3 + drivers/gpu/drm/i915/i915_drv.c | 17 +- drivers/gpu/drm/i915/i915_drv.h | 58 ++- drivers/gpu/drm/i915/i915_gem.c | 621 ++++++++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_batch_pool.c | 4 +- drivers/gpu/drm/i915/i915_gem_context.c | 4 +- drivers/gpu/drm/i915/i915_gem_gtt.c | 65 +++ drivers/gpu/drm/i915/i915_gem_gtt.h | 5 + drivers/gpu/drm/i915/i915_gem_render_state.c | 7 +- drivers/gpu/drm/i915/i915_gem_stolen.c | 281 ++++++++++-- drivers/gpu/drm/i915/i915_guc_submission.c | 52 ++- drivers/gpu/drm/i915/intel_acpi.c | 10 + drivers/gpu/drm/i915/intel_display.c | 5 +- drivers/gpu/drm/i915/intel_fbdev.c | 12 +- drivers/gpu/drm/i915/intel_lrc.c | 10 +- drivers/gpu/drm/i915/intel_overlay.c | 4 +- drivers/gpu/drm/i915/intel_pm.c | 13 +- drivers/gpu/drm/i915/intel_ringbuffer.c | 27 +- include/drm/intel-gtt.h | 3 + include/uapi/drm/i915_drm.h | 41 ++ 22 files changed, 1091 insertions(+), 166 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 1/10 drm/i915: Add support for mapping an object page by page
From: Chris Wilson <[email protected]>
Introduced a new vm specfic callback insert_page() to program a single pte in ggtt or ppgtt. This allows us to map a single page in to the mappable aperture space. This can be iterated over to access the whole object by using space as meagre as page size.
v2: Added low level rpm assertions to insert_page routines (Chris)
--- drivers/char/agp/intel-gtt.c | 9 +++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 65 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 5 +++ include/drm/intel-gtt.h | 3 ++ 4 files changed, 82 insertions(+)
drivers/char/agp/intel-gtt.c +9 -0
@@ -838,6 +838,15 @@ static bool i830_check_flags(unsigned int flags)return false; } +void intel_gtt_insert_page (dma_addr_t addr, +unsigned int pg, +unsigned int flags) +{ + intel_private.driver->write_entry (addr, pg, flags); +wmb (); +} +EXPORT_SYMBOL (intel_gtt_insert_page); +void intel_gtt_insert_sg_entries (struct sg_table *st,unsigned int pg_start,unsigned int flags)
drivers/gpu/drm/i915/i915_gem_gtt.c +65 -0
101 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_gtt.h +5 -0
@@ -316,6 +316,11 @@ struct i915_address_space {uint64_t start, uint64_t length, bool use_scratch); +void (*insert_page)(struct i915_address_space *vm, +dma_addr_t addr, +uint64_t offset, +enum i915_cache_level cache_level, +u32 flags); void (*insert_entries)(struct i915_address_space *vm, struct sg_table *st, uint64_t start,
include/drm/intel-gtt.h +3 -0
@@ -13,6 +13,9 @@ void intel_gmch_remove(void);bool intel_enable_gtt (void );void intel_gtt_chipset_flush (void ); +void intel_gtt_insert_page (dma_addr_t addr, +unsigned int pg, +unsigned int flags);void intel_gtt_insert_sg_entries (struct sg_table *st,unsigned int pg_start,unsigned int flags);
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/10] drm/i915: Add support for mapping an object page by page
Quoted 52 lines · On 04/02/16 09:30, [email protected] wrote:
From: Chris Wilson <[email protected]>
Introduced a new vm specfic callback
insert_page()to program a single pte in ggtt or ppgtt. This allows us to map a single page in to the mappable aperture space. This can be iterated over to access the whole object by using space as meagre as page size.v2: Added low level rpm assertions to
insert_pageroutines (Chris)Signed-off-by Chris Wilson <[email protected]>Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/char/agp/intel-gtt.c | 9 +++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 65 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 5 +++ include/drm/intel-gtt.h | 3 ++ 4 files changed, 82 insertions(+)drivers/char/agp/intel-gtt.c +9
-0@@ -838,6 +838,15 @@ static bool i830_check_flags(unsigned int flags)return false; } +void intel_gtt_insert_page (dma_addr_t addr, +unsigned int pg, +unsigned int flags) +{ + intel_private.driver->write_entry (addr, pg, flags); +wmb (); +} +EXPORT_SYMBOL (intel_gtt_insert_page); +void intel_gtt_insert_sg_entries (struct sg_table *st,unsigned int pg_start,unsigned int flags)drivers/gpu/drm/i915/i915_gem_gtt.c +6
-0@@ -2341,6 +2341,28 @@ static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte)#endif } +static void gen8_ggtt_insert_page (struct i915_address_space *vm, +dma_addr_t addr, +uint64_t offset, +enum i915_cache_level level, +u32 unused) +{
drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) · line 2359
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +10
-0+struct drm_i915_private *dev_priv =to_i915 (vm->dev); +gen8_pte_t __iomem *pte = + (gen8_pte_t __iomem *)dev_priv->gtt.gsm + + (offset >>PAGE_SHIFT ); +int rpm_atomic_seq; + + rpm_atomic_seq =assert_rpm_atomic_begin (dev_priv); + +gen8_set_pte (pte,gen8_pte_encode (addr, level, true)); +wmb ();
gen8_ggtt_insert_entries does a read-back of the PTE after having written it with a big fat comment talking about how that could be really important. This is not needed in this path?
drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) · line 2361
Quoted 2 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +2
-0+ +I915_WRITE (GFX_FLSH_CNTL_GEN6 ,GFX_FLSH_CNTL_EN );
Why is the posting read not required here as in gen8_ggtt_insert_entries?
Quoted 22 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +15
-0+ +assert_rpm_atomic_end (dev_priv, rpm_atomic_seq); +} + static void gen8_ggtt_insert_entries(struct i915_address_space *vm, struct sg_table *st, uint64_t start,@@ -2412,6 +2434,28 @@ static void gen8_ggtt_insert_entries__BKL(struct i915_address_space *vm,stop_machine (gen8_ggtt_insert_entries__cb, &arg,NULL ); } +static void gen6_ggtt_insert_page (struct i915_address_space *vm, +dma_addr_t addr, +uint64_t offset, +enum i915_cache_level level, +u32 flags) +{ +struct drm_i915_private *dev_priv =to_i915 (vm->dev); +gen6_pte_t __iomem *pte = + (gen6_pte_t __iomem *)dev_priv->gtt.gsm + + (offset >>PAGE_SHIFT ); +int rpm_atomic_seq;
drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_ggtt_insert_entries__BKL(struct i915_address_space *vm, · line 2457
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +10
-0+ + rpm_atomic_seq =assert_rpm_atomic_begin (dev_priv); + +iowrite32 (vm->pte_encode (addr, level, true, flags), pte); +wmb (); + +I915_WRITE (GFX_FLSH_CNTL_GEN6 ,GFX_FLSH_CNTL_EN ); + +assert_rpm_atomic_end (dev_priv, rpm_atomic_seq); +}
Same questions as for the gen8 version.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 01/10] drm/i915: Add support for mapping an object page by page
Hi,
Quoted 60 lines · Tvrtko Ursulin
Quoted 58 lines · On 04/02/16 09:30, [email protected] wrote:
From: Chris Wilson <[email protected]>
Introduced a new vm specfic callback
insert_page()to program a single pte in ggtt or ppgtt. This allows us to map a single page in to the mappable aperture space. This can be iterated over to access the whole object by using space as meagre as page size.v2: Added low level rpm assertions to
insert_pageroutines (Chris)Signed-off-by Chris Wilson <[email protected]>Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/char/agp/intel-gtt.c | 9 +++++ drivers/gpu/drm/i915/i915_gem_gtt.c | 65 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 5 +++ include/drm/intel-gtt.h | 3 ++ 4 files changed, 82 insertions(+)drivers/char/agp/intel-gtt.c +9
-0@@ -838,6 +838,15 @@ static bool i830_check_flags(unsigned int flags)return false; } +void intel_gtt_insert_page (dma_addr_t addr, +unsigned int pg, +unsigned int flags) +{ + intel_private.driver->write_entry (addr, pg, flags); +wmb (); +} +EXPORT_SYMBOL (intel_gtt_insert_page); +void intel_gtt_insert_sg_entries (struct sg_table *st,unsigned int pg_start,unsigned int flags)drivers/gpu/drm/i915/i915_gem_gtt.c +12
-0@@ -2341,6 +2341,28 @@ static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte)#endif } +static void gen8_ggtt_insert_page (struct i915_address_space *vm, +dma_addr_t addr, +uint64_t offset, +enum i915_cache_level level, +u32 unused) +{ +struct drm_i915_private *dev_priv =to_i915 (vm->dev); +gen8_pte_t __iomem *pte = + (gen8_pte_t __iomem *)dev_priv->gtt.gsm + + (offset >>PAGE_SHIFT ); +int rpm_atomic_seq; +
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) · line 2359
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +4
-0+ rpm_atomic_seq =assert_rpm_atomic_begin (dev_priv); + +gen8_set_pte (pte,gen8_pte_encode (addr, level, true)); +wmb ();
gen8_ggtt_insert_entriesdoes a read-back of the PTE after having written it with a big fat comment talking about how that could be really important. This is not needed in this path?
As per our discussion with Chris, wmb() is faster than doing a memory access for reading the PTE.
So, I guess a barrier here should be better to keep things in sync.
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) · line 2361
Quoted 3 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +2
-0+ +I915_WRITE (GFX_FLSH_CNTL_GEN6 ,GFX_FLSH_CNTL_EN );Why is the posting read not required here as in
gen8_ggtt_insert_entries?
I agree with this, a POSTING_READ is required.
Quoted 36 lines
Quoted 23 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +15
-0+ +assert_rpm_atomic_end (dev_priv, rpm_atomic_seq); +} + static void gen8_ggtt_insert_entries(struct i915_address_space *vm, struct sg_table *st, uint64_t start,@@ -2412,6 +2434,28 @@ static void gen8_ggtt_insert_entries__BKL(struct i915_address_space *vm,stop_machine (gen8_ggtt_insert_entries__cb, &arg,NULL ); } +static void gen6_ggtt_insert_page (struct i915_address_space *vm, +dma_addr_t addr, +uint64_t offset, +enum i915_cache_level level, +u32 flags) +{ +struct drm_i915_private *dev_priv =to_i915 (vm->dev); +gen6_pte_t __iomem *pte = + (gen6_pte_t __iomem *)dev_priv->gtt.gsm + + (offset >>PAGE_SHIFT ); +int rpm_atomic_seq;drivers/gpu/drm/i915/i915_gem_gtt.c static void gen8_ggtt_insert_entries__BKL(struct i915_address_space *vm, · line 2457
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_gtt.c +10
-0+ + rpm_atomic_seq =assert_rpm_atomic_begin (dev_priv); + +iowrite32 (vm->pte_encode (addr, level, true, flags), pte); +wmb (); + +I915_WRITE (GFX_FLSH_CNTL_GEN6 ,GFX_FLSH_CNTL_EN ); + +assert_rpm_atomic_end (dev_priv, rpm_atomic_seq); +}Same questions as for the gen8 version.
Quoted 3 lines
Regards,
Tvrtko
Thanks,
Ankit
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 2/10 drm/i915: Introduce i915_gem_object_get_dma_address()
In reply to [email protected]From: Chris Wilson <[email protected]>
This utility function is a companion to i915_gem_object_get_page() that uses the same cached iterator for the scatterlist to perform fast sequential lookup of the dma address associated with any page within the object.
--- drivers/gpu/drm/i915/i915_drv.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +17 -0
@@ -2947,6 +2947,23 @@ static inline int __sg_page_count(struct scatterlist *sg)struct page *i915_gem_object_get_dirty_page (struct drm_i915_gem_object *obj,int n); +static inline dma_addr_t +i915_gem_object_get_dma_address (struct drm_i915_gem_object *obj,int n) +{ +if (n < obj->get_page.last) { + obj->get_page.sg = obj->pages->sgl; + obj->get_page.last =0 ; + } + +while (obj->get_page.last +__sg_page_count (obj->get_page.sg) <= n) { + obj->get_page.last +=__sg_page_count (obj->get_page.sg++); +if (unlikely (sg_is_chain (obj->get_page.sg))) + obj->get_page.sg =sg_chain_ptr (obj->get_page.sg); + } + +return sg_dma_address (obj->get_page.sg) + ((n - obj->get_page.last) <<PAGE_SHIFT ); +} +static inline struct page *i915_gem_object_get_page (struct drm_i915_gem_object *obj,int n) {
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 02/10] drm/i915: Introduce i915_gem_object_get_dma_address()
Quoted 32 lines · On 04/02/16 09:30, [email protected] wrote:
From: Chris Wilson <[email protected]>
This utility function is a companion to
i915_gem_object_get_page()that uses the same cached iterator for the scatterlist to perform fast sequential lookup of the dma address associated with any page within the object.Signed-off-by Chris Wilson <[email protected]>Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/gpu/drm/i915/i915_drv.h +10
-0@@ -2947,6 +2947,23 @@ static inline int __sg_page_count(struct scatterlist *sg)struct page *i915_gem_object_get_dirty_page (struct drm_i915_gem_object *obj,int n); +static inline dma_addr_t +i915_gem_object_get_dma_address (struct drm_i915_gem_object *obj,int n) +{ +if (n < obj->get_page.last) { + obj->get_page.sg = obj->pages->sgl; + obj->get_page.last =0 ; + } + +while (obj->get_page.last +__sg_page_count (obj->get_page.sg) <= n) { + obj->get_page.last +=__sg_page_count (obj->get_page.sg++);
drivers/gpu/drm/i915/i915_drv.h static inline int __sg_page_count(struct scatterlist *sg) · line 2969
Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +7
-0+if (unlikely (sg_is_chain (obj->get_page.sg))) + obj->get_page.sg =sg_chain_ptr (obj->get_page.sg); + } + +return sg_dma_address (obj->get_page.sg) + ((n - obj->get_page.last) <<PAGE_SHIFT ); +} +static inline struct page *i915_gem_object_get_page (struct drm_i915_gem_object *obj,int n) {
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 3/10 drm/i915: Use insert_page for pwrite_fast
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
In pwrite_fast, map an object page by page if obj_ggtt_pin fails. First, we try a nonblocking pin for the whole object (since that is fastest if reused), then failing that we try to grab one page in the mappable aperture. It also allows us to handle objects larger than the mappable aperture (e.g. if we need to pwrite with vGPU restricting the aperture to a measely 8MiB or something like that).
v2: Pin pages before starting pwrite, Combined duplicate loops (Chris)
v3: Combined loops based on local patch by Chris (Chris)
v4: Added i915 wrapper function for drm_mm_insert_node_in_range (Chris)
v5: Renamed wrapper function for drm_mm_insert_node_in_range (Chris)
v5: Added wrapper for drm_mm_remove_node() (Chris)
v6: Added get_pages call before pinning the pages (Tvrtko) Added remove_mappable_node() wrapper for drm_mm_remove_node() (Chris)
v7: Added size argument for insert_mappable_node (Tvrtko)
v8: Do not put_pages after pwrite, do memset of node in the wrapper function (insert_mappable_node) (Chris)
--- drivers/gpu/drm/i915/i915_gem.c | 92 +++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 22 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +70 -22
@@ -61,6 +61,24 @@ static bool cpu_write_needs_clflush(struct drm_i915_gem_object *obj)return obj->pin_display; } +static int +insert_mappable_node (struct drm_i915_private *i915, +struct drm_mm_node *node,u32 size) +{ +memset (node,0 ,sizeof (*node)); +return drm_mm_insert_node_in_range_generic (&i915->gtt.base.mm, node, + size,0 ,0 ,0 , + i915->gtt.mappable_end, +DRM_MM_SEARCH_DEFAULT , +DRM_MM_CREATE_DEFAULT ); +} + +static void +remove_mappable_node (struct drm_mm_node *node) +{ +drm_mm_remove_node (node); +} +/* some bookkeeping */ static void i915_gem_info_add_obj (struct drm_i915_private *dev_priv,size_t size)
@@ -760,20 +778,33 @@ fast_user_write(struct io_mapping *mapping,* user into the GTT, uncached. */ static int -i915_gem_gtt_pwrite_fast (struct drm_device *dev, +i915_gem_gtt_pwrite_fast (struct drm_i915_private *i915,struct drm_i915_gem_object *obj,struct drm_i915_gem_pwrite *args,struct drm_file *file) { -struct drm_i915_private *dev_priv = dev->dev_private; -ssize_t remain; -loff_t offset, page_base; +struct drm_mm_node node; +uint64_t remain, offset;char __user *user_data; -int page_offset, page_length, ret; +int ret; ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE |PIN_NONBLOCK ); -if (ret) - goto out; +if (ret) { + ret =insert_mappable_node (i915, &node,PAGE_SIZE ); +if (ret) + goto out; + + ret =i915_gem_object_get_pages (obj); +if (ret) { +remove_mappable_node (&node); + goto out; + } + +i915_gem_object_pin_pages (obj); + }else { + node.start =i915_gem_obj_ggtt_offset (obj); + node.allocated = false; + } ret =i915_gem_object_set_to_gtt_domain (obj, true);if (ret)
@@ -783,31 +814,39 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,if (ret) goto out_unpin; - user_data =to_user_ptr (args->data_ptr); - remain = args->size; - - offset =i915_gem_obj_ggtt_offset (obj) + args->offset; -intel_fb_obj_invalidate (obj,ORIGIN_GTT ); + obj->dirty = true; -while (remain >0 ) { + user_data =to_user_ptr (args->data_ptr); + offset = args->offset; + remain = args->size; +while (remain) {/* Operation in this page * * page_base = page offset within aperture * page_offset = offset within page * page_length = bytes to copy for this page */ - page_base = offset &PAGE_MASK ; - page_offset =offset_in_page (offset); - page_length = remain; -if ((page_offset + remain) >PAGE_SIZE ) - page_length =PAGE_SIZE - page_offset; - +u32 page_base = node.start; +unsigned page_offset =offset_in_page (offset); +unsigned page_length =PAGE_SIZE - page_offset; + page_length = remain < page_length ? remain : page_length; +if (node.allocated) { +wmb (); + i915->gtt.base.insert_page (&i915->gtt.base, +i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), + node.start, +I915_CACHE_NONE , +0 ); +wmb (); + }else { + page_base += offset &PAGE_MASK ; + }/* If we get a fault while copying data, then (presumably) our * source page isn't available. Return the error and we'll * retry in the slow path. */ -if (fast_user_write (dev_priv->gtt.mappable, page_base, +if (fast_user_write (i915->gtt.mappable, page_base, page_offset, user_data, page_length)) { ret = -EFAULT ; goto out_flush;
@@ -821,7 +860,16 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev, out_flush:intel_fb_obj_flush (obj, false,ORIGIN_GTT ); out_unpin: -i915_gem_object_ggtt_unpin (obj); +if (node.allocated) { +wmb (); + i915->gtt.base.clear_range (&i915->gtt.base, + node.start, node.size, + true); +i915_gem_object_unpin_pages (obj); +remove_mappable_node (&node); + }else { +i915_gem_object_ggtt_unpin (obj); + } out:return ret; }
@@ -1086,7 +1134,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,if (obj->tiling_mode ==I915_TILING_NONE && obj->base.write_domain !=I915_GEM_DOMAIN_CPU &&cpu_write_needs_clflush (obj)) { - ret =i915_gem_gtt_pwrite_fast (dev, obj, args, file); + ret =i915_gem_gtt_pwrite_fast (dev_priv, obj, args, file);/* Note that the gtt paths might fail with non-page-backed user * pointers (e.g. gtt mappings when moving data between * textures). Fallback to the shmem path in that case. */
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
kbuild test robot
build botRe: [PATCH 03/10] drm/i915: Use insert_page for pwrite_fast
All warnings (new ones prefixed by >>):
Hi Ankitprasad,
[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on v4.5-rc2 next-20160204]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/ankitprasad-r-sharma-intel-com/Support-for-creating-using-Stolen-memory-backed-objects/20160204-175614 base: git://anongit.freedesktop.org/drm-intel for-linux-next reproduce: make htmldocs
All warnings (new ones prefixed by >>):
include/drm/drm_crtc.h:1533: warning: No description found for parameter 'mutex' include/drm/drm_crtc.h:1533: warning: No description found for parameter 'helper_private' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tile_idr' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'delayed_event' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'edid_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'dpms_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'path_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tile_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'plane_type_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'rotation_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_src_x' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_src_y' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_src_w' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_src_h' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_crtc_x' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_crtc_y' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_crtc_w' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_crtc_h' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_fb_id' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_crtc_id' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_active' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'prop_mode_id' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'dvi_i_subconnector_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'dvi_i_select_subconnector_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_subconnector_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_select_subconnector_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_mode_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_left_margin_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_right_margin_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_top_margin_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_bottom_margin_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_brightness_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_contrast_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_flicker_reduction_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_overscan_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_saturation_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'tv_hue_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'scaling_mode_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'aspect_ratio_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'dirty_info_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'suggested_x_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'suggested_y_property' include/drm/drm_crtc.h:2142: warning: No description found for parameter 'allow_fb_modifiers' include/drm/drm_dp_helper.h:749: warning: No description found for parameter 'i2c_nack_count' include/drm/drm_dp_helper.h:749: warning: No description found for parameter 'i2c_defer_count' drivers/gpu/drm/drm_dp_mst_topology.c:2305: warning: No description found for parameter 'connector' include/drm/drm_dp_mst_helper.h:98: warning: No description found for parameter 'cached_edid' include/drm/drm_dp_mst_helper.h:98: warning: No description found for parameter 'has_audio' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'max_dpcd_transaction_bytes' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'sink_count' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'total_slots' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'avail_slots' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'total_pbn' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'qlock' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'tx_msg_downq' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'tx_down_in_progress' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'payload_lock' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'proposed_vcpis' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'payloads' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'payload_mask' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'vcpi_mask' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'tx_waitq' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'work' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'tx_work' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'destroy_connector_list' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'destroy_connector_lock' include/drm/drm_dp_mst_helper.h:471: warning: No description found for parameter 'destroy_connector_work' drivers/gpu/drm/drm_dp_mst_topology.c:2305: warning: No description found for parameter 'connector' drivers/gpu/drm/drm_irq.c:176: warning: No description found for parameter 'flags' include/drm/drmP.h:168: warning: No description found for parameter 'fmt' include/drm/drmP.h:184: warning: No description found for parameter 'fmt' include/drm/drmP.h:202: warning: No description found for parameter 'fmt' include/drm/drmP.h:247: warning: No description found for parameter 'dev' include/drm/drmP.h:247: warning: No description found for parameter 'data' include/drm/drmP.h:247: warning: No description found for parameter 'file_priv' include/drm/drmP.h:280: warning: No description found for parameter 'ioctl' include/drm/drmP.h:280: warning: No description found for parameter '_func' include/drm/drmP.h:280: warning: No description found for parameter '_flags' include/drm/drmP.h:360: warning: cannot understand function prototype: 'struct drm_lock_data ' include/drm/drmP.h:413: warning: cannot understand function prototype: 'struct drm_driver ' include/drm/drmP.h:670: warning: cannot understand function prototype: 'struct drm_info_list ' include/drm/drmP.h:680: warning: cannot understand function prototype: 'struct drm_info_node ' include/drm/drmP.h:690: warning: cannot understand function prototype: 'struct drm_minor ' include/drm/drmP.h:738: warning: cannot understand function prototype: 'struct drm_device ' drivers/gpu/drm/i915/intel_runtime_pm.c:2173: warning: No description found for parameter 'resume' drivers/gpu/drm/i915/intel_runtime_pm.c:2173: warning: No description found for parameter 'resume' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'wedged' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'fmt' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'wedged' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'fmt' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'wedged' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'fmt' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'wedged' drivers/gpu/drm/i915/i915_irq.c:2659: warning: No description found for parameter 'fmt' drivers/gpu/drm/i915/i915_gem.c:439: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:439: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:439: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:704: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:704: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:704: warning: No description found for parameter 'file'
>> drivers/gpu/drm/i915/i915_gem.c:785: warning: No description found for parameter 'i915'
drivers/gpu/drm/i915/i915_gem.c:785: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:785: warning: No description found for parameter 'args' drivers/gpu/drm/i915/i915_gem.c:785: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:1077: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:1077: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:1077: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:1293: warning: No description found for parameter 'rps' drivers/gpu/drm/i915/i915_gem.c:1509: warning: No description found for parameter 'req' drivers/gpu/drm/i915/i915_gem.c:1544: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:1544: warning: No description found for parameter 'readonly' drivers/gpu/drm/i915/i915_gem.c:1667: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:1667: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:1667: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:1730: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:1730: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:1730: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:1775: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:1775: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:1775: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:2063: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:2063: warning: No description found for parameter 'size' drivers/gpu/drm/i915/i915_gem.c:2063: warning: No description found for parameter 'tiling_mode' drivers/gpu/drm/i915/i915_gem.c:2063: warning: No description found for parameter 'fenced' drivers/gpu/drm/i915/i915_gem.c:2063: warning: Excess function parameter 'obj' description in 'i915_gem_get_gtt_alignment' drivers/gpu/drm/i915/i915_gem.c:2962: warning: No description found for parameter 'ring' drivers/gpu/drm/i915/i915_gem.c:3095: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:3145: warning: No description found for parameter 'dev' drivers/gpu/drm/i915/i915_gem.c:3145: warning: No description found for parameter 'data' drivers/gpu/drm/i915/i915_gem.c:3145: warning: No description found for parameter 'file' drivers/gpu/drm/i915/i915_gem.c:3145: warning: Excess function parameter 'DRM_IOCTL_ARGS' description in 'i915_gem_wait_ioctl' drivers/gpu/drm/i915/i915_gem.c:3518: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:3518: warning: No description found for parameter 'vm' drivers/gpu/drm/i915/i915_gem.c:3518: warning: No description found for parameter 'ggtt_view' drivers/gpu/drm/i915/i915_gem.c:3518: warning: No description found for parameter 'alignment' drivers/gpu/drm/i915/i915_gem.c:3518: warning: No description found for parameter 'flags' drivers/gpu/drm/i915/i915_gem.c:3773: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:3773: warning: No description found for parameter 'write' drivers/gpu/drm/i915/i915_gem.c:3848: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:3848: warning: No description found for parameter 'cache_level' drivers/gpu/drm/i915/i915_gem.c:4122: warning: No description found for parameter 'obj' drivers/gpu/drm/i915/i915_gem.c:4122: warning: No description found for parameter 'write' drivers/gpu/drm/i915/intel_lrc.c:935: warning: No description found for parameter 'params' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'dev' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'file' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'ring' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'ctx' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'batch_obj' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'exec_start' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'dispatch_flags' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: No description found for parameter 'params' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'dev' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'file' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'ring' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'ctx' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'batch_obj' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'exec_start' description in 'intel_execlists_submission' drivers/gpu/drm/i915/intel_lrc.c:935: warning: Excess function parameter 'dispatch_flags' description in 'intel_execlists_submission'
Warning: didn't use docs for i915_hotplug_interrupt_update
Warning: didn't use docs for ilk_update_display_irq
Warning: didn't use docs for ilk_update_gt_irq
Warning: didn't use docs for snb_update_pm_irq
Warning: didn't use docs for bdw_update_port_irq
Warning: didn't use docs for bdw_update_pipe_irq
Warning: didn't use docs for ibx_display_interrupt_update
Warning: didn't use docs for i915_enable_asle_pipestat
Warning: didn't use docs for ivybridge_parity_work
Warning: didn't use docs for i915_reset_and_wakeup
Warning: didn't use docs for i915_handle_error
Warning: didn't use docs for intel_irq_install
Warning: didn't use docs for intel_irq_uninstall
vim +/i915 +785 drivers/gpu/drm/i915/i915_gem.c
4f0c7cfb Ben Widawsky 2012-04-16 769 vaddr = (void __force*)vaddr_atomic + page_offset;
4f0c7cfb Ben Widawsky 2012-04-16 770 unwritten = __copy_from_user_inatomic_nocache(vaddr,
0839ccb8 Keith Packard 2008-10-30 771 user_data, length);
3e4d3af5 Peter Zijlstra 2010-10-26 772 io_mapping_unmap_atomic(vaddr_atomic);
fbd5a26d Chris Wilson 2010-10-14 773 return unwritten;
0839ccb8 Keith Packard 2008-10-30 774 }
0839ccb8 Keith Packard 2008-10-30 775
3de09aa3 Eric Anholt 2009-03-09 776 /**
3de09aa3 Eric Anholt 2009-03-09 777 * This is the fast pwrite path, where we copy the data directly from the
3de09aa3 Eric Anholt 2009-03-09 778 * user into the GTT, uncached.
3de09aa3 Eric Anholt 2009-03-09 779 */
673a394b Eric Anholt 2008-07-30 780 static int
65858e3c Ankitprasad Sharma 2016-02-04 781 i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,
05394f39 Chris Wilson 2010-11-08 782 struct drm_i915_gem_object *obj,
673a394b Eric Anholt 2008-07-30 783 struct drm_i915_gem_pwrite *args,
05394f39 Chris Wilson 2010-11-08 784 struct drm_file *file)
673a394b Eric Anholt 2008-07-30 @785 {
65858e3c Ankitprasad Sharma 2016-02-04 786 struct drm_mm_node node;
65858e3c Ankitprasad Sharma 2016-02-04 787 uint64_t remain, offset;
673a394b Eric Anholt 2008-07-30 788 char __user *user_data;
65858e3c Ankitprasad Sharma 2016-02-04 789 int ret;
935aaa69 Daniel Vetter 2012-03-25 790
1ec9e26d Daniel Vetter 2014-02-14 791 ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_MAPPABLE | PIN_NONBLOCK);
65858e3c Ankitprasad Sharma 2016-02-04 792 if (ret) {
65858e3c Ankitprasad Sharma 2016-02-04 793 ret = insert_mappable_node(i915, &node, PAGE_SIZE);:::::: The code at line 785 was first introduced by commit
:::::: 673a394b1e3b69be886ff24abfd6df97c52e8d08 drm: Add GEM ("graphics execution manager") to i915 driver.
:::::: TO: Eric Anholt <[email protected]>
:::::: CC: Dave Airlie <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 4/10 drm/i915: Clearing buffer objects via CPU/GTT
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
This patch adds support for clearing buffer objects via CPU/GTT. This is particularly useful for clearing out the non shmem backed objects. Currently intend to use this only for buffers allocated from stolen region.
v2: Added kernel doc for i915_gem_clear_object(), corrected/removed variable assignments (Tvrtko)
v3: Map object page by page to the gtt if the pinning of the whole object to the ggtt fails, Corrected function name (Chris)
v4: Clear the buffer page by page, and not map the whole object in the gtt aperture. Use i915 wrapper function in place of drm_mm_insert_node_in_range.
v5: Use renamed wrapper function for drm_mm_insert_node_in_range, updated barrier positioning (Chris)
v6: Use PAGE_SIZE instead of 4096, use get_pages call before pinning pages (Tvrtko)
v7: Fixed the onion (undo operation in reverse order) (Chris)
Testcase: igt/gem_stolen
--- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -2938,6 +2938,7 @@ int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj, int *needs_clflush);int __must_check i915_gem_object_get_pages (struct drm_i915_gem_object *obj); +int i915_gem_object_clear (struct drm_i915_gem_object *obj);static inline int __sg_page_count (struct scatterlist *sg) {
drivers/gpu/drm/i915/i915_gem.c +47 -0
50 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 5/10 drm/i915: Support for creating Stolen memory backed objects
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
Extend the drm_i915_gem_create structure to add support for creating Stolen memory backed objects. Added a new flag through which user can specify the preference to allocate the object from stolen memory, which if set, an attempt will be made to allocate the object from stolen memory subject to the availability of free space in the stolen region.
v2: Rebased to the latest drm-intel-nightly (Ankit)
v3: Changed versioning of GEM_CREATE param, added new comments (Tvrtko)
v4: Changed size from 32b to 64b to prevent userspace overflow (Tvrtko) Corrected function arguments ordering (Chris)
v5: Corrected function name (Chris)
v6: Updated datatype for flags to keep sizeof(drm_i915_gem_create) u64 aligned (Chris)
v7: Use first 8 bits of gem_create flags for placement (Chris), Add helper function for object allocation from stolen region (Ankit)
v8: Added comment explaining STOLEN placement flag (Chris)
Testcase: igt/gem_stolen
--- drivers/gpu/drm/i915/i915_dma.c | 3 +++ drivers/gpu/drm/i915/i915_drv.h | 2 +- drivers/gpu/drm/i915/i915_gem.c | 45 +++++++++++++++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_stolen.c | 4 +-- include/uapi/drm/i915_drm.h | 41 +++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +3 -0
@@ -172,6 +172,9 @@ static int i915_getparam(struct drm_device *dev, void *data,case I915_PARAM_HAS_EXEC_SOFTPIN : value =1 ;break ; +case I915_PARAM_CREATE_VERSION : + value =2 ; +break ;default :DRM_DEBUG ("Unknown parameter %d\n" , param->param);return -EINVAL ;
drivers/gpu/drm/i915/i915_drv.h +1 -1
@@ -3301,7 +3301,7 @@ void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,int i915_gem_init_stolen (struct drm_device *dev);void i915_gem_cleanup_stolen (struct drm_device *dev);struct drm_i915_gem_object * -i915_gem_object_create_stolen (struct drm_device *dev,u32 size); +i915_gem_object_create_stolen (struct drm_device *dev,u64 size);struct drm_i915_gem_object * i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, u32 stolen_offset,
drivers/gpu/drm/i915/i915_gem.c +42 -3
74 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_stolen.c +2 -2
@@ -586,7 +586,7 @@ cleanup: }struct drm_i915_gem_object * -i915_gem_object_create_stolen (struct drm_device *dev,u32 size) +i915_gem_object_create_stolen (struct drm_device *dev,u64 size) {struct drm_i915_private *dev_priv = dev->dev_private;struct drm_i915_gem_object *obj;
@@ -596,7 +596,7 @@ i915_gem_object_create_stolen(struct drm_device *dev, u32 size)if (!drm_mm_initialized (&dev_priv->mm.stolen))return NULL ; -DRM_DEBUG_KMS ("creating stolen object: size=%x\n" , size); +DRM_DEBUG_KMS ("creating stolen object: size=%llx\n" , size);if (size ==0 )return NULL ;
include/uapi/drm/i915_drm.h +41 -0
53 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 6/10 drm/i915: Propagating correct error codes to the userspace
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
Propagating correct error codes to userspace by using ERR_PTR and PTR_ERR macros for stolen memory based object allocation. We generally return -ENOMEM to the user whenever there is a failure in object allocation. This patch helps user to identify the correct reason for the failure and not just -ENOMEM each time.
v2: Moved the patch up in the series, added error propagation for i915_gem_alloc_object too (Chris)
v3: Removed storing of error pointer inside structs, Corrected error propagation in caller functions (Chris)
v4: Remove assignments inside the predicate (Chris)
v5: Removed unnecessary initializations, updated kerneldoc for i915_guc_client, corrected missed error pointer handling (Tvrtko)
v6: Use ERR_CAST/temporary variable to avoid storing invalid pointer in a common field (Chris)
v7: Resolved rebasing conflicts (Ankit)
v8: Removed redundant code (Chris)
--- drivers/gpu/drm/i915/i915_gem.c | 23 ++++++------ drivers/gpu/drm/i915/i915_gem_batch_pool.c | 4 +-- drivers/gpu/drm/i915/i915_gem_context.c | 4 +-- drivers/gpu/drm/i915/i915_gem_render_state.c | 7 ++-- drivers/gpu/drm/i915/i915_gem_stolen.c | 53 +++++++++++++++------------- drivers/gpu/drm/i915/i915_guc_submission.c | 52 +++++++++++++++++---------- drivers/gpu/drm/i915/intel_display.c | 2 +- drivers/gpu/drm/i915/intel_fbdev.c | 6 ++-- drivers/gpu/drm/i915/intel_lrc.c | 10 +++--- drivers/gpu/drm/i915/intel_overlay.c | 4 +-- drivers/gpu/drm/i915/intel_pm.c | 7 ++-- drivers/gpu/drm/i915/intel_ringbuffer.c | 21 +++++------ 12 files changed, 110 insertions(+), 83 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +12 -11
@@ -397,19 +397,18 @@ i915_gem_alloc_object_stolen(struct drm_device *dev, size_t size)mutex_lock (&dev->struct_mutex); obj =i915_gem_object_create_stolen (dev, size); -if (!obj) { -mutex_unlock (&dev->struct_mutex); -return NULL ; - } +if (IS_ERR (obj)) + goto out;/* Always clear fresh buffers before handing to userspace */ ret =i915_gem_object_clear (obj);if (ret) {drm_gem_object_unreference (&obj->base); -mutex_unlock (&dev->struct_mutex); -return NULL ; + obj =ERR_PTR (ret); + goto out; } +out:mutex_unlock (&dev->struct_mutex);return obj; }
@@ -444,8 +443,8 @@ i915_gem_create(struct drm_file *file,return -EINVAL ; } -if (obj ==NULL ) -return -ENOMEM ; +if (IS_ERR (obj)) +return PTR_ERR (obj); ret =drm_gem_handle_create (file, &obj->base, &handle);/* drop reference from allocate - handle holds it now */
@@ -4562,14 +4561,16 @@ struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,struct drm_i915_gem_object *obj;struct address_space *mapping;gfp_t mask; +int ret; obj =i915_gem_object_alloc (dev);if (obj ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); -if (drm_gem_object_init (dev, &obj->base, size) !=0 ) { + ret =drm_gem_object_init (dev, &obj->base, size); +if (ret) {i915_gem_object_free (obj); -return NULL ; +return ERR_PTR (ret); } mask =GFP_HIGHUSER | __GFP_RECLAIMABLE;
drivers/gpu/drm/i915/i915_gem_batch_pool.c +2 -2
@@ -135,8 +135,8 @@ i915_gem_batch_pool_get(struct i915_gem_batch_pool *pool,int ret; obj =i915_gem_alloc_object (pool->dev, size); -if (obj ==NULL ) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (obj)) +return obj; ret =i915_gem_object_get_pages (obj);if (ret)
drivers/gpu/drm/i915/i915_gem_context.c +2 -2
@@ -179,8 +179,8 @@ i915_gem_alloc_context_obj(struct drm_device *dev, size_t size)int ret; obj =i915_gem_alloc_object (dev, size); -if (obj ==NULL ) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (obj)) +return obj;/* * Try to make the context utilize L3 as well as LLC.
drivers/gpu/drm/i915/i915_gem_render_state.c +5 -2
@@ -58,8 +58,11 @@ static int render_state_init(struct render_state *so, struct drm_device *dev)return -EINVAL ; so->obj =i915_gem_alloc_object (dev,4096 ); -if (so->obj ==NULL ) -return -ENOMEM ; +if (IS_ERR (so->obj)) { + ret =PTR_ERR (so->obj); + so->obj =NULL ; +return ret; + } ret =i915_gem_obj_ggtt_pin (so->obj,4096 ,0 );if (ret)
drivers/gpu/drm/i915/i915_gem_stolen.c +28 -25
140 lines not on this page · raw message
drivers/gpu/drm/i915/i915_guc_submission.c +33 -19
143 lines not on this page · raw message
drivers/gpu/drm/i915/intel_display.c +1 -1
@@ -2555,7 +2555,7 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc, base_aligned, base_aligned, size_aligned); -if (!obj) +if (IS_ERR (obj))return false; obj->tiling_mode = plane_config->tiling;
drivers/gpu/drm/i915/intel_fbdev.c +3 -3
@@ -148,11 +148,11 @@ static int intelfb_alloc(struct drm_fb_helper *helper,* features. */ if (size *2 < dev_priv->gtt.stolen_usable_size) obj =i915_gem_object_create_stolen (dev, size); -if (obj ==NULL ) +if (IS_ERR_OR_NULL (obj)) obj =i915_gem_alloc_object (dev, size); -if (!obj) { +if (IS_ERR (obj)) {DRM_ERROR ("failed to allocate framebuffer\n" ); - ret = -ENOMEM ; + ret =PTR_ERR (obj); goto out; }
drivers/gpu/drm/i915/intel_lrc.c +6 -4
@@ -1453,9 +1453,11 @@ static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *ring, u32 size)int ret; ring->wa_ctx.obj =i915_gem_alloc_object (ring->dev,PAGE_ALIGN (size)); -if (!ring->wa_ctx.obj) { +if (IS_ERR (ring->wa_ctx.obj)) {DRM_DEBUG_DRIVER ("alloc LRC WA ctx backing obj failed.\n" ); -return -ENOMEM ; + ret =PTR_ERR (ring->wa_ctx.obj); + ring->wa_ctx.obj =NULL ; +return ret; } ret =i915_gem_obj_ggtt_pin (ring->wa_ctx.obj,PAGE_SIZE ,0 );
@@ -2556,9 +2558,9 @@ int intel_lr_context_deferred_alloc(struct intel_context *ctx, context_size +=PAGE_SIZE *LRC_PPHWSP_PN ; ctx_obj =i915_gem_alloc_object (dev, context_size); -if (!ctx_obj) { +if (IS_ERR (ctx_obj)) {DRM_DEBUG_DRIVER ("Alloc LRC backing obj failed.\n" ); -return -ENOMEM ; +return PTR_ERR (ctx_obj); } ringbuf =intel_engine_create_ringbuffer (ring,4 *PAGE_SIZE );
drivers/gpu/drm/i915/intel_overlay.c +2 -2
@@ -1392,9 +1392,9 @@ void intel_setup_overlay(struct drm_device *dev) reg_bo =NULL ;if (!OVERLAY_NEEDS_PHYSICAL (dev)) reg_bo =i915_gem_object_create_stolen (dev,PAGE_SIZE ); -if (reg_bo ==NULL ) +if (IS_ERR_OR_NULL (reg_bo)) reg_bo =i915_gem_alloc_object (dev,PAGE_SIZE ); -if (reg_bo ==NULL ) +if (IS_ERR (reg_bo)) goto out_free; overlay->reg_bo = reg_bo;
drivers/gpu/drm/i915/intel_pm.c +5 -2
@@ -5210,10 +5210,13 @@ static void valleyview_setup_pctx(struct drm_device *dev) pcbr_offset,I915_GTT_OFFSET_NONE , pctx_size); +if (IS_ERR (pctx)) + pctx =NULL ; + goto out; } -DRM_DEBUG_DRIVER ("BIOS didn't set up PCBR, fixing up\n" ); +DRM_DEBUG_DRIVER ("BIOS didn't set up PCBR or prealloc failed, fixing up\n" );/* * From the Gunit register HAS:
@@ -5224,7 +5227,7 @@ static void valleyview_setup_pctx(struct drm_device *dev)* memory, or any other relevant ranges. */ pctx =i915_gem_object_create_stolen (dev, pctx_size); -if (!pctx) { +if (IS_ERR (pctx)) {DRM_DEBUG ("not enough stolen space for PCTX, disabling\n" );return ; }
drivers/gpu/drm/i915/intel_ringbuffer.c +11 -10
@@ -664,9 +664,10 @@ intel_init_pipe_control(struct intel_engine_cs *ring)WARN_ON (ring->scratch.obj); ring->scratch.obj =i915_gem_alloc_object (ring->dev,4096 ); -if (ring->scratch.obj ==NULL ) { +if (IS_ERR (ring->scratch.obj)) {DRM_ERROR ("Failed to allocate seqno page\n" ); - ret = -ENOMEM ; + ret =PTR_ERR (ring->scratch.obj); + ring->scratch.obj =NULL ; goto err; }
@@ -1994,9 +1995,9 @@ static int init_status_page(struct intel_engine_cs *ring)int ret; obj =i915_gem_alloc_object (ring->dev,4096 ); -if (obj ==NULL ) { +if (IS_ERR (obj)) {DRM_ERROR ("Failed to allocate status page\n" ); -return -ENOMEM ; +return PTR_ERR (obj); } ret =i915_gem_object_set_cache_level (obj,I915_CACHE_LLC );
@@ -2146,10 +2147,10 @@ static int intel_alloc_ringbuffer_obj(struct drm_device *dev, obj =NULL ;if (!HAS_LLC (dev)) obj =i915_gem_object_create_stolen (dev, ringbuf->size); -if (obj ==NULL ) +if (IS_ERR_OR_NULL (obj)) obj =i915_gem_alloc_object (dev, ringbuf->size); -if (obj ==NULL ) -return -ENOMEM ; +if (IS_ERR (obj)) +return PTR_ERR (obj);/* mark ring buffers as read-only from GPU side by default */ obj->gt_ro =1 ;
@@ -2750,7 +2751,7 @@ int intel_init_render_ring_buffer(struct drm_device *dev)if (INTEL_INFO (dev)->gen >=8 ) {if (i915_semaphore_is_enabled (dev)) { obj =i915_gem_alloc_object (dev,4096 ); -if (obj ==NULL ) { +if (IS_ERR (obj)) {DRM_ERROR ("Failed to allocate semaphore bo. Disabling semaphores\n" ); i915.semaphores =0 ; }else {
@@ -2857,9 +2858,9 @@ int intel_init_render_ring_buffer(struct drm_device *dev)/* Workaround batchbuffer to combat CS tlb bug. */ if (HAS_BROKEN_CS_TLB (dev)) { obj =i915_gem_alloc_object (dev,I830_WA_SIZE ); -if (obj ==NULL ) { +if (IS_ERR (obj)) {DRM_ERROR ("Failed to allocate batch bo\n" ); -return -ENOMEM ; +return PTR_ERR (obj); } ret =i915_gem_obj_ggtt_pin (obj,0 ,0 );
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 7/10 drm/i915: Add support for stealing purgable stolen pages
In reply to [email protected]From: Chris Wilson <chris at chris-wilson.co.uk>
If we run out of stolen memory when trying to allocate an object, see if we can reap enough purgeable objects to free up enough contiguous free space for the allocation. This is in principle very much like evicting objects to free up enough contiguous space in the vma when binding a new object - and you will be forgiven for thinking that the code looks very similar.
At the moment, we do not allow userspace to allocate objects in stolen, so there is neither the memory pressure to trigger stolen eviction nor any purgeable objects inside the stolen arena. However, this will change in the near future, and so better management and defragmentation of stolen memory will become a real issue.
v2: Remember to remove the drm_mm_node.
v3: Rebased to the latest drm-intel-nightly (Ankit)
v4: corrected if-else braces format (Tvrtko/kerneldoc)
v5: Rebased to the latest drm-intel-nightly (Ankit)
Added a seperate list to maintain purgable objects from stolen memory region (Chris/Daniel)
v6: Compiler optimization (merging 2 single loops into one for() loop), corrected code for object eviction, retire_requests before starting object eviction (Chris)
v7: Added kernel doc for i915_gem_object_create_stolen()
v8: Check for struct_mutex lock before creating object from stolen region (Tvrtko)
v9: Renamed variables to make usage clear, added comment, removed onetime used macro (Tvrtko)
v10: Avoid masking of error when stolen_alloc fails (Tvrtko)
v11: Renamed stolen_link to tmp_link, as it may be used for other purposes too (Chris)
Used ERR_CAST to cast error pointers while returning
v12: Added lockdep_assert before starting stolen-backed object eviction (Chris)
Testcase: igt/gem_stolen
--- drivers/gpu/drm/i915/i915_debugfs.c | 6 +- drivers/gpu/drm/i915/i915_drv.h | 17 +++- drivers/gpu/drm/i915/i915_gem.c | 15 +++ drivers/gpu/drm/i915/i915_gem_stolen.c | 171 +++++++++++++++++++++++++++++---- drivers/gpu/drm/i915/intel_pm.c | 4 +- 5 files changed, 188 insertions(+), 25 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +3 -3
@@ -174,7 +174,7 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)seq_puts (m,")" ); }if (obj->stolen) -seq_printf (m," (stolen: %08llx)" , obj->stolen->start); +seq_printf (m," (stolen: %08llx)" , obj->stolen->base.start);if (obj->pin_display || obj->fault_mappable) {char s[3 ], *t = s;if (obj->pin_display)
@@ -253,9 +253,9 @@ static int obj_rank_by_stolen(void *priv,struct drm_i915_gem_object *b = container_of(B, struct drm_i915_gem_object, obj_exec_link); -if (a->stolen->start < b->stolen->start) +if (a->stolen->base.start < b->stolen->base.start)return -1 ; -if (a->stolen->start > b->stolen->start) +if (a->stolen->base.start > b->stolen->base.start)return 1 ;return 0 ; }
drivers/gpu/drm/i915/i915_drv.h +16 -1
@@ -840,6 +840,12 @@ struct i915_ctx_hang_stats {bool banned; }; +struct i915_stolen_node { +struct drm_mm_node base; +struct list_head mm_link; +struct drm_i915_gem_object *obj; +}; +/* This must match up with the value previously used for execbuf2.rsvd1. */ #define DEFAULT_CONTEXT_HANDLE 0
@@ -1291,6 +1297,13 @@ struct i915_gem_mm {*/ struct list_head unbound_list; +/** +* List of stolen objects that have been marked as purgeable and +* thus available for reaping if we need more space for a new +* allocation. Ordered by time of marking purgeable. +*/ +struct list_head stolen_list; +/** Usable portion of the GTT for GEM */ unsigned long stolen_base;/* limited to low memory (32-bit) */
@@ -2089,7 +2102,7 @@ struct drm_i915_gem_object {struct list_head vma_list;/** Stolen memory for this object, instead of being backed by shmem. */ -struct drm_mm_node *stolen; +struct i915_stolen_node *stolen;struct list_head global_list;struct list_head ring_list[I915_NUM_RINGS ];
@@ -2097,6 +2110,8 @@ struct drm_i915_gem_object {struct list_head obj_exec_link;struct list_head batch_pool_link; +/** Used to link an object to a list temporarily */ +struct list_head tmp_link;/** * This is set if the object is on the active lists (has pending
drivers/gpu/drm/i915/i915_gem.c +15 -0
@@ -4521,6 +4521,20 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,if (obj->madv ==I915_MADV_DONTNEED && obj->pages ==NULL )i915_gem_object_truncate (obj); +if (obj->stolen) { +switch (obj->madv) { +case I915_MADV_WILLNEED : +list_del_init (&obj->stolen->mm_link); +break ; +case I915_MADV_DONTNEED : +list_move (&obj->stolen->mm_link, + &dev_priv->mm.stolen_list); +break ; +default : +break ; + } + } + args->retained = obj->madv != __I915_MADV_PURGED; out:
@@ -5147,6 +5161,7 @@ i915_gem_load_init(struct drm_device *dev)INIT_LIST_HEAD (&dev_priv->context_list);INIT_LIST_HEAD (&dev_priv->mm.unbound_list);INIT_LIST_HEAD (&dev_priv->mm.bound_list); +INIT_LIST_HEAD (&dev_priv->mm.stolen_list);INIT_LIST_HEAD (&dev_priv->mm.fence_list);for (i =0 ; i <I915_NUM_RINGS ; i++)init_ring_lists (&dev_priv->ring[i]);
drivers/gpu/drm/i915/i915_gem_stolen.c +152 -19
242 lines not on this page · raw message
drivers/gpu/drm/i915/intel_pm.c +2 -2
@@ -5155,7 +5155,7 @@ static void valleyview_check_pctx(struct drm_i915_private *dev_priv)unsigned long pctx_addr =I915_READ (VLV_PCBR ) & ~4095 ;WARN_ON (pctx_addr != dev_priv->mm.stolen_base + - dev_priv->vlv_pctx->stolen->start); + dev_priv->vlv_pctx->stolen->base.start); }
@@ -5232,7 +5232,7 @@ static void valleyview_setup_pctx(struct drm_device *dev)return ; } - pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; + pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->base.start;I915_WRITE (VLV_PCBR , pctx_paddr); out:
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 8/10 drm/i915: Support for pread/pwrite from/to non shmem backed objects
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
This patch adds support for extending the pread/pwrite functionality for objects not backed by shmem. The access will be made through gtt interface. This will cover objects backed by stolen memory as well as other non-shmem backed objects.
v2: Drop locks around slow_user_access, prefault the pages before access (Chris)
v3: Rebased to the latest drm-intel-nightly (Ankit)
v4: Moved page base & offset calculations outside the copy loop, corrected data types for size and offset variables, corrected if-else braces format (Tvrtko/kerneldocs)
v5: Enabled pread/pwrite for all non-shmem backed objects including without tiling restrictions (Ankit)
v6: Using pwrite_fast for non-shmem backed objects as well (Chris)
v7: Updated commit message, Renamed i915_gem_gtt_read to i915_gem_gtt_copy, added pwrite slow path for non-shmem backed objects (Chris/Tvrtko)
v8: Updated v7 commit message, mutex unlock around pwrite slow path for non-shmem backed objects (Tvrtko)
v9: Corrected check during pread_ioctl, to avoid shmem_pread being called for non-shmem backed objects (Tvrtko)
v10: Moved the write_domain check to needs_clflush and tiling mode check to pwrite_fast (Chris)
v11: Use pwrite_fast fallback for all objects (shmem and non-shmem backed), call fast_user_write regardless of pagefault in previous iteration
v12: Use page-by-page copy for slow user access too (Chris)
v13: Handled EFAULT, Avoid use of WARN_ON, put_fence only if whole obj pinned (Chris)
Testcase: igt/gem_stolen, igt/gem_pread, igt/gem_pwrite
--- drivers/gpu/drm/i915/i915_gem.c | 211 ++++++++++++++++++++++++++++++++++------ 1 file changed, 179 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +179 -32
@@ -55,6 +55,9 @@ static bool cpu_cache_is_coherent(struct drm_device *dev,static bool cpu_write_needs_clflush (struct drm_i915_gem_object *obj) { +if (obj->base.write_domain ==I915_GEM_DOMAIN_CPU ) +return false; +if (!cpu_cache_is_coherent (obj->base.dev, obj->cache_level))return true;
@@ -646,6 +649,141 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,return ret ? -EFAULT :0 ; } +static inline uint64_t +slow_user_access (struct io_mapping *mapping, +uint64_t page_base,int page_offset, +char __user *user_data, +int length,bool pwrite) +{ +void __iomem *ioaddr; +void *vaddr; +uint64_t unwritten; + + ioaddr =io_mapping_map_wc (mapping, page_base); +/* We can use the cpu mem copy function because this is X86. */ + vaddr = (void __force *)ioaddr + page_offset; +if (pwrite) + unwritten =__copy_from_user (vaddr, user_data, length); +else + unwritten =__copy_to_user (user_data, vaddr, length); + +io_mapping_unmap (ioaddr); +return unwritten; +} + +static int +i915_gem_gtt_pread (struct drm_device *dev, +struct drm_i915_gem_object *obj,uint64_t size, +uint64_t data_offset,uint64_t data_ptr) +{ +struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_mm_node node; +char __user *user_data; +uint64_t remain; +uint64_t offset; +int ret =0 ; + + ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE ); +if (ret) { + ret =insert_mappable_node (dev_priv, &node,PAGE_SIZE ); +if (ret) + goto out; + + ret =i915_gem_object_get_pages (obj); +if (ret) { +remove_mappable_node (&node); + goto out; + } + +i915_gem_object_pin_pages (obj); + }else { + node.start =i915_gem_obj_ggtt_offset (obj); + node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret) + goto out_unpin; + } + + ret =i915_gem_object_set_to_gtt_domain (obj, false); +if (ret) + goto out_unpin; + + user_data =to_user_ptr (data_ptr); + remain = size; + offset =i915_gem_obj_ggtt_offset (obj) + data_offset; + +mutex_unlock (&dev->struct_mutex); +if (likely (!i915.prefault_disable)) { + ret =fault_in_multipages_writeable (user_data, remain); +if (ret) { +mutex_lock (&dev->struct_mutex); + goto out_unpin; + } + } + +while (remain >0 ) { +/* Operation in this page +* +* page_base = page offset within aperture +* page_offset = offset within page +* page_length = bytes to copy for this page +*/ +u32 page_base = node.start; +unsigned page_offset =offset_in_page (offset); +unsigned page_length =PAGE_SIZE - page_offset; + page_length = remain < page_length ? remain : page_length; +if (node.allocated) { +wmb (); + dev_priv->gtt.base.insert_page (&dev_priv->gtt.base, +i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), + node.start, +I915_CACHE_NONE ,0 ); +wmb (); + }else { + page_base += offset &PAGE_MASK ; + } +/* This is a slow read/write as it tries to read from +* and write to user memory which may result into page +* faults, and so we cannot perform this under struct_mutex. +*/ +if (slow_user_access (dev_priv->gtt.mappable, page_base, + page_offset, user_data, + page_length, false)) { + ret = -EFAULT ; +break ; + } + + remain -= page_length; + user_data += page_length; + offset += page_length; + } + +mutex_lock (&dev->struct_mutex); +if (ret ==0 && (obj->base.read_domains &I915_GEM_DOMAIN_GTT ) ==0 ) { +/* The user has modified the object whilst we tried +* reading from it, and we now have no idea what domain +* the pages should be in. As we have just been touching +* them directly, flush everything back to the GTT +* domain. +*/ + ret =i915_gem_object_set_to_gtt_domain (obj, false); + } + +out_unpin: +if (node.allocated) { +wmb (); + dev_priv->gtt.base.clear_range (&dev_priv->gtt.base, + node.start, node.size, + true); +i915_gem_object_unpin_pages (obj); +remove_mappable_node (&node); + }else { +i915_gem_object_ggtt_unpin (obj); + } +out: +return ret; +} + static int i915_gem_shmem_pread(struct drm_device *dev, struct drm_i915_gem_object *obj,
@@ -661,6 +799,9 @@ i915_gem_shmem_pread(struct drm_device *dev,int needs_clflush =0 ;struct sg_page_iter sg_iter; +if (!obj->base.filp) +return -ENODEV ; + user_data =to_user_ptr (args->data_ptr); remain = args->size;
@@ -769,18 +910,15 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pread (obj, args->offset, args->size); ret =i915_gem_shmem_pread (dev, obj, args, file); +/* pread for non shmem backed objects */ +if (ret == -EFAULT || ret == -ENODEV ) + ret =i915_gem_gtt_pread (dev, obj, args->size, + args->offset, args->data_ptr); + out:drm_gem_object_unreference (&obj->base); unlock:
@@ -821,10 +959,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,struct drm_i915_gem_pwrite *args, struct drm_file *file) { + struct drm_device *dev = obj->base.dev;struct drm_mm_node node;uint64_t remain, offset;char __user *user_data;int ret; +bool hit_slow_path = false; + +if (obj->tiling_mode !=I915_TILING_NONE ) +return -EFAULT ; ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE |PIN_NONBLOCK );if (ret) {
@@ -842,16 +985,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, }else { node.start =i915_gem_obj_ggtt_offset (obj); node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret) + goto out_unpin; } ret =i915_gem_object_set_to_gtt_domain (obj, true);if (ret) goto out_unpin; - ret =i915_gem_object_put_fence (obj); -if (ret) - goto out_unpin; -intel_fb_obj_invalidate (obj,ORIGIN_GTT ); obj->dirty = true;
@@ -870,24 +1012,36 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,unsigned page_length =PAGE_SIZE - page_offset; page_length = remain < page_length ? remain : page_length;if (node.allocated) { -wmb (); +wmb ();/* flush the write before we modify the GGTT */ i915->gtt.base.insert_page (&i915->gtt.base,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), node.start,I915_CACHE_NONE ,0 ); -wmb (); +wmb ();/* flush modifications to the GGTT (insert_page) */ }else { page_base += offset &PAGE_MASK ; }/* If we get a fault while copying data, then (presumably) our * source page isn't available. Return the error and we'll * retry in the slow path. +* If the object is non-shmem backed, we retry again with the +* path that handles page fault. */ if (fast_user_write (i915->gtt.mappable, page_base, page_offset, user_data, page_length)) { - ret = -EFAULT ; - goto out_flush; + hit_slow_path = true; +mutex_unlock (&dev->struct_mutex); +if (slow_user_access (i915->gtt.mappable, + page_base, + page_offset, user_data, + page_length, true)) { + ret = -EFAULT ; +mutex_lock (&dev->struct_mutex); + goto out_flush; + } + +mutex_lock (&dev->struct_mutex); } remain -= page_length;
@@ -896,6 +1050,9 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, } out_flush: +if (hit_slow_path) +WARN_ON (i915_gem_object_set_to_gtt_domain (obj, true)); +intel_fb_obj_flush (obj, false,ORIGIN_GTT ); out_unpin:if (node.allocated) {
@@ -1152,14 +1309,6 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pwrite (obj, args->offset, args->size); ret = -EFAULT ;
@@ -1169,20 +1318,20 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,* pread/pwrite currently are reading and writing from the CPU * perspective, requiring manual detiling by the client. */ -if (obj->tiling_mode ==I915_TILING_NONE && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (!obj->base.filp ||cpu_write_needs_clflush (obj)) { ret =i915_gem_gtt_pwrite_fast (dev_priv, obj, args, file);/* Note that the gtt paths might fail with non-page-backed user * pointers (e.g. gtt mappings when moving data between * textures). Fallback to the shmem path in that case. */ } -if (ret == -EFAULT || ret == -ENOSPC ) { +if (ret == -EFAULT ) {if (obj->phys_handle) ret =i915_gem_phys_pwrite (obj, args, file); -else +else if (obj->base.filp) ret =i915_gem_shmem_pwrite (dev, obj, args, file); +else + ret = -ENODEV ; } out:
@@ -3979,9 +4128,7 @@ out:* object is now coherent at its new cache level (with respect * to the access domain). */ -if (obj->cache_dirty && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (obj->cache_dirty &&cpu_write_needs_clflush (obj)) {if (i915_gem_clflush_object (obj, true))i915_gem_chipset_flush (obj->base.dev); }
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem backed objects
Quoted 63 lines · On 04/02/16 09:30, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
This patch adds support for extending the pread/pwrite functionality for objects not backed by shmem. The access will be made through gtt interface. This will cover objects backed by stolen memory as well as other non-shmem backed objects.
v2: Drop locks around
slow_user_access, prefault the pages before access (Chris)v3: Rebased to the latest drm-intel-nightly (Ankit)
v4: Moved page base & offset calculations outside the copy loop, corrected data types for size and offset variables, corrected if-else braces format (Tvrtko/kerneldocs)
v5: Enabled pread/pwrite for all non-shmem backed objects including without tiling restrictions (Ankit)
v6: Using
pwrite_fastfor non-shmem backed objects as well (Chris)v7: Updated commit message, Renamed
i915_gem_gtt_readtoi915_gem_gtt_copy, added pwrite slow path for non-shmem backed objects (Chris/Tvrtko)v8: Updated v7 commit message, mutex unlock around pwrite slow path for non-shmem backed objects (Tvrtko)
v9: Corrected check during
pread_ioctl, to avoidshmem_preadbeing called for non-shmem backed objects (Tvrtko)v10: Moved the
write_domaincheck toneeds_clflushand tiling mode check topwrite_fast(Chris)v11: Use
pwrite_fastfallback for all objects (shmem and non-shmem backed), callfast_user_writeregardless of pagefault in previous iterationv12: Use page-by-page copy for slow user access too (Chris)
v13: Handled EFAULT, Avoid use of
WARN_ON,put_fenceonly if whole obj pinned (Chris)Testcase: igt/gem_stolen, igt/gem_pread, igt/gem_pwrite
Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 211 ++++++++++++++++++++++++++++++++++------ 1 file changed, 179 insertions(+), 32 deletions(-)drivers/gpu/drm/i915/i915_gem.c +3
-0@@ -55,6 +55,9 @@ static bool cpu_cache_is_coherent(struct drm_device *dev,static bool cpu_write_needs_clflush (struct drm_i915_gem_object *obj) { +if (obj->base.write_domain ==I915_GEM_DOMAIN_CPU ) +return false; +if (!cpu_cache_is_coherent (obj->base.dev, obj->cache_level))return true;
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 657
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +6
-0@@ -646,6 +649,141 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,return ret ? -EFAULT :0 ; } +static inline uint64_t +slow_user_access (struct io_mapping *mapping, +uint64_t page_base,int page_offset, +char __user *user_data, +int length,bool pwrite) +{
Return type and length should be unsigned long to match __copy_to/from_user prototypes.
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem.c +17
-0+void __iomem *ioaddr; +void *vaddr; +uint64_t unwritten; + + ioaddr =io_mapping_map_wc (mapping, page_base); +/* We can use the cpu mem copy function because this is X86. */ + vaddr = (void __force *)ioaddr + page_offset; +if (pwrite) + unwritten =__copy_from_user (vaddr, user_data, length); +else + unwritten =__copy_to_user (user_data, vaddr, length); + +io_mapping_unmap (ioaddr); +return unwritten; +} + +static int
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 684
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+i915_gem_gtt_pread(struct drm_device *dev, + struct drm_i915_gem_object *obj, uint64_t size, + uint64_t data_offset, uint64_t data_ptr) +{ + struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_mm_node node; +char __user *user_data; +uint64_t remain; +uint64_t offset; +int ret =0 ;
No need to initialize.
Quoted 19 lines
drivers/gpu/drm/i915/i915_gem.c +19
-0+ + ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE ); +if (ret) { + ret =insert_mappable_node (dev_priv, &node,PAGE_SIZE ); +if (ret) + goto out; + + ret =i915_gem_object_get_pages (obj); +if (ret) { +remove_mappable_node (&node); + goto out; + } + +i915_gem_object_pin_pages (obj); + }else { + node.start =i915_gem_obj_ggtt_offset (obj); + node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret)
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 713
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ goto out_unpin; + } + + ret =i915_gem_object_set_to_gtt_domain (obj, false); +if (ret) + goto out_unpin; + + user_data =to_user_ptr (data_ptr); + remain = size; + offset =i915_gem_obj_ggtt_offset (obj) + data_offset;
This is wrong for the page-by-page (no pin) mode.
Quoted 31 lines
drivers/gpu/drm/i915/i915_gem.c +31
-0+ +mutex_unlock (&dev->struct_mutex); +if (likely (!i915.prefault_disable)) { + ret =fault_in_multipages_writeable (user_data, remain); +if (ret) { +mutex_lock (&dev->struct_mutex); + goto out_unpin; + } + } + +while (remain >0 ) { +/* Operation in this page +* +* page_base = page offset within aperture +* page_offset = offset within page +* page_length = bytes to copy for this page +*/ +u32 page_base = node.start; +unsigned page_offset =offset_in_page (offset); +unsigned page_length =PAGE_SIZE - page_offset; + page_length = remain < page_length ? remain : page_length; +if (node.allocated) { +wmb (); + dev_priv->gtt.base.insert_page (&dev_priv->gtt.base, +i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), + node.start, +I915_CACHE_NONE ,0 ); +wmb (); + }else { + page_base += offset &PAGE_MASK ; + }
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 754
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+/* This is a slow read/write as it tries to read from +* and write to user memory which may result into page +* faults, and so we cannot perform this under struct_mutex. +*/ +if (slow_user_access (dev_priv->gtt.mappable, page_base, + page_offset, user_data, + page_length, false)) { + ret = -EFAULT ; +break ; + }
Read does not want to try the fast access first, equivalent to pwrite ?
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +5
-0+ + remain -= page_length; + user_data += page_length; + offset += page_length; + }
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 769
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ +mutex_lock (&dev->struct_mutex); +if (ret ==0 && (obj->base.read_domains &I915_GEM_DOMAIN_GTT ) ==0 ) { +/* The user has modified the object whilst we tried +* reading from it, and we now have no idea what domain +* the pages should be in. As we have just been touching +* them directly, flush everything back to the GTT +* domain. +*/ + ret =i915_gem_object_set_to_gtt_domain (obj, false);
How can this be OK? It suggests user could have moved the object to the CPU domain, calls pread and it gets silently moved to the GTT domain?
Quoted 116 lines
drivers/gpu/drm/i915/i915_gem.c +37
-16+ } + +out_unpin: +if (node.allocated) { +wmb (); + dev_priv->gtt.base.clear_range (&dev_priv->gtt.base, + node.start, node.size, + true); +i915_gem_object_unpin_pages (obj); +remove_mappable_node (&node); + }else { +i915_gem_object_ggtt_unpin (obj); + } +out: +return ret; +} + static int i915_gem_shmem_pread(struct drm_device *dev, struct drm_i915_gem_object *obj,@@ -661,6 +799,9 @@ i915_gem_shmem_pread(struct drm_device *dev,int needs_clflush =0 ;struct sg_page_iter sg_iter; +if (!obj->base.filp) +return -ENODEV ; + user_data =to_user_ptr (args->data_ptr); remain = args->size;@@ -769,18 +910,15 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pread (obj, args->offset, args->size); ret =i915_gem_shmem_pread (dev, obj, args, file); +/* pread for non shmem backed objects */ +if (ret == -EFAULT || ret == -ENODEV ) + ret =i915_gem_gtt_pread (dev, obj, args->size, + args->offset, args->data_ptr); + out:drm_gem_object_unreference (&obj->base); unlock:@@ -821,10 +959,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,struct drm_i915_gem_pwrite *args, struct drm_file *file) { + struct drm_device *dev = obj->base.dev;struct drm_mm_node node;uint64_t remain, offset;char __user *user_data;int ret; +bool hit_slow_path = false; + +if (obj->tiling_mode !=I915_TILING_NONE ) +return -EFAULT ; ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE |PIN_NONBLOCK );if (ret) {@@ -842,16 +985,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, }else { node.start =i915_gem_obj_ggtt_offset (obj); node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret) + goto out_unpin; } ret =i915_gem_object_set_to_gtt_domain (obj, true);if (ret) goto out_unpin; - ret =i915_gem_object_put_fence (obj); -if (ret) - goto out_unpin; -intel_fb_obj_invalidate (obj,ORIGIN_GTT ); obj->dirty = true;@@ -870,24 +1012,36 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,unsigned page_length =PAGE_SIZE - page_offset; page_length = remain < page_length ? remain : page_length;if (node.allocated) { -wmb (); +wmb ();/* flush the write before we modify the GGTT */ i915->gtt.base.insert_page (&i915->gtt.base,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), node.start,I915_CACHE_NONE ,0 ); -wmb (); +wmb ();/* flush modifications to the GGTT (insert_page) */ }else { page_base += offset &PAGE_MASK ; }/* If we get a fault while copying data, then (presumably) our * source page isn't available. Return the error and we'll * retry in the slow path. +* If the object is non-shmem backed, we retry again with the +* path that handles page fault. */ if (fast_user_write (i915->gtt.mappable, page_base, page_offset, user_data, page_length)) { - ret = -EFAULT ; - goto out_flush;
drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1042
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ hit_slow_path = true; +mutex_unlock (&dev->struct_mutex); +if (slow_user_access (i915->gtt.mappable, + page_base, + page_offset, user_data, + page_length, true)) { + ret = -EFAULT ; +mutex_lock (&dev->struct_mutex); + goto out_flush; + }
I think the function now be called i915_gem_gtt_pwrite.
Would it also need the same pre-fault as in i915_gem_gtt_pread ?
drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1054
Quoted 11 lines
drivers/gpu/drm/i915/i915_gem.c +4
-0+ +mutex_lock (&dev->struct_mutex); } remain -= page_length;@@ -896,6 +1050,9 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, } out_flush: +if (hit_slow_path) +WARN_ON (i915_gem_object_set_to_gtt_domain (obj, true));
I suppose this is for the same reason as in pread, maybe duplicate the comment here?
Quoted 47 lines
drivers/gpu/drm/i915/i915_gem.c +6
-13+intel_fb_obj_flush (obj, false,ORIGIN_GTT ); out_unpin:if (node.allocated) {@@ -1152,14 +1309,6 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pwrite (obj, args->offset, args->size); ret = -EFAULT ;@@ -1169,20 +1318,20 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,* pread/pwrite currently are reading and writing from the CPU * perspective, requiring manual detiling by the client. */ -if (obj->tiling_mode ==I915_TILING_NONE && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (!obj->base.filp ||cpu_write_needs_clflush (obj)) { ret =i915_gem_gtt_pwrite_fast (dev_priv, obj, args, file);/* Note that the gtt paths might fail with non-page-backed user * pointers (e.g. gtt mappings when moving data between * textures). Fallback to the shmem path in that case. */ } -if (ret == -EFAULT || ret == -ENOSPC ) { +if (ret == -EFAULT ) {if (obj->phys_handle) ret =i915_gem_phys_pwrite (obj, args, file); -else +else if (obj->base.filp) ret =i915_gem_shmem_pwrite (dev, obj, args, file); +else + ret = -ENODEV ; } out:
drivers/gpu/drm/i915/i915_gem.c out: · line 4134
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +1
-3@@ -3979,9 +4128,7 @@ out:* object is now coherent at its new cache level (with respect * to the access domain). */ -if (obj->cache_dirty && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (obj->cache_dirty &&cpu_write_needs_clflush (obj)) {if (i915_gem_clflush_object (obj, true))i915_gem_chipset_flush (obj->base.dev); }
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem backed objects
Hi,
Quoted 194 lines · Tvrtko Ursulin
Quoted 63 lines · On 04/02/16 09:30, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
This patch adds support for extending the pread/pwrite functionality for objects not backed by shmem. The access will be made through gtt interface. This will cover objects backed by stolen memory as well as other non-shmem backed objects.
v2: Drop locks around
slow_user_access, prefault the pages before access (Chris)v3: Rebased to the latest drm-intel-nightly (Ankit)
v4: Moved page base & offset calculations outside the copy loop, corrected data types for size and offset variables, corrected if-else braces format (Tvrtko/kerneldocs)
v5: Enabled pread/pwrite for all non-shmem backed objects including without tiling restrictions (Ankit)
v6: Using
pwrite_fastfor non-shmem backed objects as well (Chris)v7: Updated commit message, Renamed
i915_gem_gtt_readtoi915_gem_gtt_copy, added pwrite slow path for non-shmem backed objects (Chris/Tvrtko)v8: Updated v7 commit message, mutex unlock around pwrite slow path for non-shmem backed objects (Tvrtko)
v9: Corrected check during
pread_ioctl, to avoidshmem_preadbeing called for non-shmem backed objects (Tvrtko)v10: Moved the
write_domaincheck toneeds_clflushand tiling mode check topwrite_fast(Chris)v11: Use
pwrite_fastfallback for all objects (shmem and non-shmem backed), callfast_user_writeregardless of pagefault in previous iterationv12: Use page-by-page copy for slow user access too (Chris)
v13: Handled EFAULT, Avoid use of
WARN_ON,put_fenceonly if whole obj pinned (Chris)Testcase: igt/gem_stolen, igt/gem_pread, igt/gem_pwrite
Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/gpu/drm/i915/i915_gem.c | 211 ++++++++++++++++++++++++++++++++++------ 1 file changed, 179 insertions(+), 32 deletions(-)drivers/gpu/drm/i915/i915_gem.c +3
-0@@ -55,6 +55,9 @@ static bool cpu_cache_is_coherent(struct drm_device *dev,static bool cpu_write_needs_clflush (struct drm_i915_gem_object *obj) { +if (obj->base.write_domain ==I915_GEM_DOMAIN_CPU ) +return false; +if (!cpu_cache_is_coherent (obj->base.dev, obj->cache_level))return true;drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 657
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c +6
-0@@ -646,6 +649,141 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,return ret ? -EFAULT :0 ; } +static inline uint64_t +slow_user_access (struct io_mapping *mapping, +uint64_t page_base,int page_offset, +char __user *user_data, +int length,bool pwrite) +{Return type and length should be unsigned long to match __copy_to/from_user prototypes.
Quoted 17 lines
drivers/gpu/drm/i915/i915_gem.c +17
-0+void __iomem *ioaddr; +void *vaddr; +uint64_t unwritten; + + ioaddr =io_mapping_map_wc (mapping, page_base); +/* We can use the cpu mem copy function because this is X86. */ + vaddr = (void __force *)ioaddr + page_offset; +if (pwrite) + unwritten =__copy_from_user (vaddr, user_data, length); +else + unwritten =__copy_to_user (user_data, vaddr, length); + +io_mapping_unmap (ioaddr); +return unwritten; +} + +static intdrivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 684
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+i915_gem_gtt_pread(struct drm_device *dev, + struct drm_i915_gem_object *obj, uint64_t size, + uint64_t data_offset, uint64_t data_ptr) +{ + struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_mm_node node; +char __user *user_data; +uint64_t remain; +uint64_t offset; +int ret =0 ;No need to initialize.
Quoted 19 lines
drivers/gpu/drm/i915/i915_gem.c +19
-0+ + ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE ); +if (ret) { + ret =insert_mappable_node (dev_priv, &node,PAGE_SIZE ); +if (ret) + goto out; + + ret =i915_gem_object_get_pages (obj); +if (ret) { +remove_mappable_node (&node); + goto out; + } + +i915_gem_object_pin_pages (obj); + }else { + node.start =i915_gem_obj_ggtt_offset (obj); + node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret)drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 713
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ goto out_unpin; + } + + ret =i915_gem_object_set_to_gtt_domain (obj, false); +if (ret) + goto out_unpin; + + user_data =to_user_ptr (data_ptr); + remain = size; + offset =i915_gem_obj_ggtt_offset (obj) + data_offset;This is wrong for the page-by-page (no pin) mode.
Quoted 31 lines
drivers/gpu/drm/i915/i915_gem.c +31
-0+ +mutex_unlock (&dev->struct_mutex); +if (likely (!i915.prefault_disable)) { + ret =fault_in_multipages_writeable (user_data, remain); +if (ret) { +mutex_lock (&dev->struct_mutex); + goto out_unpin; + } + } + +while (remain >0 ) { +/* Operation in this page +* +* page_base = page offset within aperture +* page_offset = offset within page +* page_length = bytes to copy for this page +*/ +u32 page_base = node.start; +unsigned page_offset =offset_in_page (offset); +unsigned page_length =PAGE_SIZE - page_offset; + page_length = remain < page_length ? remain : page_length; +if (node.allocated) { +wmb (); + dev_priv->gtt.base.insert_page (&dev_priv->gtt.base, +i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), + node.start, +I915_CACHE_NONE ,0 ); +wmb (); + }else { + page_base += offset &PAGE_MASK ; + }drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 754
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+/* This is a slow read/write as it tries to read from +* and write to user memory which may result into page +* faults, and so we cannot perform this under struct_mutex. +*/ +if (slow_user_access (dev_priv->gtt.mappable, page_base, + page_offset, user_data, + page_length, false)) { + ret = -EFAULT ; +break ; + }Read does not want to try the fast access first, equivalent to pwrite ?
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ + remain -= page_length; + user_data += page_length; + offset += page_length; + } + +mutex_lock (&dev->struct_mutex); +if (ret ==0 && (obj->base.read_domains &I915_GEM_DOMAIN_GTT ) ==0 ) { +/* The user has modified the object whilst we tried +* reading from it, and we now have no idea what domain
Quoted 9 lines
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 769
Quoted 5 lines
drivers/gpu/drm/i915/i915_gem.c +5
-0+* the pages should be in. As we have just been touching +* them directly, flush everything back to the GTT +* domain. +*/ + ret =i915_gem_object_set_to_gtt_domain (obj, false);How can this be OK? It suggests user could have moved the object to the CPU domain, calls pread and it gets silently moved to the GTT domain?
I agree to this comment, we can add a check if the object is not in CPU_DOMAIN then only go on with gtt_pread else return the shmem_pread error.
Quoted 139 lines
Quoted 116 lines
drivers/gpu/drm/i915/i915_gem.c +37
-16+ } + +out_unpin: +if (node.allocated) { +wmb (); + dev_priv->gtt.base.clear_range (&dev_priv->gtt.base, + node.start, node.size, + true); +i915_gem_object_unpin_pages (obj); +remove_mappable_node (&node); + }else { +i915_gem_object_ggtt_unpin (obj); + } +out: +return ret; +} + static int i915_gem_shmem_pread(struct drm_device *dev, struct drm_i915_gem_object *obj,@@ -661,6 +799,9 @@ i915_gem_shmem_pread(struct drm_device *dev,int needs_clflush =0 ;struct sg_page_iter sg_iter; +if (!obj->base.filp) +return -ENODEV ; + user_data =to_user_ptr (args->data_ptr); remain = args->size;@@ -769,18 +910,15 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pread (obj, args->offset, args->size); ret =i915_gem_shmem_pread (dev, obj, args, file); +/* pread for non shmem backed objects */ +if (ret == -EFAULT || ret == -ENODEV ) + ret =i915_gem_gtt_pread (dev, obj, args->size, + args->offset, args->data_ptr); + out:drm_gem_object_unreference (&obj->base); unlock:@@ -821,10 +959,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,struct drm_i915_gem_pwrite *args, struct drm_file *file) { + struct drm_device *dev = obj->base.dev;struct drm_mm_node node;uint64_t remain, offset;char __user *user_data;int ret; +bool hit_slow_path = false; + +if (obj->tiling_mode !=I915_TILING_NONE ) +return -EFAULT ; ret =i915_gem_obj_ggtt_pin (obj,0 ,PIN_MAPPABLE |PIN_NONBLOCK );if (ret) {@@ -842,16 +985,15 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, }else { node.start =i915_gem_obj_ggtt_offset (obj); node.allocated = false; + ret =i915_gem_object_put_fence (obj); +if (ret) + goto out_unpin; } ret =i915_gem_object_set_to_gtt_domain (obj, true);if (ret) goto out_unpin; - ret =i915_gem_object_put_fence (obj); -if (ret) - goto out_unpin; -intel_fb_obj_invalidate (obj,ORIGIN_GTT ); obj->dirty = true;@@ -870,24 +1012,36 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,unsigned page_length =PAGE_SIZE - page_offset; page_length = remain < page_length ? remain : page_length;if (node.allocated) { -wmb (); +wmb ();/* flush the write before we modify the GGTT */ i915->gtt.base.insert_page (&i915->gtt.base,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), node.start,I915_CACHE_NONE ,0 ); -wmb (); +wmb ();/* flush modifications to the GGTT (insert_page) */ }else { page_base += offset &PAGE_MASK ; }/* If we get a fault while copying data, then (presumably) our * source page isn't available. Return the error and we'll * retry in the slow path. +* If the object is non-shmem backed, we retry again with the +* path that handles page fault. */ if (fast_user_write (i915->gtt.mappable, page_base, page_offset, user_data, page_length)) { - ret = -EFAULT ; - goto out_flush;drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1042
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ hit_slow_path = true; +mutex_unlock (&dev->struct_mutex); +if (slow_user_access (i915->gtt.mappable, + page_base, + page_offset, user_data, + page_length, true)) { + ret = -EFAULT ; +mutex_lock (&dev->struct_mutex); + goto out_flush; + }I think the function now be called
i915_gem_gtt_pwrite.Would it also need the same pre-fault as in
i915_gem_gtt_pread?Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c +2
-0+ +mutex_lock (&dev->struct_mutex); } remain -= page_length;@@ -896,6 +1050,9 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, }
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1054
Quoted 3 lines
drivers/gpu/drm/i915/i915_gem.c +2
-0out_flush: +if (hit_slow_path) +WARN_ON (i915_gem_object_set_to_gtt_domain (obj, true));I suppose this is for the same reason as in pread, maybe duplicate the comment here?
I do not think that this is same as pread, as we only call gtt_pwrite if the object is not in CPU_DOMAIN.
Quoted 4 lines
Regards,
Tvrtko
Thanks,
Ankit
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 08/10] drm/i915: Support for pread/pwrite from/to non shmem backed objects
In reply to Tvrtko UrsulinHi,
Quoted 35 lines · Tvrtko Ursulin
Quoted 35 lines
drivers/gpu/drm/i915/i915_gem.c +35
-0+ +mutex_unlock (&dev->struct_mutex); +if (likely (!i915.prefault_disable)) { + ret =fault_in_multipages_writeable (user_data, remain); +if (ret) { +mutex_lock (&dev->struct_mutex); + goto out_unpin; + } + } + +while (remain >0 ) { +/* Operation in this page +* +* page_base = page offset within aperture +* page_offset = offset within page +* page_length = bytes to copy for this page +*/ +u32 page_base = node.start; +unsigned page_offset =offset_in_page (offset); +unsigned page_length =PAGE_SIZE - page_offset; + page_length = remain < page_length ? remain : page_length; +if (node.allocated) { +wmb (); + dev_priv->gtt.base.insert_page (&dev_priv->gtt.base, +i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), + node.start, +I915_CACHE_NONE ,0 ); +wmb (); + }else { + page_base += offset &PAGE_MASK ; + } +/* This is a slow read/write as it tries to read from +* and write to user memory which may result into page +* faults, and so we cannot perform this under struct_mutex. +*/
Quoted 8 lines
drivers/gpu/drm/i915/i915_gem.c shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length, · line 754
Quoted 6 lines
drivers/gpu/drm/i915/i915_gem.c +6
-0+if (slow_user_access (dev_priv->gtt.mappable, page_base, + page_offset, user_data, + page_length, false)) { + ret = -EFAULT ; +break ; + }Read does not want to try the fast access first, equivalent to pwrite ?
Using fast access means we will be unable to handle faults, which are more frequent in a pread case.
Quoted 47 lines
Quoted 34 lines
drivers/gpu/drm/i915/i915_gem.c +10
-4+ + remain -= page_length; + user_data += page_length; + offset += page_length; + } +@@ -870,24 +1012,36 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915,unsigned page_length =PAGE_SIZE - page_offset; page_length = remain < page_length ? remain : page_length;if (node.allocated) { -wmb (); +wmb ();/* flush the write before we modify the GGTT */ i915->gtt.base.insert_page (&i915->gtt.base,i915_gem_object_get_dma_address (obj, offset >>PAGE_SHIFT ), node.start,I915_CACHE_NONE ,0 ); -wmb (); +wmb ();/* flush modifications to the GGTT (insert_page) */ }else { page_base += offset &PAGE_MASK ; }/* If we get a fault while copying data, then (presumably) our * source page isn't available. Return the error and we'll * retry in the slow path. +* If the object is non-shmem backed, we retry again with the +* path that handles page fault. */ if (fast_user_write (i915->gtt.mappable, page_base, page_offset, user_data, page_length)) { - ret = -EFAULT ; - goto out_flush;drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1042
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +10
-0+ hit_slow_path = true; +mutex_unlock (&dev->struct_mutex); +if (slow_user_access (i915->gtt.mappable, + page_base, + page_offset, user_data, + page_length, true)) { + ret = -EFAULT ; +mutex_lock (&dev->struct_mutex); + goto out_flush; + }I think the function now be called
i915_gem_gtt_pwrite.
Quoted 1 line
Would it also need the same pre-fault as in
i915_gem_gtt_pread?
I do not think pre-fault is needed here, as in pread we are dealing with a read from the obj and to the user buffer (which has more chances of faulting).
While in the pwrite case, we are optimistic that the user would have already mapped/accessed the buffer before using it to write the buffer contents into the object.
Quoted 76 lines
drivers/gpu/drm/i915/i915_gem.c i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, · line 1054
Quoted 12 lines
drivers/gpu/drm/i915/i915_gem.c +4
-0+ +mutex_lock (&dev->struct_mutex); } remain -= page_length;@@ -896,6 +1050,9 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_private *i915, } out_flush: +if (hit_slow_path) +WARN_ON (i915_gem_object_set_to_gtt_domain (obj, true));I suppose this is for the same reason as in pread, maybe duplicate the comment here?
Quoted 47 lines
drivers/gpu/drm/i915/i915_gem.c +6
-13+intel_fb_obj_flush (obj, false,ORIGIN_GTT ); out_unpin:if (node.allocated) {@@ -1152,14 +1309,6 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, goto out; } -/* prime objects have no backing filp to GEM pread/pwrite -* pages from. -*/ -if (!obj->base.filp) { - ret = -EINVAL ; - goto out; - } -trace_i915_gem_object_pwrite (obj, args->offset, args->size); ret = -EFAULT ;@@ -1169,20 +1318,20 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,* pread/pwrite currently are reading and writing from the CPU * perspective, requiring manual detiling by the client. */ -if (obj->tiling_mode ==I915_TILING_NONE && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (!obj->base.filp ||cpu_write_needs_clflush (obj)) { ret =i915_gem_gtt_pwrite_fast (dev_priv, obj, args, file);/* Note that the gtt paths might fail with non-page-backed user * pointers (e.g. gtt mappings when moving data between * textures). Fallback to the shmem path in that case. */ } -if (ret == -EFAULT || ret == -ENOSPC ) { +if (ret == -EFAULT ) {if (obj->phys_handle) ret =i915_gem_phys_pwrite (obj, args, file); -else +else if (obj->base.filp) ret =i915_gem_shmem_pwrite (dev, obj, args, file); +else + ret = -ENODEV ; } out:drivers/gpu/drm/i915/i915_gem.c out: · line 4134
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem.c +1
-3@@ -3979,9 +4128,7 @@ out:* object is now coherent at its new cache level (with respect * to the access domain). */ -if (obj->cache_dirty && - obj->base.write_domain !=I915_GEM_DOMAIN_CPU && -cpu_write_needs_clflush (obj)) { +if (obj->cache_dirty &&cpu_write_needs_clflush (obj)) {if (i915_gem_clflush_object (obj, true))i915_gem_chipset_flush (obj->base.dev); }Regards,
Quoted 2 lines
Tvrtko
Thanks,
Ankit
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 9/10 drm/i915: Migrate stolen objects before hibernation
In reply to [email protected]From: Chris Wilson <[email protected]>
Ville reminded us that stolen memory is not preserved across hibernation, and a result of this was that context objects now being allocated from stolen were being corrupted on S4 and promptly hanging the GPU on resume.
We want to utilise stolen for as much as possible (nothing else will use that wasted memory otherwise), so we need a strategy for handling general objects allocated from stolen and hibernation. A simple solution is to do a CPU copy through the GTT of the stolen object into a fresh shmemfs backing store and thenceforth treat it as a normal objects. This can be refined in future to either use a GPU copy to avoid the slow uncached reads (though it's hibernation!) and recreate stolen objects upon resume/first-use. For now, a simple approach should suffice for testing the object migration.
v2:
Swap PTE for pinned bindings over to the shmemfs. This adds a complicated dance, but is required as many stolen objects are likely to be pinned for use by the hardware. Swapping the PTEs should not result in externally visible behaviour, as each PTE update should be atomic and the two pages identical. (danvet)
safe-by-default, or the principle of least surprise. We need a new flag to mark objects that we can wilfully discard and recreate across hibernation. (danvet)
Just use the global_list rather than invent a new stolen_list. This is the slowpath hibernate and so adding a new list and the associated complexity isn't worth it.
v3: Rebased on drm-intel-nightly (Ankit)
v4: Use insert_page to map stolen memory backed pages for migration to shmem (Chris)
v5: Acquire mutex lock while copying stolen buffer objects to shmem (Chris)
v6: Handled file leak, Splitted object migration function, added kerneldoc for migrate_stolen_to_shmemfs() function (Tvrtko)
Use i915 wrapper function for drm_mm_insert_node_in_range()
v7: Keep the object in cpu domain after get_pages, remove the object from the unbound list only when marked PURGED, Corrected split of object migration function (Chris)
v8: Split i915_gem_freeze(), removed redundant use of barrier, corrected use of set_to_cpu_domain() (Chris)
v9: Replaced WARN_ON by BUG_ON and added a comment explaining it (Daniel/Tvrtko)
v10: Document use of barriers (Chris)
--- drivers/gpu/drm/i915/i915_drv.c | 17 ++- drivers/gpu/drm/i915/i915_drv.h | 10 ++ drivers/gpu/drm/i915/i915_gem.c | 198 ++++++++++++++++++++++++++++++-- drivers/gpu/drm/i915/i915_gem_stolen.c | 49 ++++++++ drivers/gpu/drm/i915/intel_display.c | 3 + drivers/gpu/drm/i915/intel_fbdev.c | 6 + drivers/gpu/drm/i915/intel_pm.c | 2 + drivers/gpu/drm/i915/intel_ringbuffer.c | 6 + 8 files changed, 279 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +16 -1
@@ -996,6 +996,21 @@ static int i915_pm_suspend(struct device *dev)return i915_drm_suspend (drm_dev); } +static int i915_pm_freeze (struct device *dev) +{ +int ret; + + ret =i915_gem_freeze (pci_get_drvdata (to_pci_dev (dev))); +if (ret) +return ret; + + ret =i915_pm_suspend (dev); +if (ret) +return ret; + +return 0 ; +} +static int i915_pm_suspend_late (struct device *dev) {struct drm_device *drm_dev =dev_to_i915 (dev)->dev;
@@ -1643,7 +1658,7 @@ static const struct dev_pm_ops i915_pm_ops = {* @restore, @restore_early : called after rebooting and restoring the * hibernation image [PMSG_RESTORE] */ - .freeze = i915_pm_suspend, + .freeze = i915_pm_freeze, .freeze_late = i915_pm_suspend_late, .thaw_early = i915_pm_resume_early, .thaw = i915_pm_resume,
drivers/gpu/drm/i915/i915_drv.h +10 -0
@@ -2137,6 +2137,12 @@ struct drm_i915_gem_object {* Advice: are the backing pages purgeable? */ unsigned int madv:2; +/** +* Whereas madv is for userspace, there are certain situations +* where we want I915_MADV_DONTNEED behaviour on internal objects +* without conflating the userspace setting. +*/ + unsigned int internal_volatile:1;/** * Current tiling mode for the object.
@@ -3093,6 +3099,9 @@ int i915_gem_l3_remap(struct drm_i915_gem_request *req, int slice);void i915_gem_init_swizzling (struct drm_device *dev);void i915_gem_cleanup_ringbuffer (struct drm_device *dev);int __must_check i915_gpu_idle (struct drm_device *dev); +int __must_check i915_gem_freeze (struct drm_device *dev); +int __must_check +i915_gem_object_migrate_stolen_to_shmemfs (struct drm_i915_gem_object *obj);int __must_check i915_gem_suspend (struct drm_device *dev); void __i915_add_request(struct drm_i915_gem_request *req, struct drm_i915_gem_object *batch_obj,
@@ -3322,6 +3331,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev,u32 stolen_offset, u32 gtt_offset, u32 size); +int __must_check i915_gem_stolen_freeze (struct drm_i915_private *i915);/* i915_gem_shrinker.c */ unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
drivers/gpu/drm/i915/i915_gem.c +187 -11
220 lines not on this page · raw message
drivers/gpu/drm/i915/i915_gem_stolen.c +49 -0
52 lines not on this page · raw message
drivers/gpu/drm/i915/intel_display.c +3 -0
@@ -2558,6 +2558,9 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,if (IS_ERR (obj))return false; +/* Not to be preserved across hibernation */ + obj->internal_volatile = true; + obj->tiling_mode = plane_config->tiling;if (obj->tiling_mode ==I915_TILING_X ) obj->stride = fb->pitches[0 ];
drivers/gpu/drm/i915/intel_fbdev.c +6 -0
@@ -156,6 +156,12 @@ static int intelfb_alloc(struct drm_fb_helper *helper, goto out; } +/* Discard the contents of the BIOS fb across hibernation. +* We really want to completely throwaway the earlier fbdev +* and reconfigure it anyway. +*/ + obj->internal_volatile = true; + fb =__intel_framebuffer_create (dev, &mode_cmd, obj);if (IS_ERR (fb)) {drm_gem_object_unreference (&obj->base);
drivers/gpu/drm/i915/intel_pm.c +2 -0
@@ -5236,6 +5236,8 @@ static void valleyview_setup_pctx(struct drm_device *dev)I915_WRITE (VLV_PCBR , pctx_paddr); out: +/* The power context need not be preserved across hibernation */ + pctx->internal_volatile = true;DRM_DEBUG_DRIVER ("PCBR: 0x%08x\n" ,I915_READ (VLV_PCBR )); dev_priv->vlv_pctx = pctx; }
drivers/gpu/drm/i915/intel_ringbuffer.c +6 -0
@@ -2152,6 +2152,12 @@ static int intel_alloc_ringbuffer_obj(struct drm_device *dev,if (IS_ERR (obj))return PTR_ERR (obj); +/* Ringbuffer objects are by definition volatile - only the commands +* between HEAD and TAIL need to be preserved and whilst there are +* any commands there, the ringbuffer is pinned by activity. +*/ + obj->internal_volatile = true; +/* mark ring buffers as read-only from GPU side by default */ obj->gt_ro =1 ;
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v16 10/10 drm/i915: Disable use of stolen area by User when Intel RST is present
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
The BIOS RapidStartTechnology may corrupt the stolen memory across S3 suspend due to unalarmed hibernation, in which case we will not be able to preserve the User data stored in the stolen region. Hence this patch tries to identify presence of the RST device on the ACPI bus, and disables use of stolen memory (for persistent data) if found.
v2: Updated comment, updated/corrected new functions private to driver (Chris/Tvrtko)
v3: Disabling stolen by default, wait till required acpi changes to detect device presence are pulled in (Ankit)
v4: Enabled stolen by default as required acpi changes are merged (Ankit)
--- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 8 ++++++++ drivers/gpu/drm/i915/i915_gem_stolen.c | 14 ++++++++++++++ drivers/gpu/drm/i915/intel_acpi.c | 10 ++++++++++ 4 files changed, 43 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +11 -0
@@ -1349,6 +1349,16 @@ struct i915_gem_mm {*/ bool busy; +/** +* Stolen will be lost upon hibernate (as the memory is unpowered). +* Across resume, we expect stolen to be intact - however, it may +* also be utililised by third parties (e.g. Intel RapidStart +* Technology) and if so we have to assume that any data stored in +* stolen across resume is lost and we set this flag to indicate that +* the stolen memory is volatile. +*/ +bool nonvolatile_stolen; +/* the indicator for dispatch video commands on two BSD rings */ unsigned int bsd_ring_dispatch_index;
@@ -3465,6 +3475,7 @@ intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)#endif /* intel_acpi.c */ +bool intel_detect_acpi_rst (void );#ifdef CONFIG_ACPI extern void intel_register_dsm_handler (void );extern void intel_unregister_dsm_handler (void );
drivers/gpu/drm/i915/i915_gem.c +8 -0
@@ -396,8 +396,16 @@ static struct drm_i915_gem_object * i915_gem_alloc_object_stolen(struct drm_device *dev, size_t size) {struct drm_i915_gem_object *obj; +struct drm_i915_private *dev_priv = dev->dev_private;int ret; +if (!dev_priv->mm.nonvolatile_stolen) { +/* Stolen may be overwritten by external parties +* so unsuitable for persistent user data. +*/ +return ERR_PTR (-ENODEV ); + } +mutex_lock (&dev->struct_mutex); obj =i915_gem_object_create_stolen (dev, size);if (IS_ERR (obj))
drivers/gpu/drm/i915/i915_gem_stolen.c +14 -0
@@ -482,6 +482,20 @@ int i915_gem_init_stolen(struct drm_device *dev)*/ drm_mm_init (&dev_priv->mm.stolen,0 , dev_priv->gtt.stolen_usable_size); +/* If the stolen region can be modified behind our backs upon suspend, +* then we cannot use it to store nonvolatile contents (i.e user data) +* as it will be corrupted upon resume. +*/ + dev_priv->mm.nonvolatile_stolen = true; +#ifdef CONFIG_SUSPEND +if (intel_detect_acpi_rst ()) { +/* BIOSes using RapidStart Technology have been reported +* to overwrite stolen across S3, not just S4. +*/ + dev_priv->mm.nonvolatile_stolen = false; + } +#endif +return 0 ; }
drivers/gpu/drm/i915/intel_acpi.c +10 -0
@@ -23,6 +23,11 @@ static const u8 intel_dsm_guid[] = { 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c }; +static const struct acpi_device_id irst_ids[] = { + {"INT3392" ,0 }, + {"" ,0 } +}; +static char *intel_dsm_port_name (u8 id) {switch (id) {
@@ -162,3 +167,8 @@ void intel_register_dsm_handler(void)void intel_unregister_dsm_handler (void ) { } + +bool intel_detect_acpi_rst (void ) +{ +return acpi_dev_present (irst_ids[0 ].id); +}
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present
Hi,
Quoted 87 lines · On Thu, Feb 04, 2016 at 03:00:11PM +0530, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
The BIOS RapidStartTechnology may corrupt the stolen memory across S3 suspend due to unalarmed hibernation, in which case we will not be able to preserve the User data stored in the stolen region. Hence this patch tries to identify presence of the RST device on the ACPI bus, and disables use of stolen memory (for persistent data) if found.
v2: Updated comment, updated/corrected new functions private to driver (Chris/Tvrtko)
v3: Disabling stolen by default, wait till required acpi changes to detect device presence are pulled in (Ankit)
v4: Enabled stolen by default as required acpi changes are merged (Ankit)
Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 8 ++++++++ drivers/gpu/drm/i915/i915_gem_stolen.c | 14 ++++++++++++++ drivers/gpu/drm/i915/intel_acpi.c | 10 ++++++++++ 4 files changed, 43 insertions(+)drivers/gpu/drm/i915/i915_drv.h +11
-0@@ -1349,6 +1349,16 @@ struct i915_gem_mm {*/ bool busy; +/** +* Stolen will be lost upon hibernate (as the memory is unpowered). +* Across resume, we expect stolen to be intact - however, it may +* also be utililised by third parties (e.g. Intel RapidStart +* Technology) and if so we have to assume that any data stored in +* stolen across resume is lost and we set this flag to indicate that +* the stolen memory is volatile. +*/ +bool nonvolatile_stolen; +/* the indicator for dispatch video commands on two BSD rings */ unsigned int bsd_ring_dispatch_index;@@ -3465,6 +3475,7 @@ intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)#endif /* intel_acpi.c */ +bool intel_detect_acpi_rst (void );#ifdef CONFIG_ACPI extern void intel_register_dsm_handler (void );extern void intel_unregister_dsm_handler (void );drivers/gpu/drm/i915/i915_gem.c +8
-0@@ -396,8 +396,16 @@ static struct drm_i915_gem_object * i915_gem_alloc_object_stolen(struct drm_device *dev, size_t size) {struct drm_i915_gem_object *obj; +struct drm_i915_private *dev_priv = dev->dev_private;int ret; +if (!dev_priv->mm.nonvolatile_stolen) { +/* Stolen may be overwritten by external parties +* so unsuitable for persistent user data. +*/ +return ERR_PTR (-ENODEV ); + } +mutex_lock (&dev->struct_mutex); obj =i915_gem_object_create_stolen (dev, size);if (IS_ERR (obj))drivers/gpu/drm/i915/i915_gem_stolen.c +4
-0@@ -482,6 +482,20 @@ int i915_gem_init_stolen(struct drm_device *dev)*/ drm_mm_init (&dev_priv->mm.stolen,0 , dev_priv->gtt.stolen_usable_size); +/* If the stolen region can be modified behind our backs upon suspend, +* then we cannot use it to store nonvolatile contents (i.e user data) +* as it will be corrupted upon resume. +*/
drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 498
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10
-0+ dev_priv->mm.nonvolatile_stolen = true; +#ifdef CONFIG_SUSPEND +if (intel_detect_acpi_rst ()) { +/* BIOSes using RapidStart Technology have been reported +* to overwrite stolen across S3, not just S4. +*/ + dev_priv->mm.nonvolatile_stolen = false; + } +#endif +
I'd suggest simplifying it like this:
dev_priv->mm.nonvolatile_stolen = !(IS_ENABLED(CONFIG_SUSPEND) &&
acpi_dev_present("INT3392"));And add to i915_gem_stolen.c:
#include <linux/acpi.h>
Best regards,
Lukas
Quoted 35 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +0
-0return 0 ; }drivers/gpu/drm/i915/intel_acpi.c +10
-0@@ -23,6 +23,11 @@ static const u8 intel_dsm_guid[] = { 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c }; +static const struct acpi_device_id irst_ids[] = { + {"INT3392" ,0 }, + {"" ,0 } +}; +static char *intel_dsm_port_name (u8 id) {switch (id) {@@ -162,3 +167,8 @@ void intel_register_dsm_handler(void)void intel_unregister_dsm_handler (void ) { } + +bool intel_detect_acpi_rst (void ) +{ +return acpi_dev_present (irst_ids[0 ].id); +}Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present
Quoted 17 lines · Lukas Wunner
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4
-0+/* If the stolen region can be modified behind our backs upon suspend, +* then we cannot use it to store nonvolatile contents (i.e user data) +* as it will be corrupted upon resume. +*/ drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 498
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10
-0+ dev_priv->mm.nonvolatile_stolen = true; +#ifdef CONFIG_SUSPEND +if (intel_detect_acpi_rst ()) { +/* BIOSes using RapidStart Technology have been reported +* to overwrite stolen across S3, not just S4. +*/ + dev_priv->mm.nonvolatile_stolen = false; + } +#endif +I'd suggest simplifying it like this:
Quoted 2 lines
dev_priv->mm.nonvolatile_stolen = !(IS_ENABLED(CONFIG_SUSPEND) &&
acpi_dev_present("INT3392"));Using if (IS_ENABLED(CONFIG_SUSPEND) && intel_detect_acpi_rst()) would be better indeed. My main concern here is that we document carefully why we had to disable this, and to leave room for future caveats. Hence my preference for the verbose layout.
We could #define INTEL_RAPID_START "INT339" for
if (IS_ENABLED(CONFIG_SUSPEND) && acpi_dev_present(INTEL_RAPID_START)) but Anki wanted to keep the acpi details themselves out of stolen (hence the current split).
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present
Hi,
Quoted 18 lines · Chris Wilson
Quoted 17 lines · Lukas Wunner
Quoted 4 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +4
-0+/* If the stolen region can be modified behind our backs upon suspend, +* then we cannot use it to store nonvolatile contents (i.e user data) +* as it will be corrupted upon resume. +*/ drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 498
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10
-0+ dev_priv->mm.nonvolatile_stolen = true; +#ifdef CONFIG_SUSPEND +if (intel_detect_acpi_rst ()) { +/* BIOSes using RapidStart Technology have been reported +* to overwrite stolen across S3, not just S4. +*/ + dev_priv->mm.nonvolatile_stolen = false; + } +#endif +I'd suggest simplifying it like this:
Quoted 6 lines
Quoted 2 lines
dev_priv->mm.nonvolatile_stolen = !(IS_ENABLED(CONFIG_SUSPEND) && acpi_dev_present("INT3392"));Using if (
IS_ENABLED(CONFIG_SUSPEND)&&intel_detect_acpi_rst()) would be better indeed. My main concern here is that we document carefully why we had to disable this, and to leave room for future caveats.
Yes absolutely, keep the comments. (Or meld them into one if simplifying the code as suggested.)
Quoted 4 lines
We could #define
INTEL_RAPID_START"INT3392" for
if (IS_ENABLED(CONFIG_SUSPEND)&&acpi_dev_present(INTEL_RAPID_START)) but Anki wanted to keep the acpi details themselves out of stolen (hence the current split).
At the very least the #ifdef needs to be replaced by IS_ENABLED, Documentation/CodingStyle chapter 20 very clearly states this is to be preferred.
Less code is almost always better, it's more work for a reader to follow the logic if things are split across multiple files.
If you absolutely positively want to keep the current split, the "static const struct acpi_device_id irst_ids[]" data structure should be replaced by a "static const char*" in order to not waste memory.
I'd also suggest renaming "dev_priv->mm.nonvolatile_stolen" to "volatile_stolen" since the only user of the flag uses its negation and its calculation requires negation as well.
Best regards,
Lukas
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present
Hi Ankitprasad,
Quoted 6 lines · Lukas Wunner
Quoted 4 lines · Chris Wilson
We could #define
INTEL_RAPID_START"INT3392" for
if (IS_ENABLED(CONFIG_SUSPEND)&&acpi_dev_present(INTEL_RAPID_START)) but Anki wanted to keep the acpi details themselves out of stolen (hence the current split).
Quoted 7 lines
Less code is almost always better, it's more work for a reader to follow the logic if things are split across multiple files.
If you absolutely positively want to keep the current split, the "static const struct
acpi_device_idirst_ids[]" data structure should be replaced by a "static const char*" in order to not waste memory.
As I've learned the hard way yesterday, acpi_dev_present() is undefined if the kernel is compiled without CONFIG_ACPI, so you made the right call splitting that out into intel_acpi.c and my suggested simplification was wrong. Sorry for the noise. :-/
I'd still suggest to invoke acpi_dev_present() with the string literal "INT3392" in intel_acpi.c:intel_detect_acpi_rst() though, or at least replace "static const struct acpi_device_id irst_ids[]" with "static const char*".
Best regards,
Lukas
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 10/10] drm/i915: Disable use of stolen area by User when Intel RST is present
In reply to [email protected]Quoted 32 lines · On 04/02/16 09:30, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
The BIOS RapidStartTechnology may corrupt the stolen memory across S3 suspend due to unalarmed hibernation, in which case we will not be able to preserve the User data stored in the stolen region. Hence this patch tries to identify presence of the RST device on the ACPI bus, and disables use of stolen memory (for persistent data) if found.
v2: Updated comment, updated/corrected new functions private to driver (Chris/Tvrtko)
v3: Disabling stolen by default, wait till required acpi changes to detect device presence are pulled in (Ankit)
v4: Enabled stolen by default as required acpi changes are merged (Ankit)
Signed-off-by Ankitprasad Sharma <[email protected]>--- drivers/gpu/drm/i915/i915_drv.h | 11 +++++++++++ drivers/gpu/drm/i915/i915_gem.c | 8 ++++++++ drivers/gpu/drm/i915/i915_gem_stolen.c | 14 ++++++++++++++ drivers/gpu/drm/i915/intel_acpi.c | 10 ++++++++++ 4 files changed, 43 insertions(+)drivers/gpu/drm/i915/i915_drv.h +0
-0@@ -1349,6 +1349,16 @@ struct i915_gem_mm {*/ bool busy;
drivers/gpu/drm/i915/i915_drv.h struct i915_gem_mm { · line 1360
Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +9
-0+/** +* Stolen will be lost upon hibernate (as the memory is unpowered). +* Across resume, we expect stolen to be intact - however, it may +* also be utililised by third parties (e.g. Intel RapidStart +* Technology) and if so we have to assume that any data stored in +* stolen across resume is lost and we set this flag to indicate that +* the stolen memory is volatile. +*/ +bool nonvolatile_stolen;
I agree with a point made by Lukas that volatile_stolen would be better. Even the comment above suggests so. :)
Quoted 44 lines
drivers/gpu/drm/i915/i915_drv.h +2
-0+/* the indicator for dispatch video commands on two BSD rings */ unsigned int bsd_ring_dispatch_index;@@ -3465,6 +3475,7 @@ intel_opregion_notify_adapter(struct drm_device *dev, pci_power_t state)#endif /* intel_acpi.c */ +bool intel_detect_acpi_rst (void );#ifdef CONFIG_ACPI extern void intel_register_dsm_handler (void );extern void intel_unregister_dsm_handler (void );drivers/gpu/drm/i915/i915_gem.c +8
-0@@ -396,8 +396,16 @@ static struct drm_i915_gem_object * i915_gem_alloc_object_stolen(struct drm_device *dev, size_t size) {struct drm_i915_gem_object *obj; +struct drm_i915_private *dev_priv = dev->dev_private;int ret; +if (!dev_priv->mm.nonvolatile_stolen) { +/* Stolen may be overwritten by external parties +* so unsuitable for persistent user data. +*/ +return ERR_PTR (-ENODEV ); + } +mutex_lock (&dev->struct_mutex); obj =i915_gem_object_create_stolen (dev, size);if (IS_ERR (obj))drivers/gpu/drm/i915/i915_gem_stolen.c +3
-0@@ -482,6 +482,20 @@ int i915_gem_init_stolen(struct drm_device *dev)*/ drm_mm_init (&dev_priv->mm.stolen,0 , dev_priv->gtt.stolen_usable_size); +/* If the stolen region can be modified behind our backs upon suspend, +* then we cannot use it to store nonvolatile contents (i.e user data) +* as it will be corrupted upon resume.
drivers/gpu/drm/i915/i915_gem_stolen.c int i915_gem_init_stolen(struct drm_device *dev) · line 497
Quoted 10 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +10
-0+*/ + dev_priv->mm.nonvolatile_stolen = true; +#ifdef CONFIG_SUSPEND +if (intel_detect_acpi_rst ()) { +/* BIOSes using RapidStart Technology have been reported +* to overwrite stolen across S3, not just S4. +*/ + dev_priv->mm.nonvolatile_stolen = false; + } +#endif
I also agree with the IS_ENABLED(CONFIG_SUSPEND) suggestion.
Quoted 21 lines
drivers/gpu/drm/i915/i915_gem_stolen.c +1
-0+return 0 ; }drivers/gpu/drm/i915/intel_acpi.c +5
-0@@ -23,6 +23,11 @@ static const u8 intel_dsm_guid[] = { 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c }; +static const struct acpi_device_id irst_ids[] = { + {"INT3392" ,0 }, + {"" ,0 } +}; +static char *intel_dsm_port_name (u8 id) {switch (id) {
drivers/gpu/drm/i915/intel_acpi.c void intel_register_dsm_handler(void) · line 174
Quoted 8 lines
drivers/gpu/drm/i915/intel_acpi.c +5
-0@@ -162,3 +167,8 @@ void intel_register_dsm_handler(void)void intel_unregister_dsm_handler (void ) { } + +bool intel_detect_acpi_rst (void ) +{ +return acpi_dev_present (irst_ids[0 ].id); +}
I also agree with Lukas'es suggestion to get rid of this and just do:
dev_priv->mm.volatile_stolen = IS_ENABLED(CONFIG_SUSPEND) &&
acpi_dev_present("INT3392");With the existing comment it should be OK.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx