From patchwork Mon Dec 6 22:39:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 12660203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 49E00C433EF for ; Mon, 6 Dec 2021 22:48:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.240066.416382 (Exim 4.92) (envelope-from ) id 1muMmJ-0005IV-2Q; Mon, 06 Dec 2021 22:48:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 240066.416382; Mon, 06 Dec 2021 22:48:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muMmI-0005Gr-Jj; Mon, 06 Dec 2021 22:48:10 +0000 Received: by outflank-mailman (input) for mailman id 240066; Mon, 06 Dec 2021 22:48:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1muMdS-0004dp-E9 for xen-devel@lists.xenproject.org; Mon, 06 Dec 2021 22:39:02 +0000 Received: from galois.linutronix.de (galois.linutronix.de [193.142.43.55]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f268673-56e5-11ec-a5e1-b9374ead2679; Mon, 06 Dec 2021 23:39:01 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4f268673-56e5-11ec-a5e1-b9374ead2679 Message-ID: <20211206210437.821900680@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1638830341; 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: references:references; bh=0YY6FKU+qkJtNIjBHFuT3gGg88xsiW4iB6UKl0AmwtI=; b=gtLyx1uI4U5VlfG4MyQBVx6ekZVpiz/hJtSDGpgc8fcJ7gILFMYCCiR3EJjX0IZuhmYVAb BmqVgvOEI/y3Ed/3/UBUV5K5RTOB3ECpcaneiJcP0rxT9MeNN5rIyUEo1Pv3PtSgLgUYNU dnq47rZGpN2i2WVB6wI9J/C4sxH5DafOFwNhkSyVSLCKzFcjVLCFGVYCd9f3Fs7jeRn/uZ aVr2TQH5m9zO7I0AdAJWxXmpqPbrRxHd0TfUKtx3xuAHbr+qFO44ASkG7T7Sr3YEDi7Tfx kuTvLv6LTfhAjG2IhnSIRqieTkKEzepT2+1+TsS9Tt+jmrn09EVsc/uIx7spEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1638830341; 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: references:references; bh=0YY6FKU+qkJtNIjBHFuT3gGg88xsiW4iB6UKl0AmwtI=; b=PDX2NcH6oMutIhm4blppHnJIu3p645PCE5S/fYPtzhtyjwQnto1muPhBbSVhrwl/rgluuU I6amPjh+RiNE+XDw== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , linux-pci@vger.kernel.org, Cedric Le Goater , xen-devel@lists.xenproject.org, Juergen Gross , Greg Kroah-Hartman , Will Deacon , Santosh Shilimkar , iommu@lists.linux-foundation.org, dmaengine@vger.kernel.org, Stuart Yoder , Laurentiu Tudor , Nishanth Menon , Tero Kristo , linux-arm-kernel@lists.infradead.org, Vinod Koul , Mark Rutland , Robin Murphy , Sinan Kaya Subject: [patch V2 03/36] PCI/MSI: Allocate MSI device data on first use References: <20211206210307.625116253@linutronix.de> MIME-Version: 1.0 Date: Mon, 6 Dec 2021 23:39:00 +0100 (CET) Allocate MSI device data on first use, i.e. when a PCI driver invokes one of the PCI/MSI enablement functions. Signed-off-by: Thomas Gleixner Reviewed-by: Greg Kroah-Hartman Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas --- drivers/pci/msi/msi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -889,10 +889,12 @@ static int __pci_enable_msi_range(struct /* deprecated, don't use */ int pci_enable_msi(struct pci_dev *dev) { - int rc = __pci_enable_msi_range(dev, 1, 1, NULL); - if (rc < 0) - return rc; - return 0; + int rc = msi_setup_device_data(&dev->dev); + + if (!rc) + rc = __pci_enable_msi_range(dev, 1, 1, NULL); + + return rc < 0 ? rc : 0; } EXPORT_SYMBOL(pci_enable_msi); @@ -947,7 +949,11 @@ static int __pci_enable_msix_range(struc int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int minvec, int maxvec) { - return __pci_enable_msix_range(dev, entries, minvec, maxvec, NULL, 0); + int ret = msi_setup_device_data(&dev->dev); + + if (!ret) + ret = __pci_enable_msix_range(dev, entries, minvec, maxvec, NULL, 0); + return ret; } EXPORT_SYMBOL(pci_enable_msix_range); @@ -974,8 +980,12 @@ int pci_alloc_irq_vectors_affinity(struc struct irq_affinity *affd) { struct irq_affinity msi_default_affd = {0}; + int ret = msi_setup_device_data(&dev->dev); int nvecs = -ENOSPC; + if (ret) + return ret; + if (flags & PCI_IRQ_AFFINITY) { if (!affd) affd = &msi_default_affd;