On Thu, Mar 30, 2023, David Stevens wrote: > From: David Stevens <stevensd@xxxxxxxxxxxx> > > Remove two warnings that require ref counts for pages to be non-zero, as > mapped pfns from follow_pfn may not have an initialized ref count. This patch needs to be moved earlier, e.g. if just this patch is reverted, these WARNs will fire on a guest with non-refcounted memory. The shortlog and changelog also need to be reworded. The shortlog in particular is misleading, as the the WARNs aren't overly agressive _in the current code base_, but rather are invalidated by KVM allowing non-refcounted struct page memory to be mapped into the guest. Lastly, as I mentioned in previous versions, I would like to keep the sanity check if possible. But this time, I have a concrete idea :-) When installing a SPTE that points at a refcounted page, set a flag stating as much. Then use the flag to assert that the page has an elevate refcount whenever KVM is operating on the page. It'll require some additional plumbing changes, e.g. to tell make_spte() that the pfn is refcounted, but the actual code should be straightforward. Actually, we should make that a requirement to allow an arch to get non-refcounted struct page memory: the arch must be able to keep track which pages are/aren't refcounted. That'll disallow your GPU use case with 32-bit x86 host kernels (we're out of software bits in PAE SPTEs), but I can't imaging anyone cares. Then I believe we can make that support mutually exclusive with kvm_pfn_to_refcounted_page(), because all of the kvm_follow_pfn() users will know (and remember) that the pfn is backed by a refcounted page.