Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2913867ybh; Sat, 25 Jul 2020 05:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPcZ1YfcNISLpwFYUH5aeoc9kAswtALUTHXyJARW56w4naCHyaJ+6lQes0oIfi6EtJ9ldA X-Received: by 2002:a17:906:a1c7:: with SMTP id bx7mr12997125ejb.388.1595680311957; Sat, 25 Jul 2020 05:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595680311; cv=none; d=google.com; s=arc-20160816; b=pTaZ6eg+waYSTBMS60uZolYM5BxRbbCWMgDAy7eQYIT9wxDlBvSPX9F/Hq7X1no0fA +8Z7sctjb8NSHDdINoE6bC+6Y2W5mP5ZZc9YcCGbYSblISEzyBtM06vEN90OTNQb/gjZ OAW5n6ujERUnwTLgAMEjMSIbihm0SAaphLlg/t0BaDl6marv1RmZIVSO/u8HFtFRtS/T V+zjrSZNBQhIAADT4eaSh7/XczkPhdP1XPTgEPxglol6EgofECejdiQiAouzlkYmEumS sKKnKSxooLmC27dGQLV6eyGO4xarjQURuK/F8s9/PYQ5FyFOfsMh0YoEPw2M8WaHTsqQ t+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date:dkim-signature; bh=s+AyumYHF7BNoKNTQrmedAajX7jbMA/NieRG/yUZaqw=; b=Tyg3k/8ang3tJOW5zDZCrXlw92lHQIhunl3oVTg464XAf5vR8kHXBXRjan3qqNQGBK 8Uq5BjzwrBBMnWoB7CJrAPaM+Ean+vMC4b5+qr22SBgC24SIDNl5klVjELVytI0/jdGn 2Z60GLXYuAa7m507sv2ngfFi5xI/6x1oap+OqEz4XdomytzyE7jrRQacAFUpfTKHaw74 rvCSqjq5UdgcWMv5WbDZsRmwVsWNfkndF5OszK2BS5mrVkRf5k0cQHCG0vZ2NLQoUbPr kB+BVmSk8zwizF2UIy1uXq9lAnH2Msgs5Fy/AN/PPZXgH3jUrOdkrAM3HvlWNjnkIlLo RUuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SHnGG6I1; 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 gw16si2432601ejb.274.2020.07.25.05.31.27; Sat, 25 Jul 2020 05:31:51 -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=SHnGG6I1; 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 S1726842AbgGYMa7 (ORCPT + 99 others); Sat, 25 Jul 2020 08:30:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:60900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726583AbgGYMa6 (ORCPT ); Sat, 25 Jul 2020 08:30:58 -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 D8D8F206F6; Sat, 25 Jul 2020 12:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595680258; bh=imlyu/Ml4OC0iSO9+nmsiZvgDg48e9RIRuNY+wui3tY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SHnGG6I1R0guhR23Dkh29ZnXEKtuvfGWzo3ukmJToa4XffLyKv7UpNr1d1IwLayCl SkAWPzkKNetGk/ZkGDl3K28pSPDxHLUcI02CMy6iGmWuSGYRdYduiOLHKzCEiNVocn 96fYsM3Jd9JVj1w1xwRZip8WI64riJCnvD3A32kg= 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 1jzJKK-00EqBY-5m; Sat, 25 Jul 2020 13:30:56 +0100 Date: Sat, 25 Jul 2020 13:30:55 +0100 Message-ID: <874kpvydxc.wl-maz@kernel.org> From: Marc Zyngier To: Thomas Gleixner Cc: John Keeping , LKML , x86@kernel.org, Ben Herrenschmidt , Ali Saidi , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH V2] genirq/affinity: Handle affinity setting on inactive interrupts correctly In-Reply-To: <87blk4tzgm.fsf@nanos.tec.linutronix.de> References: <87k0z2s2q3.fsf@nanos.tec.linutronix.de> <877dv2rv25.fsf@nanos.tec.linutronix.de> <20200724182422.27ddced6.john@metanate.com> <87h7twu1cp.fsf@nanos.tec.linutronix.de> <87blk4tzgm.fsf@nanos.tec.linutronix.de> 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: tglx@linutronix.de, john@metanate.com, linux-kernel@vger.kernel.org, x86@kernel.org, benh@amazon.com, alisaidi@amazon.com, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thomas, On Fri, 24 Jul 2020 21:44:41 +0100, Thomas Gleixner wrote: > > John, > > Thomas Gleixner writes: > > I have some ideas for a trivial generic way to solve this without > > undoing the commit in question and without going through all the irq > > chip drivers. So far everything I came up with is butt ugly. Maybe Marc > > has some brilliant idea. > > > > Sorry for the wreckage and thanks for the excellent problem > > description. I'll come back to you in the next days. > > couldn't give up :) > > So after staring in too many drivers, I resorted to make this mode > opt-in and mark the interrupts accordingly for the two drivers which are > known to want this. Not that I love it, but it's the least dangerous > option. Completely untested patch below. > > Thanks, > > tglx > --- > arch/x86/kernel/apic/vector.c | 4 ++++ > drivers/irqchip/irq-gic-v3-its.c | 5 ++++- > include/linux/irq.h | 13 +++++++++++++ > kernel/irq/manage.c | 6 +++++- > 4 files changed, 26 insertions(+), 2 deletions(-) > > --- a/arch/x86/kernel/apic/vector.c > +++ b/arch/x86/kernel/apic/vector.c > @@ -560,6 +560,10 @@ static int x86_vector_alloc_irqs(struct > * as that can corrupt the affinity move state. > */ > irqd_set_handle_enforce_irqctx(irqd); > + > + /* Don't invoke affinity setter on deactivated interrupts */ > + irqd_set_affinity_on_activate(irqd); > + > /* > * Legacy vectors are already assigned when the IOAPIC > * takes them over. They stay on the same vector. This is > --- a/drivers/irqchip/irq-gic-v3-its.c > +++ b/drivers/irqchip/irq-gic-v3-its.c > @@ -3523,6 +3523,7 @@ static int its_irq_domain_alloc(struct i > msi_alloc_info_t *info = args; > struct its_device *its_dev = info->scratchpad[0].ptr; > struct its_node *its = its_dev->its; > + struct irq_data *irqd; > irq_hw_number_t hwirq; > int err; > int i; > @@ -3542,7 +3543,9 @@ static int its_irq_domain_alloc(struct i > > irq_domain_set_hwirq_and_chip(domain, virq + i, > hwirq + i, &its_irq_chip, its_dev); > - irqd_set_single_target(irq_desc_get_irq_data(irq_to_desc(virq + i))); > + irqd = irq_get_irq_data(virq + i); > + irqd_set_single_target(irqd); > + irqd_set_affinity_on_activate(irqd); > pr_debug("ID:%d pID:%d vID:%d\n", > (int)(hwirq + i - its_dev->event_map.lpi_base), > (int)(hwirq + i), virq + i); > --- a/include/linux/irq.h > +++ b/include/linux/irq.h > @@ -213,6 +213,8 @@ struct irq_data { > * required > * IRQD_HANDLE_ENFORCE_IRQCTX - Enforce that handle_irq_*() is only invoked > * from actual interrupt context. > + * IRQD_AFFINITY_ON_ACTIVATE - Affinity is set on activation. Don't call > + * irq_chip::irq_set_affinity() when deactivated. > */ > enum { > IRQD_TRIGGER_MASK = 0xf, > @@ -237,6 +239,7 @@ enum { > IRQD_CAN_RESERVE = (1 << 26), > IRQD_MSI_NOMASK_QUIRK = (1 << 27), > IRQD_HANDLE_ENFORCE_IRQCTX = (1 << 28), > + IRQD_AFFINITY_ON_ACTIVATE = (1 << 29), > }; > > #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors) > @@ -421,6 +424,16 @@ static inline bool irqd_msi_nomask_quirk > return __irqd_to_state(d) & IRQD_MSI_NOMASK_QUIRK; > } > > +static inline void irqd_set_affinity_on_activate(struct irq_data *d) > +{ > + __irqd_to_state(d) |= IRQD_AFFINITY_ON_ACTIVATE; > +} > + > +static inline bool irqd_affinity_on_activate(struct irq_data *d) > +{ > + return __irqd_to_state(d) & IRQD_AFFINITY_ON_ACTIVATE; > +} > + > #undef __irqd_to_state > > static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d) > --- a/kernel/irq/manage.c > +++ b/kernel/irq/manage.c > @@ -320,12 +320,16 @@ static bool irq_set_affinity_deactivated > struct irq_desc *desc = irq_data_to_desc(data); > > /* > + * Handle irq chips which can handle affinity only in activated > + * state correctly > + * > * If the interrupt is not yet activated, just store the affinity > * mask and do not call the chip driver at all. On activation the > * driver has to make sure anyway that the interrupt is in a > * useable state so startup works. > */ > - if (!IS_ENABLED(CONFIG_IRQ_DOMAIN_HIERARCHY) || irqd_is_activated(data)) > + if (!IS_ENABLED(CONFIG_IRQ_DOMAIN_HIERARCHY) || > + irqd_is_activated(data) || !irqd_affinity_on_activate(data)) > return false; > > cpumask_copy(desc->irq_common_data.affinity, mask); > I have given this a go on two systems: one with a GICv2 that has its PMUs wired in a similar way to John's system (each CPU PMU is on a separate SPI), and another one that has an ITS. Both came up normally and their interrupts are routed as expected: * GICv2 PMU: 30: 121 0 0 0 0 0 0 0 GICv2 39 Level arm-pmu 31: 0 167 0 0 0 0 0 0 GICv2 40 Level arm-pmu 32: 0 0 145 0 0 0 0 0 GICv2 41 Level arm-pmu 33: 0 0 0 400 0 0 0 0 GICv2 42 Level arm-pmu 34: 0 0 0 0 97 0 0 0 GICv2 43 Level arm-pmu 35: 0 0 0 0 0 463 0 0 GICv2 44 Level arm-pmu 36: 0 0 0 0 0 0 74 0 GICv2 45 Level arm-pmu 37: 0 0 0 0 0 0 0 8 GICv2 46 Level arm-pmu * GICv3+ITS: 241: 219 0 0 0 0 0 ITS-MSI 524289 Edge nvme0q1 242: 0 251 0 0 0 0 ITS-MSI 524290 Edge nvme0q2 243: 0 0 197 0 0 0 ITS-MSI 524291 Edge nvme0q3 244: 0 0 0 380 0 0 ITS-MSI 524292 Edge nvme0q4 245: 0 0 0 0 675 0 ITS-MSI 524293 Edge nvme0q5 246: 0 0 0 0 0 436 ITS-MSI 524294 Edge nvme0q6 For a good measure, I've added this on top, adding the missing bits to the debugfs entries: diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c index 4f9f844074db..d44fc8a5dab2 100644 --- a/kernel/irq/debugfs.c +++ b/kernel/irq/debugfs.c @@ -120,6 +120,9 @@ static const struct irq_bit_descr irqdata_states[] = { BIT_MASK_DESCR(IRQD_WAKEUP_STATE), BIT_MASK_DESCR(IRQD_WAKEUP_ARMED), + BIT_MASK_DESCR(IRQD_DEFAULT_TRIGGER_SET), + BIT_MASK_DESCR(IRQD_HANDLE_ENFORCE_IRQCTX), + BIT_MASK_DESCR(IRQD_AFFINITY_ON_ACTIVATE), }; static const struct irq_bit_descr irqdesc_states[] = { FWIW: Acked-by: Marc Zyngier Tested-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.