Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp56433lfv; Tue, 12 Apr 2022 17:07:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/x/dh8TC5oikN1q+09dSxA85sLkxiRdoFxnO494eJBk3yjTjBV1cYqgSwmSEWIhiSp0/n X-Received: by 2002:a17:902:e889:b0:151:a56d:eb8f with SMTP id w9-20020a170902e88900b00151a56deb8fmr38865221plg.142.1649808435995; Tue, 12 Apr 2022 17:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649808435; cv=none; d=google.com; s=arc-20160816; b=hQNdpCPeESBB14rNRlHlzP8Cw/lFCMaUIyI6lW2vXh5NDzpxfeNOEol4s5hWO/jyUw Tgg54n6rDqOZe+F5/rpUtLo4M3sBZrg8Knze705zBfIer8btMCOJz5IWXIctXrs+E++Z NeRzZ3juyGIIpmArx+CLCognTF65Q7lxbaJmB+15Zd1z65qztQkHInSL8NoYjIA5803s UFsgjNTSOABPI/a7d6AKaolDkCrqQIbKGwViZYchXIuFQMOQ4wW6W9dsgjKWHsrdY0Wr tqikxaU9vhZVEEWS9d227rqeUSPLf0kgJ74lGO4tbG1FQtcV70kr6vE4q47/Ouby18ON TZOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=hndER118dmw7kYMFXyYuvsxJ9ycP9/DqyDamURXJ4cA=; b=Gm3yYaNtEzRHfi2CCE3UZR4+ZBboUA3QQYP302ARZM/Hs8RXc2reSrP5ICul03Ba6s QFzdB3Vgwgx01azczz3Tl4An9yevQUfE3WhJ2UWVXm7UiR6s21k8TMNkyPWaow2up64Z OM4tiQupagLDlEz1E925sNiIGaBVR3gdfw6+49Vx6WObOEtQ5BzHxZGjJWPPemoC8LnC g0ltMyEkKsYvEVvrcMiBfOkodMuuYlt/ZXb/dMXpiUe6zkSaYG7dwyrC6m9hpSAxihoZ 36zDfsp8/J2iUS9ZugOgT0+7EgrMEVPlhA99YXozPmhrns88d3ADLq42Yk6VSKxn+OBQ nU2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="AmRwcY/L"; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o19-20020a17090ac71300b001cb95c53172si7047329pjt.78.2022.04.12.17.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 17:07:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="AmRwcY/L"; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 285181563FF; Tue, 12 Apr 2022 15:04:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbiDLU5V (ORCPT + 99 others); Tue, 12 Apr 2022 16:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbiDLU5U (ORCPT ); Tue, 12 Apr 2022 16:57:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86DB0C9B41 for ; Tue, 12 Apr 2022 13:52:25 -0700 (PDT) Message-ID: <20220412204353.712177025@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649796708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=hndER118dmw7kYMFXyYuvsxJ9ycP9/DqyDamURXJ4cA=; b=AmRwcY/LhGb9vNhP+WyUubPJbFc+2etjHtIp065eY+h3wqeHg6fkEeELkQDzX6b8Gwryoe Iqmxq2EcM6m4fWPmRGDklO0XngB85nyLrEQNvuVhR8IyuiKGroEaUO0oDaYSfUpIkQqoaD G3zdaN69kbndjLQgIT7cfKZUj3JOaw95laXDMqttXE5sRBoiSam80uq0KbSURbjqYbMZcq 9ZSvI1ufcF3vOSEhpXUpnUWCRdCSZZ7rSWshUSn8OTyupuY4gLz+xXjJt/SFV1OENIR2cT xdopFgHYmq3GpawN5imMJD1pbEtE/jyndrweg1cclKmRz8tmdcgt3wkRVP7mGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649796708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=hndER118dmw7kYMFXyYuvsxJ9ycP9/DqyDamURXJ4cA=; b=RKZPDyIMtrgo2N2+DgcPZfB7tgeC4aJOd42vo0AKwK+Ehwfs2V4TgjDl9RWxJChp5NVyFN /nm4BKohR+tNKjBw== From: Thomas Gleixner To: LKML Cc: Christoph Hellwig , Peter Zijlstra , Sebastian Andrzej Siewior Subject: [patch V4 2/2] smp: Make softirq handling RT safe in flush_smp_call_function_queue() References: <20220412203649.956258017@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 12 Apr 2022 22:51:48 +0200 (CEST) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Andrzej Siewior flush_smp_call_function_queue() invokes do_softirq() which is not available on PREEMPT_RT. flush_smp_call_function_queue() is invoked from the idle task and the migration task with preemption or interrupts disabled. So RT kernels cannot process soft interrupts in that context as that has to acquire 'sleeping spinlocks' which is not possible with preemption or interrupts disabled and forbidden from the idle task anyway. The currently known SMP function call which raises a soft interrupt is in the block layer, but this functionality is not enabled on RT kernels due to latency and performance reasons. RT could wake up ksoftirqd unconditionally, but this wants to be avoided if there were soft interrupts pending already when this is invoked in the context of the migration task. The migration task might have preempted a threaded interrupt handler which raised a soft interrupt, but did not reach the local_bh_enable() to process it. The "running" ksoftirqd might prevent the handling in the interrupt thread context which is causing latency issues. Add a new function which handles this case explicitely for RT and falls back to do_softirq() on !RT kernels. In the RT case this warns when one of the flushed SMP function calls raised a soft interrupt so this can be investigated. [ tglx: Moved the RT part out of SMP code ] Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/YgKgL6aPj8aBES6G@linutronix.de --- v4: - Move the RT logic into softirq.c which also avoids the wakeup when softinterrupts are disabled. The enable will handle them anyway. v3: - Only wake ksoftirqd if the softirqs were raised wthin flush_smp_call_function_queue(). - Add a warning in the wake case. v2: Drop an empty line. include/linux/interrupt.h | 9 +++++++++ kernel/smp.c | 5 ++++- kernel/softirq.c | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) --- --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -607,6 +607,15 @@ struct softirq_action asmlinkage void do_softirq(void); asmlinkage void __do_softirq(void); +#ifdef CONFIG_PREEMPT_RT +extern void do_softirq_post_smp_call_flush(unsigned int was_pending); +#else +static inline void do_softirq_post_smp_call_flush(unsigned int unused) +{ + do_softirq(); +} +#endif + extern void open_softirq(int nr, void (*action)(struct softirq_action *)); extern void softirq_init(void); extern void __raise_softirq_irqoff(unsigned int nr); --- a/kernel/smp.c +++ b/kernel/smp.c @@ -696,6 +696,7 @@ static void __flush_smp_call_function_qu */ void flush_smp_call_function_queue(void) { + unsigned int was_pending; unsigned long flags; if (llist_empty(this_cpu_ptr(&call_single_queue))) @@ -704,9 +705,11 @@ void flush_smp_call_function_queue(void) cfd_seq_store(this_cpu_ptr(&cfd_seq_local)->idle, CFD_SEQ_NOCPU, smp_processor_id(), CFD_SEQ_IDLE); local_irq_save(flags); + /* Get the already pending soft interrupts for RT enabled kernels */ + was_pending = local_softirq_pending(); __flush_smp_call_function_queue(true); if (local_softirq_pending()) - do_softirq(); + do_softirq_post_smp_call_flush(was_pending); local_irq_restore(flags); } --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -294,6 +294,19 @@ static inline void invoke_softirq(void) wakeup_softirqd(); } +/* + * flush_smp_call_function_queue() can raise a soft interrupt in a function + * call. On RT kernels this is undesired and the only known functionality + * in the block layer which does this is disabled on RT. If soft interrupts + * get raised which haven't been raised before the flush, warn so it can be + * investigated. + */ +void softirq_post_smp_call_flush(unsigned int was_pending) +{ + if (WARN_ON_ONCE(was_pending != local_softirq_pending())) + invoke_softirq(); +} + #else /* CONFIG_PREEMPT_RT */ /*