[Devel] [PATCH RHEL7 COMMIT] kvm: do not SetPageDirty for file mappings

Konstantin Khorenko khorenko at virtuozzo.com
Tue Feb 16 02:22:19 PST 2016


The commit is pushed to "branch-rh7-3.10.0-327.4.5.vz7.11.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.4.5.vz7.11.2
------>
commit 9060bd98706fe2c56a6636b93b8a53a3450b0837
Author: Maxim Patlasov <mpatlasov at virtuozzo.com>
Date:   Tue Feb 16 14:22:19 2016 +0400

    kvm: do not SetPageDirty for file mappings
    
    When guest modifies the content of page with file mappings, kernel kvm
    makes the page dirty by the following call-path:
    
    vmx_handle_exit ->
     handle_ept_violation ->
      __get_user_pages ->
       page_mkwrite ->
        SetPageDirty
    
    Since then the page is dirty from both guest and host point of view. Then
    the host makes writeback and mark the page as write-protected. So any
    further write from guest triggers call-path above again.
    
    So, for file mappings, it's not possible to have new data written to a page
    inside the guest w/o corresponding SetPageDirty on the host.
    
    This makes explicit SetPageDirty from kvm_set_pfn_dirty redundant.
    
    https://lkml.org/lkml/2016/2/12/472
    https://jira.sw.ru/browse/PSBM-43243
    
    Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 virt/kvm/kvm_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 10276fe..fa2124c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1573,7 +1573,8 @@ void kvm_set_pfn_dirty(pfn_t pfn)
 {
 	if (!kvm_is_reserved_pfn(pfn)) {
 		struct page *page = pfn_to_page(pfn);
-		if (!PageReserved(page))
+		if (!PageReserved(page) &&
+		    (!page->mapping || PageAnon(page)))
 			SetPageDirty(page);
 	}
 }


More information about the Devel mailing list