From patchwork Tue Mar 12 22:16:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FE741515 for ; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBE0E296F7 for ; Tue, 12 Mar 2019 22:16:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCFA9296FE; Tue, 12 Mar 2019 22:16:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6B9D296F7 for ; Tue, 12 Mar 2019 22:16:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6153F8E0002; Tue, 12 Mar 2019 18:16:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 574838E0003; Tue, 12 Mar 2019 18:16:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EE128E0002; Tue, 12 Mar 2019 18:16:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id C26688E0003 for ; Tue, 12 Mar 2019 18:16:09 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id s5so1587985wrp.17 for ; Tue, 12 Mar 2019 15:16:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=OGZz0Q4R6Zdt3TK+8zOZmGmuwyLbFuizUxlVfu9yL9A=; b=n/ZaiOZaosz1iXIInfdpd5TCAEjSjjrNozVqHDfiQj6qpk+dlhkL0uriTULkzdXq5K fmXnuCQ1zbW0EhBFBVlK2YeF0XqkWA9F0XmQb+rqKRAMavJVN9gzkrs9rTkpume4rzVm W/p5KtZ2J9k0Z+EXm69vU98eNxfFBHp3hQAid+WP30wxFh+j/Z09iurhYx99J5eDCzJI XddJjEPQXYDqygVHg5v/ZpKAKvPjin4kuyTEpg/wrutisgIXqZdTLKHJj23zgK35jxOS eTewNrIfTSxKKjnwZJc/C0WadbvWeDTvR2KH9V5OFCMpc4axj7o4v/Vd8GzlVlwKFJ8N maBg== X-Gm-Message-State: APjAAAUtV5D4MVhTBf4DucuL++764PnW1/Gzxuw4DzRLXxhbHMq/QkIM JFa+nPzGQ9wcJVgQLNdYjuP949rqpk5hSECJSwgjO9Rp3dDI9v6rOG+HkVw50CR/E/cxilB/0Zx 0A1DEPgDX2J9Rr9gN0aRKNU9f9QYOHufC8dE8Cvvb8n45VbbIT1IYKJy+XH8yuZWDVw== X-Received: by 2002:a5d:624a:: with SMTP id m10mr7226537wrv.18.1552428968991; Tue, 12 Mar 2019 15:16:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ69pNgpfFFwmoPwCqp0ILfA2u/KayufJlU+k3eguYsPAve81vV6ZSikCE7Ddw7l0RIayI X-Received: by 2002:a5d:624a:: with SMTP id m10mr7226497wrv.18.1552428967729; Tue, 12 Mar 2019 15:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428967; cv=none; d=google.com; s=arc-20160816; b=aKHb67lMxCRhGC4cDoDh/y2s+cIK+9eKX3XZ8LISJNv+D5mR5CHSsd2Nzw2nkbuPXt o4xz3b8go1+O3Q2L19jvEUGZRWfB/lTmozoki+/D9fmCwS1m/S0DQE8IZca64+hV8e9e JThcRgpbri0MZn8T1zBy8TsHtq2W1GfMXOs+xiE1SDCiy8xOkbA79mRkhtkVY1OWoU1R fKKGW8DVOPhRpTKjW7xBQ5QENS1O2TMfSaVlnnqrFpPly6QJVUnMb9ao9IfSc+pr22aK 7XpcoRuj+2LIusKzP6eAIX8EjdnYV+uT9RYvzCOKpDw1Etf9b6yAxU5S52zWCWhSap3/ Bn/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=OGZz0Q4R6Zdt3TK+8zOZmGmuwyLbFuizUxlVfu9yL9A=; b=AWDkYP4hQ24nC+uuT5SVfREAhCXHHDiVG616kzvgn8FVihTXD7hSxYwym3JU043lPq Dqiu4VK0c2vPB+dXSLkJA+Xglry0+rOU0Ap3/pv3TGcn9GrhXMicjcRWjY1YUURsD5kr SBM3QqPz3Wt1RIDGv8S2JHiGzoYT1w0H3i7ggSYR6AR4H5ZMM7LlLKmOOBZA+glT4f3q ylnmArP3678sFIfMZTU2tuEDhx4mml4JSBITeZ3Vre549TJUITFwf8+bY615SoV5rbs0 n0PKNGCYm5Vdb0EoNr1yiIjO68ji6JlytfhqE5GHlDMhDAA3kGfIM21RqPQ2GCQyObye h7/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=KOMrUZ4F; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id 80si11947wma.155.2019.03.12.15.16.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:07 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=KOMrUZ4F; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7C05ytz9vRb3; Tue, 12 Mar 2019 23:16:07 +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=KOMrUZ4F; 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 elEkdr7Q7Ccb; Tue, 12 Mar 2019 23:16:06 +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 44Jq7B666bz9vRb0; Tue, 12 Mar 2019 23:16:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428966; bh=OGZz0Q4R6Zdt3TK+8zOZmGmuwyLbFuizUxlVfu9yL9A=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=KOMrUZ4FKyn9Qx1LCGBi8JhdyFrSKh1AC5NYVUt4kLLKAUUMshB3pcEdeJe/MY8Ar x6dG2+UiC7TocRsy2IisyT4g135rUL8xdYwIiXsIJFWi4PX7IQjNBohPT0deK3LkXw gl4IRuc04fxu6pHHL1SfvxrWbTTKcopk05zMCiEY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 119218B8B1; Tue, 12 Mar 2019 23:16:07 +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 EYmmjq3CtNLR; Tue, 12 Mar 2019 23:16:06 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CD0438B8A7; Tue, 12 Mar 2019 23:16:06 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id A162C6FA15; Tue, 12 Mar 2019 22:16:06 +0000 (UTC) Message-Id: <5047ab5aaf0fd90887fa1e5f0369182d71dcf0f6.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 01/18] powerpc/6xx: fix setup and use of SPRN_SPRG_PGDIR for hash32 To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:06 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Not only the 603 but all 6xx need SPRN_SPRG_PGDIR to be initialised at startup. This patch move it from __setup_cpu_603() to start_here() and __secondary_start(), close to the initialisation of SPRN_THREAD. Previously, virt addr of PGDIR was retrieved from thread struct. Now that it is the phys addr which is stored in SPRN_SPRG_PGDIR, hash_page() shall not convert it to phys anymore. This patch removes the conversion. Fixes: 93c4a162b014("powerpc/6xx: Store PGDIR physical address in a SPRG") Reported-by: Guenter Roeck Tested-by: Guenter Roeck Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/cpu_setup_6xx.S | 3 --- arch/powerpc/kernel/head_32.S | 6 ++++++ arch/powerpc/mm/hash_low_32.S | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kernel/cpu_setup_6xx.S b/arch/powerpc/kernel/cpu_setup_6xx.S index 6f1c11e0691f..7534ecff5e92 100644 --- a/arch/powerpc/kernel/cpu_setup_6xx.S +++ b/arch/powerpc/kernel/cpu_setup_6xx.S @@ -24,9 +24,6 @@ BEGIN_MMU_FTR_SECTION li r10,0 mtspr SPRN_SPRG_603_LRU,r10 /* init SW LRU tracking */ END_MMU_FTR_SECTION_IFSET(MMU_FTR_NEED_DTLB_SW_LRU) - lis r10, (swapper_pg_dir - PAGE_OFFSET)@h - ori r10, r10, (swapper_pg_dir - PAGE_OFFSET)@l - mtspr SPRN_SPRG_PGDIR, r10 BEGIN_FTR_SECTION bl __init_fpu_registers diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index ce6a972f2584..48051c8977c5 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -855,6 +855,9 @@ __secondary_start: li r3,0 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */ #endif + lis r4, (swapper_pg_dir - PAGE_OFFSET)@h + ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l + mtspr SPRN_SPRG_PGDIR, r4 /* enable MMU and jump to start_secondary */ li r4,MSR_KERNEL @@ -942,6 +945,9 @@ start_here: li r3,0 stw r3, RTAS_SP(r4) /* 0 => not in RTAS */ #endif + lis r4, (swapper_pg_dir - PAGE_OFFSET)@h + ori r4, r4, (swapper_pg_dir - PAGE_OFFSET)@l + mtspr SPRN_SPRG_PGDIR, r4 /* stack */ lis r1,init_thread_union@ha diff --git a/arch/powerpc/mm/hash_low_32.S b/arch/powerpc/mm/hash_low_32.S index 1f13494efb2b..a6c491f18a04 100644 --- a/arch/powerpc/mm/hash_low_32.S +++ b/arch/powerpc/mm/hash_low_32.S @@ -70,12 +70,12 @@ _GLOBAL(hash_page) lis r0,KERNELBASE@h /* check if kernel address */ cmplw 0,r4,r0 ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */ - mfspr r5, SPRN_SPRG_PGDIR /* virt page-table root */ + mfspr r5, SPRN_SPRG_PGDIR /* phys page-table root */ blt+ 112f /* assume user more likely */ - lis r5,swapper_pg_dir@ha /* if kernel address, use */ - addi r5,r5,swapper_pg_dir@l /* kernel page table */ + lis r5, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ + addi r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */ rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */ -112: tophys(r5, r5) +112: #ifndef CONFIG_PTE_64BIT rlwimi r5,r4,12,20,29 /* insert top 10 bits of address */ lwz r8,0(r5) /* get pmd entry */ From patchwork Tue Mar 12 22:16:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E28161515 for ; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE965296F7 for ; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F21296FE; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B9CA296F7 for ; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 504988E0005; Tue, 12 Mar 2019 18:16:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 48ADD8E0003; Tue, 12 Mar 2019 18:16:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3055F8E0005; Tue, 12 Mar 2019 18:16:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id C7FF88E0003 for ; Tue, 12 Mar 2019 18:16:10 -0400 (EDT) Received: by mail-wm1-f71.google.com with SMTP id h79so1034281wme.3 for ; Tue, 12 Mar 2019 15:16:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=fZn4Ngfk7JFea7diHSde6/p9kbdGl4xxyo9G2/zdnzw=; b=cp1s1lcJf8yPz0cgkimg6MiUxnDSOvCtACmua/HM3dyTeUWbBsh47z1e6Xfvx2oBtK RR2SaVoR6/sGuZmpD/prjoYOHweXJKAKUUB39F5pDjoVB6KCNWUIVjqo3GTglvR3gaIa Y3slVisuza3YYcG7M0RelUf2Np/FyBn1TxtYkjtWPhuCYs1Z+1Alm8OftEmqB3bcnWAY Pl2jhz0atvUmd+XkkTUNDojy9Ca4ir2fHxpxOQQQh8laaw3kjXByJ/9tH1tNJMymlxqL 0XW5i6hTICcmyVmphpcEAqkS6wKM2z8n6xjFo/nPJx/27M6qDhwcdAGxQ3xEtC4cx46T RFpQ== X-Gm-Message-State: APjAAAVM8dYv4hq0GKdqs2Ksow1I0cgR6rRilg0vWG+cYYfMJetSGYjD VtDoUOOz8lTvkgDInxuq2PF2UTNjpjtG15Nvx952YQm7DKrg7wKazND28pSxBb9/lO3koDnwUkb sqoFzC6Y7eqS9BPuyHNMbNGk7wC9guTUXp2JPFBlvp9f6YYhT6txMndYfHh79X7z44Q== X-Received: by 2002:adf:ed48:: with SMTP id u8mr18465249wro.185.1552428970035; Tue, 12 Mar 2019 15:16:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ+ETr32BKNwHls4oFEFvvN4mz2/JIxiniGQcKuSpHk0HlN53UVxByUCcewhml8dxtvYZS X-Received: by 2002:adf:ed48:: with SMTP id u8mr18465211wro.185.1552428968760; Tue, 12 Mar 2019 15:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428968; cv=none; d=google.com; s=arc-20160816; b=xR7KuLn8bpi86k5AxhQbKtob5GIXl0vlBKzRAudT5ejEUt8hUjFuoBg782q4iFi2at 863G9DTtSZ+kQWWnQc4Cu/mIKjWaHJcdOl7RK/LhdPxhmLQo77vKXN0VLPHnIfWATo3f 3zPr6IjpZfQYAZfXgfejF95JRDT+vsjdj7xnU4YVxPfoyzX01ACfwlckBCGdLqGtsscN 9QWknmAux7Pch3bVh5qEsUp0Aj4wgywjxFr3Ai3rXdZsISimP0zSL+ckQUj4KSWHbW1x FWjBjy0OeklFq0CddmnBMQYeAw0+17Mlc8LKTyto7uEr9uytBQ4lXCXT37jLOGoOfPn5 t4rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=fZn4Ngfk7JFea7diHSde6/p9kbdGl4xxyo9G2/zdnzw=; b=rR4hj3p1sdreP+g1CIUm2BJWByisHy4ZAsGf8emRH/LMCc1FUG157k+6WBlVM+Ps8s /uRrqKjX3tbaH4hVwgOJtfo3iurOfIqeiuCAaWbIVm+rsGkP6YIDnnhSc8aN6qEd6gD6 js9FU6KfI/g300+xqpwYmab2iRtczdTfWt99Y0YvzJZAKExHbB+98y1PpBH3IXeAz0JD DEZsdSULk+xu1NY181vOoAX2DCzndRYabSTnbcuO3n+B0DOagWcdTqRE6rdFUhESwjOo xQhWWZ58lGlB3k8MkK9JgS7LCN7G7PQYYyhlICHdahPJmBtQEuQgoLXzkbwceI38FXOx w1LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Y8gsJdMA; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id 4si13815wma.133.2019.03.12.15.16.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:08 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Y8gsJdMA; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7D0GS6z9vRb5; Tue, 12 Mar 2019 23:16:08 +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=Y8gsJdMA; 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 eMIA2_JKQpuj; Tue, 12 Mar 2019 23:16:07 +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 44Jq7C69p1z9vRb0; Tue, 12 Mar 2019 23:16:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428967; bh=fZn4Ngfk7JFea7diHSde6/p9kbdGl4xxyo9G2/zdnzw=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=Y8gsJdMA5GXDZeMcgNgsR7alt/mVnPZ6JaVQyWb/hBAIiQ4/3bPBWZRORtN/JZR2g 6P0VwAKSHk0QsYNOc6mnJvYkRLLZDteEi4U6qhdwfqZcC4yiuqdDUHWoVXDnFzNiSx pukj6CB1uVQSRYGUT8arvUIT0A3t1i4KQe0A0HIE= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 153158B8B1; Tue, 12 Mar 2019 23:16:08 +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 6NxrO2II63pO; Tue, 12 Mar 2019 23:16:07 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CD5D58B8A7; Tue, 12 Mar 2019 23:16:07 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id A73A96FA15; Tue, 12 Mar 2019 22:16:07 +0000 (UTC) Message-Id: <3c64608cacd6706fc026575bdaf4f24a20ad1fc7.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 02/18] powerpc/32: Move early_init() in a separate file To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:07 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In preparation of KASAN, move early_init() into a separate file in order to allow deactivation of KASAN for that function. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/early_32.c | 36 ++++++++++++++++++++++++++++++++++++ arch/powerpc/kernel/setup_32.c | 28 ---------------------------- 3 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 arch/powerpc/kernel/early_32.c diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index cddadccf551d..45e47752b692 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -93,7 +93,7 @@ extra-y += vmlinux.lds obj-$(CONFIG_RELOCATABLE) += reloc_$(BITS).o -obj-$(CONFIG_PPC32) += entry_32.o setup_32.o +obj-$(CONFIG_PPC32) += entry_32.o setup_32.o early_32.o obj-$(CONFIG_PPC64) += dma-iommu.o iommu.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_BOOTX_TEXT) += btext.o diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c new file mode 100644 index 000000000000..cf3cdd81dc47 --- /dev/null +++ b/arch/powerpc/kernel/early_32.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Early init before relocation + */ + +#include +#include +#include +#include +#include + +/* + * We're called here very early in the boot. + * + * Note that the kernel may be running at an address which is different + * from the address that it was linked at, so we must use RELOC/PTRRELOC + * to access static data (including strings). -- paulus + */ +notrace unsigned long __init early_init(unsigned long dt_ptr) +{ + unsigned long offset = reloc_offset(); + + /* First zero the BSS -- use memset_io, some platforms don't have caches on yet */ + memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); + + /* + * Identify the CPU type and fix up code sections + * that depend on which cpu we have. + */ + identify_cpu(offset, mfspr(SPRN_PVR)); + + apply_feature_fixups(); + + return KERNELBASE + offset; +} diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c index 4a65e08a6042..3fb9f64f88fd 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -64,34 +64,6 @@ EXPORT_SYMBOL(DMA_MODE_READ); EXPORT_SYMBOL(DMA_MODE_WRITE); /* - * We're called here very early in the boot. - * - * Note that the kernel may be running at an address which is different - * from the address that it was linked at, so we must use RELOC/PTRRELOC - * to access static data (including strings). -- paulus - */ -notrace unsigned long __init early_init(unsigned long dt_ptr) -{ - unsigned long offset = reloc_offset(); - - /* First zero the BSS -- use memset_io, some platforms don't have - * caches on yet */ - memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, - __bss_stop - __bss_start); - - /* - * Identify the CPU type and fix up code sections - * that depend on which cpu we have. - */ - identify_cpu(offset, mfspr(SPRN_PVR)); - - apply_feature_fixups(); - - return KERNELBASE + offset; -} - - -/* * This is run before start_kernel(), the kernel has been relocated * and we are running with enough of the MMU enabled to have our * proper kernel virtual addresses From patchwork Tue Mar 12 22:16:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C9C51515 for ; Tue, 12 Mar 2019 22:16:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57A8A296F7 for ; Tue, 12 Mar 2019 22:16:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BCFB296FE; Tue, 12 Mar 2019 22:16:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DE32296F7 for ; Tue, 12 Mar 2019 22:16:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDECE8E0003; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D65F78E0006; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE4488E0003; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id 4D8108E0006 for ; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id t7so1590940wrw.8 for ; Tue, 12 Mar 2019 15:16:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=9adWQ2eOTpeKwqD9lHYd+6T0EtP8IVztHNLFGdN0+Sk=; b=BXpKldODCmeXme8Nn02C4LyDyzbn0usK1PxeQCEc9qlZQClRZp1bKYzs7plMISlDvz tht8Dl/f3ZvaJftvL/Dtv/u7wQk5qWWByslt8Fc+g3nCfKcA5aSdBQKEQelANWQEo0Vg OXmRdIYIl8IjY4AmSCzseyTugQrly0GhpSrk7eNXTFm8T7DH6iH8e2+Ypn4sP0qqNXjr BqZmD2SSp1o4TyT/zbrz5MDNKDH4YH7rPcv9y63SdxMN/mKb/WEOOPSRNhoH3pv7Pki6 tt6aYlCxu4j6rtKsr0mhvxR/+MOnJZIhDKtG5GOPcQMhABPa8qKIx47jgWw8zQ+cNUK4 amVg== X-Gm-Message-State: APjAAAVeZMko16KNQQi02zGif0u9B3UxbsADXo4Onwbs7aRvwjR5eI+c zgd0XJ/cd2ob7Pq3gtuNh+SLHbossuI2QvGow1+3dbAn6UjAERfXFMYR3wtp6pDzmfpC0sGcAOO av7gnZ3I85LG3Z5axK10/OUqVsTenNzk6KdTxdUgrgOTiV83W5/sewCNrxspIUU+PVg== X-Received: by 2002:a1c:2d4c:: with SMTP id t73mr27959wmt.142.1552428972504; Tue, 12 Mar 2019 15:16:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxChqaJehqBj7W7PBMarpow2DgzlKslOGhx5J5FZvdwpw1418pH5kjuHBdJiZf4CE03CfIN X-Received: by 2002:a1c:2d4c:: with SMTP id t73mr27920wmt.142.1552428970888; Tue, 12 Mar 2019 15:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428970; cv=none; d=google.com; s=arc-20160816; b=lqq56WjzqHeNTjoOLsmlJ1A8oDPt4+EuqWdRM45t/Hf1O9iqcnX+sKlx38kQ0VYI7o B8wcmC8w0k2puG1CIX+O05NSmBdrjKIeu8+8yivIRSJoq1mAkZhzuu6a+jTm18uGiMww APx/3/Wi7E8UAfT1IZ56bPl3MmEbB9kr8/TMNRk4rkMcRTfycEMUcG8Zr9hVTF/Ok2l3 WOYwMiMItHAkdHoA/iuVm8BtaTJVFK6/0txlJj0rcSI6gc21sC2Tx7Q+tUAI9pEO95U3 MUetW0az132s8hRasXDOAyzWnPyPv42ukyeTXQIDaiISA5L1+WJEls372szDXHm10zVJ Nkjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=9adWQ2eOTpeKwqD9lHYd+6T0EtP8IVztHNLFGdN0+Sk=; b=ifjUt4TmDtTNDoHRUu+Thronko0koDVQt+MstKd1JPF4+rrHs5KkZl4gLCxLYKX8ou ti7Hcr8A2VwrsxC8TQNo4s7vejbLqaQ9Ln2VwkS0dN5QVIsxrEaIOks5Dxj/lY2QJ4t5 LhNwUX4SBYoMQ5/VAz7kNja6VhTklVACuQRJXcw5VABBGULqThFFcL9cVDstdlZiKTSB KTSkBFX9rGBDzqmvcNl3zACAB2yTciD/n0RkiQXvSZu5Xvd94/ot5T/TmfCR32NjkprE yffLibaLUrzngKesYoK3arWcvKEEfL+IkTdwNlgWyQtFNK2A21yr+QRhFEGFgLw0703P 19HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=KftVIMVS; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id t7si6353588wri.22.2019.03.12.15.16.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=KftVIMVS; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7F12J4zB09ZD; Tue, 12 Mar 2019 23:16:09 +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=KftVIMVS; 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 cwQcFsumXjKL; Tue, 12 Mar 2019 23:16:09 +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 44Jq7D6pGcz9vRb0; Tue, 12 Mar 2019 23:16:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428968; bh=9adWQ2eOTpeKwqD9lHYd+6T0EtP8IVztHNLFGdN0+Sk=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=KftVIMVSsoAcgchyq0G0S8dfd5e0GNKOH1T65UycrFrho1PK/W9dhL+5848YI8xkY KMHuxCq9Xw+m92r45fDHWl33kDihY67fFmI14zcF/3/1gsMFj4Kb1tRKNc3Rv4tt2I lIImF4c4UjmNa7GbU2faVhmAdbbRJBGiK8I/oTQU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2EB018B8B1; Tue, 12 Mar 2019 23:16:09 +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 SSfg7OlvRRXa; Tue, 12 Mar 2019 23:16:09 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D89298B8A7; Tue, 12 Mar 2019 23:16:08 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id ACE606FA15; Tue, 12 Mar 2019 22:16:08 +0000 (UTC) Message-Id: <1e6cd3250462be2939df67c4ee8ff53c3145de0a.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 03/18] powerpc: prepare string/mem functions for KASAN To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:08 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP CONFIG_KASAN implements wrappers for memcpy() memmove() and memset() Those wrappers are doing the verification then call respectively __memcpy() __memmove() and __memset(). The arches are therefore expected to rename their optimised functions that way. For files on which KASAN is inhibited, #defines are used to allow them to directly call optimised versions of the functions without going through the KASAN wrappers. See commit 393f203f5fd5 ("x86_64: kasan: add interceptors for memset/memmove/memcpy functions") for details. Other string / mem functions do not (yet) have kasan wrappers, we therefore have to fallback to the generic versions when KASAN is active, otherwise KASAN checks will be skipped. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kasan.h | 15 +++++++++++++++ arch/powerpc/include/asm/string.h | 32 +++++++++++++++++++++++++++++--- arch/powerpc/kernel/prom_init_check.sh | 10 +++++++++- arch/powerpc/lib/Makefile | 11 ++++++++--- arch/powerpc/lib/copy_32.S | 12 +++++++++--- arch/powerpc/lib/mem_64.S | 9 +++++++-- arch/powerpc/lib/memcpy_64.S | 4 +++- 7 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 arch/powerpc/include/asm/kasan.h diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h new file mode 100644 index 000000000000..2c179a39d4ba --- /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) _GLOBAL(__##fn) +#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(__##fn) +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) +#else +#define _GLOBAL_KASAN(fn) _GLOBAL(fn) +#define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(fn) +#define EXPORT_SYMBOL_KASAN(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..d5642481fb98 100644 --- a/arch/powerpc/lib/copy_32.S +++ b/arch/powerpc/lib/copy_32.S @@ -14,6 +14,7 @@ #include #include #include +#include #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 @@ -151,6 +154,7 @@ _GLOBAL(memset) bdnz 9b blr EXPORT_SYMBOL(memset) +EXPORT_SYMBOL_KASAN(memset) /* * This version uses dcbz on the complete cache lines in the @@ -163,12 +167,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 @@ -244,6 +248,8 @@ _GLOBAL(memcpy) 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..7f6bd031c306 100644 --- a/arch/powerpc/lib/mem_64.S +++ b/arch/powerpc/lib/mem_64.S @@ -12,7 +12,9 @@ #include #include #include +#include +#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 */ @@ -96,8 +99,9 @@ _GLOBAL(memset) 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 @@ -139,3 +143,4 @@ _GLOBAL(backwards_memcpy) 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..25c3772c1dfb 100644 --- a/arch/powerpc/lib/memcpy_64.S +++ b/arch/powerpc/lib/memcpy_64.S @@ -11,6 +11,7 @@ #include #include #include +#include #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 @@ -230,3 +231,4 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD) blr #endif EXPORT_SYMBOL(memcpy) +EXPORT_SYMBOL_KASAN(memcpy) From patchwork Tue Mar 12 22:16:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 366C11575 for ; Tue, 12 Mar 2019 22:16:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22B5C296FE for ; Tue, 12 Mar 2019 22:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16632296F9; Tue, 12 Mar 2019 22:16:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95E4F296F9 for ; Tue, 12 Mar 2019 22:16:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 817658E0007; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 772AC8E0003; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F0AC8E0007; Tue, 12 Mar 2019 18:16:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id ED0358E0003 for ; Tue, 12 Mar 2019 18:16:12 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id h65so1591176wrh.16 for ; Tue, 12 Mar 2019 15:16:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=WruMu/BwAMo8I9a3LF55jCSVvG/Tocg3gOnV17/tBYE=; b=sVpAELHcLqDu9tOoSwT9uTgu2y2XWqvfafrSBm7lnOCi1yXmt6KUcxGEQz3UnJF9df cuGH/SozQ6YvUibgxF2I/Cr3PhHXcvBzB4L7CFye9oqlHyBA9nINo0FU6xfWgY4Z+atU uXIMJnXdQD6eYTbwCVBtZW5Vn2QrZ0/6c3hpkGGWzwdxaf33GavjJkuZ9Ygyr1eem+Wm 3HGOQud7xa3k5UD3CAtEZRkU7MQu0XAIolxNyIc4SY0YDN9QxBJFAnSmrdJboDxx+U0+ re5FYPrG0bimtBzaPobintiPxZkjZMvOGth6Up7pQuKJhZRFG4fAxSlklOiVl0UckflC P8VA== X-Gm-Message-State: APjAAAXhgZag/Za4eFBRLzQaYgDJpzOo1DdcpfK21fIo4pXV6GKKBxtF 68PPaMmrF0l/c4EicIwioczK+mVO8YzuuvGugElpZJ2KLpID2PT6XVDFRfOEljxF353QW1Ei6vP oUEEMAcdtsMozkrzdlcNZNWXTf60q95ukWJTHfS9DxBaw2/JIypvk0JJ8wIRixC4THQ== X-Received: by 2002:a7b:c08b:: with SMTP id r11mr10059wmh.133.1552428972200; Tue, 12 Mar 2019 15:16:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOQjn/mnmCqzgRa4NQ8J72FmOun0p1xDsIah4PT7On+JBidTpQEHSYIwunQvfmpWvzk9OB X-Received: by 2002:a7b:c08b:: with SMTP id r11mr10029wmh.133.1552428970892; Tue, 12 Mar 2019 15:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428970; cv=none; d=google.com; s=arc-20160816; b=RQHGub80wPmUiTc/EmdbadeQGnj3kciKnZXZnfycHMFcFtPorLy1kMX2J1N/33oLmZ mKSKUwpLuqkAmApQrGSo1HpePPYYZ8nuS2zewiRoFTgPlPMvcDKMRqnVjL3PIgfpDBMD iBEVU4fA6Fxz4umOGw3e1PROUG4EOia/iQpcggi8yb65/Ab/brUAhhYv+nfIw8Xw2uSX aQJ2SnUfRPnPQq3XkDO+1gZaZ9Gh79EiDSXWSz7mj6aBK6poj0NwLFqufGulw3xPXEz7 uoa0EqWlRDmuxO1aAZni4BkDIFvAief5ABhrFWg2ltaDzxGKFxWZljtdqFJEC936EOSl JLQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=WruMu/BwAMo8I9a3LF55jCSVvG/Tocg3gOnV17/tBYE=; b=LR1+pYaxr9RjWG7PHmHNNp3PrFugT/+9o9xZuNbfoaD2idt1XqrfwPv2/Fn2PEhRU4 DuTDrbHXjs5rJEqXDaaw3fjXvZ2Inb1Fag0DSmkIzOn0nFxdVrCYOjbDbUQ3WNB4QYNg kEfhodCwOHqeExPt+KoT+buyNayee9a2EEyNHMfkk9R04bOftmF+m0mYd7jIaV8CD4Nw IcZAagyUGMZSG90NxwPWU9bHTj22EHr0AKP9d9NLhg82s/WH0yH0tGuxc5gbKLivUh6s sGTmb2EPt1fRJ9WV6B1bHKq3S1xYBJul96z++DCM95SH0CX2WEwA3kylKtBWbTW5lDEp REHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b="KQLanF/4"; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id d9si6261011wrn.274.2019.03.12.15.16.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b="KQLanF/4"; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7G0syJzB09ZJ; Tue, 12 Mar 2019 23:16:10 +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=KQLanF/4; 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 qEKF0zGnhklk; Tue, 12 Mar 2019 23:16:10 +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 44Jq7F6XsPzB09ZG; Tue, 12 Mar 2019 23:16:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428969; bh=WruMu/BwAMo8I9a3LF55jCSVvG/Tocg3gOnV17/tBYE=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=KQLanF/4dftXRqC6GCD0M0L1NDv7Tk3uwmOLHYfcMbzeC+NVftLENFHGm877fbTEE IqUJ0eJji/7Ty9h8hcq5o7AKByQwIgnGz7GlXQDYuo0WJNsnh7JvHOi3x3QBcfrO/f 4Tu4y32RrhY61drJqkgYuM6v7mtP3CrHTGS+Yi7M= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1F0638B8B1; Tue, 12 Mar 2019 23:16:10 +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 jEDvnohJtjOg; Tue, 12 Mar 2019 23:16:10 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E58B48B8A7; Tue, 12 Mar 2019 23:16:09 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id B3CFA6FA15; Tue, 12 Mar 2019 22:16:09 +0000 (UTC) Message-Id: <09fc2bc930197987745b937b3817b2563b0a42ab.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 04/18] powerpc: remove CONFIG_CMDLINE #ifdef mess To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:09 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch makes CONFIG_CMDLINE defined at all time. It avoids having to enclose related code inside #ifdef CONFIG_CMDLINE Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 6 +++--- arch/powerpc/kernel/prom_init.c | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index b5dce13a6132..facaa6ba0d2a 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -833,9 +833,9 @@ config CMDLINE_BOOL bool "Default bootloader kernel arguments" config CMDLINE - string "Initial kernel command string" - depends on CMDLINE_BOOL - default "console=ttyS0,9600 console=tty0 root=/dev/sda2" + string "Initial kernel command string" if CMDLINE_BOOL + default "console=ttyS0,9600 console=tty0 root=/dev/sda2" if CMDLINE_BOOL + default "" help On some platforms, there is currently no way for the boot loader to pass arguments to the kernel. For these platforms, you can supply diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index f33ff4163a51..ecf083c46bdb 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -631,17 +631,14 @@ static void __init early_cmdline_parse(void) const char *opt; char *p; - int l __maybe_unused = 0; + int l = 0; prom_cmd_line[0] = 0; p = prom_cmd_line; if ((long)prom.chosen > 0) l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); -#ifdef CONFIG_CMDLINE - if (l <= 0 || p[0] == '\0') /* dbl check */ - strlcpy(prom_cmd_line, - CONFIG_CMDLINE, sizeof(prom_cmd_line)); -#endif /* CONFIG_CMDLINE */ + if (IS_ENABLED(CONFIG_CMDLINE_BOOL) && (l <= 0 || p[0] == '\0')) /* dbl check */ + strlcpy(prom_cmd_line, CONFIG_CMDLINE, sizeof(prom_cmd_line)); prom_printf("command line: %s\n", prom_cmd_line); #ifdef CONFIG_PPC64 From patchwork Tue Mar 12 22:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2AD81515 for ; Tue, 12 Mar 2019 22:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABA07296F7 for ; Tue, 12 Mar 2019 22:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FBF1296FE; Tue, 12 Mar 2019 22:16:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E9FC296F7 for ; Tue, 12 Mar 2019 22:16:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB3CC8E0006; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8D1748E000A; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 724CB8E0006; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id 0374C8E0008 for ; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id 92so1604048wrb.6 for ; Tue, 12 Mar 2019 15:16:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=MghN/1OC9A0MTcOlT6qOCu35MkFNCpkvcFrYU21/ZNg=; b=KFrnCEwKaeOdQ9otKA+pOjF/b4NZ0BabgB70unW12EUoHJfzC9cfElT+vrTBAKU/8f FJnUi3sK/p8un8XsAL/nWyhxa7nqJ9fofeFnnDKCoG4hd0I414JNUewL2n03e1flgznN HYmh8HOD9aWaU7USkZNrXkD8CRFcUaP2+lLuiX8laSEB1XPTtl1TItXv16+wfncNw8vs ap57rEIS/V9RvuPLJzoIRAh/MxKfta5rwiRnE10vqzIQdU1eLWDXcy8J8O6l0hPO3J9m FJ5BL/GLxCCp/DJYpH+qnm1/sCS/HVb8IKtzYdEai1fHIvl4JAR6wkMDBGYwveqp22YC SCZw== X-Gm-Message-State: APjAAAXMEN/9VaiX3eA/ZLUPh09o3Nl0csDtK3vfCvR2YVwgIoYD+kPR BLzRfqioFTxck9yPh1k40dpSxhaVz3XSzt/DI2uxLdoW4KHpNXwC/NuNeURGMDQT8jHc50lsBUW iMIjHx7dVUmOD9tP8zS2ZfCor9g+eFFDujWeQ82y09C0kkbg3bjUyldFHl9UfPcFMpg== X-Received: by 2002:adf:9167:: with SMTP id j94mr26849435wrj.106.1552428974207; Tue, 12 Mar 2019 15:16:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhmUbO/X3It+gaiMREn9GTMzLViRZaWbqIGUdT31VdAN7fyFDEKsk/G+JB7tXCg3iTM/M1 X-Received: by 2002:adf:9167:: with SMTP id j94mr26849382wrj.106.1552428972065; Tue, 12 Mar 2019 15:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428972; cv=none; d=google.com; s=arc-20160816; b=peTgOxjjGltTGGAY+6P/8cgjPiMSJB/lCeLtNQ0oesZ99RUBNfS5iTMpn+aTzu5uI2 P5iqbRM78K94V5tirYQpx0X+c//ltDwrnqbJ5Te0o1tdQNtjVrrAlXQHPx1d/rFspgaA Iz6rGVI6sU6AhMMXEgD1MxYkm3RfHo5dKpZk+C55vsZYaxpzBjaN2wl3sLeGyukFSnvR /2JKfnHyUvLBPY/nWZ8zAdNpGjDF765xzeNyXd4/gz6Dsp+ytXR5ukUrgJt8OABd4ICh mpIP57Kji0UsbZg3iq/OpG++ZzKdqcrxM+yvqB5DP24ww64W8rkfJXmhLI8q6ssNr+vD 98BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=MghN/1OC9A0MTcOlT6qOCu35MkFNCpkvcFrYU21/ZNg=; b=UWyMUuzUkZP/t+qGqTmJKYeS9mWuZZeAJKgLkRSZR+h9v3/SEeNyFyU+kbrvpm6oID Ce5jFyOEF8JzBkWvw5cVtrnPxwRC+8+QVXnXBK8wrdLcvJ+/f9A7SW0Fsl/fSRn8ADkz mV41PMj+OVn3MPt/0/ucNbpzS8h0GrfX/KVl6m0q3FreDbGI6QJgidMhzq+DPrkerjqE 3dyKaQGbrQBOHlXFs1WTcJyz9gQJoKjtEiV1ykDmYSTDYwiJ0/m9OYeSCv17Oju2m7ui YAEAdPN4z22jVscJU2qVlsX1bzppyCeMC22tqdm44Cu45XDtVsJ25kw7F3azrbilmfk2 LmBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ECWoQuEW; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id y7si6072571wro.195.2019.03.12.15.16.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:12 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ECWoQuEW; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7H2QpkzB09ZL; Tue, 12 Mar 2019 23:16:11 +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=ECWoQuEW; 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 yhDPREmDayPK; Tue, 12 Mar 2019 23:16:11 +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 44Jq7H0Y9szB09ZG; Tue, 12 Mar 2019 23:16:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428971; bh=MghN/1OC9A0MTcOlT6qOCu35MkFNCpkvcFrYU21/ZNg=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ECWoQuEWAGbE9yRhVrg/pBBlDAsybXrbSUQjTalju4wyuJ22Ykqg7rOlmDuhXvA4A RlghqxqGWmiEObTS0D9SJPpNcH/phom2aDDWePBjdJz+gcODaYepDuCNSi4eJJYZt2 7h6VB+jrYojBTdsCEuiM5V9W2umEroG3XGYoXv9Y= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 443198B8B1; Tue, 12 Mar 2019 23:16:11 +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 JI0LvB-1r1Dp; Tue, 12 Mar 2019 23:16:11 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EA3088B8A7; Tue, 12 Mar 2019 23:16:10 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id B952D6FA15; Tue, 12 Mar 2019 22:16:10 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 05/18] powerpc/prom_init: don't use string functions from lib/ To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:10 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When KASAN is active, the string functions in lib/ are doing the KASAN checks. This is too early for prom_init. This patch implements dedicated string functions for prom_init, which will be compiled in with KASAN disabled. Size of prom_init before the patch: text data bss dec hex filename 12060 488 6960 19508 4c34 arch/powerpc/kernel/prom_init.o Size of prom_init after the patch: text data bss dec hex filename 12460 488 6960 19908 4dc4 arch/powerpc/kernel/prom_init.o This increases the size of prom_init a bit, but as prom_init is in __init section, it is freed after boot anyway. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/prom_init.c | 211 ++++++++++++++++++++++++++------- arch/powerpc/kernel/prom_init_check.sh | 2 +- 2 files changed, 171 insertions(+), 42 deletions(-) diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index ecf083c46bdb..7017156168e8 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -224,6 +224,135 @@ static bool __prombss rtas_has_query_cpu_stopped; #define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR) #define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR) +/* Copied from lib/string.c and lib/kstrtox.c */ + +static int __init prom_strcmp(const char *cs, const char *ct) +{ + unsigned char c1, c2; + + while (1) { + c1 = *cs++; + c2 = *ct++; + if (c1 != c2) + return c1 < c2 ? -1 : 1; + if (!c1) + break; + } + return 0; +} + +static char __init *prom_strcpy(char *dest, const char *src) +{ + char *tmp = dest; + + while ((*dest++ = *src++) != '\0') + /* nothing */; + return tmp; +} + +static int __init prom_strncmp(const char *cs, const char *ct, size_t count) +{ + unsigned char c1, c2; + + while (count) { + c1 = *cs++; + c2 = *ct++; + if (c1 != c2) + return c1 < c2 ? -1 : 1; + if (!c1) + break; + count--; + } + return 0; +} + +static size_t __init prom_strlen(const char *s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} + +static int __init prom_memcmp(const void *cs, const void *ct, size_t count) +{ + const unsigned char *su1, *su2; + int res = 0; + + for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) + if ((res = *su1 - *su2) != 0) + break; + return res; +} + +static char __init *prom_strstr(const char *s1, const char *s2) +{ + size_t l1, l2; + + l2 = prom_strlen(s2); + if (!l2) + return (char *)s1; + l1 = prom_strlen(s1); + while (l1 >= l2) { + l1--; + if (!prom_memcmp(s1, s2, l2)) + return (char *)s1; + s1++; + } + return NULL; +} + +static size_t __init prom_strlcpy(char *dest, const char *src, size_t size) +{ + size_t ret = prom_strlen(src); + + if (size) { + size_t len = (ret >= size) ? size - 1 : ret; + memcpy(dest, src, len); + dest[len] = '\0'; + } + return ret; +} + +#ifdef CONFIG_PPC_PSERIES +static int __init prom_strtobool(const char *s, bool *res) +{ + if (!s) + return -EINVAL; + + switch (s[0]) { + case 'y': + case 'Y': + case '1': + *res = true; + return 0; + case 'n': + case 'N': + case '0': + *res = false; + return 0; + case 'o': + case 'O': + switch (s[1]) { + case 'n': + case 'N': + *res = true; + return 0; + case 'f': + case 'F': + *res = false; + return 0; + default: + break; + } + default: + break; + } + + return -EINVAL; +} +#endif /* This is the one and *ONLY* place where we actually call open * firmware. @@ -555,7 +684,7 @@ static int __init prom_setprop(phandle node, const char *nodename, add_string(&p, tohex((u32)(unsigned long) value)); add_string(&p, tohex(valuelen)); add_string(&p, tohex(ADDR(pname))); - add_string(&p, tohex(strlen(pname))); + add_string(&p, tohex(prom_strlen(pname))); add_string(&p, "property"); *p = 0; return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd); @@ -638,23 +767,23 @@ static void __init early_cmdline_parse(void) if ((long)prom.chosen > 0) l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); if (IS_ENABLED(CONFIG_CMDLINE_BOOL) && (l <= 0 || p[0] == '\0')) /* dbl check */ - strlcpy(prom_cmd_line, CONFIG_CMDLINE, sizeof(prom_cmd_line)); + prom_strlcpy(prom_cmd_line, CONFIG_CMDLINE, sizeof(prom_cmd_line)); prom_printf("command line: %s\n", prom_cmd_line); #ifdef CONFIG_PPC64 - opt = strstr(prom_cmd_line, "iommu="); + opt = prom_strstr(prom_cmd_line, "iommu="); if (opt) { prom_printf("iommu opt is: %s\n", opt); opt += 6; while (*opt && *opt == ' ') opt++; - if (!strncmp(opt, "off", 3)) + if (!prom_strncmp(opt, "off", 3)) prom_iommu_off = 1; - else if (!strncmp(opt, "force", 5)) + else if (!prom_strncmp(opt, "force", 5)) prom_iommu_force_on = 1; } #endif - opt = strstr(prom_cmd_line, "mem="); + opt = prom_strstr(prom_cmd_line, "mem="); if (opt) { opt += 4; prom_memory_limit = prom_memparse(opt, (const char **)&opt); @@ -666,13 +795,13 @@ static void __init early_cmdline_parse(void) #ifdef CONFIG_PPC_PSERIES prom_radix_disable = !IS_ENABLED(CONFIG_PPC_RADIX_MMU_DEFAULT); - opt = strstr(prom_cmd_line, "disable_radix"); + opt = prom_strstr(prom_cmd_line, "disable_radix"); if (opt) { opt += 13; if (*opt && *opt == '=') { bool val; - if (kstrtobool(++opt, &val)) + if (prom_strtobool(++opt, &val)) prom_radix_disable = false; else prom_radix_disable = val; @@ -1025,7 +1154,7 @@ static int __init prom_count_smt_threads(void) type[0] = 0; prom_getprop(node, "device_type", type, sizeof(type)); - if (strcmp(type, "cpu")) + if (prom_strcmp(type, "cpu")) continue; /* * There is an entry for each smt thread, each entry being @@ -1472,7 +1601,7 @@ static void __init prom_init_mem(void) */ prom_getprop(node, "name", type, sizeof(type)); } - if (strcmp(type, "memory")) + if (prom_strcmp(type, "memory")) continue; plen = prom_getprop(node, "reg", regbuf, sizeof(regbuf)); @@ -1753,19 +1882,19 @@ static void __init prom_initialize_tce_table(void) prom_getprop(node, "device_type", type, sizeof(type)); prom_getprop(node, "model", model, sizeof(model)); - if ((type[0] == 0) || (strstr(type, "pci") == NULL)) + if ((type[0] == 0) || (prom_strstr(type, "pci") == NULL)) continue; /* Keep the old logic intact to avoid regression. */ if (compatible[0] != 0) { - if ((strstr(compatible, "python") == NULL) && - (strstr(compatible, "Speedwagon") == NULL) && - (strstr(compatible, "Winnipeg") == NULL)) + if ((prom_strstr(compatible, "python") == NULL) && + (prom_strstr(compatible, "Speedwagon") == NULL) && + (prom_strstr(compatible, "Winnipeg") == NULL)) continue; } else if (model[0] != 0) { - if ((strstr(model, "ython") == NULL) && - (strstr(model, "peedwagon") == NULL) && - (strstr(model, "innipeg") == NULL)) + if ((prom_strstr(model, "ython") == NULL) && + (prom_strstr(model, "peedwagon") == NULL) && + (prom_strstr(model, "innipeg") == NULL)) continue; } @@ -1914,12 +2043,12 @@ static void __init prom_hold_cpus(void) type[0] = 0; prom_getprop(node, "device_type", type, sizeof(type)); - if (strcmp(type, "cpu") != 0) + if (prom_strcmp(type, "cpu") != 0) continue; /* Skip non-configured cpus. */ if (prom_getprop(node, "status", type, sizeof(type)) > 0) - if (strcmp(type, "okay") != 0) + if (prom_strcmp(type, "okay") != 0) continue; reg = cpu_to_be32(-1); /* make sparse happy */ @@ -1995,9 +2124,9 @@ static void __init prom_find_mmu(void) return; version[sizeof(version) - 1] = 0; /* XXX might need to add other versions here */ - if (strcmp(version, "Open Firmware, 1.0.5") == 0) + if (prom_strcmp(version, "Open Firmware, 1.0.5") == 0) of_workarounds = OF_WA_CLAIM; - else if (strncmp(version, "FirmWorks,3.", 12) == 0) { + else if (prom_strncmp(version, "FirmWorks,3.", 12) == 0) { of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL; call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim"); } else @@ -2030,7 +2159,7 @@ static void __init prom_init_stdout(void) call_prom("instance-to-path", 3, 1, prom.stdout, path, 255); prom_printf("OF stdout device is: %s\n", of_stdout_device); prom_setprop(prom.chosen, "/chosen", "linux,stdout-path", - path, strlen(path) + 1); + path, prom_strlen(path) + 1); /* instance-to-package fails on PA-Semi */ stdout_node = call_prom("instance-to-package", 1, 1, prom.stdout); @@ -2040,7 +2169,7 @@ static void __init prom_init_stdout(void) /* If it's a display, note it */ memset(type, 0, sizeof(type)); prom_getprop(stdout_node, "device_type", type, sizeof(type)); - if (strcmp(type, "display") == 0) + if (prom_strcmp(type, "display") == 0) prom_setprop(stdout_node, path, "linux,boot-display", NULL, 0); } } @@ -2061,19 +2190,19 @@ static int __init prom_find_machine_type(void) compat[len] = 0; while (i < len) { char *p = &compat[i]; - int sl = strlen(p); + int sl = prom_strlen(p); if (sl == 0) break; - if (strstr(p, "Power Macintosh") || - strstr(p, "MacRISC")) + if (prom_strstr(p, "Power Macintosh") || + prom_strstr(p, "MacRISC")) return PLATFORM_POWERMAC; #ifdef CONFIG_PPC64 /* We must make sure we don't detect the IBM Cell * blades as pSeries due to some firmware issues, * so we do it here. */ - if (strstr(p, "IBM,CBEA") || - strstr(p, "IBM,CPBW-1.0")) + if (prom_strstr(p, "IBM,CBEA") || + prom_strstr(p, "IBM,CPBW-1.0")) return PLATFORM_GENERIC; #endif /* CONFIG_PPC64 */ i += sl + 1; @@ -2090,7 +2219,7 @@ static int __init prom_find_machine_type(void) compat, sizeof(compat)-1); if (len <= 0) return PLATFORM_GENERIC; - if (strcmp(compat, "chrp")) + if (prom_strcmp(compat, "chrp")) return PLATFORM_GENERIC; /* Default to pSeries. We need to know if we are running LPAR */ @@ -2152,7 +2281,7 @@ static void __init prom_check_displays(void) for (node = 0; prom_next_node(&node); ) { memset(type, 0, sizeof(type)); prom_getprop(node, "device_type", type, sizeof(type)); - if (strcmp(type, "display") != 0) + if (prom_strcmp(type, "display") != 0) continue; /* It seems OF doesn't null-terminate the path :-( */ @@ -2256,9 +2385,9 @@ static unsigned long __init dt_find_string(char *str) s = os = (char *)dt_string_start; s += 4; while (s < (char *)dt_string_end) { - if (strcmp(s, str) == 0) + if (prom_strcmp(s, str) == 0) return s - os; - s += strlen(s) + 1; + s += prom_strlen(s) + 1; } return 0; } @@ -2291,7 +2420,7 @@ static void __init scan_dt_build_strings(phandle node, } /* skip "name" */ - if (strcmp(namep, "name") == 0) { + if (prom_strcmp(namep, "name") == 0) { *mem_start = (unsigned long)namep; prev_name = "name"; continue; @@ -2303,7 +2432,7 @@ static void __init scan_dt_build_strings(phandle node, namep = sstart + soff; } else { /* Trim off some if we can */ - *mem_start = (unsigned long)namep + strlen(namep) + 1; + *mem_start = (unsigned long)namep + prom_strlen(namep) + 1; dt_string_end = *mem_start; } prev_name = namep; @@ -2372,7 +2501,7 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, break; /* skip "name" */ - if (strcmp(pname, "name") == 0) { + if (prom_strcmp(pname, "name") == 0) { prev_name = "name"; continue; } @@ -2403,7 +2532,7 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, call_prom("getprop", 4, 1, node, pname, valp, l); *mem_start = _ALIGN(*mem_start, 4); - if (!strcmp(pname, "phandle")) + if (!prom_strcmp(pname, "phandle")) has_phandle = 1; } @@ -2473,8 +2602,8 @@ static void __init flatten_device_tree(void) /* Add "phandle" in there, we'll need it */ namep = make_room(&mem_start, &mem_end, 16, 1); - strcpy(namep, "phandle"); - mem_start = (unsigned long)namep + strlen(namep) + 1; + prom_strcpy(namep, "phandle"); + mem_start = (unsigned long)namep + prom_strlen(namep) + 1; /* Build string array */ prom_printf("Building dt strings...\n"); @@ -2796,7 +2925,7 @@ static void __init fixup_device_tree_efika(void) rv = prom_getprop(node, "model", prop, sizeof(prop)); if (rv == PROM_ERROR) return; - if (strcmp(prop, "EFIKA5K2")) + if (prom_strcmp(prop, "EFIKA5K2")) return; prom_printf("Applying EFIKA device tree fixups\n"); @@ -2804,13 +2933,13 @@ static void __init fixup_device_tree_efika(void) /* Claiming to be 'chrp' is death */ node = call_prom("finddevice", 1, 1, ADDR("/")); rv = prom_getprop(node, "device_type", prop, sizeof(prop)); - if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0)) + if (rv != PROM_ERROR && (prom_strcmp(prop, "chrp") == 0)) prom_setprop(node, "/", "device_type", "efika", sizeof("efika")); /* CODEGEN,description is exposed in /proc/cpuinfo so fix that too */ rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop)); - if (rv != PROM_ERROR && (strstr(prop, "CHRP"))) + if (rv != PROM_ERROR && (prom_strstr(prop, "CHRP"))) prom_setprop(node, "/", "CODEGEN,description", "Efika 5200B PowerPC System", sizeof("Efika 5200B PowerPC System")); diff --git a/arch/powerpc/kernel/prom_init_check.sh b/arch/powerpc/kernel/prom_init_check.sh index 181fd10008ef..4cac45cb5de5 100644 --- a/arch/powerpc/kernel/prom_init_check.sh +++ b/arch/powerpc/kernel/prom_init_check.sh @@ -27,7 +27,7 @@ fi WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush _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 +logo_linux_clut224 reloc_got2 kernstart_addr memstart_addr linux_banner _stext __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC." From patchwork Tue Mar 12 22:16:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6238B1515 for ; Tue, 12 Mar 2019 22:16:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FDC8296F7 for ; Tue, 12 Mar 2019 22:16:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44291296FE; Tue, 12 Mar 2019 22:16:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 060D5296F7 for ; Tue, 12 Mar 2019 22:16:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8391A8E0009; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7BFBA8E0008; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DC888E0009; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by kanga.kvack.org (Postfix) with ESMTP id E05398E0006 for ; Tue, 12 Mar 2019 18:16:14 -0400 (EDT) Received: by mail-wm1-f70.google.com with SMTP id t190so1030502wmt.8 for ; Tue, 12 Mar 2019 15:16:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=g6fhwCUzzCOYhxsR7m9Lo9kcYtSGDH5kmO2yLp27uXY=; b=fKL+UKPaitcoSgVb78pnXq5PUuSc0UcQnHigh90xF1fq5+7USyhC5XutkuLd4LA3ON o4pAKw+IdQXQkxtiMaFzC6+s6+K1j6gVqCgnfTGoPKWPiGsrI+cso4GOFLOpsGNqC7Q8 pQ45l8y1vgSLpd9X3j/j1eSQujzAnz3W9FezfYQIUwRDHX8gxsXzZE+22ATqjoEGLnZD 4bvK1OQMFvxoJVBHZwAEjfpo3Y0L8uvMmxcv1bnj7KshE+lJMwDSKXnWactOliICWNvk 9VcJaHGDhzEO/etABx73UaTJeCrrGCiGVW6TgC+2e8PRtqAjFTi4cf5VaKdgvULGyPzD Gq1w== X-Gm-Message-State: APjAAAUYJyNslkIKFfWgp+ESyxdTVB8uxyEQFF0rzIodxnTSK78+zo4B xAUxgFDhWrUG+evWY7nNDnDY6hZ18Lmvu1NusTfojcjSWgpdb9t7+HkHX5GY5oRVpkJNIZOUVu6 CvufjO7o+c7iHyWuPOZoOaZI/TGR2UZCy7ldVg2pYFy5RaSVYncOlls3jIAcCwKdXvg== X-Received: by 2002:a5d:6b4a:: with SMTP id x10mr3970145wrw.63.1552428974097; Tue, 12 Mar 2019 15:16:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwINzhfZ0wJnnjlqHRwQBWJDE5V4RqROJR+XRTnWassmRtOahwIE8OnoMwOdN0pHIP8g4A5 X-Received: by 2002:a5d:6b4a:: with SMTP id x10mr3970124wrw.63.1552428972929; Tue, 12 Mar 2019 15:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428972; cv=none; d=google.com; s=arc-20160816; b=U9lP6mdjKg3+JTV9sICR9hmdNKBROyE550kYBajVW2Sp/vVOG+2hrGUz4IQw8aGNNI W6pNHwn0bp5K5A4KNm1s5ORfvPciPFwvKE1uXTQfF02h1ZcHjD/ass2mKieGMlPUScwe ViXg+Jtq0tsAdy5GXXNrhFlOApLQq0hGd1VCReNVbWO9zJY7sxxHMSnn9KGGKiBHm7aJ wykYs3YMpYRIOv4X0MZmlX591nUX7PtfmUm6cDLNiwYIJ/JO5Ex0WKPRcoJXMZqlUDU9 5jQx93ZXyvZWXMRNymfkApXk8J7hNipJX4c/HuQ49nnSNVjTWTaYn/xRcoqcPF2lmhhl EiOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=g6fhwCUzzCOYhxsR7m9Lo9kcYtSGDH5kmO2yLp27uXY=; b=eYBGLiCIoXa7vgmBwqFCxYJxBoBE7rxRqP6qk4jF05qrHCoOo7Nx0brYzxqBdg1Qyz ohTe2suoRgy1awtRkb9DQmpupe35vtdTsnbX+ybnvTY2ihPJBPFnWaCG0QlOVwbcfd0D oQ2hLqj1viL72yrQkuTGwTuuatxtin/FplqqfUju9avFiMRi+IqBQpmD4LOcfqG8IQFt avbrD9qJRzesI4G6gV2d6COp6SUGMzcBt4aFGApje4RCOx6CBh3obAvBIUyETsunlFNg 8f0A3+2pQaBfeTm6uHyGan+CDVyIAheRPDPPIP+x1L0LCy+XB6NGAYq5t+Xnra1pDh5h fC+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=GRISycul; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id n4si6752767wrv.441.2019.03.12.15.16.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:12 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=GRISycul; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7J1NQSzB09Zk; Tue, 12 Mar 2019 23:16:12 +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=GRISycul; 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 W60iEXBdWSrt; Tue, 12 Mar 2019 23:16:12 +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 44Jq7H6y2JzB09ZG; Tue, 12 Mar 2019 23:16:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428972; bh=g6fhwCUzzCOYhxsR7m9Lo9kcYtSGDH5kmO2yLp27uXY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=GRISyculWuNgpnsKVSDrLXiB3Vx7W9rFI3Jlby7Ft1rk8XgMyJxYIBcneemW5ut8W arFKEhEtOFE06YUwRz9MjH8s+X0MRv/qV4lKwTUPQsTTEhWwSxRRueOP3N0mPyyQJL nPNgPBBuLQySI9YEaaw6KAoItz6ppObJkgmsG2B0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 31E378B8B1; Tue, 12 Mar 2019 23:16:12 +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 oybGxBwVbTKv; Tue, 12 Mar 2019 23:16:12 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0577A8B8A7; Tue, 12 Mar 2019 23:16:12 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id C0B646FA15; Tue, 12 Mar 2019 22:16:11 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 06/18] powerpc/mm: don't use direct assignation during early boot. To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:11 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In kernel/cputable.c, explicitly use memcpy() instead of *y = *x; This will allow GCC to replace it with __memcpy() when KASAN is selected. Acked-by: Dmitry Vyukov Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/cputable.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c index 1eab54bc6ee9..cd12f362b61f 100644 --- a/arch/powerpc/kernel/cputable.c +++ b/arch/powerpc/kernel/cputable.c @@ -2147,7 +2147,11 @@ void __init set_cur_cpu_spec(struct cpu_spec *s) struct cpu_spec *t = &the_cpu_spec; t = PTRRELOC(t); - *t = *s; + /* + * use memcpy() instead of *t = *s so that GCC replaces it + * by __memcpy() when KASAN is active + */ + memcpy(t, s, sizeof(*t)); *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec; } @@ -2161,8 +2165,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned long offset, t = PTRRELOC(t); old = *t; - /* Copy everything, then do fixups */ - *t = *s; + /* + * Copy everything, then do fixups. Use memcpy() instead of *t = *s + * so that GCC replaces it by __memcpy() when KASAN is active + */ + memcpy(t, s, sizeof(*t)); /* * If we are overriding a previous value derived from the real From patchwork Tue Mar 12 22:16:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC0701575 for ; Tue, 12 Mar 2019 22:16:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F5029315 for ; Tue, 12 Mar 2019 22:16:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AD9D296F9; Tue, 12 Mar 2019 22:16:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41E8629315 for ; Tue, 12 Mar 2019 22:16:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C4098E000A; Tue, 12 Mar 2019 18:16:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 727038E0008; Tue, 12 Mar 2019 18:16:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 576FC8E000A; Tue, 12 Mar 2019 18:16:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id E76DC8E0008 for ; Tue, 12 Mar 2019 18:16:15 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id z16so1619379wrt.0 for ; Tue, 12 Mar 2019 15:16:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=FcoH0MWZdtOBuC7W/yk0A9+bmiNTMQTCcIimrSkyq24=; b=Lm78LUVBFW48RmlqAJNTGtjtmNah05iTYvR13xH0vR7QIcUTsYcSyAkreuf05VGoGo EDvvJqZ77pj6cRTahKsht61eMGClFu1UvAy4CbMQoQEwapgbcaaGWaQmQ14UzFgzOnWR yvlC3BlLxH2bmALZkc5CMnymxqHyHPGflnT0Pko8rYrxJvzChV9zyCHl2yL0b/FYDjQ9 AwtEj9qUq9H/3ghsB+oz5f1NB6UXIdYuy1sttr3Rjiq9H9FUw5LARAxmvzW5A4QxFc7e cE8JPd/1oVrijC/QahIoqCxqqfn5eLSEAV2Y4p4hgGstDu8DDYu+s6VK6ELc/SQjzych J+Lg== X-Gm-Message-State: APjAAAV/8hcwGRHzlae3bxLyWG+syZSwWsAk6YkZCPl5CQ/CV5fy8Lw3 +uYkFgNehJrsNceSNxr3kXBoJcecgqsOjy94EqeJVit4sMD+QhXaq9I+aUMpLwah9wVyVugECbb TrhmxJA9uu8lIY8+NSt3LoEbkDlgNT+a1S4u+gxvZjkgHajzfJBHiFmkCI5dG6CBFKA== X-Received: by 2002:a1c:2ec4:: with SMTP id u187mr21036wmu.29.1552428975212; Tue, 12 Mar 2019 15:16:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJUuGEgCd3OwWkPR9tjboT6/bCie+1nI26aMTrNZMQAgl30PhYvMc8cslMxjk0bUYvMN9B X-Received: by 2002:a1c:2ec4:: with SMTP id u187mr21008wmu.29.1552428973966; Tue, 12 Mar 2019 15:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428973; cv=none; d=google.com; s=arc-20160816; b=OVxatd40q8aGQ+Qz8cVZKALMO/kfPLU/Q13c2SmudrBWIQDoTNWclrmNTAEGn9+eQW CXDvY0CgGrNzOCWuAhtYl+TtQqQtrRG0ZceCKpEAbtJ8AMfuf4PnbolDlXIszdq7nUHJ 17ja6i+wyR8uYuY+2Ibq93J/7bXnxIFGWionk2dd09DV8zOA7O5Ks/YbcRzVsIYRrpVx CrOsovAWDKuhwNnoN5BVGTmayKeakv2eQOKPOVYRN0SutDKuuFPBLUd/K186zY9AgTxq YSOp4EyRChR0qD7SBVkxQjAVhw5fKoUEsVMj1DU44kXAKUsglFLeQQ6ZIatNtijc5mpU Vdpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=FcoH0MWZdtOBuC7W/yk0A9+bmiNTMQTCcIimrSkyq24=; b=NzsbGrX1FD3fHR84nWyQZiGQ7D+NnN2eTx57pd2W3VrcuQAgpWY5sjBsmPmtnT3Llf ar6xygmTXoYSsAXg+CJeDloAevLMWQe8XyEG0gZWZr6zNh1eyXrKD5ZOkov5N5mHjQWo JGviXLi29bXsaj5xhnZyfy6lIbM79ir47buO3QK2oeh6qvn4Goa3u0XfYtsCU4FEaSbP x09xyLKSakEQWC0ofALBC2s00haqphYI6YoJsrGLbvrKUn0HD2BeYrauL1nlsxo/76S4 DpZCy+2+ZF+S0QcLhn2jTkQ6Xp7NHcmrlujdAufsFLICK/ABVK4LrIDpxacJ+0kKiVsD is5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Dh61WMl2; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id p4si1195747wrm.281.2019.03.12.15.16.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Dh61WMl2; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7K1HxzzB09Zq; Tue, 12 Mar 2019 23:16:13 +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=Dh61WMl2; 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 UY3xorVjAvzJ; Tue, 12 Mar 2019 23:16:13 +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 44Jq7K07TzzB09ZG; Tue, 12 Mar 2019 23:16:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428973; bh=FcoH0MWZdtOBuC7W/yk0A9+bmiNTMQTCcIimrSkyq24=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=Dh61WMl2c67y4cwzG934jpk3Yi5ydkkHhikzBl19vVw9LvJW150+Qrw97nzbVCUyY LF7L/zcaBD/9YMdOwyriO/GYYmJOJqerdqn/ZuIIeU/ZeLOhoUQ2z+6vAQ9Hz+7WEC TbZkOU42NMRm5fnmzgt+d3m57eKQmPgo0ndWnKIM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 38FF48B8B1; Tue, 12 Mar 2019 23:16:13 +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 9lw61lSVAl-n; Tue, 12 Mar 2019 23:16:13 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0C92B8B8A7; Tue, 12 Mar 2019 23:16:13 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id D178E6FA15; Tue, 12 Mar 2019 22:16:12 +0000 (UTC) Message-Id: <96efc03aff3ce13f22cb7da0adb6267b9dbaa2c3.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 07/18] powerpc/32: use memset() instead of memset_io() to zero BSS To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:12 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Since commit 400c47d81ca38 ("powerpc32: memset: only use dcbz once cache is enabled"), memset() can be used before activation of the cache, so no need to use memset_io() for zeroing the BSS. Acked-by: Dmitry Vyukov Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/early_32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c index cf3cdd81dc47..3482118ffe76 100644 --- a/arch/powerpc/kernel/early_32.c +++ b/arch/powerpc/kernel/early_32.c @@ -21,8 +21,8 @@ notrace unsigned long __init early_init(unsigned long dt_ptr) { unsigned long offset = reloc_offset(); - /* First zero the BSS -- use memset_io, some platforms don't have caches on yet */ - memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); + /* First zero the BSS */ + memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); /* * Identify the CPU type and fix up code sections From patchwork Tue Mar 12 22:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78D291575 for ; Tue, 12 Mar 2019 22:16:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DB129315 for ; Tue, 12 Mar 2019 22:16:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58EB7296F9; Tue, 12 Mar 2019 22:16:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD61229315 for ; Tue, 12 Mar 2019 22:16:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F9C18E000B; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 181B08E000C; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F41098E000B; Tue, 12 Mar 2019 18:16:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 8EE268E0008 for ; Tue, 12 Mar 2019 18:16:17 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id n15so1617168wrr.2 for ; Tue, 12 Mar 2019 15:16:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=T5roomQKloe+Cr1IT+Xg0/TzN2EQ/rbW1mXIN5nYL+c=; b=qftxIRS2sXPtUc8RllSiVhFeKOVSdrNhU7qz1nf0Bb2QFvqTrA2fRJUTXu+bOepi/q K9RaPaOtbmbD4CBeWGDwwcEtxg745TQgh7B5J+iMZsgBsib+/+BVkH3bfjoKDnISq5aY NVBWwNWKN1PP84KBjPqXgrr/Q1ZkMUjCmNMtn3s90I0tJ/553nqaTqJzRVb9DOPB39u1 LruFFYFS8jkvnlXD/CLCFvL7PRrm8aPK/6lYkI3lKwAx0Li+Hm9JWeQL0r7dv97DnPSK ZveWNoeQoF2Ze1HvqTIaNCL/U3L1tZRu1T2ULQ57cUVLkk7g4CrtUAnukM+4eeWSE1yO 0AUA== X-Gm-Message-State: APjAAAW+ee2cj3bMA5ELQ7LYN87K68yF9aewp0/Ve8jIXyCfs90z9zaJ DpB1BKFwzABxOMz/5OUG//nyK4Cy3iisckeGBQkX+gMMSLar4GCE8KNG+eSvAgTq65LN6tG9hgH DbzZbGAJev/ZedG9kcxJZ1UCZj3u2eFz5IwAn4mk93WEEOcDmBXh2KtPYNgDv2hsetw== X-Received: by 2002:adf:ecca:: with SMTP id s10mr4744808wro.138.1552428976797; Tue, 12 Mar 2019 15:16:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwByTm386H9vY0vxl4COpm9zrIM/G9lJx+a91hsg0OKfgh4VGtesD2VhxqPPxhfDvigprOd X-Received: by 2002:adf:ecca:: with SMTP id s10mr4744748wro.138.1552428975098; Tue, 12 Mar 2019 15:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428975; cv=none; d=google.com; s=arc-20160816; b=cXCaPLsQ9ZU6COsdB9mWh5iZc/bX6/paranmtKh5RTqenLLBZtqhvNF4YqtMvOFLYQ +1SN6QoXLMYRtHTLu/tScpayh7QRmcm7d3ZLYX9Tz+eAnenT1giGzzy959qQEHNkt+7+ qm9inyZtpqslkSiDR7ouP6EQLShfEPQ9kt5cB/zgHMqyyDciZI1LGVXTy0CE0XMDicxr Bd2H//1Grcu1UQ/uLbhWVaT1Ere2vn5iAo2vZkVlrt2o2W1pcRWQTHkUI0p7/x0qvBqP mD0iKkQZi7tlTmXQQGJa8EirZnhWMbecejJUVF0jZieA6lTA57uT04zPNm4wmc96zchA wi4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=T5roomQKloe+Cr1IT+Xg0/TzN2EQ/rbW1mXIN5nYL+c=; b=uxLbzpWkqA3tR5hO08CXpJJJPn1bvUZvZWexXk6B81jUdhdjt8qwniSoWszj1SeHCb mzddii9U7YEp4rkDgqJE0iQMsdB1pkEG466hmW2H5PLpms8fQ/L2Uamw+XYLEzMx8TIJ 5gpuMBwCMGbzZhGtb1DodBhV2dNtEQjNvoXdO83n2KiuADwOZroNdUOLbv/WikzWNV9u UU+jqGy8/B8ARgnfx4ztvoLBiPSDnC7LRsw0m1A772e6WKo+IZbarQtdSl5dxW36oLX0 zc/TNI1j5nuRT7+aaigaodDmMDFpxLMktnW4oGVL8aA7wXcKsrLUTVkFGDHy57tLkalF e6RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ukLy0Za9; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id v62si8551wma.181.2019.03.12.15.16.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:15 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ukLy0Za9; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7L3FNPzB09Zr; Tue, 12 Mar 2019 23:16:14 +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=ukLy0Za9; 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 NpOVPJM2k5EE; Tue, 12 Mar 2019 23:16:14 +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 44Jq7L1t58zB09ZG; Tue, 12 Mar 2019 23:16:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428974; bh=T5roomQKloe+Cr1IT+Xg0/TzN2EQ/rbW1mXIN5nYL+c=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ukLy0Za9/10Y50KeWbhKydgkJlcMYhErBoRYvRsfPVuX8rSO6AVpAdsfVE4jOuIi4 fxh/RCV5Ue/ZYpKNg6W57QN2M9NkZ5wT+6ZIMAwhoapHqrA2qN8FA4yY014heZapOp jgM36KvCrY8IRR3k9ZEWbMsySbINf4sVELLVsmqM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 762368B8B1; Tue, 12 Mar 2019 23:16:14 +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 uIH54hV_LXXN; Tue, 12 Mar 2019 23:16:14 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2AD288B8A7; Tue, 12 Mar 2019 23:16:14 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id D31F86FA15; Tue, 12 Mar 2019 22:16:13 +0000 (UTC) Message-Id: <43d22280ffb24112df6393b912c7f8b9e5962611.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 08/18] powerpc/32: make KVIRT_TOP dependent on FIXMAP_START To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:13 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When we add KASAN shadow area, KVIRT_TOP can't be anymore fixed at 0xfe000000. This patch uses FIXADDR_START to define KVIRT_TOP. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/book3s/32/pgtable.h | 13 ++++++++++--- arch/powerpc/include/asm/nohash/32/pgtable.h | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h index aa8406b8f7ba..838de59f6754 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -134,15 +134,24 @@ static inline bool pte_user(pte_t pte) #define PGDIR_MASK (~(PGDIR_SIZE-1)) #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) + +#ifndef __ASSEMBLY__ + +int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); + +#endif /* !__ASSEMBLY__ */ + /* * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary * value (for now) on others, from where we can start layout kernel * virtual space that goes below PKMAP and FIXMAP */ +#include + #ifdef CONFIG_HIGHMEM #define KVIRT_TOP PKMAP_BASE #else -#define KVIRT_TOP (0xfe000000UL) /* for now, could be FIXMAP_BASE ? */ +#define KVIRT_TOP FIXADDR_START #endif /* @@ -373,8 +382,6 @@ static inline void __ptep_set_access_flags(struct vm_area_struct *vma, #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 }) #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 }) -int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); - /* Generic accessors to PTE bits */ static inline int pte_write(pte_t pte) { return !!(pte_val(pte) & _PAGE_RW);} static inline int pte_read(pte_t pte) { return 1; } diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h index bed433358260..0284f8f5305f 100644 --- a/arch/powerpc/include/asm/nohash/32/pgtable.h +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h @@ -64,15 +64,24 @@ extern int icache_44x_need_flush; #define pgd_ERROR(e) \ pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) +#ifndef __ASSEMBLY__ + +int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); + +#endif /* !__ASSEMBLY__ */ + + /* * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary * value (for now) on others, from where we can start layout kernel * virtual space that goes below PKMAP and FIXMAP */ +#include + #ifdef CONFIG_HIGHMEM #define KVIRT_TOP PKMAP_BASE #else -#define KVIRT_TOP (0xfe000000UL) /* for now, could be FIXMAP_BASE ? */ +#define KVIRT_TOP FIXADDR_START #endif /* @@ -379,8 +388,6 @@ static inline int pte_young(pte_t pte) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 }) #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 }) -int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot); - #endif /* !__ASSEMBLY__ */ #endif /* __ASM_POWERPC_NOHASH_32_PGTABLE_H */ From patchwork Tue Mar 12 22:16:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 444B01515 for ; Tue, 12 Mar 2019 22:16:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F29029315 for ; Tue, 12 Mar 2019 22:16:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21C72296F9; Tue, 12 Mar 2019 22:16:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97EF129315 for ; Tue, 12 Mar 2019 22:16:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AD638E000C; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 80D6A8E0008; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6883A8E000C; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 0DCBF8E0008 for ; Tue, 12 Mar 2019 18:16:18 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id a5so1615260wrq.3 for ; Tue, 12 Mar 2019 15:16:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=mIGQaprlAVCVWpPiH4xPJkXAyE92iR9cx2tnTNWnRqU=; b=HMSPZ1xmlljfhDhsGxSVbQjugBIiRDHtjmQTSsBcIbxLN5/hEQSbiUUlupF6ujEsz4 haeojwyRgwNEfMoWQj6cSTesZ5NCkT85dFMnAuwwLANeFa0VsD0/qbGlyRwXaNIbpWu9 FBVYwMy7TusiUOXKRf6Zvbgctne/2qwhGgbpGnOdne5aQHPZCwnQ/vRu3anxjbdJOmFX OJ8NYDEBRUYRR1fF0Ifi4yNOKaww3n1yMFkYoJDl4b+4RGsf4ZLsWeFaOBV5SL4NBT50 QxSxGq04Qm06yx6Lrh27QpTsTK6qlEKgFUTEXrOtyIL6aecQiCkBNMhJltwdCA5jAoIv R6OQ== X-Gm-Message-State: APjAAAXTTIw3EvwU0p/VHHEBmVg3LRxX1gLLO2ZyYmP4jw6LyL3orzcp AE6YivAD6ULM5OyPoHIhSZDyS8Yh4wV3V8B/lighe7mmV0F7zHmkftJc2PfFkSqRz+y8m6MYnM5 YxDxkgR5ndbFPx4FgMTqkFUDu4eM132S5o9/0TL+CDWDmEPF15XSb1kmDeLUUyGcuOw== X-Received: by 2002:a1c:96ce:: with SMTP id y197mr30503wmd.126.1552428977268; Tue, 12 Mar 2019 15:16:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhhVEI9HaE4BJWiLTTn016XGRpncBxIwWYOLAqsPDex2cSx0DQ+bewh3VIYspYVmaSDB1s X-Received: by 2002:a1c:96ce:: with SMTP id y197mr30464wmd.126.1552428976021; Tue, 12 Mar 2019 15:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428976; cv=none; d=google.com; s=arc-20160816; b=kQyHwr2SQLr37yYeCrs7gfAzFb07JY0cATBbhd+mTsqM8x6Pl31xRyaUgug8jMMHeq Imspfey9em62xWnRBVeFhSS/k4VoxBVxQ4r9fk/i8G/WrCv4N2ZsbjAm9/e+H/G/3rHo /OWvT3RgNQJ+eslW/j1WEEVV3oxTc5edxLrNJiNN8JEsj+OWjoY4GG6LsiRI9Tzh8iVg ynSv+SL0TgKhUXDqJwo/Y7RlUCIp1L8K1oh6VoeLufjZbl+T5aR8P+0olr+hmOi7GMrJ /eiCSkmFbNjjsF9VdaSW6GrnadOPZumxxtGtkJ7B99ou/8WxbGB0Mc3Xl0VKjkARTU2D pbmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=mIGQaprlAVCVWpPiH4xPJkXAyE92iR9cx2tnTNWnRqU=; b=GQbcqXkZw48D/794xiSSgCJvKYoxBrX3yPAdNsHGv+XAACJufDmG4O3D9GjGz0fkXv 9JmsEeeGpCFGiPYzyIPS3mLEqkDwqk4tqJaOseHEsrBPYEdreToK7i6HlcE2/rCAtxsr F+a/FPJWpBYUNc35CpirxfVRUlB9cH8mVHpuAnNJ4tu2XZvn9pdOnJPON8EVGGxGhuH+ IHMzJvRJKo6acVx3NT//NgpAtkyt5oYKKuwErNSMW6y/xvlAcCssEeIw3RZhk77n0srj g5Cfol7nPx0+kvtJMiwWkX5fzM/d2FxW9Qf1PeWMwp1m/kPeROOhBQ/fGZLkTtgJwFi8 Gn3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=fQXoenqm; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id p21si7427wmh.194.2019.03.12.15.16.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:16 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=fQXoenqm; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7M26gczB09Zt; Tue, 12 Mar 2019 23:16:15 +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=fQXoenqm; 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 EGUj0-8sqf2W; Tue, 12 Mar 2019 23:16:15 +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 44Jq7M0xDPzB09ZG; Tue, 12 Mar 2019 23:16:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428975; bh=mIGQaprlAVCVWpPiH4xPJkXAyE92iR9cx2tnTNWnRqU=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=fQXoenqm0P/pOBebO8hAN+jBJviFvKS7NXJNClJzbO3yPlr+BfXpE8olkWTXIqIWQ JN4rPm6po/CtsDbWm5giWD1Hx5PvyEod2zciYPIVeO/nz0+M9vTpVKFX7HC4z29YHC e+lOdfyIVMx63wfeVNhLjHiwFYAKkEecDGoICk24= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 571DD8B8B1; Tue, 12 Mar 2019 23:16:15 +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 aG88fi4S6WiR; Tue, 12 Mar 2019 23:16:15 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1A8BC8B8A7; Tue, 12 Mar 2019 23:16:15 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id D9B0D6FA15; Tue, 12 Mar 2019 22:16:14 +0000 (UTC) Message-Id: <9ddd549404655be32ea511fc055f50bc168bb30d.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 09/18] powerpc/32: prepare shadow area for KASAN To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:14 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch prepares a shadow area for KASAN. The shadow area will be at the top of the kernel virtual memory space above the fixmap area and will occupy one eighth of the total kernel virtual memory space. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig.debug | 5 +++++ arch/powerpc/include/asm/fixmap.h | 5 +++++ arch/powerpc/include/asm/kasan.h | 16 ++++++++++++++++ arch/powerpc/mm/mem.c | 4 ++++ arch/powerpc/mm/ptdump/ptdump.c | 8 ++++++++ 5 files changed, 38 insertions(+) diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 4e00cb0a5464..61febbbdd02b 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -366,3 +366,8 @@ config PPC_FAST_ENDIAN_SWITCH depends on DEBUG_KERNEL && PPC_BOOK3S_64 help If you're unsure what this is, say N. + +config KASAN_SHADOW_OFFSET + hex + depends on KASAN + default 0xe0000000 diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h index b9fbed84ddca..0cfc365d814b 100644 --- a/arch/powerpc/include/asm/fixmap.h +++ b/arch/powerpc/include/asm/fixmap.h @@ -22,7 +22,12 @@ #include #endif +#ifdef CONFIG_KASAN +#include +#define FIXADDR_TOP (KASAN_SHADOW_START - PAGE_SIZE) +#else #define FIXADDR_TOP ((unsigned long)(-PAGE_SIZE)) +#endif /* * Here we define all the compile-time 'special' virtual diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 2c179a39d4ba..05274dea3109 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -12,4 +12,20 @@ #define EXPORT_SYMBOL_KASAN(fn) #endif +#ifndef __ASSEMBLY__ + +#include + +#define KASAN_SHADOW_SCALE_SHIFT 3 + +#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ + (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT)) + +#define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) + +#define KASAN_SHADOW_END 0UL + +#define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) + +#endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index f6787f90e158..4e7fa4eb2dd3 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -309,6 +309,10 @@ void __init mem_init(void) mem_init_print_info(NULL); #ifdef CONFIG_PPC32 pr_info("Kernel virtual memory layout:\n"); +#ifdef CONFIG_KASAN + pr_info(" * 0x%08lx..0x%08lx : kasan shadow mem\n", + KASAN_SHADOW_START, KASAN_SHADOW_END); +#endif pr_info(" * 0x%08lx..0x%08lx : fixmap\n", FIXADDR_START, FIXADDR_TOP); #ifdef CONFIG_HIGHMEM pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n", diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c index 37138428ab55..812ed680024f 100644 --- a/arch/powerpc/mm/ptdump/ptdump.c +++ b/arch/powerpc/mm/ptdump/ptdump.c @@ -101,6 +101,10 @@ static struct addr_marker address_markers[] = { { 0, "Fixmap start" }, { 0, "Fixmap end" }, #endif +#ifdef CONFIG_KASAN + { 0, "kasan shadow mem start" }, + { 0, "kasan shadow mem end" }, +#endif { -1, NULL }, }; @@ -322,6 +326,10 @@ static void populate_markers(void) #endif address_markers[i++].start_address = FIXADDR_START; address_markers[i++].start_address = FIXADDR_TOP; +#ifdef CONFIG_KASAN + address_markers[i++].start_address = KASAN_SHADOW_START; + address_markers[i++].start_address = KASAN_SHADOW_END; +#endif #endif /* CONFIG_PPC64 */ } From patchwork Tue Mar 12 22:16:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 704631575 for ; Tue, 12 Mar 2019 22:16:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CCF629315 for ; Tue, 12 Mar 2019 22:16:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50F08296F9; Tue, 12 Mar 2019 22:16:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC28929315 for ; Tue, 12 Mar 2019 22:16:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF6648E000D; Tue, 12 Mar 2019 18:16:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA82D8E0008; Tue, 12 Mar 2019 18:16:19 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 947118E000D; Tue, 12 Mar 2019 18:16:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 370018E0008 for ; Tue, 12 Mar 2019 18:16:19 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id l1so1604659wrn.13 for ; Tue, 12 Mar 2019 15:16:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=11bHr9IKG31q/XWzTWTlzmha5VK7c1KEPDFWV7Md6Q0=; b=nq3PWj8mdak4U4C/Q/jkf2E85UKHzCLzuCu1i1PO44Qdg5+Oxz8AbV5Q9wMt+2jShg Uot8Kaq1ljaIfpRuSVIbcSk0YPNIv0rvybuvVk79X9wjN7QJULjCjfafUG1ebj61xVw7 cxEe8ZeH7ePzfSKDwJsEAJiZaRn+FrO4M/gOSlGE8hjsNp0HkPlHaQFWKrMDDAKkF5WV zIimkt7akir1oU3s5JPPTMF3D8eKsg5vZNHafbIm1PLKpvFdVtQrcmwV6FaoxJyj6WMP jdo6LW+V4jmwvHAYtSPqa2A9egAW8GwV63O2QHm6EwsoX6z2B1ehfDYA1zlawz3HYnNt P0Iw== X-Gm-Message-State: APjAAAUkWgEZORF0ZxtSMbG7zUy39UcsXf9BG2lVxe2wQjwZIai4s8+a GV+KQIL+5Uw+QEO/3GN9DX/ypwgsklPC4uFD6q0Fncg9tIhqA7Nj3FTuxuLXo4xU89wJaU8PrsW 1KIwa9kBnfElYfXWivJ8GOedPYoK+dYgDJbgkGeCCUJlPUJEL0YZ/DiMThqhp2sOTSg== X-Received: by 2002:a7b:c932:: with SMTP id h18mr39098wml.12.1552428978446; Tue, 12 Mar 2019 15:16:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMtGNAA2xcciwT7MAA7tUIp05UHH7WuVdtfaJrjQ0N+gu+0vJeITqVMC+PY4FIKBM6qlz6 X-Received: by 2002:a7b:c932:: with SMTP id h18mr39062wml.12.1552428977056; Tue, 12 Mar 2019 15:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428977; cv=none; d=google.com; s=arc-20160816; b=kfoyvDTXvKJhA3yMmcMDOTPsC7IN24cv3gRvCs1Vy19njS1PeUw4vcHDbxpez1ClcC y0H/WdqZo5FMReGyr6Ws+sSlxGphx4imrl2zVawtJ11i6pRBShStL6fiKhfrL/ZcfWmg 3zFuhrX44BJ+QkeFuYsBEADP4nRuHS3JjD8LkiTH9242ejxsPUIdkXkQU5b/2DO5uSeg u5wBVnq7kx3jpFzXDmrAb98QgJh8mEsUYwnoS2EKz8bkPIGYgBKgy2HQgqFx1E/rEj4j 59hR01XtwD4gfqqMz4sgFkHpggrPbLRMLAAb1mQ1cCUFBxKhe0V45LQkB8rMv1QRr46y nLfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=11bHr9IKG31q/XWzTWTlzmha5VK7c1KEPDFWV7Md6Q0=; b=Qb6d7wRilBoWFNjOOetPx9wkWOyDESWKzQT+6Q/WWFOYU3s4l3cWacIE9Rg3Ht/Wup iSIfAzZloALrNLQUIxgOb7yFxSb6GQOr3IIT9KvfBx0PIrPzMKiYOlcO/vnzhZ1vKBPy tFyb6S72x1Y5MJ2J+MLsR8MmauEHFgHdy63PnruhmDHjmFJKhoC+HRODuILyl2TUA2SH m7HDyBzu+Wu6Evt4AyPaLx9w5/xqOviGNjdOTmaLbF8xKquamJpd9iAH5ZUFwOftIDdF qc3tfV1sSHzrarBaDOujxYddtDpmrKxqokmPaCGmfSrP0xWA6m3t2JwMomWpNsd4PMYn 4JCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ShTvJkas; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id x6si6202622wrm.149.2019.03.12.15.16.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ShTvJkas; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7N37jnzB09Zw; Tue, 12 Mar 2019 23:16:16 +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=ShTvJkas; 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 nO-H_kZuUfG0; Tue, 12 Mar 2019 23:16:16 +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 44Jq7N21M6zB09ZG; Tue, 12 Mar 2019 23:16:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428976; bh=11bHr9IKG31q/XWzTWTlzmha5VK7c1KEPDFWV7Md6Q0=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ShTvJkas3sbdAPGOOgR4IJbXIwO0eALyh2u7kydGhCHX6K+1JC/cF7QNbOqO9nRZY qbCdhiuDrUQIvYQEqUZJnqPbwTIPvi8SGtSK1j1zIqIVpcco6RUINZH/YV9/wMHbXx jhJHu9vNHojN5sr1tQN8Ej48rg6bkaui//mP/364= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7CBA28B8B1; Tue, 12 Mar 2019 23:16:16 +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 V9B0UOowRjR1; Tue, 12 Mar 2019 23:16:16 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 41F1B8B8A7; Tue, 12 Mar 2019 23:16:16 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E0BA96FA15; Tue, 12 Mar 2019 22:16:15 +0000 (UTC) Message-Id: <759c1323282930614b105d72b3ae459398125478.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 10/18] powerpc: disable KASAN instrumentation on early/critical files. To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:15 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP All files containing functions run before kasan_early_init() is called must have KASAN instrumentation disabled. For those file, branch profiling also have to be disabled otherwise each if () generates a call to ftrace_likely_update(). Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/Makefile | 12 ++++++++++++ arch/powerpc/lib/Makefile | 8 ++++++++ arch/powerpc/mm/Makefile | 6 ++++++ arch/powerpc/platforms/powermac/Makefile | 6 ++++++ arch/powerpc/purgatory/Makefile | 3 +++ arch/powerpc/xmon/Makefile | 1 + 6 files changed, 36 insertions(+) diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 45e47752b692..0ea6c4aa3a20 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -31,6 +31,18 @@ CFLAGS_REMOVE_btext.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_prom.o = $(CC_FLAGS_FTRACE) endif +KASAN_SANITIZE_early_32.o := n +KASAN_SANITIZE_cputable.o := n +KASAN_SANITIZE_prom_init.o := n +KASAN_SANITIZE_btext.o := n + +ifdef CONFIG_KASAN +CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_cputable.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING +endif + obj-y := cputable.o ptrace.o syscalls.o \ irq.o align.o signal_32.o pmc.o vdso.o \ process.o systbl.o idle.o \ diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index 47a4de434c22..c55f9c27bf79 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile @@ -8,6 +8,14 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) CFLAGS_REMOVE_code-patching.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_feature-fixups.o = $(CC_FLAGS_FTRACE) +KASAN_SANITIZE_code-patching.o := n +KASAN_SANITIZE_feature-fixups.o := n + +ifdef CONFIG_KASAN +CFLAGS_code-patching.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_feature-fixups.o += -DDISABLE_BRANCH_PROFILING +endif + obj-y += alloc.o code-patching.o feature-fixups.o ifndef CONFIG_KASAN diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index d52ec118e09d..240d73dce6bb 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -7,6 +7,12 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE) +KASAN_SANITIZE_ppc_mmu_32.o := n + +ifdef CONFIG_KASAN +CFLAGS_ppc_mmu_32.o += -DDISABLE_BRANCH_PROFILING +endif + obj-y := fault.o mem.o pgtable.o mmap.o \ init_$(BITS).o pgtable_$(BITS).o \ init-common.o mmu_context.o drmem.o diff --git a/arch/powerpc/platforms/powermac/Makefile b/arch/powerpc/platforms/powermac/Makefile index 20ebf35d7913..f4247ade71ca 100644 --- a/arch/powerpc/platforms/powermac/Makefile +++ b/arch/powerpc/platforms/powermac/Makefile @@ -2,6 +2,12 @@ CFLAGS_bootx_init.o += -fPIC CFLAGS_bootx_init.o += $(call cc-option, -fno-stack-protector) +KASAN_SANITIZE_bootx_init.o := n + +ifdef CONFIG_KASAN +CFLAGS_bootx_init.o += -DDISABLE_BRANCH_PROFILING +endif + ifdef CONFIG_FUNCTION_TRACER # Do not trace early boot code CFLAGS_REMOVE_bootx_init.o = $(CC_FLAGS_FTRACE) diff --git a/arch/powerpc/purgatory/Makefile b/arch/powerpc/purgatory/Makefile index 4314ba5baf43..7c6d8b14f440 100644 --- a/arch/powerpc/purgatory/Makefile +++ b/arch/powerpc/purgatory/Makefile @@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +KASAN_SANITIZE := n + targets += trampoline.o purgatory.ro kexec-purgatory.c LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile index 3050f9323254..f142570ad860 100644 --- a/arch/powerpc/xmon/Makefile +++ b/arch/powerpc/xmon/Makefile @@ -7,6 +7,7 @@ subdir-ccflags-y := $(call cc-disable-warning, builtin-requires-header) GCOV_PROFILE := n KCOV_INSTRUMENT := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n # Disable ftrace for the entire directory ORIG_CFLAGS := $(KBUILD_CFLAGS) From patchwork Tue Mar 12 22:16:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 333A71575 for ; Tue, 12 Mar 2019 22:16:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DD5229315 for ; Tue, 12 Mar 2019 22:16:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11DA5296F9; Tue, 12 Mar 2019 22:16:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26D6429315 for ; Tue, 12 Mar 2019 22:16:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 666D78E0010; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 54D468E0008; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F0218E000F; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id D747F8E000E for ; Tue, 12 Mar 2019 18:16:20 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id 92so1604127wrb.6 for ; Tue, 12 Mar 2019 15:16:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=7elSQE3ASFtmFBbQ1baRFPz6iwmnjLE3NV7GCI8qFKM=; b=UXvlW18Nq1fgUNDnh2gYEcbXMKSyqP+tvpaBPAgB06JdyvU3yCo7EgMmZXAn2x2sC+ a2tcdz/kWD+/kSZC0kVxDzQH+y/zALLfLJuGqxLwrlZHOpLb6eQcN/venftaeQebn5tN p3gce4YxDHMoM1YVDII41Iml7bCb+QEDogxAORqoD9QTfMgudhd43Ja6KiRVqGyCWmkK PnNSt2978CDmThUB4G/p61FE9oupE5vFxe9Erk7qzULmkO2QpkNGRazHMLrxAVvzZf8L 1Fwja0329KszuajriAVAhoDWdAJGGzrPmQARqDah2SNL6hjj75JNQgKr2gb/kf6NBjH7 9nxg== X-Gm-Message-State: APjAAAUFsx/j+AKWWELgk4YBnqYXW20AXuilNC8Z+KytoOuiGQqNmHi6 n7MB3beIKzY16ifetpN8cz+vsl+1bsIYHz8W2pUj+ZzqYnS0qbCjueNNQoNT/WxTTrdUSimOHbG E0nJ1Ddy+4PtQIyx9IEcKNOiETx9wfYJJ3zOm47EX7wiw0dlyUkX208p77o0ZP02GFg== X-Received: by 2002:a5d:620f:: with SMTP id y15mr23987226wru.101.1552428980116; Tue, 12 Mar 2019 15:16:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxtDLJnD6lNetxXqJyIDGTU30FvoVfnACvg6QFSXe+NnqoPzfgHMLELJwahPJHOVwcAUDMW X-Received: by 2002:a5d:620f:: with SMTP id y15mr23987170wru.101.1552428978118; Tue, 12 Mar 2019 15:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428978; cv=none; d=google.com; s=arc-20160816; b=IvH6gLXC6EPlcGzeb5iNKEAxPiSPXEsnEstITPlwT/r7nff02Drur6PZS2FMTMy45V uVETxmoYZB0ZZG5lG0zuwsAHLYL+Nx7xqBPvhxdZtzd6SEhirwk0AAQRRpjogzoYZuHD ksg1FlOSKpRmDPiz6kzRducIlbTVu3NVZXRoqrylLh7vhkS3NtgIRNp5dAT4Hlv/rpb+ sbEYaEZOc5JeodXOip6G+KXrea4wIRheYZu1TZzNLCILW0WG9mLTNUVIeUaL/VoLaq7m QubDraulb4u5Ylwb/1i5NsT6SPhMzEcrmqOT6Mqt94ITecR7yUHWrcWzmiK+2nvAxz6s /s7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=7elSQE3ASFtmFBbQ1baRFPz6iwmnjLE3NV7GCI8qFKM=; b=AlcZpE9oOuHkUSvxzoHZQoWevtOVYOwOwZ+GcqOQqxgIvycX0MaBAIUKzST7TMd4M2 bUdpNRCSy56Dhk0N5+K+IJ3USNY6TVYKEleUKaMIT3yub02DnzI6jUVaE1qP4UUqPxKf geCaXPJZMpacFOHsCW6PEhabT7YSUHBjdR9ZTyCnrSXvOwgOci2LpmTOlXYbVovBmjkJ WsbQ8yGr1bRf4a3CdKQ2lulSjCJvN0J+nPQ2J4mUzWVwxw6EniX2EWJU9YyXT99gCe2w CGb549juZQHGAj1nKKCDc42blP/ZYopd1ts13mzBQFd/2s+hLK6IYumQlZA4dw2ANydK OUhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=r8QdH1Yn; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id t14si452wmj.42.2019.03.12.15.16.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=r8QdH1Yn; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7P3Zyvz9vRb0; Tue, 12 Mar 2019 23:16:17 +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=r8QdH1Yn; 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 p7dWFWhAvf_h; Tue, 12 Mar 2019 23:16:17 +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 44Jq7P2Pd7zB09ZG; Tue, 12 Mar 2019 23:16:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428977; bh=7elSQE3ASFtmFBbQ1baRFPz6iwmnjLE3NV7GCI8qFKM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=r8QdH1YnRJRmEclIjneD3mLM+a+NgAxLSa+QIcxrhhjWhEhJYaWv4G5pagiNMWnUs 2x2tAysmQZRb6Z8GBr78ARZ91iMYDQ3kO8Jwbx0rnFJrF4C2iPWtEhHw9IM7G8Ldt3 sarWOsQ0WQmag1AIo6mlS1Y6o743NgdT0rJZ7Hak= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 83D6F8B8B1; Tue, 12 Mar 2019 23:16:17 +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 D_VLXvzfkmS2; Tue, 12 Mar 2019 23:16:17 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 291848B8A7; Tue, 12 Mar 2019 23:16:17 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E64366FA15; Tue, 12 Mar 2019 22:16:16 +0000 (UTC) Message-Id: <7600ccac6eca9289244b7d1172a9525ef67b4822.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 11/18] powerpc/32: Add KASAN support To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch adds KASAN support for PPC32. The following patch will add an early activation of hash table for book3s. Until then, a warning will be raised if trying to use KASAN on an hash 6xx. To support KASAN, this patch initialises that MMU mapings for accessing to the KASAN shadow area defined in a previous patch. An early mapping is set as soon as the kernel code has been relocated at its definitive place. Then the definitive mapping is set once paging is initialised. For modules, the shadow area is allocated at module_alloc(). Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/kasan.h | 9 ++ arch/powerpc/kernel/head_32.S | 3 + arch/powerpc/kernel/head_40x.S | 3 + arch/powerpc/kernel/head_44x.S | 3 + arch/powerpc/kernel/head_8xx.S | 3 + arch/powerpc/kernel/head_fsl_booke.S | 3 + arch/powerpc/kernel/setup-common.c | 3 + arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/init_32.c | 3 + arch/powerpc/mm/kasan/Makefile | 5 ++ arch/powerpc/mm/kasan/kasan_init_32.c | 156 ++++++++++++++++++++++++++++++++++ 12 files changed, 193 insertions(+) create mode 100644 arch/powerpc/mm/kasan/Makefile create mode 100644 arch/powerpc/mm/kasan/kasan_init_32.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index facaa6ba0d2a..d9364368329b 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -173,6 +173,7 @@ config PPC select GENERIC_TIME_VSYSCALL select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_KASAN if PPC32 select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 05274dea3109..296e51c2f066 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -27,5 +27,14 @@ #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#ifdef CONFIG_KASAN +void kasan_early_init(void); +void kasan_mmu_init(void); +void kasan_init(void); +#else +static inline void kasan_init(void) { } +static inline void kasan_mmu_init(void) { } +#endif + #endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 48051c8977c5..3ee42c0ada69 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -958,6 +958,9 @@ start_here: * Do early platform-specific initialization, * and set up the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S index a9c934f2319b..efa219d2136e 100644 --- a/arch/powerpc/kernel/head_40x.S +++ b/arch/powerpc/kernel/head_40x.S @@ -848,6 +848,9 @@ start_here: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S index 37117ab11584..34a5df827b38 100644 --- a/arch/powerpc/kernel/head_44x.S +++ b/arch/powerpc/kernel/head_44x.S @@ -203,6 +203,9 @@ _ENTRY(_start); /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S index 03c73b4c6435..d25adb6ef235 100644 --- a/arch/powerpc/kernel/head_8xx.S +++ b/arch/powerpc/kernel/head_8xx.S @@ -853,6 +853,9 @@ start_here: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index 1881127682e9..0fc38eb957b7 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -275,6 +275,9 @@ set_ivor: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif mr r3,r30 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index e7534f306c8e..3c6c5a43901e 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -67,6 +67,7 @@ #include #include #include +#include #include "setup.h" @@ -865,6 +866,8 @@ static void smp_setup_pacas(void) */ void __init setup_arch(char **cmdline_p) { + kasan_init(); + *cmdline_p = boot_command_line; /* Set a half-reasonable default so udelay does something sensible */ diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index 240d73dce6bb..80382a2d169b 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -53,6 +53,7 @@ obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o obj-$(CONFIG_PPC_PTDUMP) += ptdump/ obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o +obj-$(CONFIG_KASAN) += kasan/ # Disable kcov instrumentation on sensitive code # This is necessary for booting with kcov enabled on book3e machines diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c index 41a3513cadc9..0217d1b405f7 100644 --- a/arch/powerpc/mm/init_32.c +++ b/arch/powerpc/mm/init_32.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "mmu_decl.h" @@ -178,6 +179,8 @@ void __init MMU_init(void) btext_unmap(); #endif + kasan_mmu_init(); + /* Shortly after that, the entire linear mapping will be available */ memblock_set_current_limit(lowmem_end_addr); } diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile new file mode 100644 index 000000000000..6577897673dd --- /dev/null +++ b/arch/powerpc/mm/kasan/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +KASAN_SANITIZE := n + +obj-$(CONFIG_PPC32) += kasan_init_32.o diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c new file mode 100644 index 000000000000..42617fcad828 --- /dev/null +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define DISABLE_BRANCH_PROFILING + +#include +#include +#include +#include +#include +#include +#include +#include + +static void kasan_populate_pte(pte_t *ptep, pgprot_t prot) +{ + unsigned long va = (unsigned long)kasan_early_shadow_page; + phys_addr_t pa = __pa(kasan_early_shadow_page); + int i; + + for (i = 0; i < PTRS_PER_PTE; i++, ptep++) + __set_pte_at(&init_mm, va, ptep, pfn_pte(PHYS_PFN(pa), prot), 0); +} + +static int kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end) +{ + pmd_t *pmd; + unsigned long k_cur, k_next; + + pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start); + + for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd++) { + pte_t *new; + + k_next = pgd_addr_end(k_cur, k_end); + if ((void *)pmd_page_vaddr(*pmd) != kasan_early_shadow_pte) + continue; + + new = pte_alloc_one_kernel(&init_mm); + + if (!new) + return -ENOMEM; + kasan_populate_pte(new, PAGE_KERNEL_RO); + pmd_populate_kernel(&init_mm, pmd, new); + } + return 0; +} + +static void __ref *kasan_get_one_page(void) +{ + if (slab_is_available()) + return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO); + + return memblock_alloc(PAGE_SIZE, PAGE_SIZE); +} + +static int __ref 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); + unsigned long k_cur; + int ret; + void *block = NULL; + + ret = kasan_init_shadow_page_tables(k_start, k_end); + if (ret) + return ret; + + if (!slab_is_available()) + block = memblock_alloc(k_end - k_start, PAGE_SIZE); + + for (k_cur = k_start; k_cur < k_end; k_cur += PAGE_SIZE) { + pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); + void *va = block ? block + k_cur - k_start : kasan_get_one_page(); + pte_t pte = pfn_pte(PHYS_PFN(__pa(va)), PAGE_KERNEL); + + if (!va) + return -ENOMEM; + + __set_pte_at(&init_mm, k_cur, pte_offset_kernel(pmd, k_cur), pte, 0); + } + flush_tlb_kernel_range(k_start, k_end); + return 0; +} + +static void __init kasan_remap_early_shadow_ro(void) +{ + kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL_RO); + + flush_tlb_kernel_range(KASAN_SHADOW_START, KASAN_SHADOW_END); +} + +void __init kasan_mmu_init(void) +{ + int ret; + struct memblock_region *reg; + + for_each_memblock(memory, reg) { + phys_addr_t base = reg->base; + phys_addr_t top = min(base + reg->size, total_lowmem); + + if (base >= top) + continue; + + ret = kasan_init_region(__va(base), top - base); + if (ret) + panic("kasan: kasan_init_region() failed"); + } +} + +void __init kasan_init(void) +{ + kasan_remap_early_shadow_ro(); + + clear_page(kasan_early_shadow_page); + + /* At this point kasan is fully initialized. Enable error messages */ + init_task.kasan_depth = 0; + pr_info("KASAN init done\n"); +} + +#ifdef CONFIG_MODULES +void *module_alloc(unsigned long size) +{ + void *base = vmalloc_exec(size); + + if (!base) + return NULL; + + if (!kasan_init_region(base, size)) + return base; + + vfree(base); + + return NULL; +} +#endif + +void __init kasan_early_init(void) +{ + unsigned long addr = KASAN_SHADOW_START; + unsigned long end = KASAN_SHADOW_END; + unsigned long next; + pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(addr), addr), addr); + + BUILD_BUG_ON(KASAN_SHADOW_START & ~PGDIR_MASK); + + kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL); + + do { + next = pgd_addr_end(addr, end); + pmd_populate_kernel(&init_mm, pmd, kasan_early_shadow_pte); + } while (pmd++, addr = next, addr != end); + + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + WARN(true, "KASAN not supported on hash 6xx"); +} From patchwork Tue Mar 12 22:16:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64C321515 for ; Tue, 12 Mar 2019 22:16:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50D9E296F7 for ; Tue, 12 Mar 2019 22:16:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D49296FE; Tue, 12 Mar 2019 22:16:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1452296F7 for ; Tue, 12 Mar 2019 22:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C69C8E0008; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6627C8E000F; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B14A8E000E; Tue, 12 Mar 2019 18:16:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id D61278E0008 for ; Tue, 12 Mar 2019 18:16:20 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id t7so1591049wrw.8 for ; Tue, 12 Mar 2019 15:16:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=acqG75nChdz0NKlCBaUDHivOgUFydlR1lE4J1UHbXOo=; b=LRFqZzgmxtswkJyEVYzMa1NFBCBEbFNN82v0TAgFoDaybq0GusgxRDl0XWBN9dIxxq wZaktP489OCAzzNqMyHBVh0tBAqW2wsH4bHJ/i72UGBT2AAZTpFCle7wW5cbpA0JThIk 0bsg1TAmLgwW9sMQN0P4qHlmnW2encxKFC3X/V6k/FttULh+Em7suEhNBoENUcTUzQ00 31sEGP/VuEknt+NCvbCikJChBNfsMcZ1C0vLZG+fuu39ZbVdDDsMWvN7dFXxs6OdUYVZ DUrMID3Y1mM68nkh79L7LEdJ1tMRPdMTWmM0i/I/onqN2cngrZwZMySKKZ8Sy5EqBFXI j54Q== X-Gm-Message-State: APjAAAWGyxr1I/zUdKhtdeJyDELnxPYmqKWy/vJIoRnuo2YFub6qUfSi q9TX2bdS+cs2ge9/LhF3TRRTfCf1dcTbKRROuox3LuqSqGBEroNUFr04r7n0qlK7vzOl1rZHOla loz4rtiK+7inHUH76r9G24wRLH0IlJMMhFyaUIK532UhFnhA9nUirq/iVWwReT4xjqg== X-Received: by 2002:a05:600c:2301:: with SMTP id 1mr29983wmo.116.1552428980147; Tue, 12 Mar 2019 15:16:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLSYD1XUrVubNT2agZbYJ3J6i/s+DrHNQHa5VAHT2boMHoqJB7vAQaccgnK2NZOpM2Q7W/ X-Received: by 2002:a05:600c:2301:: with SMTP id 1mr29946wmo.116.1552428978962; Tue, 12 Mar 2019 15:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428978; cv=none; d=google.com; s=arc-20160816; b=uqiIEwy2cjCXBptzyYdOMzRILLF6xn+rhxsr8LfxCauZjg8B9X2lYT/t/wxF0Xjmjg kziqnGDxzbtVzeyskQsVds7jOegh8CUaTQLpEA7x6yuhSiFaeyIUjPXOOB/SKnaQcyu3 +XHOgsNYgXRmT1kBjNAxfSVNXd804zvgp/n1+ulS5+a61n/SxC+BD6veq+qE7pjBmcYy /rHMG826keMZqi7xu3++RRMdHUGkAP0hznYp9DpPj0uyKJmEE9xI+uoqEtDTOS5PNvVc vZbW6fStIxHtLx6DVkEsmbdbn9P00VpK4OPSPG0booliUO+aVj2+eO0Mle3L8Omb+97p 7Nhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=acqG75nChdz0NKlCBaUDHivOgUFydlR1lE4J1UHbXOo=; b=LpJMXk4tKejebB4Tn/yV/NSyxhv+5IFuIGlExB0JVi5qes8Ht+nNJDjSFnMRuAxsTX zlDNA8exDZzgPBq1O97t0jNUYRRt5dFgggzWr71oDEaLypXRisCpKa1FKS+iFPFq6ZjU cqA6wRymcMUt4FSvnn2bCPwMrYS01oI4gGCUf9qHlGswK5ehy/Ld8h4p/K7NEKat9zZw NBrA0PdHJlUs5GgRTUVeeitO9kfhH4wg5wmRKrf5xVBYnNYM5tnb5Ot+YIil6TuS79gt oHf9C3M/6qaETHeqNvqynvnCYtejgJbt5J9WOlYnZUiuLmLTqjo6TUNAYAYgK0Hpserm VI9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=mslzkjz3; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id x26si1803wmk.36.2019.03.12.15.16.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=mslzkjz3; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7Q2VQKz9tylk; Tue, 12 Mar 2019 23:16:18 +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=mslzkjz3; 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 kQJExDHdjdbS; Tue, 12 Mar 2019 23:16:18 +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 44Jq7Q1MdLzB09ZG; Tue, 12 Mar 2019 23:16:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428978; bh=acqG75nChdz0NKlCBaUDHivOgUFydlR1lE4J1UHbXOo=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=mslzkjz309VjCj2gAhQK7SJYEHF6BddifXNIuPsHQ3b1X4xhoBE5ORIif8L3IIDtO jPRlBMjFLE80b9TqrnMAYfdk1NNLZBgcaMXKAqBTDpk5DJbsVUCRck+sZBkFwdUuGv bl9RxuHXHiti1w1eN5COxl9Z68hYJWdXdo9VvZms= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 677AE8B8B1; Tue, 12 Mar 2019 23:16:18 +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 zYRs_Sbl-S64; Tue, 12 Mar 2019 23:16:18 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2D75D8B8A7; Tue, 12 Mar 2019 23:16:18 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id EB7576FA15; Tue, 12 Mar 2019 22:16:17 +0000 (UTC) Message-Id: <0cbf282d566c67a3cded4f41f64fc29420b80aa8.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 12/18] powerpc/32s: move hash code patching out of MMU_init_hw() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:17 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP For KASAN, hash table handling will be activated early for accessing to KASAN shadow areas. In order to avoid any modification of the hash functions while they are still used with the early hash table, the code patching is moved out of MMU_init_hw() and put close to the big-bang switch to the final hash table. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_32.S | 3 +++ arch/powerpc/mm/mmu_decl.h | 1 + arch/powerpc/mm/ppc_mmu_32.c | 36 ++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 3ee42c0ada69..0bfaf64e67ee 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -966,6 +966,9 @@ start_here: bl machine_init bl __save_cpu_setup bl MMU_init +BEGIN_MMU_FTR_SECTION + bl MMU_init_hw_patch +END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE) /* * Go back to running unmapped so we can load up new values diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index 74ff61dabcb1..d726ff776054 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h @@ -130,6 +130,7 @@ extern void wii_memory_fixups(void); */ #ifdef CONFIG_PPC32 extern void MMU_init_hw(void); +void MMU_init_hw_patch(void); unsigned long mmu_mapin_ram(unsigned long base, unsigned long top); #endif diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c index 2d5b0d50fb31..38c0e28c21e1 100644 --- a/arch/powerpc/mm/ppc_mmu_32.c +++ b/arch/powerpc/mm/ppc_mmu_32.c @@ -39,6 +39,7 @@ struct hash_pte *Hash, *Hash_end; unsigned long Hash_size, Hash_mask; unsigned long _SDR1; +static unsigned int hash_mb, hash_mb2; struct ppc_bat BATS[8][2]; /* 8 pairs of IBAT, DBAT */ @@ -308,7 +309,6 @@ void hash_preload(struct mm_struct *mm, unsigned long ea, */ void __init MMU_init_hw(void) { - unsigned int hmask, mb, mb2; unsigned int n_hpteg, lg_n_hpteg; if (!mmu_has_feature(MMU_FTR_HPTE_TABLE)) @@ -349,20 +349,30 @@ void __init MMU_init_hw(void) (unsigned long long)(total_memory >> 20), Hash_size >> 10, Hash); - /* - * Patch up the instructions in hashtable.S:create_hpte - */ - if ( ppc_md.progress ) ppc_md.progress("hash:patch", 0x345); Hash_mask = n_hpteg - 1; - hmask = Hash_mask >> (16 - LG_HPTEG_SIZE); - mb2 = mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg; + hash_mb2 = hash_mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg; if (lg_n_hpteg > 16) - mb2 = 16 - LG_HPTEG_SIZE; + hash_mb2 = 16 - LG_HPTEG_SIZE; +} + +void __init MMU_init_hw_patch(void) +{ + unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE); + if (ppc_md.progress) + ppc_md.progress("hash:patch", 0x345); + if (ppc_md.progress) + ppc_md.progress("hash:done", 0x205); + + /* WARNING: Make sure nothing can trigger a KASAN check past this point */ + + /* + * Patch up the instructions in hashtable.S:create_hpte + */ modify_instruction_site(&patch__hash_page_A0, 0xffff, ((unsigned int)Hash - PAGE_OFFSET) >> 16); - modify_instruction_site(&patch__hash_page_A1, 0x7c0, mb << 6); - modify_instruction_site(&patch__hash_page_A2, 0x7c0, mb2 << 6); + modify_instruction_site(&patch__hash_page_A1, 0x7c0, hash_mb << 6); + modify_instruction_site(&patch__hash_page_A2, 0x7c0, hash_mb2 << 6); modify_instruction_site(&patch__hash_page_B, 0xffff, hmask); modify_instruction_site(&patch__hash_page_C, 0xffff, hmask); @@ -371,11 +381,9 @@ void __init MMU_init_hw(void) */ modify_instruction_site(&patch__flush_hash_A0, 0xffff, ((unsigned int)Hash - PAGE_OFFSET) >> 16); - modify_instruction_site(&patch__flush_hash_A1, 0x7c0, mb << 6); - modify_instruction_site(&patch__flush_hash_A2, 0x7c0, mb2 << 6); + modify_instruction_site(&patch__flush_hash_A1, 0x7c0, hash_mb << 6); + modify_instruction_site(&patch__flush_hash_A2, 0x7c0, hash_mb2 << 6); modify_instruction_site(&patch__flush_hash_B, 0xffff, hmask); - - if ( ppc_md.progress ) ppc_md.progress("hash:done", 0x205); } void setup_initial_memory_limit(phys_addr_t first_memblock_base, From patchwork Tue Mar 12 22:16:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1759B1515 for ; Tue, 12 Mar 2019 22:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03EF4296F7 for ; Tue, 12 Mar 2019 22:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC98A296FE; Tue, 12 Mar 2019 22:16:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54752296F7 for ; Tue, 12 Mar 2019 22:16:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0E208E000F; Tue, 12 Mar 2019 18:16:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B20058E000E; Tue, 12 Mar 2019 18:16:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96F7D8E000F; Tue, 12 Mar 2019 18:16:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 372AA8E000E for ; Tue, 12 Mar 2019 18:16:22 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id l5so1598996wrv.19 for ; Tue, 12 Mar 2019 15:16:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=vq1JoFcCtAeRhW/hDKejQR/3usXiiHCmkghqbTpni3o=; b=nf5aWalmq0D9QVxHyIM1dmrTO9YStQJnaEktstk/FgI420ipcSMa993gdq8lOwnZb2 iEKNf1SmAw/DzL9nwgq25rBrCT5GsSnN6iQRwT5USfpol+CX1r2s1PSLGl3PFahINzjV qmVfVGEdKTvphdIvsI/W5XTUzVwq3ccv9fc5f2pr5BBvKkefBNsKxyhT1725B9i8217W 2moMVHScxe7xhpZDYmW5ihhCZ808ukDoDUtJOkgvnYGn1Ljy4C76Zv8qiidAOeMnZQ1I 8f8SkB4jNCiDdRmSGJbea85P2p3xrlmgo0fRlobmiQc2sQkEkMaHpJY2hJLQgsriqfuS jpMQ== X-Gm-Message-State: APjAAAXq1Z+ErWTMc5RfBLxZXY6OXjbT2TzX33p7p2et/wSfFw2r22jl DIcUgCF5idtz16iAALUmU15aBzWh72aI+VnhUn/V+I/xus9bJ6xgBS74E3F6yYmlSM5u12XL2yC LlVBCHrcdSOeXu8bJOnBoLJMqRTn/t7mKigXXj0X+ivCYA1BeONwWnXpvIv4ZOBZ2Hg== X-Received: by 2002:adf:f30a:: with SMTP id i10mr8461274wro.300.1552428981478; Tue, 12 Mar 2019 15:16:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhzgGVnCyJuP5sax1Bv+PC2KdECa9pZH3p9f05kPEYF+dpRaqqlRtJVQF/Xj1SNDEwB5O7 X-Received: by 2002:adf:f30a:: with SMTP id i10mr8461246wro.300.1552428980171; Tue, 12 Mar 2019 15:16:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428980; cv=none; d=google.com; s=arc-20160816; b=Ry+nINO2Nj/gb2ku3DAYG+qIasOUzsLhuW+QPOrHNaLE0EGDr8rTGLgcUYnxE7IxBo MwzHY+yLnwoceFEUeED8KYTzibq3Df3DyKH7XrUXbXRAtCCBE0N/tPw6vGi9LXIxLWkP JatNO8ObRtm1RVZF9t28qAGD+95axNVNgBguCig3UmbynjQaBXEI/h7dZzKLyajlrTPo uRnuWButKbjMDsfdaoHKbtNHzqwIZ+/JFPFjsqdTtVX2XqMyglWjMZoJHw0iz+EQmXea E+yspuY+FcVevnVqpF+ofONZUNfsgf6utgNIQfGwxGMJmCKNyz0sUQcxL/BT0QBmyqJS d+gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=vq1JoFcCtAeRhW/hDKejQR/3usXiiHCmkghqbTpni3o=; b=orc0tiXCpbFkWYOYVOI7aWfVM33UGGS7FDtaOTVP1GYDOyE0I9XHiJKVRaP3vs3kUJ P5KU+bm0tOjBkBkQj40iQb/Q2VuTtH00I4OT7pZhLwqJX9hUxCosB6pKwfc+U2RxgwVQ Jl24tc/jwAN/jcSIs0kMOPPR9A/95yL1gloKCLKurWhGKKdqgxZ73vMG/NRP3+oHRih3 5Oi5USl/cHadjRKXurTNQ1vlf/ZQZgHWxqrUpZ5N7h7QHFFlUw9k46pUmsnEs9wwA1nd QFxuPaIwnCEeNtfLiJ/vIGCgnVDtYtUJ71iHoAgB3JqlY+dNTO1gfw7pqIPXl/i5IHPV tZwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ppbmv4QM; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id d194si446wmd.40.2019.03.12.15.16.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:20 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ppbmv4QM; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7R37Dgz9tylm; Tue, 12 Mar 2019 23:16:19 +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=ppbmv4QM; 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 Cxnfh8EvFSN2; Tue, 12 Mar 2019 23:16:19 +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 44Jq7R1ln8z9tyll; Tue, 12 Mar 2019 23:16:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428979; bh=vq1JoFcCtAeRhW/hDKejQR/3usXiiHCmkghqbTpni3o=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ppbmv4QMYyVzJnVaDv1LlrW/YBn7WDpq9y7uhIQIMraG1GroXwN67XUk+ewLxqBPt Q//B9yx2NBoqrwLEhvO5wM4u9CJiIX6xmnl/z+9nBhfuVSo5sRxkSwXVWpKI8yAmzO BovEfYoKfyiKqnhrP0rLgtcO8dZ4vFZ01yxV2z0g= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7149C8B8B1; Tue, 12 Mar 2019 23:16:19 +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 kNUBN7VIp_-l; Tue, 12 Mar 2019 23:16:19 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 36B708B8A7; Tue, 12 Mar 2019 23:16:19 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id F1B4F6FA15; Tue, 12 Mar 2019 22:16:18 +0000 (UTC) Message-Id: <72e314980c084940115d7568a503b615a72709c9.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 13/18] powerpc/32s: set up an early static hash table for KASAN. To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:18 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP KASAN requires early activation of hash table, before memblock() functions are available. This patch implements an early hash_table statically defined in __initdata. During early boot, a single page table is used. For hash32, when doing the final init, one page table is allocated for each PGD entry because of the _PAGE_HASHPTE flag which can't be common to several virt pages. This is done after memblock get available but before switching to the final hash table, otherwise there are issues with TLB flushing due to the shared entries. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_32.S | 40 ++++++++++++++++++++++++++--------- arch/powerpc/mm/kasan/kasan_init_32.c | 23 +++++++++++++++++++- arch/powerpc/mm/mmu_decl.h | 1 + 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 0bfaf64e67ee..fd7c394bc77c 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -160,6 +160,10 @@ __after_mmu_off: bl flush_tlbs bl initial_bats + bl load_segment_registers +#ifdef CONFIG_KASAN + bl early_hash_table +#endif #if defined(CONFIG_BOOTX_TEXT) bl setup_disp_bat #endif @@ -205,7 +209,7 @@ __after_mmu_off: */ turn_on_mmu: mfmsr r0 - ori r0,r0,MSR_DR|MSR_IR + ori r0,r0,MSR_DR|MSR_IR|MSR_RI mtspr SPRN_SRR1,r0 lis r0,start_here@h ori r0,r0,start_here@l @@ -884,11 +888,24 @@ _ENTRY(__restore_cpu_setup) blr #endif /* !defined(CONFIG_PPC_BOOK3S_32) */ - /* * Load stuff into the MMU. Intended to be called with * IR=0 and DR=0. */ +#ifdef CONFIG_KASAN +early_hash_table: + sync /* Force all PTE updates to finish */ + isync + tlbia /* Clear all TLB entries */ + sync /* wait for tlbia/tlbie to finish */ + TLBSYNC /* ... on all CPUs */ + /* Load the SDR1 register (hash table base & size) */ + lis r6, early_hash - PAGE_OFFSET@h + ori r6, r6, 3 /* 256kB table */ + mtspr SPRN_SDR1, r6 + blr +#endif + load_up_mmu: sync /* Force all PTE updates to finish */ isync @@ -900,14 +917,6 @@ load_up_mmu: tophys(r6,r6) lwz r6,_SDR1@l(r6) mtspr SPRN_SDR1,r6 - li r0,16 /* load up segment register values */ - mtctr r0 /* for context 0 */ - lis r3,0x2000 /* Ku = 1, VSID = 0 */ - li r4,0 -3: mtsrin r3,r4 - addi r3,r3,0x111 /* increment VSID */ - addis r4,r4,0x1000 /* address of next segment */ - bdnz 3b /* Load the BAT registers with the values set up by MMU_init. MMU_init takes care of whether we're on a 601 or not. */ @@ -929,6 +938,17 @@ BEGIN_MMU_FTR_SECTION END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS) blr +load_segment_registers: + li r0, 16 /* load up segment register values */ + mtctr r0 /* for context 0 */ + lis r3, 0x2000 /* Ku = 1, VSID = 0 */ + li r4, 0 +3: mtsrin r3, r4 + addi r3, r3, 0x111 /* increment VSID */ + addis r4, r4, 0x1000 /* address of next segment */ + bdnz 3b + blr + /* * This is where the main kernel code starts. */ diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index 42617fcad828..ba8361487075 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -94,6 +94,13 @@ void __init kasan_mmu_init(void) int ret; struct memblock_region *reg; + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) { + 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); @@ -135,6 +142,20 @@ void *module_alloc(unsigned long size) } #endif +#ifdef CONFIG_PPC_BOOK3S_32 +u8 __initdata early_hash[256 << 10] __aligned(256 << 10) = {0}; + +static void __init kasan_early_hash_table(void) +{ + modify_instruction_site(&patch__hash_page_A0, 0xffff, __pa(early_hash) >> 16); + modify_instruction_site(&patch__flush_hash_A0, 0xffff, __pa(early_hash) >> 16); + + Hash = (struct hash_pte *)early_hash; +} +#else +static void __init kasan_early_hash_table(void) {} +#endif + void __init kasan_early_init(void) { unsigned long addr = KASAN_SHADOW_START; @@ -152,5 +173,5 @@ void __init kasan_early_init(void) } while (pmd++, addr = next, addr != end); if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) - WARN(true, "KASAN not supported on hash 6xx"); + kasan_early_hash_table(); } diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h index d726ff776054..31fce3914ddc 100644 --- a/arch/powerpc/mm/mmu_decl.h +++ b/arch/powerpc/mm/mmu_decl.h @@ -106,6 +106,7 @@ extern unsigned int rtas_data, rtas_size; struct hash_pte; extern struct hash_pte *Hash, *Hash_end; extern unsigned long Hash_size, Hash_mask; +extern u8 early_hash[]; #endif /* CONFIG_PPC32 */ From patchwork Tue Mar 12 22:16:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E3F31575 for ; Tue, 12 Mar 2019 22:16:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A9ED286BC for ; Tue, 12 Mar 2019 22:16:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F13B296F7; Tue, 12 Mar 2019 22:16:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5F1B286BC for ; Tue, 12 Mar 2019 22:16:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D74A8E000E; Tue, 12 Mar 2019 18:16:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6402C8E0011; Tue, 12 Mar 2019 18:16:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 445D18E000E; Tue, 12 Mar 2019 18:16:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id D730D8E0011 for ; Tue, 12 Mar 2019 18:16:22 -0400 (EDT) Received: by mail-wm1-f69.google.com with SMTP id n12so1032387wmc.2 for ; Tue, 12 Mar 2019 15:16:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=3EkWwfm1J9eIRyBAvVT+4ioqJyrfykTcLJkz42zJae0=; b=H4nSBunyH0WGcWb9WOMAm9XGHn4m3NQm96dNU9rVyK4uo9TrmJZVbbZ/8ZdCViaOae FSH7fn9Z+asO2XaBavF1AfVAECj9LwLNuaCYui/3JtIMAStKjEhrsPWxXLb5+q23nzUw WJ8UzjAi/IcYEgNcBSf81KyLxhHCR9f+psJHYBg78oMHJ76zn0X0GVkLXh5PccVrxWPA yTDZ+BkEE1fDSb/FDRYxdWgT11Q4VIOcuYWDl8M5f+1bD3dlvRPyceGHBnVe/1QLE5UF L0dMXXGSWjn1AO4CylaAo29tcCqQwdTj+LQtBDylkYuaue6C+7dESUhYjG2hmUZPpl75 LlTw== X-Gm-Message-State: APjAAAVU1OTy7e6WLHNmnND+juOdq/c5F12SY7nVJ/rvXn3oknZuFKTd yh9jQ7oraOuRuTq2gOUawhBxyeAZx0kXE9AB1bwCLYkOt/zg4ur0I2L+uqm4WcRyu9wbKPX6v74 9lXEXuDMV9Tt+tdmYoMugiwubZHpTeBSkDGsq6GIVTHGRp47NLR5vUai9xetfr8NR+A== X-Received: by 2002:adf:b211:: with SMTP id u17mr27005522wra.322.1552428982289; Tue, 12 Mar 2019 15:16:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7G3kYMpt2jBJyd0UWYJcD53hOh6m94BUFBCQiMyZ14Ignb+cVJ8VGRuSggX/axUu5AIvw X-Received: by 2002:adf:b211:: with SMTP id u17mr27005482wra.322.1552428981031; Tue, 12 Mar 2019 15:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428981; cv=none; d=google.com; s=arc-20160816; b=eLYREyTKUYEVXKCN0N+yXBO58XocxVMeB1GSBsA+eHBZeQRL6beC4oStI3TOQby1mu 8Cps9VCWWoNWk5r72jZ82NkutECW9+chzpqFCVgRmr+2sivTuCJEwlmcSHAqzqSCzIix fNuk7NVB15kitTMh44TiIiDCssoxaKttPpo7gFY09hgmNNdTvkT4QaRKiRVkgUGuDJ/o XpzXqlmV80daMzTQWsAPHUz0pIbgqjJkSr8yD2+fnlzXsBlF9UaQDRy/DGjUIHq0nC0R C3qorY34dcqQqmsLN1SmSYCf6Pa0D/wsC2c6Eg2UKCtstRWonB/D8lBktLt52FTBVmND kQ7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=3EkWwfm1J9eIRyBAvVT+4ioqJyrfykTcLJkz42zJae0=; b=gkk58grF3zegHLLJDZ2Pq044vVhRAphB/qP1rLqbSiKQiF7XEarzS6c1EEuRjwp5Ol +aPi8IZPQsaFyMBnpQVklXGROchFA+oN9NnI7EBlLxzosW0CtfZ9DW3DwCXzNcPjjmmS 8Mx3ui6ZZXnyh+BxnU3xWqIBIdZXuUUahtc0GQCpFPnjtkZ3ia0WHahkvqslf26EmEci 7aSmX3W/26b9WhgHKENNHi7rQ6ouwtVxxMp11DMcQZ06uUBInCU147TNrjV/ZmC//aQo ZjTXrGOnpoaRDd3FaVpxkVc35QcxuWKWYRPTndIfUrMfrflgWOLcSfFkZ6a0M06jVyOQ vFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=N2TM9CNF; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id x10si18308wmj.95.2019.03.12.15.16.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=N2TM9CNF; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7S2kbMz9tyln; Tue, 12 Mar 2019 23:16:20 +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=N2TM9CNF; 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 qTzJ1ppy2_Hj; Tue, 12 Mar 2019 23:16:20 +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 44Jq7S1Z5Wz9tyll; Tue, 12 Mar 2019 23:16:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428980; bh=3EkWwfm1J9eIRyBAvVT+4ioqJyrfykTcLJkz42zJae0=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=N2TM9CNFJJZcGDGQgUrPK4MYpe/al6eQHIrgQrWJWcmO2YuKobOm5OK7m9EZlK0xG B6uP41oS5KK5Jzh2rvnrRFvwrgHFS7B2fPk83j6E4FGdrrsJp5+yXVRo5lW+ecBbLf qaXPTXztGHCEFMxvL91DA/r2eFRyTqWevkyabkZU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6F1D48B8B1; Tue, 12 Mar 2019 23:16:20 +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 Q5Qbh1RmwQXX; Tue, 12 Mar 2019 23:16:20 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 46EAC8B8A7; Tue, 12 Mar 2019 23:16:20 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0AB216FA15; Tue, 12 Mar 2019 22:16:19 +0000 (UTC) Message-Id: <053c7aa774fe73402e690c47f432c9d3279dfc30.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v10 14/18] powerpc/32s: map kasan zero shadow with PAGE_READONLY instead of PAGE_KERNEL_RO To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:19 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP For hash32, the zero shadow page gets mapped with PAGE_READONLY instead of PAGE_KERNEL_RO, because the PP bits don't provide a RO kernel, so PAGE_KERNEL_RO is equivalent to PAGE_KERNEL. By using PAGE_READONLY, the page is RO for both kernel and user, but this is not a security issue as it contains only zeroes. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/kasan/kasan_init_32.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index ba8361487075..0d62be3cba47 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -39,7 +39,10 @@ static int kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_ if (!new) return -ENOMEM; - kasan_populate_pte(new, PAGE_KERNEL_RO); + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + kasan_populate_pte(new, PAGE_READONLY); + else + kasan_populate_pte(new, PAGE_KERNEL_RO); pmd_populate_kernel(&init_mm, pmd, new); } return 0; @@ -84,7 +87,10 @@ static int __ref kasan_init_region(void *start, size_t size) static void __init kasan_remap_early_shadow_ro(void) { - kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL_RO); + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + kasan_populate_pte(kasan_early_shadow_pte, PAGE_READONLY); + else + kasan_populate_pte(kasan_early_shadow_pte, PAGE_KERNEL_RO); flush_tlb_kernel_range(KASAN_SHADOW_START, KASAN_SHADOW_END); } From patchwork Tue Mar 12 22:16:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 381091575 for ; Tue, 12 Mar 2019 22:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24258286BC for ; Tue, 12 Mar 2019 22:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1890B296F7; Tue, 12 Mar 2019 22:16:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1A0B286BC for ; Tue, 12 Mar 2019 22:16:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD0078E0012; Tue, 12 Mar 2019 18:16:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A5D458E0011; Tue, 12 Mar 2019 18:16:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 883C48E0012; Tue, 12 Mar 2019 18:16:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 2DDA88E0011 for ; Tue, 12 Mar 2019 18:16:24 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id l1so1604737wrn.13 for ; Tue, 12 Mar 2019 15:16:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=Rsr2lGusV3I5iCGIZKB5JSsUmE7r8qg3qRn745C2fwM=; b=p9ILBvQWE9meeXVQVP5rYfu9iCMLbOjKoLDRB1I1aegbiSSaPHwBHSUD4ElRZ13s/C n5smTjvjQ/FQa1TeYa6KmLhgbTbEE6P/NjH0tEycf7jS0YP2FiZoYcqOHKn+uOqHxpTi SPSSO+f8TYlcMFPh9iYfiyButF9FHNzmac28ZJnw0sNICdPqjWXfnDQy6ekPCrdwCIIx 9tMAPVIOtokXUl6j9722Y1hYT7JY0tx4Xm/F8Wu2VpXaw8ECuBd1ZaHGx0RP11sJAWxS 0UeLFa2rR1PVR/qQaJitLyT8/i8gx1rNT2djRZxV42EB1DfBUjUXCJfyINvlfUjW7ktD 3qow== X-Gm-Message-State: APjAAAV7GWyKJ6edUPumiM1o5GZfvo+kxROkb2Gg0t66qiJuXAY5VXLg Dj0lQi8m8UIRNsi34+cgMY2Vuehzis/11lfWa2ToRy47bJaBUFxMk+fcP0MevdXcYZ3GW1MqWLO fPYOrd3M6Ria7lE2ELIy5G1X/79ytwvuNF4//jFQzWM4PAd0AJMs4mbZDA/6YwGiX0g== X-Received: by 2002:a1c:c6c2:: with SMTP id w185mr31503wmf.62.1552428983453; Tue, 12 Mar 2019 15:16:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqysm8LW5oCcqxK3Gleu/pgq/odvsH1t4BmfXCKV27AQG7bfnB6m3YrWIUk7UDo2l9K1Tg7Y X-Received: by 2002:a1c:c6c2:: with SMTP id w185mr31472wmf.62.1552428982308; Tue, 12 Mar 2019 15:16:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428982; cv=none; d=google.com; s=arc-20160816; b=GDnI0jLj47yGhfcMXtqMfAZ9cQtiTM3CYApUT9aHHR2AVu229XUvfUcGFwucOkNwPs tF+uMtYEJYVpTC5vl9SQkEnKQdunCXRuHJW647sf7gmH/n5Z8/biXaeteBf7r3lBxeOm EamqRSO3F3AQnNUvlngtWdqERubr/Gt+m4xkNu2UclE2psFxLgp1LXxajaPFToAGS+sX b62mmo0ATr5UD9FQzm1IhdFjD8PieMqgs8F8AuVZZipUZwyH3dwqQUm6S+4IIXYmsrc3 o7QAJ29RH8zlLO3Hdec2CvTrbdIqqB4VCScq7ef03I+iqvSe/PxfNippnJAMKXvkcMpk xldw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=Rsr2lGusV3I5iCGIZKB5JSsUmE7r8qg3qRn745C2fwM=; b=XTDsLFvgdpizHHe74c8oSRwBYGp3KKiD7oWeFit2ScFnuPSDE04PoFK7jfjB1a7gRH wmtvQbbGPeFT0FyXiAJoEEWO29sotDIMfefU948HnG2UvOlgN5lqDckILqYML2D10Oj1 cNLuwGVy9UKIrawfQgZ2MzggldrEdAxa2rkdO5wy6adM4KnEg4FKWuQhTiACucambcEO p6mtbf4P5r19Nc7Rm+XBxpO+icFxpbKWU4+0YVxckGmzj6d+UEweSwGprmLMY9QJ5n40 kbzD9iqdIwLZuLwUj0eSz4mT6ypUv99gLwrFKHBj1OZjDPTxHgG/AW7uvlZrU4OJ3UDb dhqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=NqvnAjUO; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id g11si6276290wru.294.2019.03.12.15.16.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:22 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=NqvnAjUO; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7T3sfnz9tylp; Tue, 12 Mar 2019 23:16:21 +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=NqvnAjUO; 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 VZRbI8VkA4s5; Tue, 12 Mar 2019 23:16:21 +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 44Jq7T2X9Tz9tyll; Tue, 12 Mar 2019 23:16:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428981; bh=Rsr2lGusV3I5iCGIZKB5JSsUmE7r8qg3qRn745C2fwM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=NqvnAjUOFSVvFxO2pXU9N1Nqp3/2q+fi7ncFIqF+WexHrOA1Vj6q2m6o00HAEg89U mTTF22reS1UkjcOnRwuShhAcPyR6/uPgUTz3LeSDD/XeNulvINZMcgh2jESGGJmljC qIUE+qGt1/aRsvlsBE6XhGw1IPP83QjcnuBkNwDU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8ED148B8A7; Tue, 12 Mar 2019 23:16:21 +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 dcCw_wLbl2XJ; Tue, 12 Mar 2019 23:16:21 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5E8AF8B8B2; Tue, 12 Mar 2019 23:16:21 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 1ABE76FA15; Tue, 12 Mar 2019 22:16:21 +0000 (UTC) Message-Id: <40b9062b8bf49322ea4d9f91ca734eb6d93754b3.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH RFC v3 15/18] kasan: do not open-code addr_has_shadow To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:21 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Axtens We have a couple of places checking for the existence of a shadow mapping for an address by open-coding the inverse of the check in addr_has_shadow. Replace the open-coded versions with the helper. This will be needed in future to allow architectures to override the layout of the shadow mapping. Reviewed-by: Andrew Donnellan Reviewed-by: Dmitry Vyukov Signed-off-by: Daniel Axtens Signed-off-by: Christophe Leroy --- mm/kasan/generic.c | 3 +-- mm/kasan/tags.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 504c79363a34..9e5c989dab8c 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -173,8 +173,7 @@ static __always_inline void check_memory_region_inline(unsigned long addr, if (unlikely(size == 0)) return; - if (unlikely((void *)addr < - kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { + if (unlikely(!addr_has_shadow((void *)addr))) { kasan_report(addr, size, write, ret_ip); return; } diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 63fca3172659..87ebee0a6aea 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -109,8 +109,7 @@ void check_memory_region(unsigned long addr, size_t size, bool write, return; untagged_addr = reset_tag((const void *)addr); - if (unlikely(untagged_addr < - kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { + if (unlikely(!addr_has_shadow(untagged_addr))) { kasan_report(addr, size, write, ret_ip); return; } From patchwork Tue Mar 12 22:16:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CF671515 for ; Tue, 12 Mar 2019 22:17:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27DAC286BC for ; Tue, 12 Mar 2019 22:17:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BF08296F7; Tue, 12 Mar 2019 22:17:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D80D286BC for ; Tue, 12 Mar 2019 22:16:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCFCD8E0013; Tue, 12 Mar 2019 18:16:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BDDFF8E0011; Tue, 12 Mar 2019 18:16:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A365E8E0013; Tue, 12 Mar 2019 18:16:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 430108E0011 for ; Tue, 12 Mar 2019 18:16:25 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id p3so1595627wrs.7 for ; Tue, 12 Mar 2019 15:16:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=D8w+m6PVWbWnbVuhF9ZKnJbxwUjNhp1FDRV4ywUWxfs=; b=Zil/mr8RZMIQprpPFwhHeiot9mViNg9v5wGSihOtMbBnMNlY/ly91gyGQYbxmF+3os 9YKqcMGMyI81tFYHZGv4+phQ2klMb9/2r1dTBI9gIo0gNj7E6oeszSpAtXMClkpdp6WG pfFDJE9l0HaL5nFzxRA+BAXqRiqF5AYAFQkJ/zvXBLBgdwo+Vp6ccf2Uq1VhMYo9BHzI uThKMu73/tKnDEQgSNqD1/Sc6KZOSWAYB+QMYvX4v9DRYvgaqm2l/mQ3EjAJZDQt278M jTV7NZA9w5avGoqiXWtN9PHmGotjpfxHiqdcSg1n97nPN/1gooqWrpNz8IhD9sFW1w73 x77Q== X-Gm-Message-State: APjAAAXZTPb36Lo18aPkL5HxhKTBnndjFZdVaExOPfP2kCT1LpPa5DuD 7t0V9o+rnfxwQn5//t6gFXOhichhylhydmepVCNRuuNFIpKadYyf4eOiH9o0E9ljDCqHDKQ1XRa SLE0IpAq9V1Ob2J4ujAKutAGhNWqn7b6dorzaVTr/tsSaFr5tynQoAUBSd8KIDfBUnQ== X-Received: by 2002:adf:b64d:: with SMTP id i13mr20247175wre.292.1552428984487; Tue, 12 Mar 2019 15:16:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhyDjwcq0RhxKrISq+LHph/nfA7IPmV1cNS91yVn3/dIIsFQSbZXdDFzonTQKW6xiTeoH9 X-Received: by 2002:adf:b64d:: with SMTP id i13mr20247139wre.292.1552428983225; Tue, 12 Mar 2019 15:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428983; cv=none; d=google.com; s=arc-20160816; b=WGW+hwI+RzXqkFInjMbLBFCExbenF3lEZt/XjHYsjzCz54hV69e4/KC9hkdVjnC2T1 nmKCePv3cnC9VgiJkEjLv9v222zNZkk8XvbQbqBeq+m8p/upZ7StljbC9BHKzPLudEfR bpECgUZRY/o3XjvTYoFf5pXrHaqkP9p8FzwDkyJSB2XQRk1PuBy63ppztkyaZJfbG9tX uqVWkfTnF4TEscs6KOa/cBAgoXELSqQMHiLpV5DfVGkt/BWr+MiQw9usOxn08S6rXo9H KqKdQE+3F1h6AFD3xipzD22e7b35VYh5XqH9EIl0zPQwpci7rLYph523DGQehLqxbXX1 OtIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=D8w+m6PVWbWnbVuhF9ZKnJbxwUjNhp1FDRV4ywUWxfs=; b=S1TqLQFZpDH+PoqoTbFganQPNIBcrQYqiG6Ngw2kQxq+xuvD7o3F6d/SQhHoUNu/9P SNoPG23YVqM4DjP6JBMzraC832+7c+HENNG+kAeXw2ZUpzIsJRs+aL2g/qUui47s6yDt 1R5KWO9mapk3ol5tu5rEQDZGRiHS/4POAgfwEpW39qWa0XBrVo1PIxJZCpr7RWu9qgXD bOCpcIK9WrBM8qIhtPoQbclVc9GMKxyIKfowUhMX3Yv1xwtf69/jvg48H1QKfJetzWE+ jGU8iv7deJ8TC1sbjW1CoQLTQ9Guza1Gifwnq7tCF+OpCSmmNge8ckLvrKc0ByFt/Nc3 sMxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Yb6UzHtN; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id l13si6127724wrr.124.2019.03.12.15.16.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:23 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Yb6UzHtN; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7V4K2Fz9tylq; Tue, 12 Mar 2019 23:16:22 +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=Yb6UzHtN; 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 vwXcDA_2HKgG; Tue, 12 Mar 2019 23:16:22 +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 44Jq7V36Fvz9tyll; Tue, 12 Mar 2019 23:16:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428982; bh=D8w+m6PVWbWnbVuhF9ZKnJbxwUjNhp1FDRV4ywUWxfs=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=Yb6UzHtNwFgb6Hxq13PPwFfbyi7aIHatfH6zZ/4zN3oa6InMCvqGTYwCJ5RIvCDrM icUKoYFtxRiWabE0zKzjt7lbjVgWsHYbAuY/f0FlOCqzI6v+I04QJRK+Zi6H3b1vfF Y3zXlOS/T2ylFG+3vXLJVZRwZDB0EgvWHQ73oqrU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A0E3B8B8B1; Tue, 12 Mar 2019 23:16:22 +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 seg9g2DF1DLM; Tue, 12 Mar 2019 23:16:22 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5F43A8B8A7; Tue, 12 Mar 2019 23:16:22 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 214836FA15; Tue, 12 Mar 2019 22:16:22 +0000 (UTC) Message-Id: <6350da5e480a2006b8990124d74cdbfa70704d98.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH RFC v3 16/18] kasan: allow architectures to manage the memory-to-shadow mapping To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:22 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Axtens Currently, shadow addresses are always addr >> shift + offset. However, for powerpc, the virtual address space is fragmented in ways that make this simple scheme impractical. Allow architectures to override: - kasan_shadow_to_mem - kasan_mem_to_shadow - addr_has_shadow Rename addr_has_shadow to kasan_addr_has_shadow as if it is overridden it will be available in more places, increasing the risk of collisions. If architectures do not #define their own versions, the generic code will continue to run as usual. Reviewed-by: Dmitry Vyukov Signed-off-by: Daniel Axtens Signed-off-by: Christophe Leroy --- include/linux/kasan.h | 2 ++ mm/kasan/generic.c | 2 +- mm/kasan/generic_report.c | 2 +- mm/kasan/kasan.h | 6 +++++- mm/kasan/report.c | 6 +++--- mm/kasan/tags.c | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index b40ea104dd36..f6261840f94c 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -23,11 +23,13 @@ extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D]; int kasan_populate_early_shadow(const void *shadow_start, const void *shadow_end); +#ifndef kasan_mem_to_shadow static inline void *kasan_mem_to_shadow(const void *addr) { return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; } +#endif /* Enable reporting bugs after kasan_disable_current() */ extern void kasan_enable_current(void); diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 9e5c989dab8c..a5b28e3ceacb 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -173,7 +173,7 @@ static __always_inline void check_memory_region_inline(unsigned long addr, if (unlikely(size == 0)) return; - if (unlikely(!addr_has_shadow((void *)addr))) { + if (unlikely(!kasan_addr_has_shadow((void *)addr))) { kasan_report(addr, size, write, ret_ip); return; } diff --git a/mm/kasan/generic_report.c b/mm/kasan/generic_report.c index 36c645939bc9..6caafd61fc3a 100644 --- a/mm/kasan/generic_report.c +++ b/mm/kasan/generic_report.c @@ -107,7 +107,7 @@ static const char *get_wild_bug_type(struct kasan_access_info *info) const char *get_bug_type(struct kasan_access_info *info) { - if (addr_has_shadow(info->access_addr)) + if (kasan_addr_has_shadow(info->access_addr)) return get_shadow_bug_type(info); return get_wild_bug_type(info); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 3e0c11f7d7a1..958e984d4544 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -110,16 +110,20 @@ struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, struct kasan_free_meta *get_free_info(struct kmem_cache *cache, const void *object); +#ifndef kasan_shadow_to_mem static inline const void *kasan_shadow_to_mem(const void *shadow_addr) { return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) << KASAN_SHADOW_SCALE_SHIFT); } +#endif -static inline bool addr_has_shadow(const void *addr) +#ifndef kasan_addr_has_shadow +static inline bool kasan_addr_has_shadow(const void *addr) { return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } +#endif void kasan_poison_shadow(const void *address, size_t size, u8 value); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ca9418fe9232..bc3355ee2dd0 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -298,7 +298,7 @@ void kasan_report(unsigned long addr, size_t size, untagged_addr = reset_tag(tagged_addr); info.access_addr = tagged_addr; - if (addr_has_shadow(untagged_addr)) + if (kasan_addr_has_shadow(untagged_addr)) info.first_bad_addr = find_first_bad_addr(tagged_addr, size); else info.first_bad_addr = untagged_addr; @@ -309,11 +309,11 @@ void kasan_report(unsigned long addr, size_t size, start_report(&flags); print_error_description(&info); - if (addr_has_shadow(untagged_addr)) + if (kasan_addr_has_shadow(untagged_addr)) print_tags(get_tag(tagged_addr), info.first_bad_addr); pr_err("\n"); - if (addr_has_shadow(untagged_addr)) { + if (kasan_addr_has_shadow(untagged_addr)) { print_address_description(untagged_addr); pr_err("\n"); print_shadow_for_address(info.first_bad_addr); diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 87ebee0a6aea..661c23dd5340 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -109,7 +109,7 @@ void check_memory_region(unsigned long addr, size_t size, bool write, return; untagged_addr = reset_tag((const void *)addr); - if (unlikely(!addr_has_shadow(untagged_addr))) { + if (unlikely(!kasan_addr_has_shadow(untagged_addr))) { kasan_report(addr, size, write, ret_ip); return; } From patchwork Tue Mar 12 22:16:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DCC51575 for ; Tue, 12 Mar 2019 22:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA6972927D for ; Tue, 12 Mar 2019 22:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D980A286BC; Tue, 12 Mar 2019 22:17:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EF64286BC for ; Tue, 12 Mar 2019 22:17:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8124C8E0014; Tue, 12 Mar 2019 18:16:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 799D58E0011; Tue, 12 Mar 2019 18:16:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EACB8E0014; Tue, 12 Mar 2019 18:16:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id 006A08E0011 for ; Tue, 12 Mar 2019 18:16:26 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id g7so1248900wrp.23 for ; Tue, 12 Mar 2019 15:16:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=dEzxTiGln0bue6uZbHj/H20SjQwnB1JvnNPVgqIMv3k=; b=p8lDuO6lGPrc4pyr9lmHA37yoH+V5cGcNTCviUbXEWt9Q1v4scFsp1Nm/1omfMJLVa uzmQbMehrHtFzQoUgvO0kYhKeefHjGOgP5gXhUHwBjzEz2W2lAdHDUtk//c3FnSSVZ6w Rf8eTFzafUeiMXNvw90hJ5EeATdcQUVQ8OEqZgSZDxMWcfz535A8ckTfkVg2yrOnd3w8 dRAaxiVLZ7S9J47Y/IVzwSJuhKfWYpLeZzkHEWeVnkSDjQZX2o6brldGkpNVrK7rnhDU PLagCVXE1KOSviuV+ziggUbRkThegqScg/NNA0yrrVv65X5NUiKzsdz09dm8ubpOXJ9t uGOQ== X-Gm-Message-State: APjAAAWh/OObRXiar483Sx6uIAp+rXkyShX/xEOa4qxFmd+B9WvFEhB1 NzLpwr/aoGvyW1j4LxOcxbhXFFU5Myn2iMQKSkc+Uktbu1NGZBs6PeIpeP918/WGi5UvZNL+rCt MMChUTPI6Te3AzMDAiBtwCjGLnlkgB2wJ4QncQl2uhrEOVjcWSJ+I24o0uouWSclrIQ== X-Received: by 2002:a1c:4e19:: with SMTP id g25mr34109wmh.106.1552428985386; Tue, 12 Mar 2019 15:16:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqws4PHFZyXCflfBoe/TqKHOXIKROVeXodi9PO4JzGNCIOb75WbO+yUFrHK/Xmi7RLaQQsSm X-Received: by 2002:a1c:4e19:: with SMTP id g25mr34071wmh.106.1552428984274; Tue, 12 Mar 2019 15:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428984; cv=none; d=google.com; s=arc-20160816; b=vjBeuOmjEIKoD5+Oi0Gq46zF3i0M8evqCW5kZkaZ8zi+TX8qseUR2CZYqPo7NLPt8y rPM4MCp954QTfaHp2EbSk55Qy6Ue9eTlNWoYBF5+jbHuYeLaP5XGiGv/S0IORb1gM/xh 1YgLEh7tJf6WSTK5bWhYmiFOaNAFIE+bZWNlsS8Sv5bCyIp2TBd6DuzjIf/41XfNCJef HpK15MVGmbeiQ0r3wnuexpiOAti21/DRgoflF0/62dwH0eijIRDdYa6wjscC9rn865lB DTPhdCprCfCb/pHJKRM0g0nQUDxV+2qph8C+WyMoNCBkVia02cxMgkWgdG+hKTm4pqVC EYXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=dEzxTiGln0bue6uZbHj/H20SjQwnB1JvnNPVgqIMv3k=; b=QH03AppgWUGl5vjtHxnsAn8dqezychTy5Cmh8FBPIw7U5fqAbHR8o9LXRXz086ZIWa GaRK1B7iKR2AM3FmQO8mZ1SfD6ImoBZYgYgeaK4Lw3Yej5dm+aklD714VNsv+Au9kB3E 6TJQCIAQnuF1hKl78JHk/9bjLrZES1GyHMcn4N1lOAzaRWPkTWJJk7ru83MbYNBktgRb pKSFjvrA2nCSyDNz8ga357Hzh5KCEyPbq5D+jcgCrjmX550kw6U/ZgSUKOnvlfubDqLu JKvCCaFKwqDntQggRfcwv6Ytv1YqqadKTdvH8s/6PrN2YyW9dhvn/KXXA6ZW3ioXlQ6e ELaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=c8XcioCi; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id o13si6109394wrm.409.2019.03.12.15.16.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:24 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=c8XcioCi; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7W4RDwz9tylr; Tue, 12 Mar 2019 23:16:23 +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=c8XcioCi; 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 62bjLAJtcdl6; Tue, 12 Mar 2019 23:16:23 +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 44Jq7W3BJcz9tyll; Tue, 12 Mar 2019 23:16:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428983; bh=dEzxTiGln0bue6uZbHj/H20SjQwnB1JvnNPVgqIMv3k=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=c8XcioCi6Zr8+Kp6xAb9yUXdneRo3pqOMJ1PRDU2sB9qOiRQg1QeN8NxmdI0sw8Zi C1Hyab7dVkRqTDrI0m6wwDXP5xTu+FzqpvWQydoQuxGAXk1AC2w+qsOVSGPtLZUlcg N8mWkzbGl8dgqo6eb6MhZBVpDFB1J5EiU1vvSFjk= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A4D518B8B1; Tue, 12 Mar 2019 23:16:23 +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 rsP8JgWWL1Z7; Tue, 12 Mar 2019 23:16:23 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6C0338B8A7; Tue, 12 Mar 2019 23:16:23 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 2B12E6FA15; Tue, 12 Mar 2019 22:16:23 +0000 (UTC) Message-Id: <4f888b49a3c72105ef8e74997fcb2ab20ad2252d.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH RFC v3 17/18] kasan: allow architectures to provide an outline readiness check To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:23 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Axtens In powerpc (as I understand it), we spend a lot of time in boot running in real mode before MMU paging is initialised. During this time we call a lot of generic code, including printk(). If we try to access the shadow region during this time, things fail. My attempts to move early init before the first printk have not been successful. (Both previous RFCs for ppc64 - by 2 different people - have needed this trick too!) So, allow architectures to define a kasan_arch_is_ready() hook that bails out of check_memory_region_inline() unless the arch has done all of the init. Link: https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series Link: https://patchwork.ozlabs.org/patch/795211/ # ppc radix series Originally-by: Balbir Singh Cc: Aneesh Kumar K.V Signed-off-by: Daniel Axtens [check_return_arch_not_ready() ==> static inline kasan_arch_is_ready()] Signed-off-by: Christophe Leroy --- include/linux/kasan.h | 4 ++++ mm/kasan/generic.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f6261840f94c..a630d53f1a36 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -14,6 +14,10 @@ struct task_struct; #include #include +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index a5b28e3ceacb..0336f31bbae3 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -170,6 +170,9 @@ static __always_inline void check_memory_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_arch_is_ready()) + return; + if (unlikely(size == 0)) return; From patchwork Tue Mar 12 22:16:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10850083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C43E1575 for ; Tue, 12 Mar 2019 22:17:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46364286BC for ; Tue, 12 Mar 2019 22:17:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A6E62969D; Tue, 12 Mar 2019 22:17:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56B3A286BC for ; Tue, 12 Mar 2019 22:17:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C08168E0015; Tue, 12 Mar 2019 18:16:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B90EE8E0011; Tue, 12 Mar 2019 18:16:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A34DE8E0015; Tue, 12 Mar 2019 18:16:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 3D1B18E0011 for ; Tue, 12 Mar 2019 18:16:28 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id g7so1248943wrp.23 for ; Tue, 12 Mar 2019 15:16:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=QZsl/Ru3+/IhFFfMtEstuOanA3qKYxjkILWkI1v0IwY=; b=guzMJ1tatsNmGV/b0IwZqMXt8OrDNwzucviC6W+g+9chpLiQyHKTByS3UsbS/2YrsT 61DimWmzU5hcxnBA875JmIG5H34TJH/7N6TugJ6wa2bgeXkdGqFYKu/va6uQ7AuTLvFf 79dDsXHx0zl7tCIdZNXO7SodaUSJ3B/z9OGKDjZ7anNrafwqGz6j/2i4vqjgNZHd8eNE ZAVdDgvV+1zFnfuUSeQ9DRkNQvFv7+unoSA8S1z1gE93UdhmJQN1c8PYXlU9yhslrm3l c/clYoniKlj7dJ/DFMGQyvQZs8FeoznpeFB5lerqtqzlMVcNRGDoa29eOvJhOKYw+Msd 4DUQ== X-Gm-Message-State: APjAAAUGATGYrqtKTDOLWDpuy2ywSl4q9h/ugCM3vTYnjSm+vgkQroCp AszvjI+opqHpBGpSJbhZ/lLd6wqhu8LC2lkzKfktxqgBpDpHBsa6/G4DxJYjCyH+R2NhUKyqmFv z02wURWe6M8UGKHRwYyZBKZtrmhTshM69YO1UXB3wb8EQlg2Z9Yunsw33ZuKcRXUHeA== X-Received: by 2002:adf:ce90:: with SMTP id r16mr25111039wrn.64.1552428987437; Tue, 12 Mar 2019 15:16:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTet7ufUUnl6TDPejvpGn1GO9EuUMlhohV8/ZDE9j2RcrFkIehNLsrFZf0MlCv7CSzYo11 X-Received: by 2002:adf:ce90:: with SMTP id r16mr25110962wrn.64.1552428985393; Tue, 12 Mar 2019 15:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552428985; cv=none; d=google.com; s=arc-20160816; b=vBer8mQ5hxYXMaqChFc39S9M+lWMU5gAH2MZb/rZvnksvkfnmTzC9zF3huA83zbSV/ cr7ypYIEiK3RtWROBP5b4IsC/qzdaE32jEeTCaRz5Td0iEX7AOlJtLLEueY6sqlj8Kpo Yjn4n9rYRZKTHFOTBMtqqj7TQoiE6FefAJe4ViaOejHseJVrWC6Ebol/jAaYlxW704J1 b/fUo2HIPiRMyV2kKf/jkX9MOqEX5I6bQFl1sct35O9PJykWwmZT9VdAt6eXn+6Vr5n/ st40dyiyjhzni1EIKiMj342eF70hVRPB7YqRYeicuBviOeSDKvxC+UthbwDeOYUYaxSU ukLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=QZsl/Ru3+/IhFFfMtEstuOanA3qKYxjkILWkI1v0IwY=; b=BCHc0xNVZPQYY5axSQQtWiMfTtchfbJ0MlyVksK/cUxBxxst03kwz5Xl+bqHSq34NO 0AaWXex5y5DW9VugXHtS9NaIKqQR5HHGOi8BmlJSfQGYaofo960qYhZQbGiwkfvt9lG7 K8XJkb12wHos3liiNBD/dh69AweoPUxXlOBUwkEqE2vgvG4DXVkOZeUFobSHvOZGNoGT HqBw41UHseTtVizylgZRJwepF2ec4PNgv/AE/Ve+MilgLbdszzFwM4sMB3ZRsOwItOp8 3gjCLK1gRQOXoZD7xWGy1TYJFkZqnFZwsAmHxY8YVfsLx0VB19JOdnJzt6NE+saCRD+U BCUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=figi3DEp; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id a18si5973236wrx.194.2019.03.12.15.16.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 15:16:25 -0700 (PDT) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=figi3DEp; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44Jq7X5bKZz9tyls; Tue, 12 Mar 2019 23:16:24 +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=figi3DEp; 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 EVsQyKb7Wlnp; Tue, 12 Mar 2019 23:16:24 +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 44Jq7X4F2Qz9tyll; Tue, 12 Mar 2019 23:16:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1552428984; bh=QZsl/Ru3+/IhFFfMtEstuOanA3qKYxjkILWkI1v0IwY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=figi3DEpy672YkUFS5X5eRxrv3Kb0CtlE9a5CafpdoUrGP3PGVQVNX4d+D3E1G271 dWDd15Av7efTvva1yHz6GRkWTpS0/R+LQzi4PWx1pIsSH1lebvRD5klY7hPx0K2hl4 yG8aJxXwHoNWyd4eIfknHOxH1lUOUVOhxq25BwPw= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C675F8B8B1; Tue, 12 Mar 2019 23:16:24 +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 mAvbpiVo68Nq; Tue, 12 Mar 2019 23:16:24 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 827728B8A7; Tue, 12 Mar 2019 23:16:24 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 3CB036FA15; Tue, 12 Mar 2019 22:16:24 +0000 (UTC) Message-Id: <3e97aba429c769bd99ccd8d6f16eda98f7d378a7.1552428161.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH RFC v3 18/18] powerpc: KASAN for 64bit Book3E To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 12 Mar 2019 22:16:24 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Axtens Wire up KASAN. Only outline instrumentation is supported. The KASAN shadow area is mapped into vmemmap space: 0x8000 0400 0000 0000 to 0x8000 0600 0000 0000. To do this we require that vmemmap be disabled. (This is the default in the kernel config that QorIQ provides for the machine in their SDK anyway - they use flat memory.) Only the kernel linear mapping (0xc000...) is checked. The vmalloc and ioremap areas (also in 0x800...) are all mapped to the zero page. As with the Book3S hash series, this requires overriding the memory <-> shadow mapping. Also, as with both previous 64-bit series, early instrumentation is not supported. It would allow us to drop the check_return_arch_not_ready() hook in the KASAN core, but it's tricky to get it set up early enough: we need it setup before the first call to instrumented code like printk(). Perhaps in the future. Only KASAN_MINIMAL works. Tested on e6500. KVM, kexec and xmon have not been tested. The test_kasan module fires warnings as expected, except for the following tests: - Expected/by design: kasan test: memcg_accounted_kmem_cache allocate memcg accounted object - Due to only supporting KASAN_MINIMAL: kasan test: kasan_stack_oob out-of-bounds on stack kasan test: kasan_global_oob out-of-bounds global variable kasan test: kasan_alloca_oob_left out-of-bounds to left on alloca kasan test: kasan_alloca_oob_right out-of-bounds to right on alloca kasan test: use_after_scope_test use-after-scope on int kasan test: use_after_scope_test use-after-scope on array Thanks to those who have done the heavy lifting over the past several years: - Christophe's 32 bit series: https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-February/185379.html - Aneesh's Book3S hash series: https://lwn.net/Articles/655642/ - Balbir's Book3S radix series: https://patchwork.ozlabs.org/patch/795211/ Cc: Christophe Leroy Cc: Aneesh Kumar K.V Cc: Balbir Singh Signed-off-by: Daniel Axtens [- Removed EXPORT_SYMBOL of the static key - Fixed most checkpatch problems - Replaced kasan_zero_page[] by kasan_early_shadow_page[] - Reduced casting mess by using intermediate locals - Fixed build failure on pmac32_defconfig] Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/Kconfig.debug | 2 +- arch/powerpc/include/asm/kasan.h | 71 ++++++++++++++++++++++++++++ arch/powerpc/mm/Makefile | 2 + arch/powerpc/mm/kasan/Makefile | 1 + arch/powerpc/mm/kasan/kasan_init_book3e_64.c | 50 ++++++++++++++++++++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/mm/kasan/kasan_init_book3e_64.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d9364368329b..51ef9fac6c5d 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -174,6 +174,7 @@ config PPC select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_KASAN if PPC32 + select HAVE_ARCH_KASAN if PPC_BOOK3E_64 && !SPARSEMEM_VMEMMAP select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 61febbbdd02b..fc1f5fa7554e 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -369,5 +369,5 @@ config PPC_FAST_ENDIAN_SWITCH config KASAN_SHADOW_OFFSET hex - depends on KASAN + depends on KASAN && PPC32 default 0xe0000000 diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 296e51c2f066..ae410f0e060d 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -21,12 +21,15 @@ #define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT)) +#ifdef CONFIG_PPC32 #define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) #define KASAN_SHADOW_END 0UL #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#endif /* CONFIG_PPC32 */ + #ifdef CONFIG_KASAN void kasan_early_init(void); void kasan_mmu_init(void); @@ -36,5 +39,73 @@ static inline void kasan_init(void) { } static inline void kasan_mmu_init(void) { } #endif +#ifdef CONFIG_PPC_BOOK3E_64 +#include +#include + +/* + * We don't put this in Kconfig as we only support KASAN_MINIMAL, and + * that will be disabled if the symbol is available in Kconfig + */ +#define KASAN_SHADOW_OFFSET ASM_CONST(0x6800040000000000) + +#define KASAN_SHADOW_SIZE (KERN_VIRT_SIZE >> KASAN_SHADOW_SCALE_SHIFT) + +extern struct static_key_false powerpc_kasan_enabled_key; +extern unsigned char kasan_early_shadow_page[]; + +static inline bool kasan_arch_is_ready_book3e(void) +{ + if (static_branch_likely(&powerpc_kasan_enabled_key)) + return true; + return false; +} +#define kasan_arch_is_ready kasan_arch_is_ready_book3e + +static inline void *kasan_mem_to_shadow_book3e(const void *ptr) +{ + unsigned long addr = (unsigned long)ptr; + + if (addr >= KERN_VIRT_START && addr < KERN_VIRT_START + KERN_VIRT_SIZE) + return kasan_early_shadow_page; + + return (void *)(addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; +} +#define kasan_mem_to_shadow kasan_mem_to_shadow_book3e + +static inline void *kasan_shadow_to_mem_book3e(const void *shadow_addr) +{ + /* + * We map the entire non-linear virtual mapping onto the zero page so if + * we are asked to map the zero page back just pick the beginning of that + * area. + */ + if (shadow_addr >= (void *)kasan_early_shadow_page && + shadow_addr < (void *)(kasan_early_shadow_page + PAGE_SIZE)) + return (void *)KERN_VIRT_START; + + return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) << + KASAN_SHADOW_SCALE_SHIFT); +} +#define kasan_shadow_to_mem kasan_shadow_to_mem_book3e + +static inline bool kasan_addr_has_shadow_book3e(const void *ptr) +{ + unsigned long addr = (unsigned long)ptr; + + /* + * We want to specifically assert that the addresses in the 0x8000... + * region have a shadow, otherwise they are considered by the kasan + * core to be wild pointers + */ + if (addr >= KERN_VIRT_START && addr < (KERN_VIRT_START + KERN_VIRT_SIZE)) + return true; + + return (ptr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); +} +#define kasan_addr_has_shadow kasan_addr_has_shadow_book3e + +#endif /* CONFIG_PPC_BOOK3E_64 */ + #endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index 80382a2d169b..fc49231f807c 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -8,9 +8,11 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE) KASAN_SANITIZE_ppc_mmu_32.o := n +KASAN_SANITIZE_fsl_booke_mmu.o := n ifdef CONFIG_KASAN CFLAGS_ppc_mmu_32.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_fsl_booke_mmu.o += -DDISABLE_BRANCH_PROFILING endif obj-y := fault.o mem.o pgtable.o mmap.o \ diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile index 6577897673dd..f8f164ad8ade 100644 --- a/arch/powerpc/mm/kasan/Makefile +++ b/arch/powerpc/mm/kasan/Makefile @@ -3,3 +3,4 @@ KASAN_SANITIZE := n obj-$(CONFIG_PPC32) += kasan_init_32.o +obj-$(CONFIG_PPC_BOOK3E_64) += kasan_init_book3e_64.o diff --git a/arch/powerpc/mm/kasan/kasan_init_book3e_64.c b/arch/powerpc/mm/kasan/kasan_init_book3e_64.c new file mode 100644 index 000000000000..f116c211d83c --- /dev/null +++ b/arch/powerpc/mm/kasan/kasan_init_book3e_64.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define DISABLE_BRANCH_PROFILING + +#include +#include +#include +#include +#include + +DEFINE_STATIC_KEY_FALSE(powerpc_kasan_enabled_key); + +static void __init kasan_init_region(struct memblock_region *reg) +{ + void *start = __va(reg->base); + void *end = __va(reg->base + reg->size); + unsigned long k_start, k_end, k_cur; + + if (start >= end) + return; + + k_start = (unsigned long)kasan_mem_to_shadow(start); + k_end = (unsigned long)kasan_mem_to_shadow(end); + + for (k_cur = k_start; k_cur < k_end; k_cur += PAGE_SIZE) { + void *va = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + + map_kernel_page(k_cur, __pa(va), PAGE_KERNEL); + } + flush_tlb_kernel_range(k_start, k_end); +} + +void __init kasan_init(void) +{ + struct memblock_region *reg; + + for_each_memblock(memory, reg) + kasan_init_region(reg); + + /* map the zero page RO */ + map_kernel_page((unsigned long)kasan_early_shadow_page, + __pa(kasan_early_shadow_page), PAGE_KERNEL_RO); + + /* Turn on checking */ + static_branch_inc(&powerpc_kasan_enabled_key); + + /* Enable error messages */ + init_task.kasan_depth = 0; + pr_info("KASAN init done (64-bit Book3E)\n"); +}