riscv: Implement flush_cache_vmap()
PATCH 1/1 riscv: Implement flush_cache_vmap()
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma in flush_cache_vmap().
Note that we don't need to implement flush_cache_vunmap() as the generic code should emit a flush tlb after unmapping a vmalloc region.
--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/include/asm/cacheflush.h +4 -0
@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0) +#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end) +#endif +#ifndef CONFIG_SMP #define flush_icache_all () local_flush_icache_all()
Signature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 21 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 5 lines
arch/riscv/include/asm/cacheflush.h +2
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0) +#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)
Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of vmap_pages_range, ioremap_page_range ... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.
Quoted 8 lines
arch/riscv/include/asm/cacheflush.h +2
-1+#endif +#ifndef CONFIG_SMP #define flush_icache_all () local_flush_icache_all() --2.39.2
Signature · 7 lines
Best Regards Guo Ren _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)
Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.
Hi All,
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
There are currently two possible approaches to flush TLB:
1. Flush TLB in flush_cache_vmap()
2. Flush TLB in arch_sync_kernel_mappings()
But I'm not quite sure if it's a good idea to operate on the TLB inside flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush in arch_sync_kernel_mappings()?
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Best regards,
Dylan
Quoted 18 lines
Quoted 8 lines
arch/riscv/include/asm/cacheflush.h +2
-1+#endif +#ifndef CONFIG_SMP #define flush_icache_all () local_flush_icache_all() --2.39.2
Signature · 7 lines
Best Regards Guo Ren _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 36 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.
Quoted 5 lines
Hi All,
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
Quoted 13 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed vmalloc_fault() is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of 7d3332be011e and the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).
I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?
TLDR: The downsides to implementing arch_sync_kernel_mappings() instead of flush_cache_vmap():
- 2 global flushes for vunmap instead of 1 for flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop of vmap_range_noflush() without flush and then a final flush afterwards)
So I'd favour the flush_cache_vmap() implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)
Here is the long story (my raw notes):
* arch_sync_kernel_mappings() is called from:
- _apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
- __vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must call flush_tlb_kernel_range(). Then the implementation of arch_sync_kernel_mappings() would result in 2 global tlb flushes.
- vmap_range_noflush(): does not fit well with the noflush() suffix.
* flush_cache_vmap() is called from:
- kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right a apply_to_page_range() so your patch would work here)
- kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes and flush_tlb_kernel_range() must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing only arch_sync_kernel_mappings() would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where __vmap_pages_range_noflush() would result in more flush_tlb_all())
- kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for the arch_sync_kernel_mappings() implementation.
- ioremap_page_range(): legit, same as arch_sync_kernel_mappings() implementation.
- vmap_pages_range(): legit, same as arch_sync_kernel_mappings() implementation.
Let me know what you think!
Alex
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 51 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
Quoted 4 lines
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).
Actually the problem was there before this commit (Dylan has the issue in 6.1), so no faulty commit to revert :)
Quoted 68 lines
I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Let me know what you think!
Alex
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Quoted 52 lines · Alexandre Ghiti
Quoted 51 lines · Alexandre Ghiti
Quoted 48 lines · Conor Dooley
Quoted 36 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Quoted 5 lines
Hi All,
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
Quoted 7 lines
Quoted 4 lines
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).Actually the problem was there before this commit (Dylan has the issue in 6.1), so no faulty commit to revert :)
Ah, my bad - I was focusing on 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") from your commit message. Big hammer, followed by tweaks or a replacement sounds like the way forward to me so!
Cheers,
Conor.
Quoted 67 lines
Quoted 67 lines
I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Let me know what you think!
Alex
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.
Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in flush_cache_vmap().
In most case, vmap_range_noflush() and flush_cache_vmap() will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. But flush_cache_vmap() does not cover all the places where apply_to_page_range() appears (please correct me if I'm wrong), such as vmap_pfn()[1].
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB Flush
As for the performance, because the current parameter of flush_tlb_page() needs to pass *vma, we cannot pass in this parameter so we can only choose flush_tlb_all(). If it can be changed to flush_tlb_page() in the future, the performance should be improved.
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan Jhong
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Hey Dylan,
Sorry I was busy debugging 6.5 failing to boot on the Unmatched (also TLB related, crazy everything converges to TLB issues lately :))
Quoted 123 lines · Dylan Jhong
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Quoted 8 lines
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in
flush_cache_vmap().In most case,
vmap_range_noflush()andflush_cache_vmap()will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. Butflush_cache_vmap()does not cover all the places whereapply_to_page_range()appears (please correct me if I'm wrong), such as vmap_pfn()[1].
That's a good catch, but shouldn't there be a flush_cache_vmap() in vmap_pfn()? What happens to architectures that implement flush_cache_vmap() and not arch_sync_kernel_mappings() (most of them)?
Quoted 7 lines
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB FlushAs for the performance, because the current parameter of
flush_tlb_page()needs to pass *vma, we cannot pass in this parameter so we can only chooseflush_tlb_all(). If it can be changed toflush_tlb_page()in the future, the performance should be improved.
We should call only flush_tlb_kernel_range() on kernel addresses, so that won't be a problem.
Quoted 9 lines
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan JhongQuoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 147 lines · Alexandre Ghiti
Hey Dylan,
Sorry I was busy debugging 6.5 failing to boot on the Unmatched (also TLB related, crazy everything converges to TLB issues lately :))
Quoted 123 lines · Dylan Jhong
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Quoted 8 lines
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in
flush_cache_vmap().In most case,
vmap_range_noflush()andflush_cache_vmap()will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. Butflush_cache_vmap()does not cover all the places whereapply_to_page_range()appears (please correct me if I'm wrong), such as vmap_pfn()[1].That's a good catch, but shouldn't there be a
flush_cache_vmap()invmap_pfn()? What happens to architectures that implementflush_cache_vmap()and notarch_sync_kernel_mappings()(most of them)?Quoted 4 lines
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB Flush
Quoted 6 lines
Quoted 3 lines
As for the performance, because the current parameter of
flush_tlb_page()needs to pass *vma, we cannot pass in this parameter so we can only chooseflush_tlb_all(). If it can be changed toflush_tlb_page()in the future, the performance should be improved.We should call only
flush_tlb_kernel_range()on kernel addresses, so that won't be a problem.
Another idea for reference:
1. keep vmalloc_fault()
2. flush_tlb_page() for vmap_stack when creating kernel thread.
Quoted 10 lines
Quoted 10 lines
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan JhongQuoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Signature · 2 lines
Best Regards Guo Ren
Palmer Dabbelt
maintainerQuoted 152 lines · On Tue, 08 Aug 2023 16:55:12 PDT (-0700), [email protected] wrote:
Quoted 151 lines · Alexandre Ghiti
Hey Dylan,
Sorry I was busy debugging 6.5 failing to boot on the Unmatched (also TLB related, crazy everything converges to TLB issues lately :))
Quoted 123 lines · Dylan Jhong
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Quoted 8 lines
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in
flush_cache_vmap().In most case,
vmap_range_noflush()andflush_cache_vmap()will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. Butflush_cache_vmap()does not cover all the places whereapply_to_page_range()appears (please correct me if I'm wrong), such as vmap_pfn()[1].That's a good catch, but shouldn't there be a
flush_cache_vmap()invmap_pfn()? What happens to architectures that implementflush_cache_vmap()and notarch_sync_kernel_mappings()(most of them)?Quoted 7 lines
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB FlushAs for the performance, because the current parameter of
flush_tlb_page()needs to pass *vma, we cannot pass in this parameter so we can only chooseflush_tlb_all(). If it can be changed toflush_tlb_page()in the future, the performance should be improved.
Quoted 6 lines
Quoted 2 lines
We should call only
flush_tlb_kernel_range()on kernel addresses, so that won't be a problem.Another idea for reference:
1. keepvmalloc_fault()
2.flush_tlb_page()forvmap_stackwhen creating kernel thread.
Sorry, I replied to the wrong thread over here <https://lore.kernel.org/all/mhng-3d3afb21-bd40-4095-ba62-41cf40b782ca@palmer-ri-x1c9/#t>. I agree we'll likely have performance issues, but at least this fixes the bugs we're seeing. If there's performance issues on real workloads on real HW then I'm happy to look at something more complicated, but that's probably too much for this release.
So I've queue this up, it'll end up on fixes when it passes the tests.
Thanks!
Quoted 16 lines
Quoted 10 lines
Quoted 10 lines
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan JhongQuoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Signature · 2 lines
Best Regards Guo Ren
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 166 lines · Palmer Dabbelt
Quoted 152 lines · On Tue, 08 Aug 2023 16:55:12 PDT (-0700), [email protected] wrote:
Quoted 151 lines · Alexandre Ghiti
Hey Dylan,
Sorry I was busy debugging 6.5 failing to boot on the Unmatched (also TLB related, crazy everything converges to TLB issues lately :))
Quoted 123 lines · Dylan Jhong
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Quoted 8 lines
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in
flush_cache_vmap().In most case,
vmap_range_noflush()andflush_cache_vmap()will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. Butflush_cache_vmap()does not cover all the places whereapply_to_page_range()appears (please correct me if I'm wrong), such as vmap_pfn()[1].That's a good catch, but shouldn't there be a
flush_cache_vmap()invmap_pfn()? What happens to architectures that implementflush_cache_vmap()and notarch_sync_kernel_mappings()(most of them)?Quoted 7 lines
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB FlushAs for the performance, because the current parameter of
flush_tlb_page()needs to pass *vma, we cannot pass in this parameter so we can only chooseflush_tlb_all(). If it can be changed toflush_tlb_page()in the future, the performance should be improved.Quoted 6 lines
Quoted 2 lines
We should call only
flush_tlb_kernel_range()on kernel addresses, so that won't be a problem.Another idea for reference:
1. keepvmalloc_fault()
2.flush_tlb_page()forvmap_stackwhen creating kernel thread.Sorry, I replied to the wrong thread over here <https://lore.kernel.org/all/mhng-3d3afb21-bd40-4095-ba62-41cf40b782ca@palmer-ri-x1c9/#t>.
I agree we'll likely have performance issues, but at least this fixes the
bugs we're seeing. If there's performance issues on real workloads on real
HW then I'm happy to look at something more complicated, but that's probably
too much for this release.
Quoted 3 lines
So I've queue this up, it'll end up on fixes when it passes the tests.
Thanks!
Hi Palmer,
Reply to your post on another thread.
Yes, we need the implementation of flush_cache_vmap() under the RISC-V architecture to solve our problem. Alexandre proposed another solution to deal with the TLB updating issue in another thread [1], I think that patch should be able to better ensure performance and correctness. But before that, we need this patch as a workaround.
BTW, since there is no flush_cache_vmap() in vmap_pfn(), there may be a risk that the TLB is not updated. I think this patch[2] should be pulled back to the RISC-V port.
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/038079.html
[2]: https://lore.kernel.org/all/mhng-3d3afb21-bd40-4095-ba62-41cf40b782ca@palmer-ri-x1c9/#t
Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan JhongQuoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Signature · 2 lines
Best Regards Guo Ren
Palmer Dabbelt
maintainerQuoted 173 lines · On Thu, 10 Aug 2023 09:22:30 PDT (-0700), [email protected] wrote:
Quoted 166 lines · Palmer Dabbelt
Quoted 152 lines · On Tue, 08 Aug 2023 16:55:12 PDT (-0700), [email protected] wrote:
Quoted 151 lines · Alexandre Ghiti
Hey Dylan,
Sorry I was busy debugging 6.5 failing to boot on the Unmatched (also TLB related, crazy everything converges to TLB issues lately :))
Quoted 123 lines · Dylan Jhong
Quoted 115 lines · Alexandre Ghiti
Quoted 40 lines · Conor Dooley
Quoted 38 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
Quoted 8 lines
Quoted 3 lines
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
We are at -rc4 and this stuff is broken. Taking the bigger hammer, which can be reverted later when a more targeted fix shows up, to make sure that v6.5 doesn't end up broken, sounds rather prudent. Otherwise, the original commit should probably be reverted.
The original commit that removed
vmalloc_fault()is required, handling vmalloc faults in the page fault path is not possible (see the links
in the description of7d3332be011eand the example that I gave in the
thread https://lore.kernel.org/linux-riscv/[email protected]/).I totally agree with Dylan that we'll work (I'm currently working on that) on the performance side of the problem in the next release, we need correctness and for that we need a preventive global sfence.vma as we have no means (for now) to distinguish between uarch that cache or not invalid entries.
Quoted 5 lines
Quoted 5 lines
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
Quoted 7 lines
Quoted 7 lines
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?TLDR: The downsides to implementing
arch_sync_kernel_mappings()instead offlush_cache_vmap():- 2 global flushes for vunmap instead of 1 for
flush_cache_vmap()
- flushes the tlb in the noflush suffixed functions so it prevents any flush optimization (ie: a loop ofvmap_range_noflush()without flush and then a final flush afterwards)So I'd favour the
flush_cache_vmap()implementation which seems lighter. powerpc does that
https://elixir.bootlin.com/linux/latest/source/arch/powerpc/include/asm/cacheflush.h#L27
(but admits that it may not be the right place)Here is the long story (my raw notes):
*
arch_sync_kernel_mappings()is called from:
-_apply_to_page_range(): would only emit global sfence.vma if vmalloc addresses, I guess that's ok.
-__vunmap_range_noflush(): it is noted here
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L406 that any caller must callflush_tlb_kernel_range(). Then the implementation ofarch_sync_kernel_mappings()would result in 2 global tlb flushes.
-vmap_range_noflush(): does not fit well with thenoflush()suffix.*
flush_cache_vmap()is called from:
-kasan_populate_vmalloc(): legit since it bypasses vmap api (but called right aapply_to_page_range()so your patch would work here)
-kmsan_vunmap_range_noflush(): called twice for the mappings kmsan establishes andflush_tlb_kernel_range()must be called afterwards => 3 global tlb flushes but the 3 are needed as they target different addresses. Implementing onlyarch_sync_kernel_mappings()would result in way more global flushes (see the loop here
https://elixir.bootlin.com/linux/latest/source/mm/kmsan/hooks.c#L151
where__vmap_pages_range_noflush()would result in moreflush_tlb_all())
-kmsan_vmap_pages_range_noflush(): here we would flush twice, but same thing for thearch_sync_kernel_mappings()implementation.
-ioremap_page_range(): legit, same asarch_sync_kernel_mappings()implementation.
-vmap_pages_range(): legit, same asarch_sync_kernel_mappings()implementation.Quoted 4 lines
Let me know what you think!
Alex
Hi Alex,
Quoted 8 lines
Thank you for the detailed explanation. It is indeed undeniable that in certain situations, there might be a possibility of repeated flushing TLB. But I think there are some potential problem in
flush_cache_vmap().In most case,
vmap_range_noflush()andflush_cache_vmap()will appear at the same time, so it should be no problem to choose one of them to do the TLB flush. Butflush_cache_vmap()does not cover all the places whereapply_to_page_range()appears (please correct me if I'm wrong), such as vmap_pfn()[1].That's a good catch, but shouldn't there be a
flush_cache_vmap()invmap_pfn()? What happens to architectures that implementflush_cache_vmap()and notarch_sync_kernel_mappings()(most of them)?Quoted 7 lines
The function you mentioned here, each will eventually call:
vmap_range_noflush() -> arch_sync_kernel_mappings() -> TLB FlushAs for the performance, because the current parameter of
flush_tlb_page()needs to pass *vma, we cannot pass in this parameter so we can only chooseflush_tlb_all(). If it can be changed toflush_tlb_page()in the future, the performance should be improved.Quoted 6 lines
Quoted 2 lines
We should call only
flush_tlb_kernel_range()on kernel addresses, so that won't be a problem.Another idea for reference:
1. keepvmalloc_fault()
2.flush_tlb_page()forvmap_stackwhen creating kernel thread.Sorry, I replied to the wrong thread over here <https://lore.kernel.org/all/mhng-3d3afb21-bd40-4095-ba62-41cf40b782ca@palmer-ri-x1c9/#t>.
I agree we'll likely have performance issues, but at least this fixes the
bugs we're seeing. If there's performance issues on real workloads on real
HW then I'm happy to look at something more complicated, but that's probably
too much for this release.Quoted 3 lines
So I've queue this up, it'll end up on fixes when it passes the tests.
Thanks!
Hi Palmer,
Quoted 7 lines
Reply to your post on another thread.
Yes, we need the implementation of
flush_cache_vmap()under the RISC-V architecture to solve our problem. Alexandre proposed another solution to deal with the TLB updating issue in another thread [1], I think that patch should be able to better ensure performance and correctness. But before that, we need this patch as a workaround.
Awesome, thanks.
Quoted 3 lines
BTW, since there is no
flush_cache_vmap()invmap_pfn(), there may be a risk that the TLB is not updated. I think this patch[2] should be pulled back to the RISC-V port.
That one's for the MM tree, though -- it should still end up in stable, so we should be fine from the RISC-V side of things.
Quoted 21 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/038079.html
[2]: https://lore.kernel.org/all/mhng-3d3afb21-bd40-4095-ba62-41cf40b782ca@palmer-ri-x1c9/#tQuoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
[1]: https://elixir.bootlin.com/linux/v6.5-rc4/source/mm/vmalloc.c#L2977
Best regards,
Dylan JhongQuoted 3 lines
Quoted 3 lines
Quoted 2 lines
[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
--
Best Regards
Guo Ren
Quoted 51 lines · dylan
Quoted 25 lines · Guo Ren
Quoted 24 lines · Alexandre Ghiti
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.Fixes 7d3332be011e ("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area")Signed-off-by Alexandre Ghiti <[email protected]>--- arch/riscv/include/asm/cacheflush.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/cacheflush.h +0
-0@@ -37,6 +37,10 @@ static inline void flush_dcache_page(struct page *page)#define flush_icache_user_page (vma, pg, addr, len) \ flush_icache_mm(vma->vm_mm, 0)Quoted 9 lines
arch/riscv/include/asm/cacheflush.h static inline void flush_dcache_page(struct page *page) · line 41
Quoted 2 lines
arch/riscv/include/asm/cacheflush.h +2
-0+#ifdef CONFIG_64BIT +#define flush_cache_vmap (start, end) flush_tlb_kernel_range(start, end)Sorry, I couldn't agree with the above in a PIPT cache machine. It's not worth for.
It would reduce the performance of
vmap_pages_range,ioremap_page_range... API, which may cause some drivers' performance issues when they install/uninstall memory frequently.Hi All,
I think functional correctness should be more important than system performance in this case. The "preventive" SFENCE.VMA became necessary due to the RISC-V specification allowing invalidation entries to be cached in the TLB.
The problem[1] we are currently encountering is caused by not updating the TLB after the page table is created, and the solution to this problem can only be solved by updating the TLB immediately after the page table is created.
There are currently two possible approaches to flush TLB:
1. Flush TLB inflush_cache_vmap()
2. Flush TLB inarch_sync_kernel_mappings()
Quoted 5 lines
But I'm not quite sure if it's a good idea to operate on the TLB inside
flush_cache_vmap(). The name of this function indicates that it should be related to cache operations, maybe it would be more appropriate to do TLB flush inarch_sync_kernel_mappings()?[1]: http://lists.infradead.org/pipermail/linux-riscv/2023-August/037503.html
Not all machines need it, and some CPUs prevent PTE.V=0 into TLB during PTW, which is stronger than ISA's requirement.
So could we put an errata alternative here?
Quoted 22 lines
Best regards,
DylanQuoted 18 lines
Quoted 8 lines
arch/riscv/include/asm/cacheflush.h +2
-1+#endif +#ifndef CONFIG_SMP #define flush_icache_all () local_flush_icache_all() --2.39.2
--
Best Regards
Guo Ren_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Signature · 2 lines
Best Regards Guo Ren
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:
Quoted 10 lines · On Tue, 25 Jul 2023 15:22:46 +0200 you wrote:
The RISC-V kernel needs a sfence.vma after a page table modification: we used to rely on the vmalloc fault handling to emit an sfence.vma, but commit
7d3332be011e("riscv: mm: Pre-allocate PGD entries for vmalloc/modules area") got rid of this path for 64-bit kernels, so now we need to explicitly emit a sfence.vma inflush_cache_vmap().Note that we don't need to implement
flush_cache_vunmap()as the generic code should emit a flush tlb after unmapping a vmalloc region.[...]
Here is the summary with links:
- [-fixes] riscv: Implement flush_cache_vmap()
https://git.kernel.org/riscv/c/7e3811521dc3
You are awesome, thank you!
Signature · 9 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv