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=-7.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 B65BBC433E0 for ; Wed, 6 Jan 2021 11:23:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4FD8722CA2 for ; Wed, 6 Jan 2021 11:23:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4FD8722CA2 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 66A8E8D0107; Wed, 6 Jan 2021 06:23:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 61AF88D0090; Wed, 6 Jan 2021 06:23:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5098A8D0107; Wed, 6 Jan 2021 06:23:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 383BE8D0090 for ; Wed, 6 Jan 2021 06:23:06 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EE0B61DFA for ; Wed, 6 Jan 2021 11:23:05 +0000 (UTC) X-FDA: 77675113530.12.ducks58_4616dd5274e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 0812F1800CA61 for ; Wed, 6 Jan 2021 11:23:04 +0000 (UTC) X-HE-Tag: ducks58_4616dd5274e1 X-Filterd-Recvd-Size: 5842 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Jan 2021 11:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609932182; 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=usdz30vfvmLeBQ3gUZ4ei47Vuh3vKt72mif3hNqCSdM=; b=JDuBe3f0RfBIuJJoOQVPOkpt/GgSkm2xYjMvXDh4nVzWtNFUA3utzFZ4u669JRADAHzkuz IsmHtoQGhrcF/smWwXKmJlgG0HsjdZKyp1Uf2KntL0bOnT7eFlykJ/Tz4//Jp/UcZNxFHS aE33kiUxg0ndZVhAx2jWhIOBV7nVi3A= 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-341-9c0jFVblNaSSeEaoDE7DiA-1; Wed, 06 Jan 2021 06:23:00 -0500 X-MC-Unique: 9c0jFVblNaSSeEaoDE7DiA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75382801AC0; Wed, 6 Jan 2021 11:22:59 +0000 (UTC) Received: from [10.36.112.46] (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id D834960BE2; Wed, 6 Jan 2021 11:22:57 +0000 (UTC) Subject: Re: [PATCH] mm: Teach pfn_to_online_page() about ZONE_DEVICE section collisions To: Michal Hocko Cc: Dan Williams , linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org References: <160990599013.2430134.11556277600719835946.stgit@dwillia2-desk3.amr.corp.intel.com> <785b9095-eca4-8100-33ea-6ae84e02a92e@redhat.com> <20210106104255.GK13207@dhcp22.suse.cz> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <7d7c5dc4-7784-5dcc-fc00-4fe99f0a4a90@redhat.com> Date: Wed, 6 Jan 2021 12:22:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20210106104255.GK13207@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 06.01.21 11:42, Michal Hocko wrote: > On Wed 06-01-21 10:56:19, David Hildenbrand wrote: > [...] >> Note that this is not sufficient in the general case. I already >> mentioned that we effectively override an already initialized memmap. >> >> --- >> >> [ SECTION ] >> Before: >> [ ZONE_NORMAL ][ Hole ] >> >> The hole has some node/zone (currently 0/0, discussions ongoing on how >> to optimize that to e.g., ZONE_NORMAL in this example) and is >> PG_reserved - looks like an ordinary memory hole. >> >> After memremap: >> [ ZONE_NORMAL ][ ZONE_DEVICE ] >> >> The already initialized memmap was converted to ZONE_DEVICE. Your >> slowpath will work. >> >> After memunmap (no poisioning): >> [ ZONE_NORMAL ][ ZONE_DEVICE ] >> >> The slow path is no longer working. pfn_to_online_page() might return >> something that is ZONE_DEVICE. >> >> After memunmap (poisioning): >> [ ZONE_NORMAL ][ POISONED ] >> >> The slow path is no longer working. pfn_to_online_page() might return >> something that will BUG_ON via page_to_nid() etc. >> >> --- >> >> Reason is that pfn_to_online_page() does no care about sub-sections. And >> for now, it didn't had to. If there was an online section, it either was >> >> a) Completely present. The whole memmap is initialized to sane values. >> b) Partially present. The whole memmap is initialized to sane values. >> >> memremap/memunmap messes with case b) > > I do not see we ever clear the newly added flag and my understanding is > that the subsection removed would lead to get_dev_pagemap returning a > NULL. Which would obviously need to be checked for pfn_to_online_page. > Or do I miss anything and the above is not the case and we could still > get false positives? See my example above ("After memunmap"). We're still in the slow pathg. pfn_to_online_page() will return a struct page as get_dev_pagemap() is now NULL. Yet page_zone(page) will either - BUG_ON (memmap was poisoned) - return ZONE_DEVICE zone (memmap not poisoned when memunmapping) As I said, can be tackled by checking for pfn_section_valid() at least on the slow path. Ideally also on the fast path. > >> Well have to further tweak pfn_to_online_page(). You'll have to also >> check pfn_section_valid() *at least* on the slow path. Less-hacky would >> be checking it also in the "somehwat-faster" path - that would cover >> silently overriding a memmap that's visible via pfn_to_online_page(). >> Might slow down things a bit. >> >> >> Not completely opposed to this, but I would certainly still prefer just >> avoiding this corner case completely instead of patching around it. Thanks! > > Well, I would love to have no surprises either. So far there was not > actual argument why the pmem reserved space cannot be fully initialized. Yes, I'm still hoping Dan can clarify that. > On the other hand making sure that pfn_to_online_page sounds like the > right thing to do. And having an explicit check for zone device there in > a slow path makes sense to me. As I said, I'd favor to simplify and just get rid of the special case, instead of coming up with increasingly complex ways to deal with it. pfn_to_online_page() used to be simple, essentially checking a single flag was sufficient in most setups. -- Thanks, David / dhildenb