From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Maarten Lankhorst <dev@lankhorst.se>, <intel-xe@lists.freedesktop.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Subject: Re: [PATCH v4 4/5] drm/xe: Make xe_ggtt_node_insert return a node
Date: Wed, 14 Jan 2026 00:12:00 +0100 [thread overview]
Message-ID: <f81a2bbc-7528-468a-b150-dea8c487b553@intel.com> (raw)
In-Reply-To: <20260113121807.1303124-5-dev@lankhorst.se>
On 1/13/2026 1:18 PM, Maarten Lankhorst wrote:
> This extra step is easier to handle inside xe_ggtt.c and makes
> xe_ggtt_node_allocated a simple null check instead, as the intermediate
> state 'allocated but not inserted' is no longer used.
>
> Privatize xe_ggtt_node_fini() as it's no longer used outside of
> xe_ggtt.c
>
> Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
> Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> ---
> drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c | 6 +-
> drivers/gpu/drm/xe/xe_ggtt.c | 76 +++++++++------------
> drivers/gpu/drm/xe/xe_ggtt.h | 5 +-
> drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 24 +------
> 4 files changed, 38 insertions(+), 73 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> index acddbedcf17cb..7aeee6680d78c 100644
> --- a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> +++ b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
> @@ -38,12 +38,8 @@ static struct xe_bo *replacement_xe_managed_bo_create_pin_map(struct xe_device *
> if (flags & XE_BO_FLAG_GGTT) {
> struct xe_ggtt *ggtt = tile->mem.ggtt;
>
> - bo->ggtt_node[tile->id] = xe_ggtt_node_init(ggtt);
> + bo->ggtt_node[tile->id] = xe_ggtt_node_insert(ggtt, xe_bo_size(bo), SZ_4K);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bo->ggtt_node[tile->id]);
> -
> - KUNIT_ASSERT_EQ(test, 0,
> - xe_ggtt_node_insert(bo->ggtt_node[tile->id],
> - xe_bo_size(bo), SZ_4K));
> }
>
> return bo;
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> index 85babe7ab43a0..7538ba13cbab7 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
> @@ -459,6 +459,11 @@ static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)
> mutex_unlock(&ggtt->lock);
> }
>
> +static void xe_ggtt_node_fini(struct xe_ggtt_node *node)
> +{
> + kfree(node);
> +}
> +
> static void ggtt_node_remove(struct xe_ggtt_node *node)
> {
> struct xe_ggtt *ggtt = node->ggtt;
> @@ -614,68 +619,51 @@ static int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
> mm_flags);
> }
>
> +static struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt)
> +{
> + struct xe_ggtt_node *node = kzalloc(sizeof(*node), GFP_NOFS);
> +
> + if (!node)
> + return ERR_PTR(-ENOMEM);
> +
> + INIT_WORK(&node->delayed_removal_work, ggtt_node_remove_work_func);
> + node->ggtt = ggtt;
> +
> + return node;
> +}
> +
> /**
> * xe_ggtt_node_insert - Insert a &xe_ggtt_node into the GGTT
> - * @node: the &xe_ggtt_node to be inserted
> + * @ggtt: the @ggtt into which the node should be inserted.
> * @size: size of the node
> * @align: alignment constrain of the node
> *
> - * It cannot be called without first having called xe_ggtt_init() once.
> - *
> - * Return: 0 on success or a negative error code on failure.
> + * Return: &xe_ggtt_node on success or a ERR_PTR on failure.
> */
> -int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align)
> +struct xe_ggtt_node *xe_ggtt_node_insert(struct xe_ggtt *ggtt, u32 size, u32 align)
this should be now called:
xe_ggtt_insert_node(ggtt, ...)
as it doesn't take a node param any more
> {
> + struct xe_ggtt_node *node;
> int ret;
>
> - if (!node || !node->ggtt)
> - return -ENOENT;
> + if (!ggtt)
> + return ERR_PTR(-ENOENT);
can't we drop this?
we don't expect this function be called with NULL
or after we fail to allocate xe_ggtt
> +
> + node = xe_ggtt_node_init(ggtt);
> + if (IS_ERR(node))
> + return node;
>
> mutex_lock(&node->ggtt->lock);
we can now use:
mutex_lock(&ggtt->lock);
> ret = xe_ggtt_node_insert_locked(node, size, align,
> DRM_MM_INSERT_HIGH);
> mutex_unlock(&node->ggtt->lock);
> -
> - return ret;
> -}
> -
> -/**
> - * xe_ggtt_node_init - Initialize %xe_ggtt_node struct
> - * @ggtt: the &xe_ggtt where the new node will later be inserted/reserved.
> - *
> - * This function will allocate the struct %xe_ggtt_node and return its pointer.
> - * This struct will then be freed after the node removal upon xe_ggtt_node_remove()
> - * Having %xe_ggtt_node struct allocated doesn't mean that the node is already allocated
> - * in GGTT. Only xe_ggtt_node_insert() will ensure the node is inserted or reserved in GGTT.
> - *
> - * Return: A pointer to %xe_ggtt_node struct on success. An ERR_PTR otherwise.
> - **/
> -struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt)
> -{
> - struct xe_ggtt_node *node = kzalloc(sizeof(*node), GFP_NOFS);
> -
> - if (!node)
> - return ERR_PTR(-ENOMEM);
> -
> - INIT_WORK(&node->delayed_removal_work, ggtt_node_remove_work_func);
> - node->ggtt = ggtt;
> + if (ret) {
> + xe_ggtt_node_fini(node);
> + return ERR_PTR(ret);
> + }
>
> return node;
> }
>
> -/**
> - * xe_ggtt_node_fini - Forcebly finalize %xe_ggtt_node struct
> - * @node: the &xe_ggtt_node to be freed
> - *
> - * If anything went wrong with either xe_ggtt_node_insert() and this @node is
> - * not going to be reused, then this function needs to be called to free the
> - * %xe_ggtt_node struct
> - **/
> -void xe_ggtt_node_fini(struct xe_ggtt_node *node)
> -{
> - kfree(node);
> -}
> -
> /**
> * xe_ggtt_node_allocated - Check if node is allocated in GGTT
> * @node: the &xe_ggtt_node to be inspected
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
> index 403eb5c0db49d..6d8679bcc38fb 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.h
> +++ b/drivers/gpu/drm/xe/xe_ggtt.h
> @@ -18,13 +18,12 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt);
> int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 reserved, u32 size);
> int xe_ggtt_init(struct xe_ggtt *ggtt);
>
> -struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt);
> -void xe_ggtt_node_fini(struct xe_ggtt_node *node);
> 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);
>
> -int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align);
> +struct xe_ggtt_node *
> +xe_ggtt_node_insert(struct xe_ggtt *ggtt, u32 size, u32 align);
> struct xe_ggtt_node *
> xe_ggtt_node_insert_transform(struct xe_ggtt *ggtt,
> struct xe_bo *bo, u64 pte,
> diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> index 9f2525f3cb379..a6414d164166e 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> @@ -484,23 +484,9 @@ static int pf_distribute_config_ggtt(struct xe_tile *tile, unsigned int vfid, u6
> return err ?: err2;
> }
>
> -static void pf_release_ggtt(struct xe_tile *tile, struct xe_ggtt_node *node)
> -{
> - if (xe_ggtt_node_allocated(node)) {
> - /*
> - * explicit GGTT PTE assignment to the PF using xe_ggtt_assign()
> - * is redundant, as PTE will be implicitly re-assigned to PF by
> - * the xe_ggtt_clear() called by below xe_ggtt_remove_node().
> - */
> - xe_ggtt_node_remove(node, false);
> - } else {
> - xe_ggtt_node_fini(node);
> - }
> -}
> -
> static void pf_release_vf_config_ggtt(struct xe_gt *gt, struct xe_gt_sriov_config *config)
> {
> - pf_release_ggtt(gt_to_tile(gt), config->ggtt_region);
> + xe_ggtt_node_remove(config->ggtt_region, false);
> config->ggtt_region = NULL;
> }
>
> @@ -535,14 +521,10 @@ static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
> if (!size)
> return 0;
>
> - node = xe_ggtt_node_init(ggtt);
> + node = xe_ggtt_node_insert(ggtt, size, alignment);
> if (IS_ERR(node))
> return PTR_ERR(node);
>
> - err = xe_ggtt_node_insert(node, size, alignment);
> - if (unlikely(err))
> - goto err;
> -
> xe_ggtt_assign(node, vfid);
> xe_gt_sriov_dbg_verbose(gt, "VF%u assigned GGTT %llx-%llx\n",
> vfid, xe_ggtt_node_addr(node), xe_ggtt_node_addr(node) + size - 1);
> @@ -554,7 +536,7 @@ static int pf_provision_vf_ggtt(struct xe_gt *gt, unsigned int vfid, u64 size)
> config->ggtt_region = node;
> return 0;
> err:
> - pf_release_ggtt(tile, node);
> + xe_ggtt_node_remove(node, false);
> return err;
> }
>
next prev parent reply other threads:[~2026-01-13 23:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-13 12:18 [PATCH v4 0/5] drm/xe: Privatize struct xe_ggtt Maarten Lankhorst
2026-01-13 12:18 ` [PATCH v4 1/5] drm/xe: Make xe_ggtt_node offset relative to starting offset Maarten Lankhorst
2026-01-13 22:07 ` Michal Wajdeczko
2026-01-14 9:48 ` Maarten Lankhorst
2026-01-13 12:18 ` [PATCH v4 2/5] drm/xe: Rewrite GGTT VF initialisation Maarten Lankhorst
2026-01-13 22:53 ` Michal Wajdeczko
2026-01-14 9:55 ` Maarten Lankhorst
2026-01-14 16:15 ` Piotr Piórkowski
2026-01-14 17:03 ` Maarten Lankhorst
2026-01-13 12:18 ` [PATCH v4 3/5] drm/xe: Move struct xe_ggtt to xe_ggtt.c Maarten Lankhorst
2026-01-13 12:18 ` [PATCH v4 4/5] drm/xe: Make xe_ggtt_node_insert return a node Maarten Lankhorst
2026-01-13 23:12 ` Michal Wajdeczko [this message]
2026-01-13 12:18 ` [PATCH v4 5/5] drm/xe: Remove xe_ggtt_node_allocated Maarten Lankhorst
2026-01-13 12:23 ` ✗ CI.checkpatch: warning for drm/xe: Privatize struct xe_ggtt. (rev2) Patchwork
2026-01-13 12:25 ` ✓ CI.KUnit: success " Patchwork
2026-01-13 13:03 ` ✓ Xe.CI.BAT: " Patchwork
2026-01-13 20:02 ` ✓ Xe.CI.Full: " 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=f81a2bbc-7528-468a-b150-dea8c487b553@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=dev@lankhorst.se \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@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