Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp2835267pjo; Mon, 16 Mar 2020 05:36:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv99LCvBZZWR+8fokcVihBnTrV9d+SSBDHHWgG++aYJYNjcBOMwxPhrqCBYXgh38OA/eZgW X-Received: by 2002:aca:56c2:: with SMTP id k185mr16408733oib.141.1584362196647; Mon, 16 Mar 2020 05:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584362196; cv=none; d=google.com; s=arc-20160816; b=DJauDu/GammcIWqepu7BKaG18UQkDhbeAKf7ZSYSqoDokxsu3lMEF93XNd72zesFtN nNvlXsW1eAFg7NwKeCXLmQVWje/BlTcQ5VTSeI/vpi7zm9nNAHERWja2eGt+WMWkKO/p f1hRky8NefSMKIYnpX9zRw1iRmryzpsuZCCcuz+nKn7kKrFJ2i8w4NZBuWhzP6K5hfuf +9HNC9WKLhtas0/bidLFOSbL/IoNErBnbqccp3pSBUtUTrVriL99EbtiuBJ7CHZFIr46 IY1hGDCZI5Zm+XtPo5A2p3uLh/FwCacCW6uQ6EXxNdnx58NAeN5jumvN6xkjrsxQFLaW XviQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=XYOdHBpCbWLdf2RVnuSzjw76mAuRmZuvMEgA37zOapw=; b=NblMesn3zB8YveChmgEEZKQU/MYDND6Vt93f8nvZxbn5I7pfijB9cySDlgkK5zhyV2 jo+N6bh+XpLUaQJ4HsuHv/uYHvhXJISvuoHoRmt0pqHJel3rzQKm0yMB+Sl4BemvR/Jd 51iRScZlxTEWjNUCPp0A86kPNkWDyyxGHnczIHD+aiieWfUOuINTz1RzwDQDnWCp+NI9 gqvFMnnfbcsd/3mav3k0vnWgr4xKn5PBnswJIq70InfCQy81udWuOc/qwPwpHJz7+xHZ qG7ixME8T4a+tTckQRbq/ZHRAzq2Ri10t9i9dnB2kGJrMDnKNNvki+vPVdZJcUfMfbZh rxug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=CSN883t3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si8614164otp.267.2020.03.16.05.36.22; Mon, 16 Mar 2020 05:36:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=CSN883t3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731060AbgCPMf4 (ORCPT + 99 others); Mon, 16 Mar 2020 08:35:56 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:58171 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731047AbgCPMfy (ORCPT ); Mon, 16 Mar 2020 08:35:54 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48gwkq4sSpz9tygT; Mon, 16 Mar 2020 13:35:47 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=CSN883t3; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id Fc5QqP1ITPzr; Mon, 16 Mar 2020 13:35:47 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48gwkq3rKgz9tyg5; Mon, 16 Mar 2020 13:35:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1584362147; bh=XYOdHBpCbWLdf2RVnuSzjw76mAuRmZuvMEgA37zOapw=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=CSN883t3ZVDYvB4xx6Opvz9QFkhmCizuLPXRc+3Rs9r/JdoP9PPXyggvslqpKbP+C KdqO8Updn+Ew0Mzy+DIaEkZIe4SvBs7tXyNjQmEM/dibIO3l6KrMRI2yVbsenIjmCo Vnai9BKRhmLJSQzlnMdIYjiPFTbYMZFTLfJEWIxM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6600E8B7D2; Mon, 16 Mar 2020 13:35:52 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id QzkzkZwZq4ol; Mon, 16 Mar 2020 13:35:52 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.100]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3294D8B7CB; Mon, 16 Mar 2020 13:35:52 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 2AAA265595; Mon, 16 Mar 2020 12:35:52 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 07/46] powerpc/kasan: Declare kasan_init_region() weak To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 16 Mar 2020 12:35:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to alloc sub-arches to alloc KASAN regions using optimised methods (Huge pages on 8xx, BATs on BOOK3S, ...), declare kasan_init_region() weak. Also make kasan_init_shadow_page_tables() accessible from outside, so that it can be called from the specific kasan_init_region() functions if needed. And populate remaining KASAN address space only once performed the region mapping, to allow 8xx to allocate hugepd instead of standard page tables for mapping via 8M hugepages. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kasan.h | 3 +++ arch/powerpc/mm/kasan/kasan_init_32.c | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 4769bbf7173a..107a24c3f7b3 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -34,5 +34,8 @@ static inline void kasan_init(void) { } static inline void kasan_late_init(void) { } #endif +int kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end); +int kasan_init_region(void *start, size_t size); + #endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index 65fd8b891f8e..03d30ec7a858 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -28,7 +28,7 @@ static void __init kasan_populate_pte(pte_t *ptep, pgprot_t prot) __set_pte_at(&init_mm, va, ptep, pfn_pte(PHYS_PFN(pa), prot), 0); } -static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end) +int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end) { pmd_t *pmd; unsigned long k_cur, k_next; @@ -52,7 +52,7 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned return 0; } -static int __init kasan_init_region(void *start, size_t size) +int __init __weak kasan_init_region(void *start, size_t size) { unsigned long k_start = (unsigned long)kasan_mem_to_shadow(start); unsigned long k_end = (unsigned long)kasan_mem_to_shadow(start + size); @@ -122,14 +122,6 @@ static void __init kasan_mmu_init(void) int ret; struct memblock_region *reg; - if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE) || - IS_ENABLED(CONFIG_KASAN_VMALLOC)) { - ret = kasan_init_shadow_page_tables(KASAN_SHADOW_START, KASAN_SHADOW_END); - - if (ret) - panic("kasan: kasan_init_shadow_page_tables() failed"); - } - for_each_memblock(memory, reg) { phys_addr_t base = reg->base; phys_addr_t top = min(base + reg->size, total_lowmem); @@ -141,6 +133,15 @@ static void __init kasan_mmu_init(void) if (ret) panic("kasan: kasan_init_region() failed"); } + + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE) || + IS_ENABLED(CONFIG_KASAN_VMALLOC)) { + ret = kasan_init_shadow_page_tables(KASAN_SHADOW_START, KASAN_SHADOW_END); + + if (ret) + panic("kasan: kasan_init_shadow_page_tables() failed"); + } + } void __init kasan_init(void) -- 2.25.0