Re: lock in vsprintf(): was: Re: [PATCH] of: Add printf '%pOFm' for generating modalias

From: John Ogness
Date: Wed Dec 18 2024 - 09:07:44 EST


On 2024-12-18, Petr Mladek <pmladek@xxxxxxxx> wrote:
> My concern is taking a lock when processing a printf format, see
> below for more details.

Your concern is valid! printk() uses vsnprintf() to format records for
the kernel log. printk() may be called from contexts where locking is
forbidden (such as NMI). If vsnprintf() can take a lock, then either:

vsnprintf() must be made to be lockless

or

printk() must take another approach to string formatting

or

we accept that printk() can deadlock for certain format types in certain
contexts.

John Ogness