]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
riscv: Use offset_in_page() in text patching functions
authorSamuel Holland <samuel.holland@sifive.com>
Wed, 27 Mar 2024 16:04:45 +0000 (09:04 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 26 Jun 2024 14:36:32 +0000 (07:36 -0700)
This is a bit easier to parse than the equivalent bit manipulation.

Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/20240327160520.791322-7-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/patch.c

index 99c5c0385305beb43eb8d33865e543f66cc77922..830f0650656be37e9e8dbfa3efcaa766f62e8646 100644 (file)
@@ -54,7 +54,7 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
        BUG_ON(!page);
 
        return (void *)set_fixmap_offset(fixmap, page_to_phys(page) +
-                                        (uintaddr & ~PAGE_MASK));
+                                        offset_in_page(addr));
 }
 
 static void patch_unmap(int fixmap)
@@ -65,8 +65,8 @@ NOKPROBE_SYMBOL(patch_unmap);
 
 static int __patch_insn_set(void *addr, u8 c, size_t len)
 {
+       bool across_pages = (offset_in_page(addr) + len) > PAGE_SIZE;
        void *waddr = addr;
-       bool across_pages = (((uintptr_t)addr & ~PAGE_MASK) + len) > PAGE_SIZE;
 
        /*
         * Only two pages can be mapped at a time for writing.
@@ -102,8 +102,8 @@ NOKPROBE_SYMBOL(__patch_insn_set);
 
 static int __patch_insn_write(void *addr, const void *insn, size_t len)
 {
+       bool across_pages = (offset_in_page(addr) + len) > PAGE_SIZE;
        void *waddr = addr;
-       bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE;
        int ret;
 
        /*