Skip to contentSkip to conversation

riscv: fixup max_low_pfn with PFN_DOWN.

PATCH In review [email protected] 3 participants 7 messages Jan 12, 2019 – Jan 24, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: fixup max_low_pfn with PFN_DOWN.

From: Guo Ren <[email protected]>

max_low_pfn should be pfn_size not byte_size.

Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
---
 arch/riscv/kernel/setup.c | 2 +-
 arch/riscv/mm/init.c      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/riscv/kernel/setup.c +1 -1
index fc8006a..5463e67 100644
@@ -174,7 +174,7 @@ static void __init setup_bootmem(void)
 	BUG_ON(mem_size == 0);
 
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	setup_initrd();
arch/riscv/mm/init.c +2 -1
index 1d9bfaf..658ebf6 100644
@@ -28,7 +28,8 @@ static void __init zone_sizes_init(void)
 	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
 
 #ifdef CONFIG_ZONE_DMA32
-	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
+	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G,
+			(unsigned long) PFN_PHYS(max_low_pfn)));
 #endif
 	max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 18 lines · On Sat, Jan 12, 2019 at 04:16:27PM +0800, [email protected] wrote:

From: Guo Ren <[email protected]>

max_low_pfn should be pfn_size not byte_size.

Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
---
 arch/riscv/kernel/setup.c | 2 +-
 arch/riscv/mm/init.c      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/riscv/kernel/setup.c +0 -0
index fc8006a..5463e67 100644

arch/riscv/kernel/setup.c static void __init setup_bootmem(void) · line 177

Quoted 5 lines
arch/riscv/kernel/setup.c +1 -1
@@ -174,7 +174,7 @@ static void __init setup_bootmem(void)
 	BUG_ON(mem_size == 0);
 
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());

I know it is used just above, but can we please just switch this code to use >> PAGE_SHIFT instead of PFN_DOWN, which just horribly obsfucates what is going on?

Quoted 8 lines
arch/riscv/kernel/setup.c +0 -0
 #ifdef CONFIG_BLK_DEV_INITRD
 	setup_initrd();
arch/riscv/mm/init.c +0 -0
index 1d9bfaf..658ebf6 100644

arch/riscv/mm/init.c static void __init zone_sizes_init(void) · line 33

Quoted 7 lines
arch/riscv/mm/init.c +2 -1
@@ -28,7 +28,8 @@ static void __init zone_sizes_init(void)
 	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
 
 #ifdef CONFIG_ZONE_DMA32
-	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
+	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G,
+			(unsigned long) PFN_PHYS(max_low_pfn)));
 #endif

Same comment as above here, plus I think we should just use memblock_end_of_DRAM directly, e.g. something like:

static const phys_addr_t max_dma32_addr = 4UL * SZ_1G;

	max_zone_pfns[ZONE_DMA32] =
		min(memblock_end_of_DRAM(), max_dma32_addr) >> PAGE_SHIFT;
author
#2 lore raw
Quoted 21 lines · Christoph Hellwig
Quoted 20 lines · On Sat, Jan 12, 2019 at 04:16:27PM +0800, [email protected] wrote:

From: Guo Ren <[email protected]>

max_low_pfn should be pfn_size not byte_size.

Cc Palmer Dabbelt <[email protected]>
Cc Albert Ou <[email protected]>
---
 arch/riscv/kernel/setup.c | 2 +-
 arch/riscv/mm/init.c      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/riscv/kernel/setup.c +0 -0
index fc8006a..5463e67 100644
@@ -174,7 +174,7 @@ static void __init setup_bootmem(void)
 	BUG_ON(mem_size == 0);
 
Quoted 7 lines

arch/riscv/kernel/setup.c static void __init setup_bootmem(void) · line 177

Quoted 3 lines
arch/riscv/kernel/setup.c +1 -1
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());

I know it is used just above, but can we please just switch this code to use >> PAGE_SHIFT instead of PFN_DOWN, which just horribly obsfucates what is going on?

???
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)

phys_addr_t __init_memblock memblock_end_of_DRAM(void)

{
	int idx = memblock.memory.cnt - 1;

	return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
}

What's the problem? PFN_DOWN() couldn't be used with function call?

Quoted 20 lines
Quoted 9 lines
arch/riscv/kernel/setup.c +0 -0
 #ifdef CONFIG_BLK_DEV_INITRD
 	setup_initrd();
arch/riscv/mm/init.c +0 -0
index 1d9bfaf..658ebf6 100644

arch/riscv/mm/init.c static void __init zone_sizes_init(void) · line 33

Quoted 7 lines
arch/riscv/mm/init.c +2 -1
@@ -28,7 +28,8 @@ static void __init zone_sizes_init(void)
 	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
 
 #ifdef CONFIG_ZONE_DMA32
-	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
+	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G,
+			(unsigned long) PFN_PHYS(max_low_pfn)));
 #endif

Same comment as above here, plus I think we should just use memblock_end_of_DRAM directly, e.g. something like:

Quoted 4 lines

static const phys_addr_t max_dma32_addr = 4UL * SZ_1G;

	max_zone_pfns[ZONE_DMA32] =
		min(memblock_end_of_DRAM(), max_dma32_addr) >> PAGE_SHIFT;

Em... The meaning of PFN_PHYS(max_low_pfn) != memblock_end_of_DRAM() in 32-bit highmem system. Of cause, riscv doesn't support highmem, so I think memblock_end_of_DRAM() is also OK.

But...

static void __init zone_sizes_init(void)

{
	unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
#ifdef CONFIG_ZONE_DMA32
	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(min(4UL * SZ_1G, max_low_pfn));
#endif
	max_zone_pfns[ZONE_NORMAL] = max_low_pfn;

	free_area_init_nodes(max_zone_pfns);
}

The max_low_pfn also used by ZONE_NORMAL, So shall we need change that?

	max_zone_pfns[ZONE_NORMAL] = PFN_DOWN(memblock_end_of_DRAM());
                                     ^^^^^^^^ also must >> PAGE_SHIFT?

My patch just want to point out that max_low_pfn is PFN not size. In fact there is no error for running without my patch :P

Best Regards
Guo Ren

#3 lore raw
Quoted 10 lines · Guo Ren
Quoted 7 lines

arch/riscv/kernel/setup.c static void __init setup_bootmem(void) · line 177

Quoted 3 lines
arch/riscv/kernel/setup.c +1 -1
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());

I know it is used just above, but can we please just switch this code to use >> PAGE_SHIFT instead of PFN_DOWN, which just horribly obsfucates what is going on?

???
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)

Quoted 8 lines

phys_addr_t __init_memblock memblock_end_of_DRAM(void)

{
	int idx = memblock.memory.cnt - 1;

	return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
}

What's the problem? PFN_DOWN() couldn't be used with function call?

PFN_DOWN gives you the correct result. But I think it actually drastically reduces readability over just opencoding it.

Quoted 2 lines

My patch just want to point out that max_low_pfn is PFN not size. In fact there is no error for running without my patch :P

No, I think your patch is correct. I just wonder if we could make the code easier to read.

author
#4 lore raw

Hi Christoph,

I use PFN_DOWN() every where as possible and seems it's a habit problem. So let risc-v maintainer to choose "PFN_DOW()" or ">> PAGE_SHIFT".

Also the same with "end_of_DRAM & max_low_pfn".

Best Regards
Guo Ren

Quoted 28 lines · Christoph Hellwig
Quoted 10 lines · Guo Ren
Quoted 7 lines

arch/riscv/kernel/setup.c static void __init setup_bootmem(void) · line 177

Quoted 3 lines
arch/riscv/kernel/setup.c +1 -1
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());

I know it is used just above, but can we please just switch this code to use >> PAGE_SHIFT instead of PFN_DOWN, which just horribly obsfucates what is going on?

???
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)

Quoted 8 lines

phys_addr_t __init_memblock memblock_end_of_DRAM(void)

{
	int idx = memblock.memory.cnt - 1;

	return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
}

What's the problem? PFN_DOWN() couldn't be used with function call?

PFN_DOWN gives you the correct result. But I think it actually drastically reduces readability over just opencoding it.

Quoted 2 lines

My patch just want to point out that max_low_pfn is PFN not size. In fact there is no error for running without my patch :P

No, I think your patch is correct. I just wonder if we could make the code easier to read.

#5 lore raw
Quoted 7 lines · On Tue, 15 Jan 2019 17:07:38 PST (-0800), [email protected] wrote:

Hi Christoph,

I use PFN_DOWN() every where as possible and seems it's a habit problem. So let risc-v maintainer to choose "PFN_DOW()" or ">> PAGE_SHIFT".

Also the same with "end_of_DRAM & max_low_pfn".

PFN_DOWN makes sense to me, as that's what we're trying to do here (round a physical address down to page frame number). Am a I misunderstanding something?

Quoted 33 lines

Best Regards
Guo Ren

Quoted 28 lines · Christoph Hellwig
Quoted 10 lines · Guo Ren
Quoted 7 lines

arch/riscv/kernel/setup.c static void __init setup_bootmem(void) · line 177

Quoted 3 lines
arch/riscv/kernel/setup.c +1 -1
 	set_max_mapnr(PFN_DOWN(mem_size));
-	max_low_pfn = memblock_end_of_DRAM();
+	max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());

I know it is used just above, but can we please just switch this code to use >> PAGE_SHIFT instead of PFN_DOWN, which just horribly obsfucates what is going on?

???
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)

Quoted 8 lines

phys_addr_t __init_memblock memblock_end_of_DRAM(void)

{
	int idx = memblock.memory.cnt - 1;

	return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
}

What's the problem? PFN_DOWN() couldn't be used with function call?

PFN_DOWN gives you the correct result. But I think it actually drastically reduces readability over just opencoding it.

Quoted 2 lines

My patch just want to point out that max_low_pfn is PFN not size. In fact there is no error for running without my patch :P

No, I think your patch is correct. I just wonder if we could make the code easier to read.

author
#6 lore raw
Quoted 7 lines · Palmer Dabbelt
Quoted 6 lines · On Tue, 15 Jan 2019 17:07:38 PST (-0800), [email protected] wrote:

Hi Christoph,

I use PFN_DOWN() every where as possible and seems it's a habit problem. So let risc-v maintainer to choose "PFN_DOW()" or ">> PAGE_SHIFT".

Quoted 6 lines
Quoted 1 line

Also the same with "end_of_DRAM & max_low_pfn".

PFN_DOWN makes sense to me, as that's what we're trying to do here (round a physical address down to page frame number). Am a I misunderstanding something?

No, you got it :)

Best Regards
Guo Ren