From patchwork Thu Nov 17 15:07:54 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: 21705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp452117wrr; Thu, 17 Nov 2022 07:10:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ATXa/Ya0qI8ILtJx0ubi9Q8toVKQzBvAyXWCwqdyxSfL1MgvkqZZRwUvIXoaYS938rMzR X-Received: by 2002:a17:907:9951:b0:7b2:7e7a:11c1 with SMTP id kl17-20020a170907995100b007b27e7a11c1mr2348092ejc.684.1668697803593; Thu, 17 Nov 2022 07:10:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668697803; cv=none; d=google.com; s=arc-20160816; b=dMw3Chm/MWfSZmQ/9L8n/wbNrDVkJQ0CBokG+wxhDD/6DmvRuYeQR20Iv27XZlrBzD KAu1ZXgNA7NuTXyOYHOexwCDhiqEA0oX4bvBEGAED3KBriak66qiXt4JitBSvMeja+a/ T9Xul61s0xEkMnzgLcvcP0Xqr6SaRuhnci4j+U2Fil13mSo0BByg9Bus4HoN2ZVMPRib 38BBsokILxRNp41s6guPaOMNRVjLWuQz/wZo5j1UK6jarHHS/I+88pKJVFBDdZBFfTko oLSSoqk+1Y6Co8VPz3wak9rK47sh6NG89LmtlhlIAIbgLjGKJmd6wsMNKfw75eIak1TO NjKA== 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=K+p/3EF3ZPOVV5DsExwKrDuDyfRU/SzuktZL9Elkis0=; b=nIvYZJ8B2QcIRGBcZvONv5JbwnfJaYG1G/OskBf4is5qQCGsNkTJEil8vYusVBch0L cK/y3pht/Xam5NyB3Nqn15zOyL3Hi4DyzWncpNs+EM4a7vaO8kiG1/RrcWVlQdLSfJu8 lBAlFK3dPPk1b74QpfVi441yrbfZElFSrFwoD4YIa1lqjAmaQBE0xQHpFyPOoHDQJTw0 TBfAskGZUr9dqUPyh/0RIbrghTlJFCHw+EVtIpNfvgkuOc7PaOHTVm6D5O49rbC2Jc0i i1dXF8Sy/KKxHfmqDo1D+3fFasbKcYcjCI4IlDtoAi5isWtI9pBPrYFwnoq5h+oNQmjY 2MeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=16v9QNJD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=507iZZGO; 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 n11-20020a170906118b00b007ae4717bf1esi664641eja.99.2022.11.17.07.09.30; Thu, 17 Nov 2022 07:10:03 -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=16v9QNJD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=507iZZGO; 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 S240092AbiKQPIQ (ORCPT + 99 others); Thu, 17 Nov 2022 10:08:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239931AbiKQPH5 (ORCPT ); Thu, 17 Nov 2022 10:07:57 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A48A159876; Thu, 17 Nov 2022 07:07:56 -0800 (PST) Date: Thu, 17 Nov 2022 15:07:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668697675; 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=K+p/3EF3ZPOVV5DsExwKrDuDyfRU/SzuktZL9Elkis0=; b=16v9QNJDOUHSl3FcAA0be2i4TRLW8uCJSvfpgOG4LNkll5wq76egyG/f0hZONc5zDsYjMM ZFHbdwy7bq6Y+GgbYy47pNoCw860QjIE7AtUgk5h8oVEwhQ0zfpg95wJx0gobpvrw798Y+ iiMu2sl3DgCqIDRS5K9BUG3sPpICuF6Dl5oocIqIDNsK226uBJ98kEUUcplWPKCqkH1IXX rxrJDf8AG3vy3Tr2KZ0zXcZJUdeNEBrR4o1VY1RMHjNQxMOsfXImV1x6tSh5v4r1uLbddK f4KPlgAllKb++UjxNMm73fEjKENa8tmdbUoWZ66tSDTm0haIIItgqrN5Fyy7Pw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668697675; 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=K+p/3EF3ZPOVV5DsExwKrDuDyfRU/SzuktZL9Elkis0=; b=507iZZGOiQXlBE0wPou0HSprRM0m0l1BB3ehyiFxLVt1VuJPuoTRVKobMIQokEYW4jICVg uesZv1gfeKN8J8Cg== 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: Validate MSI-X contiguous restriction early Cc: Thomas Gleixner , Jason Gunthorpe , Bjorn Helgaas , x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20221111122015.691357406@linutronix.de> References: <20221111122015.691357406@linutronix.de> MIME-Version: 1.0 Message-ID: <166869767404.4906.3594475439584777347.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?1749756468033539794?= X-GMAIL-MSGID: =?utf-8?q?1749756468033539794?= The following commit has been merged into the irq/core branch of tip: Commit-ID: 4644d22eb673f173252610a93aaaba4c2bff7b41 Gitweb: https://git.kernel.org/tip/4644d22eb673f173252610a93aaaba4c2bff7b41 Author: Thomas Gleixner AuthorDate: Fri, 11 Nov 2022 14:55:12 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 17 Nov 2022 15:15:22 +01:00 PCI/MSI: Validate MSI-X contiguous restriction early With interrupt domains the sanity check for MSI-X vector validation can be done _before_ any allocation happens. The sanity check only applies to the allocation functions which have an 'entries' array argument. The entries array is filled by the caller with the requested MSI-X indices. Some drivers have gaps in the index space which is not supported on all architectures. The PCI/MSI irq domain has a 'feature' bit to enforce this validation late during the allocation phase. Just do it right away before doing any other work along with the other sanity checks on that array. Signed-off-by: Thomas Gleixner Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas Link: https://lore.kernel.org/r/20221111122015.691357406@linutronix.de --- drivers/pci/msi/msi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index 0740acd..b94f6da 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -725,13 +725,17 @@ out_disable: return ret; } -static bool pci_msix_validate_entries(struct msix_entry *entries, int nvec, int hwsize) +static bool pci_msix_validate_entries(struct pci_dev *dev, struct msix_entry *entries, + int nvec, int hwsize) { + bool nogap; int i, j; if (!entries) return true; + nogap = pci_msi_domain_supports(dev, MSI_FLAG_MSIX_CONTIGUOUS, DENY_LEGACY); + for (i = 0; i < nvec; i++) { /* Entry within hardware limit? */ if (entries[i].entry >= hwsize) @@ -742,6 +746,9 @@ static bool pci_msix_validate_entries(struct msix_entry *entries, int nvec, int if (entries[i].entry == entries[j].entry) return false; } + /* Check for unsupported gaps */ + if (nogap && entries[i].entry != i) + return false; } return true; } @@ -773,7 +780,7 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int if (hwsize < 0) return hwsize; - if (!pci_msix_validate_entries(entries, nvec, hwsize)) + if (!pci_msix_validate_entries(dev, entries, nvec, hwsize)) return -EINVAL; /* PCI_IRQ_VIRTUAL is a horrible hack! */