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 6136DC43331 for ; Thu, 7 Nov 2019 22:07:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0F12120869 for ; Thu, 7 Nov 2019 22:07:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="czSKze3j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F12120869 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 CB8CE6B0005; Thu, 7 Nov 2019 17:07:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C69196B0006; Thu, 7 Nov 2019 17:07:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5A7D6B0007; Thu, 7 Nov 2019 17:07:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 9DDC86B0005 for ; Thu, 7 Nov 2019 17:07:38 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 5399F1EF0 for ; Thu, 7 Nov 2019 22:07:38 +0000 (UTC) X-FDA: 76130868996.03.paper17_427c140457c45 X-HE-Tag: paper17_427c140457c45 X-Filterd-Recvd-Size: 7556 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Nov 2019 22:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573164455; 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=gIBG5GMIReYQpS3U1ws59fK/jF+FBXDJRRxLPPFv3ms=; b=czSKze3jDZExFyu7+VF1A9unedZ4AmaM/FPc7XsPpG7zpUhRww3+lN5jSHXIvCScCf4z4u gwPF39FeBkI2RKry2V4WpFv0NRvkqXRUlMI40qBBM/Bm3VUxZK/CAcALetlnsdxnASB3jA RwSvFXiHaE7RJEKKj+DplhmJsQOpdfw= 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-288-U5XuV8_tOUWYRd6dFnpBtA-1; Thu, 07 Nov 2019 17:07:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4A64477; Thu, 7 Nov 2019 22:07:28 +0000 (UTC) Received: from [10.36.116.80] (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1309E600D3; Thu, 7 Nov 2019 22:07:10 +0000 (UTC) Subject: Re: [PATCH v1 04/10] vfio/type1: Prepare is_invalid_reserved_pfn() for PG_reserved changes To: David Hildenbrand , 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 References: From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <0eb001e0-bb26-59bb-c514-d2f8a86a7eab@redhat.com> Date: Thu, 7 Nov 2019 23:07:10 +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.11 X-MC-Unique: U5XuV8_tOUWYRd6dFnpBtA-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 07.11.19 19:22, David Hildenbrand wrote: >=20 >=20 >> Am 07.11.2019 um 16:40 schrieb Dan Williams : >> >> =EF=BB=BFOn Thu, Oct 24, 2019 at 5:12 AM David Hildenbrand wrote: >>> >>> 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 is_invalid_reserved_pfn() similar to kvm_is_reserved_pfn() to m= ake >>> sure the function produces the same result once we stop setting ZONE_DE= VICE >>> pages PG_reserved. >>> >>> Cc: Alex Williamson >>> Cc: Cornelia Huck >>> Signed-off-by: David Hildenbrand >>> --- >>> drivers/vfio/vfio_iommu_type1.c | 10 ++++++++-- >>> 1 file changed, 8 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_= type1.c >>> index 2ada8e6cdb88..f8ce8c408ba8 100644 >>> --- a/drivers/vfio/vfio_iommu_type1.c >>> +++ b/drivers/vfio/vfio_iommu_type1.c >>> @@ -299,9 +299,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, lo= ng npage, bool async) >>> */ >>> static bool is_invalid_reserved_pfn(unsigned long pfn) >>> { >>> - if (pfn_valid(pfn)) >>> - return PageReserved(pfn_to_page(pfn)); >>> + struct page *page =3D pfn_to_online_page(pfn); >> >> Ugh, I just realized this is not a safe conversion until >> pfn_to_online_page() is moved over to subsection granularity. As it >> stands it will return true for any ZONE_DEVICE pages that share a >> section with boot memory. >=20 > That should not happen right now and I commented back when you introduced= subsection support that I don=E2=80=99t want to have ZONE_DEVICE mixed wit= h online pages in a section. Having memory block devices that partially spa= n ZONE_DEVICE would be ... really weird. With something like pfn_active() -= as discussed - we could at least make this check work - but I am not sure = if we really want to go down that path. In the worst case, some MB of RAM a= re lost ... I guess this needs more thought. >=20 I just realized the "boot memory" part. Is that a real thing? IOW, can=20 we have ZONE_DEVICE falling into a memory block (with holes)? I somewhat=20 have doubts that this would work ... --=20 Thanks, David / dhildenb