From patchwork Thu Feb 11 18:13:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Patlasov X-Patchwork-Id: 8283661 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9B4B1BEEE5 for ; Thu, 11 Feb 2016 18:13:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6BA920364 for ; Thu, 11 Feb 2016 18:13:40 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C879420260 for ; Thu, 11 Feb 2016 18:13:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1C311A1DF2; Thu, 11 Feb 2016 10:13:39 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from relay.parallels.com (relay.parallels.com [195.214.232.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5A0F01A1DF1 for ; Thu, 11 Feb 2016 10:13:38 -0800 (PST) Received: from [10.10.66.64] (helo=[192.168.101.21]) by relay.parallels.com with esmtp (Exim 4.86) (envelope-from ) id 1aTvkD-0004KO-7K; Thu, 11 Feb 2016 21:13:33 +0300 Subject: [PATCH] kvm: do not SetPageDirty from kvm_set_pfn_dirty for file mappings From: Maxim Patlasov To: pbonzini@redhat.com Date: Thu, 11 Feb 2016 10:13:29 -0800 Message-ID: <20160211181306.7864.44244.stgit@maxim-thinkpad> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: kvm@vger.kernel.org, linux-nvdimm@lists.01.org, gleb@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, devel@openvz.org X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch solves the following problem: file system specific routines involved in ordinary routine writeback process BUG_ON page_buffers() because a page goes to writeback without buffer-heads attached. The way how kvm_set_pfn_dirty calls SetPageDirty works only for anon mappings. For file mappings it is obviously incorrect - there page_mkwrite must be called. It's not easy to add page_mkwrite call to kvm_set_pfn_dirty because there is no universal way to find vma by pfn. But actually SetPageDirty may be simply skipped in those cases. Below is a justification. When guest modifies the content of a page with file mapping, 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 marks the page as write-protected. So any further write from the 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. Signed-off-by: Maxim Patlasov --- 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 a11cfd2..5a7d3fa 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1582,7 +1582,8 @@ void kvm_set_pfn_dirty(kvm_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); } }