From patchwork Mon Jun 14 02:12:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12318029 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 3461DC48BDF for ; Mon, 14 Jun 2021 02:12:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B3CA9613AB for ; Mon, 14 Jun 2021 02:12:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3CA9613AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 552316B0070; Sun, 13 Jun 2021 22:12:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 529A96B0071; Sun, 13 Jun 2021 22:12:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 416A66B0072; Sun, 13 Jun 2021 22:12:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 0ACF36B0070 for ; Sun, 13 Jun 2021 22:12:29 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9499E180AD806 for ; Mon, 14 Jun 2021 02:12:29 +0000 (UTC) X-FDA: 78250705218.39.7E26F58 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf12.hostedemail.com (Postfix) with ESMTP id 37786F2 for ; Mon, 14 Jun 2021 02:12:18 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id h12-20020a17090aa88cb029016400fd8ad8so9231903pjq.3 for ; Sun, 13 Jun 2021 19:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PD461rujAEvHxr+/423Md1bdyuXr957SSOfQ9o3RiIk=; b=Zg98D31y7/QomMWOeDbhAIjUUpumQ3WhsLgSXqChPuNcTO+2B3Yg3tFURj+HMYSTuY PMei/LmWGdXfCCmEKF9ncLLJrQ/jKYh0rTohjWY6rqlxctl4HwaV91DLBLy0OYa7dw+r MGa4EDsvCz+6oSI/dPLaVhDmrKlmWDjreg465vIppbjSNcGgDGSvyo108WGwpF5NK+62 WzSZk9NMXQpwoC+XEiabwbJ7H3gRE0GRj/mtYQzhWAzNZNltfg+YM9S96fZDpiXLUkVC BA+dAoDG9gLipFKLklBHKCam2Wq/IIdiGC5c/yfYlUXKnr+/yQXjvvPVoauEVtILZ3ri uUPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PD461rujAEvHxr+/423Md1bdyuXr957SSOfQ9o3RiIk=; b=mEwkt8FHxXjlvAD2nEO2ZpSlrbH3y1r+O2/SAenmKZCdEGPPaxSWMah7M1J2yUKmRV xcN025l1MCvn6VMA6GTTN33mAuv+PQhh2Hk/Fobj6bPCEr6xzdFykNOXQIV2LjqCi0fh L//SkEXwwyIg5SfS3y1x7O3wSoHK2xRn1z6Tgk+cojhTJAqpIsD34P4FwlYGgrzL1dqL kcZ6pyjV31ckx284g6iYufiRKA3RhrtxLrAf79hRJSmMtwE5yBnEuFXW8xhUnY6fseuF pwr9LinhIsGloIieXD+910wCigeiXfbhtK0A/o2DuBqbYJJuyAHLPHCJuZDu9gQqcanM AKHw== X-Gm-Message-State: AOAM532WLluqSrcyP4HxJKgKPWaBBmuX0O4WYf2GrwOV/8SPWe66YmAj rnG3W52CKKVImf2+7BI2Q5LyN/FMz6pz X-Google-Smtp-Source: ABdhPJwugd/Yot3NacwjR7y/JV2uBnlBgfNLUSBKKMWCNNy/msTA+QPtRFK0ZmFAhnIT4pJeCnUYrQ== X-Received: by 2002:a17:90b:4b49:: with SMTP id mi9mr20470555pjb.219.1623636748399; Sun, 13 Jun 2021 19:12:28 -0700 (PDT) Received: from localhost.localdomain (h175-177-040-153.catv02.itscom.jp. [175.177.40.153]) by smtp.gmail.com with ESMTPSA id z14sm10952986pfn.11.2021.06.13.19.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Jun 2021 19:12:28 -0700 (PDT) From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Oscar Salvador , Michal Hocko , Ding Hui , Tony Luck , "Aneesh Kumar K.V" , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/6] mm/hwpoison: mf_mutex for soft offline and unpoison Date: Mon, 14 Jun 2021 11:12:07 +0900 Message-Id: <20210614021212.223326-2-nao.horiguchi@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614021212.223326-1-nao.horiguchi@gmail.com> References: <20210614021212.223326-1-nao.horiguchi@gmail.com> MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=Zg98D31y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of naohoriguchi@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=naohoriguchi@gmail.com X-Rspamd-Server: rspam02 X-Stat-Signature: gawxybeqkrfwpj6kpoc9d8b1t46jkmtx X-Rspamd-Queue-Id: 37786F2 X-HE-Tag: 1623636738-177416 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: From: Naoya Horiguchi Originally mf_mutex is introduced to serialize multiple MCE events, but it's also helpful to exclude races among soft_offline_page() and unpoison_memory(). So apply mf_mutex to them. Signed-off-by: Naoya Horiguchi --- mm/memory-failure.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git v5.13-rc5/mm/memory-failure.c v5.13-rc5_patched/mm/memory-failure.c index ae30fd6d575a..280eb6d6dd15 100644 --- v5.13-rc5/mm/memory-failure.c +++ v5.13-rc5_patched/mm/memory-failure.c @@ -1583,6 +1583,8 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, return rc; } +static DEFINE_MUTEX(mf_mutex); + /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -1609,7 +1611,6 @@ int memory_failure(unsigned long pfn, int flags) int res = 0; unsigned long page_flags; bool retry = true; - static DEFINE_MUTEX(mf_mutex); if (!sysctl_memory_failure_recovery) panic("Memory failure on page %lx", pfn); @@ -1918,6 +1919,7 @@ int unpoison_memory(unsigned long pfn) struct page *page; struct page *p; int freeit = 0; + int ret = 0; unsigned long flags = 0; static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); @@ -1928,28 +1930,30 @@ int unpoison_memory(unsigned long pfn) p = pfn_to_page(pfn); page = compound_head(p); + mutex_lock(&mf_mutex); + if (!PageHWPoison(p)) { unpoison_pr_info("Unpoison: Page was already unpoisoned %#lx\n", pfn, &unpoison_rs); - return 0; + goto unlock_mutex; } if (page_count(page) > 1) { unpoison_pr_info("Unpoison: Someone grabs the hwpoison page %#lx\n", pfn, &unpoison_rs); - return 0; + goto unlock_mutex; } if (page_mapped(page)) { unpoison_pr_info("Unpoison: Someone maps the hwpoison page %#lx\n", pfn, &unpoison_rs); - return 0; + goto unlock_mutex; } if (page_mapping(page)) { unpoison_pr_info("Unpoison: the hwpoison page has non-NULL mapping %#lx\n", pfn, &unpoison_rs); - return 0; + goto unlock_mutex; } /* @@ -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; } if (!get_hwpoison_page(p, flags)) { @@ -1968,7 +1972,7 @@ int unpoison_memory(unsigned long pfn) num_poisoned_pages_dec(); unpoison_pr_info("Unpoison: Software-unpoisoned free page %#lx\n", pfn, &unpoison_rs); - return 0; + goto unlock_mutex; } lock_page(page); @@ -1990,7 +1994,9 @@ int unpoison_memory(unsigned long pfn) if (freeit && !(pfn == my_zero_pfn(0) && page_count(p) == 1)) put_page(page); - return 0; +unlock_mutex: + mutex_unlock(&mf_mutex); + return ret; } EXPORT_SYMBOL(unpoison_memory); @@ -2171,6 +2177,8 @@ int soft_offline_page(unsigned long pfn, int flags) return -EIO; } + mutex_lock(&mf_mutex); + if (PageHWPoison(page)) { pr_info("%s: %#lx page already poisoned\n", __func__, pfn); put_ref_page(ref_page); @@ -2194,5 +2202,7 @@ int soft_offline_page(unsigned long pfn, int flags) __func__, pfn, page->flags, &page->flags); } + mutex_unlock(&mf_mutex); + return ret; }