Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2373978imn; Mon, 1 Aug 2022 23:42:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR58DfEIg9H30QrXMxHh6MYOxmoHpIsBB8xINaIMKvVK5S77WPPJ3PlWZQeAY7XSvYde9rGr X-Received: by 2002:a17:902:d4d1:b0:16e:ec0b:75d0 with SMTP id o17-20020a170902d4d100b0016eec0b75d0mr8221043plg.123.1659422552305; Mon, 01 Aug 2022 23:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659422552; cv=none; d=google.com; s=arc-20160816; b=bgsDmlxV5dM8SukWLout6SqSCukt8UKMCX1s86tq5KQfqNwPgRMsrY6bqqEJi4v7zn yGjnw4g/l/xggIGzFY2dycEWnuSorDj/DebKbWBDuIDXkfUVI2jrGj6vm+SemLRf4yp7 RoNJg7N9MwKOY6nyTkCmtzxx0FAI22rFgEwP4TX8MogJzo4ar5JtQtAy7MOy8p2XkPj+ YRLWb3na7MpCjeo7d2ANb+e1vHV6Hl1xHdrYi9HdEk0INPkN+2Wquh+kFc/YJxd81cHX aiKdeWT9+3Oq7vMpY56nWHjX/WCS4N8ndN2onUM4NzqkyfXekTSejlKgyEj61QPRju1X Y0KA== 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 :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=uP1VCkil1vPqtfEc3ng3KdazHfz7HpDvCES/3ItiGZI=; b=GtU+nUH9Lv41DfrmOhf3dC48myYoixFdNc7199WI7F1eQCLF3SONRmeNQHMMRLnzk6 rRyYnooHXwgP9umVhiKoisX198RXPHNRa7ZmWvBeMOjEdySd29A4kHvwrrzDYMXWchpR chY1dwT98P7EoDdDbet0P969aoVn6VjsRwxWpIfKNvaS/k6tufB5kb1YFoeaGJOVA2W4 ucYO8iB0j2AsLojMzmFW7A1bi1leb8pBVQaG9djCUJpNcHHddLAPbkfX7W82T7YzNCoT LyUKHZLVWbDRAmpvtp8J4O2A44nGgej5trVVH3+8Rtzk5y9Z5+NPtODCps0id1g8uzdX 4Xmw== 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 r126-20020a632b84000000b0041baf7abbf7si11493770pgr.333.2022.08.01.23.42.18; Mon, 01 Aug 2022 23:42:32 -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 S232060AbiHBG1o (ORCPT + 99 others); Tue, 2 Aug 2022 02:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231404AbiHBG1l (ORCPT ); Tue, 2 Aug 2022 02:27:41 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C04A1A385 for ; Mon, 1 Aug 2022 23:27:40 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LxlMS2cKmz1M8Sv; Tue, 2 Aug 2022 14:24:36 +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 14:27:36 +0800 Subject: Re: [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page To: Muchun Song CC: Linux-MM , linux-kernel , Andrew Morton , Mike Kravetz , Naoya Horiguchi References: <3c542543-0965-ef60-4627-1a4116077a5b@huawei.com> From: Miaohe Lin Message-ID: Date: Tue, 2 Aug 2022 14:27:36 +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 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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,NICE_REPLY_A, 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 On 2022/8/2 12:07, Muchun Song wrote: > On Tue, Aug 02, 2022 at 10:00:50AM +0800, Miaohe Lin wrote: >> 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 agree this race is possible, I have proposed this race in thread [1]. Oh, I remember I see the race proposed in [1] but I did not look into that carefully at that time. Sorry. > But I didn't think more how to solve it. I hope this thread can find a good solution. :) > > [1] https://lore.kernel.org/linux-mm/20220623235153.2623702-1-naoya.horiguchi@linux.dev/T/#ma094a7cea7df8fd9a77a91551bf39077d89e23bd > >> 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? >> > > Luckily, the system will panic at once, which encountering this race. However, > we don't see any bug report. If we have an easy way to fix it, I think it is worth. Agree. But I can't find a easy way to fix it yet. > Just a quick reply, no suggestion/solutions from me. Many thanks for your quick reply. > > Thanks. > >> Any response would be appreciated! >> >> Thanks! >> > . >