From patchwork Tue May 28 01:54:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Anastasio X-Patchwork-Id: 10963633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BC2B1398 for ; Tue, 28 May 2019 01:54:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C507285E0 for ; Tue, 28 May 2019 01:54:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30214285F7; Tue, 28 May 2019 01:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D01BC285E0 for ; Tue, 28 May 2019 01:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbfE1ByT (ORCPT ); Mon, 27 May 2019 21:54:19 -0400 Received: from alpha.anastas.io ([104.248.188.109]:49993 "EHLO alpha.anastas.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727589AbfE1ByS (ORCPT ); Mon, 27 May 2019 21:54:18 -0400 Received: from authenticated-user (alpha.anastas.io [104.248.188.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alpha.anastas.io (Postfix) with ESMTPSA id 3C4F37F8F7; Mon, 27 May 2019 20:54:17 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=anastas.io; s=mail; t=1559008458; bh=JsmM3TF8YlXJ0OlLlUbqQr2/zPIZK0XaaIlAJ070/mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkoPdaXY5XwAO1T08QAOaqZ+F7d675TuKefYlSJiiKLq3kM55/+JyWA3ttzz9xsHW B4LlRttoyQRIcAgVxPI0IA5CLNmx+Yq0TcVnHfsCsndI20JVU3AZRUzwAAHg+gLS9W 4XLxD+Rpxe7jULMpbjHauAua9nH8IT6h4NM3uTqPcgRzgXO4Op5nB9TZa9Jm1s+GTt gONJysKq9xK9/1iMvCFK4pmLMjEZ89Z40glW/lafdgUOiALZKtEnsDj0eHvPK/NQXA CqOzh76yqt94nnDLlUkKvrIoYeVSOt+DPrlpScWEwy61RAWG/j3cw6PJ20uVlHv/H2 ZddttAT2tpcsA== From: Shawn Anastasio To: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: bhelgaas@google.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, sbobroff@linux.ibm.com, xyjxie@linux.vnet.ibm.com, rppt@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] PCI: Introduce pcibios_ignore_alignment_request Date: Mon, 27 May 2019 20:54:10 -0500 Message-Id: <20190528015412.30521-2-shawn@anastas.io> In-Reply-To: <20190528015412.30521-1-shawn@anastas.io> References: <20190528015412.30521-1-shawn@anastas.io> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new pcibios function pcibios_ignore_alignment_request which allows the PCI core to defer to platform-specific code to determine whether or not to ignore alignment requests for PCI resources. The existing behavior is to simply ignore alignment requests when PCI_PROBE_ONLY is set. This is behavior is maintained by the default implementation of pcibios_ignore_alignment_request. Signed-off-by: Shawn Anastasio --- drivers/pci/pci.c | 9 +++++++-- include/linux/pci.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 8abc843b1615..8207a09085d1 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5882,6 +5882,11 @@ resource_size_t __weak pcibios_default_alignment(void) return 0; } +int __weak pcibios_ignore_alignment_request(void) +{ + return pci_has_flag(PCI_PROBE_ONLY); +} + #define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0}; static DEFINE_SPINLOCK(resource_alignment_lock); @@ -5906,9 +5911,9 @@ static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev, p = resource_alignment_param; if (!*p && !align) goto out; - if (pci_has_flag(PCI_PROBE_ONLY)) { + if (pcibios_ignore_alignment_request()) { align = 0; - pr_info_once("PCI: Ignoring requested alignments (PCI_PROBE_ONLY)\n"); + pr_info_once("PCI: Ignoring requested alignments\n"); goto out; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 4a5a84d7bdd4..47471dcdbaf9 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1990,6 +1990,7 @@ static inline void pcibios_penalize_isa_irq(int irq, int active) {} int pcibios_alloc_irq(struct pci_dev *dev); void pcibios_free_irq(struct pci_dev *dev); resource_size_t pcibios_default_alignment(void); +int pcibios_ignore_alignment_request(void); #ifdef CONFIG_HIBERNATE_CALLBACKS extern struct dev_pm_ops pcibios_pm_ops; From patchwork Tue May 28 01:54:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Anastasio X-Patchwork-Id: 10963635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6601A1398 for ; Tue, 28 May 2019 01:54:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57AC3285E0 for ; Tue, 28 May 2019 01:54:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BB55285F7; Tue, 28 May 2019 01:54:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF5B6285E0 for ; Tue, 28 May 2019 01:54:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727890AbfE1By1 (ORCPT ); Mon, 27 May 2019 21:54:27 -0400 Received: from alpha.anastas.io ([104.248.188.109]:56217 "EHLO alpha.anastas.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbfE1ByU (ORCPT ); Mon, 27 May 2019 21:54:20 -0400 Received: from authenticated-user (alpha.anastas.io [104.248.188.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alpha.anastas.io (Postfix) with ESMTPSA id 3DD407F8F8; Mon, 27 May 2019 20:54:18 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=anastas.io; s=mail; t=1559008459; bh=EGTrKlRnXu1zsiLLv/Fv7FG8sil5S0AhH+klcU6GwLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6HTxRma9ugS+kSTEteLkii8KAfQxaSkokf6vGN9VTX0TdJQuIq9VmVCC6fOt9Epx ix+mt1WTiYhgE5dY7HDD5WJht8hnOdwmsOZ0ig2EXt7P/5XrVfqmc+l7d6opoUlpR/ vZqZQB++8IUtoaIgyIn/GlFbzuaw1IFYl8rTMdAbecQjW8Ila8tLy0tiQKaiz0lTy9 aBnQjc9ccXekz6uqoHigBzgc3U1DsHa07ku8mSUtpsbESfxgKwfDvScxE17P4zrO7c UAag/X4BIOsm1m+Bixc2360zMzWEsBK5DTOS86uGD1LXG7N1ctA9axFj+sSnUO0ffI RZ0J49C6M5oUw== From: Shawn Anastasio To: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: bhelgaas@google.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, sbobroff@linux.ibm.com, xyjxie@linux.vnet.ibm.com, rppt@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] powerpc/64: Enable pcibios_after_init hook on ppc64 Date: Mon, 27 May 2019 20:54:11 -0500 Message-Id: <20190528015412.30521-3-shawn@anastas.io> In-Reply-To: <20190528015412.30521-1-shawn@anastas.io> References: <20190528015412.30521-1-shawn@anastas.io> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable the pcibios_after_init hook on all powerpc platforms. This hook is executed at the end of pcibios_init and was previously only available on CONFIG_PPC32. Since it is useful and not inherently limited to 32-bit mode, remove the limitation and allow it on all powerpc platforms. Signed-off-by: Shawn Anastasio --- arch/powerpc/include/asm/machdep.h | 3 +-- arch/powerpc/kernel/pci_64.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h index 2f0ca6560e47..2fbfaa9176ed 100644 --- a/arch/powerpc/include/asm/machdep.h +++ b/arch/powerpc/include/asm/machdep.h @@ -150,6 +150,7 @@ struct machdep_calls { void (*init)(void); void (*kgdb_map_scc)(void); +#endif /* CONFIG_PPC32 */ /* * optional PCI "hooks" @@ -157,8 +158,6 @@ struct machdep_calls { /* Called at then very end of pcibios_init() */ void (*pcibios_after_init)(void); -#endif /* CONFIG_PPC32 */ - /* Called in indirect_* to avoid touching devices */ int (*pci_exclude_device)(struct pci_controller *, unsigned char, unsigned char); diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index 9d8c10d55407..fba7fe6e4a50 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c @@ -68,6 +68,10 @@ static int __init pcibios_init(void) printk(KERN_DEBUG "PCI: Probing PCI hardware done\n"); + /* Call machine dependent post-init code */ + if (ppc_md.pcibios_after_init) + ppc_md.pcibios_after_init(); + return 0; } From patchwork Tue May 28 01:54:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Anastasio X-Patchwork-Id: 10963631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 258D31398 for ; Tue, 28 May 2019 01:54:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 147F4285E0 for ; Tue, 28 May 2019 01:54:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 054BA285F7; Tue, 28 May 2019 01:54:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 888D0285E0 for ; Tue, 28 May 2019 01:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbfE1ByV (ORCPT ); Mon, 27 May 2019 21:54:21 -0400 Received: from alpha.anastas.io ([104.248.188.109]:35907 "EHLO alpha.anastas.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727890AbfE1ByV (ORCPT ); Mon, 27 May 2019 21:54:21 -0400 Received: from authenticated-user (alpha.anastas.io [104.248.188.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alpha.anastas.io (Postfix) with ESMTPSA id 4DE997F8F9; Mon, 27 May 2019 20:54:19 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=anastas.io; s=mail; t=1559008460; bh=S+yWBPX56gfd9GxiSJQNtc5ODUe0FOjbu3z+0qj/29c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyf9Q8Z6xg0ysEC/qTcXj7HEMeWHbzE0s06MANDXAnsuBi38wlXhQrGcK6vLLNIm0 Y7IgJ4MStJzZB4qAMay5MRaL4bzraWcNmTOO8iZ2dZ/n0f2MKd788Hp6wWhouURh0m OnDXjA1OqKWM7kf30vLOmIwpeXTZpZxmVtLpRpOEjZoz8t08xKPJNwAEZjlGdH6um+ xokMNSqeVrqVt4LU6bQdfkv4JnM8c7i2Mn/KaQHuJWAQCc1a19PKGKmPFnwdzOmsNu kPwTvvbkypcduuXoNdARh2upcVQxQccxneXayHdxQ4c7R2JmuPJ11hkKOp0qyfoYkv VwOK6mi0QWWaA== From: Shawn Anastasio To: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: bhelgaas@google.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, sbobroff@linux.ibm.com, xyjxie@linux.vnet.ibm.com, rppt@linux.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] powerpc/pseries: Allow user-specified PCI resource alignment after init Date: Mon, 27 May 2019 20:54:12 -0500 Message-Id: <20190528015412.30521-4-shawn@anastas.io> In-Reply-To: <20190528015412.30521-1-shawn@anastas.io> References: <20190528015412.30521-1-shawn@anastas.io> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On pseries, custom PCI resource alignment specified with the commandline argument pci=resource_alignment is disabled due to PCI resources being managed by the firmware. However, in the case of PCI hotplug the resources are managed by the kernel, so custom alignments should be honored in these cases. This is done by only honoring custom alignments after initial PCI initialization is done, to ensure that all devices managed by the firmware are excluded. Without this ability, sub-page BARs sometimes get mapped in between page boundaries for hotplugged devices and are therefore unusable with the VFIO framework. This change allows users to request page alignment for devices they wish to access via VFIO using the pci=resource_alignment commandline argument. In the future, this could be extended to provide page-aligned resources by default for hotplugged devices, similar to what is done on powernv by commit 382746376993 ("powerpc/powernv: Override pcibios_default_alignment() to force PCI devices to be page aligned") Signed-off-by: Shawn Anastasio --- arch/powerpc/include/asm/machdep.h | 3 +++ arch/powerpc/kernel/pci-common.c | 9 +++++++++ arch/powerpc/platforms/pseries/setup.c | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h index 2fbfaa9176ed..46eb62c0954e 100644 --- a/arch/powerpc/include/asm/machdep.h +++ b/arch/powerpc/include/asm/machdep.h @@ -179,6 +179,9 @@ struct machdep_calls { resource_size_t (*pcibios_default_alignment)(void); + /* Called when determining PCI resource alignment */ + int (*pcibios_ignore_alignment_request)(void); + #ifdef CONFIG_PCI_IOV void (*pcibios_fixup_sriov)(struct pci_dev *pdev); resource_size_t (*pcibios_iov_resource_alignment)(struct pci_dev *, int resno); diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index ff4b7539cbdf..1a6ded45a701 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -238,6 +238,15 @@ resource_size_t pcibios_default_alignment(void) return 0; } +resource_size_t pcibios_ignore_alignment_request(void) +{ + if (ppc_md.pcibios_ignore_alignment_request) + return ppc_md.pcibios_ignore_alignment_request(); + + /* Fall back to default method of checking PCI_PROBE_ONLY */ + return pci_has_flag(PCI_PROBE_ONLY); +} + #ifdef CONFIG_PCI_IOV resource_size_t pcibios_iov_resource_alignment(struct pci_dev *pdev, int resno) { diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index e4f0dfd4ae33..07f03be02afe 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -82,6 +82,8 @@ EXPORT_SYMBOL(CMO_PageSize); int fwnmi_active; /* TRUE if an FWNMI handler is present */ +static int initial_pci_init_done; /* TRUE if initial pcibios init has completed */ + static void pSeries_show_cpuinfo(struct seq_file *m) { struct device_node *root; @@ -749,6 +751,23 @@ static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev, } #endif +static void pseries_after_init(void) +{ + initial_pci_init_done = 1; +} + +static int pseries_ignore_alignment_request(void) +{ + if (initial_pci_init_done) + /* + * Allow custom alignments after init for things + * like PCI hotplugging. + */ + return 0; + + return pci_has_flag(PCI_PROBE_ONLY); +} + static void __init pSeries_setup_arch(void) { set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT); @@ -797,6 +816,9 @@ static void __init pSeries_setup_arch(void) } ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare; + ppc_md.pcibios_after_init = pseries_after_init; + ppc_md.pcibios_ignore_alignment_request = + pseries_ignore_alignment_request; } static void pseries_panic(char *str)