drm/amdkfd: Insert missing TLB flush on GFX10 and later
Subsystems (3)
PATCH 1/1 drm/amdkfd: Insert missing TLB flush on GFX10 and later
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -2
@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }
Signature · 1 line
2.34.1
Quoted 4 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan <[email protected]>
Quoted 18 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }
Quoted 13 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type); · line 1472
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }
1, If TLB_FLUSH_HEAVYWEIGHT is required after unmap on all GPUs as described in commmit message, why we have this whitelist instead of a blacklist?
2, kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT) is also called in svm_range_unmap_from_gpus(). Why not add this whitelist there?
Regards,
Lang
Quoted 3 lines
Signature · 1 line
2.34.1
Quoted 15 lines · Lang Yu
Quoted 14 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0
-0@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);
Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type); · line 1472
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }1, If
TLB_FLUSH_HEAVYWEIGHTis required after unmap on all GPUs as described in commmit message, why we have this whitelist instead of a blacklist?
That was a bug that this patch is fixing. There were specific GPUs and firmware versions where the TLB flush after unmap was causing intermittent problems in specific tests. This should have always been a blacklist.
Quoted 3 lines
2,
kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is also called insvm_range_unmap_from_gpus(). Why not add this whitelist there?
There was a patch that used kfd_flush_tlb_after_unmap in the SVM code. But you reverted that patch, probably because it caused more problems than it solved. SVM really must flush TLBs the way it does because it is so tightly integrated with Linux's virtual memory management and because with XNACK, memory can be unmapped while GPU work is in progress without preemting queues (implicitly flushing TLBs and caches):
commit 515d7cebc2e2d2b4f0a276d26f3b790a83cdfe06
Author: Lang Yu<[email protected]> Date: Wed Apr 20 10:24:31 2022 +0800
Revert "drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too"
This reverts commit 36bf93216ecbe399c40c5e0486f0f0e3a4afa69e.
It causes SVM regressions on Vega10 with XNACK-ON. Just revert it at the moment.
./kfdtest --gtest_filter=KFDSVMRangeTest.MigratePolicyTest
Regards,
Felix
Quoted 7 lines
Regards,
LangQuoted 3 lines
Signature · 1 line
2.34.1
Quoted 52 lines · Felix Kuehling
Quoted 9 lines · Lang Yu
Quoted 8 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type); · line 1471
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }1, If
TLB_FLUSH_HEAVYWEIGHTis required after unmap on all GPUs as described in commmit message, why we have this whitelist instead of a blacklist?That was a bug that this patch is fixing. There were specific GPUs and firmware versions where the TLB flush after unmap was causing intermittent problems in specific tests. This should have always been a blacklist.
Quoted 3 lines
2,
kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is also called insvm_range_unmap_from_gpus(). Why not add this whitelist there?There was a patch that used
kfd_flush_tlb_after_unmapin the SVM code. But you reverted that patch, probably because it caused more problems than it solved. SVM really must flush TLBs the way it does because it is so tightly integrated with Linux's virtual memory management and because with XNACK, memory can be unmapped while GPU work is in progress without preemting queues (implicitly flushing TLBs and caches):commit
515d7cebc2e2d2b4f0a276d26f3b790a83cdfe06Author: Lang Yu<[email protected]> Date: Wed Apr 20 10:24:31 2022 +0800Revert "drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too" This reverts commit
36bf93216ecbe399c40c5e0486f0f0e3a4afa69e.
It causes SVM regressions on Vega10 with XNACK-ON. Just revert it at the moment.
./kfdtest --gtest_filter=KFDSVMRangeTest.MigratePolicyTest
Quoted 6 lines
Signed-off-by Lang Yu<[email protected]>Reviewed-by Philip Yang<[email protected]>Signed-off-by Alex Deucher<[email protected]>Regards,
Felix
Yes, that's because kfd_flush_tlb_after_unmap() return false for Vega10(gfx901). kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT) is called unconditionally in SVM for ASICs > IP_VERSION(9, 0, 0) and works well.
So why not relax the condition to KFD_GC_VERSION(dev) > IP_VERSION(9, 0, 0) ?
Regards,
Lang
Quoted 8 lines
Quoted 8 lines
Regards,
LangQuoted 3 lines
Signature · 1 line
2.34.1
Felix Kuehling
maintainerQuoted 54 lines · Lang Yu
Quoted 53 lines · Felix Kuehling
Quoted 9 lines · Lang Yu
Quoted 8 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type); · line 1471
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }1, If
TLB_FLUSH_HEAVYWEIGHTis required after unmap on all GPUs as described in commmit message, why we have this whitelist instead of a blacklist?That was a bug that this patch is fixing. There were specific GPUs and firmware versions where the TLB flush after unmap was causing intermittent problems in specific tests. This should have always been a blacklist.
Quoted 2 lines
2,
kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is also called insvm_range_unmap_from_gpus(). Why not add this whitelist there?There was a patch that used
kfd_flush_tlb_after_unmapin the SVM code. But you reverted that patch, probably because it caused more problems than it solved. SVM really must flush TLBs the way it does because it is so tightly integrated with Linux's virtual memory management and because with XNACK, memory can be unmapped while GPU work is in progress without preemting queues (implicitly flushing TLBs and caches):commit
515d7cebc2e2d2b4f0a276d26f3b790a83cdfe06Author: Lang Yu<[email protected]> Date: Wed Apr 20 10:24:31 2022 +0800Revert "drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too" This reverts commit
36bf93216ecbe399c40c5e0486f0f0e3a4afa69e.
It causes SVM regressions on Vega10 with XNACK-ON. Just revert it at the moment.
./kfdtest --gtest_filter=KFDSVMRangeTest.MigratePolicyTestSigned-off-by Lang Yu<[email protected]>Reviewed-by Philip Yang<[email protected]>Signed-off-by Alex Deucher<[email protected]>
Quoted 7 lines
Quoted 2 lines
Regards,
FelixYes, that's because
kfd_flush_tlb_after_unmap()return false for Vega10(gfx901).kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is called unconditionally in SVM for ASICs >IP_VERSION(9, 0, 0)and works well.So why not relax the condition to
KFD_GC_VERSION(dev)>IP_VERSION(9, 0, 0)?
That would reintroduce the same problem that this workaround was meant to fix. I don't remember all the details of this, as it was years ago. I believe it was an intermittent hang or VM fault that was somewhat difficult to reproduce and investigate. Maybe Eric remembers the details as he was working on this bug back then. However, it was a real issue, and we got an SDMA firmware fix for it on GFX IP 9.4.1 as you can see from the FW version check in kfd_flush_tlb_after_unmap.
I would not recommend reverting this workaround at the risk of reintroducing a known intermittent bug that affects stability.
Regards,
Felix
Quoted 10 lines
Regards,
LangQuoted 6 lines
Quoted 6 lines
Regards,
LangQuoted 3 lines
Signature · 1 line
2.34.1
Quoted 71 lines · Felix Kuehling
Quoted 54 lines · Lang Yu
Quoted 53 lines · Felix Kuehling
Quoted 9 lines · Lang Yu
Quoted 8 lines · Harish Kasiviswanathan
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan<[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 16 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type); · line 1471
Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }1, If
TLB_FLUSH_HEAVYWEIGHTis required after unmap on all GPUs as described in commmit message, why we have this whitelist instead of a blacklist?That was a bug that this patch is fixing. There were specific GPUs and firmware versions where the TLB flush after unmap was causing intermittent problems in specific tests. This should have always been a blacklist.
Quoted 2 lines
2,
kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is also called insvm_range_unmap_from_gpus(). Why not add this whitelist there?There was a patch that used
kfd_flush_tlb_after_unmapin the SVM code. But you reverted that patch, probably because it caused more problems than it solved. SVM really must flush TLBs the way it does because it is so tightly integrated with Linux's virtual memory management and because with XNACK, memory can be unmapped while GPU work is in progress without preemting queues (implicitly flushing TLBs and caches):commit
515d7cebc2e2d2b4f0a276d26f3b790a83cdfe06Author: Lang Yu<[email protected]> Date: Wed Apr 20 10:24:31 2022 +0800Revert "drm/amdkfd: only allow heavy-weight TLB flush on some ASICs for SVM too" This reverts commit
36bf93216ecbe399c40c5e0486f0f0e3a4afa69e.
It causes SVM regressions on Vega10 with XNACK-ON. Just revert it at the moment.
./kfdtest --gtest_filter=KFDSVMRangeTest.MigratePolicyTestSigned-off-by Lang Yu<[email protected]>Reviewed-by Philip Yang<[email protected]>Signed-off-by Alex Deucher<[email protected]>Quoted 7 lines
Quoted 2 lines
Regards,
FelixYes, that's because
kfd_flush_tlb_after_unmap()return false for Vega10(gfx901).kfd_flush_tlb(pdd, TLB_FLUSH_HEAVYWEIGHT)is called unconditionally in SVM for ASICs >IP_VERSION(9, 0, 0)and works well.So why not relax the condition to
KFD_GC_VERSION(dev)>IP_VERSION(9, 0, 0)?That would reintroduce the same problem that this workaround was meant to fix. I don't remember all the details of this, as it was years ago. I believe it was an intermittent hang or VM fault that was somewhat difficult to reproduce and investigate. Maybe Eric remembers the details as he was working on this bug back then. However, it was a real issue, and we got an SDMA firmware fix for it on GFX IP 9.4.1 as you can see from the FW version check in
kfd_flush_tlb_after_unmap.
Quoted 2 lines
I would not recommend reverting this workaround at the risk of reintroducing a known intermittent bug that affects stability.
Got it. Thank you!
Regards,
Lang
Quoted 15 lines
Regards,
FelixQuoted 10 lines
Regards,
LangQuoted 6 lines
Quoted 6 lines
Regards,
LangQuoted 3 lines
Signature · 1 line
2.34.1
Am 11.09.23 um 21:00 schrieb Harish Kasiviswanathan:
Quoted 4 lines
Heavy-weight TLB flush is required after unmap on all GPUs for correctness and security.
Signed-off-by Harish Kasiviswanathan <[email protected]>
Quoted 18 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-2@@ -1466,8 +1466,7 @@ void kfd_flush_tlb(struct kfd_process_device *pdd, enum TLB_FLUSH_TYPE type);static inline bool kfd_flush_tlb_after_unmap (struct kfd_dev *dev) { -return KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,3 ) || -KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,2 ) || +return KFD_GC_VERSION (dev) >IP_VERSION (9 ,4 ,2 ) || (KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,1 ) && dev->sdma_fw_version >=18 ) ||KFD_GC_VERSION (dev) ==IP_VERSION (9 ,4 ,0 ); }