KVM: Simply gfn_to_page()
Mapping a guest page to a host page is a common operation. Currently, one has first to find the memory slot where the page belongs (gfn_to_memslot), then locate the page itself (gfn_to_page()). This is clumsy, and also won't work well with memory aliases. So simplify gfn_to_page() not to require memory slot translation first, and instead do it internally. Signed-off-by: Avi Kivity <avi@qumranet.com>
This commit is contained in:
@@ -390,13 +390,11 @@ static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn)
|
||||
{
|
||||
struct kvm *kvm = vcpu->kvm;
|
||||
struct page *page;
|
||||
struct kvm_memory_slot *slot;
|
||||
struct kvm_rmap_desc *desc;
|
||||
u64 *spte;
|
||||
|
||||
slot = gfn_to_memslot(kvm, gfn);
|
||||
BUG_ON(!slot);
|
||||
page = gfn_to_page(slot, gfn);
|
||||
page = gfn_to_page(kvm, gfn);
|
||||
BUG_ON(!page);
|
||||
|
||||
while (page_private(page)) {
|
||||
if (!(page_private(page) & 1))
|
||||
@@ -711,14 +709,12 @@ hpa_t safe_gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
|
||||
|
||||
hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
|
||||
{
|
||||
struct kvm_memory_slot *slot;
|
||||
struct page *page;
|
||||
|
||||
ASSERT((gpa & HPA_ERR_MASK) == 0);
|
||||
slot = gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT);
|
||||
if (!slot)
|
||||
page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
|
||||
if (!page)
|
||||
return gpa | HPA_ERR_MASK;
|
||||
page = gfn_to_page(slot, gpa >> PAGE_SHIFT);
|
||||
return ((hpa_t)page_to_pfn(page) << PAGE_SHIFT)
|
||||
| (gpa & (PAGE_SIZE-1));
|
||||
}
|
||||
|
Reference in New Issue
Block a user