powerpc/swiotlb: Dont free up allocated SWIOTLB slab on POWER
RFC 1/2 powerpc/swiotlb: Dont free up allocated SWIOTLB slab on POWER
Even though SWIOTLB slab gets allocated and initialized on powerpc with swiotlb_init() called during mem_init(), it gets released away again on POWER platform because 'ppc_swiotlb_enable' never gets set. The function swiotlb_detect_4g() checks for 4GB memory and then sets the variable 'ppc_swiotlb_enable' which prevents freeing up the SWIOTLB slab. Lets make POWER platform call swiotlb_detect_4g() during setup_arch() which will keep the SWIOTLB slab through out the runtime.
A previous commit cf5621032f ("powerpc/64: Limit ZONE_DMA32 to 4GiB in swiotlb_detect_4g()") enforced 4GB limit on ZONE_DMA32 which is is not applicable on POWER (CONFIG_PPC_BOOK3S_64) platform. Lets remove this unnecessary restriction.
After the patch, SWIOTLB slab does not get released.
[0.410992] software IO TLB [mem 0xfbff0000-0xffff0000] (64MB) mapped
at [00000000767f6cb3-000000004a10114f]
--- arch/powerpc/kernel/dma-swiotlb.c | 2 +- arch/powerpc/kernel/setup-common.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/dma-swiotlb.c +1 -1
@@ -110,7 +110,7 @@ void __init swiotlb_detect_4g(void) {if ((memblock_end_of_DRAM () -1 ) >0xffffffff ) { ppc_swiotlb_enable =1 ; -#ifdef CONFIG_ZONE_DMA32 +#if defined(CONFIG_ZONE_DMA32 ) && !defined(CONFIG_PPC_BOOK3S_64 )limit_zone_pfn (ZONE_DMA32 , (1ULL <<32 ) >>PAGE_SHIFT );#endif }
arch/powerpc/kernel/setup-common.c +1 -0
@@ -944,6 +944,7 @@ void __init setup_arch(char **cmdline_p)/* Initialize the MMU context management stuff. */ mmu_context_init (); +swiotlb_detect_4g ();#ifdef CONFIG_PPC64 /* Interrupt code needs to be 64K-aligned. */ if ((unsigned long )_stext &0xffff )
Signature · 1 line
2.14.1
RFC 2/2 powerpc/swiotlb: Make swiotlb_dma_ops available on POWER
Generic swiotlb_dma_ops structure is available under CONFIG_DMA_DIRECT_OPS configuration. Hence select it on POWER platform.
--- arch/powerpc/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/Kconfig +1 -0
@@ -235,6 +235,7 @@ config PPC select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select VIRT_TO_BUS if !PPC64 + select DMA_DIRECT_OPS if PPC_BOOK3S_64 # # Please keep this list sorted alphabetically. #
Signature · 1 line
2.14.1
Michael Ellerman
reviewerQuoted 8 lines · Anshuman Khandual
Even though SWIOTLB slab gets allocated and initialized on powerpc with
swiotlb_init()called duringmem_init(), it gets released away again on POWER platform because 'ppc_swiotlb_enable' never gets set. The functionswiotlb_detect_4g()checks for 4GB memory and then sets the variable 'ppc_swiotlb_enable' which prevents freeing up the SWIOTLB slab. Lets make POWER platform callswiotlb_detect_4g()duringsetup_arch()which will keep the SWIOTLB slab through out the runtime.
Quoted 4 lines
A previous commit
cf5621032f("powerpc/64: LimitZONE_DMA32to 4GiB inswiotlb_detect_4g()") enforced 4GB limit onZONE_DMA32which is is not applicable on POWER (CONFIG_PPC_BOOK3S_64) platform. Lets remove this unnecessary restriction.
You're using "POWER" to mean Book3S 64-bit, but "POWER" is something else (the ISA for POWER1/POWER2).
So please just say "Book3S 64-bit" or talk about a specific CPU, eg. Power9.
Quoted 4 lines
After the patch, SWIOTLB slab does not get released.
[0.410992] software IO TLB [mem 0xfbff0000-0xffff0000] (64MB) mappedat [00000000767f6cb3-000000004a10114f]
But we don't want SWIOTLB on any existing Book3S 64-bit platforms, so leaving it enabled is just wasting memory.
arch/powerpc/kernel/setup-common.c void __init setup_arch(char **cmdline_p) · line 947
Quoted 9 lines
arch/powerpc/kernel/setup-common.c +1
-0@@ -944,6 +944,7 @@ void __init setup_arch(char **cmdline_p)/* Initialize the MMU context management stuff. */ mmu_context_init (); +swiotlb_detect_4g ();
You shouldn't be calling this, your use case has nothing to do with 4GB.
Instead when you detect that you're running under the ultravisor then you should set ppc_swiotlb_enable = 1.
cheers
Quoted 36 lines · Michael Ellerman
Quoted 8 lines · Anshuman Khandual
Even though SWIOTLB slab gets allocated and initialized on powerpc with
swiotlb_init()called duringmem_init(), it gets released away again on POWER platform because 'ppc_swiotlb_enable' never gets set. The functionswiotlb_detect_4g()checks for 4GB memory and then sets the variable 'ppc_swiotlb_enable' which prevents freeing up the SWIOTLB slab. Lets make POWER platform callswiotlb_detect_4g()duringsetup_arch()which will keep the SWIOTLB slab through out the runtime.Quoted 4 lines
A previous commit
cf5621032f("powerpc/64: LimitZONE_DMA32to 4GiB inswiotlb_detect_4g()") enforced 4GB limit onZONE_DMA32which is is not applicable on POWER (CONFIG_PPC_BOOK3S_64) platform. Lets remove this unnecessary restriction.You're using "POWER" to mean Book3S 64-bit, but "POWER" is something else (the ISA for POWER1/POWER2).
So please just say "Book3S 64-bit" or talk about a specific CPU, eg. Power9.
Quoted 4 lines
After the patch, SWIOTLB slab does not get released.
[0.410992] software IO TLB [mem 0xfbff0000-0xffff0000] (64MB) mappedat [00000000767f6cb3-000000004a10114f]
But we don't want SWIOTLB on any existing Book3S 64-bit platforms, so leaving it enabled is just wasting memory.
Quoted 8 lines
arch/powerpc/kernel/setup-common.c +0
-0@@ -944,6 +944,7 @@ void __init setup_arch(char **cmdline_p)/* Initialize the MMU context management stuff. */ mmu_context_init ();
Quoted 6 lines
arch/powerpc/kernel/setup-common.c void __init setup_arch(char **cmdline_p) · line 947
Quoted 1 line
arch/powerpc/kernel/setup-common.c +1
-0+swiotlb_detect_4g ();You shouldn't be calling this, your use case has nothing to do with 4GB.
Instead when you detect that you're running under the ultravisor then you should set
ppc_swiotlb_enable= 1.
Please assume that you will have a interface to detect if you are running in a protected-environment(AKA secure-environment).
So maybe you can rename swiotlb_detect_4g() to swiotlb_detect() and modify that function to enable or disable ppc_swiotlb_enable depending on the availability of 4g or availability of protected-environment?
RP