aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarimAllah Ahmed <karahmed@amazon.de>2018-01-17 13:18:56 -0500
committerRadim Krčmář <rkrcmar@redhat.com>2018-01-31 12:25:33 -0500
commita340b3e229b24a56f1c7f5826b15a3af0f4b13e5 (patch)
treea49fd00bcff34d0d2c7b5235f14da0315ead715e
parente53175395d7e12d8474707271bc02a2814279843 (diff)
kvm: Map PFN-type memory regions as writable (if possible)
For EPT-violations that are triggered by a read, the pages are also mapped with write permissions (if their memory region is also writable). That would avoid getting yet another fault on the same page when a write occurs. This optimization only happens when you have a "struct page" backing the memory region. So also enable it for memory regions that do not have a "struct page". Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
-rw-r--r--virt/kvm/kvm_main.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index b4414842b023..8af42eab126d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1428,7 +1428,8 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault)
1428 1428
1429static int hva_to_pfn_remapped(struct vm_area_struct *vma, 1429static int hva_to_pfn_remapped(struct vm_area_struct *vma,
1430 unsigned long addr, bool *async, 1430 unsigned long addr, bool *async,
1431 bool write_fault, kvm_pfn_t *p_pfn) 1431 bool write_fault, bool *writable,
1432 kvm_pfn_t *p_pfn)
1432{ 1433{
1433 unsigned long pfn; 1434 unsigned long pfn;
1434 int r; 1435 int r;
@@ -1454,6 +1455,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma,
1454 1455
1455 } 1456 }
1456 1457
1458 if (writable)
1459 *writable = true;
1457 1460
1458 /* 1461 /*
1459 * Get a reference here because callers of *hva_to_pfn* and 1462 * Get a reference here because callers of *hva_to_pfn* and
@@ -1519,7 +1522,7 @@ retry:
1519 if (vma == NULL) 1522 if (vma == NULL)
1520 pfn = KVM_PFN_ERR_FAULT; 1523 pfn = KVM_PFN_ERR_FAULT;
1521 else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) { 1524 else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
1522 r = hva_to_pfn_remapped(vma, addr, async, write_fault, &pfn); 1525 r = hva_to_pfn_remapped(vma, addr, async, write_fault, writable, &pfn);
1523 if (r == -EAGAIN) 1526 if (r == -EAGAIN)
1524 goto retry; 1527 goto retry;
1525 if (r < 0) 1528 if (r < 0)