Netdev List
 help / color / mirror / Atom feed
* [RFC] netconsole: plan for a safe atomic write
@ 2026-11-13 13:41 Breno Leitao
  2026-11-16 15:52 ` John Ogness
  0 siblings, 1 reply; 2+ messages in thread
From: Breno Leitao @ 2026-11-13 13:41 UTC (permalink / raw)
  To: john.ogness, pmladek, kuba, gustavold; +Cc: linux-kernel, printk, netdev

Hello,

netconsole is CON_NBCON_ATOMIC_UNSAFE, so write_atomic() only runs at
the very end of panic. There is a desired to have called safe atomic
printing[1].

This is the plan I would like to agree on before posting patches:

1. Now that we have one console per target, use one lock per
   console/target.
   - printk holds the target's device_lock around write_thread(),
     write_atomic() runs under the console ownership, and stopping
     a target takes both. target_list_lock and the cleanup list go away:
     the list changes under dynamic_netconsole_mutex and RTNL, and is
     walked under either.

2. A per-target field to track atomic writes.
   - In that mode, skbs come only from a pool popped without a lock and
     refilled through irq_work.

3. A try-once netpoll transmit, as Jakub outlined [2]:
   - One HARD_TX_TRYLOCK, then busy, with no polling, freeing or
     wakeups, which can deadlock under rq->lock[3].
   - It refuses when this CPU owns the queue (netif_tx_owned()), is in
     the device's NAPI poll (netpoll_owner_active()), or is in NMI on
     PREEMPT_RT.

This does not make ndo_start_xmit() safe, so the flag stays until
drivers can opt in to atomic transmit.

It is still unclear to me whether write_atomic() should depend on the
context (regular NMI/panic): 
 * For regular NMI use the try lock as best effort
 * Ignore the locks only in the final panic flush. (unclear if this is
   an option)

Is this a reasonable plan, or, there are some missing parts I am not
seeing?

Thanks,
--breno

[1] https://lore.kernel.org/all/874ie4y5mw.fsf@jogness.linutronix.de/
[2] https://lore.kernel.org/all/20260617132127.645534d1@kernel.org/
[3] https://lore.kernel.org/all/20260610183621.3915271-1-vlad.wing@gmail.com/


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC] netconsole: plan for a safe atomic write
  2026-11-13 13:41 [RFC] netconsole: plan for a safe atomic write Breno Leitao
@ 2026-11-16 15:52 ` John Ogness
  0 siblings, 0 replies; 2+ messages in thread
From: John Ogness @ 2026-11-16 15:52 UTC (permalink / raw)
  To: Breno Leitao, pmladek, kuba, gustavold; +Cc: linux-kernel, printk, netdev

Hi Breno,

On 2026-11-13, Breno Leitao <leitao@debian.org> wrote:
> netconsole is CON_NBCON_ATOMIC_UNSAFE, so write_atomic() only runs at
> the very end of panic. There is a desired to have called safe atomic
> printing[1].
>
> This is the plan I would like to agree on before posting patches:
>
> 1. Now that we have one console per target, use one lock per
>    console/target.
>    - printk holds the target's device_lock around write_thread(),
>      write_atomic() runs under the console ownership, and stopping
>      a target takes both. target_list_lock and the cleanup list go away:
>      the list changes under dynamic_netconsole_mutex and RTNL, and is
>      walked under either.

This synchronizes the console against itself and the user interface
(netconsole configuration). IIUC it does not provide any synchronization
against non-netconsole usage of the port.

> 2. A per-target field to track atomic writes.
>    - In that mode, skbs come only from a pool popped without a lock and
>      refilled through irq_work.

IIUC the risk here is that the garbage collector is deferred and there
may not be skbs available. In that case, what do you expect to happen?
The printk record is dropped? Or the console disables itself from printk
flushing until some (hopefully) later time when skbs are ready and it
can enable itself, thus resuming the flush?

> 3. A try-once netpoll transmit, as Jakub outlined [2]:
>    - One HARD_TX_TRYLOCK, then busy, with no polling, freeing or
>      wakeups, which can deadlock under rq->lock[3].
>    - It refuses when this CPU owns the queue (netif_tx_owned()), is in
>      the device's NAPI poll (netpoll_owner_active()), or is in NMI on
>      PREEMPT_RT.

Same question. What happens when the trylock fails or it refuses?

As I have mentioned before [4], UART atomic printing uses the console
ownership to synchronize against _all_ port activity. What if the
_xmit_lock had console ownership underneath it (only for txq's shared
with a netconsole)? Then it would be enough to acquire console
ownership.

See, for example, include/linux/serial_core.h:uart_port_trylock().

> This does not make ndo_start_xmit() safe, so the flag stays until
> drivers can opt in to atomic transmit.

IIUC it makes it safe, but not reliable. It is more reliable than
kthreads, which can still be considered a win.

> It is still unclear to me whether write_atomic() should depend on the
> context (regular NMI/panic): 
>  * For regular NMI use the try lock as best effort

HARD_TX_TRYLOCK() is not NMI-safe.

>  * Ignore the locks only in the final panic flush. (unclear if this is
>    an option)

As a final unsafe flush before an infinite loop, this is always an
option.

John

> [1] https://lore.kernel.org/all/874ie4y5mw.fsf@jogness.linutronix.de/
> [2] https://lore.kernel.org/all/20260617132127.645534d1@kernel.org/
> [3] https://lore.kernel.org/all/20260610183621.3915271-1-vlad.wing@gmail.com/

[4] https://lore.kernel.org/all/87tsr1m6y5.fsf@jogness.linutronix.de/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 13:41 [RFC] netconsole: plan for a safe atomic write Breno Leitao
2026-11-16 15:52 ` John Ogness

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox