parisc: add set_fixmap()/clear_fixmap()
authorSven Schnelle <svens@stackframe.org>
Thu, 4 Apr 2019 19:14:08 +0000 (21:14 +0200)
committerHelge Deller <deller@gmx.de>
Fri, 3 May 2019 21:47:38 +0000 (23:47 +0200)
These functions will be used for adding code patching
functions later.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
Signed-off-by: Helge Deller <deller@gmx.de>
arch/parisc/include/asm/fixmap.h
arch/parisc/mm/Makefile
arch/parisc/mm/fixmap.c [new file with mode: 0644]
arch/parisc/mm/init.c

index f7c3a09..288da73 100644 (file)
  * from areas congruently mapped with user space.  It is 8MB large
  * and must be 16MB aligned */
 #define TMPALIAS_MAP_START     ((__PAGE_OFFSET) - 16*1024*1024)
+
+#define FIXMAP_SIZE            (FIX_BITMAP_COUNT << PAGE_SHIFT)
+#define FIXMAP_START           (TMPALIAS_MAP_START - FIXMAP_SIZE)
 /* This is the kernel area for all maps (vmalloc, dma etc.)  most
  * usually, it extends up to TMPALIAS_MAP_START.  Virtual addresses
  * 0..GATEWAY_PAGE_SIZE are reserved for the gateway page */
 #define KERNEL_MAP_START       (GATEWAY_PAGE_SIZE)
-#define KERNEL_MAP_END         (TMPALIAS_MAP_START)
+#define KERNEL_MAP_END         (FIXMAP_START)
 
 #ifndef __ASSEMBLY__
+
+
+enum fixed_addresses {
+       /* Support writing RO kernel text via kprobes, jump labels, etc. */
+       FIX_TEXT_POKE0,
+       FIX_BITMAP_COUNT
+};
+
 extern void *parisc_vmalloc_start;
 #define PCXL_DMA_MAP_SIZE      (8*1024*1024)
 #define VMALLOC_START          ((unsigned long)parisc_vmalloc_start)
 #define VMALLOC_END            (KERNEL_MAP_END)
+
+#define __fix_to_virt(_x) (FIXMAP_START + ((_x) << PAGE_SHIFT))
+
+void set_fixmap(enum fixed_addresses idx, phys_addr_t phys);
+void clear_fixmap(enum fixed_addresses idx);
+
 #endif /*__ASSEMBLY__*/
 
 #endif /*_ASM_FIXMAP_H*/
index 134393d..20e39b0 100644 (file)
@@ -2,5 +2,5 @@
 # Makefile for arch/parisc/mm
 #
 
-obj-y   := init.o fault.o ioremap.o
+obj-y   := init.o fault.o ioremap.o fixmap.o
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
diff --git a/arch/parisc/mm/fixmap.c b/arch/parisc/mm/fixmap.c
new file mode 100644 (file)
index 0000000..c8d41b5
--- /dev/null
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * fixmaps for parisc
+ *
+ * Copyright (c) 2019 Sven Schnelle <svens@stackframe.org>
+ */
+
+#include <linux/kprobes.h>
+#include <linux/mm.h>
+#include <asm/cacheflush.h>
+#include <asm/fixmap.h>
+
+void set_fixmap(enum fixed_addresses idx, phys_addr_t phys)
+{
+       unsigned long vaddr = __fix_to_virt(idx);
+       pgd_t *pgd = pgd_offset_k(vaddr);
+       pmd_t *pmd = pmd_offset(pgd, vaddr);
+       pte_t *pte;
+
+       if (pmd_none(*pmd))
+               pmd = pmd_alloc(NULL, pgd, vaddr);
+
+       pte = pte_offset_kernel(pmd, vaddr);
+       if (pte_none(*pte))
+               pte = pte_alloc_kernel(pmd, vaddr);
+
+       set_pte_at(&init_mm, vaddr, pte, __mk_pte(phys, PAGE_KERNEL_RWX));
+       flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
+}
+
+void clear_fixmap(enum fixed_addresses idx)
+{
+       unsigned long vaddr = __fix_to_virt(idx);
+       pgd_t *pgd = pgd_offset_k(vaddr);
+       pmd_t *pmd = pmd_offset(pgd, vaddr);
+       pte_t *pte = pte_offset_kernel(pmd, vaddr);
+
+       pte_clear(&init_mm, vaddr, pte);
+
+       flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
+}
index d0b1662..b2b52de 100644 (file)
@@ -622,15 +622,19 @@ void __init mem_init(void)
         * But keep code for debugging purposes.
         */
        printk("virtual kernel memory layout:\n"
-              "    vmalloc : 0x%px - 0x%px   (%4ld MB)\n"
-              "    memory  : 0x%px - 0x%px   (%4ld MB)\n"
-              "      .init : 0x%px - 0x%px   (%4ld kB)\n"
-              "      .data : 0x%px - 0x%px   (%4ld kB)\n"
-              "      .text : 0x%px - 0x%px   (%4ld kB)\n",
+              "     vmalloc : 0x%px - 0x%px   (%4ld MB)\n"
+              "     fixmap  : 0x%px - 0x%px   (%4ld kB)\n"
+              "     memory  : 0x%px - 0x%px   (%4ld MB)\n"
+              "       .init : 0x%px - 0x%px   (%4ld kB)\n"
+              "       .data : 0x%px - 0x%px   (%4ld kB)\n"
+              "       .text : 0x%px - 0x%px   (%4ld kB)\n",
 
               (void*)VMALLOC_START, (void*)VMALLOC_END,
               (VMALLOC_END - VMALLOC_START) >> 20,
 
+              (void *)FIXMAP_START, (void *)(FIXMAP_START + FIXMAP_SIZE),
+              (unsigned long)(FIXMAP_SIZE / 1024),
+
               __va(0), high_memory,
               ((unsigned long)high_memory - (unsigned long)__va(0)) >> 20,