]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
parisc: Fix patch code locking and flushing
authorJohn David Anglin <dave.anglin@bell.net>
Tue, 29 Mar 2022 18:54:36 +0000 (18:54 +0000)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 13:19:53 +0000 (15:19 +0200)
BugLink: https://bugs.launchpad.net/bugs/1971497
[ Upstream commit a9fe7fa7d874a536e0540469f314772c054a0323 ]

This change fixes the following:

1) The flags variable is not initialized. Always use raw_spin_lock_irqsave
and raw_spin_unlock_irqrestore to serialize patching.

2) flush_kernel_vmap_range is primarily intended for DMA flushes. Since
__patch_text_multiple is often called with interrupts disabled, it is
better to directly call flush_kernel_dcache_range_asm and
flush_kernel_icache_range_asm. This avoids an extra call.

3) The final call to flush_icache_range is unnecessary.

Signed-off-by: John David Anglin <dave.anglin@bell.net>
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/parisc/kernel/patch.c

index 80a0ab372802db148a1ccb0867bc0eb8ae3b7b69..e59574f65e641a09cbedb2e0ca7fa5e6045f3650 100644 (file)
@@ -40,10 +40,7 @@ static void __kprobes *patch_map(void *addr, int fixmap, unsigned long *flags,
 
        *need_unmap = 1;
        set_fixmap(fixmap, page_to_phys(page));
-       if (flags)
-               raw_spin_lock_irqsave(&patch_lock, *flags);
-       else
-               __acquire(&patch_lock);
+       raw_spin_lock_irqsave(&patch_lock, *flags);
 
        return (void *) (__fix_to_virt(fixmap) + (uintaddr & ~PAGE_MASK));
 }
@@ -52,10 +49,7 @@ static void __kprobes patch_unmap(int fixmap, unsigned long *flags)
 {
        clear_fixmap(fixmap);
 
-       if (flags)
-               raw_spin_unlock_irqrestore(&patch_lock, *flags);
-       else
-               __release(&patch_lock);
+       raw_spin_unlock_irqrestore(&patch_lock, *flags);
 }
 
 void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len)
@@ -67,8 +61,9 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len)
        int mapped;
 
        /* Make sure we don't have any aliases in cache */
-       flush_kernel_vmap_range(addr, len);
-       flush_icache_range(start, end);
+       flush_kernel_dcache_range_asm(start, end);
+       flush_kernel_icache_range_asm(start, end);
+       flush_tlb_kernel_range(start, end);
 
        p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags, &mapped);
 
@@ -81,8 +76,10 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len)
                         * We're crossing a page boundary, so
                         * need to remap
                         */
-                       flush_kernel_vmap_range((void *)fixmap,
-                                               (p-fixmap) * sizeof(*p));
+                       flush_kernel_dcache_range_asm((unsigned long)fixmap,
+                                                     (unsigned long)p);
+                       flush_tlb_kernel_range((unsigned long)fixmap,
+                                              (unsigned long)p);
                        if (mapped)
                                patch_unmap(FIX_TEXT_POKE0, &flags);
                        p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &flags,
@@ -90,10 +87,10 @@ void __kprobes __patch_text_multiple(void *addr, u32 *insn, unsigned int len)
                }
        }
 
-       flush_kernel_vmap_range((void *)fixmap, (p-fixmap) * sizeof(*p));
+       flush_kernel_dcache_range_asm((unsigned long)fixmap, (unsigned long)p);
+       flush_tlb_kernel_range((unsigned long)fixmap, (unsigned long)p);
        if (mapped)
                patch_unmap(FIX_TEXT_POKE0, &flags);
-       flush_icache_range(start, end);
 }
 
 void __kprobes __patch_text(void *addr, u32 insn)