drm/mm: Introduce address space shifting
Subsystems (3)
PATCH 1/3 drm/mm: Introduce address space shifting
From: Tomasz Lis <[email protected]>
Due to resource reprovisioning, sometimes a need arises to move a living address space to a new area, preserving all the nodes and holes stored within.
It is possible to do that by removing all nodes to a temporary list, reiniting the drm_mm instance and re-adding everything while applying a shift to each node. But that is a lot of extra work for a task which could be done internally without any node shuffle operations.
This change introduces an interface which allows to shift the range without pruning the whole drm_mm instance.
Having a drm_mm interface for such shift significantly simplifies the code required to adjust a KMD for a change in base address of a space managed by drm_mm instance.
--- drivers/gpu/drm/drm_mm.c | 24 ++++++++++++++++++++++++ include/drm/drm_mm.h | 1 + 2 files changed, 25 insertions(+)
drivers/gpu/drm/drm_mm.c +24 -0
@@ -917,6 +917,30 @@ struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan) }EXPORT_SYMBOL (drm_mm_scan_color_evict); +/** +* drm_mm_shift - move the range of addresses managed by this @mm +* @mm: the drm_mm structure instance to shift +* @shift: the shift value to be added to addresses of all nodes +* +* The function shifts all nodes by given offset, moving the address space +* range managed by this @mm. +*/ +void drm_mm_shift (struct drm_mm *mm,s64 shift) +{ +struct drm_mm_node *node; + +/* +* Head node represents a hole, with negative size and start at the end +* of addressable area. This means it is never present within nodes +* list - needs to be shifted separately. +*/ + mm->head_node.start += shift; + +drm_mm_for_each_node (node, mm) + node->start += shift; +} +EXPORT_SYMBOL (drm_mm_shift); +/** * drm_mm_init - initialize a drm-mm allocator * @mm: the drm_mm structure to initialize
include/drm/drm_mm.h +1 -0
@@ -465,6 +465,7 @@ static inline int drm_mm_insert_node(struct drm_mm *mm,void drm_mm_remove_node (struct drm_mm_node *node);void drm_mm_init (struct drm_mm *mm,u64 start,u64 size);void drm_mm_takedown (struct drm_mm *mm); +void drm_mm_shift (struct drm_mm *mm,s64 shift);/** * drm_mm_clean - checks whether an allocator is clean
Signature · 1 line
2.45.2
PATCH 2/3 drm/xe: Start using ggtt->start in preparation of balloon removal
Instead of having ggtt->size point to the end of ggtt, have ggtt->size be the actual size of the GGTT, and introduce ggtt->start to point to the beginning of GGTT.
This will allow a massive cleanup of GGTT in case of SRIOV-VF.
--- drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c | 2 +- drivers/gpu/drm/xe/xe_ggtt.c | 55 ++++++++++----------- drivers/gpu/drm/xe/xe_ggtt_types.h | 4 +- 3 files changed, 30 insertions(+), 31 deletions(-)
drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c +1 -1
@@ -67,7 +67,7 @@ static int guc_buf_test_init(struct kunit *test)KUNIT_ASSERT_EQ (test,0 ,xe_ggtt_init_kunit (ggtt,DUT_GGTT_START , -DUT_GGTT_START +DUT_GGTT_SIZE )); +DUT_GGTT_SIZE ));kunit_activate_static_stub (test, xe_managed_bo_create_pin_map, replacement_xe_managed_bo_create_pin_map);
drivers/gpu/drm/xe/xe_ggtt.c +26 -29
124 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ggtt_types.h +3 -1
@@ -22,7 +22,9 @@ struct xe_gt;struct xe_ggtt {/** @tile: Back pointer to tile where this GGTT belongs */ struct xe_tile *tile; -/** @size: Total size of this GGTT */ +/** @start: Start offset of GGTT */ +u64 start; +/** @size: Total usable size of this GGTT */ u64 size;#define XE_GGTT_FLAGS_64K BIT(0)
Signature · 1 line
2.45.2
PATCH 3/3 drm/xe: Rewrite GGTT VF initialisation
In reply to Maarten LankhorstThe previous code was using a complicated system with 2 balloons to set GGTT size and adjust GGTT offset. While it works, it's overly complicated.
A better approach is to set the offset and size when initialising GGTT, this removes the need for adding balloons. The resize function only needs to re-initialise GGTT at the new offset.
We use the newly created drm_mm_shift to shift the nodes.
This removes the need to manipulate the internals of xe_ggtt outside of xe_ggtt, and cleans up a lot of now unneeded code.
--- drivers/gpu/drm/xe/Makefile | 3 +- drivers/gpu/drm/xe/xe_ggtt.c | 144 +++------------ drivers/gpu/drm/xe/xe_ggtt.h | 5 +- drivers/gpu/drm/xe/xe_sriov_vf.c | 4 +- drivers/gpu/drm/xe/xe_tile_sriov_vf.c | 254 -------------------------- drivers/gpu/drm/xe/xe_tile_sriov_vf.h | 18 -- 6 files changed, 29 insertions(+), 399 deletions(-) delete mode 100644 drivers/gpu/drm/xe/xe_tile_sriov_vf.c delete mode 100644 drivers/gpu/drm/xe/xe_tile_sriov_vf.h
drivers/gpu/drm/xe/Makefile +1 -2
@@ -139,8 +139,7 @@ xe-y += \ xe_guc_relay.o \ xe_memirq.o \ xe_sriov.o \ - xe_sriov_vf.o \ - xe_tile_sriov_vf.o + xe_sriov_vf.o xe-$(CONFIG_PCI_IOV) += \ xe_gt_sriov_pf.o \
drivers/gpu/drm/xe/xe_ggtt.c +25 -119
198 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ggtt.h +1 -4
@@ -18,10 +18,7 @@ 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); -int xe_ggtt_node_insert_balloon_locked (struct xe_ggtt_node *node, -u64 start,u64 size); -void xe_ggtt_node_remove_balloon_locked (struct xe_ggtt_node *node); -void xe_ggtt_shift_nodes_locked (struct xe_ggtt *ggtt,s64 shift); +void xe_ggtt_shift_nodes (struct xe_ggtt *ggtt,s64 shift);int xe_ggtt_node_insert (struct xe_ggtt_node *node,u32 size,u32 align); int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
drivers/gpu/drm/xe/xe_sriov_vf.c +2 -2
@@ -7,6 +7,7 @@#include "xe_assert.h" #include "xe_device.h" +#include "xe_ggtt.h" #include "xe_gt.h" #include "xe_gt_sriov_printk.h" #include "xe_gt_sriov_vf.h"
@@ -15,7 +16,6 @@#include "xe_sriov.h" #include "xe_sriov_printk.h" #include "xe_sriov_vf.h" -#include "xe_tile_sriov_vf.h" /** * DOC: VF restore procedure in PF KMD and VF KMD
@@ -212,7 +212,7 @@ static bool vf_post_migration_fixup_ggtt_nodes(struct xe_device *xe) shift =xe_gt_sriov_vf_ggtt_shift (gt);if (shift) { need_fixups = true; -xe_tile_sriov_vf_fixup_ggtt_nodes (tile, shift); +xe_ggtt_shift_nodes (tile->mem.ggtt, shift); } }return need_fixups;
drivers/gpu/drm/xe/xe_tile_sriov_vf.c deleted +0 -254
254 lines not on this page · raw message
drivers/gpu/drm/xe/xe_tile_sriov_vf.h deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* -* Copyright © 2025 Intel Corporation -*/ - -#ifndef _XE_TILE_SRIOV_VF_H_ -#define _XE_TILE_SRIOV_VF_H_ - -#include <linux/types.h> - -struct xe_tile ; - -int xe_tile_sriov_vf_prepare_ggtt (struct xe_tile *tile); -int xe_tile_sriov_vf_balloon_ggtt_locked (struct xe_tile *tile); -void xe_tile_sriov_vf_deballoon_ggtt_locked (struct xe_tile *tile); -void xe_tile_sriov_vf_fixup_ggtt_nodes (struct xe_tile *tile,s64 shift); - -#endif
Signature · 1 line
2.45.2
Patchwork
CI✗ CI.Patch_applied: failure for series starting with [1/3] drm/mm: Introduce address space shifting
In reply to Maarten Lankhorst== Series Details ==
== Series Details ==
Series: series starting with [1/3] drm/mm: Introduce address space shifting
URL : https://patchwork.freedesktop.org/series/149998/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 52ecbb6a6878 drm-tip: 2025y-06m-09d-17h-17m-28s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_ggtt.c:254
error: drivers/gpu/drm/xe/xe_ggtt.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: drm/mm: Introduce address space shifting
Applying: drm/xe: Start using ggtt->start in preparation of balloon removal Patch failed at 0002 drm/xe: Start using ggtt->start in preparation of balloon removal When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".