From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0EA8C433F5 for ; Fri, 29 Apr 2022 21:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237865AbiD2VdT (ORCPT ); Fri, 29 Apr 2022 17:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbiD2VdR (ORCPT ); Fri, 29 Apr 2022 17:33:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD8A9F39C; Fri, 29 Apr 2022 14:29:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 704A36229E; Fri, 29 Apr 2022 21:29:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5137C385A7; Fri, 29 Apr 2022 21:29:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651267797; bh=EuQ+Tnjjj+1/zdg5oEaPiwrIStLtZ5qMD9wOSYLHeyg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OdudNfruDa6O3Jvs0g45BNiB2bs+O3p65nKmMIPAWsviqPhxjzOpNLD8GHfVnsC2u tSGfz9momnEHOq2KWdJatcMSblOQe6YUegtiOxvJU+VjEAp7z5zlgHu7JPrFdSl+iy blqoOR+sJ/ffLDl/ZNqP9Vfm1IxpXOrKcrH3k58pvsG+/t6dR2HzYeA/f2qBpZvi9c R5dGwXLnoe0YNCzQHnCH2xKG6Az11aitfhdDfVO+s5JTVz9aGlfPaylPWyxQNvxRKP j3knDg8FZxV0MNCI2Ory5rlmzpmxPjSIGDi7YSVwqfxDzHD1eKLfiH8lk0+MINkkhk /g6SEQkONBsww== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nkYBX-0082bx-4t; Fri, 29 Apr 2022 22:29:55 +0100 Date: Fri, 29 Apr 2022 22:29:54 +0100 Message-ID: <87levn8tnx.wl-maz@kernel.org> From: Marc Zyngier To: Thomas Gleixner Cc: Thomas Pfaff , linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Hillf Danton Subject: Re: [PATCH v2] irq/core: synchronize irq_thread startup In-Reply-To: <87fslvoez3.ffs@tglx> References: <1e3f96b7-9294-1534-e83b-efe3602f876f@pcs.com> <87sfpv98j0.wl-maz@kernel.org> <87fslvoez3.ffs@tglx> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: tglx@linutronix.de, tpfaff@pcs.com, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, hdanton@sina.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 29 Apr 2022 20:40:32 +0100, Thomas Gleixner wrote: > > On Fri, Apr 29 2022 at 17:08, Marc Zyngier wrote: > > On Fri, 29 Apr 2022 12:52:48 +0100, > > Thomas Pfaff wrote: > > > +static void wait_for_irq_thread_startup(struct irq_desc *desc, > > + struct irqaction *action) > > and this would be wait_for_irq_thread_ready(). > > which is sill a misnomer as this actually wakes and waits. Hey, I didn't say I picked the right color for that shed! ;-) > > >> @@ -1522,6 +1548,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) > >> } > >> } > >> > >> + init_waitqueue_head(&desc->wait_for_threads); > >> + > > > > I'm trying to convince myself that this one is safe. > > > > It was so far only done when registering the first handler of a > > threaded interrupt, while it is now done on every call to > > __setup_irq(). However, this is now done outside of the protection of > > any of the locks, meaning that a concurrent __setup_irq() for a shared > > interrupt can now barge in and corrupt the wait queue. > > > > So I don't think this is right. You may be able to hoist the > > request_lock up, but I haven't checked what could break, if anything. > > It can't be moved here, but I can see why Thomas wants to move it. With > a spurious wakeup of the irq thread (should not happen), the thread > would try to invoke wake_up() on a non initialize wait queue head. > > Something like this should do the trick. > > diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c > index 939d21cd55c3..0099b87dd853 100644 > --- a/kernel/irq/irqdesc.c > +++ b/kernel/irq/irqdesc.c > @@ -407,6 +407,7 @@ static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags, > lockdep_set_class(&desc->lock, &irq_desc_lock_class); > mutex_init(&desc->request_mutex); > init_rcu_head(&desc->rcu); > + init_waitqueue_head(&desc->wait_for_threads); > > desc_set_defaults(irq, desc, node, affinity, owner); > irqd_set(&desc->irq_data, flags); > @@ -575,6 +576,7 @@ int __init early_irq_init(void) > raw_spin_lock_init(&desc[i].lock); > lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); > mutex_init(&desc[i].request_mutex); > + init_waitqueue_head(&desc[i].wait_for_threads); > desc_set_defaults(i, &desc[i], node, NULL, NULL); > } > return arch_early_irq_init(); > diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c > index c03f71d5ec10..6a0942f4d068 100644 > --- a/kernel/irq/manage.c > +++ b/kernel/irq/manage.c > @@ -1683,8 +1683,6 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) > } > > if (!shared) { > - init_waitqueue_head(&desc->wait_for_threads); > - > /* Setup the type (level, edge polarity) if configured: */ > if (new->flags & IRQF_TRIGGER_MASK) { > ret = __irq_set_trigger(desc, > Indeed, it makes a lot of sense to fully initialise the irqdesc structure at the point of allocation, rather than later. Thanks, M. -- Without deviation from the norm, progress is not possible.