Skip to contentSkip to conversation

ARM: Qualify enabling of swiotlb_init()

PATCH In review Florian Fainelli 4 participants 9 messages Mar 19, 2021 – Apr 1, 2021 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: Qualify enabling of swiotlb_init()

We do not need a SWIOTLB unless we have DRAM that is addressable beyond the arm_dma_limit. Compare max_pfn with arm_dma_pfn_limit to determine whether we do need a SWIOTLB to be initialized.

Fixes ad3c7b18c5b3 ("arm: use swiotlb for bounce buffering on LPAE configs")
---
 arch/arm/mm/init.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mm/init.c +5 -1
index 828a2561b229..8356bf1daa28 100644
@@ -301,7 +301,11 @@ static void __init free_highpages(void)
 void __init mem_init(void)
 {
 #ifdef CONFIG_ARM_LPAE
-	swiotlb_init(1);
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;
 #endif
 
 	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
Signature · 6 lines
2.25.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#1 lore raw

arch/arm/mm/init.c static void __init free_highpages(void) · line 305

Quoted 3 lines · Florian Fainelli

#ifdef CONFIG_ARM_LPAE

arch/arm/mm/init.c +2 -0
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)

Does arm_dma_pfn_limit do the right thing even with the weirdest remapping ranges? Maybe a commen here would be useful.

arch/arm/mm/init.c static void __init free_highpages(void) · line 308

Quoted 3 lines
arch/arm/mm/init.c +3 -0
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;

Konrad: what do you think of setting swiotlb_force to SWIOTLB_NO_FORCE and only switching it to SWIOTLB_NORMAL when swiotlb_init* is called? That kind makes more sense than forcing the callers to do it.

While we're at it, I think swiotlb_force should probably be renamed to swiotlb_mode or somethng like that.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#2 lore raw
Quoted 7 lines · Christoph Hellwig

arch/arm/mm/init.c static void __init free_highpages(void) · line 305

Quoted 3 lines · Florian Fainelli

#ifdef CONFIG_ARM_LPAE

arch/arm/mm/init.c +2 -0
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)

Does arm_dma_pfn_limit do the right thing even with the weirdest remapping ranges? Maybe a commen here would be useful.

It gets assigned to either 0xffffffff or PHYS_OFFSET + arm_dma_zone_size
- 1 which is obtained from the machine descriptor, so I expect it to do the right thing, it works for a Pi 4 in 32-bit mode for instance. This is conditional upon enabling CONFIG_ZONE_DMA for ARM, and will otherwise keep its original value of 0, so this should be safe AFAICT.

Quoted 11 lines

arch/arm/mm/init.c static void __init free_highpages(void) · line 308

Quoted 4 lines
arch/arm/mm/init.c +3 -0
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;

Konrad: what do you think of setting swiotlb_force to SWIOTLB_NO_FORCE and only switching it to SWIOTLB_NORMAL when swiotlb_init* is called? That kind makes more sense than forcing the callers to do it.

While we're at it, I think swiotlb_force should probably be renamed to swiotlb_mode or somethng like that.

Agreed.

Signature · 5 lines
Florian
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#3 lore raw
In reply to Christoph Hellwig
Quoted 16 lines · Christoph Hellwig

arch/arm/mm/init.c static void __init free_highpages(void) · line 305

Quoted 3 lines · Florian Fainelli

#ifdef CONFIG_ARM_LPAE

arch/arm/mm/init.c +2 -0
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)

Does arm_dma_pfn_limit do the right thing even with the weirdest remapping ranges? Maybe a commen here would be useful.

arch/arm/mm/init.c static void __init free_highpages(void) · line 308

Quoted 3 lines
arch/arm/mm/init.c +3 -0
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;

Konrad: what do you think of setting swiotlb_force to SWIOTLB_NO_FORCE and only switching it to SWIOTLB_NORMAL when swiotlb_init* is called? That kind makes more sense than forcing the callers to do it.

Quoted 2 lines

While we're at it, I think swiotlb_force should probably be renamed to swiotlb_mode or somethng like that.

swiotlb_mode sounds good.

Also it got me thinking - ARM on Xen at some point was a bit strange, so not sure how the logic works here, Stefano?
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#4 lore raw
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 16 lines · Christoph Hellwig

arch/arm/mm/init.c static void __init free_highpages(void) · line 305

Quoted 3 lines · Florian Fainelli

#ifdef CONFIG_ARM_LPAE

arch/arm/mm/init.c +2 -0
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)

Does arm_dma_pfn_limit do the right thing even with the weirdest remapping ranges? Maybe a commen here would be useful.

arch/arm/mm/init.c static void __init free_highpages(void) · line 308

Quoted 3 lines
arch/arm/mm/init.c +3 -0
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;

Konrad: what do you think of setting swiotlb_force to SWIOTLB_NO_FORCE and only switching it to SWIOTLB_NORMAL when swiotlb_init* is called? That kind makes more sense than forcing the callers to do it.

Quoted 7 lines
Quoted 2 lines

While we're at it, I think swiotlb_force should probably be renamed to swiotlb_mode or somethng like that.

swiotlb_mode sounds good.

Also it got me thinking - ARM on Xen at some point was a bit strange, so not sure how the logic works here, Stefano?

There is nothing strange in regards to swiotlb_force. swiotlb_force is only used in swiotlb-xen map_page to figure out whether:

- we actually have to use the swiotlb bounce buffer (this is the swiotlb_xen == SWIOTLB_FORCE case)
- or we can use the provided page directly for dma if other conditions are met (dma_capable, !range_straddles_page_boundary, ...)

I don't think that switching to "swiotlb_mode" would cause any issues.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#5 lore raw
Quoted 29 lines · Stefano Stabellini
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 16 lines · Christoph Hellwig

arch/arm/mm/init.c static void __init free_highpages(void) · line 305

Quoted 3 lines · Florian Fainelli

#ifdef CONFIG_ARM_LPAE

arch/arm/mm/init.c +2 -0
+	if (swiotlb_force == SWIOTLB_FORCE ||
+	    max_pfn > arm_dma_pfn_limit)

Does arm_dma_pfn_limit do the right thing even with the weirdest remapping ranges? Maybe a commen here would be useful.

arch/arm/mm/init.c static void __init free_highpages(void) · line 308

Quoted 3 lines
arch/arm/mm/init.c +3 -0
+		swiotlb_init(1);
+	else
+		swiotlb_force = SWIOTLB_NO_FORCE;

Konrad: what do you think of setting swiotlb_force to SWIOTLB_NO_FORCE and only switching it to SWIOTLB_NORMAL when swiotlb_init* is called? That kind makes more sense than forcing the callers to do it.

Quoted 7 lines
Quoted 2 lines

While we're at it, I think swiotlb_force should probably be renamed to swiotlb_mode or somethng like that.

swiotlb_mode sounds good.

Also it got me thinking - ARM on Xen at some point was a bit strange, so not sure how the logic works here, Stefano?

There is nothing strange in regards to swiotlb_force. swiotlb_force is only used in swiotlb-xen map_page to figure out whether:

Quoted 8 lines

- we actually have to use the swiotlb bounce buffer (this is the swiotlb_xen == SWIOTLB_FORCE case)
- or we can use the provided page directly for dma if other conditions are met (dma_capable, !range_straddles_page_boundary, ...)

I don't think that switching to "swiotlb_mode" would cause any issues.

Should I toss this in Russell's patch tracker or do you need me to make some changes to the patch?

Signature · 5 lines
Florian
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#7 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Florian Fainelli

Should I toss this in Russell's patch tracker or do you need me to make some changes to the patch?

Due to all the other changes in this area I don't think anything but the swiotlb tree makes much sense here.

I've put them all on

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb.git
devel/for-linus-5.13

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#8 lore raw
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Florian Fainelli

Should I toss this in Russell's patch tracker or do you need me to make some changes to the patch?

Quoted 7 lines
Quoted 2 lines

Due to all the other changes in this area I don't think anything but the swiotlb tree makes much sense here.

I've put them all on

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb.git
devel/for-linus-5.13

Thanks! Did you also want to queue up this one:

https://lore.kernel.org/lkml/[email protected]/

Signature · 5 lines
Florian
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu