All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>, x86@kernel.org
Cc: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 2/2] genirq/matrix: WARN_ON_ONCE() when cm->allocated/m->total_allocated go negative
Date: Thu, 18 Mar 2021 08:58:55 +0100	[thread overview]
Message-ID: <87eegc7v0g.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <87eegdy0qh.fsf@nanos.tec.linutronix.de>

Thomas Gleixner <tglx@linutronix.de> writes:

> On Fri, Feb 19 2021 at 12:31, Vitaly Kuznetsov wrote:
>
>> When irq_matrix_assign()/irq_matrix_free() calls get unsynced, weird
>> effects are possible, e.g. when cm->allocated goes negative CPU hotplug
>> may get blocked. Add WARN_ON_ONCE() to simplify detecting such situations.
>>
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> ---
>>  kernel/irq/matrix.c | 11 +++++++++--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
>> index 651a4ad6d711..2438a4f9d726 100644
>> --- a/kernel/irq/matrix.c
>> +++ b/kernel/irq/matrix.c
>> @@ -189,7 +189,9 @@ void irq_matrix_assign_system(struct irq_matrix *m, unsigned int bit,
>>  	set_bit(bit, m->system_map);
>>  	if (replace) {
>>  		BUG_ON(!test_and_clear_bit(bit, cm->alloc_map));
>> +		WARN_ON_ONCE(!cm->allocated);
>>  		cm->allocated--;
>> +		WARN_ON_ONCE(!m->total_allocated);
>
> This hunk is not really useful. It already dies when the bit is not set
> in the alloc map.

This was to check for the hypothetical issue when then number of bits
set get out of sync with 'total_allocated' counter -- which is likely
impossible today but could maybe be useful as a future proof. In case
this seems to be too much I'm not against dropping it.

>
>>  		m->total_allocated--;
>>  	}
>>  	if (bit >= m->alloc_start && bit < m->alloc_end)
>> @@ -424,12 +426,17 @@ void irq_matrix_free(struct irq_matrix *m, unsigned int cpu,
>>  		return;
>>  
>>  	clear_bit(bit, cm->alloc_map);
>> +	WARN_ON_ONCE(!cm->allocated);
>>  	cm->allocated--;
>
> WARN and then decrement is not necessarily any better than just
> decrementing unconditionally. It's just more noisy.
>
> Why would you let the counter wrap into negative space if you already
> know it's 0?
>
> There is a way more useful way to handle this. In such a case the bit is
> NOT set in the alloc map. So:
>
>     if (!WARN_ON_ONCE(test_and_clear_bit(bit, cm->alloc_map)))
>     	   return;
>
> would have caught the problem at hand nicely and let the machine survive
> while just throwing warns and continuing is broken to begin with.

Thanks, I like the idea. I didn't do that probably because the problem
which triggered me to write these patches wasn't fatal, it was just
causing CPU0 offlining to fail.

>
> Thanks,
>
>         tglx
>

-- 
Vitaly


  reply	other threads:[~2021-03-18  7:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-19 11:30 [PATCH RFC 0/2] x86/apic: Avoid cm->allocated going negative in irq_matrix Vitaly Kuznetsov
2021-02-19 11:31 ` [PATCH RFC 1/2] x86/apic: Do not make an exception for PIC_CASCADE_IR when marking legacy irqs " Vitaly Kuznetsov
2021-03-17 20:14   ` Thomas Gleixner
2021-03-17 21:18     ` Thomas Gleixner
2021-03-17 21:40       ` Thomas Gleixner
2021-03-17 22:52         ` Thomas Gleixner
2021-03-18  8:47           ` Vitaly Kuznetsov
2021-03-18  8:29     ` Vitaly Kuznetsov
2021-03-18 10:10       ` Thomas Gleixner
2021-02-19 11:31 ` [PATCH RFC 2/2] genirq/matrix: WARN_ON_ONCE() when cm->allocated/m->total_allocated go negative Vitaly Kuznetsov
2021-03-17 20:38   ` Thomas Gleixner
2021-03-18  7:58     ` Vitaly Kuznetsov [this message]
2021-03-18 19:29       ` Thomas Gleixner
2021-03-19  9:59         ` Vitaly Kuznetsov
2021-03-11 10:19 ` [PATCH RFC 0/2] x86/apic: Avoid cm->allocated going negative in irq_matrix Vitaly Kuznetsov

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=87eegc7v0g.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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.