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 B0D84ECAAD3 for ; Fri, 9 Sep 2022 09:03:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32FDE8D0002; Fri, 9 Sep 2022 05:03:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E00A8D0001; Fri, 9 Sep 2022 05:03:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 180908D0002; Fri, 9 Sep 2022 05:03:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 05C2C8D0001 for ; Fri, 9 Sep 2022 05:03:54 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CB94DA03C8 for ; Fri, 9 Sep 2022 09:03:53 +0000 (UTC) X-FDA: 79891959546.08.7077E14 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 6A788C0097 for ; Fri, 9 Sep 2022 09:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662714231; 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=9AalRgf1NKZJEB+k1S5Ust8U7ijr4rKw+bIpfwyRZcE=; b=TWMC8+TRTe8AQQ44EUMQSuR0UEMaxv0W1cJ4xL1ryqHBP+g2MCFXy6rHcH8iot0LAllNjY lcdiYftc698Q1jxk9td7NpnAD86IXSB5whlO0CHnXFNcpNcY2SUaQn7cznLta/wWpQH/G7 q+fkfRiG8PTVgTwVhuW6n99z7dLLcl8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-605-3Nt4QSszMKKjyJS1vnOlyg-1; Fri, 09 Sep 2022 05:03:50 -0400 X-MC-Unique: 3Nt4QSszMKKjyJS1vnOlyg-1 Received: by mail-wm1-f70.google.com with SMTP id y4-20020a05600c364400b003b341f29747so287436wmq.3 for ; Fri, 09 Sep 2022 02:03:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date; bh=9AalRgf1NKZJEB+k1S5Ust8U7ijr4rKw+bIpfwyRZcE=; b=kYyMT3r+zfHlbb7lBzceUJEfEFnHfwnhv14ZYym0F85K5UV+0Y91JPwG/GsxL/elEs KcGp6UYUV7STa1773nrAkPKYzbzk9tPsIlIq/1Hf/5Tw8CqrmyORzmAAtDxhNbioyIBC qjNb4WaxW10QOCfDfqcPjS/V2YnAayJoLPcAUVqBLxe/wrDCkkK9oSRScHFw6rAbUsQ1 61AgDP7ds4eoGEygh9zqmcNNn914/lYKwa+gMBzFxu8nYJQoZ9QscLTA4kGLMMlhZ4Hd jHynA/qtfKDPXnLM3PxIK07jx71JKXe/SNnqbEyFipsckWi9+36aS6sUyHr3ruFiGuZF 9N1Q== X-Gm-Message-State: ACgBeo27FhrIn7g6RYFTqA/yMGCmIwRMGVhA1WI5L4TlcfK3Tk2DsVMX cX/62CZn4+SNYWMldpn7SoBzcdTas2ua4D1sLp5twOZTXomkAtvEi5PjmCCapD5C+Gra8Mmth9/ NcdDQbQyRJkA= X-Received: by 2002:a05:600c:3d05:b0:3a5:dd21:e201 with SMTP id bh5-20020a05600c3d0500b003a5dd21e201mr4741413wmb.132.1662714229590; Fri, 09 Sep 2022 02:03:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR4APiTkcm6nhNJG0w9lCvgecoEnXmH3Wo2FRBo0vEBXl1M+CNFo1If1eYRJ8GerV6PuyUfNEQ== X-Received: by 2002:a05:600c:3d05:b0:3a5:dd21:e201 with SMTP id bh5-20020a05600c3d0500b003a5dd21e201mr4741400wmb.132.1662714229313; Fri, 09 Sep 2022 02:03:49 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:6300:1fe0:42e1:62c5:91b6? (p200300cbc70463001fe042e162c591b6.dip0.t-ipconnect.de. [2003:cb:c704:6300:1fe0:42e1:62c5:91b6]) by smtp.gmail.com with ESMTPSA id o5-20020a05600c510500b003a31fd05e0fsm16443186wms.2.2022.09.09.02.03.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Sep 2022 02:03:48 -0700 (PDT) Message-ID: <9244cca9-8c99-a8f4-2acb-248c2491bee4@redhat.com> Date: Fri, 9 Sep 2022 11:03:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] mm/huge_memory: use pfn_to_online_page() in split_huge_pages_all() To: Miaohe Lin , Michal Hocko Cc: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Naoya Horiguchi , "linux-mm@kvack.org" , Andrew Morton , Muchun Song , Matthew Wilcox , Yang Shi References: <20220907100855.GA2894785@ik1-406-35019.vs.sakura.ne.jp> <1481ce19-0a64-d1dc-4d89-4db71d6f7eb3@redhat.com> <20220907121157.GA2954283@ik1-406-35019.vs.sakura.ne.jp> <9cb0b01e-c80d-667c-47f1-ad30e329784b@huawei.com> <20220908030652.GA1492282@hori.linux.bs1.fc.nec.co.jp> <2d0792c0-88e1-710c-c8bd-c126cc375e88@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <2d0792c0-88e1-710c-c8bd-c126cc375e88@huawei.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662714232; a=rsa-sha256; cv=none; b=uotT4mIwlCopO1UrAiwgrlSg8Uv4xBhUkabr6RQTphuWtMk0z9fMTrh/CxyZzuoFry5g5Q Cb976VVrF3OAZ9fRHBL+qBU0KO8nCZ1HBJ4Uy8WDy/G9UpCIuFzvDOOfecKuBgOFwD0kSt 5uwWj0Mh1dBueNg3KE2qkmV1WZkzJYI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TWMC8+TR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662714232; 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:dkim-signature; bh=9AalRgf1NKZJEB+k1S5Ust8U7ijr4rKw+bIpfwyRZcE=; b=LNqH/rBVpEh1hlwVOD2BYXpg6s/hU9H1cm+SxRFT0GJrlsrTg1rZKqssPSv4L+TzE4lgYR z3XwOQowwR5bN1X+rWnP4NWo8p6sXPDdoobdksrUfqk/qF2ZihZ/P5ywNFadU9rodrWVBr q0MQWQwS0IXkzokwFnoiGVKZPXha0fQ= X-Stat-Signature: exyh76yf4f3iud6nfmitsaaiyxi4kdta X-Rspamd-Queue-Id: 6A788C0097 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TWMC8+TR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam02 X-HE-Tag: 1662714232-958686 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 09.09.22 02:27, Miaohe Lin wrote: > On 2022/9/8 15:07, Michal Hocko wrote: >> On Thu 08-09-22 11:25:54, Miaohe Lin wrote: >>> On 2022/9/8 11:06, HORIGUCHI NAOYA(堀口 直也) wrote: >>>> On Thu, Sep 08, 2022 at 10:19:03AM +0800, Miaohe Lin wrote: >>>>> On 2022/9/7 20:11, Naoya Horiguchi wrote: >>>> ... >>>>>> >From 8a5c284df732943065d23838090d15c94cd10395 Mon Sep 17 00:00:00 2001 >>>>>> From: Naoya Horiguchi >>>>>> Date: Wed, 7 Sep 2022 20:58:44 +0900 >>>>>> Subject: [PATCH] mm/huge_memory: use pfn_to_online_page() in >>>>>> split_huge_pages_all() >>>>>> >>>>>> NULL pointer dereference is triggered when calling thp split via debugfs >>>>>> on the system with offlined memory blocks. With debug option enabled, >>>>>> the following kernel messages are printed out: >>>>>> >>>>>> page:00000000467f4890 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x121c000 >>>>>> flags: 0x17fffc00000000(node=0|zone=2|lastcpupid=0x1ffff) >>>>>> raw: 0017fffc00000000 0000000000000000 dead000000000122 0000000000000000 >>>>>> raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000 >>>>>> page dumped because: unmovable page >>>>>> page:000000007d7ab72e is uninitialized and poisoned >>>>>> page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) >>>>>> ------------[ cut here ]------------ >>>>>> kernel BUG at include/linux/mm.h:1248! >>>>>> invalid opcode: 0000 [#1] PREEMPT SMP PTI >>>>>> CPU: 16 PID: 20964 Comm: bash Tainted: G I 6.0.0-rc3-foll-numa+ #41 >>>>>> ... >>>>>> RIP: 0010:split_huge_pages_write+0xcf4/0xe30 >>>>>> >>>>>> This shows that page_to_nid() in page_zone() is unexpectedly called for an >>>>>> offlined memmap. >>>>>> >>>>>> Use pfn_to_online_page() to get struct page in PFN walker. >>>>> >>>>> With changes proposed by David, this patch looks good to me. >>>>> >>>>> Reviewed-by: Miaohe Lin >>>> >>>> Thank you. >>>> >>>>> >>>>> BTW: IMHO, there might be many similar code places need to take care of memory hotremove where >>>>> *pfn is operated directly* while it's not protected against memory hotremove. >>>> >>>> I had the similar concern, but there seems many place doing PFN walk, >>>> so checking them one-by-one that offlined memory can be walked over >>>> requires much effort. >>> >>> Yes, that will be a heavy work. We could fix them one by one if they ever occur. ;) >> >> Most of those whic are directly triggerable should be taken care of. It >> would be still good to go through `git grep -w pfn_to_page' and evaluate >> all callers. Still more than 400 callsites so not a trivial task. > > Agree. Even if pfn_to_online_page() is used, it might still races with the memory hotremove if > there's no way to guard against it, e.g. holding an extra page refcnt. So code audit should also > apply to pfn_to_online_page(). Racing with offlining+unplug a long known problem and so far we decided to ignore it, because it never appeared in practice. There once were ideas of using RCU as protection. -- Thanks, David / dhildenb