Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2470252ybh; Fri, 24 Jul 2020 13:47:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu1HJ+ls66dnQwAiVRYqNatNdQVnoAjeoHqHBBbuLuPUImDR1q0+sBzxWGz3KKuDZdjLhN X-Received: by 2002:a17:906:33d1:: with SMTP id w17mr3579094eja.68.1595623654197; Fri, 24 Jul 2020 13:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595623654; cv=none; d=google.com; s=arc-20160816; b=qaslTEFMg+CYaDT2vncxi1KNRIDB4jAVoczMbPJvua7qKFW8P0CvVSP4awgrUQ0f/1 hRlIlwHBlJxsTE/zfXq1nOtZyGiycYIrkjl1rZatwf36FQZjxe1v+i/ZrtzL7nLfOIEU ff+/gTyNfIgiZ9g+7Sm5r4BjbiCnnMH87N4/+7tIjtfnn4RBhW3xMp/d2MO8QTZLxnd0 Gd2UeiAuRk2bAwllqH0bcFU+f+1Q3k3vxRCWct6ZVN6RWcSWltcZgUo3GD3Bb7Xzbcrh WqijToOK6jJsXRJ2kiQT+TzK7D29SbHHAqrJRSKAX1QgFRQRCfFMcX8KkOnvs+qaLVHT AU0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=KOMANSmPa59euwywHw4b4bqf0Bzh61n1kQhVI7hDeSA=; b=GHIMOeBYG9XsHBVrHQuAgPMVZ1a6kUtdO0LLij+P9h6VNfAChiJiIXCR2ZZg7y22kO /bKEGiKWLJSk3TNBg8o3ViBLhvpRZaaNz8u6u/VHJF8OMFqDReNNHlsO7RB4oL8cjmQX 2YZtjaPP99Nx05xabqG2qsoBIhK4uzS1YSHEBeg+fxm5/aGzDodfeiz0428Bsu25g5WR RLtdsQxfMI2Lx1rTDJkbaNnIOwGO16XO4/GsxaWck2FCkMqcEny5+dz2gz90n0ausiy+ XdT/k/dmzj+AlKhRql3EnJEyWV+bbhTeoyG9CjcZblOxiA4ReWEqakgEO/8nPDAeV9Za ueBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1BrCxU6N; dkim=neutral (no key) header.i=@vger.kernel.org; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si1151714edy.539.2020.07.24.13.47.11; Fri, 24 Jul 2020 13:47:34 -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=@linutronix.de header.s=2020 header.b=1BrCxU6N; dkim=neutral (no key) header.i=@vger.kernel.org; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbgGXUop (ORCPT + 99 others); Fri, 24 Jul 2020 16:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbgGXUop (ORCPT ); Fri, 24 Jul 2020 16:44:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AEC2C0619D3 for ; Fri, 24 Jul 2020 13:44:45 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595623481; 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: in-reply-to:in-reply-to:references:references; bh=KOMANSmPa59euwywHw4b4bqf0Bzh61n1kQhVI7hDeSA=; b=1BrCxU6NWMdI4yfFwZA9FTs3goe4aWu5PJssMkGJYJT2wtlYA32ziE7AGWc+XVIT3pDpMg WX1lYRr/FXWn2cdQ6Qy/F/Mwkd38BKmaAxYyvuJGuzddjQhCTP5F5EaCDL/E8K9lEbUM2n ppf/ankD5bliy6nXFHy2zfrL2r3MslF0jEbhE/4+LnrIn4hCDapw4yFX4DR/Bj9dNL5Gsh S+Csc9r9kqEiyH0/qOcqt/ZUEF3wuH4NnrwcsLPiX0YZfI88ksZ/bRdXkxShRfmCmJQPfn LUN3vOhTKzKgS1PxmvR0OOHfyznM4q83bHUuhmHVa604OFCAAbJP+mi8A8hDig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595623481; 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: in-reply-to:in-reply-to:references:references; bh=KOMANSmPa59euwywHw4b4bqf0Bzh61n1kQhVI7hDeSA=; b=nnvWU/rNA6MxWmxauQsnZAB5vvMR6mpsb4pdMy0Oc/fldCT3nwN2h8rqKDtE7IaQZ/7pz1 XKvb56pHs3qZ/vAg== To: John Keeping Cc: LKML , x86@kernel.org, Ben Herrenschmidt , Ali Saidi , Marc Zyngier , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH V2] genirq/affinity: Handle affinity setting on inactive interrupts correctly In-Reply-To: <87h7twu1cp.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> Date: Fri, 24 Jul 2020 22:44:41 +0200 Message-ID: <87blk4tzgm.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);