All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
@ 2022-05-09  9:35 Zbigniew Kempczyński
  2022-05-09  9:55 ` Matthew Auld
  2022-05-09 11:03 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
  0 siblings, 2 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2022-05-09  9:35 UTC (permalink / raw)
  To: igt-dev; +Cc: Matthew Auld

Probing alignment/offset (A/O) in default context works properly only
when there're no processes which competes on same vm space. To avoid
risk that single probe will be called on already used offset in another
process lets use dedicated context for this purpose.

In other words when forking occur without A/O cache filled (subject of
COW) children will exercise A/O individually. Using same default context
leads to risk of probing offset which is in flight in another child
thus we can get different A/O. Such behavior is not allowed as allocator
infrastructure requires same type, strategy and alignment on single vm.
We expect coherent A/O in different children so use separate context
to fill this requirement.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729
---
 lib/i915/intel_memory_region.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 593f4bedc8..ea9717691c 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t start_offset = 0;
 	uint64_t bb_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context to avoid offset overlapping */
+	ctx = gem_context_create(i915);
+
 	memset(&obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
 	eb.buffers_ptr = to_user_pointer(&obj);
 	eb.buffer_count = 1;
 	eb.flags = I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
 	obj.flags = EXEC_OBJECT_PINNED;
 
@@ -670,6 +674,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		igt_assert(start_offset <= 1ull << 48);
 	}
 	gem_close(i915, obj.handle);
+	gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
@@ -770,7 +775,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t min_alignment = PAGE_SIZE;
 	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -780,6 +785,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context to avoid offset overlapping */
+	ctx = gem_context_create(i915);
+
 	memset(obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
@@ -787,6 +795,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	eb.buffers_ptr = to_user_pointer(obj);
 	eb.buffer_count = ARRAY_SIZE(obj);
 	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
 						  &bb_size, region1) == 0);
 
@@ -815,6 +824,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 
 	gem_close(i915, obj[0].handle);
 	gem_close(i915, obj[1].handle);
+	gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
  2022-05-09  9:35 [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment Zbigniew Kempczyński
@ 2022-05-09  9:55 ` Matthew Auld
  2022-05-09 11:03 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
  1 sibling, 0 replies; 7+ messages in thread
From: Matthew Auld @ 2022-05-09  9:55 UTC (permalink / raw)
  To: Zbigniew Kempczyński, igt-dev

On 09/05/2022 10:35, Zbigniew Kempczyński wrote:
> Probing alignment/offset (A/O) in default context works properly only
> when there're no processes which competes on same vm space. To avoid
> risk that single probe will be called on already used offset in another
> process lets use dedicated context for this purpose.
> 
> In other words when forking occur without A/O cache filled (subject of
> COW) children will exercise A/O individually. Using same default context
> leads to risk of probing offset which is in flight in another child
> thus we can get different A/O. Such behavior is not allowed as allocator
> infrastructure requires same type, strategy and alignment on single vm.
> We expect coherent A/O in different children so use separate context
> to fill this requirement.
> 
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729

Possibly also related:

https://gitlab.freedesktop.org/drm/intel/-/issues/5715
https://gitlab.freedesktop.org/drm/intel/-/issues/5647
https://gitlab.freedesktop.org/drm/intel/-/issues/5709
https://gitlab.freedesktop.org/drm/intel/-/issues/5769
https://gitlab.freedesktop.org/drm/intel/-/issues/5556

?

Change makes sense to me,
Reviewed-by: Matthew Auld <matthew.auld@intel.com>

> ---
>   lib/i915/intel_memory_region.c | 14 ++++++++++++--
>   1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
> index 593f4bedc8..ea9717691c 100644
> --- a/lib/i915/intel_memory_region.c
> +++ b/lib/i915/intel_memory_region.c
> @@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   	struct drm_i915_gem_execbuffer2 eb;
>   	uint64_t start_offset = 0;
>   	uint64_t bb_size = PAGE_SIZE;
> -	uint32_t *batch;
> +	uint32_t *batch, ctx;
>   	uint16_t devid = intel_get_drm_devid(i915);
>   	struct cache_entry *entry, *newentry;
>   
> @@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   		goto out;
>   	pthread_mutex_unlock(&cache_mutex);
>   
> +	/* Use separate context to avoid offset overlapping */
> +	ctx = gem_context_create(i915);
> +
>   	memset(&obj, 0, sizeof(obj));
>   	memset(&eb, 0, sizeof(eb));
>   
>   	eb.buffers_ptr = to_user_pointer(&obj);
>   	eb.buffer_count = 1;
>   	eb.flags = I915_EXEC_DEFAULT;
> +	eb.rsvd1 = ctx;
>   	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
>   	obj.flags = EXEC_OBJECT_PINNED;
>   
> @@ -670,6 +674,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   		igt_assert(start_offset <= 1ull << 48);
>   	}
>   	gem_close(i915, obj.handle);
> +	gem_context_destroy(i915, ctx);
>   
>   	newentry = malloc(sizeof(*newentry));
>   	if (!newentry)
> @@ -770,7 +775,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   	struct drm_i915_gem_execbuffer2 eb;
>   	uint64_t min_alignment = PAGE_SIZE;
>   	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
> -	uint32_t *batch;
> +	uint32_t *batch, ctx;
>   	uint16_t devid = intel_get_drm_devid(i915);
>   	struct cache_entry *entry, *newentry;
>   
> @@ -780,6 +785,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   		goto out;
>   	pthread_mutex_unlock(&cache_mutex);
>   
> +	/* Use separate context to avoid offset overlapping */
> +	ctx = gem_context_create(i915);
> +
>   	memset(obj, 0, sizeof(obj));
>   	memset(&eb, 0, sizeof(eb));
>   
> @@ -787,6 +795,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   	eb.buffers_ptr = to_user_pointer(obj);
>   	eb.buffer_count = ARRAY_SIZE(obj);
>   	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
> +	eb.rsvd1 = ctx;
>   	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
>   						  &bb_size, region1) == 0);
>   
> @@ -815,6 +824,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   
>   	gem_close(i915, obj[0].handle);
>   	gem_close(i915, obj[1].handle);
> +	gem_context_destroy(i915, ctx);
>   
>   	newentry = malloc(sizeof(*newentry));
>   	if (!newentry)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [igt-dev] ✗ Fi.CI.BAT: failure for lib/intel_memory_region: Use separate context for probing offset and alignment
  2022-05-09  9:35 [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment Zbigniew Kempczyński
  2022-05-09  9:55 ` Matthew Auld
@ 2022-05-09 11:03 ` Patchwork
  1 sibling, 0 replies; 7+ messages in thread
From: Patchwork @ 2022-05-09 11:03 UTC (permalink / raw)
  To: Zbigniew Kempczyński; +Cc: igt-dev

[-- Attachment #1: Type: text/plain, Size: 8276 bytes --]

== Series Details ==

Series: lib/intel_memory_region: Use separate context for probing offset and alignment
URL   : https://patchwork.freedesktop.org/series/103743/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_11625 -> IGTPW_7063
====================================================

Summary
-------

  **FAILURE**

  Serious unknown changes coming with IGTPW_7063 absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_7063, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/index.html

Participating hosts (43 -> 40)
------------------------------

  Additional (2): bat-dg2-8 bat-dg2-9 
  Missing    (5): fi-rkl-11600 bat-dg1-5 bat-adlm-1 fi-bsw-cyan bat-rpls-1 

Possible new issues
-------------------

  Here are the unknown changes that may have been introduced in IGTPW_7063:

### IGT changes ###

#### Possible regressions ####

  * igt@gem_softpin@safe-alignment:
    - fi-pnv-d510:        [PASS][1] -> [FAIL][2]
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-pnv-d510/igt@gem_softpin@safe-alignment.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-pnv-d510/igt@gem_softpin@safe-alignment.html
    - fi-blb-e6850:       [PASS][3] -> [FAIL][4]
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-blb-e6850/igt@gem_softpin@safe-alignment.html
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-blb-e6850/igt@gem_softpin@safe-alignment.html

  
#### Suppressed ####

  The following results come from untrusted machines, tests, or statuses.
  They do not affect the overall result.

  * igt@i915_module_load@reload:
    - {bat-rpls-2}:       [DMESG-WARN][5] ([i915#4391]) -> [DMESG-WARN][6]
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/bat-rpls-2/igt@i915_module_load@reload.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/bat-rpls-2/igt@i915_module_load@reload.html

  * igt@i915_selftest@live@gt_lrc:
    - {fi-tgl-dsi}:       [DMESG-FAIL][7] ([i915#2373]) -> [INCOMPLETE][8]
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-tgl-dsi/igt@i915_selftest@live@gt_lrc.html
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-tgl-dsi/igt@i915_selftest@live@gt_lrc.html

  
Known issues
------------

  Here are the changes found in IGTPW_7063 that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@i915_selftest@live@hangcheck:
    - fi-bdw-5557u:       NOTRUN -> [INCOMPLETE][9] ([i915#3921])
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-bdw-5557u/igt@i915_selftest@live@hangcheck.html

  * igt@kms_busy@basic@modeset:
    - bat-adlp-4:         [PASS][10] -> [DMESG-WARN][11] ([i915#3576]) +1 similar issue
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/bat-adlp-4/igt@kms_busy@basic@modeset.html
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/bat-adlp-4/igt@kms_busy@basic@modeset.html

  * igt@kms_chamelium@common-hpd-after-suspend:
    - fi-bsw-n3050:       NOTRUN -> [SKIP][12] ([fdo#109271] / [fdo#111827])
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-bsw-n3050/igt@kms_chamelium@common-hpd-after-suspend.html

  * igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
    - fi-bsw-n3050:       NOTRUN -> [SKIP][13] ([fdo#109271])
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-bsw-n3050/igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a.html

  
#### Possible fixes ####

  * igt@i915_module_load@reload:
    - fi-kbl-soraka:      [DMESG-WARN][14] ([i915#1982]) -> [PASS][15]
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-kbl-soraka/igt@i915_module_load@reload.html
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-kbl-soraka/igt@i915_module_load@reload.html

  * igt@i915_selftest@live@execlists:
    - fi-bsw-n3050:       [INCOMPLETE][16] ([i915#5801] / [i915#5847]) -> [PASS][17]
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-bsw-n3050/igt@i915_selftest@live@execlists.html
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-bsw-n3050/igt@i915_selftest@live@execlists.html

  * igt@i915_selftest@live@gtt:
    - fi-bdw-5557u:       [INCOMPLETE][18] ([i915#5685]) -> [PASS][19]
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/fi-bdw-5557u/igt@i915_selftest@live@gtt.html
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/fi-bdw-5557u/igt@i915_selftest@live@gtt.html

  * igt@kms_flip@basic-flip-vs-modeset@a-edp1:
    - {bat-adlp-6}:       [DMESG-WARN][20] ([i915#3576]) -> [PASS][21]
   [20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/bat-adlp-6/igt@kms_flip@basic-flip-vs-modeset@a-edp1.html
   [21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/bat-adlp-6/igt@kms_flip@basic-flip-vs-modeset@a-edp1.html

  * igt@kms_flip@basic-flip-vs-modeset@b-edp1:
    - bat-adlp-4:         [DMESG-WARN][22] ([i915#3576]) -> [PASS][23] +1 similar issue
   [22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11625/bat-adlp-4/igt@kms_flip@basic-flip-vs-modeset@b-edp1.html
   [23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/bat-adlp-4/igt@kms_flip@basic-flip-vs-modeset@b-edp1.html

  
  {name}: This element is suppressed. This means it is ignored when computing
          the status of the difference (SUCCESS, WARNING, or FAILURE).

  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
  [fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
  [i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
  [i915#1155]: https://gitlab.freedesktop.org/drm/intel/issues/1155
  [i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
  [i915#2373]: https://gitlab.freedesktop.org/drm/intel/issues/2373
  [i915#2582]: https://gitlab.freedesktop.org/drm/intel/issues/2582
  [i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
  [i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
  [i915#3576]: https://gitlab.freedesktop.org/drm/intel/issues/3576
  [i915#3595]: https://gitlab.freedesktop.org/drm/intel/issues/3595
  [i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
  [i915#3921]: https://gitlab.freedesktop.org/drm/intel/issues/3921
  [i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
  [i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
  [i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
  [i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
  [i915#4212]: https://gitlab.freedesktop.org/drm/intel/issues/4212
  [i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213
  [i915#4215]: https://gitlab.freedesktop.org/drm/intel/issues/4215
  [i915#4391]: https://gitlab.freedesktop.org/drm/intel/issues/4391
  [i915#4873]: https://gitlab.freedesktop.org/drm/intel/issues/4873
  [i915#5190]: https://gitlab.freedesktop.org/drm/intel/issues/5190
  [i915#5274]: https://gitlab.freedesktop.org/drm/intel/issues/5274
  [i915#5275]: https://gitlab.freedesktop.org/drm/intel/issues/5275
  [i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
  [i915#5685]: https://gitlab.freedesktop.org/drm/intel/issues/5685
  [i915#5763]: https://gitlab.freedesktop.org/drm/intel/issues/5763
  [i915#5801]: https://gitlab.freedesktop.org/drm/intel/issues/5801
  [i915#5847]: https://gitlab.freedesktop.org/drm/intel/issues/5847
  [i915#5879]: https://gitlab.freedesktop.org/drm/intel/issues/5879
  [i915#5885]: https://gitlab.freedesktop.org/drm/intel/issues/5885


Build changes
-------------

  * CI: CI-20190529 -> None
  * IGT: IGT_6468 -> IGTPW_7063

  CI-20190529: 20190529
  CI_DRM_11625: d14ec2169b06f7f6e946fd856b0bd702234d5800 @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_7063: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/index.html
  IGT_6468: cffa5fffe9acddf49565b4caeeb5e3355ff2ea44 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_7063/index.html

[-- Attachment #2: Type: text/html, Size: 7875 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
@ 2022-05-09 14:55 Zbigniew Kempczyński
  0 siblings, 0 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2022-05-09 14:55 UTC (permalink / raw)
  To: igt-dev; +Cc: Matthew Auld

Probing alignment/offset (A/O) in default context works properly only
when there're no processes which competes on same vm space. To avoid
risk that single probe will be called on already used offset in another
process lets use dedicated context for this purpose if possible.

In other words when forking occur without A/O cache filled (subject of
COW) children will exercise A/O individually. Using same default context
leads to risk of probing offset which is in flight in another child
thus we can get different A/O. Such behavior is not allowed as allocator
infrastructure requires same type, strategy and alignment on single vm.
We expect coherent A/O in different children so we try to use separate
context to fill this requirement.

v2: on old gens where're no logical contexts use default context
v3: adding missing condition for context destroy (Matt)

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729
---
 lib/i915/intel_memory_region.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 593f4bedc8..6bf6aab1e6 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t start_offset = 0;
 	uint64_t bb_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx = 0;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context if possible to avoid offset overlapping */
+	__gem_context_create(i915, &ctx);
+
 	memset(&obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
 	eb.buffers_ptr = to_user_pointer(&obj);
 	eb.buffer_count = 1;
 	eb.flags = I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
 	obj.flags = EXEC_OBJECT_PINNED;
 
@@ -670,6 +674,8 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		igt_assert(start_offset <= 1ull << 48);
 	}
 	gem_close(i915, obj.handle);
+	if (ctx)
+		gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
@@ -770,7 +776,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t min_alignment = PAGE_SIZE;
 	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx = 0;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -780,6 +786,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context if possible to avoid offset overlapping */
+	__gem_context_create(i915, &ctx);
+
 	memset(obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
@@ -787,6 +796,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	eb.buffers_ptr = to_user_pointer(obj);
 	eb.buffer_count = ARRAY_SIZE(obj);
 	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
 						  &bb_size, region1) == 0);
 
@@ -815,6 +825,8 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 
 	gem_close(i915, obj[0].handle);
 	gem_close(i915, obj[1].handle);
+	if (ctx)
+		gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
  2022-05-09 11:43 ` Matthew Auld
@ 2022-05-09 14:52   ` Zbigniew Kempczyński
  0 siblings, 0 replies; 7+ messages in thread
From: Zbigniew Kempczyński @ 2022-05-09 14:52 UTC (permalink / raw)
  To: Matthew Auld; +Cc: igt-dev

On Mon, May 09, 2022 at 12:43:11PM +0100, Matthew Auld wrote:
> On 09/05/2022 12:30, Zbigniew Kempczyński wrote:
> > Probing alignment/offset (A/O) in default context works properly only
> > when there're no processes which competes on same vm space. To avoid
> > risk that single probe will be called on already used offset in another
> > process lets use dedicated context for this purpose if possible.
> > 
> > In other words when forking occur without A/O cache filled (subject of
> > COW) children will exercise A/O individually. Using same default context
> > leads to risk of probing offset which is in flight in another child
> > thus we can get different A/O. Such behavior is not allowed as allocator
> > infrastructure requires same type, strategy and alignment on single vm.
> > We expect coherent A/O in different children so we try to use separate
> > context to fill this requirement.
> > 
> > v2: on old gens where're no logical contexts use default context
> > 
> > Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> > Cc: Matthew Auld <matthew.auld@intel.com>
> > Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729
> > ---
> >   lib/i915/intel_memory_region.c | 15 +++++++++++++--
> >   1 file changed, 13 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
> > index 593f4bedc8..c0f67bd737 100644
> > --- a/lib/i915/intel_memory_region.c
> > +++ b/lib/i915/intel_memory_region.c
> > @@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
> >   	struct drm_i915_gem_execbuffer2 eb;
> >   	uint64_t start_offset = 0;
> >   	uint64_t bb_size = PAGE_SIZE;
> > -	uint32_t *batch;
> > +	uint32_t *batch, ctx = 0;
> >   	uint16_t devid = intel_get_drm_devid(i915);
> >   	struct cache_entry *entry, *newentry;
> > @@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
> >   		goto out;
> >   	pthread_mutex_unlock(&cache_mutex);
> > +	/* Use separate context if possible to avoid offset overlapping */
> > +	__gem_context_create(i915, &ctx);
> > +
> >   	memset(&obj, 0, sizeof(obj));
> >   	memset(&eb, 0, sizeof(eb));
> >   	eb.buffers_ptr = to_user_pointer(&obj);
> >   	eb.buffer_count = 1;
> >   	eb.flags = I915_EXEC_DEFAULT;
> > +	eb.rsvd1 = ctx;
> >   	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
> >   	obj.flags = EXEC_OBJECT_PINNED;
> > @@ -670,6 +674,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
> >   		igt_assert(start_offset <= 1ull << 48);
> >   	}
> >   	gem_close(i915, obj.handle);
> > +	gem_context_destroy(i915, ctx);
> 
> if (ctx)
>     gem_context_destroy();
> 
> ?

Eh, I forgot adding this in second function :/

> 
> r-b still stands, assuming CI is now happy :)

Ok, thanks, let's CI be clear in this case (v3).

--
Zbigniew

> 
> >   	newentry = malloc(sizeof(*newentry));
> >   	if (!newentry)
> > @@ -770,7 +775,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
> >   	struct drm_i915_gem_execbuffer2 eb;
> >   	uint64_t min_alignment = PAGE_SIZE;
> >   	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
> > -	uint32_t *batch;
> > +	uint32_t *batch, ctx = 0;
> >   	uint16_t devid = intel_get_drm_devid(i915);
> >   	struct cache_entry *entry, *newentry;
> > @@ -780,6 +785,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
> >   		goto out;
> >   	pthread_mutex_unlock(&cache_mutex);
> > +	/* Use separate context if possible to avoid offset overlapping */
> > +	__gem_context_create(i915, &ctx);
> > +
> >   	memset(obj, 0, sizeof(obj));
> >   	memset(&eb, 0, sizeof(eb));
> > @@ -787,6 +795,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
> >   	eb.buffers_ptr = to_user_pointer(obj);
> >   	eb.buffer_count = ARRAY_SIZE(obj);
> >   	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
> > +	eb.rsvd1 = ctx;
> >   	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
> >   						  &bb_size, region1) == 0);
> > @@ -815,6 +824,8 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
> >   	gem_close(i915, obj[0].handle);
> >   	gem_close(i915, obj[1].handle);
> > +	if (ctx)
> > +		gem_context_destroy(i915, ctx);
> >   	newentry = malloc(sizeof(*newentry));
> >   	if (!newentry)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
  2022-05-09 11:30 [igt-dev] [PATCH i-g-t] " Zbigniew Kempczyński
@ 2022-05-09 11:43 ` Matthew Auld
  2022-05-09 14:52   ` Zbigniew Kempczyński
  0 siblings, 1 reply; 7+ messages in thread
From: Matthew Auld @ 2022-05-09 11:43 UTC (permalink / raw)
  To: Zbigniew Kempczyński, igt-dev

On 09/05/2022 12:30, Zbigniew Kempczyński wrote:
> Probing alignment/offset (A/O) in default context works properly only
> when there're no processes which competes on same vm space. To avoid
> risk that single probe will be called on already used offset in another
> process lets use dedicated context for this purpose if possible.
> 
> In other words when forking occur without A/O cache filled (subject of
> COW) children will exercise A/O individually. Using same default context
> leads to risk of probing offset which is in flight in another child
> thus we can get different A/O. Such behavior is not allowed as allocator
> infrastructure requires same type, strategy and alignment on single vm.
> We expect coherent A/O in different children so we try to use separate
> context to fill this requirement.
> 
> v2: on old gens where're no logical contexts use default context
> 
> Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729
> ---
>   lib/i915/intel_memory_region.c | 15 +++++++++++++--
>   1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
> index 593f4bedc8..c0f67bd737 100644
> --- a/lib/i915/intel_memory_region.c
> +++ b/lib/i915/intel_memory_region.c
> @@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   	struct drm_i915_gem_execbuffer2 eb;
>   	uint64_t start_offset = 0;
>   	uint64_t bb_size = PAGE_SIZE;
> -	uint32_t *batch;
> +	uint32_t *batch, ctx = 0;
>   	uint16_t devid = intel_get_drm_devid(i915);
>   	struct cache_entry *entry, *newentry;
>   
> @@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   		goto out;
>   	pthread_mutex_unlock(&cache_mutex);
>   
> +	/* Use separate context if possible to avoid offset overlapping */
> +	__gem_context_create(i915, &ctx);
> +
>   	memset(&obj, 0, sizeof(obj));
>   	memset(&eb, 0, sizeof(eb));
>   
>   	eb.buffers_ptr = to_user_pointer(&obj);
>   	eb.buffer_count = 1;
>   	eb.flags = I915_EXEC_DEFAULT;
> +	eb.rsvd1 = ctx;
>   	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
>   	obj.flags = EXEC_OBJECT_PINNED;
>   
> @@ -670,6 +674,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
>   		igt_assert(start_offset <= 1ull << 48);
>   	}
>   	gem_close(i915, obj.handle);
> +	gem_context_destroy(i915, ctx);

if (ctx)
     gem_context_destroy();

?

r-b still stands, assuming CI is now happy :)

>   
>   	newentry = malloc(sizeof(*newentry));
>   	if (!newentry)
> @@ -770,7 +775,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   	struct drm_i915_gem_execbuffer2 eb;
>   	uint64_t min_alignment = PAGE_SIZE;
>   	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
> -	uint32_t *batch;
> +	uint32_t *batch, ctx = 0;
>   	uint16_t devid = intel_get_drm_devid(i915);
>   	struct cache_entry *entry, *newentry;
>   
> @@ -780,6 +785,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   		goto out;
>   	pthread_mutex_unlock(&cache_mutex);
>   
> +	/* Use separate context if possible to avoid offset overlapping */
> +	__gem_context_create(i915, &ctx);
> +
>   	memset(obj, 0, sizeof(obj));
>   	memset(&eb, 0, sizeof(eb));
>   
> @@ -787,6 +795,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   	eb.buffers_ptr = to_user_pointer(obj);
>   	eb.buffer_count = ARRAY_SIZE(obj);
>   	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
> +	eb.rsvd1 = ctx;
>   	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
>   						  &bb_size, region1) == 0);
>   
> @@ -815,6 +824,8 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
>   
>   	gem_close(i915, obj[0].handle);
>   	gem_close(i915, obj[1].handle);
> +	if (ctx)
> +		gem_context_destroy(i915, ctx);
>   
>   	newentry = malloc(sizeof(*newentry));
>   	if (!newentry)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment
@ 2022-05-09 11:30 Zbigniew Kempczyński
  2022-05-09 11:43 ` Matthew Auld
  0 siblings, 1 reply; 7+ messages in thread
From: Zbigniew Kempczyński @ 2022-05-09 11:30 UTC (permalink / raw)
  To: igt-dev; +Cc: Matthew Auld

Probing alignment/offset (A/O) in default context works properly only
when there're no processes which competes on same vm space. To avoid
risk that single probe will be called on already used offset in another
process lets use dedicated context for this purpose if possible.

In other words when forking occur without A/O cache filled (subject of
COW) children will exercise A/O individually. Using same default context
leads to risk of probing offset which is in flight in another child
thus we can get different A/O. Such behavior is not allowed as allocator
infrastructure requires same type, strategy and alignment on single vm.
We expect coherent A/O in different children so we try to use separate
context to fill this requirement.

v2: on old gens where're no logical contexts use default context

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Fixes: https://gitlab.freedesktop.org/drm/intel/-/issues/5729
---
 lib/i915/intel_memory_region.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c
index 593f4bedc8..c0f67bd737 100644
--- a/lib/i915/intel_memory_region.c
+++ b/lib/i915/intel_memory_region.c
@@ -630,7 +630,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t start_offset = 0;
 	uint64_t bb_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx = 0;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -640,12 +640,16 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context if possible to avoid offset overlapping */
+	__gem_context_create(i915, &ctx);
+
 	memset(&obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
 	eb.buffers_ptr = to_user_pointer(&obj);
 	eb.buffer_count = 1;
 	eb.flags = I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj.handle, &bb_size, region) == 0);
 	obj.flags = EXEC_OBJECT_PINNED;
 
@@ -670,6 +674,7 @@ uint64_t gem_detect_min_start_offset_for_region(int i915, uint32_t region)
 		igt_assert(start_offset <= 1ull << 48);
 	}
 	gem_close(i915, obj.handle);
+	gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
@@ -770,7 +775,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	struct drm_i915_gem_execbuffer2 eb;
 	uint64_t min_alignment = PAGE_SIZE;
 	uint64_t bb_size = PAGE_SIZE, obj_size = PAGE_SIZE;
-	uint32_t *batch;
+	uint32_t *batch, ctx = 0;
 	uint16_t devid = intel_get_drm_devid(i915);
 	struct cache_entry *entry, *newentry;
 
@@ -780,6 +785,9 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 		goto out;
 	pthread_mutex_unlock(&cache_mutex);
 
+	/* Use separate context if possible to avoid offset overlapping */
+	__gem_context_create(i915, &ctx);
+
 	memset(obj, 0, sizeof(obj));
 	memset(&eb, 0, sizeof(eb));
 
@@ -787,6 +795,7 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 	eb.buffers_ptr = to_user_pointer(obj);
 	eb.buffer_count = ARRAY_SIZE(obj);
 	eb.flags = I915_EXEC_BATCH_FIRST | I915_EXEC_DEFAULT;
+	eb.rsvd1 = ctx;
 	igt_assert(__gem_create_in_memory_regions(i915, &obj[0].handle,
 						  &bb_size, region1) == 0);
 
@@ -815,6 +824,8 @@ uint64_t gem_detect_min_alignment_for_regions(int i915,
 
 	gem_close(i915, obj[0].handle);
 	gem_close(i915, obj[1].handle);
+	if (ctx)
+		gem_context_destroy(i915, ctx);
 
 	newentry = malloc(sizeof(*newentry));
 	if (!newentry)
-- 
2.32.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-09 14:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  9:35 [igt-dev] [PATCH i-g-t] lib/intel_memory_region: Use separate context for probing offset and alignment Zbigniew Kempczyński
2022-05-09  9:55 ` Matthew Auld
2022-05-09 11:03 ` [igt-dev] ✗ Fi.CI.BAT: failure for " Patchwork
2022-05-09 11:30 [igt-dev] [PATCH i-g-t] " Zbigniew Kempczyński
2022-05-09 11:43 ` Matthew Auld
2022-05-09 14:52   ` Zbigniew Kempczyński
2022-05-09 14:55 Zbigniew Kempczyński

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.