Skip to content

Commit b81c688

Browse files
Ryan Robertswilldeacon
authored andcommitted
arm64/mm: Disable barrier batching in interrupt contexts
Commit 5fdd05e ("arm64/mm: Batch barriers when updating kernel mappings") enabled arm64 kernels to track "lazy mmu mode" using TIF flags in order to defer barriers until exiting the mode. At the same time, it added warnings to check that pte manipulations were never performed in interrupt context, because the tracking implementation could not deal with nesting. But it turns out that some debug features (e.g. KFENCE, DEBUG_PAGEALLOC) do manipulate ptes in softirq context, which triggered the warnings. So let's take the simplest and safest route and disable the batching optimization in interrupt contexts. This makes these users no worse off than prior to the optimization. Additionally the known offenders are debug features that only manipulate a single PTE, so there is no performance gain anyway. There may be some obscure case of encrypted/decrypted DMA with the dma_free_coherent called from an interrupt context, but again, this is no worse off than prior to the commit. Some options for supporting nesting were considered, but there is a difficult to solve problem if any code manipulates ptes within interrupt context but *outside of* a lazy mmu region. If this case exists, the code would expect the updates to be immediate, but because the task context may have already been in lazy mmu mode, the updates would be deferred, which could cause incorrect behaviour. This problem is avoided by always ensuring updates within interrupt context are immediate. Fixes: 5fdd05e ("arm64/mm: Batch barriers when updating kernel mappings") Reported-by: [email protected] Closes: https://lore.kernel.org/linux-arm-kernel/[email protected]/ Signed-off-by: Ryan Roberts <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 5fdd05e commit b81c688

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ static inline void queue_pte_barriers(void)
6464
{
6565
unsigned long flags;
6666

67-
VM_WARN_ON(in_interrupt());
67+
if (in_interrupt()) {
68+
emit_pte_barriers();
69+
return;
70+
}
71+
6872
flags = read_thread_flags();
6973

7074
if (flags & BIT(TIF_LAZY_MMU)) {
@@ -79,20 +83,28 @@ static inline void queue_pte_barriers(void)
7983
#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
8084
static inline void arch_enter_lazy_mmu_mode(void)
8185
{
82-
VM_WARN_ON(in_interrupt());
86+
if (in_interrupt())
87+
return;
88+
8389
VM_WARN_ON(test_thread_flag(TIF_LAZY_MMU));
8490

8591
set_thread_flag(TIF_LAZY_MMU);
8692
}
8793

8894
static inline void arch_flush_lazy_mmu_mode(void)
8995
{
96+
if (in_interrupt())
97+
return;
98+
9099
if (test_and_clear_thread_flag(TIF_LAZY_MMU_PENDING))
91100
emit_pte_barriers();
92101
}
93102

94103
static inline void arch_leave_lazy_mmu_mode(void)
95104
{
105+
if (in_interrupt())
106+
return;
107+
96108
arch_flush_lazy_mmu_mode();
97109
clear_thread_flag(TIF_LAZY_MMU);
98110
}

0 commit comments

Comments
 (0)