From nobody Wed Feb 11 18:21:54 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AE80C77B61 for ; Mon, 10 Apr 2023 19:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjDJTPI (ORCPT ); Mon, 10 Apr 2023 15:15:08 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; } =20 -static bool pci_msix_validate_entries(struct pci_dev *dev, struct msix_ent= ry *entries, - int nvec, int hwsize) +static bool pci_msix_validate_entries(struct pci_dev *dev, struct msix_ent= ry *entries, int nvev) { bool nogap; int i, j; @@ -762,10 +761,6 @@ static bool pci_msix_validate_entries(st nogap =3D pci_msi_domain_supports(dev, MSI_FLAG_MSIX_CONTIGUOUS, DENY_LEG= ACY); =20 for (i =3D 0; i < nvec; i++) { - /* Entry within hardware limit? */ - if (entries[i].entry >=3D hwsize) - return false; - /* Check for duplicate entries */ for (j =3D i + 1; j < nvec; j++) { if (entries[i].entry =3D=3D entries[j].entry) @@ -805,7 +800,7 @@ int __pci_enable_msix_range(struct pci_d if (hwsize < 0) return hwsize; =20 - if (!pci_msix_validate_entries(dev, entries, nvec, hwsize)) + if (!pci_msix_validate_entries(dev, entries, nvec)) return -EINVAL; =20 if (hwsize < nvec) {