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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39ACEC7618E for ; Mon, 24 Apr 2023 12:48:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C366B6B0075; Mon, 24 Apr 2023 08:48:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE6B66B0078; Mon, 24 Apr 2023 08:48:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAEEF6B007B; Mon, 24 Apr 2023 08:48:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9BF9E6B0075 for ; Mon, 24 Apr 2023 08:48:44 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 760011C60CC for ; Mon, 24 Apr 2023 12:48:44 +0000 (UTC) X-FDA: 80716263768.08.9DDAD79 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf15.hostedemail.com (Postfix) with ESMTP id 16329A0016 for ; Mon, 24 Apr 2023 12:48:40 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682340522; h=from:from:sender: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=MPRdkxc2LF662OTAX6h9X2fs/QBaN7kC7Y7jmLjUjH4=; b=mA40+BSvWR3lArFt7q/fbkSabuSTN6ESVOhpiIQdzNpZt4JGlwhUpp2OC1FrNw/JPuvv6Z F4gfE+jGY/jKM0o+1jvuSZiFsGZ+l4Q9VrDmaNyagh9YRrWtKQ3mIgRS3DcOXKCX1eldTV wQzLj8HwmqReVZDsCV0fPiN2pq48KVo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf15.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682340522; a=rsa-sha256; cv=none; b=MabFrxNnCULQ5vwmv6iqoltM/VmMR+P/PvVSUOAt+tfGKa7lkvn6np2r4Hkpfht4CaX+/d 2c80gEDKfu+Omei0/Rmy/OU954a/uU3rag0hY9Px4uymSHfni/jEtGGET1LNpq+bZ3gkYc +oBusN7sumvyxj5qvGj+fMtUAOyrw7o= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R861e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VguwqY0_1682340512; Received: from 30.212.138.173(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VguwqY0_1682340512) by smtp.aliyun-inc.com; Mon, 24 Apr 2023 20:48:35 +0800 Message-ID: Date: Mon, 24 Apr 2023 20:48:32 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v2 2/2] mm/page_alloc: add some comments to explain the possible hole in __pageblock_pfn_to_page() To: Michal Hocko Cc: akpm@linux-foundation.org, rppt@kernel.org, ying.huang@intel.com, mgorman@techsingularity.net, vbabka@suse.cz, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <9fc85cce8908938f4fd75ff50bc981c073779aa5.1682229876.git.baolin.wang@linux.alibaba.com> <0733a4cf57109a4136de5ae46fac83fb15bdd528.1682229876.git.baolin.wang@linux.alibaba.com> <9a20c0b5-9d8a-2b1d-570a-61c17a4ce5e8@linux.alibaba.com> <8d4059e3-2e6d-3f0c-2881-13b9bd07aa6c@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 16329A0016 X-Stat-Signature: kyfy85no1e6iraspe8uojei1ojfoo17t X-Rspam-User: X-HE-Tag: 1682340520-176340 X-HE-Meta: U2FsdGVkX19fUX4KoqaAqlCc04VaA8G9r6H1o+48pHfvNb7moiuobyVScvsV9LBks0hQgT3Lc5fSe5UUOlk6dAujQ5S5NCel0V27V7FUhmDrJXshCDMR0owtln31cetxw7X9+N/XyQonyyTsUiqgFn9UNZNdK8vPK7cA49pdCBYZNBsIxAg9KaUF1Cg5dO7gc8j2DNSJkZxojNz/NKvlWkMkqi/b7rq6zOMJj6fNxIUX8bpaT6L75OSXnwp84ER4yryzHCl+Zi+Ky2Jk0mv8Z48bsjbnxj9L6zybHh7XFrsMyMA8dKOJqS0IKaCCzDa8nUUlhy5S4g+R6bNqLbKIqVhCapuWrZDK7RyX36fw0sgoHI9xtUK4vU4hFNCca0EOgcyYwfg8dHJYBr+RgvJ3ZyuRBj1O7lu5Cn921VEFmwnzODxmxYGzSyy39w/MDUPhmEmDR7oD3QJ7t1q8V+v3L+U9TkREssOGOnJOBcoCmuXWDKlQxmRtviNK2GY0PToeA10O+02uLm7LzwvNCgpbdZXCexGqE1PSBD68U7bOvIqv/yvV4utJ0MBFhJHO/yyGGpPzU7fZ1uaqjIFQV7hNgR+o+Md/zDxFpHJamoOna3h8zqAanmulDeWRZFRZfqe4leOf3UTKGiX2Nmc6N2oCfjXvSyaVhNBmDuNV92m4bGbhq9x/CMZ5SrkxQiU9f9UIMSfksVobng4o7+96dOWnxvRhOdsgRsXuFD/icFySCUBbdCjvP4zLFau6Krm9jFd7o1nHWVO41VlmOt28ouskvJxihEYxm8oEXOo3JJpChlDrJi106hkCb40oOc5EN1EijKegrXOzF6MNT9jEOvpTJFLN3faOWVxLsYGlYXhHGzLqEHJdA9pYuGSk3kBY0jA+DM7X1AenUHDjGMtZ9HKPrkEg61MUIA4Y2sVXn31XaJm2kIWrToZsnwN1xsw1XS+i8GE5Q7JiaT/gAwh9wT0 ikQ4Zixt EX1ED6Bw+uRJd0YbJBbWUyJaJVvBlDTHzbjqpGyPzNOUxeJJbaom8NzcGK3wXjuwwenw58ADzya9lHvV+JtX8rVtgBcjRepbIZk766eWCxfrRXblCi45d5+Pcb9Zs303dogX5QqYtff2Gm8U5g2hWFJJ56td5DcvWwnq/yTuX+DKIOfRBh9Q8uFm3Qn45wjX/KV1HkiCAfCSyaNMapKGj2tUZ9bqlK1Rw2OOeNq9SRyGiIYwHdQb8QGj9LFB8u3n5tH4RG9uENqQSylg= 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 4/24/2023 8:08 PM, Michal Hocko wrote: > On Mon 24-04-23 19:40:30, Baolin Wang wrote: >> >> >> On 4/24/2023 7:34 PM, Michal Hocko wrote: >>> On Mon 24-04-23 19:20:43, Baolin Wang wrote: >>>> >>>> >>>> On 4/24/2023 5:54 PM, Michal Hocko wrote: >>>>> On Sun 23-04-23 18:59:11, Baolin Wang wrote: >>>>>> Now the __pageblock_pfn_to_page() is used by set_zone_contiguous(), which >>>>>> checks whether the given zone contains holes, and uses pfn_to_online_page() >>>>>> to validate if the start pfn is online and valid, as well as using pfn_valid() >>>>>> to validate the end pfn. >>>>>> >>>>>> However, the __pageblock_pfn_to_page() function may return non-NULL even >>>>>> if the end pfn of a pageblock is in a memory hole in some situations. For >>>>>> example, if the pageblock order is MAX_ORDER, which will fall into 2 >>>>>> sub-sections, and the end pfn of the pageblock may be hole even though >>>>>> the start pfn is online and valid. >>>>>> >>>>>> This did not break anything until now, but the zone continuous is fragile >>>>>> in this possible scenario. So as previous discussion[1], it is better to >>>>>> add some comments to explain this possible issue in case there are some >>>>>> future pfn walkers that rely on this. >>>>>> >>>>>> [1] https://lore.kernel.org/all/87r0sdsmr6.fsf@yhuang6-desk2.ccr.corp.intel.com/ >>>>> >>>>> Do I remember correctly you've had a specific configuration that would >>>>> trigger this case? >>>> >>>> Yes, I provided an example in previous thread [2] so show the >>>> __pageblock_pfn_to_page() is fragile in some cases. >>>> >>>> [2] https://lore.kernel.org/all/52dfdd2e-9c99-eac4-233e-59919a24323e@linux.alibaba.com/ >>> >>> Please make it a part of the changelog. >> >> Sure. >> >>>>> >>>>>> Signed-off-by: Baolin Wang >>>>>> --- >>>>>> Changes from v1: >>>>>> - Update the comments per Ying and Mike, thanks. >>>>>> --- >>>>>> mm/page_alloc.c | 7 +++++++ >>>>>> 1 file changed, 7 insertions(+) >>>>>> >>>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>>>> index 6457b64fe562..9756d66f471c 100644 >>>>>> --- a/mm/page_alloc.c >>>>>> +++ b/mm/page_alloc.c >>>>>> @@ -1502,6 +1502,13 @@ void __free_pages_core(struct page *page, unsigned int order) >>>>>> * interleaving within a single pageblock. It is therefore sufficient to check >>>>>> * the first and last page of a pageblock and avoid checking each individual >>>>>> * page in a pageblock. >>>>>> + * >>>>>> + * Note: the function may return non-NULL even if the end pfn of a pageblock >>>>>> + * is in a memory hole in some situations. For example, if the pageblock >>>>>> + * order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn >>>>>> + * of the pageblock may be hole even though the start pfn is online and valid. >>>>>> + * This did not break anything until now, but be careful about this possible >>>>>> + * issue when checking whether all pfns of a pageblock are valid. >>>>> >>>>> It is not really clear what you should be doing (other than to be >>>>> careful which is not helpful much TBH) when you encounter this >>>>> situation. If the reality changes and this would break in the future >>>>> what would breakage look like? What should be done about that? >>>> >>>> That depends on what the future pfn walkers do, which may access some hole >>>> memory with zero-init page frame. For example, if checking the >>>> __PageMovable() for a zero-init page frame, that will crash the system. But >>>> I can not list all the possible cases. >>>> >>>> So how about below words? >>>> >>>> * Note: the function may return non-NULL even if the end pfn of a pageblock >>>> * is in a memory hole in some situations. For example, if the pageblock >>>> * order is MAX_ORDER, which will fall into 2 sub-sections, and the end pfn >>>> * of the pageblock may be hole even though the start pfn is online and >>>> valid. >>>> * This did not break anything until now, but be careful about this possible >>>> * issue when checking whether all pfns of a pageblock are valid, that may >>>> * lead to accessing empty page frame, and the worst case can crash the >>>> system. >>>> * So you should use pfn_to_onlie_page() instead of pfn_valid() to valid the >>>> * pfns in a pageblock if such case happens. >>> >>> Does that mean that struct page is not initialized and PagePoisoned will >>> trigger or it is just zero-prefilled? >> >> In the example I provided[2], these page frames of the hole memory are >> zero-prefilled. > > OK, so make _that_ explicit in the comment. Essentially you want to say > that there are cases where we have zero-initialized struct pages for > memory holes. In general no pfn walker should touch a physical memory > range for pfn where the struct page doesn't contain any metadata it > recognizes. Zero fill struct pages do not contain any distinguishable > state so that makes it less of a problem. > > All that being said I would reformulate the comment as follows: > > * Note: the function may return non-NULL struct page even for a > * page block which contains a memory hole (i.e. there is no > * physical memory for a subset of the pfn range). This should be > * safe most of the time because struct pages are still zero > * pre-filled and pfn walkers shouldn't touch any physical memory > * range for which they do not recognize any specific metadata in > * struct pages. Thanks. That makes sense to me. A trivial thing is I still want to add the example in the comments to make it clear. Are you okay with below description? + * Note: the function may return non-NULL struct page even for a page block + * which contains a memory hole (i.e. there is no physical memory for a subset + * of the pfn range). For example, if the pageblock order is MAX_ORDER, which + * will fall into 2 sub-sections, and the end pfn of the pageblock may be hole + * even though the start pfn is online and valid. This should be safe most of + * the time because struct pages are still zero pre-filled and pfn walkers + * shouldn't touch any physical memory range for which they do not recognize + * any specific metadata in struct pages.