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=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,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 5EAC0C433DF for ; Wed, 1 Jul 2020 07:44:45 +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 2BC8020722 for ; Wed, 1 Jul 2020 07:44:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KWLIL5GS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="OwNpReW9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BC8020722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3OO2I/lWPBxrt0g3Ilxj6YOZWaFYR6KTbcNhSgFmmV0=; b=KWLIL5GSz9PRTqP/RLVEyHBqH pzADvjloL7F9r84SNmMm50wQ72K4C/zDGb3n5I6O0czxPPTyKpaR2buBHzYVT0FhOD/BAiyRP7kup JM0q1KJbmjsbzAp+vH7R6vyt7Ln50eK7AIQECvEeUlGxvOCygC8JbwZV/3RySVyg+1j9Cnw0e/s9P eS5tB9mj8Bu02ekx+F/JpB56piPG4wzQUAwM2LvF7V/WQF8UchgTx9fv5ZtU+YPgwAj5ixoOq7q6D E9KDmcDZun8gwId1IwTm6PT1pdCv8zNB6zfw7lwYvBbZBALwBxLZtgCOSBCXkCViq41/4OjoPFTdY +kyXcsXEw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqXP6-0000Lq-Ed; Wed, 01 Jul 2020 07:43:36 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqXP2-0000L5-Sh for linux-arm-kernel@lists.infradead.org; Wed, 01 Jul 2020 07:43:34 +0000 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1A0E1207C4 for ; Wed, 1 Jul 2020 07:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593589412; bh=YLt1bGwl5CmoLv1H6AGs+Ahf8k+18fVopYNMxYWNL8s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OwNpReW9u4y/449dNsV77rTwuAobknvwM2P/gLThYSy0p15p4Q/XI5qKVxkEPAjfl D28NlUHkXSxcsJrYIUGCJ9tPkc3PXgTalwHrNrZKKkAUG8iag8phYDmm/A8/Rvm2Jk ma7FGj9oxz9DQ5WDiDoHFQPl70AKNMIhlW6mqsjY= Received: by mail-ot1-f49.google.com with SMTP id c25so3101329otf.7 for ; Wed, 01 Jul 2020 00:43:32 -0700 (PDT) X-Gm-Message-State: AOAM530yuWaiPrrZMMuV8buFjG4+BAfGoHnkwQ9tYQ75xL06rmYG2cRS RZh3GUZJS0vsswRbiTTMGGJbD3bzFGj53AbD9jc= X-Google-Smtp-Source: ABdhPJxD/KcSSdxmOqzbY72tCrkKzLFkSvivXJCQN/88OYoU6ZZQ7XGiKJc7fQmg65gVVqwvPjhDVoLpYi52LEOKZ4s= X-Received: by 2002:a9d:4a8f:: with SMTP id i15mr22793240otf.77.1593589411367; Wed, 01 Jul 2020 00:43:31 -0700 (PDT) MIME-Version: 1.0 References: <20200630133736.231220-1-linus.walleij@linaro.org> <74eec7fa-6e6f-09ba-acd4-65a976117831@gmail.com> In-Reply-To: <74eec7fa-6e6f-09ba-acd4-65a976117831@gmail.com> From: Ard Biesheuvel Date: Wed, 1 Jul 2020 09:43:20 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/5 v11] KASan for Arm To: Florian Fainelli X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200701_034333_086508_8D48F0F3 X-CRM114-Status: GOOD ( 45.05 ) 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: Arnd Bergmann , Abbott Liu , Linus Walleij , Russell King , Mike Rapoport , 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 Wed, 1 Jul 2020 at 06:53, Florian Fainelli wrote: > > > > On 6/30/2020 2:41 PM, Ard Biesheuvel wrote: > > On Tue, 30 Jun 2020 at 15:39, Linus Walleij wrote: > >> > >> This is the v11 version of the KASan patches for ARM. > >> > >> The main changes from the v10 version is: > >> > >> - LPAE now compiles and works again, at least Versatile Express > >> Cortex A15 TC1 in QEMU (which is the LPAE system I have > >> access to). > >> > >> - Rewrite some of the page directory initialization after > >> helpful feedback from Mike Rapoport and Russell King. > >> > >> Also minor improvements to commit messages and comments > >> in the code so it is clear (for most cases I hope) why > >> some ifdefs etc are there. > >> > >> All tested platforms from ARMv4 thru ARMv7 work fine. I > >> have not been able to re-test with the Qualcomm DragonBoard > >> APQ8060 yet, but I suspect the problem there is that the > >> DT parser code reaches out into non-kernel memory and > >> needs some de-instrumentation, possibly combined with the > >> memory holding the device tree getting corrupted or reused > >> before we have a chance to parse it. > >> > >> Abbott Liu (1): > >> ARM: Define the virtual space of KASan's shadow region > >> > >> Andrey Ryabinin (3): > >> ARM: Disable KASan instrumentation for some code > >> ARM: Replace string mem* functions for KASan > >> ARM: Enable KASan for ARM > >> > >> Linus Walleij (1): > >> ARM: Initialize the mapping of KASan shadow memory > >> > > > > Hi, > > > > I needed the changes below to make this work on a 16 core GICv3 > > QEMU/KVM vm with 8 GB of RAM > > > > Without masking start, I get a strange error where kasan_alloc_block() > > runs out of memory, probably because one of the do..while stop > > conditions fails to trigger and we loop until we run out of lowmem. > > > > The TLB flush is really essential to make any of these page table > > modifications take effect right away, and strange things can happen if > > you don't. I also saw a crash in the DT unflatten code without this > > change, but that is probably because it is simply the code that runs > > immediately after. > > > > If you see anything like > > > > Unable to handle kernel paging request at virtual address b744077c > > [b744077c] *pgd=80000040206003, *pmd=6abf5003, *pte=c000006abb471f > > > > where the CPU faults on an address that appears to have a valid > > mapping at each level, it means that the page table walker was using a > > stale TLB entry to do the translation, triggered a fault and when we > > look at the page tables in software, everything looks like it is > > supposed to. > > Thanks Ard, this allows me to boot successfully to a prompt on a BCM7278 > system whereas we would have an error before while unflattening the DT. > > Now there are still other systems that fail booting with the error log > attached previously, but it is not clear yet to me why this is happening > as it does not seem to depend on the memory ranges only as I initially > thought. It seems to me that for LPAE, we are not copying enough of the level 2 early shadow tables: a level 2 table covers 512 MB, which is exactly the size of the KASAN shadow region for a 4 GB address space. However, the shadow region is not 512 MB aligned, and so the early shadow necessarily covers two level 2 tables. Could you try the following please? diff --git a/arch/arm/mm/kasan_init.c b/arch/arm/mm/kasan_init.c index 535dce42e59d..3c9c37a59b57 100644 --- a/arch/arm/mm/kasan_init.c +++ b/arch/arm/mm/kasan_init.c @@ -27,7 +27,7 @@ static pgd_t tmp_pgd_table[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE); -pmd_t tmp_pmd_table[PTRS_PER_PMD] __page_aligned_bss; +static pmd_t tmp_pmd_table[2][PTRS_PER_PMD] __page_aligned_bss; static __init void *kasan_alloc_block(size_t size, int node) { @@ -231,13 +231,15 @@ void __init kasan_init(void) * to the proper swapper_pg_dir. */ memcpy(tmp_pgd_table, swapper_pg_dir, sizeof(tmp_pgd_table)); -#ifdef CONFIG_ARM_LPAE - memcpy(tmp_pmd_table, - pgd_page_vaddr(*pgd_offset_k(KASAN_SHADOW_START)), - sizeof(tmp_pmd_table)); - set_pgd(&tmp_pgd_table[pgd_index(KASAN_SHADOW_START)], - __pgd(__pa(tmp_pmd_table) | PMD_TYPE_TABLE | L_PGD_SWAPPER)); -#endif + if (IS_ENABLED(CONFIG_ARM_LPAE)) { + memcpy(tmp_pmd_table, + pgd_page_vaddr(*pgd_offset_k(KASAN_SHADOW_START)), + sizeof(tmp_pmd_table)); + set_pgd(&tmp_pgd_table[pgd_index(KASAN_SHADOW_START)], + __pgd(__pa(&tmp_pmd_table[0]) | PMD_TYPE_TABLE | L_PGD_SWAPPER)); + set_pgd(&tmp_pgd_table[pgd_index(KASAN_SHADOW_START) + 1], + __pgd(__pa(&tmp_pmd_table[1]) | PMD_TYPE_TABLE | L_PGD_SWAPPER)); + } cpu_switch_mm(tmp_pgd_table, &init_mm); clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel