Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp2835136pjo; Mon, 16 Mar 2020 05:36:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vullRaKWvDny4PGqAlUElFWNnEn9dSmkCDYITCjthurP8iOrRPoLBoNsuO0G8sW1vbnQSYQ X-Received: by 2002:aca:eb4e:: with SMTP id j75mr17359087oih.18.1584362188787; Mon, 16 Mar 2020 05:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584362188; cv=none; d=google.com; s=arc-20160816; b=G5s8bAd8UMMCMR2pgKf/zvSvaL7TmlWZJg9t7HD8Tvfhqise9VtiY0P/Sl3nD5+LKm jIBVzyRJHIZy9V8BYQUrgnIEJwrsKuLf91d3tyth216WfbIIlD9REVoEZ84iYWd0ew9P nkNcFmVXGagVcS0CQYsq9HAomSp6Rn0W2Gc7+BUi6U4iMLvfbNIjREgvL6aCfW3dsdIa CXeMdIZ0TsG+YUyEp7fnQG3QdegrY98V75KjtNloioa4xPqSD/ifu0SYYgcZ62zNxGTR LG1v0ZJn0iWpJ64qAPRM69PGqXIkzjFUZ5IFR31LoPMc4BPd89XCTLeinubdS3wasmzJ wMrw== 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=fb8Dm2InOClKUpndBVgU08V295ttuJmHU5Av7nsj+Pg=; b=0GBrLlMZPv6KA+Gbh1tD6Eea8/2Zp7E27m7oE+kv2gd5fbfINsMxfwMT3K9h9+kkUJ HP5TL4x1E6U/ud39zKosWkzDul/NvqrBf6CYaIp84UMWOdc8m3TkuiJYSSm0CMPAuGdC obq36azEEETknl4OjV931cr0pRq89GliwjiZbK4YH7/XW/iubv5vXJd2tGs5lKvG47T7 tukjOdcRTWghwq22CN7z+EdP9M976vmNnepFqV1unkRh4u+08JkHc7YoJY4Mv5fOhAYs rfPcRcqaGKn4p8bIoxALYIhEzKrjHGEtLkoeU1wbs3/FVsANKjDJr71ogYp2pscrvNV+ 0a4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=HcqOBxVf; 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 y132si6298941oig.238.2020.03.16.05.36.16; Mon, 16 Mar 2020 05:36:28 -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=HcqOBxVf; 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 S1731071AbgCPMfx (ORCPT + 99 others); Mon, 16 Mar 2020 08:35:53 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:63177 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731058AbgCPMfw (ORCPT ); Mon, 16 Mar 2020 08:35:52 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48gwkp33Kvz9tygS; Mon, 16 Mar 2020 13:35:46 +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=HcqOBxVf; 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 jGyaWm4O7Ilk; Mon, 16 Mar 2020 13:35:46 +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 48gwkp1pTqz9tyg5; Mon, 16 Mar 2020 13:35:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1584362146; bh=fb8Dm2InOClKUpndBVgU08V295ttuJmHU5Av7nsj+Pg=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=HcqOBxVf6Yz3ro30G9tatBWc4pvJVduX4luZ+LvNFwmA5KK1zDcULDyIoyRTRaGIA iBxhFurqB8VIoNeWHgf4PybGP7mtDYrNAo5dtwhPThl/v3xkAVFpC8d9OPnIEF1X2X eRVWPZIzx+k1FfRXw61KaAGrvyFGqYy8szbUnnqA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3BF6E8B7D0; Mon, 16 Mar 2020 13:35:51 +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 m4VOUuB4DmEF; Mon, 16 Mar 2020 13:35:51 +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 1DC8C8B7CB; Mon, 16 Mar 2020 13:35:51 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 1650F65595; Mon, 16 Mar 2020 12:35:51 +0000 (UTC) Message-Id: <5eb93a773184aa0d36faa93c096b21cbe0a069c9.1584360344.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 06/46] powerpc/kasan: Refactor update of early shadow mappings 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:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kasan_remap_early_shadow_ro() and kasan_unmap_early_shadow_vmalloc() are both updating the early shadow mapping: the first one sets the mapping read-only while the other clears the mapping. Refactor and create kasan_update_early_region() Signed-off-by: Christophe Leroy --- arch/powerpc/mm/kasan/kasan_init_32.c | 39 +++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index c9d053078c37..65fd8b891f8e 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -79,45 +79,42 @@ static int __init kasan_init_region(void *start, size_t size) return 0; } -static void __init kasan_remap_early_shadow_ro(void) +static void __init +kasan_update_early_region(unsigned long k_start, unsigned long k_end, pte_t pte) { - pgprot_t prot = kasan_prot_ro(); - unsigned long k_start = KASAN_SHADOW_START; - unsigned long k_end = KASAN_SHADOW_END; unsigned long k_cur; phys_addr_t pa = __pa(kasan_early_shadow_page); - kasan_populate_pte(kasan_early_shadow_pte, prot); - - for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { + for (k_cur = k_start; k_cur < k_end; k_cur += PAGE_SIZE) { pmd_t *pmd = pmd_ptr_k(k_cur); pte_t *ptep = pte_offset_kernel(pmd, k_cur); if ((pte_val(*ptep) & PTE_RPN_MASK) != pa) continue; - __set_pte_at(&init_mm, k_cur, ptep, pfn_pte(PHYS_PFN(pa), prot), 0); + __set_pte_at(&init_mm, k_cur, ptep, pte, 0); } - flush_tlb_kernel_range(KASAN_SHADOW_START, KASAN_SHADOW_END); + + flush_tlb_kernel_range(k_start, k_end); } -static void __init kasan_unmap_early_shadow_vmalloc(void) +static void __init kasan_remap_early_shadow_ro(void) { - unsigned long k_start = (unsigned long)kasan_mem_to_shadow((void *)VMALLOC_START); - unsigned long k_end = (unsigned long)kasan_mem_to_shadow((void *)VMALLOC_END); - unsigned long k_cur; + pgprot_t prot = kasan_prot_ro(); phys_addr_t pa = __pa(kasan_early_shadow_page); - for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) { - pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); - pte_t *ptep = pte_offset_kernel(pmd, k_cur); + kasan_populate_pte(kasan_early_shadow_pte, prot); - if ((pte_val(*ptep) & PTE_RPN_MASK) != pa) - continue; + kasan_update_early_region(KASAN_SHADOW_START, KASAN_SHADOW_END, + pfn_pte(PHYS_PFN(pa), prot)); +} - __set_pte_at(&init_mm, k_cur, ptep, __pte(0), 0); - } - flush_tlb_kernel_range(k_start, k_end); +static void __init kasan_unmap_early_shadow_vmalloc(void) +{ + unsigned long k_start = (unsigned long)kasan_mem_to_shadow((void *)VMALLOC_START); + unsigned long k_end = (unsigned long)kasan_mem_to_shadow((void *)VMALLOC_END); + + kasan_update_early_region(k_start, k_end, __pte(0)); } static void __init kasan_mmu_init(void) -- 2.25.0