Merge tag 'powerpc-4.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 5 Aug 2016 13:00:54 +0000 (09:00 -0400)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 5 Aug 2016 13:00:54 +0000 (09:00 -0400)
Pull more powerpc updates from Michael Ellerman:
 "These were delayed for various reasons, so I let them sit in next a
  bit longer, rather than including them in my first pull request.

  Fixes:
   - Fix early access to cpu_spec relocation from Benjamin Herrenschmidt
   - Fix incorrect event codes in power9-event-list from Madhavan Srinivasan
   - Move register_process_table() out of ppc_md from Michael Ellerman

  Use jump_label use for [cpu|mmu]_has_feature():
   - Add mmu_early_init_devtree() from Michael Ellerman
   - Move disable_radix handling into mmu_early_init_devtree() from Michael Ellerman
   - Do hash device tree scanning earlier from Michael Ellerman
   - Do radix device tree scanning earlier from Michael Ellerman
   - Do feature patching before MMU init from Michael Ellerman
   - Check features don't change after patching from Michael Ellerman
   - Make MMU_FTR_RADIX a MMU family feature from Aneesh Kumar K.V
   - Convert mmu_has_feature() to returning bool from Michael Ellerman
   - Convert cpu_has_feature() to returning bool from Michael Ellerman
   - Define radix_enabled() in one place & use static inline from Michael Ellerman
   - Add early_[cpu|mmu]_has_feature() from Michael Ellerman
   - Convert early cpu/mmu feature check to use the new helpers from Aneesh Kumar K.V
   - jump_label: Make it possible for arches to invoke jump_label_init() earlier from Kevin Hao
   - Call jump_label_init() in apply_feature_fixups() from Aneesh Kumar K.V
   - Remove mfvtb() from Kevin Hao
   - Move cpu_has_feature() to a separate file from Kevin Hao
   - Add kconfig option to use jump labels for cpu/mmu_has_feature() from Michael Ellerman
   - Add option to use jump label for cpu_has_feature() from Kevin Hao
   - Add option to use jump label for mmu_has_feature() from Kevin Hao
   - Catch usage of cpu/mmu_has_feature() before jump label init from Aneesh Kumar K.V
   - Annotate jump label assembly from Michael Ellerman

  TLB flush enhancements from Aneesh Kumar K.V:
   - radix: Implement tlb mmu gather flush efficiently
   - Add helper for finding SLBE LLP encoding
   - Use hugetlb flush functions
   - Drop multiple definition of mm_is_core_local
   - radix: Add tlb flush of THP ptes
   - radix: Rename function and drop unused arg
   - radix/hugetlb: Add helper for finding page size
   - hugetlb: Add flush_hugetlb_tlb_range
   - remove flush_tlb_page_nohash

  Add new ptrace regsets from Anshuman Khandual and Simon Guo:
   - elf: Add powerpc specific core note sections
   - Add the function flush_tmregs_to_thread
   - Enable in transaction NT_PRFPREG ptrace requests
   - Enable in transaction NT_PPC_VMX ptrace requests
   - Enable in transaction NT_PPC_VSX ptrace requests
   - Adapt gpr32_get, gpr32_set functions for transaction
   - Enable support for NT_PPC_CGPR
   - Enable support for NT_PPC_CFPR
   - Enable support for NT_PPC_CVMX
   - Enable support for NT_PPC_CVSX
   - Enable support for TM SPR state
   - Enable NT_PPC_TM_CTAR, NT_PPC_TM_CPPR, NT_PPC_TM_CDSCR
   - Enable support for NT_PPPC_TAR, NT_PPC_PPR, NT_PPC_DSCR
   - Enable support for EBB registers
   - Enable support for Performance Monitor registers"

* tag 'powerpc-4.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (48 commits)
  powerpc/mm: Move register_process_table() out of ppc_md
  powerpc/perf: Fix incorrect event codes in power9-event-list
  powerpc/32: Fix early access to cpu_spec relocation
  powerpc/ptrace: Enable support for Performance Monitor registers
  powerpc/ptrace: Enable support for EBB registers
  powerpc/ptrace: Enable support for NT_PPPC_TAR, NT_PPC_PPR, NT_PPC_DSCR
  powerpc/ptrace: Enable NT_PPC_TM_CTAR, NT_PPC_TM_CPPR, NT_PPC_TM_CDSCR
  powerpc/ptrace: Enable support for TM SPR state
  powerpc/ptrace: Enable support for NT_PPC_CVSX
  powerpc/ptrace: Enable support for NT_PPC_CVMX
  powerpc/ptrace: Enable support for NT_PPC_CFPR
  powerpc/ptrace: Enable support for NT_PPC_CGPR
  powerpc/ptrace: Adapt gpr32_get, gpr32_set functions for transaction
  powerpc/ptrace: Enable in transaction NT_PPC_VSX ptrace requests
  powerpc/ptrace: Enable in transaction NT_PPC_VMX ptrace requests
  powerpc/ptrace: Enable in transaction NT_PRFPREG ptrace requests
  powerpc/process: Add the function flush_tmregs_to_thread
  elf: Add powerpc specific core note sections
  powerpc/mm: remove flush_tlb_page_nohash
  powerpc/mm/hugetlb: Add flush_hugetlb_tlb_range
  ...

1  2 
arch/powerpc/include/asm/jump_label.h
arch/powerpc/include/asm/mman.h
arch/powerpc/kernel/exceptions-64s.S
arch/powerpc/kernel/idle_book3s.S
include/uapi/linux/elf.h
kernel/jump_label.c
mm/hugetlb.c

index 9af103a2397592013e43adb4c48cd4738c3e6867,9878cac7b47c14e9156f1ff12493c4d697c4634c..9a287e0ac8b16343e61ab9cc146957bfc4fb85b1
@@@ -14,7 -14,6 +14,7 @@@
  #include <linux/types.h>
  
  #include <asm/feature-fixups.h>
 +#include <asm/asm-compat.h>
  
  #define JUMP_ENTRY_TYPE               stringify_in_c(FTR_ENTRY_LONG)
  #define JUMP_LABEL_NOP_SIZE   4
@@@ -22,7 -21,7 +22,7 @@@
  static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  {
        asm_volatile_goto("1:\n\t"
-                "nop\n\t"
+                "nop # arch_static_branch\n\t"
                 ".pushsection __jump_table,  \"aw\"\n\t"
                 JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
                 ".popsection \n\t"
@@@ -36,7 -35,7 +36,7 @@@ l_yes
  static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  {
        asm_volatile_goto("1:\n\t"
-                "b %l[l_yes]\n\t"
+                "b %l[l_yes] # arch_static_branch_jump\n\t"
                 ".pushsection __jump_table,  \"aw\"\n\t"
                 JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
                 ".popsection \n\t"
index fc420cedecae59c6ee90579b67bf817bb2123491,ef2d9ac1bc5233dc72ee3e1ee480f5b173f5b20f..30922f699341bc3fdf57f51eff9921b058140697
@@@ -13,6 -13,7 +13,7 @@@
  
  #include <asm/cputable.h>
  #include <linux/mm.h>
+ #include <asm/cpu_has_feature.h>
  
  /*
   * This file is included by linux/mman.h, so we can't use cacl_vm_prot_bits()
@@@ -31,13 -32,13 +32,13 @@@ static inline pgprot_t arch_vm_get_page
  }
  #define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags)
  
 -static inline int arch_validate_prot(unsigned long prot)
 +static inline bool arch_validate_prot(unsigned long prot)
  {
        if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO))
 -              return 0;
 +              return false;
        if ((prot & PROT_SAO) && !cpu_has_feature(CPU_FTR_SAO))
 -              return 0;
 -      return 1;
 +              return false;
 +      return true;
  }
  #define arch_validate_prot(prot) arch_validate_prot(prot)
  
index 694def6c9d617818bf2a4cf4778a7648b0fb82f5,334c7fac7a4ae286bacaa743d2fd60f45f147db0..41091fdf9bd88fbe68d9ef15aeb04c1b59b18e77
@@@ -671,8 -671,6 +671,8 @@@ BEGIN_FTR_SECTIO
        beq     h_doorbell_common
        cmpwi   r3,0xea0
        beq     h_virt_irq_common
 +      cmpwi   r3,0xe60
 +      beq     hmi_exception_common
  FTR_SECTION_ELSE
        cmpwi   r3,0xa00
        beq     doorbell_super_common
@@@ -940,7 -938,7 +940,7 @@@ BEGIN_MMU_FTR_SECTIO
        b       do_hash_page            /* Try to handle as hpte fault */
  MMU_FTR_SECTION_ELSE
        b       handle_page_fault
- ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_RADIX)
+ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  
        .align  7
        .globl  h_data_storage_common
@@@ -971,7 -969,7 +971,7 @@@ BEGIN_MMU_FTR_SECTIO
        b       do_hash_page            /* Try to handle as hpte fault */
  MMU_FTR_SECTION_ELSE
        b       handle_page_fault
- ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_RADIX)
+ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  
        STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
  
@@@ -1174,7 -1172,7 +1174,7 @@@ fwnmi_data_area
  
        .globl hmi_exception_early
  hmi_exception_early:
 -      EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0xe60)
 +      EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST, 0xe62)
        mr      r10,r1                  /* Save r1                      */
        ld      r1,PACAEMERGSP(r13)     /* Use emergency stack          */
        subi    r1,r1,INT_FRAME_SIZE    /* alloc stack frame            */
@@@ -1392,7 -1390,7 +1392,7 @@@ slb_miss_realmode
  #ifdef CONFIG_PPC_STD_MMU_64
  BEGIN_MMU_FTR_SECTION
        bl      slb_allocate_realmode
- END_MMU_FTR_SECTION_IFCLR(MMU_FTR_RADIX)
+ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
  #endif
        /* All done -- return from exception. */
  
@@@ -1406,7 -1404,7 +1406,7 @@@ BEGIN_MMU_FTR_SECTIO
        beq-    2f
  FTR_SECTION_ELSE
        b       2f
- ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_RADIX)
+ ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  
  .machine      push
  .machine      "power4"
index 8a56a51fc0cbc08d5a011cfe4b91a503d0c41eb8,4c2222cffbbc80434b34dd22a234df741d2a785a..ba79d15f4ddd7c0d8ce946e15098d977a00338fa
@@@ -336,9 -336,7 +336,9 @@@ ALT_FTR_SECTION_END_NESTED_IFSET(CPU_FT
        ld      r2,PACATOC(r13);                                        \
        ld      r1,PACAR1(r13);                                         \
        std     r3,ORIG_GPR3(r1);       /* Save original r3 */          \
 -      bl      opal_rm_handle_hmi;                                     \
 +      li      r3,0;                   /* NULL argument */             \
 +      bl      hmi_exception_realmode;                                 \
 +      nop;                                                            \
        ld      r3,ORIG_GPR3(r1);       /* Restore original r3 */       \
  20:   nop;
  
@@@ -572,7 -570,7 +572,7 @@@ common_exit
  
  BEGIN_MMU_FTR_SECTION
        b       no_segments
- END_MMU_FTR_SECTION_IFSET(MMU_FTR_RADIX)
+ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
        /* Restore SLB  from PACA */
        ld      r8,PACA_SLBSHADOWPTR(r13)
  
diff --combined include/uapi/linux/elf.h
index 70b172ba41ce34ce846567a9e8f16aba53d6d166,1be3c5f6183b5754f157c1036d1e943c37c210e7..b59ee077a5964a888be764fdb5b817e3e377bcc0
@@@ -286,7 -286,6 +286,7 @@@ typedef struct elf64_phdr 
  #define SHF_ALLOC             0x2
  #define SHF_EXECINSTR         0x4
  #define SHF_RELA_LIVEPATCH    0x00100000
 +#define SHF_RO_AFTER_INIT     0x00200000
  #define SHF_MASKPROC          0xf0000000
  
  /* special section indexes */
@@@ -382,6 -381,19 +382,19 @@@ typedef struct elf64_shdr 
  #define NT_PPC_VMX    0x100           /* PowerPC Altivec/VMX registers */
  #define NT_PPC_SPE    0x101           /* PowerPC SPE/EVR registers */
  #define NT_PPC_VSX    0x102           /* PowerPC VSX registers */
+ #define NT_PPC_TAR    0x103           /* Target Address Register */
+ #define NT_PPC_PPR    0x104           /* Program Priority Register */
+ #define NT_PPC_DSCR   0x105           /* Data Stream Control Register */
+ #define NT_PPC_EBB    0x106           /* Event Based Branch Registers */
+ #define NT_PPC_PMU    0x107           /* Performance Monitor Registers */
+ #define NT_PPC_TM_CGPR        0x108           /* TM checkpointed GPR Registers */
+ #define NT_PPC_TM_CFPR        0x109           /* TM checkpointed FPR Registers */
+ #define NT_PPC_TM_CVMX        0x10a           /* TM checkpointed VMX Registers */
+ #define NT_PPC_TM_CVSX        0x10b           /* TM checkpointed VSX Registers */
+ #define NT_PPC_TM_SPR 0x10c           /* TM Special Purpose Registers */
+ #define NT_PPC_TM_CTAR        0x10d           /* TM checkpointed Target Address Register */
+ #define NT_PPC_TM_CPPR        0x10e           /* TM checkpointed Program Priority Register */
+ #define NT_PPC_TM_CDSCR       0x10f           /* TM checkpointed Data Stream Control Register */
  #define NT_386_TLS    0x200           /* i386 TLS slots (struct user_desc) */
  #define NT_386_IOPERM 0x201           /* x86 io permission bitmap (1=deny) */
  #define NT_X86_XSTATE 0x202           /* x86 extended state using xsave */
diff --combined kernel/jump_label.c
index 20400055f177cd9ab83748fd740a01036747df90,2d693be967dfdce869cfc24be918d7f65fe60831..93ad6c1fb9b6212e706eb3ae08f7b881192008ec
@@@ -14,7 -14,6 +14,7 @@@
  #include <linux/err.h>
  #include <linux/static_key.h>
  #include <linux/jump_label_ratelimit.h>
 +#include <linux/bug.h>
  
  #ifdef HAVE_JUMP_LABEL
  
@@@ -57,49 -56,6 +57,49 @@@ jump_label_sort_entries(struct jump_ent
  
  static void jump_label_update(struct static_key *key);
  
 +/*
 + * There are similar definitions for the !HAVE_JUMP_LABEL case in jump_label.h.
 + * The use of 'atomic_read()' requires atomic.h and its problematic for some
 + * kernel headers such as kernel.h and others. Since static_key_count() is not
 + * used in the branch statements as it is for the !HAVE_JUMP_LABEL case its ok
 + * to have it be a function here. Similarly, for 'static_key_enable()' and
 + * 'static_key_disable()', which require bug.h. This should allow jump_label.h
 + * to be included from most/all places for HAVE_JUMP_LABEL.
 + */
 +int static_key_count(struct static_key *key)
 +{
 +      /*
 +       * -1 means the first static_key_slow_inc() is in progress.
 +       *  static_key_enabled() must return true, so return 1 here.
 +       */
 +      int n = atomic_read(&key->enabled);
 +
 +      return n >= 0 ? n : 1;
 +}
 +EXPORT_SYMBOL_GPL(static_key_count);
 +
 +void static_key_enable(struct static_key *key)
 +{
 +      int count = static_key_count(key);
 +
 +      WARN_ON_ONCE(count < 0 || count > 1);
 +
 +      if (!count)
 +              static_key_slow_inc(key);
 +}
 +EXPORT_SYMBOL_GPL(static_key_enable);
 +
 +void static_key_disable(struct static_key *key)
 +{
 +      int count = static_key_count(key);
 +
 +      WARN_ON_ONCE(count < 0 || count > 1);
 +
 +      if (count)
 +              static_key_slow_dec(key);
 +}
 +EXPORT_SYMBOL_GPL(static_key_disable);
 +
  void static_key_slow_inc(struct static_key *key)
  {
        int v, v1;
@@@ -279,15 -235,9 +279,18 @@@ void __init jump_label_init(void
        struct static_key *key = NULL;
        struct jump_entry *iter;
  
 +      /*
 +       * Since we are initializing the static_key.enabled field with
 +       * with the 'raw' int values (to avoid pulling in atomic.h) in
 +       * jump_label.h, let's make sure that is safe. There are only two
 +       * cases to check since we initialize to 0 or 1.
 +       */
 +      BUILD_BUG_ON((int)ATOMIC_INIT(0) != 0);
 +      BUILD_BUG_ON((int)ATOMIC_INIT(1) != 1);
 +
+       if (static_key_initialized)
+               return;
        jump_label_lock();
        jump_label_sort_entries(iter_start, iter_stop);
  
@@@ -337,14 -287,11 +340,14 @@@ static int __jump_label_mod_text_reserv
  {
        struct module *mod;
  
 +      preempt_disable();
        mod = __module_text_address((unsigned long)start);
 +      WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
 +      preempt_enable();
 +
        if (!mod)
                return 0;
  
 -      WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
  
        return __jump_label_text_reserved(mod->jump_entries,
                                mod->jump_entries + mod->num_jump_entries,
diff --combined mm/hugetlb.c
index ef968306fd5b8bc4cd9b06f402595d041f81a26f,af2d88253bfcb0a9377dc2a80b21d30c0c3ba92c..b9aa1b0b38b0ecdb769cd33a8d77c0ffda2621bf
@@@ -2216,10 -2216,6 +2216,10 @@@ static unsigned long set_max_huge_pages
                 * and reducing the surplus.
                 */
                spin_unlock(&hugetlb_lock);
 +
 +              /* yield cpu to avoid soft lockup */
 +              cond_resched();
 +
                if (hstate_is_gigantic(h))
                        ret = alloc_fresh_gigantic_page(h, nodes_allowed);
                else
@@@ -3942,6 -3938,14 +3942,14 @@@ same_page
        return i ? i : -EFAULT;
  }
  
+ #ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE
+ /*
+  * ARCHes with special requirements for evicting HUGETLB backing TLB entries can
+  * implement this.
+  */
+ #define flush_hugetlb_tlb_range(vma, addr, end)       flush_tlb_range(vma, addr, end)
+ #endif
  unsigned long hugetlb_change_protection(struct vm_area_struct *vma,
                unsigned long address, unsigned long end, pgprot_t newprot)
  {
         * once we release i_mmap_rwsem, another task can do the final put_page
         * and that page table be reused and filled with junk.
         */
-       flush_tlb_range(vma, start, end);
+       flush_hugetlb_tlb_range(vma, start, end);
        mmu_notifier_invalidate_range(mm, start, end);
        i_mmap_unlock_write(vma->vm_file->f_mapping);
        mmu_notifier_invalidate_range_end(mm, start, end);
@@@ -4310,7 -4314,7 +4318,7 @@@ pte_t *huge_pte_alloc(struct mm_struct 
                                pte = (pte_t *)pmd_alloc(mm, pud, addr);
                }
        }
 -      BUG_ON(pte && !pte_none(*pte) && !pte_huge(*pte));
 +      BUG_ON(pte && pte_present(*pte) && !pte_huge(*pte));
  
        return pte;
  }