From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82CCBC433C1 for ; Tue, 23 Mar 2021 13:27:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1AFF61994 for ; Tue, 23 Mar 2021 13:27:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1AFF61994 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1FF28D000F; Tue, 23 Mar 2021 09:27:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED1708D0001; Tue, 23 Mar 2021 09:27:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0E1D8D000F; Tue, 23 Mar 2021 09:27:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id B0FDC8D0001 for ; Tue, 23 Mar 2021 09:27:51 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5704F1DE6 for ; Tue, 23 Mar 2021 13:27:51 +0000 (UTC) X-FDA: 77951216742.18.8632880 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf14.hostedemail.com (Postfix) with ESMTP id B2D91C0007D3 for ; Tue, 23 Mar 2021 13:27:48 +0000 (UTC) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4F4XH70jjqz9v1GL; Tue, 23 Mar 2021 14:27:47 +0100 (CET) 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 RzqWHqF5nznC; Tue, 23 Mar 2021 14:27:47 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4F4XH66lWHz9v1GJ; Tue, 23 Mar 2021 14:27:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4CFA18B7F7; Tue, 23 Mar 2021 14:27:48 +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 TWHHaF8PUfFg; Tue, 23 Mar 2021 14:27:48 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B4B0A8B7F4; Tue, 23 Mar 2021 14:27:47 +0100 (CET) Subject: Re: [PATCH v11 0/6] KASAN for powerpc64 radix To: Daniel Axtens , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com References: <20210319144058.772525-1-dja@axtens.net> <5a3b5952-b31f-42bf-eaf4-ea24444f8df6@csgroup.eu> <87ft0mbr6r.fsf@dja-thinkpad.axtens.net> From: Christophe Leroy Message-ID: Date: Tue, 23 Mar 2021 14:27:45 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <87ft0mbr6r.fsf@dja-thinkpad.axtens.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B2D91C0007D3 X-Stat-Signature: 4ggng7r495krnqbj3hxbfde7wdeeoun9 Received-SPF: none (csgroup.eu>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=pegase1.c-s.fr; client-ip=93.17.236.30 X-HE-DKIM-Result: none/none X-HE-Tag: 1616506068-422719 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 23/03/2021 =C3=A0 02:21, Daniel Axtens a =C3=A9crit=C2=A0: > Hi Christophe, >=20 >> In the discussion we had long time ago, >> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20190806233827= .16454-5-dja@axtens.net/#2321067 >> , I challenged you on why it was not possible to implement things the = same way as other >> architectures, in extenso with an early mapping. >> >> Your first answer was that too many things were done in real mode at s= tartup. After some discussion >> you said that finally there was not that much things at startup but th= e issue was KVM. >> >> Now you say that instrumentation on KVM is fully disabled. >> >> So my question is, if KVM is not a problem anymore, why not go the sta= ndard way with an early shadow >> ? Then you could also support inline instrumentation. >=20 > Fair enough, I've had some trouble both understanding the problem mysel= f > and clearly articulating it. Let me try again. >=20 > We need translations on to access the shadow area. >=20 > We reach setup_64.c::early_setup() with translations off. At this point > we don't know what MMU we're running under, or our CPU features. What do you need to know ? Whether it is Hash or Radix, or more/different= details ? IIUC, today we only support KASAN on Radix. Would it make sense to say th= at a kernel built with=20 KASAN can only run on processors having Radix capacility ? Then select CO= NFIG_PPC_RADIX_MMU_DEFAULT=20 when KASAN is set, and accept that the kernel crashes if Radix is not ava= ilable ? >=20 > To determine our MMU and CPU features, early_setup() calls functions > (dt_cpu_ftrs_init, early_init_devtree) that call out to generic code > like of_scan_flat_dt. We need to do this before we turn on translations > because we can't set up the MMU until we know what MMU we have. >=20 > So this puts us in a bind: >=20 > - We can't set up an early shadow until we have translations on, whic= h > requires that the MMU is set up. >=20 > - We can't set up an MMU until we call out to generic code for FDT > parsing. >=20 > So there will be calls to generic FDT parsing code that happen before t= he > early shadow is set up. I see some logic in kernel/prom_init.c for detecting MMU. Can we get the = information from there in=20 order to setup the MMU ? >=20 > The setup code also prints a bunch of information about the platform > with printk() while translations are off, so it wouldn't even be enough > to disable instrumentation for bits of the generic DT code on ppc64. I'm sure the printk() stuff can be avoided or delayed without much proble= ms, I guess the main=20 problem is the DT code, isn't it ? As far as I can see the code only use udbg_printf() before MMU is on, and= this could be simply=20 skipped when KASAN is selected, I see no situation where you need early p= rintk together with KASAN. >=20 > Does that make sense? If you can figure out how to 'square the circle' > here I'm all ears. Yes it is a lot more clear now, thanks you. Gave a few ideas above, does = it help ? >=20 > Other notes: >=20 > - There's a comment about printk() being 'safe' in early_setup(), tha= t > refers to having a valid PACA, it doesn't mean that it's safe in an= y > other sense. >=20 > - KVM does indeed also run stuff with translations off but we can cat= ch > all of that by disabling instrumentation on the real-mode handlers: > it doesn't seem to leak out to generic code. So you are right that > KVM is no longer an issue. >=20 Christophe