On Thu, Aug 20, 2020 at 12:05:00PM -0500, Eric van Tassell wrote: > > > On 8/19/20 11:05 AM, Sean Christopherson wrote: > > On Wed, Aug 19, 2020 at 11:03:48AM -0500, Eric van Tassell wrote: > > > > > > > > > On 8/3/20 11:27 AM, Sean Christopherson wrote: > > > > On Sun, Aug 02, 2020 at 03:53:54PM -0500, Eric van Tassell wrote: > > > > > > > > > > On 7/31/20 3:25 PM, Sean Christopherson wrote: > > > > > > On Fri, Jul 24, 2020 at 06:54:46PM -0500, eric van tassell wrote: > > > > > > > Improve SEV guest startup time from O(n) to a constant by deferring > > > > > > > guest page pinning until the pages are used to satisfy nested page faults. > > > > > > > > > > > > > > Implement the code to do the pinning (sev_get_page) and the notifier > > > > > > > sev_set_spte_notify(). > > > > > > > > > > > > > > Track the pinned pages with xarray so they can be released during guest > > > > > > > termination. > > > > > > > > > > > > I like that SEV is trying to be a better citizen, but this is trading one > > > > > > hack for another. > > > > > > > > > > > > - KVM goes through a lot of effort to ensure page faults don't need to > > > > > > allocate memory, and this throws all that effort out the window. > > > > > > > > > > > can you elaborate on that? > > > > > > > > mmu_topup_memory_caches() is called from the page fault handlers before > > > > acquiring mmu_lock to pre-allocate shadow pages, PTE list descriptors, GFN > > > > arrays, etc... that may be needed to handle the page fault. This allows > > > > using standard GFP flags for the allocation and obviates the need for error > > > > handling in the consumers. > > > > > > > > > > I see what you meant. The issue that causes us to use this approach is that > > > we need to be able to unpin the pages when the VM exits. > > > > Yes, but using a software available flag in the SPTE to track pinned pages > > should be very doable. > > > > The issue, as I understand it, is that when spte(s) get zapped/unzapped, the > flags are lost so we'd have to have some mechanism to, before zapping, cache > the pfn <-> spte mapping The issue is that code doesn't exist :-) The idea is to leave the pfn in the spte itself when a pinned spte is zapped, and use software available bits in the spte to indicate the page is pinned and has zap. When the VM is destroyed, remove all sptes and drop the page reference for pinned pages.