Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2303204imn; Mon, 1 Aug 2022 19:57:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR4jowf1OrD/CF6uZkXbqAfAlXvLmgIp6kxLWYFIpFFTer1BNBxlUo5Vmy5wd9JM9L5OwGiA X-Received: by 2002:a17:90b:4b0a:b0:1f2:a904:8af7 with SMTP id lx10-20020a17090b4b0a00b001f2a9048af7mr22386168pjb.76.1659409077375; Mon, 01 Aug 2022 19:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659409077; cv=none; d=google.com; s=arc-20160816; b=bnURdP12u0kv7+NBacNLk2KvgLyoghrfhGzExdj9Yjb6hJzXIORKF969PmTQS8lvSc JluV7Fa2f9hn0emeBPPm11VAx9kNEbsiGTAJSUhFEHUiF7oWDQ6lhZsTWx9Pn5E9dHOo wVokukr3OoPitWFf+gBsn/WECwYiNecIzLDxQNIn0cJ6dvT4DIeXBMp6ghAoKt4Tcf7K MbZ4DK8kh0SmnIq0upLItu/U/bcGwzxblPvEQGd/vrHRbcZbjEXOJB5dUdj6DgrhSXL3 XbD2dIwVFhPb45R/3rXMY4jGtzM1GwsdRvFOBLv6SdRH95bF0Cx0ZnXDeMsLQLkGnlIg pv/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=pIe3yxmAvsH3UcuWKwArYIIxwCAKTxil2MNnmi8wFUk=; b=pZaVNOUdDykdVrYT8ErckzFFGrSZkb0oiUnnZEZKRvQZKBzpF2UL/rzEd4mACjMPta oQDsceFzVIm3dFTI0Dgaj7xTLoFsLYlwYMXwr3ykyPJUaZXKclqQylS9RZ7g/jUmA7cS 9SaEkCxBEhMothHS4MDftzchVV5JQ+BgHU/Mj/R5KomATgz+RdzWxTaGS47tPwAw4W6D xkPgRibYnJX8Y59DCcihT04/TPsMImnsHos6IzFfniQshOaqhQBR2YxzmsHc4XfvF6XT pFCUPE9M9EHgc/sRMe1/lmhhx8pIf29UFOpbcTZswP4eVPYlWpV0VQE5D1QsAmzA5LBD eoiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a170902f64800b0016daa0c3ab5si13689648plg.406.2022.08.01.19.57.42; Mon, 01 Aug 2022 19:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232075AbiHBCBT (ORCPT + 99 others); Mon, 1 Aug 2022 22:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235646AbiHBCAy (ORCPT ); Mon, 1 Aug 2022 22:00:54 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 110AA9FC6 for ; Mon, 1 Aug 2022 19:00:53 -0700 (PDT) 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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!