From: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
To: <intel-xe@lists.freedesktop.org>
Cc: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
Subject: [PATCH v3 2/4] drm/xe/ttm: Add PF-mem VRAM placement types for TTM
Date: Mon, 24 Aug 2026 10:09:06 +0200 [thread overview]
Message-ID: <20260824080908.701133-3-piotr.piorkowski@intel.com> (raw)
In-Reply-To: <20260824080908.701133-1-piotr.piorkowski@intel.com>
From: Piotr Piórkowski <piotr.piorkowski@intel.com>
PF-mem regions are dedicated to kernel-only pinned BOs. They are not
exposed to userspace and cannot be exported through dma-buf.
Add dedicated TTM placement types for PF-mem VRAM regions and update
the BO, resource iterator, power-management, and PCI removal paths to
recognize them. Since PF-mem cannot contain user memory, its placement
types are intentionally excluded from user BO eviction.
v2:
- Modify commit message.
- Add comments explaining why PF-mem is excluded from user BO eviction
(Sashiko).
- Resolve xe_ttm_vram_mgr_alloc_sgt() physical address via
xe_map_resource_to_region() instead of the tile's
VRAM region (Sashiko).
- Assert in add_vram() that the requested placement is a VRAM one before
resolving its TTM manager.
Assisted-by: Claude:claude-5-sonnet
Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
---
drivers/gpu/drm/xe/xe_bo.c | 25 ++++++++++++++++++-------
drivers/gpu/drm/xe/xe_bo.h | 17 +++++++++++++++++
drivers/gpu/drm/xe/xe_bo_evict.c | 7 +++++--
drivers/gpu/drm/xe/xe_pm.c | 4 ++--
drivers/gpu/drm/xe/xe_res_cursor.h | 9 ++++++++-
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 9 ++++-----
6 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index dde309821237..91070a0a926d 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -46,6 +46,8 @@ const char *const xe_mem_type_to_name[TTM_NUM_MEM_TYPES] = {
[XE_PL_TT] = "gtt",
[XE_PL_VRAM0] = "vram0",
[XE_PL_VRAM1] = "vram1",
+ [XE_PL_VRAM0_PFMEM] = "vram0_pfmem",
+ [XE_PL_VRAM1_PFMEM] = "vram1_pfmem",
[XE_PL_STOLEN] = "stolen"
};
@@ -166,11 +168,12 @@ static bool xe_bo_is_user(struct xe_bo *bo)
static struct xe_migrate *
mem_type_to_migrate(struct xe_device *xe, u32 mem_type)
{
- struct xe_tile *tile;
+ u8 tile_id;
xe_assert(xe, mem_type == XE_PL_STOLEN || mem_type_is_vram(mem_type));
- tile = &xe->tiles[mem_type == XE_PL_STOLEN ? 0 : (mem_type - XE_PL_VRAM0)];
- return tile->migrate;
+ tile_id = mem_type == XE_PL_STOLEN ? 0 : xe_vram_pl_to_tile_id(xe, mem_type);
+
+ return xe->tiles[tile_id].migrate;
}
static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
@@ -231,13 +234,16 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
struct ttm_place *places, u32 bo_flags, u32 mem_type, u32 *c)
{
struct ttm_place place = { .mem_type = mem_type };
- struct ttm_resource_manager *mgr = ttm_manager_type(&xe->ttm, mem_type);
- struct xe_ttm_vram_mgr *vram_mgr = to_xe_ttm_vram_mgr(mgr);
-
+ struct ttm_resource_manager *mgr;
+ struct xe_ttm_vram_mgr *vram_mgr;
struct xe_vram_region *vram;
u64 io_size;
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
+ xe_assert(xe, mem_type_is_vram(mem_type));
+
+ mgr = ttm_manager_type(&xe->ttm, mem_type);
+ vram_mgr = to_xe_ttm_vram_mgr(mgr);
vram = container_of(vram_mgr, struct xe_vram_region, ttm);
xe_assert(xe, vram && vram->usable_size);
@@ -360,6 +366,8 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
switch (tbo->resource->mem_type) {
case XE_PL_VRAM0:
case XE_PL_VRAM1:
+ case XE_PL_VRAM0_PFMEM:
+ case XE_PL_VRAM1_PFMEM:
case XE_PL_STOLEN:
*placement = tt_placement;
break;
@@ -639,7 +647,10 @@ static int xe_ttm_io_mem_reserve(struct ttm_device *bdev,
case XE_PL_TT:
return 0;
case XE_PL_VRAM0:
- case XE_PL_VRAM1: {
+ case XE_PL_VRAM1:
+ case XE_PL_VRAM0_PFMEM:
+ case XE_PL_VRAM1_PFMEM:
+ {
struct xe_vram_region *vram = xe_map_resource_to_region(mem);
if (!xe_ttm_resource_visible(xe, mem))
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index e8081af5bfc1..c698f70a3b0c 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -83,8 +83,13 @@
#define XE_PL_TT TTM_PL_TT
#define XE_PL_VRAM0 TTM_PL_VRAM
#define XE_PL_VRAM1 (XE_PL_VRAM0 + 1)
+#define XE_PL_VRAM0_PFMEM (XE_PL_VRAM1 + 1)
+#define XE_PL_VRAM1_PFMEM (XE_PL_VRAM0_PFMEM + 1)
#define XE_PL_STOLEN (TTM_NUM_MEM_TYPES - 1)
+#define xe_for_each_vram_pl(i) \
+ for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1_PFMEM; i++)
+
#define XE_BO_PROPS_INVALID (-1)
#define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT)
@@ -614,4 +619,16 @@ static inline bool xe_bo_is_mem_type(struct xe_bo *bo, u32 mem_type)
xe_bo_assert_held(bo);
return bo->ttm.resource->mem_type == mem_type;
}
+
+static inline u8 xe_vram_pl_to_tile_id(struct xe_device *xe, u32 mem_type)
+{
+ xe_assert(xe, mem_type_is_vram(mem_type));
+
+ if (mem_type >= XE_PL_VRAM0 && mem_type <= XE_PL_VRAM1)
+ return mem_type - XE_PL_VRAM0;
+
+ xe_assert(xe, mem_type >= XE_PL_VRAM0_PFMEM && mem_type <= XE_PL_VRAM1_PFMEM);
+ return mem_type - XE_PL_VRAM0_PFMEM;
+}
+
#endif
diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c
index 7661fca7f278..a25ec6c750da 100644
--- a/drivers/gpu/drm/xe/xe_bo_evict.c
+++ b/drivers/gpu/drm/xe/xe_bo_evict.c
@@ -118,7 +118,10 @@ int xe_bo_evict_all_user(struct xe_device *xe)
u32 mem_type;
int ret;
- /* User memory */
+ /*
+ * Iterate over placements that can contain user memory. PF-mem placements
+ * are excluded since they are reserved for pinned kernel BOs.
+ */
for (mem_type = XE_PL_TT; mem_type <= XE_PL_VRAM1; ++mem_type) {
struct ttm_resource_manager *man =
ttm_manager_type(bdev, mem_type);
@@ -303,7 +306,7 @@ void xe_bo_pci_dev_remove_all(struct xe_device *xe)
* Move pagemap bos and exported dma-buf to system, and
* purge everything else.
*/
- for (mem_type = XE_PL_VRAM1; mem_type >= XE_PL_TT; --mem_type) {
+ for (mem_type = XE_PL_VRAM1_PFMEM; mem_type >= XE_PL_TT; --mem_type) {
struct ttm_resource_manager *man =
ttm_manager_type(&xe->ttm, mem_type);
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index f517bf453b54..a4fe6a89d9dd 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -975,7 +975,7 @@ int xe_pm_set_vram_threshold(struct xe_device *xe, u32 threshold)
u32 vram_total_mb = 0;
int i;
- for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1; ++i) {
+ xe_for_each_vram_pl(i) {
man = ttm_manager_type(&xe->ttm, i);
if (man)
vram_total_mb += DIV_ROUND_UP_ULL(man->size, 1024 * 1024);
@@ -1012,7 +1012,7 @@ void xe_pm_d3cold_allowed_toggle(struct xe_device *xe)
return;
}
- for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1; ++i) {
+ xe_for_each_vram_pl(i) {
man = ttm_manager_type(&xe->ttm, i);
if (man) {
vram_used = ttm_resource_manager_usage(man);
diff --git a/drivers/gpu/drm/xe/xe_res_cursor.h b/drivers/gpu/drm/xe/xe_res_cursor.h
index 0522caafd89d..4603a3356e53 100644
--- a/drivers/gpu/drm/xe/xe_res_cursor.h
+++ b/drivers/gpu/drm/xe/xe_res_cursor.h
@@ -111,7 +111,9 @@ static inline void xe_res_first(struct ttm_resource *res,
break;
}
case XE_PL_VRAM0:
- case XE_PL_VRAM1: {
+ case XE_PL_VRAM1:
+ case XE_PL_VRAM0_PFMEM:
+ case XE_PL_VRAM1_PFMEM: {
struct gpu_buddy_block *block;
struct list_head *head, *next;
struct gpu_buddy *mm = xe_res_get_buddy(res);
@@ -303,6 +305,8 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size)
break;
case XE_PL_VRAM0:
case XE_PL_VRAM1:
+ case XE_PL_VRAM0_PFMEM:
+ case XE_PL_VRAM1_PFMEM: {
start = size - cur->size;
block = cur->node;
@@ -322,6 +326,7 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size)
cur->remaining);
cur->node = block;
break;
+ }
default:
return;
}
@@ -358,6 +363,8 @@ static inline bool xe_res_is_vram(const struct xe_res_cursor *cur)
case XE_PL_STOLEN:
case XE_PL_VRAM0:
case XE_PL_VRAM1:
+ case XE_PL_VRAM0_PFMEM:
+ case XE_PL_VRAM1_PFMEM:
return true;
default:
break;
diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
index 05911904c1f9..bb28b493fd93 100644
--- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
+++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
@@ -18,6 +18,7 @@
#include "xe_pm.h"
#include "xe_res_cursor.h"
#include "xe_ttm_vram_mgr.h"
+#include "xe_vram.h"
#include "xe_vram_types.h"
static inline struct gpu_buddy_block *
@@ -336,7 +337,6 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr,
{
struct ttm_resource_manager *man = &mgr->manager;
struct dmem_cgroup_region *cg;
- const char *name;
int err;
man->func = &xe_ttm_vram_mgr_func;
@@ -365,8 +365,7 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr,
if (err)
return err;
- name = mem_type == XE_PL_VRAM0 ? "vram0" : "vram1";
- cg = drmm_cgroup_register_region(&xe->drm, name,
+ cg = drmm_cgroup_register_region(&xe->drm, xe_mem_type_to_name[mem_type],
&(struct dmem_cgroup_init){
.size = size,
.ops = &xe_ttm_vram_mgr_dmem_ops,
@@ -405,7 +404,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
enum dma_data_direction dir,
struct sg_table **sgt)
{
- struct xe_tile *tile = &xe->tiles[res->mem_type - XE_PL_VRAM0];
+ struct xe_vram_region *vram = xe_map_resource_to_region(res);
struct xe_ttm_vram_mgr_resource *vres = to_xe_ttm_vram_mgr_resource(res);
struct xe_res_cursor cursor;
struct scatterlist *sg;
@@ -443,7 +442,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe,
*/
xe_res_first(res, offset, length, &cursor);
for_each_sgtable_sg((*sgt), sg, i) {
- phys_addr_t phys = cursor.start + xe_vram_region_io_start(tile->mem.vram);
+ phys_addr_t phys = cursor.start + xe_vram_region_io_start(vram);
size_t size = min_t(u64, cursor.size, SZ_2G);
dma_addr_t addr;
--
2.34.1
next prev parent reply other threads:[~2026-08-24 8:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 8:09 [PATCH v3 0/4] Introduce PF-mem VRAM regions Piórkowski, Piotr
2026-08-24 8:09 ` [PATCH v3 1/4] drm/xe/vram: Add binding information to " Piórkowski, Piotr
2026-08-24 8:09 ` Piórkowski, Piotr [this message]
2026-08-24 8:09 ` [PATCH v3 3/4] drm/xe/vram: Add initial support for PF-mem regions Piórkowski, Piotr
2026-08-24 8:09 ` [PATCH v3 4/4] drm/xe/kunit: Add tests " Piórkowski, Piotr
2026-08-25 5:39 ` ✗ CI.checkpatch: warning for Introduce PF-mem VRAM regions (rev3) Patchwork
2026-08-25 5:40 ` ✓ CI.KUnit: success " Patchwork
2026-08-25 6:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-25 10:19 ` ✗ 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=20260824080908.701133-3-piotr.piorkowski@intel.com \
--to=piotr.piorkowski@intel.com \
--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