Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2911650pxb; Tue, 24 Aug 2021 10:25:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWsBg82iYfNhQJbiILhlNl2uhGoTcSdB8r0mD5OG7nbqyfpzkR1T16NO8Z7AZMcIzriCVb X-Received: by 2002:a05:6e02:1c2b:: with SMTP id m11mr27202949ilh.242.1629825931589; Tue, 24 Aug 2021 10:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825931; cv=none; d=google.com; s=arc-20160816; b=nWAl/2tDdRk2PLz2HT8uoDFVQ8+fWqQUGid7n0KfKt6726+4PV7GtGpe2doJ8HIZGi xrYDXFbWifTxqIHFL3DbjN9c+0MV7uAtiyNaNWdc68v/A/uuFaWvnIeSu5lMEyrUak+A lRyqqJmT9RP8pyEaiZVUdYyh+9Y2+MbcpCc+ac7rvdnKisce/P5eiGlheEHiyYZoJ+HC leT4O0KUw5NczW1jcK3B/giq0Ky1sN1h5CdVKwXmihcXcAC7BkQt01IiuRv1+3vzZC6K h2NPhjC2JL1+kVLdsPzhsB0OGumTZ7NWWZc0TExr2/0HXCES3W95/ECzQahyQ8ZkEo3F n3Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L9ojaOds9u6NokHzFZUFFj30hNw5gOtAtuOb/P6rUkY=; b=xBkdh11tQCkabICq+RsKQxaPV0dQlvHjZ6XgtlffC6bqh893dRcQUZqPvk51vvlA6o 8X/Qx2t9uKVzvv0pl59qMcyQKEbEYHvsUPIl6bxoMZqHW46fmk0JOrxv9xoPgprDQ00c zhX2MVRlSKskI2wzFNWW7ofVV/bR0r8CsNKpFqudVyZgkW2s1tE/0IVbF6ylZjpL9gY8 GdM1mmfXJqzwXOgTd3WsOZHvWZy8UZyVDZ0TR/Lc302xl4PrjGGlV4IHnGiYIB+lKNzk 762ATtbM9egvoXxj5R8dVvN2oMwEZMmkZsO7lALnxKmQ1SYFJ7qi12MQhbOTzNAoDvqh 9fZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=onuNfpCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m39si1848074jav.28.2021.08.24.10.25.19; Tue, 24 Aug 2021 10:25:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=onuNfpCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241100AbhHXRYG (ORCPT + 99 others); Tue, 24 Aug 2021 13:24:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:60104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbhHXRV2 (ORCPT ); Tue, 24 Aug 2021 13:21:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2946B61AFC; Tue, 24 Aug 2021 17:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824602; bh=paJZbifc+ugyXU5TgUKbgGU68isjZxSnEZrpd6krfmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=onuNfpCeQa//Ts8N78VTZMaGiRYcFpJ5Xxn0TWsCEqGT7OhNR7bTRDWzMtBEiOWU9 Ju0TLMTUapC+erRsxEVec5bLBp2nIhkaAlJpOegGJ2uBqozYGFYHhFEMHvQD5EKlqF A+gA+iCSxVJ3lYKc6V+yFORA2OJlW8vteqrgU2/iuexdsxVgae/Nf7O8p6VMFB1hHX R1pnZw7cJRPzqJcrFWIeSWou7cvh9KipalrwtFeqvkh/FuzWsY3SvD1qLmN+5sx05p ZQGIj6oReWu9p8NdX6grh0X814dtjOH4VT2cZ7U+7uYgYGS/PQuXLWNYeY8Lz0PC8H yMFaK71T5jVog== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Thomas Gleixner , Marc Zyngier , Ashok Raj , Bjorn Helgaas , Greg Kroah-Hartman Subject: [PATCH 4.19 31/84] PCI/MSI: Enable and mask MSI-X early Date: Tue, 24 Aug 2021 13:01:57 -0400 Message-Id: <20210824170250.710392-32-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170250.710392-1-sashal@kernel.org> References: <20210824170250.710392-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.205-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.205-rc1 X-KernelTest-Deadline: 2021-08-26T17:02+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit 438553958ba19296663c6d6583d208dfb6792830 upstream. The ordering of MSI-X enable in hardware is dysfunctional: 1) MSI-X is disabled in the control register 2) Various setup functions 3) pci_msi_setup_msi_irqs() is invoked which ends up accessing the MSI-X table entries 4) MSI-X is enabled and masked in the control register with the comment that enabling is required for some hardware to access the MSI-X table Step #4 obviously contradicts #3. The history of this is an issue with the NIU hardware. When #4 was introduced the table access actually happened in msix_program_entries() which was invoked after enabling and masking MSI-X. This was changed in commit d71d6432e105 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") which removed the table write from msix_program_entries(). Interestingly enough nobody noticed and either NIU still works or it did not get any testing with a kernel 3.19 or later. Nevertheless this is inconsistent and there is no reason why MSI-X can't be enabled and masked in the control register early on, i.e. move step #4 above to step #1. This preserves the NIU workaround and has no side effects on other hardware. Fixes: d71d6432e105 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") Signed-off-by: Thomas Gleixner Tested-by: Marc Zyngier Reviewed-by: Ashok Raj Reviewed-by: Marc Zyngier Acked-by: Bjorn Helgaas Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210729222542.344136412@linutronix.de Signed-off-by: Greg Kroah-Hartman --- drivers/pci/msi.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 23a363fd4c59..949dc342c16a 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -743,18 +743,25 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, u16 control; void __iomem *base; - /* Ensure MSI-X is disabled while it is set up */ - pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); + /* + * Some devices require MSI-X to be enabled before the MSI-X + * registers can be accessed. Mask all the vectors to prevent + * interrupts coming in before they're fully set up. + */ + pci_msix_clear_and_set_ctrl(dev, 0, PCI_MSIX_FLAGS_MASKALL | + PCI_MSIX_FLAGS_ENABLE); pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); /* Request & Map MSI-X table region */ base = msix_map_region(dev, msix_table_size(control)); - if (!base) - return -ENOMEM; + if (!base) { + ret = -ENOMEM; + goto out_disable; + } ret = msix_setup_entries(dev, base, entries, nvec, affd); if (ret) - return ret; + goto out_disable; ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX); if (ret) @@ -765,14 +772,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, if (ret) goto out_free; - /* - * Some devices require MSI-X to be enabled before we can touch the - * MSI-X registers. We need to mask all the vectors to prevent - * interrupts coming in before they're fully set up. - */ - pci_msix_clear_and_set_ctrl(dev, 0, - PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE); - msix_program_entries(dev, entries); ret = populate_msi_sysfs(dev); @@ -807,6 +806,9 @@ out_avail: out_free: free_msi_irqs(dev); +out_disable: + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); + return ret; } -- 2.30.2