* Re: [PATCH] cpufreq: powernv: fix missing check of return value in init_powernv_pstates()
From: Akshay Adiga @ 2019-02-17 19:11 UTC (permalink / raw)
To: Yangtao Li
Cc: linux-pm, viresh.kumar, rjw, linux-kernel, paulus, linuxppc-dev
In-Reply-To: <20190216170623.12634-1-tiny.windzz@gmail.com>
On Sat, Feb 16, 2019 at 12:06:23PM -0500, Yangtao Li wrote:
> kmalloc() could fail, so insert a check of its return value. And
> if it fails, returns -ENOMEM.
>
> And remove (struct pstate_idx_revmap_data *) to fix coccinelle WARNING
> by the way.
>
> WARNING: casting value returned by memory allocation function to (struct
> pstate_idx_revmap_data *) is useless.
>
> Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
> ---
> drivers/cpufreq/powernv-cpufreq.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
Looks good to me. Thanks for fixing this.
^ permalink raw reply
* Re: [PATCH v3] hugetlb: allow to free gigantic pages regardless of the configuration
From: Alex Ghiti @ 2019-02-17 17:06 UTC (permalink / raw)
To: Dave Hansen, Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H . Peter Anvin, x86, Dave Hansen,
Andy Lutomirski, Peter Zijlstra, Alexander Viro, Mike Kravetz,
linux-arm-kernel, linux-kernel, linuxppc-dev, linux-s390,
linux-fsdevel, linux-mm
In-Reply-To: <c6d9be5f-3b3a-c95b-0045-9f98ea52a5c4@intel.com>
On 2/15/19 12:34 PM, Dave Hansen wrote:
>> -#if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA)
>> +#ifdef CONFIG_CONTIG_ALLOC
>> /* The below functions must be run on a range from a single zone. */
>> extern int alloc_contig_range(unsigned long start, unsigned long end,
>> unsigned migratetype, gfp_t gfp_mask);
>> -extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
>> #endif
>> +extern void free_contig_range(unsigned long pfn, unsigned int nr_pages);
> There's a lot of stuff going on in this patch. Adding/removing config
> options. Please get rid of these superfluous changes or at least break
> them out.
I agree that this patch does a lot of things. I am going at least to
split it
into 2 separate patches, one suggested-by Vlastimil regarding the renaming
of MEMORY_ISOLATION && COMPACTION || CMA, and another that indeed
does what was primarily intended.
>> #ifdef CONFIG_CMA
>> /* CMA stuff */
>> diff --git a/mm/Kconfig b/mm/Kconfig
>> index 25c71eb8a7db..138a8df9b813 100644
>> --- a/mm/Kconfig
>> +++ b/mm/Kconfig
>> @@ -252,12 +252,17 @@ config MIGRATION
>> pages as migration can relocate pages to satisfy a huge page
>> allocation instead of reclaiming.
>>
>> +
>> config ARCH_ENABLE_HUGEPAGE_MIGRATION
>> bool
> Like this. :)
My apologies for that.
>> config ARCH_ENABLE_THP_MIGRATION
>> bool
>>
>> +config CONTIG_ALLOC
>> + def_bool y
>> + depends on (MEMORY_ISOLATION && COMPACTION) || CMA
>> +
>> config PHYS_ADDR_T_64BIT
>> def_bool 64BIT
> Please think carefully though the Kconfig dependencies. 'select' is
> *not* the same as 'depends on'.
>
> This replaces a bunch of arch-specific "select ARCH_HAS_GIGANTIC_PAGE"
> with a 'depends on'. I *think* that ends up being OK, but it absolutely
> needs to be addressed in the changelog about why *you* think it is OK
> and why it doesn't change the functionality of any of the patched
> architetures.
Ok.
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index afef61656c1e..e686c92212e9 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -1035,7 +1035,6 @@ static int hstate_next_node_to_free(struct hstate *h, nodemask_t *nodes_allowed)
>> ((node = hstate_next_node_to_free(hs, mask)) || 1); \
>> nr_nodes--)
>>
>> -#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
>> static void destroy_compound_gigantic_page(struct page *page,
>> unsigned int order)
>> {
> Whats the result of this #ifdef removal? A universally larger kernel
> even for architectures that do not support runtime gigantic page
> alloc/free? That doesn't seem like a good thing.
Ok, I agree, now that we removed the "wrong" definition of
ARCH_HAS_GIGANTIC_PAGE,
we can actually use this define for architectures to show they support
gigantic pages
and avoid the problem you mention. Thanks.
>> @@ -1058,6 +1057,12 @@ static void free_gigantic_page(struct page *page, unsigned int order)
>> free_contig_range(page_to_pfn(page), 1 << order);
>> }
>>
>> +static inline bool gigantic_page_runtime_allocation_supported(void)
>> +{
>> + return IS_ENABLED(CONFIG_CONTIG_ALLOC);
>> +}
> Why bother having this function? Why don't the callers just check the
> config option directly?
Ok, this function is only used once in set_max_huge_pages where you
mention the need for a comment, so I can get rid of it. Thanks.
>> +#ifdef CONFIG_CONTIG_ALLOC
>> static int __alloc_gigantic_page(unsigned long start_pfn,
>> unsigned long nr_pages, gfp_t gfp_mask)
>> {
>> @@ -1143,22 +1148,15 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
>> static void prep_new_huge_page(struct hstate *h, struct page *page, int nid);
>> static void prep_compound_gigantic_page(struct page *page, unsigned int order);
>>
>> -#else /* !CONFIG_ARCH_HAS_GIGANTIC_PAGE */
>> -static inline bool gigantic_page_supported(void) { return false; }
>> +#else /* !CONFIG_CONTIG_ALLOC */
>> static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
>> int nid, nodemask_t *nodemask) { return NULL; }
>> -static inline void free_gigantic_page(struct page *page, unsigned int order) { }
>> -static inline void destroy_compound_gigantic_page(struct page *page,
>> - unsigned int order) { }
>> #endif
>>
>> static void update_and_free_page(struct hstate *h, struct page *page)
>> {
>> int i;
>>
>> - if (hstate_is_gigantic(h) && !gigantic_page_supported())
>> - return;
> I don't get the point of removing this check. Logically, this reads as
> checking if the architecture supports gigantic hstates and has nothing
> to do with allocation.
I think this check was wrong from the beginning: gigantic_page_supported()
was only checking (MEMORY_ISOLATION && COMPACTION) || CMA, which has
nothing to do with the capability to free gigantic pages.
But then I went through all the architectures to see if removing this
test could
affect any of them. And I noticed that if an architecture supports gigantic
page without advertising it with ARCH_HAS_GIGANTIC_PAGE, then it would
decrement the number of free huge page but would not actually free the
pages.
I found at least 2 archs that have gigantic pages, but do not allow
runtime allocation nor freeing of those pages because they do not define
the (wrong) ARCH_HAS_GIGANTIC_PAGE:
- ia64 has HPAGE_SHIFT_DEFAULT = 28, with PAGE_SHIFT = 14
- sh has max HPAGE_SHIFT = 29 and max PAGE_SHIFT = 16
with default MAX_ORDER = 11, both architectures support gigantic pages.
So I'm going to propose a patch that selects the (right)
ARCH_HAS_GIGANTIC_PAGE
for those archs, because I think they should be able to free their boottime
gigantic pages.
Regarding this check, we can either remove it if we are sure that
every architecture that has gigantic pages selects ARCH_HAS_GIGANTIC_PAGE,
or leaving it in case some future archs forget to select it.
I'd rather patch all archs so that they can at least free gigantic pages and
then remove the test since hstate_is_gigantic would imply
gigantic_page_supported.
I will propose something like that if you agree.
>> h->nr_huge_pages--;
>> h->nr_huge_pages_node[page_to_nid(page)]--;
>> for (i = 0; i < pages_per_huge_page(h); i++) {
>> @@ -2276,13 +2274,20 @@ static int adjust_pool_surplus(struct hstate *h, nodemask_t *nodes_allowed,
>> }
>>
>> #define persistent_huge_pages(h) (h->nr_huge_pages - h->surplus_huge_pages)
>> -static unsigned long set_max_huge_pages(struct hstate *h, unsigned long count,
>> +static int set_max_huge_pages(struct hstate *h, unsigned long count,
>> nodemask_t *nodes_allowed)
>> {
>> unsigned long min_count, ret;
>>
>> - if (hstate_is_gigantic(h) && !gigantic_page_supported())
>> - return h->max_huge_pages;
>> + if (hstate_is_gigantic(h) &&
>> + !gigantic_page_runtime_allocation_supported()) {
> The indentation here is wrong and reduces readability. Needs to be like
> this:
>
> if (hstate_is_gigantic(h) &&
> !gigantic_page_runtime_allocation_supported()) {
This will disappear with your previous remark, thanks.
>> + spin_lock(&hugetlb_lock);
>> + if (count > persistent_huge_pages(h)) {
>> + spin_unlock(&hugetlb_lock);
>> + return -EINVAL;
>> + }
>> + goto decrease_pool;
>> + }
> Needs comments.
>
> /* Gigantic pages can be freed but not allocated */
>
> or something.
>
Ok, I agree, I'll add that and another sentence regarding the removal
of gigantic_page_runtime_allocation_supported.
Thank you Dave for your comments !
Alex
^ permalink raw reply
* Re: [GIT PULL] Please pull powerpc/linux.git powerpc-5.0-5 tag
From: pr-tracker-bot @ 2019-02-17 16:50 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, Linus Torvalds, linux-kernel
In-Reply-To: <87k1hyddwd.fsf@concordia.ellerman.id.au>
The pull request you sent on Sun, 17 Feb 2019 19:20:50 +1100:
> https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git tags/powerpc-5.0-5
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/c5f1ac5e9afb199638414be77cbc22eb68e14d97
Thank you!
--
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker
^ permalink raw reply
* Re: [RFC PATCH 4/5] powerpc: move KASAN into its own subdirectory
From: christophe leroy @ 2019-02-17 16:29 UTC (permalink / raw)
To: Daniel Axtens, aneesh.kumar, bsingharora; +Cc: linuxppc-dev, kasan-dev
In-Reply-To: <20190215000441.14323-5-dja@axtens.net>
Le 15/02/2019 à 01:04, Daniel Axtens a écrit :
> In preparation for adding ppc64 implementations, break out the
> code into its own subdirectory.
That's not a bad idea, arch/powerpc/mm is rather messy with lot of
subarch stuff.
I'll take it in my series.
Christophe
>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
> arch/powerpc/mm/Makefile | 4 +---
> arch/powerpc/mm/kasan/Makefile | 5 +++++
> arch/powerpc/mm/{kasan_init.c => kasan/kasan_init_32.c} | 0
> 3 files changed, 6 insertions(+), 3 deletions(-)
> create mode 100644 arch/powerpc/mm/kasan/Makefile
> rename arch/powerpc/mm/{kasan_init.c => kasan/kasan_init_32.c} (100%)
>
> diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
> index d6b76f25f6de..457c0ea2b5e7 100644
> --- a/arch/powerpc/mm/Makefile
> +++ b/arch/powerpc/mm/Makefile
> @@ -7,8 +7,6 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
>
> CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
>
> -KASAN_SANITIZE_kasan_init.o := n
> -
> obj-y := fault.o mem.o pgtable.o mmap.o \
> init_$(BITS).o pgtable_$(BITS).o \
> init-common.o mmu_context.o drmem.o
> @@ -57,4 +55,4 @@ obj-$(CONFIG_PPC_BOOK3S_64) += dump_linuxpagetables-book3s64.o
> endif
> obj-$(CONFIG_PPC_HTDUMP) += dump_hashpagetable.o
> obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o
> -obj-$(CONFIG_KASAN) += kasan_init.o
> +obj-$(CONFIG_KASAN) += kasan/
> diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile
> new file mode 100644
> index 000000000000..6577897673dd
> --- /dev/null
> +++ b/arch/powerpc/mm/kasan/Makefile
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +KASAN_SANITIZE := n
> +
> +obj-$(CONFIG_PPC32) += kasan_init_32.o
> diff --git a/arch/powerpc/mm/kasan_init.c b/arch/powerpc/mm/kasan/kasan_init_32.c
> similarity index 100%
> rename from arch/powerpc/mm/kasan_init.c
> rename to arch/powerpc/mm/kasan/kasan_init_32.c
>
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply
* Re: [RFC PATCH 5/5] powerpc: KASAN for 64bit Book3E
From: christophe leroy @ 2019-02-17 14:06 UTC (permalink / raw)
To: Daniel Axtens, aneesh.kumar, bsingharora
Cc: linuxppc-dev, Aneesh Kumar K . V, kasan-dev
In-Reply-To: <20190215000441.14323-6-dja@axtens.net>
Le 15/02/2019 à 01:04, Daniel Axtens a écrit :
> Wire up KASAN. Only outline instrumentation is supported.
>
> The KASAN shadow area is mapped into vmemmap space:
> 0x8000 0400 0000 0000 to 0x8000 0600 0000 0000.
> To do this we require that vmemmap be disabled. (This is the default
> in the kernel config that QorIQ provides for the machine in their
> SDK anyway - they use flat memory.)
>
> Only the kernel linear mapping (0xc000...) is checked. The vmalloc and
> ioremap areas (also in 0x800...) are all mapped to a zero page. As
> with the Book3S hash series, this requires overriding the memory <->
> shadow mapping.
>
> Also, as with both previous 64-bit series, early instrumentation is not
> supported. It would allow us to drop the check_return_arch_not_ready()
> hook in the KASAN core, but it's tricky to get it set up early enough:
> we need it setup before the first call to instrumented code like printk().
> Perhaps in the future.
>
> Only KASAN_MINIMAL works.
>
> Lightly tested on e6500. KVM, kexec and xmon have not been tested.
>
> The test_kasan module fires warnings as expected, except for the
> following tests:
>
> - Expected/by design:
> kasan test: memcg_accounted_kmem_cache allocate memcg accounted object
>
> - Due to only supporting KASAN_MINIMAL:
> kasan test: kasan_stack_oob out-of-bounds on stack
> kasan test: kasan_global_oob out-of-bounds global variable
> kasan test: kasan_alloca_oob_left out-of-bounds to left on alloca
> kasan test: kasan_alloca_oob_right out-of-bounds to right on alloca
> kasan test: use_after_scope_test use-after-scope on int
> kasan test: use_after_scope_test use-after-scope on array
>
> Thanks to those who have done the heavy lifting over the past several years:
> - Christophe's 32 bit series: https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-February/185379.html
You're welcome.
> - Aneesh's Book3S hash series: https://lwn.net/Articles/655642/
> - Balbir's Book3S radix series: https://patchwork.ozlabs.org/patch/795211/
>
> Cc: Christophe Leroy <christophe.leroy@c-s.fr>
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Cc: Balbir Singh <bsingharora@gmail.com>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
>
> ---
>
> While useful if you have a book3e device, this is mostly intended
> as a warm-up exercise for reviving Aneesh's series for book3s hash.
> In particular, changes to the kasan core are going to be required
> for hash and radix as well.
And part of it will be needed for hash32 as well, until we implement an
early static hash stable.
> ---
> arch/powerpc/Kconfig | 1 +
> arch/powerpc/Makefile | 2 +
> arch/powerpc/include/asm/kasan.h | 77 ++++++++++++++++++--
> arch/powerpc/include/asm/ppc_asm.h | 7 ++
> arch/powerpc/include/asm/string.h | 7 +-
> arch/powerpc/lib/mem_64.S | 6 +-
> arch/powerpc/lib/memcmp_64.S | 5 +-
> arch/powerpc/lib/memcpy_64.S | 3 +-
> arch/powerpc/lib/string.S | 15 ++--
> arch/powerpc/mm/Makefile | 2 +
> arch/powerpc/mm/kasan/Makefile | 1 +
> arch/powerpc/mm/kasan/kasan_init_book3e_64.c | 53 ++++++++++++++
> arch/powerpc/purgatory/Makefile | 3 +
> arch/powerpc/xmon/Makefile | 1 +
> 14 files changed, 164 insertions(+), 19 deletions(-)
> create mode 100644 arch/powerpc/mm/kasan/kasan_init_book3e_64.c
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 850b06def84f..2c7c20d52778 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -176,6 +176,7 @@ config PPC
> select HAVE_ARCH_AUDITSYSCALL
> select HAVE_ARCH_JUMP_LABEL
> select HAVE_ARCH_KASAN if PPC32
> + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && !SPARSEMEM_VMEMMAP
> select HAVE_ARCH_KGDB
> select HAVE_ARCH_MMAP_RND_BITS
> select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
> diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
> index f0738099e31e..21c2dadf0315 100644
> --- a/arch/powerpc/Makefile
> +++ b/arch/powerpc/Makefile
> @@ -428,11 +428,13 @@ endif
> endif
>
> ifdef CONFIG_KASAN
> +ifdef CONFIG_PPC32
> prepare: kasan_prepare
>
> kasan_prepare: prepare0
> $(eval KASAN_SHADOW_OFFSET = $(shell awk '{if ($$2 == "KASAN_SHADOW_OFFSET") print $$3;}' include/generated/asm-offsets.h))
> endif
> +endif
>
> # Check toolchain versions:
> # - gcc-4.6 is the minimum kernel-wide version so nothing required.
> diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
> index 5d0088429b62..c2f6f05dfaa3 100644
> --- a/arch/powerpc/include/asm/kasan.h
> +++ b/arch/powerpc/include/asm/kasan.h
> @@ -5,20 +5,85 @@
> #ifndef __ASSEMBLY__
>
> #include <asm/page.h>
> +#include <asm/pgtable.h>
> #include <asm/pgtable-types.h>
> -#include <asm/fixmap.h>
>
> #define KASAN_SHADOW_SCALE_SHIFT 3
> -#define KASAN_SHADOW_SIZE ((~0UL - PAGE_OFFSET + 1) >> KASAN_SHADOW_SCALE_SHIFT)
>
> -#define KASAN_SHADOW_START (ALIGN_DOWN(FIXADDR_START - KASAN_SHADOW_SIZE, \
> - PGDIR_SIZE))
> -#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE)
> #define KASAN_SHADOW_OFFSET (KASAN_SHADOW_START - \
> (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
> +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE)
> +
> +
> +#ifdef CONFIG_PPC32
> +#include <asm/fixmap.h>
> +#define KASAN_SHADOW_START (ALIGN_DOWN(FIXADDR_START - KASAN_SHADOW_SIZE, \
> + PGDIR_SIZE))
> +#define KASAN_SHADOW_SIZE ((~0UL - PAGE_OFFSET + 1) >> KASAN_SHADOW_SCALE_SHIFT)
>
> void kasan_early_init(void);
> +
> +#endif /* CONFIG_PPC32 */
All the above is a bit messy. I'll reorder this file in my series so
that when your patch comes in it doesn't reshuffle existing lines.
> +
> +#ifdef CONFIG_PPC_BOOK3E_64
> +#define KASAN_SHADOW_START VMEMMAP_BASE
> +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT)
> +
> +extern struct static_key_false powerpc_kasan_enabled_key;
> +#define check_return_arch_not_ready() \
> + do { \
> + if (!static_branch_likely(&powerpc_kasan_enabled_key)) \
> + return; \
> + } while (0)
Would look better like
static inline bool kasan_arch_is_ready(void)
{
if (static_branch_likely(&powerpc_kasan_enabled_key))
return true;
return false;
}
> +
> +extern unsigned char kasan_zero_page[PAGE_SIZE];
> +static inline void *kasan_mem_to_shadow_book3e(const void *addr)
> +{
> + if ((unsigned long)addr >= KERN_VIRT_START &&
> + (unsigned long)addr < (KERN_VIRT_START + KERN_VIRT_SIZE)) {
> + return (void *)kasan_zero_page;
> + }
> +
> + return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
> + + KASAN_SHADOW_OFFSET;
> +}
> +#define kasan_mem_to_shadow kasan_mem_to_shadow_book3e
> +
> +static inline void *kasan_shadow_to_mem_book3e(const void *shadow_addr)
> +{
> + /*
> + * We map the entire non-linear virtual mapping onto the zero page so if
> + * we are asked to map the zero page back just pick the beginning of that
> + * area.
> + */
> + if (shadow_addr >= (void *)kasan_zero_page &&
> + shadow_addr < (void *)(kasan_zero_page + PAGE_SIZE)) {
> + return (void *)KERN_VIRT_START;
> + }
> +
> + return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
> + << KASAN_SHADOW_SCALE_SHIFT);
> +}
> +#define kasan_shadow_to_mem kasan_shadow_to_mem_book3e
> +
> +static inline bool kasan_addr_has_shadow_book3e(const void *addr)
> +{
> + /*
> + * We want to specifically assert that the addresses in the 0x8000...
> + * region have a shadow, otherwise they are considered by the kasan
> + * core to be wild pointers
> + */
> + if ((unsigned long)addr >= KERN_VIRT_START &&
> + (unsigned long)addr < (KERN_VIRT_START + KERN_VIRT_SIZE)) {
> + return true;
> + }
> + return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START));
> +}
> +#define kasan_addr_has_shadow kasan_addr_has_shadow_book3e
> +
> +#endif /* CONFIG_PPC_BOOK3E_64 */
> +
> void kasan_init(void);
>
> -#endif
> +#endif /* CONFIG_KASAN */
The above endif is for __ASSEMBLY__
> #endif
> diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
> index dba2c1038363..fd7c9fa9d307 100644
> --- a/arch/powerpc/include/asm/ppc_asm.h
> +++ b/arch/powerpc/include/asm/ppc_asm.h
> @@ -251,10 +251,17 @@ GLUE(.,name):
>
> #define _GLOBAL_TOC(name) _GLOBAL(name)
>
> +#endif /* 32-bit */
> +
> +/* KASAN helpers */
> #define KASAN_OVERRIDE(x, y) \
> .weak x; \
> .set x, y
>
I'll leave it out of the PPC32 section in my series, it's harmless.
> +#ifdef CONFIG_KASAN
> +#define EXPORT_SYMBOL_NOKASAN(x)
> +#else
> +#define EXPORT_SYMBOL_NOKASAN(x) EXPORT_SYMBOL(x)
> #endif
I can't see the point about the above. Is it worth still having the
functions when nobody is going to use them ?
>
> /*
> diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h
> index 64d44d4836b4..e2801d517d57 100644
> --- a/arch/powerpc/include/asm/string.h
> +++ b/arch/powerpc/include/asm/string.h
> @@ -4,13 +4,16 @@
>
> #ifdef __KERNEL__
>
> +#ifndef CONFIG_KASAN
> #define __HAVE_ARCH_STRNCPY
> #define __HAVE_ARCH_STRNCMP
> +#define __HAVE_ARCH_MEMCHR
> +#define __HAVE_ARCH_MEMCMP
> +#endif
> +
Good catch, we can't use the optimised version when CONFIG_KASAN is set
until kasan implements verifications with check_memory_region() as it
does for memmove(), memcpy() and memset().
I'll take that in my series.
> #define __HAVE_ARCH_MEMSET
> #define __HAVE_ARCH_MEMCPY
> #define __HAVE_ARCH_MEMMOVE
> -#define __HAVE_ARCH_MEMCMP
> -#define __HAVE_ARCH_MEMCHR
> #define __HAVE_ARCH_MEMSET16
> #define __HAVE_ARCH_MEMCPY_FLUSHCACHE
>
> diff --git a/arch/powerpc/lib/mem_64.S b/arch/powerpc/lib/mem_64.S
> index 3c3be02f33b7..3ff4c6b45505 100644
> --- a/arch/powerpc/lib/mem_64.S
> +++ b/arch/powerpc/lib/mem_64.S
> @@ -30,7 +30,8 @@ EXPORT_SYMBOL(__memset16)
> EXPORT_SYMBOL(__memset32)
> EXPORT_SYMBOL(__memset64)
>
> -_GLOBAL(memset)
> +_GLOBAL(__memset)
> +KASAN_OVERRIDE(memset, __memset)
> neg r0,r3
> rlwimi r4,r4,8,16,23
> andi. r0,r0,7 /* # bytes to be 8-byte aligned */
> @@ -97,7 +98,8 @@ _GLOBAL(memset)
> blr
> EXPORT_SYMBOL(memset)
>
> -_GLOBAL_TOC(memmove)
> +_GLOBAL_TOC(__memmove)
> +KASAN_OVERRIDE(memmove, __memmove)
> cmplw 0,r3,r4
> bgt backwards_memcpy
> b memcpy
> diff --git a/arch/powerpc/lib/memcmp_64.S b/arch/powerpc/lib/memcmp_64.S
> index 844d8e774492..21aee60de2cd 100644
> --- a/arch/powerpc/lib/memcmp_64.S
> +++ b/arch/powerpc/lib/memcmp_64.S
> @@ -102,7 +102,8 @@
> * 2) src/dst has different offset to the 8 bytes boundary. The handlers
> * are named like .Ldiffoffset_xxxx
> */
> -_GLOBAL_TOC(memcmp)
> +_GLOBAL_TOC(__memcmp)
> +KASAN_OVERRIDE(memcmp, __memcmp)
> cmpdi cr1,r5,0
>
> /* Use the short loop if the src/dst addresses are not
> @@ -630,4 +631,4 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
> b .Lcmp_lt32bytes
>
> #endif
> -EXPORT_SYMBOL(memcmp)
> +EXPORT_SYMBOL_NOKASAN(memcmp)
That's pointless. Nobody is going to call __memcmp(), so we should just
not compile it in when CONFIG_KASAN is defined. Same for memchr(),
strncpy() and strncmp().
I'll do it in my series.
> diff --git a/arch/powerpc/lib/memcpy_64.S b/arch/powerpc/lib/memcpy_64.S
> index 273ea67e60a1..e9092a0e531a 100644
> --- a/arch/powerpc/lib/memcpy_64.S
> +++ b/arch/powerpc/lib/memcpy_64.S
> @@ -18,7 +18,8 @@
> #endif
>
> .align 7
> -_GLOBAL_TOC(memcpy)
> +_GLOBAL_TOC(__memcpy)
> +KASAN_OVERRIDE(memcpy, __memcpy)
> BEGIN_FTR_SECTION
> #ifdef __LITTLE_ENDIAN__
> cmpdi cr7,r5,0
> diff --git a/arch/powerpc/lib/string.S b/arch/powerpc/lib/string.S
> index 4b41970e9ed8..09deaac6e5f1 100644
> --- a/arch/powerpc/lib/string.S
> +++ b/arch/powerpc/lib/string.S
> @@ -16,7 +16,8 @@
>
> /* This clears out any unused part of the destination buffer,
> just as the libc version does. -- paulus */
> -_GLOBAL(strncpy)
> +_GLOBAL(__strncpy)
> +KASAN_OVERRIDE(strncpy, __strncpy)
> PPC_LCMPI 0,r5,0
> beqlr
> mtctr r5
> @@ -34,9 +35,10 @@ _GLOBAL(strncpy)
> 2: stbu r0,1(r6) /* clear it out if so */
> bdnz 2b
> blr
> -EXPORT_SYMBOL(strncpy)
> +EXPORT_SYMBOL_NOKASAN(strncpy)
>
> -_GLOBAL(strncmp)
> +_GLOBAL(__strncmp)
> +KASAN_OVERRIDE(strncmp, __strncmp)
> PPC_LCMPI 0,r5,0
> beq- 2f
> mtctr r5
> @@ -52,9 +54,10 @@ _GLOBAL(strncmp)
> blr
> 2: li r3,0
> blr
> -EXPORT_SYMBOL(strncmp)
> +EXPORT_SYMBOL_NOKASAN(strncmp)
>
> -_GLOBAL(memchr)
> +_GLOBAL(__memchr)
> +KASAN_OVERRIDE(memchr, __memchr)
> PPC_LCMPI 0,r5,0
> beq- 2f
> mtctr r5
> @@ -66,4 +69,4 @@ _GLOBAL(memchr)
> beqlr
> 2: li r3,0
> blr
> -EXPORT_SYMBOL(memchr)
> +EXPORT_SYMBOL_NOKASAN(memchr)
> diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
> index 457c0ea2b5e7..d974f7bcb177 100644
> --- a/arch/powerpc/mm/Makefile
> +++ b/arch/powerpc/mm/Makefile
> @@ -7,6 +7,8 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
>
> CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
>
> +KASAN_SANITIZE_fsl_booke_mmu.o := n
> +
> obj-y := fault.o mem.o pgtable.o mmap.o \
> init_$(BITS).o pgtable_$(BITS).o \
> init-common.o mmu_context.o drmem.o
> diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile
> index 6577897673dd..f8f164ad8ade 100644
> --- a/arch/powerpc/mm/kasan/Makefile
> +++ b/arch/powerpc/mm/kasan/Makefile
> @@ -3,3 +3,4 @@
> KASAN_SANITIZE := n
>
> obj-$(CONFIG_PPC32) += kasan_init_32.o
> +obj-$(CONFIG_PPC_BOOK3E_64) += kasan_init_book3e_64.o
> diff --git a/arch/powerpc/mm/kasan/kasan_init_book3e_64.c b/arch/powerpc/mm/kasan/kasan_init_book3e_64.c
> new file mode 100644
> index 000000000000..93b9afcf1020
> --- /dev/null
> +++ b/arch/powerpc/mm/kasan/kasan_init_book3e_64.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#define DISABLE_BRANCH_PROFILING
> +
> +#include <linux/kasan.h>
> +#include <linux/printk.h>
> +#include <linux/memblock.h>
> +#include <linux/sched/task.h>
> +#include <asm/pgalloc.h>
> +
> +DEFINE_STATIC_KEY_FALSE(powerpc_kasan_enabled_key);
> +EXPORT_SYMBOL(powerpc_kasan_enabled_key);
> +unsigned char kasan_zero_page[PAGE_SIZE] __page_aligned_bss;
Why not using the existing kasan_early_shadow_page[] defined in
mm/kasan/init.c ? (which was called kasan_zero_page before)
> +
> +static void __init kasan_init_region(struct memblock_region *reg)
> +{
> + void *start = __va(reg->base);
> + void *end = __va(reg->base + reg->size);
> + unsigned long k_start, k_end, k_cur;
> +
> + if (start >= end)
> + return;
> +
> + k_start = (unsigned long)kasan_mem_to_shadow(start);
> + k_end = (unsigned long)kasan_mem_to_shadow(end);
> +
> + for (k_cur = k_start; k_cur < k_end; k_cur += PAGE_SIZE) {
> + void *va = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
What if memblock_alloc() fails are return NULL ?
> + map_kernel_page(k_cur, __pa(va), PAGE_KERNEL);
> + }
> + flush_tlb_kernel_range(k_start, k_end);
> +}
> +
> +void __init kasan_init(void)
> +{
> + struct memblock_region *reg;
> +
> + for_each_memblock(memory, reg)
> + kasan_init_region(reg);
> +
> + /* map the zero page RO */
> + map_kernel_page((unsigned long)kasan_zero_page,
> + __pa(kasan_zero_page), PAGE_KERNEL_RO);
This page is already mapped. Shouldn't the change be done with a kind of
page rights updating function() ?
> +
> + kasan_init_tags();
This is unneeded, it is specific to arm64.
> +
> + /* Turn on checking */
> + static_branch_inc(&powerpc_kasan_enabled_key);
> +
> + /* Enable error messages */
> + init_task.kasan_depth = 0;
> + pr_info("KASAN init done (64-bit Book3E)\n");
> +}
> diff --git a/arch/powerpc/purgatory/Makefile b/arch/powerpc/purgatory/Makefile
> index 4314ba5baf43..7c6d8b14f440 100644
> --- a/arch/powerpc/purgatory/Makefile
> +++ b/arch/powerpc/purgatory/Makefile
> @@ -1,4 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0
> +
> +KASAN_SANITIZE := n
> +
I'll take it in my series.
> targets += trampoline.o purgatory.ro kexec-purgatory.c
>
> LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined
> diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
> index 878f9c1d3615..064f7062c0a3 100644
> --- a/arch/powerpc/xmon/Makefile
> +++ b/arch/powerpc/xmon/Makefile
> @@ -6,6 +6,7 @@ subdir-ccflags-y := $(call cc-disable-warning, builtin-requires-header)
>
> GCOV_PROFILE := n
> UBSAN_SANITIZE := n
> +KASAN_SANITIZE := n
>
I'll take it in my series.
> # Disable ftrace for the entire directory
> ORIG_CFLAGS := $(KBUILD_CFLAGS)
>
Christophe
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply
* Re: [RFC PATCH 3/5] kasan: allow architectures to provide an outline readiness check
From: christophe leroy @ 2019-02-17 12:05 UTC (permalink / raw)
To: Daniel Axtens, aneesh.kumar, bsingharora
Cc: linuxppc-dev, Aneesh Kumar K . V, kasan-dev
In-Reply-To: <20190215000441.14323-4-dja@axtens.net>
Le 15/02/2019 à 01:04, Daniel Axtens a écrit :
> In powerpc (as I understand it), we spend a lot of time in boot
> running in real mode before MMU paging is initalised. During
> this time we call a lot of generic code, including printk(). If
> we try to access the shadow region during this time, things fail.
>
> My attempts to move early init before the first printk have not
> been successful. (Both previous RFCs for ppc64 - by 2 different
> people - have needed this trick too!)
>
> So, allow architectures to define a check_return_arch_not_ready()
> hook that bails out of check_memory_region_inline() unless the
> arch has done all of the init.
>
> Link: https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series
> Link: https://patchwork.ozlabs.org/patch/795211/ # ppc radix series
> Originally-by: Balbir Singh <bsingharora@gmail.com>
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
> include/linux/kasan.h | 4 ++++
> mm/kasan/generic.c | 2 ++
> 2 files changed, 6 insertions(+)
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index f6261840f94c..83edc5e2b6a0 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -14,6 +14,10 @@ struct task_struct;
> #include <asm/kasan.h>
> #include <asm/pgtable.h>
>
> +#ifndef check_return_arch_not_ready
> +#define check_return_arch_not_ready() do { } while (0)
> +#endif
A static inline would be better I believe.
Something like
#ifndef kasan_arch_is_ready
static inline bool kasan_arch_is_ready {return true;}
#endif
> +
> extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
> extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE];
> extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD];
> diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c
> index bafa2f986660..4c18bbd09a20 100644
> --- a/mm/kasan/generic.c
> +++ b/mm/kasan/generic.c
> @@ -170,6 +170,8 @@ static __always_inline void check_memory_region_inline(unsigned long addr,
> size_t size, bool write,
> unsigned long ret_ip)
> {
> + check_return_arch_not_ready();
> +
Not good for readibility that the above macro embeds a return, something
like below would be better I think:
if (!kasan_arch_is_ready())
return;
Unless somebody minds, I'll do the change and take this patch in my
series in order to handle the case of book3s/32 hash.
Christophe
> if (unlikely(size == 0))
> return;
>
>
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Michael Ellerman @ 2019-02-17 8:34 UTC (permalink / raw)
To: Segher Boessenkool, Balbir Singh
Cc: erhard_f, jack, linuxppc-dev, linux-kernel, linux-mm,
aneesh.kumar
In-Reply-To: <20190216142206.GE14180@gate.crashing.org>
Segher Boessenkool <segher@kernel.crashing.org> writes:
> Hi all,
>
> On Sat, Feb 16, 2019 at 09:55:11PM +1100, Balbir Singh wrote:
>> On Thu, Feb 14, 2019 at 05:23:39PM +1100, Michael Ellerman wrote:
>> > In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
>> > rather than just checking that the value is non-zero, e.g.:
>> >
>> > static inline int pgd_present(pgd_t pgd)
>> > {
>> > - return !pgd_none(pgd);
>> > + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
>> > }
>> >
>> > Unfortunately this is broken on big endian, as the result of the
>> > bitwise && is truncated to int, which is always zero because
>
> (Bitwise "&" of course).
Thanks, I fixed that up.
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Michael Ellerman @ 2019-02-17 8:34 UTC (permalink / raw)
To: Balbir Singh, Segher Boessenkool
Cc: erhard_f, jack, linuxppc-dev, linux-kernel, linux-mm,
aneesh.kumar
In-Reply-To: <20190217062333.GC31125@350D>
Balbir Singh <bsingharora@gmail.com> writes:
> On Sat, Feb 16, 2019 at 08:22:12AM -0600, Segher Boessenkool wrote:
>> Hi all,
>>
>> On Sat, Feb 16, 2019 at 09:55:11PM +1100, Balbir Singh wrote:
>> > On Thu, Feb 14, 2019 at 05:23:39PM +1100, Michael Ellerman wrote:
>> > > In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
>> > > rather than just checking that the value is non-zero, e.g.:
>> > >
>> > > static inline int pgd_present(pgd_t pgd)
>> > > {
>> > > - return !pgd_none(pgd);
>> > > + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
>> > > }
>> > >
>> > > Unfortunately this is broken on big endian, as the result of the
>> > > bitwise && is truncated to int, which is always zero because
>>
>> (Bitwise "&" of course).
>>
>> > Not sure why that should happen, why is the result an int? What
>> > causes the casting of pgd_t & be64 to be truncated to an int.
>>
>> Yes, it's not obvious as written... It's simply that the return type of
>> pgd_present is int. So it is truncated _after_ the bitwise and.
>>
>
> Thanks, I am surprised the compiler does not complain about the truncation
> of bits. I wonder if we are missing -Wconversion
Good luck with that :)
What I should start doing is building with it enabled and then comparing
the output before and after commits to make sure we're not introducing
new cases.
cheers
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Michael Ellerman @ 2019-02-17 8:26 UTC (permalink / raw)
To: Andreas Schwab
Cc: erhard_f, jack, linux-mm, linux-kernel, linuxppc-dev,
aneesh.kumar
In-Reply-To: <87pnrran89.fsf@igel.home>
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Feb 14 2019, Michael Ellerman <mpe@ellerman.id.au> wrote:
>
>> The fix is simple, we need to convert the result of the bitwise && to
>> an int before returning it.
>
> Alternatively, the return type could be changed to bool, so that the
> compiler does the right thing by itself.
Yes that would be preferable. All other architectures return an int so
I wasn't game to switch to bool for a fix. But I don't see why it should
matter so I'll do a patch using bool for next.
cheers
^ permalink raw reply
* Re: powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Michael Ellerman @ 2019-02-17 8:21 UTC (permalink / raw)
To: Michael Ellerman, linuxppc-dev
Cc: linux-mm, jack, aneesh.kumar, linux-kernel, erhard_f
In-Reply-To: <20190214062339.7139-1-mpe@ellerman.id.au>
On Thu, 2019-02-14 at 06:23:39 UTC, Michael Ellerman wrote:
> In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
> rather than just checking that the value is non-zero, e.g.:
>
> static inline int pgd_present(pgd_t pgd)
> {
> - return !pgd_none(pgd);
> + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> }
>
> Unfortunately this is broken on big endian, as the result of the
> bitwise && is truncated to int, which is always zero because
> _PAGE_PRESENT is 0x8000000000000000ul. This means pgd_present() and
> pud_present() are always false at compile time, and the compiler
> elides the subsequent code.
>
> Remarkably with that bug present we are still able to boot and run
> with few noticeable effects. However under some work loads we are able
> to trigger a warning in the ext4 code:
>
> WARNING: CPU: 11 PID: 29593 at fs/ext4/inode.c:3927 .ext4_set_page_dirty+0x70/0xb0
> CPU: 11 PID: 29593 Comm: debugedit Not tainted 4.20.0-rc1 #1
> ...
> NIP .ext4_set_page_dirty+0x70/0xb0
> LR .set_page_dirty+0xa0/0x150
> Call Trace:
> .set_page_dirty+0xa0/0x150
> .unmap_page_range+0xbf0/0xe10
> .unmap_vmas+0x84/0x130
> .unmap_region+0xe8/0x190
> .__do_munmap+0x2f0/0x510
> .__vm_munmap+0x80/0x110
> .__se_sys_munmap+0x14/0x30
> system_call+0x5c/0x70
>
> The fix is simple, we need to convert the result of the bitwise && to
> an int before returning it.
>
> Thanks to Jan Kara and Aneesh for help with debugging.
>
> Fixes: da7ad366b497 ("powerpc/mm/book3s: Update pmd_present to look at _PAGE_PRESENT bit")
> Cc: stable@vger.kernel.org # v4.20+
> Reported-by: Erhard F. <erhard_f@mailbox.org>
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Applied to powerpc fixes.
https://git.kernel.org/powerpc/c/a58007621be33e9f7c7bed5d5ff8ecb9
cheers
^ permalink raw reply
* [GIT PULL] Please pull powerpc/linux.git powerpc-5.0-5 tag
From: Michael Ellerman @ 2019-02-17 8:20 UTC (permalink / raw)
To: Linus Torvalds; +Cc: linuxppc-dev, linux-kernel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Linus,
Please pull one more powerpc fix for 5.0:
The following changes since commit 5a3840a470c41ec0b85cd36ca80370330656b163:
powerpc/papr_scm: Use the correct bind address (2019-02-01 10:13:51 +1100)
are available in the git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git tags/powerpc-5.0-5
for you to fetch changes up to a58007621be33e9f7c7bed5d5ff8ecb914e1044a:
powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present() (2019-02-17 15:24:45 +1100)
- ------------------------------------------------------------------
powerpc fixes for 5.0 #5
Just one fix, for pgd/pud_present() which were broken on big endian since v4.20,
leading to possible data corruption.
Thanks to:
Aneesh Kumar K.V., Erhard F., Jan Kara.
- ------------------------------------------------------------------
Michael Ellerman (1):
powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
-----BEGIN PGP SIGNATURE-----
iQIcBAEBAgAGBQJcaRiIAAoJEFHr6jzI4aWA6rYQAKQQGiQAWrbGlP65hMGjx++c
6YTsHnR88NpvWc0hGp9Pa8w/JCHBVWY1rlkrm/WfmerGb9y2vHR7HrwMVwA3Sw4Y
tTzYO4zUPtRghdcSQhLLKmkfxFtX6w/ZrLcBDwcQkhUhNKGxEptgIaJZFwJmdpfv
2eAbq+inaNwDK5IVjANOxniwUmRYCcj5HhmnBiK46zrQ5q6S/0Z77CvZri4OxrlX
ywyH9RjqTTqqfUe0abAt3C0/7SKjzjZeHOOGHeGb314+70zCYfT781IlCaII6d3J
sOP4WnXGXX4pKVuDqu6BzaRf/sJBppiyHe4+iWE4FGKFUT1AUU18wausYmIeJcE/
P4FzEMWk9dOJEOJ4/XKbvrpWmpOiUl9w1jY/PVNh1QWyrzk1NVr+jhhNTjgvX6lj
9SVrYuhl57Ops5nqv3b6we+WbnG9Irfy+LqopJUePyUrdq/OljrRGp21WiLF1GYI
fzYszqvv8+iES+F4sgocpgf0nt2M3YSu+f5HdHJ8Q2RwbeScZz24IVSV7N4/ko3e
aGG8PL8dhddu5jFxOWEKWesv5w4RaxPpnMqz+VolDoP21+p6nZvx2QsxtVwk0V/R
WXMV7iEMZpjJK+KvKN1dKDKVX+sf5XcMa2fbCZ2LiXEnj5esF3EL2YABuSUOapm3
i04uXRAf2lxI5mEXPxK7
=PcTT
-----END PGP SIGNATURE-----
^ permalink raw reply
* Re: [RFC PATCH 0/5] powerpc: KASAN for 64-bit Book3E
From: Balbir Singh @ 2019-02-17 6:34 UTC (permalink / raw)
To: Daniel Axtens; +Cc: aneesh.kumar, linuxppc-dev, kasan-dev
In-Reply-To: <20190215000441.14323-1-dja@axtens.net>
On Fri, Feb 15, 2019 at 11:04:36AM +1100, Daniel Axtens wrote:
> Building on the work of Christophe, Aneesh and Balbir, I've ported
> KASAN to the e6500, a 64-bit Book3E processor which doesn't have a
> hashed page table. It applies on top of Christophe's series, v5.
>
> It requires some changes to the KASAN core - please let me know if
> these are problematic and we see if an alternative approach is
> possible.
>
> The KASAN shadow area is mapped into vmemmap space:
> 0x8000 0400 0000 0000 to 0x8000 0600 0000 0000.
> To do this we require that vmemmap be disabled. (This is the default
> in the kernel config that QorIQ provides for the machine in their
> SDK anyway - they use flat memory.)
>
> Only outline instrumentation is supported and only KASAN_MINIMAL works.
> Only the kernel linear mapping (0xc000...) is checked. The vmalloc and
> ioremap areas (also in 0x800...) are all mapped to a zero page. As
> with the Book3S hash series, this requires overriding the memory <->
> shadow mapping.
>
> Also, as with both previous 64-bit series, early instrumentation is not
> supported.
>
> KVM, kexec and xmon have not been tested.
>
> Thanks to those who have done the heavy lifting over the past several years:
> - Christophe's 32 bit series: https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-February/185379.html
> - Aneesh's Book3S hash series: https://lwn.net/Articles/655642/
> - Balbir's Book3S radix series: https://patchwork.ozlabs.org/patch/795211/
>
> While useful if you have an Book3E device, this is mostly intended
> as a warm-up exercise for reviving Aneesh's series for book3s hash.
> In particular, changes to the kasan core are going to be required
> for hash and radix as well.
>
Thanks for following through with this, could you please share details on
how you've been testing this?
I know qemu supports qemu -cpu e6500, but beyond that what does the machine
look like?
Balbir Singh.
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Balbir Singh @ 2019-02-17 6:23 UTC (permalink / raw)
To: Segher Boessenkool
Cc: erhard_f, jack, linux-mm, linux-kernel, linuxppc-dev,
aneesh.kumar
In-Reply-To: <20190216142206.GE14180@gate.crashing.org>
On Sat, Feb 16, 2019 at 08:22:12AM -0600, Segher Boessenkool wrote:
> Hi all,
>
> On Sat, Feb 16, 2019 at 09:55:11PM +1100, Balbir Singh wrote:
> > On Thu, Feb 14, 2019 at 05:23:39PM +1100, Michael Ellerman wrote:
> > > In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
> > > rather than just checking that the value is non-zero, e.g.:
> > >
> > > static inline int pgd_present(pgd_t pgd)
> > > {
> > > - return !pgd_none(pgd);
> > > + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> > > }
> > >
> > > Unfortunately this is broken on big endian, as the result of the
> > > bitwise && is truncated to int, which is always zero because
>
> (Bitwise "&" of course).
>
> > Not sure why that should happen, why is the result an int? What
> > causes the casting of pgd_t & be64 to be truncated to an int.
>
> Yes, it's not obvious as written... It's simply that the return type of
> pgd_present is int. So it is truncated _after_ the bitwise and.
>
Thanks, I am surprised the compiler does not complain about the truncation
of bits. I wonder if we are missing -Wconversion
Balbir
^ permalink raw reply
* [RFC PATCH 2/2] powerpc/mm/hash64: Map all the kernel mapping in the same 0xc range
From: Aneesh Kumar K.V @ 2019-02-17 5:16 UTC (permalink / raw)
To: npiggin, benh, paulus, mpe, Akshay Adiga, Daniel Axtens
Cc: Aneesh Kumar K.V, linuxppc-dev
In-Reply-To: <20190217051609.24140-1-aneesh.kumar@linux.ibm.com>
This patch maps vmap, IO and vmemap regions in the 0xc address range
instead of the current 0xd and 0xf range. This brings the mapping closer
to radix translation mode.
With hash 64K page size each of this region is 512TB whereas with 4K config
we are limitted by the max page table range of 64TB and hence there regions
are of 16TB size.
NOT-Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
arch/powerpc/include/asm/book3s/64/hash-4k.h | 17 ++++
arch/powerpc/include/asm/book3s/64/hash-64k.h | 11 +++
arch/powerpc/include/asm/book3s/64/hash.h | 89 ++++++++++++++-----
arch/powerpc/include/asm/book3s/64/mmu-hash.h | 31 ++++---
arch/powerpc/include/asm/book3s/64/radix.h | 24 ++---
arch/powerpc/include/asm/page.h | 3 +-
arch/powerpc/kvm/book3s_hv_rm_xics.c | 2 +-
arch/powerpc/mm/copro_fault.c | 14 +--
arch/powerpc/mm/dump_hashpagetable.c | 2 +-
arch/powerpc/mm/dump_linuxpagetables.c | 2 +-
arch/powerpc/mm/hash_utils_64.c | 29 +++---
arch/powerpc/mm/pgtable-radix.c | 2 +-
arch/powerpc/mm/slb.c | 22 +++--
13 files changed, 166 insertions(+), 82 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/hash-4k.h b/arch/powerpc/include/asm/book3s/64/hash-4k.h
index cf5ba5254299..6db6e5c5c176 100644
--- a/arch/powerpc/include/asm/book3s/64/hash-4k.h
+++ b/arch/powerpc/include/asm/book3s/64/hash-4k.h
@@ -13,6 +13,23 @@
*/
#define MAX_EA_BITS_PER_CONTEXT 46
+/*
+ * Our page table limit us to 64TB. Hence for the kernel mapping,
+ * each MAP area is limited to 16 TB.
+ * The four map areas are:
+ * linear mapping
+ * vmap
+ * IO
+ * vmemmap
+ */
+#define EA_KERNEL_MAP_SIZE (ASM_CONST(1) << (46 - 2))
+
+/*
+ * Define the address range of the kernel non-linear virtual area
+ * 16TB
+ */
+#define H_KERN_VIRT_START ASM_CONST(0xc000100000000000)
+
#ifndef __ASSEMBLY__
#define H_PTE_TABLE_SIZE (sizeof(pte_t) << H_PTE_INDEX_SIZE)
#define H_PMD_TABLE_SIZE (sizeof(pmd_t) << H_PMD_INDEX_SIZE)
diff --git a/arch/powerpc/include/asm/book3s/64/hash-64k.h b/arch/powerpc/include/asm/book3s/64/hash-64k.h
index f82ee8a3b561..11add16d25d3 100644
--- a/arch/powerpc/include/asm/book3s/64/hash-64k.h
+++ b/arch/powerpc/include/asm/book3s/64/hash-64k.h
@@ -13,6 +13,17 @@
*/
#define MAX_EA_BITS_PER_CONTEXT 49
+/*
+ * We use one context for each MAP area.
+ */
+#define EA_KERNEL_MAP_SIZE (1UL << MAX_EA_BITS_PER_CONTEXT)
+
+/*
+ * Define the address range of the kernel non-linear virtual area
+ * 2PB
+ */
+#define H_KERN_VIRT_START ASM_CONST(0xc008000000000000)
+
/*
* 64k aligned address free up few of the lower bits of RPN for us
* We steal that here. For more deatils look at pte_pfn/pfn_pte()
diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/include/asm/book3s/64/hash.h
index 94f9db7a746a..18d5caab7e1d 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -30,6 +30,11 @@
H_PUD_INDEX_SIZE + H_PGD_INDEX_SIZE + PAGE_SHIFT)
#define H_PGTABLE_RANGE (ASM_CONST(1) << H_PGTABLE_EADDR_SIZE)
+/*
+ * Top 4 bits are ignored in page table walk.
+ */
+#define EA_MASK (~(0xfUL << 60))
+
/*
* We store the slot details in the second half of page table.
* Increase the pud level table so that hugetlb ptes can be stored
@@ -40,41 +45,63 @@
#else
#define H_PUD_CACHE_INDEX (H_PUD_INDEX_SIZE)
#endif
+
/*
- * Define the address range of the kernel non-linear virtual area
+ * 3 context will be used for vmap, IO and vmemmap
*/
-#define H_KERN_VIRT_START ASM_CONST(0xD000000000000000)
-#define H_KERN_VIRT_SIZE ASM_CONST(0x0000400000000000) /* 64T */
-
+#define H_KERN_VIRT_SIZE (EA_KERNEL_MAP_SIZE * 3)
/*
- * The vmalloc space starts at the beginning of that region, and
- * occupies half of it on hash CPUs and a quarter of it on Book3E
- * (we keep a quarter for the virtual memmap)
+ * +------------------------------+
+ * | |
+ * | |
+ * | |
+ * +------------------------------+ Kernel virtual map end (0xc00e000000000000)
+ * | |
+ * | |
+ * | 512TB/16TB of vmemmap |
+ * | |
+ * | |
+ * +------------------------------+ Kernel vmemmap start
+ * | |
+ * | 512TB/16TB of IO map |
+ * | |
+ * +------------------------------+ Kernel IO map start
+ * | |
+ * | 512TB/16TB of vmap |
+ * | |
+ * +------------------------------+ Kernel virt start (0xc008000000000000)
+ * | |
+ * | |
+ * | |
+ * +------------------------------+ Kernel linear (0xc.....)
*/
-#define H_VMALLOC_START H_KERN_VIRT_START
-#define H_VMALLOC_SIZE ASM_CONST(0x380000000000) /* 56T */
-#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)
-#define H_KERN_IO_START H_VMALLOC_END
-#define H_KERN_IO_END (H_KERN_VIRT_START + H_KER_VIRT_SIZE)
+#define H_KERN_VMALLOC_START H_KERN_VIRT_START
+#define H_KERN_VMALLOC_SIZE EA_KERNEL_MAP_SIZE
+#define H_KERN_VMALLOC_END (H_KERN_VMALLOC_START + H_KERN_VMALLOC_SIZE)
+
+#define H_KERN_IO_START H_KERN_VMALLOC_END
+#define H_KERN_IO_SIZE EA_KERNEL_MAP_SIZE
+#define H_KERN_IO_END (H_KERN_IO_START + H_KERN_IO_SIZE)
+
+#define H_KERN_VMEMMAP_START H_KERN_IO_END
+#define H_KERN_VMEMMAP_SIZE EA_KERNEL_MAP_SIZE
+#define H_KERN_VMEMMAP_END (H_KERN_VMEMMAP_START + H_KERN_VMEMMAP_SIZE)
/*
* Region IDs
*/
-#define REGION_SHIFT 60UL
-#define REGION_MASK (0xfUL << REGION_SHIFT)
-#define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
-
-#define VMALLOC_REGION_ID (REGION_ID(H_VMALLOC_START))
-#define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET))
-#define VMEMMAP_REGION_ID (0xfUL) /* Server only */
-#define USER_REGION_ID (0UL)
+#define USER_REGION_ID 1
+#define KERNEL_REGION_ID 2
+#define VMALLOC_REGION_ID 3
+#define IO_REGION_ID 4
+#define VMEMMAP_REGION_ID 5
+#define INVALID_REGION_ID 6
/*
* Defines the address of the vmemap area, in its own region on
* hash table CPUs.
*/
-#define H_VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT)
#ifdef CONFIG_PPC_MM_SLICES
#define HAVE_ARCH_UNMAPPED_AREA
@@ -90,6 +117,26 @@
#define H_PUD_BAD_BITS (PMD_TABLE_SIZE-1)
#ifndef __ASSEMBLY__
+static inline int get_region_id(unsigned long ea)
+{
+ int id = (ea >> 60UL);
+
+ if (id == 0)
+ return USER_REGION_ID;
+
+ if (id != 0xc)
+ return INVALID_REGION_ID;
+
+ if (ea >= H_KERN_VMEMMAP_START)
+ return VMEMMAP_REGION_ID;
+ else if (ea >= H_KERN_IO_START)
+ return IO_REGION_ID;
+ else if (ea >= H_KERN_VMALLOC_START)
+ return VMALLOC_REGION_ID;
+
+ return KERNEL_REGION_ID;
+}
+
#define hash__pmd_bad(pmd) (pmd_val(pmd) & H_PMD_BAD_BITS)
#define hash__pud_bad(pud) (pud_val(pud) & H_PUD_BAD_BITS)
static inline int hash__pgd_bad(pgd_t pgd)
diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 12e522807f9f..ddc67bc64ce0 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -588,7 +588,8 @@ extern void slb_set_size(u16 size);
#endif
#define MAX_VMALLOC_CTX_CNT 1
-#define MAX_MEMMAP_CTX_CNT 1
+#define MAX_IO_CTX_CNT 1
+#define MAX_VMEMMAP_CTX_CNT 1
/*
* 256MB segment
@@ -601,13 +602,10 @@ extern void slb_set_size(u16 size);
* would give a protovsid of 0x1fffffffff. That will result in a VSID 0
* because of the modulo operation in vsid scramble.
*
- * We add one extra context to MIN_USER_CONTEXT so that we can map kernel
- * context easily. The +1 is to map the unused 0xe region mapping.
*/
#define MAX_USER_CONTEXT ((ASM_CONST(1) << CONTEXT_BITS) - 2)
#define MIN_USER_CONTEXT (MAX_KERNEL_CTX_CNT + MAX_VMALLOC_CTX_CNT + \
- MAX_MEMMAP_CTX_CNT + 2)
-
+ MAX_IO_CTX_CNT + MAX_VMEMMAP_CTX_CNT)
/*
* For platforms that support on 65bit VA we limit the context bits
*/
@@ -747,7 +745,7 @@ static inline unsigned long get_vsid(unsigned long context, unsigned long ea,
/*
* Bad address. We return VSID 0 for that
*/
- if ((ea & ~REGION_MASK) >= H_PGTABLE_RANGE)
+ if ((ea & EA_MASK) >= H_PGTABLE_RANGE)
return 0;
if (!mmu_has_feature(MMU_FTR_68_BIT_VA))
@@ -774,28 +772,29 @@ static inline unsigned long get_vsid(unsigned long context, unsigned long ea,
* 0x00002 - [ 0xc002000000000000 - 0xc003ffffffffffff]
* 0x00003 - [ 0xc004000000000000 - 0xc005ffffffffffff]
* 0x00004 - [ 0xc006000000000000 - 0xc007ffffffffffff]
-
- * 0x00005 - [ 0xd000000000000000 - 0xd001ffffffffffff ]
- * 0x00006 - Not used - Can map 0xe000000000000000 range.
- * 0x00007 - [ 0xf000000000000000 - 0xf001ffffffffffff ]
*
- * So we can compute the context from the region (top nibble) by
- * subtracting 11, or 0xc - 1.
+ * vmap, IO, vmemap
+ *
+ * 0x00005 - [ 0xc008000000000000 - 0xc009ffffffffffff]
+ * 0x00006 - [ 0xc00a000000000000 - 0xc00bffffffffffff]
+ * 0x00007 - [ 0xc00c000000000000 - 0xc00dffffffffffff]
+ *
*/
static inline unsigned long get_kernel_context(unsigned long ea)
{
- unsigned long region_id = REGION_ID(ea);
+ unsigned long region_id = get_region_id(ea);
unsigned long ctx;
/*
- * For linear mapping we do support multiple context
+ * Depending on Kernel config, kernel region can have one context
+ * or more.
*/
if (region_id == KERNEL_REGION_ID) {
/*
* We already verified ea to be not beyond the addr limit.
*/
- ctx = 1 + ((ea & ~REGION_MASK) >> MAX_EA_BITS_PER_CONTEXT);
+ ctx = 1 + ((ea & EA_MASK) >> MAX_EA_BITS_PER_CONTEXT);
} else
- ctx = (region_id - 0xc) + MAX_KERNEL_CTX_CNT;
+ ctx = region_id + MAX_KERNEL_CTX_CNT - 2;
return ctx;
}
diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/asm/book3s/64/radix.h
index 0718c16b4e8d..f1287bb5ce60 100644
--- a/arch/powerpc/include/asm/book3s/64/radix.h
+++ b/arch/powerpc/include/asm/book3s/64/radix.h
@@ -72,17 +72,17 @@
* | |
* | |
* | |
- * +------------------------------+ Kernel IO map end (0xc010000000000000)
+ * +------------------------------+ Kernel vmemmap end (0xc010000000000000)
* | |
* | |
* | 1/2 of virtual map |
* | |
* | |
- * +------------------------------+ Kernel IO map start
+ * +------------------------------+ Kernel IO map end/vmemap start
* | |
* | 1/4 of virtual map |
* | |
- * +------------------------------+ Kernel vmemap start
+ * +------------------------------+ Kernel vmap end/ IO map start
* | |
* | 1/4 of virtual map |
* | |
@@ -96,22 +96,16 @@
#define RADIX_KERN_VIRT_START ASM_CONST(0xc008000000000000)
#define RADIX_KERN_VIRT_SIZE ASM_CONST(0x0008000000000000)
-/*
- * The vmalloc space starts at the beginning of that region, and
- * occupies a quarter of it on radix config.
- * (we keep a quarter for the virtual memmap)
- */
#define RADIX_VMALLOC_START RADIX_KERN_VIRT_START
#define RADIX_VMALLOC_SIZE (RADIX_KERN_VIRT_SIZE >> 2)
#define RADIX_VMALLOC_END (RADIX_VMALLOC_START + RADIX_VMALLOC_SIZE)
-/*
- * Defines the address of the vmemap area, in its own region on
- * hash table CPUs.
- */
-#define RADIX_VMEMMAP_BASE (RADIX_VMALLOC_END)
-#define RADIX_KERN_IO_START (RADIX_KERN_VIRT_START + (RADIX_KERN_VIRT_SIZE >> 1))
-#define RADIX_KERN_IO_END (RADIX_KERN_VIRT_START + RADIX_KERN_VIRT_SIZE)
+#define RADIX_KERN_IO_START RADIX_VMALLOC_END
+#define RADIX_KERN_IO_SIZE (RADIX_KERN_VIRT_SIZE >> 2)
+#define RADIX_KERN_IO_END (RADIX_KERN_IO_START + RADIX_KERN_IO_SIZE)
+
+#define RADIX_VMEMMAP_START (RADIX_VMALLOC_END)
+#define RADIX_VMEMMAP_END (RADIX_KERN_VIRT_START + RADIX_KERN_VIRT_SIZE)
#ifndef __ASSEMBLY__
#define RADIX_PTE_TABLE_SIZE (sizeof(pte_t) << RADIX_PTE_INDEX_SIZE)
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
index aa4497175bd3..bf18b4b335d8 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -148,7 +148,8 @@ static inline bool pfn_valid(unsigned long pfn)
* return true for some vmalloc addresses, which is incorrect. So explicitly
* check that the address is in the kernel region.
*/
-#define virt_addr_valid(kaddr) (REGION_ID(kaddr) == KERNEL_REGION_ID && \
+/* may be can drop get_region_id */
+#define virt_addr_valid(kaddr) (get_region_id((unsigned long)kaddr) == KERNEL_REGION_ID && \
pfn_valid(virt_to_pfn(kaddr)))
#else
#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
diff --git a/arch/powerpc/kvm/book3s_hv_rm_xics.c b/arch/powerpc/kvm/book3s_hv_rm_xics.c
index b3f5786b20dc..5ceddb1e3903 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_xics.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_xics.c
@@ -815,7 +815,7 @@ static inline void this_cpu_inc_rm(unsigned int __percpu *addr)
raddr = per_cpu_ptr(addr, cpu);
l = (unsigned long)raddr;
- if (REGION_ID(l) == VMALLOC_REGION_ID) {
+ if (get_region_id(l) == VMALLOC_REGION_ID) {
l = vmalloc_to_phys(raddr);
raddr = (unsigned int *)l;
}
diff --git a/arch/powerpc/mm/copro_fault.c b/arch/powerpc/mm/copro_fault.c
index c8da352e8686..0da84a03388c 100644
--- a/arch/powerpc/mm/copro_fault.c
+++ b/arch/powerpc/mm/copro_fault.c
@@ -105,7 +105,7 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
u64 vsid, vsidkey;
int psize, ssize;
- switch (REGION_ID(ea)) {
+ switch (get_region_id(ea)) {
case USER_REGION_ID:
pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
if (mm == NULL)
@@ -117,14 +117,18 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
break;
case VMALLOC_REGION_ID:
pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
- if (ea < VMALLOC_END)
- psize = mmu_vmalloc_psize;
- else
- psize = mmu_io_psize;
+ psize = mmu_vmalloc_psize;
ssize = mmu_kernel_ssize;
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
vsidkey = SLB_VSID_KERNEL;
break;
+
+ case IO_REGION_ID:
+ pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea);
+ psize = mmu_io_psize;
+ ssize = mmu_kernel_ssize;
+ vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
+ vsidkey = SLB_VSID_KERNEL;
case KERNEL_REGION_ID:
pr_devel("%s: 0x%llx -- KERNEL_REGION_ID\n", __func__, ea);
psize = mmu_linear_psize;
diff --git a/arch/powerpc/mm/dump_hashpagetable.c b/arch/powerpc/mm/dump_hashpagetable.c
index 869294695048..7f1b31dc2887 100644
--- a/arch/powerpc/mm/dump_hashpagetable.c
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -500,7 +500,7 @@ static void populate_markers(void)
address_markers[7].start_address = IOREMAP_BASE;
address_markers[8].start_address = IOREMAP_END;
#ifdef CONFIG_PPC_BOOK3S_64
- address_markers[9].start_address = H_VMEMMAP_BASE;
+ address_markers[9].start_address = H_KERN_VMEMMAP_START;
#else
address_markers[9].start_address = VMEMMAP_BASE;
#endif
diff --git a/arch/powerpc/mm/dump_linuxpagetables.c b/arch/powerpc/mm/dump_linuxpagetables.c
index 6aa41669ac1a..9de42f0b5ac2 100644
--- a/arch/powerpc/mm/dump_linuxpagetables.c
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -298,7 +298,7 @@ static void populate_markers(void)
address_markers[i++].start_address = IOREMAP_BASE;
address_markers[i++].start_address = IOREMAP_END;
#ifdef CONFIG_PPC_BOOK3S_64
- address_markers[i++].start_address = H_VMEMMAP_BASE;
+ address_markers[i++].start_address = H_KERN_VMEMMAP_START;
#else
address_markers[i++].start_address = VMEMMAP_BASE;
#endif
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index bbd87748f3f7..bf31f6479497 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1007,11 +1007,11 @@ void __init hash__early_init_mmu(void)
__kernel_virt_start = H_KERN_VIRT_START;
__kernel_virt_size = H_KERN_VIRT_SIZE;
- __vmalloc_start = H_VMALLOC_START;
- __vmalloc_end = H_VMALLOC_END;
+ __vmalloc_start = H_KERN_VMALLOC_START;
+ __vmalloc_end = H_KERN_VMALLOC_END;
__kernel_io_start = H_KERN_IO_START;
__kernel_io_end = H_KERN_IO_END;
- vmemmap = (struct page *)H_VMEMMAP_BASE;
+ vmemmap = (struct page *)H_KERN_VMEMMAP_START;
ioremap_bot = IOREMAP_BASE;
#ifdef CONFIG_PCI
@@ -1232,7 +1232,7 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea,
trace_hash_fault(ea, access, trap);
/* Get region & vsid */
- switch (REGION_ID(ea)) {
+ switch (get_region_id(ea)) {
case USER_REGION_ID:
user_region = 1;
if (! mm) {
@@ -1246,10 +1246,13 @@ int hash_page_mm(struct mm_struct *mm, unsigned long ea,
break;
case VMALLOC_REGION_ID:
vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
- if (ea < VMALLOC_END)
- psize = mmu_vmalloc_psize;
- else
- psize = mmu_io_psize;
+ psize = mmu_vmalloc_psize;
+ ssize = mmu_kernel_ssize;
+ break;
+
+ case IO_REGION_ID:
+ vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
+ psize = mmu_io_psize;
ssize = mmu_kernel_ssize;
break;
default:
@@ -1415,7 +1418,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap,
unsigned long flags = 0;
struct mm_struct *mm = current->mm;
- if (REGION_ID(ea) == VMALLOC_REGION_ID)
+ if ((get_region_id(ea) == VMALLOC_REGION_ID) ||
+ (get_region_id(ea) == IO_REGION_ID))
mm = &init_mm;
if (dsisr & DSISR_NOHPTE)
@@ -1431,8 +1435,9 @@ int __hash_page(unsigned long ea, unsigned long msr, unsigned long trap,
unsigned long access = _PAGE_PRESENT | _PAGE_READ;
unsigned long flags = 0;
struct mm_struct *mm = current->mm;
+ unsigned int region_id = get_region_id(ea);
- if (REGION_ID(ea) == VMALLOC_REGION_ID)
+ if ((region_id == VMALLOC_REGION_ID) || (region_id == IO_REGION_ID))
mm = &init_mm;
if (dsisr & DSISR_NOHPTE)
@@ -1449,7 +1454,7 @@ int __hash_page(unsigned long ea, unsigned long msr, unsigned long trap,
* 2) user space access kernel space.
*/
access |= _PAGE_PRIVILEGED;
- if ((msr & MSR_PR) || (REGION_ID(ea) == USER_REGION_ID))
+ if ((msr & MSR_PR) || (region_id == USER_REGION_ID))
access &= ~_PAGE_PRIVILEGED;
if (trap == 0x400)
@@ -1493,7 +1498,7 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,
int rc, ssize, update_flags = 0;
unsigned long access = _PAGE_PRESENT | _PAGE_READ | (is_exec ? _PAGE_EXEC : 0);
- BUG_ON(REGION_ID(ea) != USER_REGION_ID);
+ BUG_ON(get_region_id(ea) != USER_REGION_ID);
if (!should_hash_preload(mm, ea))
return;
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index c288abfc09e1..805250c5d181 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -583,7 +583,7 @@ void __init radix__early_init_mmu(void)
__vmalloc_end = RADIX_VMALLOC_END;
__kernel_io_start = RADIX_KERN_IO_START;
__kernel_io_end = RADIX_KERN_IO_END;
- vmemmap = (struct page *)RADIX_VMEMMAP_BASE;
+ vmemmap = (struct page *)RADIX_VMEMMAP_START;
ioremap_bot = IOREMAP_BASE;
#ifdef CONFIG_PCI
diff --git a/arch/powerpc/mm/slb.c b/arch/powerpc/mm/slb.c
index bc3914d54e26..a200cfffed2a 100644
--- a/arch/powerpc/mm/slb.c
+++ b/arch/powerpc/mm/slb.c
@@ -689,7 +689,7 @@ static long slb_allocate_kernel(unsigned long ea, unsigned long id)
if (id == KERNEL_REGION_ID) {
/* We only support upto MAX_PHYSMEM_BITS */
- if ((ea & ~REGION_MASK) > (1UL << MAX_PHYSMEM_BITS))
+ if ((ea & EA_MASK) > (1UL << MAX_PHYSMEM_BITS))
return -EFAULT;
flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_linear_psize].sllp;
@@ -697,20 +697,25 @@ static long slb_allocate_kernel(unsigned long ea, unsigned long id)
#ifdef CONFIG_SPARSEMEM_VMEMMAP
} else if (id == VMEMMAP_REGION_ID) {
- if ((ea & ~REGION_MASK) >= (1ULL << MAX_EA_BITS_PER_CONTEXT))
+ if (ea >= H_KERN_VMEMMAP_END)
return -EFAULT;
flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_vmemmap_psize].sllp;
#endif
} else if (id == VMALLOC_REGION_ID) {
- if ((ea & ~REGION_MASK) >= (1ULL << MAX_EA_BITS_PER_CONTEXT))
+ if (ea >= H_KERN_VMALLOC_END)
return -EFAULT;
- if (ea < H_VMALLOC_END)
- flags = local_paca->vmalloc_sllp;
- else
- flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_io_psize].sllp;
+ flags = local_paca->vmalloc_sllp;
+
+ } else if (id == IO_REGION_ID) {
+
+ if (ea >= H_KERN_IO_END)
+ return -EFAULT;
+
+ flags = SLB_VSID_KERNEL | mmu_psize_defs[mmu_io_psize].sllp;
+
} else {
return -EFAULT;
}
@@ -720,6 +725,7 @@ static long slb_allocate_kernel(unsigned long ea, unsigned long id)
ssize = MMU_SEGSIZE_256M;
context = get_kernel_context(ea);
+
return slb_insert_entry(ea, context, flags, ssize, true);
}
@@ -756,7 +762,7 @@ static long slb_allocate_user(struct mm_struct *mm, unsigned long ea)
long do_slb_fault(struct pt_regs *regs, unsigned long ea)
{
- unsigned long id = REGION_ID(ea);
+ unsigned long id = get_region_id(ea);
/* IRQs are not reconciled here, so can't check irqs_disabled */
VM_WARN_ON(mfmsr() & MSR_EE);
--
2.20.1
^ permalink raw reply related
* [RFC PATCH 1/2] powerpc/mm/hash64: Add a variable to track the end of IO mapping
From: Aneesh Kumar K.V @ 2019-02-17 5:16 UTC (permalink / raw)
To: npiggin, benh, paulus, mpe, Akshay Adiga, Daniel Axtens
Cc: Aneesh Kumar K.V, linuxppc-dev
NOT-Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
arch/powerpc/include/asm/book3s/64/hash.h | 1 +
arch/powerpc/include/asm/book3s/64/pgtable.h | 8 +++++---
arch/powerpc/include/asm/book3s/64/radix.h | 1 +
arch/powerpc/mm/hash_utils_64.c | 1 +
arch/powerpc/mm/pgtable-radix.c | 1 +
arch/powerpc/mm/pgtable_64.c | 2 ++
6 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/include/asm/book3s/64/hash.h
index 247aff9cc6ba..94f9db7a746a 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -56,6 +56,7 @@
#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)
#define H_KERN_IO_START H_VMALLOC_END
+#define H_KERN_IO_END (H_KERN_VIRT_START + H_KER_VIRT_SIZE)
/*
* Region IDs
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 544e54b3046d..dc71e2b92003 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -277,9 +277,12 @@ extern unsigned long __vmalloc_end;
extern unsigned long __kernel_virt_start;
extern unsigned long __kernel_virt_size;
extern unsigned long __kernel_io_start;
+extern unsigned long __kernel_io_end;
#define KERN_VIRT_START __kernel_virt_start
#define KERN_VIRT_SIZE __kernel_virt_size
#define KERN_IO_START __kernel_io_start
+#define KERN_IO_END __kernel_io_end
+
extern struct page *vmemmap;
extern unsigned long ioremap_bot;
extern unsigned long pci_io_base;
@@ -296,8 +299,7 @@ extern unsigned long pci_io_base;
#include <asm/barrier.h>
/*
- * The second half of the kernel virtual space is used for IO mappings,
- * it's itself carved into the PIO region (ISA and PHB IO space) and
+ * IO space itself carved into the PIO region (ISA and PHB IO space) and
* the ioremap space
*
* ISA_IO_BASE = KERN_IO_START, 64K reserved area
@@ -310,7 +312,7 @@ extern unsigned long pci_io_base;
#define PHB_IO_BASE (ISA_IO_END)
#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
#define IOREMAP_BASE (PHB_IO_END)
-#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE)
+#define IOREMAP_END (KERN_IO_END)
/* Advertise special mapping type for AGP */
#define HAVE_PAGE_AGP
diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/asm/book3s/64/radix.h
index 7d1a3d1543fc..0718c16b4e8d 100644
--- a/arch/powerpc/include/asm/book3s/64/radix.h
+++ b/arch/powerpc/include/asm/book3s/64/radix.h
@@ -111,6 +111,7 @@
#define RADIX_VMEMMAP_BASE (RADIX_VMALLOC_END)
#define RADIX_KERN_IO_START (RADIX_KERN_VIRT_START + (RADIX_KERN_VIRT_SIZE >> 1))
+#define RADIX_KERN_IO_END (RADIX_KERN_VIRT_START + RADIX_KERN_VIRT_SIZE)
#ifndef __ASSEMBLY__
#define RADIX_PTE_TABLE_SIZE (sizeof(pte_t) << RADIX_PTE_INDEX_SIZE)
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 4aa0797000f7..bbd87748f3f7 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1010,6 +1010,7 @@ void __init hash__early_init_mmu(void)
__vmalloc_start = H_VMALLOC_START;
__vmalloc_end = H_VMALLOC_END;
__kernel_io_start = H_KERN_IO_START;
+ __kernel_io_end = H_KERN_IO_END;
vmemmap = (struct page *)H_VMEMMAP_BASE;
ioremap_bot = IOREMAP_BASE;
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 931156069a81..c288abfc09e1 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -582,6 +582,7 @@ void __init radix__early_init_mmu(void)
__vmalloc_start = RADIX_VMALLOC_START;
__vmalloc_end = RADIX_VMALLOC_END;
__kernel_io_start = RADIX_KERN_IO_START;
+ __kernel_io_end = RADIX_KERN_IO_END;
vmemmap = (struct page *)RADIX_VMEMMAP_BASE;
ioremap_bot = IOREMAP_BASE;
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index fb1375c07e8c..7cea39bdf05f 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -98,6 +98,8 @@ unsigned long __vmalloc_end;
EXPORT_SYMBOL(__vmalloc_end);
unsigned long __kernel_io_start;
EXPORT_SYMBOL(__kernel_io_start);
+unsigned long __kernel_io_end;
+EXPORT_SYMBOL(__kernel_io_end);
struct page *vmemmap;
EXPORT_SYMBOL(vmemmap);
unsigned long __pte_frag_nr;
--
2.20.1
^ permalink raw reply related
* Re: [PATCH] powerpc/ptrace: Simplify vr_get/set() to avoid GCC warning
From: Meelis Roos @ 2019-02-16 19:15 UTC (permalink / raw)
To: Michael Ellerman, linuxppc-dev; +Cc: malat
In-Reply-To: <20190215061400.20302-1-mpe@ellerman.id.au>
> Rather than relying on that we can pass an explict end_pos based on
> the sizeof(vrsave). The result should be exactly the same but it's
> more obviously not over-reading/writing the stack and it avoids the
> compiler warning.
It works on my PowerMac G4 with Debian-ports unstable with gcc 8.
--
Meelis Roos
^ permalink raw reply
* [PATCH] cpufreq: powernv: fix missing check of return value in init_powernv_pstates()
From: Yangtao Li @ 2019-02-16 17:06 UTC (permalink / raw)
To: rjw, viresh.kumar, benh, paulus, mpe
Cc: Yangtao Li, linuxppc-dev, linux-kernel, linux-pm
kmalloc() could fail, so insert a check of its return value. And
if it fails, returns -ENOMEM.
And remove (struct pstate_idx_revmap_data *) to fix coccinelle WARNING
by the way.
WARNING: casting value returned by memory allocation function to (struct
pstate_idx_revmap_data *) is useless.
Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
---
drivers/cpufreq/powernv-cpufreq.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 7e7ad3879c4e..d2230812fa4b 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -244,6 +244,7 @@ static int init_powernv_pstates(void)
u32 len_ids, len_freqs;
u32 pstate_min, pstate_max, pstate_nominal;
u32 pstate_turbo, pstate_ultra_turbo;
+ int rc = -ENODEV;
power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
if (!power_mgt) {
@@ -327,8 +328,11 @@ static int init_powernv_pstates(void)
powernv_freqs[i].frequency = freq * 1000; /* kHz */
powernv_freqs[i].driver_data = id & 0xFF;
- revmap_data = (struct pstate_idx_revmap_data *)
- kmalloc(sizeof(*revmap_data), GFP_KERNEL);
+ revmap_data = kmalloc(sizeof(*revmap_data), GFP_KERNEL);
+ if (!revmap_data) {
+ rc = -ENOMEM;
+ goto out;
+ }
revmap_data->pstate_id = id & 0xFF;
revmap_data->cpufreq_table_idx = i;
@@ -357,7 +361,7 @@ static int init_powernv_pstates(void)
return 0;
out:
of_node_put(power_mgt);
- return -ENODEV;
+ return rc;
}
/* Returns the CPU frequency corresponding to the pstate_id. */
--
2.17.0
^ permalink raw reply related
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Segher Boessenkool @ 2019-02-16 14:22 UTC (permalink / raw)
To: Balbir Singh
Cc: erhard_f, jack, linux-mm, linux-kernel, linuxppc-dev,
aneesh.kumar
In-Reply-To: <20190216105511.GA31125@350D>
Hi all,
On Sat, Feb 16, 2019 at 09:55:11PM +1100, Balbir Singh wrote:
> On Thu, Feb 14, 2019 at 05:23:39PM +1100, Michael Ellerman wrote:
> > In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
> > rather than just checking that the value is non-zero, e.g.:
> >
> > static inline int pgd_present(pgd_t pgd)
> > {
> > - return !pgd_none(pgd);
> > + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> > }
> >
> > Unfortunately this is broken on big endian, as the result of the
> > bitwise && is truncated to int, which is always zero because
(Bitwise "&" of course).
> Not sure why that should happen, why is the result an int? What
> causes the casting of pgd_t & be64 to be truncated to an int.
Yes, it's not obvious as written... It's simply that the return type of
pgd_present is int. So it is truncated _after_ the bitwise and.
Segher
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Andreas Schwab @ 2019-02-16 13:15 UTC (permalink / raw)
To: Michael Ellerman
Cc: erhard_f, jack, linux-mm, linux-kernel, linuxppc-dev,
aneesh.kumar
In-Reply-To: <20190214062339.7139-1-mpe@ellerman.id.au>
On Feb 14 2019, Michael Ellerman <mpe@ellerman.id.au> wrote:
> The fix is simple, we need to convert the result of the bitwise && to
> an int before returning it.
Alternatively, the return type could be changed to bool, so that the
compiler does the right thing by itself.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply
* Re: [PATCH] ASoC: fsl_esai: fix register setting issue in RIGHT_J mode
From: Fabio Estevam @ 2019-02-16 13:19 UTC (permalink / raw)
To: S.j. Wang
Cc: nicoleotsuka@gmail.com, alsa-devel@alsa-project.org,
linuxppc-dev@lists.ozlabs.org, timur@kernel.org,
Xiubo.Lee@gmail.com
In-Reply-To: <1550228637-5675-1-git-send-email-shengjiu.wang@nxp.com>
Hi Shengjiu,
On Fri, Feb 15, 2019 at 9:04 AM S.j. Wang <shengjiu.wang@nxp.com> wrote:
>
> The ESAI_xCR_xWA is xCR's bit, not the xCCR's bit, driver set it to
> wrong register, correct it.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Please add a Fixes tag and Cc stable.
Also, it seems that Mark Brown is not on Cc. Please Cc him in v2.
Thanks
^ permalink raw reply
* Re: [PATCH] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present()
From: Balbir Singh @ 2019-02-16 10:55 UTC (permalink / raw)
To: Michael Ellerman
Cc: erhard_f, jack, linuxppc-dev, linux-kernel, linux-mm,
aneesh.kumar
In-Reply-To: <20190214062339.7139-1-mpe@ellerman.id.au>
On Thu, Feb 14, 2019 at 05:23:39PM +1100, Michael Ellerman wrote:
> In v4.20 we changed our pgd/pud_present() to check for _PAGE_PRESENT
> rather than just checking that the value is non-zero, e.g.:
>
> static inline int pgd_present(pgd_t pgd)
> {
> - return !pgd_none(pgd);
> + return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> }
>
> Unfortunately this is broken on big endian, as the result of the
> bitwise && is truncated to int, which is always zero because
Not sure why that should happen, why is the result an int? What
causes the casting of pgd_t & be64 to be truncated to an int.
> _PAGE_PRESENT is 0x8000000000000000ul. This means pgd_present() and
> pud_present() are always false at compile time, and the compiler
> elides the subsequent code.
>
> Remarkably with that bug present we are still able to boot and run
> with few noticeable effects. However under some work loads we are able
> to trigger a warning in the ext4 code:
>
> WARNING: CPU: 11 PID: 29593 at fs/ext4/inode.c:3927 .ext4_set_page_dirty+0x70/0xb0
> CPU: 11 PID: 29593 Comm: debugedit Not tainted 4.20.0-rc1 #1
> ...
> NIP .ext4_set_page_dirty+0x70/0xb0
> LR .set_page_dirty+0xa0/0x150
> Call Trace:
> .set_page_dirty+0xa0/0x150
> .unmap_page_range+0xbf0/0xe10
> .unmap_vmas+0x84/0x130
> .unmap_region+0xe8/0x190
> .__do_munmap+0x2f0/0x510
> .__vm_munmap+0x80/0x110
> .__se_sys_munmap+0x14/0x30
> system_call+0x5c/0x70
>
> The fix is simple, we need to convert the result of the bitwise && to
> an int before returning it.
>
> Thanks to Jan Kara and Aneesh for help with debugging.
>
> Fixes: da7ad366b497 ("powerpc/mm/book3s: Update pmd_present to look at _PAGE_PRESENT bit")
> Cc: stable@vger.kernel.org # v4.20+
> Reported-by: Erhard F. <erhard_f@mailbox.org>
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
> arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index c9bfe526ca9d..d8c8d7c9df15 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -904,7 +904,7 @@ static inline int pud_none(pud_t pud)
>
> static inline int pud_present(pud_t pud)
> {
> - return (pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT));
> + return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT));
> }
>
> extern struct page *pud_page(pud_t pud);
> @@ -951,7 +951,7 @@ static inline int pgd_none(pgd_t pgd)
>
> static inline int pgd_present(pgd_t pgd)
> {
> - return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> + return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
> }
>
Care to put a big FAT warning, so that we don't repeat this again
(as in authors planning on changing these bits).
Balbir Singh.
^ permalink raw reply
* Re: [PATCH] powerpc: use $(origin ARCH) to select KBUILD_DEFCONFIG
From: Masahiro Yamada @ 2019-02-16 2:25 UTC (permalink / raw)
To: Mathieu Malaterre; +Cc: linuxppc-dev, LKML, Paul Mackerras
In-Reply-To: <CA+7wUswJ5+nb3OdZYrx6++batRMUcnje3jLTgdN4zAQo=--xBg@mail.gmail.com>
On Sat, Feb 16, 2019 at 1:11 AM Mathieu Malaterre <malat@debian.org> wrote:
>
> On Fri, Feb 15, 2019 at 10:41 AM Masahiro Yamada
> <yamada.masahiro@socionext.com> wrote:
> >
> > I often test all Kconfig commands for all architectures. To ease my
> > workflow, I want 'make defconfig' at least working without any cross
> > compiler.
> >
> > Currently, arch/powerpc/Makefile checks CROSS_COMPILE to decide the
> > default defconfig source.
> >
> > If CROSS_COMPILE is unset, it is likely to be the native build, so
> > 'uname -m' is useful to choose the defconfig. If CROSS_COMPILE is set,
> > the user is cross-building (i.e. 'uname -m' is probably x86_64), so
> > it falls back to ppc64_defconfig. Yup, make sense.
> >
> > However, I want to run 'make ARCH=* defconfig' without setting
> > CROSS_COMPILE for each architecture.
> >
> > My suggestion is to check $(origin ARCH).
> >
> > When you cross-compile the kernel, you need to set ARCH from your
> > environment or from the command line.
> >
> > For the native build, you do not need to set ARCH. The default in
> > the top Makefile is used:
> >
> > ARCH ?= $(SUBARCH)
> >
> > Hence, $(origin ARCH) returns 'file'.
> >
> > Before this commit, 'make ARCH=powerpc defconfig' failed:
>
> In case you have not seen it, please check:
>
> http://patchwork.ozlabs.org/patch/1037835/
I did not know that because I do not subscribe to ppc ML.
Michael's patch looks good to me.
If you mimic x86, the following will work:
diff --git a/Makefile b/Makefile
index 86cf35d..eb9552d 100644
--- a/Makefile
+++ b/Makefile
@@ -356,6 +356,11 @@ ifeq ($(ARCH),sh64)
SRCARCH := sh
endif
+# Additional ARCH settings for powerpc
+ifneq ($(filter ppc%,$(ARCH)),)
+ SRCARCH := powerpc
+endif
+
KCONFIG_CONFIG ?= .config
export KCONFIG_CONFIG
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 488c9ed..ff01fef 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -34,10 +34,10 @@ ifdef CONFIG_PPC_BOOK3S_32
KBUILD_CFLAGS += -mcpu=powerpc
endif
-ifeq ($(CROSS_COMPILE),)
-KBUILD_DEFCONFIG := $(shell uname -m)_defconfig
-else
+ifeq ($(ARCH),powerpc)
KBUILD_DEFCONFIG := ppc64_defconfig
+else
+KBUILD_DEFCONFIG := $(ARCH)_defconfig
endif
ifdef CONFIG_PPC64
diff --git a/scripts/subarch.include b/scripts/subarch.include
index 6506828..c98323f 100644
--- a/scripts/subarch.include
+++ b/scripts/subarch.include
@@ -8,6 +8,6 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e
s/x86_64/x86/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
- -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
+ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
-e s/riscv.*/riscv/)
--
Best Regards
Masahiro Yamada
^ permalink raw reply related
* Re: [PATCH v5 0/3] Add NXP AUDMIX device and machine drivers
From: Nicolin Chen @ 2019-02-15 19:04 UTC (permalink / raw)
To: Viorel Suman
Cc: Mark Rutland, devicetree@vger.kernel.org,
alsa-devel@alsa-project.org, Timur Tabi, Xiubo Li,
linux-kernel@vger.kernel.org, S.j. Wang,
linuxppc-dev@lists.ozlabs.org, Takashi Iwai, Rob Herring,
Liam Girdwood, Viorel Suman, Cosmin Samoila, Mark Brown,
dl-linux-imx, Fabio Estevam, Jaroslav Kysela, Daniel Baluta
In-Reply-To: <1550239285-12587-1-git-send-email-viorel.suman@nxp.com>
On Fri, Feb 15, 2019 at 02:01:32PM +0000, Viorel Suman wrote:
> The patchset adds NXP Audio Mixer (AUDMIX) device and machine
> drivers and related DT bindings documentation.
For this series,
Acked-by: Nicolin Chen <nicoleotsuka@gmail.com>
And Rob gave his at the previous version already.
Thanks.
> Changes since V4:
> 1. Removed "model" attribute from device driver DT bindings documentation
> as suggested by Nicolin.
>
> Changes since V3:
> 1. Removed machine driver DT bindings documentation.
> 2. Trigger machine driver probe from device driver as suggested by Nicolin.
>
> Changes since V2:
> 1. Moved "dais" node from machine driver DTS node to device driver DTS node
> as suggested by Rob.
>
> Changes since V1:
> 1. Original patch split into distinct patches for the device driver and
> DT binding documentation.
> 2. Replaced AMIX with AUDMIX in both code and file names as it looks more
> RM-compliant.
> 3. Removed polarity control from CPU DAI driver as suggested by Nicolin.
> 4. Added machine driver and related DT binding documentation.
>
> Viorel Suman (3):
> ASoC: fsl: Add Audio Mixer CPU DAI driver
> ASoC: add fsl_audmix DT binding documentation
> ASoC: fsl: Add Audio Mixer machine driver
>
> .../devicetree/bindings/sound/fsl,audmix.txt | 50 ++
> sound/soc/fsl/Kconfig | 16 +
> sound/soc/fsl/Makefile | 5 +
> sound/soc/fsl/fsl_audmix.c | 578 +++++++++++++++++++++
> sound/soc/fsl/fsl_audmix.h | 102 ++++
> sound/soc/fsl/imx-audmix.c | 327 ++++++++++++
> 6 files changed, 1078 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/sound/fsl,audmix.txt
> create mode 100644 sound/soc/fsl/fsl_audmix.c
> create mode 100644 sound/soc/fsl/fsl_audmix.h
> create mode 100644 sound/soc/fsl/imx-audmix.c
>
> --
> 2.7.4
>
^ permalink raw reply
* Re: [PATCH v4 0/3] locking/rwsem: Rwsem rearchitecture part 0
From: Waiman Long @ 2019-02-15 18:58 UTC (permalink / raw)
To: Will Deacon, Peter Zijlstra
Cc: linux-ia64, linux-sh, linux-mips, H. Peter Anvin, sparclinux,
linux-riscv, linux-arch, linux-s390, Davidlohr Bueso,
linux-c6x-dev, linux-hexagon, x86, Ingo Molnar, uclinux-h8-devel,
linux-xtensa, Arnd Bergmann, linux-um, linux-m68k, openrisc,
Borislav Petkov, Thomas Gleixner, linux-arm-kernel, Tim Chen,
linux-parisc, Linus Torvalds, linux-kernel, linux-alpha,
nios2-dev, Andrew Morton, linuxppc-dev
In-Reply-To: <20190215184056.GC15084@fuggles.cambridge.arm.com>
On 02/15/2019 01:40 PM, Will Deacon wrote:
> On Thu, Feb 14, 2019 at 11:37:15AM +0100, Peter Zijlstra wrote:
>> On Wed, Feb 13, 2019 at 05:00:14PM -0500, Waiman Long wrote:
>>> v4:
>>> - Remove rwsem-spinlock.c and make all archs use rwsem-xadd.c.
>>>
>>> v3:
>>> - Optimize __down_read_trylock() for the uncontended case as suggested
>>> by Linus.
>>>
>>> v2:
>>> - Add patch 2 to optimize __down_read_trylock() as suggested by PeterZ.
>>> - Update performance test data in patch 1.
>>>
>>> The goal of this patchset is to remove the architecture specific files
>>> for rwsem-xadd to make it easer to add enhancements in the later rwsem
>>> patches. It also removes the legacy rwsem-spinlock.c file and make all
>>> the architectures use one single implementation of rwsem - rwsem-xadd.c.
>>>
>>> Waiman Long (3):
>>> locking/rwsem: Remove arch specific rwsem files
>>> locking/rwsem: Remove rwsem-spinlock.c & use rwsem-xadd.c for all
>>> archs
>>> locking/rwsem: Optimize down_read_trylock()
>> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
>>
>> with the caveat that I'm happy to exchange patch 3 back to my earlier
>> suggestion in case Will expesses concerns wrt the ARM64 performance of
>> Linus' suggestion.
> Right, the current proposal doesn't work well for us, unfortunately. Which
> was your earlier suggestion?
>
> Will
In my posting yesterday, I showed that most of the trylocks done were
actually uncontended. Assuming that pattern hold for the most of the
workloads, it will not that bad after all.
-Longman
^ permalink raw reply
* Re: [PATCH] ASoC: fsl_esai: fix register setting issue in RIGHT_J mode
From: Nicolin Chen @ 2019-02-15 18:55 UTC (permalink / raw)
To: S.j. Wang
Cc: linuxppc-dev@lists.ozlabs.org, alsa-devel@alsa-project.org,
festevam@gmail.com, timur@kernel.org, Xiubo.Lee@gmail.com
In-Reply-To: <1550228637-5675-1-git-send-email-shengjiu.wang@nxp.com>
On Fri, Feb 15, 2019 at 11:04:38AM +0000, S.j. Wang wrote:
> The ESAI_xCR_xWA is xCR's bit, not the xCCR's bit, driver set it to
> wrong register, correct it.
>
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Would need this for stable kernel too.
Ackedy-by: Nicolin Chen <nicoleotsuka@gmail.com>
Thanks.
> ---
> sound/soc/fsl/fsl_esai.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
> index 57b484768a58..afe67c865330 100644
> --- a/sound/soc/fsl/fsl_esai.c
> +++ b/sound/soc/fsl/fsl_esai.c
> @@ -398,7 +398,8 @@ static int fsl_esai_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
> break;
> case SND_SOC_DAIFMT_RIGHT_J:
> /* Data on rising edge of bclk, frame high, right aligned */
> - xccr |= ESAI_xCCR_xCKP | ESAI_xCCR_xHCKP | ESAI_xCR_xWA;
> + xccr |= ESAI_xCCR_xCKP | ESAI_xCCR_xHCKP;
> + xcr |= ESAI_xCR_xWA;
> break;
> case SND_SOC_DAIFMT_DSP_A:
> /* Data on rising edge of bclk, frame high, 1clk before data */
> @@ -455,12 +456,12 @@ static int fsl_esai_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
> return -EINVAL;
> }
>
> - mask = ESAI_xCR_xFSL | ESAI_xCR_xFSR;
> + mask = ESAI_xCR_xFSL | ESAI_xCR_xFSR | ESAI_xCR_xWA;
> regmap_update_bits(esai_priv->regmap, REG_ESAI_TCR, mask, xcr);
> regmap_update_bits(esai_priv->regmap, REG_ESAI_RCR, mask, xcr);
>
> mask = ESAI_xCCR_xCKP | ESAI_xCCR_xHCKP | ESAI_xCCR_xFSP |
> - ESAI_xCCR_xFSD | ESAI_xCCR_xCKD | ESAI_xCR_xWA;
> + ESAI_xCCR_xFSD | ESAI_xCCR_xCKD;
> regmap_update_bits(esai_priv->regmap, REG_ESAI_TCCR, mask, xccr);
> regmap_update_bits(esai_priv->regmap, REG_ESAI_RCCR, mask, xccr);
>
> --
> 1.9.1
>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox