From: Thomas Gleixner <tglx@linutronix.de>
To: Manfred Spraul <manfred@colorfullife.com>,
"Sverdlin, Alexander" <alexander.sverdlin@siemens.com>,
"corbet@lwn.net" <corbet@lwn.net>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
1vier1@web.de
Subject: Re: Invalid locking pattern in Documentation/kernel-hacking/locking.rst?
Date: Mon, 12 Dec 2022 15:43:44 +0100 [thread overview]
Message-ID: <87k02wbs2n.ffs@tglx> (raw)
In-Reply-To: <be5a4c10-3b69-1c2d-d413-62f79ccc178b@colorfullife.com>
On Fri, Dec 09 2022 at 19:47, Manfred Spraul wrote:
> On 12/9/22 13:23, Sverdlin, Alexander wrote:
>> the latest version of locking.rst contains the following (since 2005):
>>
>> "Manfred Spraul points out that you can still do this, even if the data
>> is very occasionally accessed in user context or softirqs/tasklets. The
>> irq handler doesn't use a lock, and all other accesses are done as so::
>>
>> spin_lock(&lock);
>> disable_irq(irq);
>> "
>>
>> Isn't it "sleeping in atomic" actually because of the sleeping
>> disable_irq()?
>
> Good catch!
>
> The documentation of disable_irq() claims that the function is safe to
> be called from IRQ context (for careful callers)
>
> But it calls synchronize_irq(). And synchronize_irq() claims that the
> function can be called only from preemptible code.
>
> The change was in 2009:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.1-rc8&id=3aa551c9b4c40018f0e261a178e3d25478dc04a9
>
>
> @Thomas/@Ingo: What do we want?
>
> Declare disable_irq()&synchronize_irq() as safe from irq context only if
> no threaded irq handlers are used?
>
> Or declare both function as preemptible context only?
The latter.
The comment for disable_irq() needs to go away too:
"This function may be called - with care - from IRQ context."
Obviously it can't be called from the interrupt context which it
tries to disable as it will live-lock on the "in progress" flag.
So that leaves the option to call it from some unrelated interrupt
context which does not make much sense. In fact, back in the days when
this comment was added it was still allowed to reenable interrupts in
the interrupt handler, which obviously opens the window for some other
interrupt to come in which then tries to disable the one it just
interrupted. Not an issue anymore, but the synchronize_irq() change to
handle threaded interrupts made it more or less impossible.
Thanks,
tglx
prev parent reply other threads:[~2022-12-12 14:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 12:23 Invalid locking pattern in Documentation/kernel-hacking/locking.rst? Sverdlin, Alexander
2022-12-09 18:47 ` Manfred Spraul
2022-12-12 14:43 ` Thomas Gleixner [this message]
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=87k02wbs2n.ffs@tglx \
--to=tglx@linutronix.de \
--cc=1vier1@web.de \
--cc=alexander.sverdlin@siemens.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=mingo@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).