Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4542100ybi; Mon, 27 May 2019 21:06:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwb3r6Xx4DS3t8Jj3/8SO9xh9qf9W5PVDLTnCZaYVgE60etIcrT9o/m5mErfMW45zuniDo/ X-Received: by 2002:a17:902:624:: with SMTP id 33mr8740459plg.325.1559016407988; Mon, 27 May 2019 21:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559016407; cv=none; d=google.com; s=arc-20160816; b=UWolMhS1sFarDVQg4lFwmKsUg0FVadeqWni69GXN35wTezIKKSf7JMkLlyQEeINqQ6 3/wUAquCqnC0YNNanURnbH+YX0BU1SPBpQHdI51oCFUHlHm6PPZN46p0JM621JOnaRTa xo9ETUzCWGV4LJ4cvlcrGMOeLEx4RaCypnIUW62F6BusGsjYQcfvQdomPSzSI1F5QhqW bBP7zcsN2DDQsg142NXBl37dGHwQFpjpu8SHTDF1N1e73oKMi3chveZ3lOHvnZrbBz6t qy9Uk6vw6dw3PmQRf/oqQFCxBtPqtvPNefO44/y4NsdQxo6XMYfNf+4oXixCps2ptxv6 cUjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xBHTBzMGJ4JNNuBMLQzxFwPrR3/+8GC9j0HwyTq4l2k=; b=f8UKr/h+9CLxUHzGQjroxX37loMimoo5AwymMtyKwvdXgzTtw2jK3vAQv4zULAD4T/ LkImLrutMFH0/ezJTMNK5tFG8+lOznbSJJ0WO8jsE+/vZCDI2l6DP5JpGRgQb8s3ohDP Q4MJ/tUPdYGpmXudhGnEZ65cAhxNsHVFV4CsA8wQDZaSP+jvNciHMlp6QnljTgIkcJTk OXX4XW98JazdwG+2c1/qmj1B2b+GNlqby9mpw4THG7AfFkwi0r3nD7/qfwpcahUZkv5V R2FsT9mTRE6imWjod7NWYRKuEVInWbfRtXCi06k5jGfCMEOARsWdbpAu/mL3TRs/GL5q Gi6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@anastas.io header.s=mail header.b=S0LRDY54; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=anastas.io Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g73si12581487pfb.282.2019.05.27.21.06.32; Mon, 27 May 2019 21:06:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@anastas.io header.s=mail header.b=S0LRDY54; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=anastas.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727645AbfE1EDd (ORCPT + 99 others); Tue, 28 May 2019 00:03:33 -0400 Received: from alpha.anastas.io ([104.248.188.109]:39219 "EHLO alpha.anastas.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727111AbfE1EDX (ORCPT ); Tue, 28 May 2019 00:03:23 -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 479367F8F9; Mon, 27 May 2019 23:03:22 -0500 (CDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=anastas.io; s=mail; t=1559016203; bh=d7HSj1NeiZzN0IBJ4m95CWLCN7fcLkCyyM2sJV0Fuxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S0LRDY54DafHLUD4yrYY7MWwE7LixJzPImPGQVlhthp6CDeOGpNuDni5ud9Isc1aW z5pPl3ifzkyHMF8vi23njGBNXh3B5MPVwo+Z/Px2t/tMlq08Uw/B5X5W3aw3a0NMKP WB8F10Z46YIjGM3Zbu1w+iAwwf6cXVkYsfNcAtOHsRd2HWKXEkrs+0kpSb51jxV/Lr YrE+B2F8b654IBPCIg6c/lqP0ASpslV/yGY+CTTJDHfJ5sYc6KxeOs2gauObfC73lC /EGvH6utCSYZXFd4fKQl9ZEUF92mnKBs5jmbzah2j1mW/PpakeEP8PgoE7BP5o2vTl RnW20pxCO8Dcw== 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 v3 3/3] powerpc/pseries: Allow user-specified PCI resource alignment after init Date: Mon, 27 May 2019 23:03:13 -0500 Message-Id: <20190528040313.35582-4-shawn@anastas.io> In-Reply-To: <20190528040313.35582-1-shawn@anastas.io> References: <20190528040313.35582-1-shawn@anastas.io> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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..8e0d73b4c188 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; } +int 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) -- 2.20.1