From: Jiri Slaby <jirislaby@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>, Yury Norov <yury.norov@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH] irq: simplify irq_im_handle_irq()
Date: Thu, 31 Jul 2025 10:02:48 +0200 [thread overview]
Message-ID: <38a023cd-4e67-418f-bc27-e272c5484671@kernel.org> (raw)
In-Reply-To: <87o6tdtupb.ffs@tglx>
Hi,
On 21. 07. 25, 17:44, Thomas Gleixner wrote:
> On Mon, Jul 21 2025 at 10:27, Yury Norov wrote:
>> On Mon, Jul 21, 2025 at 04:07:22PM +0200, Thomas Gleixner wrote:
>> find_next_bit() and for_each_bit() cannot be used in concurrent
>> environment, and having atomic clear_bit() is meaningless here.
>> Two concurrent processes, if running in parallel, may pick the
>> same offset, ending up executing the handle_simple_irq() twice.
>
> The irq work cannot be run in parallel on multiple CPUs. It's guaranteed
> that only one irq work handler runs at a time. So irq_sim_handle_irq()
> is fully serialized by the irq work magic.
>
> But the bitmap can be modified concurrently, which is not a problem.
Actually, it is (IMO):
while (!bitmap_empty(work_ctx->pending, work_ctx->irq_count)) {
offset = find_next_bit(work_ctx->pending,
work_ctx->irq_count, offset);
clear_bit(offset, work_ctx->pending);
irqnum = irq_find_mapping(work_ctx->domain, offset);
handle_simple_irq(irq_to_desc(irqnum));
}
If another CPU sets a bit X in the beginning of the work_ctx->pending
bitmap while this is running for some time already (that means offset is
already greater that that X), bitmap_empty() will be always true and
this spins forever (or crashes). It is because find_next_bit() will
never return that bit X -- so clear_bit() will never happen on that.
What is worse, find_next_bit() will return work_ctx->irq_count and both
clear_bit() and irq_find_mapping() will touch an OOB memory.
Or what am I missing?
find_next_bit_wrap() would cure that.
thanks,
--
js
suse labs
next prev parent reply other threads:[~2025-07-31 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-19 21:18 [PATCH] irq: simplify irq_im_handle_irq() Yury Norov
2025-07-21 14:07 ` Thomas Gleixner
2025-07-21 14:27 ` Yury Norov
2025-07-21 15:44 ` Thomas Gleixner
2025-07-31 8:02 ` Jiri Slaby [this message]
2025-07-22 8:11 ` Jiri Slaby
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=38a023cd-4e67-418f-bc27-e272c5484671@kernel.org \
--to=jirislaby@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.