1. 23 Dec, 2018 5 commits
  2. 20 Dec, 2018 1 commit
    • Paul Burton's avatar
      MIPS: math-emu: Write-protect delay slot emulation pages · adcc81f1
      Paul Burton authored
      Mapping the delay slot emulation page as both writeable & executable
      presents a security risk, in that if an exploit can write to & jump into
      the page then it can be used as an easy way to execute arbitrary code.
      
      Prevent this by mapping the page read-only for userland, and using
      access_process_vm() with the FOLL_FORCE flag to write to it from
      mips_dsemul().
      
      This will likely be less efficient due to copy_to_user_page() performing
      cache maintenance on a whole page, rather than a single line as in the
      previous use of flush_cache_sigtramp(). However this delay slot
      emulation code ought not to be running in any performance critical paths
      anyway so this isn't really a problem, and we can probably do better in
      copy_to_user_page() anyway in future.
      
      A major advantage of this approach is that the fix is small & simple to
      backport to stable kernels.
      Reported-by: default avatarAndy Lutomirski <luto@kernel.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Fixes: 432c6bac ("MIPS: Use per-mm page to execute branch delay slot instructions")
      Cc: stable@vger.kernel.org # v4.8+
      Cc: linux-mips@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Cc: Rich Felker <dalias@libc.org>
      Cc: David Daney <david.daney@cavium.com>
      adcc81f1
  3. 18 Dec, 2018 1 commit
  4. 14 Dec, 2018 6 commits
    • Firoz Khan's avatar
      mips: generate uapi header and system call table files · 99bf73eb
      Firoz Khan authored
      System call table generation script must be run to gener-
      ate unistd_(nr_)n64/n32/o32.h and syscall_table_32_o32/
      64_n64/64_n32/64-o32.h files. This patch will have changes
      which will invokes the script.
      
      This patch will generate unistd_(nr_)n64/n32/o32.h and
      syscall_table_32_o32/64_n64/64-n32/64-o32.h files by the
      syscall table generation script invoked by parisc/Make-
      file and the generated files against the removed files
      must be identical.
      
      The generated uapi header file will be included in uapi/-
      asm/unistd.h and generated system call table header file
      will be included by kernel/scall32-o32/64-n64/64-n32/-
      64-o32.Sfile.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      99bf73eb
    • Firoz Khan's avatar
      mips: add system call table generation support · 9bcbf97c
      Firoz Khan authored
      The system call tables are in different format in all
      architecture and it will be difficult to manually add,
      modify or delete the syscall table entries in the res-
      pective files. To make it easy by keeping a script and
      which will generate the uapi header and syscall table
      file. This change will also help to unify the implemen-
      tation across all architectures.
      
      The system call table generation script is added in
      kernel/syscalls directory which contain the scripts to
      generate both uapi header file and system call table
      files. The syscall.tbl will be input for the scripts.
      
      syscall.tbl contains the list of available system calls
      along with system call number and corresponding entry
      point. Add a new system call in this architecture will
      be possible by adding new entry in the syscall.tbl file.
      
      Adding a new table entry consisting of:
        	- System call number.
      	- ABI.
      	- System call name.
      	- Entry point name.
      	- Compat entry name, if required.
      
      syscallhdr.sh, syscallnr.sh and syscalltbl.sh will gene-
      rate uapi header unistd_n64/n32/o32.h, unistd_nr_n64/n32/-
      o32.h and syscall_table_32_o32/64_n64/64-n32/64-o32.h files
      respectively. All *.sh files will parse the content sys-
      call.tbl to generate the header and table files. unistd-
      _n64/n32/o32.h and unistd_nr_n64/n32/o32.h will be included
      by uapi/asm/unistd.h and syscall_table_32_o32/64_n64/64-n32-
      /64-o32.h is included by kernel/syscall_table32_o32/64-
      _n64/64-n32/64-o32.S - the real system call table.
      
      ARM, s390 and x86 architecuture does have similar support.
      I leverage their implementation to come up with a generic
      solution.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      [paul.burton@mips.com:
       - Change sysnr_pfx_unistd_nr_n64 to 64.]
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      9bcbf97c
    • Firoz Khan's avatar
      mips: remove syscall table entries · 6a00cb61
      Firoz Khan authored
      The config flag - CONFIG_MIPS_MT_FPAFF uses to check whether which
      syscall entries need to be used in scall32-o32.S file.
      
      One of the patch in this patch series will generate syscall table
      file. But CONFIG_MIPS_MT_FPAFF flag will add more complexity in the
      script to generate the syscall table file.
      
      In order to come up with a common implementation across all archit-
      ecture, we need to remove mipsmt_sys_sched_setaffinity and mipsmt-
      _sys_sched_getaffinity from the table and define it in other way.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      6a00cb61
    • Firoz Khan's avatar
      mips: add +1 to __NR_syscalls in uapi header · be856439
      Firoz Khan authored
      All other architectures are hold a value for __NR_syscalls will
      be equal to the last system call number +1.
      
      But in mips architecture, __NR_syscalls hold the value equal to
      total number of system exits in the architecture. One of the
      patch in this patch series will genarate uapi header files.
      
      In order to make the implementation common across all architect-
      ures, add +1 to __NR_syscalls, which will be equal to the last
      system call number +1.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      be856439
    • Firoz Khan's avatar
      mips: rename scall64-64.S to scall64-n64.S · 6d92c268
      Firoz Khan authored
      When we get nanoMIPS support we'll be introducing the p32
      ABI, and there's a reasonable chance that the equivalent
      p64 ABI may come along in the future. Using 'n64' now would
      avoid confusion in that case where we may have 2 different
      64-bit ABIs.
      Suggested-by: default avatarPaul Burton <paul.burton@mips.com>
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      [paul.burton@mips.com:
        - Remove UAPI macro renaming, github code search shows at least the
          chromium project uses __NR_64_Linux & __NR_64_Linux_syscalls.]
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      6d92c268
    • Firoz Khan's avatar
      mips: remove unused macros · a5ee2be9
      Firoz Khan authored
      Remove __NR_Linux_syscalls from uapi/asm/unistd.h as
      there is no users to use NR_syscalls macro in mips
      kernel.
      
      MAX_SYSCALL_NO can also remove as there is commit
      2957c9e6 ("[MIPS] IRIX: Goodbye and thanks for
      all the fish"), eight years ago.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      [paul.burton@mips.com:
       - Drop the removal of NR_syscalls which is used by
         kernel/trace/trace.h.]
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      a5ee2be9
  5. 13 Dec, 2018 1 commit
    • Firoz Khan's avatar
      mips: add __NR_syscalls along with __NR_Linux_syscalls · ef2512c8
      Firoz Khan authored
      __NR_Linux_syscalls macro holds the number of system call
      exist in mips architecture. We have to change the value of
      __NR_Linux_syscalls, if we add or delete a system call.
      
      One of the patch in this patch series has a script which
      will generate a uapi header based on syscall.tbl file.
      The syscall.tbl file contains the total number of system
      calls information. So we have two option to update __NR-
      _Linux_syscalls value.
      
      1. Update __NR_Linux_syscalls in asm/unistd.h manually
         by counting the no.of system calls. No need to update
         __NR_Linux_syscalls until we either add a new system
         call or delete existing system call.
      
      2. We can keep this feature it above mentioned script,
         that will count the number of syscalls and keep it in
         a generated file. In this case we don't need to expli-
         citly update __NR_Linux_syscalls in asm/unistd.h file.
      
      The 2nd option will be the recommended one. For that, I
      added the __NR_syscalls macro in uapi/asm/unistd.h along
      with __NR_Linux_syscalls. The macro __NR_syscalls also
      added for making the name convention same across all
      architecture. While __NR_syscalls isn't strictly part of
      the uapi, having it as part of the generated header to
      simplifies the implementation. We also need to enclose
      this macro with #ifdef __KERNEL__ to avoid side effects.
      Signed-off-by: default avatarFiroz Khan <firoz.khan@linaro.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: linux-mips@vger.kernel.org
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: y2038@lists.linaro.org
      Cc: linux-kernel@vger.kernel.org
      Cc: linux-arch@vger.kernel.org
      Cc: arnd@arndb.de
      Cc: deepa.kernel@gmail.com
      Cc: marcin.juszkiewicz@linaro.org
      ef2512c8
  6. 05 Dec, 2018 1 commit
    • Paul Burton's avatar
      MIPS: Expand MIPS32 ASIDs to 64 bits · ff4dd232
      Paul Burton authored
      ASIDs have always been stored as unsigned longs, ie. 32 bits on MIPS32
      kernels. This is problematic because it is feasible for the ASID version
      to overflow & wrap around to zero.
      
      We currently attempt to handle this overflow by simply setting the ASID
      version to 1, using asid_first_version(), but we make no attempt to
      account for the fact that there may be mm_structs with stale ASIDs that
      have versions which we now reuse due to the overflow & wrap around.
      
      Encountering this requires that:
      
        1) A struct mm_struct X is active on CPU A using ASID (V,n).
      
        2) That mm is not used on CPU A for the length of time that it takes
           for CPU A's asid_cache to overflow & wrap around to the same
           version V that the mm had in step 1. During this time tasks using
           the mm could either be sleeping or only scheduled on other CPUs.
      
        3) Some other mm Y becomes active on CPU A and is allocated the same
           ASID (V,n).
      
        4) mm X now becomes active on CPU A again, and now incorrectly has the
           same ASID as mm Y.
      
      Where struct mm_struct ASIDs are represented above in the format
      (version, EntryHi.ASID), and on a typical MIPS32 system version will be
      24 bits wide & EntryHi.ASID will be 8 bits wide.
      
      The length of time required in step 2 is highly dependent upon the CPU &
      workload, but for a hypothetical 2GHz CPU running a workload which
      generates a new ASID every 10000 cycles this period is around 248 days.
      Due to this long period of time & the fact that tasks need to be
      scheduled in just the right (or wrong, depending upon your inclination)
      way, this is obviously a difficult bug to encounter but it's entirely
      possible as evidenced by reports.
      
      In order to fix this, simply extend ASIDs to 64 bits even on MIPS32
      builds. This will extend the period of time required for the
      hypothetical system above to encounter the problem from 28 days to
      around 3 trillion years, which feels safely outside of the realms of
      possibility.
      
      The cost of this is slightly more generated code in some commonly
      executed paths, but this is pretty minimal:
      
                               | Code Size Gain | Percentage
        -----------------------|----------------|-------------
          decstation_defconfig |           +270 | +0.00%
              32r2el_defconfig |           +652 | +0.01%
              32r6el_defconfig |          +1000 | +0.01%
      
      I have been unable to measure any change in performance of the LMbench
      lat_ctx or lat_proc tests resulting from the 64b ASIDs on either
      32r2el_defconfig+interAptiv or 32r6el_defconfig+I6500 systems.
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Suggested-by: default avatarJames Hogan <jhogan@kernel.org>
      References: https://lore.kernel.org/linux-mips/80B78A8B8FEE6145A87579E8435D78C30205D5F3@fzex.ruijie.com.cn/
      References: https://lore.kernel.org/linux-mips/1488684260-18867-1-git-send-email-jiwei.sun@windriver.com/
      Cc: Jiwei Sun <jiwei.sun@windriver.com>
      Cc: Yu Huabing <yhb@ruijie.com.cn>
      Cc: stable@vger.kernel.org # 2.6.12+
      Cc: linux-mips@vger.kernel.org
      ff4dd232
  7. 04 Dec, 2018 6 commits
  8. 03 Dec, 2018 1 commit
    • Mathieu Malaterre's avatar
      mips: annotate implicit fall throughs · 69095e39
      Mathieu Malaterre authored
      There is a plan to build the kernel with -Wimplicit-fallthrough and
      these places in the code produced warnings. Fix them up.
      
      This patch produces no change in behaviour, but should be reviewed in
      case these are actually bugs not intentional fallthoughs.
      Signed-off-by: default avatarMathieu Malaterre <malat@debian.org>
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Cc: Kees Cook <keescook@google.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: linux-mips@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      69095e39
  9. 27 Nov, 2018 2 commits
  10. 22 Nov, 2018 1 commit
    • Paul Burton's avatar
      MIPS: Only include mmzone.h when CONFIG_NEED_MULTIPLE_NODES=y · 66a4059b
      Paul Burton authored
      MIPS' asm/mmzone.h includes the machine/platform mmzone.h
      unconditionally, but since commit bb53fdf3 ("MIPS: c-r4k: Add
      r4k_blast_scache_node for Loongson-3") is included by asm/rk4cache.h for
      all r4k-style configs regardless of CONFIG_NEED_MULTIPLE_NODES.
      
      This is problematic when CONFIG_NEED_MULTIPLE_NODES=n because both the
      loongson3 & ip27 mmzone.h headers unconditionally define the NODE_DATA
      preprocessor macro which is aready defined by linux/mmzone.h, resulting
      in the following build error:
      
        In file included from ./arch/mips/include/asm/mmzone.h:10,
                         from ./arch/mips/include/asm/r4kcache.h:23,
                         from arch/mips/mm/c-r4k.c:33:
        ./arch/mips/include/asm/mach-loongson64/mmzone.h:48: error: "NODE_DATA" redefined [-Werror]
         #define NODE_DATA(n)  (&__node_data[(n)]->pglist)
      
        In file included from ./include/linux/topology.h:32,
                         from ./include/linux/irq.h:19,
                         from ./include/asm-generic/hardirq.h:13,
                         from ./arch/mips/include/asm/hardirq.h:16,
                         from ./include/linux/hardirq.h:9,
                         from arch/mips/mm/c-r4k.c:11:
        ./include/linux/mmzone.h:907: note: this is the location of the previous definition
         #define NODE_DATA(nid)  (&contig_page_data)
      
      Resolve this by only including the machine mmzone.h when
      CONFIG_NEED_MULTIPLE_NODES=y, which also removes the need for the empty
      mach-generic version of the header which we delete.
      Signed-off-by: default avatarPaul Burton <paul.burton@mips.com>
      Fixes: bb53fdf3 ("MIPS: c-r4k: Add r4k_blast_scache_node for Loongson-3")
      66a4059b
  11. 21 Nov, 2018 15 commits