From patchwork Wed Sep 21 07:48:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12983325 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 1FC5BC32771 for ; Wed, 21 Sep 2022 07:50:06 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=OEAlGwYvh6hVBKhmwOz7fCEAqLu+lbHFrnNo7ksS+4g=; b=4qmX5lN1+2ZksG KKeE6414lpyp4slSIkJFVOFI6cZsXzv3yEuRwNUmbtB2rjKN4CQTfp5sH4z2Q3bCnnBlWbuqVLFrx gazaeFvnYzIVJeU4dwv5x5B+GNx479Wa3uUa7X9jXeaS+Lvopu8LFuvaXcNb5SYcJCEo/Crv/Zq37 1ZMqOhvWSnevh480sfGr5HCEjfw8mw2iQppj1sfvOlihZvo0AOZyrIXhxHI+4yo39QhUSKwD6Tcq4 DEFGdhbA5Khh3i5aKj9k4bAElVs5XDS7fuTJUvNZ+cz9OdT6uwa6Tj8Jg2iLS0Efi4ivtzuOxqZaV y9eTxFYoeoI33snw8xkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oauTe-009h5S-Sp; Wed, 21 Sep 2022 07:49:03 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oauTa-009h3o-G2 for linux-arm-kernel@lists.infradead.org; Wed, 21 Sep 2022 07:49:00 +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 ams.source.kernel.org (Postfix) with ESMTPS id 0BEA0B82E4C; Wed, 21 Sep 2022 07:48:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DDEFC433C1; Wed, 21 Sep 2022 07:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663746535; bh=IzRgoxZ6RnaM4sIz+et5DXk5atJjzwXvP8kXZDGpFW8=; h=From:To:Cc:Subject:Date:From; b=DbCIWuPqOvmII3MueM54cgiUWWfQ+1BUCg5m0OqB0SQQfrUiFyPNFUNYnoeNpyfHK Q9RYQn6ZETswdPjOM4f86LCrVUi9T2rrZom/e58q82hJJTkp+WZ8fKDKwFMhObwwgf 733GPgF4faztXTv3HyUS3iuThQ7VEbLPD+dpjy44q6ccFTIZGGABXv9s598IsOisZZ 3+tTegtFCWc2Dc/vDiWvZYlo4FhnnedeKkWbJkhNNVas/aIrEV63uHsFHqn4soWdVl F0aFRR65ExQDko2+ZZ3pKGV0+WOVM4Zbe0WO65TLUZ9sCzlm2Rq4kqQjW/iW9AMrpF C/QdvM9q7qVHw== From: Mike Rapoport To: Catalin Marinas , Will Deacon Cc: Mike Rapoport , Mike Rapoport , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64/mm: fold check for KFENCE into can_set_direct_map() Date: Wed, 21 Sep 2022 10:48:41 +0300 Message-Id: <20220921074841.382615-1-rppt@kernel.org> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_004858_701782_199954C1 X-CRM114-Status: GOOD ( 14.46 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Anshuman Khandual --- 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); } static int change_page_range(pte_t *ptep, unsigned long addr, void *data)