lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 20 May 2024 14:13:14 +0200
From: Petr Mladek <pmladek@...e.com>
To: John Ogness <john.ogness@...utronix.de>
Cc: Sergey Senozhatsky <senozhatsky@...omium.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Thomas Gleixner <tglx@...utronix.de>, linux-kernel@...r.kernel.org,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [PATCH printk v5 11/30] nbcon: Provide functions for drivers to
 acquire console for non-printing

On Thu 2024-05-02 23:44:20, John Ogness wrote:
> Provide functions nbcon_driver_try_acquire() and
> nbcon_driver_release() to allow drivers to acquire the nbcon
> console and mark it unsafe for handover/takeover.

I would prefer to rename 'driver' to 'device' to keep the existing
naming scheme in struct console. The API will be used to
synchronize the 'device' element.

> These functions are to be used by nbcon drivers when performing
> non-printing activities that should be synchronized with their
> atomic_write() callback.

I am still trying to create a mental model around the synchronization
between the device-specific locks and nbcon context. Also it took
me some time to realize that just disambling the migration is
perfectly fine here.

I propose a bit extended commit message:

<proposal>
Subject: nbcon: Add API to acquire context for non-printing operations

Provide functions nbcon_device_try_acquire() and
nbcon_device_release() which will try to acquire the nbcon console
ownership with NBCON_PRIO_NORMAL and mark it unsafe for handover/takeover.

These functions are to be used together with the device-specific
locking when performing non-printing activities on the console device.
They will allow synchronization against atomic_write() callback which
will be serialized, for higher priority contexts, only by acquiring
the console context ownership.

Pitfalls:

The API requires to be called in a context with a disabled migration
because it uses per-CPU variables internally.

The context is set unsafe for a takeover all the time. It guarantees
full serialization against any atomic_write() caller except for
the final flush in panic() which might try an unsafe takeover.
</proposal>

> --- a/include/linux/console.h
> +++ b/include/linux/console.h
> @@ -304,6 +304,7 @@ struct nbcon_write_context {
>   *
>   * @nbcon_state:	State for nbcon consoles
>   * @nbcon_seq:		Sequence number of the next record for nbcon to print
> + * @nbcon_driver_ctxt:	Context available for driver non-printing operations

This provides a context for "@device".

We should call this "@nbcon_device_ctxt" to avoid confusion.


>   * @pbufs:		Pointer to nbcon private buffer
>   */
>  struct console {
> @@ -399,6 +400,7 @@ struct console {
>  
>  	atomic_t		__private nbcon_state;
>  	atomic_long_t		__private nbcon_seq;
> +	struct nbcon_context	__private nbcon_driver_ctxt;
>  	struct printk_buffers	*pbufs;
>  };
>  
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index d8b3f51d9e98..d0a1106388d1 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -9,6 +9,8 @@
>  #include <linux/ratelimit_types.h>
>  #include <linux/once_lite.h>
>  
> +struct console;
> +
>  extern const char linux_banner[];
>  extern const char linux_proc_banner[];
>  
> @@ -193,6 +195,8 @@ void show_regs_print_info(const char *log_lvl);
>  extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
>  extern asmlinkage void dump_stack(void) __cold;
>  void printk_trigger_flush(void);
> +extern bool nbcon_driver_try_acquire(struct console *con);
> +extern void nbcon_driver_release(struct console *con);

Similar here:

s/driver/device/

>  #else
>  static inline __printf(1, 0)
>  int vprintk(const char *s, va_list args)


With all the renames and updated commit message:

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

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ