From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12252C43331 for ; Tue, 12 Nov 2019 16:57:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E80EB2196E for ; Tue, 12 Nov 2019 16:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727516AbfKLQ5S (ORCPT ); Tue, 12 Nov 2019 11:57:18 -0500 Received: from mga05.intel.com ([192.55.52.43]:28377 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbfKLQ5S (ORCPT ); Tue, 12 Nov 2019 11:57:18 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Nov 2019 08:57:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,297,1569308400"; d="scan'208";a="229453522" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga004.fm.intel.com with ESMTP; 12 Nov 2019 08:57:17 -0800 Date: Tue, 12 Nov 2019 08:57:17 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Dan Williams , Radim =?utf-8?B?S3LEjW3DocWZ?= , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , KVM list , Linux Kernel Mailing List , Adam Borowski , David Hildenbrand Subject: Re: [PATCH 1/2] KVM: MMU: Do not treat ZONE_DEVICE pages as being reserved Message-ID: <20191112165717.GA18089@linux.intel.com> References: <0db7c328-1543-55db-bc02-c589deb3db22@redhat.com> <20191107155846.GA7760@linux.intel.com> <20191109014323.GB8254@linux.intel.com> <20191111182750.GE11805@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Tue, Nov 12, 2019 at 11:19:44AM +0100, Paolo Bonzini wrote: > On 12/11/19 01:51, Dan Williams wrote: > > An elevated page reference count for file mapped pages causes the > > filesystem (for a dax mode file) to wait for that reference count to > > drop to 1 before allowing the truncate to proceed. For a page cache > > backed file mapping (non-dax) the reference count is not considered in > > the truncate path. It does prevent the page from getting freed in the > > page cache case, but the association to the file is lost for truncate. > > KVM support for file-backed guest memory is limited. It is not > completely broken, in fact cases such as hugetlbfs are in use routinely, > but corner cases such as truncate aren't covered well indeed. KVM's actual MMU should be ok since it coordinates with the mmu_notifier. kvm_vcpu_map() is where KVM could run afoul of page cache truncation. This is the other main use of hva_to_pfn*(), where KVM directly accesses guest memory (which could be file-backed) without coordinating with the mmu_notifier. IIUC, an ill-timed page cache truncation could result in a write from KVM effectively being dropped due to writeback racing with KVM's write to the page. If that's true, then I think KVM would need to to move to the proposed pin_user_pages() to ensure its "DMA" isn't lost. > > As long as any memory the guest expects to be persistent is backed by > > mmu-notifier coordination we're all good, otherwise an elevated > > reference count does not coordinate with truncate in a reliable way. KVM itself is (mostly) blissfully unaware of any such expectations. The userspace VMM, e.g. Qemu, is ultimately responsible for ensuring the guest sees a valid model, e.g. that persistent memory (as presented to the guest) is actually persistent (from the guest's perspective). The big caveat is the truncation issue above.