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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77406C19F2D for ; Tue, 9 Aug 2022 12:11:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C88546B0071; Tue, 9 Aug 2022 08:11:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C373A6B0072; Tue, 9 Aug 2022 08:11:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFF2D8E0001; Tue, 9 Aug 2022 08:11:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9EEF16B0071 for ; Tue, 9 Aug 2022 08:11:21 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 72613140E3F for ; Tue, 9 Aug 2022 12:11:21 +0000 (UTC) X-FDA: 79779939162.04.95D0788 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf28.hostedemail.com (Postfix) with ESMTP id E4D5EC0150 for ; Tue, 9 Aug 2022 12:11:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 76B88372E8; Tue, 9 Aug 2022 12:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1660047079; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GdLGC6Kobyq/QbsvrksoB2ni8bDhZJiYGP6/6oP2jRQ=; b=XbFdEHUgjUG1UdhOc51XSeqtw68PS/r/XBzf9iF1XAE+1lXl/FmpyB+AN+//1moKp8azt6 YKQYacRdGmlaAWKO3GyJ3/HeshUxsKULHC8gJLJNdvnDAP+3xQWDU4BUFuJoeMzVlhqUCm Y6vSIyjzvflNUyGolTOSLz6IRa36Ncs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5881013A9D; Tue, 9 Aug 2022 12:11:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6940E+dO8mJOCQAAMHmgww (envelope-from ); Tue, 09 Aug 2022 12:11:19 +0000 Date: Tue, 9 Aug 2022 14:11:18 +0200 From: Michal Hocko To: Abel Wu Cc: Andrew Morton , Vlastimil Babka , Mel Gorman , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/mempolicy: fix lock contention on mems_allowed Message-ID: References: <20220809104927.44366-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220809104927.44366-1-wuyun.abel@bytedance.com> ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=XbFdEHUg; spf=pass (imf28.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660047081; a=rsa-sha256; cv=none; b=peIVuwqPYbRAD1Rqd9S/hNiWyF+LvydrQE48dFgoG+xwfQ7sJ5iKYZ4reh8dEUYpktlCDG OF7eB9497wODfIiYn22Ew8EQC7lgdmz+UPv6NHl8pztV+A33a446LOvdvyitl+9hJdjezg 0T0alyuuLrYuNDCXP1jOkFqKaaO7DWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660047081; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GdLGC6Kobyq/QbsvrksoB2ni8bDhZJiYGP6/6oP2jRQ=; b=drqKi1Y0Pa7wRyc6tSyzvJpguZ3B318mh1PlFGiO4ZoBZOHqeeXIKJ1Wyb6MrdpKWjNRi/ D7mQ0Ood7Z2ncRqyqKmI6h65Mzk5lQhHtgDtFDSheQBIbJzz6PKq8B4ET7xdUq2HM1/Msj UBL5Nup9/FbrlOSKQv9VcmAyb4xA9RQ= X-Stat-Signature: 38ptw4hwd36jp3fu75hwthx17x8gb8js X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E4D5EC0150 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=XbFdEHUg; spf=pass (imf28.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-HE-Tag: 1660047080-78132 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 Tue 09-08-22 18:49:27, Abel Wu wrote: > The mems_allowed field can be modified by other tasks, so it > isn't safe to access it with alloc_lock unlocked even in the > current process context. It would be useful to describe the racing scenario and the effect it would have. 78b132e9bae9 hasn't really explained thinking behind and why it was considered safe to drop the lock. I assume it was based on the fact that the operation happens on the current task but this is hard to tell. > Fixes: 78b132e9bae9 ("mm/mempolicy: remove or narrow the lock on current") > Signed-off-by: Abel Wu > --- > mm/mempolicy.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/mm/mempolicy.c b/mm/mempolicy.c > index d39b01fd52fe..ae422e44affb 100644 > --- a/mm/mempolicy.c > +++ b/mm/mempolicy.c > @@ -855,12 +855,14 @@ static long do_set_mempolicy(unsigned short mode, unsigned short flags, > goto out; > } > > + task_lock(current); > ret = mpol_set_nodemask(new, nodes, scratch); > if (ret) { > + task_unlock(current); > mpol_put(new); > goto out; > } > - task_lock(current); > + > old = current->mempolicy; > current->mempolicy = new; > if (new && new->mode == MPOL_INTERLEAVE) > @@ -1295,7 +1297,9 @@ static long do_mbind(unsigned long start, unsigned long len, > NODEMASK_SCRATCH(scratch); > if (scratch) { > mmap_write_lock(mm); > + task_lock(current); > err = mpol_set_nodemask(new, nmask, scratch); > + task_unlock(current); > if (err) > mmap_write_unlock(mm); > } else > -- > 2.31.1 -- Michal Hocko SUSE Labs