Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4515803rwl; Mon, 10 Apr 2023 12:17:09 -0700 (PDT) X-Google-Smtp-Source: AKy350auOBZaAxAjcE50d3V3FI5LMUaLkwl7fLzXlScZXyhfS6uXRI1N53DS8q55i40AqZpuhsWc X-Received: by 2002:aa7:c156:0:b0:504:92f2:deb3 with SMTP id r22-20020aa7c156000000b0050492f2deb3mr5357012edp.26.1681154228848; Mon, 10 Apr 2023 12:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681154228; cv=none; d=google.com; s=arc-20160816; b=Rxe9QVzX0b21I5hOl3wKNWDTZTO2QTJhNlSl99jOej2uKnAYL1uN4qwfxdfx5Yc5kc pwy8wn5ncO/KUyZExaN3N6mh4dsbHj3ZlEQBUuZpeRm2K8ng6jN4hWucBD0e/atpe2iX pCVLj3WB1EZRdD4VBq4gmOy0nL55mVzn93/XHjI7QbElwyrjRUWyAbwFibN62CnExlP6 fD7k4cNLQt/7DHFpLwHfRsok7lF9SbqhvCHsYC4E4rjdBckJVOExnI/ZouJZyEDJ4biP Ahk3ypQJNzcAMEGVQJEOsMMZF6+S2l2+TB0ba0AHQQJJvDDayeXerFNTkCj6rYqpjG3Q w47g== 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; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a24-20020aa7d918000000b00504c269149csi4840edr.337.2023.04.10.12.16.44; Mon, 10 Apr 2023 12:17:08 -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; 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 S229694AbjDJTPE (ORCPT + 99 others); Mon, 10 Apr 2023 15:15:04 -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 Content-Type: text/plain 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 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) {