From patchwork Mon Apr 10 19:14:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 81622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2106109vqo; Mon, 10 Apr 2023 12:29:11 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1EIUaIzIKI2TZcHedu1krnDXWKoWXWK9zwPoiAIiAcxj/TTC3bDiNTy08gjg7OnUeI3r0 X-Received: by 2002:aa7:de13:0:b0:502:a700:dc8b with SMTP id h19-20020aa7de13000000b00502a700dc8bmr6867530edv.9.1681154950986; Mon, 10 Apr 2023 12:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681154950; cv=none; d=google.com; s=arc-20160816; b=vzGvB7OAUdrWSmaVtH+jH2M/AEPBWHO1eN9bfi3Dbe5eyf5qVJW/FUtuLXpqEalzkv ogqavLe9jHGsJiO202PGQg7Kk27z2CuN9fIfwPxGAyDD/uu+dQwCVWI7iGa19IuTv4Ln rkPZZPcfUSLw1Mjdji0otENm05b460J7rahaC6W7x0QsbPoyqMpRst+HSxyHzV2jOLG9 PTu1FotHe5JREa9ZS2uzl1OTwnxzqYCULTtwnW6PsRVXUoKeilt6xV+KMyDxE7EsoocK bR5PeSyHppzbmGylCMNV5pGcIZV/HOqkvapoz6UxHZT6++d2UuiF9WOq10/NDhYbDycz O+Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=VACFH6nP2OHBr9zz8HSVitcsLS/GkoJrTXejyQVrgsE=; b=Hl6PawJ0QO9ob0xEM7JnrdaD68FaGH/dPDNayKcoKfDFttwSP6ca8mSCj1bSiWAgjc sHCBaiJBB1PsmK9Y2H+659KYNohcSfLXtPkcoj0LY+bRDpA/MJciHJXSudbBFuxmKBmw 4mAvnLXk+1Gn7Dzyo+TpiM3vmG+qtZObXIHdntIRG1fXC51t4Z+4/qAVFxgdc3CVhiRK QZRObxB/iQ+Ima58KOjdlxZl1zDr6W5nWpMjd/hrh7uLYzKYcr2Aydp9aU/GUaz3SulB YRsI9tvyLEGnElGwGkjrFssPqY7jL3rjjW/yVhnz0tCVIBehhMErlzUWqaIKphAtV6a2 +evw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WroTXvyF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yhYXLIXP; 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 w23-20020aa7dcd7000000b00504b99d69basi517829edu.418.2023.04.10.12.28.45; Mon, 10 Apr 2023 12:29:10 -0700 (PDT) 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=WroTXvyF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=yhYXLIXP; 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 S229702AbjDJTPF (ORCPT + 99 others); Mon, 10 Apr 2023 15:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjDJTOu (ORCPT ); Mon, 10 Apr 2023 15:14:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0846A1980 for ; Mon, 10 Apr 2023 12:14:48 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1681154086; 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: in-reply-to:in-reply-to:references:references; bh=VACFH6nP2OHBr9zz8HSVitcsLS/GkoJrTXejyQVrgsE=; b=WroTXvyFge1YF3sP6p3ZH7e08JdEOZfXRVFqISXoJly9QdtLzLcsQZqBSq2qx1J3iWipO8 2J3awYVKfU15ZxBGafaGknGurEozpLNdTH4VQPCs1oQxtWRctAmdXMhsWcZFjzEq1r7GBK Vb/SU/33FjK+4mI0L8zcFj2lo0kj8rmWfIZZUmru4LPJcAMq4xC9f80IsetEnkjjSVqo4l YDy3W24SfO/N/92SY45fGwxeGhofl1rExW2NxVrmkI7Wcd05K/cOULHe2NTnkghFJP6sR3 ynD2NI2kbmqeV2hBl3UImU75+vgMlrl9TSg8CbIzW/0+9lr6zM3bOTeocC6sjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1681154086; 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: in-reply-to:in-reply-to:references:references; bh=VACFH6nP2OHBr9zz8HSVitcsLS/GkoJrTXejyQVrgsE=; b=yhYXLIXPOmSF9iXJGKYWMgdshLRtqbh1CbGNM2u7U1Y9zbVgI/BuY/Z5mL9+AgPc2UoDRc RBzJ9S0mv0LDOrBQ== To: Linus Torvalds , David Laight Cc: "linux-kernel@vger.kernel.org" , Jason Gunthorpe , Bjorn Helgaas , Christoph Hellwig Subject: [PATCH] PCI/MSI: Remove over-zealous hardware size check in pci_msix_validate_entries() In-Reply-To: <878rf3tm48.ffs@tglx> References: <878rf3tm48.ffs@tglx> Date: Mon, 10 Apr 2023 21:14:45 +0200 Message-ID: <87v8i3sg62.ffs@tglx> MIME-Version: 1.0 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1762818734042249019?= X-GMAIL-MSGID: =?utf-8?q?1762818734042249019?= pci_msix_validate_entries() validates the entries array which is handed in by the caller for a MSI-X interrupt allocation. Aside of consistency failures it also detects a failure when the size of the MSI-X hardware table in the device is smaller than the size of the entries array. That's wrong for the case of range allocations where the caller provides the minimum and the maximum number of vectors to allocate, when the hardware size is greater or equal to the mininum, but smaller than the maximum. Remove the hardware size check completely from that function and just ensure that the entires array up to the maximum size is consistent. The limitation and range checking versus the hardware size happens independently of that afterwards anyway because the entries array is optional. Fixes: 4644d22eb673 ("PCI/MSI: Validate MSI-X contiguous restriction early") Reported-by: David Laight Signed-off-by: Thomas Gleixner --- David, can you please confirm that this fixes your issue? --- drivers/pci/msi/msi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -750,8 +750,7 @@ static int msix_capability_init(struct p return ret; } -static bool pci_msix_validate_entries(struct pci_dev *dev, struct msix_entry *entries, - int nvec, int hwsize) +static bool pci_msix_validate_entries(struct pci_dev *dev, struct msix_entry *entries, int nvev) { bool nogap; int i, j; @@ -762,10 +761,6 @@ static bool pci_msix_validate_entries(st 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) - return false; - /* Check for duplicate entries */ for (j = i + 1; j < nvec; j++) { if (entries[i].entry == entries[j].entry) @@ -805,7 +800,7 @@ int __pci_enable_msix_range(struct pci_d if (hwsize < 0) return hwsize; - if (!pci_msix_validate_entries(dev, entries, nvec, hwsize)) + if (!pci_msix_validate_entries(dev, entries, nvec)) return -EINVAL; if (hwsize < nvec) {