From patchwork Mon Feb 25 13:48:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828595 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 BFE201390 for ; Mon, 25 Feb 2019 13:48:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED182B723 for ; Mon, 25 Feb 2019 13:48:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2D882B725; Mon, 25 Feb 2019 13:48:43 +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 1E7B12B723 for ; Mon, 25 Feb 2019 13:48:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 192878E000C; Mon, 25 Feb 2019 08:48:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 11D558E0012; Mon, 25 Feb 2019 08:48:39 -0500 (EST) 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 00B438E000C; Mon, 25 Feb 2019 08:48:38 -0500 (EST) 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 9E42E8E0012 for ; Mon, 25 Feb 2019 08:48:38 -0500 (EST) Received: by mail-wm1-f71.google.com with SMTP id f202so1266945wme.2 for ; Mon, 25 Feb 2019 05:48:38 -0800 (PST) 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=XoNu5UKdQv6Oj1+txTayOhAazQZhJqCtOSMVXLNcft8=; b=eRQZkDGcW7mfZNf4an3bDS4wTIx8jtRCYSklQtJgHwNaSSJRy70EHE324+RLtfu4vF yqtVp90SxjlYrynnmUU+taisAli61qWKr2gkdiHbXSTuB1uPzQd51fS1snOOy9w2TJWS Uzj7Ss+lw27atXL/4tXj0fuMzFdxvGuOSoiZ1MLs2XkY1d0HZisuHnCXQ0XR8H6UsXAD QJFD30L/VYjKYsKOXSMXeydE0PUUlc7O9mwW3slxxBq1fMt36xzemoYrygvfS6vNgXur UZ2bJBddq+dWjWuiFUHYp7LLH7jekMJlHX8ZQi849dxlHVHC32oW3mOvAoEkGAH/H/Wj NIHw== X-Gm-Message-State: AHQUAua3E7jPXMZVEqYStBrfU5VTM+be6VCyRdogC05dbuCmTnu3xC4k 9vp2yJdzDjBWyuUpeRf5RXC4cAHJM5OLAaKadogr0LamJoSjh4R+7RJpxNWnjqjme/Rd9V4mnIY usf1q6hhTvQDoGmAlB+pUiM6mIzdxw957zVHxkR8pLN1/9cFcaVEMhXDpvEPoyQOVAA== X-Received: by 2002:adf:81a1:: with SMTP id 30mr2549810wra.285.1551102518106; Mon, 25 Feb 2019 05:48:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IZARJg5PCE3SznFmieRcP8Xy4uXXCn6Mbl7mQ6aWL+YcU0Ms3NrGhd365bwiAveVhOLMwcl X-Received: by 2002:adf:81a1:: with SMTP id 30mr2549764wra.285.1551102517073; Mon, 25 Feb 2019 05:48:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102517; cv=none; d=google.com; s=arc-20160816; b=eSAHmJRcANcrTITyX7UrhVfl1EZtUinmHq5Ai5J05x61a3MD8eW2sw+DA7U/9lBaRc oxZUF2NpDYZUA4RCg/1s+QoZ2sMsLjuyVvVX1b3i+1tubelViIbL3IracUQDd0XNerrx DamjuwfvnG/TGz9sSg3/cylXZrG0KPLeDJH5stkcePo7RP2qUIqaX9sYs78pSrAZr8ww OlQxi5iqFErr5vxhZkE/nQ/RWPSLq7H//YYOHNgXhOz6dWuBznW0X0csRDu2ejTqz0Fx FOuYzba69dEbe5IEknRwNWIn4EYHtQS1kGJLaQY4Z1G0dB7VUkddGSgPdnb/rorgjn1n Qadg== 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=XoNu5UKdQv6Oj1+txTayOhAazQZhJqCtOSMVXLNcft8=; b=roLHiNhO7XZ6djCVdTXgFKvcdg785xI/BUkv/VVnk9aGr1/CUbjD/e3W+pXsLh0I/B xKyVzvxhgFXkKD3PLY98Sfn8ch1yXyAGKdn18QvQzUqgjxXlu1IjoNvWRO5KntmigEF4 bAP0ZEFEFMol3l2Pt0XlEg7YnU0QcKC7VuYGnYI29F798jhw7lVLCVfFx7Nq1Bm+S654 +HnuQGhaBDhkUdVVvvM38M3t7gENBkKrJqnZMz9YTcVm0fEOj51hYEQzzyJw77xmhl+u pyw8gYhqszGLyYz7WFJUAJl9XY1fgf9T6CwqfR37Z4cacI+qtXdu7qSgIcT9SJ2MxBM6 uSRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=obBI6q3m; 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 o3si6279894wrm.298.2019.02.25.05.48.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:37 -0800 (PST) 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=obBI6q3m; 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 447NZR4vl2zB09Zq; Mon, 25 Feb 2019 14:48:31 +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=obBI6q3m; 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 LA2tJU5tYAhl; Mon, 25 Feb 2019 14:48:31 +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 447NZR3fQhzB09Zn; Mon, 25 Feb 2019 14:48:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102511; bh=XoNu5UKdQv6Oj1+txTayOhAazQZhJqCtOSMVXLNcft8=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=obBI6q3mX7+YpW9Y1c9Gl/ovw23rGdr62p/kAFWaA37NLWH+t9POXaLmL2e6rJnKx qM3DYP2B/GrpF4gFyVfNANCC2a7gtchgtRhRjYVB/mkKH513liSWVG0+mu8gyEPqSp O/8yt7UhWdVeWXNBIzqrN1Dxn2aPnrK3uGcZK9uA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D1AA78B844; Mon, 25 Feb 2019 14:48:35 +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 ArQiIcXbIiqH; Mon, 25 Feb 2019 14:48:35 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A205B8B81D; Mon, 25 Feb 2019 14:48:35 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 428856F20E; Mon, 25 Feb 2019 13:48:36 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 01/11] 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: Mon, 25 Feb 2019 13:48:36 +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 | 38 ++++++++++++++++++++++++++++++++++++++ arch/powerpc/kernel/setup_32.c | 28 ---------------------------- 3 files changed, 39 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..99a3d82588e7 --- /dev/null +++ b/arch/powerpc/kernel/early_32.c @@ -0,0 +1,38 @@ +// 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 1f0b7629c1a6..3f0d51b4b2f5 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -63,34 +63,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 Mon Feb 25 13:48:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828603 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 810981390 for ; Mon, 25 Feb 2019 13:48:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF2A2A6B6 for ; Mon, 25 Feb 2019 13:48:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BEAC2B723; Mon, 25 Feb 2019 13:48: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 6E1C92B721 for ; Mon, 25 Feb 2019 13:48:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D5548E0167; Mon, 25 Feb 2019 08:48:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9354F8E0155; Mon, 25 Feb 2019 08:48:43 -0500 (EST) 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 802488E011F; Mon, 25 Feb 2019 08:48:43 -0500 (EST) 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 10E688E0155 for ; Mon, 25 Feb 2019 08:48:43 -0500 (EST) Received: by mail-wm1-f71.google.com with SMTP id t133so1446475wmg.4 for ; Mon, 25 Feb 2019 05:48:43 -0800 (PST) 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=aZargV6nO712fK9s1js2k48oU87IFWvTxERGiBvMagQ=; b=lvx3RdHqjEtnxm5LfB1K1I9pzl3kChJXGfs8dfjU7T1mTqslitBfKrngzJRPN0cUpC dmTVsaYYQkXayc3AER9JqehhcvOOcCYxMHO1GxwnLnaT/I9MtA8gK1FNsHHgjElKXV+R ocjxX1D7+OK0/VAEmD2mG5o+oZhOqW+CUoURLv3x6i61gs4TRKqMUleSSGVGceOS+U37 2uBf8tEath/kr0JXD9DYrZQ49jrucW38vDa4imNU2qkMJ8HFt4jVuJxiQxspKJCvzMSe 0Plx8MjXRP7IVtU0FdKvj3mF43QdGZdK9/RctKYpmSTmc2HtXjjfDuLbFBAhU5jCHGwh Jtvg== X-Gm-Message-State: AHQUAubcxLUcbTCDkDGw1WZTb/niro6oO/TAZqUtVKZSEsI1NJiwPfYB LQkTSgH48aEMRis7kNjWMMMyZEwwzHea4R4t2tBs3mKPKw1wWAPA/9LL84jZ+hW2oOVRyTekWuO vN5Dy8ydwFxld2RnMMCTXSyiGr+czl+QAcTvy0s44XqcU50+iTo8WzMnruhzjgW/XLw== X-Received: by 2002:a5d:6983:: with SMTP id g3mr13105531wru.286.1551102522573; Mon, 25 Feb 2019 05:48:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IbfR9maQtx1dKpMZr5AfY/DcuElkwUFh2EnmsNRkvewBfZAxd3gpJQXtdp9caJyw0kdfPPz X-Received: by 2002:a5d:6983:: with SMTP id g3mr13105474wru.286.1551102521332; Mon, 25 Feb 2019 05:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102521; cv=none; d=google.com; s=arc-20160816; b=OA4KFn8aPNaJ1oA8LUofkfA70cp9QZuK+7ai2mQ3z+8TX3w89Llv+W2FMf3OghqHHn 4hxsA6gYHdWRoObR3gulQoQSJVuCYDhR2T6G0yaJIXI9a6NtK6gDADLvm7v9ldNS6B+5 A7eSn8RWJynaf0DTKeTDxajQdjsYo9qE0Wk+tRq04qXQFRxhN4Lj+4zIdaR0qCIwDtSK Gn8A3d0gF/ITwHMNJJodHpsuItne3DmXDQDCQLn6ANfwwQ2XrrPSNyPtzRjLTAtrwekU XiASf+x3cQa6go3KZN15DPRELPsev4Kpu+4QzLdwsBNyr0xL1iTnI093fdlOt+Bv144O hZgw== 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=aZargV6nO712fK9s1js2k48oU87IFWvTxERGiBvMagQ=; b=D6CkBnXZkvAbsGwZ/Dt8vgy9MExEIwWoQQ0IqUCXhSxEdhd/Foux5O94zUFut3EmIA VjbAaP0mVsl6veVGk0yjT4VzudFH3p61Po10z8zJUp0aLxzYmVWp75PFaMQOAwDXlpQr 8f70v3l1xazHtoYokp0APRNJPoi2+hZ7MER2W3t6lDCO7OpTP0ZxIsRCjhIRM1+7Dv4t dwZriGU+qxJ+4q/QclUX5+zVSvPdsvCmhz0fhoyUScN0gj02nd/KNTulSO3LxX3sL9gm dg66koMQFfJnPWZnHVjvn1/BlCH5dlWy8MZJwg0i7s9PFbeu7zZ8i3vAet5ScmydIEE0 Mxgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=nvwKIEsb; 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 v13si6090371wrw.391.2019.02.25.05.48.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:41 -0800 (PST) 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=nvwKIEsb; 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 447NZW66ZMzB09Zw; Mon, 25 Feb 2019 14:48:35 +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=nvwKIEsb; 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 qw8s9DifD9YA; Mon, 25 Feb 2019 14:48:35 +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 447NZW5105zB09Zn; Mon, 25 Feb 2019 14:48:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102515; bh=aZargV6nO712fK9s1js2k48oU87IFWvTxERGiBvMagQ=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=nvwKIEsbciM206cBDTafGGQNmyOLTokA6n0J4QnMc0jMUQpXLEZD4rSeEjnl91+0m BWsgKxEWPDfwyrT8zlv8rNGG0GeqzBKz6G4kLYZwW6kC0inkehDgZ+sh3G5UNm7nMh LSiLq89GRl2+dOFrBX19hzAh8NFa/Af2UBuM3X/A= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 063918B844; Mon, 25 Feb 2019 14:48:37 +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 P6_LQaMFCa2m; Mon, 25 Feb 2019 14:48:36 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AE13A8B81D; Mon, 25 Feb 2019 14:48:36 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 49F0C6F20E; Mon, 25 Feb 2019 13:48:37 +0000 (UTC) Message-Id: <42ee601ffe33df4652808b09caae6824edf1b667.1551098214.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 02/11] 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: Mon, 25 Feb 2019 13:48:37 +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 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 | 15 +++++++++------ arch/powerpc/lib/mem_64.S | 10 ++++++---- arch/powerpc/lib/memcpy_64.S | 4 ++-- 7 files changed, 78 insertions(+), 19 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..2efd0e42cfc9 --- /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) .weak fn ; _GLOBAL(__##fn) ; _GLOBAL(fn) +#define _GLOBAL_KASAN_TOC(fn) .weak fn ; _GLOBAL_TOC(__##fn) ; _GLOBAL_TOC(fn) +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) ; EXPORT_SYMBOL(fn) +#else +#define _GLOBAL_KASAN(fn) _GLOBAL(fn) +#define _GLOBAL_KASAN_TOC(fn) _GLOBAL_TOC(fn) +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(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..fc4fa7246200 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 @@ -150,7 +153,7 @@ _GLOBAL(memset) 9: stbu r4,1(r6) bdnz 9b blr -EXPORT_SYMBOL(memset) +EXPORT_SYMBOL_KASAN(memset) /* * This version uses dcbz on the complete cache lines in the @@ -163,12 +166,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 @@ -242,8 +245,8 @@ _GLOBAL(memcpy) stbu r0,1(r6) bdnz 40b 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..aa02a0abf96c 100644 --- a/arch/powerpc/lib/mem_64.S +++ b/arch/powerpc/lib/mem_64.S @@ -13,6 +13,7 @@ #include #include +#ifndef CONFIG_KASAN _GLOBAL(__memset16) rlwimi r4,r4,16,0,15 /* fall through */ @@ -29,8 +30,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 */ @@ -95,9 +97,9 @@ _GLOBAL(memset) 10: bflr 31 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 @@ -138,4 +140,4 @@ _GLOBAL(backwards_memcpy) beq 2b 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..2d5358cee711 100644 --- a/arch/powerpc/lib/memcpy_64.S +++ b/arch/powerpc/lib/memcpy_64.S @@ -18,7 +18,7 @@ #endif .align 7 -_GLOBAL_TOC(memcpy) +_GLOBAL_TOC_KASAN(memcpy) BEGIN_FTR_SECTION #ifdef __LITTLE_ENDIAN__ cmpdi cr7,r5,0 @@ -229,4 +229,4 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD) 4: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */ blr #endif -EXPORT_SYMBOL(memcpy) +EXPORT_SYMBOL_KASAN(memcpy) From patchwork Mon Feb 25 13:48:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828597 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 9AC6D1390 for ; Mon, 25 Feb 2019 13:48:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8781A2B721 for ; Mon, 25 Feb 2019 13:48:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B8342B722; Mon, 25 Feb 2019 13:48:47 +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 699BB2B725 for ; Mon, 25 Feb 2019 13:48:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 174828E0123; Mon, 25 Feb 2019 08:48:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 05CFC8E011F; Mon, 25 Feb 2019 08:48:41 -0500 (EST) 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 DF2808E0123; Mon, 25 Feb 2019 08:48:41 -0500 (EST) 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 6DB2D8E0012 for ; Mon, 25 Feb 2019 08:48:41 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id o6so4907064wrm.2 for ; Mon, 25 Feb 2019 05:48:41 -0800 (PST) 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=0QUiUDKjGToLpkzDPACzHo0JlotDF22Jf4TM6PGaWLw=; b=uYw8E6Wz5cQjm9tGF7tJd2bLL14UWC6lb3kXMxcYyidk+3UERyXKpiAgBTqpN9Wo5Q dmxbjnGwL97RiMHgYiiowi8045HGyjQWhG7oDQia9mbZWRecaGPqrZNuiMzDemQ7qwmK 0NOTlarvehGDJYkmKrhCmTs+uUbSZ7hTSfpVI9pEGJCkRX9euvIFpEf6/TBFzA+TJni9 I8vZb42dGRPjPHoo2zo0TxfR6bYUFjznS0t6eRvwZRAsyFoF8Xw0a9Amm3EvgQXfy0QH 23XlWsVSBfSjvVINn7GsIUCdhNHKmp+ttHqNS11taBDs/R0PGqRANN2sLcDscDfJjXNA GROg== X-Gm-Message-State: AHQUAuYOyF6O78Y4qG6UAN2qjWeMU3zjT6/U1JPrAldVx0oWD0oXSlJp 8ar+93tJJOYMCHoe/c/zUKCOiCH2II/hQljZ/iH0GQchwzwaqbMCQjPg5p8yK/HY1M4MmWpgAUv 31eh9FuSmwsl3roXs+VdPmldjL+jBH3BdAJYo+F+2xv5Q93Fl6vKRyegVQAliipLqtA== X-Received: by 2002:a1c:39d5:: with SMTP id g204mr11174439wma.17.1551102520921; Mon, 25 Feb 2019 05:48:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IaVuocMRfHcXAkMEMz2C9pZY48FYb0WTxgnSfhv72EgtdZuOCDaOzSXg1FCeeKp7TXreaTF X-Received: by 2002:a1c:39d5:: with SMTP id g204mr11174367wma.17.1551102519367; Mon, 25 Feb 2019 05:48:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102519; cv=none; d=google.com; s=arc-20160816; b=h2G/XWg79vWnh7qDvjQQt9v3MKUomTwur+oD5dr+8R6KNlkrRcY0Kjj7O1t3BwB9ou P8IYfrz6FGQTimOgLRYlEKrWFfuD/yvcMo6sgoXaFaTxB+SwDdIGN2WkdTRsuUZX5JRt 7FlshYxrAI9N9NndqPECQbZEG+DqfUgm1Im8fLtBfjU9MlfVPtBQCfPMLcqaXOMP5Ium L4mZBasREnF7u4Brbt/ZL7c5jGhDPawqlzvZUlcH8k/tOyTP1unGqMpVb4x58OaEi49/ QPvmnKCcBCLmHyOxpCv9CPyobRMmgVOJWooRpNf9CRbvM9gLYw3jO5JaIzA5MfbMCzUN 2Y8w== 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=0QUiUDKjGToLpkzDPACzHo0JlotDF22Jf4TM6PGaWLw=; b=t8wjosLk3JbDycQOlg37ZicIVxHAK3FeRZxG4oHzj6YZ2voXAblCunhMIsQ/Gugfkv rinHMyQmAGO6AlmmfMoQHQZFNoGWwC6jXx6S5jWT/16P9XXM6QS7yq091JDN5yt6nE8R AcqRXorlAGkPYVIjaauHGnjI7cleyivL3PxeUTQzh7w123RrgDfZTmSF/tKb+0dT8/kC gOYbIsoWZ9+5AnpHoolsP4Liz6y1wRRH5VvA6p5oB6NCqr52sC7LHKdQokDt3XL0KOmk 76YoVl/p6CcX6QKO6k7aqfNz/Muk7I9tZEBDFWokMR3mg56B7VIGq5Iq2TDQx6nhRd+U Tdww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=T2pLmr4F; 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 v6si5459524wma.200.2019.02.25.05.48.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:39 -0800 (PST) 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=T2pLmr4F; 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 447NZT61jmzB09Zt; Mon, 25 Feb 2019 14:48:33 +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=T2pLmr4F; 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 FoZoWxWDSv7o; Mon, 25 Feb 2019 14:48:33 +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 447NZT4qsNzB09Zn; Mon, 25 Feb 2019 14:48:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102513; bh=0QUiUDKjGToLpkzDPACzHo0JlotDF22Jf4TM6PGaWLw=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=T2pLmr4F6h7g+Ms6CrWZexuhm1G60VD86GoLOvkhB8KLc0m9vNTGMAwirGLmL/zlW MBVO+1JlwGa37QI3ODnS3fIpX4KDXhN8/cb5OkfoRbQoRHAsxkmU0yr1g62/GUooGz av6RVO2IKkQDT1vJQ6H2rE00/taeUeNYbdtRcGXY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 052EA8B847; Mon, 25 Feb 2019 14:48:38 +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 moYkSILUSqXQ; Mon, 25 Feb 2019 14:48:37 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BEF488B845; Mon, 25 Feb 2019 14:48:37 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 5CE4C6F20E; Mon, 25 Feb 2019 13:48:38 +0000 (UTC) Message-Id: <3e9b360164c9a7eb4550c28161859121622b750c.1551098214.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 03/11] 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: Mon, 25 Feb 2019 13:48:38 +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 | 213 ++++++++++++++++++++++++++------- arch/powerpc/kernel/prom_init_check.sh | 2 +- 2 files changed, 173 insertions(+), 42 deletions(-) diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c index f33ff4163a51..56d5639ab082 100644 --- a/arch/powerpc/kernel/prom_init.c +++ b/arch/powerpc/kernel/prom_init.c @@ -224,6 +224,137 @@ 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; +} + +#ifdef CONFIG_CMDLINE +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; +} +#endif + +#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 +686,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); @@ -639,25 +770,25 @@ static void __init early_cmdline_parse(void) 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, + prom_strlcpy(prom_cmd_line, CONFIG_CMDLINE, sizeof(prom_cmd_line)); #endif /* CONFIG_CMDLINE */ 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); @@ -669,13 +800,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; @@ -1028,7 +1159,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 @@ -1475,7 +1606,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)); @@ -1756,19 +1887,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; } @@ -1917,12 +2048,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 */ @@ -1998,9 +2129,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 @@ -2033,7 +2164,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); @@ -2043,7 +2174,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); } } @@ -2064,19 +2195,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; @@ -2093,7 +2224,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 */ @@ -2155,7 +2286,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 :-( */ @@ -2259,9 +2390,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; } @@ -2294,7 +2425,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; @@ -2306,7 +2437,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; @@ -2375,7 +2506,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; } @@ -2406,7 +2537,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; } @@ -2476,8 +2607,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"); @@ -2799,7 +2930,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"); @@ -2807,13 +2938,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 Mon Feb 25 13:48:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828599 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 BF1F41805 for ; Mon, 25 Feb 2019 13:48:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE9622B722 for ; Mon, 25 Feb 2019 13:48:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2EAC2B724; Mon, 25 Feb 2019 13:48:49 +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 47DB82B722 for ; Mon, 25 Feb 2019 13:48:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B0318E0012; Mon, 25 Feb 2019 08:48:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1758C8E0155; Mon, 25 Feb 2019 08:48:42 -0500 (EST) 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 E62D28E0012; Mon, 25 Feb 2019 08:48:41 -0500 (EST) 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 8DC078E011F for ; Mon, 25 Feb 2019 08:48:41 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id m7so4841591wrn.15 for ; Mon, 25 Feb 2019 05:48:41 -0800 (PST) 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=iLXoe++LpfSUvqcYYiqGhOwnt7UpGCD6RPQAh5w5AHX9Xu3PnSuRENyPMU72E0PDIx BS7wGidzPDE9b9F9bEYkkhA+Svfm4z+672XBSzOO0tXWenNIMOmX1F2bqiSqClt5XlHi Hh4dNVDtcXykl46u4tzWeBhVyGZvZgyucQYQn8bizDcFPm8BqszCvzjOziWP6wEZIr7d XpFMco4CJ9TbK7xhMVZ/6tvHdbTiH3Bl3QUXH318T6Vdgqj2nSEwnFocwv50AcqxIs/t DvWl+R0QN5miBM/eoRpk3XnM7A/UdGGPq+/4tFrczFvQ/DMd0LHavFJMLnPTF6+H7oJH 7qtg== X-Gm-Message-State: AHQUAuaf1HCqa5E45v854xwfvkMXs2cLUdoVrwkymWSU+RMw2uM6Lt6E y/1E/7Cd/4Yw8tnv9qLBrftkWb+gSJ1F2lhME3NlPhFR0zuhuvef2m9CcbheNd3SkwCIkqqAWgo USv5dbDZeQoE4MI90clH7xVH8FuJxjPptom3vCPZXrXBhfE0QnJ43OvWUKYsbbW+Czw== X-Received: by 2002:adf:f011:: with SMTP id j17mr12880495wro.166.1551102521130; Mon, 25 Feb 2019 05:48:41 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia/lxx+1JeZzYUXryv+LuRY9lhpeV5tKekDH8xNUV1Ze5GEJb6QoPGhzxutGFcByuw2gHwr X-Received: by 2002:adf:f011:: with SMTP id j17mr12880454wro.166.1551102520304; Mon, 25 Feb 2019 05:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102520; cv=none; d=google.com; s=arc-20160816; b=B04W7NyISqOxRnCmyt+2spDAOKh4fMjTmrjBEAvOYyOWvxQ12/CCNfK/OnT2jDeoIn wZCIAsHNVbJ9N9ECW3ZKwgcd+LKDBQve2a37D/SzHk3OMgR/8tGTb4/hvzp7XeylddK4 Bpg9TDusJTwLVSCIKee8t1MD6a/xsMzosvEAg4VD0RGJr6eOI3YrD3lMq2aGVB2yN+4G R0J3j4REI+8xyFCrzIVWtSauJrF+bTdhP4tcBw3UyVYyC1uFwcZf6h4QT6jtWKTtHlpv R+X1CTvMuMybjdLdG6pOFz/AvMbYYcOV7QCJWNs3DSIk1ckrmn8+gRW8rXnD+6XnF0XG 0uuw== 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=AMXlIsp9bdrbt3bJfqQ0daVOTOAMlbE0sS2ZQB9htc3lkhuk35+rbR7uwGPZU+DbB8 LfwnSt/EraQlR1Y2RvemhRK8B2azzOZvmt5AvRSP2c8knSyYGGNsaFU3XO+B1uxSojxW 1BUm9mJSeTFQinvzRXlodqRUPNE7BvpGXCvOzgGKTq5uL+ORmhQ2maMpZ+anUsAl/hoY Ap/HM8Qg0r1GSJwltOx6tRp82UyWUIV9TTPplppSj1Gf1SFI3B6D4sALBtGAM8lbHskj WQbz2cn//4JRP78eTjHYJ/zDhoxN3hcXknKJSjRKMnhYsCwQU9fd9YD8i6dg84TFufla jftQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=UzkSBnS+; 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 x67si6065194wmb.146.2019.02.25.05.48.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:40 -0800 (PST) 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=UzkSBnS+; 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 447NZV5z3wzB09Zv; Mon, 25 Feb 2019 14:48:34 +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=UzkSBnS+; 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 hTlR81ImJoUe; Mon, 25 Feb 2019 14:48:34 +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 447NZV4w2kzB09Zr; Mon, 25 Feb 2019 14:48:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102514; bh=g6fhwCUzzCOYhxsR7m9Lo9kcYtSGDH5kmO2yLp27uXY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=UzkSBnS+Z5+G8J5VD7TdE2eK6NIJPyTkS3M+LJmSylXmyqBTgWGwRp+kVOMuc3HMi ctQJPSKxGzqpl6MwU8jVGxp2V7PCF+Xv0uoIWeuoHWdrmadjKwNqaEs/j0SzmGiwcQ wcDy1+g50u+XFQYFZNriC0NaE+eKSGjGQ0MlmOP0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 069058B845; Mon, 25 Feb 2019 14:48:39 +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 9NJRGqyfSr0c; Mon, 25 Feb 2019 14:48:38 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CEE168B81D; Mon, 25 Feb 2019 14:48:38 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 620FB6F20E; Mon, 25 Feb 2019 13:48:39 +0000 (UTC) Message-Id: <0eb4945efb0475cc6d42a3f6ed5aa0f342d5fa22.1551098214.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 04/11] 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: Mon, 25 Feb 2019 13:48:39 +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 Mon Feb 25 13:48:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828601 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 A47EA1575 for ; Mon, 25 Feb 2019 13:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93C022B722 for ; Mon, 25 Feb 2019 13:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 871492B724; Mon, 25 Feb 2019 13:48: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 2E8752B722 for ; Mon, 25 Feb 2019 13:48:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A3038E0156; Mon, 25 Feb 2019 08:48:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 42B258E011F; Mon, 25 Feb 2019 08:48:43 -0500 (EST) 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 3407A8E0156; Mon, 25 Feb 2019 08:48:43 -0500 (EST) 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 D1A638E011F for ; Mon, 25 Feb 2019 08:48:42 -0500 (EST) Received: by mail-wr1-f71.google.com with SMTP id s5so4757659wrp.17 for ; Mon, 25 Feb 2019 05:48:42 -0800 (PST) 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=x5Dwfe9pBn0jiYAytmPEco/+5u9wkUq+xY/xh4B++1o=; b=m/f5p6N/lFjEWzOdUgcaB9/2mrGydahbxMi0oeEEGqFBrmJ9O0B1ypIQsiu4uBwy41 FMEovepkO7X52Nl/qzQQWquxFw5Udn+9fkCqtcvjgs+0Ss6mDnq24KsQlrHLMUMkxoy1 srN8RUwlI/MKtvmO94+EsgdLZq19j2mpM/4tNDBO95FiW4nq4bgsBJse///e9hL1aWXf Oo33eAatOePXNQBn+wdaVBEkp/Ta48HDYOhj2lIzfQO1QwLFcYEter0HnLDkOhz6WW/f GUlsM0cFxf4rjC5v3JoAp5kOpmEj6Ca5by8D4o/tYTF0c3wdPuNmUuvf28dMEVAfU9BU Ucmw== X-Gm-Message-State: AHQUAuYCrQF2K/0j2v3JiEiTCj+KEby8gN6SBoOo8oV4Sks5ZPe31SQ4 cPe2XzLFIWDSzu9f7OWAm9RsBYaeq1ZNlRl0O6KiJO7BCyUbs6lFwVbY1Ja1YTa51TjF1/q/U5m 3PssJwgr33UrtrDtdA0QHdr7RaMTnUxDTI7jDRJIrx0Z2RL7XNFJ0g620mBOkahV0Iw== X-Received: by 2002:adf:c3c5:: with SMTP id d5mr12192470wrg.308.1551102522350; Mon, 25 Feb 2019 05:48:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IYXN2ri3Rf891Em7SWT6ECyNvgxa4cRkaLeA/5XdmRtkyXTW+SlgxXfnbprjRnTlCgDcdpY X-Received: by 2002:adf:c3c5:: with SMTP id d5mr12192432wrg.308.1551102521473; Mon, 25 Feb 2019 05:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102521; cv=none; d=google.com; s=arc-20160816; b=K0pi1oBF8gPxDG/uBwAG1nGhGATZGhhfjUXL/qUaDxtCtdYweBX762waBxZq7WFiW+ Lt+LOeqPHOzEJ63or+5FdnQa26NSPzqkO8YZrWBsajzUztRI6NrRO3xo1diSm1N/Bgly D9bCN7z2RIVbjAdJhvt7gAbdbr53yiPPeSh+OrjjtZkWK+Co0KV72jJO+cq3Hzxun5Rt 1TpiLVaZFkZaagE+OzrzFRIJ5YIom7ORVvPfmFQJORqGTQJRyVNl8C3l8O6ECXexr6pm k/niKWRTWYDHcFcRGZECTdQjjedPsuarrOsIN78rJBSscmZ28Mt8WikHOn8/ws38EW87 nMxQ== 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=x5Dwfe9pBn0jiYAytmPEco/+5u9wkUq+xY/xh4B++1o=; b=HYK0zlb0DlH/IMXejusc9zXSRsl2EB2Lb+jeJiHX4r782OaKo9SYWGEli0JFPzJMIr XNdM6YlKl9veUMfdTDE0Fw9av7P43gX+1+SoyZeP7Bj/5mzYaqY4HuNe4leRJ4YqetWJ wYvUVw03LqZLe27Uph0JnS7rq6OSIB61ZUdHpxmKi4kZIjsg9dmsEEiPWfvM29PtmoOP ydb9OoK/YRVnzGZHAIDcn4blViplEADJAAshOfq25MiClwk6xMnZfpnQMFNgMkMd0rd4 3ELKTpB76wnAygQ6gFvBBphviGFQv8HzLRYKaLB6MmLuRrq6E6F+OFB+OisrRniTfiqn GwbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=InB4Rtmw; 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 f17si3261647wmh.24.2019.02.25.05.48.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:41 -0800 (PST) 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=InB4Rtmw; 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 447NZW6sbhzB09Zx; Mon, 25 Feb 2019 14:48:35 +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=InB4Rtmw; 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 KITX66fVEf2E; Mon, 25 Feb 2019 14:48:35 +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 447NZW5p8YzB09Zr; Mon, 25 Feb 2019 14:48:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102515; bh=x5Dwfe9pBn0jiYAytmPEco/+5u9wkUq+xY/xh4B++1o=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=InB4RtmwYoK6LQaYlrN8w0doKaOvX/dKEXYejh8RpF/WfWvvN1AmsYBpLQeY0du5P mHTbB12/X5l5xY+VNueAh7CFB1/SwNTNFtQdGnGXnLuESiXoeAUK33+mwiqOqM8RnU C0HCq8V7Zb6ojSSYHw8fSFHia6p5TXhYZ5xCE+ss= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 110048B849; Mon, 25 Feb 2019 14:48:40 +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 qbr4j7dF2fny; Mon, 25 Feb 2019 14:48:40 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CD30F8B847; Mon, 25 Feb 2019 14:48:39 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 67C2A6F20E; Mon, 25 Feb 2019 13:48:40 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 05/11] 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: Mon, 25 Feb 2019 13:48:40 +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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c index 99a3d82588e7..3482118ffe76 100644 --- a/arch/powerpc/kernel/early_32.c +++ b/arch/powerpc/kernel/early_32.c @@ -21,10 +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 Mon Feb 25 13:48:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828605 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 0737A1575 for ; Mon, 25 Feb 2019 13:49:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7CB52A768 for ; Mon, 25 Feb 2019 13:48:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D799C2A76C; Mon, 25 Feb 2019 13:48:59 +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 622172A768 for ; Mon, 25 Feb 2019 13:48:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 149FD8E0155; Mon, 25 Feb 2019 08:48:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D1D08E011F; Mon, 25 Feb 2019 08:48:44 -0500 (EST) 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 F011A8E0155; Mon, 25 Feb 2019 08:48:43 -0500 (EST) 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 99C918E011F for ; Mon, 25 Feb 2019 08:48:43 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id 92so3688317wrb.6 for ; Mon, 25 Feb 2019 05:48:43 -0800 (PST) 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=QhQmZaAZJZ69E9F/zZFRmLWd5K/IsYQno7oOFU3XPxU=; b=Wj9uM9fcXHpQqNMzFWYvJGDkL5BSIoESTr+S80LOdXgrZwt0AHrspHwAGog2iXaGQ7 VfdcAUQGv1UOT4Zkrr01RCMPXWvPE+M1pz6KhmCgsrmPKraOpc+eGn2AfafiCa3m8x1E ZaebE7TzIZHvuwVum06ywNS4Kt31ICXKPLbMsq48ao2OWJPmSdpo/25ejAg6m16D+TQl XjNLQlgjDr8qJepg0LpszN8TVpKguXNfBzr6PKGPT104bVy9mkaemt+5M7RmJGQw0IE9 oOTbOyIne2Rk3fhBHPG917hYLQCIxmQgh3nMRvQbUFm4sbIBW24gEdRXvbcFbrv4WiWN 0YNQ== X-Gm-Message-State: AHQUAuZEQx6vOmwCoYeq5R6gW/ufDKZnhGPzowh3d8prWR2oSDU4wJtO bS0hWoES4bRbB2Uivlq1xZ/mn/hX3lAqWjyScbCDX9uuwk6Kzf8LDUCIOGnUGpK2mTyta76z5tw 57wm3IGuKcp/t9+3WmXFk1ssDX3pLQwSHoR4jxVjoee/xFma24czlFDvr9p7ExJgS7g== X-Received: by 2002:adf:deca:: with SMTP id i10mr11988792wrn.312.1551102523172; Mon, 25 Feb 2019 05:48:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYZX5ZTyFFaJGiBLHbkx8YKfIlBDTjOgJFff9m2B4561AN7u/fbmizBkru5/hnjIfMItB07 X-Received: by 2002:adf:deca:: with SMTP id i10mr11988756wrn.312.1551102522266; Mon, 25 Feb 2019 05:48:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102522; cv=none; d=google.com; s=arc-20160816; b=V++9LXL7KTPs5Gbfmw7QDi5ClaLHtYekLBJHcSSEJbHDEwfICUfkhWLGDTn3EdNIS8 fNUihok21iCJv29ENDcYiu6FvP3qJ2zxpOHcm8efGsspIntlccmVjW7mj6ino2t05reK Shs1NXagQAVPFrYM9lBMv4I89twNr1ghrnI+U+EwiK6YFUAdT0SXkTx8wVa1oOiwliU8 LK5QpGeB7jB/2VrxEWZCMB1UoTTubtDcGkt4XRAN05X6iSfVrI1uNbwJTQJeR8YXlmzD o2P3lVDBC+bxpGr5t99vmukv6sEvpIhWfObZg/IuySvghp8b0ibALrDZGXaZ1ud2dCNG hvPw== 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=QhQmZaAZJZ69E9F/zZFRmLWd5K/IsYQno7oOFU3XPxU=; b=yky3BJf5cL8r45LxD8zkpSwMOgR/F+J2PNDCGSgV0MsYe5+7dtbkGDYmbhVIke5OJ0 UQwa+GODAxn6f0POMtRPcBhAbN71wcmna5tLjMFO3iiJ1+AEw39YYNLQEz3QHu7TnUX+ lfQe+xmQEYhhlnzTSmy4JorXKBTXe+jsHJLg7PU7bxQ+hyV0/Ghj5rIn3nXDgTQv3h67 ZySt37HuCvT2ujWIkq2rEGKnyU4g5jpb12nXJSowJJ3poWnuOACaCOueEL4fTfUcaqIR oAEJuIu8ogVlFJ/fHeKNqeqiv3/khk9N9iIVeX13xdqLUo0Pql9brR2AmNepBHY772F9 sYmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=qYalwARn; 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 g192si5387913wmg.188.2019.02.25.05.48.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:42 -0800 (PST) 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=qYalwARn; 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 447NZX5z8MzB09Zr; Mon, 25 Feb 2019 14:48:36 +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=qYalwARn; 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 IWSys9YX47Os; Mon, 25 Feb 2019 14:48:36 +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 447NZX4wZSzB09Zn; Mon, 25 Feb 2019 14:48:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102516; bh=QhQmZaAZJZ69E9F/zZFRmLWd5K/IsYQno7oOFU3XPxU=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=qYalwARnPCzjIFXETiEBuZ7czi+D4/fUqFN0gAZ9pC/dj/JZsL/y/Zs/qCeRVqRiW vGE0qR8lbWGxYzKxOIaIu13RKCdJDvRhm5zgHqHGvCLCoIpgfiJ9UufqCdOfxaqAQE ZFH23Tpr8T7aFztA7lSVIl5qSndCde/zNFC8sB/U= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 056888B844; Mon, 25 Feb 2019 14:48:41 +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 j3jW_ZJQWi3J; Mon, 25 Feb 2019 14:48:40 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D3DEA8B81D; Mon, 25 Feb 2019 14:48:40 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 6D9D16F20E; Mon, 25 Feb 2019 13:48:41 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 06/11] powerpc/32: make KVIRT_TOP dependant 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: Mon, 25 Feb 2019 13:48:41 +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 | 2 +- arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +- arch/powerpc/mm/init_32.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h index aa8406b8f7ba..008e6237a1b2 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -142,7 +142,7 @@ static inline bool pte_user(pte_t pte) #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 /* diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h index bed433358260..6c4acd842a3e 100644 --- a/arch/powerpc/include/asm/nohash/32/pgtable.h +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h @@ -72,7 +72,7 @@ extern int icache_44x_need_flush; #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 /* diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c index 41a3513cadc9..c077ab1a63ea 100644 --- a/arch/powerpc/mm/init_32.c +++ b/arch/powerpc/mm/init_32.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include From patchwork Mon Feb 25 13:48:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828607 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 A8F0F1575 for ; Mon, 25 Feb 2019 13:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 952BB2A6A6 for ; Mon, 25 Feb 2019 13:49:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 847782A687; Mon, 25 Feb 2019 13:49: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 BCF292A443 for ; Mon, 25 Feb 2019 13:49:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D7358E017D; Mon, 25 Feb 2019 08:48:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 73B6B8E011F; Mon, 25 Feb 2019 08:48:45 -0500 (EST) 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 64E708E017D; Mon, 25 Feb 2019 08:48:45 -0500 (EST) 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 03FE38E011F for ; Mon, 25 Feb 2019 08:48:45 -0500 (EST) Received: by mail-wr1-f71.google.com with SMTP id m2so2158156wrs.23 for ; Mon, 25 Feb 2019 05:48:44 -0800 (PST) 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=fF6LjTP5Ef3hsquG7Y6XBTU3dO56YlYJpsVAo831ABM=; b=JDwsNbj2UWjLtUQN/FafPd5RfNG6n16NIXLzb+x0jfw3wi3hSwLdztvGBInEm7J4IA bsHw2moxjMj7SV0Lx5PuMwTVsL79nHbFD7fJbODU4x/LO82pS/NNVasrEKezKvF86urg 8abMj1I7LsEeh2f1zbYExZszs7ZdKpY3PUGhsKTP/PSFCe28d8R6VGU0EwZQ9iPFFhp4 ldq1N/nwODB8xtQxNloCIO/YjFiUKDjRZbPvl1FfDIV/MSzV/qy9pvayKHt/ooTqGdT+ CQo6L4WREgu9xz7ixfJVsIH69HJZomXCrsG8MKnadkcxwRzPfYFdK8EjwuOBWhqRSSwz rvvQ== X-Gm-Message-State: AHQUAubX/3xMcq+O4uPWAnBDcyM8oSIrOm4Ka0EUpXG/r3MflB/FLAlB 5ORCJnEw4241m3ZXbrZALRnai/xFwyyZbgahVpb98ZnTR2kAu7oV0zDVpVDpuMgmjjyaDkJsKc0 P93vK7QTiQgrRaPu/OEQeon7o/BpVIkSrIYHHhT9xPcc5ElUNU7ytIhMiNNKSf5MUIA== X-Received: by 2002:a1c:e0d7:: with SMTP id x206mr10923350wmg.152.1551102524510; Mon, 25 Feb 2019 05:48:44 -0800 (PST) X-Google-Smtp-Source: AHgI3IabBD0zvfLK/bzhobElvZzkIBqwYXpa3s6cv3i5k5h/dk4rdlO+ox+qjLmw0VNTZuRB6YmX X-Received: by 2002:a1c:e0d7:: with SMTP id x206mr10923291wmg.152.1551102523428; Mon, 25 Feb 2019 05:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102523; cv=none; d=google.com; s=arc-20160816; b=Pzqi2FG/7x8XdZ1T0Xx9gXBecT7/EZsocF1SG5bgtFQqzV7bDMyHj5aZtAAQplEb1V ZOTGOT0N98FgOeny34d+7cDQGyDDHwLRxNOPXXl8K6Stmp+/LNx14FOlkfdqR7MA/SuY T5wTKtJnY+s7e/REB0UnMUkntjpJTva5/KHL3vc4K2eGRotLsohLARHyFFBsVG5ph/Ja f0JL6HImNexc1vXW8PF2Sa5rssQZk+3qcaRH5GTPNl8cMr1s3IrrE+yUVjIfEuBxCsAT ygc8o8t9FQPXtFlXpzKGfGrg6beo7V7/GVRbDxAzr+iQKhU7AS4kCpezVdp+n0InubrX h5pg== 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=fF6LjTP5Ef3hsquG7Y6XBTU3dO56YlYJpsVAo831ABM=; b=QhxDsrOeFYNJWlfM6wxKBMADdXpF3Z5ZCYu3ilSCD+JJs7Eddt9P0eDK8Hm1CSUU/9 I+2e1kesCEyDXUaTHa+ccBKA18ynm8EFS6AlLtjeZlSsL1eh2p5ctXdU8Dpof8itRITD ZeLF8lwb8eznzVzDB/MmgQgBTMixcxYgvE2LG4/7zFxQ8QiNsWvD9Le07YDK6iTKVDyl pop4e6i7FcEE031B2FRLiu6jC1TLhU71XxYPpZjR8Nnz9Ar7KK5RQPDvv6XgQ+kazTHH 3Hj4BbnDNnwjQrsbZT8ji0n0MYw2ZeIii6PcSxxAjXCsivwfAxtluo9Uaut/PCPpMG/M scIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=wCmnPKwz; 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 b1si5656353wmg.88.2019.02.25.05.48.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:43 -0800 (PST) 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=wCmnPKwz; 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 447NZY6k4GzB09Zy; Mon, 25 Feb 2019 14:48:37 +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=wCmnPKwz; 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 ADRVeE-l3elj; Mon, 25 Feb 2019 14:48:37 +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 447NZY5b2tzB09Zn; Mon, 25 Feb 2019 14:48:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102517; bh=fF6LjTP5Ef3hsquG7Y6XBTU3dO56YlYJpsVAo831ABM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=wCmnPKwzCLDNOLCiscA/KESLJ4fbF2vwYcH6QM5d/0uVh9xt8mU8NyQeswDgNOahv sHtP8AWt9i/xJDumilkf4Lsf+w3XBrGYsvjbAXI+Wo0p7xcX01rXP0ciuDUMvn69m/ hC31j4yPbRMuhtZXCBxxQpZS2HbM+1mvlxtWNMUg= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1B6E28B845; Mon, 25 Feb 2019 14:48:42 +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 cHyaQZ8BiJa5; Mon, 25 Feb 2019 14:48:42 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DFC7C8B81D; Mon, 25 Feb 2019 14:48:41 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 731256F20E; Mon, 25 Feb 2019 13:48:42 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 07/11] 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: Mon, 25 Feb 2019 13:48:42 +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 | 5 +++++ arch/powerpc/include/asm/fixmap.h | 5 +++++ arch/powerpc/include/asm/kasan.h | 17 +++++++++++++++++ arch/powerpc/mm/mem.c | 4 ++++ arch/powerpc/mm/ptdump/ptdump.c | 8 ++++++++ 5 files changed, 39 insertions(+) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 652c25260838..f446e016f4a1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -382,6 +382,11 @@ config PGTABLE_LEVELS default 3 if PPC_64K_PAGES && !PPC_BOOK3S_64 default 4 +config KASAN_SHADOW_OFFSET + hex + depends on KASAN + default 0xe0000000 + source "arch/powerpc/sysdev/Kconfig" source "arch/powerpc/platforms/Kconfig" diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h index b9fbed84ddca..51a1a309c919 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 +#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 2efd0e42cfc9..b554d3bd3e2c 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -12,4 +12,21 @@ #define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(fn) #endif +#ifndef __ASSEMBLY__ + +#include +#include + +#define KASAN_SHADOW_SCALE_SHIFT 3 + +#define KASAN_SHADOW_OFFSET ASM_CONST(CONFIG_KASAN_SHADOW_OFFSET) + +#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ + (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT)) + +#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 Mon Feb 25 13:48:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828609 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 5DC041390 for ; Mon, 25 Feb 2019 13:49:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ABBF2A7E2 for ; Mon, 25 Feb 2019 13:49:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EE472A82B; Mon, 25 Feb 2019 13:49: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 A8DDD2A7E2 for ; Mon, 25 Feb 2019 13:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FAA48E017E; Mon, 25 Feb 2019 08:48:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9821B8E011F; Mon, 25 Feb 2019 08:48:46 -0500 (EST) 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 7D4628E017E; Mon, 25 Feb 2019 08:48:46 -0500 (EST) 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 29E898E011F for ; Mon, 25 Feb 2019 08:48:46 -0500 (EST) Received: by mail-wr1-f70.google.com with SMTP id j44so4745277wre.22 for ; Mon, 25 Feb 2019 05:48:46 -0800 (PST) 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=mcZlyr+Y9QTQOXdd/Np+U2T6LsmbrnCiae9jtlgpNP8=; b=f+gjqhz+4Hk5KVmhC1e+ByhOtoyj/5eiHmzF+GAPS6HTDFaTzKn3Hi4FoFEMzov72w vBE1thaCcdPyhI5Ex8SvGfSKk9ut+plUgDabv5kUSMlAtNuaqX3j4CeIqguIC6QX6twt /GVX3pXa9/KTbyFTwWBA8elrUfQggqSbmpI0TGZOW9KZCYinVnxPGKEWuZmS73D+tl6P Kzgcdi/RmguxziEOqeMAVASoaLIQFH18bKSoaUVOxluyOSmW/V1qzsO6UpCst5VlpJdi HvLnjpm7cjpsf1Vcktcke07rOZg2L3D51jemU3CrE8NLwCg5mNZVZCJZGqhZh5LjLtso cGiA== X-Gm-Message-State: AHQUAuaZ3blwmwPi5XfDxWsYBrKjDfnwB7WtgWQR8SewwitHtaapXOxl lKa86F8yDkcMBHVhDu8KkQQbpr32HjOqMUl+sb0sCafyZVKoGTBX8eWGNj1iFpfPDrGhe7rzl3X c2aW2Dz/usQKoL+sfUFX0J9I+9DD0BPnGPxsnaIbya7Ws0loEx2L58OtqDC9DFm/oUA== X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr12848071wrw.14.1551102525697; Mon, 25 Feb 2019 05:48:45 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4AdjJwyuxXT6xVtUlI/iKcKxlnacp4drgO4ZzZDlLqUz1nj8PSqyZwxE72RMFGClITrt0 X-Received: by 2002:a05:6000:1084:: with SMTP id y4mr12848014wrw.14.1551102524590; Mon, 25 Feb 2019 05:48:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102524; cv=none; d=google.com; s=arc-20160816; b=lnCXOf6SDn4GtBZ5zYrpeJo0yH6QTxJPx8IvEaSFiQcvaXu//ZW5Wk+lss9DEqxlax VLigd+2mFZuVmNdPQ7bJhV6Oq1kpts+gM+i3FIFqQtrWyeqp1c2FVAtr8BGW2jEoOCxh LoxthT+vTx54ySBf0BBhYDfbbRC0RWzHknu17K/Tivo4uy6CuEDDoGg2DrCEKt+8g5bI /gvUQkZaZYIZocxxRuc3TlUXEUor1gXCmEaRvyZkgswYhUJgljzLwJrqENL6m52h75jI qmxdanwaU6Cg9X9ziDOVP+31S28/4Mf0YiKpGSIRuKrvzC4ozER4ZkPnWbt+nnFn5iwY Wt9w== 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=mcZlyr+Y9QTQOXdd/Np+U2T6LsmbrnCiae9jtlgpNP8=; b=tBlxZ8uK9dW6srH88I58aiWDBXLhgsDAGTkch51e33CEVeM2tB83ZZysuqvvGyZykq NF1b+1Z0Yx0LHQ113gP6oHBONW0V4kkVU+ae9BMRJ8outHqqxkOkVrQPkZ8b3+WkyiNa hJBw6xxtjDTYGZXhPljxqoSbEFe5mHJ2JXTaSgIn2cID66A+p+xanJDu0rjvCLdJg2UE /VPVjGRQV+oDNuesM5/zN2pNF2lk7E7TB2Hn/zIBEk/Hppln+oT3kUVVRNYk6mBncZVs 0lwjOxWIQjLqq1f3t/h1hg9aJKUYrXaZlIfmDLXIo+Rbe4D5HzMFzdXHP8WGr8Jxnnog 3HJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=RBEEY4AQ; 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 n18si6382134wrv.402.2019.02.25.05.48.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:44 -0800 (PST) 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=RBEEY4AQ; 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 447NZb0NKQzB09b1; Mon, 25 Feb 2019 14:48:39 +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=RBEEY4AQ; 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 0O_-sGb4wsrg; Mon, 25 Feb 2019 14:48:38 +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 447NZZ6Cc2zB09Zn; Mon, 25 Feb 2019 14:48:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102518; bh=mcZlyr+Y9QTQOXdd/Np+U2T6LsmbrnCiae9jtlgpNP8=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=RBEEY4AQo8xa5HF8qWEOFssZdky5eor7b9BU+Rj0jA3o5vwVLekQ/PxsPPrz0Y1gg x7u2B52szmMVmuaPqQa/owp9xkb1wHv4FbQm/jS2BG1qmOCKAWt9zLxj8OP5vGEOEK ow9cKNzwQc1Mxpphhj6M+vvuq8DfiXNoXUFKYtGQ= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2A5858B81D; Mon, 25 Feb 2019 14:48:43 +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 E5-LlNlcuG2j; Mon, 25 Feb 2019 14:48:43 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E48F58B844; Mon, 25 Feb 2019 14:48:42 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 7B65D6F20E; Mon, 25 Feb 2019 13:48:43 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 08/11] 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: Mon, 25 Feb 2019 13:48:43 +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 923bfb340433..859efbacdf06 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 Mon Feb 25 13:48:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828611 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 9BAC115AC for ; Mon, 25 Feb 2019 13:49:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88C1E2A7E2 for ; Mon, 25 Feb 2019 13:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A4DC2A82B; Mon, 25 Feb 2019 13:49:11 +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 92BF22A7E2 for ; Mon, 25 Feb 2019 13:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8BBE8E017F; Mon, 25 Feb 2019 08:48:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E48FB8E0180; Mon, 25 Feb 2019 08:48:47 -0500 (EST) 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 C1A618E017F; Mon, 25 Feb 2019 08:48:47 -0500 (EST) 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 6B5E58E011F for ; Mon, 25 Feb 2019 08:48:47 -0500 (EST) Received: by mail-wr1-f70.google.com with SMTP id v8so4746883wrt.18 for ; Mon, 25 Feb 2019 05:48:47 -0800 (PST) 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=avkvCO0YSkiHhZQviuJ9CIGAQeC8sUGL2Kik9xSDfo0=; b=b483x50txuQI/jvYSooHKVriuH6ByIl41tKKMzLyuIIEYRr1wnsQw1T79q/Hjhcr7z fv8oBEhGSaf2Oq7cLMXcNp4w0PLHGVLhlxD2AxD46kfFp299jGzHLNPfi464rGBC+VAt kXqBdXrQCIxXfRKHN7EcsqaQ9ZjS2ozHZAaV/9phDN5F7GcY6MumjSe4aXwQMgXnXrW5 0568pUbSzQ4ZXKVisM0PaQ3GZGGmw9LSPBked7mjZfWYctMqUGzzCNrmeqMO2IfBYoCf jvuyOsfNBxEnq4jIReo2VnME24bzT8WY9CS2NlSkVMgK3LW81MgFvLwDQQAKz/iu9V07 6Obw== X-Gm-Message-State: AHQUAuZ0LKqilvaMVn4xswsljWOjoTGNKy/p0XNHaPzO05MgTM83rsAP BDl6g6K70unwUbJjJXNHaczzHkZGnrpN/KQhOvurKLRdXlkk35YzcDrb9iEAEoanI0pB1qvc+9Q kSmW6xwpR/bRyyXL0CSk1v0US3+Szbod9vk2B3In0IayOogTCXU/nnK88P7kZ0q+YuA== X-Received: by 2002:a1c:d18a:: with SMTP id i132mr10747921wmg.27.1551102526911; Mon, 25 Feb 2019 05:48:46 -0800 (PST) X-Google-Smtp-Source: AHgI3IaovxDG25iZYXIkwyNEfJDlKVKMTZiLSC9knHz5asJ8aIMEPyLqPAB6nzO2aYYkcfWKrz7+ X-Received: by 2002:a1c:d18a:: with SMTP id i132mr10747860wmg.27.1551102525500; Mon, 25 Feb 2019 05:48:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102525; cv=none; d=google.com; s=arc-20160816; b=uC/buRIBmzn7avScbe3Ecy20O9koS7ogyP7ir/zn/v43lhnVn0n1CEoJV6vkbNwJp2 amb1eDm+pC6D8taVj3eeaEJiGPOgDe7DYBNmc696F55fTIMnxdV7g9HZ4x3okCJOiNRV zGnbTA2G3z+GpwGw9K1KbOSGfgYw3KrKSwxX6QSPtYvI/d66TYQdO25PMvaDtjmTmKfG MtMJhWeMm4/nU7jshraV3y39Etjb8obJDGJtz+PDb1RDrlp8/IjIhew2dd5OZfJEEEQj z7JJRowBYnSMVUrNIUQwIxnMTDsVRo7SOEhi3z/f8A1HOk7Bvo9Oc2izP8ihtmNtYava ngJw== 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=avkvCO0YSkiHhZQviuJ9CIGAQeC8sUGL2Kik9xSDfo0=; b=mfOe0bUKU39vAccAZCJWfkMi3mf8bdr9/HbejZyw2vrSlG87+cOiKOiJzHgo4ttxWQ O/+vH6gg0/ms27dpF66SgB489Eo+i+CjATmJXEko1Q9pgwkE4iE5JjazWOToAa/5G0lb 1S3f4t21rj43Z+z2Efin9KwLNYJz170UpotDVLZHCEN+MKJg4CN6UWnQXCW4vZ1XZxmS wQvr2kRoLt2NFSdjoF6HN2NPBgZh85vpbhg1U/1dfAujk+Tht1n/usBqXj3nD59gQ3Ss W6MVwZoRHkaP+zl9ZZ0c7LkA5p8/n2ef9NILCu8MYecl4QJ7+ES6mH1V0bGz6kh8OHnV 6cMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=sRVSClS7; 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 x8si5332357wmk.93.2019.02.25.05.48.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:45 -0800 (PST) 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=sRVSClS7; 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 447NZc0z5czB09b2; Mon, 25 Feb 2019 14:48:40 +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=sRVSClS7; 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 8zNigNsus2x5; Mon, 25 Feb 2019 14:48:40 +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 447NZb6zhpzB09Zn; Mon, 25 Feb 2019 14:48:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102520; bh=avkvCO0YSkiHhZQviuJ9CIGAQeC8sUGL2Kik9xSDfo0=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=sRVSClS7uNT7/u0ChGCS+V16yk4QnHoBFdD9fmrifdpMQ1PYWON1Tkg07LZBCpbov 0xQE5xBqfGmk0bJNoNlWLYLuf7/cpv8CYmJT1iqpy61wagPCdhPrAl3D9Y+oqDFWHu Dt/Zu27tPUR+Oyd5KSBDIHGZA2H7Pt1Q2P7yybJY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 468738B81D; Mon, 25 Feb 2019 14:48:44 +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 fMoqPP9Wk5xF; Mon, 25 Feb 2019 14:48:44 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EF4238B844; Mon, 25 Feb 2019 14:48:43 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 824196F20E; Mon, 25 Feb 2019 13:48:44 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 09/11] 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: Mon, 25 Feb 2019 13:48:44 +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 | 7 ++ 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/kasan/Makefile | 5 ++ arch/powerpc/mm/kasan/kasan_init_32.c | 153 ++++++++++++++++++++++++++++++++++ 11 files changed, 185 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 f446e016f4a1..88f430cc9b96 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -172,6 +172,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 b554d3bd3e2c..7bea5ba53760 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -28,5 +28,12 @@ #define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START) +#ifdef CONFIG_KASAN +void kasan_early_init(void); +void kasan_init(void); +#else +static inline void kasan_init(void) { } +#endif + #endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index ce6a972f2584..02229c005853 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -952,6 +952,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/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..b7c0fdd88c8e --- /dev/null +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -0,0 +1,153 @@ +// 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) +{ + 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, (unsigned long)kasan_early_shadow_page, + 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; + pmd_t *pmd; + void *block = NULL; + int 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) { + 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; + + pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); + pte_update(pte_offset_kernel(pmd, k_cur), ~0, pte_val(pte)); + } + 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_mm(&init_mm); +} + +void __init kasan_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"); + } + + 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(1, "KASAN not supported on hash 6xx"); +} From patchwork Mon Feb 25 13:48:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828613 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 C4D611575 for ; Mon, 25 Feb 2019 13:49:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2FAD2A824 for ; Mon, 25 Feb 2019 13:49:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A74962A844; Mon, 25 Feb 2019 13:49: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 0D6C02A824 for ; Mon, 25 Feb 2019 13:49:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 545978E0180; Mon, 25 Feb 2019 08:48:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 454EC8E011F; Mon, 25 Feb 2019 08:48:48 -0500 (EST) 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 33F078E0180; Mon, 25 Feb 2019 08:48:48 -0500 (EST) 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 D4A238E011F for ; Mon, 25 Feb 2019 08:48:47 -0500 (EST) Received: by mail-wm1-f69.google.com with SMTP id b6so1266871wmj.7 for ; Mon, 25 Feb 2019 05:48:47 -0800 (PST) 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=8i6BZYBVOnklYOVbK567NRMBSuNfNdhf+35JteJYb48=; b=nJwUjQab4+c8puFLEXW3m07kuOQemLP4c9E/3XAipklL1NWA86IX10XUnohQNEqZiZ 4W1BTULSjtwF4q39+HEP18c3RM4LYIBglb3h5ky3Q+zxcAFGhAFDoj8RlQ3WL5JDi4CE +H7cfLT/nEukBkpTqXSDYfcXBHTnSJq34v8WgqyPCEMnMqjv4WLNG1PcNJXunYBo6dXd XVU4fOb0TXu4fSglfG20TzsS5atofJrVx8BIU0huPkKj5//s7Xqdf/rBCo9n/jkDEG7D 5/dWm2nzxuF6uWHWxmTaTnZ2FIpLwxfNHfUfPp0s6n4S1AWPT5Dl6rCGSgcZQpufKNHB 5PVQ== X-Gm-Message-State: AHQUAuYx6gBPQqmX++VvZM1MwiJdaK6HODZWf9988yU1udkwOvNuVikz 79bTuUP2ZlIPAW3hXUgICnEQsKAhZiEIFIBAXPdYsb+v9rzZuN/yNAin0NH1xjhXw9EZmzN70WY jpbfkBYiERriQqIBBgu9ZIJH2J7I4dZf6X/8z5430pm4P5669XR6Vip3pp8baKyTWfQ== X-Received: by 2002:adf:c7c6:: with SMTP id y6mr12454913wrg.217.1551102527352; Mon, 25 Feb 2019 05:48:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4zXPL7Uv2UHx/aLGQLT+cHD768WMdbCPVhV/4Xh01PZ98xuaAVAu2pLgOUXvfM30aj5wX X-Received: by 2002:adf:c7c6:: with SMTP id y6mr12454879wrg.217.1551102526405; Mon, 25 Feb 2019 05:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102526; cv=none; d=google.com; s=arc-20160816; b=Rkt1HmZqYFw+FhUhPWKMtAxaddAAVby5MCQ2y7x4xmALSvAeCVKunvHxfNZ5zTImn2 Ej83Wu/owuXEfE4SSSXDNiljoX7pFJnfemslVMyqT5Xu+YjbeacWl08pJQP+7ECsvhqK R9HeVdYo6Y3rE1FogWIoGS/DntovaCt4DuK+JrI+LEieY3vkOrA5Ws3ynG4BQ4NQAhlT XoBWe+fUUtlFbTNMGOuMokGi8l0f46ZO9f2hztt9laZESR/f64BWrcXAD27UlAAljFNR 4vA7YL5vR6tm+47uxv7epICU67a6flgiE8llNFS8zpcgXg35qtbxxSIYIi9gpATNKf7k yl+g== 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=8i6BZYBVOnklYOVbK567NRMBSuNfNdhf+35JteJYb48=; b=F+EQGWCRUq4GwqkNiVKcK3DT5ECxRR5S8TCuykHGH2xIy2xxtAlfUuxw1miF5AnH// QRgBJJ+Kt2KCr20QvvoUJi8IFKAlFShZZaeuQW62DW37CbxWa7MZsi8k8anlUaOdq4ze 9lLCoEaV1bqHwqTPHbMDk+2r/VH/+aJg83ueR6k3x8fjzZtE2B7JSsc2EbGfGzN/22wR FizM2S/qkpAYmoR1Oy1iWLud/mcKZNpf+o85YCgUNDQU+L2fuTFnBlkMYskOirILmA/B f9U6Lc5FYU43JrR2ocHtfIUx8bFHZyV/o2dE8OAhFzCmCSKrEmo1JVj36k58eYn04uqg UwCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=imulGtqB; 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 e6si5355144wmh.71.2019.02.25.05.48.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:46 -0800 (PST) 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=imulGtqB; 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 447NZd0Ft2zB09b3; Mon, 25 Feb 2019 14:48:41 +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=imulGtqB; 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 OO7uHKRQX9Et; Mon, 25 Feb 2019 14:48:40 +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 447NZc6HvszB09Zn; Mon, 25 Feb 2019 14:48:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102520; bh=8i6BZYBVOnklYOVbK567NRMBSuNfNdhf+35JteJYb48=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=imulGtqBo/ES7Z2dxdDVORNqJ3N0i4PSkqYblVgWQX+panXUiCtjEQGguU3Pal7vr EBaZzGCsI6+36+zobAcXGdiRj7IkLBt0xbxRtaFyvCGdv/zRr6w1joTF6MgoA7lJLU /G29i5DppfA1z7QDqhT51JApPIklKA0m9V17yE/s= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 366BA8B844; Mon, 25 Feb 2019 14:48:45 +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 VXX0HYr9fIOD; Mon, 25 Feb 2019 14:48:45 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0A9AA8B81D; Mon, 25 Feb 2019 14:48:45 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 8A7636F20E; Mon, 25 Feb 2019 13:48:45 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 10/11] 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: Mon, 25 Feb 2019 13:48:45 +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 | 34 ++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 02229c005853..e644aab2cf5b 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -960,6 +960,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..d591f768fac6 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,28 @@ 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 +379,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 Mon Feb 25 13:48:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10828615 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 4AF3A17E6 for ; Mon, 25 Feb 2019 13:49:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37A812A7E2 for ; Mon, 25 Feb 2019 13:49:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BAC62A82B; Mon, 25 Feb 2019 13:49:20 +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 82C802A824 for ; Mon, 25 Feb 2019 13:49:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FD1C8E0181; Mon, 25 Feb 2019 08:48:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7D86A8E011F; Mon, 25 Feb 2019 08:48:49 -0500 (EST) 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 6286B8E0181; Mon, 25 Feb 2019 08:48:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 086608E011F for ; Mon, 25 Feb 2019 08:48:49 -0500 (EST) Received: by mail-wm1-f72.google.com with SMTP id q24so334330wmq.9 for ; Mon, 25 Feb 2019 05:48:48 -0800 (PST) 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=eNCDjVYIgy6lNbk859Vm+9SPMgCX7rafzT3Fmt9o26w=; b=MuucZRQQKYJs7QFUX7owjtRsJYyfMwmTMlogM5FcnEFviZTAdL0bJcfET/cQ+E6TSz fq7ALmpKcfzBJawWLVHjBSH2Y6Zw+QwBKCyFaD9MixYLa0l6G81PgPnrMPSlsTGUctix JfMmyfWAR8vmdhc/ovWpcNOJNrwWHNxKmOsJ5m51A+MvKFZWKeysWtXG0zg0PsmkbvHd FHHTbgJJ9qUSUalbNzS2+xYw/w9fcl2aY9EOqiBjDZjO9u5DCBrx/lj5lZJtw9t5YyrU o13VYtnhi4TjMCJ/+9gjNVXRO0zM0Hqbu8N1uMLuyLT2yTBsXPuj08zm4nW6EAcuc4oj G0Ug== X-Gm-Message-State: AHQUAuYHQiwCQv/I7gNQOSUfFeho0l/jsyB9KBdfGe7fWGb2HhPtPj9+ rniBbZTtPr2EqwScxtqT9L5CfgCCC8Yp+D/szaj97c5zNUie2tcdeC7tKw6R8rEflKt+FtXYarl CSNE6mY1L15u7z+Y8+8NkVvGkgTSc8K4SO+IIMYST1wYQZLHzgGAEzckJMY7XU5sXmA== X-Received: by 2002:a1c:dc07:: with SMTP id t7mr11117114wmg.90.1551102528493; Mon, 25 Feb 2019 05:48:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IaZ1u5DMaHe8oIFAWfeFGfQ4AD0GuzDAwl6UrXCzwDL2zHVUWjHRjeaN7gdQjeubXMuy07x X-Received: by 2002:a1c:dc07:: with SMTP id t7mr11117078wmg.90.1551102527574; Mon, 25 Feb 2019 05:48:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551102527; cv=none; d=google.com; s=arc-20160816; b=OQbzfGVjaW219EoVQ5LCuuiFOuWrasfNgWlvlWg93KWT1GmoLqh4ToCwNrNe3dPI/F RQbqzhBqWL/XIqCyYg/bxCMzwlLALIW2liRUu4dFNCkigGMVgXVlJLFxw4oe9AeEgdFq DecTBHvbTrLROmiCDqblwmd+VY8BPhcegEWabWOZyHXnEEO5tIPv6sGM4jeRLJyJKdYT 4p82N8mz117JyhiJ90lEr7cgilvHFDNjpRc8obZ6AaAA7IONgoM9o1AY6knkJiMOrO1F Om625uBT5UqCljrR86cn8Z6a3n8ARkPl/bDEtCVwtnxV+L8mf+pWjK/Z6QSuR5F/9kL7 xk3w== 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=eNCDjVYIgy6lNbk859Vm+9SPMgCX7rafzT3Fmt9o26w=; b=YOU0Iiyrrwf3HgWdZ+HjiBpIsKLeq7qI6CVWiVwE1hUwV1+StoHgwG4rrmll2n7Azi 54BdiKLOXKn0TXtWV22ylf3jiDYYVtkTApIbxSXx1KnHsKLyfemABQZLaXzG/bHnYrtN REQvD3DJSl5BRRemKMn7SwxxW/lXfytz6zlGbUju/AhRfiu2qsGqBrxlywqkZlC1/1is 4fdmGU6cp14inlBYHIADM6/I1bQLCaib0HQJR3mw0Aa9ORT7ObAZanPbdrTbU1jVxBJk W7rcdZ98OdCjlBNQ71a2QDEh0N8CSZMDTNYBWiU5mZnicJjIVoEkX9KZrWj9I72gMUdN OX+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=uFzyzm8M; 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 h9si6392853wrq.2.2019.02.25.05.48.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 05:48:47 -0800 (PST) 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=uFzyzm8M; 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 447NZf0NwtzB09b4; Mon, 25 Feb 2019 14:48:42 +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=uFzyzm8M; 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 kBscLWewVmDX; Mon, 25 Feb 2019 14:48:41 +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 447NZd6KrLzB09Zn; Mon, 25 Feb 2019 14:48:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1551102521; bh=eNCDjVYIgy6lNbk859Vm+9SPMgCX7rafzT3Fmt9o26w=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=uFzyzm8MHshOvTiqr+SoqqSnIL/1hRd+UvKp2q3wxh2kEzVYT66d+sUcACOqTy5uH Wxoj5wDCoJH6zMR9yF2vYt4Qu/Unq/UhpeNTYVtrHYPJX34Mvy7qNtF1Qt0XHQM1XM Ig53qS3xB5renN+INmF1bcyWWukiLMvkf6ppJwQ4= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3E2CB8B844; Mon, 25 Feb 2019 14:48:46 +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 VlpQTLdF9oug; Mon, 25 Feb 2019 14:48:46 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 110A78B81D; Mon, 25 Feb 2019 14:48:46 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 976CC6F20E; Mon, 25 Feb 2019 13:48:46 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v7 11/11] 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: Mon, 25 Feb 2019 13:48:46 +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. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_32.S | 40 ++++++++++++++++++++++++++--------- arch/powerpc/mm/kasan/kasan_init_32.c | 32 ++++++++++++++++++++++++---- arch/powerpc/mm/mmu_decl.h | 1 + 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index e644aab2cf5b..1d881047ce76 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 @@ -881,11 +885,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 @@ -897,14 +914,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. */ @@ -926,6 +935,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 b7c0fdd88c8e..0058bf606fbd 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -60,10 +60,13 @@ static int __ref kasan_init_region(void *start, size_t size) unsigned long k_cur; pmd_t *pmd; void *block = NULL; - int ret = kasan_init_shadow_page_tables(k_start, k_end); - if (ret) - return ret; + if (!early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) { + int 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); @@ -94,6 +97,13 @@ void __init kasan_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); @@ -132,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; @@ -149,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(1, "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..525f7640ff40 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 */