From: Sean Christopherson <firstname.lastname@example.org> To: "Kirill A. Shutemov" <email@example.com> Cc: "Kirill A. Shutemov" <firstname.lastname@example.org>, Dave Hansen <email@example.com>, Andy Lutomirski <firstname.lastname@example.org>, Peter Zijlstra <email@example.com>, Jim Mattson <firstname.lastname@example.org>, David Rientjes <email@example.com>, "Edgecombe, Rick P" <firstname.lastname@example.org>, "Kleen, Andi" <email@example.com>, "Yamahata, Isaku" <firstname.lastname@example.org>, Erdem Aktas <email@example.com>, Steve Rutherford <firstname.lastname@example.org>, Peter Gonda <email@example.com>, David Hildenbrand <firstname.lastname@example.org>, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org Subject: Re: [RFCv2 13/13] KVM: unmap guest memory using poisoned pages Date: Mon, 19 Apr 2021 20:09:13 +0000 Message-ID: <YH3jaf5ThzLZdY4K@google.com> (raw) In-Reply-To: <20210419185354.v3rgandtrel7bzjj@box> On Mon, Apr 19, 2021, Kirill A. Shutemov wrote: > On Mon, Apr 19, 2021 at 06:09:29PM +0000, Sean Christopherson wrote: > > On Mon, Apr 19, 2021, Kirill A. Shutemov wrote: > > > On Mon, Apr 19, 2021 at 04:01:46PM +0000, Sean Christopherson wrote: > > > > But fundamentally the private pages, are well, private. They can't be shared > > > > across processes, so I think we could (should?) require the VMA to always be > > > > MAP_PRIVATE. Does that buy us enough to rely on the VMA alone? I.e. is that > > > > enough to prevent userspace and unaware kernel code from acquiring a reference > > > > to the underlying page? > > > > > > Shared pages should be fine too (you folks wanted tmpfs support). > > > > Is that a conflict though? If the private->shared conversion request is kicked > > out to userspace, then userspace can re-mmap() the files as MAP_SHARED, no? > > > > Allowing MAP_SHARED for guest private memory feels wrong. The data can't be > > shared, and dirty data can't be written back to the file. > > It can be remapped, but faulting in the page would produce hwpoison entry. It sounds like you're thinking the whole tmpfs file is poisoned. My thought is that userspace would need to do something like for guest private memory: mmap(NULL, guest_size, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_GUEST_ONLY, fd, 0); The MAP_GUEST_ONLY would be used by the kernel to ensure the resulting VMA can only point at private/poisoned memory, e.g. on fault, the associated PFN would be tagged with PG_hwpoison or whtaever. @fd in this case could point at tmpfs, but I don't think it's a hard requirement. On conversion to shared, userspace could then do: munmap(<addr>, <size>) mmap(<addr>, <size>, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_FIXED_NOREPLACE, fd, <offset>); or mmap(<addr>, <size>, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, <offset>); or ioctl(kvm, KVM_SET_USER_MEMORY_REGION, <delete private range>); mmap(NULL, <size>, PROT_READ|PROT_WRITE, MAP_SHARED, fd, <offset>); ioctl(kvm, KVM_SET_USER_MEMORY_REGION, <add shared range>); Combinations would also work, e.g. unmap the private range and move the memslot. The private and shared memory regions could also be backed differently, e.g. tmpfs for shared memory, anonymous for private memory. > I don't see other way to make Google's use-case with tmpfs-backed guest > memory work. The underlying use-case is to be able to access guest memory from more than one process, e.g. so that communication with the guest isn't limited to the VMM process associated with the KVM instances. By definition, guest private memory can't be accessed by the host; I don't see how anyone, Google included, can have any real requirements about > > > The poisoned pages must be useless outside of the process with the blessed > > > struct kvm. See kvm_pfn_map in the patch. > > > > The big requirement for kernel TDX support is that the pages are useless in the > > host. Regarding the guest, for TDX, the TDX Module guarantees that at most a > > single KVM guest can have access to a page at any given time. I believe the RMP > > provides the same guarantees for SEV-SNP. > > > > SEV/SEV-ES could still end up with corruption if multiple guests map the same > > private page, but that's obviously not the end of the world since it's the status > > quo today. Living with that shortcoming might be a worthy tradeoff if punting > > mutual exclusion between guests to firmware/hardware allows us to simplify the > > kernel implementation. > > The critical question is whether we ever need to translate hva->pfn after > the page is added to the guest private memory. I believe we do, but I > never checked. And that's the reason we need to keep hwpoison entries > around, which encode pfn. As proposed in the TDX RFC, KVM would "need" the hva->pfn translation if the guest private EPT entry was zapped, e.g. by NUMA balancing (which will fail on the backend). But in that case, KVM still has the original PFN, the "new" translation becomes a sanity check to make sure that the zapped translation wasn't moved unexpectedly. Regardless, I don't see what that has to do with kvm_pfn_map. At some point, gup() has to fault in the page or look at the host PTE value. For the latter, at least on x86, we can throw info into the PTE itself to tag it as guest-only. No matter what implementation we settle on, I think we've failed if we end up in a situation where the primary MMU has pages it doesn't know are guest-only. > If we don't, it would simplify the solution: kvm_pfn_map is not needed. > Single bit-per page would be enough.
next prev parent reply index Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-16 15:40 [RFCv2 00/13] TDX and guest memory unmapping Kirill A. Shutemov 2021-04-16 15:40 ` [RFCv2 01/13] x86/mm: Move force_dma_unencrypted() to common code Kirill A. Shutemov 2021-04-16 15:40 ` [RFCv2 02/13] x86/kvm: Introduce KVM memory protection feature Kirill A. Shutemov 2021-04-16 16:10 ` Borislav Petkov 2021-04-19 10:10 ` Kirill A. Shutemov 2021-04-16 15:40 ` [RFCv2 03/13] x86/kvm: Make DMA pages shared Kirill A. Shutemov 2021-04-16 15:40 ` [RFCv2 04/13] x86/kvm: Use bounce buffers for KVM memory protection Kirill A. Shutemov 2021-04-16 16:21 ` Dave Hansen 2021-04-16 15:40 ` [RFCv2 05/13] x86/kvmclock: Share hvclock memory with the host Kirill A. Shutemov 2021-04-16 15:40 ` [RFCv2 06/13] x86/realmode: Share trampoline area if KVM memory protection enabled Kirill A. Shutemov 2021-04-19 16:49 ` Dave Hansen 2021-04-16 15:41 ` [RFCv2 07/13] mm: Add hwpoison_entry_to_pfn() and hwpoison_entry_to_page() Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 08/13] mm/gup: Add FOLL_ALLOW_POISONED Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 09/13] shmem: Fail shmem_getpage_gfp() on poisoned pages Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 10/13] mm: Keep page reference for hwpoison entries Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 11/13] mm: Replace hwpoison entry with present PTE if page got unpoisoned Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 12/13] KVM: passdown struct kvm to hva_to_pfn_slow() Kirill A. Shutemov 2021-04-16 15:41 ` [RFCv2 13/13] KVM: unmap guest memory using poisoned pages Kirill A. Shutemov 2021-04-16 17:30 ` Sean Christopherson 2021-04-19 11:32 ` Xiaoyao Li 2021-04-19 14:26 ` Kirill A. Shutemov 2021-04-19 16:01 ` Sean Christopherson 2021-04-19 16:40 ` Kirill A. Shutemov 2021-04-19 18:09 ` Sean Christopherson 2021-04-19 18:12 ` David Hildenbrand 2021-04-19 18:53 ` Kirill A. Shutemov 2021-04-19 20:09 ` Sean Christopherson [this message] 2021-04-19 22:57 ` Kirill A. Shutemov 2021-04-20 17:13 ` Sean Christopherson 2021-05-21 12:31 ` Kirill A. Shutemov 2021-05-26 19:46 ` Sean Christopherson 2021-05-31 20:07 ` Kirill A. Shutemov 2021-06-02 17:51 ` Sean Christopherson 2021-06-02 23:33 ` Kirill A. Shutemov 2021-06-03 19:46 ` Sean Christopherson 2021-06-04 14:29 ` Kirill A. Shutemov 2021-06-04 17:16 ` Andy Lutomirski 2021-06-04 17:54 ` Kirill A. Shutemov 2021-04-16 16:46 ` [RFCv2 00/13] TDX and guest memory unmapping Matthew Wilcox
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YH3jaf5ThzLZdY4K@google.com \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
KVM Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/kvm/0 kvm/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 kvm kvm/ https://lore.kernel.org/kvm \ firstname.lastname@example.org public-inbox-index kvm Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.kvm AGPL code for this site: git clone https://public-inbox.org/public-inbox.git