Re: [PATCH printk v2 09/11] panic: Add atomic write enforcement to oops

From: Andy Shevchenko
Date: Wed Sep 20 2023 - 09:28:52 EST


On Wed, Sep 20, 2023 at 01:14:54AM +0206, John Ogness wrote:
> Invoke the atomic write enforcement functions for oops to
> ensure that the information gets out to the consoles.
>
> Since there is no single general function that calls both
> oops_enter() and oops_exit(), the nesting feature of atomic
> write sections is taken advantage of in order to guarantee
> full coverage between the first oops_enter() and the last
> oops_exit().
>
> It is important to note that if there are any legacy consoles
> registered, they will be attempting to directly print from the
> printk-caller context, which may jeopardize the reliability of
> the atomic consoles. Optimally there should be no legacy
> consoles registered.

...

> + if (atomic_read(&oops_cpu) == smp_processor_id()) {
> + oops_nesting--;
> + if (oops_nesting == 0) {
> + atomic_set(&oops_cpu, -1);

Between read and set the variable can change, can't it?
If not, why this variable is atomic then? Or, why it's not a problem?
If the latter is the case, perhaps a comment to explain this?

> + /* Exit outmost atomic section. */
> + nbcon_atomic_exit(NBCON_PRIO_EMERGENCY, oops_prev_prio);
> + }
> + }
> + put_cpu();

--
With Best Regards,
Andy Shevchenko