Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp263662rwb; Wed, 21 Sep 2022 22:01:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62tfrPFfGP98K6SB2jU6k0526fJxrmuR6X9sjBo34UsKovikncwEGpK6Jdkw2nakn7Dnkv X-Received: by 2002:a05:6402:400e:b0:44f:1b9d:9556 with SMTP id d14-20020a056402400e00b0044f1b9d9556mr1398351eda.208.1663822907092; Wed, 21 Sep 2022 22:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663822907; cv=none; d=google.com; s=arc-20160816; b=EH6L6UmE/hXphA5TjceL9T+QZQ7cKUkoeSg/K6YSeVFu5t0Vuz7fg2mXfgynJgK2LN NQ3vJML9MeyE7Pw8BWGakXeD+DzXP3N5e/W4kfx7729Txdcs12Kjt9bVI/uKCV9O3Cta bRCxnEo1a2C1bFFGjZyt4Z4dEeb7Nmw29r6HHF1bzcYPX20WYjRjdSYwt0fL2x8PJo+e q7ViCMnIZ3dQ8CDT5ChIH7XFL4Y2bAeAEbw6rhn71XmW0HnWOYc+U2rWkVCFTiJgf801 RIw/sgnXONGhnQqJUIt2CTXTU9OWiXVw6g0wjDjoE04BYySb73yxH5KKh3ZgchqWFapB s47g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2aNHiv7LxndVCnk40c2BSUrQpGzurP8P3VcUx+DV+90=; b=olOMLJtRHG2xVgUC+s4bU3gn4Ay9D9ZyHnkfwrzVfSHkPUbHJ56YimONnpyOfLVxOY bGqty3W6UMsF5Bc1X94Amd5Wl/ZVAYXkLxLeCgl3q8G47+PaLn0uEjJbRqTVT/fCB6Ti Z1ZtRUg3MbzdAxWdeP9LII7jfRSISgoJwzYlOn2gqVCji5y27offT3c0FcT8KB2NxydP zAPKhE0yTlDyDtJXroXhJUt2AqtLqMWEofUwS0W5AujY7qWHiCs9wstTYVIAelrXmSkM aVFQsaSqAAhHAebIFN2FidAC14lKoYW0q2Gag0Zx0VRtpcm1fMvt2Z+pquhFygfcacdz 8Ylw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sOV5alI5; 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 sa27-20020a1709076d1b00b007825337afeesi838153ejc.273.2022.09.21.22.01.14; Wed, 21 Sep 2022 22:01:47 -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=sOV5alI5; 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 S229771AbiIVEgJ (ORCPT + 99 others); Thu, 22 Sep 2022 00:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiIVEf7 (ORCPT ); Thu, 22 Sep 2022 00:35:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7EEE7C74A for ; Wed, 21 Sep 2022 21:35: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 ams.source.kernel.org (Postfix) with ESMTPS id 65688B8239B for ; Thu, 22 Sep 2022 04:35:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07B5FC433D6; Thu, 22 Sep 2022 04:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663821355; bh=pyeFh9s8VF6usTdLZxp7Y3s3vv8L4E2Hw3/+Q8rJiUc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sOV5alI5m0Gd7fkLhqPYfZ/a2lR0KXiK6AQR2aWP/H117uu8S8KaPY62ngNevxdmO PRR3STFQkfxpnuE6XDjH0grcisI42ZEPFMH7gdqlGjnso69C4hHboADShgjJvSr+yH MR9vMh1MJ89zT0PG8THMcyXWwCvBUJYAF+lvjm6OxS3d/iLopUDlzg3sMJb4X11ocd VD7+41UQXBaxS6KIucWGM9ShoJDUSPiayK+YASv5IrO+tkX90FSzneioJ107mVkXLP L6rdO0lt0MDKasH1u4PpJ1yLDAtHFbVly+tYdNxlTLboRnP3J6uxHaCh+KTargMJTs gJbcxJGA6v96Q== Date: Thu, 22 Sep 2022 07:35:41 +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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Thu, Sep 22, 2022 at 08:21:38AM +0530, Anshuman Khandual wrote: > > On 9/21/22 20:49, Mike Rapoport wrote: > > 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 > > Okay but then should not this have a "Fixes:" tag as well ? I feel that this is more of a theoretical bug and it's not worth backporting to stable. > >>> static int change_page_range(pte_t *ptep, unsigned long addr, void *data) > > -- Sincerely yours, Mike.