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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 78C61C2B9F7 for ; Tue, 25 May 2021 00:44:39 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 40A0D6135F for ; Tue, 25 May 2021 00:44:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40A0D6135F 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=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc: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=in6LLUvl4PzHWatCdECHknWZQNGaVLx0q4hbdS+U3AI=; b=G5ewEBV2nFec9M UoGGx1Pek86B7nUvmUXdaISySG3Rh2WEBKxkolBDXGS9NZbER/QkmGL2Bp5xv8CaZpdrE3gJP06qP FDNnuXiURKYPaOBZac3Ckc01VOMfwkXqh02Pz2UxAKiWY3qkxCCig/ui9IGeuuaPISf7RUT13I6hx JbCJO0Wue/pITVEb3S6KW8KOE1hYh13dCiEEft3m0qMzD73U/a/2zTwJ0uBeBiK8hs5LpyxKwDZrV ZrN7AoEPCdTqyk7n5KBBycQtEXQkM824iGqiwuyoYc3nUWu7G+oyp2PglfEcsc6c192RkB6H3Efm5 gqfLmkb4qQ7UiotmXZ6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llL9b-002c5s-5i; Tue, 25 May 2021 00:42:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llEws-001OGa-Sm for linux-arm-kernel@lists.infradead.org; Mon, 24 May 2021 18:05:08 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BDB5C60E0C for ; Mon, 24 May 2021 18:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621879505; bh=KGRCoMcUCffmNqNMyYCNwM4ghBH4MssFfRhQ/aKFadw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BcdB6cNQvxd4u6LUFIOZOlNu8JlNiEjvUpUmxR71JMGIB8xYsyqiutXKAIZHgafcA 589dFAs9mMxTQFFFcbCIw6tA5SoQ+MIJSepIJSrA3o12WPR3rQYbFhhbkCiK8GW+s9 SXWgPB/U/sq5CrKW4He40cPP2SyHLL9fyBpTTQfnqfavjucq+DEaQUdZ+uq16c9lLm XTiSIAxs3VXos8NJcMkrJJxLDh4m50xlp7OXaRgGUZV23/sbhKxlBXc2CxjwUFJivp zBljbCjyTR4a1dquB+MqHFckUeVk+UJvWH7T00qMRIMHHX8JQmMAdBMyRxI+VqJ8Jy KTb8+vdFHwtSg== Received: by mail-ot1-f47.google.com with SMTP id h24-20020a9d64180000b029036edcf8f9a6so1740028otl.3 for ; Mon, 24 May 2021 11:05:05 -0700 (PDT) X-Gm-Message-State: AOAM531jpGZfdQoMaDpGbtxAKkCXqkstNGJZJR69E3pM2CCjyz3x2ZSu 2qFFCnjei8y5k+pA9Oxenb4zsl3NFi69j+ZCTAw= X-Google-Smtp-Source: ABdhPJzwa+eGro5LfpsUg8LpjxTeuWPx0fycPTgtYU+cKxtT4ii8rv0+oT0G8vyH2SBT1iB3LZJFWVcv8tiG7iSQL/c= X-Received: by 2002:a9d:7cd8:: with SMTP id r24mr19941356otn.90.1621879505060; Mon, 24 May 2021 11:05:05 -0700 (PDT) MIME-Version: 1.0 References: <20210524172433.015b3b6b@xhacker.debian> <20210524172606.08dac28d@xhacker.debian> In-Reply-To: From: Ard Biesheuvel Date: Mon, 24 May 2021 20:04:53 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] arm64: remove page granularity limitation from KFENCE To: Marco Elver Cc: Jisheng Zhang , Catalin Marinas , Will Deacon , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , Linux ARM , LKML , kasan-dev , Linux Memory Management List , Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_110507_020958_1493366E X-CRM114-Status: GOOD ( 33.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, 24 May 2021 at 19:31, Marco Elver wrote: > > +Cc Mark > > On Mon, 24 May 2021 at 11:26, Jisheng Zhang wrote: > > > > KFENCE requires linear map to be mapped at page granularity, so that > > it is possible to protect/unprotect single pages in the KFENCE pool. > > Currently if KFENCE is enabled, arm64 maps all pages at page > > granularity, it seems overkilled. In fact, we only need to map the > > pages in KFENCE pool itself at page granularity. We acchieve this goal > > by allocating KFENCE pool before paging_init() so we know the KFENCE > > pool address, then we take care to map the pool at page granularity > > during map_mem(). > > > > Signed-off-by: Jisheng Zhang Could you please share some performance numbers that result from this optimization? (There are other reasons why we may need to map the linear region down to pages unconditionally in the future, so it would be good to have some solid numbers about the potential impact of doing so) > > --- > > arch/arm64/kernel/setup.c | 3 +++ > > arch/arm64/mm/mmu.c | 27 +++++++++++++++++++-------- > > 2 files changed, 22 insertions(+), 8 deletions(-) > > > > diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c > > index 61845c0821d9..51c0d6e8b67b 100644 > > --- a/arch/arm64/kernel/setup.c > > +++ b/arch/arm64/kernel/setup.c > > @@ -18,6 +18,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -345,6 +346,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) > > > > arm64_memblock_init(); > > > > + kfence_alloc_pool(); > > + > > paging_init(); > > > > acpi_table_upgrade(); > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > index 89b66ef43a0f..12712d31a054 100644 > > --- a/arch/arm64/mm/mmu.c > > +++ b/arch/arm64/mm/mmu.c > > @@ -13,6 +13,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -515,10 +516,16 @@ static void __init map_mem(pgd_t *pgdp) > > */ > > BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); > > > > - if (rodata_full || crash_mem_map || debug_pagealloc_enabled() || > > - IS_ENABLED(CONFIG_KFENCE)) > > + if (rodata_full || crash_mem_map || debug_pagealloc_enabled()) > > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > > > + /* > > + * KFENCE requires linear map to be mapped at page granularity, so > > + * temporarily skip mapping for __kfence_pool in the following > > + * for-loop > > + */ > > + memblock_mark_nomap(__pa(__kfence_pool), KFENCE_POOL_SIZE); > > + > > Did you build this with CONFIG_KFENCE unset? I don't think it builds. > > > /* > > * Take care not to create a writable alias for the > > * read-only text and rodata sections of the kernel image. > > @@ -553,6 +560,15 @@ static void __init map_mem(pgd_t *pgdp) > > __map_memblock(pgdp, kernel_start, kernel_end, > > PAGE_KERNEL, NO_CONT_MAPPINGS); > > memblock_clear_nomap(kernel_start, kernel_end - kernel_start); > > + > > + /* > > + * Map the __kfence_pool at page granularity now. > > + */ > > + __map_memblock(pgdp, __pa(__kfence_pool), > > + __pa(__kfence_pool + KFENCE_POOL_SIZE), > > + pgprot_tagged(PAGE_KERNEL), > > + NO_EXEC_MAPPINGS | NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); > > + memblock_clear_nomap(__pa(__kfence_pool), KFENCE_POOL_SIZE); > > } > > > > void mark_rodata_ro(void) > > @@ -1480,12 +1496,7 @@ int arch_add_memory(int nid, u64 start, u64 size, > > > > VM_BUG_ON(!mhp_range_allowed(start, size, true)); > > > > - /* > > - * KFENCE requires linear map to be mapped at page granularity, so that > > - * it is possible to protect/unprotect single pages in the KFENCE pool. > > - */ > > - if (rodata_full || debug_pagealloc_enabled() || > > - IS_ENABLED(CONFIG_KFENCE)) > > + if (rodata_full || debug_pagealloc_enabled()) > > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > > > __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start), > > -- > > 2.31.0 > > > > -- > > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20210524172606.08dac28d%40xhacker.debian. > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel