Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2319138rwl; Thu, 6 Apr 2023 08:37:18 -0700 (PDT) X-Google-Smtp-Source: AKy350aDnBa0HgcZF3RFYQ+f1S+YTXQuf1jrQMh51548JaWmzTlPpmm04/FpSMlE52nHNdbUOXNy X-Received: by 2002:a17:907:101a:b0:931:4f2c:4e83 with SMTP id ox26-20020a170907101a00b009314f2c4e83mr6062341ejb.63.1680795438536; Thu, 06 Apr 2023 08:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680795438; cv=none; d=google.com; s=arc-20160816; b=RRo5VC2ve6zCH6KsaST1yuvMnOsgn6kttfuPhaOfLhTSg2fEBegSk7CGdBSjTbWSgs e47eqPlIvJtK8Ye+FiD7gu/P3ZG7x2pQRR6B9TGzXzfQYYCW2vH8YCD/DDZZ7UEmBJ05 kt5GxeqFPikWykRVLVfz+UC26dF88SMXaQV618EK9q8Ov2sqy6WNfBisbHkTkM0G0D9q lPQMV7iiDXCH44jy6do7kXNqzS1xlXNoKnPjoizml4pk/ew05DqCrLAFDTXsWd1PDLdV H64z/AAVHCBtaPeVIYgsGR30oSKSLRxf0tc4WyA0fIHREERcM+D2m5NB845S5TcixcfD mKRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=TfJOZXuG8Z29FmbUJiNwmFRsv39j9Q926clySbCEQyg=; b=P+VY9dYiiqzyGU0pgNP7tZt9ygtQPKHVpg6P3r2DpfiqZ3bqy6D3yeY2PeGiVkRyWn l6JdlWOSsG34RcJbrDI2yIfRMwX2auNLqGezVwLeWOnW8EBjy0gfAkcdxBeAMw6f50/q 2vJpXeTagh3FJ+FHStaJCxIzhQ4rmpevbyXaVp9LVKn9Z4B2P9BLt25cHLDLEpUuNgFG gVAztz1I/ol9gZ4bqTqObYpk/RwwY4PcUTXHcN0VIsqxEz8Ki8QX0TZ0vJD2UhREofzC DxroeAgLk717mOpslLbfwpzEzw78RYd/zAdlgvHbSxbfbnUcaqerxM4PBREsixvhZG5U w46Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a17090629d500b00947791bfdcasi1225196eje.312.2023.04.06.08.36.53; Thu, 06 Apr 2023 08:37:18 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239782AbjDFPgp convert rfc822-to-8bit (ORCPT + 99 others); Thu, 6 Apr 2023 11:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239747AbjDFPgn (ORCPT ); Thu, 6 Apr 2023 11:36:43 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABECB7D9A for ; Thu, 6 Apr 2023 08:36:41 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-29-UuMCYDyaOwWGz8MYzNkIwA-1; Thu, 06 Apr 2023 16:36:38 +0100 X-MC-Unique: UuMCYDyaOwWGz8MYzNkIwA-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 6 Apr 2023 16:36:36 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Thu, 6 Apr 2023 16:36:36 +0100 From: David Laight To: 'Bjorn Helgaas' CC: "linux-kernel@vger.kernel.org" , "Thomas Gleixner" , Jason Gunthorpe , "Bjorn Helgaas" , Linus Torvalds , Christoph Hellwig , "linux-pci@vger.kernel.org" , "regressions@lists.linux.dev" Subject: RE: revert bab65e48cb064 PCI/MSI Sanitize MSI-X checks Thread-Topic: revert bab65e48cb064 PCI/MSI Sanitize MSI-X checks Thread-Index: AdlodgFkFYa3Wd45RlGJwWEgKJXFDwAGyW4AAALDCHA= Date: Thu, 6 Apr 2023 15:36:36 +0000 Message-ID: References: <20230406150742.GA3703273@bhelgaas> In-Reply-To: <20230406150742.GA3703273@bhelgaas> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, 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 From: Bjorn Helgaas > Sent: 06 April 2023 16:08 > > [+cc linux-pci, regressions] > > On Thu, Apr 06, 2023 at 11:05:14AM +0000, David Laight wrote: > > The change in bab65e48cb064 breaks pci_enable_msix_range(). > > The intent is to optimise the sanity checks, but it is > > somewhat overenthusiastic. > > > > The interface allows you to ask for a lot of vectors and > > returns the number that were allocated. > > However, after the change, you can't request a vector > > that is higher than the largest the hardware supports. > > Which makes that rather pointless. > > > > So code like: > > for (i = 0; i < 16; i++) > > msix_tbl[i].entry = i; > > nvec = pci_enable_msix_range(dev, msix_tbl, 1, 16); > > Now returns -22 if the hardware only supports 8 interrupts. > > > > Previously it returned 8. > > > > I can fix my driver, but I suspect that any code that relies > > on a smaller number of vectors being returned is now broken. > > Thanks for the report! bab65e48cb06 ("PCI/MSI: Sanitize MSI-X > checks") appeared in v6.2-rc1, so this is a recent regression and it > would be good to fix it for v6.3. I do try to test every release at around rc3. > bab65e48cb06 only touches drivers/pci/msi/msi.c, but since it didn't > go through the PCI tree, I'll let Thomas handle any revert (or better, > an improvement to pci_msix_validate_entries()) since he wrote and > applied the original. Looking it: 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) return false; /* Check for duplicate entries */ for (j = i + 1; j < nvec; j++) { if (entries[i].entry == entries[j].entry) return false; } /* Check for unsupported gaps */ if (nogap && entries[i].entry != i) return false; } return true; } It probably needs to return an updated 'nvec'. The gap/duplicate check is also a bit horrid, why not: if (nogap) { if (entries[i].entry != i) return false; continue; } if (!i || entries[i].entry > entries[i - 1].entry) continue; horrid, expensive loop... David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)