Don't split flush for amd_iommu_domain_flush_all()
Subsystems (2)
cover Don't split flush for amd_iommu_domain_flush_all()
This patch is a respin of Josef Bacik's original work[1] to fix the performance issues and soft lockups in the AMD IOMMU driver when running within a VM. I am taking over the respin as Josef currently has limited time for this
Weinan Liu (1):
iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
PATCH 1/1 iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
-> detach_device()
-> amd_iommu_domain_flush_all()
-> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS)
while (size != 0) {
-> __domain_flush_pages( flush_size /* power of 2 flush_size */)
-> domain_flush_pages_v1()
-> build_inv_iommu_pages()
-> build_inv_address()
}build_inv_address() will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call to amd_iommu_domain_flush_all()
Without this patch, we will see 10 time instead of 1 time full invalidations for every amd_iommu_domain_flush_all().
--- drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +2 -1
@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size ==CMD_INV_IOMMU_ALL_PAGES_ADDRESS ) {__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
drivers/iommu/amd/iommu.c void amd_iommu_domain_flush_pages(struct protection_domain *domain, · line 1773
Quoted 11 lines · Weinan Liu
drivers/iommu/amd/iommu.c +2
-1@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size ==CMD_INV_IOMMU_ALL_PAGES_ADDRESS ) {
This is better as size >= (1ULL<<52)
Which is the break point where it switches over to full invalidation anyhow, there is no sense then in doing the special np flow..
Otherwise
Jason
PATCH 1/1 iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
-> detach_device()
-> amd_iommu_domain_flush_all()
-> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS)
while (size != 0) {
-> __domain_flush_pages( flush_size /* power of 2 flush_size */)
-> domain_flush_pages_v1()
-> build_inv_iommu_pages()
-> build_inv_address()
}build_inv_address() will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call to amd_iommu_domain_flush_all()
Without this patch, we will see 10 time instead of 1 time full invalidations for every amd_iommu_domain_flush_all().
--- drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +2 -1
@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size >= (1ULL <<52 )) {__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
Quoted 24 lines · Weinan Liu
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
->detach_device()-> amd_iommu_domain_flush_all() -> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS) while (size != 0) { -> __domain_flush_pages( flush_size /* power of 2 flush_size */) -> domain_flush_pages_v1() -> build_inv_iommu_pages() -> build_inv_address() }
build_inv_address()will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call toamd_iommu_domain_flush_all()Without this patch, we will see 10 time instead of 1 time full invalidations for every
amd_iommu_domain_flush_all().
Quoted 8 lines
Fixes a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")Suggested-by Josef Bacik <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Weinan Liu <[email protected]>--- drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Jason
Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
In reply to Weinan LiuQuoted 38 lines · Weinan Liu
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
->detach_device()-> amd_iommu_domain_flush_all() -> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS) while (size != 0) { -> __domain_flush_pages( flush_size /* power of 2 flush_size */) -> domain_flush_pages_v1() -> build_inv_iommu_pages() -> build_inv_address() }
build_inv_address()will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call toamd_iommu_domain_flush_all()Without this patch, we will see 10 time instead of 1 time full invalidations for every
amd_iommu_domain_flush_all().Fixes a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")Suggested-by Josef Bacik <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Weinan Liu <[email protected]>--- drivers/iommu/amd/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/amd/iommu.c +0
-0
drivers/iommu/amd/iommu.c void amd_iommu_domain_flush_pages(struct protection_domain *domain, · line 1776
Quoted 9 lines
drivers/iommu/amd/iommu.c +2
-1@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size >= (1ULL <<52 )) {__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */
Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
In reply to Weinan LiuQuoted 51 lines · Weinan Liu
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
->detach_device()
->amd_iommu_domain_flush_all()-> amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS) while (size != 0) { -> __domain_flush_pages( flush_size /* power of 2 flush_size */) -> domain_flush_pages_v1() -> build_inv_iommu_pages() -> build_inv_address() }
build_inv_address()will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call toamd_iommu_domain_flush_all()Without this patch, we will see 10 time instead of 1 time full invalidations for every
amd_iommu_domain_flush_all().Fixes a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")Suggested-by Josef Bacik <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Weinan Liu <[email protected]>---
drivers/iommu/amd/iommu.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/amd/iommu.c +2
-1@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(struct protection_domain *domain, {lockdep_assert_held (&domain->lock); -if (likely (!amd_iommu_np_cache)) { +if (likely (!amd_iommu_np_cache) || + size ==CMD_INV_IOMMU_ALL_PAGES_ADDRESS ) {__domain_flush_pages (domain, address, size);/* Wait until IOMMU TLB and all device IOTLB flushes are complete */ Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
Re: [PATCH v1 1/1] iommu/amd: Don't split flush for amd_iommu_domain_flush_all()
Quoted 48 lines · Samiullah Khawaja
Quoted 47 lines · Weinan Liu
We have observed multiple full invalidations occurring during device detach when we are done using the vfio-device.
blocked_domain_attach_device()
->detach_device()
->amd_iommu_domain_flush_all()
->amd_iommu_domain_flush_pages(..., CMD_INV_IOMMU_ALL_PAGES_ADDRESS)while (size != 0) {
->
__domain_flush_pages( flush_size /* power of 2 flush_size */)->domain_flush_pages_v1()
->build_inv_iommu_pages()
->build_inv_address()}
build_inv_address()will trigger a full invalidation if the chunk size > (1 << 51). Consequently, the guest will issue multiple full invalidations for a single call toamd_iommu_domain_flush_all()Without this patch, we will see 10 time instead of 1 time full invalidations for every
amd_iommu_domain_flush_all().Fixes a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM")Suggested-by Josef Bacik <[email protected]>Suggested-by Jason Gunthorpe <[email protected]>Signed-off-by Weinan Liu <[email protected]>---
drivers/iommu/amd/iommu.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/amd/iommu.c +2
-1@@ -1769,7 +1769,8 @@ void amd_iommu_domain_flush_pages(structprotection_domain *domain, { lockdep_assert_held(&domain->lock); - if (likely(!amd_iommu_np_cache)) { + if (likely(!amd_iommu_np_cache) || + size == CMD_INV_IOMMU_ALL_PAGES_ADDRESS) { __domain_flush_pages(domain, address, size);
Quoted 7 lines
Quoted 5 lines
/* Wait until IOMMU TLB and all device IOTLB flushes are complete */
Signature · 1 line
2.54.0.rc0.605.g598a273b03-googReviewed-by Samiullah Khawaja <[email protected]>
Thanks,
Jörg Rödel
maintainerHi,
There is an updated patch in this thread, can you please re-send with the correct diff as a new thread and all Acks/Reviewed-by tags added?
Thanks,
Joerg
Thanks for the feedback. I will update the patch, gather the necessary tags, and re-send it as a new thread shortly.
Weinan
Quoted 9 lines · Jörg Rödel
Hi,
There is an updated patch in this thread, can you please re-send with the correct diff as a new thread and all Acks/Reviewed-by tags added?
Thanks,
Joerg