From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8379D3D47A6 for ; Fri, 7 Aug 2026 22:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786142658; cv=none; b=SWclbpdIi9w3uw2y24bVcY8a9ULS1Pu2haGn48uJSgI19AWxvJ8oRqrVzxPsyYonliohfG7J0UaKiHD8N3+zGJg6SIH6n4RTNRarbJIraOUw7sW8GOpglmn93MJU8sxfYSsHFwukZC1qBSloAlmkP4XiYK1Ets6XPDd10v6PbvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786142658; c=relaxed/simple; bh=RPiElr8F3BbF/1rA3J+F4L+PLAE2K6dEmW7lDcik8fM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hX+VlJv2JmPG+wjTotuw5TS8RR/zUUYRy4DgmMz5LxSmyXvWsSf0PKRbf3XqOrO2af0x0PKNRDTVsVALEExY2F53loVZIXiLac+mXxx58ogPQ9dxvB26Go1i8Kb/gcuzBUc4+94XYTzUoMcYrDJO1+ExoouyU5WZOH70kh240gQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YD4cU6Ox; arc=none smtp.client-ip=209.85.214.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YD4cU6Ox" Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2cf6acd760cso1143485ad.3 for ; Fri, 07 Aug 2026 15:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786142657; x=1786747457; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FCIAdlKPQC8LVh2CNqE5/NqRnErFXsfFV6IWU+8zDG0=; b=YD4cU6OxTaO/OEhh9GynZp9o6QoNodizvGEvwfATE4njyse/RtNVrbKK4pIRRs0yrJ X7JqKcPJg1wqNEpoynSfzMzSMoi9pyBruO6nCQaIfGBkcy8auNAIGSnTPl9Dihr/8t4k HwNGDEFmrWpyY5Z2eO47D3tKWAYACyL7hjc8l4kXsb2Yv2PU0OixVTP6Q6r9WDw6rwK4 qFyHWym3uDGOhDE+N53NiXmHYqbzZdQVF0/lHij6LmIzAIJBXp1WCtAkm6zJbZH0aoBR LcjDEBqymkN9NZxDjsSwAsFMOCHJvAsiGTFUB0TMwY1emd136IWksKcd5yyAiCKQpM98 8yHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786142657; x=1786747457; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FCIAdlKPQC8LVh2CNqE5/NqRnErFXsfFV6IWU+8zDG0=; b=lHuYyDNVUibnSbDxuB7eLxqDImDQRx0wQH0SU/x23HoZyxzZI0ZY/x3EPdXvD+NSnR LmMCawYumYIwyZRICUwTGbjOtFGvzBCAOMCirf6wpl5vRDh+87vBr8fsTmrqRI8W7zQ6 YV3XuM4XA4qY5pBWPNpXEdhSmzjpPJ2EPRhuOQoI05NbP/IBDMSkQG+k9Ab8KqfMwTa7 QkYrdZT1jrWvURMiCmSFZhv7DMGDRdPI+Ojsv35z7ciQDL0lijuf91PBfkEIO2nPIfUu yIAUFenCZLuTBis0m8Y1wn+TQj1TG0XDYfdoRgZlfBUMwgW4qCz0DtYwl71p5bQATmnD 2eXA== X-Forwarded-Encrypted: i=1; AHgh+Rp0pNKoY/PHnXI6DvqVajzN2+s5F+PH1D8zcBXmUEf/au2F1FpKHcxp41iKcnFOzxPHXJrFNxWZUkYC2jQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzrcgI4lV2zl++JVgGC3d0gZcQa6CRLHibSaqNquqciG4JHQmqp ziPi/oRVPc69EQWdCPrNyT5edV4Wc0Y7FcBPsXv+9InUHyXYCZAZByKRX/ZQ59i4s4tGimlqfUU +nzq96g== X-Received: from pjrq16.prod.google.com ([2002:a17:90a:b990:b0:38e:6cdf:217a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5683:b0:381:26f:8f05 with SMTP id 98e67ed59e1d1-3903c5380f7mr25970788a91.3.1786142656515; Fri, 07 Aug 2026 15:44:16 -0700 (PDT) Date: Fri, 7 Aug 2026 15:44:15 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: Message-ID: Subject: Re: [PATCH v3 03/26] mm: introduce AS_NO_DIRECT_MAP From: Sean Christopherson To: Yosry Ahmed Cc: Brendan Jackman , Brendan Jackman , 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, patrick.roy@linux.dev, Takahiro Itazuri , Andy Lutomirski , David Kaplan , Thomas Gleixner , Patrick Bellasi , Reiji Watanabe , Nikita Kalyazin , Ackerley Tng Content-Type: text/plain; charset="us-ascii" On Fri, Aug 07, 2026, Yosry Ahmed wrote: > > > > > > > > At that point, userspace is basically required to > > > > > > > > maintain mappings for all host-accessible guest memory, and if there are userspace > > > > > > > > mappings, then not using GUP doesn't make much sense. > > > > > > > > > > > > > > > > Note, I called out x86 because x86 has the most extensive emulator and shadow > > > > > > > > paging support, which is where the isolated, one-off accesses happen in spades. > > > > > > > > Other architectures might be able to squeak by without userspace mappings, at > > > > > > > > least for now. > > > > > > > > > > > > > > > > So, in all likelihood, KVM will want GUP. > > > > > > > > > > > > > > Yeah I am thinking that the check here to disallow GUP completely for > > > > > > > unmapped pages is aggressive. Maybe it works for now if KVM does not > > > > > > > currently have any use cases for accessing guest_memfd memory. But if it does > > > > > > > (or will very soon), we need to think more about it, otherwise > > > > > > > AS_NO_DIRECT_MAP is not really usable for guest_memfd. Since you said KVM > > > > > > > "will want" GUP, I assume it currently doesn't? > > > > > > > > > > > > Doesn't what? Have GUP? KVM heavily uses GUP, including for guest_memfd that > > > > > > can be mapped into userspace. > > > > > > > > > > Your wording made me think that KVM doesn't currently use GUP for > > > > > guest_memfd, but I was obviously wrong. So IIUC GUP needs to succeed for > > > > > guest_memfd pages with AS_NO_DIRECT_MAP. > > > > > > > > Yes, though as I said early, it doesn't *have* to be exactly GUP, just something > > > > GUP-like. E.g. it could be a new API, if that's easier/cleaner. What I don't > > > > think is a good idea though is handling this entirely in KVM/guest_memfd. > > > > > > Just to clarify, you mean that GUP (or GUP-like) should work in terms of > > > pinning the page and handing KVM/guest_memfd the pfn/address, but not > > > actually making the page accessible or establishing mappings, right? > > > > No, I'm saying that whatever API the kernel provides needs to ensure there's a > > valid kernel mapping (or provide one as a return value). > > > > > Looking at [2], seems like the consensus was that AS_NO_DIRECT_MAP > > > means folios are not in the direct map, and callers are responsible > > > for establishing the mappings (e.g. using the mermap). > > > > I'm fine with that direction, but in that case GUP _does_ need to be disallowed. > > I.e. _if_ we allow GUP, then GUP itself needs to somehow ensure the direct map > > is populated. If GUP is not allowed, then IMO the core kernel needs to provide > > an API to get at "inaccessible" mappings. Or I suppose GUP could take a flag > > that says "I pinky-swear not to try and access the memory via the direct map". > > Okay in this case I think the simplest thing to do here is to disallow GUP > for unmapped pages like this patch does. Once we have a use case (e.g. > guest_memfd with unmapped memory using GUP), we can figure out if we want a > separate API or a GUP flag. I assume the GUP flag could either be: "I know > the page is unmapped, I will map it" or "create an ephemeral mapping for the > page". I'm not ok punting on that, i.e. whatever we come up with needs to land alongside AS_NO_DIRECT_MAP, or at least before guest_memfd tries to use AS_NO_DIRECT_MAP. The only way KVM can use AS_NO_DIRECT_MAP without GUP is with a massive list of caveats and addendums on things the VMM and guest can't do. I'm not ok merging guest_memfd support for AS_NO_DIRECT_MAP with such a list.