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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 90610C6FA82 for ; Wed, 21 Sep 2022 15:20:25 +0000 (UTC) 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc: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=ERdQ3sc4TKz3SylhxHaBzcaGDwt6MG9z1VeqoBdpyEw=; b=0OLcbXkm3PAxwb piLwXtiMg3SVtAkFB5dutuuaMD2XIMephGDZ3sGpeXdvPL/KC0ks15O/Ex8QwrEmO6bsWgpgxSIpE 2ssr+rnpgD1ViBG8zizvR4FiFYPZrtv3Ow0MWReTL5mJiq9avHKos2PoLaShnpFmIQca9Ee9JhcKt cthmzHTjrkVNQe37V1G10OjISs7NqFW5ez+YLmzxjp3XcMhUCeYY8LV6qzxP2Z5uvVrWJs1Gcjnq/ bJwCcZKEAj7bo+wjkIH/BLvyJjdjrtbML43nIuRCoowrBTLPZ6k50oMyFux/yAmlFyShRLf8iNsis rZ5/C6i7urbgmprYZgDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ob1Va-00BkDI-Ij; Wed, 21 Sep 2022 15:19:30 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ob1VX-00BkCg-Fg for linux-arm-kernel@lists.infradead.org; Wed, 21 Sep 2022 15:19:28 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0D1CB62685; Wed, 21 Sep 2022 15:19:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 275CDC433C1; Wed, 21 Sep 2022 15:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663773566; bh=dbFiBb96XQe4U0eDZ+uXd3wxcpqjYtrh6LsgsTTGho0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MPCgfALMkZMmrCpvLjMnb44QHoCKH55Z7hBvgBWNEX8T7NtvVuFFgpxyyuqVIZfTk 2ZF5WpTBGufJ/KRLGDuNlpZ4FtW7jWJoFnm7xHIzqSznBcYX8pJTsBAX7FVf5cGhem t/a4srQMQNtpXPZ6a6XEn7Gql/oz4OjT/sPt7M56GW/vAUXRNoDNXcoS4lFuEoOcFA 8zohy5kQhU9WqapK5dtERlOjEJ1gBQWxAdoZzCQyWO8szqFLSkGAaC/znVgbcwoC5W J1HJwHSPUKppX3cuAgwczPwn/nEbPsJD116nq0xDSDhu83GJ8lesjhimNef+4lH7P1 h3j4br5CKHM1w== Date: Wed, 21 Sep 2022 18:19:12 +0300 From: Mike Rapoport To: Anshuman Khandual Cc: Catalin Marinas , Will Deacon , Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64/mm: fold check for KFENCE into can_set_direct_map() Message-ID: References: <20220921074841.382615-1-rppt@kernel.org> <1a87b8a4-46f0-69c9-83ec-10cce8f0aa72@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1a87b8a4-46f0-69c9-83ec-10cce8f0aa72@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_081927_617494_D67573CA X-CRM114-Status: GOOD ( 27.44 ) 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 Hi Anshuman, On Wed, Sep 21, 2022 at 05:09:19PM +0530, Anshuman Khandual wrote: > > > 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 ? Yes. Since KFENCE disables block mappings, these will actually change the page tables. Actually, before this change the test for can_set_direct_map() in these functions was false negative when CONFIG_KFENCE=y > > static int change_page_range(pte_t *ptep, unsigned long addr, void *data) -- Sincerely yours, Mike. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel