Re: [PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()
Hi! On Tue, Apr 21, 2020 at 01:04:05AM +, Joel Stanley wrote: > On Mon, 20 Apr 2020 at 18:38, Christophe Leroy > wrote: > > _ALIGN_DOWN() is specific to powerpc > > ALIGN_DOWN() is generic and does the same > > > > Replace _ALIGN_DOWN() by ALIGN_DOWN() > > This one is a bit less obvious. It becomes (leaving the typeof's alone > for clarity): > > -((addr)&(~((typeof(addr))(size)-1))) > +addr) - ((size) - 1)) + ((typeof(addr))(size) - 1)) & > ~((typeof(addr))(size)-1)) > > Which I assume the compiler will sort out? [ This is line-wrapped, something in your mailer? Took me a bit to figure out the - and + are diff -u things :-) ] In the common case where size is a constant integer power of two, the compiler will have no problem with this. But why do so complicated? Why are the casts there, btw? Segher
Re: [PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()
On Mon, 20 Apr 2020 at 18:38, Christophe Leroy wrote: > > _ALIGN_DOWN() is specific to powerpc > ALIGN_DOWN() is generic and does the same > > Replace _ALIGN_DOWN() by ALIGN_DOWN() This one is a bit less obvious. It becomes (leaving the typeof's alone for clarity): -((addr)&(~((typeof(addr))(size)-1))) +addr) - ((size) - 1)) + ((typeof(addr))(size) - 1)) & ~((typeof(addr))(size)-1)) Which I assume the compiler will sort out? Reviewed-by: Joel Stanley > > Signed-off-by: Christophe Leroy > --- > arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +- > arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +- > arch/powerpc/kernel/pci_64.c | 2 +- > arch/powerpc/kernel/prom.c | 6 +++--- > arch/powerpc/kernel/prom_init.c | 8 > arch/powerpc/mm/book3s64/hash_tlb.c | 4 ++-- > arch/powerpc/mm/init_64.c| 4 ++-- > arch/powerpc/platforms/powernv/opal-fadump.c | 2 +- > arch/powerpc/platforms/powernv/pci-ioda.c| 2 +- > arch/powerpc/platforms/ps3/mm.c | 14 +++--- > arch/powerpc/platforms/pseries/rtas-fadump.c | 2 +- > 11 files changed, 24 insertions(+), 24 deletions(-) > > diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h > b/arch/powerpc/include/asm/book3s/32/pgtable.h > index 7549393c4c43..53b5c93eaf5d 100644 > --- a/arch/powerpc/include/asm/book3s/32/pgtable.h > +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h > @@ -195,7 +195,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, > pgprot_t prot); > #endif > > #ifdef CONFIG_KASAN_VMALLOC > -#define VMALLOC_END_ALIGN_DOWN(ioremap_bot, PAGE_SIZE << > KASAN_SHADOW_SCALE_SHIFT) > +#define VMALLOC_ENDALIGN_DOWN(ioremap_bot, PAGE_SIZE << > KASAN_SHADOW_SCALE_SHIFT) > #else > #define VMALLOC_ENDioremap_bot > #endif > diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h > b/arch/powerpc/include/asm/nohash/32/pgtable.h > index b04ba257fddb..5b4d4c4297e1 100644 > --- a/arch/powerpc/include/asm/nohash/32/pgtable.h > +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h > @@ -116,7 +116,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, > pgprot_t prot); > #endif > > #ifdef CONFIG_KASAN_VMALLOC > -#define VMALLOC_END_ALIGN_DOWN(ioremap_bot, PAGE_SIZE << > KASAN_SHADOW_SCALE_SHIFT) > +#define VMALLOC_ENDALIGN_DOWN(ioremap_bot, PAGE_SIZE << > KASAN_SHADOW_SCALE_SHIFT) > #else > #define VMALLOC_ENDioremap_bot > #endif > diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c > index f83d1f69b1dd..e5d05af5a9af 100644 > --- a/arch/powerpc/kernel/pci_64.c > +++ b/arch/powerpc/kernel/pci_64.c > @@ -130,7 +130,7 @@ static int pcibios_map_phb_io_space(struct pci_controller > *hose) > unsigned long size_page; > unsigned long io_virt_offset; > > - phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE); > + phys_page = ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE); > size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE); > > /* Make sure IO area address is clear */ > diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c > index 6620f37abe73..10b5d5eafd34 100644 > --- a/arch/powerpc/kernel/prom.c > +++ b/arch/powerpc/kernel/prom.c > @@ -96,7 +96,7 @@ static inline int overlaps_initrd(unsigned long start, > unsigned long size) > if (!initrd_start) > return 0; > > - return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) && > + return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) && > start <= _ALIGN_UP(initrd_end, PAGE_SIZE); > #else > return 0; > @@ -623,9 +623,9 @@ static void __init early_reserve_mem(void) > #ifdef CONFIG_BLK_DEV_INITRD > /* Then reserve the initrd, if any */ > if (initrd_start && (initrd_end > initrd_start)) { > - memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), > + memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), > _ALIGN_UP(initrd_end, PAGE_SIZE) - > - _ALIGN_DOWN(initrd_start, PAGE_SIZE)); > + ALIGN_DOWN(initrd_start, PAGE_SIZE)); > } > #endif /* CONFIG_BLK_DEV_INITRD */ > > diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c > index 806be751c336..4cf5958eebd4 100644 > --- a/arch/powerpc/kernel/prom_init.c > +++ b/arch/powerpc/kernel/prom_init.c > @@ -1500,7 +1500,7 @@ static unsigned long __init alloc_down(unsigned long > size, unsigned long align, > > if (highmem) { > /* Carve out storage for the TCE table. */ > - addr = _ALIGN_DOWN(alloc_top_high - size, align); > + addr = ALIGN_DOWN(alloc_top_high - size, align); > if (addr <= alloc_bottom) > return 0; > /* Will we bump into the RMO ? If yes, check out that we > @@ -1518,9 +1518,9 @@
[PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()
_ALIGN_DOWN() is specific to powerpc ALIGN_DOWN() is generic and does the same Replace _ALIGN_DOWN() by ALIGN_DOWN() Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +- arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +- arch/powerpc/kernel/pci_64.c | 2 +- arch/powerpc/kernel/prom.c | 6 +++--- arch/powerpc/kernel/prom_init.c | 8 arch/powerpc/mm/book3s64/hash_tlb.c | 4 ++-- arch/powerpc/mm/init_64.c| 4 ++-- arch/powerpc/platforms/powernv/opal-fadump.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c| 2 +- arch/powerpc/platforms/ps3/mm.c | 14 +++--- arch/powerpc/platforms/pseries/rtas-fadump.c | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h index 7549393c4c43..53b5c93eaf5d 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -195,7 +195,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); #endif #ifdef CONFIG_KASAN_VMALLOC -#define VMALLOC_END_ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) +#define VMALLOC_ENDALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #else #define VMALLOC_ENDioremap_bot #endif diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h index b04ba257fddb..5b4d4c4297e1 100644 --- a/arch/powerpc/include/asm/nohash/32/pgtable.h +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h @@ -116,7 +116,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); #endif #ifdef CONFIG_KASAN_VMALLOC -#define VMALLOC_END_ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) +#define VMALLOC_ENDALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #else #define VMALLOC_ENDioremap_bot #endif diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index f83d1f69b1dd..e5d05af5a9af 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c @@ -130,7 +130,7 @@ static int pcibios_map_phb_io_space(struct pci_controller *hose) unsigned long size_page; unsigned long io_virt_offset; - phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE); + phys_page = ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE); size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE); /* Make sure IO area address is clear */ diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 6620f37abe73..10b5d5eafd34 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -96,7 +96,7 @@ static inline int overlaps_initrd(unsigned long start, unsigned long size) if (!initrd_start) return 0; - return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) && + return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) && start <= _ALIGN_UP(initrd_end, PAGE_SIZE); #else return 0; @@ -623,9 +623,9 @@ static void __init early_reserve_mem(void) #ifdef CONFIG_BLK_DEV_INITRD /* Then reserve the initrd, if any */ if (initrd_start && (initrd_end > initrd_start)) { - memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), + memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), _ALIGN_UP(initrd_end, PAGE_SIZE) - - _ALIGN_DOWN(initrd_start, PAGE_SIZE)); + ALIGN_DOWN(initrd_start, PAGE_SIZE)); } #endif /* CONFIG_BLK_DEV_INITRD */ diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index 806be751c336..4cf5958eebd4 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -1500,7 +1500,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align, if (highmem) { /* Carve out storage for the TCE table. */ - addr = _ALIGN_DOWN(alloc_top_high - size, align); + addr = ALIGN_DOWN(alloc_top_high - size, align); if (addr <= alloc_bottom) return 0; /* Will we bump into the RMO ? If yes, check out that we @@ -1518,9 +1518,9 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align, goto bail; } - base = _ALIGN_DOWN(alloc_top - size, align); + base = ALIGN_DOWN(alloc_top - size, align); for (; base > alloc_bottom; -base = _ALIGN_DOWN(base - 0x10, align)) { +base = ALIGN_DOWN(base - 0x10, align)) { prom_debug("trying: 0x%lx\n\r", base); addr = (unsigned long)prom_claim(base, size, 0); if (addr != PROM_ERROR &&