All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Sebastian Brzezinka" <sebastian.brzezinka@intel.com>
To: Krzysztof Karas <krzysztof.karas@intel.com>,
	Sebastian Brzezinka <sebastian.brzezinka@intel.com>
Cc: <intel-gfx@lists.freedesktop.org>, <andi.shyti@linux.intel.com>,
	<chris.p.wilson@intel.com>, <krzysztof.niemiec@intel.com>
Subject: Re: [PATCH v6 1/3] drm/i915/selftests: Fix unlocked mm.stolen in reset selftest
Date: Thu, 19 Nov 2026 11:32:09 +0100	[thread overview]
Message-ID: <DMZ4ACDNRWED.LAR9KL21OIDK@intel.com> (raw)
In-Reply-To: <dveqarxlsulf7nwrfjgolsp5ntcqlhkbziwsyth5pdzqeiqlrc@znzrnadm3rie>

Hi,

On Wed Nov 18, 2026 at 4:23 PM CET, Krzysztof Karas wrote:
> Hi Sebastian,
>
> On 2026-11-18 at 14:02:18 +0100, Sebastian Brzezinka wrote:
>> _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)
> You forgot about the changelog for this version :)
This series started as a single patch. When I split it into a series,
I moved the changelog to the cover letter.

>
> Not critical, so:
> Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
>
>> ---
>>  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
>> 





-- 
Best regards,
Sebastian


  reply	other threads:[~2026-11-19 10:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 15:23   ` Krzysztof Karas
2026-11-19 10:32     ` Sebastian Brzezinka [this message]
2026-11-19 14:48       ` Krzysztof Karas
2026-11-19 15:07   ` Krzysztof Niemiec
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 15:24   ` Krzysztof Karas
2026-11-19 15:12   ` Krzysztof Niemiec
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
2026-11-18 15:34   ` Krzysztof Karas
2026-11-19 10:45     ` Sebastian Brzezinka
2026-11-19 10:58       ` Andi Shyti
2026-11-19 11:06         ` Sebastian Brzezinka
2026-11-19 14:46           ` Krzysztof Karas
2026-11-19 15:11           ` Krzysztof Niemiec
2026-11-18 17:29 ` ✗ i915.CI.BAT: failure for drm/i915/selftests: fix stolen reset test races Patchwork
2026-11-19  8:26 ` ✓ i915.CI.BAT: success for drm/i915/selftests: fix stolen reset test races (rev2) Patchwork
2026-11-19 18:53 ` ✗ i915.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DMZ4ACDNRWED.LAR9KL21OIDK@intel.com \
    --to=sebastian.brzezinka@intel.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=chris.p.wilson@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=krzysztof.karas@intel.com \
    --cc=krzysztof.niemiec@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.