* [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition
@ 2026-11-17 16:59 James Zhu
2026-11-17 16:59 ` [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: James Zhu @ 2026-11-17 16:59 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The reserved (SPM) VMID handling was designed on single-XCC hardware,
where one GFXHUB is all there is. On multi-XCC parts with partitioning
every XCC has an own GFXHUB and every partition is exposed as an own
render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on
AMDGPU_GFXHUB(0) only. The VMID grab path checks
vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use
AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the
reservation silently does nothing. A debugger relying on a stable
VMID gets one on exactly one XCC of the partition it runs on, or
none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs
gfxhub callback broadcasts the SPM VMID's page table base to every
XCC of the device, including XCCs of partitions the caller cannot
even submit to.
3. The exclusion is device-global: because every reservation contends
for hub 0's id_mgr, one partition's render node blocks every other
partition from reserving, which breaks the isolation the render
nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all
hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3
partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in
the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub
arrays), real end to end:
Patch 1 exposes the XCC-masked setup_vm_pt_regs variant, which gfxhub
v1.2 and v12.1 already implement internally, as a gfxhub callback.
Patch 2 makes the hub argument of the binding path mean what it says:
amdgpu_gmc_bind_vmid() programs and flushes only the given hub,
amdgpu_vmid_free_spm() unbinds the hub it frees, amdgpu_vm_spm_update()
binds every hub the VM holds the reservation on, and the ioctl reserves
on every GFXHUB instance. This fixes 1. and 2. while keeping the
device-wide scope.
Patch 3 then derives the hub set from the caller's partition
(fpriv->xcp_id), fixing 3.: each partition reserves, binds and
conflicts only on its own XCCs. Unreserve keeps operating on every hub,
freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be
recorded on the partition's first GFXHUB only and treated as a pure
ownership token, closest to the original single-hub design. But the
record plays three roles at once: the ownership token, the set of hubs
whose page table base has to be bound (each XCC translates through its
own hub, so the binding must cover every XCC of the partition either
way), and the per-hub check of the VMID grab and CS paths
(vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the
partition keeps the three consistent by construction, lets
amdgpu_vm_spm_update() derive the binding set from the existing
structures without a new field, and gives jobs on every XCC of the
partition the same reserved-VMID semantics instead of only on the
first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device
node, the mask degenerates to every XCC and nothing changes; on
single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m
(amdgpu_vm.o, amdgpu_ids.o, amdgpu_gmc.o, gfxhub_v1_2.o,
gfxhub_v12_1.o build warning-free); checkpatch clean.
James Zhu (3):
drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub
callback
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 49 ++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 50 ++++++++++++++++------
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 +
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 +
7 files changed, 96 insertions(+), 15 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
@ 2026-11-17 16:59 ` James Zhu
2026-11-18 9:36 ` Christian König
2026-11-17 16:59 ` [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
` (3 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: James Zhu @ 2026-11-17 16:59 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the
setup_vm_pt_regs gfxhub callback programs a VMID's page table base on
every XCC. Callers which bind a VMID on a single VMHUB, like the SPM
VMID binding, have no way to reach one GFXHUB through the callback
interface.
gfxhub v1.2 and v12.1 already implement an XCC-masked variant
internally. Expose it as a new setup_vm_pt_regs_xcc callback. GFXHUBs
of IPs with a single XCC don't implement it, for them the existing
callback already is per-hub.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 +
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 +
3 files changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
index c7b44aeb671b..19b961cb12f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
@@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {
u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);
void (*setup_vm_pt_regs)(struct amdgpu_device *adev, uint32_t vmid,
uint64_t page_table_base);
+ void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev, uint32_t vmid,
+ uint64_t page_table_base, uint32_t xcc_mask);
int (*gart_enable)(struct amdgpu_device *adev);
void (*gart_disable)(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
index b13967a1c8fb..7bc17721f463 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
@@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = {
.get_fb_location = gfxhub_v12_1_get_fb_location,
.get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset,
.setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs,
+ .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v12_1_gart_enable,
.gart_disable = gfxhub_v12_1_gart_disable,
.set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
index e89813590539..a56c072daf15 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
@@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)
const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = {
.get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset,
.setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs,
+ .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v1_2_gart_enable,
.gart_disable = gfxhub_v1_2_gart_disable,
.set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 16:59 ` [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
@ 2026-11-17 16:59 ` James Zhu
2026-11-17 17:21 ` sashiko-bot
2026-11-18 9:38 ` Christian König
2026-11-17 16:59 ` [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
` (2 subsequent siblings)
4 siblings, 2 replies; 17+ messages in thread
From: James Zhu @ 2026-11-17 16:59 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The SPM VMID reservation made through AMDGPU_VM_OP_RESERVE_VMID is
recorded on AMDGPU_GFXHUB(0) only, while gfxhub v1.2's
setup_vm_pt_regs broadcasts the page table base to every XCC. On
multi-XCC parts the two disagree, in both directions:
- the reservation only takes effect for jobs running on XCC 0, since
the VMID grab path checks vm->reserved_vmid[ring->vm_hub] and the
rings of XCC i use AMDGPU_GFXHUB(i);
- the page table base is physically programmed on all XCCs anyway,
and conflicting reservations are only detected on hub 0's id_mgr.
Make the hub argument real end to end: amdgpu_gmc_bind_vmid() programs
only the given hub, through the XCC-masked gfxhub callback where one
exists, and amdgpu_vmid_free_spm() unbinds the hub it frees instead of
hub 0. amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds
the reservation. The VM ioctl reserves the VMID on every GFXHUB
instance through the new amdgpu_vmid_alloc_spm_gfxhubs() helper, so
the reservation now takes effect, is bound and is flushed on every XCC
the VM's jobs can run on, and a conflicting reservation shows up on
whichever hub two VMs share.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 49 ++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 40 +++++++++++++-------
4 files changed, 82 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 08d3ff61edcc..704a30ad388a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -797,6 +797,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
*
* For VMIDs that are bound directly to a VM's page table outside the
* normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ * Only @vmhub is programmed and flushed, other hubs keep their binding.
*/
void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
unsigned int vmid, uint64_t pd_addr)
@@ -805,6 +806,9 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
if (is_mmhub)
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+ else if (adev->gfxhub.funcs->setup_vm_pt_regs_xcc)
+ adev->gfxhub.funcs->setup_vm_pt_regs_xcc(adev, vmid, pd_addr,
+ BIT(vmhub - AMDGPU_GFXHUB_START));
else
adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index 9c879ac68352..41f3dba530e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -651,12 +651,59 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
id_mgr->reserved_vmid = false;
if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs)
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+ amdgpu_gmc_bind_vmid(adev, vmhub,
adev->vm_manager.spm_vmid, 0);
}
mutex_unlock(&id_mgr->lock);
}
+/*
+ * amdgpu_vmid_alloc_spm_gfxhubs - reserve the SPM VMID on a set of GFXHUBs
+ * @adev: amdgpu device structure
+ * @vm: the VM to reserve the ID for
+ * @xcc_mask: XCC instances on whose GFXHUBs to reserve
+ *
+ * Reserve the SPM VMID on the GFXHUB of every XCC in @xcc_mask, so that
+ * the reservation covers every hub the VM's jobs can run on.
+ *
+ * Returns: 0 for success, the first per-hub error otherwise. On an error
+ * the reservation is released on every hub in @xcc_mask again.
+ */
+int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask)
+{
+ int i, r;
+
+ for_each_inst(i, xcc_mask) {
+ r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i));
+ if (r) {
+ amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask);
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * amdgpu_vmid_free_spm_gfxhubs - undo amdgpu_vmid_alloc_spm_gfxhubs
+ * @adev: amdgpu device structure
+ * @vm: the VM with the reserved ID
+ * @xcc_mask: XCC instances on whose GFXHUBs to free the reservation
+ *
+ * Free the SPM VMID on every GFXHUB in @xcc_mask @vm holds it on, hubs
+ * without a reservation are skipped. The same wait requirement as for
+ * amdgpu_vmid_free_spm() applies.
+ */
+void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask)
+{
+ int i;
+
+ for_each_inst(i, xcc_mask)
+ amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(i));
+}
+
/**
* amdgpu_vmid_reset - reset VMID to zero
*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
index c134000eecfd..d2b225d0aa38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
@@ -129,6 +129,10 @@ int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
unsigned vmhub);
void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
unsigned vmhub);
+int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask);
+void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask);
int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
struct amdgpu_job *job, struct dma_fence **fence);
void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 6b4dc0276e27..bd9aa35933dc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -589,30 +589,36 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)
* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base
* register must track whichever VM currently holds the reservation instead
* of being set per-job like a normal VMID. Bind it to @vm's real root PD
- * address if @vm holds the reservation; otherwise do nothing, since @vm is
- * not the one that could legitimately change the current binding.
+ * address on every GFXHUB @vm holds the reservation on; hubs reserved by
+ * other VMs or not reserved at all are left alone, since @vm is not the
+ * one that could legitimately change their binding.
*
* @vm's root PD must be locked by the caller.
*/
void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{
- struct amdgpu_kq_vmid_mgr *id_mgr =
- &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)];
uint64_t pd_addr;
+ int i;
if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs)
return;
- mutex_lock(&id_mgr->lock);
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
- &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) {
- mutex_unlock(&id_mgr->lock);
+ if (!amdgpu_vm_ready(vm))
return;
- }
pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
- mutex_unlock(&id_mgr->lock);
+ for_each_inst(i, adev->gfx.xcc_mask) {
+ struct amdgpu_kq_vmid_mgr *id_mgr =
+ &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)];
+
+ mutex_lock(&id_mgr->lock);
+ if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] ==
+ &id_mgr->ids[adev->vm_manager.spm_vmid])
+ amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i),
+ adev->vm_manager.spm_vmid,
+ pd_addr);
+ mutex_unlock(&id_mgr->lock);
+ }
}
/**
@@ -3018,7 +3024,8 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
int r;
/* We only have requirement to reserve vmid from gfxhub */
- r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
+ r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm,
+ adev->gfx.xcc_mask);
if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
amdgpu_vm_spm_update(adev, vm);
amdgpu_bo_unreserve(vm->root.bo);
@@ -3027,14 +3034,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
}
case AMDGPU_VM_OP_UNRESERVE_VMID: {
struct amdgpu_bo *root = vm->root.bo;
+ bool reserved = false;
+ int i;
amdgpu_bo_reserve(root, true);
+ for_each_inst(i, adev->gfx.xcc_mask)
+ reserved |= amdgpu_vmid_uses_reserved(vm,
+ AMDGPU_GFXHUB(i));
/* Wait for the jobs which might still use the reserved VMID */
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
+ if (reserved)
dma_resv_wait_timeout(root->tbo.base.resv,
DMA_RESV_USAGE_READ, false,
MAX_SCHEDULE_TIMEOUT);
- amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
+ amdgpu_vmid_free_spm_gfxhubs(adev, vm, adev->gfx.xcc_mask);
amdgpu_bo_unreserve(root);
break;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 16:59 ` [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
2026-11-17 16:59 ` [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
@ 2026-11-17 16:59 ` James Zhu
2026-11-17 17:18 ` sashiko-bot
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
4 siblings, 1 reply; 17+ messages in thread
From: James Zhu @ 2026-11-17 16:59 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On partitioned devices every partition is exposed as an own render
node and fpriv->xcp_id records which partition a drm file belongs to.
But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every
other partition from reserving, and rebinds the VMID's page table base
on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The
reservation then only covers the XCCs of the caller's partition, and
each partition can hold the reserved VMID on its own hubs
independently, matching the isolation the render nodes promise.
Unreserve keeps operating on every hub, freeing whatever the VM
actually holds.
Without partitioning, or on the whole-device node, the mask stays
adev->gfx.xcc_mask and nothing changes.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index bd9aa35933dc..d37af0dbd691 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3021,11 +3021,21 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
switch (args->in.op) {
case AMDGPU_VM_OP_RESERVE_VMID: {
+ uint32_t xcc_mask = adev->gfx.xcc_mask;
int r;
+ /*
+ * Scope the reservation to the hardware partition behind the
+ * caller's render node, so other partitions can hold the
+ * reserved VMID on their own XCCs independently.
+ */
+ if (adev->xcp_mgr && fpriv->xcp_id != AMDGPU_XCP_NO_PARTITION)
+ amdgpu_xcp_get_inst_details(
+ &adev->xcp_mgr->xcp[fpriv->xcp_id],
+ AMDGPU_XCP_GFX, &xcc_mask);
+
/* We only have requirement to reserve vmid from gfxhub */
- r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm,
- adev->gfx.xcc_mask);
+ r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, xcc_mask);
if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
amdgpu_vm_spm_update(adev, vm);
amdgpu_bo_unreserve(vm->root.bo);
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
2026-11-17 16:59 ` [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
@ 2026-11-17 17:18 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-17 17:18 UTC (permalink / raw)
To: James Zhu, amd-gfx
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdgpu: skipped wait in amdgpu_vm_fini() for partition SPM
VMID
- [Medium] drm/amdgpu: unchecked amdgpu_xcp_get_inst_details() in
amdgpu_vm_ioctl()
--
commit a5f43653ba23f302ebd963bef5053a4d46508cd1
Author: James Zhu <James.Zhu@amd.com>
drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
This commit scopes AMDGPU_VM_OP_RESERVE_VMID to the GFXHUB instances of
the caller's compute partition when fpriv->xcp_id is set.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index e1691145da903..8098fbb542c82 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -3021,11 +3021,21 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>
> switch (args->in.op) {
> case AMDGPU_VM_OP_RESERVE_VMID: {
> + uint32_t xcc_mask = adev->gfx.xcc_mask;
> int r;
>
> + /*
> + * Scope the reservation to the hardware partition behind the
> + * caller's render node, so other partitions can hold the
> + * reserved VMID on their own XCCs independently.
> + */
> + if (adev->xcp_mgr && fpriv->xcp_id != AMDGPU_XCP_NO_PARTITION)
> + amdgpu_xcp_get_inst_details(
> + &adev->xcp_mgr->xcp[fpriv->xcp_id],
> + AMDGPU_XCP_GFX, &xcc_mask);
[Severity: Medium]
Should the return value of amdgpu_xcp_get_inst_details() be checked here?
If a runtime compute partition switch reduces the number of partitions
while a DRM file opened on a higher-numbered partition remains open,
xcp[fpriv->xcp_id].valid becomes false and amdgpu_xcp_get_inst_details()
returns -EINVAL without updating xcc_mask. The reservation then silently
falls back to adev->gfx.xcc_mask and reserves the SPM VMID across every
GFXHUB on the device.
> +
> /* We only have requirement to reserve vmid from gfxhub */
> - r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm,
> - adev->gfx.xcc_mask);
> + r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, xcc_mask);
[Severity: High]
When a process on a non-zero partition (fpriv->xcp_id > 0) closes its DRM
file without calling AMDGPU_VM_OP_UNRESERVE_VMID, does amdgpu_vm_fini()
skip waiting for in-flight jobs before unbinding and freeing the reserved
SPM VMID?
For fpriv->xcp_id > 0, xcc_mask only includes that partition's XCCs, so
vm->reserved_vmid[AMDGPU_GFXHUB(0)] stays NULL. Unlike
AMDGPU_VM_OP_UNRESERVE_VMID, amdgpu_vm_fini() only checks GFXHUB(0) before
waiting and then frees the SPM VMID on all hubs:
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_fini() {
...
/* Wait for the jobs which might still use the reserved VMID */
if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
false, MAX_SCHEDULE_TIMEOUT);
...
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
amdgpu_vmid_free_spm(adev, vm, i);
}
...
}
amdgpu_vmid_free_spm() then unbinds spm_vmid to address 0 and clears
id_mgr->reserved_vmid while GPU jobs on that partition are still running
under spm_vmid, causing in-flight work to page-fault and letting another
process rebind the VMID concurrently. Checking all GFXHUBs in
adev->gfx.xcc_mask in amdgpu_vm_fini(), matching
AMDGPU_VM_OP_UNRESERVE_VMID, would avoid this regression.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117165952.3558762-1-James.Zhu@amd.com?part=3
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-17 16:59 ` [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
@ 2026-11-17 17:21 ` sashiko-bot
2026-11-18 9:38 ` Christian König
1 sibling, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-17 17:21 UTC (permalink / raw)
To: James Zhu, amd-gfx
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdgpu: physical xcc_mask used as logical index in
amdgpu_vm_spm_update()
- [High] drm/amdgpu: amdgpu_vm_fini() only checks GFXHUB(0) before
waiting on jobs
- [Medium] drm/amdgpu: unlocked allocation and unsafe rollback in
amdgpu_vmid_alloc_spm_gfxhubs()
--
commit 0df4e49e9ba90dc0c43a497872e17c100a8d4894
Author: James Zhu <James.Zhu@amd.com>
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
This commit updates SPM VMID reservation, binding, and unbinding to operate
per GFXHUB instance across XCCs rather than only on AMDGPU_GFXHUB(0).
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> index 9c879ac683520..41f3dba530e38 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
[ ... ]
> +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask)
> +{
> + int i, r;
> +
> + for_each_inst(i, xcc_mask) {
> + r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i));
> + if (r) {
> + amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask);
> + return r;
> + }
> + }
> +
> + return 0;
> +}
[Severity: Medium]
If amdgpu_vmid_alloc_spm() fails on a later hub, can rolling back with
amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask) unbind an active SPM VMID
to 0 while GPU jobs are still using it?
amdgpu_vmid_alloc_spm() returns 0 when vm->reserved_vmid[vmhub] is already
set, and AMDGPU_VM_OP_RESERVE_VMID calls amdgpu_vmid_alloc_spm_gfxhubs()
before reserving vm->root.bo. If vm already held a reservation on an
earlier hub, or a concurrent job submission grabs a newly published
vm->reserved_vmid[AMDGPU_GFXHUB(i)] before a subsequent hub fails with
-ENOENT, the rollback frees and unbinds those earlier hubs to 0 without
waiting via dma_resv_wait_timeout().
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 94b1cfe05e3e0..e1691145da903 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -589,30 +589,36 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> * The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base
> * register must track whichever VM currently holds the reservation instead
> * of being set per-job like a normal VMID. Bind it to @vm's real root PD
> - * address if @vm holds the reservation; otherwise do nothing, since @vm is
> - * not the one that could legitimately change the current binding.
> + * address on every GFXHUB @vm holds the reservation on; hubs reserved by
> + * other VMs or not reserved at all are left alone, since @vm is not the
> + * one that could legitimately change their binding.
> *
> * @vm's root PD must be locked by the caller.
> */
> void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> {
> - struct amdgpu_kq_vmid_mgr *id_mgr =
> - &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)];
> uint64_t pd_addr;
> + int i;
>
> if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs)
> return;
>
> - mutex_lock(&id_mgr->lock);
> - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
> - &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) {
> - mutex_unlock(&id_mgr->lock);
> + if (!amdgpu_vm_ready(vm))
> return;
> - }
>
> pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
> - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
> - mutex_unlock(&id_mgr->lock);
> + for_each_inst(i, adev->gfx.xcc_mask) {
> + struct amdgpu_kq_vmid_mgr *id_mgr =
> + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)];
> +
> + mutex_lock(&id_mgr->lock);
> + if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] ==
> + &id_mgr->ids[adev->vm_manager.spm_vmid])
> + amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i),
> + adev->vm_manager.spm_vmid,
> + pd_addr);
> + mutex_unlock(&id_mgr->lock);
> + }
> }
[Severity: High]
Can iterating over adev->gfx.xcc_mask here and in amdgpu_vm_ioctl() index
adev->reg_offset[GC_HWIP] out of bounds when lower-numbered physical XCCs
are harvested?
adev->gfx.xcc_mask is a bitmask of physical XCC instances, whereas
AMDGPU_GFXHUB(i), adev->vmhub[], ring->vm_hub, and setup_vm_pt_regs_xcc()
all use contiguous logical XCC indices 0 .. NUM_XCC(adev->gfx.xcc_mask) - 1
and translate them via GET_INST(GC, i):
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c:gfxhub_v1_2_xcc_setup_vm_pt_regs() {
for_each_inst(i, xcc_mask) {
hub = &adev->vmhub[AMDGPU_GFXHUB(i)];
WREG32_SOC15_OFFSET(GC, GET_INST(GC, i),
regVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
hub->ctx_addr_distance * vmid,
lower_32_bits(page_table_base));
...
}
When a lower physical XCC is harvested, amdgpu_populate_ip_map() sets
adev->ip_map.dev_inst[GC_HWIP][i] to -1 for i >= NUM_XCC(adev->gfx.xcc_mask).
Passing a physical bit position i >= NUM_XCC(adev->gfx.xcc_mask) through
amdgpu_gmc_bind_vmid() causes GET_INST(GC, i) to return 0xffffffff, reading
adev->reg_offset[GC_HWIP][0xffffffff] out of bounds and flushing an
uninitialized adev->vmhub[AMDGPU_GFXHUB(i)], while skipping the logical
GFXHUBs at the harvested bit positions. Using
GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0) avoids mixing physical and
logical XCC masks.
[ ... ]
> @@ -3027,14 +3034,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
> }
> case AMDGPU_VM_OP_UNRESERVE_VMID: {
> struct amdgpu_bo *root = vm->root.bo;
> + bool reserved = false;
> + int i;
>
> amdgpu_bo_reserve(root, true);
> + for_each_inst(i, adev->gfx.xcc_mask)
> + reserved |= amdgpu_vmid_uses_reserved(vm,
> + AMDGPU_GFXHUB(i));
> /* Wait for the jobs which might still use the reserved VMID */
> - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
> + if (reserved)
> dma_resv_wait_timeout(root->tbo.base.resv,
> DMA_RESV_USAGE_READ, false,
> MAX_SCHEDULE_TIMEOUT);
> - amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
> + amdgpu_vmid_free_spm_gfxhubs(adev, vm, adev->gfx.xcc_mask);
> amdgpu_bo_unreserve(root);
> break;
> }
[Severity: High]
Should amdgpu_vm_fini() also check all GFXHUBs before waiting on
root->tbo.base.resv, matching this change in AMDGPU_VM_OP_UNRESERVE_VMID?
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_fini() {
...
/* Wait for the jobs which might still use the reserved VMID */
if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
false, MAX_SCHEDULE_TIMEOUT);
...
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
amdgpu_vmid_free_spm(adev, vm, i);
}
...
}
If a VM holds an SPM reservation on a non-zero GFXHUB while
vm->reserved_vmid[AMDGPU_GFXHUB(0)] is NULL (for example when reserved on a
subset of GFXHUBs via amdgpu_vmid_alloc_spm_gfxhubs()), closing the DRM file
skips dma_resv_wait_timeout(), frees the root PD in amdgpu_vm_pt_free_root(),
and unbinds the SPM VMID to 0 while jobs using that VMID are still running.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117165952.3558762-1-James.Zhu@amd.com?part=2
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
` (2 preceding siblings ...)
2026-11-17 16:59 ` [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
@ 2026-11-17 18:19 ` James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
` (2 more replies)
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
4 siblings, 3 replies; 17+ messages in thread
From: James Zhu @ 2026-11-17 18:19 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The reserved (SPM) VMID handling was designed on single-XCC hardware,
where one GFXHUB is all there is. On multi-XCC parts with partitioning
every XCC has an own GFXHUB and every partition is exposed as an own
render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on
AMDGPU_GFXHUB(0) only. The VMID grab path checks
vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use
AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the
reservation silently does nothing. A debugger relying on a stable
VMID gets one on exactly one XCC of the partition it runs on, or
none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs
gfxhub callback broadcasts the SPM VMID's page table base to every
XCC of the device, including XCCs of partitions the caller cannot
even submit to.
3. The exclusion is device-global: because every reservation contends
for hub 0's id_mgr, one partition's render node blocks every other
partition from reserving, which breaks the isolation the render
nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all
hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3
partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in
the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub
arrays), real end to end:
Patch 1 exposes the XCC-masked setup_vm_pt_regs variant, which gfxhub
v1.2 and v12.1 already implement internally, as a gfxhub callback.
Patch 2 makes the hub argument of the binding path mean what it says:
amdgpu_gmc_bind_vmid() programs and flushes only the given hub,
amdgpu_vmid_free_spm() unbinds the hub it frees, amdgpu_vm_spm_update()
binds every hub the VM holds the reservation on, and the ioctl reserves
on every GFXHUB instance. This fixes 1. and 2. while keeping the
device-wide scope.
Patch 3 then derives the hub set from the caller's partition
(fpriv->xcp_id), fixing 3.: each partition reserves, binds and
conflicts only on its own XCCs. Unreserve keeps operating on every hub,
freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be
recorded on the partition's first GFXHUB only and treated as a pure
ownership token, closest to the original single-hub design. But the
record plays three roles at once: the ownership token, the set of hubs
whose page table base has to be bound (each XCC translates through its
own hub, so the binding must cover every XCC of the partition either
way), and the per-hub check of the VMID grab and CS paths
(vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the
partition keeps the three consistent by construction, lets
amdgpu_vm_spm_update() derive the binding set from the existing
structures without a new field, and gives jobs on every XCC of the
partition the same reserved-VMID semantics instead of only on the
first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device
node, the mask degenerates to every XCC and nothing changes; on
single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m;
checkpatch clean.
v2: address the Sashiko AI review findings, all of which checked out:
- Iterate the GFXHUBs with a logical XCC mask
(GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0)) instead of the physical
adev->gfx.xcc_mask, which can be sparse when an XCC is harvested and
would send out-of-range logical indices into GET_INST()
(amdgpu_vm_spm_update(), both ioctl ops). The partition path already
used the logical xcp inst_mask.
- amdgpu_vm_fini() now checks every VMHUB, not just GFXHUB(0), before
waiting for jobs that may still use a reserved VMID; with patch 3 a
partition > 0 holds no reservation on hub 0 and the wait was skipped.
- amdgpu_vmid_alloc_spm_gfxhubs() rolls back only the hubs it newly
reserved, and waits on the root PD reservation first, honoring
amdgpu_vmid_free_spm()'s wait requirement; previously the rollback
could free pre-held hubs and unbind a VMID a just-submitted job uses.
- The return of amdgpu_xcp_get_inst_details() is checked; a stale
fpriv->xcp_id now fails the ioctl instead of silently reserving the
whole device.
James Zhu (3):
drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub
callback
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 68 ++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 ++++++++++++++++------
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 +
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 +
7 files changed, 132 insertions(+), 18 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC PATCH v2 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
@ 2026-11-17 18:19 ` James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2 siblings, 0 replies; 17+ messages in thread
From: James Zhu @ 2026-11-17 18:19 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the
setup_vm_pt_regs gfxhub callback programs a VMID's page table base on
every XCC. Callers which bind a VMID on a single VMHUB, like the SPM
VMID binding, have no way to reach one GFXHUB through the callback
interface.
gfxhub v1.2 and v12.1 already implement an XCC-masked variant
internally. Expose it as a new setup_vm_pt_regs_xcc callback. GFXHUBs
of IPs with a single XCC don't implement it, for them the existing
callback already is per-hub.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 +
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 +
3 files changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
index c7b44aeb671b..19b961cb12f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
@@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {
u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);
void (*setup_vm_pt_regs)(struct amdgpu_device *adev, uint32_t vmid,
uint64_t page_table_base);
+ void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev, uint32_t vmid,
+ uint64_t page_table_base, uint32_t xcc_mask);
int (*gart_enable)(struct amdgpu_device *adev);
void (*gart_disable)(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
index b13967a1c8fb..7bc17721f463 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
@@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = {
.get_fb_location = gfxhub_v12_1_get_fb_location,
.get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset,
.setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs,
+ .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v12_1_gart_enable,
.gart_disable = gfxhub_v12_1_gart_disable,
.set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
index e89813590539..a56c072daf15 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
@@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)
const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = {
.get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset,
.setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs,
+ .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v1_2_gart_enable,
.gart_disable = gfxhub_v1_2_gart_disable,
.set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
@ 2026-11-17 18:19 ` James Zhu
2026-11-17 18:47 ` sashiko-bot
2026-11-17 18:19 ` [RFC PATCH v2 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2 siblings, 1 reply; 17+ messages in thread
From: James Zhu @ 2026-11-17 18:19 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The SPM VMID reservation made through AMDGPU_VM_OP_RESERVE_VMID is
recorded on AMDGPU_GFXHUB(0) only, while gfxhub v1.2's
setup_vm_pt_regs broadcasts the page table base to every XCC. On
multi-XCC parts the two disagree, in both directions:
- the reservation only takes effect for jobs running on XCC 0, since
the VMID grab path checks vm->reserved_vmid[ring->vm_hub] and the
rings of XCC i use AMDGPU_GFXHUB(i);
- the page table base is physically programmed on all XCCs anyway,
and conflicting reservations are only detected on hub 0's id_mgr.
Make the hub argument real end to end: amdgpu_gmc_bind_vmid() programs
only the given hub, through the XCC-masked gfxhub callback where one
exists, and amdgpu_vmid_free_spm() unbinds the hub it frees instead of
hub 0. amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds
the reservation. The VM ioctl reserves the VMID on every GFXHUB
instance through the new amdgpu_vmid_alloc_spm_gfxhubs() helper, so
the reservation now takes effect, is bound and is flushed on every XCC
the VM's jobs can run on, and a conflicting reservation shows up on
whichever hub two VMs share.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 68 ++++++++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 56 +++++++++++++-------
4 files changed, 114 insertions(+), 18 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 08d3ff61edcc..704a30ad388a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -797,6 +797,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
*
* For VMIDs that are bound directly to a VM's page table outside the
* normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ * Only @vmhub is programmed and flushed, other hubs keep their binding.
*/
void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
unsigned int vmid, uint64_t pd_addr)
@@ -805,6 +806,9 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
if (is_mmhub)
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+ else if (adev->gfxhub.funcs->setup_vm_pt_regs_xcc)
+ adev->gfxhub.funcs->setup_vm_pt_regs_xcc(adev, vmid, pd_addr,
+ BIT(vmhub - AMDGPU_GFXHUB_START));
else
adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index 9c879ac68352..a4403e5cc344 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -651,12 +651,78 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
id_mgr->reserved_vmid = false;
if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs)
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+ amdgpu_gmc_bind_vmid(adev, vmhub,
adev->vm_manager.spm_vmid, 0);
}
mutex_unlock(&id_mgr->lock);
}
+/*
+ * amdgpu_vmid_alloc_spm_gfxhubs - reserve the SPM VMID on a set of GFXHUBs
+ * @adev: amdgpu device structure
+ * @vm: the VM to reserve the ID for
+ * @xcc_mask: XCC instances on whose GFXHUBs to reserve
+ *
+ * Reserve the SPM VMID on the GFXHUB of every XCC in @xcc_mask, so that
+ * the reservation covers every hub the VM's jobs can run on.
+ *
+ * Returns: 0 for success, the first per-hub error otherwise. On an error
+ * only the hubs this call reserved are released again, after waiting for
+ * the jobs which might have grabbed the reserved VMID in the meantime;
+ * hubs @vm already held before the call stay reserved.
+ */
+int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask)
+{
+ uint32_t allocated = 0;
+ int i, r;
+
+ for_each_inst(i, xcc_mask) {
+ bool held = amdgpu_vmid_uses_reserved(vm, AMDGPU_GFXHUB(i));
+
+ r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i));
+ if (r)
+ goto error_free;
+ if (!held)
+ allocated |= BIT(i);
+ }
+
+ return 0;
+
+error_free:
+ /*
+ * A job may already have grabbed a freshly reserved VMID, give it
+ * the wait amdgpu_vmid_free_spm() demands before the rollback
+ * unbinds the VMID again.
+ */
+ if (allocated) {
+ dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
+ DMA_RESV_USAGE_READ, false,
+ MAX_SCHEDULE_TIMEOUT);
+ amdgpu_vmid_free_spm_gfxhubs(adev, vm, allocated);
+ }
+ return r;
+}
+
+/*
+ * amdgpu_vmid_free_spm_gfxhubs - undo amdgpu_vmid_alloc_spm_gfxhubs
+ * @adev: amdgpu device structure
+ * @vm: the VM with the reserved ID
+ * @xcc_mask: XCC instances on whose GFXHUBs to free the reservation
+ *
+ * Free the SPM VMID on every GFXHUB in @xcc_mask @vm holds it on, hubs
+ * without a reservation are skipped. The same wait requirement as for
+ * amdgpu_vmid_free_spm() applies.
+ */
+void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask)
+{
+ int i;
+
+ for_each_inst(i, xcc_mask)
+ amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(i));
+}
+
/**
* amdgpu_vmid_reset - reset VMID to zero
*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
index c134000eecfd..d2b225d0aa38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
@@ -129,6 +129,10 @@ int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
unsigned vmhub);
void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
unsigned vmhub);
+int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask);
+void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, uint32_t xcc_mask);
int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
struct amdgpu_job *job, struct dma_fence **fence);
void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 6b4dc0276e27..a9c23759d058 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -589,30 +589,38 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)
* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base
* register must track whichever VM currently holds the reservation instead
* of being set per-job like a normal VMID. Bind it to @vm's real root PD
- * address if @vm holds the reservation; otherwise do nothing, since @vm is
- * not the one that could legitimately change the current binding.
+ * address on every GFXHUB @vm holds the reservation on; hubs reserved by
+ * other VMs or not reserved at all are left alone, since @vm is not the
+ * one that could legitimately change their binding.
*
* @vm's root PD must be locked by the caller.
*/
void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{
- struct amdgpu_kq_vmid_mgr *id_mgr =
- &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)];
+ /* the GFXHUBs are indexed by logical XCC, adev->gfx.xcc_mask is physical */
+ uint32_t gfxhub_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
uint64_t pd_addr;
+ int i;
if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs)
return;
- mutex_lock(&id_mgr->lock);
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
- &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) {
- mutex_unlock(&id_mgr->lock);
+ if (!amdgpu_vm_ready(vm))
return;
- }
pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
- mutex_unlock(&id_mgr->lock);
+ for_each_inst(i, gfxhub_mask) {
+ struct amdgpu_kq_vmid_mgr *id_mgr =
+ &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)];
+
+ mutex_lock(&id_mgr->lock);
+ if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] ==
+ &id_mgr->ids[adev->vm_manager.spm_vmid])
+ amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i),
+ adev->vm_manager.spm_vmid,
+ pd_addr);
+ mutex_unlock(&id_mgr->lock);
+ }
}
/**
@@ -2871,9 +2879,14 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
root = amdgpu_bo_ref(vm->root.bo);
amdgpu_bo_reserve(root, true);
/* Wait for the jobs which might still use the reserved VMID */
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
- dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
- false, MAX_SCHEDULE_TIMEOUT);
+ for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
+ if (vm->reserved_vmid[i]) {
+ dma_resv_wait_timeout(root->tbo.base.resv,
+ DMA_RESV_USAGE_READ,
+ false, MAX_SCHEDULE_TIMEOUT);
+ break;
+ }
+ }
dma_fence_wait(vm->last_unlocked, false);
dma_fence_put(vm->last_unlocked);
dma_fence_wait(vm->last_seq_flush, false);
@@ -3015,10 +3028,12 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
switch (args->in.op) {
case AMDGPU_VM_OP_RESERVE_VMID: {
+ /* logical XCCs, the GFXHUB index space; xcc_mask is physical */
+ uint32_t gfxhub_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
int r;
/* We only have requirement to reserve vmid from gfxhub */
- r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
+ r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, gfxhub_mask);
if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
amdgpu_vm_spm_update(adev, vm);
amdgpu_bo_unreserve(vm->root.bo);
@@ -3026,15 +3041,22 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
return r;
}
case AMDGPU_VM_OP_UNRESERVE_VMID: {
+ /* logical XCCs, the GFXHUB index space; xcc_mask is physical */
+ uint32_t gfxhub_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
struct amdgpu_bo *root = vm->root.bo;
+ bool reserved = false;
+ int i;
amdgpu_bo_reserve(root, true);
+ for_each_inst(i, gfxhub_mask)
+ reserved |= amdgpu_vmid_uses_reserved(vm,
+ AMDGPU_GFXHUB(i));
/* Wait for the jobs which might still use the reserved VMID */
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
+ if (reserved)
dma_resv_wait_timeout(root->tbo.base.resv,
DMA_RESV_USAGE_READ, false,
MAX_SCHEDULE_TIMEOUT);
- amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
+ amdgpu_vmid_free_spm_gfxhubs(adev, vm, gfxhub_mask);
amdgpu_bo_unreserve(root);
break;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH v2 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
@ 2026-11-17 18:19 ` James Zhu
2 siblings, 0 replies; 17+ messages in thread
From: James Zhu @ 2026-11-17 18:19 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On partitioned devices every partition is exposed as an own render
node and fpriv->xcp_id records which partition a drm file belongs to.
But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every
other partition from reserving, and rebinds the VMID's page table base
on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The
reservation then only covers the XCCs of the caller's partition, and
each partition can hold the reserved VMID on its own hubs
independently, matching the isolation the render nodes promise.
Unreserve keeps operating on every hub, freeing whatever the VM
actually holds.
Without partitioning, or on the whole-device node, the mask stays
adev->gfx.xcc_mask and nothing changes.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index a9c23759d058..403807cb615d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3032,6 +3032,20 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
uint32_t gfxhub_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
int r;
+ /*
+ * Scope the reservation to the hardware partition behind the
+ * caller's render node, so other partitions can hold the
+ * reserved VMID on their own XCCs independently. The
+ * partition's inst_mask is logical like the GFXHUB indices.
+ */
+ if (adev->xcp_mgr && fpriv->xcp_id != AMDGPU_XCP_NO_PARTITION) {
+ r = amdgpu_xcp_get_inst_details(
+ &adev->xcp_mgr->xcp[fpriv->xcp_id],
+ AMDGPU_XCP_GFX, &gfxhub_mask);
+ if (r)
+ return r;
+ }
+
/* We only have requirement to reserve vmid from gfxhub */
r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, gfxhub_mask);
if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-17 18:19 ` [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
@ 2026-11-17 18:47 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-17 18:47 UTC (permalink / raw)
To: James Zhu, amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: missing root PD lock in
amdgpu_vmid_alloc_spm_gfxhubs()
--
commit 4216e97db26fd6fc889673c452d2434887bc13af
Author: James Zhu <James.Zhu@amd.com>
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
This commit reserves, binds, and unbinds the SPM VMID on every GFXHUB
instance rather than only on AMDGPU_GFXHUB(0).
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> index 9c879ac683520..a4403e5cc3443 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> @@ -651,12 +651,78 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> id_mgr->reserved_vmid = false;
>
> if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs)
> - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
> + amdgpu_gmc_bind_vmid(adev, vmhub,
> adev->vm_manager.spm_vmid, 0);
> }
> mutex_unlock(&id_mgr->lock);
> }
>
> +/*
> + * amdgpu_vmid_alloc_spm_gfxhubs - reserve the SPM VMID on a set of GFXHUBs
> + * @adev: amdgpu device structure
> + * @vm: the VM to reserve the ID for
> + * @xcc_mask: XCC instances on whose GFXHUBs to reserve
> + *
> + * Reserve the SPM VMID on the GFXHUB of every XCC in @xcc_mask, so that
> + * the reservation covers every hub the VM's jobs can run on.
> + *
> + * Returns: 0 for success, the first per-hub error otherwise. On an error
> + * only the hubs this call reserved are released again, after waiting for
> + * the jobs which might have grabbed the reserved VMID in the meantime;
> + * hubs @vm already held before the call stay reserved.
> + */
> +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask)
> +{
> + uint32_t allocated = 0;
> + int i, r;
> +
> + for_each_inst(i, xcc_mask) {
> + bool held = amdgpu_vmid_uses_reserved(vm, AMDGPU_GFXHUB(i));
> +
> + r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i));
> + if (r)
> + goto error_free;
> + if (!held)
> + allocated |= BIT(i);
> + }
> +
> + return 0;
> +
> +error_free:
> + /*
> + * A job may already have grabbed a freshly reserved VMID, give it
> + * the wait amdgpu_vmid_free_spm() demands before the rollback
> + * unbinds the VMID again.
> + */
> + if (allocated) {
> + dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
> + DMA_RESV_USAGE_READ, false,
> + MAX_SCHEDULE_TIMEOUT);
> + amdgpu_vmid_free_spm_gfxhubs(adev, vm, allocated);
> + }
> + return r;
> +}
[ ... ]
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 94b1cfe05e3e0..f64020162a4bf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
[ ... ]
> @@ -3015,10 +3028,12 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>
> switch (args->in.op) {
> case AMDGPU_VM_OP_RESERVE_VMID: {
> + /* logical XCCs, the GFXHUB index space; xcc_mask is physical */
> + uint32_t gfxhub_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
> int r;
>
> /* We only have requirement to reserve vmid from gfxhub */
> - r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
> + r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, gfxhub_mask);
> if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
> amdgpu_vm_spm_update(adev, vm);
> amdgpu_bo_unreserve(vm->root.bo);
> }
> return r;
> }
[Severity: Medium]
Can the error rollback in amdgpu_vmid_alloc_spm_gfxhubs() unbind a newly
reserved SPM VMID while a concurrent CS job is still using it?
Unlike AMDGPU_VM_OP_UNRESERVE_VMID, AMDGPU_VM_OP_RESERVE_VMID calls
amdgpu_vmid_alloc_spm_gfxhubs() without holding the vm->root.bo
reservation lock:
CPU0 CPU1
amdgpu_vm_ioctl(RESERVE_VMID)
amdgpu_vmid_alloc_spm_gfxhubs()
amdgpu_vmid_alloc_spm(hub 0)
vm->reserved_vmid[hub 0] = id
amdgpu_vmid_alloc_spm(hub 1)
-> -ENOENT
dma_resv_wait_timeout(root)
amdgpu_cs_ioctl()
/* reserves root, adds fence */
amdgpu_job_prepare_job()
amdgpu_vmid_grab()
/* grabs reserved VMID on hub 0 */
amdgpu_vmid_free_spm(hub 0)
amdgpu_gmc_bind_vmid(..., 0) <-- unbinds VMID under active job
Because vm->root.bo is not reserved across the wait and free, a command
submission on the same VM can attach a new fence and grab the reserved
VMID on hub 0 after dma_resv_wait_timeout() returns and right before
amdgpu_vmid_free_spm() unbinds its page-table-base register to 0, causing
GPU page faults for the in-flight job.
Running without vm->root.bo reserved also leaves held =
amdgpu_vmid_uses_reserved() unsynchronized: amdgpu_vmid_alloc_spm()
returns 0 when vm->reserved_vmid[vmhub] is already set, so two concurrent
AMDGPU_VM_OP_RESERVE_VMID calls on the same VM can both observe held ==
false on hub 0 and set allocated |= BIT(0), causing a failure on a later
hub in one thread to free the reservation held by the other. Similarly,
concurrent RESERVE_VMID and UNRESERVE_VMID calls can interleave across
hubs, and if amdgpu_bo_reserve(vm->root.bo, true) fails after
amdgpu_vmid_alloc_spm_gfxhubs() succeeds, amdgpu_vm_spm_update() is
skipped while returning 0.
Reserving vm->root.bo in AMDGPU_VM_OP_RESERVE_VMID before calling
amdgpu_vmid_alloc_spm_gfxhubs() and holding it across
amdgpu_vm_spm_update() (matching AMDGPU_VM_OP_UNRESERVE_VMID) would
serialize per-VM reservation state and prevent new CS jobs during rollback.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117181941.3968996-1-James.Zhu@amd.com?part=2
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
2026-11-17 16:59 ` [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
@ 2026-11-18 9:36 ` Christian König
0 siblings, 0 replies; 17+ messages in thread
From: Christian König @ 2026-11-18 9:36 UTC (permalink / raw)
To: James Zhu, amd-gfx; +Cc: Sunil Khatri
On 11/17/26 17:59, James Zhu wrote:
> On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the
> setup_vm_pt_regs gfxhub callback programs a VMID's page table base on
> every XCC. Callers which bind a VMID on a single VMHUB, like the SPM
> VMID binding, have no way to reach one GFXHUB through the callback
> interface.
>
> gfxhub v1.2 and v12.1 already implement an XCC-masked variant
> internally. Expose it as a new setup_vm_pt_regs_xcc callback. GFXHUBs
> of IPs with a single XCC don't implement it, for them the existing
> callback already is per-hub.
>
> Signed-off-by: James Zhu <James.Zhu@amd.com>
> Assisted-by: Claude:claude-fable-5
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++
> drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 +
> drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 +
> 3 files changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
> index c7b44aeb671b..19b961cb12f6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
> @@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {
> u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);
> void (*setup_vm_pt_regs)(struct amdgpu_device *adev, uint32_t vmid,
> uint64_t page_table_base);
> + void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev, uint32_t vmid,
> + uint64_t page_table_base, uint32_t xcc_mask);
Don't add a new callback, extend the setup_vm_pt_regs with the xcc_mask instead.
Regards,
Christian.
> int (*gart_enable)(struct amdgpu_device *adev);
>
> void (*gart_disable)(struct amdgpu_device *adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> index b13967a1c8fb..7bc17721f463 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
> @@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = {
> .get_fb_location = gfxhub_v12_1_get_fb_location,
> .get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset,
> .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs,
> + .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs,
> .gart_enable = gfxhub_v12_1_gart_enable,
> .gart_disable = gfxhub_v12_1_gart_disable,
> .set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
> index e89813590539..a56c072daf15 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
> @@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)
> const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = {
> .get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset,
> .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs,
> + .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs,
> .gart_enable = gfxhub_v1_2_gart_enable,
> .gart_disable = gfxhub_v1_2_gart_disable,
> .set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-17 16:59 ` [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-17 17:21 ` sashiko-bot
@ 2026-11-18 9:38 ` Christian König
1 sibling, 0 replies; 17+ messages in thread
From: Christian König @ 2026-11-18 9:38 UTC (permalink / raw)
To: James Zhu, amd-gfx; +Cc: Sunil Khatri
On 11/17/26 17:59, James Zhu wrote:
> The SPM VMID reservation made through AMDGPU_VM_OP_RESERVE_VMID is
> recorded on AMDGPU_GFXHUB(0) only, while gfxhub v1.2's
> setup_vm_pt_regs broadcasts the page table base to every XCC. On
> multi-XCC parts the two disagree, in both directions:
>
> - the reservation only takes effect for jobs running on XCC 0, since
> the VMID grab path checks vm->reserved_vmid[ring->vm_hub] and the
> rings of XCC i use AMDGPU_GFXHUB(i);
> - the page table base is physically programmed on all XCCs anyway,
> and conflicting reservations are only detected on hub 0's id_mgr.
>
> Make the hub argument real end to end: amdgpu_gmc_bind_vmid() programs
> only the given hub, through the XCC-masked gfxhub callback where one
> exists, and amdgpu_vmid_free_spm() unbinds the hub it frees instead of
> hub 0. amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds
> the reservation. The VM ioctl reserves the VMID on every GFXHUB
> instance through the new amdgpu_vmid_alloc_spm_gfxhubs() helper, so
> the reservation now takes effect, is bound and is flushed on every XCC
> the VM's jobs can run on, and a conflicting reservation shows up on
> whichever hub two VMs share.
Don't add paralell infrastructure, instead change the existing one to handle the vmhub.
Regards,
Christian.
>
> Signed-off-by: James Zhu <James.Zhu@amd.com>
> Assisted-by: Claude:claude-fable-5
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++
> drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 49 ++++++++++++++++++++++++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 40 +++++++++++++-------
> 4 files changed, 82 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> index 08d3ff61edcc..704a30ad388a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> @@ -797,6 +797,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
> *
> * For VMIDs that are bound directly to a VM's page table outside the
> * normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
> + * Only @vmhub is programmed and flushed, other hubs keep their binding.
> */
> void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
> unsigned int vmid, uint64_t pd_addr)
> @@ -805,6 +806,9 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
>
> if (is_mmhub)
> adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
> + else if (adev->gfxhub.funcs->setup_vm_pt_regs_xcc)
> + adev->gfxhub.funcs->setup_vm_pt_regs_xcc(adev, vmid, pd_addr,
> + BIT(vmhub - AMDGPU_GFXHUB_START));
> else
> adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> index 9c879ac68352..41f3dba530e3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
> @@ -651,12 +651,59 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> id_mgr->reserved_vmid = false;
>
> if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs)
> - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
> + amdgpu_gmc_bind_vmid(adev, vmhub,
> adev->vm_manager.spm_vmid, 0);
> }
> mutex_unlock(&id_mgr->lock);
> }
>
> +/*
> + * amdgpu_vmid_alloc_spm_gfxhubs - reserve the SPM VMID on a set of GFXHUBs
> + * @adev: amdgpu device structure
> + * @vm: the VM to reserve the ID for
> + * @xcc_mask: XCC instances on whose GFXHUBs to reserve
> + *
> + * Reserve the SPM VMID on the GFXHUB of every XCC in @xcc_mask, so that
> + * the reservation covers every hub the VM's jobs can run on.
> + *
> + * Returns: 0 for success, the first per-hub error otherwise. On an error
> + * the reservation is released on every hub in @xcc_mask again.
> + */
> +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask)
> +{
> + int i, r;
> +
> + for_each_inst(i, xcc_mask) {
> + r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i));
> + if (r) {
> + amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask);
> + return r;
> + }
> + }
> +
> + return 0;
> +}
> +
> +/*
> + * amdgpu_vmid_free_spm_gfxhubs - undo amdgpu_vmid_alloc_spm_gfxhubs
> + * @adev: amdgpu device structure
> + * @vm: the VM with the reserved ID
> + * @xcc_mask: XCC instances on whose GFXHUBs to free the reservation
> + *
> + * Free the SPM VMID on every GFXHUB in @xcc_mask @vm holds it on, hubs
> + * without a reservation are skipped. The same wait requirement as for
> + * amdgpu_vmid_free_spm() applies.
> + */
> +void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask)
> +{
> + int i;
> +
> + for_each_inst(i, xcc_mask)
> + amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(i));
> +}
> +
> /**
> * amdgpu_vmid_reset - reset VMID to zero
> *
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
> index c134000eecfd..d2b225d0aa38 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
> @@ -129,6 +129,10 @@ int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> unsigned vmhub);
> void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
> unsigned vmhub);
> +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask);
> +void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev,
> + struct amdgpu_vm *vm, uint32_t xcc_mask);
> int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
> struct amdgpu_job *job, struct dma_fence **fence);
> void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 6b4dc0276e27..bd9aa35933dc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -589,30 +589,36 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> * The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base
> * register must track whichever VM currently holds the reservation instead
> * of being set per-job like a normal VMID. Bind it to @vm's real root PD
> - * address if @vm holds the reservation; otherwise do nothing, since @vm is
> - * not the one that could legitimately change the current binding.
> + * address on every GFXHUB @vm holds the reservation on; hubs reserved by
> + * other VMs or not reserved at all are left alone, since @vm is not the
> + * one that could legitimately change their binding.
> *
> * @vm's root PD must be locked by the caller.
> */
> void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm)
> {
> - struct amdgpu_kq_vmid_mgr *id_mgr =
> - &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)];
> uint64_t pd_addr;
> + int i;
>
> if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs)
> return;
>
> - mutex_lock(&id_mgr->lock);
> - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
> - &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) {
> - mutex_unlock(&id_mgr->lock);
> + if (!amdgpu_vm_ready(vm))
> return;
> - }
>
> pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
> - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
> - mutex_unlock(&id_mgr->lock);
> + for_each_inst(i, adev->gfx.xcc_mask) {
> + struct amdgpu_kq_vmid_mgr *id_mgr =
> + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)];
> +
> + mutex_lock(&id_mgr->lock);
> + if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] ==
> + &id_mgr->ids[adev->vm_manager.spm_vmid])
> + amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i),
> + adev->vm_manager.spm_vmid,
> + pd_addr);
> + mutex_unlock(&id_mgr->lock);
> + }
> }
>
> /**
> @@ -3018,7 +3024,8 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
> int r;
>
> /* We only have requirement to reserve vmid from gfxhub */
> - r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
> + r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm,
> + adev->gfx.xcc_mask);
> if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
> amdgpu_vm_spm_update(adev, vm);
> amdgpu_bo_unreserve(vm->root.bo);
> @@ -3027,14 +3034,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
> }
> case AMDGPU_VM_OP_UNRESERVE_VMID: {
> struct amdgpu_bo *root = vm->root.bo;
> + bool reserved = false;
> + int i;
>
> amdgpu_bo_reserve(root, true);
> + for_each_inst(i, adev->gfx.xcc_mask)
> + reserved |= amdgpu_vmid_uses_reserved(vm,
> + AMDGPU_GFXHUB(i));
> /* Wait for the jobs which might still use the reserved VMID */
> - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
> + if (reserved)
> dma_resv_wait_timeout(root->tbo.base.resv,
> DMA_RESV_USAGE_READ, false,
> MAX_SCHEDULE_TIMEOUT);
> - amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
> + amdgpu_vmid_free_spm_gfxhubs(adev, vm, adev->gfx.xcc_mask);
> amdgpu_bo_unreserve(root);
> break;
> }
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
` (3 preceding siblings ...)
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
@ 2026-11-18 16:24 ` James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 1/3] drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback James Zhu
` (2 more replies)
4 siblings, 3 replies; 17+ messages in thread
From: James Zhu @ 2026-11-18 16:24 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The reserved (SPM) VMID handling was designed on single-XCC hardware,
where one GFXHUB is all there is. On multi-XCC parts with partitioning
every XCC has an own GFXHUB and every partition is exposed as an own
render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on
AMDGPU_GFXHUB(0) only. The VMID grab path checks
vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use
AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the
reservation silently does nothing. A debugger relying on a stable
VMID gets one on exactly one XCC of the partition it runs on, or
none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs
gfxhub callback broadcasts the SPM VMID's page table base to every
XCC of the device, including XCCs of partitions the caller cannot
even submit to.
3. The exclusion is device-global: because every reservation contends
for hub 0's id_mgr, one partition's render node blocks every other
partition from reserving, which breaks the isolation the render
nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all
hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3
partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in
the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub
arrays), real end to end:
Patch 1 extends the setup_vm_pt_regs gfxhub callback with the mask of
logical XCCs to program and adds amdgpu_gfx_logical_xcc_mask() for
deriving that mask (the GFXHUBs are indexed by logical XCC, while
adev->gfx.xcc_mask holds physical instances and can be sparse under
harvesting); no functional change.
Patch 2 makes the hub argument of the binding path mean what it says:
amdgpu_gmc_bind_vmid() programs and flushes only the given hub, and
amdgpu_vmid_alloc_spm()/free_spm() take the set of GFXHUBs directly,
reserving on every hub the VM's jobs can run on, under the root PD
reservation as an asserted lock contract. This fixes 1. and 2. while
keeping the device-wide scope.
Patch 3 then derives the hub set from the caller's partition
(fpriv->xcp_id), fixing 3.: each partition reserves, binds and
conflicts only on its own XCCs. Unreserve keeps operating on every hub,
freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be
recorded on the partition's first GFXHUB only and treated as a pure
ownership token, closest to the original single-hub design. But the
record plays three roles at once: the ownership token, the set of hubs
whose page table base has to be bound (each XCC translates through its
own hub, so the binding must cover every XCC of the partition either
way), and the per-hub check of the VMID grab and CS paths
(vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the
partition keeps the three consistent by construction, lets
amdgpu_vm_spm_update() derive the binding set from the existing
structures without a new field, and gives jobs on every XCC of the
partition the same reserved-VMID semantics instead of only on the
first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device
node, the mask degenerates to every XCC and nothing changes; on
single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m (the
whole amdgpu directory builds warning-free); checkpatch clean.
v3: address Christian's review of the v1 structure and the Sashiko AI
review of v2:
- Per Christian: no parallel interfaces. Patch 1 extends the existing
setup_vm_pt_regs callback with an xcc_mask argument (all nine
implementations and all callers updated; gfxhub v1.2/v12.1 hook up
their internal XCC-masked variants directly and lose the broadcast
wrappers) instead of adding a setup_vm_pt_regs_xcc callback. Patch 2
changes amdgpu_vmid_alloc_spm()/amdgpu_vmid_free_spm() themselves to
take the GFXHUB set instead of adding *_gfxhubs() wrappers.
- Per the Sashiko review of v2 (verified): AMDGPU_VM_OP_RESERVE_VMID
takes the root PD reservation before reserving and holds it across
amdgpu_vm_spm_update(), matching UNRESERVE; both functions assert the
root PD reservation. This serializes the per-VM reservation state
against concurrent RESERVE/UNRESERVE, keeps a new CS of the same VM
from grabbing a freshly reserved VMID between the rollback's wait and
its unbind, and makes a failed root PD reservation an ioctl error.
amdgpu_vm_fini() consequently frees the reservation while the root PD
is still held.
- Further hardening from self-review: the logical-mask idiom lives in
one helper (amdgpu_gfx_logical_xcc_mask(), guarding xcc_mask == 0)
instead of eight open-coded copies; UNRESERVE checks the root PD
reservation result like RESERVE does; amdgpu_vm_spm_update() skips
hubs without a reservation with a lock-free check (reserved_vmid[]
only changes under the root PD reservation the caller holds), so the
common non-SPM VM takes no id_mgr lock on the userqueue validate
path.
v2: address the Sashiko AI review findings of v1, all of which checked
out:
- Iterate the GFXHUBs with a logical XCC mask instead of the physical
adev->gfx.xcc_mask, which can be sparse when an XCC is harvested and
would send out-of-range logical indices into GET_INST(). The
partition path already used the logical xcp inst_mask.
- amdgpu_vm_fini() now checks every VMHUB, not just GFXHUB(0), before
waiting for jobs that may still use a reserved VMID.
- The reservation rollback releases only the hubs the call newly
reserved, after waiting for jobs which might have grabbed the VMID.
- The return of amdgpu_xcp_get_inst_details() is checked; a stale
fpriv->xcp_id now fails the ioctl instead of silently reserving the
whole device.
James Zhu (3):
drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
.../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 3 +-
.../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 3 +-
.../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c | 3 +-
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 18 ++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 6 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 102 ++++++++++++++----
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 101 ++++++++++++-----
drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 4 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 5 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 13 +--
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 12 +--
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 4 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 4 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 4 +-
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 4 +-
20 files changed, 211 insertions(+), 90 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [RFC PATCH v3 1/3] drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
@ 2026-11-18 16:24 ` James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2 siblings, 0 replies; 17+ messages in thread
From: James Zhu @ 2026-11-18 16:24 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the
setup_vm_pt_regs gfxhub callback programs a VMID's page table base on
every XCC. Callers which bind a VMID on a single VMHUB, like the SPM
VMID binding, have no way to reach one GFXHUB through the callback
interface.
Extend the callback with the mask of logical XCCs to program. gfxhub
v1.2 and v12.1 already implement an XCC-masked variant internally, hook
it up directly and drop their broadcast wrappers; the implementations
for IPs with a single XCC ignore the mask. All callers pass the full
mask, no functional change.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 3 ++-
.../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 3 ++-
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c | 3 ++-
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 3 ++-
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 18 ++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++-
drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 4 ++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 5 +++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 13 +------------
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 12 +-----------
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 4 ++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 4 ++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 4 ++--
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 4 ++--
17 files changed, 48 insertions(+), 43 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
index 1550e275f0ee..762b3a53ebbd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
@@ -708,7 +708,8 @@ static void set_vm_context_page_table_base(struct amdgpu_device *adev,
}
/* SDMA is on gfxhub as well for Navi1* series */
- adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
+ adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base,
+ amdgpu_gfx_logical_xcc_mask(adev));
}
/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
index 50535563efa8..837a17dd03de 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
@@ -626,7 +626,8 @@ static void set_vm_context_page_table_base_v10_3(struct amdgpu_device *adev,
uint32_t vmid, uint64_t page_table_base)
{
/* SDMA is on gfxhub as well for Navi1* series */
- adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
+ adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base,
+ amdgpu_gfx_logical_xcc_mask(adev));
}
static void program_trap_handler_settings_v10_3(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c
index 96a308b94646..0c8983b353f2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c
@@ -606,7 +606,8 @@ static void set_vm_context_page_table_base_v11(struct amdgpu_device *adev,
}
/* SDMA is on gfxhub as well for gfx11 adapters */
- adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
+ adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base,
+ amdgpu_gfx_logical_xcc_mask(adev));
}
/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index 0bc8d31081e6..475058562b75 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -923,7 +923,8 @@ void kgd_gfx_v9_set_vm_context_page_table_base(struct amdgpu_device *adev,
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
- adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
+ adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base,
+ amdgpu_gfx_logical_xcc_mask(adev));
}
static void lock_spi_csq_mutexes(struct amdgpu_device *adev)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index c5a2dcff5058..f42fe3510f16 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -170,6 +170,24 @@ static bool amdgpu_gfx_is_compute_multipipe_capable(struct amdgpu_device *adev)
return adev->gfx.mec.num_mec > 1;
}
+/**
+ * amdgpu_gfx_logical_xcc_mask - mask of the logical XCCs
+ * @adev: amdgpu device pointer
+ *
+ * The GFXHUBs, and everything else going through GET_INST(GC, ...), are
+ * indexed by logical XCC. adev->gfx.xcc_mask holds physical instances
+ * and can be sparse when an XCC is harvested, so it must not be used to
+ * iterate the GFXHUBs.
+ *
+ * Returns: the contiguous mask of the logical XCCs.
+ */
+uint32_t amdgpu_gfx_logical_xcc_mask(struct amdgpu_device *adev)
+{
+ int num_xcc = NUM_XCC(adev->gfx.xcc_mask);
+
+ return num_xcc ? GENMASK(num_xcc - 1, 0) : 0;
+}
+
bool amdgpu_gfx_is_high_priority_graphics_queue(struct amdgpu_device *adev,
struct amdgpu_ring *ring)
{
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 6529c395f5bc..b7354a7dce79 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -597,6 +597,7 @@ static inline u32 amdgpu_gfx_create_bitmask(u32 bit_width)
return (u32)((1ULL << bit_width) - 1);
}
+uint32_t amdgpu_gfx_logical_xcc_mask(struct amdgpu_device *adev);
void amdgpu_gfx_parse_disable_cu(struct amdgpu_device *adev, unsigned int *mask,
unsigned int max_se, unsigned int max_sh);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
index c7b44aeb671b..65893a40c959 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
@@ -27,7 +27,7 @@ struct amdgpu_gfxhub_funcs {
u64 (*get_fb_location)(struct amdgpu_device *adev);
u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);
void (*setup_vm_pt_regs)(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base);
+ uint64_t page_table_base, uint32_t xcc_mask);
int (*gart_enable)(struct amdgpu_device *adev);
void (*gart_disable)(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 08d3ff61edcc..c0efb90e1d2e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -806,7 +806,8 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
if (is_mmhub)
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
else
- adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
+ adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr,
+ amdgpu_gfx_logical_xcc_mask(adev));
amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, TLB_FLUSH_LEGACY);
}
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c
index 8be912d50601..0b7d89d04f4c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c
@@ -122,7 +122,7 @@ static u64 gfxhub_v11_5_0_get_mc_fb_offset(struct amdgpu_device *adev)
}
static void gfxhub_v11_5_0_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base, uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -139,7 +139,7 @@ static void gfxhub_v11_5_0_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v11_5_0_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v11_5_0_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c
index 4144c1c2ee13..9bfd97671699 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c
@@ -125,7 +125,8 @@ static u64 gfxhub_v12_0_get_mc_fb_offset(struct amdgpu_device *adev)
static void gfxhub_v12_0_setup_vm_pt_regs(struct amdgpu_device *adev,
uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base,
+ uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -142,7 +143,7 @@ static void gfxhub_v12_0_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v12_0_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v12_0_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
index b13967a1c8fb..afcf7a58cae4 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c
@@ -79,17 +79,6 @@ static void gfxhub_v12_1_xcc_setup_vm_pt_regs(struct amdgpu_device *adev,
}
}
-static void gfxhub_v12_1_setup_vm_pt_regs(struct amdgpu_device *adev,
- uint32_t vmid,
- uint64_t page_table_base)
-{
- uint32_t xcc_mask;
-
- xcc_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
- gfxhub_v12_1_xcc_setup_vm_pt_regs(adev, vmid, page_table_base,
- xcc_mask);
-}
-
static void gfxhub_v12_1_xcc_init_gart_aperture_regs(struct amdgpu_device *adev,
uint32_t xcc_mask)
{
@@ -808,7 +797,7 @@ static void gfxhub_v12_1_init(struct amdgpu_device *adev)
const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = {
.get_fb_location = gfxhub_v12_1_get_fb_location,
.get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset,
- .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs,
+ .setup_vm_pt_regs = gfxhub_v12_1_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v12_1_gart_enable,
.gart_disable = gfxhub_v12_1_gart_disable,
.set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index c35856180c3c..a3ef12d6b20a 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -38,7 +38,8 @@ static u64 gfxhub_v1_0_get_mc_fb_offset(struct amdgpu_device *adev)
static void gfxhub_v1_0_setup_vm_pt_regs(struct amdgpu_device *adev,
uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base,
+ uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -60,7 +61,7 @@ static void gfxhub_v1_0_init_gart_aperture_regs(struct amdgpu_device *adev)
else
pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v1_0_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v1_0_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
/* If use GART for FB translation, vmid0 page table covers both
* vram and system memory (gart)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
index e89813590539..79653ffd42b6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c
@@ -62,16 +62,6 @@ static void gfxhub_v1_2_xcc_setup_vm_pt_regs(struct amdgpu_device *adev,
}
}
-static void gfxhub_v1_2_setup_vm_pt_regs(struct amdgpu_device *adev,
- uint32_t vmid,
- uint64_t page_table_base)
-{
- uint32_t xcc_mask;
-
- xcc_mask = GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0);
- gfxhub_v1_2_xcc_setup_vm_pt_regs(adev, vmid, page_table_base, xcc_mask);
-}
-
static void gfxhub_v1_2_xcc_init_gart_aperture_regs(struct amdgpu_device *adev,
uint32_t xcc_mask)
{
@@ -633,7 +623,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)
const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = {
.get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset,
- .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs,
+ .setup_vm_pt_regs = gfxhub_v1_2_xcc_setup_vm_pt_regs,
.gart_enable = gfxhub_v1_2_gart_enable,
.gart_disable = gfxhub_v1_2_gart_disable,
.set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
index 04778f9f95bd..0aabd25e1c71 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
@@ -118,7 +118,7 @@ static u64 gfxhub_v2_0_get_mc_fb_offset(struct amdgpu_device *adev)
}
static void gfxhub_v2_0_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base, uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -135,7 +135,7 @@ static void gfxhub_v2_0_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v2_0_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v2_0_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, mmGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
index 6c77c17878f8..3f2661f8531e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
@@ -121,7 +121,7 @@ static u64 gfxhub_v2_1_get_mc_fb_offset(struct amdgpu_device *adev)
}
static void gfxhub_v2_1_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base, uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -138,7 +138,7 @@ static void gfxhub_v2_1_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v2_1_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v2_1_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, mmGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c
index e2b9fd0c8af0..fdb47bf557c6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c
@@ -117,7 +117,7 @@ static u64 gfxhub_v3_0_get_mc_fb_offset(struct amdgpu_device *adev)
}
static void gfxhub_v3_0_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base, uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -134,7 +134,7 @@ static void gfxhub_v3_0_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v3_0_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v3_0_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c b/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c
index fa8b966b7ea1..4e6e35120b6c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c
@@ -120,7 +120,7 @@ static u64 gfxhub_v3_0_3_get_mc_fb_offset(struct amdgpu_device *adev)
}
static void gfxhub_v3_0_3_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
- uint64_t page_table_base)
+ uint64_t page_table_base, uint32_t xcc_mask)
{
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB(0)];
@@ -137,7 +137,7 @@ static void gfxhub_v3_0_3_init_gart_aperture_regs(struct amdgpu_device *adev)
{
uint64_t pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
- gfxhub_v3_0_3_setup_vm_pt_regs(adev, 0, pt_base);
+ gfxhub_v3_0_3_setup_vm_pt_regs(adev, 0, pt_base, BIT(0));
WREG32_SOC15(GC, 0, regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32,
(u32)(adev->gmc.gart_start >> 12));
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH v3 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 1/3] drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback James Zhu
@ 2026-11-18 16:24 ` James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2 siblings, 0 replies; 17+ messages in thread
From: James Zhu @ 2026-11-18 16:24 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
The SPM VMID reservation made through AMDGPU_VM_OP_RESERVE_VMID is
recorded on AMDGPU_GFXHUB(0) only, while gfxhub v1.2's
setup_vm_pt_regs broadcasts the page table base to every XCC. On
multi-XCC parts the two disagree, in both directions:
- the reservation only takes effect for jobs running on XCC 0, since
the VMID grab path checks vm->reserved_vmid[ring->vm_hub] and the
rings of XCC i use AMDGPU_GFXHUB(i);
- the page table base is physically programmed on all XCCs anyway,
and conflicting reservations are only detected on hub 0's id_mgr.
Make the hub argument real end to end: amdgpu_gmc_bind_vmid() programs
and flushes only the given hub, and amdgpu_vmid_alloc_spm() and
amdgpu_vmid_free_spm() take the set of GFXHUBs directly, reserving the
VMID on every hub the VM's jobs can run on. The hub loops use a logical
XCC mask (GENMASK(NUM_XCC() - 1, 0)): the GFXHUBs are indexed by
logical XCC, while adev->gfx.xcc_mask holds physical instances and can
be sparse when an XCC is harvested.
On a partial reservation failure only the hubs the call newly reserved
are released again, after waiting for jobs which might have grabbed the
VMID in the meantime. Both functions require the root PD reservation as
a documented, asserted lock contract; AMDGPU_VM_OP_RESERVE_VMID takes
it before reserving, which also serializes the per-VM reservation state
against concurrent RESERVE/UNRESERVE calls and makes a failed root PD
reservation an ioctl error instead of silently skipping the bind.
amdgpu_vm_fini() gives the reservation up while the root PD is still
held and checks every hub, not just hub 0, before waiting for jobs.
amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds the
reservation, so a conflicting reservation shows up on whichever hub two
VMs share.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 102 +++++++++++++++++++-----
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 87 +++++++++++++-------
4 files changed, 150 insertions(+), 48 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index c0efb90e1d2e..97068471e7a1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -797,6 +797,9 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
*
* For VMIDs that are bound directly to a VM's page table outside the
* normal per-job VM flush path, e.g. a dedicated out-of-pool VMID.
+ * Only @vmhub is flushed, and for a GFXHUB only @vmhub is programmed;
+ * the MMHUB callback still programs every AID's MMHUB on IPs with
+ * more than one.
*/
void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
unsigned int vmid, uint64_t pd_addr)
@@ -807,7 +810,7 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub,
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr);
else
adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr,
- amdgpu_gfx_logical_xcc_mask(adev));
+ BIT(vmhub - AMDGPU_GFXHUB_START));
amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, TLB_FLUSH_LEGACY);
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
index 9c879ac68352..cf4cc798912d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
@@ -589,17 +589,15 @@ bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub)
}
/*
- * amdgpu_vmid_alloc_spm - reserve a specific VMID for this vm
+ * amdgpu_vmid_alloc_spm_hub - reserve the SPM VMID on one VMHUB
* @adev: amdgpu device structure
* @vm: the VM to reserve an ID for
* @vmhub: the VMHUB which should be used
*
- * Mostly used to have a reserved VMID for debugging and SPM.
- *
* Returns: 0 for success, -ENOENT if an ID is already reserved.
*/
-int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
- unsigned vmhub)
+static int amdgpu_vmid_alloc_spm_hub(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, unsigned int vmhub)
{
struct amdgpu_kq_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
struct amdgpu_vmid *id;
@@ -628,18 +626,8 @@ int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
return r;
}
-/*
- * amdgpu_vmid_free_spm - free up a reserved VMID again
- * @adev: amdgpu device structure
- * @vm: the VM with the reserved ID
- * @vmhub: the VMHUB which should be used
- *
- * The caller must wait for all work that used the reserved VMID to finish
- * before, so submissions still in flight don't suddenly fault when its page
- * table gets unbound.
- */
-void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
- unsigned vmhub)
+static void amdgpu_vmid_free_spm_hub(struct amdgpu_device *adev,
+ struct amdgpu_vm *vm, unsigned int vmhub)
{
struct amdgpu_kq_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
struct amdgpu_vmid *id;
@@ -651,12 +639,90 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
id_mgr->reserved_vmid = false;
if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs)
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0),
+ amdgpu_gmc_bind_vmid(adev, vmhub,
adev->vm_manager.spm_vmid, 0);
}
mutex_unlock(&id_mgr->lock);
}
+/*
+ * amdgpu_vmid_free_spm - free up a reserved VMID again
+ * @adev: amdgpu device structure
+ * @vm: the VM with the reserved ID
+ * @gfxhub_mask: logical XCCs on whose GFXHUBs to free the reservation
+ *
+ * Free the SPM VMID on every GFXHUB in @gfxhub_mask @vm holds it on, hubs
+ * without a reservation are skipped. The caller must hold @vm's root PD
+ * reservation, and must wait for all work that used the reserved VMID to
+ * finish before, so submissions still in flight don't suddenly fault when
+ * its page table gets unbound.
+ */
+void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+ uint32_t gfxhub_mask)
+{
+ int i;
+
+ dma_resv_assert_held(vm->root.bo->tbo.base.resv);
+
+ for_each_inst(i, gfxhub_mask)
+ amdgpu_vmid_free_spm_hub(adev, vm, AMDGPU_GFXHUB(i));
+}
+
+/*
+ * amdgpu_vmid_alloc_spm - reserve the SPM VMID for this vm
+ * @adev: amdgpu device structure
+ * @vm: the VM to reserve the ID for
+ * @gfxhub_mask: logical XCCs on whose GFXHUBs to reserve
+ *
+ * Mostly used to have a reserved VMID for debugging and SPM, reserved on
+ * the GFXHUB of every XCC in @gfxhub_mask so that the reservation covers
+ * every hub the VM's jobs can run on.
+ *
+ * The caller must hold @vm's root PD reservation: it serializes the
+ * per-VM reservation state and keeps new jobs of @vm from grabbing a
+ * freshly reserved VMID while the error path unbinds it again.
+ *
+ * Returns: 0 for success, the first per-hub error otherwise (-ENOENT if
+ * the ID is already reserved). On an error only the hubs this call
+ * reserved are released again, after waiting for the jobs which might
+ * have grabbed the reserved VMID in the meantime; hubs @vm already held
+ * before the call stay reserved.
+ */
+int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
+ uint32_t gfxhub_mask)
+{
+ uint32_t allocated = 0;
+ int i, r;
+
+ dma_resv_assert_held(vm->root.bo->tbo.base.resv);
+
+ for_each_inst(i, gfxhub_mask) {
+ bool held = amdgpu_vmid_uses_reserved(vm, AMDGPU_GFXHUB(i));
+
+ r = amdgpu_vmid_alloc_spm_hub(adev, vm, AMDGPU_GFXHUB(i));
+ if (r)
+ goto error_free;
+ if (!held)
+ allocated |= BIT(i);
+ }
+
+ return 0;
+
+error_free:
+ /*
+ * A job may already have grabbed a freshly reserved VMID, give it
+ * the wait amdgpu_vmid_free_spm() demands before the rollback
+ * unbinds the VMID again.
+ */
+ if (allocated) {
+ dma_resv_wait_timeout(vm->root.bo->tbo.base.resv,
+ DMA_RESV_USAGE_READ, false,
+ MAX_SCHEDULE_TIMEOUT);
+ amdgpu_vmid_free_spm(adev, vm, allocated);
+ }
+ return r;
+}
+
/**
* amdgpu_vmid_reset - reset VMID to zero
*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
index c134000eecfd..f2a721c836af 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h
@@ -126,9 +126,9 @@ bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
struct amdgpu_vmid *id);
bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub);
int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
- unsigned vmhub);
+ uint32_t gfxhub_mask);
void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm,
- unsigned vmhub);
+ uint32_t gfxhub_mask);
int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
struct amdgpu_job *job, struct dma_fence **fence);
void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 6b4dc0276e27..e81fbe32e3c8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -589,30 +589,45 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm)
* The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base
* register must track whichever VM currently holds the reservation instead
* of being set per-job like a normal VMID. Bind it to @vm's real root PD
- * address if @vm holds the reservation; otherwise do nothing, since @vm is
- * not the one that could legitimately change the current binding.
+ * address on every GFXHUB @vm holds the reservation on; hubs reserved by
+ * other VMs or not reserved at all are left alone, since @vm is not the
+ * one that could legitimately change their binding.
*
* @vm's root PD must be locked by the caller.
*/
void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{
- struct amdgpu_kq_vmid_mgr *id_mgr =
- &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)];
- uint64_t pd_addr;
+ uint32_t gfxhub_mask = amdgpu_gfx_logical_xcc_mask(adev);
+ uint64_t pd_addr = 0;
+ int i;
if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs)
return;
- mutex_lock(&id_mgr->lock);
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] !=
- &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) {
- mutex_unlock(&id_mgr->lock);
+ if (!amdgpu_vm_ready(vm))
return;
- }
- pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
- amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr);
- mutex_unlock(&id_mgr->lock);
+ for_each_inst(i, gfxhub_mask) {
+ struct amdgpu_kq_vmid_mgr *id_mgr =
+ &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)];
+
+ /*
+ * reserved_vmid[] only changes under the root PD reservation
+ * the caller holds, so the common case - a VM not holding
+ * the SPM VMID - gets away without taking any lock.
+ */
+ if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] !=
+ &id_mgr->ids[adev->vm_manager.spm_vmid])
+ continue;
+
+ if (!pd_addr)
+ pd_addr = amdgpu_gmc_pd_addr(vm->root.bo);
+
+ mutex_lock(&id_mgr->lock);
+ amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i),
+ adev->vm_manager.spm_vmid, pd_addr);
+ mutex_unlock(&id_mgr->lock);
+ }
}
/**
@@ -2871,9 +2886,15 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
root = amdgpu_bo_ref(vm->root.bo);
amdgpu_bo_reserve(root, true);
/* Wait for the jobs which might still use the reserved VMID */
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
- dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
- false, MAX_SCHEDULE_TIMEOUT);
+ for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
+ if (vm->reserved_vmid[i]) {
+ dma_resv_wait_timeout(root->tbo.base.resv,
+ DMA_RESV_USAGE_READ,
+ false, MAX_SCHEDULE_TIMEOUT);
+ break;
+ }
+ }
+ amdgpu_vmid_free_spm(adev, vm, amdgpu_gfx_logical_xcc_mask(adev));
dma_fence_wait(vm->last_unlocked, false);
dma_fence_put(vm->last_unlocked);
dma_fence_wait(vm->last_seq_flush, false);
@@ -2914,10 +2935,6 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
dma_fence_put(vm->last_update);
- for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
- amdgpu_vmid_free_spm(adev, vm, i);
- }
-
ttm_lru_bulk_move_fini(&adev->mman.bdev, &vm->lru_bulk_move);
if (!amdgpu_vm_stats_is_zero(vm)) {
@@ -3015,26 +3032,42 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
switch (args->in.op) {
case AMDGPU_VM_OP_RESERVE_VMID: {
+ uint32_t gfxhub_mask = amdgpu_gfx_logical_xcc_mask(adev);
int r;
+ /*
+ * The root PD reservation serializes the per-VM reservation
+ * state and keeps new jobs of this VM from grabbing a freshly
+ * reserved VMID while an error path would unbind it again.
+ */
+ r = amdgpu_bo_reserve(vm->root.bo, true);
+ if (r)
+ return r;
/* We only have requirement to reserve vmid from gfxhub */
- r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
- if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
+ r = amdgpu_vmid_alloc_spm(adev, vm, gfxhub_mask);
+ if (!r)
amdgpu_vm_spm_update(adev, vm);
- amdgpu_bo_unreserve(vm->root.bo);
- }
+ amdgpu_bo_unreserve(vm->root.bo);
return r;
}
case AMDGPU_VM_OP_UNRESERVE_VMID: {
+ uint32_t gfxhub_mask = amdgpu_gfx_logical_xcc_mask(adev);
struct amdgpu_bo *root = vm->root.bo;
+ bool reserved = false;
+ int i, r;
- amdgpu_bo_reserve(root, true);
+ r = amdgpu_bo_reserve(root, true);
+ if (r)
+ return r;
+ for_each_inst(i, gfxhub_mask)
+ reserved |= amdgpu_vmid_uses_reserved(vm,
+ AMDGPU_GFXHUB(i));
/* Wait for the jobs which might still use the reserved VMID */
- if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
+ if (reserved)
dma_resv_wait_timeout(root->tbo.base.resv,
DMA_RESV_USAGE_READ, false,
MAX_SCHEDULE_TIMEOUT);
- amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
+ amdgpu_vmid_free_spm(adev, vm, gfxhub_mask);
amdgpu_bo_unreserve(root);
break;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [RFC PATCH v3 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 1/3] drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
@ 2026-11-18 16:24 ` James Zhu
2 siblings, 0 replies; 17+ messages in thread
From: James Zhu @ 2026-11-18 16:24 UTC (permalink / raw)
To: amd-gfx; +Cc: Christian König, Sunil Khatri, James Zhu
On partitioned devices every partition is exposed as an own render
node and fpriv->xcp_id records which partition a drm file belongs to.
But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every
other partition from reserving, and rebinds the VMID's page table base
on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The
reservation then only covers the XCCs of the caller's partition, and
each partition can hold the reserved VMID on its own hubs
independently, matching the isolation the render nodes promise.
Unreserve keeps operating on every hub, freeing whatever the VM
actually holds.
Without partitioning, or on the whole-device node, the mask stays the
full set of XCCs and nothing changes.
Signed-off-by: James Zhu <James.Zhu@amd.com>
Assisted-by: Claude:claude-fable-5
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index e81fbe32e3c8..131bafb5530f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3035,6 +3035,20 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
uint32_t gfxhub_mask = amdgpu_gfx_logical_xcc_mask(adev);
int r;
+ /*
+ * Scope the reservation to the hardware partition behind the
+ * caller's render node, so other partitions can hold the
+ * reserved VMID on their own XCCs independently. The
+ * partition's inst_mask is logical like the GFXHUB indices.
+ */
+ if (adev->xcp_mgr && fpriv->xcp_id != AMDGPU_XCP_NO_PARTITION) {
+ r = amdgpu_xcp_get_inst_details(
+ &adev->xcp_mgr->xcp[fpriv->xcp_id],
+ AMDGPU_XCP_GFX, &gfxhub_mask);
+ if (r)
+ return r;
+ }
+
/*
* The root PD reservation serializes the per-VM reservation
* state and keeps new jobs of this VM from grabbing a freshly
--
2.34.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-11-18 16:25 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 16:59 [RFC PATCH 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 16:59 ` [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
2026-11-18 9:36 ` Christian König
2026-11-17 16:59 ` [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-17 17:21 ` sashiko-bot
2026-11-18 9:38 ` Christian König
2026-11-17 16:59 ` [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2026-11-17 17:18 ` sashiko-bot
2026-11-17 18:19 ` [RFC PATCH v2 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback James Zhu
2026-11-17 18:19 ` [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-17 18:47 ` sashiko-bot
2026-11-17 18:19 ` [RFC PATCH v2 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 0/3] drm/amdgpu: make the reserved SPM VMID per-partition James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 1/3] drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance James Zhu
2026-11-18 16:24 ` [RFC PATCH v3 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition James Zhu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox