tamlok
tamlok

Reputation: 707

How to pin a guest page in memory in KVM?

I am doing stuff in KVM memory. I noticed that sometimes kvm_mmu_notifier_invalidate_range_start() would be called and then kvm_unmap_hva_range() then drop_stpe(), which would set a certain spte to zero. I guess there is a change in the mapping from HVA to PFN in the QEMU, so it need to invalidate those sptes pointing to those PFN, right?
I did some CoW mechanism to the spte, so drop_spte() made it difficult to work. Can I pin a page in memory so that the mapping from its HVA to PFN will not be changed? I want to pin a page when I CoW a guest page so that it will not be dropped accidentally.
Thanks very much!

Upvotes: 2

Views: 1026

Answers (1)

Yogi
Yogi

Reputation: 476

I guess kvm_get_pfn() can be used to pin a pfn. You can use gfn_to_pfn() to get the pfn corresponding to gfn. To unpin the page you can use kvm_release_pfn_clean().

Upvotes: 2

Related Questions