mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Marcos Paulo de Souza" <mpdesouza@suse.com>,
	"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
	"Fushuai Wang" <wangfushuai@baidu.com>,
	"Kees Cook" <kees@kernel.org>,
	"Stepan Ionichev" <sozdayvek@gmail.com>,
	linux-serial@vger.kernel.org,
	"Manuel Lauss" <manuel.lauss@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] printk: nbcon: Introduce Braille helpers
Date: Fri, 25 Sep 2026 16:34:12 +0200	[thread overview]
Message-ID: <araGZN5_ixhM4AXh@pathway.suse.cz> (raw)
In-Reply-To: <87fqyxigqj.fsf@jogness.linutronix.de>

On Fri 2026-09-25 15:54:52, John Ogness wrote:
> On 2026-09-22, Petr Mladek <pmladek@suse.com> wrote:
> > These helpers will be used when calling console->write_atomic
> > in the Braille console driver.
> >
> > The Braille console is not registered as a standard printk console.
> > Instead, it is integrated with the virtual terminal (VT) and writes
> > data using the legacy con->write() callback of the associated serial
> > console driver.
> >
> > When the underlying console driver is converted to the NBCON API, the
> > Braille console needs to use the con->write_atomic() callback instead.
> > This callback must be synchronized by acquiring the nbcon console context.
> >
> > Fixes: d3539347022a ("serial: 8250: Switch to nbcon console, take 2")
> 
> This is not 8250 specific. But I am not sure which commit you want to
> mark as Fixes.
> 
> For 62627bf0cadf ("kdb: Adapt kdb_msg_write to work with NBCON
> consoles") there was no Fixes tag.

You are right. I somehow though that it was connected with the uart
8250 serial console. But the code allows to use it with other console
drivers as well.

Well, I guess that the driver was created for a particular Braille
device. I wonder if there exists Braille devices working with
other serial ports which are compatible...

I could omit the Fixes tag. But I think that in practice it is
primary for the uart 8250 driver.

> > Signed-off-by: Petr Mladek <pmladek@suse.com>
> > ---
> >  include/linux/console.h |  8 ++++++
> >  kernel/printk/nbcon.c   | 59 +++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 67 insertions(+)
> >
> > diff --git a/include/linux/console.h b/include/linux/console.h
> > index 502d1abe3f50..d780f6de303a 100644
> > --- a/include/linux/console.h
> > +++ b/include/linux/console.h
> > @@ -615,6 +615,10 @@ extern bool nbcon_allow_unsafe_takeover(void);
> >  extern bool nbcon_kdb_try_acquire(struct console *con,
> >  				  struct nbcon_write_context *wctxt);
> >  extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
> > +extern bool nbcon_is_braille(struct nbcon_write_context *wctxt);
> > +extern bool nbcon_braille_try_acquire(struct console *con,
> > +				      struct nbcon_write_context *wctxt);
> > +extern void nbcon_braille_release(struct nbcon_write_context *wctxt);
> >  
> >  /*
> >   * Check if the given console is currently capable and allowed to print
> > @@ -678,8 +682,12 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }
> >  static inline bool nbcon_kdb_try_acquire(struct console *con,
> >  					 struct nbcon_write_context *wctxt) { return false; }
> >  static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
> > +static inline bool nbcon_is_braille(struct nbcon_write_context *wctxt) { return false; }
> >  static inline bool console_is_usable(struct console *con, short flags,
> >  				     bool use_atomic) { return false; }
> > +static inline bool nbcon_braille_try_acquire(struct console *con,
> > +					     struct nbcon_write_context *wctxt) { return false; }
> > +static inline void nbcon_braille_release(struct nbcon_write_context *wctxt) { }
> >  #endif
> >  
> >  extern int console_set_on_cmdline;
> > diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> > index d17704fe93ae..a5e053ffe4da 100644
> > --- a/kernel/printk/nbcon.c
> > +++ b/kernel/printk/nbcon.c
> > @@ -2002,3 +2002,62 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt)
> >  	 */
> >  	__nbcon_atomic_flush_pending_con(ctxt->console, prb_next_reserve_seq(prb));
> >  }
> > +
> > +/**
> > + * nbcon_is_braille - Checks whether the nbcon write context is using Braille console
> > + *
> > + * @wctxt:	checked nbcon write context
> > + *
> > + * Return: True when the write context is associated with a Braille console.
> > + *	   Othrewise, return false.
> > + *
> > + * Context: Can be called in any context but only when Braille console is
> > + *	registered and the struct console could not disappear.
> > + */
> > +bool nbcon_is_braille(struct nbcon_write_context *wctxt)
> > +{
> > +	struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
> > +	struct console *con = ctxt->console;
> > +
> > +	return con && con->flags & CON_BRL;
> > +}
> > +
> > +/**
> > + * nbcon_braille_try_acquire - Try to acquire nbcon console for braille_write()
> > + *
> > + * @con:	The nbcon console to acquire
> > + * @wctxt:	The nbcon write context to be used on success
> > + *
> > + * Context:	braille_write() for emitting a single buffer on Braille console.
> > + *
> > + * Return:	True if the console was acquired. False otherwise.
> > + *
> > + * Braille console is not registered as a proper printk consoles. Instead,
> > + * it is integrated with the graphical virtual terminal.
> > + *
> > + * This function acquires the nbcon console using priority NBCON_PRIO_EMERGENCY.
> > + */
> > +bool nbcon_braille_try_acquire(struct console *con,
> > +			   struct nbcon_write_context *wctxt)
> > +{
> > +	struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
> > +
> > +	memset(ctxt, 0, sizeof(*ctxt));
> > +	ctxt->console = con;
> > +	ctxt->prio    = NBCON_PRIO_EMERGENCY;
> > +
> > +	return nbcon_context_try_acquire(ctxt, false);
> > +}
> 
> This is really the same thing as nbcon_kdb_try_acquire().
> 
> As you mentioned in your cover letter, it is a bug that
> nbcon_kdb_try_acquire() enters an unsafe section because @unsafe is a
> bool rather than a usage counter.
> 
> Since we have limited bits for struct nbcon_state, we need to stop
> entering unsafe within nbcon_kdb_try_acquire(). As I mentioned in the
> response to your cover letter, all the other CPUs should be quiesced
> anyway.

I working on v2 today morning and looked at it from different angles.
I decided to send v2 where I described my thoughts, see
https://lore.kernel.org/all/20260925141729.173943-1-pmladek@suse.com/

I guess that we need another solution at least for PREEMPT_RT.
But I am not sure how to do so correctly.

Sigh, the Braille console is quite a hack. I am afraid that the NBCON
API is not ready for this use case. IMHO, the most similar user
is nbcon_legacy_emit_next_record() which is used to flush nbcon
consoles from the legacy loop when some early console driver is
still registered.

Best Regards,
Petr

  reply	other threads:[~2026-09-25 14:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  7:25 [PATCH 0/2] braille: nbcon: Allow using a serial driver converted to nbcon API as a Braille console Petr Mladek
2026-09-22  7:25 ` [PATCH 1/2] printk: nbcon: Introduce Braille helpers Petr Mladek
2026-09-25 13:48   ` John Ogness
2026-09-25 14:34     ` Petr Mladek [this message]
2026-09-22  7:25 ` [PATCH 2/2] braille: nbcon: Use nbcon atomic console callbacks Petr Mladek
     [not found]   ` <20260922073728.2ADCD1F000FF@smtp.kernel.org>
2026-09-23 14:39     ` Petr Mladek
2026-09-25 14:34   ` John Ogness
2026-09-24 23:53 ` [PATCH 0/2] braille: nbcon: Allow using a serial driver converted to nbcon API as a Braille console Samuel Thibault
2026-09-25 13:08 ` John Ogness
2026-09-25 14:10   ` Petr Mladek
2026-09-25 14:36     ` John Ogness
2026-09-25 14:49       ` Petr Mladek
2026-09-25 15:05         ` John Ogness
2026-09-25 15:41           ` Petr Mladek

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=araGZN5_ixhM4AXh@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=manuel.lauss@gmail.com \
    --cc=mpdesouza@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=senozhatsky@chromium.org \
    --cc=sozdayvek@gmail.com \
    --cc=wangfushuai@baidu.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®