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 2ADB938838B for ; Thu, 30 Jul 2026 20:35:03 +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=1785443710; cv=none; b=e1WMiV0oJVFH+fV4OGVDjFwBQyRVW3hKOTCAkdNXpFjbe32+OPUKpd3f8KuS7CCI7dfTA8T/3lDlHtlkJDmXEZZGp5r2g+oMmXwJ2Xc2wrYrQXNu8FxRT91+BqhtRmXDylFOfNfjNmrwjvIBp3oTJ3jF5Y+VSUp+mwhwn8cOwGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785443710; c=relaxed/simple; bh=fz0YO17ikWeJ63UH1JNiVqG3gKWJd4E3tk/R5zKwHis=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rlwGnv1V4Ky5foHa/2zgkcXugoZN3MQg0XLvzbF8NIDTJx6ICDIHLJd0Hwr6ZnBqUwhRN2EXEMXDuf8yknJvI4Z1ETNU8RR09YIYH0wetW8/qpi82+ok5DdzSDdefFCHiPNpPTFqn6mvvWejR68eeX77GQp9r/bHnLLVXleYyys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k9Zp8zfa; 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="k9Zp8zfa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EA7A1F00ADF; Thu, 30 Jul 2026 20:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785443700; bh=kxPQVUUeBFMYjUQxP77IGXtrmE4HtaqYq+gTa7cv8Bw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=k9Zp8zfa1ZmOgIw9AvsC0jJ3gGh7VbtLISPNsLrxUqcsBAt9qAuUDY11NK7V0XtTL h3Ada4S50vzVNffn6XMcfann7GJH40vy0tUzoYh9/Q0hc1XuFft1lwOyrAz0W3/2ez C8YPfSzIH0/gzCO5xnHwiICmh2+S/CWP7o69hrz1Xq60SGt4Kek2E2c+40pyotrWLn L++RQ00DlNYtkSMHuABLS1PpMjnlpEwYMjRfAZk75De9n6gifR4xMwwbdx+vY9WgAc xUm597feIzpmo2R7FjKGr8XSpjHqr+S29XtVhlzhif62yJiSHNT+PkiQ54pbf+q5tO 3Vkaj6f2LfI1w== Date: Thu, 30 Jul 2026 20:34:57 +0000 From: Yosry Ahmed To: Brendan Jackman Cc: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , 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: <20260726-page_alloc-unmapped-v3-1-6f5729aa9832@google.com> 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.