From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760165AbcAKQ2B (ORCPT ); Mon, 11 Jan 2016 11:28:01 -0500 Received: from foss.arm.com ([217.140.101.70]:56609 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757960AbcAKQ2A (ORCPT ); Mon, 11 Jan 2016 11:28:00 -0500 Date: Mon, 11 Jan 2016 16:27:38 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: "linux-arm-kernel@lists.infradead.org" , kernel-hardening@lists.openwall.com, Will Deacon , Catalin Marinas , Leif Lindholm , Kees Cook , "linux-kernel@vger.kernel.org" , Stuart Yoder , Sharma Bhupesh , Arnd Bergmann , Marc Zyngier , Christoffer Dall Subject: Re: [PATCH v3 04/21] arm64: decouple early fixmap init from linear mapping Message-ID: <20160111162737.GQ6499@leverpostej> References: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> <1452518355-4606-5-git-send-email-ard.biesheuvel@linaro.org> <20160111160906.GO6499@leverpostej> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 11, 2016 at 05:15:13PM +0100, Ard Biesheuvel wrote: > On 11 January 2016 at 17:09, Mark Rutland wrote: > > On Mon, Jan 11, 2016 at 02:18:57PM +0100, Ard Biesheuvel wrote: > >> Since the early fixmap page tables are populated using pages that are > >> part of the static footprint of the kernel, they are covered by the > >> initial kernel mapping, and we can refer to them without using __va/__pa > >> translations, which are tied to the linear mapping. > >> > >> Since the fixmap page tables are disjoint from the kernel mapping up > >> to the top level pgd entry, we can refer to bm_pte[] directly, and there > >> is no need to walk the page tables and perform __pa()/__va() translations > >> at each step. > >> > >> Signed-off-by: Ard Biesheuvel > >> --- > >> arch/arm64/mm/mmu.c | 32 ++++++-------------- > >> 1 file changed, 9 insertions(+), 23 deletions(-) > >> > >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > >> index 7711554a94f4..75b5f0dc3bdc 100644 > >> --- a/arch/arm64/mm/mmu.c > >> +++ b/arch/arm64/mm/mmu.c > >> @@ -570,38 +570,24 @@ void vmemmap_free(unsigned long start, unsigned long end) > >> #endif /* CONFIG_SPARSEMEM_VMEMMAP */ > >> > >> static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; > >> -#if CONFIG_PGTABLE_LEVELS > 2 > >> static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss; > >> -#endif > >> -#if CONFIG_PGTABLE_LEVELS > 3 > >> static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss; > >> -#endif > >> > >> static inline pud_t * fixmap_pud(unsigned long addr) > >> { > >> - pgd_t *pgd = pgd_offset_k(addr); > >> - > >> - BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd)); > >> - > >> - return pud_offset(pgd, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 3) ? &bm_pud[pud_index(addr)] > >> + : (pud_t *)pgd_offset_k(addr); > > > > If we move patch 6 earlier, we could use pud_offset_kimg here, and avoid > > the cast, at the cost of passing the pgd into fixmap_pud. > > > > Similarly for fixmap_pmd. > > > > Is that necessarily an improvement? I know it hides the cast, but I > think having an explicit pgd_t* to pud_t* cast that so obviously > applies to CONFIG_PGTABLE_LEVELS < 4 only is fine as well. True; it's not a big thing either way. > >> } > >> > >> -static inline pmd_t * fixmap_pmd(unsigned long addr) > >> +static inline pte_t * fixmap_pmd(unsigned long addr) > >> { > >> - pud_t *pud = fixmap_pud(addr); > >> - > >> - BUG_ON(pud_none(*pud) || pud_bad(*pud)); > >> - > >> - return pmd_offset(pud, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 2) ? &bm_pmd[pmd_index(addr)] > >> + : (pmd_t *)pgd_offset_k(addr); > >> } > > > > I assume the return type change was unintentional? > > > > Yes. Thanks for spotting that. With that fixed: Reviewed-by: Mark Rutland > > Side note: is there any reason we can't/shouldn't make > > STRICT_MM_TYPECHECKS a common config option? Or simply have it on by > > default for arm64? > > > > I wouldn't mind at all. I'll dig into that a bit futher then... Thanks, Mark. From mboxrd@z Thu Jan 1 00:00:00 1970 From: mark.rutland@arm.com (Mark Rutland) Date: Mon, 11 Jan 2016 16:27:38 +0000 Subject: [PATCH v3 04/21] arm64: decouple early fixmap init from linear mapping In-Reply-To: References: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> <1452518355-4606-5-git-send-email-ard.biesheuvel@linaro.org> <20160111160906.GO6499@leverpostej> Message-ID: <20160111162737.GQ6499@leverpostej> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Mon, Jan 11, 2016 at 05:15:13PM +0100, Ard Biesheuvel wrote: > On 11 January 2016 at 17:09, Mark Rutland wrote: > > On Mon, Jan 11, 2016 at 02:18:57PM +0100, Ard Biesheuvel wrote: > >> Since the early fixmap page tables are populated using pages that are > >> part of the static footprint of the kernel, they are covered by the > >> initial kernel mapping, and we can refer to them without using __va/__pa > >> translations, which are tied to the linear mapping. > >> > >> Since the fixmap page tables are disjoint from the kernel mapping up > >> to the top level pgd entry, we can refer to bm_pte[] directly, and there > >> is no need to walk the page tables and perform __pa()/__va() translations > >> at each step. > >> > >> Signed-off-by: Ard Biesheuvel > >> --- > >> arch/arm64/mm/mmu.c | 32 ++++++-------------- > >> 1 file changed, 9 insertions(+), 23 deletions(-) > >> > >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > >> index 7711554a94f4..75b5f0dc3bdc 100644 > >> --- a/arch/arm64/mm/mmu.c > >> +++ b/arch/arm64/mm/mmu.c > >> @@ -570,38 +570,24 @@ void vmemmap_free(unsigned long start, unsigned long end) > >> #endif /* CONFIG_SPARSEMEM_VMEMMAP */ > >> > >> static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; > >> -#if CONFIG_PGTABLE_LEVELS > 2 > >> static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss; > >> -#endif > >> -#if CONFIG_PGTABLE_LEVELS > 3 > >> static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss; > >> -#endif > >> > >> static inline pud_t * fixmap_pud(unsigned long addr) > >> { > >> - pgd_t *pgd = pgd_offset_k(addr); > >> - > >> - BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd)); > >> - > >> - return pud_offset(pgd, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 3) ? &bm_pud[pud_index(addr)] > >> + : (pud_t *)pgd_offset_k(addr); > > > > If we move patch 6 earlier, we could use pud_offset_kimg here, and avoid > > the cast, at the cost of passing the pgd into fixmap_pud. > > > > Similarly for fixmap_pmd. > > > > Is that necessarily an improvement? I know it hides the cast, but I > think having an explicit pgd_t* to pud_t* cast that so obviously > applies to CONFIG_PGTABLE_LEVELS < 4 only is fine as well. True; it's not a big thing either way. > >> } > >> > >> -static inline pmd_t * fixmap_pmd(unsigned long addr) > >> +static inline pte_t * fixmap_pmd(unsigned long addr) > >> { > >> - pud_t *pud = fixmap_pud(addr); > >> - > >> - BUG_ON(pud_none(*pud) || pud_bad(*pud)); > >> - > >> - return pmd_offset(pud, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 2) ? &bm_pmd[pmd_index(addr)] > >> + : (pmd_t *)pgd_offset_k(addr); > >> } > > > > I assume the return type change was unintentional? > > > > Yes. Thanks for spotting that. With that fixed: Reviewed-by: Mark Rutland > > Side note: is there any reason we can't/shouldn't make > > STRICT_MM_TYPECHECKS a common config option? Or simply have it on by > > default for arm64? > > > > I wouldn't mind at all. I'll dig into that a bit futher then... Thanks, Mark. From mboxrd@z Thu Jan 1 00:00:00 1970 Reply-To: kernel-hardening@lists.openwall.com Date: Mon, 11 Jan 2016 16:27:38 +0000 From: Mark Rutland Message-ID: <20160111162737.GQ6499@leverpostej> References: <1452518355-4606-1-git-send-email-ard.biesheuvel@linaro.org> <1452518355-4606-5-git-send-email-ard.biesheuvel@linaro.org> <20160111160906.GO6499@leverpostej> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [kernel-hardening] Re: [PATCH v3 04/21] arm64: decouple early fixmap init from linear mapping To: Ard Biesheuvel Cc: "linux-arm-kernel@lists.infradead.org" , kernel-hardening@lists.openwall.com, Will Deacon , Catalin Marinas , Leif Lindholm , Kees Cook , "linux-kernel@vger.kernel.org" , Stuart Yoder , Sharma Bhupesh , Arnd Bergmann , Marc Zyngier , Christoffer Dall List-ID: On Mon, Jan 11, 2016 at 05:15:13PM +0100, Ard Biesheuvel wrote: > On 11 January 2016 at 17:09, Mark Rutland wrote: > > On Mon, Jan 11, 2016 at 02:18:57PM +0100, Ard Biesheuvel wrote: > >> Since the early fixmap page tables are populated using pages that are > >> part of the static footprint of the kernel, they are covered by the > >> initial kernel mapping, and we can refer to them without using __va/__pa > >> translations, which are tied to the linear mapping. > >> > >> Since the fixmap page tables are disjoint from the kernel mapping up > >> to the top level pgd entry, we can refer to bm_pte[] directly, and there > >> is no need to walk the page tables and perform __pa()/__va() translations > >> at each step. > >> > >> Signed-off-by: Ard Biesheuvel > >> --- > >> arch/arm64/mm/mmu.c | 32 ++++++-------------- > >> 1 file changed, 9 insertions(+), 23 deletions(-) > >> > >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > >> index 7711554a94f4..75b5f0dc3bdc 100644 > >> --- a/arch/arm64/mm/mmu.c > >> +++ b/arch/arm64/mm/mmu.c > >> @@ -570,38 +570,24 @@ void vmemmap_free(unsigned long start, unsigned long end) > >> #endif /* CONFIG_SPARSEMEM_VMEMMAP */ > >> > >> static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; > >> -#if CONFIG_PGTABLE_LEVELS > 2 > >> static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss; > >> -#endif > >> -#if CONFIG_PGTABLE_LEVELS > 3 > >> static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss; > >> -#endif > >> > >> static inline pud_t * fixmap_pud(unsigned long addr) > >> { > >> - pgd_t *pgd = pgd_offset_k(addr); > >> - > >> - BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd)); > >> - > >> - return pud_offset(pgd, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 3) ? &bm_pud[pud_index(addr)] > >> + : (pud_t *)pgd_offset_k(addr); > > > > If we move patch 6 earlier, we could use pud_offset_kimg here, and avoid > > the cast, at the cost of passing the pgd into fixmap_pud. > > > > Similarly for fixmap_pmd. > > > > Is that necessarily an improvement? I know it hides the cast, but I > think having an explicit pgd_t* to pud_t* cast that so obviously > applies to CONFIG_PGTABLE_LEVELS < 4 only is fine as well. True; it's not a big thing either way. > >> } > >> > >> -static inline pmd_t * fixmap_pmd(unsigned long addr) > >> +static inline pte_t * fixmap_pmd(unsigned long addr) > >> { > >> - pud_t *pud = fixmap_pud(addr); > >> - > >> - BUG_ON(pud_none(*pud) || pud_bad(*pud)); > >> - > >> - return pmd_offset(pud, addr); > >> + return (CONFIG_PGTABLE_LEVELS > 2) ? &bm_pmd[pmd_index(addr)] > >> + : (pmd_t *)pgd_offset_k(addr); > >> } > > > > I assume the return type change was unintentional? > > > > Yes. Thanks for spotting that. With that fixed: Reviewed-by: Mark Rutland > > Side note: is there any reason we can't/shouldn't make > > STRICT_MM_TYPECHECKS a common config option? Or simply have it on by > > default for arm64? > > > > I wouldn't mind at all. I'll dig into that a bit futher then... Thanks, Mark.