Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Maarten Lankhorst <dev@lankhorst.se>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v4 1/6] drm/xe/ggtt: Add xe_ggtt_reserve_area
Date: Thu, 19 Nov 2026 18:27:42 +0200	[thread overview]
Message-ID: <av8jfpzMHgp67fkK@intel.com> (raw)
In-Reply-To: <4fdec542-ca17-4b16-bed3-85c5b650b9cf@lankhorst.se>

On Thu, Nov 19, 2026 at 04:47:17PM +0100, Maarten Lankhorst wrote:
> 
> 
> On 11/19/26 14:48, Ville Syrjälä wrote:
> > On Thu, Nov 19, 2026 at 12:59:55PM +0100, Maarten Lankhorst wrote:
> >> Hey,
> >>
> >> On 11/18/26 21:09, Ville Syrjälä wrote:
> >>> On Mon, Nov 16, 2026 at 01:28:30PM +0100, Maarten Lankhorst wrote:
> >>>> Create a new function xe_ggtt_reserve_area() which will be used
> >>>> for reserving the part of GGTT where the initial framebuffer was
> >>>> allocated, while ensuring the reservation fits within mappable
> >>>> GGTT boundaries.
> >>>>
> >>>> This will allow us to either take over the initial mapping, or
> >>>> reserve it to have the newly allocated GGTT mapping not overwriting
> >>>> the initial mapping, which would cause flickering.
> >>>>
> >>>> Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
> >>>> ---
> >>>>  drivers/gpu/drm/xe/xe_ggtt.c | 69 +++++++++++++++++++++++++++++++++---
> >>>>  drivers/gpu/drm/xe/xe_ggtt.h |  2 ++
> >>>>  2 files changed, 67 insertions(+), 4 deletions(-)
> >>>>
> >>>> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> >>>> index 9ef2ce743770f..ca38d51f41441 100644
> >>>> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> >>>> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
> >>>> @@ -681,14 +681,17 @@ static struct xe_ggtt_node *ggtt_node_init(struct xe_ggtt *ggtt)
> >>>>  }
> >>>>  
> >>>>  /**
> >>>> - * xe_ggtt_insert_node - Insert a &xe_ggtt_node into the GGTT
> >>>> + * xe_ggtt_insert_node_at - Insert a &xe_ggtt_node into the GGTT
> >>>>   * @ggtt: the &xe_ggtt into which the node should be inserted.
> >>>>   * @size: size of the node
> >>>>   * @align: alignment constrain of the node
> >>>> + * @start: Starting offset of range to insert node
> >>>> + * @end: Last offset for node insertion
> >>>>   *
> >>>>   * Return: &xe_ggtt_node on success or a ERR_PTR on failure.
> >>>>   */
> >>>> -struct xe_ggtt_node *xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 align)
> >>>> +static struct xe_ggtt_node *xe_ggtt_insert_node_at(struct xe_ggtt *ggtt, u32 size,
> >>>> +						   u32 align, u64 start, u64 end)
> >>>>  {
> >>>>  	struct xe_ggtt_node *node;
> >>>>  	int ret;
> >>>> @@ -698,8 +701,19 @@ struct xe_ggtt_node *xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 ali
> >>>>  		return node;
> >>>>  
> >>>>  	guard(mutex)(&ggtt->lock);
> >>>> -	ret = xe_ggtt_insert_node_locked(node, size, align,
> >>>> -					 DRM_MM_INSERT_HIGH);
> >>>> +	if (start >= ggtt->start)
> >>>> +		start -= ggtt->start;
> >>>> +	else
> >>>> +		start = 0;
> >>>> +
> >>>> +	/* Should never happen, but since we handle start, fail graciously for end */
> >>>> +	if (end >= ggtt->start)
> >>>> +		end -= ggtt->start;
> >>>> +	else
> >>>> +		end = 0;
> >>>> +
> >>>> +	ret = drm_mm_insert_node_in_range(&ggtt->mm, &node->base, size, align,
> >>>> +					  0, start, end, DRM_MM_INSERT_HIGH);
> >>>>  	if (ret) {
> >>>>  		ggtt_node_fini(node);
> >>>>  		return ERR_PTR(ret);
> >>>> @@ -708,6 +722,53 @@ struct xe_ggtt_node *xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 ali
> >>>>  	return node;
> >>>>  }
> >>>>  
> >>>> +/**
> >>>> + * xe_ggtt_reserve_area - Ensure an area of the GGTT is reserved.
> >>>> + * @ggtt: the &xe_ggtt where the area should be reserved.
> >>>> + * @start: Starting offset of range to reserve
> >>>> + * @size: size of the reservation
> >>>> + *
> >>>> + * This function ensures the area of [start...start+size)
> >>>> + * is reserved, while taking care of any clipping due to start or start+size
> >>>> + * falling outside of the adressable GGTT. The size of the returned node may
> >>>> + * be smaller if part of the region falls outside the accessible GGTT, or a
> >>>> + * NULL node may be returned.
> >>>> + *
> >>>> + * Return: &xe_ggtt_node or NULL on success or a ERR_PTR on failure.
> >>>> + */
> >>>> +struct xe_ggtt_node *xe_ggtt_reserve_area(struct xe_ggtt *ggtt, u32 base, u32 size)
> >>>> +{
> >>>> +	u64 ggtt_start = xe_ggtt_start(ggtt), ggtt_end = ggtt_start + xe_ggtt_size(ggtt);
> >>>> +
> >>>> +	/* Completely truncated? */
> >>>> +	if (base + size <= ggtt_start || base >= ggtt_end)
> >>>> +		return NULL;
> >>>> +
> >>>> +	/* Partially truncated? */
> >>>> +	if (base <= ggtt_start) {
> >>>> +		size -= ggtt_start - base;
> >>>> +		base = ggtt_start;
> >>>> +	}
> >>>> +
> >>>> +	if (base + size >= ggtt_end)
> >>>> +		size = ggtt_end - base;
> >>>
> >>> We seem to be doing the same chop both here and in
> >>> xe_ggtt_insert_node_at(). Isn't one place enough?
> >> They're complementary, and there for different reasons.
> >>
> >> The math in node_at() converts the raw ggtt addresses from [0...full_ggtt_size) to the
> >> range of [0...ggtt_size) in drm_mm_init.
> >>
> >> The truncation in reserve_area is there to physically adjust the size
> >> to fit inside a valid area, or return a NULL node if it's entirely outside it.
> > 
> > I find the whole thing rather confusing. So what we're saying here is
> > that xe_ggtt_insert_node_at() start/end parameters are to be specified 
> > in terms of the full hw ggtt range. And if other users would like to
> > call it, they will potentially have to do the drm_mm->hw range conversion
> > before calling it. If we leave it like this, then I think it really
> > needs to be documented to avoid people shooting themselves in to foot.
> > xe_ggtt_reserve_area() docs should also clearly point out that it 
> > operates on the full hw ggtt range. Right now it's only implied
> > by the statement about clipping.
> > 
> 
> I think you misunderstand.
> 
> When run with SR-IOV VF, the whole GGTT can be moved if the PF suspends,
> and resumes at a different offset.
> 
> This means that ggtt->start is flexible, and can be changed,
> see xe_ggtt_node_addr:
> 
> u64 xe_ggtt_node_addr(const struct xe_ggtt_node *node)
> {
> 	/* pairs with WRITE_ONCE in xe_ggtt_shift_nodes() */
> 	return node->base.start + READ_ONCE(node->ggtt->start);
> }
> 
> What you pass to insert_node_at is in *absolute* GGTT coordinates,
> but are shifted to *relative* coordinates with offset 0 = ggtt->start.

The thing I don't get is *why* are we passing full hw ggtt offsets
to xe_ggtt_insert_node_at(). It takes an arbitrary xe_ggtt
(each VF has its own no?) as its parameter, so at first blush I
would expect the offsets to be specified relative to that 
xe_ggtt's start. The documentation says nothing to convince me
otherwise.

If there is a good reason for passing the full hw ggtt offsets 
to xe_ggtt_insert_node_at() then I think the documentation has
to explicitly point that out. 

> 
> reserve_area also takes absolute GGTT coordinates, but clips them to fit
> inside the area between ggtt->start and end of ggtt. Unlike node_at,
> it adjusts size to fit since it is only meant to prevent the area
> [start...start+size) from being overwritten. If it's outside the
> normally reserved area, this will never happen at all so it is shrunk.

xe_ggtt_reserve_area() of course needs to take the full hw ggtt
offsets. That's the whole point really, to keep xe_ggtt->start
hidden from the display code.

> 
> >>
> >>>
> >>> Sashiko's comments about the 32bit overflow seem potentially valid
> >>> to me. I don't recall how high in the ggtt the GOP now places the
> >>> FB, but if it's at the very top, and there is no extra padding then
> >>> we could have the FB extend all the way to the 4 GiB mark.
> >>>
> >>> We also have a 32bit 'plane_config->base + plane_config->size' in
> >>> both i915 and xe initial plane code, where that overflow would also
> >>> hit us.
> >>>
> >>>> +
> >>>> +	return xe_ggtt_insert_node_at(ggtt, size, XE_PAGE_SIZE, base, base + size);
> >>>> +}
> >>>> +
> >>>> +/**
> >>>> + * xe_ggtt_insert_node - Insert a &xe_ggtt_node into the GGTT
> >>>> + * @ggtt: the &xe_ggtt into which the node should be inserted.
> >>>> + * @size: size of the node
> >>>> + * @align: alignment constrain of the node
> >>>> + *
> >>>> + * Return: &xe_ggtt_node on success or a ERR_PTR on failure.
> >>>> + */
> >>>> +struct xe_ggtt_node *xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 align)
> >>>> +{
> >>>> +	return xe_ggtt_insert_node_at(ggtt, size, align, 0, ~0ULL);
> >>>> +}
> >>>> +
> >>>>  /**
> >>>>   * xe_ggtt_node_pt_size() - Get the size of page table entries needed to map a GGTT node.
> >>>>   * @node: the &xe_ggtt_node
> >>>> diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
> >>>> index c864cc975a695..15e62ecec2287 100644
> >>>> --- a/drivers/gpu/drm/xe/xe_ggtt.h
> >>>> +++ b/drivers/gpu/drm/xe/xe_ggtt.h
> >>>> @@ -22,6 +22,8 @@ void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, u64 new_base);
> >>>>  u64 xe_ggtt_start(struct xe_ggtt *ggtt);
> >>>>  u64 xe_ggtt_size(struct xe_ggtt *ggtt);
> >>>>  
> >>>> +struct xe_ggtt_node *
> >>>> +xe_ggtt_reserve_area(struct xe_ggtt *ggtt, u32 base, u32 size);
> >>>>  struct xe_ggtt_node *
> >>>>  xe_ggtt_insert_node(struct xe_ggtt *ggtt, u32 size, u32 align);
> >>>>  struct xe_ggtt_node *
> >>>> -- 
> >>>> 2.55.0
> >>>
> > 

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2026-11-19 16:28 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 12:28 [PATCH v4 0/6] drm/xe: More BIOS FB takeover fixes Maarten Lankhorst
2026-11-16 12:28 ` [PATCH v4 1/6] drm/xe/ggtt: Add xe_ggtt_reserve_area Maarten Lankhorst
2026-11-16 12:38   ` sashiko-bot
2026-11-18 20:09   ` Ville Syrjälä
2026-11-19 11:59     ` Maarten Lankhorst
2026-11-19 13:48       ` Ville Syrjälä
2026-11-19 15:47         ` Maarten Lankhorst
2026-11-19 16:27           ` Ville Syrjälä [this message]
2026-11-16 12:28 ` [PATCH v4 2/6] drm/xe/ggtt: Add xe_ggtt_node_remove_noclear Maarten Lankhorst
2026-11-16 12:28 ` [PATCH v4 3/6] drm/xe/display: Reserve the original GGTT space before creating a bo Maarten Lankhorst
2026-11-18 20:38   ` Ville Syrjälä
2026-11-16 12:28 ` [PATCH v4 4/6] drm/xe/display: Use the correct calculation for phys_base on integrated Maarten Lankhorst
2026-11-16 12:49   ` sashiko-bot
2026-11-18 20:32   ` Ville Syrjälä
2026-11-19 11:31     ` Maarten Lankhorst
2026-11-16 12:28 ` [PATCH v4 5/6] drm/xe/display: Remove duplicated code Maarten Lankhorst
2026-11-16 12:56   ` sashiko-bot
2026-11-18 20:14     ` Ville Syrjälä
2026-11-16 12:28 ` [PATCH v4 6/6] drm/xe/ggtt: Remove xe_ggtt_insert_bo_at Maarten Lankhorst
2026-11-18 20:13   ` Ville Syrjälä
2026-11-16 14:40 ` ✗ CI.checkpatch: warning for drm/xe: More BIOS FB takeover fixes (rev5) Patchwork
2026-11-16 14:43 ` ✓ CI.KUnit: success " Patchwork
2026-11-16 15:17 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-16 23:16 ` ✗ Xe.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=av8jfpzMHgp67fkK@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dev@lankhorst.se \
    --cc=intel-xe@lists.freedesktop.org \
    /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