2019-09-12 13:54:03

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v1 0/4] powerpc: Add support for GENERIC_EARLY_IOREMAP

This series adds support for GENERIC_EARLY_IOREMAP on powerpc.

It also adds a warning in the standard ioremap() when it's called
before vmalloc is available in order to help locate those users.

Next step will be to incrementaly migrate all early users of
ioremap() to using early_ioremap() or other method.

Once they are all converted we can drop all the logic
behind ioremap_bot.

Christophe Leroy (4):
powerpc/fixmap: don't clear fixmap area in paging_init()
powerpc/fixmap: Use __fix_to_virt() instead of fix_to_virt()
powerpc: Add support for GENERIC_EARLY_IOREMAP
powerpc/ioremap: warn on early use of ioremap()

arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/Kbuild | 1 +
arch/powerpc/include/asm/fixmap.h | 19 ++++++++++++++++++-
arch/powerpc/kernel/setup_32.c | 3 +++
arch/powerpc/kernel/setup_64.c | 3 +++
arch/powerpc/mm/ioremap_32.c | 1 +
arch/powerpc/mm/ioremap_64.c | 2 ++
arch/powerpc/mm/mem.c | 8 --------
8 files changed, 29 insertions(+), 9 deletions(-)

--
2.13.3


2019-09-12 13:54:24

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v1 4/4] powerpc/ioremap: warn on early use of ioremap()

Powerpc now has EARLY_IOREMAP.

Next step is to convert all early users of ioremap() to
early_ioremap().

Add a warning to help locate those users.

Signed-off-by: Christophe Leroy <[email protected]>
---
arch/powerpc/mm/ioremap_32.c | 1 +
arch/powerpc/mm/ioremap_64.c | 2 ++
2 files changed, 3 insertions(+)

diff --git a/arch/powerpc/mm/ioremap_32.c b/arch/powerpc/mm/ioremap_32.c
index f36121f25243..743e11384dea 100644
--- a/arch/powerpc/mm/ioremap_32.c
+++ b/arch/powerpc/mm/ioremap_32.c
@@ -68,6 +68,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call
/*
* Should check if it is a candidate for a BAT mapping
*/
+ pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller);

err = early_ioremap_range(ioremap_bot - size, p, size, prot);
if (err)
diff --git a/arch/powerpc/mm/ioremap_64.c b/arch/powerpc/mm/ioremap_64.c
index fd29e51700cd..50a99d9684f7 100644
--- a/arch/powerpc/mm/ioremap_64.c
+++ b/arch/powerpc/mm/ioremap_64.c
@@ -81,6 +81,8 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,
if (slab_is_available())
return do_ioremap(paligned, offset, size, prot, caller);

+ pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller);
+
err = early_ioremap_range(ioremap_bot, paligned, size, prot);
if (err)
return NULL;
--
2.13.3

2019-09-12 17:33:16

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v1 1/4] powerpc/fixmap: don't clear fixmap area in paging_init()

fixmap is intended to map things permanently like the IMMR region on
FSL SOC (8xx, 83xx, ...), so don't clear it when initialising paging()

Signed-off-by: Christophe Leroy <[email protected]>
---
arch/powerpc/mm/mem.c | 8 --------
1 file changed, 8 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index be941d382c8d..278be4712e10 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -216,14 +216,6 @@ void __init paging_init(void)
unsigned long long total_ram = memblock_phys_mem_size();
phys_addr_t top_of_ram = memblock_end_of_DRAM();

-#ifdef CONFIG_PPC32
- unsigned long v = __fix_to_virt(__end_of_fixed_addresses - 1);
- unsigned long end = __fix_to_virt(FIX_HOLE);
-
- for (; v < end; v += PAGE_SIZE)
- map_kernel_page(v, 0, __pgprot(0)); /* XXX gross */
-#endif
-
#ifdef CONFIG_HIGHMEM
map_kernel_page(PKMAP_BASE, 0, __pgprot(0)); /* XXX gross */
pkmap_page_table = virt_to_kpte(PKMAP_BASE);
--
2.13.3

2019-09-12 17:33:58

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH v1 2/4] powerpc/fixmap: Use __fix_to_virt() instead of fix_to_virt()

Modify back __set_fixmap() to using __fix_to_virt() instead
of fix_to_virt() otherwise the following happens because it
seems GCC doesn't see idx as a builtin const.

CC mm/early_ioremap.o
In file included from ./include/linux/kernel.h:11:0,
from mm/early_ioremap.c:11:
In function ‘fix_to_virt’,
inlined from ‘__set_fixmap’ at ./arch/powerpc/include/asm/fixmap.h:87:2,
inlined from ‘__early_ioremap’ at mm/early_ioremap.c:156:4:
./include/linux/compiler.h:350:38: error: call to ‘__compiletime_assert_32’ declared with attribute error: BUILD_BUG_ON failed: idx >= __end_of_fixed_addresses
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
./include/linux/compiler.h:331:4: note: in definition of macro ‘__compiletime_assert’
prefix ## suffix(); \
^
./include/linux/compiler.h:350:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^

Signed-off-by: Christophe Leroy <[email protected]>
Fixes: 4cfac2f9c7f1 ("powerpc/mm: Simplify __set_fixmap()")
---
arch/powerpc/include/asm/fixmap.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h
index 0cfc365d814b..722289a1d000 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -77,7 +77,12 @@ enum fixed_addresses {
static inline void __set_fixmap(enum fixed_addresses idx,
phys_addr_t phys, pgprot_t flags)
{
- map_kernel_page(fix_to_virt(idx), phys, flags);
+ if (__builtin_constant_p(idx))
+ BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
+ else if (WARN_ON(idx >= __end_of_fixed_addresses))
+ return;
+
+ map_kernel_page(__fix_to_virt(idx), phys, flags);
}

#endif /* !__ASSEMBLY__ */
--
2.13.3

2019-09-18 19:50:56

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v1 0/4] powerpc: Add support for GENERIC_EARLY_IOREMAP

On Thu, Sep 12, 2019 at 01:49:40PM +0000, Christophe Leroy wrote:
> This series adds support for GENERIC_EARLY_IOREMAP on powerpc.
>
> It also adds a warning in the standard ioremap() when it's called
> before vmalloc is available in order to help locate those users.
>
> Next step will be to incrementaly migrate all early users of
> ioremap() to using early_ioremap() or other method.
>
> Once they are all converted we can drop all the logic
> behind ioremap_bot.

Thanks, this looks pretty nice!

2019-11-25 10:51:13

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v1 2/4] powerpc/fixmap: Use __fix_to_virt() instead of fix_to_virt()

On Thu, 2019-09-12 at 13:49:42 UTC, Christophe Leroy wrote:
> Modify back __set_fixmap() to using __fix_to_virt() instead
> of fix_to_virt() otherwise the following happens because it
> seems GCC doesn't see idx as a builtin const.
>
> CC mm/early_ioremap.o
> In file included from ./include/linux/kernel.h:11:0,
> from mm/early_ioremap.c:11:
> In function ‘fix_to_virt’,
> inlined from ‘__set_fixmap’ at ./arch/powerpc/include/asm/fixmap.h:87:2,
> inlined from ‘__early_ioremap’ at mm/early_ioremap.c:156:4:
> ./include/linux/compiler.h:350:38: error: call to ‘__compiletime_assert_32’ declared with attribute error: BUILD_BUG_ON failed: idx >= __end_of_fixed_addresses
> _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
> ^
> ./include/linux/compiler.h:331:4: note: in definition of macro ‘__compiletime_assert’
> prefix ## suffix(); \
> ^
> ./include/linux/compiler.h:350:2: note: in expansion of macro ‘_compiletime_assert’
> _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
> ^
> ./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> ^
> ./include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
> BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
> ^
> ./include/asm-generic/fixmap.h:32:2: note: in expansion of macro ‘BUILD_BUG_ON’
> BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
> ^
>
> Signed-off-by: Christophe Leroy <[email protected]>
> Fixes: 4cfac2f9c7f1 ("powerpc/mm: Simplify __set_fixmap()")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/77693a5fb57be4606a6024ec8e3076f9499b906b

cheers

2019-11-25 10:51:28

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v1 4/4] powerpc/ioremap: warn on early use of ioremap()

On Thu, 2019-09-12 at 13:49:44 UTC, Christophe Leroy wrote:
> Powerpc now has EARLY_IOREMAP.
>
> Next step is to convert all early users of ioremap() to
> early_ioremap().
>
> Add a warning to help locate those users.
>
> Signed-off-by: Christophe Leroy <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/d538aadc2718a95bfd80095c66ea814824535b34

cheers

2019-11-26 01:16:59

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v1 1/4] powerpc/fixmap: don't clear fixmap area in paging_init()

On Thu, 2019-09-12 at 13:49:41 UTC, Christophe Leroy wrote:
> fixmap is intended to map things permanently like the IMMR region on
> FSL SOC (8xx, 83xx, ...), so don't clear it when initialising paging()
>
> Signed-off-by: Christophe Leroy <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f2bb86937d86ebcb0e52f95b6d19aba1d850e601

cheers

2019-11-27 14:47:48

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v1 1/4] powerpc/fixmap: don't clear fixmap area in paging_init()



Le 26/11/2019 à 02:13, Michael Ellerman a écrit :
> On Thu, 2019-09-12 at 13:49:41 UTC, Christophe Leroy wrote:
>> fixmap is intended to map things permanently like the IMMR region on
>> FSL SOC (8xx, 83xx, ...), so don't clear it when initialising paging()
>>
>> Signed-off-by: Christophe Leroy <[email protected]>
>
> Applied to powerpc next, thanks.
>
> https://git.kernel.org/powerpc/c/f2bb86937d86ebcb0e52f95b6d19aba1d850e601
>

Hi,

What happened ?

It looks like it is gone in today's powerpc next.

Christophe

2019-11-28 08:09:13

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH v1 1/4] powerpc/fixmap: don't clear fixmap area in paging_init()



Le 27/11/2019 à 15:43, Christophe Leroy a écrit :
>
>
> Le 26/11/2019 à 02:13, Michael Ellerman a écrit :
>> On Thu, 2019-09-12 at 13:49:41 UTC, Christophe Leroy wrote:
>>> fixmap is intended to map things permanently like the IMMR region on
>>> FSL SOC (8xx, 83xx, ...), so don't clear it when initialising paging()
>>>
>>> Signed-off-by: Christophe Leroy <[email protected]>
>>
>> Applied to powerpc next, thanks.
>>
>> https://git.kernel.org/powerpc/c/f2bb86937d86ebcb0e52f95b6d19aba1d850e601
>>
>
> Hi,
>
> What happened ?
>
> It looks like it is gone in today's powerpc next.
>

I see it back today in powerpc/merge, thanks.

The issue is it is crashing with HIGHMEM, indeed exactly the same as you
saw with "[PATCH] powerpc/8xx: Fix permanently mapped IMMR region.",
since that was exactly the same code.

I sent a fix for it, and I also rebased "[PATCH] powerpc/8xx: Fix
permanently mapped IMMR region." into v2 to exclude from it the already
merged part.

It would be wise if you could merge both.

Thanks
Christophe