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 6AB9F1F099C for ; Fri, 31 Jul 2026 05:21:18 +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=1785475279; cv=none; b=cuZf/0hFbTLrCJFjg0tzfEAiNHYbGrJx5KHplJ3Ky/OE3U7G8lIyvsfYTiH8/9LV2d+Oj5AGubxHhhABqY6MQyKBNv/gZYkkufTRPezYte6CGU5uUH/Z9sjOA9oEaQ8XNX9lC6Ph7rEWCjWDPqlu0pa6Mpj7yDu7+OXsIic2riE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785475279; c=relaxed/simple; bh=G+3yitoznMfLBGOlWoRjuda33K4HG0bChuH06RGOTMo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pmwLooMqi7ViUDypFBOWSwLdNbT0lX8cJGKFaeoJBgAHYmHHKHdvQUokxb0nqgjmAUV9gnZCnYvlR512ev+LDtxMCxd1GuE7PZfs3dnkSPOP2IhC0hlEgGU3RULu16O4c2ZsSg+nsZ50YE1Jp/b1Utnz8fCpVipJPCobkUSRjlk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FTRgX+Q/; 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="FTRgX+Q/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D3B21F00A3A; Fri, 31 Jul 2026 05:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785475278; bh=YJjBnEkh+nKHKY+8/SylN01ajLlOLYOCTOua+gFNFzU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FTRgX+Q/6LPx/bvDmDU2kJ8GmAsSNZui+PwVv4w61rL39dDN+2G4enh2VmRozbYn7 GsJbcHWY2ijfeq1hNqCZi/+5CZNATEMUGN+NGRIQQnZn98SGbEuaON+JGNeIPrSQn5 86T3bIan+pShYe5kWz5wOKhgF1CL11s0XSD0NDhY4U1chBowSHfKcbIRmGV028Blt9 D4EmmcMcsX2VpqRWA55TOBkh21SUAIw0ENDA/MKBMTJkU5ecuzoQEtRHTQyWcp3Cv0 yvm+vszfZbuMimHyJy2OiLJL2e04N4YrpSkkGy/laeVYd9BQVybLMKHZC/IsISTNXD r4+/mJDA/Wp9A== Date: Fri, 31 Jul 2026 08:21:05 +0300 From: Mike Rapoport To: Yosry Ahmed Cc: Brendan Jackman , Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, Sumit Garg , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Patrick Bellasi , Reiji Watanabe , Sean Christopherson , Nikita Kalyazin Subject: Re: [PATCH v3 01/26] set_memory: add folio_{zap,restore}_direct_map helpers Message-ID: References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> <20260726-page_alloc-unmapped-v3-1-6f5729aa9832@google.com> 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: On Thu, Jul 30, 2026 at 08:34:57PM +0000, Yosry Ahmed wrote: > On Sun, Jul 26, 2026 at 10:22:34PM +0000, Brendan Jackman wrote: > > From: Nikita Kalyazin > > > > Let's provide folio_{zap,restore}_direct_map helpers as preparation for > > supporting removal of the direct map for guest_memfd folios. > > In folio_zap_direct_map(), flush TLB to make sure the data is not > > accessible. On some architectures, there may be a double TLB flush > > issued because set_direct_map_valid_noflush already performs a flush > > internally. > > > > The new helpers need to be accessible to KVM on architectures that > > support guest_memfd (x86 and arm64). > > > > Direct map removal gives guest_memfd the same protection that > > memfd_secret does, such as hardening against Spectre-like attacks > > through in-kernel gadgets. > > > > Acked-by: David Hildenbrand (Arm) > > Signed-off-by: Nikita Kalyazin > > [Added comment, dropped modified set_direct_map API, added highmem check] > > Signed-off-by: Brendan Jackman > > --- > > include/linux/set_memory.h | 13 +++++++++++++ > > mm/memory.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 59 insertions(+) > > > > diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h > > index 3030d9245f5ac..1bf2a15bca118 100644 > > --- a/include/linux/set_memory.h > > +++ b/include/linux/set_memory.h > > @@ -40,6 +40,15 @@ static inline int set_direct_map_valid_noflush(struct page *page, > > return 0; > > } > > > > +static inline int folio_zap_direct_map(struct folio *folio) > > +{ > > + return 0; > > Should this return an error (e.g. -EOPNOTSUPP)? Seems like it would > silently succeed if the arch doesn't actually support removing from the > direct map. That's the pattern we have now for all set_memory APIs. -- Sincerely yours, Mike.