Re: [PATCH] console: don't select first registered console if stdout-path used

2017-08-28 Thread Eugeniy Paltsev
On Sat, 2017-08-26 at 02:44 +0900, Sergey Senozhatsky wrote:
> On (08/25/17 16:14), Eugeniy Paltsev wrote:
> > In the current implementation we take the first console that
> > registers if we didn't select one.
> > 
> > But if we specify console via "stdout-path" property in device tree
> > we don't want first console that registers here to be selected.
> > Otherwise we may choose wrong console - for example if some console
> > is registered earlier than console is pointed in "stdout-path"
> > property because console pointed in "stdout-path" property can be
> > add as
> > preferred quite late - when it's driver is probed.
> > 
> > Signed-off-by: Eugeniy Paltsev 
> 
> hm... this is not the first time we see DT and stdout-path.
> and so far it was pretty painful :) e.g. commits c6c7d83b9c9e,
> 05fd007e4629.
> 
>   -ss

Hm... looks like I had to update my patch to keep existing tty0
behavior.

Before this patch tty0 was registered even if it was specified neither
in "bootargs" nor in "stdout-path". 
So I should retain this behavior as a lot of ARM boards (and some
powerpc) rely on it.

> 
> > ---
> >  kernel/printk/printk.c | 11 +++
> >  1 file changed, 11 insertions(+)
> > 
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index 512f7c2..23262c1 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -26,6 +26,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -2431,6 +2432,16 @@ void register_console(struct console
> > *newcon)
> >     if (!has_preferred || bcon || !console_drivers)
> >     has_preferred = preferred_console >= 0;
> >  
> > +
> > +   /*
> > +    * If we specify console via "stdout-path" property in
> > device tree
> > +    * we don't want first console that registers here to be
> > selected.
> > +    */
> > +#ifdef CONFIG_OF
> > +   if (of_stdout)
> > +   has_preferred = true;
> > +#endif
> > +
> >     /*
> >      *  See if we want to use this console driver. If we
> >      *  didn't select a console we take the first one
> > -- 
> > 2.9.3
> > 
-- 
 Eugeniy Paltsev
___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

[PATCH v2 1/2] OF: move extern declarations of of_stdout inside ifdef

2017-08-28 Thread Eugeniy Paltsev
Move extern declarations of "of_stdout" pointer inside "CONFIG_OF"
ifdef to be able to get rid of "CONFIG_OF" ifdef in its usage places.

Acked-by: Rob Herring 
Suggested-by: Steven Rostedt 
Signed-off-by: Eugeniy Paltsev 
---
 include/linux/of.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index cfc3411..be28cb9 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -135,7 +135,6 @@ static inline void of_node_put(struct device_node *node) { }
 extern struct device_node *of_root;
 extern struct device_node *of_chosen;
 extern struct device_node *of_aliases;
-extern struct device_node *of_stdout;
 extern raw_spinlock_t devtree_lock;
 
 /* flag descriptions (need to be visible even when !CONFIG_OF) */
@@ -147,6 +146,8 @@ extern raw_spinlock_t devtree_lock;
 #define OF_BAD_ADDR((u64)-1)
 
 #ifdef CONFIG_OF
+extern struct device_node *of_stdout;
+
 void of_core_init(void);
 
 static inline bool is_of_node(const struct fwnode_handle *fwnode)
@@ -539,6 +540,7 @@ const char *of_prop_next_string(struct property *prop, 
const char *cur);
 bool of_console_check(struct device_node *dn, char *name, int index);
 
 #else /* CONFIG_OF */
+#define of_stdout  NULL
 
 static inline void of_core_init(void)
 {
-- 
2.9.3


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 0/2] console: don't select first registered console if stdout-path used

2017-08-28 Thread Eugeniy Paltsev
Don't select first registered console if one is specified by the device tree
via the stdout-path (or linux,stdout-path) chosen node properties.

Eugeniy Paltsev (2):
  OF: move extern declarations of of_stdout inside ifdef
  console: don't select first registered console if stdout-path used
  
Changes v1->v2:
 * Add exception for "tty0" console as current tty0 behavior is widely used
   by ARM and powerpc boards.

 include/linux/of.h |  4 ++-
 kernel/printk/printk.c | 84 +-
 2 files changed, 72 insertions(+), 16 deletions(-)

-- 
2.9.3

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH v2 2/2] console: don't select first registered console if stdout-path used

2017-08-28 Thread Eugeniy Paltsev
In the current implementation we take the first console that
registers if we didn't select one.

But if we specify console via "stdout-path" property in device tree
we don't want first console that registers here to be selected.
Otherwise we may choose wrong console - for example if some console
is registered earlier than console is pointed in "stdout-path"
property because console pointed in "stdout-path" property can be add as
preferred quite late - when it's driver is probed.

We retain previous behavior for tty0 console (if "stdout-path" used)
as a special case:
tty0 will be registered even if it was specified neither
in "bootargs" nor in "stdout-path".
We had to retain this behavior because a lot of ARM boards (and some
powerpc) rely on it.

Signed-off-by: Eugeniy Paltsev 
---
Changes v1->v2:
 * Add exception for "tty0" console as current behavior is widely used
   by ARM and powerpc boards.

 kernel/printk/printk.c | 84 +-
 1 file changed, 69 insertions(+), 15 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 512f7c2..be40f57 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2376,6 +2377,55 @@ static int __init keep_bootcon_setup(char *str)
 
 early_param("keep_bootcon", keep_bootcon_setup);
 
+static bool console_selected_by_of(void)
+{
+   return !!of_stdout;
+}
+
+static bool can_be_tty0(struct console *newcon)
+{
+   struct console *con = NULL;
+
+   if (newcon->index > 0)
+   return false;
+
+   if (strcmp(newcon->name, "tty") != 0)
+   return false;
+
+   if (newcon->index == 0)
+   return true;
+
+   /* do we have "tty" console already registered? */
+   for_each_console(con) {
+   if (strcmp(con->name, "tty") != 0)
+   continue;
+
+   if (con->index >= 0)
+   return false;
+   }
+
+   return true;
+}
+
+static bool take_console_noopts(struct console *newcon)
+{
+   if (newcon->index < 0)
+   newcon->index = 0;
+
+   if ((newcon->setup != NULL) && (newcon->setup(newcon, NULL) != 0))
+   return false;
+
+   newcon->flags |= CON_ENABLED;
+
+   if (newcon->device && !can_be_tty0(newcon))
+   newcon->flags |= CON_CONSDEV;
+
+   if (newcon->device)
+   return true;
+
+   return false;
+}
+
 /*
  * The console driver calls this routine during kernel initialization
  * to register the console printing procedure with printk() and to
@@ -2432,22 +2482,26 @@ void register_console(struct console *newcon)
has_preferred = preferred_console >= 0;
 
/*
-*  See if we want to use this console driver. If we
-*  didn't select a console we take the first one
-*  that registers here.
+* If we specify console via "stdout-path" property in device tree
+* we don't want first console that registers here to be selected.
 */
-   if (!has_preferred) {
-   if (newcon->index < 0)
-   newcon->index = 0;
-   if (newcon->setup == NULL ||
-   newcon->setup(newcon, NULL) == 0) {
-   newcon->flags |= CON_ENABLED;
-   if (newcon->device) {
-   newcon->flags |= CON_CONSDEV;
-   has_preferred = true;
-   }
-   }
-   }
+   if (console_selected_by_of())
+   has_preferred = true;
+
+   /*
+* See if we want to use this console driver. If we didn't select
+* a console we take the first one that registers here.
+*/
+   if (!has_preferred)
+   has_preferred |= take_console_noopts(newcon);
+
+   /*
+* Treat "tty0" (in case of "stdout-path" using) as a special case:
+* "tty0" will be registered even if it was specified neither in
+* "bootargs" nor in "stdout-path".
+*/
+   if (console_selected_by_of() && can_be_tty0(newcon))
+   has_preferred |= take_console_noopts(newcon);
 
/*
 *  See if this console matches one we selected on
-- 
2.9.3


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARCv2: SMP: Mask only private-per-core IRQ lines on boot at core intc

2017-08-28 Thread Vineet Gupta
From: Alexey Brodkin 

Recent commit a8ec3ee861b6 "arc: Mask individual IRQ lines during core INTC 
init"
breaks interrupt handling on ARCv2 SMP systems.

That commit masked all interrupts at onset, as some controllers on some boards
(customer as well as internal), would assert interrutps early before any 
handlers
were installed. For SMP systems, the masking was done at each cpu's core-intc.
Later, when the IRQ was actually requested, it was unmasked, but only on the
requesting cpu. For "common" interrupts, which were wired up from the
2nd level IDU intc, this was as issue as they needed to be enabled on ALL
the cpus (given that IDU IRQs are by default served Round Robin across
cpus)

So fix that by NOT masking "common" interrupts at core-intc, but instead
at the 2nd level IDU intc (latter already being done in idu_of_init())

Fixes: a8ec3ee861b6 ("arc: Mask individual IRQ lines during core INTC init")
Signed-off-by: Alexey Brodkin 
Signed-off-by: Vineet Gupta 
[vgupta: reworked changelog, removed the extraneous idu_irq_mask_raw()]

Signed-off-by: Vineet Gupta 
---
 arch/arc/kernel/intc-arcv2.c   | 11 +--
 arch/arc/kernel/intc-compact.c |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/arc/kernel/intc-arcv2.c b/arch/arc/kernel/intc-arcv2.c
index cf90714a676d..067ea362fb3e 100644
--- a/arch/arc/kernel/intc-arcv2.c
+++ b/arch/arc/kernel/intc-arcv2.c
@@ -75,13 +75,20 @@ void arc_init_IRQ(void)
 * Set a default priority for all available interrupts to prevent
 * switching of register banks if Fast IRQ and multiple register banks
 * are supported by CPU.
-* Also disable all IRQ lines so faulty external hardware won't
+* Also disable private-per-core IRQ lines so faulty external HW won't
 * trigger interrupt that kernel is not ready to handle.
 */
for (i = NR_EXCEPTIONS; i < irq_bcr.irqs + NR_EXCEPTIONS; i++) {
write_aux_reg(AUX_IRQ_SELECT, i);
write_aux_reg(AUX_IRQ_PRIORITY, ARCV2_IRQ_DEF_PRIO);
-   write_aux_reg(AUX_IRQ_ENABLE, 0);
+
+   /*
+* Only mask cpu private IRQs here.
+* "common" interrupts are masked at IDU, otherwise it would
+* need to be unmasked at each cpu, with IPIs
+*/
+   if (i < FIRST_EXT_IRQ)
+   write_aux_reg(AUX_IRQ_ENABLE, 0);
}
 
/* setup status32, don't enable intr yet as kernel doesn't want */
diff --git a/arch/arc/kernel/intc-compact.c b/arch/arc/kernel/intc-compact.c
index cef388025adf..47b421fa0147 100644
--- a/arch/arc/kernel/intc-compact.c
+++ b/arch/arc/kernel/intc-compact.c
@@ -27,7 +27,7 @@
  */
 void arc_init_IRQ(void)
 {
-   int level_mask = 0, i;
+   unsigned int level_mask = 0, i;
 
/* Is timer high priority Interrupt (Level2 in ARCompact jargon) */
level_mask |= IS_ENABLED(CONFIG_ARC_COMPACT_IRQ_LEVELS) << TIMER0_IRQ;
-- 
2.7.4


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARC fix for 4.13-final

2017-08-28 Thread Vineet Gupta
Hi Linus,

Could you please add this ARC fixlet - which is a regression from pull req of
last week - but only shows up in our out of tree platform (slated for next
window).

Thx,
-Vineet

Alexey Brodkin (1):
  ARCv2: SMP: Mask only private-per-core IRQ lines on boot at core intc

 arch/arc/kernel/intc-arcv2.c   | 11 +--
 arch/arc/kernel/intc-compact.c |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

-- 
2.7.4


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc