linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: linuxppc-dev@lists.ozlabs.org, iommu@lists.linux-foundation.org,
	linux-mm@kvack.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 01/33] powerpc: use mm zones more sensibly
Date: Tue,  9 Oct 2018 15:24:28 +0200	[thread overview]
Message-ID: <20181009132500.17643-2-hch@lst.de> (raw)
In-Reply-To: <20181009132500.17643-1-hch@lst.de>

Powerpc has somewhat odd usage where ZONE_DMA is used for all memory on
common 64-bit configfs, and ZONE_DMA32 is used for 31-bit schemes.

Move to a scheme closer to what other architectures use (and I dare to
say the intent of the system):

 - ZONE_DMA: optionally for memory < 31-bit
 - ZONE_NORMAL: everything addressable by the kernel
 - ZONE_HIGHMEM: memory > 32-bit for 32-bit kernels

Also provide information on how ZONE_DMA is used by defining
ARCH_ZONE_DMA_BITS.

Contains various fixes from Benjamin Herrenschmidt.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/powerpc/Kconfig                          |  6 +--
 arch/powerpc/include/asm/page.h               |  2 +
 arch/powerpc/include/asm/pgtable.h            |  1 -
 arch/powerpc/kernel/dma-swiotlb.c             |  6 +--
 arch/powerpc/kernel/dma.c                     |  7 +--
 arch/powerpc/mm/mem.c                         | 50 +++++++------------
 arch/powerpc/platforms/85xx/corenet_generic.c | 10 ----
 arch/powerpc/platforms/85xx/qemu_e500.c       |  9 ----
 include/linux/mmzone.h                        |  2 +-
 9 files changed, 24 insertions(+), 69 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index a80669209155..06996df07cad 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -380,7 +380,7 @@ config PPC_ADV_DEBUG_DAC_RANGE
 	depends on PPC_ADV_DEBUG_REGS && 44x
 	default y
 
-config ZONE_DMA32
+config ZONE_DMA
 	bool
 	default y if PPC64
 
@@ -879,10 +879,6 @@ config ISA
 	  have an IBM RS/6000 or pSeries machine, say Y.  If you have an
 	  embedded board, consult your board documentation.
 
-config ZONE_DMA
-	bool
-	default y
-
 config GENERIC_ISA_DMA
 	bool
 	depends on ISA_DMA_API
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index f6a1265face2..fc8c9ac0c6be 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -354,4 +354,6 @@ typedef struct page *pgtable_t;
 #endif /* __ASSEMBLY__ */
 #include <asm/slice.h>
 
+#define ARCH_ZONE_DMA_BITS 31
+
 #endif /* _ASM_POWERPC_PAGE_H */
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index 14c79a7dc855..9bafb38e959e 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -37,7 +37,6 @@ extern unsigned long empty_zero_page[];
 
 extern pgd_t swapper_pg_dir[];
 
-void limit_zone_pfn(enum zone_type zone, unsigned long max_pfn);
 int dma_pfn_limit_to_zone(u64 pfn_limit);
 extern void paging_init(void);
 
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
index 88f3963ca30f..93a4622563c6 100644
--- a/arch/powerpc/kernel/dma-swiotlb.c
+++ b/arch/powerpc/kernel/dma-swiotlb.c
@@ -108,12 +108,8 @@ int __init swiotlb_setup_bus_notifier(void)
 
 void __init swiotlb_detect_4g(void)
 {
-	if ((memblock_end_of_DRAM() - 1) > 0xffffffff) {
+	if ((memblock_end_of_DRAM() - 1) > 0xffffffff)
 		ppc_swiotlb_enable = 1;
-#ifdef CONFIG_ZONE_DMA32
-		limit_zone_pfn(ZONE_DMA32, (1ULL << 32) >> PAGE_SHIFT);
-#endif
-	}
 }
 
 static int __init check_swiotlb_enabled(void)
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index dbfc7056d7df..6551685a4ed0 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -50,7 +50,7 @@ static int dma_nommu_dma_supported(struct device *dev, u64 mask)
 		return 1;
 
 #ifdef CONFIG_FSL_SOC
-	/* Freescale gets another chance via ZONE_DMA/ZONE_DMA32, however
+	/* Freescale gets another chance via ZONE_DMA, however
 	 * that will have to be refined if/when they support iommus
 	 */
 	return 1;
@@ -94,13 +94,10 @@ void *__dma_nommu_alloc_coherent(struct device *dev, size_t size,
 	}
 
 	switch (zone) {
+#ifdef CONFIG_ZONE_DMA
 	case ZONE_DMA:
 		flag |= GFP_DMA;
 		break;
-#ifdef CONFIG_ZONE_DMA32
-	case ZONE_DMA32:
-		flag |= GFP_DMA32;
-		break;
 #endif
 	};
 #endif /* CONFIG_FSL_SOC */
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 5c8530d0c611..8bff7e893bde 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -69,15 +69,12 @@ pte_t *kmap_pte;
 EXPORT_SYMBOL(kmap_pte);
 pgprot_t kmap_prot;
 EXPORT_SYMBOL(kmap_prot);
-#define TOP_ZONE ZONE_HIGHMEM
 
 static inline pte_t *virt_to_kpte(unsigned long vaddr)
 {
 	return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr),
 			vaddr), vaddr), vaddr);
 }
-#else
-#define TOP_ZONE ZONE_NORMAL
 #endif
 
 int page_is_ram(unsigned long pfn)
@@ -246,35 +243,19 @@ static int __init mark_nonram_nosave(void)
 }
 #endif
 
-static bool zone_limits_final;
-
-/*
- * The memory zones past TOP_ZONE are managed by generic mm code.
- * These should be set to zero since that's what every other
- * architecture does.
- */
-static unsigned long max_zone_pfns[MAX_NR_ZONES] = {
-	[0            ... TOP_ZONE        ] = ~0UL,
-	[TOP_ZONE + 1 ... MAX_NR_ZONES - 1] = 0
-};
-
 /*
- * Restrict the specified zone and all more restrictive zones
- * to be below the specified pfn.  May not be called after
- * paging_init().
+ * Zones usage:
+ *
+ * We setup ZONE_DMA to be 31-bits on all platforms and ZONE_NORMAL to be
+ * everything else. GFP_DMA32 page allocations automatically fall back to
+ * ZONE_DMA.
+ *
+ * By using 31-bit unconditionally, we can exploit ARCH_ZONE_DMA_BITS to
+ * inform the generic DMA mapping code.  32-bit only devices (if not handled
+ * by an IOMMU anyway) will take a first dip into ZONE_NORMAL and get
+ * otherwise served by ZONE_DMA.
  */
-void __init limit_zone_pfn(enum zone_type zone, unsigned long pfn_limit)
-{
-	int i;
-
-	if (WARN_ON(zone_limits_final))
-		return;
-
-	for (i = zone; i >= 0; i--) {
-		if (max_zone_pfns[i] > pfn_limit)
-			max_zone_pfns[i] = pfn_limit;
-	}
-}
+static unsigned long max_zone_pfns[MAX_NR_ZONES];
 
 /*
  * Find the least restrictive zone that is entirely below the
@@ -324,11 +305,14 @@ void __init paging_init(void)
 	printk(KERN_DEBUG "Memory hole size: %ldMB\n",
 	       (long int)((top_of_ram - total_ram) >> 20));
 
+#ifdef CONFIG_ZONE_DMA
+	max_zone_pfns[ZONE_DMA]	= min(max_low_pfn, 0x7fffffffUL >> PAGE_SHIFT);
+#endif
+	max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
 #ifdef CONFIG_HIGHMEM
-	limit_zone_pfn(ZONE_NORMAL, lowmem_end_addr >> PAGE_SHIFT);
+	max_zone_pfns[ZONE_HIGHMEM] = max_pfn
 #endif
-	limit_zone_pfn(TOP_ZONE, top_of_ram >> PAGE_SHIFT);
-	zone_limits_final = true;
+
 	free_area_init_nodes(max_zone_pfns);
 
 	mark_nonram_nosave();
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c b/arch/powerpc/platforms/85xx/corenet_generic.c
index ac191a7a1337..b0dac307bebf 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -68,16 +68,6 @@ void __init corenet_gen_setup_arch(void)
 
 	swiotlb_detect_4g();
 
-#if defined(CONFIG_FSL_PCI) && defined(CONFIG_ZONE_DMA32)
-	/*
-	 * Inbound windows don't cover the full lower 4 GiB
-	 * due to conflicts with PCICSRBAR and outbound windows,
-	 * so limit the DMA32 zone to 2 GiB, to allow consistent
-	 * allocations to succeed.
-	 */
-	limit_zone_pfn(ZONE_DMA32, 1UL << (31 - PAGE_SHIFT));
-#endif
-
 	pr_info("%s board\n", ppc_md.name);
 
 	mpc85xx_qe_init();
diff --git a/arch/powerpc/platforms/85xx/qemu_e500.c b/arch/powerpc/platforms/85xx/qemu_e500.c
index b63a8548366f..27631c607f3d 100644
--- a/arch/powerpc/platforms/85xx/qemu_e500.c
+++ b/arch/powerpc/platforms/85xx/qemu_e500.c
@@ -45,15 +45,6 @@ static void __init qemu_e500_setup_arch(void)
 
 	fsl_pci_assign_primary();
 	swiotlb_detect_4g();
-#if defined(CONFIG_FSL_PCI) && defined(CONFIG_ZONE_DMA32)
-	/*
-	 * Inbound windows don't cover the full lower 4 GiB
-	 * due to conflicts with PCICSRBAR and outbound windows,
-	 * so limit the DMA32 zone to 2 GiB, to allow consistent
-	 * allocations to succeed.
-	 */
-	limit_zone_pfn(ZONE_DMA32, 1UL << (31 - PAGE_SHIFT));
-#endif
 	mpc85xx_smp_init();
 }
 
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 1e22d96734e0..68970340df1c 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -312,7 +312,7 @@ enum zone_type {
 	 * Architecture		Limit
 	 * ---------------------------
 	 * parisc, ia64, sparc	<4G
-	 * s390			<2G
+	 * s390, powerpc	<2G
 	 * arm			Various
 	 * alpha		Unlimited or 0-16MB.
 	 *
-- 
2.19.0

  parent reply	other threads:[~2018-10-09 13:24 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 13:24 use generic DMA mapping code in powerpc V3 Christoph Hellwig
2018-10-09 13:24 ` Christoph Hellwig
2018-10-09 13:24 ` Christoph Hellwig [this message]
2018-10-09 13:24   ` [PATCH 01/33] powerpc: use mm zones more sensibly Christoph Hellwig
     [not found]   ` <20181009132500.17643-2-hch-jcswGhMUV9g@public.gmane.org>
2018-10-15  0:47     ` Benjamin Herrenschmidt
2018-10-15  0:47       ` Benjamin Herrenschmidt
2018-10-09 13:24 ` [PATCH 03/33] powerpc/dma: remove the unused ISA_DMA_THRESHOLD export Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 04/33] powerpc/dma: remove the unused dma_iommu_ops export Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 05/33] powerpc/dma: split the two __dma_alloc_coherent implementations Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 06/33] powerpc/dma: remove the no-op dma_nommu_unmap_{page,sg} routines Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 07/33] powerpc/dma: untangle vio_dma_mapping_ops from dma_iommu_ops Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 09/33] powerpc/pseries: unwind dma_get_required_mask_pSeriesLP a bit Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 10/33] powerpc/pseries: use the generic iommu bypass code Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 11/33] powerpc/cell: move dma direct window setup out of dma_configure Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 12/33] powerpc/cell: use the generic iommu bypass code Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 14/33] powerpc/dart: " Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 15/33] powerpc/powernv: remove pnv_pci_ioda_pe_single_vendor Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 16/33] powerpc/powernv: remove dead npu-dma code Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
     [not found]   ` <20181009132500.17643-17-hch-jcswGhMUV9g@public.gmane.org>
2018-10-15  1:34     ` Alexey Kardashevskiy
2018-10-15  1:34       ` Alexey Kardashevskiy
     [not found]       ` <7709932d-efb8-2c9b-5128-99cc491c302b-sLpHqDYs0B2HXe+LvDLADg@public.gmane.org>
2018-10-15  2:45         ` Benjamin Herrenschmidt
2018-10-15  2:45           ` Benjamin Herrenschmidt
2018-10-15  5:50       ` Christoph Hellwig
2018-10-15  5:50         ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 17/33] powerpc/powernv: use the generic iommu bypass code Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
     [not found] ` <20181009132500.17643-1-hch-jcswGhMUV9g@public.gmane.org>
2018-10-09 13:24   ` [PATCH 02/33] powerpc/dma: remove the unused ARCH_HAS_DMA_MMAP_COHERENT define Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24   ` [PATCH 08/33] powerpc/dma: handle iommu bypass in dma_iommu_ops Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24   ` [PATCH 13/33] powerpc/dart: remove dead cleanup code in iommu_init_early_dart Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24   ` [PATCH 18/33] powerpc/dma: stop overriding dma_get_required_mask Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24   ` [PATCH 19/33] powerpc/pci: remove the dma_set_mask pci_controller ops methods Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24   ` [PATCH 20/33] powerpc/dma: remove the iommu fallback for coherent allocations Christoph Hellwig
2018-10-09 13:24     ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 21/33] powerpc/dma: remove get_pci_dma_ops Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 22/33] powerpc/dma: move pci_dma_dev_setup_swiotlb to fsl_pci.c Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 23/33] powerpc/dma: remove max_direct_dma_addr Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 24/33] powerpc/dma: fix an off-by-one in dma_capable Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 25/33] cxl: drop the dma_set_mask callback from vphb Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 26/33] powerpc/fsl_pci: simplify fsl_pci_dma_set_mask Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 27/33] dma-mapping, powerpc: simplify the arch dma_set_mask override Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 28/33] powerpc/dma: use phys_to_dma instead of get_dma_offset Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 29/33] powerpc/dma: remove get_dma_offset Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 30/33] powerpc/dma: remove set_dma_offset Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 31/33] powerpc/dma: remove dma_nommu_mmap_coherent Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:24 ` [PATCH 32/33] powerpc/dma: use generic direct and swiotlb ops Christoph Hellwig
2018-10-09 13:24   ` Christoph Hellwig
2018-10-09 13:25 ` [PATCH 33/33] powerpc/dma: trim the fat from <asm/dma-mapping.h> Christoph Hellwig
2018-10-09 13:25   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181009132500.17643-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=benh@kernel.crashing.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --subject='Re: [PATCH 01/33] powerpc: use mm zones more sensibly' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox