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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32FA3C32771 for ; Wed, 21 Sep 2022 11:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbiIULj3 (ORCPT ); Wed, 21 Sep 2022 07:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbiIULj0 (ORCPT ); Wed, 21 Sep 2022 07:39:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C58CE8E99F for ; Wed, 21 Sep 2022 04:39:25 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CD9D113D5; Wed, 21 Sep 2022 04:39:31 -0700 (PDT) Received: from [10.163.58.166] (unknown [10.163.58.166]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5FA1C3F73B; Wed, 21 Sep 2022 04:39:23 -0700 (PDT) Message-ID: <1a87b8a4-46f0-69c9-83ec-10cce8f0aa72@arm.com> Date: Wed, 21 Sep 2022 17:09:19 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] arm64/mm: fold check for KFENCE into can_set_direct_map() Content-Language: en-US To: Mike Rapoport , Catalin Marinas , Will Deacon Cc: Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20220921074841.382615-1-rppt@kernel.org> From: Anshuman Khandual In-Reply-To: <20220921074841.382615-1-rppt@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/21/22 13:18, Mike Rapoport wrote: > From: Mike Rapoport > > KFENCE requires linear map to be mapped at page granularity, so that it > is possible to protect/unprotect single pages, just like with > rodata_full and DEBUG_PAGEALLOC. > > Instead of repating > > can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE) > > make can_set_direct_map() handle the KFENCE case. > > This also prevents potential false positives in kernel_page_present() > that may return true for non-present page if CONFIG_KFENCE is enabled. > > Signed-off-by: Mike Rapoport > --- > arch/arm64/mm/mmu.c | 8 ++------ > arch/arm64/mm/pageattr.c | 8 +++++++- > 2 files changed, 9 insertions(+), 7 deletions(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index e7ad44585f40..c5065abec55a 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -535,7 +535,7 @@ static void __init map_mem(pgd_t *pgdp) > */ > BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); > > - if (can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE)) > + if (can_set_direct_map()) > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > /* > @@ -1547,11 +1547,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 (can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE)) > + if (can_set_direct_map()) > flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; > > __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start), > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c > index 64e985eaa52d..d107c3d434e2 100644 > --- a/arch/arm64/mm/pageattr.c > +++ b/arch/arm64/mm/pageattr.c > @@ -21,7 +21,13 @@ bool rodata_full __ro_after_init = IS_ENABLED(CONFIG_RODATA_FULL_DEFAULT_ENABLED > > bool can_set_direct_map(void) > { > - return rodata_full || debug_pagealloc_enabled(); > + /* > + * rodata_full, DEBUG_PAGEALLOC and KFENCE require linear map to be > + * mapped at page granularity, so that it is possible to > + * protect/unprotect single pages. > + */ > + return rodata_full || debug_pagealloc_enabled() || > + IS_ENABLED(CONFIG_KFENCE); > } Changing can_set_direct_map() also changes behaviour for other functions such as set_direct_map_default_noflush() set_direct_map_invalid_noflush() __kernel_map_pages() Is that okay ? > > static int change_page_range(pte_t *ptep, unsigned long addr, void *data)