Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1083538pxk; Fri, 18 Sep 2020 03:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHKx02sDY8US2qV/1A2do+rbV3ILFTfhLpKGX3zt2Kha2nB0PTrt40i8/HfyPK3owOgjUI X-Received: by 2002:a17:907:110f:: with SMTP id qu15mr36745606ejb.359.1600424692347; Fri, 18 Sep 2020 03:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600424692; cv=none; d=google.com; s=arc-20160816; b=mqHOecWFD7nvTum0oZKW6bIgEO/6QHwiVs2ZmBAZes3DgBnWKlb+epSM2wCtGzwOS2 lPdBqyjbk9whpbjXfGxGTUeXCITSytBV23UQ4Wen0/676a26miA+vhQeRT7a51XcFzpV HjEraoTTO9+DzPemvewEGQPrYrh8ljNRCa8QYPkcK+Xv0l3vd1w/ouZIjhKJPPmtgugK ZBAfMszNiET4CLoHb881Xt1BXyepIjvtY4SXcx6x5u+MkqlSSc1AejwddpA8aC63R8jS bbI/8rZCMC6Zled7vjYaEVvNFWO89fjHc45uUkV5wxZUQTKt2912p03ujiBBtGmGQ0Hm Uc8g== 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=2RAmoTOGg7xfTEJ6gRSnr8CYP5B/7+XLsYAUNrEyrNw=; b=hKosoV8kLwKrwnYNIMN8wFmVWkmoKpDOIHe0lJ+i6kRXOFV2KbW7P6Pe8shUnFj0Tu YOtyUuv3jK8fKmt+R5q1wIpncTJhXh7MB4ukzJLPadTugsWSV9GbzhSPee0BVy+WSKFR 2U7yRL4JWN6byb+W5KToV4XuvzN14SbWGDVGxt1wBwmOBr0kDFzz2tal9HRG6tTi1OXr XPOS3OscIVXyDJsBXBW/tYlak972lXzAYMcH2D6Sq0aQNiyvSLRSD0G4+2l9F/rP8BAk 9gHMFohT2SvmM6mWZD4SjkezIbV77BMdY9xwfGcTMphSwrELD7jVKqt0bItwyu1sXn8j wUDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAKa1fFC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si1696850edy.150.2020.09.18.03.24.28; Fri, 18 Sep 2020 03:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HAKa1fFC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726412AbgIRKWE (ORCPT + 99 others); Fri, 18 Sep 2020 06:22:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:58110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726304AbgIRKWD (ORCPT ); Fri, 18 Sep 2020 06:22:03 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC3AD208DB; Fri, 18 Sep 2020 10:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600424523; bh=Uu+bmGTBgLjg7wVQ/owRSKt7ej5xLC0BHxLGBSXNJFk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HAKa1fFCgkk1s9z9BmartTRBp+oRtYqvpG2VuZDxgJlHF/XXDfCRqqX1wpxO5yHFE QvUvIETGi5Oy0/Al4sDSdP8Adq/A3qIDLQNhiIgRn7Lub+i5RxveP5yDGRXdabPUiW GWC1l5ha0cb3+SaBgg+qbjTbbawS9/cXoKVK/uCo= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kJDWj-00CxiS-0u; Fri, 18 Sep 2020 11:22:01 +0100 Date: Fri, 18 Sep 2020 11:21:59 +0100 Message-ID: <87h7rvqta0.wl-maz@kernel.org> From: Marc Zyngier To: James Morse Cc: jonathanh@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sumit Garg , kernel-team@android.com, Florian Fainelli , Russell King , Jason Cooper , Saravana Kannan , Andrew Lunn , Catalin Marinas , Gregory Clement , Thomas Gleixner , Will Deacon , Valentin Schneider Subject: Re: [PATCH v3 08/16] irqchip/gic: Configure SGIs as standard interrupts In-Reply-To: References: <20200901144324.1071694-1-maz@kernel.org> <20200901144324.1071694-9-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26.3 (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: 62.31.163.78 X-SA-Exim-Rcpt-To: james.morse@arm.com, jonathanh@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sumit.garg@linaro.org, kernel-team@android.com, f.fainelli@gmail.com, linux@arm.linux.org.uk, jason@lakedaemon.net, saravanak@google.com, andrew@lunn.ch, catalin.marinas@arm.com, gregory.clement@bootlin.com, tglx@linutronix.de, will@kernel.org, valentin.schneider@arm.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 Hi James, On Fri, 18 Sep 2020 10:58:45 +0100, James Morse wrote: > > Hi Marc, > > (CC: +Jon) > > On 01/09/2020 15:43, Marc Zyngier wrote: > > Change the way we deal with GIC SGIs by turning them into proper > > IRQs, and calling into the arch code to register the interrupt range > > instead of a callback. > > Your comment "This only works because we don't nest SGIs..." on this > thread tripped some bad memories from adding the irq-stack. Softirq > causes us to nest irqs, but only once. > > > (I've messed with the below diff to remove the added stuff:) > > > diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c > > index 4ffd62af888f..4be2b62f816f 100644 > > --- a/drivers/irqchip/irq-gic.c > > +++ b/drivers/irqchip/irq-gic.c > > @@ -335,31 +335,22 @@ static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) > > irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); > > irqnr = irqstat & GICC_IAR_INT_ID_MASK; > > > > - if (likely(irqnr > 15 && irqnr < 1020)) { > > - if (static_branch_likely(&supports_deactivate_key)) > > - writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); > > - isb(); > > - handle_domain_irq(gic->domain, irqnr, regs); > > - continue; > > - } > > - if (irqnr < 16) { > > writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); > > - if (static_branch_likely(&supports_deactivate_key)) > > - writel_relaxed(irqstat, cpu_base + GIC_CPU_DEACTIVATE); > > -#ifdef CONFIG_SMP > > - /* > > - * Ensure any shared data written by the CPU sending > > - * the IPI is read after we've read the ACK register > > - * on the GIC. > > - * > > - * Pairs with the write barrier in gic_raise_softirq > > - */ > > smp_rmb(); > > - handle_IPI(irqnr, regs); > > If I read this right, previously we would EOI the interrupt before > calling handle_IPI(). Where as now with the version of this series > in your tree, we stuff the to-be-EOId value in a percpu variable, > which is only safe if these don't nest. > > Hidden in irq_exit(), kernel/softirq.c::__irq_exit_rcu() has this: > | preempt_count_sub(HARDIRQ_OFFSET); > | if (!in_interrupt() && local_softirq_pending()) > | invoke_softirq(); > > The arch code doesn't raise the preempt counter by HARDIRQ, so once > __irq_exit_rcu() has dropped it, in_interrupt() returns false, and > we invoke_softirq(). > > invoke_softirq() -> __do_softirq() -> local_irq_enable()! > > Fortunately, __do_softirq() raises the softirq count first using > __local_bh_disable_ip(), which in-interrupt() checks too, so this > can only happen once per IRQ. > > Now the irq_exit() has moved from handle_IPI(), which ran after EOI, > into handle_domain_irq(), which runs before. I think its possible > SGIs nest, and the new percpu variable becomes corrupted. I can't see how. The interrupt is active until we EOI/deactivate it, and thus cannot be observed again by the CPU interface until this happens. Furthermore, irq_exit() in __handle_domain_irq() is *after* the EOI anyway (generic_handle_irq_() directly calls the flow, which immediately EOIs the interrupt). The only material change is that irq_enter() happens before EOI. Is that what you are referring to? Thanks, M. -- Without deviation from the norm, progress is not possible.