From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752664AbdJKTjr (ORCPT ); Wed, 11 Oct 2017 15:39:47 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:37973 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751906AbdJKTjp (ORCPT ); Wed, 11 Oct 2017 15:39:45 -0400 X-Google-Smtp-Source: AOwi7QDZKWfaMMo2AjqbBv54jS+RiF5UkcUYEVN4FkGI5w4jCp50hkwgcIPtmtGqnWzfjZGEvoQCAw== Subject: Re: [PATCH 01/11] Initialize the mapping of KASan shadow memory To: Abbott Liu , linux@armlinux.org.uk, aryabinin@virtuozzo.com, afzal.mohd.ma@gmail.com, labbott@redhat.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, cdall@linaro.org, marc.zyngier@arm.com, catalin.marinas@arm.com, akpm@linux-foundation.org, mawilcox@microsoft.com, tglx@linutronix.de, thgarnie@google.com, keescook@chromium.org, arnd@arndb.de, vladimir.murzin@arm.com, tixy@linaro.org, ard.biesheuvel@linaro.org, robin.murphy@arm.com, mingo@kernel.org, grygorii.strashko@linaro.org Cc: glider@google.com, dvyukov@google.com, opendmb@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, jiazhenghua@huawei.com, dylix.dailei@huawei.com, zengweilin@huawei.com, heshaoliang@huawei.com References: <20171011082227.20546-1-liuwenliang@huawei.com> <20171011082227.20546-2-liuwenliang@huawei.com> From: Florian Fainelli Message-ID: Date: Wed, 11 Oct 2017 12:39:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20171011082227.20546-2-liuwenliang@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/11/2017 01:22 AM, Abbott Liu wrote: > From: Andrey Ryabinin > > This patch initializes KASan shadow region's page table and memory. > There are two stage for KASan initializing: > 1. At early boot stage the whole shadow region is mapped to just > one physical page (kasan_zero_page). It's finished by the function > kasan_early_init which is called by __mmap_switched(arch/arm/kernel/ > head-common.S) > > 2. After the calling of paging_init, we use kasan_zero_page as zero > shadow for some memory that KASan don't need to track, and we alloc > new shadow space for the other memory that KASan need to track. These > issues are finished by the function kasan_init which is call by setup_arch. > > Cc: Andrey Ryabinin > Signed-off-by: Abbott Liu > --- [snip] \ > @@ -140,6 +149,30 @@ extern void cpu_resume(void); > pg &= ~0x3fff; \ > (pgd_t *)phys_to_virt(pg); \ > }) > + > +#define cpu_set_ttbr(nr, val) \ > + do { \ > + u64 ttbr = val; \ > + __asm__("mcr p15, 0, %0, c2, c0, 0" \ > + : : "r" (ttbr)); \ > + } while (0) nr seems to be unused here? > + > +#define cpu_get_ttbr(nr) \ > + ({ \ > + unsigned long ttbr; \ > + __asm__("mrc p15, 0, %0, c2, c0, 0" \ > + : "=r" (ttbr)); \ > + ttbr; \ > + }) > + > +#define cpu_set_ttbr0(val) \ > + do { \ > + u64 ttbr = val; \ > + __asm__("mcr p15, 0, %0, c2, c0, 0" \ > + : : "r" (ttbr)); \ > + } while (0) > + Why is not cpu_set_ttbr0() not using cpu_set_ttbr()? > + > #endif > > #else /*!CONFIG_MMU */ > diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h > index 1d468b5..52c4858 100644 > --- a/arch/arm/include/asm/thread_info.h > +++ b/arch/arm/include/asm/thread_info.h > @@ -16,7 +16,11 @@ > #include > #include > > +#ifdef CONFIG_KASAN > +#define THREAD_SIZE_ORDER 2 > +#else > #define THREAD_SIZE_ORDER 1 > +#endif > #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) > #define THREAD_START_SP (THREAD_SIZE - 8) > > diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S > index 8733012..c17f4a2 100644 > --- a/arch/arm/kernel/head-common.S > +++ b/arch/arm/kernel/head-common.S > @@ -101,7 +101,11 @@ __mmap_switched: > str r2, [r6] @ Save atags pointer > cmp r7, #0 > strne r0, [r7] @ Save control register values > +#ifdef CONFIG_KASAN > + b kasan_early_init > +#else > b start_kernel > +#endif Please don't make this "exclusive" just conditionally call kasan_early_init(), remove the call to start_kernel from kasan_early_init and keep the call to start_kernel here. > ENDPROC(__mmap_switched) > > .align 2 [snip] > +void __init kasan_early_init(void) > +{ > + struct proc_info_list *list; > + > + /* > + * locate processor in the list of supported processor > + * types. The linker builds this table for us from the > + * entries in arch/arm/mm/proc-*.S > + */ > + list = lookup_processor_type(read_cpuid_id()); > + if (list) { > +#ifdef MULTI_CPU > + processor = *list->proc; > +#endif > + } I could not quite spot in your patch series when do you need this information? -- Florian