From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B35B5606A31C for ; Mon, 30 Nov 2026 18:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hgH6W+6I; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=W9tvgmOP DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=C8ue8zOfS3Vyhx+sgV6tOcKLVltdRWMuzLuedLKtw4U=; b=hgH6W+6I5dUZ/0pC7SgctsJqHY 7z2JERWrhDDrdfsJuduqGfs5vBI4UyziCzmS2WlishwtYjor4YDpGxHWOxbsHs3WozXXDhs7W3TVJ NDxjithsfa4/lBtoFpijuPX1IrbIhD+KQHzN+90IoojuMNKnVNvVzL8n6GBJNx1yx98rnxMCnQLMB 0BYfE+qIU2jLBfb/u1evlHhcPHRQyY+aDKkxIyR/pkLywsFrqYMnolf0PVB41h++1WBNeStfAwXsI gPuPg9T/OxuxM8fjQXulCACsI0Z7F0Km1piGA4ZRlCVUGBNGCiEE7sn/JzktP5J4i/SN+mnrAvIfH J3jG99XA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY6LD-00000005gQb-0DeY; Mon, 30 Nov 2026 18:43:07 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY6KK-00000005gMf-35Nh for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 18:42:15 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso100200125e9.0 for ; Mon, 30 Nov 2026 10:42:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796064131; x=1796668931; darn=lists.infradead.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=C8ue8zOfS3Vyhx+sgV6tOcKLVltdRWMuzLuedLKtw4U=; b=W9tvgmOPE4R7Tdr2lLs4CAQ4+Wbw9bQ/C+TwJ4szWFCa4WH8GjvrbNdIYuH5WvpZMS rRLh13r80EYLXDF+Wwci1TSRkjHLVJhgW8dPKD+1UlCc/oLXw5hvkq7FR7GyPAHlQem5 /Z2K0eZBu7tbydtsN7mHYWS8o733Q2yzOOO6EoOgozumTvnUsqGpQPZ1VGg3I5S4IDJI zs6iJS91Pek7zdSmEhf7WuvbkxicVEfQIxKq2y4JMsKKovANB/10mv4C1w+CzqyVJA8a DTnT6+IvukrttO3OR7mJvwe7PWLhbWutS4m9j7aGL8bNa4aXHO1HXFzkCpdB+bL5rcz4 zGSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796064131; x=1796668931; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=C8ue8zOfS3Vyhx+sgV6tOcKLVltdRWMuzLuedLKtw4U=; b=SH4+A3f1Eq4KqKqCFO+URQ7/axVAEGLXdaH/GGueqtvIlkgBavED1Z6uNHHyYacqPO m4kNwnnUsXlPrQl8zFZq9V+2dWOrhbfAktP+nVuWJsDsCJbKT6rlERxx6MYf/hBB2MJl rqlY47jD3CUzNKA5XudeVuEvC84cqHkkMweghGSdxSiVZO7HlGUCwV8xF3GNnTzduRrt Mfu+k73JuMdhv4jocbaoHdvrYSf/KYo+8ME1007xKDliZqSNxeoVaQLYaxdKBFY6S/yD x8hp3MycAo4t11KureNR6Fym8+WvMHKFyLBANaPkRi2rVhbx9AuuYzz2W4fM33/dzdyb tSCQ== X-Forwarded-Encrypted: i=1; AL+hErHVF0kREddx/Zb1laudmr1yZU/xPGrA6Kmh57XpwqljAn6hni6UbsG1MXHts/bMvEwf1VL54DTAlu1KwQbTSTm8@lists.infradead.org X-Gm-Message-State: APuU4Z9RF8Q+wIrokP5dOaTSSYnTeX8Pw7a+a8VJ04w/VNuIer70Gzk+ kjLlviuatIkziyjFUYn1Lhp9KWVwPWUWqafmVgKHrTnG8so4XjiR/e8VAzAzswYFVg== X-Gm-Gg: AZFdTZcsS4SpyfivIKjm25j8XG1OhQ502hO2gFf9fwDlkoJFy45MAS+/dfjzX65SL+s NCDOjHkv/YgnlrO05JptNxnhT8gaZxei8EFpgByGFSHbqUWAQTnUni91P5nl0T2JON3Lj1j+4CV bqyBCm0pgHjntlBdjTaNOftTbYMou6YssV8Ng30JfoYGWfppeOobyDE/DhfszpIypAM0c+MrPb8 7+iwvUMG0Yqpg/hQaPlKinx9nX5ubZC633cK5IWWXrxcvbAsvgZP7ZjPoJC3Inv5zUkeOPJMcTV iaWiPh150zStKL6J/fufrk7F+wjabfK8mmeX32kTi9vBzxC/FLIFTxzFBuEv5dYaDeGUOKjcscX L13Y8/8X+rO+H2NA0KKTJQGnDlIGg6vYAgwY2yUZtuz7NyeQH+99/dOWCJ6KAX1BFVimmGNm7eu Iev5WoOJtolP2yjlBwTY5aJzRJQdEP7HmQ4CaBUupV3wNUsTFD2cef+teNcK+hlx30m1KTVMIrP KP/GhD9yqqaS835bt+3hDcPVxOqV/Bf4YNG9aQ9iutrD/SBrjTcoz5P6a/Tjzrv4TqGR7ENS12y WENRzLG95uUr3jENuLEV2e4Xi0BEzS1kTAPJaQVnoMR782pSgjQwgO1tqGh6RNu78jRNgX7B+g7 7hPDGS5+gKvP9vASH2U+fx8gYRmI2XwCRqHDDEQqX2FQ= X-Received: by 2002:a05:600c:848a:b0:4bb:6626:5a25 with SMTP id 5b1f17b1804b1-4bb88813462mr581782765e9.20.1796064130411; Mon, 30 Nov 2026 10:42:10 -0800 (PST) Received: from google.com (0.182.34.34.bc.googleusercontent.com. [34.34.182.0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb905f1489sm650143205e9.0.2026.11.30.10.42.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:42:09 -0800 (PST) Date: Mon, 30 Nov 2026 18:42:06 +0000 From: Vincent Donnefort To: Will Deacon Cc: catalin.marinas@arm.com, rafael@kernel.org, mark.rutland@arm.com, lenb@kernel.org, pavel@kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, thierry.reding@kernel.org, rppt@kernel.org Subject: Re: [PATCH v1 3/4] arm64: mm: Introduce linear_map_needs_set() helper Message-ID: References: <20260918131656.3710047-1-vdonnefort@google.com> <20260918131656.3710047-4-vdonnefort@google.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_104212_939995_212F7956 X-CRM114-Status: GOOD ( 23.45 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 [...] > > +/* > > + * True if the linear map needs to be modified for one of the following > > + * features: > > + * > > + * rodata_full and DEBUG_PAGEALLOC need to protect/unprotect pages in > > + * the linear map. > > + * > > + * KFENCE pool needs to protect/unprotect pages in the linear map if > > + * initialized late. > > + * > > + * Realms need to mark pages shared/protected in the linear map. > > + */ > > +bool linear_map_needs_set(void) > > +{ > > nit: I'm not a big fan of this function name, but see below. > > > + return rodata_full || debug_pagealloc_enabled() || > > + arm64_kfence_can_set_direct_map() || is_realm_world(); > > +} > > + > > static inline bool force_pte_mapping(void) > > { > > const bool bbml3 = system_capabilities_finalized() ? > > @@ -785,7 +803,7 @@ static inline bool force_pte_mapping(void) > > return true; > > This 'return true' above is part of a check for debug_pagealloc_enabled(), > which is now redundant because you've added that to linear_map_needs_set(). The redundant debug_pagealloc_enabled() is the one in linear_map_needs_set(). I believe this one is necessary because we must force PTE regardless of bbml3. > > > if (bbml3) > > return false; > > - return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world(); > > + return linear_map_needs_set(); > > } > > > > static DEFINE_MUTEX(pgtable_split_lock); > > @@ -1203,7 +1221,7 @@ static void __init map_mem(void) > > > > arm64_kfence_map_pool(); > > > > - linear_map_requires_bbml3 = !force_pte_mapping() && can_set_direct_map(); > > + linear_map_requires_bbml3 = !force_pte_mapping() && linear_map_needs_set(); > > That looks pretty odd now that force_pte_mapping() calls > linear_map_needs_set() under the hood. > > I wonder if you should avoid introducing the new function and just put > the logic in force_pte_mapping() instead? You could rename it to > linear_map_force_pte_mapping(). > > Then map_mem() just needs to check force_pte_mapping() whereas > can_set_direct_map() is force_pte_mapping() || has_bbml3(). > > Will I am not sure we can get by with just linear_map_force_pte_mapping(). When false, we still need to distinguish if this is because we have no feature that requires PTE level mappings or if it is because we might be BBML3. How about something like: static inline bool linear_map_needs_split_or_ptes(void) { return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world(); } bool linear_map_force_pte_mapping(void) { ... return linear_map_needs_split_or_pte(); } And then perhaps this map_mem() snippet is easier to reason about? void map_mem() { ... if (linear_map_force_pte_mapping()) flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; else if (linear_map_needs_split_or_pte()) linear_map_requires_bbml3 = true; ... } -- Vincent