Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2353211iob; Sat, 30 Apr 2022 06:25:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYXZBccgq4YZRW6d/9ukvSaWnCJztFXrXZTS1hVgUa+bY7sQMRklpgQunsIKlT+SmUczvR X-Received: by 2002:a62:33c2:0:b0:50d:a588:daab with SMTP id z185-20020a6233c2000000b0050da588daabmr3365876pfz.31.1651325100563; Sat, 30 Apr 2022 06:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651325100; cv=none; d=google.com; s=arc-20160816; b=hsOqAnfmPwUWoPay7La6XhPqYGS9MR1HKCS+u0VE+sLUZBkbhvzUrOP20kLf6CCb4o 7cBzXmVx7ZmpCnthu7fybTYfB73edmMB9/cBQGmGx3zmcWoMs7gPi4Km9a5fxcd6pulr A8QxczM+/ZTLFCmKjeOObirZM/qEZLUp2iqLpi82+Pwz7PySM0CnJishlCLYglKzuNPr JXuZYYd6nuo0ABGdhCQ0bai8rqbE9MRaOkZYSYyowf+y1+5IVZb5DKmSJAIwtXmtMwYk IgDHuWDeYaL/0aJYJvL7wBmG0z0CNfxaLgo8EBgj4iE/wmQrIzBtyAts8Wl40czNB3JY xFAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=5b8XJu4Hkha8rfhppOGOU6gxO/f5yOHoAHMRlkSburU=; b=M+5oMuWM/RxISjb4JOAeyPHa1nQRjLR8sBPME4BMbC6NM6imTbXGzHDl1I+8p9o3v3 Fhfgn5cvxBc8jkG5KF9ccs7d2cgoedR1P7AQkxG+hul/TAygjjn4Ezh1M3H0ktx0p1kT rG0cr99lzv0eVs0hYJs+tpxZ5U2VNyJc4BnrP3imQMnPB+VqgKy6Yvbag1ZUAbtSBIjT KQSa03LPsnDQQznKxIGX/Ae6U6VWpeORgKTS/WExv4awnLOkx3vYWcalR1A94D6eDgmA wDMN6C3TSLxIBp0A7nLpbJPlC/qXT1SPkERyH1RnLMUsTkcPUQQfsnmsdM6wPXsRB6cq x/Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OdudNfru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c30-20020a63725e000000b003ab5908dc1csi10868165pgn.22.2022.04.30.06.24.38; Sat, 30 Apr 2022 06:25:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OdudNfru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237845AbiD2VdT (ORCPT + 99 others); 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 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 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.