public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org,
	Zhenzhong Duan <zhenzhong.duan@oracle.com>,
	James Morse <james.morse@arm.com>, Borislav Petkov <bp@alien8.de>,
	SRINIVAS <srinivas.eeda@oracle.com>
Subject: Re: [PATCH] locking/qspinlock: Add bug check for exceeding MAX_NODES
Date: Wed, 16 Jan 2019 16:47:26 +0000	[thread overview]
Message-ID: <20190116164725.GC1910@brain-police> (raw)
In-Reply-To: <1547589344-11504-1-git-send-email-longman@redhat.com>

On Tue, Jan 15, 2019 at 04:55:44PM -0500, Waiman Long wrote:
> On some architectures, it is possible to have nested NMIs taking
> spinlocks nestedly. Even though the chance of having more than 4 nested
> spinlocks with contention is extremely small, there could still be a
> possibility that it may happen some days leading to system panic.
> 
> What we don't want is a silent corruption with system panic somewhere
> else. So add a BUG_ON() check to make sure that a system panic caused
> by this will show the correct root cause.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  kernel/locking/qspinlock.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
> index 8a8c3c2..f823221 100644
> --- a/kernel/locking/qspinlock.c
> +++ b/kernel/locking/qspinlock.c
> @@ -412,6 +412,16 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
>  	idx = node->count++;
>  	tail = encode_tail(smp_processor_id(), idx);
>  
> +	/*
> +	 * 4 nodes are allocated based on the assumption that there will
> +	 * not be nested NMIs taking spinlocks. That may not be true in
> +	 * some architectures even though the chance of needing more than
> +	 * 4 nodes will still be extremely unlikely. Adding a bug check
> +	 * here to make sure there won't be a silent corruption in case
> +	 * this condition happens.
> +	 */
> +	BUG_ON(idx >= MAX_NODES);
> +

Hmm, I really don't like the idea of putting a BUG_ON() on the spin_lock()
path. I'd prefer it if (a) we didn't add extra conditional code for the
common case and (b) didn't bring down the machine. Could we emit a
lockdep-style splat, instead?

Will

  reply	other threads:[~2019-01-16 16:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 21:55 [PATCH] locking/qspinlock: Add bug check for exceeding MAX_NODES Waiman Long
2019-01-16 16:47 ` Will Deacon [this message]
2019-01-16 16:53   ` Waiman Long

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=20190116164725.GC1910@brain-police \
    --to=will.deacon@arm.com \
    --cc=bp@alien8.de \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=srinivas.eeda@oracle.com \
    --cc=zhenzhong.duan@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox