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=-6.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 B8B74C433DF for ; Mon, 19 Oct 2020 10:06:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 16B8620791 for ; Mon, 19 Oct 2020 10:06:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UyZOW9DL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="LoKdogj9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16B8620791 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=n/5Mf8xD2jRYsxCczMZGwZpJzfdZziwDRPh+JkvcHIc=; b=UyZOW9DLo+8+ImXM+NUcLdUxu xHpkod3OWfFobIj2GmPWCAvbWEaNOjDLLcxIY+ChORJ9253XOODtRa3xebArFsAJjdOVmkZ6C709u Q3YgGlhGopmmx4LgzSgtHCoSalmyTUjF0NEQv+y3fTMKH5LJ69CjrWu1sNhOTkkMuGUBB9BZL3JTh Mdc+BPBDsgtB+oitFCQmYyuDK4uhm5BQl6PE6mcCMo/5BzQvW/XII/RKWY0W6L/mwZ8mgeOEIrbut I/oKPldugxrYTDXik0bAw3DjJWuxMM93YHMufhSbqCE6oCYnIXq0IR12O9jqy8hVxUBad0wHKvG/8 eOxYyKqEg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUS2b-0000z9-4Z; Mon, 19 Oct 2020 10:05:21 +0000 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUS2X-0000xx-Vl for linux-arm-kernel@lists.infradead.org; Mon, 19 Oct 2020 10:05:19 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09JA3I3L049331; Mon, 19 Oct 2020 06:05:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=Q7yLpk89mef1+7HqpucR7qC5KiIHsVSBjK5x78JpXZM=; b=LoKdogj9h5uzFvCv2o/fTwE/FckZqPKxUKA7KVJ60/v4IlBcoKobY3XMujOTwJe9plDT G7UIm65HiJYvdQ/vIQzZF91bQKQfzqO3PBxvc+RJpBbHffhd3j+GQZKlrcf8DTiE5B9Z mxhCpKOWs1mLISqOHrKTdNoi7ThhQP0Xy0uKp0wo/7kDtZF3ry7cByP+a7G0RUeix/ss PV7aFQE245Xey5KGheDS1wAZJAC2ifkBD49UG4q1hVDj99896XqP56vO6zF7DH/HeWvr j051hKcFRiP8OAzU3AdlChT6a0H9DQ6eCgAYw0hAnjEx6/21VBXrtkJ7YAYIuJNOi/ku MA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 34987h112s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Oct 2020 06:05:06 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 09JA3RuT050131; Mon, 19 Oct 2020 06:05:06 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 34987h1109-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Oct 2020 06:05:06 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 09JA2Zv6001774; Mon, 19 Oct 2020 10:05:04 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 347r8810ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Oct 2020 10:05:03 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 09JA51OA33292554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Oct 2020 10:05:01 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8A0A42049; Mon, 19 Oct 2020 10:05:01 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B1074203F; Mon, 19 Oct 2020 10:05:00 +0000 (GMT) Received: from linux.ibm.com (unknown [9.145.52.221]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 19 Oct 2020 10:05:00 +0000 (GMT) Date: Mon, 19 Oct 2020 13:04:58 +0300 From: Mike Rapoport To: Ard Biesheuvel Subject: Re: [PATCH 4/5 v16] ARM: Initialize the mapping of KASan shadow memory Message-ID: <20201019100458.GB455883@linux.ibm.com> References: <20201019084140.4532-1-linus.walleij@linaro.org> <20201019084140.4532-5-linus.walleij@linaro.org> <20201019093421.GA455883@linux.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-10-19_02:2020-10-16, 2020-10-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 clxscore=1015 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 spamscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010190074 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201019_060518_089335_FA63627F X-CRM114-Status: GOOD ( 40.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Fainelli , Ahmad Fatoum , Arnd Bergmann , Abbott Liu , Linus Walleij , Russell King , kasan-dev , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 19, 2020 at 11:42:44AM +0200, Ard Biesheuvel wrote: > On Mon, 19 Oct 2020 at 11:37, Mike Rapoport wrote: > > > > On Mon, Oct 19, 2020 at 10:41:39AM +0200, Linus Walleij wrote: > > > This patch initializes KASan shadow region's page table and memory. > > > There are two stage for KASan initializing: > > > > > > 1. At early boot stage the whole shadow region is mapped to just > > > one physical page (kasan_zero_page). It is finished by the function > > > kasan_early_init which is called by __mmap_switched(arch/arm/kernel/ > > > head-common.S) > > > > > > 2. After the calling of paging_init, we use kasan_zero_page as zero > > > shadow for some memory that KASan does not need to track, and we > > > allocate a new shadow space for the other memory that KASan need to > > > track. These issues are finished by the function kasan_init which is > > > call by setup_arch. > > > > > > When using KASan we also need to increase the THREAD_SIZE_ORDER > > > from 1 to 2 as the extra calls for shadow memory uses quite a bit > > > of stack. > > > > > > As we need to make a temporary copy of the PGD when setting up > > > shadow memory we create a helpful PGD_SIZE definition for both > > > LPAE and non-LPAE setups. > > > > > > The KASan core code unconditionally calls pud_populate() so this > > > needs to be changed from BUG() to do {} while (0) when building > > > with KASan enabled. > > > > > > After the initial development by Andre Ryabinin several modifications > > > have been made to this code: > > > > > > Abbott Liu > > > - Add support ARM LPAE: If LPAE is enabled, KASan shadow region's > > > mapping table need be copied in the pgd_alloc() function. > > > - Change kasan_pte_populate,kasan_pmd_populate,kasan_pud_populate, > > > kasan_pgd_populate from .meminit.text section to .init.text section. > > > Reported by Florian Fainelli > > > > > > Linus Walleij : > > > - Drop the custom mainpulation of TTBR0 and just use > > > cpu_switch_mm() to switch the pgd table. > > > - Adopt to handle 4th level page tabel folding. > > > - Rewrite the entire page directory and page entry initialization > > > sequence to be recursive based on ARM64:s kasan_init.c. > > > > > > Ard Biesheuvel : > > > - Necessary underlying fixes. > > > - Crucial bug fixes to the memory set-up code. > > > > > > Cc: Alexander Potapenko > > > Cc: Dmitry Vyukov > > > Cc: kasan-dev@googlegroups.com > > > Cc: Mike Rapoport > > > Co-developed-by: Andrey Ryabinin > > > Co-developed-by: Abbott Liu > > > Co-developed-by: Ard Biesheuvel > > > Acked-by: Mike Rapoport > > > Reviewed-by: Ard Biesheuvel > > > Tested-by: Ard Biesheuvel # QEMU/KVM/mach-virt/LPAE/8G > > > Tested-by: Florian Fainelli # Brahma SoCs > > > Tested-by: Ahmad Fatoum # i.MX6Q > > > Reported-by: Russell King - ARM Linux > > > Reported-by: Florian Fainelli > > > Signed-off-by: Andrey Ryabinin > > > Signed-off-by: Abbott Liu > > > Signed-off-by: Florian Fainelli > > > Signed-off-by: Ard Biesheuvel > > > Signed-off-by: Linus Walleij > > > --- > > > > ... > > > > > + cpu_switch_mm(tmp_pgd_table, &init_mm); > > > + local_flush_tlb_all(); > > > + > > > + clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); > > > + > > > + kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START), > > > + kasan_mem_to_shadow((void *)-1UL) + 1); > > > + > > > + for_each_memblock(memory, reg) { > > > + void *start = __va(reg->base); > > > + void *end = __va(reg->base + reg->size); > > > + > > > > I've killed for_each_memblock() recently and we have now > > > > for_each_mem_range(idx, &pa_start, &pa_end) > > > > instead. > > > > Will the enumeration include NOMAP regions as well? We could actually > omit them here, since they don't need KASAN shadow. The NOMAP regions are omitted. -- Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel