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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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 873F8C2B9F2 for ; Sat, 22 May 2021 22:09:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFFAB61183 for ; Sat, 22 May 2021 22:09:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFFAB61183 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6B49A6B0138; Sat, 22 May 2021 18:09:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 663736B0139; Sat, 22 May 2021 18:09:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52B736B013A; Sat, 22 May 2021 18:09:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 226E56B0138 for ; Sat, 22 May 2021 18:09:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A991C181AEF2A for ; Sat, 22 May 2021 22:09:02 +0000 (UTC) X-FDA: 78170258124.20.8CA387F Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP id 930C340B8CFF for ; Sat, 22 May 2021 22:08:58 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id BA2A661182; Sat, 22 May 2021 22:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1621721341; bh=fQ0aMPh12hl+5c7WBOSl31XItRi0ATmMKJSFriH63vw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=wOkXc1V/JbPb5GHrwUa9gxLporsN9D101phMZvDCVmuEtJ7Zh/TA2TcRzzdfyK1n4 9+6FMbLyjX5EUIGa2Fip8UkowFZE+y5P7L8kpIyCE2qkUMtYu3z5ZGh21mffn0Vu6n TfmrafZ6jBwSPw0npvfmELrgDPUXGuU2TNjvwujc= Date: Sat, 22 May 2021 15:09:00 -0700 From: Andrew Morton To: Naoya Horiguchi Cc: linux-mm@kvack.org, Tony Luck , Aili Yao , Oscar Salvador , David Hildenbrand , Borislav Petkov , Andy Lutomirski , Naoya Horiguchi , Jue Wang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/3] mm/memory-failure: Use a mutex to avoid memory_failure() races Message-Id: <20210522150900.39d6832a03c5f772911c5b6d@linux-foundation.org> In-Reply-To: <20210521030156.2612074-2-nao.horiguchi@gmail.com> References: <20210521030156.2612074-1-nao.horiguchi@gmail.com> <20210521030156.2612074-2-nao.horiguchi@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 930C340B8CFF Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="wOkXc1V/"; dmarc=none; spf=pass (imf10.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam03 X-Stat-Signature: w6ofwtxp8esou4mqzmgdamsmeqxtz9px X-HE-Tag: 1621721338-331888 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 Fri, 21 May 2021 12:01:54 +0900 Naoya Horiguchi wrote: > There can be races when multiple CPUs consume poison from the same > page. The first into memory_failure() atomically sets the HWPoison > page flag and begins hunting for tasks that map this page. Eventually > it invalidates those mappings and may send a SIGBUS to the affected > tasks. > > But while all that work is going on, other CPUs see a "success" > return code from memory_failure() and so they believe the error > has been handled and continue executing. > > Fix by wrapping most of the internal parts of memory_failure() in > a mutex. We can reduce the scope of that mutex, which helps readability at least. --- a/mm/memory-failure.c~mm-memory-failure-use-a-mutex-to-avoid-memory_failure-races-fix +++ a/mm/memory-failure.c @@ -1397,8 +1397,6 @@ out: return rc; } -static DEFINE_MUTEX(mf_mutex); - /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -1425,6 +1423,7 @@ int memory_failure(unsigned long pfn, in 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); _