1. 08 8月, 2017 2 次提交
    • M
      MIPS: PCI: Fix smp_processor_id() in preemptible · 73530266
      Matt Redfearn 提交于
      Commit 1c3c5eab ("sched/core: Enable might_sleep() and
      smp_processor_id() checks early") enables checks for might_sleep() and
      smp_processor_id() being used in preemptible code earlier in the boot
      than before. This results in a new BUG from
      pcibios_set_cache_line_size().
      
      BUG: using smp_processor_id() in preemptible [00000000] code:
      swapper/0/1 caller is pcibios_set_cache_line_size+0x10/0x70
      CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.13.0-rc1-00007-g3ce3e4ba4275 #615
      Stack: 0000000000000000 ffffffff81189694 0000000000000000 ffffffff81822318
             000000000000004e 0000000000000001 800000000e20bd08 20c49ba5e3540000
             0000000000000000 0000000000000000 ffffffff818d0000 0000000000000000
             0000000000000000 ffffffff81189328 ffffffff818ce692 0000000000000000
             0000000000000000 ffffffff81189bc8 ffffffff818d0000 0000000000000000
             ffffffff81828907 ffffffff81769970 800000020ec78d80 ffffffff818c7b48
             0000000000000001 0000000000000001 ffffffff818652b0 ffffffff81896268
             ffffffff818c0000 800000020ec7fb40 800000020ec7fc58 ffffffff81684cac
             0000000000000000 ffffffff8118ab50 0000000000000030 ffffffff81769970
             0000000000000001 ffffffff81122a58 0000000000000000 0000000000000000 ...
      Call Trace:
      [<ffffffff81122a58>] show_stack+0x90/0xb0
      [<ffffffff81684cac>] dump_stack+0xac/0xf0
      [<ffffffff813f7050>] check_preemption_disabled+0x120/0x128
      [<ffffffff818855e8>] pcibios_set_cache_line_size+0x10/0x70
      [<ffffffff81100578>] do_one_initcall+0x48/0x140
      [<ffffffff81865dc4>] kernel_init_freeable+0x194/0x24c
      [<ffffffff8169c534>] kernel_init+0x14/0x118
      [<ffffffff8111ca84>] ret_from_kernel_thread+0x14/0x1c
      
      Fix this by using the cpu_*cache_line_size() macros instead. These
      macros are the "proper" way to determine the CPU cache sizes.
      This makes use of the newly added cpu_tcache_line_size.
      
      Fixes: 1c3c5eab ("sched/core: Enable might_sleep() and smp_processor_id() checks early")
      Signed-off-by: NMatt Redfearn <matt.redfearn@imgtec.com>
      Suggested-by: NJames Hogan <james.hogan@imgtec.com>
      Reviewed-by: NJames Hogan <james.hogan@imgtec.com>
      Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      73530266
    • M
      MIPS: Introduce cpu_tcache_line_size · 21da5332
      Matt Redfearn 提交于
      There exist macros to return the cache line size of the L1 dcache and L2
      scache but there is currently no macro for the L3 tcache. Add this macro
      which will be used by the following patch "MIPS: PCI: Fix
      smp_processor_id() in preemptible"
      Signed-off-by: NMatt Redfearn <matt.redfearn@imgtec.com>
      Cc: Maciej W. Rozycki <macro@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16871/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      21da5332
  2. 07 8月, 2017 8 次提交
  3. 20 7月, 2017 1 次提交
  4. 19 7月, 2017 2 次提交
    • H
      MIPS: ralink: mt7620: Add missing header · f13343e8
      Harvey Hunt 提交于
      Fix a build error caused by not including <linux/bug.h>.
      
      The following compilation errors are caused by the missing header:
      
      arch/mips/ralink/mt7620.c: In function ‘mt7620_get_cpu_pll_rate’:
      arch/mips/ralink/mt7620.c:431:2: error: implicit declaration of function ‘WARN_ON’ [-Werror=implicit-function-declaration]
        WARN_ON(div >= ARRAY_SIZE(mt7620_clk_divider));
        ^
      arch/mips/ralink/mt7620.c: In function ‘mt7620_get_sys_rate’:
      arch/mips/ralink/mt7620.c:500:2: error: implicit declaration of function ‘WARN’ [-Werror=implicit-function-declaration]
        if (WARN(!div, "invalid divider for OCP ratio %u", ocp_ratio))
        ^
      arch/mips/ralink/mt7620.c: In function ‘mt7620_dram_init’:
      arch/mips/ralink/mt7620.c:619:3: error: implicit declaration of function ‘BUG’ [-Werror=implicit-function-declaration]
         BUG();
         ^
      cc1: some warnings being treated as errors
      scripts/Makefile.build:302: recipe for target 'arch/mips/ralink/mt7620.o' failed
      Signed-off-by: NHarvey Hunt <harvey.hunt@imgtec.com>
      Cc: John Crispin <john@phrozen.org>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16781/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      f13343e8
    • H
      MIPS: ralink: Fix build error due to missing header · e3ccf1d1
      Harvey Hunt 提交于
      Previously, <linux/module.h> was included before ralink_regs.h in all
      ralink files - leading to <linux/io.h> being implicitly included.
      
      After commit 26dd3e4f ("MIPS: Audit and remove any unnecessary
      uses of module.h") removed the inclusion of module.h from multiple
      places, some ralink platforms failed to build with the following error:
      
      In file included from arch/mips/ralink/mt7620.c:17:0:
      ./arch/mips/include/asm/mach-ralink/ralink_regs.h: In function ‘rt_sysc_w32’:
      ./arch/mips/include/asm/mach-ralink/ralink_regs.h:38:2: error: implicit declaration of function ‘__raw_writel’ [-Werror=implicit-function-declaration]
        __raw_writel(val, rt_sysc_membase + reg);
        ^
      ./arch/mips/include/asm/mach-ralink/ralink_regs.h: In function ‘rt_sysc_r32’:
      ./arch/mips/include/asm/mach-ralink/ralink_regs.h:43:2: error: implicit declaration of function ‘__raw_readl’ [-Werror=implicit-function-declaration]
        return __raw_readl(rt_sysc_membase + reg);
      
      Fix this by including <linux/io.h>.
      Signed-off-by: NHarvey Hunt <harvey.hunt@imgtec.com>
      Fixes: 26dd3e4f ("MIPS: Audit and remove any unnecessary uses of module.h")
      Cc: John Crispin <john@phrozen.org>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Cc: <stable@vger.kernel.org> #4.11+
      Patchwork: https://patchwork.linux-mips.org/patch/16780/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      e3ccf1d1
  5. 17 7月, 2017 1 次提交
  6. 13 7月, 2017 2 次提交
    • J
      MIPS: SMP: move asmlinkage before return type · b745fcb9
      Joe Perches 提交于
      Make the code like the rest of the kernel.
      
      Link: http://lkml.kernel.org/r/756d3fb543e981b9284e756fa27616725a354b28.1499284835.git.joe@perches.comSigned-off-by: NJoe Perches <joe@perches.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b745fcb9
    • M
      MIPS: do not use __GFP_REPEAT for order-0 request · 473738eb
      Michal Hocko 提交于
      Patch series "mm: give __GFP_REPEAT a better semantic".
      
      The main motivation for the change is that the current implementation of
      __GFP_REPEAT is not very much useful.
      
      The documentation says:
       * __GFP_REPEAT: Try hard to allocate the memory, but the allocation attempt
       *   _might_ fail.  This depends upon the particular VM implementation.
      
      It just fails to mention that this is true only for large (costly) high
      order which has been the case since the flag was introduced.  A similar
      semantic would be really helpful for smal orders as well, though,
      because we have places where a failure with a specific fallback error
      handling is preferred to a potential endless loop inside the page
      allocator.
      
      The earlier cleanup dropped __GFP_REPEAT usage for low (!costly) order
      users so only those which might use larger orders have stayed.  One new
      user added in the meantime is addressed in patch 1.
      
      Let's rename the flag to something more verbose and use it for existing
      users.  Semantic for those will not change.  Then implement low
      (!costly) orders failure path which is hit after the page allocator is
      about to invoke the oom killer.  With that we have a good counterpart
      for __GFP_NORETRY and finally can tell try as hard as possible without
      the OOM killer.
      
      Xfs code already has an existing annotation for allocations which are
      allowed to fail and we can trivially map them to the new gfp flag
      because it will provide the semantic KM_MAYFAIL wants.  Christoph didn't
      consider the new flag really necessary but didn't respond to the OOM
      killer aspect of the change so I have kept the patch.  If this is still
      seen as not really needed I can drop the patch.
      
      kvmalloc will allow also !costly high order allocations to retry hard
      before falling back to the vmalloc.
      
      drm/i915 asked for the new semantic explicitly.
      
      Memory migration code, especially for the memory hotplug, should back
      off rather than invoking the OOM killer as well.
      
      This patch (of 6):
      
      Commit 3377e227 ("MIPS: Add 48-bit VA space (and 4-level page
      tables) for 4K pages.") has added a new __GFP_REPEAT user but using this
      flag doesn't really make any sense for order-0 request which is the case
      here because PUD_ORDER is 0.  __GFP_REPEAT has historically effect only
      on allocation requests with order > PAGE_ALLOC_COSTLY_ORDER.
      
      This doesn't introduce any functional change.  This is a preparatory
      patch for later work which renames the flag and redefines its semantic.
      
      Link: http://lkml.kernel.org/r/20170623085345.11304-2-mhocko@kernel.orgSigned-off-by: NMichal Hocko <mhocko@suse.com>
      Acked-by: NVlastimil Babka <vbabka@suse.cz>
      Cc: Alex Belits <alex.belits@cavium.com>
      Cc: David Daney <david.daney@cavium.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: NeilBrown <neilb@suse.com>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Darrick J. Wong <darrick.wong@oracle.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      473738eb
  7. 11 7月, 2017 11 次提交
  8. 07 7月, 2017 1 次提交
    • P
      mm/hugetlb: add size parameter to huge_pte_offset() · 7868a208
      Punit Agrawal 提交于
      A poisoned or migrated hugepage is stored as a swap entry in the page
      tables.  On architectures that support hugepages consisting of
      contiguous page table entries (such as on arm64) this leads to ambiguity
      in determining the page table entry to return in huge_pte_offset() when
      a poisoned entry is encountered.
      
      Let's remove the ambiguity by adding a size parameter to convey
      additional information about the requested address.  Also fixup the
      definition/usage of huge_pte_offset() throughout the tree.
      
      Link: http://lkml.kernel.org/r/20170522133604.11392-4-punit.agrawal@arm.comSigned-off-by: NPunit Agrawal <punit.agrawal@arm.com>
      Acked-by: NSteve Capper <steve.capper@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: James Hogan <james.hogan@imgtec.com> (odd fixer:METAG ARCHITECTURE)
      Cc: Ralf Baechle <ralf@linux-mips.org> (supporter:MIPS)
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Cc: Rich Felker <dalias@libc.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Kravetz <mike.kravetz@oracle.com>
      Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
      Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
      Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
      Cc: Hillf Danton <hillf.zj@alibaba-inc.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7868a208
  9. 05 7月, 2017 2 次提交
    • M
      MIPS: MIPS16e2: Subdecode extended LWSP/SWSP instructions · f3235d32
      Maciej W. Rozycki 提交于
      Implement extended LWSP/SWSP instruction subdecoding for the purpose of
      unaligned GP-relative memory access emulation.
      
      With the introduction of the MIPS16e2 ASE[1] the previously must-be-zero
      3-bit field at bits 7..5 of the extended encodings of the instructions
      selected with the LWSP and SWSP major opcodes has become a `sel' field,
      acting as an opcode extension for additional operations.  In both cases
      the `sel' value of 0 has retained the original operation, that is:
      
      	LW	rx, offset(sp)
      
      and:
      
      	SW	rx, offset(sp)
      
      for LWSP and SWSP respectively.  In hardware predating the MIPS16e2 ASE
      other values may or may not have been decoded, architecturally yielding
      unpredictable results, and in our unaligned memory access emulation we
      have treated the 3-bit field as a don't-care, that is effectively making
      all the possible encodings of the field alias to the architecturally
      defined encoding of 0.
      
      For the non-zero values of the `sel' field the MIPS16e2 ASE has in
      particular defined these GP-relative operations:
      
      	LW	rx, offset(gp)		# sel = 1
      	LH	rx, offset(gp)		# sel = 2
      	LHU	rx, offset(gp)		# sel = 4
      
      and
      
      	SW	rx, offset(gp)		# sel = 1
      	SH	rx, offset(gp)		# sel = 2
      
      for LWSP and SWSP respectively, which will trap with an Address Error
      exception if the effective address calculated is not naturally-aligned
      for the operation requested.  These operations have been selected for
      unaligned access emulation, for consistency with the corresponding
      regular MIPS and microMIPS operations.
      
      For other non-zero values of the `sel' field the MIPS16e2 ASE has
      defined further operations, which however either never trap with an
      Address Error exception, such as LWL or GP-relative SB, or are not
      supposed to be emulated, such as LL or SC.  These operations have been
      selected to exclude from unaligned access emulation, should an Address
      Error exception ever happen with them.
      
      Subdecode the `sel' field in unaligned access emulation then for the
      extended encodings of the instructions selected with the LWSP and SWSP
      major opcodes, whenever support for the MIPS16e2 ASE has been detected
      in hardware, and either emulate the operation requested or send SIGBUS
      to the originating process, according to the selection described above.
      For hardware implementing the MIPS16 ASE, however lacking MIPS16e2 ASE
      support retain the original interpretation of the `sel' field.
      
      The effects of this change are illustrated with the following user
      program:
      
      $ cat mips16e2-test.c
      #include <inttypes.h>
      #include <stdio.h>
      
      int main(void)
      {
      	int64_t scratch[16] = { 0 };
      	int32_t *tmp0, *tmp1, *tmp2;
      	int i;
      
      	scratch[0] = 0xc8c7c6c5c4c3c2c1;
      	scratch[1] = 0xd0cfcecdcccbcac9;
      
      	asm volatile(
      		"move	%0, $sp\n\t"
      		"move	%1, $gp\n\t"
      		"move	$sp, %4\n\t"
      		"addiu	%2, %4, 8\n\t"
      		"move	$gp, %2\n\t"
      
      		"lw	%2, 2($sp)\n\t"
      		"sw	%2, 16(%4)\n\t"
      		"lw	%2, 2($gp)\n\t"
      		"sw	%2, 24(%4)\n\t"
      
      		"lw	%2, 1($sp)\n\t"
      		"sw	%2, 32(%4)\n\t"
      		"lh	%2, 1($gp)\n\t"
      		"sw	%2, 40(%4)\n\t"
      
      		"lw	%2, 3($sp)\n\t"
      		"sw	%2, 48(%4)\n\t"
      		"lhu	%2, 3($gp)\n\t"
      		"sw	%2, 56(%4)\n\t"
      
      		"lw	%2, 0(%4)\n\t"
      		"sw	%2, 66($sp)\n\t"
      		"lw	%2, 8(%4)\n\t"
      		"sw	%2, 82($gp)\n\t"
      
      		"lw	%2, 0(%4)\n\t"
      		"sw	%2, 97($sp)\n\t"
      		"lw	%2, 8(%4)\n\t"
      		"sh	%2, 113($gp)\n\t"
      
      		"move	$gp, %1\n\t"
      		"move	$sp, %0"
      		: "=&d" (tmp0), "=&d" (tmp1), "=&d" (tmp2), "=m" (scratch)
      		: "d" (scratch));
      
      	for (i = 0; i < sizeof(scratch) / sizeof(*scratch); i += 2)
      		printf("%016" PRIx64 "\t%016" PRIx64 "\n",
      		       scratch[i], scratch[i + 1]);
      
      	return 0;
      }
      $
      
      to be compiled with:
      
      $ gcc -mips16 -mips32r2 -Wa,-mmips16e2 -o mips16e2-test mips16e2-test.c
      $
      
      With 74Kf hardware, which does not implement the MIPS16e2 ASE, this
      program produces the following output:
      
      $ ./mips16e2-test
      c8c7c6c5c4c3c2c1        d0cfcecdcccbcac9
      00000000c6c5c4c3        00000000c6c5c4c3
      00000000c5c4c3c2        00000000c5c4c3c2
      00000000c7c6c5c4        00000000c7c6c5c4
      0000c4c3c2c10000        0000000000000000
      0000cccbcac90000        0000000000000000
      000000c4c3c2c100        0000000000000000
      000000cccbcac900        0000000000000000
      $
      
      regardless of whether the change has been applied or not.
      
      With the change not applied and interAptive MR2 hardware[2], which does
      implement the MIPS16e2 ASE, it produces the following output:
      
      $ ./mips16e2-test
      c8c7c6c5c4c3c2c1        d0cfcecdcccbcac9
      00000000c6c5c4c3        00000000cecdcccb
      00000000c5c4c3c2        00000000cdcccbca
      00000000c7c6c5c4        00000000cfcecdcc
      0000c4c3c2c10000        0000000000000000
      0000000000000000        0000cccbcac90000
      000000c4c3c2c100        0000000000000000
      0000000000000000        000000cccbcac900
      $
      
      which shows that for GP-relative operations the correct trapping address
      calculated from $gp has been obtained from the CP0 BadVAddr register and
      so has data from the source operand, however masking and extension has
      not been applied for halfword operations.
      
      With the change applied and interAptive MR2 hardware the program
      produces the following output:
      
      $ ./mips16e2-test
      c8c7c6c5c4c3c2c1        d0cfcecdcccbcac9
      00000000c6c5c4c3        00000000cecdcccb
      00000000c5c4c3c2        00000000ffffcbca
      00000000c7c6c5c4        000000000000cdcc
      0000c4c3c2c10000        0000000000000000
      0000000000000000        0000cccbcac90000
      000000c4c3c2c100        0000000000000000
      0000000000000000        0000000000cac900
      $
      
      as expected.
      
      References:
      
      [1] "MIPS32 Architecture for Programmers: MIPS16e2 Application-Specific
          Extension Technical Reference Manual", Imagination Technologies
          Ltd., Document Number: MD01172, Revision 01.00, April 26, 2016
      
      [2] "MIPS32 interAptiv Multiprocessing System Software User's Manual",
          Imagination Technologies Ltd., Document Number: MD00904, Revision
          02.01, June 15, 2016, Chapter 24 "MIPS16e Application-Specific
          Extension to the MIPS32 Instruction Set", pp. 871-883
      Signed-off-by: NMaciej W. Rozycki <macro@imgtec.com>
      Reviewed-by: NJames Hogan <james.hogan@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16095/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      f3235d32
    • M
      MIPS: MIPS16e2: Identify ASE presence · 8d1630f1
      Maciej W. Rozycki 提交于
      Identify the presence of the MIPS16e2 ASE as per the architecture
      specification[1], by checking for CP0 Config5.CA2 bit being 1[2].
      
      References:
      
      [1] "MIPS32 Architecture for Programmers: MIPS16e2 Application-Specific
          Extension Technical Reference Manual", Imagination Technologies
          Ltd., Document Number: MD01172, Revision 01.00, April 26, 2016,
          Section 1.2 "Software Detection of the ASE", p. 5
      
      [2] "MIPS32 interAptiv Multiprocessing System Software User's Manual",
          Imagination Technologies Ltd., Document Number: MD00904, Revision
          02.01, June 15, 2016, Section 2.2.1.6 "Device Configuration 5 --
          Config5 (CP0 Register 16, Select 5)", pp. 71-72
      Signed-off-by: NMaciej W. Rozycki <macro@imgtec.com>
      Reviewed-by: NJames Hogan <james.hogan@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16094/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      8d1630f1
  10. 04 7月, 2017 1 次提交
  11. 30 6月, 2017 4 次提交
    • J
      MIPS: Avoid accidental raw backtrace · 85423636
      James Hogan 提交于
      Since commit 81a76d71 ("MIPS: Avoid using unwind_stack() with
      usermode") show_backtrace() invokes the raw backtracer when
      cp0_status & ST0_KSU indicates user mode to fix issues on EVA kernels
      where user and kernel address spaces overlap.
      
      However this is used by show_stack() which creates its own pt_regs on
      the stack and leaves cp0_status uninitialised in most of the code paths.
      This results in the non deterministic use of the raw back tracer
      depending on the previous stack content.
      
      show_stack() deals exclusively with kernel mode stacks anyway, so
      explicitly initialise regs.cp0_status to KSU_KERNEL (i.e. 0) to ensure
      we get a useful backtrace.
      
      Fixes: 81a76d71 ("MIPS: Avoid using unwind_stack() with usermode")
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: <stable@vger.kernel.org> # 3.15+
      Patchwork: https://patchwork.linux-mips.org/patch/16656/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      85423636
    • P
      MIPS: Perform post-DMA cache flushes on systems with MAARs · cad482c1
      Paul Burton 提交于
      Recent CPUs from Imagination Technologies such as the I6400 or P6600 are
      able to speculatively fetch data from memory into caches. This means
      that if used in a system with non-coherent DMA they require that caches
      be invalidated after a device performs DMA, and before the CPU reads the
      DMA'd data, in order to ensure that stale values weren't speculatively
      prefetched.
      
      Such CPUs also introduced Memory Accessibility Attribute Registers
      (MAARs) in order to control the regions in which they are allowed to
      speculate. Thus we can use the presence of MAARs as a good indication
      that the CPU requires the above cache maintenance. Use the presence of
      MAARs to determine the result of cpu_needs_post_dma_flush() in the
      default case, in order to handle these recent CPUs correctly.
      
      Note that the return type of cpu_needs_post_dma_flush() is changed to
      bool, such that it's clearer what's happening when cpu_has_maar is cast
      to bool for the return value. If this patch were backported to a
      pre-v4.7 kernel then MIPS_CPU_MAAR was 1ull<<34, so when cast to an int
      we would incorrectly return 0. It so happens that MIPS_CPU_MAAR is
      currently 1ull<<30, so when truncated to an int gives a non-zero value
      anyway, but even so the implicit conversion from long long int to bool
      makes it clearer to understand what will happen than the implicit
      conversion from long long int to int would. The bool return type also
      fits this usage better semantically, so seems like an all-round win.
      
      Thanks to Ed for spotting the issue for pre-v4.7 kernels & suggesting
      the return type change.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Reviewed-by: NBryan O'Donoghue <pure.logic@nexus-software.ie>
      Tested-by: NBryan O'Donoghue <pure.logic@nexus-software.ie>
      Cc: Ed Blake <ed.blake@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16363/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      cad482c1
    • P
      MIPS: Fix IRQ tracing & lockdep when rescheduling · d8550860
      Paul Burton 提交于
      When the scheduler sets TIF_NEED_RESCHED & we call into the scheduler
      from arch/mips/kernel/entry.S we disable interrupts. This is true
      regardless of whether we reach work_resched from syscall_exit_work,
      resume_userspace or by looping after calling schedule(). Although we
      disable interrupts in these paths we don't call trace_hardirqs_off()
      before calling into C code which may acquire locks, and we therefore
      leave lockdep with an inconsistent view of whether interrupts are
      disabled or not when CONFIG_PROVE_LOCKING & CONFIG_DEBUG_LOCKDEP are
      both enabled.
      
      Without tracing this interrupt state lockdep will print warnings such
      as the following once a task returns from a syscall via
      syscall_exit_partial with TIF_NEED_RESCHED set:
      
      [   49.927678] ------------[ cut here ]------------
      [   49.934445] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:3687 check_flags.part.41+0x1dc/0x1e8
      [   49.946031] DEBUG_LOCKS_WARN_ON(current->hardirqs_enabled)
      [   49.946355] CPU: 0 PID: 1 Comm: init Not tainted 4.10.0-00439-gc9fd5d362289-dirty #197
      [   49.963505] Stack : 0000000000000000 ffffffff81bb5d6a 0000000000000006 ffffffff801ce9c4
      [   49.974431]         0000000000000000 0000000000000000 0000000000000000 000000000000004a
      [   49.985300]         ffffffff80b7e487 ffffffff80a24498 a8000000ff160000 ffffffff80ede8b8
      [   49.996194]         0000000000000001 0000000000000000 0000000000000000 0000000077c8030c
      [   50.007063]         000000007fd8a510 ffffffff801cd45c 0000000000000000 a8000000ff127c88
      [   50.017945]         0000000000000000 ffffffff801cf928 0000000000000001 ffffffff80a24498
      [   50.028827]         0000000000000000 0000000000000001 0000000000000000 0000000000000000
      [   50.039688]         0000000000000000 a8000000ff127bd0 0000000000000000 ffffffff805509bc
      [   50.050575]         00000000140084e0 0000000000000000 0000000000000000 0000000000040a00
      [   50.061448]         0000000000000000 ffffffff8010e1b0 0000000000000000 ffffffff805509bc
      [   50.072327]         ...
      [   50.076087] Call Trace:
      [   50.079869] [<ffffffff8010e1b0>] show_stack+0x80/0xa8
      [   50.086577] [<ffffffff805509bc>] dump_stack+0x10c/0x190
      [   50.093498] [<ffffffff8015dde0>] __warn+0xf0/0x108
      [   50.099889] [<ffffffff8015de34>] warn_slowpath_fmt+0x3c/0x48
      [   50.107241] [<ffffffff801c15b4>] check_flags.part.41+0x1dc/0x1e8
      [   50.114961] [<ffffffff801c239c>] lock_is_held_type+0x8c/0xb0
      [   50.122291] [<ffffffff809461b8>] __schedule+0x8c0/0x10f8
      [   50.129221] [<ffffffff80946a60>] schedule+0x30/0x98
      [   50.135659] [<ffffffff80106278>] work_resched+0x8/0x34
      [   50.142397] ---[ end trace 0cb4f6ef5b99fe21 ]---
      [   50.148405] possible reason: unannotated irqs-off.
      [   50.154600] irq event stamp: 400463
      [   50.159566] hardirqs last  enabled at (400463): [<ffffffff8094edc8>] _raw_spin_unlock_irqrestore+0x40/0xa8
      [   50.171981] hardirqs last disabled at (400462): [<ffffffff8094eb98>] _raw_spin_lock_irqsave+0x30/0xb0
      [   50.183897] softirqs last  enabled at (400450): [<ffffffff8016580c>] __do_softirq+0x4ac/0x6a8
      [   50.195015] softirqs last disabled at (400425): [<ffffffff80165e78>] irq_exit+0x110/0x128
      
      Fix this by using the TRACE_IRQS_OFF macro to call trace_hardirqs_off()
      when CONFIG_TRACE_IRQFLAGS is enabled. This is done before invoking
      schedule() following the work_resched label because:
      
       1) Interrupts are disabled regardless of the path we take to reach
          work_resched() & schedule().
      
       2) Performing the tracing here avoids the need to do it in paths which
          disable interrupts but don't call out to C code before hitting a
          path which uses the RESTORE_SOME macro that will call
          trace_hardirqs_on() or trace_hardirqs_off() as appropriate.
      
      We call trace_hardirqs_on() using the TRACE_IRQS_ON macro before calling
      syscall_trace_leave() for similar reasons, ensuring that lockdep has a
      consistent view of state after we re-enable interrupts.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Fixes: 1da177e4 ("Linux-2.6.12-rc2")
      Cc: linux-mips@linux-mips.org
      Cc: stable <stable@vger.kernel.org>
      Patchwork: https://patchwork.linux-mips.org/patch/15385/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      d8550860
    • P
      MIPS: pm-cps: Drop manual cache-line alignment of ready_count · 161c51cc
      Paul Burton 提交于
      We allocate memory for a ready_count variable per-CPU, which is accessed
      via a cached non-coherent TLB mapping to perform synchronisation between
      threads within the core using LL/SC instructions. In order to ensure
      that the variable is contained within its own data cache line we
      allocate 2 lines worth of memory & align the resulting pointer to a line
      boundary. This is however unnecessary, since kmalloc is guaranteed to
      return memory which is at least cache-line aligned (see
      ARCH_DMA_MINALIGN). Stop the redundant manual alignment.
      
      Besides cleaning up the code & avoiding needless work, this has the side
      effect of avoiding an arithmetic error found by Bryan on 64 bit systems
      due to the 32 bit size of the former dlinesz. This led the ready_count
      variable to have its upper 32b cleared erroneously for MIPS64 kernels,
      causing problems when ready_count was later used on MIPS64 via cpuidle.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Fixes: 3179d37e ("MIPS: pm-cps: add PM state entry code for CPS systems")
      Reported-by: NBryan O'Donoghue <bryan.odonoghue@imgtec.com>
      Reviewed-by: NBryan O'Donoghue <bryan.odonoghue@imgtec.com>
      Tested-by: NBryan O'Donoghue <bryan.odonoghue@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: stable <stable@vger.kernel.org> # v3.16+
      Patchwork: https://patchwork.linux-mips.org/patch/15383/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      161c51cc
  12. 29 6月, 2017 5 次提交
    • A
      MIPS: VDSO: Fix a mismatch between comment and preprocessor constant · bdb94f6e
      Aleksandar Markovic 提交于
      Sync the comment with its preprocessor constant counterpart.
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Miodrag Dinic <miodrag.dinic@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
      Cc: Raghu Gandham <raghu.gandham@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16641/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      bdb94f6e
    • G
      MIPS: VDSO: Add implementation of gettimeofday() fallback · 0b523a85
      Goran Ferenc 提交于
      This patch adds gettimeofday_fallback() function that wraps assembly
      invocation of gettimeofday() syscall using __NR_gettimeofday.
      
      This function is used if pure VDSO implementation gettimeofday()
      does not succeed for any reason. Its imeplementation is enclosed in
      "#ifdef CONFIG_MIPS_CLOCK_VSYSCALL" to be in sync with the similar
      arrangement for __vdso_gettimeofday().
      
      If syscall invocation via __NR_gettimeofday fails, register a3 will
      be set. So, after the syscall, register a3 is tested and the return
      valuem is negated if it's set.
      Signed-off-by: NGoran Ferenc <goran.ferenc@imgtec.com>
      Signed-off-by: NMiodrag Dinic <miodrag.dinic@imgtec.com>
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtec.com>
      Cc: Douglas Leung <douglas.leung@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
      Cc: Raghu Gandham <raghu.gandham@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16640/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      0b523a85
    • G
      MIPS: VDSO: Add implementation of clock_gettime() fallback · 180902e0
      Goran Ferenc 提交于
      This patch adds clock_gettime_fallback() function that wraps assembly
      invocation of clock_gettime() syscall using __NR_clock_gettime.
      
      This function is used if pure VDSO implementation of clock_gettime()
      does not succeed for any reason. For example, it is called if the
      clkid parameter of clock_gettime() is not one of the clkids listed
      in the switch-case block of the function __vdso_clock_gettime()
      (one such case for clkid is CLOCK_BOOTIME).
      
      If syscall invocation via __NR_clock_gettime fails, register a3 will
      be set. So, after the syscall, register a3 is tested and the return
      value is negated if it's set.
      Signed-off-by: NGoran Ferenc <goran.ferenc@imgtec.com>
      Signed-off-by: NMiodrag Dinic <miodrag.dinic@imgtec.com>
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtec.com>
      Cc: Douglas Leung <douglas.leung@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
      Cc: Raghu Gandham <raghu.gandham@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16639/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      180902e0
    • G
      MIPS: VDSO: Fix conversions in do_monotonic()/do_monotonic_coarse() · 8ec7f15b
      Goran Ferenc 提交于
      Fix incorrect calculation in do_monotonic() and do_monotonic_coarse()
      function that in turn caused incorrect values returned by the vdso
      version of system call clock_gettime() on mips64 if its system clock
      ID parameter was CLOCK_MONOTONIC or CLOCK_MONOTONIC_COARSE.
      
      Consider these variables and their types on mips32 and mips64:
      
      tk->wall_to_monotonic.tv_sec  s64, s64   (kernel/vdso.c)
      vdso_data.wall_to_mono_sec    u32, u32   (kernel/vdso.c)
      to_mono_sec                   u32, u32   (vdso/gettimeofday.c)
      ts->tv_sec                    s32, s64   (vdso/gettimeofday.c)
      
      For mips64 case, u32 vdso_data.wall_to_mono_sec variable is updated
      from the 64-bit signed variable tk->wall_to_monotonic.tv_sec
      (kernel/vdso.c:76) which is a negative number holding the time passed
      from 1970-01-01 to the time boot started. This 64-bit signed value is
      currently around 47+ years, in seconds. For instance, let this value
      be:
      
      -1489757461
      
      or
      
      11111111111111111111111111111111 10100111001101000001101011101011
      
      By updating 32-bit vdso_data.wall_to_mono_sec variable, we lose upper
      32 bits (signed 1's).
      
      to_mono_sec variable is a parameter of do_monotonic() and
      do_monotonic_coarse() functions which holds vdso_data.wall_to_mono_sec
      value. Its value needs to be added (or subtracted considering it holds
      negative value from the tk->wall_to_monotonic.tv_sec) to the current
      time passed from 1970-01-01 (ts->tv_sec), which is again something like
      47+ years, but increased by the time passed from the boot to the
      current time. ts->tv_sec is 32-bit long in case of 32-bit architecture
      and 64-bit long in case of 64-bit architecture. Consider the update of
      ts->tv_sec (vdso/gettimeofday.c:55 & 167):
      
      ts->tv_sec += to_mono_sec;
      
      mips32 case: This update will be performed correctly, since both
      ts->tv_sec and to_mono_sec are 32-bit long and the sign in to_mono_sec
      is preserved. Implicit conversion from u32 to s32 will be done
      correctly.
      
      mips64 case: This update will be wrong, since the implicit conversion
      will not be done correctly. The reason is that the conversion will be
      from u32 to s64. This is because to_mono_sec is 32-bit long for both
      mips32 and mips64 cases and s64..33 bits of converted to_mono_sec
      variable will be zeros.
      
      So, in order to make MIPS64 implementation work properly for
      MONOTONIC and MONOTONIC_COARSE clock ids on mips64, the size of
      wall_to_mono_sec variable in mips_vdso_data union and respective
      parameters in do_monotonic() and do_monotonic_coarse() functions
      should be changed from u32 to u64. Because of consistency, this
      size change from u32 and u64 is also done for wall_to_mono_nsec
      variable and corresponding function parameters.
      
      As far as similar situations for other architectures are concerned,
      let's take a look at arm. Arm has two distinct vdso_data structures
      for 32-bit & 64-bit cases, and arm's wall_to_mono_sec and
      wall_to_mono_nsec are u32 for 32-bit and u64 for 64-bit cases.
      On the other hand, MIPS has only one structure (mips_vdso_data),
      hence the need for changing the size of above mentioned parameters.
      Signed-off-by: NGoran Ferenc <goran.ferenc@imgtec.com>
      Signed-off-by: NMiodrag Dinic <miodrag.dinic@imgtec.com>
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtec.com>
      Cc: Douglas Leung <douglas.leung@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Petar Jovanovic <petar.jovanovic@imgtec.com>
      Cc: Raghu Gandham <raghu.gandham@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/16638/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      8ec7f15b
    • P
      MIPS: Use current_cpu_type() in m4kc_tlbp_war() · 5f930860
      Paul Burton 提交于
      Use current_cpu_type() to check for 4Kc processors instead of checking
      the PRID directly. This will allow for the 4Kc case to be optimised out
      of kernels that can't run on 4KC processors, thanks to __get_cpu_type()
      and its unreachable() call.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16205/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      5f930860