Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4991930rwb; Wed, 21 Sep 2022 01:21:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nTFUhejx7qReCerY5JgfuzXe/SF0wpstx0sq/Oe7WW/vaMaoSvqmsDafLDkaDSbyJ3SsU X-Received: by 2002:a17:903:18d:b0:178:28d1:4a13 with SMTP id z13-20020a170903018d00b0017828d14a13mr3611639plg.160.1663748479800; Wed, 21 Sep 2022 01:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663748479; cv=none; d=google.com; s=arc-20160816; b=IPkXeV6hi+8YARJmAbF5J5jVGhVN6IY/Q9hSQHzAplQ7bqwZvfXoZpJk/Xu/6ZjhRK L/lmrL+2slPZd8UXyz6x2QBHYzBY1N2t3bz4waKf31eu/zBmME8fKJWoLlnJppxMo5Mi N/DrwgCA+EJAVQcpSjkO3yag0XSmHaYdDSdElmqEtesuwYilbfhZqlfu1tHleKPGEbrS utzb1RLxQkC1qCE+S3DGbTRbrSORE61BWleZuZBwKsmbVNsr0O1ESD/42Ql90dLKAnRp j4aD2tifCp9n7ezDenwLD4cJxWYAqBrwNyRN9nkUFUVAKr5L2NxMJZEQO6kSCXZ21nyO /qHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4EEdk8yCAxoiuXcOsN/rBJefpouX89Q4vnjbUmw8y6U=; b=KZ7u0GsynxuiYETxyGzlEkZP+OIZjIqWbnXLw5vumfhXMU37kqATxCtNFAAvgZRJrk orEYGbmCyQpcn9idy28hXWwUmkWf1pSIfiKoIkOUMDRME603Qi22QXX6yrHN/ubq+A9w ilKSBfOpOWEkTkpVa9F8WFMJrvGOZAXEMzqv0629j3jM5mWjZN9C9C2zTfJbcis7eyc+ 6t2KoV5lUPQDF035GNH0hz65VTwELfed/SD7t50z6kbnnBZtOG1EZZ8MP4wwHlNVePVm WU2LF7mQHN2eQa1K1fXKvWJppGkdqt72PtPiroL27N/L/NWbGJR0n//FhI1GQCaRJ+1K Iypw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DbCIWuPq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a62ea09000000b0053b9c18617esi2005701pfh.300.2022.09.21.01.20.49; Wed, 21 Sep 2022 01:21:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DbCIWuPq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbiIUHtB (ORCPT + 99 others); Wed, 21 Sep 2022 03:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbiIUHs6 (ORCPT ); Wed, 21 Sep 2022 03:48:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4910D85AB7 for ; Wed, 21 Sep 2022 00:48:57 -0700 (PDT) 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 55E1762890 for ; Wed, 21 Sep 2022 07:48:56 +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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 --- 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) -- 2.35.3