Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp927566pxb; Mon, 25 Oct 2021 22:41:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPgtSDU6xBPEd0ytqCry8QKE9MAgW7sqJaSCF4hQH/XIC3QXql7JAfsa5GgNnKmfODMiEx X-Received: by 2002:a17:902:e741:b0:140:9a0b:1918 with SMTP id p1-20020a170902e74100b001409a0b1918mr5156293plf.72.1635226901750; Mon, 25 Oct 2021 22:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635226901; cv=none; d=google.com; s=arc-20160816; b=YhlKiE3gIZuLi8easx6YQ08NPQq4xukcBFaIEbm73ib3XIADYxeepy/Rkd/PxGvzAs jHPXNCT7FPiBbIL8ovs6MwWD0EAmIDFWcPacH6153tnIrJboXryvaZmbFcc8exVW5Bjr A1UvAsc79/KkRCZWZHWOLOdyJPbbmIZ36t2C62SUi8zwSYAYfiKyEkFqC9mubQZAR6qU o/eV4343XP0gHgjHQVTrpxXJrIIAomvtOJ/N8zRkpgl1341+E45XEVYQ3j5bCscc1Glk HwT7GfzxCQQA3IZkou+MquhcPokrnnJ3eNqZ73Md9Te8vtjMawPOOtS/dXxoPQF4H+k2 vLWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RR7imi14Z6SUKcAiAGApew2NGLLdTeu4YcmU7ch/wOs=; b=evKg1Cx0llJV1Nxt6R072S/CNb2payVo4Irm/7jCvWgElV8b7zgYmO2yQhgO13CLPi HrIzXMIfYI6kEp+/IEXx13YG7mcQz1k0XNHNYWCbu+iI2K3WT7O9Sq98GCTd1FcKRwsT oFqKyfDC85KcEjZIHl+StHtjwezGyvzdgWtz5P00vO0gH87VkfdZiqizkGo5F0j23AVB boC4fSixs0ohJgYof8MnP+d3ZomUx9OcbvxQWAwAQpZ9w7hMbquu0iRXUwGuFaIKeuYQ 55kiaLyokAdlPz3maWZqMq+Gb+brCsamneCwnNK9a1upugccIXfmu+vYl3Xcmtb0Woma soKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JSZSt4rE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si5977203pfc.67.2021.10.25.22.41.17; Mon, 25 Oct 2021 22:41:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=JSZSt4rE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235112AbhJYXJE (ORCPT + 99 others); Mon, 25 Oct 2021 19:09:04 -0400 Received: from out1.migadu.com ([91.121.223.63]:29448 "EHLO out1.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235109AbhJYXIx (ORCPT ); Mon, 25 Oct 2021 19:08:53 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1635203189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RR7imi14Z6SUKcAiAGApew2NGLLdTeu4YcmU7ch/wOs=; b=JSZSt4rEezuk5+bDKBhgCteVmui5+uPUamj0ljbeldA6sgTX2nqdcD3aOpqO9LxJvKTHde Eg0dz1OiBSx238wJ5lpjtX5FvYgLx5DYVQBv9GD7+8uFLXzpVZb8xOg+wNXGKc/td+1//i 23tAvpVQbVcL/5PXtU4a9rGzSCFzG3I= 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" , Miaohe Lin , Yang Shi , Peter Xu , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] mm/hwpoison: mf_mutex for soft offline and unpoison Date: Tue, 26 Oct 2021 08:05:00 +0900 Message-Id: <20211025230503.2650970-2-naoya.horiguchi@linux.dev> In-Reply-To: <20211025230503.2650970-1-naoya.horiguchi@linux.dev> References: <20211025230503.2650970-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: naoya.horiguchi@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- ChangeLog v2: - add mutex_unlock() in "page already poisoned" path in soft_offline_page(). (Thanks to Ding Hui) --- mm/memory-failure.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index fa9dda95a2a2..97297edfbd8e 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1628,6 +1628,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 @@ -1654,7 +1656,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); @@ -1978,6 +1979,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); @@ -1988,28 +1990,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; } /* @@ -2020,7 +2024,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)) { @@ -2028,7 +2032,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); @@ -2050,7 +2054,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); @@ -2231,9 +2237,12 @@ 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); + mutex_unlock(&mf_mutex); return 0; } @@ -2251,5 +2260,7 @@ int soft_offline_page(unsigned long pfn, int flags) } } + mutex_unlock(&mf_mutex); + return ret; } -- 2.25.1