mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* A question of sleeping with interrupts are disabled in start_kernel()
@ 2018-04-06  9:53 Jia-Ju Bai
  2018-04-06 10:27 ` Thomas Gleixner
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2018-04-06  9:53 UTC (permalink / raw)
  To: akpm, tglx, mingo, keescook, lauraa, viresh.kumar, nicolas.pitre,
	thomas.lendacky
  Cc: Linux Kernel Mailing List

Hello,

I have a question of the call path init/main.c:
init/main.c: start_kernel() ->
kernel/events/core.c: perf_pmu_register() ->
kernel/events/core.c: perf_event_init() ->
kernel/events/core.c: pmu_dev_alloc()

In this call path, start_kernel() calls local_irq_disable() to disable 
the interrupt;
perf_pmu_register() calls mutex_lock() and idr_alloc(GFP_KERNEL), and 
they can sleep;
pmu_dev_alloc() calls kzalloc(GFP_KERNEL), and it can sleep.

In my opinion, this code may sleep with interrupts are disabled.
I wonder why this code is okay?


Best wishes,
Jia-Ju Bai

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

* Re: A question of sleeping with interrupts are disabled in start_kernel()
  2018-04-06  9:53 A question of sleeping with interrupts are disabled in start_kernel() Jia-Ju Bai
@ 2018-04-06 10:27 ` Thomas Gleixner
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2018-04-06 10:27 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: akpm, mingo, keescook, lauraa, viresh.kumar, nicolas.pitre,
	thomas.lendacky, Linux Kernel Mailing List

On Fri, 6 Apr 2018, Jia-Ju Bai wrote:

> Hello,
> 
> I have a question of the call path init/main.c:
> init/main.c: start_kernel() ->
> kernel/events/core.c: perf_pmu_register() ->
> kernel/events/core.c: perf_event_init() ->
> kernel/events/core.c: pmu_dev_alloc()
> 
> In this call path, start_kernel() calls local_irq_disable() to disable the
> interrupt;
> perf_pmu_register() calls mutex_lock() and idr_alloc(GFP_KERNEL), and they can
> sleep;
> pmu_dev_alloc() calls kzalloc(GFP_KERNEL), and it can sleep.
> 
> In my opinion, this code may sleep with interrupts are disabled.
> I wonder why this code is okay?

Because this is the very early boot up stage where contention of the mutex
cannot happen and the allocations are all implicitely converted to atomic
allocations. If the mutex would be contended then the system would fail to
boot anyway. If the allocations fail at that stage, it's unlikely that the
machine will come up at all.

So yes, it looks odd, but we don't want to have duplicated code pathes just
for the early boot up and the debugging mechanisms are aware of that
situation and don't emit warnings. Once the scheduler is functional and the
early boot stage is done, these 'magic' violations are not longer allowed.

Hope that helps.

Thanks,

	tglx

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

end of thread, other threads:[~2018-04-06 10:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06  9:53 A question of sleeping with interrupts are disabled in start_kernel() Jia-Ju Bai
2018-04-06 10:27 ` Thomas Gleixner

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

all inboxes | Powered by JetHome®