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 X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 818C3C48BDF for ; Wed, 16 Jun 2021 03:14:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F0C1561369 for ; Wed, 16 Jun 2021 03:14:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0C1561369 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 41BFD6B006C; Tue, 15 Jun 2021 23:14:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CCA66B006E; Tue, 15 Jun 2021 23:14:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26D7C6B0070; Tue, 15 Jun 2021 23:14:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id EDA7C6B006C for ; Tue, 15 Jun 2021 23:14:36 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 90E95180AD804 for ; Wed, 16 Jun 2021 03:14:36 +0000 (UTC) X-FDA: 78258119352.02.33CBC9B Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf18.hostedemail.com (Postfix) with ESMTP id B027D2001060 for ; Wed, 16 Jun 2021 03:14:26 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4G4VYj1w7jz6y6Y; Wed, 16 Jun 2021 11:10:33 +0800 (CST) Received: from [10.174.176.146] (10.174.176.146) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 16 Jun 2021 11:14:31 +0800 Subject: Re: [PATCH v1 1/6] mm/hwpoison: mf_mutex for soft offline and unpoison To: =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= CC: Naoya Horiguchi , Andrew Morton , David Hildenbrand , Oscar Salvador , Michal Hocko , Ding Hui , Tony Luck , Aneesh Kumar K.V , "linux-kernel@vger.kernel.org" , Linux-MM References: <20210614021212.223326-1-nao.horiguchi@gmail.com> <20210614021212.223326-2-nao.horiguchi@gmail.com> <20210616004129.GB1924716@hori.linux.bs1.fc.nec.co.jp> From: Miaohe Lin Message-ID: Date: Wed, 16 Jun 2021 11:14:31 +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: <20210616004129.GB1924716@hori.linux.bs1.fc.nec.co.jp> Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.176.146] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-Stat-Signature: cdytnmsnqbgjatyb7qft1hk7uk8xtfox X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B027D2001060 X-HE-Tag: 1623813266-255064 Content-Transfer-Encoding: quoted-printable 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 2021/6/16 8:41, HORIGUCHI NAOYA(=E5=A0=80=E5=8F=A3 =E7=9B=B4=E4=B9=9F)= wrote: > On Tue, Jun 15, 2021 at 08:42:23PM +0800, Miaohe Lin wrote: > ... >>> @@ -1960,7 +1964,7 @@ int unpoison_memory(unsigned long pfn) >>> if (!PageHuge(page) && PageTransHuge(page)) { >>> unpoison_pr_info("Unpoison: Memory failure is now running on %#lx\= n", >>> pfn, &unpoison_rs); >>> - return 0; >>> + goto unlock_mutex; >>> } >>> =20 >> >> Maybe it's more appropriate to start mutex_lock(&mf_mutex) here? I thi= nk these races start here. >=20 > Hi Miaohe, >=20 > Thank your for the review. > > Consider that we put mutex_lock() here, and let's think about two con= current > calls of unpoison_memory(), then these events could be processed like b= elow: >=20 > CPU 0 CPU 1 > unpoison_memory > check PageHWPoison // true > unpoison_memory > check PageHWPoison // true > mutex_lock > get_hwpoison_page > TestClearPageHWPoison > put_page > put_page // freed > mutex_unlock >=20 > // the unpoisoned page can be used for allocation >=20 > mutex_lock > get_hwpoison_page // succeeds > ... // unpoison the !PageHWPoison= page !? >=20 >=20 > So I thought that we had better do the prechecks in mf_mutex. Maybe th= e 2nd > unpoison_memory() just get and put the page refcount by 1 even in this = race, > so the impact is not so big, but I feel like avoiding "unpoison the > !PageHWPoison page" situation. >=20 > Does it make sense for you? Yes, I missed the races inside unpoison_memory() itself. Many thanks for your detailed explanation! >=20 > Thanks, > Naoya Horiguchi >=20