Skip to contentSkip to conversation

drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

PATCH In review Shaoyun Liu 2 participants 5 messages Jul 30, 2025 – Aug 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

From MES version 0x81, it provide the new API INV_TLBS that support invalidate tlbs with PASID.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h |  9 +++++++++
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c  | 15 +++++++++++++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +9 -0
index c0d2c195fe2e..f4c40f1aecd2 100644
@@ -280,6 +280,12 @@ struct mes_reset_queue_input {
 	bool                               is_kq;
 };
 
+struct mes_inv_tlbs_pasid_input {
+	uint16_t        pasid;
+	uint8_t         hub_id;
+	uint8_t         flush_type;
+};
+
 enum mes_misc_opcode {
 	MES_MISC_OP_WRITE_REG,
 	MES_MISC_OP_READ_REG,
@@ -367,6 +373,9 @@ struct amdgpu_mes_funcs {
 
 	int (*reset_hw_queue)(struct amdgpu_mes *mes,
 			      struct mes_reset_queue_input *input);
+
+	int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
+			      struct mes_inv_tlbs_pasid_input *input);
 };
 
 #define amdgpu_mes_kiq_hw_init(adev) (adev)->mes.kiq_hw_init((adev))
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +15 -0
index feb92e107af8..323ec04094ed 100644
@@ -339,6 +339,21 @@ static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
 	uint16_t queried;
 	int vmid, i;
 
+	if (adev->enable_uni_mes && adev->mes.ring[0].sched.ready &&
+	    (adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >= 0x81) {
+
+		struct mes_inv_tlbs_pasid_input input = {0};
+		input.pasid = pasid;
+		input.flush_type = flush_type;
+		adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+		if (all_hub) {
+			/* hub_id = 1 means  for mm_hub*/
+			input.hub_id = 1;
+			adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+		}
+		return;
+	}
+
 	for (vmid = 1; vmid < 16; vmid++) {
 		bool valid;
 
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +24 -0
index 6b222630f3fa..2e9191fffaf1 100644
@@ -108,6 +108,7 @@ static const char *mes_v12_0_opcodes[] = {
 	"SET_SE_MODE",
 	"SET_GANG_SUBMIT",
 	"SET_HW_RSRC_1",
+	"INVALIDATE_TLBS",
 };
 
 static const char *mes_v12_0_misc_opcodes[] = {
@@ -879,6 +880,28 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,
 			offsetof(union MESAPI__RESET, api_status));
 }
 
+static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
+				    struct mes_inv_tlbs_pasid_input *input)
+{
+	union MESAPI__INV_TLBS mes_inv_tlbs;
+
+	memset(&mes_inv_tlbs, 0, sizeof(mes_inv_tlbs));
+
+	mes_inv_tlbs.header.type = MES_API_TYPE_SCHEDULER;
+	mes_inv_tlbs.header.opcode = MES_SCH_API_INV_TLBS;
+	mes_inv_tlbs.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+	mes_inv_tlbs.invalidate_tlbs.inv_sel = 0;
+	mes_inv_tlbs.invalidate_tlbs.flush_type = input->flush_type;
+	mes_inv_tlbs.invalidate_tlbs.inv_sel_id = input->pasid;
+	mes_inv_tlbs.invalidate_tlbs.hub_id = (uint32_t)input->hub_id;
+
+	return mes_v12_0_submit_pkt_and_poll_completion(mes, AMDGPU_MES_KIQ_PIPE,
+			&mes_inv_tlbs, sizeof(mes_inv_tlbs),
+			offsetof(union MESAPI__INV_TLBS, api_status));
+
+}
+
 static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
 	.add_hw_queue = mes_v12_0_add_hw_queue,
 	.remove_hw_queue = mes_v12_0_remove_hw_queue,
@@ -888,6 +911,7 @@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
 	.resume_gang = mes_v12_0_resume_gang,
 	.misc_op = mes_v12_0_misc_op,
 	.reset_hw_queue = mes_v12_0_reset_hw_queue,
+	.invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
 };
 
 static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device *adev,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 42 lines · Shaoyun Liu

From MES version 0x81, it provide the new API INV_TLBS that support invalidate tlbs with PASID.

---> drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 9 +++++++++

 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c  | 15 +++++++++++++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +9 -0
index c0d2c195fe2e..f4c40f1aecd2 100644
@@ -280,6 +280,12 @@ struct mes_reset_queue_input {
        bool                               is_kq;
 };
 
+struct mes_inv_tlbs_pasid_input {
+       uint16_t        pasid;
+       uint8_t         hub_id;
+       uint8_t         flush_type;
+};
+
 enum mes_misc_opcode {
        MES_MISC_OP_WRITE_REG,
        MES_MISC_OP_READ_REG,
@@ -367,6 +373,9 @@ struct amdgpu_mes_funcs {
 
        int (*reset_hw_queue)(struct amdgpu_mes *mes,
                              struct mes_reset_queue_input *input);
+
+       int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
+                             struct mes_inv_tlbs_pasid_input *input);
 };
 
 #define amdgpu_mes_kiq_hw_init(adev) (adev)->mes.kiq_hw_init((adev))
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index feb92e107af8..323ec04094ed 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev, · line 342

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
@@ -339,6 +339,21 @@ static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
        uint16_t queried;
        int vmid, i;
 
+       if (adev->enable_uni_mes && adev->mes.ring[0].sched.ready &&

maybe specify the pipe index explicitly? E.g.,, adev->mes.ring[AMDGPU_MES_SCHED_PIPE].sched.ready I always forget which index is KIQ and which is SCHED.

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +14 -0
+           (adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >= 0x81) {
+
+               struct mes_inv_tlbs_pasid_input input = {0};
+               input.pasid = pasid;
+               input.flush_type = flush_type;
+               adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               if (all_hub) {
+                       /* hub_id = 1 means  for mm_hub*/
+                       input.hub_id = 1;
+                       adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               }
+               return;
+       }
+
        for (vmid = 1; vmid < 16; vmid++) {
                bool valid;
 
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +8 -0
index 6b222630f3fa..2e9191fffaf1 100644
@@ -108,6 +108,7 @@ static const char *mes_v12_0_opcodes[] = {
        "SET_SE_MODE",
        "SET_GANG_SUBMIT",
        "SET_HW_RSRC_1",
+       "INVALIDATE_TLBS",
 };
 
 static const char *mes_v12_0_misc_opcodes[] = {
@@ -879,6 +880,28 @@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,
                        offsetof(union MESAPI__RESET, api_status));
 }
 
+static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
+                                   struct mes_inv_tlbs_pasid_input *input)
+{
+       union MESAPI__INV_TLBS mes_inv_tlbs;
+
+       memset(&mes_inv_tlbs, 0, sizeof(mes_inv_tlbs));
+

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes, · line 899

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +10 -0
+       mes_inv_tlbs.header.type = MES_API_TYPE_SCHEDULER;
+       mes_inv_tlbs.header.opcode = MES_SCH_API_INV_TLBS;
+       mes_inv_tlbs.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_inv_tlbs.invalidate_tlbs.inv_sel = 0;
+       mes_inv_tlbs.invalidate_tlbs.flush_type = input->flush_type;
+       mes_inv_tlbs.invalidate_tlbs.inv_sel_id = input->pasid;
+       mes_inv_tlbs.invalidate_tlbs.hub_id = (uint32_t)input->hub_id;
+
+       return mes_v12_0_submit_pkt_and_poll_completion(mes, AMDGPU_MES_KIQ_PIPE,

Should this be AMDGPU_MES_KIQ_PIPE or AMDGPU_MES_SCHED_PIPE? This seems to differ from the check above in gmc_v12_0_flush_gpu_tlb_pasid().

Alex

Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -1
+                       &mes_inv_tlbs, sizeof(mes_inv_tlbs),
+                       offsetof(union MESAPI__INV_TLBS, api_status));
+
+}
+
 static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .add_hw_queue = mes_v12_0_add_hw_queue,
        .remove_hw_queue = mes_v12_0_remove_hw_queue,
@@ -888,6 +911,7 @@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .resume_gang = mes_v12_0_resume_gang,
        .misc_op = mes_v12_0_misc_op,
        .reset_hw_queue = mes_v12_0_reset_hw_queue,
+       .invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
 };
 
 static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device *adev,
--

2.34.1

#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, August 6, 2025 1:45 PM
To: Liu, Shaoyun <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

Quoted 44 lines · Shaoyun Liu

From MES version 0x81, it provide the new API INV_TLBS that support invalidate tlbs with PASID.

---> drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 9 +++++++++

 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c  | 15 +++++++++++++++
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +9 -0
index c0d2c195fe2e..f4c40f1aecd2 100644
@@ -280,6 +280,12 @@ struct mes_reset_queue_input {
        bool                               is_kq;
 };
 
+struct mes_inv_tlbs_pasid_input {
+       uint16_t        pasid;
+       uint8_t         hub_id;
+       uint8_t         flush_type;
+};
+
 enum mes_misc_opcode {
        MES_MISC_OP_WRITE_REG,
        MES_MISC_OP_READ_REG,
@@ -367,6 +373,9 @@ struct amdgpu_mes_funcs {
 
        int (*reset_hw_queue)(struct amdgpu_mes *mes,
                              struct mes_reset_queue_input *input);
+
+       int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
+                             struct mes_inv_tlbs_pasid_input *input);
 };
 
 #define amdgpu_mes_kiq_hw_init(adev) (adev)->mes.kiq_hw_init((adev))
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index feb92e107af8..323ec04094ed 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev, · line 342

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
@@ -339,6 +339,21 @@ static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
        uint16_t queried;
        int vmid, i;
 
+       if (adev->enable_uni_mes && adev->mes.ring[0].sched.ready &&

maybe specify the pipe index explicitly? E.g.,, adev->mes.ring[AMDGPU_MES_SCHED_PIPE].sched.ready I always forget which index is KIQ and which is SCHED.

[shaoyunl] ok .

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +15 -0
+           (adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >=
+ 0x81) {
+
+               struct mes_inv_tlbs_pasid_input input = {0};
+               input.pasid = pasid;
+               input.flush_type = flush_type;
+               adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               if (all_hub) {
+                       /* hub_id = 1 means  for mm_hub*/
+                       input.hub_id = 1;
+                       adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               }
+               return;
+       }
+
        for (vmid = 1; vmid < 16; vmid++) {
                bool valid;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +1 -0
index 6b222630f3fa..2e9191fffaf1 100644
@@ -108,6 +108,7 @@ static const char *mes_v12_0_opcodes[] = {
        "SET_SE_MODE",
        "SET_GANG_SUBMIT",
        "SET_HW_RSRC_1",
+       "INVALIDATE_TLBS",
 };
 
 static const char *mes_v12_0_misc_opcodes[] = { @@ -879,6 +880,28 @@

static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

                        offsetof(union MESAPI__RESET, api_status));  }
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +8 -0
+static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
+                                   struct mes_inv_tlbs_pasid_input
+*input) {
+       union MESAPI__INV_TLBS mes_inv_tlbs;
+
+       memset(&mes_inv_tlbs, 0, sizeof(mes_inv_tlbs));
+
+       mes_inv_tlbs.header.type = MES_API_TYPE_SCHEDULER;

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +10 -0
+       mes_inv_tlbs.header.opcode = MES_SCH_API_INV_TLBS;
+       mes_inv_tlbs.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_inv_tlbs.invalidate_tlbs.inv_sel = 0;
+       mes_inv_tlbs.invalidate_tlbs.flush_type = input->flush_type;
+       mes_inv_tlbs.invalidate_tlbs.inv_sel_id = input->pasid;
+       mes_inv_tlbs.invalidate_tlbs.hub_id = (uint32_t)input->hub_id;
+
+       return mes_v12_0_submit_pkt_and_poll_completion(mes,
+ AMDGPU_MES_KIQ_PIPE,

Should this be AMDGPU_MES_KIQ_PIPE or AMDGPU_MES_SCHED_PIPE? This seems to differ from the check above in gmc_v12_0_flush_gpu_tlb_pasid().

Alex

[Shaoyun.liu] What I want is submit to the kiq pipe when unified MES is ready , the above check is for MES is ready or not. We would like all none running-list related operation been submitted to KIQ so it won't create any unnecessary delay or impact on process schedule decision . It's like original driver usage for KIQ . The sched pipe (HIQ) will be used for all user queues.

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +5 -0
+                       &mes_inv_tlbs, sizeof(mes_inv_tlbs),
+                       offsetof(union MESAPI__INV_TLBS, api_status));
+
+}
+
 static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .add_hw_queue = mes_v12_0_add_hw_queue,
        .remove_hw_queue = mes_v12_0_remove_hw_queue, @@ -888,6 +911,7
@@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .resume_gang = mes_v12_0_resume_gang,
        .misc_op = mes_v12_0_misc_op,
        .reset_hw_queue = mes_v12_0_reset_hw_queue,

+ .invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
};

static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device
*adev,
--
2.34.1

#3 lore raw
Quoted 122 lines · Shaoyun

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, August 6, 2025 1:45 PM
To: Liu, Shaoyun <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

Quoted 44 lines · Shaoyun Liu

From MES version 0x81, it provide the new API INV_TLBS that support invalidate tlbs with PASID.

---> drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 9 +++++++++

 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c  | 15 +++++++++++++++
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +9 -0
index c0d2c195fe2e..f4c40f1aecd2 100644
@@ -280,6 +280,12 @@ struct mes_reset_queue_input {
        bool                               is_kq;
 };
 
+struct mes_inv_tlbs_pasid_input {
+       uint16_t        pasid;
+       uint8_t         hub_id;
+       uint8_t         flush_type;
+};
+
 enum mes_misc_opcode {
        MES_MISC_OP_WRITE_REG,
        MES_MISC_OP_READ_REG,
@@ -367,6 +373,9 @@ struct amdgpu_mes_funcs {
 
        int (*reset_hw_queue)(struct amdgpu_mes *mes,
                              struct mes_reset_queue_input *input);
+
+       int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
+                             struct mes_inv_tlbs_pasid_input *input);
 };
 
 #define amdgpu_mes_kiq_hw_init(adev) (adev)->mes.kiq_hw_init((adev))
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +0 -0
index feb92e107af8..323ec04094ed 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev, · line 342

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
@@ -339,6 +339,21 @@ static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
        uint16_t queried;
        int vmid, i;
 
+       if (adev->enable_uni_mes && adev->mes.ring[0].sched.ready &&

maybe specify the pipe index explicitly? E.g.,, adev->mes.ring[AMDGPU_MES_SCHED_PIPE].sched.ready I always forget which index is KIQ and which is SCHED.

[shaoyunl] ok .

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +15 -0
+           (adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >=
+ 0x81) {
+
+               struct mes_inv_tlbs_pasid_input input = {0};
+               input.pasid = pasid;
+               input.flush_type = flush_type;
+               adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               if (all_hub) {
+                       /* hub_id = 1 means  for mm_hub*/
+                       input.hub_id = 1;
+                       adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               }
+               return;
+       }
+
        for (vmid = 1; vmid < 16; vmid++) {
                bool valid;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +1 -0
index 6b222630f3fa..2e9191fffaf1 100644
@@ -108,6 +108,7 @@ static const char *mes_v12_0_opcodes[] = {
        "SET_SE_MODE",
        "SET_GANG_SUBMIT",
        "SET_HW_RSRC_1",
+       "INVALIDATE_TLBS",
 };
 
 static const char *mes_v12_0_misc_opcodes[] = { @@ -879,6 +880,28 @@

static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

                        offsetof(union MESAPI__RESET, api_status));  }
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +8 -0
+static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
+                                   struct mes_inv_tlbs_pasid_input
+*input) {
+       union MESAPI__INV_TLBS mes_inv_tlbs;
+
+       memset(&mes_inv_tlbs, 0, sizeof(mes_inv_tlbs));
+
+       mes_inv_tlbs.header.type = MES_API_TYPE_SCHEDULER;

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +10 -0
+       mes_inv_tlbs.header.opcode = MES_SCH_API_INV_TLBS;
+       mes_inv_tlbs.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_inv_tlbs.invalidate_tlbs.inv_sel = 0;
+       mes_inv_tlbs.invalidate_tlbs.flush_type = input->flush_type;
+       mes_inv_tlbs.invalidate_tlbs.inv_sel_id = input->pasid;
+       mes_inv_tlbs.invalidate_tlbs.hub_id = (uint32_t)input->hub_id;
+
+       return mes_v12_0_submit_pkt_and_poll_completion(mes,
+ AMDGPU_MES_KIQ_PIPE,

Should this be AMDGPU_MES_KIQ_PIPE or AMDGPU_MES_SCHED_PIPE? This seems to differ from the check above in gmc_v12_0_flush_gpu_tlb_pasid().

Quoted 4 lines

Alex

[Shaoyun.liu] What I want is submit to the kiq pipe when unified MES is ready , the above check is for MES is ready or not. We would like all none running-list related operation been submitted to KIQ so it won't create any unnecessary delay or impact on process schedule decision . It's like original driver usage for KIQ . The sched pipe (HIQ) will be used for all user queues.

In that case, should we check if both pipes are ready in gmc_v12_0_flush_gpu_tlb_pasid()?

Alex

Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +5 -0
+                       &mes_inv_tlbs, sizeof(mes_inv_tlbs),
+                       offsetof(union MESAPI__INV_TLBS, api_status));
+
+}
+
 static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .add_hw_queue = mes_v12_0_add_hw_queue,
        .remove_hw_queue = mes_v12_0_remove_hw_queue, @@ -888,6 +911,7
@@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .resume_gang = mes_v12_0_resume_gang,
        .misc_op = mes_v12_0_misc_op,
        .reset_hw_queue = mes_v12_0_reset_hw_queue,

+ .invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
};

static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device
*adev,
--
2.34.1

#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, August 6, 2025 2:06 PM
To: Liu, Shaoyun <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

Quoted 129 lines · Shaoyun

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Wednesday, August 6, 2025 1:45 PM
To: Liu, Shaoyun <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] drm/amd/amdgpu : Use the MES INV_TLBS API for tlb invalidation on gfx12

Quoted 47 lines · Shaoyun Liu

From MES version 0x81, it provide the new API INV_TLBS that support invalidate tlbs with PASID.

---> drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 9 +++++++++

 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c  | 15 +++++++++++++++
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c  | 24
++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +10 -0
index c0d2c195fe2e..f4c40f1aecd2 100644
@@ -280,6 +280,12 @@ struct mes_reset_queue_input {
        bool                               is_kq;
 };
 
+struct mes_inv_tlbs_pasid_input {
+       uint16_t        pasid;
+       uint8_t         hub_id;
+       uint8_t         flush_type;
+};
+
 enum mes_misc_opcode {
        MES_MISC_OP_WRITE_REG,
        MES_MISC_OP_READ_REG,
@@ -367,6 +373,9 @@ struct amdgpu_mes_funcs {
 
        int (*reset_hw_queue)(struct amdgpu_mes *mes,
                              struct mes_reset_queue_input *input);
+
+       int (*invalidate_tlbs_pasid)(struct amdgpu_mes *mes,
+                             struct mes_inv_tlbs_pasid_input
+ *input);
 };
 
 #define amdgpu_mes_kiq_hw_init(adev)

(adev)->mes.kiq_hw_init((adev)) diff --git
a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c
index feb92e107af8..323ec04094ed 100644

drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev, · line 342

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
@@ -339,6 +339,21 @@ static void gmc_v12_0_flush_gpu_tlb_pasid(struct amdgpu_device *adev,
        uint16_t queried;
        int vmid, i;
 
+       if (adev->enable_uni_mes && adev->mes.ring[0].sched.ready &&

maybe specify the pipe index explicitly? E.g.,, adev->mes.ring[AMDGPU_MES_SCHED_PIPE].sched.ready I always forget which index is KIQ and which is SCHED.

[shaoyunl] ok .

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +15 -0
+           (adev->mes.sched_version & AMDGPU_MES_VERSION_MASK) >=
+ 0x81) {
+
+               struct mes_inv_tlbs_pasid_input input = {0};
+               input.pasid = pasid;
+               input.flush_type = flush_type;
+               adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               if (all_hub) {
+                       /* hub_id = 1 means  for mm_hub*/
+                       input.hub_id = 1;
+                       adev->mes.funcs->invalidate_tlbs_pasid(&adev->mes, &input);
+               }
+               return;
+       }
+
        for (vmid = 1; vmid < 16; vmid++) {
                bool valid;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +1 -0
index 6b222630f3fa..2e9191fffaf1 100644
@@ -108,6 +108,7 @@ static const char *mes_v12_0_opcodes[] = {
        "SET_SE_MODE",
        "SET_GANG_SUBMIT",
        "SET_HW_RSRC_1",
+       "INVALIDATE_TLBS",
 };
 
 static const char *mes_v12_0_misc_opcodes[] = { @@ -879,6 +880,28

@@ static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

                        offsetof(union MESAPI__RESET, api_status));
}
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +9 -0
+static int mes_v12_0_inv_tlbs_pasid(struct amdgpu_mes *mes,
+                                   struct mes_inv_tlbs_pasid_input
+*input) {
+       union MESAPI__INV_TLBS mes_inv_tlbs;
+
+       memset(&mes_inv_tlbs, 0, sizeof(mes_inv_tlbs));
+
+       mes_inv_tlbs.header.type = MES_API_TYPE_SCHEDULER;
+       mes_inv_tlbs.header.opcode = MES_SCH_API_INV_TLBS;

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c static int mes_v12_0_reset_hw_queue(struct amdgpu_mes *mes,

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +10 -0
+       mes_inv_tlbs.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
+
+       mes_inv_tlbs.invalidate_tlbs.inv_sel = 0;
+       mes_inv_tlbs.invalidate_tlbs.flush_type = input->flush_type;
+       mes_inv_tlbs.invalidate_tlbs.inv_sel_id = input->pasid;
+       mes_inv_tlbs.invalidate_tlbs.hub_id =
+ (uint32_t)input->hub_id;
+
+       return mes_v12_0_submit_pkt_and_poll_completion(mes,
+ AMDGPU_MES_KIQ_PIPE,

Should this be AMDGPU_MES_KIQ_PIPE or AMDGPU_MES_SCHED_PIPE? This seems to differ from the check above in gmc_v12_0_flush_gpu_tlb_pasid().

Quoted 4 lines

Alex

[Shaoyun.liu] What I want is submit to the kiq pipe when unified MES is ready , the above check is for MES is ready or not. We would like all none running-list related operation been submitted to KIQ so it won't create any unnecessary delay or impact on process schedule decision . It's like original driver usage for KIQ . The sched pipe (HIQ) will be used for all user queues.

In that case, should we check if both pipes are ready in gmc_v12_0_flush_gpu_tlb_pasid()?

Alex

[shaoyunl] Seems when mes is enabled , it assume the mes kiq pipe will always be ready and I haven't see the code to set and check the ready for mes.ring[KIQ] .

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +8 -0
+                       &mes_inv_tlbs, sizeof(mes_inv_tlbs),
+                       offsetof(union MESAPI__INV_TLBS,
+ api_status));
+
+}
+
 static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .add_hw_queue = mes_v12_0_add_hw_queue,
        .remove_hw_queue = mes_v12_0_remove_hw_queue, @@ -888,6
+911,7 @@ static const struct amdgpu_mes_funcs mes_v12_0_funcs = {
        .resume_gang = mes_v12_0_resume_gang,
        .misc_op = mes_v12_0_misc_op,
        .reset_hw_queue = mes_v12_0_reset_hw_queue,
+       .invalidate_tlbs_pasid = mes_v12_0_inv_tlbs_pasid,
 };
 
 static int mes_v12_0_allocate_ucode_buffer(struct amdgpu_device

*adev,
--
2.34.1