Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/3] drm/i915/selftests: fix stolen reset test races
@ 2026-11-18 13:02 Sebastian Brzezinka
  2026-11-18 13:02 ` [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest Sebastian Brzezinka
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sebastian Brzezinka @ 2026-11-18 13:02 UTC (permalink / raw)
  To: intel-gfx
  Cc: andi.shyti, chris.p.wilson, krzysztof.karas, krzysztof.niemiec,
	Sebastian Brzezinka

The stolen reset selftests (igt_reset_device_stolen and
igt_reset_engines_stolen) poison the unused stolen pages, reset the GPU
and check that those pages did not change. This series fixes two races
in the test itself. Neither one is a GPU reset problem.

v5 -> v6:
- Split the series into 3 patches (Krzysztof)
- Drop the poisoned bitmap, it was redundant (Sashiko)
- Use raw_insert_page when available, like
  i915_vma_coredump_create() (Sashiko)
- Take error_mutex only around the sampling loops, not across the
  reset, to avoid a deadlock with the GuC CT worker (Sashiko)

v4 -> v5:
- Hold stolen_lock across the reset too
- Add a patch that takes ggtt->error_mutex in the test

Sebastian Brzezinka (3):
  drm/i915/selftests: Fix unlocked mm.stolen in reset selftest
  drm/i915/selftests: Limit stolen reset test to usable stolen
  drm/i915/selftests: take error_mutex in stolen reset test

 drivers/gpu/drm/i915/gt/selftest_reset.c | 52 ++++++++++++++++--------
 1 file changed, 34 insertions(+), 18 deletions(-)

-- 
2.56.1


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

* [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest
  2026-11-18 13:02 [PATCH v6 0/3] drm/i915/selftests: fix stolen reset test races Sebastian Brzezinka
@ 2026-11-18 13:02 ` Sebastian Brzezinka
  2026-11-18 13:31   ` sashiko-bot
  2026-11-18 13:02 ` [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen Sebastian Brzezinka
  2026-11-18 13:02 ` [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test Sebastian Brzezinka
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Brzezinka @ 2026-11-18 13:02 UTC (permalink / raw)
  To: intel-gfx
  Cc: andi.shyti, chris.p.wilson, krzysztof.karas, krzysztof.niemiec,
	Sebastian Brzezinka

_igt_reset_stolen() use via __drm_mm_interval_first(), but
does so without holding i915->mm.stolen_lock. Every writer of this
(i915_gem_stolen.c: drm_mm_insert_node_in_range(), drm_mm_reserve_node(),
drm_mm_remove_node()) takes stolen_lock, so the selftest's unlocked
reader can race.

This was observed as a NULL pointer dereference in
__drm_mm_interval_first() during igt_reset_device_stolen():

BUG: kernel NULL pointer dereference, address: 0000000000000010
...
RIP: 0010:__drm_mm_interval_first+0x2c/0x90
...
Call Trace:
  __igt_reset_stolen+0x565/0x6a0 [i915]
  igt_reset_device_stolen+0x1a/0x30 [i915]
  __i915_subtests+0xb8/0x250 [i915]
...

Fixes: 3da3c5c1c982 ("drm/i915: Exclude low pages (128KiB) of stolen from use")
Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/work_items/16841
Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
---
v1 -> v2:
- Fix always false !__drm_mm_interval_first() check (Andi)
- Extend stolen_lock over the poison/verify writes, not just
  the lookup (Andi)
- Move the lookup into stolen_page_unused() helper

v2 -> v3:
- Cap num_pages to i915->dsm.usable_size to avoid poisoning
  hardware reserved stolen pages (Shashiko)

v3 -> v4:
- Only verify pages poisoned before the reset; pages in use (e.g.
  rings) may be rewritten and freed during reset (CI)
---
 drivers/gpu/drm/i915/gt/selftest_reset.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c
index 2cfc23c58e90..7d4b0382fe19 100644
--- a/drivers/gpu/drm/i915/gt/selftest_reset.c
+++ b/drivers/gpu/drm/i915/gt/selftest_reset.c
@@ -14,6 +14,16 @@
 #include "selftests/igt_atomic.h"
 #include "selftests/igt_spinner.h"
 
+static bool stolen_page_unused(struct intel_gt *gt, resource_size_t page)
+{
+	lockdep_assert_held(&gt->i915->mm.stolen_lock);
+
+	return __drm_mm_interval_first(&gt->i915->mm.stolen,
+					page << PAGE_SHIFT,
+					((page + 1) << PAGE_SHIFT) - 1) ==
+	       &gt->i915->mm.stolen.head_node;
+}
+
 static int
 __igt_reset_stolen(struct intel_gt *gt,
 		   intel_engine_mask_t mask,
@@ -79,6 +89,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 		i915_request_add(rq);
 	}
 
+	mutex_lock(&gt->i915->mm.stolen_lock);
+
 	for (page = 0; page < num_pages; page++) {
 		dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT);
 		void __iomem *s;
@@ -95,9 +107,7 @@ __igt_reset_stolen(struct intel_gt *gt,
 				      ggtt->error_capture.start,
 				      PAGE_SIZE);
 
-		if (!__drm_mm_interval_first(&gt->i915->mm.stolen,
-					     page << PAGE_SHIFT,
-					     ((page + 1) << PAGE_SHIFT) - 1))
+		if (stolen_page_unused(gt, page))
 			memset_io(s, STACK_MAGIC, PAGE_SIZE);
 
 		in = (void __force *)s;
@@ -143,10 +153,7 @@ __igt_reset_stolen(struct intel_gt *gt,
 			in = tmp;
 		x = crc32_le(0, in, PAGE_SIZE);
 
-		if (x != crc[page] &&
-		    !__drm_mm_interval_first(&gt->i915->mm.stolen,
-					     page << PAGE_SHIFT,
-					     ((page + 1) << PAGE_SHIFT) - 1)) {
+		if (x != crc[page] && stolen_page_unused(gt, page)) {
 			pr_debug("unused stolen page %pa modified by GPU reset\n",
 				 &page);
 			if (count++ == 0)
@@ -159,6 +166,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	mb();
 	ggtt->vm.clear_range(&ggtt->vm, ggtt->error_capture.start, PAGE_SIZE);
 
+	mutex_unlock(&gt->i915->mm.stolen_lock);
+
 	if (count > 0) {
 		pr_info("%s reset clobbered %ld pages of stolen, last clobber at page %ld\n",
 			msg, count, max);
-- 
2.56.1


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

* [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen
  2026-11-18 13:02 [PATCH v6 0/3] drm/i915/selftests: fix stolen reset test races Sebastian Brzezinka
  2026-11-18 13:02 ` [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest Sebastian Brzezinka
@ 2026-11-18 13:02 ` Sebastian Brzezinka
  2026-11-18 13:09   ` sashiko-bot
  2026-11-18 13:02 ` [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test Sebastian Brzezinka
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Brzezinka @ 2026-11-18 13:02 UTC (permalink / raw)
  To: intel-gfx
  Cc: andi.shyti, chris.p.wilson, krzysztof.karas, krzysztof.niemiec,
	Sebastian Brzezinka

The test pokes every page of the DSM, but the hardware reserved region
is not part of mm.stolen and must not be written.

Only scan the usable part of stolen memory (dsm.usable_size) instead of
the whole DSM.

Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
---
 drivers/gpu/drm/i915/gt/selftest_reset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c
index 7d4b0382fe19..09a08a91e610 100644
--- a/drivers/gpu/drm/i915/gt/selftest_reset.c
+++ b/drivers/gpu/drm/i915/gt/selftest_reset.c
@@ -44,7 +44,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	if (!drm_mm_node_allocated(&ggtt->error_capture))
 		return 0;
 
-	num_pages = resource_size(dsm) >> PAGE_SHIFT;
+	num_pages = min_t(resource_size_t, resource_size(dsm),
+			  gt->i915->dsm.usable_size) >> PAGE_SHIFT;
 	if (!num_pages)
 		return 0;
 
-- 
2.56.1


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

* [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test
  2026-11-18 13:02 [PATCH v6 0/3] drm/i915/selftests: fix stolen reset test races Sebastian Brzezinka
  2026-11-18 13:02 ` [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest Sebastian Brzezinka
  2026-11-18 13:02 ` [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen Sebastian Brzezinka
@ 2026-11-18 13:02 ` Sebastian Brzezinka
  2026-11-18 13:13   ` sashiko-bot
  2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Brzezinka @ 2026-11-18 13:02 UTC (permalink / raw)
  To: intel-gfx
  Cc: andi.shyti, chris.p.wilson, krzysztof.karas, krzysztof.niemiec,
	Sebastian Brzezinka

The stolen reset test reads and writes stolen pages through the ggtt
error_capture slot, but it does not take ggtt->error_mutex. The DEBUG_GEM
poisoning of stolen pages, which runs from the object free worker, and
the GPU error capture use the same slot, and both take that mutex.

So the free worker can change the slot while the test is using it, and
part of its poison ends up in the page under test. The page then looks
partly like STACK_MAGIC and partly like POISON_INUSE/POISON_FREE, and the
test wrongly reports that the GPU reset modified stolen memory.

Take ggtt->error_mutex, nested inside stolen_lock, around each sampling
loop. Don't hold it across the reset, as the GuC CT worker can take it
from the error capture path while the reset flushes that worker. Use
raw_insert_page when available, as i915_vma_coredump_create() does.

Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
---
 drivers/gpu/drm/i915/gt/selftest_reset.c | 26 +++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c
index 09a08a91e610..bd5876da6449 100644
--- a/drivers/gpu/drm/i915/gt/selftest_reset.c
+++ b/drivers/gpu/drm/i915/gt/selftest_reset.c
@@ -36,6 +36,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	intel_wakeref_t wakeref;
 	enum intel_engine_id id;
 	struct igt_spinner spin;
+	void (*insert_page)(struct i915_address_space *vm, dma_addr_t addr,
+			    u64 offset, unsigned int pat_index, u32 flags);
 	long max, count;
 	void *tmp;
 	u32 *crc;
@@ -90,18 +92,19 @@ __igt_reset_stolen(struct intel_gt *gt,
 		i915_request_add(rq);
 	}
 
+	insert_page = ggtt->vm.raw_insert_page ?: ggtt->vm.insert_page;
+
 	mutex_lock(&gt->i915->mm.stolen_lock);
 
+	mutex_lock(&ggtt->error_mutex);
 	for (page = 0; page < num_pages; page++) {
 		dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT);
 		void __iomem *s;
 		void *in;
 
-		ggtt->vm.insert_page(&ggtt->vm, dma,
-				     ggtt->error_capture.start,
-				     i915_gem_get_pat_index(gt->i915,
-							    I915_CACHE_NONE),
-				     0);
+		insert_page(&ggtt->vm, dma, ggtt->error_capture.start,
+			    i915_gem_get_pat_index(gt->i915, I915_CACHE_NONE),
+			    0);
 		mb();
 
 		s = io_mapping_map_wc(&ggtt->iomap,
@@ -120,6 +123,7 @@ __igt_reset_stolen(struct intel_gt *gt,
 	}
 	mb();
 	ggtt->vm.clear_range(&ggtt->vm, ggtt->error_capture.start, PAGE_SIZE);
+	mutex_unlock(&ggtt->error_mutex);
 
 	if (mask == ALL_ENGINES) {
 		intel_gt_reset(gt, mask, NULL);
@@ -132,17 +136,17 @@ __igt_reset_stolen(struct intel_gt *gt,
 
 	max = -1;
 	count = 0;
+
+	mutex_lock(&ggtt->error_mutex);
 	for (page = 0; page < num_pages; page++) {
 		dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT);
 		void __iomem *s;
 		void *in;
 		u32 x;
 
-		ggtt->vm.insert_page(&ggtt->vm, dma,
-				     ggtt->error_capture.start,
-				     i915_gem_get_pat_index(gt->i915,
-							    I915_CACHE_NONE),
-				     0);
+		insert_page(&ggtt->vm, dma, ggtt->error_capture.start,
+			    i915_gem_get_pat_index(gt->i915, I915_CACHE_NONE),
+			    0);
 		mb();
 
 		s = io_mapping_map_wc(&ggtt->iomap,
@@ -167,6 +171,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	mb();
 	ggtt->vm.clear_range(&ggtt->vm, ggtt->error_capture.start, PAGE_SIZE);
 
+	mutex_unlock(&ggtt->error_mutex);
+
 	mutex_unlock(&gt->i915->mm.stolen_lock);
 
 	if (count > 0) {
-- 
2.56.1


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

* Re: [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen
  2026-11-18 13:02 ` [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen Sebastian Brzezinka
@ 2026-11-18 13:09   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-18 13:09 UTC (permalink / raw)
  To: Sebastian Brzezinka, intel-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/i915/selftests: missing Fixes trailer for
  __igt_reset_stolen() fix
--

commit b10bdf167e49f764d1b458f21032c5d7c411774c
Author: Sebastian Brzezinka <sebastian.brzezinka@intel.com>

> drm/i915/selftests: Limit stolen reset test to usable stolen
>
> The test pokes every page of the DSM, but the hardware reserved region
> is not part of mm.stolen and must not be written.
>
> Only scan the usable part of stolen memory (dsm.usable_size) instead of
> the whole DSM.
>
> Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>

[Severity: Low]
__igt_reset_stolen() has scanned the entire DSM since it was introduced.
Should this bug fix include:

  Fixes: 3da3c5c1c982 ("drm/i915: Exclude low pages (128KiB) of stolen from use")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/c47b0ea2093da73a92e9e6d62b062f9cc52851d1.1795006734.git.sebastian.brzezinka@intel.com?part=2

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

* Re: [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test
  2026-11-18 13:02 ` [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test Sebastian Brzezinka
@ 2026-11-18 13:13   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-18 13:13 UTC (permalink / raw)
  To: Sebastian Brzezinka, intel-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/i915/selftests: missing Fixes trailer for
  __igt_reset_stolen() race fix
--

commit 2d0178da9e274898248734afa1c912d704b93b76
Author: Sebastian Brzezinka <sebastian.brzezinka@intel.com>

> drm/i915/selftests: take error_mutex in stolen reset test
>
> The stolen reset test reads and writes stolen pages through the ggtt
> error_capture slot, but it does not take ggtt->error_mutex. The DEBUG_GEM
> poisoning of stolen pages, which runs from the object free worker, and
> the GPU error capture use the same slot, and both take that mutex.
>
> So the free worker can change the slot while the test is using it, and
> part of its poison ends up in the page under test. The page then looks
> partly like STACK_MAGIC and partly like POISON_INUSE/POISON_FREE, and the
> test wrongly reports that the GPU reset modified stolen memory.
>
> Take ggtt->error_mutex, nested inside stolen_lock, around each sampling
> loop. Don't hold it across the reset, as the GuC CT worker can take it
> from the error capture path while the reset flushes that worker. Use
> raw_insert_page when available, as i915_vma_coredump_create() does.
>
> Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>

[Severity: Low]
__igt_reset_stolen() has accessed the ggtt->error_capture slot without
holding ggtt->error_mutex since it was added.  Should this include a
Fixes: tag?

  Fixes: 3da3c5c1c982 ("drm/i915: Exclude low pages (128KiB) of stolen from use")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/c47b0ea2093da73a92e9e6d62b062f9cc52851d1.1795006734.git.sebastian.brzezinka@intel.com?part=3

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

* Re: [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest
  2026-11-18 13:02 ` [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest Sebastian Brzezinka
@ 2026-11-18 13:31   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-18 13:31 UTC (permalink / raw)
  To: Sebastian Brzezinka, intel-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/i915/selftests: commit message omits
  __drm_mm_interval_first() check fix
--

commit 7de700f4e6f9ce33a0c4b581db34793a6145c70e
Author: Sebastian Brzezinka <sebastian.brzezinka@intel.com>

drm/i915/selftests: Fix unlocked mm.stolen in reset selftest

This commit acquires gt->i915->mm.stolen_lock around the stolen memory
walk in __igt_reset_stolen() and moves the interval tree lookup into a
stolen_page_unused() helper that compares the result against
&gt->i915->mm.stolen.head_node.

> diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c
> index 3599c9f101e14..8d5f3ef84db55 100644
> --- a/drivers/gpu/drm/i915/gt/selftest_reset.c
> +++ b/drivers/gpu/drm/i915/gt/selftest_reset.c
> @@ -14,6 +14,16 @@
>  #include "selftests/igt_atomic.h"
>  #include "selftests/igt_spinner.h"
>  
> +static bool stolen_page_unused(struct intel_gt *gt, resource_size_t page)
> +{
> +	lockdep_assert_held(&gt->i915->mm.stolen_lock);
> +
> +	return __drm_mm_interval_first(&gt->i915->mm.stolen,
> +					page << PAGE_SHIFT,
> +					((page + 1) << PAGE_SHIFT) - 1) ==
> +	       &gt->i915->mm.stolen.head_node;
> +}

[ ... ]

> @@ -95,9 +107,7 @@ __igt_reset_stolen(struct intel_gt *gt,
>  				      ggtt->error_capture.start,
>  				      PAGE_SIZE);
>  
> -		if (!__drm_mm_interval_first(&gt->i915->mm.stolen,
> -					     page << PAGE_SHIFT,
> -					     ((page + 1) << PAGE_SHIFT) - 1))
> +		if (stolen_page_unused(gt, page))
>  			memset_io(s, STACK_MAGIC, PAGE_SIZE);

[Severity: Low]
Should the commit message also describe the __drm_mm_interval_first()
return-value fix in stolen_page_unused()?

__drm_mm_interval_first() returns &mm->head_node when no interval overlaps
the queried range, so the previous !__drm_mm_interval_first() checks were
always false and __igt_reset_stolen() never poisoned or verified unused
stolen pages.  This functional change is currently only mentioned in the
changelog notes below the "---" separator, which will be stripped when the
patch is applied.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/c47b0ea2093da73a92e9e6d62b062f9cc52851d1.1795006734.git.sebastian.brzezinka@intel.com?part=1

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

end of thread, other threads:[~2026-11-18 13:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:02 [PATCH v6 0/3] drm/i915/selftests: fix stolen reset test races Sebastian Brzezinka
2026-11-18 13:02 ` [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest Sebastian Brzezinka
2026-11-18 13:31   ` sashiko-bot
2026-11-18 13:02 ` [PATCH v6 2/3] drm/i915/selftests: Limit stolen reset test to usable stolen Sebastian Brzezinka
2026-11-18 13:09   ` sashiko-bot
2026-11-18 13:02 ` [PATCH v6 3/3] drm/i915/selftests: take error_mutex in stolen reset test Sebastian Brzezinka
2026-11-18 13:13   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox