[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DS0PR11MB63734C0FC6A7FABCAF826620DC4E9@DS0PR11MB6373.namprd11.prod.outlook.com>
Date: Thu, 22 Sep 2022 13:23:42 +0000
From: "Wang, Wei W" <wei.w.wang@...el.com>
To: "Lutomirski, Andy" <luto@...nel.org>,
"Christopherson,, Sean" <seanjc@...gle.com>,
David Hildenbrand <david@...hat.com>
CC: Chao Peng <chao.p.peng@...ux.intel.com>,
kvm list <kvm@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
Linux API <linux-api@...r.kernel.org>,
"linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
"qemu-devel@...gnu.org" <qemu-devel@...gnu.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Jonathan Corbet <corbet@....net>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
the arch/x86 maintainers <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>, Hugh Dickins <hughd@...gle.com>,
Jeff Layton <jlayton@...nel.org>,
"J . Bruce Fields" <bfields@...ldses.org>,
"Andrew Morton" <akpm@...ux-foundation.org>,
Shuah Khan <shuah@...nel.org>,
"Mike Rapoport" <rppt@...nel.org>,
Steven Price <steven.price@....com>,
"Maciej S . Szmigiero" <mail@...iej.szmigiero.name>,
Vlastimil Babka <vbabka@...e.cz>,
Vishal Annapurve <vannapurve@...gle.com>,
Yu Zhang <yu.c.zhang@...ux.intel.com>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
"Nakajima, Jun" <jun.nakajima@...el.com>,
"Hansen, Dave" <dave.hansen@...el.com>,
Andi Kleen <ak@...ux.intel.com>,
"aarcange@...hat.com" <aarcange@...hat.com>,
"ddutile@...hat.com" <ddutile@...hat.com>,
"dhildenb@...hat.com" <dhildenb@...hat.com>,
"Quentin Perret" <qperret@...gle.com>,
Michael Roth <michael.roth@....com>,
"Hocko, Michal" <mhocko@...e.com>,
Muchun Song <songmuchun@...edance.com>,
"Will Deacon" <will@...nel.org>, Marc Zyngier <maz@...nel.org>,
Fuad Tabba <tabba@...gle.com>
Subject: RE: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible memfd
On Thursday, September 22, 2022 5:11 AM, Andy Lutomirski wrote:
> To: Christopherson,, Sean <seanjc@...gle.com>; David Hildenbrand
> <david@...hat.com>
> Cc: Chao Peng <chao.p.peng@...ux.intel.com>; kvm list
> <kvm@...r.kernel.org>; Linux Kernel Mailing List
> <linux-kernel@...r.kernel.org>; linux-mm@...ck.org;
> linux-fsdevel@...r.kernel.org; Linux API <linux-api@...r.kernel.org>;
> linux-doc@...r.kernel.org; qemu-devel@...gnu.org; Paolo Bonzini
> <pbonzini@...hat.com>; Jonathan Corbet <corbet@....net>; Vitaly
> Kuznetsov <vkuznets@...hat.com>; Wanpeng Li <wanpengli@...cent.com>;
> Jim Mattson <jmattson@...gle.com>; Joerg Roedel <joro@...tes.org>;
> Thomas Gleixner <tglx@...utronix.de>; Ingo Molnar <mingo@...hat.com>;
> Borislav Petkov <bp@...en8.de>; the arch/x86 maintainers <x86@...nel.org>;
> H. Peter Anvin <hpa@...or.com>; Hugh Dickins <hughd@...gle.com>; Jeff
> Layton <jlayton@...nel.org>; J . Bruce Fields <bfields@...ldses.org>; Andrew
> Morton <akpm@...ux-foundation.org>; Shuah Khan <shuah@...nel.org>;
> Mike Rapoport <rppt@...nel.org>; Steven Price <steven.price@....com>;
> Maciej S . Szmigiero <mail@...iej.szmigiero.name>; Vlastimil Babka
> <vbabka@...e.cz>; Vishal Annapurve <vannapurve@...gle.com>; Yu Zhang
> <yu.c.zhang@...ux.intel.com>; Kirill A. Shutemov
> <kirill.shutemov@...ux.intel.com>; Nakajima, Jun <jun.nakajima@...el.com>;
> Hansen, Dave <dave.hansen@...el.com>; Andi Kleen <ak@...ux.intel.com>;
> aarcange@...hat.com; ddutile@...hat.com; dhildenb@...hat.com; Quentin
> Perret <qperret@...gle.com>; Michael Roth <michael.roth@....com>;
> Hocko, Michal <mhocko@...e.com>; Muchun Song
> <songmuchun@...edance.com>; Wang, Wei W <wei.w.wang@...el.com>;
> Will Deacon <will@...nel.org>; Marc Zyngier <maz@...nel.org>; Fuad Tabba
> <tabba@...gle.com>
> Subject: Re: [PATCH v8 1/8] mm/memfd: Introduce userspace inaccessible
> memfd
>
> (please excuse any formatting disasters. my internet went out as I was
> composing this, and i did my best to rescue it.)
>
> On Mon, Sep 19, 2022, at 12:10 PM, Sean Christopherson wrote:
> > +Will, Marc and Fuad (apologies if I missed other pKVM folks)
> >
> > On Mon, Sep 19, 2022, David Hildenbrand wrote:
> >> On 15.09.22 16:29, Chao Peng wrote:
> >> > From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
> >> >
> >> > KVM can use memfd-provided memory for guest memory. For normal
> >> > userspace accessible memory, KVM userspace (e.g. QEMU) mmaps the
> >> > memfd into its virtual address space and then tells KVM to use the
> >> > virtual address to setup the mapping in the secondary page table (e.g.
> EPT).
> >> >
> >> > With confidential computing technologies like Intel TDX, the
> >> > memfd-provided memory may be encrypted with special key for special
> >> > software domain (e.g. KVM guest) and is not expected to be directly
> >> > accessed by userspace. Precisely, userspace access to such
> >> > encrypted memory may lead to host crash so it should be prevented.
> >>
> >> Initially my thaught was that this whole inaccessible thing is TDX
> >> specific and there is no need to force that on other mechanisms.
> >> That's why I suggested to not expose this to user space but handle
> >> the notifier requirements internally.
> >>
> >> IIUC now, protected KVM has similar demands. Either access
> >> (read/write) of guest RAM would result in a fault and possibly crash
> >> the hypervisor (at least not the whole machine IIUC).
> >
> > Yep. The missing piece for pKVM is the ability to convert from shared
> > to private while preserving the contents, e.g. to hand off a large
> > buffer (hundreds of MiB) for processing in the protected VM. Thoughts
> > on this at the bottom.
> >
> >> > This patch introduces userspace inaccessible memfd (created with
> >> > MFD_INACCESSIBLE). Its memory is inaccessible from userspace
> >> > through ordinary MMU access (e.g. read/write/mmap) but can be
> >> > accessed via in-kernel interface so KVM can directly interact with
> >> > core-mm without the need to map the memory into KVM userspace.
> >>
> >> With secretmem we decided to not add such "concept switch" flags and
> >> instead use a dedicated syscall.
> >>
> >
> > I have no personal preference whatsoever between a flag and a
> > dedicated syscall, but a dedicated syscall does seem like it would
> > give the kernel a bit more flexibility.
>
> The third option is a device node, e.g. /dev/kvm_secretmem or
> /dev/kvm_tdxmem or similar. But if we need flags or other details in the
> future, maybe this isn't ideal.
>
> >
> >> What about memfd_inaccessible()? Especially, sealing and hugetlb are
> >> not even supported and it might take a while to support either.
> >
> > Don't know about sealing, but hugetlb support for "inaccessible"
> > memory needs to come sooner than later. "inaccessible" in quotes
> > because we might want to choose a less binary name, e.g.
> > "restricted"?.
> >
> > Regarding pKVM's use case, with the shim approach I believe this can
> > be done by allowing userspace mmap() the "hidden" memfd, but with a
> > ton of restrictions piled on top.
> >
> > My first thought was to make the uAPI a set of KVM ioctls so that KVM
> > could tightly tightly control usage without taking on too much
> > complexity in the kernel, but working through things, routing the
> > behavior through the shim itself might not be all that horrific.
> >
> > IIRC, we discarded the idea of allowing userspace to map the "private"
> > fd because
> > things got too complex, but with the shim it doesn't seem _that_ bad.
>
> What's the exact use case? Is it just to pre-populate the memory?
Add one more use case here. For TDX live migration support, on the destination side,
we map the private fd during migration to store the encrypted private memory data sent
from source, and at the end of migration, we unmap it and make it inaccessible before
resuming the TD to run.
Powered by blists - more mailing lists