public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: Tejas Upadhyay <tejas.upadhyay@intel.com>,
	intel-xe@lists.freedesktop.org
Cc: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com,
	himal.prasad.ghimiray@intel.com
Subject: Re: [RFC PATCH V7 2/9] drm/gpu: Add gpu_buddy_addr_to_block helper
Date: Mon, 13 Apr 2026 14:28:54 +0100	[thread overview]
Message-ID: <2d928829-8627-4535-9a68-f0fd6882e64b@intel.com> (raw)
In-Reply-To: <20260413131623.2891528-13-tejas.upadhyay@intel.com>

On 13/04/2026 14:16, Tejas Upadhyay wrote:
> Add helper with primary purpose is to efficiently trace a specific
> physical memory address back to its corresponding TTM buffer object.
> 
> Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>

I think you missed the feedback from the prev revision?

> ---
>   drivers/gpu/buddy.c       | 56 +++++++++++++++++++++++++++++++++++++++
>   include/linux/gpu_buddy.h |  2 ++
>   2 files changed, 58 insertions(+)
> 
> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index 52686672e99f..2d26c2a0f971 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c
> @@ -589,6 +589,62 @@ void gpu_buddy_free_block(struct gpu_buddy *mm,
>   }
>   EXPORT_SYMBOL(gpu_buddy_free_block);
>   
> +/**
> + * gpu_buddy_addr_to_block - given physical address find a block
> + *
> + * @mm: GPU buddy manager
> + * @addr: Physical address
> + *
> + * Returns:
> + * gpu_buddy_block on success, NULL or error code on failure
> + */
> +struct gpu_buddy_block *gpu_buddy_addr_to_block(struct gpu_buddy *mm, u64 addr)
> +{
> +	struct gpu_buddy_block *block;
> +	LIST_HEAD(dfs);
> +	u64 end;
> +	int i;
> +
> +	end = addr + SZ_4K - 1;
> +	for (i = 0; i < mm->n_roots; ++i)
> +		list_add_tail(&mm->roots[i]->tmp_link, &dfs);
> +
> +	do {
> +		u64 block_start;
> +		u64 block_end;
> +
> +		block = list_first_entry_or_null(&dfs,
> +						 struct gpu_buddy_block,
> +						 tmp_link);
> +		if (!block)
> +			break;
> +
> +		list_del(&block->tmp_link);
> +
> +		block_start = gpu_buddy_block_offset(block);
> +		block_end = block_start + gpu_buddy_block_size(mm, block) - 1;
> +
> +		if (!overlaps(addr, end, block_start, block_end))
> +			continue;
> +
> +		if (contains(addr, end, block_start, block_end) &&
> +		    !gpu_buddy_block_is_split(block)) {
> +			if (gpu_buddy_block_is_free(block))
> +				return NULL;
> +			else if (gpu_buddy_block_is_allocated(block) && !mm->clear_avail)
> +				return block;
> +		}
> +
> +		if (gpu_buddy_block_is_split(block)) {
> +			list_add(&block->right->tmp_link, &dfs);
> +			list_add(&block->left->tmp_link, &dfs);
> +		}
> +	} while (1);
> +
> +	return ERR_PTR(-ENXIO);
> +}
> +EXPORT_SYMBOL(gpu_buddy_addr_to_block);
> +
>   static void __gpu_buddy_free_list(struct gpu_buddy *mm,
>   				  struct list_head *objects,
>   				  bool mark_clear,
> diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h
> index 5fa917ba5450..957c69c560bc 100644
> --- a/include/linux/gpu_buddy.h
> +++ b/include/linux/gpu_buddy.h
> @@ -231,6 +231,8 @@ void gpu_buddy_reset_clear(struct gpu_buddy *mm, bool is_clear);
>   
>   void gpu_buddy_free_block(struct gpu_buddy *mm, struct gpu_buddy_block *block);
>   
> +struct gpu_buddy_block *gpu_buddy_addr_to_block(struct gpu_buddy *mm, u64 addr);
> +
>   void gpu_buddy_free_list(struct gpu_buddy *mm,
>   			 struct list_head *objects,
>   			 unsigned int flags);


  reply	other threads:[~2026-04-13 13:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 13:16 [RFC PATCH V7 0/9] Add memory page offlining support Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 1/9] drm/xe: Link VRAM object with gpu buddy Tejas Upadhyay
2026-04-30  3:50   ` Matthew Brost
2026-04-13 13:16 ` [RFC PATCH V7 2/9] drm/gpu: Add gpu_buddy_addr_to_block helper Tejas Upadhyay
2026-04-13 13:28   ` Matthew Auld [this message]
2026-04-13 17:30   ` Matthew Auld
2026-04-14  5:36     ` Upadhyay, Tejas
2026-04-13 13:16 ` [RFC PATCH V7 3/9] drm/xe: Link LRC BO and its execution Queue Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 4/9] drm/xe: Extend BO purge to handle vram pages as well Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 5/9] drm/xe: Handle physical memory address error Tejas Upadhyay
2026-04-30 11:28   ` Matthew Auld
2026-05-04 10:52     ` Upadhyay, Tejas
2026-04-13 13:16 ` [RFC PATCH V7 6/9] drm/xe/cri: Add debugfs to inject faulty vram address Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 7/9] gpu/buddy: Add routine to dump allocated buddy blocks Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 8/9] drm/xe/configfs: Add vram bad page reservation policy Tejas Upadhyay
2026-04-13 13:16 ` [RFC PATCH V7 9/9] drm/xe/cri: Add sysfs interface for bad gpu vram pages Tejas Upadhyay
2026-04-13 16:36 ` ✗ CI.checkpatch: warning for Add memory page offlining support (rev7) Patchwork
2026-04-13 16:37 ` ✓ CI.KUnit: success " Patchwork
2026-04-13 17:43 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-13 20:12 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-04-15 15:10 ` [RFC PATCH V7 0/9] Add memory page offlining support Upadhyay, Tejas

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=2d928829-8627-4535-9a68-f0fd6882e64b@intel.com \
    --to=matthew.auld@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=tejas.upadhyay@intel.com \
    --cc=thomas.hellstrom@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox