All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Xiaoming Ni <nixiaoming@huawei.com>
Cc: mingo@redhat.com, Will Deacon <will@kernel.org>,
	longman@redhat.com, boqun.feng@gmail.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	rjw@rjwysocki.net, lenb@kernel.org,
	Hanjun Guo <guohanjun@huawei.com>,
	"xiaoqian9@huawei.com" <xiaoqian9@huawei.com>,
	"wangle6@huawei.com" <wangle6@huawei.com>
Subject: Re: Question: Can I call down() in an atomic context?
Date: Fri, 6 Aug 2021 10:23:20 +0200	[thread overview]
Message-ID: <20210806082320.GD22037@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <6b5e1da8-4360-e9da-ad42-a5365fb853fa@huawei.com>

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

      reply	other threads:[~2021-08-06  8:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06  2:35 Question: Can I call down() in an atomic context? Xiaoming Ni
2021-08-06  8:23 ` Peter Zijlstra [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=20210806082320.GD22037@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=boqun.feng@gmail.com \
    --cc=guohanjun@huawei.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nixiaoming@huawei.com \
    --cc=rjw@rjwysocki.net \
    --cc=wangle6@huawei.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=xiaoqian9@huawei.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.