Re: [PATCH v12 22/29] KVM: SEV: Implement gmem hook for invalidating private pages

From: Paolo Bonzini
Date: Sat Mar 30 2024 - 17:32:08 EST


On 3/29/24 23:58, Michael Roth wrote:
+ /*
+ * If an unaligned PFN corresponds to a 2M region assigned as a
+ * large page in he RMP table, PSMASH the region into individual
+ * 4K RMP entries before attempting to convert a 4K sub-page.
+ */
+ if (!use_2m_update && rmp_level > PG_LEVEL_4K) {
+ rc = snp_rmptable_psmash(pfn);
+ if (rc)
+ pr_err_ratelimited("SEV: Failed to PSMASH RMP entry for PFN 0x%llx error %d\n",
+ pfn, rc);
+ }

Ignoring the PSMASH failure is pretty scary... At this point free_folio cannot fail, should the psmash part of this patch be done in kvm_gmem_invalidate_begin() before kvm_mmu_unmap_gfn_range()?

Also, can you get PSMASH_FAIL_INUSE and if so what's the best way to address it? Should fallocate() return -EBUSY?

Thanks,

Paolo