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 570D4C00144 for ; Tue, 2 Aug 2022 02:00:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C94DE8E0001; Mon, 1 Aug 2022 22:00:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C44E26B0072; Mon, 1 Aug 2022 22:00:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0C898E0001; Mon, 1 Aug 2022 22:00:55 -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 9DB916B0071 for ; Mon, 1 Aug 2022 22:00:55 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 700181207AC for ; Tue, 2 Aug 2022 02:00:55 +0000 (UTC) X-FDA: 79752999270.25.C8281BB Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id 57C71A0046 for ; Tue, 2 Aug 2022 02:00:54 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LxdS20W7PzlVws; Tue, 2 Aug 2022 09:58:10 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:00:50 +0800 To: Linux-MM , linux-kernel CC: Andrew Morton , Mike Kravetz , Naoya Horiguchi , Muchun Song From: Miaohe Lin Subject: [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page Message-ID: <3c542543-0965-ef60-4627-1a4116077a5b@huawei.com> Date: Tue, 2 Aug 2022 10:00:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659405655; a=rsa-sha256; cv=none; b=ZHzZXngFLKpo1p32lYcg2joWYulR5dE03uQYsQl4fNyJzs5fSZODO2MTFY17KUjbY4HFpV 8mA7KRvN4U96j0CrC9d3CHSRpOboow1J/voPHiLkzwrDQXXjiFb0nMfXNBj8QbdcCo6Kg4 n3Pg6m6ZugLxdb/YdTo0oV8p2KcHFBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659405655; 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: references; bh=pIe3yxmAvsH3UcuWKwArYIIxwCAKTxil2MNnmi8wFUk=; b=y10UN7He8vAhGHwjrqu6dtEdxmFn/sVD8VyMJOBx2G2ECwCDpYKOsNKAm0XJz9pQnmsXE6 b6PdJWlIrH1ZUWtUGd1/gexjBIG305EzFvB19CDswZNc7Mx5Yi5juAUB1u+o3Bt9lZof+v lqWmB3SqFZ+VIQpWnDk3zQBqHxCI2ZQ= X-Stat-Signature: ster1eqatcjrixr5mq8xksqnkwap43k9 X-Rspamd-Queue-Id: 57C71A0046 Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1659405654-558879 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi all: When I investigate the mm/memory-failure.c code again, I found there's a possible race window between memory_failure and alloc_fresh_huge_page/free_huge_page. Thank about the below scene: CPU 1 CPU 2 alloc_fresh_huge_page -- page refcnt > 0 memory_failure prep_new_huge_page get_huge_page_for_hwpoison !PageHeadHuge -- so 2(not a hugepage) is returned hugetlb_vmemmap_optimize -- subpages is read-only set_compound_page_dtor -- PageHuge is true now, but too late!!! TestSetPageHWPoison(p) -- We might write to read-only subpages here!!! Another similar scene: CPU 1 CPU 2 free_huge_page -- page refcnt == 0 and not PageHuge memory_failure get_huge_page_for_hwpoison !PageHeadHuge -- so 2(not a hugepage) is returned TestSetPageHWPoison(p) -- We might write to read-only subpages here!!! hugetlb_vmemmap_restore -- subpages can be written to now, but too late!!! I think the above scenes are possible. But I can't found a stable solution to fix it. Any suggestions? Or is it not worth to fix it as it's too rare? Or am I miss something? Any response would be appreciated! Thanks!