From patchwork Thu Nov 17 15:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 21707 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp452424wrr; Thu, 17 Nov 2022 07:10:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf55w478cMnhgV4yr/mPTDjRWZ6l18miR2gjY/yNq2ayalW6njK+flk3gVK2ZPPaxYF0I79D X-Received: by 2002:a05:6402:4504:b0:463:71ef:b9ce with SMTP id ez4-20020a056402450400b0046371efb9cemr2493719edb.75.1668697831792; Thu, 17 Nov 2022 07:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668697831; cv=none; d=google.com; s=arc-20160816; b=GO7R4Pcec7Qc6M8c+LvigzKv3ytr4C6csLDOOoZs8iIyIQBzRXqrH2RV0ndmmzTD3T SvvhhcbZ+l3mO03uNT63BnksrM1DWgw9mvekFoOApaThh7wXEQnTspyu9jtDKsrSsko4 CLekk/tVAQPYqKdmFNXfqFLYJ4gcrVYAqoV0Ls9kYAh9GoX2SrVWreQDLtaXGK2XyQ4u VUJIItBi1V7wZZod/DwYKoerc7qbzhd8NHgOAoBuYKe7G3HJ/ow7ymdGHkO+YEiOFq8L nq3pSocBqNt13WJmkiMUllJIRurErF+A9owNgnye1UGMU1Uc/wHbYUXOq161RCmWTrWg V9yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=CcmMTDwhnaQQDnjreSFcEJhXe5wKANWvkUnc3Ky9kuQ=; b=0DN1lYHFhaC1Kdon203AUPlUSFZlwDRKLdOo70Mn77U35sMf3zWgj5PrDOWk4eAZHc vMKseDacHp9F0az1ODQwLkN6DJ8PgBBr4x60VXC4wmFG5Wl4Qc3LamvR2gY15K7D6tDJ PrVvffnpNjp9fbPtbYEq6AY03XVTWeI6JWXWq0CaUGq9lz/mdAgmJuZrKinb4wUWTYyN Rj/iKOYKj9srq7pPt6XQhbvS2onMis1U+Vd9wtiogQypLHtM2SOXxq8mGR8bnTb5xbLt 5d0CWNGo42j8MUzLG8Dmcqz+ZaLNU0sizrp/eWQC9mtwTRtPKivyWREM/4NoMc0BQP/o 13SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2XUpKKJU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a056402525200b00467ad3f4426si1153065edd.312.2022.11.17.07.09.43; Thu, 17 Nov 2022 07:10:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2XUpKKJU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239979AbiKQPId (ORCPT + 99 others); Thu, 17 Nov 2022 10:08:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240102AbiKQPIA (ORCPT ); Thu, 17 Nov 2022 10:08:00 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07EB774CE5; Thu, 17 Nov 2022 07:07:59 -0800 (PST) Date: Thu, 17 Nov 2022 15:07:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668697677; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcmMTDwhnaQQDnjreSFcEJhXe5wKANWvkUnc3Ky9kuQ=; b=2XUpKKJU6E8jWHSCQF9vIwZOwUheDTmJ6YmAK+Z5GxXeZ2X7FROMHRX456hYjN7WLRrnvm n7K83ZYEJJjm4LfSgbyr1MfzEcS/4h/eqmXd3bFwLZviqBEnrR59bVqcbI4YjuvKLb4Oi/ 1is1Jghs9HebwsaAXmjCEiL2MecJpxPYk7tS0tniySKpQV/j3LY5LGMCR4ae2nCze3akNm K8OfGBGB+bsskiGX1OYUMMu1UJ0l054dafcOBuoHrJmtmAwBBUNLWacKZnMLed/nRQX7yb Lwbz4kOG9DREllc2z1HioiUw8YyZv7BLh+OlZ8a1IWdxaatYZNFHPd4eifyDmA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668697677; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcmMTDwhnaQQDnjreSFcEJhXe5wKANWvkUnc3Ky9kuQ=; b=5Vtm2Dhr2e2GaD7lzmCDGvCTgEyQzlk1WKJMiAJEi2cvyp8zLFJDlGc9gNEhs5v+q01a3u V4BeeWeWna3L/1Aw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] PCI/MSI: Reject multi-MSI early Cc: Thomas Gleixner , Jason Gunthorpe , Bjorn Helgaas , x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20221111122015.574339988@linutronix.de> References: <20221111122015.574339988@linutronix.de> MIME-Version: 1.0 Message-ID: <166869767633.4906.12501148304122264760.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749208450734092372?= X-GMAIL-MSGID: =?utf-8?q?1749756497779650674?= The following commit has been merged into the irq/core branch of tip: Commit-ID: d2a463b297415ca6dd4d60bb1c867dd7c931587b Gitweb: https://git.kernel.org/tip/d2a463b297415ca6dd4d60bb1c867dd7c931587b Author: Thomas Gleixner AuthorDate: Fri, 11 Nov 2022 14:55:09 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 17 Nov 2022 15:15:22 +01:00 PCI/MSI: Reject multi-MSI early When hierarchical MSI interrupt domains are enabled then there is no point to do tons of work and detect the missing support for multi-MSI late in the allocation path. Just query the domain feature flags right away. The query function is going to be used for other purposes later and has a mode argument which influences the result: ALLOW_LEGACY returns true when: - there is no irq domain attached (legacy support) - there is a irq domain attached which has the feature flag set DENY_LEGACY returns only true when: - there is a irq domain attached which has the feature flag set This allows to use the function universally without ifdeffery in the calling code. Signed-off-by: Thomas Gleixner Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas Link: https://lore.kernel.org/r/20221111122015.574339988@linutronix.de --- drivers/pci/msi/irqdomain.c | 22 ++++++++++++++++++++++ drivers/pci/msi/msi.c | 4 ++++ drivers/pci/msi/msi.h | 9 +++++++++ 3 files changed, 35 insertions(+) diff --git a/drivers/pci/msi/irqdomain.c b/drivers/pci/msi/irqdomain.c index edd0cc2..666ed21 100644 --- a/drivers/pci/msi/irqdomain.c +++ b/drivers/pci/msi/irqdomain.c @@ -187,6 +187,28 @@ struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain); +/** + * pci_msi_domain_supports - Check for support of a particular feature flag + * @pdev: The PCI device to operate on + * @feature_mask: The feature mask to check for (full match) + * @mode: If ALLOW_LEGACY this grants the feature when there is no irq domain + * associated to the device. If DENY_LEGACY the lack of an irq domain + * makes the feature unsupported + */ +bool pci_msi_domain_supports(struct pci_dev *pdev, unsigned int feature_mask, + enum support_mode mode) +{ + struct msi_domain_info *info; + struct irq_domain *domain; + + domain = dev_get_msi_domain(&pdev->dev); + + if (!domain || !irq_domain_is_hierarchy(domain)) + return mode == ALLOW_LEGACY; + info = domain->host_data; + return (info->flags & feature_mask) == feature_mask; +} + /* * Users of the generic MSI infrastructure expect a device to have a single ID, * so with DMA aliases we have to pick the least-worst compromise. Devices with diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index 794ec97..bc84647 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -347,6 +347,10 @@ static int msi_capability_init(struct pci_dev *dev, int nvec, struct msi_desc *entry; int ret; + /* Reject multi-MSI early on irq domain enabled architectures */ + if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY)) + return 1; + /* * Disable MSI during setup in the hardware, but mark it enabled * so that setup code can evaluate it. diff --git a/drivers/pci/msi/msi.h b/drivers/pci/msi/msi.h index 8170ef2..9d75b6f 100644 --- a/drivers/pci/msi/msi.h +++ b/drivers/pci/msi/msi.h @@ -97,6 +97,15 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int void __pci_restore_msi_state(struct pci_dev *dev); void __pci_restore_msix_state(struct pci_dev *dev); +/* irq_domain related functionality */ + +enum support_mode { + ALLOW_LEGACY, + DENY_LEGACY, +}; + +bool pci_msi_domain_supports(struct pci_dev *dev, unsigned int feature_mask, enum support_mode mode); + /* Legacy (!IRQDOMAIN) fallbacks */ #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS