From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE699C4320A for ; Wed, 25 Aug 2021 09:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A77EB61153 for ; Wed, 25 Aug 2021 09:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239637AbhHYJqV (ORCPT ); Wed, 25 Aug 2021 05:46:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:55964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236314AbhHYJqQ (ORCPT ); Wed, 25 Aug 2021 05:46:16 -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 7CDCA61100; Wed, 25 Aug 2021 09:45:31 +0000 (UTC) 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 1mIpTN-0076h0-FZ; Wed, 25 Aug 2021 10:45:29 +0100 Date: Wed, 25 Aug 2021 10:45:28 +0100 Message-ID: <87lf4pq2mf.wl-maz@kernel.org> From: Marc Zyngier To: Bjorn Helgaas Cc: Barry Song <21cnbao@gmail.com>, Bjorn Helgaas , Jonathan Corbet , Jonathan.Cameron@huawei.com, bilbao@vt.edu, Greg Kroah-Hartman , leon@kernel.org, LKML , linux-pci@vger.kernel.org, Linuxarm , luzmaximilian@gmail.com, mchehab+huawei@kernel.org, schnelle@linux.ibm.com, Barry Song , Thomas Gleixner Subject: Re: [PATCH v2 1/2] PCI/MSI: Fix the confusing IRQ sysfs ABI for MSI-X In-Reply-To: <20210824193438.GA3486820@bjorn-Precision-5520> References: <20210824193438.GA3486820@bjorn-Precision-5520> 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: helgaas@kernel.org, 21cnbao@gmail.com, bhelgaas@google.com, corbet@lwn.net, Jonathan.Cameron@huawei.com, bilbao@vt.edu, gregkh@linuxfoundation.org, leon@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linuxarm@huawei.com, luzmaximilian@gmail.com, mchehab+huawei@kernel.org, schnelle@linux.ibm.com, song.bao.hua@hisilicon.com, tglx@linutronix.de 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 On Tue, 24 Aug 2021 20:34:38 +0100, Bjorn Helgaas wrote: > > On Tue, Aug 24, 2021 at 10:46:59AM +1200, Barry Song wrote: > > On Mon, Aug 23, 2021 at 11:28 PM Marc Zyngier wrote: > > > > > > On Mon, 23 Aug 2021 12:03:08 +0100, > > > Barry Song <21cnbao@gmail.com> wrote: > > > +static ssize_t irq_show(struct device *dev, > > + struct device_attribute *attr, > > + char *buf) > > +{ > > + struct pci_dev *pdev = to_pci_dev(dev); > > +#ifdef CONFIG_PCI_MSI > > + struct msi_desc *desc = first_pci_msi_entry(pdev); > > + > > + /* for MSI, return the 1st IRQ in IRQ vector */ > > + if (desc && !desc->msi_attrib.is_msix) > > + return sysfs_emit(buf, "%u\n", desc->irq); > > +#endif > > + > > + return sysfs_emit(buf, "%u\n", pdev->irq); > > +} > > +static DEVICE_ATTR_RO(irq); > > Makes sense to me. And with Marc's patch maybe we could get rid of > default_irq, which also seems nice. > > > > > if we don't want to change the behaviour of any existing ABI, it > > > > seems the only thing we can do here to document it well in ABI > > > > doc. i actually doubt anyone has really understood what the irq > > > > entry is really showing. > > > > > > Given that we can't prove that it is actually the case, I believe this > > > is the only option. > > > > we have to document the ABI like below though it seems quite annoying. > > > > 1. for devices which don't support MSI and MSI-X, show legacy INTx > > 2. for devices which support MSI > > a. if CONFIG_PCI_MSI is not enabled, show legacy INTx > > b. if CONFIG_PCI_MSI is enabled and devices are using MSI at this > > moment, show 1st IRQ in the vector > > c. if CONFIG_PCI_MSI is enabled, but we shutdown its MSI before > > the users call sysfs entry, > > so at this moment, devices are not using MSI, show legacy INTx > > 3. for devices which support MSI-X, no matter if it is using MSI-X, > > show legacy INTx > > 4. In Addition, INTx might be broken due to incomplete firmware or > > hardware design for MSI and MSI-X cases > > > > To be honest, it sounds like a disaster :-) but if this is what we > > have to do, I'd like to try it in v3. > > It doesn't seem necessary to me to get into the gory details of > CONFIG_PCI_MSI -- if that's not enabled, drivers can't use MSI anyway. > > I don't understand 3. If a device supports both MSI and MSI-X and a > driver enables MSI, msi_capability_init() writes dev->irq, so it looks > like "irq" should contain the first MSI vector. > > I don't understand 4, either. Is the possibility of broken hardware > or firmware something we need to document? > > What about something like this? > > If a driver has enabled MSI (not MSI-X), "irq" contains the IRQ of > the first MSI vector. Otherwise "irq" contains the IRQ of the > legacy INTx interrupt. > I think that pretty much nails it. CONFIG_MSI is not something that userspace can (nor should) discover anyway. For (4), you may want to add that "irq" being set to 0 indicates that the device isn't capable of generating legacy INTx interrupts. Thanks, M. -- Without deviation from the norm, progress is not possible.