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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 04C00C5DF63 for ; Wed, 6 Nov 2019 19:58:26 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B16912075C for ; Wed, 6 Nov 2019 19:58:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B16912075C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 477clz00B0zF3Kq for ; Thu, 7 Nov 2019 06:58:23 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=intel.com (client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=sean.j.christopherson@intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=intel.com Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 477Wgh6fkhzF3Ys for ; Thu, 7 Nov 2019 03:09:18 +1100 (AEDT) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2019 08:09:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,275,1569308400"; d="scan'208";a="200752952" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga008.fm.intel.com with ESMTP; 06 Nov 2019 08:09:13 -0800 Date: Wed, 6 Nov 2019 08:09:13 -0800 From: Sean Christopherson To: David Hildenbrand Subject: Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes Message-ID: <20191106160913.GD16249@linux.intel.com> References: <613f3606-748b-0e56-a3ad-1efaffa1a67b@redhat.com> <20191105160000.GC8128@linux.intel.com> <20191105231316.GE23297@linux.intel.com> <20191106000315.GI23297@linux.intel.com> <694202e7-d8e6-6ac8-6e47-3553b298bbcc@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <694202e7-d8e6-6ac8-6e47-3553b298bbcc@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Mailman-Approved-At: Thu, 07 Nov 2019 06:55:50 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-hyperv@vger.kernel.org, Michal Hocko , Radim =?utf-8?B?S3LEjW3DocWZ?= , KVM list , Pavel Tatashin , KarimAllah Ahmed , Dave Hansen , Alexander Duyck , Michal Hocko , Linux MM , Paul Mackerras , "H. Peter Anvin" , Wanpeng Li , Alexander Duyck , "K. Y. Srinivasan" , Boris Ostrovsky , Kees Cook , devel@driverdev.osuosl.org, Stefano Stabellini , Stephen Hemminger , "Aneesh Kumar K.V" , Joerg Roedel , X86 ML , YueHaibing , "Matthew Wilcox \(Oracle\)" , Mike Rapoport , Peter Zijlstra , Ingo Molnar , Vlastimil Babka , Anthony Yznaga , Oscar Salvador , "Isaac J. Manjarres" , Matt Sickler , Juergen Gross , Anshuman Khandual , Haiyang Zhang , Sasha Levin , kvm-ppc@vger.kernel.org, Qian Cai , Alex Williamson , Mike Rapoport , Borislav Petkov , Nicholas Piggin , Andy Lutomirski , xen-devel , Dan Williams , Vitaly Kuznetsov , Allison Randal , Jim Mattson , Mel Gorman , Adam Borowski , Cornelia Huck , Pavel Tatashin , Linux Kernel Mailing List , Thomas Gleixner , Johannes Weiner , Paolo Bonzini , Andrew Morton , linuxppc-dev Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Wed, Nov 06, 2019 at 07:56:34AM +0100, David Hildenbrand wrote: > On 06.11.19 01:08, Dan Williams wrote: > >On Tue, Nov 5, 2019 at 4:03 PM Sean Christopherson > >>But David's proposed fix for the above refcount bug is to omit the patch > >>so that KVM no longer treats ZONE_DEVICE pages as reserved. That seems > >>like the right thing to do, including for thp_adjust(), e.g. it would > >>naturally let KVM use 2mb pages for the guest when a ZONE_DEVICE page is > >>mapped with a huge page (2mb or above) in the host. The only hiccup is > >>figuring out how to correctly transfer the reference. > > > >That might not be the only hiccup. There's currently no such thing as > >huge pages for ZONE_DEVICE, there are huge *mappings* (pmd and pud), > >but the result of pfn_to_page() on such a mapping does not yield a > >huge 'struct page'. It seems there are other paths in KVM that assume > >that more typical page machinery is active like SetPageDirty() based > >on kvm_is_reserved_pfn(). While I told David that I did not want to > >see more usage of is_zone_device_page(), this patch below (untested) > >seems a cleaner path with less surprises: > > > >diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > >index 4df0aa6b8e5c..fbea17c1810c 100644 > >--- a/virt/kvm/kvm_main.c > >+++ b/virt/kvm/kvm_main.c > >@@ -1831,7 +1831,8 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean); > > > > void kvm_release_pfn_clean(kvm_pfn_t pfn) > > { > >- if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn)) > >+ if ((!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn)) || The is_error_noslot_pfn() check shouldn't be overriden by zone_device. > >+ (pfn_valid(pfn) && is_zone_device_page(pfn_to_page(pfn)))) But rather than special case kvm_release_pfn_clean(), I'd rather KVM explicitly handle ZONE_DEVICE pages, there are other flows where KVM really should be aware of ZONE_DEVICE pages, e.g. for sanity checks and whatnot. There are surprisingly few callers of kvm_is_reserved_pfn(), so it's actually not too big of a change. > > put_page(pfn_to_page(pfn)); > > } > > EXPORT_SYMBOL_GPL(kvm_release_pfn_clean); > > I had the same thought, but I do wonder about the kvm_get_pfn() users, > e.g.,: > > hva_to_pfn_remapped(): > r = follow_pfn(vma, addr, &pfn); > ... > kvm_get_pfn(pfn); > ... > > We would not take a reference for ZONE_DEVICE, but later drop one reference > via kvm_release_pfn_clean(). IOW, kvm_get_pfn() gets *really* dangerous to > use. I can't tell if this can happen right now. > > We do have 3 users of kvm_get_pfn() that we have to audit before this > change. Also, we should add a comment to kvm_get_pfn() that it should never > be used with possible ZONE_DEVICE pages. > > Also, we should add a comment to kvm_release_pfn_clean(), describing why we > treat ZONE_DEVICE in a special way here. > > > We can then progress like this > > 1. Get this fix upstream, it's somewhat unrelated to this series. > 2. This patch here remains as is in this series (+/- documentation update) > 3. Long term, rework KVM to not have to not treat ZONE_DEVICE like reserved > pages. E.g., get rid of kvm_get_pfn(). Then, this special zone check can go. Dropping kvm_get_pfn() is less than ideal, and at this point unnecessary. I'm 99% sure the existing call sites for kvm_get_pfn() can never be reached with ZONE_DEVICE pages. I think we can do: 1. Get a fix upstream to have KVM stop treating ZONE_DEVICE pages as reserved PFNs, i.e. exempt them in kvm_is_reserved_pfn() and change the callers of kvm_is_reserved_pfn() to handle ZONE_DEVICE pages. 2. Drop this patch from the series, and instead remove the special treatment of ZONE_DEVICE pages from kvm_is_reserved_pfn(). Give me a few minutes to prep a patch. > > -- > > Thanks, > > David / dhildenb >