Skip to content

Commit d757c3a

Browse files
KarimAllah Ahmedgregkh
authored andcommitted
kvm: Map PFN-type memory regions as writable (if possible)
[ Upstream commit a340b3e ] 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 <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: KarimAllah Ahmed <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Signed-off-by: Radim Krčmář <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a6a2500 commit d757c3a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

virt/kvm/kvm_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,8 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault)
14341434

14351435
static int hva_to_pfn_remapped(struct vm_area_struct *vma,
14361436
unsigned long addr, bool *async,
1437-
bool write_fault, kvm_pfn_t *p_pfn)
1437+
bool write_fault, bool *writable,
1438+
kvm_pfn_t *p_pfn)
14381439
{
14391440
unsigned long pfn;
14401441
int r;
@@ -1460,6 +1461,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma,
14601461

14611462
}
14621463

1464+
if (writable)
1465+
*writable = true;
14631466

14641467
/*
14651468
* Get a reference here because callers of *hva_to_pfn* and
@@ -1525,7 +1528,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
15251528
if (vma == NULL)
15261529
pfn = KVM_PFN_ERR_FAULT;
15271530
else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
1528-
r = hva_to_pfn_remapped(vma, addr, async, write_fault, &pfn);
1531+
r = hva_to_pfn_remapped(vma, addr, async, write_fault, writable, &pfn);
15291532
if (r == -EAGAIN)
15301533
goto retry;
15311534
if (r < 0)

0 commit comments

Comments
 (0)