1. 30 6月, 2017 3 次提交
    • 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: 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
  2. 28 6月, 2017 1 次提交
  3. 15 6月, 2017 1 次提交
    • P
      MIPS: Fix bnezc/jialc return address calculation · 1a73d931
      Paul Burton 提交于
      The code handling the pop76 opcode (ie. bnezc & jialc instructions) in
      __compute_return_epc_for_insn() needs to set the value of $31 in the
      jialc case, which is encoded with rs = 0. However its check to
      differentiate bnezc (rs != 0) from jialc (rs = 0) was unfortunately
      backwards, meaning that if we emulate a bnezc instruction we clobber $31
      & if we emulate a jialc instruction it actually behaves like a jic
      instruction.
      
      Fix this by inverting the check of rs to match the way the instructions
      are actually encoded.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Fixes: 28d6f93d ("MIPS: Emulate the new MIPS R6 BNEZC and JIALC instructions")
      Cc: stable <stable@vger.kernel.org> # v4.0+
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/16178/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      1a73d931
  4. 08 6月, 2017 2 次提交
  5. 30 5月, 2017 1 次提交
    • V
      kthread: fix boot hang (regression) on MIPS/OpenRISC · b0f5a8f3
      Vegard Nossum 提交于
      This fixes a regression in commit 4d6501dc where I didn't notice
      that MIPS and OpenRISC were reinitialising p->{set,clear}_child_tid to
      NULL after our initialisation in copy_process().
      
      We can simply get rid of the arch-specific initialisation here since it
      is now always done in copy_process() before hitting copy_thread{,_tls}().
      
      Review notes:
      
       - As far as I can tell, copy_process() is the only user of
         copy_thread_tls(), which is the only caller of copy_thread() for
         architectures that don't implement copy_thread_tls().
      
       - After this patch, there is no arch-specific code touching
         p->set_child_tid or p->clear_child_tid whatsoever.
      
       - It may look like MIPS/OpenRISC wanted to always have these fields be
         NULL, but that's not true, as copy_process() would unconditionally
         set them again _after_ calling copy_thread_tls() before commit
         4d6501dc.
      
      Fixes: 4d6501dc ("kthread: Fix use-after-free if kthread fork fails")
      Reported-by: NGuenter Roeck <linux@roeck-us.net>
      Tested-by: Guenter Roeck <linux@roeck-us.net> # MIPS only
      Acked-by: NStafford Horne <shorne@gmail.com>
      Acked-by: NOleg Nesterov <oleg@redhat.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: linux-mips@linux-mips.org
      Cc: Jonas Bonn <jonas@southpole.se>
      Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
      Cc: openrisc@lists.librecores.org
      Cc: Jamie Iles <jamie.iles@oracle.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NVegard Nossum <vegard.nossum@oracle.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b0f5a8f3
  6. 26 5月, 2017 1 次提交
    • T
      jump_label: Reorder hotplug lock and jump_label_lock · f2545b2d
      Thomas Gleixner 提交于
      The conversion of the hotplug locking to a percpu rwsem unearthed lock
      ordering issues all over the place.
      
      The jump_label code has two issues:
      
       1) Nested get_online_cpus() invocations
      
       2) Ordering problems vs. the cpus rwsem and the jump_label_mutex
      
      To cure these, the following lock order has been established;
      
         cpus_rwsem -> jump_label_lock -> text_mutex
      
      Even if not all architectures need protection against CPU hotplug, taking
      cpus_rwsem before jump_label_lock is now mandatory in code pathes which
      actually modify code and therefor need text_mutex protection.
      
      Move the get_online_cpus() invocations into the core jump label code and
      establish the proper lock order where required.
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Acked-by: NIngo Molnar <mingo@kernel.org>
      Acked-by: N"David S. Miller" <davem@davemloft.net>
      Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sebastian Siewior <bigeasy@linutronix.de>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Jason Baron <jbaron@akamai.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Link: http://lkml.kernel.org/r/20170524081549.025830817@linutronix.de
      f2545b2d
  7. 09 5月, 2017 2 次提交
    • K
      format-security: move static strings to const · 06324664
      Kees Cook 提交于
      While examining output from trial builds with -Wformat-security enabled,
      many strings were found that should be defined as "const", or as a char
      array instead of char pointer.  This makes some static analysis easier,
      by producing fewer false positives.
      
      As these are all trivial changes, it seemed best to put them all in a
      single patch rather than chopping them up per maintainer.
      
      Link: http://lkml.kernel.org/r/20170405214711.GA5711@beastSigned-off-by: NKees Cook <keescook@chromium.org>
      Acked-by: Jes Sorensen <jes@trained-monkey.org>	[runner.c]
      Cc: Tony Lindgren <tony@atomide.com>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Cc: Viresh Kumar <viresh.kumar@linaro.org>
      Cc: Daniel Vetter <daniel.vetter@intel.com>
      Cc: Jani Nikula <jani.nikula@linux.intel.com>
      Cc: Sean Paul <seanpaul@chromium.org>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
      Cc: Salil Mehta <salil.mehta@huawei.com>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Matt Redfearn <matt.redfearn@imgtec.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Mugunthan V N <mugunthanvnm@ti.com>
      Cc: Felipe Balbi <felipe.balbi@linux.intel.com>
      Cc: Jarod Wilson <jarod@redhat.com>
      Cc: Florian Westphal <fw@strlen.de>
      Cc: Antonio Quartulli <a@unstable.cc>
      Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: Kejian Yan <yankejian@huawei.com>
      Cc: Daode Huang <huangdaode@hisilicon.com>
      Cc: Qianqian Xie <xieqianqian@huawei.com>
      Cc: Philippe Reynes <tremyfr@gmail.com>
      Cc: Colin Ian King <colin.king@canonical.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Christian Gromm <christian.gromm@microchip.com>
      Cc: Andrey Shvetsov <andrey.shvetsov@k2l.de>
      Cc: Jason Litzinger <jlitzingerdev@gmail.com>
      Cc: WANG Cong <xiyou.wangcong@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      06324664
    • A
      cpumask: make "nr_cpumask_bits" unsigned · c311c797
      Alexey Dobriyan 提交于
      Bit searching functions accept "unsigned long" indices but
      "nr_cpumask_bits" is "int" which is signed, so inevitable sign
      extensions occur on x86_64.  Those MOVSX are #1 MOVSX bloat by number of
      uses across whole kernel.
      
      Change "nr_cpumask_bits" to unsigned, this number can't be negative
      after all.  It allows to do implicit zero-extension on x86_64 without
      MOVSX.
      
      Change signed comparisons into unsigned comparisons where necessary.
      
      Other uses looks fine because it is either argument passed to a function
      or comparison is already unsigned.
      
      Net win on allyesconfig type of kernel: ~2.8 KB (!)
      
      	add/remove: 0/0 grow/shrink: 8/725 up/down: 93/-2926 (-2833)
      	function                                     old     new   delta
      	xen_exit_mmap                                691     735     +44
      	qstat_read                                   426     440     +14
      	__cpufreq_cooling_register                  1678    1687      +9
      	trace_rb_cpu_prepare                         447     455      +8
      	vermagic                                      54      60      +6
      	nfp_driver_version                            54      60      +6
      	rcu_torture_stats_print                     1147    1151      +4
      	find_next_push_cpu                           267     269      +2
      	xen_irq_resume                               961     960      -1
      				...
      	init_vp_index                                946     906     -40
      	od_set_powersave_bias                        328     281     -47
      	power_cpu_exit                               193     139     -54
      	arch_show_interrupts                        3538    3484     -54
      	select_idle_sibling                         1558    1471     -87
      	Total: Before=158358910, After=158356077, chg -0.00%
      
      Same arguments apply to "nr_cpu_ids" but I haven't yet found enough
      courage to delve into this issue (and proper fix may require new type
      "cpu_t" which is whole separate story).
      
      Link: http://lkml.kernel.org/r/20170309205322.GA1728@avx2Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c311c797
  8. 15 4月, 2017 1 次提交
    • N
      MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks · e4db9253
      Nicolai Stange 提交于
      In preparation for making the clockevents core NTP correction aware,
      all clockevent device drivers must set ->min_delta_ticks and
      ->max_delta_ticks rather than ->min_delta_ns and ->max_delta_ns: a
      clockevent device's rate is going to change dynamically and thus, the
      ratio of ns to ticks ceases to stay invariant.
      
      Make the MIPS arch's clockevent drivers initialize these fields properly.
      
      This patch alone doesn't introduce any change in functionality as the
      clockevents core still looks exclusively at the (untouched) ->min_delta_ns
      and ->max_delta_ns. As soon as this has changed, a followup patch will
      purge the initialization of ->min_delta_ns and ->max_delta_ns from these
      drivers.
      
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
      Cc: Richard Cochran <richardcochran@gmail.com>
      Cc: Prarit Bhargava <prarit@redhat.com>
      Cc: Stephen Boyd <sboyd@codeaurora.org>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Cc: Keguang Zhang <keguang.zhang@gmail.com>
      Cc: John Crispin <john@phrozen.org>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      e4db9253
  9. 13 4月, 2017 4 次提交
    • P
      MIPS: Stengthen IPI IRQ domain sanity check · e6488982
      Paul Burton 提交于
      Commit fbde2d7d ("MIPS: Add generic SMP IPI support") introduced a
      sanity check that an IPI IRQ domain can be found during boot, in order
      to ensure that IPIs are able to be set up in systems using such domains.
      However it was added at a point where systems may have used an IPI IRQ
      domain in some situations but not others, and we could not know which
      were the case until runtime, so commit 578bffc8 ("MIPS: Don't BUG_ON
      when no IPI domain is found") made that check simply skip IPI init if no
      domain were found in order to fix the boot for systems such as QEMU
      Malta.
      
      We now use IPI IRQ domains for the MIPS CPU interrupt controller, which
      means systems which make use of IPI IRQ domains will always do so when
      running on multiple CPUs. As a result we now strengthen the sanity check
      to ensure that an IPI IRQ domain is found when multiple CPUs are present
      in the system.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Jason Cooper <jason@lakedaemon.net>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/15838/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      e6488982
    • P
      MIPS: smp-mt: Use CPU interrupt controller IPI IRQ domain support · 1eed4004
      Paul Burton 提交于
      Remove the smp-mt IPI code that supported single-core multithreaded
      systems and instead make use of the IPI IRQ domain support provided by
      the MIPS CPU interrupt controller driver. This removes some less than
      nice code, the horrible split between arch & board code and the
      duplication that led to within board code.
      
      The lantiq portion of this patch has only been compile tested. Malta has
      been tested & is functional.
      Signed-off-by: NPaul Burton <paul.burton@imgtec.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Jason Cooper <jason@lakedaemon.net>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/15837/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      1eed4004
    • J
      MIPS: KGDB: Use kernel context for sleeping threads · 162b270c
      James Hogan 提交于
      KGDB is a kernel debug stub and it can't be used to debug userland as it
      can only safely access kernel memory.
      
      On MIPS however KGDB has always got the register state of sleeping
      processes from the userland register context at the beginning of the
      kernel stack. This is meaningless for kernel threads (which never enter
      userland), and for user threads it prevents the user seeing what it is
      doing while in the kernel:
      
      (gdb) info threads
        Id   Target Id         Frame
        ...
        3    Thread 2 (kthreadd) 0x0000000000000000 in ?? ()
        2    Thread 1 (init)   0x000000007705c4b4 in ?? ()
        1    Thread -2 (shadowCPU0) 0xffffffff8012524c in arch_kgdb_breakpoint () at arch/mips/kernel/kgdb.c:201
      
      Get the register state instead from the (partial) kernel register
      context stored in the task's thread_struct for resume() to restore. All
      threads now correctly appear to be in context_switch():
      
      (gdb) info threads
        Id   Target Id         Frame
        ...
        3    Thread 2 (kthreadd) context_switch (rq=<optimized out>, cookie=..., next=<optimized out>, prev=0x0) at kernel/sched/core.c:2903
        2    Thread 1 (init)   context_switch (rq=<optimized out>, cookie=..., next=<optimized out>, prev=0x0) at kernel/sched/core.c:2903
        1    Thread -2 (shadowCPU0) 0xffffffff8012524c in arch_kgdb_breakpoint () at arch/mips/kernel/kgdb.c:201
      
      Call clobbered registers which aren't saved and exception registers
      (BadVAddr & Cause) which can't be easily determined without stack
      unwinding are reported as 0. The PC is taken from the return address,
      such that the state presented matches that found immediately after
      returning from resume().
      
      Fixes: 88547001 ("[MIPS] kgdb: add arch support for the kernel's kgdb core")
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: linux-mips@linux-mips.org
      Cc: stable@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/15829/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      162b270c
    • M
      MIPS: smp-cps: Fix potentially uninitialised value of core · bac06cf0
      Matt Redfearn 提交于
      Turning on DEBUG in smp-cps.c, or compiling the kernel with
      CONFIG_DYNAMIC_DEBUG enabled results the build error:
      
      arch/mips/kernel/smp-cps.c: In function 'play_dead':
      ./include/linux/dynamic_debug.h:126:3: error: 'core' may be used
      uninitialized in this function [-Werror=maybe-uninitialized]
      
      Fix this by always initialising the variable.
      
      Fixes: 0d2808f3 ("MIPS: smp-cps: Add support for CPU hotplug of MIPSr6 processors")
      Signed-off-by: NMatt Redfearn <matt.redfearn@imgtec.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/15848/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      bac06cf0
  10. 12 4月, 2017 5 次提交
  11. 10 4月, 2017 5 次提交
    • J
      MIPS: cevt-r4k: Fix out-of-bounds array access · 9d7f29cd
      James Hogan 提交于
      calculate_min_delta() may incorrectly access a 4th element of buf2[]
      which only has 3 elements. This may trigger undefined behaviour and has
      been reported to cause strange crashes in start_kernel() sometime after
      timer initialization when built with GCC 5.3, possibly due to
      register/stack corruption:
      
      sched_clock: 32 bits at 200MHz, resolution 5ns, wraps every 10737418237ns
      CPU 0 Unable to handle kernel paging request at virtual address ffffb0aa, epc == 8067daa8, ra == 8067da84
      Oops[#1]:
      CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.9.18 #51
      task: 8065e3e0 task.stack: 80644000
      $ 0   : 00000000 00000001 00000000 00000000
      $ 4   : 8065b4d0 00000000 805d0000 00000010
      $ 8   : 00000010 80321400 fffff000 812de408
      $12   : 00000000 00000000 00000000 ffffffff
      $16   : 00000002 ffffffff 80660000 806a666c
      $20   : 806c0000 00000000 00000000 00000000
      $24   : 00000000 00000010
      $28   : 80644000 80645ed0 00000000 8067da84
      Hi    : 00000000
      Lo    : 00000000
      epc   : 8067daa8 start_kernel+0x33c/0x500
      ra    : 8067da84 start_kernel+0x318/0x500
      Status: 11000402 KERNEL EXL
      Cause : 4080040c (ExcCode 03)
      BadVA : ffffb0aa
      PrId  : 0501992c (MIPS 1004Kc)
      Modules linked in:
      Process swapper/0 (pid: 0, threadinfo=80644000, task=8065e3e0, tls=00000000)
      Call Trace:
      [<8067daa8>] start_kernel+0x33c/0x500
      Code: 24050240  0c0131f9  24849c64 <a200b0a8> 41606020  000000c0  0c1a45e6 00000000  0c1a5f44
      
      UBSAN also detects the same issue:
      
      ================================================================
      UBSAN: Undefined behaviour in arch/mips/kernel/cevt-r4k.c:85:41
      load of address 80647e4c with insufficient space
      for an object of type 'unsigned int'
      CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.9.18 #47
      Call Trace:
      [<80028f70>] show_stack+0x88/0xa4
      [<80312654>] dump_stack+0x84/0xc0
      [<8034163c>] ubsan_epilogue+0x14/0x50
      [<803417d8>] __ubsan_handle_type_mismatch+0x160/0x168
      [<8002dab0>] r4k_clockevent_init+0x544/0x764
      [<80684d34>] time_init+0x18/0x90
      [<8067fa5c>] start_kernel+0x2f0/0x500
      =================================================================
      
      buf2[] is intentionally only 3 elements so that the last element is the
      median once 5 samples have been inserted, so explicitly prevent the
      possibility of comparing against the 4th element rather than extending
      the array.
      
      Fixes: 1fa40555 ("MIPS: cevt-r4k: Dynamically calculate min_delta_ns")
      Reported-by: NRabin Vincent <rabinv@axis.com>
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Tested-by: NRabin Vincent <rabinv@axis.com>
      Cc: linux-mips@linux-mips.org
      Cc: <stable@vger.kernel.org> # 4.7.x-
      Patchwork: https://patchwork.linux-mips.org/patch/15892/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      9d7f29cd
    • R
      MIPS: perf: fix deadlock · f2b42866
      Rabin Vincent 提交于
      mipsxx_pmu_handle_shared_irq() calls irq_work_run() while holding the
      pmuint_rwlock for read.  irq_work_run() can, via perf_pending_event(),
      call try_to_wake_up() which can try to take rq->lock.
      
      However, perf can also call perf_pmu_enable() (and thus take the
      pmuint_rwlock for write) while holding the rq->lock, from
      finish_task_switch() via perf_event_context_sched_in().
      
      This leads to an ABBA deadlock:
      
       PID: 3855   TASK: 8f7ce288  CPU: 2   COMMAND: "process"
        #0 [89c39ac8] __delay at 803b5be4
        #1 [89c39ac8] do_raw_spin_lock at 8008fdcc
        #2 [89c39af8] try_to_wake_up at 8006e47c
        #3 [89c39b38] pollwake at 8018eab0
        #4 [89c39b68] __wake_up_common at 800879f4
        #5 [89c39b98] __wake_up at 800880e4
        #6 [89c39bc8] perf_event_wakeup at 8012109c
        #7 [89c39be8] perf_pending_event at 80121184
        #8 [89c39c08] irq_work_run_list at 801151f0
        #9 [89c39c38] irq_work_run at 80115274
       #10 [89c39c50] mipsxx_pmu_handle_shared_irq at 8002cc7c
      
       PID: 1481   TASK: 8eaac6a8  CPU: 3   COMMAND: "process"
        #0 [8de7f900] do_raw_write_lock at 800900e0
        #1 [8de7f918] perf_event_context_sched_in at 80122310
        #2 [8de7f938] __perf_event_task_sched_in at 80122608
        #3 [8de7f958] finish_task_switch at 8006b8a4
        #4 [8de7f998] __schedule at 805e4dc4
        #5 [8de7f9f8] schedule at 805e5558
        #6 [8de7fa10] schedule_hrtimeout_range_clock at 805e9984
        #7 [8de7fa70] poll_schedule_timeout at 8018e8f8
        #8 [8de7fa88] do_select at 8018f338
        #9 [8de7fd88] core_sys_select at 8018f5cc
       #10 [8de7fee0] sys_select at 8018f854
       #11 [8de7ff28] syscall_common at 80028fc8
      
      The lock seems to be there to protect the hardware counters so there is
      no need to hold it across irq_work_run().
      Signed-off-by: NRabin Vincent <rabinv@axis.com>
      Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      f2b42866
    • A
      MIPS: r2-on-r6-emu: Clear BLTZALL and BGEZALL debugfs counters · 411dac79
      Aleksandar Markovic 提交于
      Add missing clearing of BLTZALL and BGEZALL emulation counters in
      function mipsr2_stats_clear_show().
      
      Previously, it was not possible to reset BLTZALL and BGEZALL
      emulation counters - their value remained the same even after
      explicit request via debugfs. As far as other related counters
      are concerned, they all seem to be properly cleared.
      
      This change affects debugfs operation only, core R2 emulation
      functionality is not affected.
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtec.com>
      Reviewed-by: NPaul Burton <paul.burton@imgtec.com>
      Cc: james.hogan@imgtec.com
      Cc: leonid.yegoshin@imgtec.com
      Cc: douglas.leung@imgtec.com
      Cc: petar.jovanovic@imgtec.com
      Cc: miodrag.dinic@imgtec.com
      Cc: goran.ferenc@imgtec.com
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/15517/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      411dac79
    • L
      MIPS: r2-on-r6-emu: Fix BLEZL and BGTZL identification · 5bba7aa4
      Leonid Yegoshin 提交于
      Fix the problem of inaccurate identification of instructions BLEZL and
      BGTZL in R2 emulation code by making sure all necessary encoding
      specifications are met.
      
      Previously, certain R6 instructions could be identified as BLEZL or
      BGTZL. R2 emulation routine didn't take into account that both BLEZL
      and BGTZL instructions require their rt field (bits 20 to 16 of
      instruction encoding) to be 0, and that, at same time, if the value in
      that field is not 0, the encoding may represent a legitimate MIPS R6
      instruction.
      
      This means that a problem could occur after emulation optimization,
      when emulation routine tried to pipeline emulation, picked up a next
      candidate, and subsequently misrecognized an R6 instruction as BLEZL
      or BGTZL.
      
      It should be said that for single pass strategy, the problem does not
      happen because CPU doesn't trap on branch-compacts which share opcode
      space with BLEZL/BGTZL (but have rt field != 0, of course).
      Signed-off-by: NLeonid Yegoshin <leonid.yegoshin@imgtec.com>
      Signed-off-by: NMiodrag Dinic <miodrag.dinic@imgtech.com>
      Signed-off-by: NAleksandar Markovic <aleksandar.markovic@imgtech.com>
      Reported-by: NDouglas Leung <douglas.leung@imgtec.com>
      Reviewed-by: NPaul Burton <paul.burton@imgtec.com>
      Cc: james.hogan@imgtec.com
      Cc: petar.jovanovic@imgtec.com
      Cc: goran.ferenc@imgtec.com
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/15456/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      5bba7aa4
    • M
      MIPS: Enable GENERIC_CPU_AUTOPROBE · 05510f2b
      Marcin Nowakowski 提交于
      Add missing macros and methods that are required by
      CONFIG_GENERIC_CPU_AUTOPROBE: MAX_CPU_FEATURES, cpu_have_feature(),
      cpu_feature().
      
      Also set a default elf platform as currently it is not set for most MIPS
      platforms resulting in incorrectly specified modalias values in cpu
      autoprobe ("cpu:type:(null):feature:...").
      
      Export 'elf_hwcap' symbol so that it can be accessed from modules that
      use module_cpu_feature_match()
      Signed-off-by: NMarcin Nowakowski <marcin.nowakowski@imgtec.com>
      Cc: linux-mips@linux-mips.org
      Patchwork: https://patchwork.linux-mips.org/patch/15395/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      05510f2b
  12. 06 4月, 2017 1 次提交
    • A
      mips: sanitize __access_ok() · f0a955f4
      Al Viro 提交于
      for one thing, the last argument is always __access_mask and had been such
      since 2.4.0-test3pre8; for another, it can bloody well be a static inline -
      -O2 or -Os, __builtin_constant_p() propagates through static inline calls.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      f0a955f4
  13. 03 4月, 2017 1 次提交
    • P
      debug: Fix __bug_table[] in arch linker scripts · b5effd38
      Peter Zijlstra 提交于
      The kbuild test robot reported this build failure on a number
      of architectures:
      
       >         make.cross ARCH=arm
       >    lib/lib.a(bug.o): In function `find_bug':
       > >> lib/bug.c:135: undefined reference to `__start___bug_table'
       > >> lib/bug.c:135: undefined reference to `__stop___bug_table'
      
      Caused by:
      
        19d43626 ("debug: Add _ONCE() logic to report_bug()")
      
      Which moved the BUG_TABLE from RO_DATA_SECTION() to RW_DATA_SECTION(),
      but a number of architectures don't use RW_DATA_SECTION(), so they
      ended up with no __bug_table[] ...
      
      Ideally all those would use RW_DATA_SECTION() in their linker scripts,
      but that's for another day.
      Signed-off-by: NPeter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Cc: kbuild-all@01.org
      Cc: tipbuild@zytor.com
      Link: http://lkml.kernel.org/r/20170330154927.o6qmgfp4bdhrajbm@hirez.programming.kicks-ass.netSigned-off-by: NIngo Molnar <mingo@kernel.org>
      b5effd38
  14. 29 3月, 2017 2 次提交
  15. 28 3月, 2017 4 次提交
    • J
      KVM: MIPS: Implement VZ support · c992a4f6
      James Hogan 提交于
      Add the main support for the MIPS Virtualization ASE (A.K.A. VZ) to MIPS
      KVM. The bulk of this work is in vz.c, with various new state and
      definitions elsewhere.
      
      Enough is implemented to be able to run on a minimal VZ core. Further
      patches will fill out support for guest features which are optional or
      can be disabled.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Radim Krčmář" <rkrcmar@redhat.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      Cc: linux-doc@vger.kernel.org
      c992a4f6
    • J
      MIPS: Probe guest MVH · a929bdc5
      James Hogan 提交于
      Probe for availablility of M{T,F}HC0 instructions used with e.g. XPA in
      the VZ guest context, and make it available via cpu_guest_has_mvh. This
      will be helpful in properly emulating the MAAR registers in KVM for MIPS
      VZ.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Radim Krčmář" <rkrcmar@redhat.com>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      a929bdc5
    • J
      MIPS: Probe guest CP0_UserLocal · a7c7ad6c
      James Hogan 提交于
      Probe for presence of guest CP0_UserLocal register and expose via
      cpu_guest_has_userlocal. This register is optional pre-r6, so this will
      allow KVM to only save/restore/expose the guest CP0_UserLocal register
      if it exists.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Radim Krčmář" <rkrcmar@redhat.com>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      a7c7ad6c
    • J
      MIPS: Add defs & probing of UFR · 4e87580e
      James Hogan 提交于
      Add definitions and probing of the UFR bit in Config5. This bit allows
      user mode control of the FR bit (floating point register mode). It is
      present if the UFRP bit is set in the floating point implementation
      register.
      
      This is a capability KVM may want to expose to guest kernels, even
      though Linux is unlikely to ever use it due to the implications for
      multi-threaded programs.
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Acked-by: NRalf Baechle <ralf@linux-mips.org>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Radim Krčmář" <rkrcmar@redhat.com>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      4e87580e
  16. 22 3月, 2017 4 次提交
    • M
      MIPS: IRQ Stack: Unwind IRQ stack onto task stack · db8466c5
      Matt Redfearn 提交于
      When the separate IRQ stack was introduced, stack unwinding only
      proceeded as far as the top of the IRQ stack, leading to kernel
      backtraces being less useful, lacking the trace of what was interrupted.
      
      Fix this by providing a means for the kernel to unwind the IRQ stack
      onto the interrupted task stack. The processor state is saved to the
      kernel task stack on interrupt. The IRQ_STACK_START macro reserves an
      unsigned long at the top of the IRQ stack where the interrupted task
      stack pointer can be saved. After the active stack is switched to the
      IRQ stack, save the interrupted tasks stack pointer to the reserved
      location.
      
      Fix the stack unwinding code to look for the frame being the top of the
      IRQ stack and if so get the next frame from the saved location. The
      existing test does not work with the separate stack since the ra is no
      longer pointed at ret_from_{irq,exception}.
      
      The test to stop unwinding the stack 32 bytes from the top of a stack
      must be modified to allow unwinding to continue up to the location of
      the saved task stack pointer when on the IRQ stack. The low / high marks
      of the stack are set depending on whether the sp is on an irq stack or
      not.
      Signed-off-by: NMatt Redfearn <matt.redfearn@imgtec.com>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
      Cc: Masanari Iida <standby24x7@gmail.com>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: James Hogan <james.hogan@imgtec.com>
      Cc: Paul Burton <paul.burton@imgtec.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jason A. Donenfeld <jason@zx2c4.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linux-mips@linux-mips.org
      Cc: linux-kernel@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/15788/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      db8466c5
    • H
      MIPS: Check TLB before handle_ri_rdhwr() for Loongson-3 · 5a341331
      Huacai Chen 提交于
      Loongson-3's micro TLB (ITLB) is not strictly a subset of JTLB. That
      means: when a JTLB entry is replaced by hardware, there may be an old
      valid entry exists in ITLB. So, a TLB miss exception may occur while
      handle_ri_rdhwr() is running because it try to access EPC's content.
      However, handle_ri_rdhwr() doesn't clear EXL, which makes a TLB Refill
      exception be treated as a TLB Invalid exception and tlbp may fail. In
      this case, if FTLB (which is usually set-associative instead of set-
      associative) is enabled, a tlbp failure will cause an invalid tlbwi,
      which will hang the whole system.
      
      This patch rename handle_ri_rdhwr_vivt to handle_ri_rdhwr_tlbp and use
      it for Loongson-3. It try to solve the same problem described as below,
      but more straightforwards.
      
      https://patchwork.linux-mips.org/patch/12591/
      
      I think Loongson-2 has the same problem, but it has no FTLB, so we just
      keep it as is.
      Signed-off-by: NHuacai Chen <chenhc@lemote.com>
      Cc: Rui Wang <wangr@lemote.com>
      Cc: John Crispin <john@phrozen.org>
      Cc: Steven J . Hill <Steven.Hill@caviumnetworks.com>
      Cc: Fuxin Zhang <zhangfx@lemote.com>
      Cc: Zhangjin Wu <wuzhangjin@gmail.com>
      Cc: Huacai Chen <chenhc@lemote.com>
      Cc: linux-mips@linux-mips.org
      Cc: stable@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/15753/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      5a341331
    • H
      MIPS: Add MIPS_CPU_FTLB for Loongson-3A R2 · 033cffee
      Huacai Chen 提交于
      Loongson-3A R2 and newer CPU have FTLB, but Config0.MT is 1, so add
      MIPS_CPU_FTLB to the CPU options.
      Signed-off-by: NHuacai Chen <chenhc@lemote.com>
      Cc: John Crispin <john@phrozen.org>
      Cc: Steven J . Hill <Steven.Hill@caviumnetworks.com>
      Cc: Fuxin Zhang <zhangfx@lemote.com>
      Cc: Zhangjin Wu <wuzhangjin@gmail.com>
      Cc: linux-mips@linux-mips.org
      Cc: stable@vger.kernel.org
      Patchwork: https://patchwork.linux-mips.org/patch/15752/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      033cffee
    • M
      MIPS: smp-cps: Fix retrieval of VPE mask on big endian CPUs · fb2155e3
      Matt Redfearn 提交于
      The vpe_mask member of struct core_boot_config is of type atomic_t,
      which is a 32bit type. In cps-vec.S this member was being retrieved by a
      PTR_L macro, which on 64bit systems is a 64bit load. On little endian
      systems this is OK, since the double word that is retrieved will have
      the required less significant word in the correct position. However, on
      big endian systems the less significant word of the load is retrieved
      from address+4, and the more significant from address+0. The destination
      register therefore ends up with the required word in the more
      significant word
      e.g. when starting the second VP of a big endian 64bit system, the load
      
      PTR_L    ta2, COREBOOTCFG_VPEMASK(a0)
      
      ends up setting register ta2 to 0x0000000300000000
      
      When this value is written to the CPC it is ignored, since it is
      invalid to write anything larger than 4 bits. This results in any VP
      other than VP0 in a core failing to start in 64bit big endian systems.
      
      Change the load to a 32bit load word instruction to fix the bug.
      
      Fixes: f12401d7 ("MIPS: smp-cps: Pull boot config retrieval out of mips_cps_boot_vpes")
      Signed-off-by: NMatt Redfearn <matt.redfearn@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/15787/Signed-off-by: NRalf Baechle <ralf@linux-mips.org>
      fb2155e3
  17. 08 3月, 2017 2 次提交