]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge tag 'v4.13-rc1' into fixes
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 31 Jul 2017 10:20:29 +0000 (20:20 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 31 Jul 2017 10:20:29 +0000 (20:20 +1000)
The fixes branch is based off a random pre-rc1 commit, because we had
some fixes that needed to go in before rc1 was released.

However we now need to fix some code that went in after that point, but
before rc1, so merge rc1 to get that code into fixes so we can fix it!

23 files changed:
arch/powerpc/Makefile
arch/powerpc/boot/Makefile
arch/powerpc/include/asm/book3s/64/hash.h
arch/powerpc/include/asm/book3s/64/mmu.h
arch/powerpc/include/asm/book3s/64/pgtable.h
arch/powerpc/include/asm/book3s/64/radix.h
arch/powerpc/include/asm/mmu_context.h
arch/powerpc/include/asm/pgtable.h
arch/powerpc/kernel/exceptions-64s.S
arch/powerpc/kernel/idle_book3s.S
arch/powerpc/kernel/ptrace.c
arch/powerpc/kernel/smp.c
arch/powerpc/kvm/book3s_hv_rmhandlers.S
arch/powerpc/mm/mem.c
arch/powerpc/mm/mmu_context_book3s64.c
arch/powerpc/mm/pgtable-hash64.c
arch/powerpc/mm/pgtable-radix.c
arch/powerpc/mm/pgtable_64.c
arch/powerpc/mm/subpage-prot.c
arch/powerpc/mm/tlb-radix.c
arch/powerpc/platforms/powernv/opal.c
arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/platforms/pseries/reconfig.c

index 8d4ed73d549091368be87c5b4483f33d6b00640d..e2b3e7a00c9e3548e0b0086f878d4b707ba40dbb 100644 (file)
@@ -59,6 +59,19 @@ machine-$(CONFIG_PPC64) += 64
 machine-$(CONFIG_CPU_LITTLE_ENDIAN) += le
 UTS_MACHINE := $(subst $(space),,$(machine-y))
 
+# XXX This needs to be before we override LD below
+ifdef CONFIG_PPC32
+KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
+else
+ifeq ($(call ld-ifversion, -ge, 225000000, y),y)
+# Have the linker provide sfpr if possible.
+# There is a corresponding test in arch/powerpc/lib/Makefile
+KBUILD_LDFLAGS_MODULE += --save-restore-funcs
+else
+KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
+endif
+endif
+
 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
 override LD    += -EL
 LDEMULATION    := lppc
@@ -190,18 +203,6 @@ else
 CHECKFLAGS     += -D__LITTLE_ENDIAN__
 endif
 
-ifdef CONFIG_PPC32
-KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
-else
-ifeq ($(call ld-ifversion, -ge, 225000000, y),y)
-# Have the linker provide sfpr if possible.
-# There is a corresponding test in arch/powerpc/lib/Makefile
-KBUILD_LDFLAGS_MODULE += --save-restore-funcs
-else
-KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
-endif
-endif
-
 ifeq ($(CONFIG_476FPE_ERR46),y)
        KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
                -T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
index a7814a7b15233261b0d9ba9d848543948dcd34d6..6f952fe1f0842232fab09eba6d89953d09946111 100644 (file)
@@ -25,12 +25,20 @@ compress-$(CONFIG_KERNEL_XZ)   := CONFIG_KERNEL_XZ
 BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                 -fno-strict-aliasing -Os -msoft-float -pipe \
                 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
-                -isystem $(shell $(CROSS32CC) -print-file-name=include) \
                 -D$(compress-y)
 
+BOOTCC := $(CC)
 ifdef CONFIG_PPC64_BOOT_WRAPPER
 BOOTCFLAGS     += -m64
+else
+BOOTCFLAGS     += -m32
+ifdef CROSS32_COMPILE
+    BOOTCC := $(CROSS32_COMPILE)gcc
+endif
 endif
+
+BOOTCFLAGS     += -isystem $(shell $(BOOTCC) -print-file-name=include)
+
 ifdef CONFIG_CPU_BIG_ENDIAN
 BOOTCFLAGS     += -mbig-endian
 else
@@ -183,10 +191,10 @@ clean-files := $(zlib-) $(zlibheader-) $(zliblinuxheader-) \
                empty.c zImage.coff.lds zImage.ps3.lds zImage.lds
 
 quiet_cmd_bootcc = BOOTCC  $@
-      cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
+      cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
 
 quiet_cmd_bootas = BOOTAS  $@
-      cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
+      cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
 
 quiet_cmd_bootar = BOOTAR  $@
       cmd_bootar = $(CROSS32AR) -cr$(KBUILD_ARFLAGS) $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
index 0ce513f2926f12680ce1570266550eb8b2b09eeb..36fc7bfe9e1140d1e5eabc781199851a6445d51a 100644 (file)
@@ -91,6 +91,7 @@ static inline int hash__pgd_bad(pgd_t pgd)
 }
 #ifdef CONFIG_STRICT_KERNEL_RWX
 extern void hash__mark_rodata_ro(void);
+extern void hash__mark_initmem_nx(void);
 #endif
 
 extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
index 77529a3e38114cd4e5d413d687184e037827ea3a..5b4023c616f7087d247d17509f170944b26f6a76 100644 (file)
@@ -59,13 +59,14 @@ extern struct patb_entry *partition_tb;
 #define PRTS_MASK      0x1f            /* process table size field */
 #define PRTB_MASK      0x0ffffffffffff000UL
 
-/*
- * Limit process table to PAGE_SIZE table. This
- * also limit the max pid we can support.
- * MAX_USER_CONTEXT * 16 bytes of space.
- */
-#define PRTB_SIZE_SHIFT        (CONTEXT_BITS + 4)
-#define PRTB_ENTRIES   (1ul << CONTEXT_BITS)
+/* Number of supported PID bits */
+extern unsigned int mmu_pid_bits;
+
+/* Base PID to allocate from */
+extern unsigned int mmu_base_pid;
+
+#define PRTB_SIZE_SHIFT        (mmu_pid_bits + 4)
+#define PRTB_ENTRIES   (1ul << mmu_pid_bits)
 
 /*
  * Power9 currently only support 64K partition table size.
index c0737c86a36272b1df213a41c4c75426c16d9178..818a58fc3f4f967d3bc4524c32e64ba4529c4cca 100644 (file)
@@ -608,9 +608,17 @@ static inline pte_t pte_mkdevmap(pte_t pte)
        return __pte(pte_val(pte) | _PAGE_SPECIAL|_PAGE_DEVMAP);
 }
 
+/*
+ * This is potentially called with a pmd as the argument, in which case it's not
+ * safe to check _PAGE_DEVMAP unless we also confirm that _PAGE_PTE is set.
+ * That's because the bit we use for _PAGE_DEVMAP is not reserved for software
+ * use in page directory entries (ie. non-ptes).
+ */
 static inline int pte_devmap(pte_t pte)
 {
-       return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DEVMAP));
+       u64 mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
+
+       return (pte_raw(pte) & mask) == mask;
 }
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
@@ -1192,5 +1200,6 @@ static inline const int pud_pfn(pud_t pud)
        BUILD_BUG();
        return 0;
 }
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
index 487709ff6875bd61d6b6cc7c8652c7e27f8404a2..544440b5aff395c1d00076af87dec8b15628dd77 100644 (file)
 
 #ifdef CONFIG_STRICT_KERNEL_RWX
 extern void radix__mark_rodata_ro(void);
+extern void radix__mark_initmem_nx(void);
 #endif
 
 static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr,
index da7e9432fa8fc512b8c00f0ecc57bd626cf56911..0c76675394c5930d5cecf2ac01a2718c8e9b6c1f 100644 (file)
@@ -45,7 +45,7 @@ extern void set_context(unsigned long id, pgd_t *pgd);
 
 #ifdef CONFIG_PPC_BOOK3S_64
 extern void radix__switch_mmu_context(struct mm_struct *prev,
-                                    struct mm_struct *next);
+                                     struct mm_struct *next);
 static inline void switch_mmu_context(struct mm_struct *prev,
                                      struct mm_struct *next,
                                      struct task_struct *tsk)
@@ -67,6 +67,12 @@ extern void __destroy_context(unsigned long context_id);
 extern void mmu_context_init(void);
 #endif
 
+#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE) && defined(CONFIG_PPC_RADIX_MMU)
+extern void radix_kvm_prefetch_workaround(struct mm_struct *mm);
+#else
+static inline void radix_kvm_prefetch_workaround(struct mm_struct *mm) { }
+#endif
+
 extern void switch_cop(struct mm_struct *next);
 extern int use_cop(unsigned long acop, struct mm_struct *mm);
 extern void drop_cop(unsigned long acop, struct mm_struct *mm);
@@ -79,9 +85,13 @@ static inline void switch_mm_irqs_off(struct mm_struct *prev,
                                      struct mm_struct *next,
                                      struct task_struct *tsk)
 {
+       bool new_on_cpu = false;
+
        /* Mark this context has been used on the new CPU */
-       if (!cpumask_test_cpu(smp_processor_id(), mm_cpumask(next)))
+       if (!cpumask_test_cpu(smp_processor_id(), mm_cpumask(next))) {
                cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
+               new_on_cpu = true;
+       }
 
        /* 32-bit keeps track of the current PGDIR in the thread struct */
 #ifdef CONFIG_PPC32
@@ -109,6 +119,10 @@ static inline void switch_mm_irqs_off(struct mm_struct *prev,
        if (cpu_has_feature(CPU_FTR_ALTIVEC))
                asm volatile ("dssall");
 #endif /* CONFIG_ALTIVEC */
+
+       if (new_on_cpu)
+               radix_kvm_prefetch_workaround(next);
+
        /*
         * The actual HW switching method differs between the various
         * sub architectures. Out of line for now
index dd01212935acacd32504e0ab2783b6670674f744..afae9a336136a4916c9912d3fd7f8c8f268406f2 100644 (file)
@@ -80,6 +80,13 @@ unsigned long vmalloc_to_phys(void *vmalloc_addr);
 
 void pgtable_cache_add(unsigned shift, void (*ctor)(void *));
 void pgtable_cache_init(void);
+
+#ifdef CONFIG_STRICT_KERNEL_RWX
+void mark_initmem_nx(void);
+#else
+static inline void mark_initmem_nx(void) { }
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_H */
index e6d8354d79ef25a34ece7766683813a65ffde57c..9029afd1fa2ab2ce231045659abf11ec9eaa32f6 100644 (file)
@@ -824,7 +824,7 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  * r3 volatile parameter and return value for status
  * r4-r10 volatile input and output value
  * r11 volatile hypercall number and output value
- * r12 volatile
+ * r12 volatile input and output value
  * r13-r31 nonvolatile
  * LR nonvolatile
  * CTR volatile
@@ -834,25 +834,26 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  * Other registers nonvolatile
  *
  * The intersection of volatile registers that don't contain possible
- * inputs is: r12, cr0, xer, ctr. We may use these as scratch regs
- * upon entry without saving.
+ * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
+ * without saving, though xer is not a good idea to use, as hardware may
+ * interpret some bits so it may be costly to change them.
  */
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
        /*
         * There is a little bit of juggling to get syscall and hcall
-        * working well. Save r10 in ctr to be restored in case it is a
-        * hcall.
+        * working well. Save r13 in ctr to avoid using SPRG scratch
+        * register.
         *
         * Userspace syscalls have already saved the PPR, hcalls must save
         * it before setting HMT_MEDIUM.
         */
 #define SYSCALL_KVMTEST                                                        \
-       mr      r12,r13;                                                \
+       mtctr   r13;                                                    \
        GET_PACA(r13);                                                  \
-       mtctr   r10;                                                    \
+       std     r10,PACA_EXGEN+EX_R10(r13);                             \
        KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
        HMT_MEDIUM;                                                     \
-       mr      r9,r12;                                                 \
+       mfctr   r9;
 
 #else
 #define SYSCALL_KVMTEST                                                        \
@@ -935,8 +936,8 @@ EXC_VIRT_END(system_call, 0x4c00, 0x100)
         * This is a hcall, so register convention is as above, with these
         * differences:
         * r13 = PACA
-        * r12 = orig r13
-        * ctr = orig r10
+        * ctr = orig r13
+        * orig r10 saved in PACA
         */
 TRAMP_KVM_BEGIN(do_kvm_0xc00)
         /*
@@ -944,14 +945,13 @@ TRAMP_KVM_BEGIN(do_kvm_0xc00)
          * HMT_MEDIUM. That allows the KVM code to save that value into the
          * guest state (it is the guest's PPR value).
          */
-       OPT_GET_SPR(r0, SPRN_PPR, CPU_FTR_HAS_PPR)
+       OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
        HMT_MEDIUM
-       OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r0, CPU_FTR_HAS_PPR)
+       OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
        mfctr   r10
-       SET_SCRATCH0(r12)
+       SET_SCRATCH0(r10)
        std     r9,PACA_EXGEN+EX_R9(r13)
        mfcr    r9
-       std     r10,PACA_EXGEN+EX_R10(r13)
        KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
 #endif
 
index 5adb390e773bdd441ed0456eaed2511c094264a7..516ebef905c063b6bdb696f5f6048da37f7822cd 100644 (file)
@@ -30,6 +30,7 @@
  * Use unused space in the interrupt stack to save and restore
  * registers for winkle support.
  */
+#define _MMCR0 GPR0
 #define _SDR1  GPR3
 #define _PTCR  GPR3
 #define _RPR   GPR4
@@ -272,6 +273,14 @@ power_enter_stop:
        b       pnv_wakeup_noloss
 
 .Lhandle_esl_ec_set:
+       /*
+        * POWER9 DD2 can incorrectly set PMAO when waking up after a
+        * state-loss idle. Saving and restoring MMCR0 over idle is a
+        * workaround.
+        */
+       mfspr   r4,SPRN_MMCR0
+       std     r4,_MMCR0(r1)
+
 /*
  * Check if the requested state is a deep idle state.
  */
@@ -450,10 +459,14 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
 pnv_restore_hyp_resource_arch300:
        /*
         * Workaround for POWER9, if we lost resources, the ERAT
-        * might have been mixed up and needs flushing.
+        * might have been mixed up and needs flushing. We also need
+        * to reload MMCR0 (see comment above).
         */
        blt     cr3,1f
        PPC_INVALIDATE_ERAT
+       ld      r1,PACAR1(r13)
+       ld      r4,_MMCR0(r1)
+       mtspr   SPRN_MMCR0,r4
 1:
        /*
         * POWER ISA 3. Use PSSCR to determine if we
index 925a4ef9055932174b4dc5a8f0424b330149132b..660ed39e9c9a59fc3b7087362787502a41ba50fd 100644 (file)
@@ -127,12 +127,19 @@ static void flush_tmregs_to_thread(struct task_struct *tsk)
         * If task is not current, it will have been flushed already to
         * it's thread_struct during __switch_to().
         *
-        * A reclaim flushes ALL the state.
+        * A reclaim flushes ALL the state or if not in TM save TM SPRs
+        * in the appropriate thread structures from live.
         */
 
-       if (tsk == current && MSR_TM_SUSPENDED(mfmsr()))
-               tm_reclaim_current(TM_CAUSE_SIGNAL);
+       if (tsk != current)
+               return;
 
+       if (MSR_TM_SUSPENDED(mfmsr())) {
+               tm_reclaim_current(TM_CAUSE_SIGNAL);
+       } else {
+               tm_enable();
+               tm_save_sprs(&(tsk->thread));
+       }
 }
 #else
 static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
index 997c88d54acf292b3e80beef1791ee2194ca9071..cf0e1245b8cc1c78948a4004be2d20c5b5ac0b78 100644 (file)
@@ -1003,21 +1003,13 @@ static struct sched_domain_topology_level powerpc_topology[] = {
        { NULL, },
 };
 
-static __init long smp_setup_cpu_workfn(void *data __always_unused)
-{
-       smp_ops->setup_cpu(boot_cpuid);
-       return 0;
-}
-
 void __init smp_cpus_done(unsigned int max_cpus)
 {
        /*
-        * We want the setup_cpu() here to be called on the boot CPU, but
-        * init might run on any CPU, so make sure it's invoked on the boot
-        * CPU.
+        * We are running pinned to the boot CPU, see rest_init().
         */
        if (smp_ops && smp_ops->setup_cpu)
-               work_on_cpu_safe(boot_cpuid, smp_setup_cpu_workfn, NULL);
+               smp_ops->setup_cpu(boot_cpuid);
 
        if (smp_ops && smp_ops->bringup_done)
                smp_ops->bringup_done();
index cb44065e29463f99d6c44bf129ca01e82695a8ff..c52184a8efdf025c1efffc6dd7310e9374dca630 100644 (file)
@@ -1443,12 +1443,14 @@ mc_cont:
        ori     r6,r6,1
        mtspr   SPRN_CTRLT,r6
 4:
-       /* Read the guest SLB and save it away */
+       /* Check if we are running hash or radix and store it in cr2 */
        ld      r5, VCPU_KVM(r9)
        lbz     r0, KVM_RADIX(r5)
-       cmpwi   r0, 0
+       cmpwi   cr2,r0,0
+
+       /* Read the guest SLB and save it away */
        li      r5, 0
-       bne     3f                      /* for radix, save 0 entries */
+       bne     cr2, 3f                 /* for radix, save 0 entries */
        lwz     r0,VCPU_SLB_NR(r9)      /* number of entries in SLB */
        mtctr   r0
        li      r6,0
@@ -1712,11 +1714,6 @@ BEGIN_FTR_SECTION_NESTED(96)
 END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 22:
-       /* Clear out SLB */
-       li      r5,0
-       slbmte  r5,r5
-       slbia
-       ptesync
 
        /* Restore host values of some registers */
 BEGIN_FTR_SECTION
@@ -1737,10 +1734,56 @@ BEGIN_FTR_SECTION
        mtspr   SPRN_PID, r7
        mtspr   SPRN_IAMR, r8
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
+
+#ifdef CONFIG_PPC_RADIX_MMU
+       /*
+        * Are we running hash or radix ?
+        */
+       beq     cr2,3f
+
+       /* Radix: Handle the case where the guest used an illegal PID */
+       LOAD_REG_ADDR(r4, mmu_base_pid)
+       lwz     r3, VCPU_GUEST_PID(r9)
+       lwz     r5, 0(r4)
+       cmpw    cr0,r3,r5
+       blt     2f
+
+       /*
+        * Illegal PID, the HW might have prefetched and cached in the TLB
+        * some translations for the  LPID 0 / guest PID combination which
+        * Linux doesn't know about, so we need to flush that PID out of
+        * the TLB. First we need to set LPIDR to 0 so tlbiel applies to
+        * the right context.
+       */
+       li      r0,0
+       mtspr   SPRN_LPID,r0
+       isync
+
+       /* Then do a congruence class local flush */
+       ld      r6,VCPU_KVM(r9)
+       lwz     r0,KVM_TLB_SETS(r6)
+       mtctr   r0
+       li      r7,0x400                /* IS field = 0b01 */
+       ptesync
+       sldi    r0,r3,32                /* RS has PID */
+1:     PPC_TLBIEL(7,0,2,1,1)           /* RIC=2, PRS=1, R=1 */
+       addi    r7,r7,0x1000
+       bdnz    1b
+       ptesync
+
+2:     /* Flush the ERAT on radix P9 DD1 guest exit */
 BEGIN_FTR_SECTION
        PPC_INVALIDATE_ERAT
 END_FTR_SECTION_IFSET(CPU_FTR_POWER9_DD1)
+       b       4f
+#endif /* CONFIG_PPC_RADIX_MMU */
 
+       /* Hash: clear out SLB */
+3:     li      r5,0
+       slbmte  r5,r5
+       slbia
+       ptesync
+4:
        /*
         * POWER7/POWER8 guest -> host partition switch code.
         * We don't have to lock against tlbies but we do
index 8541f18694a4a6d8003b32ad29f7c192f190ef6e..46b4e67d2372328231b47c7e225af6d780fde022 100644 (file)
@@ -402,6 +402,7 @@ void __init mem_init(void)
 void free_initmem(void)
 {
        ppc_md.progress = ppc_printk_progress;
+       mark_initmem_nx();
        free_initmem_default(POISON_FREE_INITMEM);
 }
 
index abed1fe6992fa1bb365dfd30717bcfac3f402ee4..a75f63833284cbb089f67fa21bee0357426a2a88 100644 (file)
@@ -126,9 +126,10 @@ static int hash__init_new_context(struct mm_struct *mm)
 static int radix__init_new_context(struct mm_struct *mm)
 {
        unsigned long rts_field;
-       int index;
+       int index, max_id;
 
-       index = alloc_context_id(1, PRTB_ENTRIES - 1);
+       max_id = (1 << mmu_pid_bits) - 1;
+       index = alloc_context_id(mmu_base_pid, max_id);
        if (index < 0)
                return index;
 
index 188b4107584d2a741645aac48382bffadbfb4116..443a2c66a30467d7bea260d6a7d01df19d55c33a 100644 (file)
@@ -425,33 +425,51 @@ int hash__has_transparent_hugepage(void)
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
 #ifdef CONFIG_STRICT_KERNEL_RWX
-void hash__mark_rodata_ro(void)
+static bool hash__change_memory_range(unsigned long start, unsigned long end,
+                                     unsigned long newpp)
 {
-       unsigned long start = (unsigned long)_stext;
-       unsigned long end = (unsigned long)__init_begin;
        unsigned long idx;
        unsigned int step, shift;
-       unsigned long newpp = PP_RXXX;
 
        shift = mmu_psize_defs[mmu_linear_psize].shift;
        step = 1 << shift;
 
-       start = ((start + step - 1) >> shift) << shift;
-       end = (end >> shift) << shift;
+       start = ALIGN_DOWN(start, step);
+       end = ALIGN(end, step); // aligns up
 
-       pr_devel("marking ro start %lx, end %lx, step %x\n",
-                       start, end, step);
+       if (start >= end)
+               return false;
 
-       if (start == end) {
-               pr_warn("could not set rodata ro, relocate the start"
-                       " of the kernel to a 0x%x boundary\n", step);
-               return;
-       }
+       pr_debug("Changing page protection on range 0x%lx-0x%lx, to 0x%lx, step 0x%x\n",
+                start, end, newpp, step);
 
        for (idx = start; idx < end; idx += step)
                /* Not sure if we can do much with the return value */
                mmu_hash_ops.hpte_updateboltedpp(newpp, idx, mmu_linear_psize,
                                                        mmu_kernel_ssize);
 
+       return true;
+}
+
+void hash__mark_rodata_ro(void)
+{
+       unsigned long start, end;
+
+       start = (unsigned long)_stext;
+       end = (unsigned long)__init_begin;
+
+       WARN_ON(!hash__change_memory_range(start, end, PP_RXXX));
+}
+
+void hash__mark_initmem_nx(void)
+{
+       unsigned long start, end, pp;
+
+       start = (unsigned long)__init_begin;
+       end = (unsigned long)__init_end;
+
+       pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL));
+
+       WARN_ON(!hash__change_memory_range(start, end, pp));
 }
 #endif
index 8c13e4282308add562bf794be32b989ef90eb803..671a45d86c18dd7e174ffb909084cd0a37fcdaff 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <trace/events/thp.h>
 
+unsigned int mmu_pid_bits;
+unsigned int mmu_base_pid;
+
 static int native_register_process_table(unsigned long base, unsigned long pg_sz,
                                         unsigned long table_size)
 {
@@ -112,10 +115,9 @@ set_the_pte:
 }
 
 #ifdef CONFIG_STRICT_KERNEL_RWX
-void radix__mark_rodata_ro(void)
+void radix__change_memory_range(unsigned long start, unsigned long end,
+                               unsigned long clear)
 {
-       unsigned long start = (unsigned long)_stext;
-       unsigned long end = (unsigned long)__init_begin;
        unsigned long idx;
        pgd_t *pgdp;
        pud_t *pudp;
@@ -125,7 +127,8 @@ void radix__mark_rodata_ro(void)
        start = ALIGN_DOWN(start, PAGE_SIZE);
        end = PAGE_ALIGN(end); // aligns up
 
-       pr_devel("marking ro start %lx, end %lx\n", start, end);
+       pr_debug("Changing flags on range %lx-%lx removing 0x%lx\n",
+                start, end, clear);
 
        for (idx = start; idx < end; idx += PAGE_SIZE) {
                pgdp = pgd_offset_k(idx);
@@ -147,11 +150,29 @@ void radix__mark_rodata_ro(void)
                if (!ptep)
                        continue;
 update_the_pte:
-               radix__pte_update(&init_mm, idx, ptep, _PAGE_WRITE, 0, 0);
+               radix__pte_update(&init_mm, idx, ptep, clear, 0, 0);
        }
 
        radix__flush_tlb_kernel_range(start, end);
 }
+
+void radix__mark_rodata_ro(void)
+{
+       unsigned long start, end;
+
+       start = (unsigned long)_stext;
+       end = (unsigned long)__init_begin;
+
+       radix__change_memory_range(start, end, _PAGE_WRITE);
+}
+
+void radix__mark_initmem_nx(void)
+{
+       unsigned long start = (unsigned long)__init_begin;
+       unsigned long end = (unsigned long)__init_end;
+
+       radix__change_memory_range(start, end, _PAGE_EXEC);
+}
 #endif /* CONFIG_STRICT_KERNEL_RWX */
 
 static inline void __meminit print_mapping(unsigned long start,
@@ -243,11 +264,34 @@ static void __init radix_init_pgtable(void)
        for_each_memblock(memory, reg)
                WARN_ON(create_physical_mapping(reg->base,
                                                reg->base + reg->size));
+
+       /* Find out how many PID bits are supported */
+       if (cpu_has_feature(CPU_FTR_HVMODE)) {
+               if (!mmu_pid_bits)
+                       mmu_pid_bits = 20;
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+               /*
+                * When KVM is possible, we only use the top half of the
+                * PID space to avoid collisions between host and guest PIDs
+                * which can cause problems due to prefetch when exiting the
+                * guest with AIL=3
+                */
+               mmu_base_pid = 1 << (mmu_pid_bits - 1);
+#else
+               mmu_base_pid = 1;
+#endif
+       } else {
+               /* The guest uses the bottom half of the PID space */
+               if (!mmu_pid_bits)
+                       mmu_pid_bits = 19;
+               mmu_base_pid = 1;
+       }
+
        /*
         * Allocate Partition table and process table for the
         * host.
         */
-       BUILD_BUG_ON_MSG((PRTB_SIZE_SHIFT > 36), "Process table size too large.");
+       BUG_ON(PRTB_SIZE_SHIFT > 36);
        process_tb = early_alloc_pgtable(1UL << PRTB_SIZE_SHIFT);
        /*
         * Fill in the process table.
@@ -321,6 +365,12 @@ static int __init radix_dt_scan_page_sizes(unsigned long node,
        if (type == NULL || strcmp(type, "cpu") != 0)
                return 0;
 
+       /* Find MMU PID size */
+       prop = of_get_flat_dt_prop(node, "ibm,mmu-pid-bits", &size);
+       if (prop && size == 4)
+               mmu_pid_bits = be32_to_cpup(prop);
+
+       /* Grab page size encodings */
        prop = of_get_flat_dt_prop(node, "ibm,processor-radix-AP-encodings", &size);
        if (!prop)
                return 0;
index 5c0b795d656c4298fc36aaac72d15d58359f23e7..0736e94c7615a67b2efd8bd39e237bb757a8e74c 100644 (file)
@@ -505,4 +505,12 @@ void mark_rodata_ro(void)
        else
                hash__mark_rodata_ro();
 }
+
+void mark_initmem_nx(void)
+{
+       if (radix_enabled())
+               radix__mark_initmem_nx();
+       else
+               hash__mark_initmem_nx();
+}
 #endif
index e94fbd4c88458aa5953a271b1ef1eac0ef5c5c66..781532d7bc4d29683ab2ac72cff6f0ad7d4d01f4 100644 (file)
@@ -36,7 +36,7 @@ void subpage_prot_free(struct mm_struct *mm)
                }
        }
        addr = 0;
-       for (i = 0; i < 2; ++i) {
+       for (i = 0; i < (TASK_SIZE_USER64 >> 43); ++i) {
                p = spt->protptrs[i];
                if (!p)
                        continue;
index 744e0164ecf58551f036ef30e19a79638adcaa76..16ae1bbe13f09e588919f8aa55a81ed575290360 100644 (file)
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
 #include <linux/memblock.h>
-#include <asm/ppc-opcode.h>
 
+#include <asm/ppc-opcode.h>
 #include <asm/tlb.h>
 #include <asm/tlbflush.h>
 #include <asm/trace.h>
-
+#include <asm/cputhreads.h>
 
 #define RIC_FLUSH_TLB 0
 #define RIC_FLUSH_PWC 1
@@ -454,3 +454,44 @@ void radix__flush_tlb_pte_p9_dd1(unsigned long old_pte, struct mm_struct *mm,
        else
                radix__flush_tlb_page_psize(mm, address, mmu_virtual_psize);
 }
+
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+extern void radix_kvm_prefetch_workaround(struct mm_struct *mm)
+{
+       unsigned int pid = mm->context.id;
+
+       if (unlikely(pid == MMU_NO_CONTEXT))
+               return;
+
+       /*
+        * If this context hasn't run on that CPU before and KVM is
+        * around, there's a slim chance that the guest on another
+        * CPU just brought in obsolete translation into the TLB of
+        * this CPU due to a bad prefetch using the guest PID on
+        * the way into the hypervisor.
+        *
+        * We work around this here. If KVM is possible, we check if
+        * any sibling thread is in KVM. If it is, the window may exist
+        * and thus we flush that PID from the core.
+        *
+        * A potential future improvement would be to mark which PIDs
+        * have never been used on the system and avoid it if the PID
+        * is new and the process has no other cpumask bit set.
+        */
+       if (cpu_has_feature(CPU_FTR_HVMODE) && radix_enabled()) {
+               int cpu = smp_processor_id();
+               int sib = cpu_first_thread_sibling(cpu);
+               bool flush = false;
+
+               for (; sib <= cpu_last_thread_sibling(cpu) && !flush; sib++) {
+                       if (sib == cpu)
+                               continue;
+                       if (paca[sib].kvm_hstate.kvm_vcpu)
+                               flush = true;
+               }
+               if (flush)
+                       _tlbiel_pid(pid, RIC_FLUSH_ALL);
+       }
+}
+EXPORT_SYMBOL_GPL(radix_kvm_prefetch_workaround);
+#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
index 9b87abb178f02aaa0dd3afc757499df58bf133eb..cad6b57ce494bb72dff04102e7d8d0499b8e038a 100644 (file)
@@ -78,7 +78,7 @@ void opal_configure_cores(void)
         *  ie. Host hash  supports  hash guests
         *      Host radix supports  hash/radix guests
         */
-       if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+       if (early_cpu_has_feature(CPU_FTR_ARCH_300)) {
                reinit_flags |= OPAL_REINIT_CPUS_MMU_HASH;
                if (early_radix_enabled())
                        reinit_flags |= OPAL_REINIT_CPUS_MMU_RADIX;
index 437613588df15ceab2a1ce5e88649b675c495de4..b900eb1d5e174c1cdafc0a7e9620caecac98bb69 100644 (file)
@@ -1852,6 +1852,14 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
                        /* 4GB offset bypasses 32-bit space */
                        set_dma_offset(&pdev->dev, (1ULL << 32));
                        set_dma_ops(&pdev->dev, &dma_direct_ops);
+               } else if (dma_mask >> 32 && dma_mask != DMA_BIT_MASK(64)) {
+                       /*
+                        * Fail the request if a DMA mask between 32 and 64 bits
+                        * was requested but couldn't be fulfilled. Ideally we
+                        * would do this for 64-bits but historically we have
+                        * always fallen back to 32-bits.
+                        */
+                       return -ENOMEM;
                } else {
                        dev_info(&pdev->dev, "Using 32-bit DMA via iommu\n");
                        set_dma_ops(&pdev->dev, &dma_iommu_ops);
index e5bf1e84047f4c3fb9746ae85b0c6593f47ab012..011ef2180fe6b8d85f4fa11a1b31e8636e29d617 100644 (file)
@@ -82,7 +82,6 @@ static int pSeries_reconfig_remove_node(struct device_node *np)
 
        of_detach_node(np);
        of_node_put(parent);
-       of_node_put(np); /* Must decrement the refcount */
        return 0;
 }