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=-8.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 158ECC4338F for ; Sat, 14 Aug 2021 03:12:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E90E60F39 for ; Sat, 14 Aug 2021 03:12:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7E90E60F39 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 186928D0001; Fri, 13 Aug 2021 23:12:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 137176B0071; Fri, 13 Aug 2021 23:12:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 025A38D0001; Fri, 13 Aug 2021 23:12:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id D99C86B006C for ; Fri, 13 Aug 2021 23:12:42 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 81A7F182A5ECD for ; Sat, 14 Aug 2021 03:12:42 +0000 (UTC) X-FDA: 78472213764.08.0C9193E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 3EF27B0001BD for ; Sat, 14 Aug 2021 03:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=a2w/FFTPHRKMwNNPXutLDjmT0K32wSU3qKEjze61mV8=; b=R2OEwz1ihwtpPeXS5Zu32Pvzs3 iD8oe9SduQLSYLLsKBrx6iNif6LKs6YjiCB6IYpaAiKMEeZQV+JypyaAosQw4ROUNufrhp89Z35z2 7nEnRcbGMOv5bXu+EAoxk/rDrule0a/W63XMG1B6+5j5FYzYykNgqMuziV3AWNxlvUP6V2UYXxgKX Wy7VrXMy193+xsmLMBgWg5oP3ZFkXhg3WtVA7TCxxK8LaQ+tSr/gaytOjaBJjBfzeekIG5TdO7yBu WJ/wLfTvdOruGlUu64YP5GEjZGKUoREEwLYmLZpZEysqZZrX+8GP7GBoi8s4BRiAnq9X+PyLOeYH7 pY+D27YA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mEk5S-00GL5o-Bn; Sat, 14 Aug 2021 03:11:59 +0000 Date: Sat, 14 Aug 2021 04:11:54 +0100 From: Matthew Wilcox To: Muchun Song Cc: yanghui , Andrew Morton , Linux Memory Management List Subject: Re: [PATCH] mm/mempolicy: fix a race between offset_il_node and mpol_rebind_task Message-ID: References: <20210813164053.51481-1-yanghui.def@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 3EF27B0001BD Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=R2OEwz1i; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Stat-Signature: 311ycddnzgzummuk6ckqh5wbt5fu8cjk X-HE-Tag: 1628910762-800983 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 Sat, Aug 14, 2021 at 10:37:23AM +0800, Muchun Song wrote: > On Sat, Aug 14, 2021 at 12:58 AM Matthew Wilcox wrote: > > > > On Sat, Aug 14, 2021 at 12:40:53AM +0800, yanghui wrote: > > > +++ b/mm/mempolicy.c > > > @@ -193,7 +193,7 @@ static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes) > > > { > > > if (nodes_empty(*nodes)) > > > return -EINVAL; > > > - pol->nodes = *nodes; > > > + WRITE_ONCE(pol->nodes, *nodes); > > > > typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; > > > > If MAX_NUMNODES is large enough, is WRITE_ONCE going to work? It could > > be 128 bits, and few architectures have an atomic 128-bit store > > instruction. > > > > Hi Matthew, > > In my memory, the WRITE_ONCE will become memcpy if > the size is greater than sizeof(long). But I found that it didn't > support the size over sizeof(long) nowadays. So you are > right. It doesn't work when MAX_NUMNODES is large enough. > > If we don't use WRITE_ONCE/READ_ONCE here, it seems > like no problem. At least we can sure offset_il_node returns > a valid node id. What is your opinion about this fix? Yes, I think that's a reasonable fix. Include a comment about how copying pol->nodes to the stack might race with a change to pol->nodes, but that doesn't matter as long as we don't look at pol->nodes later?