Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3169223pxb; Mon, 25 Jan 2021 08:40:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0MXTn7AlLm2ooseb/d8X7a7+k0a6cS0eYXO/4GkAU7Sc1Us7nPT5R6/nXsHUResnh29Y+ X-Received: by 2002:a50:998f:: with SMTP id m15mr1204481edb.342.1611592845402; Mon, 25 Jan 2021 08:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611592845; cv=none; d=google.com; s=arc-20160816; b=aWCUkA1kHOCnBWQ4TVARZaiV5JCWYoQHkk+XAnbEVPZ063w1Y3fHgVXe+doksZPTWA +9n27Hx4I8S5ot3rzIWPP98hgUBuLiwyK3wXO17sQHlJuS4clQqh9c/gpq3nDXVGcfBL P4hLKuubfD/XMgzXqBOVsaRGvTyZf7fGUohiR5jNGhzOUTVBnWLRZGDg4HKJuLkIM3Uo sYkIGx6Hj9HT+xPox5TBt44uapSxsNS6JQWSyxLXcjDUtr+CHj0nuVibLdRRy2tjEzEe KjKb4QqLuo3SG6XyDZgUzeVT+8oBWOjabqe9vtjLqny7ytD+9H7a47x6owVR/Zb/gTuC QpgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=p5cFtT50IM5TQ47HESDxn/bIHqLg4nnuUzyr//XBrBI=; b=g4JGu3mx3BSMjg9kNVtwqUPVPa4bn9OxrjCDtuU5j+di1d8SlW0QpawQn+7H/CJ1sC qaVHYHezDQIVAXdKiXcIVL1LDN7aMVSW5HU0g6N0oaKwvHCbh2nDq5rttz66FVXSBPB8 K9zHr5sSaEP+6pumByxHcDnSCovlJ5Z3pb9j0rN0tzClvza0DFFP9fdl8RUETk9irAVu VlYCbhTqqa8rU92l9Q3/Zq/TPb+1E5KsQ1uKLvWDg+UXpvAG+cI1OWeOHyHOEXpM03Ae OyASyPFZaIUw/yFufiIvaA96ZZoXiJZ5Xs+fFm4EzXHHlhnWUFjRzylzLzGn7h31NeuP sooQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs42si6098285ejc.136.2021.01.25.08.40.09; Mon, 25 Jan 2021 08:40:45 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730672AbhAYQhF convert rfc822-to-8bit (ORCPT + 99 others); Mon, 25 Jan 2021 11:37:05 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2418 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbhAYQgB (ORCPT ); Mon, 25 Jan 2021 11:36:01 -0500 Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4DPXRy11h7z67gWC; Mon, 25 Jan 2021 22:34:06 +0800 (CST) Received: from lhreml716-chm.china.huawei.com (10.201.108.67) by fraeml707-chm.china.huawei.com (10.206.15.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 25 Jan 2021 15:39:52 +0100 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml716-chm.china.huawei.com (10.201.108.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 25 Jan 2021 14:39:51 +0000 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2106.006; Mon, 25 Jan 2021 14:39:51 +0000 From: Shameerali Kolothum Thodi To: Marc Zyngier , "linux-kernel@vger.kernel.org" CC: Thomas Gleixner , Bjorn Helgaas , "stable@vger.kernel.org" Subject: RE: [PATCH] genirq/msi: Activate Multi-MSI early when MSI_FLAG_ACTIVATE_EARLY is set Thread-Topic: [PATCH] genirq/msi: Activate Multi-MSI early when MSI_FLAG_ACTIVATE_EARLY is set Thread-Index: AQHW8YM/ALz6HSUk/kKcnCo0G2LmYqo4alSg Date: Mon, 25 Jan 2021 14:39:51 +0000 Message-ID: <19ddad1517f0495d92c2248d04cf0d5c@huawei.com> References: <20210123122759.1781359-1-maz@kernel.org> In-Reply-To: <20210123122759.1781359-1-maz@kernel.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.47.92.195] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Marc Zyngier [mailto:maz@kernel.org] > Sent: 23 January 2021 12:28 > To: linux-kernel@vger.kernel.org > Cc: Thomas Gleixner ; Bjorn Helgaas > ; Shameerali Kolothum Thodi > ; stable@vger.kernel.org > Subject: [PATCH] genirq/msi: Activate Multi-MSI early when > MSI_FLAG_ACTIVATE_EARLY is set > > When MSI_FLAG_ACTIVATE_EARLY is set (which is the case for PCI), > we perform the activation of the interrupt (which in the case of > PCI results in the endpoint being programmed) as soon as the > interrupt is allocated. > > But it appears that this is only done for the first vector, > introducing an inconsistent behaviour for PCI Multi-MSI. > > Fix it by iterating over the number of vectors allocated to > each MSI descriptor. This is easily achieved by introducing > a new "for_each_msi_vector" iterator, together with a tiny > bit of refactoring. > > Fixes: f3b0946d629c ("genirq/msi: Make sure PCI MSIs are activated early") > Reported-by: Shameer Kolothum > Signed-off-by: Marc Zyngier > Cc: stable@vger.kernel.org > --- > include/linux/msi.h | 6 ++++++ > kernel/irq/msi.c | 44 ++++++++++++++++++++------------------------ > 2 files changed, 26 insertions(+), 24 deletions(-) > > diff --git a/include/linux/msi.h b/include/linux/msi.h > index 360a0a7e7341..aef35fd1cf11 100644 > --- a/include/linux/msi.h > +++ b/include/linux/msi.h > @@ -178,6 +178,12 @@ struct msi_desc { > list_for_each_entry((desc), dev_to_msi_list((dev)), list) > #define for_each_msi_entry_safe(desc, tmp, dev) \ > list_for_each_entry_safe((desc), (tmp), dev_to_msi_list((dev)), list) > +#define for_each_msi_vector(desc, __irq, dev) \ > + for_each_msi_entry((desc), (dev)) \ > + if ((desc)->irq) \ > + for (__irq = (desc)->irq; \ > + __irq < ((desc)->irq + (desc)->nvec_used); \ > + __irq++) > > #ifdef CONFIG_IRQ_MSI_IOMMU > static inline const void *msi_desc_get_iommu_cookie(struct msi_desc *desc) > diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c > index 2c0c4d6d0f83..d924676c8781 100644 > --- a/kernel/irq/msi.c > +++ b/kernel/irq/msi.c > @@ -436,22 +436,22 @@ int __msi_domain_alloc_irqs(struct irq_domain > *domain, struct device *dev, > > can_reserve = msi_check_reservation_mode(domain, info, dev); > > - for_each_msi_entry(desc, dev) { > - virq = desc->irq; > - if (desc->nvec_used == 1) > - dev_dbg(dev, "irq %d for MSI\n", virq); > - else > + /* > + * This flag is set by the PCI layer as we need to activate > + * the MSI entries before the PCI layer enables MSI in the > + * card. Otherwise the card latches a random msi message. > + */ > + if (!(info->flags & MSI_FLAG_ACTIVATE_EARLY)) > + goto skip_activate; This will change the dbg print behavior. From the commit f3b0946d629c, it looks like the below dev_dbg() code was there for !MSI_FLAG_ACTIVATE_EARLY case as well. Not sure how much this matters though. Thanks, Shameer > + > + for_each_msi_vector(desc, i, dev) { > + if (desc->irq == i) { > + virq = desc->irq; > dev_dbg(dev, "irq [%d-%d] for MSI\n", > virq, virq + desc->nvec_used - 1); > - /* > - * This flag is set by the PCI layer as we need to activate > - * the MSI entries before the PCI layer enables MSI in the > - * card. Otherwise the card latches a random msi message. > - */ > - if (!(info->flags & MSI_FLAG_ACTIVATE_EARLY)) > - continue; > + } > > - irq_data = irq_domain_get_irq_data(domain, desc->irq); > + irq_data = irq_domain_get_irq_data(domain, i); > if (!can_reserve) { > irqd_clr_can_reserve(irq_data); > if (domain->flags & IRQ_DOMAIN_MSI_NOMASK_QUIRK) > @@ -462,28 +462,24 @@ int __msi_domain_alloc_irqs(struct irq_domain > *domain, struct device *dev, > goto cleanup; > } > > +skip_activate: > /* > * If these interrupts use reservation mode, clear the activated bit > * so request_irq() will assign the final vector. > */ > if (can_reserve) { > - for_each_msi_entry(desc, dev) { > - irq_data = irq_domain_get_irq_data(domain, desc->irq); > + for_each_msi_vector(desc, i, dev) { > + irq_data = irq_domain_get_irq_data(domain, i); > irqd_clr_activated(irq_data); > } > } > return 0; > > cleanup: > - for_each_msi_entry(desc, dev) { > - struct irq_data *irqd; > - > - if (desc->irq == virq) > - break; > - > - irqd = irq_domain_get_irq_data(domain, desc->irq); > - if (irqd_is_activated(irqd)) > - irq_domain_deactivate_irq(irqd); > + for_each_msi_vector(desc, i, dev) { > + irq_data = irq_domain_get_irq_data(domain, i); > + if (irqd_is_activated(irq_data)) > + irq_domain_deactivate_irq(irq_data); > } > msi_domain_free_irqs(domain, dev); > return ret; > -- > 2.29.2