LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Question: Can I call down() in an atomic context?
@ 2021-08-06  2:35 Xiaoming Ni
  2021-08-06  8:23 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoming Ni @ 2021-08-06  2:35 UTC (permalink / raw)
  To: Peter Zijlstra, mingo, Will Deacon, longman, boqun.feng,
	Linux Kernel Mailing List, Matthew Wilcox, rjw, lenb, Hanjun Guo,
	xiaoqian9, wangle6

might_sleep() is called in kernel/locking/rwsem.c (API: 
down_read/down_write/...)
but not in kernel/locking/semaphore.c (API: down/down_timeout/..).
Was it designed so purposely, or was it missed by mistake?

After I added might_sleep() to kernel/locking/semaphore.c,
an alarm log was occasionally detected in my test environment:

	BUG: sleeping function called from invalid context at 
kernel/locking/semaphore.c:163
	in_atomic(): 1, irqs_disabled(): 128, pid: 0, name: swapper/8
	...
	Call trace:
	dump_backtrace+0x0/0x3c
	dump_backtrace+0x2c/0x3c
	show_stack+0x24/0x34
	dump_stack+0xb0/0xf0
	___might_sleep+0x130/0x144
	__might_sleep+0x78/0x88
	down_timeout+0x40/0xc8
	acpi_os_wait_semaphore+0x78/0xa0  drivers/acpi/osl.c#L1266
	acpi_ut_acquire_mutex+0x50/0xb4   drivers/acpi/acpica/utmutex.c#L241
	acpi_get_table+0x3c/0xc8          drivers/acpi/acpica/tbxface.c#L318
	acpi_find_last_cache_level+0x7c/0x140  drivers/acpi/pptt.c#L602
	_init_cache_level+0xd0/0xd8    arch/arm64/kernel/cacheinfo.c#L64
	flush_smp_call_function_queue+0x138/0x160   kernel/smp.c#L561
	generic_smp_call_function_single_interrupt+0x18/0x24
	handle_IPI+0x1d0/0x50c
	gic_handle_irq+0x13c/0x140
	el1_irq+0xcc/0x180
	arch_cpu_idle+0xc0/0x16c
	default_idle_call+0x34/0x38
	cpu_startup_entry+0x2b4/0x358
	secondary_start_kernel+0x1a8/0x1dc

Does this mean that it is necessary to add might_sleep in 
kernel/locking/semaphore.c?


Thanks
Xiaoming Ni

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

* Re: Question: Can I call down() in an atomic context?
  2021-08-06  2:35 Question: Can I call down() in an atomic context? Xiaoming Ni
@ 2021-08-06  8:23 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2021-08-06  8:23 UTC (permalink / raw)
  To: Xiaoming Ni
  Cc: mingo, Will Deacon, longman, boqun.feng,
	Linux Kernel Mailing List, Matthew Wilcox, rjw, lenb, Hanjun Guo,
	xiaoqian9, wangle6

On Fri, Aug 06, 2021 at 10:35:36AM +0800, Xiaoming Ni wrote:
> might_sleep() is called in kernel/locking/rwsem.c (API:
> down_read/down_write/...)
> but not in kernel/locking/semaphore.c (API: down/down_timeout/..).
> Was it designed so purposely, or was it missed by mistake?

Simply forgotten I suspect. The semaphore is definitely a sleeping lock.

> After I added might_sleep() to kernel/locking/semaphore.c,
> an alarm log was occasionally detected in my test environment:
> 
> 	BUG: sleeping function called from invalid context at
> kernel/locking/semaphore.c:163
> 	in_atomic(): 1, irqs_disabled(): 128, pid: 0, name: swapper/8
> 	...
> 	Call trace:
> 	dump_backtrace+0x0/0x3c
> 	dump_backtrace+0x2c/0x3c
> 	show_stack+0x24/0x34
> 	dump_stack+0xb0/0xf0
> 	___might_sleep+0x130/0x144
> 	__might_sleep+0x78/0x88
> 	down_timeout+0x40/0xc8
> 	acpi_os_wait_semaphore+0x78/0xa0  drivers/acpi/osl.c#L1266
> 	acpi_ut_acquire_mutex+0x50/0xb4   drivers/acpi/acpica/utmutex.c#L241
> 	acpi_get_table+0x3c/0xc8          drivers/acpi/acpica/tbxface.c#L318
> 	acpi_find_last_cache_level+0x7c/0x140  drivers/acpi/pptt.c#L602
> 	_init_cache_level+0xd0/0xd8    arch/arm64/kernel/cacheinfo.c#L64
> 	flush_smp_call_function_queue+0x138/0x160   kernel/smp.c#L561
> 	generic_smp_call_function_single_interrupt+0x18/0x24
> 	handle_IPI+0x1d0/0x50c
> 	gic_handle_irq+0x13c/0x140
> 	el1_irq+0xcc/0x180
> 	arch_cpu_idle+0xc0/0x16c
> 	default_idle_call+0x34/0x38
> 	cpu_startup_entry+0x2b4/0x358
> 	secondary_start_kernel+0x1a8/0x1dc
> 
> Does this mean that it is necessary to add might_sleep in
> kernel/locking/semaphore.c?

Necessary might be the wrong word, but yes, I think the whole down_*()
family (with exception of down_trylock() obvs) could do with a
might_sleep().

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

end of thread, other threads:[~2021-08-06  8:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06  2:35 Question: Can I call down() in an atomic context? Xiaoming Ni
2021-08-06  8:23 ` Peter Zijlstra

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).