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=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 903C5C49EAA for ; Tue, 5 Nov 2019 09:18:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 439CD217F4 for ; Tue, 5 Nov 2019 09:18:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b6DH0v8G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 439CD217F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B35566B0006; Tue, 5 Nov 2019 04:18:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE4DD6B0008; Tue, 5 Nov 2019 04:18:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 985C16B000A; Tue, 5 Nov 2019 04:18:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 823B06B0006 for ; Tue, 5 Nov 2019 04:18:28 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 23468B785 for ; Tue, 5 Nov 2019 09:18:28 +0000 (UTC) X-FDA: 76121673096.18.event15_49aa8d4bcc560 X-HE-Tag: event15_49aa8d4bcc560 X-Filterd-Recvd-Size: 7505 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 Nov 2019 09:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572945505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fsUg4V2hCRqokDEt6EDiLa/nWjJkgCxKTlTyYOik09s=; b=b6DH0v8GS26OpMHXc7M+R6iK1WWnEegVfyYJG/4L8sm+b14ZLK0wnTWOjm237KU+DYsZ/m VelgWfhEb9mNBeq1mrYyd1KsrBLpp/y4ZPWReg2b6RWcC+QMOhrwC3n17Dv+AYAWHtpIuE AW3FH4I9u5ySBfXd5kxzmj6CkUp7ayM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-wRX3ELHkOxy3Ag2rKnjLCA-1; Tue, 05 Nov 2019 04:18:24 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90226477; Tue, 5 Nov 2019 09:18:16 +0000 (UTC) Received: from [10.36.117.253] (ovpn-117-253.ams2.redhat.com [10.36.117.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1D465D70D; Tue, 5 Nov 2019 09:17:55 +0000 (UTC) Subject: Re: [PATCH v1 03/10] KVM: Prepare kvm_is_reserved_pfn() for PG_reserved changes To: Dan Williams Cc: Linux Kernel Mailing List , Linux MM , Michal Hocko , Andrew Morton , kvm-ppc@vger.kernel.org, linuxppc-dev , KVM list , linux-hyperv@vger.kernel.org, devel@driverdev.osuosl.org, xen-devel , X86 ML , Alexander Duyck , Alexander Duyck , Alex Williamson , Allison Randal , Andy Lutomirski , "Aneesh Kumar K.V" , Anshuman Khandual , Anthony Yznaga , Benjamin Herrenschmidt , Borislav Petkov , Boris Ostrovsky , Christophe Leroy , Cornelia Huck , Dave Hansen , Haiyang Zhang , "H. Peter Anvin" , Ingo Molnar , "Isaac J. Manjarres" , Jim Mattson , Joerg Roedel , Johannes Weiner , Juergen Gross , KarimAllah Ahmed , Kees Cook , "K. Y. Srinivasan" , "Matthew Wilcox (Oracle)" , Matt Sickler , Mel Gorman , Michael Ellerman , Michal Hocko , Mike Rapoport , Mike Rapoport , Nicholas Piggin , Oscar Salvador , Paolo Bonzini , Paul Mackerras , Paul Mackerras , Pavel Tatashin , Pavel Tatashin , Peter Zijlstra , Qian Cai , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Sasha Levin , Sean Christopherson , Stefano Stabellini , Stephen Hemminger , Thomas Gleixner , Vitaly Kuznetsov , Vlastimil Babka , Wanpeng Li , YueHaibing , Adam Borowski References: <20191024120938.11237-1-david@redhat.com> <20191024120938.11237-4-david@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: Date: Tue, 5 Nov 2019 10:17:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: wRX3ELHkOxy3Ag2rKnjLCA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 05.11.19 05:38, Dan Williams wrote: > On Thu, Oct 24, 2019 at 5:11 AM David Hildenbrand wrot= e: >> >> Right now, ZONE_DEVICE memory is always set PG_reserved. We want to >> change that. >> >> KVM has this weird use case that you can map anything from /dev/mem >> into the guest. pfn_valid() is not a reliable check whether the memmap >> was initialized and can be touched. pfn_to_online_page() makes sure >> that we have an initialized memmap (and don't have ZONE_DEVICE memory). >> >> Rewrite kvm_is_reserved_pfn() to make sure the function produces the >> same result once we stop setting ZONE_DEVICE pages PG_reserved. >> >> Cc: Paolo Bonzini >> Cc: "Radim Kr=C4=8Dm=C3=A1=C5=99" >> Cc: Michal Hocko >> Cc: Dan Williams >> Cc: KarimAllah Ahmed >> Signed-off-by: David Hildenbrand >> --- >> virt/kvm/kvm_main.c | 10 ++++++++-- >> 1 file changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c >> index e9eb666eb6e8..9d18cc67d124 100644 >> --- a/virt/kvm/kvm_main.c >> +++ b/virt/kvm/kvm_main.c >> @@ -151,9 +151,15 @@ __weak int kvm_arch_mmu_notifier_invalidate_range(s= truct kvm *kvm, >> >> bool kvm_is_reserved_pfn(kvm_pfn_t pfn) >> { >> - if (pfn_valid(pfn)) >> - return PageReserved(pfn_to_page(pfn)); >> + struct page *page =3D pfn_to_online_page(pfn); >> >> + /* >> + * We treat any pages that are not online (not managed by the bu= ddy) >> + * as reserved - this includes ZONE_DEVICE pages and pages witho= ut >> + * a memmap (e.g., mapped via /dev/mem). >> + */ >> + if (page) >> + return PageReserved(page); >> return true; >> } >=20 > So after this all the pfn_valid() usage in kvm_main.c is replaced with > pfn_to_online_page()? Looks correct to me. >=20 > However, I'm worried that kvm is taking reference on ZONE_DEVICE pages > through some other path resulting in this: >=20 > https://lore.kernel.org/linux-nvdimm/20190919154708.GA24650@angband.= pl/ >=20 > I'll see if this patch set modulates or maintains that failure mode. >=20 I'd assume that the behavior is unchanged. Ithink we get a reference to=20 these ZONE_DEVICE pages via __get_user_pages_fast() and friends in=20 hva_to_pfn_fast() and friends in virt/kvm/kvm_main.c --=20 Thanks, David / dhildenb