All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Esben Haabendal" <esben@geanix.com>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Ray Jui" <rjui@broadcom.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Sunil V L" <sunilvl@ventanamicro.com>,
	"Matt Turner" <mattst88@gmail.com>,
	"Stefan Wahren" <wahrenst@gmx.net>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Markus Schneider-Pargmann" <msp@baylibre.com>,
	"Udit Kumar" <u-kumar1@ti.com>,
	"Griffin Kroah-Hartman" <griffin@kroah.com>,
	"Niklas Schnelle" <schnelle@linux.ibm.com>,
	"Serge Semin" <fancer.lancer@gmail.com>,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH tty-next v4 4/6] serial: 8250: Provide flag for IER toggling for RS485
Date: Fri, 3 Jan 2025 16:30:00 +0100	[thread overview]
Message-ID: <Z3gCeP_P7VPpcOLA@pathway.suse.cz> (raw)
In-Reply-To: <20241227224523.28131-5-john.ogness@linutronix.de>

On Fri 2024-12-27 23:51:20, John Ogness wrote:
> For RS485 mode, if SER_RS485_RX_DURING_TX is not available, the
> console ->write() callback needs to enable/disable Tx. It does
> this by calling the ->rs485_start_tx() and ->rs485_stop_tx()
> callbacks. However, some of these callbacks also disable/enable
> interrupts and makes power management calls. This causes 2
> problems for console writing:
> 
> 1. A console write can occur in contexts that are illegal for
>    pm_runtime_*(). It is not even necessary for console writing
>    to use pm_runtime_*() because a console already does this in
>    serial8250_console_setup() and serial8250_console_exit().
>
> 2. The console ->write() callback already handles
>    disabling/enabling the interrupts by properly restoring the
>    previous IER value.

I was a bit confused by the description of the 2nd problem.
It is not clear whether it actually is a problem.

My understanding is that the nested IER manipulation does not
harm. And it is not needed at the same time. As a result,
the related pr_runtime_*() calls are not needed either.
So this is 2nd reason why the problematic pr_runtime_*() calls
can be removed in the serial8250_console_write() code path.

> Add an argument @toggle_ier to the ->rs485_start_tx() and
> ->rs485_stop_tx() callbacks to specify if they may disable/enable
> receive interrupts while using pm_runtime_*(). Console writing
> will not allow the toggling.
> 
> For all call sites other than console writing there is no
> functional change.
> 
> Signed-off-by: John Ogness <john.ogness@linutronix.de>

It seems that the patch does what is says. I'll try to describe
it using my words to explain how I understand it.

IMHO, the main motivation is to prevent calling pm_runtime_*() in
serial8250_console_write(). It is not safe in some contexts,
especially in NMI. And it is not needed from two reasons:

  1. The console->write() callback is used only by registered consoles.
     And the pm_runtime usage counter is already bumped during
     the console registration by serial8250_console_setup().

  2. The pm_runtime_*() calls are used in the following code path

	+ serial8250_console_write()
	  + up->rs485_start_tx()
	    + serial8250_em485_start_tx()
	      + serial8250_stop_rx()

     This code is not needed because serial8250_console_write()
     always clears IER by __serial8250_clear_IER(up) anyway.

     In fact, the extra IER manipulation in serial8250_em485_start_tx()
     might be seen as a bug. Well, it is a NOP.

All in all, the patch looks good to me.

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr


  reply	other threads:[~2025-01-03 15:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-27 22:45 [PATCH tty-next v4 0/6] convert 8250 to nbcon John Ogness
2024-12-27 22:45 ` [PATCH tty-next v4 1/6] serial: 8250: Adjust the timeout for FIFO mode John Ogness
2025-01-03  9:39   ` Petr Mladek
2024-12-27 22:45 ` [PATCH tty-next v4 2/6] serial: 8250: Use frame rate to determine timeout John Ogness
2024-12-28 21:51   ` Andy Shevchenko
2025-01-03 11:18   ` Petr Mladek
2024-12-27 22:45 ` [PATCH tty-next v4 3/6] serial: 8250: Use high-level writing function for FIFO John Ogness
2024-12-27 22:45 ` [PATCH tty-next v4 4/6] serial: 8250: Provide flag for IER toggling for RS485 John Ogness
2025-01-03 15:30   ` Petr Mladek [this message]
2025-01-05  0:26     ` John Ogness
2025-01-06 14:00       ` Petr Mladek
2024-12-27 22:45 ` [PATCH tty-next v4 5/6] serial: 8250: Switch to nbcon console John Ogness
2024-12-28 22:11   ` Andy Shevchenko
2024-12-30 10:22     ` John Ogness
2025-01-03 16:43   ` Petr Mladek
2025-01-05  0:57     ` John Ogness
2025-01-06 16:08       ` Petr Mladek
2024-12-27 22:45 ` [PATCH tty-next v4 6/6] serial: 8250: Revert "drop lockdep annotation from serial8250_clear_IER()" John Ogness
2024-12-28 22:18 ` [PATCH tty-next v4 0/6] convert 8250 to nbcon Andy Shevchenko
2024-12-30 11:00   ` John Ogness
2024-12-30 15:29 ` John Ogness

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z3gCeP_P7VPpcOLA@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=esben@geanix.com \
    --cc=fancer.lancer@gmail.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=griffin@kroah.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=khilman@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mattst88@gmail.com \
    --cc=msp@baylibre.com \
    --cc=rjui@broadcom.com \
    --cc=rostedt@goodmis.org \
    --cc=sbranden@broadcom.com \
    --cc=schnelle@linux.ibm.com \
    --cc=senozhatsky@chromium.org \
    --cc=sunilvl@ventanamicro.com \
    --cc=tglx@linutronix.de \
    --cc=u-kumar1@ti.com \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.