From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3255A46AF25 for ; Wed, 3 Jun 2026 12:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780490152; cv=none; b=Wf7OoKL4lwtBz6V2JMTBh4wzeBinTQyRyqMIuMrU5YWLTRqalV3trg3N2YjkTELM8SIcTn37ao0kPr3zlCblIHT0enZSflLTHe2f2i9HK23J1h8r8NK4o/ODtQARveLyl7vm3CQVxOWZBeByWJJAprbmrAbzOcQCoQmFs4As+uM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780490152; c=relaxed/simple; bh=e8KnwBL8oHeSR7y1LPOgdfaPHDjT2hUcgBj2BPOAYHw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g3O+ZCB0Jg5D0SDUlHwBnYWPh9BMMcZB7df5X2pLdp731pxlWMCzRXfPtypSXIAqyvHE4yPekpHUMoUre1tJ9/71FLV+Eql7Q6b1o/I7+XTVG9LWxYNmSy/t4CJfMGAFXFbrxTRmOMPPrA0BUM2G0K9yTWkKqonK5+mDZpO1fiM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LKDfMWcx; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LKDfMWcx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8508D1F00893; Wed, 3 Jun 2026 12:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780490150; bh=zbzStD6JF1CVBiCJzS07Yx88ycASZSaAr8mU89zlpzw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=LKDfMWcxrynE0rXIrrwYN/aoUZ2Rgr+E7/lykSCJqfQ+90yFbvcrUGEy2YLi+LqgX TFbKhd/5Mt+uOUtmr7Kc0ZKGKFy9lneoTjtb3jPxdvb///0N2nDi8hJi99ka4rG+3Z cLRADL++t8XhL5W+ATn8P9mdV4q4hhiAsy6jRkfMGD7YZ776ni+p5SUzHZp1Y0ZuA8 3YZSpJieKtAFSAA2VE8sMMJuuCUA66UpgOzL0kpZaZZlTIR71c8o3zvhMwx8LjrJXa YheH+bQMYE/8eoFTvvjGWVtxEC5hoXpPZKvh5aZyJUiIHzbzlHQZuy2hDYPySoGqHX j9vQbes5fpEdg== Date: Wed, 3 Jun 2026 15:35:43 +0300 From: Mike Rapoport To: Lance Yang Cc: akpm@linux-foundation.org, david@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, peterz@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, xueyuan.chen21@gmail.com, ioworker0@gmail.com Subject: Re: [RFC PATCH 1/2] mm/secretmem: try to restore large page mappings in direct map Message-ID: References: <20260603114134.3010-1-lance.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260603114134.3010-1-lance.yang@linux.dev> On Wed, Jun 03, 2026 at 07:41:34PM +0800, Lance Yang wrote: > On Wed, Jun 03, 2026 at 01:59:39PM +0300, Mike Rapoport wrote: > >On Wed, Jun 03, 2026 at 06:46:23PM +0800, Lance Yang wrote: > >> From: Lance Yang > >> > >> secretmem removes the pages backing secretmem mappings from the direct map. > >> > >> Removing one base page from the direct map can split the covering large > >> mapping down to PTE mappings. Repeated splits can leave more of the direct > >> map mapped with PTEs, meaning more TLB entries for the same range and > >> potentially more TLB pressure. > >> > >> So let's try to restore large page mappings whenever secretmem restores a > >> folio to the direct map. > >> > >> Tested-by: Xueyuan Chen > >> Signed-off-by: Lance Yang > >> --- > >> include/linux/set_memory.h | 6 ++++++ > >> mm/secretmem.c | 12 ++++++++++-- > >> 2 files changed, 16 insertions(+), 2 deletions(-) > >> > >> diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h > >> index 3030d9245f5a..ad2fa414a22d 100644 > >> --- a/include/linux/set_memory.h > >> +++ b/include/linux/set_memory.h > >> @@ -58,6 +58,12 @@ static inline bool can_set_direct_map(void) > >> #endif > >> #endif /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */ > >> > >> +#ifndef arch_try_collapse_direct_map > >> +static inline void arch_try_collapse_direct_map(struct page *page) > >> +{ > >> +} > >> +#endif > > > >Did you explore what would it mean to hook collapse_large_pages() into > >set_direct_map_default_noflush()? > > Good point, I kept it separate on purpose :) > > Putting collapse into set_direct_map_default_noflush() would change the > semantics of that helper a bit, IMHO. For x86 default means present + rw + PSE, so yuu can look at it as actually better enforcing the semantics :) > I would expect arch_try_collapse_direct_map() to also be useful for cases > where a direct-map permission change could split a large maping first, > and the user wants to try restoring the large mapping after changing it > back. One example[1] is making a direct-map range read-only for security, > which I am also working on :) I don't think users should care. The users care for particular permissions of a range in the direct map. It should be up to the architecture to select most suitable mapping size. The splits are implicit, I don't see why collapses can't be implicit as well. > [1] https://lore.kernel.org/linux-mm/9979fa87-88ef-4baf-8592-502ff4888085@kernel.org/ > > Cheers, Lance > -- Sincerely yours, Mike.