linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM
@ 2018-03-28  0:25 Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory Jonathan Neuschäfer
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer

v1: https://www.spinics.net/lists/linux-mm/msg145939.html

This patchset makes it possible to allocate MMIO ranges that are between
the two RAM chunks on the Wii, MEM1 and MEM2, not only with ioremap
(which previously worked through a hack) but also with kernel/resource.c.

Changes in v2:
- I added back the p < virt_to_phys(high_memory) check in
  __ioremap_caller because high memory should be allocatable through
  ioremap
- I expanded the commit messages a bit

Jonathan Neuschäfer (5):
  powerpc: mm: Simplify page_is_ram by using memblock_is_memory
  powerpc: mm: Use memblock API for PPC32 page_is_ram
  powerpc/mm/32: Use page_is_ram to check for RAM
  powerpc: wii: Don't rely on the reserved memory hack
  powerpc/mm/32: Remove the reserved memory hack

 arch/powerpc/mm/init_32.c                |  5 -----
 arch/powerpc/mm/mem.c                    | 12 +-----------
 arch/powerpc/mm/mmu_decl.h               |  1 -
 arch/powerpc/mm/pgtable_32.c             |  2 +-
 arch/powerpc/platforms/embedded6xx/wii.c | 14 +-------------
 5 files changed, 3 insertions(+), 31 deletions(-)

-- 
2.16.2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory
  2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
@ 2018-03-28  0:25 ` Jonathan Neuschäfer
  2018-03-31 14:04   ` [v2, " Michael Ellerman
  2018-03-28  0:25 ` [PATCH v2 2/5] powerpc: mm: Use memblock API for PPC32 page_is_ram Jonathan Neuschäfer
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer, Benjamin Herrenschmidt, Paul Mackerras,
	Michal Hocko, Andrew Morton, Vlastimil Babka, Joe Perches,
	Oliver O'Halloran

Instead of open-coding the search in page_is_ram, call memblock_is_memory.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---

v2: no changes
---
 arch/powerpc/mm/mem.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index fe8c61149fb8..da4e1555d61d 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -85,13 +85,7 @@ int page_is_ram(unsigned long pfn)
 #ifndef CONFIG_PPC64	/* XXX for now */
 	return pfn < max_pfn;
 #else
-	unsigned long paddr = (pfn << PAGE_SHIFT);
-	struct memblock_region *reg;
-
-	for_each_memblock(memory, reg)
-		if (paddr >= reg->base && paddr < (reg->base + reg->size))
-			return 1;
-	return 0;
+	return memblock_is_memory(__pfn_to_phys(pfn));
 #endif
 }
 
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/5] powerpc: mm: Use memblock API for PPC32 page_is_ram
  2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory Jonathan Neuschäfer
@ 2018-03-28  0:25 ` Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 3/5] powerpc/mm/32: Use page_is_ram to check for RAM Jonathan Neuschäfer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer, Benjamin Herrenschmidt, Paul Mackerras,
	Michal Hocko, Andrew Morton, Vlastimil Babka, Dan Williams,
	Joe Perches, Oliver O'Halloran

To support accurate checking for different blocks of memory on PPC32,
use the same memblock-based approach that's already used on PPC64 also
on PPC32.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---

v2: no changes
---
 arch/powerpc/mm/mem.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index da4e1555d61d..a42b86e2a34c 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -82,11 +82,7 @@ static inline pte_t *virt_to_kpte(unsigned long vaddr)
 
 int page_is_ram(unsigned long pfn)
 {
-#ifndef CONFIG_PPC64	/* XXX for now */
-	return pfn < max_pfn;
-#else
 	return memblock_is_memory(__pfn_to_phys(pfn));
-#endif
 }
 
 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/5] powerpc/mm/32: Use page_is_ram to check for RAM
  2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 2/5] powerpc: mm: Use memblock API for PPC32 page_is_ram Jonathan Neuschäfer
@ 2018-03-28  0:25 ` Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 4/5] powerpc: wii: Don't rely on the reserved memory hack Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 5/5] powerpc/mm/32: Remove " Jonathan Neuschäfer
  4 siblings, 0 replies; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer, Benjamin Herrenschmidt, Paul Mackerras,
	Balbir Singh, Guenter Roeck

On systems where there is MMIO space between different blocks of RAM in
the physical address space, __ioremap_caller did not allow mapping these
MMIO areas, because they were below the end RAM and thus considered RAM
as well.  Use the memblock-based page_is_ram function, which returns
false for such MMIO holes.

v2:
  Keep the check for p < virt_to_phys(high_memory). On 32-bit systems
  with high memory (memory above physical address 4GiB), the high memory
  is expected to be available though ioremap. The high_memory variable
  marks the end of low memory; comparing against it means that only
  ioremap requests for low RAM will be denied.
  Reported by Michael Ellerman.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---
 arch/powerpc/mm/pgtable_32.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index d35d9ad3c1cd..6668ecc041ad 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -148,6 +148,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, unsigned long flags,
 	 * mem_init() sets high_memory so only do the check after that.
 	 */
 	if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
+	    page_is_ram(__phys_to_pfn(p)) &&
 	    !(__allow_ioremap_reserved && memblock_is_region_reserved(p, size))) {
 		printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
 		       (unsigned long long)p, __builtin_return_address(0));
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/5] powerpc: wii: Don't rely on the reserved memory hack
  2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
                   ` (2 preceding siblings ...)
  2018-03-28  0:25 ` [PATCH v2 3/5] powerpc/mm/32: Use page_is_ram to check for RAM Jonathan Neuschäfer
@ 2018-03-28  0:25 ` Jonathan Neuschäfer
  2018-03-28  0:25 ` [PATCH v2 5/5] powerpc/mm/32: Remove " Jonathan Neuschäfer
  4 siblings, 0 replies; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer, Benjamin Herrenschmidt, Paul Mackerras

Because the two memory blocks (usually called MEM1 and MEM2) are not
merged anymore, __request_region in kernel/resource.c will correctly
allow reserving regions in the physical address space between MEM1 and
MEM2, where many important peripherals are (GPIO, MMC, USB, ...).

A previous change to __ioremap_caller in arch/powerpc/mm/pgtable_32.c
ensures that multiple memblocks are properly considered in ioremap; this
makes it unnecessary to set __allow_ioremap_reserved.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---

v2:
Add some text to the commit message.
---
 arch/powerpc/platforms/embedded6xx/wii.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/wii.c b/arch/powerpc/platforms/embedded6xx/wii.c
index 4682327f76a9..fc00d82691e1 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -81,21 +81,9 @@ void __init wii_memory_fixups(void)
 	BUG_ON(memblock.memory.cnt != 2);
 	BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
 
-	/* trim unaligned tail */
-	memblock_remove(ALIGN(p[1].base + p[1].size, PAGE_SIZE),
-			(phys_addr_t)ULLONG_MAX);
-
-	/* determine hole, add & reserve them */
+	/* determine hole */
 	wii_hole_start = ALIGN(p[0].base + p[0].size, PAGE_SIZE);
 	wii_hole_size = p[1].base - wii_hole_start;
-	memblock_add(wii_hole_start, wii_hole_size);
-	memblock_reserve(wii_hole_start, wii_hole_size);
-
-	BUG_ON(memblock.memory.cnt != 1);
-	__memblock_dump_all();
-
-	/* allow ioremapping the address space in the hole */
-	__allow_ioremap_reserved = 1;
 }
 
 unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/5] powerpc/mm/32: Remove the reserved memory hack
  2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
                   ` (3 preceding siblings ...)
  2018-03-28  0:25 ` [PATCH v2 4/5] powerpc: wii: Don't rely on the reserved memory hack Jonathan Neuschäfer
@ 2018-03-28  0:25 ` Jonathan Neuschäfer
  4 siblings, 0 replies; 7+ messages in thread
From: Jonathan Neuschäfer @ 2018-03-28  0:25 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: linux-kernel, Michael Ellerman, Christophe Leroy,
	Jonathan Neuschäfer, Benjamin Herrenschmidt, Paul Mackerras,
	Aneesh Kumar K.V, Mathieu Malaterre, Balbir Singh, Guenter Roeck

This hack, introduced in commit c5df7f775148 ("powerpc: allow ioremap
within reserved memory regions") is now unnecessary.

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
---

v2: no changes
---
 arch/powerpc/mm/init_32.c    | 5 -----
 arch/powerpc/mm/mmu_decl.h   | 1 -
 arch/powerpc/mm/pgtable_32.c | 3 +--
 3 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index a2bf6965d04f..3e59e5d64b01 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -88,11 +88,6 @@ void MMU_init(void);
 int __map_without_bats;
 int __map_without_ltlbs;
 
-/*
- * This tells the system to allow ioremapping memory marked as reserved.
- */
-int __allow_ioremap_reserved;
-
 /* max amount of low RAM to map in */
 unsigned long __max_low_memory = MAX_LOW_MEM;
 
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index 57fbc554c785..c4c0a09a7775 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -98,7 +98,6 @@ extern void setbat(int index, unsigned long virt, phys_addr_t phys,
 		   unsigned int size, pgprot_t prot);
 
 extern int __map_without_bats;
-extern int __allow_ioremap_reserved;
 extern unsigned int rtas_data, rtas_size;
 
 struct hash_pte;
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index 6668ecc041ad..120a49bfb9c6 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -148,8 +148,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, unsigned long flags,
 	 * mem_init() sets high_memory so only do the check after that.
 	 */
 	if (slab_is_available() && (p < virt_to_phys(high_memory)) &&
-	    page_is_ram(__phys_to_pfn(p)) &&
-	    !(__allow_ioremap_reserved && memblock_is_region_reserved(p, size))) {
+	    page_is_ram(__phys_to_pfn(p))) {
 		printk("__ioremap(): phys addr 0x%llx is RAM lr %ps\n",
 		       (unsigned long long)p, __builtin_return_address(0));
 		return NULL;
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [v2, 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory
  2018-03-28  0:25 ` [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory Jonathan Neuschäfer
@ 2018-03-31 14:04   ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2018-03-31 14:04 UTC (permalink / raw)
  To: Jonathan Neuschäfer, linuxppc-dev
  Cc: Michal Hocko, linux-kernel, Jonathan Neuschäfer,
	Paul Mackerras, Joe Perches, Oliver O'Halloran,
	Andrew Morton, Vlastimil Babka

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 336 bytes --]

On Wed, 2018-03-28 at 00:25:40 UTC, =?utf-8?q?Jonathan_Neusch=C3=A4fer?= wrote:
> Instead of open-coding the search in page_is_ram, call memblock_is_memory.
> 
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/2615c93e5f52db62586112793d889f

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-31 14:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28  0:25 [PATCH v2 0/5] PPC32/ioremap: Use memblock API to check for RAM Jonathan Neuschäfer
2018-03-28  0:25 ` [PATCH v2 1/5] powerpc: mm: Simplify page_is_ram by using memblock_is_memory Jonathan Neuschäfer
2018-03-31 14:04   ` [v2, " Michael Ellerman
2018-03-28  0:25 ` [PATCH v2 2/5] powerpc: mm: Use memblock API for PPC32 page_is_ram Jonathan Neuschäfer
2018-03-28  0:25 ` [PATCH v2 3/5] powerpc/mm/32: Use page_is_ram to check for RAM Jonathan Neuschäfer
2018-03-28  0:25 ` [PATCH v2 4/5] powerpc: wii: Don't rely on the reserved memory hack Jonathan Neuschäfer
2018-03-28  0:25 ` [PATCH v2 5/5] powerpc/mm/32: Remove " Jonathan Neuschäfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).