Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maarten Lankhorst" <dev@lankhorst.se>, intel-xe@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v6 5/5] drm/i915: Introduce intel_bo_fbdev_bios_fb_takeover()
Date: Tue, 17 Nov 2026 15:45:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-219104@kernel.org> (raw)
In-Reply-To: <20261117143038.479557-12-dev@lankhorst.se>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] drm/i915/fbdev: deferred BIOS FB takeover breaks FBC and
  drm_panic
- [Medium] drm/xe/display: missing fence wait in
  xe_display_bo_fbdev_bios_fb_takeover()
- [Medium] drm/xe/display: unconditional return false in
  xe_display_bo_fbdev_prefer_stolen()
- [Medium] drm/i915/fbdev: double unpin on error in
  __intel_fbdev_fb_realloc()
- [Low] drm/i915/fbdev: commit message mismatch on bios_fb_ok() rename
--

commit 9269db9d41cf2915da41de1cbfd42a10b2dd2198
Author: Maarten Lankhorst <dev@lankhorst.se>

drm/i915: Introduce intel_bo_fbdev_bios_fb_takeover()

This commit defers the decision to keep or replace a stolen-memory BIOS
framebuffer from initial plane readout to fbdev probing via a new
intel_bo_fbdev_bios_fb_takeover() parent interface callback, copying the
BIOS framebuffer to system memory with the blitter on Xe when stolen
memory is not preferred.

> Additionally, bios_fb_ok() was renamed
> to bios_fb_takeover() with a different function signature.

[Severity: Low]
This isn't a bug, but bios_fb_ok() is kept unchanged in intel_fbdev.c while
intel_fbdev_fb_takeover() and intel_bo_fbdev_bios_fb_takeover() are added
alongside it.

[ ... ]

> diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.c b/drivers/gpu/drm/i915/display/intel_fbdev.c
> index 219ee17de3f68..31f4dd2660c07 100644
> --- a/drivers/gpu/drm/i915/display/intel_fbdev.c
> +++ b/drivers/gpu/drm/i915/display/intel_fbdev.c
> @@ -262,6 +262,50 @@ __intel_fbdev_fb_alloc(struct intel_display *display,
>  
>  }
>  
> +static struct intel_framebuffer *
> +__intel_fbdev_fb_realloc(struct intel_display *display,
> +			 const struct drm_framebuffer *orig_fb,
> +			 struct drm_gem_object *obj)
> +{
> +	struct drm_framebuffer *new_fb;
> +	struct drm_mode_fb_cmd2 mode_cmd = {
> +		.flags = DRM_MODE_FB_MODIFIERS,
> +		.width = orig_fb->width,
> +		.height = orig_fb->height,
> +		.pitches[0] = orig_fb->pitches[0],
> +		.offsets[0] = orig_fb->offsets[0],
> +		.pixel_format = orig_fb->format->format,
> +		.modifier[0] = orig_fb->modifier,
> +	};
> +
> +	new_fb = intel_framebuffer_create(obj, orig_fb->format, &mode_cmd);
> +
> +	if (IS_ERR(new_fb)) {
> +		intel_bo_fbdev_destroy(obj);
> +		return ERR_CAST(new_fb);
> +	}

[Severity: Medium]
Can this error path unpin obj twice on Xe when intel_framebuffer_create()
fails after intel_bo_framebuffer_init()?

xe_display_bo_fbdev_bios_fb_takeover() allocates copy_bo via
xe_bo_create_pin_map_novm() with XE_BO_FLAG_PINNED set and pin_count == 1.
Inside intel_framebuffer_init(), xe_display_bo_framebuffer_init() takes a
reference on the BO without pinning it, but if a later step in
intel_framebuffer_init() fails (such as drm_framebuffer_init()), its error
unwind calls intel_bo_framebuffer_fini() -> xe_display_bo_framebuffer_fini():

drivers/gpu/drm/xe/display/xe_display_bo.c:xe_display_bo_framebuffer_fini() {
	struct xe_bo *bo = gem_to_xe_bo(obj);

	if (bo->flags & XE_BO_FLAG_PINNED) {
		/* Unpin our kernel fb first */
		xe_bo_lock(bo, false);
		xe_bo_unpin(bo);
		xe_bo_unlock(bo);
	}
	xe_bo_put(bo);
}

intel_bo_fbdev_destroy() -> xe_bo_unpin_map_no_vm() then calls
xe_bo_unpin() a second time on copy_bo, triggering the pinned assertions in
xe_bo_unpin() and WARN_ON_ONCE(!bo->pin_count) in ttm_bo_unpin().

> +
> +	drm_gem_object_put(obj);
> +	return to_intel_framebuffer(new_fb);
> +}

[ ... ]

> @@ -305,13 +349,26 @@ int intel_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,
>  
>  	ifbdev->fb = NULL;
>  
> -	if (fb && !bios_fb_ok(fb, sizes)) {
> +	wakeref = intel_display_rpm_get(display);
> +
> +	if (fb && bios_fb_ok(fb, sizes)) {
> +		struct intel_framebuffer *bios_fb =
> +			intel_fbdev_fb_takeover(display, fb);
> +
> +		if (IS_ERR(bios_fb)) {
> +			drm_dbg_kms(display->drm, "Re-using BIOS fb failed (%pe).", bios_fb);
> +			bios_fb = NULL;
> +		}
> +
> +		if (fb != bios_fb) {
> +			drm_framebuffer_put(&fb->base);
> +			fb = bios_fb;
> +		}
> +	} else if (fb) {
>  		drm_framebuffer_put(&fb->base);
>  		fb = NULL;
>  	}

[Severity: Medium]
Does deferring the stolen-memory check to intel_fbdev_driver_fbdev_probe()
and swapping ifbdev->fb without a plane commit regress FBC, stolen-memory
workarounds, and drm_panic?

Because initial_plane_vma() and initial_plane_bo() now unconditionally wrap
the BIOS framebuffer in stolen memory, it remains allocated during
intel_initial_commit() before intel_fbdev_setup() runs.  When the BIOS
framebuffer occupies more than half of stolen memory, intel_fbc_alloc_cfb()
-> find_compression_limit() during intel_initial_commit() either fails with
-ENOSPC or permanently degrades fbc->limit to 1:2 or 1:4, as
intel_fbc_is_cfb_ok() does not upgrade the CFB once the stolen BIOS
framebuffer is freed.

In addition, when intel_fbdev_fb_takeover() replaces the stolen framebuffer
with a system-memory framebuffer, drm_framebuffer_put(&fb->base) only drops
ifbdev->fb's reference; the active primary plane's plane_state->uapi.fb and
plane_state->hw.fb still hold the original stolen framebuffer until an
atomic commit flips the plane.  When
CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y or
CONFIG_FRAMEBUFFER_CONSOLE=n, register_framebuffer() returns without
calling fb_set_par(), leaving the hardware plane scanning out the stolen
framebuffer (and leaving MTL Wa_22018444074, Xe Wa_22019338487_display, and
media GT MC6 latency unmitigated) while ifbdev->fb and /dev/fb0 point to
the new system-memory buffer.

While plane_state->hw.fb still points to the stolen BIOS framebuffer and
display->fbdev.fbdev->fb points to the replacement framebuffer,
intel_get_scanout_buffer() also no longer matches
intel_fbdev_framebuffer(display->fbdev.fbdev) and falls back to
intel_parent_panic_setup() on the stolen BO, which fails on both i915 and
Xe.

[ ... ]

> diff --git a/drivers/gpu/drm/xe/display/xe_display_bo.c b/drivers/gpu/drm/xe/display/xe_display_bo.c
> index d78d893210c4f..43d05a58bcb47 100644
> --- a/drivers/gpu/drm/xe/display/xe_display_bo.c
> +++ b/drivers/gpu/drm/xe/display/xe_display_bo.c
> @@ -120,7 +121,7 @@ static u32 xe_display_bo_fbdev_pitch_align(u32 stride)
>  	return ALIGN(stride, XE_PAGE_SIZE);
>  }
>  
> -bool xe_display_bo_fbdev_prefer_stolen(struct xe_device *xe, unsigned int size)
> +static bool xe_display_bo_fbdev_prefer_stolen(struct xe_device *xe, unsigned int size)
>  {
>  	struct ttm_resource_manager *stolen;
>  
> @@ -152,6 +153,64 @@ bool xe_display_bo_fbdev_prefer_stolen(struct xe_device *xe, unsigned int size)
>  	return stolen->size >= (size * 2) >> PAGE_SHIFT;
>  }
>  
> +static struct drm_gem_object *xe_display_bo_fbdev_bios_fb_takeover(struct drm_gem_object *obj)
> +{
> +	struct xe_bo *orig_bo = gem_to_xe_bo(obj), *copy_bo;
> +	struct xe_device *xe = xe_bo_device(orig_bo);
> +	struct xe_validation_ctx ctx;
> +	struct drm_exec exec;
> +	int err;
> +
> +	if (IS_DGFX(xe) ||
> +	    xe_display_bo_fbdev_prefer_stolen(xe, xe_bo_size(orig_bo)))
> +		return obj;

[Severity: Medium]
Does xe_display_bo_fbdev_prefer_stolen() unconditionally return false here?

Earlier commit "HACK: Always fallback" in this series left an unconditional
"return false;" right before the size check in
xe_display_bo_fbdev_prefer_stolen():

drivers/gpu/drm/xe/display/xe_display_bo.c:xe_display_bo_fbdev_prefer_stolen() {
    ...
	/* machine hang when doing lots of LMEMBAR accesses */
	if (XE_DEVICE_WA(xe, 22019338487_display))
		return false;

	return false;

	/*
	 * If the FB is too big, just don't use it since fbdev is not very
	 * important and we should probably use that space with FBC or other
	 * features.
	 */
	return stolen->size >= (size * 2) >> PAGE_SHIFT;
}

Because of that statement, the stolen size check is unreachable and
xe_display_bo_fbdev_bios_fb_takeover() always rejects stolen memory on
every integrated Xe platform.

> +
> +	copy_bo = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), xe_bo_size(orig_bo),
> +					    ttm_bo_type_kernel,
> +					    XE_BO_FLAG_FORCE_WC | XE_BO_FLAG_SYSTEM | XE_BO_FLAG_GGTT,
> +					    false);
> +	if (IS_ERR(copy_bo))
> +		return ERR_CAST(copy_bo);
> +
> +	xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {}, err) {
> +		struct dma_fence *fence;
> +
> +		err = drm_exec_lock_obj(&exec, &orig_bo->ttm.base);
> +		drm_exec_retry_on_contention(&exec);
> +		if (err)
> +			break;
> +
> +		err = drm_exec_lock_obj(&exec, &copy_bo->ttm.base);
> +		drm_exec_retry_on_contention(&exec);
> +		if (err)
> +			break;
> +
> +		err = dma_resv_reserve_fences(orig_bo->ttm.base.resv, 1);
> +		if (err)
> +			break;
> +
> +		err = dma_resv_reserve_fences(copy_bo->ttm.base.resv, 1);
> +		if (err)
> +			break;
> +
> +		fence = xe_migrate_copy(xe_device_get_root_tile(xe)->migrate, orig_bo, copy_bo,
> +					orig_bo->ttm.resource, copy_bo->ttm.resource, false);
> +		if (IS_ERR(fence)) {
> +			err = PTR_ERR(fence);
> +			break;
> +		}
> +
> +		dma_resv_add_fence(copy_bo->ttm.base.resv, fence, DMA_RESV_USAGE_KERNEL);
> +		dma_resv_add_fence(orig_bo->ttm.base.resv, fence, DMA_RESV_USAGE_BOOKKEEP);
> +		dma_fence_put(fence);\n+\n+\t\treturn &copy_bo->ttm.base;\n+\t}

[Severity: Medium]
Can CPU accesses to info->screen_base race with the asynchronous
xe_migrate_copy() blit into copy_bo?

copy_bo is created already pinned via xe_bo_create_pin_map_novm(), so when
intel_fbdev_driver_fbdev_probe() subsequently calls
intel_parent_fb_pin_ggtt_pin() -> __xe_pin_fb_vma() -> xe_bo_validate(),
xe_bo_validate() returns early because xe_bo_is_pinned(copy_bo) is true
without waiting on copy_bo's reservation fences.
intel_bo_fbdev_fill_info() then exposes copy_bo->vmap.vaddr_iomem as
info->screen_base and register_framebuffer() registers /dev/fb0.  If
fb_set_par() is not called immediately (for example with
CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y) or if
drm_client_modeset_commit() in drm_fb_helper_set_par() returns -EBUSY,
nothing waits for fence before CPU reads or writes hit info->screen_base,
allowing the in-flight GPU blit to overwrite newly rendered fbdev pixels or
expose incomplete copy data.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117143038.479557-7-dev@lankhorst.se?part=5

  reply	other threads:[~2026-11-17 15:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 14:30 [PATCH v6 0/5] drm/xe/display: Transparant fallback from stolen to sysmem Maarten Lankhorst
2026-11-17 14:30 ` [PATCH v6 1/5] drm/xe/display: Avoid using stolen memory for framebuffer when media gt exists Maarten Lankhorst
2026-11-17 14:30 ` [PATCH v6 2/5] drm/xe/migrate: Support copying between sysmem and stolen Maarten Lankhorst
2026-11-17 14:30 ` [PATCH v6 3/5] drm/xe: Raise gt frequency slightly earlier Maarten Lankhorst
2026-11-17 14:30 ` [PATCH v6 4/5] HACK: Always fallback Maarten Lankhorst
2026-11-17 15:09   ` sashiko-bot
2026-11-17 14:30 ` [PATCH v6 5/5] drm/i915: Introduce intel_bo_fbdev_bios_fb_takeover() Maarten Lankhorst
2026-11-17 15:45   ` sashiko-bot [this message]
2026-11-17 19:31     ` Maarten Lankhorst
2026-11-17 17:07 ` ✓ i915.CI.BAT: success for drm/xe/display: Transparant fallback from stolen to sysmem. (rev6) Patchwork
2026-11-17 19:17 ` ✗ 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=sashiko-outbox-219104@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dev@lankhorst.se \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox