[PATCH] powerpc: Fix missing declaration of [en/dis]able_kernel_vsx()

2021-03-09 Thread Christophe Leroy
Add stub instances of enable_kernel_vsx() and disable_kernel_vsx()
when CONFIG_VSX is not set, to avoid following build failure.

  CC [M]  drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.o
In file included from 
./drivers/gpu/drm/amd/amdgpu/../display/dc/dm_services_types.h:29,
 from 
./drivers/gpu/drm/amd/amdgpu/../display/dc/dm_services.h:37,
 from 
drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:27:
drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c: In function 
'dcn_bw_apply_registry_override':
./drivers/gpu/drm/amd/amdgpu/../display/dc/os_types.h:64:3: error: implicit 
declaration of function 'enable_kernel_vsx'; did you mean 'enable_kernel_fp'? 
[-Werror=implicit-function-declaration]
   64 |   enable_kernel_vsx(); \
  |   ^
drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:640:2: note: in 
expansion of macro 'DC_FP_START'
  640 |  DC_FP_START();
  |  ^~~
./drivers/gpu/drm/amd/amdgpu/../display/dc/os_types.h:75:3: error: implicit 
declaration of function 'disable_kernel_vsx'; did you mean 'disable_kernel_fp'? 
[-Werror=implicit-function-declaration]
   75 |   disable_kernel_vsx(); \
  |   ^~
drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:676:2: note: in 
expansion of macro 'DC_FP_END'
  676 |  DC_FP_END();
  |  ^
cc1: some warnings being treated as errors
make[5]: *** [drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.o] Error 
1

Fixes: 16a9dea110a6 ("amdgpu: Enable initial DCN support on POWER")
Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/switch_to.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/include/asm/switch_to.h 
b/arch/powerpc/include/asm/switch_to.h
index fdab93428372..9d1fbd8be1c7 100644
--- a/arch/powerpc/include/asm/switch_to.h
+++ b/arch/powerpc/include/asm/switch_to.h
@@ -71,6 +71,16 @@ static inline void disable_kernel_vsx(void)
 {
msr_check_and_clear(MSR_FP|MSR_VEC|MSR_VSX);
 }
+#else
+static inline void enable_kernel_vsx(void)
+{
+   BUILD_BUG();
+}
+
+static inline void disable_kernel_vsx(void)
+{
+   BUILD_BUG();
+}
 #endif
 
 #ifdef CONFIG_SPE
-- 
2.25.0



Re: [PATCH 2/2] KVM: arm64: Skip the cache flush when coalescing tables into a block

2021-03-09 Thread Marc Zyngier
On Tue, 09 Mar 2021 08:34:43 +,
"wangyanan (Y)"  wrote:
> 
> 
> On 2021/3/9 0:34, Will Deacon wrote:
> > On Mon, Jan 25, 2021 at 10:10:44PM +0800, Yanan Wang wrote:
> >> After dirty-logging is stopped for a VM configured with huge mappings,
> >> KVM will recover the table mappings back to block mappings. As we only
> >> replace the existing page tables with a block entry and the cacheability
> >> has not been changed, the cache maintenance opreations can be skipped.
> >> 
> >> Signed-off-by: Yanan Wang 
> >> ---
> >>   arch/arm64/kvm/mmu.c | 12 +---
> >>   1 file changed, 9 insertions(+), 3 deletions(-)
> >> 
> >> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> >> index 8e8549ea1d70..37b427dcbc4f 100644
> >> --- a/arch/arm64/kvm/mmu.c
> >> +++ b/arch/arm64/kvm/mmu.c
> >> @@ -744,7 +744,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, 
> >> phys_addr_t fault_ipa,
> >>   {
> >>int ret = 0;
> >>bool write_fault, writable, force_pte = false;
> >> -  bool exec_fault;
> >> +  bool exec_fault, adjust_hugepage;
> >>bool device = false;
> >>unsigned long mmu_seq;
> >>struct kvm *kvm = vcpu->kvm;
> >> @@ -872,12 +872,18 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, 
> >> phys_addr_t fault_ipa,
> >>mark_page_dirty(kvm, gfn);
> >>}
> >>   -if (fault_status != FSC_PERM && !device)
> >> +  /*
> >> +   * There is no necessity to perform cache maintenance operations if we
> >> +   * will only replace the existing table mappings with a block mapping.
> >> +   */
> >> +  adjust_hugepage = fault_granule < vma_pagesize ? true : false;
> > nit: you don't need the '? true : false' part
> > 
> > That said, your previous patch checks for 'fault_granule > vma_pagesize',
> > so I'm not sure the local variable helps all that much here because it
> > obscures the size checks in my opinion. It would be more straight-forward
> > if we could structure the logic as:
> > 
> > 
> > if (fault_granule < vma_pagesize) {
> > 
> > } else if (fault_granule > vma_page_size) {
> > 
> > } else {
> > 
> > }
> > 
> > With some comments describing what we can infer about the memcache and cache
> > maintenance requirements for each case.
> Thanks for your suggestion here, Will.
> But I have resent another newer series [1] (KVM: arm64: Improve
> efficiency of stage2 page table)
> recently, which has the same theme but different solutions that I
> think are better.
> [1]
> https://lore.kernel.org/lkml/20210208112250.163568-1-wangyana...@huawei.com/
> 
> Could you please comment on that series ?  I think it can be found in
> your inbox :).

There were already a bunch of comments on that series, and I stopped
at the point where the cache maintenance was broken. Please respin
that series if you want further feedback on it.

In the future, if you deprecate a series (which is completely
understandable), please leave a note on the list with a pointer to the
new series so that people don't waste time reviewing an obsolete
series. Or post the new series with a new version number so that it is
obvious that the original series has been superseded.

Thanks,

M.

-- 
Without deviation from the norm, progress is not possible.


[patch V3 0/6] softirq: Add RT specific softirq accounting

2021-03-09 Thread Thomas Gleixner
RT runs softirq processing always in thread context and it requires that
both the softirq execution and the BH disabled sections are preemptible.

This is achieved by serialization through per CPU local locks and
substituting a few parts of the existing softirq processing code with
helper functions.

The series applies on top of

   git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git 
tasklet-2021-03-09

and is completely available from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git softirq

Changes to V2 which can be found here:

  https://lore.kernel.org/r/20201204170151.960336...@linutronix.de

 - Split the tasklet changes out (seperate submission)
 
 - Rebase it on the tasklet series (no further changes)

Thanks,

tglx



[patch V3 1/6] softirq: Add RT specific softirq accounting

2021-03-09 Thread Thomas Gleixner
RT requires the softirq processing and local bottomhalf disabled regions to
be preemptible. Using the normal preempt count based serialization is
therefore not possible because this implicitely disables preemption.

RT kernels use a per CPU local lock to serialize bottomhalfs. As
local_bh_disable() can nest the lock can only be acquired on the outermost
invocation of local_bh_disable() and released when the nest count becomes
zero. Tasks which hold the local lock can be preempted so its required to
keep track of the nest count per task.

Add a RT only counter to task struct and adjust the relevant macros in
preempt.h.

Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Frederic Weisbecker 
---
 include/linux/hardirq.h |1 +
 include/linux/preempt.h |6 +-
 include/linux/sched.h   |3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -79,7 +79,11 @@
 
 #define nmi_count()(preempt_count() & NMI_MASK)
 #define hardirq_count()(preempt_count() & HARDIRQ_MASK)
-#define softirq_count()(preempt_count() & SOFTIRQ_MASK)
+#ifdef CONFIG_PREEMPT_RT
+# define softirq_count()   (current->softirq_disable_cnt & SOFTIRQ_MASK)
+#else
+# define softirq_count()   (preempt_count() & SOFTIRQ_MASK)
+#endif
 #define irq_count()(nmi_count() | hardirq_count() | softirq_count())
 
 /*
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1044,6 +1044,9 @@ struct task_struct {
int softirq_context;
int irq_config;
 #endif
+#ifdef CONFIG_PREEMPT_RT
+   int softirq_disable_cnt;
+#endif
 
 #ifdef CONFIG_LOCKDEP
 # define MAX_LOCK_DEPTH48UL



[patch V3 4/6] softirq: Make softirq control and processing RT aware

2021-03-09 Thread Thomas Gleixner
Provide a local lock based serialization for soft interrupts on RT which
allows the local_bh_disabled() sections and servicing soft interrupts to be
preemptible.

Provide the necessary inline helpers which allow to reuse the bulk of the
softirq processing code.

Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Frederic Weisbecker 
---
 include/linux/bottom_half.h |2 
 kernel/softirq.c|  188 ++--
 2 files changed, 182 insertions(+), 8 deletions(-)

--- a/include/linux/bottom_half.h
+++ b/include/linux/bottom_half.h
@@ -4,7 +4,7 @@
 
 #include 
 
-#ifdef CONFIG_TRACE_IRQFLAGS
+#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_TRACE_IRQFLAGS)
 extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
 #else
 static __always_inline void __local_bh_disable_ip(unsigned long ip, unsigned 
int cnt)
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -103,20 +104,189 @@ EXPORT_PER_CPU_SYMBOL_GPL(hardirq_contex
 #endif
 
 /*
- * preempt_count and SOFTIRQ_OFFSET usage:
- * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
- *   softirq processing.
- * - preempt_count is changed by SOFTIRQ_DISABLE_OFFSET (= 2 * SOFTIRQ_OFFSET)
+ * SOFTIRQ_OFFSET usage:
+ *
+ * On !RT kernels 'count' is the preempt counter, on RT kernels this applies
+ * to a per CPU counter and to task::softirqs_disabled_cnt.
+ *
+ * - count is changed by SOFTIRQ_OFFSET on entering or leaving softirq
+ *   processing.
+ *
+ * - count is changed by SOFTIRQ_DISABLE_OFFSET (= 2 * SOFTIRQ_OFFSET)
  *   on local_bh_disable or local_bh_enable.
+ *
  * This lets us distinguish between whether we are currently processing
  * softirq and whether we just have bh disabled.
  */
+#ifdef CONFIG_PREEMPT_RT
+
+/*
+ * RT accounts for BH disabled sections in task::softirqs_disabled_cnt and
+ * also in per CPU softirq_ctrl::cnt. This is necessary to allow tasks in a
+ * softirq disabled section to be preempted.
+ *
+ * The per task counter is used for softirq_count(), in_softirq() and
+ * in_serving_softirqs() because these counts are only valid when the task
+ * holding softirq_ctrl::lock is running.
+ *
+ * The per CPU counter prevents pointless wakeups of ksoftirqd in case that
+ * the task which is in a softirq disabled section is preempted or blocks.
+ */
+struct softirq_ctrl {
+   local_lock_tlock;
+   int cnt;
+};
+
+static DEFINE_PER_CPU(struct softirq_ctrl, softirq_ctrl) = {
+   .lock   = INIT_LOCAL_LOCK(softirq_ctrl.lock),
+};
+
+void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
+{
+   unsigned long flags;
+   int newcnt;
+
+   WARN_ON_ONCE(in_hardirq());
+
+   /* First entry of a task into a BH disabled section? */
+   if (!current->softirq_disable_cnt) {
+   if (preemptible()) {
+   local_lock(_ctrl.lock);
+   /* Required to meet the RCU bottomhalf requirements. */
+   rcu_read_lock();
+   } else {
+   DEBUG_LOCKS_WARN_ON(this_cpu_read(softirq_ctrl.cnt));
+   }
+   }
+
+   /*
+* Track the per CPU softirq disabled state. On RT this is per CPU
+* state to allow preemption of bottom half disabled sections.
+*/
+   newcnt = __this_cpu_add_return(softirq_ctrl.cnt, cnt);
+   /*
+* Reflect the result in the task state to prevent recursion on the
+* local lock and to make softirq_count() & al work.
+*/
+   current->softirq_disable_cnt = newcnt;
+
+   if (IS_ENABLED(CONFIG_TRACE_IRQFLAGS) && newcnt == cnt) {
+   raw_local_irq_save(flags);
+   lockdep_softirqs_off(ip);
+   raw_local_irq_restore(flags);
+   }
+}
+EXPORT_SYMBOL(__local_bh_disable_ip);
+
+static void __local_bh_enable(unsigned int cnt, bool unlock)
+{
+   unsigned long flags;
+   int newcnt;
+
+   DEBUG_LOCKS_WARN_ON(current->softirq_disable_cnt !=
+   this_cpu_read(softirq_ctrl.cnt));
+
+   if (IS_ENABLED(CONFIG_TRACE_IRQFLAGS) && softirq_count() == cnt) {
+   raw_local_irq_save(flags);
+   lockdep_softirqs_on(_RET_IP_);
+   raw_local_irq_restore(flags);
+   }
+
+   newcnt = __this_cpu_sub_return(softirq_ctrl.cnt, cnt);
+   current->softirq_disable_cnt = newcnt;
+
+   if (!newcnt && unlock) {
+   rcu_read_unlock();
+   local_unlock(_ctrl.lock);
+   }
+}
+
+void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
+{
+   bool preempt_on = preemptible();
+   unsigned long flags;
+   u32 pending;
+   int curcnt;
+
+   WARN_ON_ONCE(in_irq());
+   lockdep_assert_irqs_enabled();
+
+   local_irq_save(flags);
+   curcnt = __this_cpu_read(softirq_ctrl.cnt);
+
+  

[patch V3 3/6] softirq: Move various protections into inline helpers

2021-03-09 Thread Thomas Gleixner
To allow reuse of the bulk of softirq processing code for RT and to avoid
#ifdeffery all over the place, split protections for various code sections
out into inline helpers so the RT variant can just replace them in one go.

Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Frederic Weisbecker 
---
 kernel/softirq.c |   39 ---
 1 file changed, 32 insertions(+), 7 deletions(-)

--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -207,6 +207,32 @@ void __local_bh_enable_ip(unsigned long
 }
 EXPORT_SYMBOL(__local_bh_enable_ip);
 
+static inline void softirq_handle_begin(void)
+{
+   __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
+}
+
+static inline void softirq_handle_end(void)
+{
+   __local_bh_enable(SOFTIRQ_OFFSET);
+   WARN_ON_ONCE(in_interrupt());
+}
+
+static inline void ksoftirqd_run_begin(void)
+{
+   local_irq_disable();
+}
+
+static inline void ksoftirqd_run_end(void)
+{
+   local_irq_enable();
+}
+
+static inline bool should_wake_ksoftirqd(void)
+{
+   return true;
+}
+
 static inline void invoke_softirq(void)
 {
if (ksoftirqd_running(local_softirq_pending()))
@@ -319,7 +345,7 @@ asmlinkage __visible void __softirq_entr
 
pending = local_softirq_pending();
 
-   __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
+   softirq_handle_begin();
in_hardirq = lockdep_softirq_start();
account_softirq_enter(current);
 
@@ -370,8 +396,7 @@ asmlinkage __visible void __softirq_entr
 
account_softirq_exit(current);
lockdep_softirq_end(in_hardirq);
-   __local_bh_enable(SOFTIRQ_OFFSET);
-   WARN_ON_ONCE(in_interrupt());
+   softirq_handle_end();
current_restore_flags(old_flags, PF_MEMALLOC);
 }
 
@@ -466,7 +491,7 @@ inline void raise_softirq_irqoff(unsigne
 * Otherwise we wake up ksoftirqd to make sure we
 * schedule the softirq soon.
 */
-   if (!in_interrupt())
+   if (!in_interrupt() && should_wake_ksoftirqd())
wakeup_softirqd();
 }
 
@@ -694,18 +719,18 @@ static int ksoftirqd_should_run(unsigned
 
 static void run_ksoftirqd(unsigned int cpu)
 {
-   local_irq_disable();
+   ksoftirqd_run_begin();
if (local_softirq_pending()) {
/*
 * We can safely run softirq on inline stack, as we are not deep
 * in the task stack here.
 */
__do_softirq();
-   local_irq_enable();
+   ksoftirqd_run_end();
cond_resched();
return;
}
-   local_irq_enable();
+   ksoftirqd_run_end();
 }
 
 #ifdef CONFIG_HOTPLUG_CPU



[patch V3 6/6] rcu: Prevent false positive softirq warning on RT

2021-03-09 Thread Thomas Gleixner
Soft interrupt disabled sections can legitimately be preempted or schedule
out when blocking on a lock on RT enabled kernels so the RCU preempt check
warning has to be disabled for RT kernels.

Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Paul E. McKenney 
---
 include/linux/rcupdate.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -334,7 +334,8 @@ static inline void rcu_preempt_sleep_che
 #define rcu_sleep_check()  \
do {\
rcu_preempt_sleep_check();  \
-   RCU_LOCKDEP_WARN(lock_is_held(_bh_lock_map),\
+   if (!IS_ENABLED(CONFIG_PREEMPT_RT)) \
+   RCU_LOCKDEP_WARN(lock_is_held(_bh_lock_map),\
 "Illegal context switch in RCU-bh read-side 
critical section"); \
RCU_LOCKDEP_WARN(lock_is_held(_sched_lock_map), \
 "Illegal context switch in RCU-sched read-side 
critical section"); \



[patch V3 2/6] irqtime: Make accounting correct on RT

2021-03-09 Thread Thomas Gleixner
vtime_account_irq and irqtime_account_irq() base checks on preempt_count()
which fails on RT because preempt_count() does not contain the softirq
accounting which is seperate on RT.

These checks do not need the full preempt count as they only operate on the
hard and softirq sections.

Use irq_count() instead which provides the correct value on both RT and non
RT kernels. The compiler is clever enough to fold the masking for !RT:

   99b: 65 8b 05 00 00 00 00mov%gs:0x0(%rip),%eax
 - 9a2: 25 ff ff ff 7f  and$0x7fff,%eax
 + 9a2: 25 00 ff ff 00  and$0x00,%eax

Reported-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Frederic Weisbecker 
---
 kernel/sched/cputime.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -60,7 +60,7 @@ void irqtime_account_irq(struct task_str
cpu = smp_processor_id();
delta = sched_clock_cpu(cpu) - irqtime->irq_start_time;
irqtime->irq_start_time += delta;
-   pc = preempt_count() - offset;
+   pc = irq_count() - offset;
 
/*
 * We do not account for softirq time from ksoftirqd here.
@@ -421,7 +421,7 @@ void vtime_task_switch(struct task_struc
 
 void vtime_account_irq(struct task_struct *tsk, unsigned int offset)
 {
-   unsigned int pc = preempt_count() - offset;
+   unsigned int pc = irq_count() - offset;
 
if (pc & HARDIRQ_OFFSET) {
vtime_account_hardirq(tsk);



[patch V3 5/6] tick/sched: Prevent false positive softirq pending warnings on RT

2021-03-09 Thread Thomas Gleixner
On RT a task which has soft interrupts disabled can block on a lock and
schedule out to idle while soft interrupts are pending. This triggers the
warning in the NOHZ idle code which complains about going idle with pending
soft interrupts. But as the task is blocked soft interrupt processing is
temporarily blocked as well which means that such a warning is a false
positive.

To prevent that check the per CPU state which indicates that a scheduled
out task has soft interrupts disabled.

Signed-off-by: Thomas Gleixner 
Tested-by: Sebastian Andrzej Siewior 
Reviewed-by: Frederic Weisbecker 
---
 include/linux/bottom_half.h |6 ++
 kernel/softirq.c|   15 +++
 kernel/time/tick-sched.c|2 +-
 3 files changed, 22 insertions(+), 1 deletion(-)

--- a/include/linux/bottom_half.h
+++ b/include/linux/bottom_half.h
@@ -32,4 +32,10 @@ static inline void local_bh_enable(void)
__local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
 }
 
+#ifdef CONFIG_PREEMPT_RT
+extern bool local_bh_blocked(void);
+#else
+static inline bool local_bh_blocked(void) { return false; }
+#endif
+
 #endif /* _LINUX_BH_H */
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -141,6 +141,21 @@ static DEFINE_PER_CPU(struct softirq_ctr
.lock   = INIT_LOCAL_LOCK(softirq_ctrl.lock),
 };
 
+/**
+ * local_bh_blocked() - Check for idle whether BH processing is blocked
+ *
+ * Returns false if the per CPU softirq::cnt is 0 otherwise true.
+ *
+ * This is invoked from the idle task to guard against false positive
+ * softirq pending warnings, which would happen when the task which holds
+ * softirq_ctrl::lock was the only running task on the CPU and blocks on
+ * some other lock.
+ */
+bool local_bh_blocked(void)
+{
+   return __this_cpu_read(softirq_ctrl.cnt) != 0;
+}
+
 void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
 {
unsigned long flags;
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -973,7 +973,7 @@ static bool can_stop_idle_tick(int cpu,
if (unlikely(local_softirq_pending())) {
static int ratelimit;
 
-   if (ratelimit < 10 &&
+   if (ratelimit < 10 && !local_bh_blocked() &&
(local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
pr_warn("NOHZ tick-stop error: Non-RCU local softirq 
work is pending, handler #%02x!!!\n",
(unsigned int) local_softirq_pending());



Re: [PATCH v9 0/4] Introduce TEE based Trusted Keys support

2021-03-09 Thread Sumit Garg
On Thu, 4 Mar 2021 at 21:14, Jarkko Sakkinen  wrote:
>
> On Thu, Mar 04, 2021 at 03:30:18PM +0530, Sumit Garg wrote:
> > Hi Jarkko,
> >
> > On Mon, 1 Mar 2021 at 18:41, Sumit Garg  wrote:
> > >
> > > Add support for TEE based trusted keys where TEE provides the 
> > > functionality
> > > to seal and unseal trusted keys using hardware unique key. Also, this is
> > > an alternative in case platform doesn't possess a TPM device.
> > >
> > > This patch-set has been tested with OP-TEE based early TA which is already
> > > merged in upstream [1].
> > >
> > > [1] 
> > > https://github.com/OP-TEE/optee_os/commit/f86ab8e7e0de869dfa25ca05a37ee070d7e5b86b
> > >
> > > Changes in v9:
> > > 1. Rebased to latest tpmdd/master.
> > > 2. Defined pr_fmt() and removed redundant tags.
> > > 3. Patch #2: incorporated misc. comments.
> > > 4. Patch #3: incorporated doc changes from Elaine and misc. comments
> > >from Randy.
> > > 5. Patch #4: reverted to separate maintainer entry as per request from
> > >Jarkko.
> > > 6. Added Jarkko's Tested-by: tag on patch #2.
> >
> > It looks like we don't have any further comments on this patch-set. So
> > would you be able to pick up this patch-set?
>
> I'm cool with that - I can pick this for 5.13.
>

Thanks.

-Sumit

> /Jarkko


Re: [PATCH v3 5/7] irqchip/loongson-liointc: irqchip add 2.0 version

2021-03-09 Thread Marc Zyngier
On Sat, 06 Mar 2021 02:36:31 +,
Qing Zhang  wrote:
> 
> Add IO interrupt controller support for Loongson 2k1000, different
> from the 3a series is that 2K1000 has 64 interrupt sources, 0-31
> correspond to the device tree liointc0 device node, and the other
> correspond to liointc1 node.
> 
> Signed-off-by: Jiaxun Yang 
> Signed-off-by: Qing Zhang 
> ---
> 
> v2-v3: No change
> 
>  drivers/irqchip/irq-loongson-liointc.c | 55 +-
>  1 file changed, 46 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-loongson-liointc.c 
> b/drivers/irqchip/irq-loongson-liointc.c
> index 09b91b81851c..1c3c80f7f9f5 100644
> --- a/drivers/irqchip/irq-loongson-liointc.c
> +++ b/drivers/irqchip/irq-loongson-liointc.c
> @@ -20,6 +20,7 @@
>  
>  #define LIOINTC_CHIP_IRQ 32
>  #define LIOINTC_NUM_PARENT 4
> +#define LIOINTC_NUM_CORES4
>  
>  #define LIOINTC_INTC_CHIP_START  0x20
>  
> @@ -42,6 +43,7 @@ struct liointc_handler_data {
>  struct liointc_priv {
>   struct irq_chip_generic *gc;
>   struct liointc_handler_data handler[LIOINTC_NUM_PARENT];
> + void __iomem*core_isr[LIOINTC_NUM_CORES];
>   u8  map_cache[LIOINTC_CHIP_IRQ];
>   boolhas_lpc_irq_errata;
>  };
> @@ -51,11 +53,12 @@ static void liointc_chained_handle_irq(struct irq_desc 
> *desc)
>   struct liointc_handler_data *handler = irq_desc_get_handler_data(desc);
>   struct irq_chip *chip = irq_desc_get_chip(desc);
>   struct irq_chip_generic *gc = handler->priv->gc;
> + int core = get_ebase_cpunum() % LIOINTC_NUM_CORES;
>   u32 pending;
>  
>   chained_irq_enter(chip, desc);
>  
> - pending = readl(gc->reg_base + LIOINTC_REG_INTC_STATUS);
> + pending = readl(handler->priv->core_isr[core]);
>  
>   if (!pending) {
>   /* Always blame LPC IRQ if we have that bug */
> @@ -141,6 +144,15 @@ static void liointc_resume(struct irq_chip_generic *gc)
>  }
>  
>  static const char * const parent_names[] = {"int0", "int1", "int2", "int3"};
> +static const char * const core_reg_names[] = {"isr0", "isr1", "isr2", 
> "isr3"};
> +
> +static void __iomem *liointc_get_reg_byname(struct device_node *node,
> + const char *name)
> +{
> + int index = of_property_match_string(node, "reg-names", name);
> +
> + return of_iomap(node, index);

So if of_property_match_string() returns an error, you feed that error
to of_iomap()? Somehow, I don't think that's a good idea.

> +}
>  
>  static int __init liointc_of_init(struct device_node *node,
> struct device_node *parent)
> @@ -159,10 +171,28 @@ static int __init liointc_of_init(struct device_node 
> *node,
>   if (!priv)
>   return -ENOMEM;
>  
> - base = of_iomap(node, 0);
> - if (!base) {
> - err = -ENODEV;
> - goto out_free_priv;
> + if (of_device_is_compatible(node, "loongson,liointc-2.0")) {
> + base = liointc_get_reg_byname(node, "main");
> + if (!base) {
> + err = -ENODEV;
> + goto out_free_priv;
> + }
> + for (i = 0; i < LIOINTC_NUM_CORES; i++) {
> + priv->core_isr[i] =
> + liointc_get_reg_byname(node, core_reg_names[i]);

Please write assignments on a single line.

Thanks,

M.

-- 
Without deviation from the norm, progress is not possible.


[PATCH v5 0/4] Check codeSigning extended key usage extension

2021-03-09 Thread Lee, Chun-Yi
NIAP PP_OS certification requests that the OS shall validate the
CodeSigning extended key usage extension field for integrity
verifiction of exectable code:

https://www.niap-ccevs.org/MMO/PP/-442-/
FIA_X509_EXT.1.1

This patchset adds the logic for parsing the codeSigning EKU extension
field in X.509. And checking the CodeSigning EKU when verifying
signature of kernel module or kexec PE binary in PKCS#7.

v5:
Fixed the wording in module-signing.rst.

v4:
Fixed the wording in patch description.

v3:
- Add codeSigning EKU to x509.genkey key generation config.
- Add openssl command option example for generating CodeSign EKU to
  module-signing.rst document. 

v2:
Changed the help wording in the Kconfig.

Lee, Chun-Yi (4):
  X.509: Add CodeSigning extended key usage parsing
  PKCS#7: Check codeSigning EKU for kernel module and kexec pe
verification
  modsign: Add codeSigning EKU when generating X.509 key generation
config
  Documentation/admin-guide/module-signing.rst: add openssl command
option example for CodeSign EKU

 Documentation/admin-guide/module-signing.rst |  6 +
 certs/Makefile   |  1 +
 certs/system_keyring.c   |  2 +-
 crypto/asymmetric_keys/Kconfig   |  9 +++
 crypto/asymmetric_keys/pkcs7_trust.c | 37 +---
 crypto/asymmetric_keys/x509_cert_parser.c| 24 ++
 include/crypto/pkcs7.h   |  3 ++-
 include/crypto/public_key.h  |  1 +
 include/linux/oid_registry.h |  5 
 9 files changed, 83 insertions(+), 5 deletions(-)

-- 
2.16.4



Re: [f2fs-dev] [PATCH v2] f2fs: expose # of overprivision segments

2021-03-09 Thread Chao Yu

On 2021/3/4 3:28, Jaegeuk Kim wrote:

This is useful when checking conditions during checkpoint=disable in Android.

Signed-off-by: Jaegeuk Kim 


Reviewed-by: Chao Yu 

Thanks,


Re: [RESEND PATCH v5 1/4] dt-bindings: devfreq: rk3399_dmc: Add rockchip,pmu phandle.

2021-03-09 Thread Chanwoo Choi
On 3/9/21 8:38 AM, Daniel Lezcano wrote:
> From: Enric Balletbo i Serra 
> 
> The Rockchip DMC (Dynamic Memory Interface) needs to access to the PMU
> general register files to know the DRAM type, so add a phandle to the
> syscon that manages these registers.
> 
> Signed-off-by: Enric Balletbo i Serra 
> Reviewed-by: Chanwoo Choi 
> Acked-by: Rob Herring 
> Signed-off-by: Gaël PORTAY 
> Acked-by: MyungJoo Ham 
> Signed-off-by: Daniel Lezcano 
> ---
>  Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt 
> b/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> index a10d1f6d85c6..a41bcfef95c8 100644
> --- a/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> +++ b/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> @@ -12,6 +12,8 @@ Required properties:
>for details.
>  - center-supply:  DMC supply node.
>  - status: Marks the node enabled/disabled.
> +- rockchip,pmu:   Phandle to the syscon managing the "PMU 
> general register
> +  files".
>  
>  Optional properties:
>  - interrupts: The CPU interrupt number. The interrupt 
> specifier
> 

Applied it. Thanks.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


[PATCH] x86/kaslr: Assign boolean values to a bool variable

2021-03-09 Thread Jiapeng Chong
Fix the following coccicheck warnings:

./arch/x86/boot/compressed/kaslr.c:642:10-11: WARNING: return of 0/1 in
function 'process_mem_region' with return type bool.

Reported-by: Abaci Robot 
Signed-off-by: Jiapeng Chong 
---
 arch/x86/boot/compressed/kaslr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index b92fffb..e366907 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -639,9 +639,9 @@ static bool process_mem_region(struct mem_vector *region,
 
if (slot_area_index == MAX_SLOT_AREA) {
debug_putstr("Aborted e820/efi memmap scan (slot_areas 
full)!\n");
-   return 1;
+   return true;
}
-   return 0;
+   return false;
}
 
 #if defined(CONFIG_MEMORY_HOTREMOVE) && defined(CONFIG_ACPI)
-- 
1.8.3.1



Re: [RESEND PATCH v5 4/4] dt-bindings: devfreq: rk3399_dmc: Remove references of unexistant defines

2021-03-09 Thread Chanwoo Choi
On 3/9/21 8:38 AM, Daniel Lezcano wrote:
> From: Gaël PORTAY 
> 
> Those DDR related defines do not exist. Replace their references with
> their numerical constant.
> 
> Signed-off-by: Gaël PORTAY 
> Reviewed-by: Rob Herring 
> Signed-off-by: Daniel Lezcano 
> ---
>  .../bindings/devfreq/rk3399_dmc.txt   | 73 +--
>  1 file changed, 34 insertions(+), 39 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt 
> b/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> index a41bcfef95c8..ddde2c4f97df 100644
> --- a/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> +++ b/Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
> @@ -79,24 +79,23 @@ Following properties relate to DDR timing:
>  
>  - rockchip,ddr3_drv :  When the DRAM type is DDR3, this 
> parameter defines
> the DRAM side driver strength in ohms. Default
> -   value is DDR3_DS_40ohm.
> +   value is 40.
>  
>  - rockchip,ddr3_odt :  When the DRAM type is DDR3, this 
> parameter defines
> the DRAM side ODT strength in ohms. Default 
> value
> -   is DDR3_ODT_120ohm.
> +   is 120.
>  
>  - rockchip,phy_ddr3_ca_drv :   When the DRAM type is DDR3, this parameter 
> defines
> the phy side CA line (incluing command line,
> address line and clock line) driver strength.
> -   Default value is PHY_DRV_ODT_40.
> +   Default value is 40.
>  
>  - rockchip,phy_ddr3_dq_drv :   When the DRAM type is DDR3, this parameter 
> defines
> the PHY side DQ line (including DQS/DQ/DM 
> line)
> -   driver strength. Default value is 
> PHY_DRV_ODT_40.
> +   driver strength. Default value is 40.
>  
>  - rockchip,phy_ddr3_odt :  When the DRAM type is DDR3, this parameter 
> defines
> -   the PHY side ODT strength. Default value is
> -   PHY_DRV_ODT_240.
> +   the PHY side ODT strength. Default value is 
> 240.
>  
>  - rockchip,lpddr3_odt_dis_freq : When the DRAM type is LPDDR3, this 
> parameter defines
> then ODT disable frequency in MHz (Mega Hz).
> @@ -106,25 +105,23 @@ Following properties relate to DDR timing:
>  
>  - rockchip,lpddr3_drv :When the DRAM type is LPDDR3, this 
> parameter defines
> the DRAM side driver strength in ohms. Default
> -   value is LP3_DS_34ohm.
> +   value is 34.
>  
>  - rockchip,lpddr3_odt :When the DRAM type is LPDDR3, this 
> parameter defines
> the DRAM side ODT strength in ohms. Default 
> value
> -   is LP3_ODT_240ohm.
> +   is 240.
>  
>  - rockchip,phy_lpddr3_ca_drv : When the DRAM type is LPDDR3, this 
> parameter defines
> the PHY side CA line (including command line,
> address line and clock line) driver strength.
> -   Default value is PHY_DRV_ODT_40.
> +   Default value is 40.
>  
>  - rockchip,phy_lpddr3_dq_drv : When the DRAM type is LPDDR3, this 
> parameter defines
> the PHY side DQ line (including DQS/DQ/DM 
> line)
> -   driver strength. Default value is
> -   PHY_DRV_ODT_40.
> +   driver strength. Default value is 40.
>  
>  - rockchip,phy_lpddr3_odt :When dram type is LPDDR3, this parameter 
> define
> -   the phy side odt strength, default value is
> -   PHY_DRV_ODT_240.
> +   the phy side odt strength, default value is 
> 240.
>  
>  - rockchip,lpddr4_odt_dis_freq : When the DRAM type is LPDDR4, this parameter
> defines the ODT disable frequency in
> @@ -134,32 +131,30 @@ Following properties relate to DDR timing:
>  
>  - rockchip,lpddr4_drv :When the DRAM type is LPDDR4, this 
> parameter defines
> the DRAM side driver strength in ohms. Default
> -   value is LP4_PDDS_60ohm.
> +   value is 60.
>  
>  - rockchip,lpddr4_dq_odt : When the DRAM type is LPDDR4, this parameter 
> defines
> the DRAM side ODT on DQS/DQ line strength in 
> ohms.
> -   Default value is LP4_DQ_ODT_40ohm.
> +

Re: [PATCH] scsi:ufs: remove duplicate include in ufshcd

2021-03-09 Thread Bean Huo
On Sat, 2021-03-06 at 03:47 -0800, menglong8.d...@gmail.com wrote:
> From: Zhang Yunkai 
> 
> 
> 
> 'blkdev.h' included in 'ufshcd.c' is duplicated.
> 
> It is also included in the 18th line.
> 
> 
> 
> Signed-off-by: Zhang Yunkai 
Reviewed-by: Bean Huo 



Re: [PATCH v14 0/8] arm64: ARMv8.5-A: MTE: Add async mode support

2021-03-09 Thread Vincenzo Frascino
Hi Andrey,

On 3/8/21 9:02 PM, Andrey Konovalov wrote:
> On Mon, Mar 8, 2021 at 5:14 PM Vincenzo Frascino
>  wrote:
>>
>> This patchset implements the asynchronous mode support for ARMv8.5-A
>> Memory Tagging Extension (MTE), which is a debugging feature that allows
>> to detect with the help of the architecture the C and C++ programmatic
>> memory errors like buffer overflow, use-after-free, use-after-return, etc.
>>
>> MTE is built on top of the AArch64 v8.0 virtual address tagging TBI
>> (Top Byte Ignore) feature and allows a task to set a 4 bit tag on any
>> subset of its address space that is multiple of a 16 bytes granule. MTE
>> is based on a lock-key mechanism where the lock is the tag associated to
>> the physical memory and the key is the tag associated to the virtual
>> address.
>> When MTE is enabled and tags are set for ranges of address space of a task,
>> the PE will compare the tag related to the physical memory with the tag
>> related to the virtual address (tag check operation). Access to the memory
>> is granted only if the two tags match. In case of mismatch the PE will raise
>> an exception.
>>
>> The exception can be handled synchronously or asynchronously. When the
>> asynchronous mode is enabled:
>>   - Upon fault the PE updates the TFSR_EL1 register.
>>   - The kernel detects the change during one of the following:
>> - Context switching
>> - Return to user/EL0
>> - Kernel entry from EL1
>> - Kernel exit to EL1
>>   - If the register has been updated by the PE the kernel clears it and
>> reports the error.
>>
>> The series is based on linux-next/akpm.
>>
>> To simplify the testing a tree with the new patches on top has been made
>> available at [1].
>>
>> [1] https://git.gitlab.arm.com/linux-arm/linux-vf.git mte/v12.async.akpm
> 
> Hi Vincenzo,
> 
> As previously discussed, here's the tree with tests support added to
> this series:
> 
> https://github.com/xairy/linux/tree/vf-v12.async.akpm-tests
> 
> Please take a look at the last two patches. Feel free to include them
> into v15 if they look good.
> 
> Thanks!
> 

Thank you for this. I will definitely have a look and include them.
Based on the review process, I am planning to have another version early next 
week.

-- 
Regards,
Vincenzo


Re: [PATCH 5.10 00/42] 5.10.22-rc1 review

2021-03-09 Thread Greg Kroah-Hartman
On Tue, Mar 09, 2021 at 09:08:20AM +0800, Samuel Zou wrote:
> 
> 
> On 2021/3/8 20:30, Greg Kroah-Hartman wrote:
> > This is the start of the stable review cycle for the 5.10.22 release.
> > There are 42 patches in this series, all will be posted as a response
> > to this one.  If anyone has any issues with these being applied, please
> > let me know.
> > 
> > Responses should be made by Wed, 10 Mar 2021 12:27:05 +.
> > Anything received after that time might be too late.
> > 
> > The whole patch series can be found in one patch at:
> > 
> > https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.22-rc1.gz
> > or in the git tree and branch at:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> > linux-5.10.y
> > and the diffstat can be found below.
> > 
> > thanks,
> > 
> > greg k-h
> 
> Tested on arm64 and x86 for 5.10.22-rc1,
> 
> Kernel repo:
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
> Branch: linux-5.10.y
> Version: 5.10.22-rc1+
> Commit: 9226165b6cc7667b147e1de52090d1b6a17af336
> Compiler: gcc version 7.3.0 (GCC)
> 
> 
> arm64 (No kernel failures)
> 
> Testcase Result Summary:
> total_num: 4710
> succeed_num: 4709
> failed_num: 1
> timeout_num: 0
> 
> x86 (No kernel failures)
> 
> Testcase Result Summary:
> total_num: 4710
> succeed_num: 4709
> failed_num: 1
> timeout_num: 0
> 
> Tested-by: Hulk Robot 

thanks for testing 2 of these and letting me know.

greg k-h


Re: [PATCH 5.10 00/42] 5.10.22-rc1 review

2021-03-09 Thread Greg Kroah-Hartman
On Tue, Mar 09, 2021 at 09:08:20AM +0800, Samuel Zou wrote:
> 
> 
> On 2021/3/8 20:30, Greg Kroah-Hartman wrote:
> > This is the start of the stable review cycle for the 5.10.22 release.
> > There are 42 patches in this series, all will be posted as a response
> > to this one.  If anyone has any issues with these being applied, please
> > let me know.
> > 
> > Responses should be made by Wed, 10 Mar 2021 12:27:05 +.
> > Anything received after that time might be too late.
> > 
> > The whole patch series can be found in one patch at:
> > 
> > https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.22-rc1.gz
> > or in the git tree and branch at:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> > linux-5.10.y
> > and the diffstat can be found below.
> > 
> > thanks,
> > 
> > greg k-h
> 
> Tested on arm64 and x86 for 5.10.22-rc1,
> 
> Kernel repo:
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
> Branch: linux-5.10.y
> Version: 5.10.22-rc1+
> Commit: 9226165b6cc7667b147e1de52090d1b6a17af336
> Compiler: gcc version 7.3.0 (GCC)
> 
> 
> arm64 (No kernel failures)
> 
> Testcase Result Summary:
> total_num: 4710
> succeed_num: 4709
> failed_num: 1

What does "failed_num" mean?

thanks,

greg k-h


Re: [PATCH 5.11 00/44] 5.11.5-rc1 review

2021-03-09 Thread Greg Kroah-Hartman
On Tue, Mar 09, 2021 at 09:52:04AM +0530, Naresh Kamboju wrote:
> On Mon, 8 Mar 2021 at 18:06,  wrote:
> >
> > From: Greg Kroah-Hartman 
> >
> > This is the start of the stable review cycle for the 5.11.5 release.
> > There are 44 patches in this series, all will be posted as a response
> > to this one.  If anyone has any issues with these being applied, please
> > let me know.
> >
> > Responses should be made by Wed, 10 Mar 2021 12:27:05 +.
> > Anything received after that time might be too late.
> >
> > The whole patch series can be found in one patch at:
> > 
> > https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.11.5-rc1.gz
> > or in the git tree and branch at:
> > 
> > git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
> > linux-5.11.y
> > and the diffstat can be found below.
> >
> > thanks,
> >
> > greg k-h
> 
> Results from Linaro’s test farm.
> No regressions on arm64, arm, x86_64, and i386.
> 
> Tested-by: Linux Kernel Functional Testing 

thanks for testing them all and letting me know.

greg k-h


Re: [PATCH 4.4 0/3] Backport patch series to update Futex from 4.9

2021-03-09 Thread Greg KH
On Tue, Mar 09, 2021 at 11:06:02AM +0800, Zheng Yejian wrote:
> Lee sent a patchset to update Futex for 4.9, see 
> https://www.spinics.net/lists/stable/msg443081.html,
> Then Xiaoming sent a follow-up patch for it, see 
> https://lore.kernel.org/lkml/20210225093120.GD641347@dell/.
> 
> These patchsets may also resolve following issues in 4.4.260 which have been 
> reported in 4.9,
> see 
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/?h=linux-4.4.y=319f66f08de1083c1fe271261665c209009dd65a
>   > /*
>   >  * The task is on the way out. When the futex state is
>   >  * FUTEX_STATE_DEAD, we know that the task has finished
>   >  * the cleanup:
>   >  */
>   > int ret = (p->futex_state = FUTEX_STATE_DEAD) ? -ESRCH : -EAGAIN;
> 
> Here may be:
>   int ret = (p->futex_state == FUTEX_STATE_DEAD) ? -ESRCH : -EAGAIN;
> 
>   > raw_spin_unlock_irq(>pi_lock);
>   > /*
>   >  * If the owner task is between FUTEX_STATE_EXITING and
>   >  * FUTEX_STATE_DEAD then store the task pointer and keep
>   >  * the reference on the task struct. The calling code will
>   >  * drop all locks, wait for the task to reach
>   >  * FUTEX_STATE_DEAD and then drop the refcount. This is
>   >  * required to prevent a live lock when the current task
>   >  * preempted the exiting task between the two states.
>   >  */
>   > if (ret == -EBUSY)
> 
> And here, the variable "ret" may only be "-ESRCH" or "-EAGAIN", but not 
> "-EBUSY".
> 
>   >   *exiting = p;
>   > else
>   >   put_task_struct(p);
> 
> Since 074e7d515783 ("futex: Ensure the correct return value from 
> futex_lock_pi()") has
> been merged in 4.4.260, I send the remain 3 patches.

There already are 2 futex patches in the 4.4.y stable queue, do those
not resolve these issues for you?

If not, please resend this series with the needed git commit ids added to
them.

thanks,

greg k-h


Re: [PATCH 4.4 3/3] futex: fix dead code in attach_to_pi_owner()

2021-03-09 Thread Greg KH
On Tue, Mar 09, 2021 at 11:06:05AM +0800, Zheng Yejian wrote:
> From: Thomas Gleixner 
> 
> The handle_exit_race() function is defined in commit 9c3f39860367
>  ("futex: Cure exit race"), which never returns -EBUSY. This results
> in a small piece of dead code in the attach_to_pi_owner() function:
> 
>   int ret = handle_exit_race(uaddr, uval, p); /* Never return -EBUSY */
>   ...
>   if (ret == -EBUSY)
>   *exiting = p; /* dead code */
> 
> The return value -EBUSY is added to handle_exit_race() in upsteam
> commit ac31c7ff8624409 ("futex: Provide distinct return value when
> owner is exiting"). This commit was incorporated into v4.9.255, before
> the function handle_exit_race() was introduced, whitout Modify
> handle_exit_race().
> 
> To fix dead code, extract the change of handle_exit_race() from
> commit ac31c7ff8624409 ("futex: Provide distinct return value when owner
>  is exiting"), re-incorporated.
> 
> Lee writes:
> 
> This commit takes the remaining functional snippet of:
> 
>  ac31c7ff8624409 ("futex: Provide distinct return value when owner is 
> exiting")
> 
> ... and is the correct fix for this issue.
> 
> Fixes: 9c3f39860367 ("futex: Cure exit race")
> Cc: sta...@vger.kernel.org # v4.9.258
> Signed-off-by: Xiaoming Ni 
> Reviewed-by: Lee Jones 
> Signed-off-by: Greg Kroah-Hartman 
> Signed-off-by: Zheng Yejian 
> ---
>  kernel/futex.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Same here, what is the upstream git id?

thanks,

greg k-h


Re: [PATCH v1 1/7] pps: clients: gpio: Bail out on error when requesting GPIO echo line

2021-03-09 Thread Rodolfo Giometti
On 09/03/21 11:47, Andy Shevchenko wrote:
> +Cc: Greg
> 
> On Fri, Feb 26, 2021 at 07:03:32PM +0200, Andy Shevchenko wrote:
>> On Tue, Feb 16, 2021 at 01:31:48PM +0200, Andy Shevchenko wrote:
>>> When requesting optional GPIO echo line, bail out on error,
>>> so user will know that something wrong with the existing property.
>>
>> Guys, any comments on this series?
> 
> Greg, seems PPS maintainer keeps silent, can I route this series thru one of
> yours tree (resend implied)?

I'm sorry but I suppose I missed this patch... -_-'

Can you please resend it to me?

Ciao,

Rodolfo

-- 
GNU/Linux Solutions  e-mail: giome...@enneenne.com
Linux Device Driver  giome...@linux.it
Embedded Systems phone:  +39 349 2432127
UNIX programming skype:  rodolfo.giometti


RE: [PATCH] dt-bindings: spi: Convert NXP flexspi to json schema

2021-03-09 Thread Kuldeep Singh
+ Mark (Forgot to add him previously)

> -Original Message-
> From: Kuldeep Singh 
> Sent: Tuesday, March 9, 2021 4:05 PM
> To: Rob Herring ; linux-...@vger.kernel.org;
> devicet...@vger.kernel.org; linux-kernel@vger.kernel.org
> Cc: Ashish Kumar ; Kuldeep Singh
> 
> Subject: [PATCH] dt-bindings: spi: Convert NXP flexspi to json schema
> 
> Convert the NXP FlexSPI binding to DT schema format using json-schema.
> 
> Signed-off-by: Kuldeep Singh 
> 

Hi Rob and Mark,
I was not sure with which tree this patch will go through.
Currently, I have rebased this on top of 
tree(git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git, branch: 
for-next)

Regards
Kuldeep


Re: [PATCH v1 2/2] iio: adc: add ADC driver for the TI TSC2046 controller

2021-03-09 Thread Oleksij Rempel
On Tue, Mar 09, 2021 at 01:05:27PM +0200, Andy Shevchenko wrote:
> On Fri, Mar 5, 2021 at 9:05 PM Jonathan Cameron
>  wrote:
> >
> > On Fri, 5 Mar 2021 14:38:13 +0100
> > Oleksij Rempel  wrote:
> >
> > > Basically the TI TSC2046 touchscreen controller is 8 channel ADC 
> > > optimized for
> > > the touchscreen use case. By implementing it as IIO ADC device, we can
> > > make use of resistive-adc-touch and iio-hwmon drivers.
> > >
> > > So far, this driver was tested with custom version of resistive-adc-touch 
> > > driver,
> > > since it need to be extended to make use of Z1 and Z2 channels. The X/Y
> > > are working without additional changes.
> > >
> > > Signed-off-by: Oleksij Rempel 
> >
> > Hi Oleksij,
> >
> > To consider this as a possible long term route instead of just making this
> > a touchscreen driver, we'll want to see those mods to the 
> > resistive-adc-touch.
> > Of course that doesn't stop review of this in the meantime.
> >
> > There are quite a few things in here that feel pretty specific to the 
> > touchscreen
> > usecase. That makes me wonder if this is a sensible approach or not.
> 
> I'm wondering if this has any similarities with existing drivers under
> drivers/input/touchscreen.

Yes, for example: drivers/input/touchscreen/ads7846.c

Regards,
Oleksij
-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


[PATCH v2 3/3] scsi: ufshcd: remove version check

2021-03-09 Thread Caleb Connolly
This check is redundant as all UFS versions are currently supported.

Signed-off-by: Nitin Rawat 
Signed-off-by: Caleb Connolly 
---
 drivers/scsi/ufs/ufshcd.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index a458c248e5ef..a6f317f0dc9b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -9291,10 +9291,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem 
*mmio_base, unsigned int irq)
/* Get UFS version supported by the controller */
hba->ufs_version = ufshcd_get_ufs_version(hba);
 
-   if (hba->ufs_version < UFSHCI_VER(1, 0))
-   dev_err(hba->dev, "invalid UFS version 0x%x\n",
-   hba->ufs_version);
-
/* Get Interrupt bit mask per version */
hba->intr_mask = ufshcd_get_intr_mask(hba);
 
-- 
2.29.2




v2: scsi: ufshcd: use a macro for UFS versions

2021-03-09 Thread Caleb Connolly
When using a device with UFS > 2.1 the error "invalid UFS version" is
misleadingly printed. There was a patch for this almost a year
ago to which this solution was suggested.

This series replaces the use of the growing UFSHCI_VERSION_xy macros with
an inline function to encode a major and minor version into the scheme
used on devices, that being:

(major << 8) + (minor << 4)

I dealt with the different encoding used for UFS 1.x by converting it
to match the newer versions in ufshcd_get_ufs_version(). That means it's
possible to use comparisons for version checks, e.g.

if (hba->ufs_version < ufshci_version(3, 0))
...

I've also dropped the "invalid UFS version" check entirely as it seems to
be more misleading than useful, and hasn't been accurate for a long time.

This has been tested on a device with UFS 3.0 and a device with UFS 2.1,
however I don't own any older devices to test with.

Caleb
---
Changes since v1:
 * Switch from macro to static inline function
 * Address Christoph's formatting comments
 * Add Nitin's signoff on patch 3 ("scsi: ufshcd: remove version check")

Caleb Connolly (3):
  scsi: ufshcd: use a function to calculate versions
  scsi: ufs: qcom: use ufshci_version function
  scsi: ufshcd: remove version check

 drivers/scsi/ufs/ufs-qcom.c |  4 +--
 drivers/scsi/ufs/ufshcd.c   | 66 ++---
 drivers/scsi/ufs/ufshci.h   | 17 +++-
 3 files changed, 38 insertions(+), 49 deletions(-)





[PATCH v2 2/3] scsi: ufs: qcom: use ufshci_version function

2021-03-09 Thread Caleb Connolly
Replace the UFSHCI_VERSION_xy macros.

Signed-off-by: Caleb Connolly 
---
 drivers/scsi/ufs/ufs-qcom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ufs/ufs-qcom.c b/drivers/scsi/ufs/ufs-qcom.c
index f97d7b0ae3b6..2d54dce0eeda 100644
--- a/drivers/scsi/ufs/ufs-qcom.c
+++ b/drivers/scsi/ufs/ufs-qcom.c
@@ -809,9 +809,9 @@ static u32 ufs_qcom_get_ufs_hci_version(struct ufs_hba *hba)
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
 
if (host->hw_ver.major == 0x1)
-   return UFSHCI_VERSION_11;
+   return ufshci_version(1, 1);
else
-   return UFSHCI_VERSION_20;
+   return ufshci_version(2, 0);
 }
 
 /**
-- 
2.29.2




[PATCH v2 1/3] scsi: ufshcd: use a function to calculate versions

2021-03-09 Thread Caleb Connolly
Update the driver to use a function for referencing the UFS version.
This replaces the UFSHCI_VERSION_xy macros, and supports comparisons
where they did not.

Suggested-by: Christoph Hellwig 
Signed-off-by: Caleb Connolly 
---
 drivers/scsi/ufs/ufshcd.c | 64 +--
 drivers/scsi/ufs/ufshci.h | 17 ++-
 2 files changed, 37 insertions(+), 44 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 77161750c9fb..a458c248e5ef 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -669,23 +669,12 @@ int ufshcd_wait_for_register(struct ufs_hba *hba, u32 
reg, u32 mask,
  */
 static inline u32 ufshcd_get_intr_mask(struct ufs_hba *hba)
 {
-   u32 intr_mask = 0;
+   if (hba->ufs_version == ufshci_version(1, 0))
+   return INTERRUPT_MASK_ALL_VER_10;
+   if (hba->ufs_version <= ufshci_version(2, 0))
+   return INTERRUPT_MASK_ALL_VER_11;
 
-   switch (hba->ufs_version) {
-   case UFSHCI_VERSION_10:
-   intr_mask = INTERRUPT_MASK_ALL_VER_10;
-   break;
-   case UFSHCI_VERSION_11:
-   case UFSHCI_VERSION_20:
-   intr_mask = INTERRUPT_MASK_ALL_VER_11;
-   break;
-   case UFSHCI_VERSION_21:
-   default:
-   intr_mask = INTERRUPT_MASK_ALL_VER_21;
-   break;
-   }
-
-   return intr_mask;
+   return INTERRUPT_MASK_ALL_VER_21;
 }
 
 /**
@@ -696,10 +685,22 @@ static inline u32 ufshcd_get_intr_mask(struct ufs_hba 
*hba)
  */
 static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba)
 {
+   u32 ufshci_ver;
+
if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION)
-   return ufshcd_vops_get_ufs_hci_version(hba);
+   ufshci_ver = ufshcd_vops_get_ufs_hci_version(hba);
+   else
+   ufshci_ver = ufshcd_readl(hba, REG_UFS_VERSION);
 
-   return ufshcd_readl(hba, REG_UFS_VERSION);
+   /*
+* UFSHCI v1.x uses a different version scheme, in order
+* to allow the use of comparisons with the ufshci_version
+* function, we convert it to the same scheme as ufs 2.0+.
+*/
+   if (ufshci_ver & 0x0001)
+   return ufshci_version(1, ufshci_ver & 0x0100);
+
+   return ufshci_ver;
 }
 
 /**
@@ -931,8 +932,7 @@ static inline bool ufshcd_is_hba_active(struct ufs_hba *hba)
 u32 ufshcd_get_local_unipro_ver(struct ufs_hba *hba)
 {
/* HCI version 1.0 and 1.1 supports UniPro 1.41 */
-   if ((hba->ufs_version == UFSHCI_VERSION_10) ||
-   (hba->ufs_version == UFSHCI_VERSION_11))
+   if (hba->ufs_version <= ufshci_version(1, 1))
return UFS_UNIPRO_VER_1_41;
else
return UFS_UNIPRO_VER_1_6;
@@ -2335,7 +2335,7 @@ static void ufshcd_enable_intr(struct ufs_hba *hba, u32 
intrs)
 {
u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
 
-   if (hba->ufs_version == UFSHCI_VERSION_10) {
+   if (hba->ufs_version == ufshci_version(1, 0)) {
u32 rw;
rw = set & INTERRUPT_MASK_RW_VER_10;
set = rw | ((set ^ intrs) & intrs);
@@ -2355,7 +2355,7 @@ static void ufshcd_disable_intr(struct ufs_hba *hba, u32 
intrs)
 {
u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
 
-   if (hba->ufs_version == UFSHCI_VERSION_10) {
+   if (hba->ufs_version == ufshci_version(1, 0)) {
u32 rw;
rw = (set & INTERRUPT_MASK_RW_VER_10) &
~(intrs & INTERRUPT_MASK_RW_VER_10);
@@ -2518,8 +2518,7 @@ static int ufshcd_compose_devman_upiu(struct ufs_hba *hba,
u8 upiu_flags;
int ret = 0;
 
-   if ((hba->ufs_version == UFSHCI_VERSION_10) ||
-   (hba->ufs_version == UFSHCI_VERSION_11))
+   if (hba->ufs_version <= ufshci_version(1, 1))
lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE;
else
lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
@@ -2546,8 +2545,7 @@ static int ufshcd_comp_scsi_upiu(struct ufs_hba *hba, 
struct ufshcd_lrb *lrbp)
u8 upiu_flags;
int ret = 0;
 
-   if ((hba->ufs_version == UFSHCI_VERSION_10) ||
-   (hba->ufs_version == UFSHCI_VERSION_11))
+   if (hba->ufs_version <= ufshci_version(1, 1))
lrbp->command_type = UTP_CMD_TYPE_SCSI;
else
lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
@@ -6561,15 +6559,10 @@ static int ufshcd_issue_devman_upiu_cmd(struct ufs_hba 
*hba,
ufshcd_prepare_lrbp_crypto(NULL, lrbp);
hba->dev_cmd.type = cmd_type;
 
-   switch (hba->ufs_version) {
-   case UFSHCI_VERSION_10:
-   case UFSHCI_VERSION_11:
+   if (hba->ufs_version <= ufshci_version(1, 1))
lrbp->command_type = UTP_CMD_TYPE_DEV_MANAGE;
-   break;
-   default:
+   else
lrbp->command_type = UTP_CMD_TYPE_UFS_STORAGE;
-   break;
-   }
 

[PATCH v2 14/43] powerpc/32: Always enable data translation in exception prolog

2021-03-09 Thread Christophe Leroy
If the code can use a stack in vm area, it can also use a
stack in linear space.

Simplify code by removing old non VMAP stack code on PPC32.

That means the data translation is now re-enabled early in
exception prolog in all cases, not only when using VMAP stacks.

While we are touching EXCEPTION_PROLOG macros, remove the
unused for_rtas parameter in EXCEPTION_PROLOG_1.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/processor.h |  4 +-
 arch/powerpc/kernel/asm-offsets.c|  2 -
 arch/powerpc/kernel/entry_32.S   | 19 +++
 arch/powerpc/kernel/fpu.S|  2 -
 arch/powerpc/kernel/head_32.h| 85 +---
 arch/powerpc/kernel/head_40x.S   | 23 
 arch/powerpc/kernel/head_8xx.S   | 19 +--
 arch/powerpc/kernel/head_book3s_32.S | 47 +--
 arch/powerpc/kernel/idle_6xx.S   | 12 +---
 arch/powerpc/kernel/idle_e500.S  |  4 +-
 arch/powerpc/kernel/vector.S |  2 -
 arch/powerpc/mm/book3s32/hash_low.S  | 14 -
 12 files changed, 17 insertions(+), 216 deletions(-)

diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index 43cbd9281055..eae16facc390 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -147,11 +147,9 @@ struct thread_struct {
 #ifdef CONFIG_PPC_RTAS
unsigned long   rtas_sp;/* stack pointer for when in RTAS */
 #endif
-#endif
 #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
unsigned long   kuap;   /* opened segments for user access */
 #endif
-#ifdef CONFIG_VMAP_STACK
unsigned long   srr0;
unsigned long   srr1;
unsigned long   dar;
@@ -160,7 +158,7 @@ struct thread_struct {
unsigned long   r0, r3, r4, r5, r6, r8, r9, r11;
unsigned long   lr, ctr;
 #endif
-#endif
+#endif /* CONFIG_PPC32 */
/* Debug Registers */
struct debug_reg debug;
 #ifdef CONFIG_PPC_FPU_REGS
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 73620536c801..85ba2b0bc8d8 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -131,7 +131,6 @@ int main(void)
OFFSET(KSP_VSID, thread_struct, ksp_vsid);
 #else /* CONFIG_PPC64 */
OFFSET(PGDIR, thread_struct, pgdir);
-#ifdef CONFIG_VMAP_STACK
OFFSET(SRR0, thread_struct, srr0);
OFFSET(SRR1, thread_struct, srr1);
OFFSET(DAR, thread_struct, dar);
@@ -148,7 +147,6 @@ int main(void)
OFFSET(THLR, thread_struct, lr);
OFFSET(THCTR, thread_struct, ctr);
 #endif
-#endif
 #ifdef CONFIG_SPE
OFFSET(THREAD_EVR0, thread_struct, evr[0]);
OFFSET(THREAD_ACC, thread_struct, acc);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 66198e6e25e7..33e97032ca25 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -129,7 +129,7 @@ transfer_to_handler:
stw r12,_CTR(r11)
stw r2,_XER(r11)
mfspr   r12,SPRN_SPRG_THREAD
-   tovirt_vmstack r12, r12
+   tovirt(r12, r12)
beq 2f  /* if from user, fix up THREAD.regs */
addir2, r12, -THREAD
addir11,r1,STACK_FRAME_OVERHEAD
@@ -153,8 +153,7 @@ transfer_to_handler:
 transfer_to_handler_cont:
 3:
mflrr9
-   tovirt_novmstack r2, r2 /* set r2 to current */
-   tovirt_vmstack r9, r9
+   tovirt(r9, r9)
lwz r11,0(r9)   /* virtual address of handler */
lwz r9,4(r9)/* where to go when done */
 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
@@ -933,7 +932,6 @@ _GLOBAL(enter_rtas)
lis r6,1f@ha/* physical return address for rtas */
addir6,r6,1f@l
tophys(r6,r6)
-   tophys_novmstack r7, r1
lwz r8,RTASENTRY(r4)
lwz r4,RTASBASE(r4)
mfmsr   r9
@@ -942,22 +940,19 @@ _GLOBAL(enter_rtas)
mtmsr   r0  /* disable interrupts so SRR0/1 don't get trashed */
li  r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
mtlrr6
-   stw r7, THREAD + RTAS_SP(r2)
+   stw r1, THREAD + RTAS_SP(r2)
mtspr   SPRN_SRR0,r8
mtspr   SPRN_SRR1,r9
rfi
-1: tophys_novmstack r9, r1
-#ifdef CONFIG_VMAP_STACK
+1:
li  r0, MSR_KERNEL & ~MSR_IR/* can take DTLB miss */
mtmsr   r0
isync
-#endif
-   lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
-   lwz r9,8(r9)/* original msr value */
+   lwz r8,INT_FRAME_SIZE+4(r1) /* get return address */
+   lwz r9,8(r1)/* original msr value */
addir1,r1,INT_FRAME_SIZE
li  r0,0
-   tophys_novmstack r7, r2
-   stw r0, THREAD + RTAS_SP(r7)
+   stw r0, THREAD + RTAS_SP(r2)
mtspr   SPRN_SRR0,r8
mtspr   SPRN_SRR1,r9
rfi 

[PATCH v2 16/43] powerpc/32: Enable instruction translation at the same time as data translation

2021-03-09 Thread Christophe Leroy
On 40x and 8xx, kernel text is pinned.
On book3s/32, kernel text is mapped by BATs.

Enable instruction translation at the same time as data translation, it
makes things simpler.

In syscall handler, MSR_RI can also be set at the same time because
srr0/srr1 are already saved and r1 is set properly.

On booke, translation is always on, so at the end all PPC32
have translation on early. Just update msr.

Also update comment in power_save_ppc32_restore().

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 30 --
 arch/powerpc/kernel/head_32.h| 13 -
 arch/powerpc/kernel/head_40x.S   | 10 +++---
 arch/powerpc/kernel/head_booke.h |  6 --
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 33e97032ca25..01a064c8a96a 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -153,19 +153,11 @@ transfer_to_handler:
 transfer_to_handler_cont:
 3:
mflrr9
-   tovirt(r9, r9)
lwz r11,0(r9)   /* virtual address of handler */
lwz r9,4(r9)/* where to go when done */
-#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
-   mtspr   SPRN_NRI, r0
-#endif
-   mtspr   SPRN_SRR0,r11
-   mtspr   SPRN_SRR1,r10
+   mtctr   r11
mtlrr9
-   rfi /* jump to handler, enable MMU */
-#ifdef CONFIG_40x
-   b . /* Prevent prefetch past rfi */
-#endif
+   bctr/* jump to handler */
 
 #if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
 4: rlwinm  r12,r12,0,~_TLF_NAPPING
@@ -444,8 +436,6 @@ fee_restarts:
li  r10,-1
stw r10,_TRAP(r11)
addir3,r1,STACK_FRAME_OVERHEAD
-   lis r10,MSR_KERNEL@h
-   ori r10,r10,MSR_KERNEL@l
bl  transfer_to_handler_full
.long   unrecoverable_exception
.long   ret_from_except
@@ -945,16 +935,20 @@ _GLOBAL(enter_rtas)
mtspr   SPRN_SRR1,r9
rfi
 1:
-   li  r0, MSR_KERNEL & ~MSR_IR/* can take DTLB miss */
-   mtmsr   r0
-   isync
+   lis r8, 1f@h
+   ori r8, r8, 1f@l
+   LOAD_REG_IMMEDIATE(r9,MSR_KERNEL)
+   mtspr   SPRN_SRR0,r8
+   mtspr   SPRN_SRR1,r9
+   rfi /* Reactivate MMU translation */
+1:
lwz r8,INT_FRAME_SIZE+4(r1) /* get return address */
lwz r9,8(r1)/* original msr value */
addir1,r1,INT_FRAME_SIZE
li  r0,0
stw r0, THREAD + RTAS_SP(r2)
-   mtspr   SPRN_SRR0,r8
-   mtspr   SPRN_SRR1,r9
-   rfi /* return to caller */
+   mtlrr8
+   mtmsr   r9
+   blr /* return to caller */
 _ASM_NOKPROBE_SYMBOL(enter_rtas)
 #endif /* CONFIG_PPC_RTAS */
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 910f86642eec..88b02bd91e8e 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -63,10 +63,14 @@
mtspr   SPRN_DAR, r11   /* Tag DAR, to be used in DTLB Error */
.endif
 #endif
-   LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_IR | MSR_RI)) /* can take 
DTLB miss */
-   mtmsr   r11
-   isync
+   LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~MSR_RI) /* re-enable MMU */
+   mtspr   SPRN_SRR1, r11
+   lis r11, 1f@h
+   ori r11, r11, 1f@l
+   mtspr   SPRN_SRR0, r11
mfspr   r11, SPRN_SPRG_SCRATCH2
+   rfi
+1:
stw r11,GPR1(r1)
stw r11,0(r1)
mr  r11, r1
@@ -94,7 +98,7 @@
 #elif defined(CONFIG_PPC_8xx)
mtspr   SPRN_EID, r2/* Set MSR_RI */
 #else
-   li  r10, MSR_KERNEL & ~MSR_IR /* can take exceptions */
+   li  r10, MSR_KERNEL /* can take exceptions */
mtmsr   r10 /* (except for mach check in rtas) */
 #endif
stw r0,GPR0(r11)
@@ -179,7 +183,6 @@
 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret)  \
li  r10,trap;   \
stw r10,_TRAP(r11); \
-   LOAD_REG_IMMEDIATE(r10, msr);   \
bl  tfer;   \
.long   hdlr;   \
.long   ret
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 7da673ec63ef..55fa99c5085c 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -126,9 +126,13 @@ _ENTRY(crit_esr)
lwz r11,TASK_STACK-THREAD(r11) /* this thread's kernel stack */
 1: stw r1,crit_r1@l(0)
addir1,r11,THREAD_SIZE-INT_FRAME_SIZE /* Alloc an excpt frm  */
-   LOAD_REG_IMMEDIATE(r11,MSR_KERNEL & ~(MSR_IR | MSR_RI))
-   mtmsr   r11
-   

[PATCH v2 13/43] powerpc/32: Remove ksp_limit

2021-03-09 Thread Christophe Leroy
ksp_limit is there to help detect stack overflows.
That is specific to ppc32 as it was removed from ppc64 in
commit cbc9565ee826 ("powerpc: Remove ksp_limit on ppc64").

There are other means for detecting stack overflows.

As ppc64 has proven to not need it, ppc32 should be able to do
without it too.

Lets remove it and simplify exception handling.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/processor.h |  2 -
 arch/powerpc/kernel/asm-offsets.c|  2 -
 arch/powerpc/kernel/entry_32.S   | 68 +---
 arch/powerpc/kernel/head_40x.S   |  2 -
 arch/powerpc/kernel/head_booke.h |  1 -
 arch/powerpc/kernel/misc_32.S| 14 --
 arch/powerpc/kernel/process.c|  3 --
 arch/powerpc/kernel/traps.c  |  9 
 arch/powerpc/lib/sstep.c |  9 
 9 files changed, 2 insertions(+), 108 deletions(-)

diff --git a/arch/powerpc/include/asm/processor.h 
b/arch/powerpc/include/asm/processor.h
index 8acc3590c971..43cbd9281055 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -144,7 +144,6 @@ struct thread_struct {
 #endif
 #ifdef CONFIG_PPC32
void*pgdir; /* root of page-table tree */
-   unsigned long   ksp_limit;  /* if ksp <= ksp_limit stack overflow */
 #ifdef CONFIG_PPC_RTAS
unsigned long   rtas_sp;/* stack pointer for when in RTAS */
 #endif
@@ -282,7 +281,6 @@ struct thread_struct {
 #ifdef CONFIG_PPC32
 #define INIT_THREAD { \
.ksp = INIT_SP, \
-   .ksp_limit = INIT_SP_LIMIT, \
.pgdir = swapper_pg_dir, \
.fpexc_mode = MSR_FE0 | MSR_FE1, \
SPEFSCR_INIT \
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index f3a662201a9f..73620536c801 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -91,7 +91,6 @@ int main(void)
DEFINE(SIGSEGV, SIGSEGV);
DEFINE(NMI_MASK, NMI_MASK);
 #else
-   OFFSET(KSP_LIMIT, thread_struct, ksp_limit);
 #ifdef CONFIG_PPC_RTAS
OFFSET(RTAS_SP, thread_struct, rtas_sp);
 #endif
@@ -381,7 +380,6 @@ int main(void)
DEFINE(_CSRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
csrr1));
DEFINE(_DSRR0, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
dsrr0));
DEFINE(_DSRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
dsrr1));
-   DEFINE(SAVED_KSP_LIMIT, STACK_INT_FRAME_SIZE+offsetof(struct 
exception_regs, saved_ksp_limit));
 #endif
 #endif
 
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 4ffbcf3df72e..66198e6e25e7 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -94,12 +94,6 @@ crit_transfer_to_handler:
mfspr   r0,SPRN_SRR1
stw r0,_SRR1(r11)
 
-   /* set the stack limit to the current stack */
-   mfspr   r8,SPRN_SPRG_THREAD
-   lwz r0,KSP_LIMIT(r8)
-   stw r0,SAVED_KSP_LIMIT(r11)
-   rlwinm  r0,r1,0,0,(31 - THREAD_SHIFT)
-   stw r0,KSP_LIMIT(r8)
/* fall through */
 _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #endif
@@ -107,12 +101,6 @@ _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #ifdef CONFIG_40x
.globl  crit_transfer_to_handler
 crit_transfer_to_handler:
-   /* set the stack limit to the current stack */
-   mfspr   r8,SPRN_SPRG_THREAD
-   lwz r0,KSP_LIMIT(r8)
-   stw r0,saved_ksp_limit@l(0)
-   rlwinm  r0,r1,0,0,(31 - THREAD_SHIFT)
-   stw r0,KSP_LIMIT(r8)
/* fall through */
 _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #endif
@@ -151,17 +139,10 @@ transfer_to_handler:
 #endif
b   3f
 
-2: /* if from kernel, check interrupted DOZE/NAP mode and
- * check for stack overflow
- */
+   /* if from kernel, check interrupted DOZE/NAP mode */
+2:
kuap_save_and_lock r11, r12, r9, r2, r6
addir2, r12, -THREAD
-#ifndef CONFIG_VMAP_STACK
-   lwz r9,KSP_LIMIT(r12)
-   cmplw   r1,r9   /* if r1 <= ksp_limit */
-   ble-stack_ovf   /* then the kernel stack overflowed */
-#endif
-5:
 #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
lwz r12,TI_LOCAL_FLAGS(r2)
mtcrf   0x01,r12
@@ -204,37 +185,6 @@ transfer_to_handler_cont:
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler)
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
 
-#ifndef CONFIG_VMAP_STACK
-/*
- * On kernel stack overflow, load up an initial stack pointer
- * and call StackOverflow(regs), which should not return.
- */
-stack_ovf:
-   /* sometimes we use a statically-allocated stack, which is OK. */
-   lis r12,_end@h
-   ori r12,r12,_end@l
-   cmplw   r1,r12
-   ble 5b  /* r1 <= &_end is OK */
-   SAVE_NVGPRS(r11)
-   addir3,r1,STACK_FRAME_OVERHEAD
-   lis r1,init_thread_union@ha
-   addi

[PATCH v2 17/43] powerpc/32: Statically initialise first emergency context

2021-03-09 Thread Christophe Leroy
The check of the emergency context initialisation in
vmap_stack_overflow is buggy for the SMP case, as it
compares r1 with 0 while in the SMP case r1 is offseted
by the CPU id.

Instead of fixing it, just perform static initialisation
of the first emergency context.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h  | 6 +-
 arch/powerpc/kernel/setup_32.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 88b02bd91e8e..15c6fc7cbbf5 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -205,11 +205,7 @@
lis r1, emergency_ctx@ha
 #endif
lwz r1, emergency_ctx@l(r1)
-   cmpwi   cr1, r1, 0
-   bne cr1, 1f
-   lis r1, init_thread_union@ha
-   addir1, r1, init_thread_union@l
-1: addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
+   addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
EXCEPTION_PROLOG_2
SAVE_NVGPRS(r11)
addir3, r1, STACK_FRAME_OVERHEAD
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 8ba49a6bf515..d7c1f92152af 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -164,7 +164,7 @@ void __init irqstack_early_init(void)
 }
 
 #ifdef CONFIG_VMAP_STACK
-void *emergency_ctx[NR_CPUS] __ro_after_init;
+void *emergency_ctx[NR_CPUS] __ro_after_init = {[0] = _stack};
 
 void __init emergency_stack_init(void)
 {
-- 
2.25.0



[PATCH v2 20/43] powerpc/32: Move exception prolog code into .text once MMU is back on

2021-03-09 Thread Christophe Leroy
The space in the head section is rather constrained by the fact that
exception vectors are spread every 0x100 bytes and sometimes we
need to have "out of line" code because it doesn't fit.

Now that we are enabling MMU early in the prolog, take that opportunity
to jump somewhere else in the .text section where we don't have any
space constraint.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h|  5 
 arch/powerpc/kernel/head_40x.S   |  6 +
 arch/powerpc/kernel/head_8xx.S   | 25 
 arch/powerpc/kernel/head_book3s_32.S | 34 
 4 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index d97ec94b34da..3c0aa4538514 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -70,6 +70,8 @@
mtspr   SPRN_SRR0, r11
mfspr   r11, SPRN_SPRG_SCRATCH2
rfi
+
+   .text
 1:
stw r11,GPR1(r1)
stw r11,0(r1)
@@ -163,12 +165,14 @@
  */
 #ifdef CONFIG_PPC_BOOK3S
 #defineSTART_EXCEPTION(n, label)   \
+   __HEAD; \
. = n;  \
DO_KVM n;   \
 label:
 
 #else
 #defineSTART_EXCEPTION(n, label)   \
+   __HEAD; \
. = n;  \
 label:
 
@@ -196,6 +200,7 @@
  ret_from_except)
 
 .macro vmap_stack_overflow_exception
+   __HEAD
 vmap_stack_overflow:
 #ifdef CONFIG_SMP
mfspr   r1, SPRN_SPRG_THREAD
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index c14a71e0d6d3..e7d8856714d3 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -132,6 +132,8 @@ _ENTRY(crit_esr)
ori r11, r11, 1f@l
mtspr   SPRN_SRR0, r11
rfi
+
+   .text
 1:
lwz r11,crit_r1@l(0)
stw r11,GPR1(r1)
@@ -496,6 +498,7 @@ _ENTRY(crit_esr)
crit_transfer_to_handler, ret_from_crit_exc)
 
/* Programmable Interval Timer (PIT) Exception. (from 0x1000) */
+   __HEAD
 Decrementer:
EXCEPTION_PROLOG
lis r0,TSR_PIS@h
@@ -504,12 +507,14 @@ Decrementer:
EXC_XFER_LITE(0x1000, timer_interrupt)
 
/* Fixed Interval Timer (FIT) Exception. (from 0x1010) */
+   __HEAD
 FITException:
EXCEPTION_PROLOG
addir3,r1,STACK_FRAME_OVERHEAD;
EXC_XFER_STD(0x1010, unknown_exception)
 
/* Watchdog Timer (WDT) Exception. (from 0x1020) */
+   __HEAD
 WDTException:
CRITICAL_EXCEPTION_PROLOG;
addir3,r1,STACK_FRAME_OVERHEAD;
@@ -523,6 +528,7 @@ WDTException:
  * reserved.
  */
 
+   __HEAD
/* Damn, I came up one instruction too many to fit into the
 * exception space :-).  Both the instruction and data TLB
 * miss get to this point to load the TLB.
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 11789a077d76..d16d0ec71bb2 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -133,7 +133,7 @@ instruction_counter:
START_EXCEPTION(0x600, Alignment)
EXCEPTION_PROLOG handle_dar_dsisr=1
addir3,r1,STACK_FRAME_OVERHEAD
-   b   .Lalignment_exception_ool
+   EXC_XFER_STD(0x600, alignment_exception)
 
 /* Program check exception */
EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
@@ -141,11 +141,6 @@ instruction_counter:
 /* Decrementer */
EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
 
-   /* With VMAP_STACK there's not enough room for this at 0x600 */
-   . = 0xa00
-.Lalignment_exception_ool:
-   EXC_XFER_STD(0x600, alignment_exception)
-
 /* System call */
START_EXCEPTION(0xc00, SystemCall)
SYSCALL_ENTRY   0xc00
@@ -339,26 +334,25 @@ DARFixed:/* Return from dcbx instruction bug workaround */
  * support of breakpoints and such.  Someday I will get around to
  * using them.
  */
-do_databreakpoint:
-   EXCEPTION_PROLOG_1
-   EXCEPTION_PROLOG_2 handle_dar_dsisr=1
-   addir3,r1,STACK_FRAME_OVERHEAD
-   mfspr   r4,SPRN_BAR
-   stw r4,_DAR(r11)
-   EXC_XFER_STD(0x1c00, do_break)
-
START_EXCEPTION(0x1c00, DataBreakpoint)
EXCEPTION_PROLOG_0 handle_dar_dsisr=1
mfspr   r11, SPRN_SRR0
cmplwi  cr1, r11, (.Ldtlbie - PAGE_OFFSET)@l
cmplwi  cr7, r11, (.Litlbie - PAGE_OFFSET)@l
cror4*cr1+eq, 4*cr1+eq, 4*cr7+eq
-   bne cr1, do_databreakpoint
+   bne cr1, 1f
mtcrr10
mfspr   r10, SPRN_SPRG_SCRATCH0
mfspr   r11, SPRN_SPRG_SCRATCH1
rfi
 
+1: EXCEPTION_PROLOG_1
+   EXCEPTION_PROLOG_2 handle_dar_dsisr=1
+   addir3,r1,STACK_FRAME_OVERHEAD
+   mfspr   r4,SPRN_BAR

[PATCH v2 18/43] powerpc/32: Add vmap_stack_overflow label inside the macro

2021-03-09 Thread Christophe Leroy
For consistency, add in the macro the label used by exception prolog
to branch to stack overflow processing.

While at it, enclose the macro in #ifdef CONFIG_VMAP_STACK on the 8xx
as already done on book3s/32.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h| 3 ++-
 arch/powerpc/kernel/head_8xx.S   | 3 ++-
 arch/powerpc/kernel/head_book3s_32.S | 1 -
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 15c6fc7cbbf5..d97ec94b34da 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -52,7 +52,7 @@
 1:
 #ifdef CONFIG_VMAP_STACK
mtcrf   0x3f, r1
-   bt  32 - THREAD_ALIGN_SHIFT, stack_overflow
+   bt  32 - THREAD_ALIGN_SHIFT, vmap_stack_overflow
 #endif
 .endm
 
@@ -196,6 +196,7 @@
  ret_from_except)
 
 .macro vmap_stack_overflow_exception
+vmap_stack_overflow:
 #ifdef CONFIG_SMP
mfspr   r1, SPRN_SPRG_THREAD
lwz r1, TASK_CPU - THREAD(r1)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index cdbfa9d41353..b63445c55f4d 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -338,8 +338,9 @@ DARFixed:/* Return from dcbx instruction bug workaround */
/* 0x300 is DataAccess exception, needed by bad_page_fault() */
EXC_XFER_LITE(0x300, handle_page_fault)
 
-stack_overflow:
+#ifdef CONFIG_VMAP_STACK
vmap_stack_overflow_exception
+#endif
 
 /* On the MPC8xx, these next four traps are used for development
  * support of breakpoints and such.  Someday I will get around to
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 59efbee7c080..9dc05890477d 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -729,7 +729,6 @@ fast_hash_page_return:
 #endif /* CONFIG_PPC_BOOK3S_604 */
 
 #ifdef CONFIG_VMAP_STACK
-stack_overflow:
vmap_stack_overflow_exception
 #endif
 
-- 
2.25.0



[PATCH v2 24/43] powerpc/32: Always save non volatile registers on exception entry

2021-03-09 Thread Christophe Leroy
In preparation of handling exception entry and exit in C,
in order to simplify the handling, always save non volatile registers
when entering an exception.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/ptrace.h |  6 ++
 arch/powerpc/kernel/entry_32.S| 13 +
 arch/powerpc/kernel/head_32.h |  3 +--
 arch/powerpc/kernel/head_booke.h  |  2 +-
 4 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 975ba260006a..0a5d8c6b13c4 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -209,16 +209,14 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
  */
 #define TRAP_FLAGS_MASK0x1F
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
-#define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap |= 1)
+#define FULL_REGS(regs)true
+#define SET_FULL_REGS(regs)do { } while (0)
 #define IS_CRITICAL_EXC(regs)  (((regs)->trap & 2) != 0)
 #define IS_MCHECK_EXC(regs)(((regs)->trap & 4) != 0)
 #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
 #define NV_REG_POISON  0xdeadbeef
 #define CHECK_FULL_REGS(regs)\
 do { \
-   if ((regs)->trap & 1) \
-   printk(KERN_CRIT "%s: partial register set\n", __func__); \
 } while (0)
 #endif /* __powerpc64__ */
 
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index fb849ef922fb..7084289994b3 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -81,12 +81,12 @@ _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
  */
.globl  transfer_to_handler_full
 transfer_to_handler_full:
-   SAVE_NVGPRS(r11)
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
/* fall through */
 
.globl  transfer_to_handler
 transfer_to_handler:
+   SAVE_NVGPRS(r11)
stw r2,GPR2(r11)
stw r12,_NIP(r11)
stw r9,_MSR(r11)
@@ -234,10 +234,6 @@ handle_page_fault:
bl  do_page_fault
cmpwi   r3,0
beq+ret_from_except
-   SAVE_NVGPRS(r1)
-   lwz r0,_TRAP(r1)
-   clrrwi  r0,r0,1
-   stw r0,_TRAP(r1)
mr  r4,r3   /* err arg for bad_page_fault */
addir3,r1,STACK_FRAME_OVERHEAD
bl  __bad_page_fault
@@ -810,13 +806,6 @@ recheck:
 do_user_signal:/* r10 contains MSR_KERNEL here */
ori r10,r10,MSR_EE
mtmsr   r10 /* hard-enable interrupts */
-   /* save r13-r31 in the exception frame, if not already done */
-   lwz r3,_TRAP(r1)
-   andi.   r0,r3,1
-   beq 2f
-   SAVE_NVGPRS(r1)
-   rlwinm  r3,r3,0,0,30
-   stw r3,_TRAP(r1)
 2: addir3,r1,STACK_FRAME_OVERHEAD
mr  r4,r9
bl  do_notify_resume
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index e09585b88ba7..087445e45489 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -198,7 +198,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  ret_from_except_full)
 
 #define EXC_XFER_LITE(n, hdlr) \
-   EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, transfer_to_handler, \
+   EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler, \
  ret_from_except)
 
 .macro vmap_stack_overflow_exception
@@ -215,7 +215,6 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
lwz r1, emergency_ctx@l(r1)
addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
EXCEPTION_PROLOG_2 vmap_stack_overflow
-   SAVE_NVGPRS(r11)
addir3, r1, STACK_FRAME_OVERHEAD
EXC_XFER_STD(0, stack_overflow_exception)
 .endm
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 3707f49f0b78..b31bf9e833c0 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -331,7 +331,7 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
  ret_from_except_full)
 
 #define EXC_XFER_LITE(n, hdlr) \
-   EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, transfer_to_handler, \
+   EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler, \
  ret_from_except)
 
 /* Check for a single step debug exception while in an exception
-- 
2.25.0



[PATCH v2 23/43] powerpc/32: Perform normal function call in exception entry

2021-03-09 Thread Christophe Leroy
Now that the MMU is re-enabled before calling the transfer function,
we don't need anymore that hack with the address of the handler and
the return function sitting just after the 'bl' to the transfer
fonction, that function is retrieving via a read relative to 'lr'.

Do a regular call to the transfer function, then to the handler,
then branch to the return function.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 14 --
 arch/powerpc/kernel/head_32.h|  4 ++--
 arch/powerpc/kernel/head_booke.h |  6 +++---
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index ad1fd33e1126..fb849ef922fb 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -104,7 +104,7 @@ transfer_to_handler:
 #ifdef CONFIG_PPC_BOOK3S_32
kuep_lock r11, r12
 #endif
-   b   3f
+   blr
 
/* if from kernel, check interrupted DOZE/NAP mode */
 2:
@@ -118,13 +118,7 @@ transfer_to_handler:
 #endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
.globl transfer_to_handler_cont
 transfer_to_handler_cont:
-3:
-   mflrr9
-   lwz r11,0(r9)   /* virtual address of handler */
-   lwz r9,4(r9)/* where to go when done */
-   mtctr   r11
-   mtlrr9
-   bctr/* jump to handler */
+   blr
 
 #if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
 4: rlwinm  r12,r12,0,~_TLF_NAPPING
@@ -404,8 +398,8 @@ fee_restarts:
stw r10,_TRAP(r11)
addir3,r1,STACK_FRAME_OVERHEAD
bl  transfer_to_handler_full
-   .long   unrecoverable_exception
-   .long   ret_from_except
+   bl  unrecoverable_exception
+   b   ret_from_except
 #endif
 
.globl  ret_from_except_full
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 160ebd573c37..e09585b88ba7 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -190,8 +190,8 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
li  r10,trap;   \
stw r10,_TRAP(r11); \
bl  tfer;   \
-   .long   hdlr;   \
-   .long   ret
+   bl  hdlr;   \
+   b   ret
 
 #define EXC_XFER_STD(n, hdlr)  \
EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler_full,
\
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index a127d5e7efb4..3707f49f0b78 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -322,9 +322,9 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret)  \
li  r10,trap;   \
stw r10,_TRAP(r11); \
-   bl  tfer;   \
-   .long   hdlr;   \
-   .long   ret
+   bl  tfer;   \
+   bl  hdlr;   \
+   b   ret;\
 
 #define EXC_XFER_STD(n, hdlr)  \
EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler_full, \
-- 
2.25.0



[PATCH v2 25/43] powerpc/32: Replace ASM exception exit by C exception exit from ppc64

2021-03-09 Thread Christophe Leroy
This patch replaces the PPC32 ASM exception exit by C exception exit.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S  | 481 +---
 arch/powerpc/kernel/interrupt.c |   4 +
 2 files changed, 132 insertions(+), 353 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 7084289994b3..d8fd2fd2c777 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -129,9 +129,7 @@ transfer_to_handler_cont:
stw r12,TI_LOCAL_FLAGS(r2)
lwz r9,_MSR(r11)/* if sleeping, clear MSR.EE */
rlwinm  r9,r9,0,~MSR_EE
-   lwz r12,_LINK(r11)  /* and return to address in LR */
-   kuap_restore r11, r2, r3, r4, r5
-   lwz r2, GPR2(r11)
+   stw r9,_MSR(r11)
b   fast_exception_return
 #endif
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler)
@@ -334,69 +332,20 @@ END_FTR_SECTION_IFSET(CPU_FTR_SPE)
 
.globl  fast_exception_return
 fast_exception_return:
+   lwz r6,_MSR(r1)
+   andi.   r0,r6,MSR_PR
+   bne .Lfast_user_interrupt_return
+   li  r3,0 /* 0 return value, no EMULATE_STACK_STORE */
 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
-   andi.   r10,r9,MSR_RI   /* check for recoverable interrupt */
-   beq 1f  /* if not, we've got problems */
-#endif
-
-2: REST_4GPRS(3, r11)
-   lwz r10,_CCR(r11)
-   REST_GPR(1, r11)
-   mtcrr10
-   lwz r10,_LINK(r11)
-   mtlrr10
-   /* Clear the exception_marker on the stack to avoid confusing 
stacktrace */
-   li  r10, 0
-   stw r10, 8(r11)
-   REST_GPR(10, r11)
-#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
-   mtspr   SPRN_NRI, r0
-#endif
-   mtspr   SPRN_SRR1,r9
-   mtspr   SPRN_SRR0,r12
-   REST_GPR(9, r11)
-   REST_GPR(12, r11)
-   lwz r11,GPR11(r11)
-   rfi
-#ifdef CONFIG_40x
-   b . /* Prevent prefetch past rfi */
-#endif
-_ASM_NOKPROBE_SYMBOL(fast_exception_return)
-
-#if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
-/* check if the exception happened in a restartable section */
-1: lis r3,exc_exit_restart_end@ha
-   addir3,r3,exc_exit_restart_end@l
-   cmplw   r12,r3
-   bge 3f
-   lis r4,exc_exit_restart@ha
-   addir4,r4,exc_exit_restart@l
-   cmplw   r12,r4
-   blt 3f
-   lis r3,fee_restarts@ha
-   tophys(r3,r3)
-   lwz r5,fee_restarts@l(r3)
-   addir5,r5,1
-   stw r5,fee_restarts@l(r3)
-   mr  r12,r4  /* restart at exc_exit_restart */
-   b   2b
-
-   .section .bss
-   .align  2
-fee_restarts:
-   .space  4
-   .previous
-
-/* aargh, a nonrecoverable interrupt, panic */
-/* aargh, we don't know which trap this is */
-3:
-   li  r10,-1
-   stw r10,_TRAP(r11)
+   andi.   r0,r6,MSR_RI
+   bne+.Lfast_kernel_interrupt_return
addir3,r1,STACK_FRAME_OVERHEAD
-   bl  transfer_to_handler_full
bl  unrecoverable_exception
-   b   ret_from_except
+   trap/* should not get here */
+#else
+   b   .Lfast_kernel_interrupt_return
 #endif
+_ASM_NOKPROBE_SYMBOL(fast_exception_return)
 
.globl  ret_from_except_full
 ret_from_except_full:
@@ -405,213 +354,146 @@ ret_from_except_full:
 
.globl  ret_from_except
 ret_from_except:
-   /* Hard-disable interrupts so that current_thread_info()->flags
-* can't change between when we test it and when we return
-* from the interrupt. */
-   /* Note: We don't bother telling lockdep about it */
-   LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
-   mtmsr   r10 /* disable interrupts */
-
-   lwz r3,_MSR(r1) /* Returning to user mode? */
-   andi.   r0,r3,MSR_PR
-   beq resume_kernel
-
-user_exc_return:   /* r10 contains MSR_KERNEL here */
-   /* Check current_thread_info()->flags */
-   lwz r9,TI_FLAGS(r2)
-   andi.   r0,r9,_TIF_USER_WORK_MASK
-   bne do_work
-
-restore_user:
-#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
-   /* Check whether this process has its own DBCR0 value.  The internal
-  debug mode bit tells us that dbcr0 should be loaded. */
-   lwz r0,THREAD+THREAD_DBCR0(r2)
-   andis.  r10,r0,DBCR0_IDM@h
-   bnel-   load_dbcr0
-#endif
-   ACCOUNT_CPU_USER_EXIT(r2, r10, r11)
+_ASM_NOKPROBE_SYMBOL(ret_from_except)
+
+   .globl interrupt_return
+interrupt_return:
+   lwz r4,_MSR(r1)
+   andi.   r0,r4,MSR_PR
+   beq .Lkernel_interrupt_return
+   addir3,r1,STACK_FRAME_OVERHEAD
+   bl  interrupt_exit_user_prepare
+   cmpwi   r3,0
+   bne-.Lrestore_nvgprs
+
+.Lfast_user_interrupt_return:
 #ifdef CONFIG_PPC_BOOK3S_32
kuep_unlock r10, r11
 #endif
+   

[PATCH v2 26/43] powerpc/32: Set regs parameter in r3 in transfer_to_handler

2021-03-09 Thread Christophe Leroy
All exception handlers take regs as first parameter.

Instead of setting r3 just before each call to a handler, set
it in transfer_to_handler.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   |  5 ++---
 arch/powerpc/kernel/head_32.h|  2 --
 arch/powerpc/kernel/head_40x.S   |  7 ---
 arch/powerpc/kernel/head_8xx.S   |  3 ---
 arch/powerpc/kernel/head_book3s_32.S |  9 ++---
 arch/powerpc/kernel/head_booke.h | 11 +--
 arch/powerpc/kernel/head_fsl_booke.S |  4 +---
 7 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index d8fd2fd2c777..4698fd1bd8c8 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -87,6 +87,7 @@ _ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
.globl  transfer_to_handler
 transfer_to_handler:
SAVE_NVGPRS(r11)
+   addir3,r1,STACK_FRAME_OVERHEAD
stw r2,GPR2(r11)
stw r12,_NIP(r11)
stw r9,_MSR(r11)
@@ -99,8 +100,7 @@ transfer_to_handler:
tovirt(r12, r12)
beq 2f  /* if from user, fix up THREAD.regs */
addir2, r12, -THREAD
-   addir11,r1,STACK_FRAME_OVERHEAD
-   stw r11,PT_REGS(r12)
+   stw r3,PT_REGS(r12)
 #ifdef CONFIG_PPC_BOOK3S_32
kuep_lock r11, r12
 #endif
@@ -228,7 +228,6 @@ ret_from_kernel_thread:
  */
.globl  handle_page_fault
 handle_page_fault:
-   addir3,r1,STACK_FRAME_OVERHEAD
bl  do_page_fault
cmpwi   r3,0
beq+ret_from_except
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 087445e45489..4d638d760a96 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -183,7 +183,6 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 #define EXCEPTION(n, label, hdlr, xfer)\
START_EXCEPTION(n, label)   \
EXCEPTION_PROLOG label; \
-   addir3,r1,STACK_FRAME_OVERHEAD; \
xfer(n, hdlr)
 
 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret)  \
@@ -215,7 +214,6 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
lwz r1, emergency_ctx@l(r1)
addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
EXCEPTION_PROLOG_2 vmap_stack_overflow
-   addir3, r1, STACK_FRAME_OVERHEAD
EXC_XFER_STD(0, stack_overflow_exception)
 .endm
 
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 86883ccb3dc5..08563d4170c6 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -185,7 +185,6 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 #define CRITICAL_EXCEPTION(n, label, hdlr) \
START_EXCEPTION(n, label);  \
CRITICAL_EXCEPTION_PROLOG label;\
-   addir3,r1,STACK_FRAME_OVERHEAD; \
EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  crit_transfer_to_handler, ret_from_crit_exc)
 
@@ -227,13 +226,11 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 /* 0x0600 - Alignment Exception */
START_EXCEPTION(0x0600, Alignment)
EXCEPTION_PROLOG Alignment handle_dar_dsisr=1
-   addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x600, alignment_exception)
 
 /* 0x0700 - Program Exception */
START_EXCEPTION(0x0700, ProgramCheck)
EXCEPTION_PROLOG ProgramCheck handle_dar_dsisr=1
-   addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x700, program_check_exception)
 
EXCEPTION(0x0800, Trap_08, unknown_exception, EXC_XFER_STD)
@@ -494,7 +491,6 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
/* continue normal handling for a critical exception... */
 2: mfspr   r4,SPRN_DBSR
stw r4,_ESR(r11)/* DebugException takes DBSR in _ESR */
-   addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_TEMPLATE(DebugException, 0x2002, \
(MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
crit_transfer_to_handler, ret_from_crit_exc)
@@ -505,21 +501,18 @@ Decrementer:
EXCEPTION_PROLOG Decrementer
lis r0,TSR_PIS@h
mtspr   SPRN_TSR,r0 /* Clear the PIT exception */
-   addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_LITE(0x1000, timer_interrupt)
 
/* Fixed Interval Timer (FIT) Exception. (from 0x1010) */
__HEAD
 FITException:
EXCEPTION_PROLOG FITException
-   addir3,r1,STACK_FRAME_OVERHEAD;
EXC_XFER_STD(0x1010, unknown_exception)
 
/* Watchdog Timer (WDT) Exception. (from 0x1020) */
__HEAD
 WDTException:
CRITICAL_EXCEPTION_PROLOG WDTException
-   addir3,r1,STACK_FRAME_OVERHEAD;
EXC_XFER_TEMPLATE(WatchdogException, 0x1020+2,
  (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)),
  

[PATCH v2 28/43] powerpc/64e: Call bad_page_fault() from do_page_fault()

2021-03-09 Thread Christophe Leroy
book3e/64 is the last one calling __bad_page_fault()
from assembly.

Save non volatile registers before calling do_page_fault()
and modify do_page_fault() to call __bad_page_fault()
for all platforms.

Then it can be refactored by the call of bad_page_fault()
which avoids the duplication of the exception table search.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/exceptions-64e.S |  8 +---
 arch/powerpc/mm/fault.c  | 17 -
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index e8eb9992a270..b60f89078a3f 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -1010,15 +1010,9 @@ storage_fault_common:
addir3,r1,STACK_FRAME_OVERHEAD
ld  r14,PACA_EXGEN+EX_R14(r13)
ld  r15,PACA_EXGEN+EX_R15(r13)
+   bl  save_nvgprs
bl  do_page_fault
-   cmpdi   r3,0
-   bne-1f
b   ret_from_except_lite
-1: bl  save_nvgprs
-   mr  r4,r3
-   addir3,r1,STACK_FRAME_OVERHEAD
-   bl  __bad_page_fault
-   b   ret_from_except
 
 /*
  * Alignment exception doesn't fit entirely in the 0x100 bytes so it
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 2e54bac99a22..7bcff3fca110 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -541,24 +541,15 @@ NOKPROBE_SYMBOL(___do_page_fault);
 
 static long __do_page_fault(struct pt_regs *regs)
 {
-   const struct exception_table_entry *entry;
long err;
 
err = ___do_page_fault(regs, regs->dar, regs->dsisr);
if (likely(!err))
-   return err;
-
-   entry = search_exception_tables(regs->nip);
-   if (likely(entry)) {
-   instruction_pointer_set(regs, extable_fixup(entry));
return 0;
-   } else if (!IS_ENABLED(CONFIG_PPC_BOOK3E_64)) {
-   __bad_page_fault(regs, err);
-   return 0;
-   } else {
-   /* 32 and 64e handle the bad page fault in asm */
-   return err;
-   }
+
+   bad_page_fault(regs, err);
+
+   return 0;
 }
 NOKPROBE_SYMBOL(__do_page_fault);
 
-- 
2.25.0



[PATCH v2 27/43] powerpc/32: Call bad_page_fault() from do_page_fault()

2021-03-09 Thread Christophe Leroy
Now that non volatile registers are saved at all time, no
need to split bad_page_fault() out of do_page_fault().

Remove handle_page_fault() and use do_page_fault() directly.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 16 
 arch/powerpc/kernel/head_40x.S   |  4 ++--
 arch/powerpc/kernel/head_8xx.S   |  4 ++--
 arch/powerpc/kernel/head_book3s_32.S |  4 ++--
 arch/powerpc/kernel/head_booke.h |  4 ++--
 arch/powerpc/kernel/head_fsl_booke.S |  2 +-
 arch/powerpc/mm/fault.c  |  2 +-
 7 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 4698fd1bd8c8..cb2fa00b8fc1 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -220,22 +220,6 @@ ret_from_kernel_thread:
li  r3,0
b   ret_from_syscall
 
-/*
- * Top-level page fault handling.
- * This is in assembler because if do_page_fault tells us that
- * it is a bad kernel page fault, we want to save the non-volatile
- * registers before calling bad_page_fault.
- */
-   .globl  handle_page_fault
-handle_page_fault:
-   bl  do_page_fault
-   cmpwi   r3,0
-   beq+ret_from_except
-   mr  r4,r3   /* err arg for bad_page_fault */
-   addir3,r1,STACK_FRAME_OVERHEAD
-   bl  __bad_page_fault
-   b   ret_from_except_full
-
 /*
  * This routine switches between two different tasks.  The process
  * state of one is saved on its kernel stack.  Then the state
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 08563d4170c6..a65778380704 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -207,7 +207,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  */
START_EXCEPTION(0x0300, DataStorage)
EXCEPTION_PROLOG DataStorage handle_dar_dsisr=1
-   EXC_XFER_LITE(0x300, handle_page_fault)
+   EXC_XFER_LITE(0x300, do_page_fault)
 
 /*
  * 0x0400 - Instruction Storage Exception
@@ -218,7 +218,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
li  r5,0
stw r5, _ESR(r11)   /* Zero ESR */
stw r12, _DEAR(r11) /* SRR0 as DEAR */
-   EXC_XFER_LITE(0x400, handle_page_fault)
+   EXC_XFER_LITE(0x400, do_page_fault)
 
 /* 0x0500 - External Interrupt Exception */
EXCEPTION(0x0500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index eb1d40a8f2c4..4078d0dc2f18 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -301,7 +301,7 @@ instruction_counter:
 .Litlbie:
stw r12, _DAR(r11)
stw r5, _DSISR(r11)
-   EXC_XFER_LITE(0x400, handle_page_fault)
+   EXC_XFER_LITE(0x400, do_page_fault)
 
 /* This is the data TLB error on the MPC8xx.  This could be due to
  * many reasons, including a dirty update to a pte.  We bail out to
@@ -322,7 +322,7 @@ DARFixed:/* Return from dcbx instruction bug workaround */
tlbie   r4
 .Ldtlbie:
/* 0x300 is DataAccess exception, needed by bad_page_fault() */
-   EXC_XFER_LITE(0x300, handle_page_fault)
+   EXC_XFER_LITE(0x300, do_page_fault)
 
 #ifdef CONFIG_VMAP_STACK
vmap_stack_overflow_exception
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 626e9fbac2cc..81a6ec098dd1 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -299,7 +299,7 @@ ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_HPTE_TABLE)
lwz r5, _DSISR(r11)
andis.  r0, r5, DSISR_DABRMATCH@h
bne-1f
-   EXC_XFER_LITE(0x300, handle_page_fault)
+   EXC_XFER_LITE(0x300, do_page_fault)
 1: EXC_XFER_STD(0x300, do_break)
 
 
@@ -328,7 +328,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
andis.  r5,r9,DSISR_SRR1_MATCH_32S@h /* Filter relevant SRR1 bits */
stw r5, _DSISR(r11)
stw r12, _DAR(r11)
-   EXC_XFER_LITE(0x400, handle_page_fault)
+   EXC_XFER_LITE(0x400, do_page_fault)
 
 /* External interrupt */
EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 009a56d70d76..036a69d16605 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -462,7 +462,7 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
stw r5,_ESR(r11); \
mfspr   r4,SPRN_DEAR;   /* Grab the DEAR */   \
stw r4, _DEAR(r11);   \
-   EXC_XFER_LITE(0x0300, handle_page_fault)
+   EXC_XFER_LITE(0x0300, do_page_fault)
 
 #define INSTRUCTION_STORAGE_EXCEPTION\
START_EXCEPTION(InstructionStorage)  

[PATCH v2 19/43] powerpc/32: Use START_EXCEPTION() as much as possible

2021-03-09 Thread Christophe Leroy
Everywhere where it is possible, use START_EXCEPTION().

This will help for proper exception init in future patches.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_40x.S   | 12 +--
 arch/powerpc/kernel/head_8xx.S   | 27 +
 arch/powerpc/kernel/head_book3s_32.S | 30 
 3 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 55fa99c5085c..c14a71e0d6d3 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -247,17 +247,15 @@ _ENTRY(crit_esr)
EXCEPTION(0x0F00, Trap_0F, unknown_exception, EXC_XFER_STD)
 
 /* 0x1000 - Programmable Interval Timer (PIT) Exception */
-   . = 0x1000
+   START_EXCEPTION(0x1000, DecrementerTrap)
b Decrementer
 
-/* 0x1010 - Fixed Interval Timer (FIT) Exception
-*/
-   . = 0x1010
+/* 0x1010 - Fixed Interval Timer (FIT) Exception */
+   START_EXCEPTION(0x1010, FITExceptionTrap)
b FITException
 
-/* 0x1020 - Watchdog Timer (WDT) Exception
-*/
-   . = 0x1020
+/* 0x1020 - Watchdog Timer (WDT) Exception */
+   START_EXCEPTION(0x1020, WDTExceptionTrap)
b WDTException
 
 /* 0x1100 - Data TLB Miss Exception
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index b63445c55f4d..11789a077d76 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -121,8 +121,7 @@ instruction_counter:
EXCEPTION(0x100, Reset, system_reset_exception, EXC_XFER_STD)
 
 /* Machine check */
-   . = 0x200
-MachineCheck:
+   START_EXCEPTION(0x200, MachineCheck)
EXCEPTION_PROLOG handle_dar_dsisr=1
addi r3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x200, machine_check_exception)
@@ -131,8 +130,7 @@ MachineCheck:
EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
 
 /* Alignment exception */
-   . = 0x600
-Alignment:
+   START_EXCEPTION(0x600, Alignment)
EXCEPTION_PROLOG handle_dar_dsisr=1
addir3,r1,STACK_FRAME_OVERHEAD
b   .Lalignment_exception_ool
@@ -149,8 +147,7 @@ Alignment:
EXC_XFER_STD(0x600, alignment_exception)
 
 /* System call */
-   . = 0xc00
-SystemCall:
+   START_EXCEPTION(0xc00, SystemCall)
SYSCALL_ENTRY   0xc00
 
 /* Single step - not used on 601 */
@@ -161,7 +158,6 @@ SystemCall:
  */
EXCEPTION(0x1000, SoftEmu, emulation_assist_interrupt, EXC_XFER_STD)
 
-   . = 0x1100
 /*
  * For the MPC8xx, this is a software tablewalk to load the instruction
  * TLB.  The task switch loads the M_TWB register with the pointer to the first
@@ -183,7 +179,7 @@ SystemCall:
 #define INVALIDATE_ADJACENT_PAGES_CPU15(addr, tmp)
 #endif
 
-InstructionTLBMiss:
+   START_EXCEPTION(0x1100, InstructionTLBMiss)
mtspr   SPRN_SPRG_SCRATCH2, r10
mtspr   SPRN_M_TW, r11
 
@@ -239,8 +235,7 @@ InstructionTLBMiss:
rfi
 #endif
 
-   . = 0x1200
-DataStoreTLBMiss:
+   START_EXCEPTION(0x1200, DataStoreTLBMiss)
mtspr   SPRN_SPRG_SCRATCH2, r10
mtspr   SPRN_M_TW, r11
mfcrr11
@@ -303,8 +298,7 @@ DataStoreTLBMiss:
  * to many reasons, such as executing guarded memory or illegal instruction
  * addresses.  There is nothing to do but handle a big time error fault.
  */
-   . = 0x1300
-InstructionTLBError:
+   START_EXCEPTION(0x1300, InstructionTLBError)
EXCEPTION_PROLOG
andis.  r5,r9,DSISR_SRR1_MATCH_32S@h /* Filter relevant SRR1 bits */
andis.  r10,r9,SRR1_ISI_NOPT@h
@@ -320,8 +314,7 @@ InstructionTLBError:
  * many reasons, including a dirty update to a pte.  We bail out to
  * a higher level function that can handle it.
  */
-   . = 0x1400
-DataTLBError:
+   START_EXCEPTION(0x1400, DataTLBError)
EXCEPTION_PROLOG_0 handle_dar_dsisr=1
mfspr   r11, SPRN_DAR
cmpwi   cr1, r11, RPN_PATTERN
@@ -354,8 +347,7 @@ do_databreakpoint:
stw r4,_DAR(r11)
EXC_XFER_STD(0x1c00, do_break)
 
-   . = 0x1c00
-DataBreakpoint:
+   START_EXCEPTION(0x1c00, DataBreakpoint)
EXCEPTION_PROLOG_0 handle_dar_dsisr=1
mfspr   r11, SPRN_SRR0
cmplwi  cr1, r11, (.Ldtlbie - PAGE_OFFSET)@l
@@ -368,8 +360,7 @@ DataBreakpoint:
rfi
 
 #ifdef CONFIG_PERF_EVENTS
-   . = 0x1d00
-InstructionBreakpoint:
+   START_EXCEPTION(0x1d00, InstructionBreakpoint)
mtspr   SPRN_SPRG_SCRATCH0, r10
lwz r10, (instruction_counter - PAGE_OFFSET)@l(0)
addir10, r10, -1
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 9dc05890477d..8f5c8c8da63d 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -255,9 +255,7 @@ __secondary_hold_acknowledge:
  * pointer when we take an exception from supervisor mode.)
  * -- paulus.
  */
-   . = 0x200
-   DO_KVM  0x200
-MachineCheck:
+ 

[PATCH v2 21/43] powerpc/32: Provide a name to exception prolog continuation in virtual mode

2021-03-09 Thread Christophe Leroy
Now that the prolog continuation is separated in .text, give it a name
and mark it _ASM_NOKPROBE_SYMBOL.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h| 12 +++-
 arch/powerpc/kernel/head_40x.S   | 22 --
 arch/powerpc/kernel/head_8xx.S   | 10 +-
 arch/powerpc/kernel/head_book3s_32.S | 14 +++---
 4 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 3c0aa4538514..160ebd573c37 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -10,10 +10,10 @@
  * We assume sprg3 has the physical address of the current
  * task's thread_struct.
  */
-.macro EXCEPTION_PROLOG handle_dar_dsisr=0
+.macro EXCEPTION_PROLOGname handle_dar_dsisr=0
EXCEPTION_PROLOG_0  handle_dar_dsisr=\handle_dar_dsisr
EXCEPTION_PROLOG_1
-   EXCEPTION_PROLOG_2  handle_dar_dsisr=\handle_dar_dsisr
+   EXCEPTION_PROLOG_2  \name handle_dar_dsisr=\handle_dar_dsisr
 .endm
 
 .macro EXCEPTION_PROLOG_0 handle_dar_dsisr=0
@@ -56,7 +56,7 @@
 #endif
 .endm
 
-.macro EXCEPTION_PROLOG_2 handle_dar_dsisr=0
+.macro EXCEPTION_PROLOG_2 name handle_dar_dsisr=0
 #ifdef CONFIG_PPC_8xx
.if \handle_dar_dsisr
li  r11, RPN_PATTERN
@@ -72,6 +72,7 @@
rfi
 
.text
+\name\()_virt:
 1:
stw r11,GPR1(r1)
stw r11,0(r1)
@@ -109,6 +110,7 @@
stw r10,8(r11)
SAVE_4GPRS(3, r11)
SAVE_2GPRS(7, r11)
+_ASM_NOKPROBE_SYMBOL(\name\()_virt)
 .endm
 
 .macro SYSCALL_ENTRY trapno
@@ -180,7 +182,7 @@
 
 #define EXCEPTION(n, label, hdlr, xfer)\
START_EXCEPTION(n, label)   \
-   EXCEPTION_PROLOG;   \
+   EXCEPTION_PROLOG label; \
addir3,r1,STACK_FRAME_OVERHEAD; \
xfer(n, hdlr)
 
@@ -212,7 +214,7 @@
 #endif
lwz r1, emergency_ctx@l(r1)
addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
-   EXCEPTION_PROLOG_2
+   EXCEPTION_PROLOG_2 vmap_stack_overflow
SAVE_NVGPRS(r11)
addir3, r1, STACK_FRAME_OVERHEAD
EXC_XFER_STD(0, stack_overflow_exception)
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index e7d8856714d3..86883ccb3dc5 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -104,7 +104,7 @@ _ENTRY(crit_esr)
  * Instead we use a couple of words of memory at low physical addresses.
  * This is OK since we don't support SMP on these processors.
  */
-.macro CRITICAL_EXCEPTION_PROLOG
+.macro CRITICAL_EXCEPTION_PROLOG name
stw r10,crit_r10@l(0)   /* save two registers to work with */
stw r11,crit_r11@l(0)
mfspr   r10,SPRN_SRR0
@@ -135,6 +135,7 @@ _ENTRY(crit_esr)
 
.text
 1:
+\name\()_virt:
lwz r11,crit_r1@l(0)
stw r11,GPR1(r1)
stw r11,0(r1)
@@ -162,6 +163,7 @@ _ENTRY(crit_esr)
stw r10, 8(r11)
SAVE_4GPRS(3, r11)
SAVE_2GPRS(7, r11)
+_ASM_NOKPROBE_SYMBOL(\name\()_virt)
 .endm
 
/*
@@ -182,7 +184,7 @@ _ENTRY(crit_esr)
  */
 #define CRITICAL_EXCEPTION(n, label, hdlr) \
START_EXCEPTION(n, label);  \
-   CRITICAL_EXCEPTION_PROLOG;  \
+   CRITICAL_EXCEPTION_PROLOG label;\
addir3,r1,STACK_FRAME_OVERHEAD; \
EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  crit_transfer_to_handler, ret_from_crit_exc)
@@ -205,7 +207,7 @@ _ENTRY(crit_esr)
  * if they can't resolve the lightweight TLB fault.
  */
START_EXCEPTION(0x0300, DataStorage)
-   EXCEPTION_PROLOG handle_dar_dsisr=1
+   EXCEPTION_PROLOG DataStorage handle_dar_dsisr=1
EXC_XFER_LITE(0x300, handle_page_fault)
 
 /*
@@ -213,7 +215,7 @@ _ENTRY(crit_esr)
  * This is caused by a fetch from non-execute or guarded pages.
  */
START_EXCEPTION(0x0400, InstructionAccess)
-   EXCEPTION_PROLOG
+   EXCEPTION_PROLOG InstructionAccess
li  r5,0
stw r5, _ESR(r11)   /* Zero ESR */
stw r12, _DEAR(r11) /* SRR0 as DEAR */
@@ -224,13 +226,13 @@ _ENTRY(crit_esr)
 
 /* 0x0600 - Alignment Exception */
START_EXCEPTION(0x0600, Alignment)
-   EXCEPTION_PROLOG handle_dar_dsisr=1
+   EXCEPTION_PROLOG Alignment handle_dar_dsisr=1
addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x600, alignment_exception)
 
 /* 0x0700 - Program Exception */
START_EXCEPTION(0x0700, ProgramCheck)
-   EXCEPTION_PROLOG handle_dar_dsisr=1
+   EXCEPTION_PROLOG ProgramCheck handle_dar_dsisr=1
addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x700, program_check_exception)
 
@@ -450,7 +452,7 @@ _ENTRY(crit_esr)
 

[PATCH v2 29/43] powerpc/32: Save trap number on stack in exception prolog

2021-03-09 Thread Christophe Leroy
Saving the trap number into the stack goes into
the exception prolog, as EXC_XFER_xxx will soon disappear.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h| 14 -
 arch/powerpc/kernel/head_40x.S   | 22 +++---
 arch/powerpc/kernel/head_8xx.S   | 14 -
 arch/powerpc/kernel/head_book3s_32.S | 14 -
 arch/powerpc/kernel/head_booke.h | 44 +++-
 arch/powerpc/kernel/head_fsl_booke.S |  4 +--
 6 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 4d638d760a96..bf4c288173ad 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -10,10 +10,10 @@
  * We assume sprg3 has the physical address of the current
  * task's thread_struct.
  */
-.macro EXCEPTION_PROLOGname handle_dar_dsisr=0
+.macro EXCEPTION_PROLOGtrapno name handle_dar_dsisr=0
EXCEPTION_PROLOG_0  handle_dar_dsisr=\handle_dar_dsisr
EXCEPTION_PROLOG_1
-   EXCEPTION_PROLOG_2  \name handle_dar_dsisr=\handle_dar_dsisr
+   EXCEPTION_PROLOG_2  \trapno \name handle_dar_dsisr=\handle_dar_dsisr
 .endm
 
 .macro EXCEPTION_PROLOG_0 handle_dar_dsisr=0
@@ -56,7 +56,7 @@
 #endif
 .endm
 
-.macro EXCEPTION_PROLOG_2 name handle_dar_dsisr=0
+.macro EXCEPTION_PROLOG_2 trapno name handle_dar_dsisr=0
 #ifdef CONFIG_PPC_8xx
.if \handle_dar_dsisr
li  r11, RPN_PATTERN
@@ -108,6 +108,8 @@
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
addir10,r10,STACK_FRAME_REGS_MARKER@l
stw r10,8(r11)
+   li  r10, \trapno
+   stw r10,_TRAP(r11)
SAVE_4GPRS(3, r11)
SAVE_2GPRS(7, r11)
 _ASM_NOKPROBE_SYMBOL(\name\()_virt)
@@ -182,12 +184,10 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 
 #define EXCEPTION(n, label, hdlr, xfer)\
START_EXCEPTION(n, label)   \
-   EXCEPTION_PROLOG label; \
+   EXCEPTION_PROLOG n label;   \
xfer(n, hdlr)
 
 #define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret)  \
-   li  r10,trap;   \
-   stw r10,_TRAP(r11); \
bl  tfer;   \
bl  hdlr;   \
b   ret
@@ -213,7 +213,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 #endif
lwz r1, emergency_ctx@l(r1)
addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
-   EXCEPTION_PROLOG_2 vmap_stack_overflow
+   EXCEPTION_PROLOG_2 0 vmap_stack_overflow
EXC_XFER_STD(0, stack_overflow_exception)
 .endm
 
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index a65778380704..7270caff665c 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -104,7 +104,7 @@ _ENTRY(crit_esr)
  * Instead we use a couple of words of memory at low physical addresses.
  * This is OK since we don't support SMP on these processors.
  */
-.macro CRITICAL_EXCEPTION_PROLOG name
+.macro CRITICAL_EXCEPTION_PROLOG trapno name
stw r10,crit_r10@l(0)   /* save two registers to work with */
stw r11,crit_r11@l(0)
mfspr   r10,SPRN_SRR0
@@ -161,6 +161,8 @@ _ENTRY(crit_esr)
lis r10, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
addir10, r10, STACK_FRAME_REGS_MARKER@l
stw r10, 8(r11)
+   li  r10, \trapno + 2
+   stw r10,_TRAP(r11)
SAVE_4GPRS(3, r11)
SAVE_2GPRS(7, r11)
 _ASM_NOKPROBE_SYMBOL(\name\()_virt)
@@ -184,7 +186,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  */
 #define CRITICAL_EXCEPTION(n, label, hdlr) \
START_EXCEPTION(n, label);  \
-   CRITICAL_EXCEPTION_PROLOG label;\
+   CRITICAL_EXCEPTION_PROLOG n label;  \
EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  crit_transfer_to_handler, ret_from_crit_exc)
 
@@ -206,7 +208,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  * if they can't resolve the lightweight TLB fault.
  */
START_EXCEPTION(0x0300, DataStorage)
-   EXCEPTION_PROLOG DataStorage handle_dar_dsisr=1
+   EXCEPTION_PROLOG 0x300 DataStorage handle_dar_dsisr=1
EXC_XFER_LITE(0x300, do_page_fault)
 
 /*
@@ -214,7 +216,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
  * This is caused by a fetch from non-execute or guarded pages.
  */
START_EXCEPTION(0x0400, InstructionAccess)
-   EXCEPTION_PROLOG InstructionAccess
+   EXCEPTION_PROLOG 0x400 InstructionAccess
li  r5,0
stw r5, _ESR(r11)   /* Zero ESR */
stw r12, _DEAR(r11) /* SRR0 as DEAR */
@@ -225,12 +227,12 @@ 

[PATCH v2 15/43] powerpc/32: Tag DAR in EXCEPTION_PROLOG_2 for the 8xx

2021-03-09 Thread Christophe Leroy
8xx requires to tag the DAR with a magic value in order to
fixup DAR on faults generated by 'dcbX', as the 8xx
forgets to update the DAR for those faults.

Do the tagging as early as possible, that is before enabling MMU.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h  |  6 ++
 arch/powerpc/kernel/head_8xx.S | 18 ++
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 1b707755c68e..910f86642eec 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -57,6 +57,12 @@
 .endm
 
 .macro EXCEPTION_PROLOG_2 handle_dar_dsisr=0
+#ifdef CONFIG_PPC_8xx
+   .if \handle_dar_dsisr
+   li  r11, RPN_PATTERN
+   mtspr   SPRN_DAR, r11   /* Tag DAR, to be used in DTLB Error */
+   .endif
+#endif
LOAD_REG_IMMEDIATE(r11, MSR_KERNEL & ~(MSR_IR | MSR_RI)) /* can take 
DTLB miss */
mtmsr   r11
isync
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 792e2fd86479..cdbfa9d41353 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -30,6 +30,12 @@
 #include 
 #include 
 
+/*
+ * Value for the bits that have fixed value in RPN entries.
+ * Also used for tagging DAR for DTLBerror.
+ */
+#define RPN_PATTERN0x00f0
+
 #include "head_32.h"
 
 .macro compare_to_kernel_boundary scratch, addr
@@ -42,12 +48,6 @@
 #endif
 .endm
 
-/*
- * Value for the bits that have fixed value in RPN entries.
- * Also used for tagging DAR for DTLBerror.
- */
-#define RPN_PATTERN0x00f0
-
 #define PAGE_SHIFT_512K19
 #define PAGE_SHIFT_8M  23
 
@@ -124,8 +124,6 @@ instruction_counter:
. = 0x200
 MachineCheck:
EXCEPTION_PROLOG handle_dar_dsisr=1
-   li  r6, RPN_PATTERN
-   mtspr   SPRN_DAR, r6/* Tag DAR, to be used in DTLB Error */
addi r3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x200, machine_check_exception)
 
@@ -136,8 +134,6 @@ MachineCheck:
. = 0x600
 Alignment:
EXCEPTION_PROLOG handle_dar_dsisr=1
-   li  r6, RPN_PATTERN
-   mtspr   SPRN_DAR, r6/* Tag DAR, to be used in DTLB Error */
addir3,r1,STACK_FRAME_OVERHEAD
b   .Lalignment_exception_ool
 
@@ -331,8 +327,6 @@ DataTLBError:
cmpwi   cr1, r11, RPN_PATTERN
beq-cr1, FixupDAR   /* must be a buggy dcbX, icbi insn. */
 DARFixed:/* Return from dcbx instruction bug workaround */
-   li  r11, RPN_PATTERN
-   mtspr   SPRN_DAR, r11   /* Tag DAR, to be used in DTLB Error */
EXCEPTION_PROLOG_1
EXCEPTION_PROLOG_2 handle_dar_dsisr=1
lwz r4, _DAR(r11)
-- 
2.25.0



[PATCH v2 22/43] powerpc/32: Refactor booke critical registers saving

2021-03-09 Thread Christophe Leroy
Refactor booke critical registers saving into a few macros
and move it into the exception prolog directly.

Keep the dedicated transfert_to_handler entry point for the
moment allthough they are empty. They will be removed in a
later patch to reduce churn.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 33 -
 arch/powerpc/kernel/head_booke.h | 41 
 2 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 01a064c8a96a..ad1fd33e1126 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -51,49 +51,16 @@
 #ifdef CONFIG_BOOKE
.globl  mcheck_transfer_to_handler
 mcheck_transfer_to_handler:
-   mfspr   r0,SPRN_DSRR0
-   stw r0,_DSRR0(r11)
-   mfspr   r0,SPRN_DSRR1
-   stw r0,_DSRR1(r11)
/* fall through */
 _ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
 
.globl  debug_transfer_to_handler
 debug_transfer_to_handler:
-   mfspr   r0,SPRN_CSRR0
-   stw r0,_CSRR0(r11)
-   mfspr   r0,SPRN_CSRR1
-   stw r0,_CSRR1(r11)
/* fall through */
 _ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
 
.globl  crit_transfer_to_handler
 crit_transfer_to_handler:
-#ifdef CONFIG_PPC_BOOK3E_MMU
-   mfspr   r0,SPRN_MAS0
-   stw r0,MAS0(r11)
-   mfspr   r0,SPRN_MAS1
-   stw r0,MAS1(r11)
-   mfspr   r0,SPRN_MAS2
-   stw r0,MAS2(r11)
-   mfspr   r0,SPRN_MAS3
-   stw r0,MAS3(r11)
-   mfspr   r0,SPRN_MAS6
-   stw r0,MAS6(r11)
-#ifdef CONFIG_PHYS_64BIT
-   mfspr   r0,SPRN_MAS7
-   stw r0,MAS7(r11)
-#endif /* CONFIG_PHYS_64BIT */
-#endif /* CONFIG_PPC_BOOK3E_MMU */
-#ifdef CONFIG_44x
-   mfspr   r0,SPRN_MMUCR
-   stw r0,MMUCR(r11)
-#endif
-   mfspr   r0,SPRN_SRR0
-   stw r0,_SRR0(r11)
-   mfspr   r0,SPRN_SRR1
-   stw r0,_SRR1(r11)
-
/* fall through */
 _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
 #endif
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index f712b9bc6d62..a127d5e7efb4 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -229,6 +229,36 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
SAVE_4GPRS(3, r11);  \
SAVE_2GPRS(7, r11)
 
+#define SAVE_xSRR(xSRR)\
+   mfspr   r0,SPRN_##xSRR##0;  \
+   stw r0,_##xSRR##0(r1);  \
+   mfspr   r0,SPRN_##xSRR##1;  \
+   stw r0,_##xSRR##1(r1)
+
+
+.macro SAVE_MMU_REGS
+#ifdef CONFIG_PPC_BOOK3E_MMU
+   mfspr   r0,SPRN_MAS0
+   stw r0,MAS0(r1)
+   mfspr   r0,SPRN_MAS1
+   stw r0,MAS1(r1)
+   mfspr   r0,SPRN_MAS2
+   stw r0,MAS2(r1)
+   mfspr   r0,SPRN_MAS3
+   stw r0,MAS3(r1)
+   mfspr   r0,SPRN_MAS6
+   stw r0,MAS6(r1)
+#ifdef CONFIG_PHYS_64BIT
+   mfspr   r0,SPRN_MAS7
+   stw r0,MAS7(r1)
+#endif /* CONFIG_PHYS_64BIT */
+#endif /* CONFIG_PPC_BOOK3E_MMU */
+#ifdef CONFIG_44x
+   mfspr   r0,SPRN_MMUCR
+   stw r0,MMUCR(r1)
+#endif
+.endm
+
 #define CRITICAL_EXCEPTION_PROLOG(intno) \
EXC_LEVEL_EXCEPTION_PROLOG(CRIT, intno, SPRN_CSRR0, SPRN_CSRR1)
 #define DEBUG_EXCEPTION_PROLOG \
@@ -271,6 +301,8 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
START_EXCEPTION(label); \
CRITICAL_EXCEPTION_PROLOG(intno);   \
addir3,r1,STACK_FRAME_OVERHEAD; \
+   SAVE_MMU_REGS;  \
+   SAVE_xSRR(SRR); \
EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  crit_transfer_to_handler, ret_from_crit_exc)
 
@@ -280,6 +312,10 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
mfspr   r5,SPRN_ESR;\
stw r5,_ESR(r11);   \
addir3,r1,STACK_FRAME_OVERHEAD; \
+   SAVE_xSRR(DSRR);\
+   SAVE_xSRR(CSRR);\
+   SAVE_MMU_REGS;  \
+   SAVE_xSRR(SRR); \
EXC_XFER_TEMPLATE(hdlr, n+4, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
  mcheck_transfer_to_handler, ret_from_mcheck_exc)
 
@@ -363,6 +399,9 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
 2: mfspr   r4,SPRN_DBSR; \
stw r4,_ESR(r11);   /* DebugException takes DBSR in _ESR */\
addir3,r1,STACK_FRAME_OVERHEAD;   \
+   

Re: [PATCH resend v1 3/7] pps: clients: gpio: Remove redundant condition in ->remove()

2021-03-09 Thread Rodolfo Giometti
On 09/03/21 12:23, Andy Shevchenko wrote:
> The timer along with GPIO API are NULL-aware, there is no need to test
> against existing GPIO echo line.
> 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/pps/clients/pps-gpio.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index 78c9680e8063..dc9ed6fc3dae 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -240,11 +240,9 @@ static int pps_gpio_remove(struct platform_device *pdev)
>   struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
>  
>   pps_unregister_source(data->pps);
> - if (data->echo_pin) {
> - del_timer_sync(>echo_timer);
> - /* reset echo pin in any case */
> - gpiod_set_value(data->echo_pin, 0);
> - }
> + del_timer_sync(>echo_timer);
> + /* reset echo pin in any case */
> + gpiod_set_value(data->echo_pin, 0);
>   dev_info(>dev, "removed IRQ %d as PPS source\n", data->irq);
>   return 0;
>  }
> 

Acked-by: Rodolfo Giometti 

-- 
GNU/Linux Solutions  e-mail: giome...@enneenne.com
Linux Device Driver  giome...@linux.it
Embedded Systems phone:  +39 349 2432127
UNIX programming skype:  rodolfo.giometti


Re: [PATCH] btrfs: turn btrfs_destroy_delayed_refs() into void function

2021-03-09 Thread David Sterba
On Tue, Mar 09, 2021 at 05:32:54PM +0800, Yang Li wrote:
> This function always return '0' and no callers use the return value.
> So make it a void function.
> 
> This eliminates the following coccicheck warning:
> ./fs/btrfs/disk-io.c:4522:5-8: Unneeded variable: "ret". Return "0" on
> line 4530
> 
> Reported-by: Abaci Robot 

Can you please tell your robot to ignore this warning, I'm getting tired
to explain the same thing again,

https://lore.kernel.org/linux-btrfs/20210302120708.gh7...@suse.cz/

this is like 5th attempt to blindly fix a tool warning without
understanding the code.


Re: [PATCH resend v1 2/7] pps: clients: gpio: Use dev_err_probe() to avoid log noise

2021-03-09 Thread Rodolfo Giometti
On 09/03/21 12:23, Andy Shevchenko wrote:
> When GPIO APIs return -EPROBE_DEFER there is no need to print the message,
> especially taking into consideration that it may repeat several times.
> Use dev_err_probe() to avoid log noise in such cases.
> 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/pps/clients/pps-gpio.c | 15 ++-
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index f89c31aa66f1..78c9680e8063 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -110,19 +110,16 @@ static int pps_gpio_setup(struct platform_device *pdev)
>   data->gpio_pin = devm_gpiod_get(>dev,
>   NULL,   /* request "gpios" */
>   GPIOD_IN);
> - if (IS_ERR(data->gpio_pin)) {
> - dev_err(>dev,
> - "failed to request PPS GPIO\n");
> - return PTR_ERR(data->gpio_pin);
> - }
> + if (IS_ERR(data->gpio_pin))
> + return dev_err_probe(>dev, PTR_ERR(data->gpio_pin),
> +  "failed to request PPS GPIO\n");
>  
>   data->echo_pin = devm_gpiod_get_optional(>dev,
>   "echo",
>   GPIOD_OUT_LOW);
> - if (IS_ERR(data->echo_pin)) {
> - dev_err(>dev, "failed to request ECHO GPIO\n");
> - return PTR_ERR(data->echo_pin);
> - }
> + if (IS_ERR(data->echo_pin))
> + return dev_err_probe(>dev, PTR_ERR(data->echo_pin),
> +  "failed to request ECHO GPIO\n");
>  
>   if (data->echo_pin) {
>   ret = of_property_read_u32(np,
> 

Acked-by: Rodolfo Giometti 

-- 
GNU/Linux Solutions  e-mail: giome...@enneenne.com
Linux Device Driver  giome...@linux.it
Embedded Systems phone:  +39 349 2432127
UNIX programming skype:  rodolfo.giometti


Re: [PATCH resend v1 6/7] pps: clients: gpio: Use struct device pointer directly

2021-03-09 Thread Rodolfo Giometti
On 09/03/21 12:24, Andy Shevchenko wrote:
> In most parts of the code the platform device is not used.
> Use struct device pointer directly to reduce code size and
> increase readability.
> 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/pps/clients/pps-gpio.c | 42 +++---
>  1 file changed, 19 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index c6db3a3b257b..b097da5a659a 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -99,45 +99,39 @@ static void pps_gpio_echo_timer_callback(struct 
> timer_list *t)
>   gpiod_set_value(info->echo_pin, 0);
>  }
>  
> -static int pps_gpio_setup(struct platform_device *pdev)
> +static int pps_gpio_setup(struct device *dev)
>  {
> - struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
> + struct pps_gpio_device_data *data = dev_get_drvdata(dev);
>   int ret;
>   u32 value;
>  
> - data->gpio_pin = devm_gpiod_get(>dev,
> - NULL,   /* request "gpios" */
> - GPIOD_IN);
> + data->gpio_pin = devm_gpiod_get(dev, NULL, GPIOD_IN);
>   if (IS_ERR(data->gpio_pin))
> - return dev_err_probe(>dev, PTR_ERR(data->gpio_pin),
> + return dev_err_probe(dev, PTR_ERR(data->gpio_pin),
>"failed to request PPS GPIO\n");
>  
> - data->echo_pin = devm_gpiod_get_optional(>dev,
> - "echo",
> - GPIOD_OUT_LOW);
> + data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
>   if (IS_ERR(data->echo_pin))
> - return dev_err_probe(>dev, PTR_ERR(data->echo_pin),
> + return dev_err_probe(dev, PTR_ERR(data->echo_pin),
>"failed to request ECHO GPIO\n");
>  
>   if (data->echo_pin) {
> - ret = device_property_read_u32(>dev, "echo-active-ms", 
> );
> + ret = device_property_read_u32(dev, "echo-active-ms", );
>   if (ret) {
> - dev_err(>dev,
> - "failed to get echo-active-ms from FW\n");
> + dev_err(dev, "failed to get echo-active-ms from FW\n");
>   return ret;
>   }
>   data->echo_active_ms = value;
>   /* sanity check on echo_active_ms */
>   if (!data->echo_active_ms || data->echo_active_ms > 999) {
> - dev_err(>dev,
> - "echo-active-ms: %u - bad value from FW\n",
> + dev_err(dev, "echo-active-ms: %u - bad value from FW\n",
>   data->echo_active_ms);
>   return -EINVAL;
>   }
>   }
>  
>   data->assert_falling_edge =
> - device_property_read_bool(>dev, "assert-falling-edge");
> + device_property_read_bool(dev, "assert-falling-edge");
>   return 0;
>  }
>  
> @@ -158,24 +152,26 @@ get_irqf_trigger_flags(const struct 
> pps_gpio_device_data *data)
>  static int pps_gpio_probe(struct platform_device *pdev)
>  {
>   struct pps_gpio_device_data *data;
> + struct device *dev = >dev;
>   int ret;
>   int pps_default_params;
>  
>   /* allocate space for device info */
> - data = devm_kzalloc(>dev, sizeof(*data), GFP_KERNEL);
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>   if (!data)
>   return -ENOMEM;
> - platform_set_drvdata(pdev, data);
> +
> + dev_set_drvdata(dev, data);
>  
>   /* GPIO setup */
> - ret = pps_gpio_setup(pdev);
> + ret = pps_gpio_setup(dev);
>   if (ret)
>   return -EINVAL;
>  
>   /* IRQ setup */
>   ret = gpiod_to_irq(data->gpio_pin);
>   if (ret < 0) {
> - dev_err(>dev, "failed to map GPIO to IRQ: %d\n", ret);
> + dev_err(dev, "failed to map GPIO to IRQ: %d\n", ret);
>   return -EINVAL;
>   }
>   data->irq = ret;
> @@ -201,17 +197,17 @@ static int pps_gpio_probe(struct platform_device *pdev)
>   pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
>   data->pps = pps_register_source(>info, pps_default_params);
>   if (IS_ERR(data->pps)) {
> - dev_err(>dev, "failed to register IRQ %d as PPS source\n",
> + dev_err(dev, "failed to register IRQ %d as PPS source\n",
>   data->irq);
>   return PTR_ERR(data->pps);
>   }
>  
>   /* register IRQ interrupt handler */
> - ret = devm_request_irq(>dev, data->irq, pps_gpio_irq_handler,
> + ret = devm_request_irq(dev, data->irq, pps_gpio_irq_handler,
>   get_irqf_trigger_flags(data), data->info.name, data);
>   if (ret) {
>   pps_unregister_source(data->pps);
> - dev_err(>dev, "failed to acquire IRQ %d\n", data->irq);
> + dev_err(dev, 

Re: [PATCH resend v1 7/7] pps: clients: gpio: Rearrange optional stuff in pps_gpio_setup()

2021-03-09 Thread Rodolfo Giometti
On 09/03/21 12:24, Andy Shevchenko wrote:
> Rearrange optional stuff in pps_gpio_setup() so it will go after mandatory one
> and with reduced indentation. This will increase readability of the sources.
> 
> Signed-off-by: Andy Shevchenko 
> ---
>  drivers/pps/clients/pps-gpio.c | 33 ++---
>  1 file changed, 18 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index b097da5a659a..35799e6401c9 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -110,28 +110,31 @@ static int pps_gpio_setup(struct device *dev)
>   return dev_err_probe(dev, PTR_ERR(data->gpio_pin),
>"failed to request PPS GPIO\n");
>  
> + data->assert_falling_edge =
> + device_property_read_bool(dev, "assert-falling-edge");
> +
>   data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
>   if (IS_ERR(data->echo_pin))
>   return dev_err_probe(dev, PTR_ERR(data->echo_pin),
>"failed to request ECHO GPIO\n");
>  
> - if (data->echo_pin) {
> - ret = device_property_read_u32(dev, "echo-active-ms", );
> - if (ret) {
> - dev_err(dev, "failed to get echo-active-ms from FW\n");
> - return ret;
> - }
> - data->echo_active_ms = value;
> - /* sanity check on echo_active_ms */
> - if (!data->echo_active_ms || data->echo_active_ms > 999) {
> - dev_err(dev, "echo-active-ms: %u - bad value from FW\n",
> - data->echo_active_ms);
> - return -EINVAL;
> - }
> + if (!data->echo_pin)
> + return 0;
> +
> + ret = device_property_read_u32(dev, "echo-active-ms", );
> + if (ret) {
> + dev_err(dev, "failed to get echo-active-ms from FW\n");
> + return ret;
>   }
>  
> - data->assert_falling_edge =
> - device_property_read_bool(dev, "assert-falling-edge");
> + /* sanity check on echo_active_ms */
> + if (!value || value > 999) {
> + dev_err(dev, "echo-active-ms: %u - bad value from FW\n", value);
> + return -EINVAL;
> + }
> +
> + data->echo_active_ms = value;
> +
>   return 0;
>  }
>  
> 

Acked-by: Rodolfo Giometti 

-- 
GNU/Linux Solutions  e-mail: giome...@enneenne.com
Linux Device Driver  giome...@linux.it
Embedded Systems phone:  +39 349 2432127
UNIX programming skype:  rodolfo.giometti


Re: patch: do_wait: make PIDTYPE_PID case O(1) instead of O(n)

2021-03-09 Thread Oleg Nesterov
Ah, and you forgot to CC lkml ;) let me resend my email.


Hi Jim,

Please do not use the attachments, just send the patch as plain text.
See Documentation/process/submitting-patches.rst

On 03/08, Jim Newsome wrote:
>
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -1462,8 +1462,61 @@ static long do_wait(struct wait_opts *wo)
>   goto notask;
>
>   set_current_state(TASK_INTERRUPTIBLE);
> +
>   read_lock(_lock);
>   tsk = current;
> +
> + if (wo->wo_type == PIDTYPE_PID) {
> + // Optimization for PIDTYPE_PID. No need to iterate through 
> child and
> + // tracee lists to find the target task.

I'd suggest to put this PIDTYPE_PID code into the new function.

> +
> + struct task_struct *real_parent = NULL;
> + struct task_struct *target = NULL;
> + bool do_regular_wait, do_ptrace_wait;
> +
> + // XXX: Do we need this? Or is the tasklist_lock sufficient?
> + rcu_read_lock();

No, you don't need rcu lock, tasklist_lock is sufficient

> + target = pid_task(wo->wo_pid, PIDTYPE_PID);
> + if (!target) {
> + rcu_read_unlock();
> + goto notask;

This is wrong, you forgot to drop tasklist_lock.


> + real_parent = !target->real_parent ? target->parent :
> +  target->real_parent;

Hmm, I don't understand the line above... perhaps it connects to the
question below.

> + if (!real_parent) {
> + // XXX: Is it a kernel bug to get here? Or would this be
> + // true of the init process?

Afaics, parent/real_parent can't be NULL if pid_task() succeeds.

> + do_regular_wait = tsk == real_parent ||
> +   (!(wo->wo_flags & __WNOTHREAD) &&
> +same_thread_group(tsk, real_parent));
> + do_ptrace_wait = target->ptrace &&
> +  (tsk == target->parent ||
> +   (!(wo->wo_flags & __WNOTHREAD) &&
> +same_thread_group(tsk, target->parent)));
> + rcu_read_unlock();
> +
> + if (do_regular_wait) {
> + retval =
> + wait_consider_task(wo, /* ptrace= */ 0, target);
> + if (retval) {
> + goto end;
> + }
> + }
> + if (do_ptrace_wait) {
> + retval =
> + wait_consider_task(wo, /* ptrace= */ 1, target);
> + if (retval) {
> + goto end;
> + }
> + }
> + read_unlock(_lock);
> + goto notask;

This part looks correct at first glance...

Please redo and send V2 ;)

Oleg.



Re: [PATCH v4 2/3] xen/events: don't unmask an event channel when an eoi is pending

2021-03-09 Thread Ross Lagerwall
On 2021-03-09 05:14, Jürgen Groß wrote:
> On 08.03.21 21:33, Boris Ostrovsky wrote:
>>
>> On 3/6/21 11:18 AM, Juergen Gross wrote:
>>> An event channel should be kept masked when an eoi is pending for it.
>>> When being migrated to another cpu it might be unmasked, though.
>>>
>>> In order to avoid this keep three different flags for each event channel
>>> to be able to distinguish "normal" masking/unmasking from eoi related
>>> masking/unmasking and temporary masking. The event channel should only
>>> be able to generate an interrupt if all flags are cleared.
>>>
>>> Cc: sta...@vger.kernel.org
>>> Fixes: 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn 
>>> framework")
>>> Reported-by: Julien Grall 
>>> Signed-off-by: Juergen Gross 
>>> Reviewed-by: Julien Grall 
>>> ---
>>> V2:
>>> - introduce a lock around masking/unmasking
>>> - merge patch 3 into this one (Jan Beulich)
>>> V4:
>>> - don't set eoi masking flag in lateeoi_mask_ack_dynirq()
>>
>>
>> Reviewed-by: Boris Ostrovsky 
>>
>>
>> Ross, are you planning to test this?
> 
> Just as another data point: With the previous version of the patches
> a reboot loop of a guest needed max 33 reboots to loose network in
> my tests (those were IIRC 6 test runs). With this patch version I
> stopped the test after about 1300 reboots without having seen any
> problems.
> 

Thanks, I'll test it today and get back to you.

Ross


[PATCH 4/4] Documentation/admin-guide/module-signing.rst: add openssl command option example for CodeSign EKU

2021-03-09 Thread Lee, Chun-Yi
Add an openssl command option example for generating CodeSign extended
key usage in X.509 when CONFIG_CHECK_CODESIGN_EKU is enabled.

Signed-off-by: "Lee, Chun-Yi" 
---
 Documentation/admin-guide/module-signing.rst | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/admin-guide/module-signing.rst 
b/Documentation/admin-guide/module-signing.rst
index 7d7c7c8a545c..ca3b8f19466c 100644
--- a/Documentation/admin-guide/module-signing.rst
+++ b/Documentation/admin-guide/module-signing.rst
@@ -170,6 +170,12 @@ generate the public/private key files::
   -config x509.genkey -outform PEM -out kernel_key.pem \
   -keyout kernel_key.pem
 
+When ``CONFIG_CHECK_CODESIGN_EKU`` option is enabled, the following openssl
+command option should be added where for generating CodeSign extended key usage
+in X.509::
+
+-addext "extendedKeyUsage=codeSigning"
+
 The full pathname for the resulting kernel_key.pem file can then be specified
 in the ``CONFIG_MODULE_SIG_KEY`` option, and the certificate and key therein 
will
 be used instead of an autogenerated keypair.
-- 
2.16.4



[PATCH 3/4] modsign: Add codeSigning EKU when generating X.509 key generation config

2021-03-09 Thread Lee, Chun-Yi
Add codeSigning EKU to the X.509 key generation config for the build time
autogenerated kernel key.

Signed-off-by: "Lee, Chun-Yi" 
---
 certs/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/certs/Makefile b/certs/Makefile
index f4c25b67aad9..1ef4d6ca43b7 100644
--- a/certs/Makefile
+++ b/certs/Makefile
@@ -88,6 +88,7 @@ $(obj)/x509.genkey:
@echo >>$@ "keyUsage=digitalSignature"
@echo >>$@ "subjectKeyIdentifier=hash"
@echo >>$@ "authorityKeyIdentifier=keyid"
+   @echo >>$@ "extendedKeyUsage=codeSigning"
 endif # CONFIG_MODULE_SIG_KEY
 
 $(eval $(call config_filename,MODULE_SIG_KEY))
-- 
2.16.4



[PATCH 2/4] PKCS#7: Check codeSigning EKU for kernel module and kexec pe verification

2021-03-09 Thread Lee, Chun-Yi
This patch adds the logic for checking the CodeSigning extended
key usage when verifying signature of kernel module or
kexec PE binary in PKCS#7.

Signed-off-by: "Lee, Chun-Yi" 
---
 certs/system_keyring.c   |  2 +-
 crypto/asymmetric_keys/Kconfig   |  9 +
 crypto/asymmetric_keys/pkcs7_trust.c | 37 +---
 include/crypto/pkcs7.h   |  3 ++-
 4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index 4b693da488f1..c9f8bca0b0d3 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -243,7 +243,7 @@ int verify_pkcs7_message_sig(const void *data, size_t len,
goto error;
}
}
-   ret = pkcs7_validate_trust(pkcs7, trusted_keys);
+   ret = pkcs7_validate_trust(pkcs7, trusted_keys, usage);
if (ret < 0) {
if (ret == -ENOKEY)
pr_devel("PKCS#7 signature not signed with a trusted 
key\n");
diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig
index 1f1f004dc757..1754812df989 100644
--- a/crypto/asymmetric_keys/Kconfig
+++ b/crypto/asymmetric_keys/Kconfig
@@ -96,4 +96,13 @@ config SIGNED_PE_FILE_VERIFICATION
  This option provides support for verifying the signature(s) on a
  signed PE binary.
 
+config CHECK_CODESIGN_EKU
+   bool "Check codeSigning extended key usage"
+   depends on PKCS7_MESSAGE_PARSER=y
+   depends on SYSTEM_DATA_VERIFICATION
+   help
+ This option provides support for checking the codeSigning extended
+ key usage when verifying the signature in PKCS#7. It affects kernel
+ module verification and kexec PE binary verification.
+
 endif # ASYMMETRIC_KEY_TYPE
diff --git a/crypto/asymmetric_keys/pkcs7_trust.c 
b/crypto/asymmetric_keys/pkcs7_trust.c
index b531df2013c4..077bfef928b6 100644
--- a/crypto/asymmetric_keys/pkcs7_trust.c
+++ b/crypto/asymmetric_keys/pkcs7_trust.c
@@ -16,12 +16,36 @@
 #include 
 #include "pkcs7_parser.h"
 
+#ifdef CONFIG_CHECK_CODESIGN_EKU
+static bool check_codesign_eku(struct key *key,
+enum key_being_used_for usage)
+{
+   struct public_key *public_key = key->payload.data[asym_crypto];
+
+   switch (usage) {
+   case VERIFYING_MODULE_SIGNATURE:
+   case VERIFYING_KEXEC_PE_SIGNATURE:
+   return !!(public_key->eku & EKU_codeSigning);
+   default:
+   break;
+   }
+   return true;
+}
+#else
+static bool check_codesign_eku(struct key *key,
+enum key_being_used_for usage)
+{
+   return true;
+}
+#endif
+
 /*
  * Check the trust on one PKCS#7 SignedInfo block.
  */
 static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,
struct pkcs7_signed_info *sinfo,
-   struct key *trust_keyring)
+   struct key *trust_keyring,
+   enum key_being_used_for usage)
 {
struct public_key_signature *sig = sinfo->sig;
struct x509_certificate *x509, *last = NULL, *p;
@@ -112,6 +136,12 @@ static int pkcs7_validate_trust_one(struct pkcs7_message 
*pkcs7,
return -ENOKEY;
 
 matched:
+   if (!check_codesign_eku(key, usage)) {
+   pr_warn("sinfo %u: The signer %x key is not CodeSigning\n",
+   sinfo->index, key_serial(key));
+   key_put(key);
+   return -ENOKEY;
+   }
ret = verify_signature(key, sig);
key_put(key);
if (ret < 0) {
@@ -156,7 +186,8 @@ static int pkcs7_validate_trust_one(struct pkcs7_message 
*pkcs7,
  * May also return -ENOMEM.
  */
 int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
-struct key *trust_keyring)
+struct key *trust_keyring,
+enum key_being_used_for usage)
 {
struct pkcs7_signed_info *sinfo;
struct x509_certificate *p;
@@ -167,7 +198,7 @@ int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
p->seen = false;
 
for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) {
-   ret = pkcs7_validate_trust_one(pkcs7, sinfo, trust_keyring);
+   ret = pkcs7_validate_trust_one(pkcs7, sinfo, trust_keyring, 
usage);
switch (ret) {
case -ENOKEY:
continue;
diff --git a/include/crypto/pkcs7.h b/include/crypto/pkcs7.h
index 38ec7f5f9041..b3b48240ba73 100644
--- a/include/crypto/pkcs7.h
+++ b/include/crypto/pkcs7.h
@@ -30,7 +30,8 @@ extern int pkcs7_get_content_data(const struct pkcs7_message 
*pkcs7,
  * pkcs7_trust.c
  */
 extern int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
-   struct key *trust_keyring);
+   struct key *trust_keyring,
+

[PATCH 1/4] X.509: Add CodeSigning extended key usage parsing

2021-03-09 Thread Lee, Chun-Yi
This patch adds the logic for parsing the CodeSign extended key usage
extension in X.509. The parsing result will be set to the eku flag
which is carried by public key. It can be used in the PKCS#7
verification.

Signed-off-by: "Lee, Chun-Yi" 
---
 crypto/asymmetric_keys/x509_cert_parser.c | 24 
 include/crypto/public_key.h   |  1 +
 include/linux/oid_registry.h  |  5 +
 3 files changed, 30 insertions(+)

diff --git a/crypto/asymmetric_keys/x509_cert_parser.c 
b/crypto/asymmetric_keys/x509_cert_parser.c
index 52c9b455fc7d..65721313b265 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -497,6 +497,8 @@ int x509_process_extension(void *context, size_t hdrlen,
struct x509_parse_context *ctx = context;
struct asymmetric_key_id *kid;
const unsigned char *v = value;
+   int i = 0;
+   enum OID oid;
 
pr_debug("Extension: %u\n", ctx->last_oid);
 
@@ -526,6 +528,28 @@ int x509_process_extension(void *context, size_t hdrlen,
return 0;
}
 
+   if (ctx->last_oid == OID_extKeyUsage) {
+   if (v[0] != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ) ||
+   v[1] != vlen - 2)
+   return -EBADMSG;
+   i += 2;
+
+   while (i < vlen) {
+   /* A 10 bytes EKU OID Octet blob =
+* ASN1_OID + size byte + 8 bytes OID */
+   if (v[i] != ASN1_OID || v[i + 1] != 8 || (i + 10) > 
vlen)
+   return -EBADMSG;
+
+   oid = look_up_OID(v + i + 2, v[i + 1]);
+   if (oid == OID_codeSigning) {
+   ctx->cert->pub->eku |= EKU_codeSigning;
+   }
+   i += 10;
+   }
+   pr_debug("extKeyUsage: %d\n", ctx->cert->pub->eku);
+   return 0;
+   }
+
return 0;
 }
 
diff --git a/include/crypto/public_key.h b/include/crypto/public_key.h
index 47accec68cb0..1ccaebe2a28b 100644
--- a/include/crypto/public_key.h
+++ b/include/crypto/public_key.h
@@ -28,6 +28,7 @@ struct public_key {
bool key_is_private;
const char *id_type;
const char *pkey_algo;
+   unsigned int eku : 9;  /* Extended Key Usage (9-bit) */
 };
 
 extern void public_key_free(struct public_key *key);
diff --git a/include/linux/oid_registry.h b/include/linux/oid_registry.h
index 4462ed2c18cd..e20e8eb53b21 100644
--- a/include/linux/oid_registry.h
+++ b/include/linux/oid_registry.h
@@ -113,9 +113,14 @@ enum OID {
OID_SM2_with_SM3,   /* 1.2.156.10197.1.501 */
OID_sm3WithRSAEncryption,   /* 1.2.156.10197.1.504 */
 
+   /* Extended key purpose OIDs [RFC 5280] */
+   OID_codeSigning,/* 1.3.6.1.5.5.7.3.3 */
+
OID__NR
 };
 
+#define EKU_codeSigning(1 << 2)
+
 extern enum OID look_up_OID(const void *data, size_t datasize);
 extern int sprint_oid(const void *, size_t, char *, size_t);
 extern int sprint_OID(enum OID, char *, size_t);
-- 
2.16.4



[PATCH] mm: cma: Use pr_err_ratelimited for CMA warning

2021-03-09 Thread Baolin Wang
If we did not reserve extra CMA memory, the log buffer can be
easily filled up by CMA failure warning when the devices calling
dmam_alloc_coherent() to alloc DMA memory. Thus we can use
pr_err_ratelimited() instead to reduce the duplicate CMA warning.

Signed-off-by: Baolin Wang 
---
 mm/cma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/cma.c b/mm/cma.c
index 54eee21..d101bdb 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -500,8 +500,8 @@ struct page *cma_alloc(struct cma *cma, size_t count, 
unsigned int align,
}
 
if (ret && !no_warn) {
-   pr_err("%s: %s: alloc failed, req-size: %zu pages, ret: %d\n",
-  __func__, cma->name, count, ret);
+   pr_err_ratelimited("%s: %s: alloc failed, req-size: %zu pages, 
ret: %d\n",
+  __func__, cma->name, count, ret);
cma_debug_show_areas(cma);
}
 
-- 
1.8.3.1



Re: [PATCH] powerpc: Fix missing declaration of [en/dis]able_kernel_vsx()

2021-03-09 Thread Geert Uytterhoeven
Hi Christophe,

On Tue, Mar 9, 2021 at 9:52 AM Christophe Leroy
 wrote:
> Le 09/03/2021 à 09:45, Geert Uytterhoeven a écrit :
> > On Tue, Mar 9, 2021 at 9:39 AM Christophe Leroy
> >  wrote:
> >> Add stub instances of enable_kernel_vsx() and disable_kernel_vsx()
> >> when CONFIG_VSX is not set, to avoid following build failure.
> >>
> >>CC [M]  drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.o
> >> In file included from 
> >> ./drivers/gpu/drm/amd/amdgpu/../display/dc/dm_services_types.h:29,
> >>   from 
> >> ./drivers/gpu/drm/amd/amdgpu/../display/dc/dm_services.h:37,
> >>   from 
> >> drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:27:
> >> drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c: In function 
> >> 'dcn_bw_apply_registry_override':
> >> ./drivers/gpu/drm/amd/amdgpu/../display/dc/os_types.h:64:3: error: 
> >> implicit declaration of function 'enable_kernel_vsx'; did you mean 
> >> 'enable_kernel_fp'? [-Werror=implicit-function-declaration]
> >> 64 |   enable_kernel_vsx(); \
> >>|   ^
> >> drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:640:2: note: in 
> >> expansion of macro 'DC_FP_START'
> >>640 |  DC_FP_START();
> >>|  ^~~
> >> ./drivers/gpu/drm/amd/amdgpu/../display/dc/os_types.h:75:3: error: 
> >> implicit declaration of function 'disable_kernel_vsx'; did you mean 
> >> 'disable_kernel_fp'? [-Werror=implicit-function-declaration]
> >> 75 |   disable_kernel_vsx(); \
> >>|   ^~
> >> drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.c:676:2: note: in 
> >> expansion of macro 'DC_FP_END'
> >>676 |  DC_FP_END();
> >>|  ^
> >> cc1: some warnings being treated as errors
> >> make[5]: *** [drivers/gpu/drm/amd/amdgpu/../display/dc/calcs/dcn_calcs.o] 
> >> Error 1
> >>
> >> Fixes: 16a9dea110a6 ("amdgpu: Enable initial DCN support on POWER")
> >> Cc: sta...@vger.kernel.org
> >> Signed-off-by: Christophe Leroy 
> >
> > Thanks for your patch!
> >
> >> --- a/arch/powerpc/include/asm/switch_to.h
> >> +++ b/arch/powerpc/include/asm/switch_to.h
> >> @@ -71,6 +71,16 @@ static inline void disable_kernel_vsx(void)
> >>   {
> >>  msr_check_and_clear(MSR_FP|MSR_VEC|MSR_VSX);
> >>   }
> >> +#else
> >> +static inline void enable_kernel_vsx(void)
> >> +{
> >> +   BUILD_BUG();
> >> +}
> >> +
> >> +static inline void disable_kernel_vsx(void)
> >> +{
> >> +   BUILD_BUG();
> >> +}
> >>   #endif
> >
> > I'm wondering how this is any better than the current situation: using
> > BUILD_BUG() will still cause a build failure?
>
> No it won't cause a failure. In drivers/gpu/drm/amd/display/dc/os_types.h you 
> have:
>
> #define DC_FP_START() { \
> if (cpu_has_feature(CPU_FTR_VSX_COMP)) { \
> preempt_disable(); \
> enable_kernel_vsx(); \
> } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { \
> preempt_disable(); \
> enable_kernel_altivec(); \
> } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { \
> preempt_disable(); \
> enable_kernel_fp(); \
> } \
>
> When CONFIG_VSX is not selected, cpu_has_feature(CPU_FTR_VSX_COMP) constant 
> folds to 'false' so the
> call to enable_kernel_vsx() is discarded and the build succeeds.

IC. So you might as well have an empty (dummy) function instead?

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 1/2] mm: disable LRU pagevec during the migration temporarily

2021-03-09 Thread kernel test robot
Hi Minchan,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.12-rc2 next-20210309]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210309-131826
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
144c79ef33536b4ecb4951e07dbc1f2b7fa99d32
config: powerpc-skiroot_defconfig (attached as .config)
compiler: powerpc64le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/0day-ci/linux/commit/e746db1a2ab13441890fa2cad8604bbec190b401
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210309-131826
git checkout e746db1a2ab13441890fa2cad8604bbec190b401
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   In file included from mm/mempolicy.c:92:
   include/linux/migrate.h: In function 'migrate_prep':
   include/linux/migrate.h:70:48: error: 'return' with a value, in function 
returning void [-Werror=return-type]
  70 | static inline void migrate_prep(void) { return -ENOSYS; }
 |^
   include/linux/migrate.h:70:20: note: declared here
  70 | static inline void migrate_prep(void) { return -ENOSYS; }
 |^~~~
   include/linux/migrate.h: In function 'migrate_prep_local':
   include/linux/migrate.h:71:54: error: 'return' with a value, in function 
returning void [-Werror=return-type]
  71 | static inline void migrate_prep_local(void) { return -ENOSYS; }
 |  ^
   include/linux/migrate.h:71:20: note: declared here
  71 | static inline void migrate_prep_local(void) { return -ENOSYS; }
 |^~
   mm/mempolicy.c: In function 'do_mbind':
>> mm/mempolicy.c:1378:3: error: implicit declaration of function 
>> 'migrate_finish'; did you mean 'migrate_done'? 
>> [-Werror=implicit-function-declaration]
1378 |   migrate_finish();
 |   ^~
 |   migrate_done
   cc1: some warnings being treated as errors


vim +1378 mm/mempolicy.c

  1277  
  1278  static long do_mbind(unsigned long start, unsigned long len,
  1279   unsigned short mode, unsigned short mode_flags,
  1280   nodemask_t *nmask, unsigned long flags)
  1281  {
  1282  struct mm_struct *mm = current->mm;
  1283  struct mempolicy *new;
  1284  unsigned long end;
  1285  int err;
  1286  int ret;
  1287  LIST_HEAD(pagelist);
  1288  
  1289  if (flags & ~(unsigned long)MPOL_MF_VALID)
  1290  return -EINVAL;
  1291  if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
  1292  return -EPERM;
  1293  
  1294  if (start & ~PAGE_MASK)
  1295  return -EINVAL;
  1296  
  1297  if (mode == MPOL_DEFAULT)
  1298  flags &= ~MPOL_MF_STRICT;
  1299  
  1300  len = (len + PAGE_SIZE - 1) & PAGE_MASK;
  1301  end = start + len;
  1302  
  1303  if (end < start)
  1304  return -EINVAL;
  1305  if (end == start)
  1306  return 0;
  1307  
  1308  new = mpol_new(mode, mode_flags, nmask);
  1309  if (IS_ERR(new))
  1310  return PTR_ERR(new);
  1311  
  1312  if (flags & MPOL_MF_LAZY)
  1313  new->flags |= MPOL_F_MOF;
  1314  
  1315  /*
  1316   * If we are using the default policy then operation
  1317   * on discontinuous address spaces is okay after all
  1318   */
  1319  if (!new)
  1320  flags |= MPOL_MF_DISCONTIG_OK;
  1321  
  1322  pr_debug("mbind %lx-%lx mode:%d flags:%d nodes:%lx\n",
  1323   start, start + len, mode, mode_flags,
  1324   nmask ? nodes_addr(*nmask)[0] : NUMA_NO_NODE);
  1325  
  1326  if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
  1327  
  1328  migrate_prep();
  1329  }
  1330  {
  1331 

[PATCH] perf/x86/intel/lbr: Assign boolean values to a bool variable

2021-03-09 Thread Jiapeng Chong
Fix the following coccicheck warnings:

./arch/x86/events/intel/lbr.c:917:9-10: WARNING: return of 0/1 in
function 'get_lbr_predicted' with return type bool.

./arch/x86/events/intel/lbr.c:909:9-10: WARNING: return of 0/1 in
function 'get_lbr_mispred' with return type bool.

Reported-by: Abaci Robot 
Signed-off-by: Jiapeng Chong 
---
 arch/x86/events/intel/lbr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index 21890da..edf8247 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -906,7 +906,7 @@ static __always_inline int get_lbr_br_type(u64 info)
 static __always_inline bool get_lbr_mispred(u64 info)
 {
if (static_cpu_has(X86_FEATURE_ARCH_LBR) && !x86_pmu.lbr_mispred)
-   return 0;
+   return false;
 
return !!(info & LBR_INFO_MISPRED);
 }
@@ -914,7 +914,7 @@ static __always_inline bool get_lbr_mispred(u64 info)
 static __always_inline bool get_lbr_predicted(u64 info)
 {
if (static_cpu_has(X86_FEATURE_ARCH_LBR) && !x86_pmu.lbr_mispred)
-   return 0;
+   return false;
 
return !(info & LBR_INFO_MISPRED);
 }
-- 
1.8.3.1



Re: [PATCH] ARM: omap1: fix building with clang IAS

2021-03-09 Thread Tony Lindgren
* Arnd Bergmann  [210308 15:35]:
> From: Arnd Bergmann 
> 
> The clang integrated assembler fails to build one file with
> a complex asm instruction:
> 
> arch/arm/mach-omap1/ams-delta-fiq-handler.S:249:2: error: invalid 
> instruction, any one of the following would fix this:
>  mov r10, #(1 << (((NR_IRQS_LEGACY + 12) - NR_IRQS_LEGACY) % 32)) @ set 
> deferred_fiq bit
>  ^
> arch/arm/mach-omap1/ams-delta-fiq-handler.S:249:2: note: instruction 
> requires: armv6t2
>  mov r10, #(1 << (((NR_IRQS_LEGACY + 12) - NR_IRQS_LEGACY) % 32)) @ set 
> deferred_fiq bit
>  ^
> arch/arm/mach-omap1/ams-delta-fiq-handler.S:249:2: note: instruction 
> requires: thumb2
>  mov r10, #(1 << (((NR_IRQS_LEGACY + 12) - NR_IRQS_LEGACY) % 32)) @ set 
> deferred_fiq bit
>  ^
> 
> The problem is that 'NR_IRQS_LEGACY' is not defined here. Apparently
> gas does not care because we first add and then subtract this number,
> leading to the immediate value to be the same regardless of the
> specific definition of NR_IRQS_LEGACY.
> 
> Neither the way that 'gas' just silently builds this file, nor the
> way that clang IAS makes nonsensical suggestions for how to fix it
> is great. Fortunately there is an easy fix, which is to #include
> the header that contains the definition.

Acked-by: Tony Lindgren 


Re: [PATCH net-next v3] net: Add Qcom WWAN control driver

2021-03-09 Thread kernel test robot
Hi Loic,

I love your patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Loic-Poulain/net-Add-Qcom-WWAN-control-driver/20210309-163643
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 
d310ec03a34e92a77302edb804f7d68ee4f01ba0
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/0day-ci/linux/commit/f4fcd3ed7ac5f29a28988eed9f5516f874073802
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Loic-Poulain/net-Add-Qcom-WWAN-control-driver/20210309-163643
git checkout f4fcd3ed7ac5f29a28988eed9f5516f874073802
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=m68k 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   In file included from include/linux/kernel.h:10,
from drivers/net/wwan/mhi_wwan_ctrl.c:4:
   include/linux/scatterlist.h: In function 'sg_set_buf':
   arch/m68k/include/asm/page_mm.h:174:49: warning: ordered comparison of 
pointer with null pointer [-Wextra]
 174 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void 
*)PAGE_OFFSET && (void *)(kaddr) < high_memory)
 | ^~
   include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
  78 | # define unlikely(x) __builtin_expect(!!(x), 0)
 |  ^
   include/linux/scatterlist.h:137:2: note: in expansion of macro 'BUG_ON'
 137 |  BUG_ON(!virt_addr_valid(buf));
 |  ^~
   include/linux/scatterlist.h:137:10: note: in expansion of macro 
'virt_addr_valid'
 137 |  BUG_ON(!virt_addr_valid(buf));
 |  ^~~
   In file included from include/linux/kernel.h:14,
from drivers/net/wwan/mhi_wwan_ctrl.c:4:
   drivers/net/wwan/mhi_wwan_ctrl.c: In function 'mhi_wwan_ctrl_probe':
>> drivers/net/wwan/mhi_wwan_ctrl.c:442:48: error: 'MHI_MAX_MTU' undeclared 
>> (first use in this function); did you mean 'ETH_MAX_MTU'?
 442 |  wwandev->mtu = min_t(size_t, id->driver_data, MHI_MAX_MTU);
 |^~~
   include/linux/minmax.h:18:39: note: in definition of macro '__typecheck'
  18 |  (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 |   ^
   include/linux/minmax.h:42:24: note: in expansion of macro '__safe_cmp'
  42 |  __builtin_choose_expr(__safe_cmp(x, y), \
 |^~
   include/linux/minmax.h:110:27: note: in expansion of macro '__careful_cmp'
 110 | #define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <)
 |   ^
   drivers/net/wwan/mhi_wwan_ctrl.c:442:17: note: in expansion of macro 'min_t'
 442 |  wwandev->mtu = min_t(size_t, id->driver_data, MHI_MAX_MTU);
 | ^
   drivers/net/wwan/mhi_wwan_ctrl.c:442:48: note: each undeclared identifier is 
reported only once for each function it appears in
 442 |  wwandev->mtu = min_t(size_t, id->driver_data, MHI_MAX_MTU);
 |^~~
   include/linux/minmax.h:18:39: note: in definition of macro '__typecheck'
  18 |  (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 |   ^
   include/linux/minmax.h:42:24: note: in expansion of macro '__safe_cmp'
  42 |  __builtin_choose_expr(__safe_cmp(x, y), \
 |^~
   include/linux/minmax.h:110:27: note: in expansion of macro '__careful_cmp'
 110 | #define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <)
 |   ^
   drivers/net/wwan/mhi_wwan_ctrl.c:442:17: note: in expansion of macro 'min_t'
 442 |  wwandev->mtu = min_t(size_t, id->driver_data, MHI_MAX_MTU);
 | ^
   include/linux/minmax.h:42:2: error: first argument to 
'__builtin_choose_expr' not a constant
  42 |  __builtin_choose_expr(__safe_cmp(x, y), \
 |  ^
   include/linux/minmax.h:110:27: note: in expansion of macro '__careful_cmp'
 110 | #define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <)
 |   ^
   drivers/net/wwan/mhi_wwan_ctrl.c:442:17: note: in expansion of macro 'min_t'
 442 |  wwandev->mtu = min_t(size_t, id->driver_data, MHI_MAX_MTU);
 

[PATCH] perf machine: Assign boolean values to a bool variable

2021-03-09 Thread Jiapeng Chong
Fix the following coccicheck warnings:

./tools/perf/util/machine.c:2041:9-10: WARNING: return of 0/1 in
function 'symbol__match_regex' with return type bool.

Reported-by: Abaci Robot 
Signed-off-by: Jiapeng Chong 
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index b5c2d8b..435771e 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2038,8 +2038,8 @@ int machine__process_event(struct machine *machine, union 
perf_event *event,
 static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
 {
if (!regexec(regex, sym->name, 0, NULL, 0))
-   return 1;
-   return 0;
+   return true;
+   return false;
 }
 
 static void ip__resolve_ams(struct thread *thread,
-- 
1.8.3.1



Re: [PATCH net-next v3] net: Add Qcom WWAN control driver

2021-03-09 Thread Greg KH
On Tue, Mar 09, 2021 at 11:28:49AM +0100, Loic Poulain wrote:
> Hi Greg,
> 
> On Tue, 9 Mar 2021 at 10:35, Greg KH  wrote:
> >
> > On Tue, Mar 09, 2021 at 09:42:16AM +0100, Loic Poulain wrote:
> > > The MHI WWWAN control driver allows MHI Qcom based modems to expose
> > > different modem control protocols/ports to userspace, so that userspace
> > > modem tools or daemon (e.g. ModemManager) can control WWAN config
> > > and state (APN config, SMS, provider selection...). A Qcom based
> > > modem can expose one or several of the following protocols:
> > > - AT: Well known AT commands interactive protocol (microcom, minicom...)
> > > - MBIM: Mobile Broadband Interface Model (libmbim, mbimcli)
> > > - QMI: Qcom MSM/Modem Interface (libqmi, qmicli)
> > > - QCDM: Qcom Modem diagnostic interface (libqcdm)
> > > - FIREHOSE: XML-based protocol for Modem firmware management
> > > (qmi-firmware-update)
> > >
> > > The different interfaces are exposed as character devices, in the same
> > > way as for USB modem variants (known as modem 'ports').
> > >
> > > Note that this patch is mostly a rework of the earlier MHI UCI
> > > tentative that was a generic interface for accessing MHI bus from
> > > userspace. As suggested, this new version is WWAN specific and is
> > > dedicated to only expose channels used for controlling a modem, and
> > > for which related opensource user support exist. Other MHI channels
> > > not fitting the requirements will request either to be plugged to
> > > the right Linux subsystem (when available) or to be discussed as a
> > > new MHI driver (e.g AI accelerator, WiFi debug channels, etc...).
> > >
> > > This change introduces a new drivers/net/wwan directory, aiming to
> > > be the common place for WWAN drivers.
> > >
> > > Co-developed-by: Hemant Kumar 
> > > Signed-off-by: Hemant Kumar 
> > > Signed-off-by: Loic Poulain 
> > > ---
> > >  v2: update copyright (2021)
> > >  v3: Move driver to dedicated drivers/net/wwan directory
> > >
> > >  drivers/net/Kconfig  |   2 +
> > >  drivers/net/Makefile |   1 +
> > >  drivers/net/wwan/Kconfig |  26 ++
> > >  drivers/net/wwan/Makefile|   6 +
> > >  drivers/net/wwan/mhi_wwan_ctrl.c | 559 
> > > +++
> > >  5 files changed, 594 insertions(+)
> > >  create mode 100644 drivers/net/wwan/Kconfig
> > >  create mode 100644 drivers/net/wwan/Makefile
> > >  create mode 100644 drivers/net/wwan/mhi_wwan_ctrl.c
> > >
> > > diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> > > index 1ebb4b9..28b18f2 100644
> > > --- a/drivers/net/Kconfig
> > > +++ b/drivers/net/Kconfig
> > > @@ -501,6 +501,8 @@ source "drivers/net/wan/Kconfig"
> > >
> > >  source "drivers/net/ieee802154/Kconfig"
> > >
> > > +source "drivers/net/wwan/Kconfig"
> > > +
> > >  config XEN_NETDEV_FRONTEND
> > >   tristate "Xen network device frontend driver"
> > >   depends on XEN
> > > diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> > > index f4990ff..5da6424 100644
> > > --- a/drivers/net/Makefile
> > > +++ b/drivers/net/Makefile
> > > @@ -68,6 +68,7 @@ obj-$(CONFIG_SUNGEM_PHY) += sungem_phy.o
> > >  obj-$(CONFIG_WAN) += wan/
> > >  obj-$(CONFIG_WLAN) += wireless/
> > >  obj-$(CONFIG_IEEE802154) += ieee802154/
> > > +obj-$(CONFIG_WWAN) += wwan/
> > >
> > >  obj-$(CONFIG_VMXNET3) += vmxnet3/
> > >  obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
> > > diff --git a/drivers/net/wwan/Kconfig b/drivers/net/wwan/Kconfig
> > > new file mode 100644
> > > index 000..643aa10
> > > --- /dev/null
> > > +++ b/drivers/net/wwan/Kconfig
> > > @@ -0,0 +1,26 @@
> > > +# SPDX-License-Identifier: GPL-2.0-only
> > > +#
> > > +# Wireless WAN device configuration
> > > +#
> > > +
> > > +menuconfig WWAN
> > > +   bool "Wireless WAN"
> > > +   help
> > > + This section contains Wireless WAN driver configurations.
> > > +
> > > +if WWAN
> > > +
> > > +config MHI_WWAN_CTRL
> > > + tristate "MHI WWAN control driver for QCOM based PCIe modems"
> > > + depends on MHI_BUS
> > > + help
> > > +   MHI WWAN CTRL allow QCOM based PCIe modems to expose different 
> > > modem
> > > +   control protocols/ports to userspace, including AT, MBIM, QMI, 
> > > DIAG
> > > +   and FIREHOSE. These protocols can be accessed directly from 
> > > userspace
> > > +   (e.g. AT commands) or via libraries/tools (e.g. libmbim, libqmi,
> > > +   libqcdm...).
> > > +
> > > +   To compile this driver as a module, choose M here: the module 
> > > will be
> > > +   called mhi_wwan_ctrl.
> > > +
> > > +endif # WWAN
> > > diff --git a/drivers/net/wwan/Makefile b/drivers/net/wwan/Makefile
> > > new file mode 100644
> > > index 000..994a80b
> > > --- /dev/null
> > > +++ b/drivers/net/wwan/Makefile
> > > @@ -0,0 +1,6 @@
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +#
> > > +# Makefile for the Linux WWAN device drivers.
> > > +#
> > > +
> > > +obj-$(CONFIG_MHI_WWAN_CTRL) += 

Re: [PATCH 4.4 1/3] futex: Change locking rules

2021-03-09 Thread Greg KH
On Tue, Mar 09, 2021 at 11:06:03AM +0800, Zheng Yejian wrote:
> From: Peter Zijlstra 
> 
> Currently futex-pi relies on hb->lock to serialize everything. But hb->lock
> creates another set of problems, especially priority inversions on RT where
> hb->lock becomes a rt_mutex itself.
> 
> The rt_mutex::wait_lock is the most obvious protection for keeping the
> futex user space value and the kernel internal pi_state in sync.
> 
> Rework and document the locking so rt_mutex::wait_lock is held accross all
> operations which modify the user space value and the pi state.
> 
> This allows to invoke rt_mutex_unlock() (including deboost) without holding
> hb->lock as a next step.
> 
> Nothing yet relies on the new locking rules.
> 
> Signed-off-by: Peter Zijlstra (Intel) 
> Cc: juri.le...@arm.com
> Cc: bige...@linutronix.de
> Cc: xlp...@redhat.com
> Cc: rost...@goodmis.org
> Cc: mathieu.desnoy...@efficios.com
> Cc: jdesfos...@efficios.com
> Cc: dvh...@infradead.org
> Cc: bris...@redhat.com
> Link: http://lkml.kernel.org/r/20170322104151.751993...@infradead.org
> Signed-off-by: Thomas Gleixner 
> [Lee: Back-ported in support of a previous futex back-port attempt]
> Signed-off-by: Lee Jones 
> Signed-off-by: Greg Kroah-Hartman 
> Signed-off-by: Zheng Yejian 
> ---
>  kernel/futex.c | 138 +++--
>  1 file changed, 112 insertions(+), 26 deletions(-)

What is the git commit id of this patch in Linus's tree?

thanks,

greg k-h


[RESEND PATCH v2] soundwire: bus: Fix device found flag correctly

2021-03-09 Thread Srinivas Kandagatla
found flag is used to indicate SoundWire devices that are
both enumerated on the bus and available in the device list.
However this flag is not reset correctly after one iteration,
This could miss some of the devices that are enumerated on the
bus but not in device list. So reset this correctly to fix this issue!

Fixes: d52d7a1be02c ("soundwire: Add Slave status handling helpers")
Signed-off-by: Srinivas Kandagatla 
Reviewed-by: Pierre-Louis Bossart 
---
For some reason I ended up deleting Fixes tag so resending with it!

 drivers/soundwire/bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index a9ab4a6264e0..188e391c5a83 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -712,7 +712,7 @@ static int sdw_program_device_num(struct sdw_bus *bus)
struct sdw_slave *slave, *_s;
struct sdw_slave_id id;
struct sdw_msg msg;
-   bool found = false;
+   bool found;
int count = 0, ret;
u64 addr;
 
@@ -744,6 +744,7 @@ static int sdw_program_device_num(struct sdw_bus *bus)
 
sdw_extract_slave_id(bus, addr, );
 
+   found = false;
/* Now compare with entries */
list_for_each_entry_safe(slave, _s, >slaves, node) {
if (sdw_compare_devid(slave, id) == 0) {
-- 
2.21.0



Re: [PATCH v1 1/7] pps: clients: gpio: Bail out on error when requesting GPIO echo line

2021-03-09 Thread Andy Shevchenko
+Cc: Greg

On Fri, Feb 26, 2021 at 07:03:32PM +0200, Andy Shevchenko wrote:
> On Tue, Feb 16, 2021 at 01:31:48PM +0200, Andy Shevchenko wrote:
> > When requesting optional GPIO echo line, bail out on error,
> > so user will know that something wrong with the existing property.
> 
> Guys, any comments on this series?

Greg, seems PPS maintainer keeps silent, can I route this series thru one of
yours tree (resend implied)?

-- 
With Best Regards,
Andy Shevchenko




Re: [PATCH v2 2/2] irqchip: add support for BCM6345 external interrupt controller

2021-03-09 Thread Marc Zyngier
On Wed, 24 Feb 2021 07:56:40 +,
Álvaro Fernández Rojas  wrote:
> 
> This interrupt controller is present on bcm63xx SoCs in order to generate
> interrupts based on GPIO status changes.
> 
> Signed-off-by: Álvaro Fernández Rojas 
> Signed-off-by: Jonas Gorski 
> Reviewed-by: Florian Fainelli 
> ---
>  v3: no changes.
>  v2: no changes.
> 
>  drivers/irqchip/Kconfig   |   4 +
>  drivers/irqchip/Makefile  |   1 +
>  drivers/irqchip/irq-bcm6345-ext.c | 271 ++
>  3 files changed, 276 insertions(+)
>  create mode 100644 drivers/irqchip/irq-bcm6345-ext.c
> 
> diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
> index e74fa206240a..eaa101939a34 100644
> --- a/drivers/irqchip/Kconfig
> +++ b/drivers/irqchip/Kconfig
> @@ -113,6 +113,10 @@ config I8259
>   bool
>   select IRQ_DOMAIN
>  
> +config BCM6345_EXT_IRQ
> + bool "BCM6345 External IRQ Controller"
> + select IRQ_DOMAIN
> +
>  config BCM6345_L1_IRQ
>   bool
>   select GENERIC_IRQ_CHIP
> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index c59b95a0532c..3cba65bc0aa5 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -62,6 +62,7 @@ obj-$(CONFIG_XTENSA_MX) += 
> irq-xtensa-mx.o
>  obj-$(CONFIG_XILINX_INTC)+= irq-xilinx-intc.o
>  obj-$(CONFIG_IRQ_CROSSBAR)   += irq-crossbar.o
>  obj-$(CONFIG_SOC_VF610)  += irq-vf610-mscm-ir.o
> +obj-$(CONFIG_BCM6345_EXT_IRQ)+= irq-bcm6345-ext.o
>  obj-$(CONFIG_BCM6345_L1_IRQ) += irq-bcm6345-l1.o
>  obj-$(CONFIG_BCM7038_L1_IRQ) += irq-bcm7038-l1.o
>  obj-$(CONFIG_BCM7120_L2_IRQ) += irq-bcm7120-l2.o
> diff --git a/drivers/irqchip/irq-bcm6345-ext.c 
> b/drivers/irqchip/irq-bcm6345-ext.c
> new file mode 100644
> index ..5721ac8de295
> --- /dev/null
> +++ b/drivers/irqchip/irq-bcm6345-ext.c
> @@ -0,0 +1,271 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Broadcom BCM6345 style external interrupt controller driver
> + *
> + * Copyright (C) 2021 Álvaro Fernández Rojas 
> + * Copyright (C) 2014 Jonas Gorski 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MAX_IRQS 4
> +
> +#define EXTIRQ_CFG_SENSE 0
> +#define EXTIRQ_CFG_STAT  1
> +#define EXTIRQ_CFG_CLEAR 2
> +#define EXTIRQ_CFG_MASK  3
> +#define EXTIRQ_CFG_BOTHEDGE  4
> +#define EXTIRQ_CFG_LEVELSENSE5
> +
> +struct intc_data {
> + struct irq_chip chip;
> + struct irq_domain *domain;
> + raw_spinlock_t lock;
> +
> + int parent_irq[MAX_IRQS];
> + void __iomem *reg;
> + int shift;
> + unsigned int toggle_clear_on_ack:1;

Please use the bool type.

> +};
> +
> +static void bcm6345_ext_intc_irq_handle(struct irq_desc *desc)
> +{
> + struct intc_data *data = irq_desc_get_handler_data(desc);
> + struct irq_chip *chip = irq_desc_get_chip(desc);
> + unsigned int irq = irq_desc_get_irq(desc);
> + unsigned int idx;
> +
> + chained_irq_enter(chip, desc);
> +
> + for (idx = 0; idx < MAX_IRQS; idx++) {
> + if (data->parent_irq[idx] != irq)
> + continue;
> +
> + generic_handle_irq(irq_find_mapping(data->domain, idx));

One parent IRQ per input? Why isn't this a hierarchical interrupt
controller? Even *if* this really has to be a chained interrupt
controller, I'm sure there are better ways to identify the input then
this loop (offset from a base, for example).

> + }
> +
> + chained_irq_exit(chip, desc);
> +}
> +
> +static void bcm6345_ext_intc_irq_ack(struct irq_data *data)
> +{
> + struct intc_data *priv = data->domain->host_data;
> + irq_hw_number_t hwirq = irqd_to_hwirq(data);
> + u32 reg;
> +
> + raw_spin_lock(>lock);
> + reg = __raw_readl(priv->reg);
> + __raw_writel(reg | (1 << (hwirq + EXTIRQ_CFG_CLEAR * priv->shift)),
> +  priv->reg);
> + if (priv->toggle_clear_on_ack)

Under what condition do you need this?

> + __raw_writel(reg, priv->reg);
> + raw_spin_unlock(>lock);
> +}
> +
> +static void bcm6345_ext_intc_irq_mask(struct irq_data *data)
> +{
> + struct intc_data *priv = data->domain->host_data;
> + irq_hw_number_t hwirq = irqd_to_hwirq(data);
> + u32 reg;
> +
> + raw_spin_lock(>lock);
> + reg = __raw_readl(priv->reg);
> + reg &= ~(1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift));
> + __raw_writel(reg, priv->reg);
> + raw_spin_unlock(>lock);
> +}
> +
> +static void bcm6345_ext_intc_irq_unmask(struct irq_data *data)
> +{
> + struct intc_data *priv = data->domain->host_data;
> + irq_hw_number_t hwirq = irqd_to_hwirq(data);
> + u32 reg;
> +
> + raw_spin_lock(>lock);
> + reg = __raw_readl(priv->reg);
> + reg |= 1 << (hwirq + EXTIRQ_CFG_MASK * priv->shift);
> + 

Re: [PATCH v2 2/2] mm: fs: Invalidate BH LRU during page migration

2021-03-09 Thread kernel test robot
Hi Minchan,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.12-rc2 next-20210309]
[cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210309-131826
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
144c79ef33536b4ecb4951e07dbc1f2b7fa99d32
config: openrisc-randconfig-r026-20210308 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/0day-ci/linux/commit/dfca8699b8fb8cf3bed2297e261fca53c0fc523c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Minchan-Kim/mm-disable-LRU-pagevec-during-the-migration-temporarily/20210309-131826
git checkout dfca8699b8fb8cf3bed2297e261fca53c0fc523c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=openrisc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   mm/swap.c:745:6: warning: no previous prototype for '__lru_add_drain_all' 
[-Wmissing-prototypes]
 745 | void __lru_add_drain_all(bool force_all_cpus)
 |  ^~~
   mm/swap.c: In function '__lru_add_drain_all':
>> mm/swap.c:827:7: error: implicit declaration of function 'has_bh_in_lru' 
>> [-Werror=implicit-function-declaration]
 827 |   has_bh_in_lru(cpu, NULL)) {
 |   ^
   cc1: some warnings being treated as errors


vim +/has_bh_in_lru +827 mm/swap.c

   744  
   745  void __lru_add_drain_all(bool force_all_cpus)
   746  {
   747  /*
   748   * lru_drain_gen - Global pages generation number
   749   *
   750   * (A) Definition: global lru_drain_gen = x implies that all 
generations
   751   * 0 < n <= x are already *scheduled* for draining.
   752   *
   753   * This is an optimization for the highly-contended use case 
where a
   754   * user space workload keeps constantly generating a flow of 
pages for
   755   * each CPU.
   756   */
   757  static unsigned int lru_drain_gen;
   758  static struct cpumask has_work;
   759  static DEFINE_MUTEX(lock);
   760  unsigned cpu, this_gen;
   761  
   762  /*
   763   * Make sure nobody triggers this path before mm_percpu_wq is 
fully
   764   * initialized.
   765   */
   766  if (WARN_ON(!mm_percpu_wq))
   767  return;
   768  
   769  /*
   770   * Guarantee pagevec counter stores visible by this CPU are 
visible to
   771   * other CPUs before loading the current drain generation.
   772   */
   773  smp_mb();
   774  
   775  /*
   776   * (B) Locally cache global LRU draining generation number
   777   *
   778   * The read barrier ensures that the counter is loaded before 
the mutex
   779   * is taken. It pairs with smp_mb() inside the mutex critical 
section
   780   * at (D).
   781   */
   782  this_gen = smp_load_acquire(_drain_gen);
   783  
   784  mutex_lock();
   785  
   786  /*
   787   * (C) Exit the draining operation if a newer generation, from 
another
   788   * lru_add_drain_all(), was already scheduled for draining. 
Check (A).
   789   */
   790  if (unlikely(this_gen != lru_drain_gen && !force_all_cpus))
   791  goto done;
   792  
   793  /*
   794   * (D) Increment global generation number
   795   *
   796   * Pairs with smp_load_acquire() at (B), outside of the critical
   797   * section. Use a full memory barrier to guarantee that the new 
global
   798   * drain generation number is stored before loading pagevec 
counters.
   799   *
   800   * This pairing must be done here, before the 
for_each_online_cpu loop
   801   * below which drains the page vectors.
   802   *
   803   * Let x, y, and z represent some system CPU numbers, where x < 
y < z.
   804   * Assume CPU #z is is in the middle of the for_each_online_cpu 
loop
   805   * below and has already reached CPU #y's per-cpu data. CPU #x 
comes
   806   * along, adds some pages to 

Re: Metadata writtenback notification? -- was Re: fscache: Redesigning the on-disk cache

2021-03-09 Thread David Howells
Dave Chinner  wrote:

> > > There was a discussion about fsyncing a range of files on LSFMM [1].
> > > In the last comment on the article dchinner argues why we already have 
> > > that
> > > API (and now also with io_uring(), but AFAIK, we do not have a useful
> > > wait_for_sync() API. And it doesn't need to be exposed to userspace at 
> > > all.
> > > 
> > > [1] https://lwn.net/Articles/789024/
> > 
> > This sounds like an interesting idea.  Actually, what I probably want is a
> > notification to say that a particular object has been completely sync'd to
> > disk, metadata and all.
> 
> This isn't hard to do yourself in the kernel. All it takes is a
> workqueue to run vfs_fsync() calls asynchronously and for the work
> to queue a local notification/wakeup when the fsync completes...
> 
> That's all aio_fsync() does - the notification it queues on
> completion is the AIO completion event for userspace - so I think
> you could do this in about 50 lines of code if you really needed
> it...

I was thinking more in terms of passively finding out when metadata has been
flushed to disk rather than actively forcing it.  Obviously I can manually
flush from a worker thread, but that ties up a thread per file I want to
flush (unless I want to do a higher-level sync).

Btw, looking at aio_fsync(), is there any reason it copies the current creds
rather than just taking a ref on them?  (Granted, this may not be a question
for you)

> > However, there are some performance problems are arising in my fscache-iter
> > branch:
> > 
> >  (1) It's doing a lot of synchronous metadata operations (tmpfile, truncate,
> >  setxattr).
> 
> Async pipelines using unbound workqueues are your friend.

Maybe.  I could just throw everything into a workqueue and let the workqueue
deal with it.  There still have to be synchronisation points, though - I can't
schedule a cache-write from a server-read to the cache following a 3rd-party
induced invalidation until after the invalidation has happened - and that
holds up userspace from writing to the cache.  But maybe it will work.

Btw, how expensive is it to throw an operation off to a workqueue versus doing
it in thread?  Particularly if it's a synchronous op that the thread is going
to have to wait for (e.g. write_begin()).

> >  (2) It's retaining a lot of open file structs on cache files.  Cachefiles
> >  opens the file when it's first asked to access it and retains that till
> >  the cookie is relinquished or the cache withdrawn (the file* doesn't
> >  contribute to ENFILE/EMFILE but it still eats memory).
> 
> Sounds similar to the problem that the NFSd open file cache solves.
> (fs/nfsd/filecache.c)

Looks similiarish to what I was thinking of with having a queue of
currently-not-in-use cookies to go through and commit and close.

> >  but if the file is truncated
> >  larger, that excess data now becomes part of the file.
> 
> Keep the actual file size in your tracking xattr.

I do that, but it doesn't help entirely.  If someone truncates the file larger
and then writes non-contiguously, the problem occurs.

I've tried truncating the file down and then truncating it up, but that
requires two synchronous ops - though the latter is relatively cheap.  I've
also tried fallocate() to clear the block.  What I've found is that the next
DIO write then has to sync because these may read data into the pagecache of
the backing file.

Apart from clearing the tail of a page on writing, it might be better for me
to read the data into a spare page, clear the tail and write it back.

> >  Possibly it's sufficient to just clear the excess page space before
> >  writing, but that doesn't necessarily stop a writable mmap from
> >  scribbling on it.
> 
> We can't stop mmap from scribbling in it. All filesystems have this
> problem, so to prevent data leaks we have to zero the post-eof tail
> region on every write of the EOF block, anyway.

I meant an mmap scribbling on it after it's been cleared - but I guess taking
away the PTE-writeable flag and making page_mkwrite() wait should solve that.

> >  (4) Committing outstanding cache metadata at cache withdrawal or netfs
> >  unmount.  I've previously mentioned this: it ends up with a whole
> >  slew of synchronous metadata changes being committed to the cache in
> >  one go (truncates, fallocates, fsync, xattrs, unlink+link of tmpfile)
> >  - and this can take quite a long time.  The cache needs to be more
> >  proactive in getting stuff committed as it goes along.
> 
> Workqueues give you an easy mechanism for async dispatch and
> concurrency for synchronous operations. This is a largely solved
> problem...

Yes and no.  Yes, I can fan out the number of threads doing the committing,
but there's still a limit on the I/O bandwidth - and a lot of the operations
still have to hit the disk in the right order.  It still stuffs up the user
experience if the cache eats up the entirety of the disk I/O for a 

[PATCH v2 31/43] powerpc/32: Only restore non volatile registers when required

2021-03-09 Thread Christophe Leroy
Until now, non volatile registers were restored everytime they
were saved, ie using EXC_XFER_STD meant saving and restoring
them while EXC_XFER_LITE meant neither saving not restoring them.

Now that they are always saved, EXC_XFER_STD means to restore
them and EXC_XFER_LITE means to not restore them.

Most of the users of EXC_XFER_STD only need to retrieve the
non volatile registers. For them there is no need to restore
the non volatile registers as they have not been modified.

Only very few exceptions require non volatile registers restore.

Opencode the few places which require saving of non volatile
registers.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   |  1 -
 arch/powerpc/kernel/head_40x.S   | 10 --
 arch/powerpc/kernel/head_8xx.S   | 24 
 arch/powerpc/kernel/head_book3s_32.S | 17 ++---
 arch/powerpc/kernel/head_booke.h | 10 --
 arch/powerpc/kernel/head_fsl_booke.S | 16 
 6 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index e2346662444d..ca14bc2f3418 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -335,7 +335,6 @@ _ASM_NOKPROBE_SYMBOL(fast_exception_return)
 
.globl  ret_from_except_full
 ret_from_except_full:
-   REST_NVGPRS(r1)
/* fall through */
 
.globl  ret_from_except
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 7270caff665c..f3e5b462113f 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -228,12 +228,18 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 /* 0x0600 - Alignment Exception */
START_EXCEPTION(0x0600, Alignment)
EXCEPTION_PROLOG 0x600 Alignment handle_dar_dsisr=1
-   EXC_XFER_STD(0x600, alignment_exception)
+   prepare_transfer_to_handler
+   bl  alignment_exception
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 /* 0x0700 - Program Exception */
START_EXCEPTION(0x0700, ProgramCheck)
EXCEPTION_PROLOG 0x700 ProgramCheck handle_dar_dsisr=1
-   EXC_XFER_STD(0x700, program_check_exception)
+   prepare_transfer_to_handler
+   bl  program_check_exception
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
EXCEPTION(0x0800, Trap_08, unknown_exception, EXC_XFER_STD)
EXCEPTION(0x0900, Trap_09, unknown_exception, EXC_XFER_STD)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index c48de97f42fc..86f844eb0e5a 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -131,10 +131,18 @@ instruction_counter:
 /* Alignment exception */
START_EXCEPTION(0x600, Alignment)
EXCEPTION_PROLOG 0x600 Alignment handle_dar_dsisr=1
-   EXC_XFER_STD(0x600, alignment_exception)
+   prepare_transfer_to_handler
+   bl  alignment_exception
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 /* Program check exception */
-   EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
+   START_EXCEPTION(0x700, ProgramCheck)
+   EXCEPTION_PROLOG 0x700 ProgramCheck
+   prepare_transfer_to_handler
+   bl  program_check_exception
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 /* Decrementer */
EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
@@ -149,7 +157,12 @@ instruction_counter:
 /* On the MPC8xx, this is a software emulation interrupt.  It occurs
  * for all unimplemented and illegal instructions.
  */
-   EXCEPTION(0x1000, SoftEmu, emulation_assist_interrupt, EXC_XFER_STD)
+   START_EXCEPTION(0x1000, SoftEmu)
+   EXCEPTION_PROLOG 0x1000 SoftEmu
+   prepare_transfer_to_handler
+   bl  emulation_assist_interrupt
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 /*
  * For the MPC8xx, this is a software tablewalk to load the instruction
@@ -348,7 +361,10 @@ DARFixed:/* Return from dcbx instruction bug workaround */
EXCEPTION_PROLOG_2 0x1c00 DataBreakpoint handle_dar_dsisr=1
mfspr   r4,SPRN_BAR
stw r4,_DAR(r11)
-   EXC_XFER_STD(0x1c00, do_break)
+   prepare_transfer_to_handler
+   bl  do_break
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 #ifdef CONFIG_PERF_EVENTS
START_EXCEPTION(0x1d00, InstructionBreakpoint)
diff --git a/arch/powerpc/kernel/head_book3s_32.S 
b/arch/powerpc/kernel/head_book3s_32.S
index 67dac65b8ec3..609b2eedd4f9 100644
--- a/arch/powerpc/kernel/head_book3s_32.S
+++ b/arch/powerpc/kernel/head_book3s_32.S
@@ -300,7 +300,10 @@ ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_HPTE_TABLE)
andis.  r0, r5, DSISR_DABRMATCH@h
bne-1f
EXC_XFER_LITE(0x300, do_page_fault)
-1: EXC_XFER_STD(0x300, do_break)
+1: prepare_transfer_to_handler
+   bl  do_break
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 
 

[PATCH v2 30/43] powerpc/32: Add a prepare_transfer_to_handler macro for exception prologs

2021-03-09 Thread Christophe Leroy
In order to increase flexibility, add a macro that will for now
call transfer_to_handler.

As transfer_to_handler doesn't do the actual transfer anymore,
also name it prepare_transfer_to_handler. The following patches
will progressively remove the use of transfer_to_handler label.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 3 +++
 arch/powerpc/kernel/head_32.h| 4 
 arch/powerpc/kernel/head_booke.h | 4 
 3 files changed, 11 insertions(+)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index cb2fa00b8fc1..e2346662444d 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -86,6 +86,8 @@ _ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
 
.globl  transfer_to_handler
 transfer_to_handler:
+   .globl  prepare_transfer_to_handler
+prepare_transfer_to_handler:
SAVE_NVGPRS(r11)
addir3,r1,STACK_FRAME_OVERHEAD
stw r2,GPR2(r11)
@@ -132,6 +134,7 @@ transfer_to_handler_cont:
stw r9,_MSR(r11)
b   fast_exception_return
 #endif
+_ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler)
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
 
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index bf4c288173ad..3ab0f3ad9a6a 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -115,6 +115,10 @@
 _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 .endm
 
+.macro prepare_transfer_to_handler
+   bl  prepare_transfer_to_handler
+.endm
+
 .macro SYSCALL_ENTRY trapno
mfspr   r9, SPRN_SRR1
mfspr   r10, SPRN_SRR0
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 27a7358c04bb..0f02b970e797 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -87,6 +87,10 @@ END_BTB_FLUSH_SECTION
SAVE_4GPRS(3, r11);  \
SAVE_2GPRS(7, r11)
 
+.macro prepare_transfer_to_handler
+   bl  prepare_transfer_to_handler
+.endm
+
 .macro SYSCALL_ENTRY trapno intno srr1
mfspr   r10, SPRN_SPRG_THREAD
 #ifdef CONFIG_KVM_BOOKE_HV
-- 
2.25.0



[PATCH v2 33/43] powerpc/32: Remove the xfer parameter in EXCEPTION() macro

2021-03-09 Thread Christophe Leroy
The xfer parameter is not used anymore, remove it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h|  2 +-
 arch/powerpc/kernel/head_40x.S   | 42 
 arch/powerpc/kernel/head_44x.S   | 10 ++--
 arch/powerpc/kernel/head_8xx.S   | 14 +++---
 arch/powerpc/kernel/head_book3s_32.S | 72 ++--
 arch/powerpc/kernel/head_booke.h |  2 +-
 arch/powerpc/kernel/head_fsl_booke.S | 28 +--
 7 files changed, 81 insertions(+), 89 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 412ede8610f7..84e6251622e8 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -186,7 +186,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 
 #endif
 
-#define EXCEPTION(n, label, hdlr, xfer)\
+#define EXCEPTION(n, label, hdlr)  \
START_EXCEPTION(n, label)   \
EXCEPTION_PROLOG n label;   \
prepare_transfer_to_handler;\
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 7eb49ebd6000..52b40bf529c6 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -228,7 +228,7 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
b   interrupt_return
 
 /* 0x0500 - External Interrupt Exception */
-   EXCEPTION(0x0500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
+   EXCEPTION(0x0500, HardwareInterrupt, do_IRQ)
 
 /* 0x0600 - Alignment Exception */
START_EXCEPTION(0x0600, Alignment)
@@ -246,19 +246,19 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
REST_NVGPRS(r1)
b   interrupt_return
 
-   EXCEPTION(0x0800, Trap_08, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x0900, Trap_09, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x0A00, Trap_0A, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x0B00, Trap_0B, unknown_exception, EXC_XFER_STD)
+   EXCEPTION(0x0800, Trap_08, unknown_exception)
+   EXCEPTION(0x0900, Trap_09, unknown_exception)
+   EXCEPTION(0x0A00, Trap_0A, unknown_exception)
+   EXCEPTION(0x0B00, Trap_0B, unknown_exception)
 
 /* 0x0C00 - System Call Exception */
START_EXCEPTION(0x0C00, SystemCall)
SYSCALL_ENTRY   0xc00
 /* Trap_0D is commented out to get more space for system call exception */
 
-/* EXCEPTION(0x0D00, Trap_0D, unknown_exception, EXC_XFER_STD) */
-   EXCEPTION(0x0E00, Trap_0E, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x0F00, Trap_0F, unknown_exception, EXC_XFER_STD)
+/* EXCEPTION(0x0D00, Trap_0D, unknown_exception) */
+   EXCEPTION(0x0E00, Trap_0E, unknown_exception)
+   EXCEPTION(0x0F00, Trap_0F, unknown_exception)
 
 /* 0x1000 - Programmable Interval Timer (PIT) Exception */
START_EXCEPTION(0x1000, DecrementerTrap)
@@ -433,19 +433,19 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
mfspr   r10, SPRN_SPRG_SCRATCH5
b   InstructionAccess
 
-   EXCEPTION(0x1300, Trap_13, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1400, Trap_14, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1700, Trap_17, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1A00, Trap_1A, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1B00, Trap_1B, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1C00, Trap_1C, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1D00, Trap_1D, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1E00, Trap_1E, unknown_exception, EXC_XFER_STD)
-   EXCEPTION(0x1F00, Trap_1F, unknown_exception, EXC_XFER_STD)
+   EXCEPTION(0x1300, Trap_13, unknown_exception)
+   EXCEPTION(0x1400, Trap_14, unknown_exception)
+   EXCEPTION(0x1500, Trap_15, unknown_exception)
+   EXCEPTION(0x1600, Trap_16, unknown_exception)
+   EXCEPTION(0x1700, Trap_17, unknown_exception)
+   EXCEPTION(0x1800, Trap_18, unknown_exception)
+   EXCEPTION(0x1900, Trap_19, unknown_exception)
+   EXCEPTION(0x1A00, Trap_1A, unknown_exception)
+   EXCEPTION(0x1B00, Trap_1B, unknown_exception)
+   EXCEPTION(0x1C00, Trap_1C, unknown_exception)
+   EXCEPTION(0x1D00, Trap_1D, unknown_exception)
+   EXCEPTION(0x1E00, Trap_1E, unknown_exception)
+   EXCEPTION(0x1F00, Trap_1F, unknown_exception)
 
 /* Check for a single step debug exception while in an exception
  * handler before state has been saved.  This is to catch the case
diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 813fa305c33b..5c106ac36626 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -263,8 +263,7 @@ interrupt_base:
INSTRUCTION_STORAGE_EXCEPTION
 
/* External Input 

[PATCH v2 32/43] powerpc/32: Dismantle EXC_XFER_STD/LITE/TEMPLATE

2021-03-09 Thread Christophe Leroy
In order to get more control in exception prolog, dismantle
all non standard exception macros, finishing with EXC_XFER_STD
and EXC_XFER_LITE and EXC_XFER_TEMPLATE.

Also remove transfer_to_handler_full and ret_from_except and
ret_from_except_full as they are not used anymore.

Last parameter of EXCEPTION() is now ignored, will be removed
in a later patch to avoid too much churn.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 40 ---
 arch/powerpc/kernel/head_32.h| 21 
 arch/powerpc/kernel/head_40x.S   | 33 ---
 arch/powerpc/kernel/head_8xx.S   | 12 +--
 arch/powerpc/kernel/head_book3s_32.S | 27 ++-
 arch/powerpc/kernel/head_booke.h | 49 +++-
 arch/powerpc/kernel/head_fsl_booke.S | 14 +---
 7 files changed, 91 insertions(+), 105 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index ca14bc2f3418..289f111a5ac7 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -48,30 +48,6 @@
  */
.align  12
 
-#ifdef CONFIG_BOOKE
-   .globl  mcheck_transfer_to_handler
-mcheck_transfer_to_handler:
-   /* fall through */
-_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
-
-   .globl  debug_transfer_to_handler
-debug_transfer_to_handler:
-   /* fall through */
-_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
-
-   .globl  crit_transfer_to_handler
-crit_transfer_to_handler:
-   /* fall through */
-_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
-#endif
-
-#ifdef CONFIG_40x
-   .globl  crit_transfer_to_handler
-crit_transfer_to_handler:
-   /* fall through */
-_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
-#endif
-
 /*
  * This code finishes saving the registers to the exception frame
  * and jumps to the appropriate handler for the exception, turning
@@ -79,13 +55,6 @@ _ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
  * Note that we rely on the caller having set cr0.eq iff the exception
  * occurred in kernel mode (i.e. MSR:PR = 0).
  */
-   .globl  transfer_to_handler_full
-transfer_to_handler_full:
-_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
-   /* fall through */
-
-   .globl  transfer_to_handler
-transfer_to_handler:
.globl  prepare_transfer_to_handler
 prepare_transfer_to_handler:
SAVE_NVGPRS(r11)
@@ -135,7 +104,6 @@ transfer_to_handler_cont:
b   fast_exception_return
 #endif
 _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
-_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
 _ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
 
.globl  transfer_to_syscall
@@ -333,14 +301,6 @@ fast_exception_return:
 #endif
 _ASM_NOKPROBE_SYMBOL(fast_exception_return)
 
-   .globl  ret_from_except_full
-ret_from_except_full:
-   /* fall through */
-
-   .globl  ret_from_except
-ret_from_except:
-_ASM_NOKPROBE_SYMBOL(ret_from_except)
-
.globl interrupt_return
 interrupt_return:
lwz r4,_MSR(r1)
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 3ab0f3ad9a6a..412ede8610f7 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -189,20 +189,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 #define EXCEPTION(n, label, hdlr, xfer)\
START_EXCEPTION(n, label)   \
EXCEPTION_PROLOG n label;   \
-   xfer(n, hdlr)
-
-#define EXC_XFER_TEMPLATE(hdlr, trap, msr, tfer, ret)  \
-   bl  tfer;   \
-   bl  hdlr;   \
-   b   ret
-
-#define EXC_XFER_STD(n, hdlr)  \
-   EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler_full,
\
- ret_from_except_full)
-
-#define EXC_XFER_LITE(n, hdlr) \
-   EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, transfer_to_handler, \
- ret_from_except)
+   prepare_transfer_to_handler;\
+   bl  hdlr;   \
+   b   interrupt_return
 
 .macro vmap_stack_overflow_exception
__HEAD
@@ -218,7 +207,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
lwz r1, emergency_ctx@l(r1)
addir1, r1, THREAD_SIZE - INT_FRAME_SIZE
EXCEPTION_PROLOG_2 0 vmap_stack_overflow
-   EXC_XFER_STD(0, stack_overflow_exception)
+   prepare_transfer_to_handler
+   bl  stack_overflow_exception
+   b   interrupt_return
 .endm
 
 #endif /* __HEAD_32_H__ */
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index f3e5b462113f..7eb49ebd6000 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -187,8 +187,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 #define CRITICAL_EXCEPTION(n, label, hdlr) \
START_EXCEPTION(n, label);  \

[PATCH v2 35/43] powerpc/32: Save remaining registers in exception prolog

2021-03-09 Thread Christophe Leroy
Save non volatile registers, XER, CTR, MSR and NIP in exception prolog.

Also assign proper value to r2 and r3 there.

For now, recalculate thread pointer in prepare_transfer_to_handler.
It will disappear once KUAP is ported to C.

And remove the comment which is now completely wrong.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S | 25 +++--
 arch/powerpc/kernel/head_32.h  | 12 
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 289f111a5ac7..8fe1c3fdfa6e 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -48,29 +48,11 @@
  */
.align  12
 
-/*
- * This code finishes saving the registers to the exception frame
- * and jumps to the appropriate handler for the exception, turning
- * on address translation.
- * Note that we rely on the caller having set cr0.eq iff the exception
- * occurred in kernel mode (i.e. MSR:PR = 0).
- */
.globl  prepare_transfer_to_handler
 prepare_transfer_to_handler:
-   SAVE_NVGPRS(r11)
-   addir3,r1,STACK_FRAME_OVERHEAD
-   stw r2,GPR2(r11)
-   stw r12,_NIP(r11)
-   stw r9,_MSR(r11)
-   andi.   r2,r9,MSR_PR
-   mfctr   r12
-   mfspr   r2,SPRN_XER
-   stw r12,_CTR(r11)
-   stw r2,_XER(r11)
-   mfspr   r12,SPRN_SPRG_THREAD
-   tovirt(r12, r12)
+   andi.   r0,r9,MSR_PR
+   addir12, r2, THREAD
beq 2f  /* if from user, fix up THREAD.regs */
-   addir2, r12, -THREAD
stw r3,PT_REGS(r12)
 #ifdef CONFIG_PPC_BOOK3S_32
kuep_lock r11, r12
@@ -79,8 +61,7 @@ prepare_transfer_to_handler:
 
/* if from kernel, check interrupted DOZE/NAP mode */
 2:
-   kuap_save_and_lock r11, r12, r9, r2, r6
-   addir2, r12, -THREAD
+   kuap_save_and_lock r11, r12, r9, r5, r6
 #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
lwz r12,TI_LOCAL_FLAGS(r2)
mtcrf   0x01,r12
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index ba20bfabdf63..267479072495 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -117,6 +117,18 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
stw r10,_TRAP(r1)
SAVE_4GPRS(3, r1)
SAVE_2GPRS(7, r1)
+   SAVE_NVGPRS(r1)
+   stw r2,GPR2(r1)
+   stw r12,_NIP(r1)
+   stw r9,_MSR(r1)
+   mfctr   r0
+   mfspr   r10,SPRN_XER
+   mfspr   r2,SPRN_SPRG_THREAD
+   stw r0,_CTR(r1)
+   tovirt(r2, r2)
+   stw r10,_XER(r1)
+   addir2, r2, -THREAD
+   addir3,r1,STACK_FRAME_OVERHEAD
 .endm
 
 .macro prepare_transfer_to_handler
-- 
2.25.0



[PATCH v2 34/43] powerpc/32: Refactor saving of volatile registers in exception prologs

2021-03-09 Thread Christophe Leroy
Exception prologs all do the same at the end:
- Save trapno in stack
- Mark stack with exception marker
- Save r0
- Save r3 to r8

Refactor that into a COMMON_EXCEPTION_PROLOG_END macro.
At the same time use r1 instead of r11.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.h| 16 ++--
 arch/powerpc/kernel/head_40x.S   |  9 +
 arch/powerpc/kernel/head_booke.h | 26 +-
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 84e6251622e8..ba20bfabdf63 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -104,15 +104,19 @@
li  r10, MSR_KERNEL /* can take exceptions */
mtmsr   r10 /* (except for mach check in rtas) */
 #endif
-   stw r0,GPR0(r11)
+   COMMON_EXCEPTION_PROLOG_END \trapno
+_ASM_NOKPROBE_SYMBOL(\name\()_virt)
+.endm
+
+.macro COMMON_EXCEPTION_PROLOG_END trapno
+   stw r0,GPR0(r1)
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
addir10,r10,STACK_FRAME_REGS_MARKER@l
-   stw r10,8(r11)
+   stw r10,8(r1)
li  r10, \trapno
-   stw r10,_TRAP(r11)
-   SAVE_4GPRS(3, r11)
-   SAVE_2GPRS(7, r11)
-_ASM_NOKPROBE_SYMBOL(\name\()_virt)
+   stw r10,_TRAP(r1)
+   SAVE_4GPRS(3, r1)
+   SAVE_2GPRS(7, r1)
 .endm
 
 .macro prepare_transfer_to_handler
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index 52b40bf529c6..e1360b88b6cb 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -157,14 +157,7 @@ _ENTRY(crit_esr)
mfspr   r12,SPRN_SRR2
mfspr   r9,SPRN_SRR3
rlwinm  r9,r9,0,14,12   /* clear MSR_WE (necessary?)   */
-   stw r0,GPR0(r11)
-   lis r10, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
-   addir10, r10, STACK_FRAME_REGS_MARKER@l
-   stw r10, 8(r11)
-   li  r10, \trapno + 2
-   stw r10,_TRAP(r11)
-   SAVE_4GPRS(3, r11)
-   SAVE_2GPRS(7, r11)
+   COMMON_EXCEPTION_PROLOG_END \trapno + 2
 _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 .endm
 
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index fa566e89f18b..4d583fbef0b6 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -78,14 +78,18 @@ END_BTB_FLUSH_SECTION
stw r1, 0(r11);  \
mr  r1, r11; \
rlwinm  r9,r9,0,14,12;  /* clear MSR_WE (necessary?)   */\
-   stw r0,GPR0(r11);\
-   lis r10, STACK_FRAME_REGS_MARKER@ha;/* exception frame marker */ \
-   addir10, r10, STACK_FRAME_REGS_MARKER@l; \
-   stw r10, 8(r11); \
-   li  r10, trapno; \
-   stw r10,_TRAP(r11);  \
-   SAVE_4GPRS(3, r11);  \
-   SAVE_2GPRS(7, r11)
+   COMMON_EXCEPTION_PROLOG_END trapno
+
+.macro COMMON_EXCEPTION_PROLOG_END trapno
+   stw r0,GPR0(r1)
+   lis r10, STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
+   addir10, r10, STACK_FRAME_REGS_MARKER@l
+   stw r10, 8(r1)
+   li  r10, \trapno
+   stw r10,_TRAP(r1)
+   SAVE_4GPRS(3, r1)
+   SAVE_2GPRS(7, r1)
+.endm
 
 .macro prepare_transfer_to_handler
bl  prepare_transfer_to_handler
@@ -231,11 +235,7 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
stw r1,0(r11);   \
mr  r1,r11;  \
rlwinm  r9,r9,0,14,12;  /* clear MSR_WE (necessary?)   */\
-   li  r10, trapno; \
-   stw r10,_TRAP(r11);  \
-   stw r0,GPR0(r11);\
-   SAVE_4GPRS(3, r11);  \
-   SAVE_2GPRS(7, r11)
+   COMMON_EXCEPTION_PROLOG_END trapno
 
 #define SAVE_xSRR(xSRR)\
mfspr   r0,SPRN_##xSRR##0;  \
-- 
2.25.0



[PATCH v2 39/43] powerpc/32s: Move KUEP locking/unlocking in C

2021-03-09 Thread Christophe Leroy
This can be done in C, do it.

Unrolling the loop gains approx. 15% performance.

>From now on, prepare_transfer_to_handler() is only for
interrupts from kernel.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/32/kup.h | 31 ---
 arch/powerpc/include/asm/interrupt.h |  3 ++
 arch/powerpc/include/asm/kup.h   |  8 +
 arch/powerpc/kernel/entry_32.S   | 16 +-
 arch/powerpc/kernel/interrupt.c  |  4 +++
 arch/powerpc/mm/book3s32/Makefile|  1 +
 arch/powerpc/mm/book3s32/kuep.c  | 38 
 7 files changed, 55 insertions(+), 46 deletions(-)
 create mode 100644 arch/powerpc/mm/book3s32/kuep.c

diff --git a/arch/powerpc/include/asm/book3s/32/kup.h 
b/arch/powerpc/include/asm/book3s/32/kup.h
index 73bc5d2c431d..b97ea60f6fa3 100644
--- a/arch/powerpc/include/asm/book3s/32/kup.h
+++ b/arch/powerpc/include/asm/book3s/32/kup.h
@@ -7,37 +7,6 @@
 
 #ifdef __ASSEMBLY__
 
-.macro kuep_update_sr  gpr1, gpr2  /* NEVER use r0 as gpr2 due to 
addis */
-101:   mtsrin  \gpr1, \gpr2
-   addi\gpr1, \gpr1, 0x111 /* next VSID */
-   rlwinm  \gpr1, \gpr1, 0, 0xf0ff /* clear VSID overflow */
-   addis   \gpr2, \gpr2, 0x1000/* address of next segment */
-   bdnz101b
-   isync
-.endm
-
-.macro kuep_lock   gpr1, gpr2
-#ifdef CONFIG_PPC_KUEP
-   li  \gpr1, NUM_USER_SEGMENTS
-   li  \gpr2, 0
-   mtctr   \gpr1
-   mfsrin  \gpr1, \gpr2
-   oris\gpr1, \gpr1, SR_NX@h   /* set Nx */
-   kuep_update_sr \gpr1, \gpr2
-#endif
-.endm
-
-.macro kuep_unlock gpr1, gpr2
-#ifdef CONFIG_PPC_KUEP
-   li  \gpr1, NUM_USER_SEGMENTS
-   li  \gpr2, 0
-   mtctr   \gpr1
-   mfsrin  \gpr1, \gpr2
-   rlwinm  \gpr1, \gpr1, 0, ~SR_NX /* Clear Nx */
-   kuep_update_sr \gpr1, \gpr2
-#endif
-.endm
-
 #ifdef CONFIG_PPC_KUAP
 
 .macro kuap_update_sr  gpr1, gpr2, gpr3/* NEVER use r0 as gpr2 due to 
addis */
diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index e6d71c2e3aa2..d4bfe94b4a68 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -34,6 +34,7 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
trace_hardirqs_off();
 
if (user_mode(regs)) {
+   kuep_lock();
current->thread.regs = regs;
account_cpu_user_entry();
}
@@ -91,6 +92,8 @@ static inline void interrupt_exit_prepare(struct pt_regs 
*regs, struct interrupt
exception_exit(state->ctx_state);
 #endif
 
+   if (user_mode(regs))
+   kuep_unlock();
/*
 * Book3S exits to user via interrupt_exit_user_prepare(), which does
 * context tracking, which is a cleaner way to handle PREEMPT=y
diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
index 7ec21af49a45..25671f711ec2 100644
--- a/arch/powerpc/include/asm/kup.h
+++ b/arch/powerpc/include/asm/kup.h
@@ -55,6 +55,14 @@ void setup_kuep(bool disabled);
 static inline void setup_kuep(bool disabled) { }
 #endif /* CONFIG_PPC_KUEP */
 
+#if defined(CONFIG_PPC_KUEP) && defined(CONFIG_PPC_BOOK3S_32)
+void kuep_lock(void);
+void kuep_unlock(void);
+#else
+static inline void kuep_lock(void) { }
+static inline void kuep_unlock(void) { }
+#endif
+
 #ifdef CONFIG_PPC_KUAP
 void setup_kuap(bool disabled);
 #else
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 9c333e6db5fa..850cb17a937f 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -53,14 +53,9 @@
 prepare_transfer_to_handler:
andi.   r0,r9,MSR_PR
addir12, r2, THREAD
-   beq 2f
-#ifdef CONFIG_PPC_BOOK3S_32
-   kuep_lock r11, r12
-#endif
-   blr
+   bnelr
 
/* if from kernel, check interrupted DOZE/NAP mode */
-2:
kuap_save_and_lock r11, r12, r9, r5, r6
lwz r12,TI_LOCAL_FLAGS(r2)
mtcrf   0x01,r12
@@ -84,9 +79,6 @@ _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
.globl  transfer_to_syscall
 transfer_to_syscall:
SAVE_NVGPRS(r1)
-#ifdef CONFIG_PPC_BOOK3S_32
-   kuep_lock r11, r12
-#endif
 
/* Calling convention has r9 = orig r0, r10 = regs */
addir10,r1,STACK_FRAME_OVERHEAD
@@ -104,9 +96,6 @@ ret_from_syscall:
cmplwi  cr0,r5,0
bne-2f
 #endif /* CONFIG_PPC_47x */
-#ifdef CONFIG_PPC_BOOK3S_32
-   kuep_unlock r5, r7
-#endif
kuap_check r2, r4
lwz r4,_LINK(r1)
lwz r5,_CCR(r1)
@@ -287,9 +276,6 @@ interrupt_return:
bne-.Lrestore_nvgprs
 
 .Lfast_user_interrupt_return:
-#ifdef CONFIG_PPC_BOOK3S_32
-   kuep_unlock r10, r11
-#endif
kuap_check r2, r4
lwz r11,_NIP(r1)
lwz r12,_MSR(r1)
diff --git 

[PATCH v2 43/43] powerpc/32: Manage KUAP in C

2021-03-09 Thread Christophe Leroy
Move all KUAP management in C.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/32/kup.h | 50 +---
 arch/powerpc/include/asm/interrupt.h |  2 +
 arch/powerpc/include/asm/kup.h   |  9 
 arch/powerpc/include/asm/nohash/32/kup-8xx.h | 25 +-
 arch/powerpc/kernel/entry_32.S   |  6 ---
 arch/powerpc/kernel/interrupt.c  | 19 ++--
 arch/powerpc/kernel/process.c|  3 ++
 7 files changed, 11 insertions(+), 103 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/kup.h 
b/arch/powerpc/include/asm/book3s/32/kup.h
index c9d6c28bcd10..27991e0d2cf9 100644
--- a/arch/powerpc/include/asm/book3s/32/kup.h
+++ b/arch/powerpc/include/asm/book3s/32/kup.h
@@ -5,55 +5,7 @@
 #include 
 #include 
 
-#ifdef __ASSEMBLY__
-
-#ifdef CONFIG_PPC_KUAP
-
-.macro kuap_update_sr  gpr1, gpr2, gpr3/* NEVER use r0 as gpr2 due to 
addis */
-101:   mtsrin  \gpr1, \gpr2
-   addi\gpr1, \gpr1, 0x111 /* next VSID */
-   rlwinm  \gpr1, \gpr1, 0, 0xf0ff /* clear VSID overflow */
-   addis   \gpr2, \gpr2, 0x1000/* address of next segment */
-   cmplw   \gpr2, \gpr3
-   blt-101b
-   isync
-.endm
-
-.macro kuap_save_and_lock  sp, thread, gpr1, gpr2, gpr3
-   lwz \gpr2, KUAP(\thread)
-   rlwinm. \gpr3, \gpr2, 28, 0xf000
-   stw \gpr2, STACK_REGS_KUAP(\sp)
-   beq+102f
-   li  \gpr1, 0
-   stw \gpr1, KUAP(\thread)
-   mfsrin  \gpr1, \gpr2
-   oris\gpr1, \gpr1, SR_KS@h   /* set Ks */
-   kuap_update_sr  \gpr1, \gpr2, \gpr3
-102:
-.endm
-
-.macro kuap_restoresp, current, gpr1, gpr2, gpr3
-   lwz \gpr2, STACK_REGS_KUAP(\sp)
-   rlwinm. \gpr3, \gpr2, 28, 0xf000
-   stw \gpr2, THREAD + KUAP(\current)
-   beq+102f
-   mfsrin  \gpr1, \gpr2
-   rlwinm  \gpr1, \gpr1, 0, ~SR_KS /* Clear Ks */
-   kuap_update_sr  \gpr1, \gpr2, \gpr3
-102:
-.endm
-
-.macro kuap_check  current, gpr
-#ifdef CONFIG_PPC_KUAP_DEBUG
-   lwz \gpr, THREAD + KUAP(\current)
-999:   twnei   \gpr, 0
-   EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | 
BUGFLAG_ONCE)
-#endif
-.endm
-
-#endif /* CONFIG_PPC_KUAP */
-
-#else /* !__ASSEMBLY__ */
+#ifndef __ASSEMBLY__
 
 #ifdef CONFIG_PPC_KUAP
 
diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index d4bfe94b4a68..b41cb4e014b2 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -37,6 +37,8 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
kuep_lock();
current->thread.regs = regs;
account_cpu_user_entry();
+   } else {
+   kuap_save_and_lock(regs);
}
 #endif
/*
diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
index b7efa46b3109..5bbe8f28d26b 100644
--- a/arch/powerpc/include/asm/kup.h
+++ b/arch/powerpc/include/asm/kup.h
@@ -28,15 +28,6 @@
 
 #ifdef __ASSEMBLY__
 #ifndef CONFIG_PPC_KUAP
-.macro kuap_save_and_lock  sp, thread, gpr1, gpr2, gpr3
-.endm
-
-.macro kuap_restoresp, current, gpr1, gpr2, gpr3
-.endm
-
-.macro kuap_check  current, gpr
-.endm
-
 .macro kuap_check_amr  gpr1, gpr2
 .endm
 
diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h 
b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
index c74f5704bc47..fb294dbca102 100644
--- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h
+++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
@@ -7,30 +7,7 @@
 
 #ifdef CONFIG_PPC_KUAP
 
-#ifdef __ASSEMBLY__
-
-.macro kuap_save_and_lock  sp, thread, gpr1, gpr2, gpr3
-   lis \gpr2, MD_APG_KUAP@h/* only APG0 and APG1 are used */
-   mfspr   \gpr1, SPRN_MD_AP
-   mtspr   SPRN_MD_AP, \gpr2
-   stw \gpr1, STACK_REGS_KUAP(\sp)
-.endm
-
-.macro kuap_restoresp, current, gpr1, gpr2, gpr3
-   lwz \gpr1, STACK_REGS_KUAP(\sp)
-   mtspr   SPRN_MD_AP, \gpr1
-.endm
-
-.macro kuap_check  current, gpr
-#ifdef CONFIG_PPC_KUAP_DEBUG
-   mfspr   \gpr, SPRN_MD_AP
-   rlwinm  \gpr, \gpr, 16, 0x
-999:   twnei   \gpr, MD_APG_KUAP@h
-   EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | 
BUGFLAG_ONCE)
-#endif
-.endm
-
-#else /* !__ASSEMBLY__ */
+#ifndef __ASSEMBLY__
 
 #include 
 
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 850cb17a937f..f5ac021ff9ed 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -52,11 +52,9 @@
.globl  prepare_transfer_to_handler
 prepare_transfer_to_handler:
andi.   r0,r9,MSR_PR
-   addir12, r2, THREAD
bnelr
 
/* if from kernel, check interrupted DOZE/NAP mode */
-   kuap_save_and_lock r11, r12, r9, r5, r6
lwz r12,TI_LOCAL_FLAGS(r2)
mtcrf   0x01,r12
bt- 31-TLF_NAPPING,4f

[PATCH v2 41/43] powerpc/32s: Create C version of kuap save/restore/check helpers

2021-03-09 Thread Christophe Leroy
In preparation of porting PPC32 to C syscall entry/exit,
create C version of kuap_save_and_lock() and kuap_user_restore() and
kuap_kernel_restore() and kuap_check() and kuap_get_and_check()
on book3s/32.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/32/kup.h | 45 
 1 file changed, 45 insertions(+)

diff --git a/arch/powerpc/include/asm/book3s/32/kup.h 
b/arch/powerpc/include/asm/book3s/32/kup.h
index b97ea60f6fa3..c9d6c28bcd10 100644
--- a/arch/powerpc/include/asm/book3s/32/kup.h
+++ b/arch/powerpc/include/asm/book3s/32/kup.h
@@ -72,6 +72,51 @@ static inline void kuap_update_sr(u32 sr, u32 addr, u32 end)
isync();/* Context sync required after mtsr() */
 }
 
+static inline void kuap_save_and_lock(struct pt_regs *regs)
+{
+   unsigned long kuap = current->thread.kuap;
+   u32 addr = kuap & 0xf000;
+   u32 end = kuap << 28;
+
+   regs->kuap = kuap;
+   if (unlikely(!kuap))
+   return;
+
+   current->thread.kuap = 0;
+   kuap_update_sr(mfsr(addr) | SR_KS, addr, end);  /* Set Ks */
+}
+
+static inline void kuap_user_restore(struct pt_regs *regs)
+{
+}
+
+static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long 
kuap)
+{
+   u32 addr = regs->kuap & 0xf000;
+   u32 end = regs->kuap << 28;
+
+   current->thread.kuap = regs->kuap;
+
+   if (unlikely(regs->kuap == kuap))
+   return;
+
+   kuap_update_sr(mfsr(addr) & ~SR_KS, addr, end); /* Clear Ks */
+}
+
+static inline unsigned long kuap_get_and_check(void)
+{
+   unsigned long kuap = current->thread.kuap;
+
+   WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != 0);
+
+   return kuap;
+}
+
+static inline void kuap_check(void)
+{
+   kuap_get_and_check();
+}
+
 static __always_inline void allow_user_access(void __user *to, const void 
__user *from,
  u32 size, unsigned long dir)
 {
-- 
2.25.0



[PATCH v2 36/43] powerpc/32: Set current->thread.regs in C interrupt entry

2021-03-09 Thread Christophe Leroy
No need to do that is assembly, do it in C.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/interrupt.h | 4 +++-
 arch/powerpc/kernel/entry_32.S   | 3 +--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index 861e6eadc98c..e6d71c2e3aa2 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -33,8 +33,10 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
if (!arch_irq_disabled_regs(regs))
trace_hardirqs_off();
 
-   if (user_mode(regs))
+   if (user_mode(regs)) {
+   current->thread.regs = regs;
account_cpu_user_entry();
+   }
 #endif
/*
 * Book3E reconciles irq soft mask in asm
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 8fe1c3fdfa6e..815a4ff1ba76 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -52,8 +52,7 @@
 prepare_transfer_to_handler:
andi.   r0,r9,MSR_PR
addir12, r2, THREAD
-   beq 2f  /* if from user, fix up THREAD.regs */
-   stw r3,PT_REGS(r12)
+   beq 2f
 #ifdef CONFIG_PPC_BOOK3S_32
kuep_lock r11, r12
 #endif
-- 
2.25.0



[PATCH v2 37/43] powerpc/32: Return directly from power_save_ppc32_restore()

2021-03-09 Thread Christophe Leroy
transfer_to_handler_cont: is now just a blr.

Directly perform blr in power_save_ppc32_restore().

Also remove useless setting of r11 in e500 version of
power_save_ppc32_restore().

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S  |  3 ---
 arch/powerpc/kernel/idle_6xx.S  |  2 +-
 arch/powerpc/kernel/idle_e500.S | 10 +-
 3 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 815a4ff1ba76..5cfa10816261 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -67,8 +67,6 @@ prepare_transfer_to_handler:
bt- 31-TLF_NAPPING,4f
bt- 31-TLF_SLEEPING,7f
 #endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
-   .globl transfer_to_handler_cont
-transfer_to_handler_cont:
blr
 
 #if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
@@ -84,7 +82,6 @@ transfer_to_handler_cont:
b   fast_exception_return
 #endif
 _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
-_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
 
.globl  transfer_to_syscall
 transfer_to_syscall:
diff --git a/arch/powerpc/kernel/idle_6xx.S b/arch/powerpc/kernel/idle_6xx.S
index 153366e178c4..13cad9297d82 100644
--- a/arch/powerpc/kernel/idle_6xx.S
+++ b/arch/powerpc/kernel/idle_6xx.S
@@ -176,7 +176,7 @@ BEGIN_FTR_SECTION
lwz r9,nap_save_hid1@l(r9)
mtspr   SPRN_HID1, r9
 END_FTR_SECTION_IFSET(CPU_FTR_DUAL_PLL_750FX)
-   b   transfer_to_handler_cont
+   blr
 _ASM_NOKPROBE_SYMBOL(power_save_ppc32_restore)
 
.data
diff --git a/arch/powerpc/kernel/idle_e500.S b/arch/powerpc/kernel/idle_e500.S
index 7795727e7f08..9e1bc4502c50 100644
--- a/arch/powerpc/kernel/idle_e500.S
+++ b/arch/powerpc/kernel/idle_e500.S
@@ -81,13 +81,5 @@ END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
 _GLOBAL(power_save_ppc32_restore)
lwz r9,_LINK(r11)   /* interrupted in e500_idle */
stw r9,_NIP(r11)/* make it do a blr */
-
-#ifdef CONFIG_SMP
-   lwz r11,TASK_CPU(r2)/* get cpu number * 4 */
-   slwir11,r11,2
-#else
-   li  r11,0
-#endif
-
-   b   transfer_to_handler_cont
+   blr
 _ASM_NOKPROBE_SYMBOL(power_save_ppc32_restore)
-- 
2.25.0



[RESEND v12 0/1] Introducing ETAS ES58X CAN USB interfaces

2021-03-09 Thread Vincent Mailhol
*Reason for resend:* the patch does not reach the linux-can mailing
list because it is over the 10 characters limit. Adding
linux-kernel@vger.kernel.org in CC so that people who are not in CC
can get it from the general mailing list instead.

Here comes the twelfth iteration of the ETAS es58x usb driver. The
major difference from previous version is the total removal of
spinlocks. Aside of that, I also implemented the TDC accordingly to
the patch series which I submitted here two weeks ago.

This patch series is based on linux-can-next/testing. It requires the
latest patches in that branch to compile.

Crossing fingers, hoping that we are now close to a release.

Thank you in advance for your review and for your time!


Yours sincerely,
Vincent

Vincent Mailhol (1):
  can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

 drivers/net/can/usb/Kconfig |   10 +
 drivers/net/can/usb/Makefile|1 +
 drivers/net/can/usb/etas_es58x/Makefile |3 +
 drivers/net/can/usb/etas_es58x/es581_4.c|  525 
 drivers/net/can/usb/etas_es58x/es581_4.h|  208 ++
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2404 +++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  690 ++
 drivers/net/can/usb/etas_es58x/es58x_fd.c   |  600 +
 drivers/net/can/usb/etas_es58x/es58x_fd.h   |  243 ++
 9 files changed, 4684 insertions(+)
 create mode 100644 drivers/net/can/usb/etas_es58x/Makefile
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.h
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.h
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.h
-- 
2.26.2



[PATCH v2 38/43] powerpc/32: Only use prepare_transfer_to_handler function on book3s/32 and e500

2021-03-09 Thread Christophe Leroy
Only book3s/32 and e500 have significative work to do in
prepare_transfer_to_handler.

Other 32 bit have nothing to do at all.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S   | 6 ++
 arch/powerpc/kernel/head_32.h| 2 ++
 arch/powerpc/kernel/head_booke.h | 2 ++
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 5cfa10816261..9c333e6db5fa 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -48,6 +48,7 @@
  */
.align  12
 
+#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
.globl  prepare_transfer_to_handler
 prepare_transfer_to_handler:
andi.   r0,r9,MSR_PR
@@ -61,15 +62,12 @@ prepare_transfer_to_handler:
/* if from kernel, check interrupted DOZE/NAP mode */
 2:
kuap_save_and_lock r11, r12, r9, r5, r6
-#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
lwz r12,TI_LOCAL_FLAGS(r2)
mtcrf   0x01,r12
bt- 31-TLF_NAPPING,4f
bt- 31-TLF_SLEEPING,7f
-#endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
blr
 
-#if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
 4: rlwinm  r12,r12,0,~_TLF_NAPPING
stw r12,TI_LOCAL_FLAGS(r2)
b   power_save_ppc32_restore
@@ -80,8 +78,8 @@ prepare_transfer_to_handler:
rlwinm  r9,r9,0,~MSR_EE
stw r9,_MSR(r11)
b   fast_exception_return
-#endif
 _ASM_NOKPROBE_SYMBOL(prepare_transfer_to_handler)
+#endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
 
.globl  transfer_to_syscall
 transfer_to_syscall:
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 267479072495..ca303762d8cc 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -132,7 +132,9 @@ _ASM_NOKPROBE_SYMBOL(\name\()_virt)
 .endm
 
 .macro prepare_transfer_to_handler
+#ifdef CONFIG_PPC_BOOK3S_32
bl  prepare_transfer_to_handler
+#endif
 .endm
 
 .macro SYSCALL_ENTRY trapno
diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h
index 4d583fbef0b6..a2565023d2d0 100644
--- a/arch/powerpc/kernel/head_booke.h
+++ b/arch/powerpc/kernel/head_booke.h
@@ -92,7 +92,9 @@ END_BTB_FLUSH_SECTION
 .endm
 
 .macro prepare_transfer_to_handler
+#ifdef CONFIG_E500
bl  prepare_transfer_to_handler
+#endif
 .endm
 
 .macro SYSCALL_ENTRY trapno intno srr1
-- 
2.25.0



Re: [PATCH] perf machine: Assign boolean values to a bool variable

2021-03-09 Thread Arnaldo Carvalho de Melo
Em Tue, Mar 09, 2021 at 06:11:09PM +0800, Jiapeng Chong escreveu:
> Fix the following coccicheck warnings:
> 
> ./tools/perf/util/machine.c:2041:9-10: WARNING: return of 0/1 in
> function 'symbol__match_regex' with return type bool.

Thanks, applied.

- Arnaldo

 
> Reported-by: Abaci Robot 
> Signed-off-by: Jiapeng Chong 
> ---
>  tools/perf/util/machine.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index b5c2d8b..435771e 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2038,8 +2038,8 @@ int machine__process_event(struct machine *machine, 
> union perf_event *event,
>  static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
>  {
>   if (!regexec(regex, sym->name, 0, NULL, 0))
> - return 1;
> - return 0;
> + return true;
> + return false;
>  }
>  
>  static void ip__resolve_ams(struct thread *thread,
> -- 
> 1.8.3.1
> 

-- 

- Arnaldo


[PATCH v2 40/43] powerpc/64s: Make kuap_check_amr() and kuap_get_and_check_amr() generic

2021-03-09 Thread Christophe Leroy
In preparation of porting powerpc32 to C syscall entry/exit,
rename kuap_check_amr() and kuap_get_and_check_amr() as kuap_check()
and kuap_get_and_check(), and move in the generic asm/kup.h the stub
for when CONFIG_PPC_KUAP is not selected.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/64/kup.h | 24 ++--
 arch/powerpc/include/asm/kup.h   | 10 +-
 arch/powerpc/kernel/interrupt.c  | 12 ++--
 arch/powerpc/kernel/irq.c|  2 +-
 4 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/kup.h 
b/arch/powerpc/include/asm/book3s/64/kup.h
index 8bd905050896..d9b07e9998be 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h
@@ -287,7 +287,7 @@ static inline void kuap_kernel_restore(struct pt_regs *regs,
 */
 }
 
-static inline unsigned long kuap_get_and_check_amr(void)
+static inline unsigned long kuap_get_and_check(void)
 {
if (mmu_has_feature(MMU_FTR_BOOK3S_KUAP)) {
unsigned long amr = mfspr(SPRN_AMR);
@@ -298,27 +298,7 @@ static inline unsigned long kuap_get_and_check_amr(void)
return 0;
 }
 
-#else /* CONFIG_PPC_PKEY */
-
-static inline void kuap_user_restore(struct pt_regs *regs)
-{
-}
-
-static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long amr)
-{
-}
-
-static inline unsigned long kuap_get_and_check_amr(void)
-{
-   return 0;
-}
-
-#endif /* CONFIG_PPC_PKEY */
-
-
-#ifdef CONFIG_PPC_KUAP
-
-static inline void kuap_check_amr(void)
+static inline void kuap_check(void)
 {
if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && 
mmu_has_feature(MMU_FTR_BOOK3S_KUAP))
WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
index 25671f711ec2..b7efa46b3109 100644
--- a/arch/powerpc/include/asm/kup.h
+++ b/arch/powerpc/include/asm/kup.h
@@ -74,7 +74,15 @@ bad_kuap_fault(struct pt_regs *regs, unsigned long address, 
bool is_write)
return false;
 }
 
-static inline void kuap_check_amr(void) { }
+static inline void kuap_check(void) { }
+static inline void kuap_save_and_lock(struct pt_regs *regs) { }
+static inline void kuap_user_restore(struct pt_regs *regs) { }
+static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long 
amr) { }
+
+static inline unsigned long kuap_get_and_check(void)
+{
+   return 0;
+}
 
 /*
  * book3s/64/kup-radix.h defines these functions for the !KUAP case to flush
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 727b7848c9cc..40ed55064e54 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -76,7 +76,7 @@ notrace long system_call_exception(long r3, long r4, long r5,
} else
 #endif
 #ifdef CONFIG_PPC64
-   kuap_check_amr();
+   kuap_check();
 #endif
 
booke_restore_dbcr0();
@@ -254,7 +254,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
CT_WARN_ON(ct_state() == CONTEXT_USER);
 
 #ifdef CONFIG_PPC64
-   kuap_check_amr();
+   kuap_check();
 #endif
 
regs->result = r3;
@@ -380,7 +380,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct 
pt_regs *regs, unsigned
 * AMR can only have been unlocked if we interrupted the kernel.
 */
 #ifdef CONFIG_PPC64
-   kuap_check_amr();
+   kuap_check();
 #endif
 
local_irq_save(flags);
@@ -451,7 +451,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct 
pt_regs *regs, unsign
unsigned long flags;
unsigned long ret = 0;
 #ifdef CONFIG_PPC64
-   unsigned long amr;
+   unsigned long kuap;
 #endif
 
if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x) &&
@@ -467,7 +467,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct 
pt_regs *regs, unsign
CT_WARN_ON(ct_state() == CONTEXT_USER);
 
 #ifdef CONFIG_PPC64
-   amr = kuap_get_and_check_amr();
+   kuap = kuap_get_and_check();
 #endif
 
if (unlikely(current_thread_info()->flags & _TIF_EMULATE_STACK_STORE)) {
@@ -511,7 +511,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct 
pt_regs *regs, unsign
 * value from the check above.
 */
 #ifdef CONFIG_PPC64
-   kuap_kernel_restore(regs, amr);
+   kuap_kernel_restore(regs, kuap);
 #endif
 
return ret;
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index d71fd10a1dd4..3b18d2b2c702 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -282,7 +282,7 @@ static inline void replay_soft_interrupts_irqrestore(void)
 * and re-locking AMR but we shouldn't get here in the first place,
 * hence the warning.
 */
-   kuap_check_amr();
+   kuap_check();
 
if (kuap_state != AMR_KUAP_BLOCKED)
set_kuap(AMR_KUAP_BLOCKED);
-- 
2.25.0



[PATCH v2 42/43] powerpc/8xx: Create C version of kuap save/restore/check helpers

2021-03-09 Thread Christophe Leroy
In preparation of porting PPC32 to C syscall entry/exit,
create C version of kuap_save_and_lock() and kuap_user_restore() and
kuap_kernel_restore() and kuap_check() and kuap_get_and_check() on 8xx.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/nohash/32/kup-8xx.h | 31 
 1 file changed, 31 insertions(+)

diff --git a/arch/powerpc/include/asm/nohash/32/kup-8xx.h 
b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
index 17a4a616436f..c74f5704bc47 100644
--- a/arch/powerpc/include/asm/nohash/32/kup-8xx.h
+++ b/arch/powerpc/include/asm/nohash/32/kup-8xx.h
@@ -34,6 +34,37 @@
 
 #include 
 
+static inline void kuap_save_and_lock(struct pt_regs *regs)
+{
+   regs->kuap = mfspr(SPRN_MD_AP);
+   mtspr(SPRN_MD_AP, MD_APG_KUAP);
+}
+
+static inline void kuap_user_restore(struct pt_regs *regs)
+{
+}
+
+static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long 
kuap)
+{
+   mtspr(SPRN_MD_AP, regs->kuap);
+}
+
+static inline unsigned long kuap_get_and_check(void)
+{
+   unsigned long kuap = mfspr(SPRN_MD_AP);
+
+   if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG))
+   WARN_ON_ONCE(kuap >> 16 != MD_APG_KUAP >> 16);
+
+   return kuap;
+}
+
+static inline void kuap_check(void)
+{
+   if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG))
+   kuap_get_and_check();
+}
+
 static inline void allow_user_access(void __user *to, const void __user *from,
 unsigned long size, unsigned long dir)
 {
-- 
2.25.0



Re: [PATCH v2] arm64: dts: qcom: Introduce SM8350 HDK

2021-03-09 Thread Vinod Koul
On 08-03-21, 10:21, Bjorn Andersson wrote:

> +#include 
> +#include 
> +#include "sm8350.dtsi"
> +
> +/ {
> + model = "Qualcomm Technologies, Inc. SM8350 HDK";
> + compatible = "qcom,sm8350-hdk", "qcom,sm8350";

qcom,sm8350-hdk needs to be documented

With that:

Reviewed-by: Vinod Koul 

-- 
~Vinod


Re: [syzbot] KASAN: use-after-free Read in usb_audio_disconnect

2021-03-09 Thread Dmitry Vyukov
On Tue, Mar 9, 2021 at 12:38 PM Takashi Iwai  wrote:
>
> On Tue, 09 Mar 2021 12:32:18 +0100,
> syzbot wrote:
> >
> > Hello,
> >
> > syzbot found the following issue on:
> >
> > HEAD commit:4641b323 Add linux-next specific files for 20210305
> > git tree:   linux-next
> > console output: https://syzkaller.appspot.com/x/log.txt?x=103252ead0
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=b87b6a083d302a90
> > dashboard link: https://syzkaller.appspot.com/bug?extid=ffad4c74b3b3ea3aa9c3
> > syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=1122d35cd0
> > C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17f6476cd0
> >
> > The issue was bisected to:
> >
> > commit 9799110825dba087c2bdce886977cf84dada2005
> > Author: Kai-Heng Feng 
> > Date:   Thu Mar 4 04:34:16 2021 +
> >
> > ALSA: usb-audio: Disable USB autosuspend properly in 
> > setup_disable_autosuspend()
> >
> > bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=166d91ead0
> > final oops: https://syzkaller.appspot.com/x/report.txt?x=156d91ead0
> > console output: https://syzkaller.appspot.com/x/log.txt?x=116d91ead0
> >
> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+ffad4c74b3b3ea3aa...@syzkaller.appspotmail.com
> > Fixes: 9799110825db ("ALSA: usb-audio: Disable USB autosuspend properly in 
> > setup_disable_autosuspend()")
> >
> > usb 1-1: USB disconnect, device number 2
> > ==
> > BUG: KASAN: use-after-free in usb_audio_disconnect+0x750/0x800 
> > sound/usb/card.c:918
>
> This must be fixed by the commit that was already merged to sound.git
> tree today:
> c5aa956eaeb0 ("ALSA: usb-audio: fix use after free in usb_audio_disconnect")


#syz fix: ALSA: usb-audio: fix use after free in usb_audio_disconnect


Re: [syzbot] KASAN: use-after-free Read in usb_audio_disconnect

2021-03-09 Thread syzbot
> On Tue, Mar 9, 2021 at 12:38 PM Takashi Iwai  wrote:
>>
>> On Tue, 09 Mar 2021 12:32:18 +0100,
>> syzbot wrote:
>> >
>> > Hello,
>> >
>> > syzbot found the following issue on:
>> >
>> > HEAD commit:4641b323 Add linux-next specific files for 20210305
>> > git tree:   linux-next
>> > console output: https://syzkaller.appspot.com/x/log.txt?x=103252ead0
>> > kernel config:  https://syzkaller.appspot.com/x/.config?x=b87b6a083d302a90
>> > dashboard link: 
>> > https://syzkaller.appspot.com/bug?extid=ffad4c74b3b3ea3aa9c3
>> > syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=1122d35cd0
>> > C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17f6476cd0
>> >
>> > The issue was bisected to:
>> >
>> > commit 9799110825dba087c2bdce886977cf84dada2005
>> > Author: Kai-Heng Feng 
>> > Date:   Thu Mar 4 04:34:16 2021 +
>> >
>> > ALSA: usb-audio: Disable USB autosuspend properly in 
>> > setup_disable_autosuspend()
>> >
>> > bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=166d91ead0
>> > final oops: https://syzkaller.appspot.com/x/report.txt?x=156d91ead0
>> > console output: https://syzkaller.appspot.com/x/log.txt?x=116d91ead0
>> >
>> > IMPORTANT: if you fix the issue, please add the following tag to the 
>> > commit:
>> > Reported-by: syzbot+ffad4c74b3b3ea3aa...@syzkaller.appspotmail.com
>> > Fixes: 9799110825db ("ALSA: usb-audio: Disable USB autosuspend properly in 
>> > setup_disable_autosuspend()")
>> >
>> > usb 1-1: USB disconnect, device number 2
>> > ==
>> > BUG: KASAN: use-after-free in usb_audio_disconnect+0x750/0x800 
>> > sound/usb/card.c:918
>>
>> This must be fixed by the commit that was already merged to sound.git
>> tree today:
>> c5aa956eaeb0 ("ALSA: usb-audio: fix use after free in usb_audio_disconnect")
>
>
> #syz fix: ALSA: usb-audio: fix use after free in usb_audio_disconnect

I see the command but can't find the corresponding bug.
Please resend the email to syzbot+h...@syzkaller.appspotmail.com address
that is the sender of the bug report (also present in the Reported-by tag).

>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to syzkaller-bugs+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/syzkaller-bugs/CACT4Y%2BbWYQu3h8pJaX4GS1JdJpPheE416TJH4%3DK5zOaseAH4Fg%40mail.gmail.com.


Re: [PATCH] dt-bindings: spi: Convert NXP flexspi to json schema

2021-03-09 Thread Mark Brown
On Tue, Mar 09, 2021 at 11:41:50AM +, Kuldeep Singh wrote:
> + Mark (Forgot to add him previously)

...

> I was not sure with which tree this patch will go through.
> Currently, I have rebased this on top of 
> tree(git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git, branch: 
> for-next)

Binding patches generally go through the subsystem tree so please send
the patch to me.


signature.asc
Description: PGP signature


Re: [PATCH v3 05/15] dt_bindings: mfd: Add ROHM BD71815 PMIC

2021-03-09 Thread Matti Vaittinen
Hello Rob,

On Mon, 2021-03-08 at 10:39 -0700, Rob Herring wrote:
> On Mon, 08 Mar 2021 12:40:50 +0200, Matti Vaittinen wrote:
> > Document DT bindings for ROHM BD71815.
> > 
> > BD71815 is a single-chip power management IC mainly for battery-
> > powered
> > portable devices. The IC integrates 5 bucks, 7 LDOs, a boost driver
> > for
> > LED, a battery charger with a Coulomb counter, a real-time clock, a
> > 32kHz
> > clock and two general-purpose outputs although only one is
> > documented by
> > the data-sheet.
> > 
> > Signed-off-by: Matti Vaittinen 
> > Reviewed-by: Rob Herring 
> > ---
> >  .../bindings/mfd/rohm,bd71815-pmic.yaml   | 201
> > ++
> >  1 file changed, 201 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/mfd/rohm,bd71815-pmic.yaml
> > 
> 
> My bot found errors running 'make dt_binding_check' on your patch:

I am sorry to bother but I've spent a while trying to reproduce this.
For some reason I can't trigger the error from

'make dt_binding_check' or
'make dt_binding_check
DT_SCHEMA_FILES=Documentation/devicetree/bindings/mfd/rohm,bd71815-
pmic.yaml'

even after I ran

'pip3 install dtschema --upgrade --user'.

I should also have yamllint installed.

> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> Unknown file referenced: [Errno 2] No such file or directory:
> '/usr/local/lib/python3.8/dist-
> packages/dtschema/schemas/regulator/rohm,bd71815-regulator.yaml'

This bothers me slightly. The patch 04/15 should bring-in the
rohm,bd71815-regulator.yaml. Does this error indicate that file is
missing or is my $ref somehow invalid?

*** opinion follows - not sure if it just me but... ***

I know I should probably keep my mouth shut but... I am more and more
thinking that the yaml bindings are yet another 'excessive unit-test'
type solution. Tooling which should "force doing things correctly" is
eventually hindering development and causing the end result being sub-
optimal.

I mean that creating binding docs takes way too much time from someone
like me who is "yaml-illiterate". And when I eventually get yaml done -
the end result is far less descriptive for human eyes than the "good
old" free-text format would've been. I know one can add comments - but
I don't see much of them in the binding docs...


Best Regards
 -- Matti Vaittinen




Re: [PATCH v4] powerpc/uprobes: Validation for prefixed instruction

2021-03-09 Thread Ravi Bangoria




On 3/9/21 4:51 PM, Naveen N. Rao wrote:

On 2021/03/09 08:54PM, Michael Ellerman wrote:

Ravi Bangoria  writes:

As per ISA 3.1, prefixed instruction should not cross 64-byte
boundary. So don't allow Uprobe on such prefixed instruction.

There are two ways probed instruction is changed in mapped pages.
First, when Uprobe is activated, it searches for all the relevant
pages and replace instruction in them. In this case, if that probe
is on the 64-byte unaligned prefixed instruction, error out
directly. Second, when Uprobe is already active and user maps a
relevant page via mmap(), instruction is replaced via mmap() code
path. But because Uprobe is invalid, entire mmap() operation can
not be stopped. In this case just print an error and continue.

Signed-off-by: Ravi Bangoria 
Acked-by: Naveen N. Rao 


Do we have a Fixes: tag for this?


Since this is an additional check we are adding, I don't think we should
add a Fixes: tag. Nothing is broken per-se -- we're just adding more
checks to catch simple mistakes. Also, like Oleg pointed out, there are
still many other ways for users to shoot themselves in the foot with
uprobes and prefixed instructions, if they so desire.

However, if you still think we should add a Fixes: tag, we can perhaps
use the below commit since I didn't see any specific commit adding
support for prefixed instructions for uprobes:

Fixes: 650b55b707fdfa ("powerpc: Add prefixed instructions to
instruction data type")


True. IMO, It doesn't really need any Fixes tag.






---
v3: https://lore.kernel.org/r/20210304050529.59391-1-ravi.bango...@linux.ibm.com
v3->v4:
   - CONFIG_PPC64 check was not required, remove it.
   - Use SZ_ macros instead of hardcoded numbers.

  arch/powerpc/kernel/uprobes.c | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/arch/powerpc/kernel/uprobes.c b/arch/powerpc/kernel/uprobes.c
index e8a63713e655..4cbfff6e94a3 100644
--- a/arch/powerpc/kernel/uprobes.c
+++ b/arch/powerpc/kernel/uprobes.c
@@ -41,6 +41,13 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe,
if (addr & 0x03)
return -EINVAL;
  
+	if (cpu_has_feature(CPU_FTR_ARCH_31) &&

+   ppc_inst_prefixed(auprobe->insn) &&
+   (addr & (SZ_64 - 4)) == SZ_64 - 4) {
+   pr_info_ratelimited("Cannot register a uprobe on 64 byte unaligned 
prefixed instruction\n");
+   return -EINVAL;


I realise we already did the 0x03 check above, but I still think this
would be clearer simply as:

(addr & 0x3f == 60)


Indeed, I like the use of `60' there -- hex is overrated ;)


Sure. Will resend.

Ravi


Re: [PATCH v1 2/2] iio: adc: add ADC driver for the TI TSC2046 controller

2021-03-09 Thread Andy Shevchenko
On Tue, Mar 9, 2021 at 2:18 PM Oleksij Rempel  wrote:
>
> On Tue, Mar 09, 2021 at 01:46:55PM +0200, Andy Shevchenko wrote:
> > On Tue, Mar 9, 2021 at 1:42 PM Oleksij Rempel  
> > wrote:
> > > On Tue, Mar 09, 2021 at 01:05:27PM +0200, Andy Shevchenko wrote:
> > > > On Fri, Mar 5, 2021 at 9:05 PM Jonathan Cameron
> > > >  wrote:
> > > > >
> > > > > On Fri, 5 Mar 2021 14:38:13 +0100
> > > > > Oleksij Rempel  wrote:
> > > > >
> > > > > > Basically the TI TSC2046 touchscreen controller is 8 channel ADC 
> > > > > > optimized for
> > > > > > the touchscreen use case. By implementing it as IIO ADC device, we 
> > > > > > can
> > > > > > make use of resistive-adc-touch and iio-hwmon drivers.
> > > > > >
> > > > > > So far, this driver was tested with custom version of 
> > > > > > resistive-adc-touch driver,
> > > > > > since it need to be extended to make use of Z1 and Z2 channels. The 
> > > > > > X/Y
> > > > > > are working without additional changes.
> > > > > >
> > > > > > Signed-off-by: Oleksij Rempel 
> > > > >
> > > > > Hi Oleksij,
> > > > >
> > > > > To consider this as a possible long term route instead of just making 
> > > > > this
> > > > > a touchscreen driver, we'll want to see those mods to the 
> > > > > resistive-adc-touch.
> > > > > Of course that doesn't stop review of this in the meantime.
> > > > >
> > > > > There are quite a few things in here that feel pretty specific to the 
> > > > > touchscreen
> > > > > usecase. That makes me wonder if this is a sensible approach or not.
> > > >
> > > > I'm wondering if this has any similarities with existing drivers under
> > > > drivers/input/touchscreen.
> > >
> > > Yes, for example: drivers/input/touchscreen/ads7846.c
> >
> > Then I have a few questions here:
> > 1/ why the above mentioned driver can't be extended to cover this?
>
> It is not possible to keep old device tree binding compatible with the
> new driver at least not for currently existing abstraction: ADC +
> touchscreen node.
>
> It is too expensive to overwrite the old driver, we do not have enough time 
> and
> resource to do it. I lardy spend some weeks to do it and I would need a
> many more weeks to make it by tiny slices without solving actual
> problem. Many resistive touchscreen driver should share a lot of code.
>
> Since there is already existing IIO based components, it seems to me
> better to spend available resource and making it properly in a way,
> which reflect modern best practices.
>
> > 2/ or why is the proposed driver named after the touchscreen instead
> > of the real AD/C chip behind it?
>
> I do not understand this question. The proposed driver is named after
> the chip which provides ADC functionality, In this case, it is TSC2046.
> The touchscreen is a separate physical module.
>
> The idea of this proposition is to keep physically separate components
> separately on the kernel side.
>
> > 3/ maybe we can introduce a simple AD/C driver under IIO for that?
>
> There are already simple ADC drivers for that:
> iio-hwmon: drivers/hwmon/iio_hwmon.c
> resistive-adc-touch: drivers/input/touchscreen/resistive-adc-touch.c
>
> This two driver + the proposed one, will replace functionality of ads7846.c

Okay, then maybe you can elaborate all this in the cover letter to
make sure that maintainers will know why the new driver appeared
instead of modifications to the old one.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH v2 1/5] arm64: kasan: allow to init memory when setting tags

2021-03-09 Thread Andrey Konovalov
On Mon, Mar 8, 2021 at 5:58 PM Catalin Marinas  wrote:
>
> On Mon, Mar 08, 2021 at 04:55:14PM +0100, Andrey Konovalov wrote:
> > @@ -68,10 +69,16 @@ static inline void mte_set_mem_tag_range(void *addr, 
> > size_t size, u8 tag)
> >* 'asm volatile' is required to prevent the compiler to move
> >* the statement outside of the loop.
> >*/
> > - asm volatile(__MTE_PREAMBLE "stg %0, [%0]"
> > -  :
> > -  : "r" (curr)
> > -  : "memory");
> > + if (init)
> > + asm volatile(__MTE_PREAMBLE "stzg %0, [%0]"
> > +  :
> > +  : "r" (curr)
> > +  : "memory");
> > + else
> > + asm volatile(__MTE_PREAMBLE "stg %0, [%0]"
> > +  :
> > +  : "r" (curr)
> > +  : "memory");
> >
> >   curr += MTE_GRANULE_SIZE;
> >   } while (curr != end);
>
> Is 'init' always a built-in constant here? If not, checking it once
> outside the loop may be better (or check the code generation, maybe the
> compiler is smart enough).

I think it's worth moving the init check outside the loop anyway. Will do in v3.

Thanks!


[patch 09/14] net: sundance: Use tasklet_disable_in_atomic().

2021-03-09 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

tasklet_disable() is used in the timer callback. This might be distangled,
but without access to the hardware that's a bit risky.

Replace it with tasklet_disable_in_atomic() so tasklet_disable() can be
changed to a sleep wait once all remaining atomic users are converted.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: Denis Kirjanov 
Cc: "David S. Miller" 
Cc: Jakub Kicinski 
Cc: net...@vger.kernel.org
---
 drivers/net/ethernet/dlink/sundance.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/ethernet/dlink/sundance.c
+++ b/drivers/net/ethernet/dlink/sundance.c
@@ -963,7 +963,7 @@ static void tx_timeout(struct net_device
unsigned long flag;
 
netif_stop_queue(dev);
-   tasklet_disable(>tx_tasklet);
+   tasklet_disable_in_atomic(>tx_tasklet);
iowrite16(0, ioaddr + IntrEnable);
printk(KERN_WARNING "%s: Transmit timed out, TxStatus %2.2x "
   "TxFrameId %2.2x,"



[patch 08/14] net: jme: Replace link-change tasklet with work

2021-03-09 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

The link change tasklet disables the tasklets for tx/rx processing while
upating hw parameters and then enables the tasklets again.

This update can also be pushed into a workqueue where it can be performed
in preemptible context. This allows tasklet_disable() to become sleeping.

Replace the linkch_task tasklet with a work.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
---
 drivers/net/ethernet/jme.c |   10 +-
 drivers/net/ethernet/jme.h |2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

--- a/drivers/net/ethernet/jme.c
+++ b/drivers/net/ethernet/jme.c
@@ -1265,9 +1265,9 @@ jme_stop_shutdown_timer(struct jme_adapt
jwrite32f(jme, JME_APMC, apmc);
 }
 
-static void jme_link_change_tasklet(struct tasklet_struct *t)
+static void jme_link_change_work(struct work_struct *work)
 {
-   struct jme_adapter *jme = from_tasklet(jme, t, linkch_task);
+   struct jme_adapter *jme = container_of(work, struct jme_adapter, 
linkch_task);
struct net_device *netdev = jme->dev;
int rc;
 
@@ -1510,7 +1510,7 @@ jme_intr_msi(struct jme_adapter *jme, u3
 * all other events are ignored
 */
jwrite32(jme, JME_IEVE, intrstat);
-   tasklet_schedule(>linkch_task);
+   schedule_work(>linkch_task);
goto out_reenable;
}
 
@@ -1832,7 +1832,6 @@ jme_open(struct net_device *netdev)
jme_clear_pm_disable_wol(jme);
JME_NAPI_ENABLE(jme);
 
-   tasklet_setup(>linkch_task, jme_link_change_tasklet);
tasklet_setup(>txclean_task, jme_tx_clean_tasklet);
tasklet_setup(>rxclean_task, jme_rx_clean_tasklet);
tasklet_setup(>rxempty_task, jme_rx_empty_tasklet);
@@ -1920,7 +1919,7 @@ jme_close(struct net_device *netdev)
 
JME_NAPI_DISABLE(jme);
 
-   tasklet_kill(>linkch_task);
+   cancel_work_sync(>linkch_task);
tasklet_kill(>txclean_task);
tasklet_kill(>rxclean_task);
tasklet_kill(>rxempty_task);
@@ -3035,6 +3034,7 @@ jme_init_one(struct pci_dev *pdev,
atomic_set(>rx_empty, 1);
 
tasklet_setup(>pcc_task, jme_pcc_tasklet);
+   INIT_WORK(>linkch_task, jme_link_change_work);
jme->dpi.cur = PCC_P1;
 
jme->reg_ghc = 0;
--- a/drivers/net/ethernet/jme.h
+++ b/drivers/net/ethernet/jme.h
@@ -411,7 +411,7 @@ struct jme_adapter {
struct tasklet_struct   rxempty_task;
struct tasklet_struct   rxclean_task;
struct tasklet_struct   txclean_task;
-   struct tasklet_struct   linkch_task;
+   struct work_struct  linkch_task;
struct tasklet_struct   pcc_task;
unsigned long   flags;
u32 reg_txcs;



[patch 10/14] ath9k: Use tasklet_disable_in_atomic()

2021-03-09 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

All callers of ath9k_beacon_ensure_primary_slot() are preemptible /
acquire a mutex except for this callchain:

  spin_lock_bh(>sc_pcu_lock);
  ath_complete_reset()
  -> ath9k_calculate_summary_state()
 -> ath9k_beacon_ensure_primary_slot()

It's unclear how that can be distangled, so use tasklet_disable_in_atomic()
for now. This allows tasklet_disable() to become sleepable once the
remaining atomic users are cleaned up.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: ath9k-de...@qca.qualcomm.com
Cc: Kalle Valo 
Cc: "David S. Miller" 
Cc: Jakub Kicinski 
Cc: linux-wirel...@vger.kernel.org
Cc: net...@vger.kernel.org
---
 drivers/net/wireless/ath/ath9k/beacon.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -251,7 +251,7 @@ void ath9k_beacon_ensure_primary_slot(st
int first_slot = ATH_BCBUF;
int slot;
 
-   tasklet_disable(>bcon_tasklet);
+   tasklet_disable_in_atomic(>bcon_tasklet);
 
/* Find first taken slot. */
for (slot = 0; slot < ATH_BCBUF; slot++) {



[patch 12/14] PCI: hv: Use tasklet_disable_in_atomic()

2021-03-09 Thread Thomas Gleixner
From: Sebastian Andrzej Siewior 

The hv_compose_msi_msg() callback in irq_chip::irq_compose_msi_msg is
invoked via irq_chip_compose_msi_msg(), which itself is always invoked from
atomic contexts from the guts of the interrupt core code.

There is no way to change this w/o rewriting the whole driver, so use
tasklet_disable_in_atomic() which allows to make tasklet_disable()
sleepable once the remaining atomic users are addressed.

Signed-off-by: Sebastian Andrzej Siewior 
Signed-off-by: Thomas Gleixner 
Cc: "K. Y. Srinivasan" 
Cc: Haiyang Zhang 
Cc: Stephen Hemminger 
Cc: Wei Liu 
Cc: Lorenzo Pieralisi 
Cc: Rob Herring 
Cc: Bjorn Helgaas 
Cc: linux-hyp...@vger.kernel.org
Cc: linux-...@vger.kernel.org
---
 drivers/pci/controller/pci-hyperv.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -1458,7 +1458,7 @@ static void hv_compose_msi_msg(struct ir
 * Prevents hv_pci_onchannelcallback() from running concurrently
 * in the tasklet.
 */
-   tasklet_disable(>callback_event);
+   tasklet_disable_in_atomic(>callback_event);
 
/*
 * Since this function is called with IRQ locks held, can't



  1   2   3   4   5   6   7   8   9   10   >