* Re: [PATCH] Disable kcov for slb routines.
From: Satheesh Rajendran @ 2019-03-07 4:37 UTC (permalink / raw)
To: Mahesh J Salgaonkar
Cc: linuxppc-dev, syzkaller, Paul Mackerras, Nicholas Piggin,
Andrew Donnellan
In-Reply-To: <155168793242.4372.10864050702181452671.stgit@jupiter.in.ibm.com>
On Mon, Mar 04, 2019 at 01:55:51PM +0530, Mahesh J Salgaonkar wrote:
> From: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
>
> The kcov instrumentation inside SLB routines causes duplicate SLB entries
> to be added resulting into SLB multihit machine checks.
> Disable kcov instrumentation on slb.o
>
> Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
> ---
> arch/powerpc/mm/Makefile | 1 +
> 1 file changed, 1 insertion(+)
Fixes: https://github.com/linuxppc/issues/issues/230
Tested-by: Satheesh Rajendran <sathnaga@linux.vent.ibm.com>
>
> diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
> index d4d32e229ace..f9cb40684746 100644
> --- a/arch/powerpc/mm/Makefile
> +++ b/arch/powerpc/mm/Makefile
> @@ -60,3 +60,4 @@ obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o
> # This is necessary for booting with kcov enabled on book3e machines
> KCOV_INSTRUMENT_tlb_nohash.o := n
> KCOV_INSTRUMENT_fsl_booke_mmu.o := n
> +KCOV_INSTRUMENT_slb.o := n
>
^ permalink raw reply
* [PATCH] powerpc: silence unused-but-set-variable warnings
From: Qian Cai @ 2019-03-07 3:48 UTC (permalink / raw)
To: benh, paulus, mpe; +Cc: Qian Cai, linuxppc-dev, linux-kernel
pte_unmap() compiles away on some powerpc platforms, so silence the
warnings below by using the argument to pte_unmap() as a nop. Also, fix
checkpatch.pl warnings "Single statement macros should not use a do {}
while (0) loop".
mm/memory.c: In function 'copy_pte_range':
mm/memory.c:820:24: warning: variable 'orig_dst_pte' set but not used
[-Wunused-but-set-variable]
mm/memory.c:820:9: warning: variable 'orig_src_pte' set but not used
[-Wunused-but-set-variable]
mm/madvise.c: In function 'madvise_free_pte_range':
mm/madvise.c:318:9: warning: variable 'orig_pte' set but not used
[-Wunused-but-set-variable]
mm/swap_state.c: In function 'swap_ra_info':
mm/swap_state.c:634:15: warning: variable 'orig_pte' set but not used
[-Wunused-but-set-variable]
Signed-off-by: Qian Cai <cai@lca.pw>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +-
arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
2 files 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 868fcaf56f6b..ec00ce6dd312 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1006,7 +1006,7 @@ extern struct page *pgd_page(pgd_t pgd);
(((pte_t *) pmd_page_vaddr(*(dir))) + pte_index(addr))
#define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
-#define pte_unmap(pte) do { } while(0)
+#define pte_unmap(pte) (void)(pte)
/* to find an entry in a kernel page-table-directory */
/* This now only contains the vmalloc pages */
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
index e77ed9761632..103071afab3d 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -205,7 +205,7 @@ static inline void pgd_set(pgd_t *pgdp, unsigned long val)
(((pte_t *) pmd_page_vaddr(*(dir))) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
#define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
-#define pte_unmap(pte) do { } while(0)
+#define pte_unmap(pte) (void)(pte)
/* to find an entry in a kernel page-table-directory */
/* This now only contains the vmalloc pages */
--
2.17.2 (Apple Git-113)
^ permalink raw reply related
* Re: [PATCH v9 02/11] powerpc: prepare string/mem functions for KASAN
From: Christophe Leroy @ 2019-03-06 21:54 UTC (permalink / raw)
To: Daniel Axtens, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, Nicholas Piggin, Aneesh Kumar K.V,
Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov
Cc: linux-mm, linuxppc-dev, linux-kernel, kasan-dev
In-Reply-To: <87sgw31a85.fsf@dja-thinkpad.axtens.net>
Le 04/03/2019 à 06:26, Daniel Axtens a écrit :
> Hi Christophe,
>> diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
>> new file mode 100644
>> index 000000000000..c3161b8fc017
>> --- /dev/null
>> +++ b/arch/powerpc/include/asm/kasan.h
>> @@ -0,0 +1,15 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +#ifndef __ASM_KASAN_H
>> +#define __ASM_KASAN_H
>> +
>> +#ifdef CONFIG_KASAN
>> +#define _GLOBAL_KASAN(fn) .weak fn ; _GLOBAL(__##fn) ; _GLOBAL(fn)
>> +#define _GLOBAL_TOC_KASAN(fn) .weak fn ; _GLOBAL_TOC(__##fn) ; _GLOBAL_TOC(fn)
>> +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) ; EXPORT_SYMBOL(fn)
>
> I'm having some trouble with this. I get warnings like this:
I don't have such problem, neither with ppc32 nor with ppc64e_defconfig.
What config are you using ?
Another (unrelated) question I have:
On the initial arm64 implementation (39d114ddc682 arm64: add KASAN
support) they made KASAN implementation depend on SPARSEMEM_VMEMMAP
(allthough they later removed that dependency with commit e17d8025f07e
arm64/mm/kasan: don't use vmemmap_populate() to initialize shadow)
So I'm wondering why on your side, KASAN depends on !SPARSEMEM_VMEMMAP
Thanks
Christophe
>
> WARNING: EXPORT symbol "__memcpy" [vmlinux] version generation failed, symbol will not be versioned.
>
> It seems to be related to the export line, as if I swap the exports to
> do fn before __##fn I get:
>
> WARNING: EXPORT symbol "memset" [vmlinux] version generation failed, symbol will not be versioned.
>
> I have narrowed this down to combining 2 EXPORT_SYMBOL()s on one line.
> This works - no warning:
>
> EXPORT_SYMBOL(memset)
> EXPORT_SYMBOL(__memset)
>
> This throws a warning:
>
> EXPORT_SYMBOL(memset) ; EXPORT_SYMBOL(__memset)
>
> I notice in looking at the diff of preprocessed source we end up
> invoking an asm macro that doesn't seem to have a full final argument, I
> wonder if that's relevant...
>
> -___EXPORT_SYMBOL __memset, __memset, ; ___EXPORT_SYMBOL memset, memset,
> +___EXPORT_SYMBOL __memset, __memset,
> +___EXPORT_SYMBOL memset, memset,
>
> I also notice that nowhere else in the source do people have multiple
> EXPORT_SYMBOLs on the same line, and other arches seem to just
> unconditionally export both symbols on multiple lines.
>
> I have no idea how this works for you - maybe it's affected by something 32bit.
>
> How would you feel about this approach instead? I'm not tied to any of
> the names or anything.
>
> diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
> index e0637730a8e7..7b6a91b448dd 100644
> --- a/arch/powerpc/include/asm/ppc_asm.h
> +++ b/arch/powerpc/include/asm/ppc_asm.h
> @@ -214,6 +214,9 @@ name: \
>
> #define DOTSYM(a) a
>
> +#define PROVIDE_WEAK_ALIAS(strongname, weakname) \
> + .weak weakname ; .set weakname, strongname ;
> +
> #else
>
> #define XGLUE(a,b) a##b
> @@ -236,6 +239,10 @@ GLUE(.,name):
>
> #define DOTSYM(a) GLUE(.,a)
>
> +#define PROVIDE_WEAK_ALIAS(strongname, weakname) \
> + .weak weakname ; .set weakname, strongname ; \
> + .weak DOTSYM(weakname) ; .set DOTSYM(weakname), DOTSYM(strongname) ;
> +
> #endif
>
> #else /* 32-bit */
> @@ -251,6 +258,9 @@ GLUE(.,name):
>
> #define _GLOBAL_TOC(name) _GLOBAL(name)
>
> +#define PROVIDE_WEAK_ALIAS(strongname, weakname) \
> + .weak weakname ; .set weakname, strongname ;
> +
> #endif
>
> /*
> --- a/arch/powerpc/lib/mem_64.S
> +++ b/arch/powerpc/lib/mem_64.S
> @@ -33,7 +33,8 @@ EXPORT_SYMBOL(__memset32)
> EXPORT_SYMBOL(__memset64)
> #endif
>
> -_GLOBAL_KASAN(memset)
> +PROVIDE_WEAK_ALIAS(__memset,memset)
> +_GLOBAL(__memset)
> neg r0,r3
> rlwimi r4,r4,8,16,23
> andi. r0,r0,7 /* # bytes to be 8-byte aligned */
> @@ -98,9 +99,11 @@ _GLOBAL_KASAN(memset)
> 10: bflr 31
> stb r4,0(r6)
> blr
> -EXPORT_SYMBOL_KASAN(memset)
> +EXPORT_SYMBOL(memset)
> +EXPORT_SYMBOL(__memset)
>
> -_GLOBAL_TOC_KASAN(memmove)
> +PROVIDE_WEAK_ALIAS(__memmove,memove)
> +_GLOBAL_TOC(__memmove)
> cmplw 0,r3,r4
> bgt backwards_memcpy
> b memcpy
> @@ -141,4 +144,5 @@ _GLOBAL(backwards_memcpy)
> beq 2b
> mtctr r7
> b 1b
> -EXPORT_SYMBOL_KASAN(memmove)
> +EXPORT_SYMBOL(memmove)
> +EXPORT_SYMBOL(__memmove)
> diff --git a/arch/powerpc/lib/memcpy_64.S b/arch/powerpc/lib/memcpy_64.S
> index 862b515b8868..7c1b09556cad 100644
> --- a/arch/powerpc/lib/memcpy_64.S
> +++ b/arch/powerpc/lib/memcpy_64.S
> @@ -19,7 +19,8 @@
> #endif
>
> .align 7
> -_GLOBAL_TOC_KASAN(memcpy)
> +PROVIDE_WEAK_ALIAS(__memcpy,memcpy)
> +_GLOBAL_TOC(__memcpy)
> BEGIN_FTR_SECTION
> #ifdef __LITTLE_ENDIAN__
> cmpdi cr7,r5,0
> @@ -230,4 +231,5 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD)
> 4: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */
> blr
> #endif
> -EXPORT_SYMBOL_KASAN(memcpy)
> +EXPORT_SYMBOL(__memcpy)
> +EXPORT_SYMBOL(memcpy)
>
>
> Regards,
> Daniel
>
>
>> +#else
>> +#define _GLOBAL_KASAN(fn) _GLOBAL(fn)
>> +#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(fn)
>> +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(fn)
>> +#endif
>> +
>> +#endif
>> diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h
>> index 1647de15a31e..9bf6dffb4090 100644
>> --- a/arch/powerpc/include/asm/string.h
>> +++ b/arch/powerpc/include/asm/string.h
>> @@ -4,14 +4,17 @@
>>
>> #ifdef __KERNEL__
>>
>> +#ifndef CONFIG_KASAN
>> #define __HAVE_ARCH_STRNCPY
>> #define __HAVE_ARCH_STRNCMP
>> +#define __HAVE_ARCH_MEMCHR
>> +#define __HAVE_ARCH_MEMCMP
>> +#define __HAVE_ARCH_MEMSET16
>> +#endif
>> +
>> #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
>>
>> extern char * strcpy(char *,const char *);
>> @@ -27,7 +30,27 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
>> extern void * memchr(const void *,int,__kernel_size_t);
>> extern void * memcpy_flushcache(void *,const void *,__kernel_size_t);
>>
>> +void *__memset(void *s, int c, __kernel_size_t count);
>> +void *__memcpy(void *to, const void *from, __kernel_size_t n);
>> +void *__memmove(void *to, const void *from, __kernel_size_t n);
>> +
>> +#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
>> +/*
>> + * For files that are not instrumented (e.g. mm/slub.c) we
>> + * should use not instrumented version of mem* functions.
>> + */
>> +#define memcpy(dst, src, len) __memcpy(dst, src, len)
>> +#define memmove(dst, src, len) __memmove(dst, src, len)
>> +#define memset(s, c, n) __memset(s, c, n)
>> +
>> +#ifndef __NO_FORTIFY
>> +#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
>> +#endif
>> +
>> +#endif
>> +
>> #ifdef CONFIG_PPC64
>> +#ifndef CONFIG_KASAN
>> #define __HAVE_ARCH_MEMSET32
>> #define __HAVE_ARCH_MEMSET64
>>
>> @@ -49,8 +72,11 @@ static inline void *memset64(uint64_t *p, uint64_t v, __kernel_size_t n)
>> {
>> return __memset64(p, v, n * 8);
>> }
>> +#endif
>> #else
>> +#ifndef CONFIG_KASAN
>> #define __HAVE_ARCH_STRLEN
>> +#endif
>>
>> extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
>> #endif
>> diff --git a/arch/powerpc/kernel/prom_init_check.sh b/arch/powerpc/kernel/prom_init_check.sh
>> index 667df97d2595..181fd10008ef 100644
>> --- a/arch/powerpc/kernel/prom_init_check.sh
>> +++ b/arch/powerpc/kernel/prom_init_check.sh
>> @@ -16,8 +16,16 @@
>> # If you really need to reference something from prom_init.o add
>> # it to the list below:
>>
>> +grep "^CONFIG_KASAN=y$" .config >/dev/null
>> +if [ $? -eq 0 ]
>> +then
>> + MEM_FUNCS="__memcpy __memset"
>> +else
>> + MEM_FUNCS="memcpy memset"
>> +fi
>> +
>> WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
>> -_end enter_prom memcpy memset reloc_offset __secondary_hold
>> +_end enter_prom $MEM_FUNCS reloc_offset __secondary_hold
>> __secondary_hold_acknowledge __secondary_hold_spinloop __start
>> strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224
>> reloc_got2 kernstart_addr memstart_addr linux_banner _stext
>> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
>> index 79396e184bca..47a4de434c22 100644
>> --- a/arch/powerpc/lib/Makefile
>> +++ b/arch/powerpc/lib/Makefile
>> @@ -8,9 +8,14 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
>> CFLAGS_REMOVE_code-patching.o = $(CC_FLAGS_FTRACE)
>> CFLAGS_REMOVE_feature-fixups.o = $(CC_FLAGS_FTRACE)
>>
>> -obj-y += string.o alloc.o code-patching.o feature-fixups.o
>> +obj-y += alloc.o code-patching.o feature-fixups.o
>>
>> -obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o strlen_32.o
>> +ifndef CONFIG_KASAN
>> +obj-y += string.o memcmp_$(BITS).o
>> +obj-$(CONFIG_PPC32) += strlen_32.o
>> +endif
>> +
>> +obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o
>>
>> obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
>>
>> @@ -34,7 +39,7 @@ obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o \
>> test_emulate_step_exec_instr.o
>>
>> obj-y += checksum_$(BITS).o checksum_wrappers.o \
>> - string_$(BITS).o memcmp_$(BITS).o
>> + string_$(BITS).o
>>
>> obj-y += sstep.o ldstfp.o quad.o
>> obj64-y += quad.o
>> diff --git a/arch/powerpc/lib/copy_32.S b/arch/powerpc/lib/copy_32.S
>> index ba66846fe973..fc4fa7246200 100644
>> --- a/arch/powerpc/lib/copy_32.S
>> +++ b/arch/powerpc/lib/copy_32.S
>> @@ -14,6 +14,7 @@
>> #include <asm/ppc_asm.h>
>> #include <asm/export.h>
>> #include <asm/code-patching-asm.h>
>> +#include <asm/kasan.h>
>>
>> #define COPY_16_BYTES \
>> lwz r7,4(r4); \
>> @@ -68,6 +69,7 @@ CACHELINE_BYTES = L1_CACHE_BYTES
>> LG_CACHELINE_BYTES = L1_CACHE_SHIFT
>> CACHELINE_MASK = (L1_CACHE_BYTES-1)
>>
>> +#ifndef CONFIG_KASAN
>> _GLOBAL(memset16)
>> rlwinm. r0 ,r5, 31, 1, 31
>> addi r6, r3, -4
>> @@ -81,6 +83,7 @@ _GLOBAL(memset16)
>> sth r4, 4(r6)
>> blr
>> EXPORT_SYMBOL(memset16)
>> +#endif
>>
>> /*
>> * Use dcbz on the complete cache lines in the destination
>> @@ -91,7 +94,7 @@ EXPORT_SYMBOL(memset16)
>> * We therefore skip the optimised bloc that uses dcbz. This jump is
>> * replaced by a nop once cache is active. This is done in machine_init()
>> */
>> -_GLOBAL(memset)
>> +_GLOBAL_KASAN(memset)
>> cmplwi 0,r5,4
>> blt 7f
>>
>> @@ -150,7 +153,7 @@ _GLOBAL(memset)
>> 9: stbu r4,1(r6)
>> bdnz 9b
>> blr
>> -EXPORT_SYMBOL(memset)
>> +EXPORT_SYMBOL_KASAN(memset)
>>
>> /*
>> * This version uses dcbz on the complete cache lines in the
>> @@ -163,12 +166,12 @@ EXPORT_SYMBOL(memset)
>> * We therefore jump to generic_memcpy which doesn't use dcbz. This jump is
>> * replaced by a nop once cache is active. This is done in machine_init()
>> */
>> -_GLOBAL(memmove)
>> +_GLOBAL_KASAN(memmove)
>> cmplw 0,r3,r4
>> bgt backwards_memcpy
>> /* fall through */
>>
>> -_GLOBAL(memcpy)
>> +_GLOBAL_KASAN(memcpy)
>> 1: b generic_memcpy
>> patch_site 1b, patch__memcpy_nocache
>>
>> @@ -242,8 +245,8 @@ _GLOBAL(memcpy)
>> stbu r0,1(r6)
>> bdnz 40b
>> 65: blr
>> -EXPORT_SYMBOL(memcpy)
>> -EXPORT_SYMBOL(memmove)
>> +EXPORT_SYMBOL_KASAN(memcpy)
>> +EXPORT_SYMBOL_KASAN(memmove)
>>
>> generic_memcpy:
>> srwi. r7,r5,3
>> diff --git a/arch/powerpc/lib/mem_64.S b/arch/powerpc/lib/mem_64.S
>> index 3c3be02f33b7..7cd6cf6822a2 100644
>> --- a/arch/powerpc/lib/mem_64.S
>> +++ b/arch/powerpc/lib/mem_64.S
>> @@ -12,7 +12,9 @@
>> #include <asm/errno.h>
>> #include <asm/ppc_asm.h>
>> #include <asm/export.h>
>> +#include <asm/kasan.h>
>>
>> +#ifndef CONFIG_KASAN
>> _GLOBAL(__memset16)
>> rlwimi r4,r4,16,0,15
>> /* fall through */
>> @@ -29,8 +31,9 @@ _GLOBAL(__memset64)
>> EXPORT_SYMBOL(__memset16)
>> EXPORT_SYMBOL(__memset32)
>> EXPORT_SYMBOL(__memset64)
>> +#endif
>>
>> -_GLOBAL(memset)
>> +_GLOBAL_KASAN(memset)
>> neg r0,r3
>> rlwimi r4,r4,8,16,23
>> andi. r0,r0,7 /* # bytes to be 8-byte aligned */
>> @@ -95,9 +98,9 @@ _GLOBAL(memset)
>> 10: bflr 31
>> stb r4,0(r6)
>> blr
>> -EXPORT_SYMBOL(memset)
>> +EXPORT_SYMBOL_KASAN(memset)
>>
>> -_GLOBAL_TOC(memmove)
>> +_GLOBAL_TOC_KASAN(memmove)
>> cmplw 0,r3,r4
>> bgt backwards_memcpy
>> b memcpy
>> @@ -138,4 +141,4 @@ _GLOBAL(backwards_memcpy)
>> beq 2b
>> mtctr r7
>> b 1b
>> -EXPORT_SYMBOL(memmove)
>> +EXPORT_SYMBOL_KASAN(memmove)
>> diff --git a/arch/powerpc/lib/memcpy_64.S b/arch/powerpc/lib/memcpy_64.S
>> index 273ea67e60a1..862b515b8868 100644
>> --- a/arch/powerpc/lib/memcpy_64.S
>> +++ b/arch/powerpc/lib/memcpy_64.S
>> @@ -11,6 +11,7 @@
>> #include <asm/export.h>
>> #include <asm/asm-compat.h>
>> #include <asm/feature-fixups.h>
>> +#include <asm/kasan.h>
>>
>> #ifndef SELFTEST_CASE
>> /* For big-endian, 0 == most CPUs, 1 == POWER6, 2 == Cell */
>> @@ -18,7 +19,7 @@
>> #endif
>>
>> .align 7
>> -_GLOBAL_TOC(memcpy)
>> +_GLOBAL_TOC_KASAN(memcpy)
>> BEGIN_FTR_SECTION
>> #ifdef __LITTLE_ENDIAN__
>> cmpdi cr7,r5,0
>> @@ -229,4 +230,4 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD)
>> 4: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */
>> blr
>> #endif
>> -EXPORT_SYMBOL(memcpy)
>> +EXPORT_SYMBOL_KASAN(memcpy)
>> --
>> 2.13.3
^ permalink raw reply
* Re: [PATCH v5 4/4] hugetlb: allow to free gigantic pages regardless of the configuration
From: Dave Hansen @ 2019-03-06 21:17 UTC (permalink / raw)
To: Alex Ghiti, Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
In-Reply-To: <82a3f572-e9c1-0151-3d7d-a646f5e5302c@ghiti.fr>
On 3/6/19 12:08 PM, Alex Ghiti wrote:
>>>
>>> + /*
>>> + * Gigantic pages allocation depends on the capability for large
>>> page
>>> + * range allocation. If the system cannot provide
>>> alloc_contig_range,
>>> + * allow users to free gigantic pages.
>>> + */
>>> + if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
>>> + spin_lock(&hugetlb_lock);
>>> + if (count > persistent_huge_pages(h)) {
>>> + spin_unlock(&hugetlb_lock);
>>> + return -EINVAL;
>>> + }
>>> + goto decrease_pool;
>>> + }
>> We talked about it during the last round and I don't seen any mention of
>> it here in comments or the changelog: Why is this a goto? Why don't we
>> just let the code fall through to the "decrease_pool" label? Why is
>> this new block needed at all? Can't we just remove the old check and
>> let it be?
>
> I'll get rid of the goto, I don't know how to justify it properly in a
> comment,
> maybe because it is not necessary.
> This is not a new block, this means exactly the same as before (remember
> gigantic_page_supported() actually meant CONTIG_ALLOC before this series),
> except that now we allow a user to free boottime allocated gigantic pages.
> And no we cannot just remove the check and let it be since it would modify
> the current behaviour, which is to return an error when trying to allocate
> gigantic pages whereas alloc_contig_range is not defined. I thought it was
> clearly commented above, I can try to make it more explicit.
OK, that makes sense. Could you get some of this in the changelog,
please? Otherwise this all looks good to me.
^ permalink raw reply
* Re: [PATCH v5 4/4] hugetlb: allow to free gigantic pages regardless of the configuration
From: Alex Ghiti @ 2019-03-06 20:08 UTC (permalink / raw)
To: Dave Hansen, Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
In-Reply-To: <7c81abe0-5f9d-32f9-1e9a-70ab06d48f8e@intel.com>
On 3/6/19 2:16 PM, Dave Hansen wrote:
> On 3/6/19 11:00 AM, Alexandre Ghiti wrote:
>> +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;
>> + /*
>> + * Gigantic pages allocation depends on the capability for large page
>> + * range allocation. If the system cannot provide alloc_contig_range,
>> + * allow users to free gigantic pages.
>> + */
>> + if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
>> + spin_lock(&hugetlb_lock);
>> + if (count > persistent_huge_pages(h)) {
>> + spin_unlock(&hugetlb_lock);
>> + return -EINVAL;
>> + }
>> + goto decrease_pool;
>> + }
> We talked about it during the last round and I don't seen any mention of
> it here in comments or the changelog: Why is this a goto? Why don't we
> just let the code fall through to the "decrease_pool" label? Why is
> this new block needed at all? Can't we just remove the old check and
> let it be?
I'll get rid of the goto, I don't know how to justify it properly in a
comment,
maybe because it is not necessary.
This is not a new block, this means exactly the same as before (remember
gigantic_page_supported() actually meant CONTIG_ALLOC before this series),
except that now we allow a user to free boottime allocated gigantic pages.
And no we cannot just remove the check and let it be since it would modify
the current behaviour, which is to return an error when trying to allocate
gigantic pages whereas alloc_contig_range is not defined. I thought it was
clearly commented above, I can try to make it more explicit.
^ permalink raw reply
* Re: [PATCH v5 3/4] mm: Simplify MEMORY_ISOLATION && COMPACTION || CMA into CONTIG_ALLOC
From: Alex Ghiti @ 2019-03-06 19:42 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
In-Reply-To: <6a50153b-c68b-f96c-1840-df6b7dd2cc61@suse.cz>
On 3/6/19 2:30 PM, Vlastimil Babka wrote:
> On 3/6/19 8:00 PM, Alexandre Ghiti wrote:
>> This condition allows to define alloc_contig_range, so simplify
>> it into a more accurate naming.
>>
>> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
>> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
>
> (you could have sent this with my ack from v4 as there wasn't
> significant change, just the one I suggested :)
Thanks, that's good to know.
Alex
^ permalink raw reply
* Re: [PATCH v5 2/4] sparc: Advertise gigantic page support
From: Alex Ghiti @ 2019-03-06 19:10 UTC (permalink / raw)
To: David Miller
Cc: dalias, linux-sh, peterz, dave.hansen, heiko.carstens, linux-mm,
paulus, hpa, sparclinux, linux-s390, ysato, x86, mingo, vbabka,
catalin.marinas, will.deacon, bp, luto, tglx, linux-arm-kernel,
linux-kernel, schwidefsky, linuxppc-dev, mike.kravetz
In-Reply-To: <20190306.110436.1714716608828903522.davem@davemloft.net>
On 3/6/19 2:04 PM, David Miller wrote:
> From: Alexandre Ghiti <alex@ghiti.fr>
> Date: Wed, 6 Mar 2019 14:00:03 -0500
>
>> sparc actually supports gigantic pages and selecting
>> ARCH_HAS_GIGANTIC_PAGE allows it to allocate and free
>> gigantic pages at runtime.
>>
>> sparc allows configuration such as huge pages of 16GB,
>> pages of 8KB and MAX_ORDER = 13 (default):
>> HPAGE_SHIFT (34) - PAGE_SHIFT (13) = 21 >= MAX_ORDER (13)
>>
>> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> Much better.
>
> Acked-by: David S. Miller <davem@davemloft.net>
Thanks !
Alex
^ permalink raw reply
* Re: [PATCH v5 3/4] mm: Simplify MEMORY_ISOLATION && COMPACTION || CMA into CONTIG_ALLOC
From: Vlastimil Babka @ 2019-03-06 19:30 UTC (permalink / raw)
To: Alexandre Ghiti, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
In-Reply-To: <20190306190005.7036-4-alex@ghiti.fr>
On 3/6/19 8:00 PM, Alexandre Ghiti wrote:
> This condition allows to define alloc_contig_range, so simplify
> it into a more accurate naming.
>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
(you could have sent this with my ack from v4 as there wasn't
significant change, just the one I suggested :)
^ permalink raw reply
* Re: [PATCH v5 4/4] hugetlb: allow to free gigantic pages regardless of the configuration
From: David Miller @ 2019-03-06 19:20 UTC (permalink / raw)
To: alex
Cc: dalias, linux-sh, peterz, dave.hansen, heiko.carstens, linux-mm,
paulus, hpa, sparclinux, linux-s390, ysato, x86, mingo, vbabka,
catalin.marinas, will.deacon, bp, luto, tglx, linux-arm-kernel,
linux-kernel, schwidefsky, linuxppc-dev, mike.kravetz
In-Reply-To: <20190306190005.7036-5-alex@ghiti.fr>
From: Alexandre Ghiti <alex@ghiti.fr>
Date: Wed, 6 Mar 2019 14:00:05 -0500
> On systems without CONTIG_ALLOC activated but that support gigantic pages,
> boottime reserved gigantic pages can not be freed at all. This patch
> simply enables the possibility to hand back those pages to memory
> allocator.
>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
For sparc:
Acked-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply
* Re: [PATCH v5 4/4] hugetlb: allow to free gigantic pages regardless of the configuration
From: Dave Hansen @ 2019-03-06 19:16 UTC (permalink / raw)
To: Alexandre Ghiti, Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
In-Reply-To: <20190306190005.7036-5-alex@ghiti.fr>
On 3/6/19 11:00 AM, Alexandre Ghiti wrote:
> +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;
> + /*
> + * Gigantic pages allocation depends on the capability for large page
> + * range allocation. If the system cannot provide alloc_contig_range,
> + * allow users to free gigantic pages.
> + */
> + if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
> + spin_lock(&hugetlb_lock);
> + if (count > persistent_huge_pages(h)) {
> + spin_unlock(&hugetlb_lock);
> + return -EINVAL;
> + }
> + goto decrease_pool;
> + }
We talked about it during the last round and I don't seen any mention of
it here in comments or the changelog: Why is this a goto? Why don't we
just let the code fall through to the "decrease_pool" label? Why is
this new block needed at all? Can't we just remove the old check and
let it be?
^ permalink raw reply
* [PATCH v5 4/4] hugetlb: allow to free gigantic pages regardless of the configuration
From: Alexandre Ghiti @ 2019-03-06 19:00 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
Cc: Alexandre Ghiti
In-Reply-To: <20190306190005.7036-1-alex@ghiti.fr>
On systems without CONTIG_ALLOC activated but that support gigantic pages,
boottime reserved gigantic pages can not be freed at all. This patch
simply enables the possibility to hand back those pages to memory
allocator.
Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
---
arch/arm64/Kconfig | 2 +-
arch/arm64/include/asm/hugetlb.h | 4 --
arch/powerpc/include/asm/book3s/64/hugetlb.h | 7 ---
arch/powerpc/platforms/Kconfig.cputype | 2 +-
arch/s390/Kconfig | 2 +-
arch/s390/include/asm/hugetlb.h | 3 --
arch/sh/Kconfig | 2 +-
arch/sparc/Kconfig | 2 +-
arch/x86/Kconfig | 2 +-
arch/x86/include/asm/hugetlb.h | 4 --
include/linux/gfp.h | 2 +-
mm/hugetlb.c | 54 ++++++++++++--------
mm/page_alloc.c | 4 +-
13 files changed, 42 insertions(+), 48 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 091a513b93e9..af687eff884a 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -18,7 +18,7 @@ config ARM64
select ARCH_HAS_FAST_MULTIPLIER
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
select ARCH_HAS_KCOV
select ARCH_HAS_MEMBARRIER_SYNC_CORE
select ARCH_HAS_PTE_SPECIAL
diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h
index fb6609875455..59893e766824 100644
--- a/arch/arm64/include/asm/hugetlb.h
+++ b/arch/arm64/include/asm/hugetlb.h
@@ -65,8 +65,4 @@ extern void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr,
#include <asm-generic/hugetlb.h>
-#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
-static inline bool gigantic_page_supported(void) { return true; }
-#endif
-
#endif /* __ASM_HUGETLB_H */
diff --git a/arch/powerpc/include/asm/book3s/64/hugetlb.h b/arch/powerpc/include/asm/book3s/64/hugetlb.h
index 5b0177733994..d04a0bcc2f1c 100644
--- a/arch/powerpc/include/asm/book3s/64/hugetlb.h
+++ b/arch/powerpc/include/asm/book3s/64/hugetlb.h
@@ -32,13 +32,6 @@ static inline int hstate_get_psize(struct hstate *hstate)
}
}
-#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
-static inline bool gigantic_page_supported(void)
-{
- return true;
-}
-#endif
-
/* hugepd entry valid bit */
#define HUGEPD_VAL_BITS (0x8000000000000000UL)
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index f677c8974212..dc0328de20cd 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -319,7 +319,7 @@ config ARCH_ENABLE_SPLIT_PMD_PTLOCK
config PPC_RADIX_MMU
bool "Radix MMU Support"
depends on PPC_BOOK3S_64
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
default y
help
Enable support for the Power ISA 3.0 Radix style MMU. Currently this
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 1c57b83c76f5..d84e536796b1 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -69,7 +69,7 @@ config S390
select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
select ARCH_HAS_KCOV
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SET_MEMORY
diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h
index 2d1afa58a4b6..bd191560efcf 100644
--- a/arch/s390/include/asm/hugetlb.h
+++ b/arch/s390/include/asm/hugetlb.h
@@ -116,7 +116,4 @@ static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
return pte_modify(pte, newprot);
}
-#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
-static inline bool gigantic_page_supported(void) { return true; }
-#endif
#endif /* _ASM_S390_HUGETLB_H */
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index c7266302691c..404b12a0d871 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -53,7 +53,7 @@ config SUPERH
select HAVE_FUTEX_CMPXCHG if FUTEX
select HAVE_NMI
select NEED_SG_DMA_LENGTH
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
help
The SuperH is a RISC processor targeted for use in embedded systems
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index ca33c80870e2..234a6bd46e89 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -90,7 +90,7 @@ config SPARC64
select ARCH_CLOCKSOURCE_DATA
select ARCH_HAS_PTE_SPECIAL
select PCI_DOMAINS if PCI
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
config ARCH_DEFCONFIG
string
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 8ba90f3e0038..ff24eaeef211 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -23,7 +23,7 @@ config X86_64
def_bool y
depends on 64BIT
# Options that are inherently 64-bit kernel only:
- select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
+ select ARCH_HAS_GIGANTIC_PAGE
select ARCH_SUPPORTS_INT128
select ARCH_USE_CMPXCHG_LOCKREF
select HAVE_ARCH_SOFT_DIRTY
diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
index 7469d321f072..f65cfb48cfdd 100644
--- a/arch/x86/include/asm/hugetlb.h
+++ b/arch/x86/include/asm/hugetlb.h
@@ -17,8 +17,4 @@ static inline void arch_clear_hugepage_flags(struct page *page)
{
}
-#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
-static inline bool gigantic_page_supported(void) { return true; }
-#endif
-
#endif /* _ASM_X86_HUGETLB_H */
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 1f1ad9aeebb9..58ea44bf75de 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -589,8 +589,8 @@ static inline bool pm_suspended_storage(void)
/* 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);
#ifdef CONFIG_CMA
/* CMA stuff */
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index afef61656c1e..7c57d58051ec 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1058,6 +1058,7 @@ static void free_gigantic_page(struct page *page, unsigned int order)
free_contig_range(page_to_pfn(page), 1 << order);
}
+#ifdef CONFIG_CONTIG_ALLOC
static int __alloc_gigantic_page(unsigned long start_pfn,
unsigned long nr_pages, gfp_t gfp_mask)
{
@@ -1142,11 +1143,20 @@ 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_CONTIG_ALLOC */
+static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
+ int nid, nodemask_t *nodemask)
+{
+ return NULL;
+}
+#endif /* CONFIG_CONTIG_ALLOC */
#else /* !CONFIG_ARCH_HAS_GIGANTIC_PAGE */
-static inline bool gigantic_page_supported(void) { return false; }
static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask,
- int nid, nodemask_t *nodemask) { return NULL; }
+ 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) { }
@@ -1156,9 +1166,6 @@ static void update_and_free_page(struct hstate *h, struct page *page)
{
int i;
- if (hstate_is_gigantic(h) && !gigantic_page_supported())
- return;
-
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 +2283,24 @@ 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,
- nodemask_t *nodes_allowed)
+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;
+ /*
+ * Gigantic pages allocation depends on the capability for large page
+ * range allocation. If the system cannot provide alloc_contig_range,
+ * allow users to free gigantic pages.
+ */
+ if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
+ spin_lock(&hugetlb_lock);
+ if (count > persistent_huge_pages(h)) {
+ spin_unlock(&hugetlb_lock);
+ return -EINVAL;
+ }
+ goto decrease_pool;
+ }
/*
* Increase the pool size
@@ -2322,6 +2340,7 @@ static unsigned long set_max_huge_pages(struct hstate *h, unsigned long count,
goto out;
}
+decrease_pool:
/*
* Decrease the pool size
* First return free pages to the buddy allocator (being careful
@@ -2350,9 +2369,10 @@ static unsigned long set_max_huge_pages(struct hstate *h, unsigned long count,
break;
}
out:
- ret = persistent_huge_pages(h);
+ h->max_huge_pages = persistent_huge_pages(h);
spin_unlock(&hugetlb_lock);
- return ret;
+
+ return 0;
}
#define HSTATE_ATTR_RO(_name) \
@@ -2404,11 +2424,6 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
int err;
NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
- if (hstate_is_gigantic(h) && !gigantic_page_supported()) {
- err = -EINVAL;
- goto out;
- }
-
if (nid == NUMA_NO_NODE) {
/*
* global hstate attribute
@@ -2428,15 +2443,12 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
} else
nodes_allowed = &node_states[N_MEMORY];
- h->max_huge_pages = set_max_huge_pages(h, count, nodes_allowed);
+ err = set_max_huge_pages(h, count, nodes_allowed);
if (nodes_allowed != &node_states[N_MEMORY])
NODEMASK_FREE(nodes_allowed);
- return len;
-out:
- NODEMASK_FREE(nodes_allowed);
- return err;
+ return err ? err : len;
}
static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ac9c45ffb344..a4547d90fa7a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8234,8 +8234,9 @@ int alloc_contig_range(unsigned long start, unsigned long end,
pfn_max_align_up(end), migratetype);
return ret;
}
+#endif /* CONFIG_CONTIG_ALLOC */
-void free_contig_range(unsigned long pfn, unsigned nr_pages)
+void free_contig_range(unsigned long pfn, unsigned int nr_pages)
{
unsigned int count = 0;
@@ -8247,7 +8248,6 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages)
}
WARN(count != 0, "%d pages are still in use!\n", count);
}
-#endif
#ifdef CONFIG_MEMORY_HOTPLUG
/*
--
2.20.1
^ permalink raw reply related
* Re: [PATCH v5 2/4] sparc: Advertise gigantic page support
From: David Miller @ 2019-03-06 19:04 UTC (permalink / raw)
To: alex
Cc: dalias, linux-sh, peterz, dave.hansen, heiko.carstens, linux-mm,
paulus, hpa, sparclinux, linux-s390, ysato, x86, mingo, vbabka,
catalin.marinas, will.deacon, bp, luto, tglx, linux-arm-kernel,
linux-kernel, schwidefsky, linuxppc-dev, mike.kravetz
In-Reply-To: <20190306190005.7036-3-alex@ghiti.fr>
From: Alexandre Ghiti <alex@ghiti.fr>
Date: Wed, 6 Mar 2019 14:00:03 -0500
> sparc actually supports gigantic pages and selecting
> ARCH_HAS_GIGANTIC_PAGE allows it to allocate and free
> gigantic pages at runtime.
>
> sparc allows configuration such as huge pages of 16GB,
> pages of 8KB and MAX_ORDER = 13 (default):
> HPAGE_SHIFT (34) - PAGE_SHIFT (13) = 21 >= MAX_ORDER (13)
>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
Much better.
Acked-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply
* [PATCH v5 3/4] mm: Simplify MEMORY_ISOLATION && COMPACTION || CMA into CONTIG_ALLOC
From: Alexandre Ghiti @ 2019-03-06 19:00 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
Cc: Alexandre Ghiti
In-Reply-To: <20190306190005.7036-1-alex@ghiti.fr>
This condition allows to define alloc_contig_range, so simplify
it into a more accurate naming.
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
---
arch/arm64/Kconfig | 2 +-
arch/powerpc/platforms/Kconfig.cputype | 2 +-
arch/s390/Kconfig | 2 +-
arch/sh/Kconfig | 2 +-
arch/sparc/Kconfig | 2 +-
arch/x86/Kconfig | 2 +-
arch/x86/mm/hugetlbpage.c | 2 +-
include/linux/gfp.h | 2 +-
mm/Kconfig | 3 +++
mm/page_alloc.c | 3 +--
10 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index a4168d366127..091a513b93e9 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -18,7 +18,7 @@ config ARM64
select ARCH_HAS_FAST_MULTIPLIER
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
select ARCH_HAS_KCOV
select ARCH_HAS_MEMBARRIER_SYNC_CORE
select ARCH_HAS_PTE_SPECIAL
diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
index 8c7464c3f27f..f677c8974212 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -319,7 +319,7 @@ config ARCH_ENABLE_SPLIT_PMD_PTLOCK
config PPC_RADIX_MMU
bool "Radix MMU Support"
depends on PPC_BOOK3S_64
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
default y
help
Enable support for the Power ISA 3.0 Radix style MMU. Currently this
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index ed554b09eb3f..1c57b83c76f5 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -69,7 +69,7 @@ config S390
select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_GCOV_PROFILE_ALL
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
select ARCH_HAS_KCOV
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SET_MEMORY
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 299a17bed67c..c7266302691c 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -53,7 +53,7 @@ config SUPERH
select HAVE_FUTEX_CMPXCHG if FUTEX
select HAVE_NMI
select NEED_SG_DMA_LENGTH
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
help
The SuperH is a RISC processor targeted for use in embedded systems
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 0b7f0e0fefa5..ca33c80870e2 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -90,7 +90,7 @@ config SPARC64
select ARCH_CLOCKSOURCE_DATA
select ARCH_HAS_PTE_SPECIAL
select PCI_DOMAINS if PCI
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
config ARCH_DEFCONFIG
string
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 68261430fe6e..8ba90f3e0038 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -23,7 +23,7 @@ config X86_64
def_bool y
depends on 64BIT
# Options that are inherently 64-bit kernel only:
- select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
+ select ARCH_HAS_GIGANTIC_PAGE if CONTIG_ALLOC
select ARCH_SUPPORTS_INT128
select ARCH_USE_CMPXCHG_LOCKREF
select HAVE_ARCH_SOFT_DIRTY
diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
index 92e4c4b85bba..fab095362c50 100644
--- a/arch/x86/mm/hugetlbpage.c
+++ b/arch/x86/mm/hugetlbpage.c
@@ -203,7 +203,7 @@ static __init int setup_hugepagesz(char *opt)
}
__setup("hugepagesz=", setup_hugepagesz);
-#if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA)
+#ifdef CONFIG_CONTIG_ALLOC
static __init int gigantic_pages_init(void)
{
/* With compaction or CMA we can allocate gigantic pages at runtime */
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 5f5e25fd6149..1f1ad9aeebb9 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -585,7 +585,7 @@ static inline bool pm_suspended_storage(void)
}
#endif /* CONFIG_PM_SLEEP */
-#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);
diff --git a/mm/Kconfig b/mm/Kconfig
index 25c71eb8a7db..137eadc18732 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -258,6 +258,9 @@ config ARCH_ENABLE_HUGEPAGE_MIGRATION
config ARCH_ENABLE_THP_MIGRATION
bool
+config CONTIG_ALLOC
+ def_bool (MEMORY_ISOLATION && COMPACTION) || CMA
+
config PHYS_ADDR_T_64BIT
def_bool 64BIT
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 35fdde041f5c..ac9c45ffb344 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8024,8 +8024,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
return true;
}
-#if (defined(CONFIG_MEMORY_ISOLATION) && defined(CONFIG_COMPACTION)) || defined(CONFIG_CMA)
-
+#ifdef CONFIG_CONTIG_ALLOC
static unsigned long pfn_max_align_down(unsigned long pfn)
{
return pfn & ~(max_t(unsigned long, MAX_ORDER_NR_PAGES,
--
2.20.1
^ permalink raw reply related
* [PATCH v5 2/4] sparc: Advertise gigantic page support
From: Alexandre Ghiti @ 2019-03-06 19:00 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
Cc: Alexandre Ghiti
In-Reply-To: <20190306190005.7036-1-alex@ghiti.fr>
sparc actually supports gigantic pages and selecting
ARCH_HAS_GIGANTIC_PAGE allows it to allocate and free
gigantic pages at runtime.
sparc allows configuration such as huge pages of 16GB,
pages of 8KB and MAX_ORDER = 13 (default):
HPAGE_SHIFT (34) - PAGE_SHIFT (13) = 21 >= MAX_ORDER (13)
Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
---
arch/sparc/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index d5dd652fb8cc..0b7f0e0fefa5 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -90,6 +90,7 @@ config SPARC64
select ARCH_CLOCKSOURCE_DATA
select ARCH_HAS_PTE_SPECIAL
select PCI_DOMAINS if PCI
+ select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
config ARCH_DEFCONFIG
string
--
2.20.1
^ permalink raw reply related
* [PATCH v5 1/4] sh: Advertise gigantic page support
From: Alexandre Ghiti @ 2019-03-06 19:00 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
Cc: Alexandre Ghiti
In-Reply-To: <20190306190005.7036-1-alex@ghiti.fr>
sh actually supports gigantic pages and selecting
ARCH_HAS_GIGANTIC_PAGE allows it to allocate and free
gigantic pages at runtime.
At least sdk7786_defconfig exposes such a configuration with
huge pages of 64MB, pages of 4KB and MAX_ORDER = 11:
HPAGE_SHIFT (26) - PAGE_SHIFT (12) = 14 >= MAX_ORDER (11)
Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
---
arch/sh/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index a9c36f95744a..299a17bed67c 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -53,6 +53,7 @@ config SUPERH
select HAVE_FUTEX_CMPXCHG if FUTEX
select HAVE_NMI
select NEED_SG_DMA_LENGTH
+ select ARCH_HAS_GIGANTIC_PAGE if (MEMORY_ISOLATION && COMPACTION) || CMA
help
The SuperH is a RISC processor targeted for use in embedded systems
--
2.20.1
^ permalink raw reply related
* [PATCH v5 0/4] Fix free/allocation of runtime gigantic pages
From: Alexandre Ghiti @ 2019-03-06 19:00 UTC (permalink / raw)
To: Vlastimil Babka, Catalin Marinas, Will Deacon,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Martin Schwidefsky, Heiko Carstens, Yoshinori Sato, Rich Felker,
David S . Miller, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H . Peter Anvin, x86, Dave Hansen, Andy Lutomirski,
Peter Zijlstra, Mike Kravetz, linux-arm-kernel, linux-kernel,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm
Cc: Alexandre Ghiti
This series fixes sh and sparc that did not advertise their gigantic page
support and then were not able to allocate and free those pages at runtime.
It renames MEMORY_ISOLATION && COMPACTION || CMA condition into the more
accurate CONTIG_ALLOC, since it allows the definition of alloc_contig_range
function.
Finally, it then fixes the wrong definition of ARCH_HAS_GIGANTIC_PAGE config
that, without MEMORY_ISOLATION && COMPACTION || CMA defined, did not allow
architectures to free boottime allocated gigantic pages although unrelated.
Changes in v5:
- Fix bug in previous version thanks to Mike Kravetz
- Fix block comments that did not respect coding style thanks to Dave Hensen
- Define ARCH_HAS_GIGANTIC_PAGE only for sparc64 as advised by David Miller
- Factorize "def_bool" and "depends on" thanks to Vlastimil Babka
Changes in v4 as suggested by Dave Hensen:
- Split previous version into small patches
- Do not compile alloc_gigantic** functions for architectures that do not
support those pages
- Define correct ARCH_HAS_GIGANTIC_PAGE in all arch that support them to avoid
useless runtime check
- Add comment in set_max_huge_pages to explain that freeing is possible even
without CONTIG_ALLOC defined
- Remove gigantic_page_supported function across all archs
Changes in v3 as suggested by Vlastimil Babka and Dave Hansen:
- config definition was wrong and is now in mm/Kconfig
- COMPACTION_CORE was renamed in CONTIG_ALLOC
Changes in v2 as suggested by Vlastimil Babka:
- Get rid of ARCH_HAS_GIGANTIC_PAGE
- Get rid of architecture specific gigantic_page_supported
- Factorize CMA or (MEMORY_ISOLATION && COMPACTION) into COMPACTION_CORE
*** BLURB HERE ***
Alexandre Ghiti (4):
sh: Advertise gigantic page support
sparc: Advertise gigantic page support
mm: Simplify MEMORY_ISOLATION && COMPACTION || CMA into CONTIG_ALLOC
hugetlb: allow to free gigantic pages regardless of the configuration
arch/arm64/Kconfig | 2 +-
arch/arm64/include/asm/hugetlb.h | 4 --
arch/powerpc/include/asm/book3s/64/hugetlb.h | 7 ---
arch/powerpc/platforms/Kconfig.cputype | 2 +-
arch/s390/Kconfig | 2 +-
arch/s390/include/asm/hugetlb.h | 3 --
arch/sh/Kconfig | 1 +
arch/sparc/Kconfig | 1 +
arch/x86/Kconfig | 2 +-
arch/x86/include/asm/hugetlb.h | 4 --
arch/x86/mm/hugetlbpage.c | 2 +-
include/linux/gfp.h | 4 +-
mm/Kconfig | 3 ++
mm/hugetlb.c | 54 ++++++++++++--------
mm/page_alloc.c | 7 ++-
15 files changed, 48 insertions(+), 50 deletions(-)
--
2.20.1
^ permalink raw reply
* Re: [PATCH] tools: testing: selftests: Remove duplicate headers
From: Souptick Joarder @ 2019-03-06 18:06 UTC (permalink / raw)
To: Michael Ellerman
Cc: linux-fsdevel, John Stultz, Andrew Morton, linux-gpio,
Peter Zijlstra, Boqun Feng, linuxppc-dev, linux-kernel,
David S. Miller, sboyd, Sabyasachi Gupta, Bamvor Zhang,
linux-kselftest, netdev, Mathieu Desnoyers, Paul Mackerras,
Thomas Gleixner, Paul McKenney, shuah, Alexey Dobriyan
In-Reply-To: <CAFqt6zYqa6aCAcs51AdePtBSL58hMa1BSA87ZMLbwUJA=rWNLA@mail.gmail.com>
On Mon, Mar 4, 2019 at 4:19 PM Souptick Joarder <jrdr.linux@gmail.com> wrote:
>
> On Tue, Feb 26, 2019 at 10:59 AM Souptick Joarder <jrdr.linux@gmail.com> wrote:
> >
> > On Tue, Feb 26, 2019 at 7:18 AM Michael Ellerman <mpe@ellerman.id.au> wrote:
> > >
> > > Souptick Joarder <jrdr.linux@gmail.com> writes:
> > > > Remove duplicate headers which are included twice.
> > > >
> > > > Signed-off-by: Sabyasachi Gupta <sabyasachi.linux@gmail.com>
> > > > Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> > > > ---
> > > ...
> > > > tools/testing/selftests/powerpc/pmu/ebb/fork_cleanup_test.c | 1 -
> > >
> > > I took this hunk via the powerpc tree.
> >
> > How about taking this entirely through a single tree ?
> > or Shall I send these changes in different patches ?
>
> If no comment, can we get this patch in queue for 5.1 ?
I will drop this patch as we have submitted these changes in
different patches. ( Except the one picked by Michael).
>
> >
> > >
> > > > diff --git a/tools/testing/selftests/powerpc/pmu/ebb/fork_cleanup_test.c b/tools/testing/selftests/powerpc/pmu/ebb/fork_cleanup_test.c
> > > > index 167135b..af1b802 100644
> > > > --- a/tools/testing/selftests/powerpc/pmu/ebb/fork_cleanup_test.c
> > > > +++ b/tools/testing/selftests/powerpc/pmu/ebb/fork_cleanup_test.c
> > > > @@ -11,7 +11,6 @@
> > > > #include <sys/wait.h>
> > > > #include <unistd.h>
> > > > #include <setjmp.h>
> > > > -#include <signal.h>
> > > >
> > > > #include "ebb.h"
> > >
> > >
> > > cheers
^ permalink raw reply
* [PATCH v4 04/19] powerpc: mm: Add p?d_large() definitions
From: Steven Price @ 2019-03-06 15:50 UTC (permalink / raw)
To: linux-mm
Cc: Mark Rutland, Peter Zijlstra, Dave Hansen, Will Deacon,
Paul Mackerras, H. Peter Anvin, Liang, Kan, x86, Steven Price,
Ingo Molnar, Catalin Marinas, Arnd Bergmann, kvm-ppc,
Jérôme Glisse, Borislav Petkov, Andy Lutomirski,
Thomas Gleixner, linux-arm-kernel, Ard Biesheuvel, linux-kernel,
James Morse, linuxppc-dev
In-Reply-To: <20190306155031.4291-1-steven.price@arm.com>
walk_page_range() is going to be allowed to walk page tables other than
those of user space. For this it needs to know when it has reached a
'leaf' entry in the page tables. This information is provided by the
p?d_large() functions/macros.
For powerpc pmd_large() was already implemented, so hoist it out of the
CONFIG_TRANSPARENT_HUGEPAGE condition and implement the other levels.
Also since we now have a pmd_large always implemented we can drop the
pmd_is_leaf() function.
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: linuxppc-dev@lists.ozlabs.org
CC: kvm-ppc@vger.kernel.org
Signed-off-by: Steven Price <steven.price@arm.com>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 30 ++++++++++++++------
arch/powerpc/kvm/book3s_64_mmu_radix.c | 12 ++------
2 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index c9bfe526ca9d..c4b29caf2a3b 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -907,6 +907,12 @@ static inline int pud_present(pud_t pud)
return (pud_raw(pud) & cpu_to_be64(_PAGE_PRESENT));
}
+#define pud_large pud_large
+static inline int pud_large(pud_t pud)
+{
+ return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
+}
+
extern struct page *pud_page(pud_t pud);
extern struct page *pmd_page(pmd_t pmd);
static inline pte_t pud_pte(pud_t pud)
@@ -954,6 +960,12 @@ static inline int pgd_present(pgd_t pgd)
return (pgd_raw(pgd) & cpu_to_be64(_PAGE_PRESENT));
}
+#define pgd_large pgd_large
+static inline int pgd_large(pgd_t pgd)
+{
+ return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PTE));
+}
+
static inline pte_t pgd_pte(pgd_t pgd)
{
return __pte_raw(pgd_raw(pgd));
@@ -1107,6 +1119,15 @@ static inline bool pmd_access_permitted(pmd_t pmd, bool write)
return pte_access_permitted(pmd_pte(pmd), write);
}
+#define pmd_large pmd_large
+/*
+ * returns true for pmd migration entries, THP, devmap, hugetlb
+ */
+static inline int pmd_large(pmd_t pmd)
+{
+ return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
+}
+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
extern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot);
extern pmd_t mk_pmd(struct page *page, pgprot_t pgprot);
@@ -1133,15 +1154,6 @@ pmd_hugepage_update(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp,
return hash__pmd_hugepage_update(mm, addr, pmdp, clr, set);
}
-/*
- * returns true for pmd migration entries, THP, devmap, hugetlb
- * But compile time dependent on THP config
- */
-static inline int pmd_large(pmd_t pmd)
-{
- return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
-}
-
static inline pmd_t pmd_mknotpresent(pmd_t pmd)
{
return __pmd(pmd_val(pmd) & ~_PAGE_PRESENT);
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index 1b821c6efdef..040db20ac2ab 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
@@ -363,12 +363,6 @@ static void kvmppc_pte_free(pte_t *ptep)
kmem_cache_free(kvm_pte_cache, ptep);
}
-/* Like pmd_huge() and pmd_large(), but works regardless of config options */
-static inline int pmd_is_leaf(pmd_t pmd)
-{
- return !!(pmd_val(pmd) & _PAGE_PTE);
-}
-
static pmd_t *kvmppc_pmd_alloc(void)
{
return kmem_cache_alloc(kvm_pmd_cache, GFP_KERNEL);
@@ -455,7 +449,7 @@ static void kvmppc_unmap_free_pmd(struct kvm *kvm, pmd_t *pmd, bool full,
for (im = 0; im < PTRS_PER_PMD; ++im, ++p) {
if (!pmd_present(*p))
continue;
- if (pmd_is_leaf(*p)) {
+ if (pmd_large(*p)) {
if (full) {
pmd_clear(p);
} else {
@@ -588,7 +582,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, pte_t pte,
else if (level <= 1)
new_pmd = kvmppc_pmd_alloc();
- if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_is_leaf(*pmd)))
+ if (level == 0 && !(pmd && pmd_present(*pmd) && !pmd_large(*pmd)))
new_ptep = kvmppc_pte_alloc();
/* Check if we might have been invalidated; let the guest retry if so */
@@ -657,7 +651,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, pte_t pte,
new_pmd = NULL;
}
pmd = pmd_offset(pud, gpa);
- if (pmd_is_leaf(*pmd)) {
+ if (pmd_large(*pmd)) {
unsigned long lgpa = gpa & PMD_MASK;
/* Check if we raced and someone else has set the same thing */
--
2.20.1
^ permalink raw reply related
* Re: [PATCH 2/2] mm/dax: Don't enable huge dax mapping by default
From: Kirill A. Shutemov @ 2019-03-06 13:06 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Jan Kara, linux-nvdimm, Linux Kernel Mailing List, Linux MM,
Oliver, Ross Zwisler, Dan Williams, Michal Suchánek,
linuxppc-dev, Andrew Morton, Kirill A . Shutemov
In-Reply-To: <df01bf6e-84a1-53fb-bf0c-0957af2f79e1@linux.ibm.com>
On Wed, Mar 06, 2019 at 06:15:25PM +0530, Aneesh Kumar K.V wrote:
> On 3/6/19 5:14 PM, Michal Suchánek wrote:
> > On Wed, 06 Mar 2019 14:47:33 +0530
> > "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> wrote:
> >
> > > Dan Williams <dan.j.williams@intel.com> writes:
> > >
> > > > On Thu, Feb 28, 2019 at 1:40 AM Oliver <oohall@gmail.com> wrote:
> > > > >
> > > > > On Thu, Feb 28, 2019 at 7:35 PM Aneesh Kumar K.V
> > > > > <aneesh.kumar@linux.ibm.com> wrote:
> > > Also even if the user decided to not use THP, by
> > > echo "never" > transparent_hugepage/enabled , we should continue to map
> > > dax fault using huge page on platforms that can support huge pages.
> >
> > Is this a good idea?
> >
> > This knob is there for a reason. In some situations having huge pages
> > can severely impact performance of the system (due to host-guest
> > interaction or whatever) and the ability to really turn off all THP
> > would be important in those cases, right?
> >
>
> My understanding was that is not true for dax pages? These are not regular
> memory that got allocated. They are allocated out of /dev/dax/ or
> /dev/pmem*. Do we have a reason not to use hugepages for mapping pages in
> that case?
Yes. Like when you don't want dax to compete for TLB with mission-critical
application (which uses hugetlb for instance).
--
Kirill A. Shutemov
^ permalink raw reply
* Re: [PATCH 2/2] mm/dax: Don't enable huge dax mapping by default
From: Aneesh Kumar K.V @ 2019-03-06 12:45 UTC (permalink / raw)
To: Michal Suchánek
Cc: Jan Kara, linux-nvdimm, Linux Kernel Mailing List, Linux MM,
Oliver, Ross Zwisler, Dan Williams, linuxppc-dev, Andrew Morton,
Kirill A . Shutemov
In-Reply-To: <20190306124453.126d36d8@naga.suse.cz>
On 3/6/19 5:14 PM, Michal Suchánek wrote:
> On Wed, 06 Mar 2019 14:47:33 +0530
> "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> wrote:
>
>> Dan Williams <dan.j.williams@intel.com> writes:
>>
>>> On Thu, Feb 28, 2019 at 1:40 AM Oliver <oohall@gmail.com> wrote:
>>>>
>>>> On Thu, Feb 28, 2019 at 7:35 PM Aneesh Kumar K.V
>>>> <aneesh.kumar@linux.ibm.com> wrote:
>
>> Also even if the user decided to not use THP, by
>> echo "never" > transparent_hugepage/enabled , we should continue to map
>> dax fault using huge page on platforms that can support huge pages.
>
> Is this a good idea?
>
> This knob is there for a reason. In some situations having huge pages
> can severely impact performance of the system (due to host-guest
> interaction or whatever) and the ability to really turn off all THP
> would be important in those cases, right?
>
My understanding was that is not true for dax pages? These are not
regular memory that got allocated. They are allocated out of /dev/dax/
or /dev/pmem*. Do we have a reason not to use hugepages for mapping
pages in that case?
-aneesh
^ permalink raw reply
* Re: [PATCH 2/2] mm/dax: Don't enable huge dax mapping by default
From: Michal Suchánek @ 2019-03-06 11:44 UTC (permalink / raw)
To: Aneesh Kumar K.V
Cc: Jan Kara, linux-nvdimm, Linux Kernel Mailing List, Linux MM,
Oliver, Ross Zwisler, Dan Williams, linuxppc-dev, Andrew Morton,
Kirill A . Shutemov
In-Reply-To: <87k1hc8iqa.fsf@linux.ibm.com>
On Wed, 06 Mar 2019 14:47:33 +0530
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> wrote:
> Dan Williams <dan.j.williams@intel.com> writes:
>
> > On Thu, Feb 28, 2019 at 1:40 AM Oliver <oohall@gmail.com> wrote:
> >>
> >> On Thu, Feb 28, 2019 at 7:35 PM Aneesh Kumar K.V
> >> <aneesh.kumar@linux.ibm.com> wrote:
> Also even if the user decided to not use THP, by
> echo "never" > transparent_hugepage/enabled , we should continue to map
> dax fault using huge page on platforms that can support huge pages.
Is this a good idea?
This knob is there for a reason. In some situations having huge pages
can severely impact performance of the system (due to host-guest
interaction or whatever) and the ability to really turn off all THP
would be important in those cases, right?
Thanks
Michal
^ permalink raw reply
* [PATCH v2 7/7] LS1021A: dtsi: add ftm quad decoder entries
From: Patrick Havelange @ 2019-03-06 11:12 UTC (permalink / raw)
To: William Breathitt Gray, Rob Herring, Mark Rutland, Shawn Guo,
Li Yang, Daniel Lezcano, Thomas Gleixner, Thierry Reding,
Esben Haabendal, linux-iio, linux-kernel, devicetree,
linux-arm-kernel, linux-pwm, linuxppc-dev, Jonathan Cameron
Cc: Patrick Havelange
In-Reply-To: <20190306111208.7454-1-patrick.havelange@essensium.com>
Add the 4 Quadrature counters for this board.
Signed-off-by: Patrick Havelange <patrick.havelange@essensium.com>
Reviewed-by: Esben Haabendal <esben@haabendal.dk>
---
Changes v2
- None
---
arch/arm/boot/dts/ls1021a.dtsi | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index ed0941292172..0168fb62590a 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -433,6 +433,34 @@
status = "disabled";
};
+ counter0: counter@29d0000 {
+ compatible = "fsl,ftm-quaddec";
+ reg = <0x0 0x29d0000 0x0 0x10000>;
+ big-endian;
+ status = "disabled";
+ };
+
+ counter1: counter@29e0000 {
+ compatible = "fsl,ftm-quaddec";
+ reg = <0x0 0x29e0000 0x0 0x10000>;
+ big-endian;
+ status = "disabled";
+ };
+
+ counter2: counter@29f0000 {
+ compatible = "fsl,ftm-quaddec";
+ reg = <0x0 0x29f0000 0x0 0x10000>;
+ big-endian;
+ status = "disabled";
+ };
+
+ counter3: counter@2a00000 {
+ compatible = "fsl,ftm-quaddec";
+ reg = <0x0 0x2a00000 0x0 0x10000>;
+ big-endian;
+ status = "disabled";
+ };
+
gpio0: gpio@2300000 {
compatible = "fsl,ls1021a-gpio", "fsl,qoriq-gpio";
reg = <0x0 0x2300000 0x0 0x10000>;
--
2.19.1
^ permalink raw reply related
* [PATCH v2 6/7] counter: ftm-quaddec: Documentation: Add specific counter sysfs documentation
From: Patrick Havelange @ 2019-03-06 11:12 UTC (permalink / raw)
To: William Breathitt Gray, Rob Herring, Mark Rutland, Shawn Guo,
Li Yang, Daniel Lezcano, Thomas Gleixner, Thierry Reding,
Esben Haabendal, linux-iio, linux-kernel, devicetree,
linux-arm-kernel, linux-pwm, linuxppc-dev, Jonathan Cameron
Cc: Patrick Havelange
In-Reply-To: <20190306111208.7454-1-patrick.havelange@essensium.com>
This adds documentation for the specific prescaler entry.
Signed-off-by: Patrick Havelange <patrick.havelange@essensium.com>
---
Changes v2
- Add doc for prescaler entry
---
.../ABI/testing/sysfs-bus-counter-ftm-quaddec | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec
diff --git a/Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec b/Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec
new file mode 100644
index 000000000000..2da629d6d485
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec
@@ -0,0 +1,16 @@
+What: /sys/bus/counter/devices/counterX/countY/prescaler_available
+KernelVersion: 5.1
+Contact: linux-iio@vger.kernel.org
+Description:
+ Discrete set of available values for the respective Count Y
+ configuration are listed in this file. Values are delimited by
+ newline characters.
+
+What: /sys/bus/counter/devices/counterX/countY/prescaler
+KernelVersion: 5.1
+Contact: linux-iio@vger.kernel.org
+Description:
+ Configure the prescaler value associated with Count Y.
+ On the FlexTimer, the counter clock source passes through a
+ prescaler that is a 7-bit counter. This acts like a clock
+ divider.
--
2.19.1
^ permalink raw reply related
* [PATCH v2 5/7] counter: add FlexTimer Module Quadrature decoder counter driver
From: Patrick Havelange @ 2019-03-06 11:12 UTC (permalink / raw)
To: William Breathitt Gray, Rob Herring, Mark Rutland, Shawn Guo,
Li Yang, Daniel Lezcano, Thomas Gleixner, Thierry Reding,
Esben Haabendal, linux-iio, linux-kernel, devicetree,
linux-arm-kernel, linux-pwm, linuxppc-dev, Jonathan Cameron
Cc: Patrick Havelange
In-Reply-To: <20190306111208.7454-1-patrick.havelange@essensium.com>
This driver exposes the counter for the quadrature decoder of the
FlexTimer Module, present in the LS1021A soc.
Signed-off-by: Patrick Havelange <patrick.havelange@essensium.com>
---
Changes v2
- Rebased on new counter subsystem
- Cleaned up included headers
- Use devm_ioremap()
- Correct order of devm_ and unmanaged resources
---
drivers/counter/Kconfig | 9 +
drivers/counter/Makefile | 1 +
drivers/counter/ftm-quaddec.c | 356 ++++++++++++++++++++++++++++++++++
3 files changed, 366 insertions(+)
create mode 100644 drivers/counter/ftm-quaddec.c
diff --git a/drivers/counter/Kconfig b/drivers/counter/Kconfig
index 87c491a19c63..233ac305d878 100644
--- a/drivers/counter/Kconfig
+++ b/drivers/counter/Kconfig
@@ -48,4 +48,13 @@ config STM32_LPTIMER_CNT
To compile this driver as a module, choose M here: the
module will be called stm32-lptimer-cnt.
+config FTM_QUADDEC
+ tristate "Flex Timer Module Quadrature decoder driver"
+ help
+ Select this option to enable the Flex Timer Quadrature decoder
+ driver.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ftm-quaddec.
+
endif # COUNTER
diff --git a/drivers/counter/Makefile b/drivers/counter/Makefile
index 5589976d37f8..0c9e622a6bea 100644
--- a/drivers/counter/Makefile
+++ b/drivers/counter/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_COUNTER) += counter.o
obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o
obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o
obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o
+obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o
diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
new file mode 100644
index 000000000000..1bc9e075a386
--- /dev/null
+++ b/drivers/counter/ftm-quaddec.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Flex Timer Module Quadrature decoder
+ *
+ * This module implements a driver for decoding the FTM quadrature
+ * of ex. a LS1021A
+ */
+
+#include <linux/fsl/ftm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/io.h>
+#include <linux/mutex.h>
+#include <linux/counter.h>
+
+struct ftm_quaddec {
+ struct counter_device counter;
+ struct platform_device *pdev;
+ void __iomem *ftm_base;
+ bool big_endian;
+ struct mutex ftm_quaddec_mutex;
+};
+
+static void ftm_read(struct ftm_quaddec *ftm, uint32_t offset, uint32_t *data)
+{
+ if (ftm->big_endian)
+ *data = ioread32be(ftm->ftm_base + offset);
+ else
+ *data = ioread32(ftm->ftm_base + offset);
+}
+
+static void ftm_write(struct ftm_quaddec *ftm, uint32_t offset, uint32_t data)
+{
+ if (ftm->big_endian)
+ iowrite32be(data, ftm->ftm_base + offset);
+ else
+ iowrite32(data, ftm->ftm_base + offset);
+}
+
+/*
+ * take mutex
+ * call ftm_clear_write_protection
+ * update settings
+ * call ftm_set_write_protection
+ * release mutex
+ */
+static void ftm_clear_write_protection(struct ftm_quaddec *ftm)
+{
+ uint32_t flag;
+
+ /* First see if it is enabled */
+ ftm_read(ftm, FTM_FMS, &flag);
+
+ if (flag & FTM_FMS_WPEN) {
+ ftm_read(ftm, FTM_MODE, &flag);
+ ftm_write(ftm, FTM_MODE, flag | FTM_MODE_WPDIS);
+ }
+}
+
+static void ftm_set_write_protection(struct ftm_quaddec *ftm)
+{
+ ftm_write(ftm, FTM_FMS, FTM_FMS_WPEN);
+}
+
+static void ftm_reset_counter(struct ftm_quaddec *ftm)
+{
+ /* Reset hardware counter to CNTIN */
+ ftm_write(ftm, FTM_CNT, 0x0);
+}
+
+static void ftm_quaddec_init(struct ftm_quaddec *ftm)
+{
+ ftm_clear_write_protection(ftm);
+
+ /*
+ * Do not write in the region from the CNTIN register through the
+ * PWMLOAD register when FTMEN = 0.
+ */
+ ftm_write(ftm, FTM_MODE, FTM_MODE_FTMEN);
+ ftm_write(ftm, FTM_CNTIN, 0x0000);
+ ftm_write(ftm, FTM_MOD, 0xffff);
+ ftm_write(ftm, FTM_CNT, 0x0);
+ ftm_write(ftm, FTM_SC, FTM_SC_PS_1);
+
+ /* Select quad mode */
+ ftm_write(ftm, FTM_QDCTRL, FTM_QDCTRL_QUADEN);
+
+ /* Unused features and reset to default section */
+ ftm_write(ftm, FTM_POL, 0x0);
+ ftm_write(ftm, FTM_FLTCTRL, 0x0);
+ ftm_write(ftm, FTM_SYNCONF, 0x0);
+ ftm_write(ftm, FTM_SYNC, 0xffff);
+
+ /* Lock the FTM */
+ ftm_set_write_protection(ftm);
+}
+
+static void ftm_quaddec_disable(struct ftm_quaddec *ftm)
+{
+ ftm_write(ftm, FTM_MODE, 0);
+}
+
+static int ftm_quaddec_get_prescaler(struct counter_device *counter,
+ struct counter_count *count,
+ size_t *cnt_mode)
+{
+ struct ftm_quaddec *ftm = counter->priv;
+ uint32_t scflags;
+
+ ftm_read(ftm, FTM_SC, &scflags);
+
+ *cnt_mode = scflags & FTM_SC_PS_MASK;
+
+ return 0;
+}
+
+static int ftm_quaddec_set_prescaler(struct counter_device *counter,
+ struct counter_count *count,
+ size_t cnt_mode)
+{
+ struct ftm_quaddec *ftm = counter->priv;
+
+ uint32_t scflags;
+
+ mutex_lock(&ftm->ftm_quaddec_mutex);
+
+ ftm_read(ftm, FTM_SC, &scflags);
+
+ scflags &= ~FTM_SC_PS_MASK;
+ cnt_mode &= FTM_SC_PS_MASK; /*just to be 100% sure*/
+
+ scflags |= cnt_mode;
+
+ /* Write */
+ ftm_clear_write_protection(ftm);
+ ftm_write(ftm, FTM_SC, scflags);
+ ftm_set_write_protection(ftm);
+
+ /* Also resets the counter as it is undefined anyway now */
+ ftm_reset_counter(ftm);
+
+ mutex_unlock(&ftm->ftm_quaddec_mutex);
+ return 0;
+}
+
+static const char * const ftm_quaddec_prescaler[] = {
+ "1", "2", "4", "8", "16", "32", "64", "128"
+};
+
+static struct counter_count_enum_ext ftm_quaddec_prescaler_enum = {
+ .items = ftm_quaddec_prescaler,
+ .num_items = ARRAY_SIZE(ftm_quaddec_prescaler),
+ .get = ftm_quaddec_get_prescaler,
+ .set = ftm_quaddec_set_prescaler
+};
+
+enum ftm_quaddec_synapse_action {
+ FTM_QUADDEC_SYNAPSE_ACTION_BOTH_EDGES,
+};
+
+static enum counter_synapse_action ftm_quaddec_synapse_actions[] = {
+ [FTM_QUADDEC_SYNAPSE_ACTION_BOTH_EDGES] =
+ COUNTER_SYNAPSE_ACTION_BOTH_EDGES
+};
+
+enum ftm_quaddec_count_function {
+ FTM_QUADDEC_COUNT_ENCODER_MODE_1,
+};
+
+static const enum counter_count_function ftm_quaddec_count_functions[] = {
+ [FTM_QUADDEC_COUNT_ENCODER_MODE_1] =
+ COUNTER_COUNT_FUNCTION_QUADRATURE_X4
+};
+
+static int ftm_quaddec_count_read(struct counter_device *counter,
+ struct counter_count *count,
+ struct counter_count_read_value *val)
+{
+ struct ftm_quaddec *const ftm = counter->priv;
+ uint32_t cntval;
+
+ ftm_read(ftm, FTM_CNT, &cntval);
+
+ counter_count_read_value_set(val, COUNTER_COUNT_POSITION, &cntval);
+
+ return 0;
+}
+
+static int ftm_quaddec_count_write(struct counter_device *counter,
+ struct counter_count *count,
+ struct counter_count_write_value *val)
+{
+ struct ftm_quaddec *const ftm = counter->priv;
+ u32 cnt;
+ int err;
+
+ err = counter_count_write_value_get(&cnt, COUNTER_COUNT_POSITION, val);
+ if (err)
+ return err;
+
+ if (cnt != 0) {
+ dev_warn(&ftm->pdev->dev, "Can only accept '0' as new counter value\n");
+ return -EINVAL;
+ }
+
+ ftm_reset_counter(ftm);
+
+ return 0;
+}
+
+static int ftm_quaddec_count_function_get(struct counter_device *counter,
+ struct counter_count *count,
+ size_t *function)
+{
+ *function = FTM_QUADDEC_COUNT_ENCODER_MODE_1;
+
+ return 0;
+}
+
+static int ftm_quaddec_action_get(struct counter_device *counter,
+ struct counter_count *count,
+ struct counter_synapse *synapse,
+ size_t *action)
+{
+ *action = FTM_QUADDEC_SYNAPSE_ACTION_BOTH_EDGES;
+
+ return 0;
+}
+
+static const struct counter_ops ftm_quaddec_cnt_ops = {
+ .count_read = ftm_quaddec_count_read,
+ .count_write = ftm_quaddec_count_write,
+ .function_get = ftm_quaddec_count_function_get,
+ .action_get = ftm_quaddec_action_get,
+};
+
+static struct counter_signal ftm_quaddec_signals[] = {
+ {
+ .id = 0,
+ .name = "Channel 1 Quadrature A"
+ },
+ {
+ .id = 1,
+ .name = "Channel 1 Quadrature B"
+ }
+};
+
+static struct counter_synapse ftm_quaddec_count_synapses[] = {
+ {
+ .actions_list = ftm_quaddec_synapse_actions,
+ .num_actions = ARRAY_SIZE(ftm_quaddec_synapse_actions),
+ .signal = &ftm_quaddec_signals[0]
+ },
+ {
+ .actions_list = ftm_quaddec_synapse_actions,
+ .num_actions = ARRAY_SIZE(ftm_quaddec_synapse_actions),
+ .signal = &ftm_quaddec_signals[1]
+ }
+};
+
+static const struct counter_count_ext ftm_quaddec_count_ext[] = {
+ COUNTER_COUNT_ENUM("prescaler", &ftm_quaddec_prescaler_enum),
+ COUNTER_COUNT_ENUM_AVAILABLE("prescaler", &ftm_quaddec_prescaler_enum),
+};
+
+static struct counter_count ftm_quaddec_counts = {
+ .id = 0,
+ .name = "Channel 1 Count",
+ .functions_list = ftm_quaddec_count_functions,
+ .num_functions = ARRAY_SIZE(ftm_quaddec_count_functions),
+ .synapses = ftm_quaddec_count_synapses,
+ .num_synapses = ARRAY_SIZE(ftm_quaddec_count_synapses),
+ .ext = ftm_quaddec_count_ext,
+ .num_ext = ARRAY_SIZE(ftm_quaddec_count_ext)
+};
+
+static int ftm_quaddec_probe(struct platform_device *pdev)
+{
+ struct ftm_quaddec *ftm;
+
+ struct device_node *node = pdev->dev.of_node;
+ struct resource *io;
+ int ret;
+
+ ftm = devm_kzalloc(&pdev->dev, sizeof(*ftm), GFP_KERNEL);
+ if (!ftm)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, ftm);
+
+ io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!io) {
+ dev_err(&pdev->dev, "Failed to get memory region\n");
+ return -ENODEV;
+ }
+
+ ftm->pdev = pdev;
+ ftm->big_endian = of_property_read_bool(node, "big-endian");
+ ftm->ftm_base = devm_ioremap(&pdev->dev, io->start, resource_size(io));
+
+ if (!ftm->ftm_base) {
+ dev_err(&pdev->dev, "Failed to map memory region\n");
+ return -EINVAL;
+ }
+ ftm->counter.name = dev_name(&pdev->dev);
+ ftm->counter.parent = &pdev->dev;
+ ftm->counter.ops = &ftm_quaddec_cnt_ops;
+ ftm->counter.counts = &ftm_quaddec_counts;
+ ftm->counter.num_counts = 1;
+ ftm->counter.signals = ftm_quaddec_signals;
+ ftm->counter.num_signals = ARRAY_SIZE(ftm_quaddec_signals);
+ ftm->counter.priv = ftm;
+
+ mutex_init(&ftm->ftm_quaddec_mutex);
+
+ ftm_quaddec_init(ftm);
+
+ ret = counter_register(&ftm->counter);
+ if (ret)
+ ftm_quaddec_disable(ftm);
+
+ return ret;
+}
+
+static int ftm_quaddec_remove(struct platform_device *pdev)
+{
+ struct ftm_quaddec *ftm = platform_get_drvdata(pdev);
+
+ counter_unregister(&ftm->counter);
+
+ ftm_quaddec_disable(ftm);
+
+ return 0;
+}
+
+static const struct of_device_id ftm_quaddec_match[] = {
+ { .compatible = "fsl,ftm-quaddec" },
+ {},
+};
+
+static struct platform_driver ftm_quaddec_driver = {
+ .driver = {
+ .name = "ftm-quaddec",
+ .owner = THIS_MODULE,
+ .of_match_table = ftm_quaddec_match,
+ },
+ .probe = ftm_quaddec_probe,
+ .remove = ftm_quaddec_remove,
+};
+
+module_platform_driver(ftm_quaddec_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kjeld Flarup <kfa@deif.com");
+MODULE_AUTHOR("Patrick Havelange <patrick.havelange@essensium.com");
--
2.19.1
^ permalink raw reply related
* [PATCH v2 4/7] dt-bindings: counter: ftm-quaddec
From: Patrick Havelange @ 2019-03-06 11:12 UTC (permalink / raw)
To: William Breathitt Gray, Rob Herring, Mark Rutland, Shawn Guo,
Li Yang, Daniel Lezcano, Thomas Gleixner, Thierry Reding,
Esben Haabendal, linux-iio, linux-kernel, devicetree,
linux-arm-kernel, linux-pwm, linuxppc-dev, Jonathan Cameron
Cc: Patrick Havelange
In-Reply-To: <20190306111208.7454-1-patrick.havelange@essensium.com>
FlexTimer quadrature decoder driver.
Signed-off-by: Patrick Havelange <patrick.havelange@essensium.com>
Reviewed-by: Esben Haabendal <esben@haabendal.dk>
---
Changes v2
- None
---
.../bindings/counter/ftm-quaddec.txt | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 Documentation/devicetree/bindings/counter/ftm-quaddec.txt
diff --git a/Documentation/devicetree/bindings/counter/ftm-quaddec.txt b/Documentation/devicetree/bindings/counter/ftm-quaddec.txt
new file mode 100644
index 000000000000..4d18cd722074
--- /dev/null
+++ b/Documentation/devicetree/bindings/counter/ftm-quaddec.txt
@@ -0,0 +1,18 @@
+FlexTimer Quadrature decoder counter
+
+This driver exposes a simple counter for the quadrature decoder mode.
+
+Required properties:
+- compatible: Must be "fsl,ftm-quaddec".
+- reg: Must be set to the memory region of the flextimer.
+
+Optional property:
+- big-endian: Access the device registers in big-endian mode.
+
+Example:
+ counter0: counter@29d0000 {
+ compatible = "fsl,ftm-quaddec";
+ reg = <0x0 0x29d0000 0x0 0x10000>;
+ big-endian;
+ status = "disabled";
+ };
--
2.19.1
^ permalink raw reply related
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