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=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 A1393C4727D for ; Thu, 24 Sep 2020 15:01:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 10F66206B2 for ; Thu, 24 Sep 2020 15:01:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="NySRi5tb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10F66206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 263558E0003; Thu, 24 Sep 2020 11:01:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ECCB8E0001; Thu, 24 Sep 2020 11:01:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DD0C8E0003; Thu, 24 Sep 2020 11:01:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id DCD368E0001 for ; Thu, 24 Sep 2020 11:01:09 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9260F3641 for ; Thu, 24 Sep 2020 15:01:09 +0000 (UTC) X-FDA: 77298267858.07.door23_1b09b3b2715f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 568C71803F9B0 for ; Thu, 24 Sep 2020 15:01:09 +0000 (UTC) X-HE-Tag: door23_1b09b3b2715f X-Filterd-Recvd-Size: 6944 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 15:01:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id D6DBC2D53CC; Thu, 24 Sep 2020 11:01:07 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id nLOEPWIbPagi; Thu, 24 Sep 2020 11:01:07 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 5AD222D53CB; Thu, 24 Sep 2020 11:01:07 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 5AD222D53CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1600959667; bh=5ZRlq7ZuFCz2+2F8HW2zumswqp4iesEAF1uFv08MBW0=; h=Date:From:To:Message-ID:MIME-Version; b=NySRi5tbajQBlNy0v5RnJ6MH+iIXlAzVsRG9pI4iILSI4opmstXoRz+8htcydO9PV 5RCE0VQnRWbDphklCX0vZFvjiqAgjrcChGZVzITFwYDxSK67Wdw7V+0ZSPpvrZZPya ZjjZsMJE91xqRyTTjFJeXBWWl7HrG7A73gTADrm8w1ne8g9v2vecfm8BJuD9D+Fn1o 6MjTvS4jdXqe0SkVdA2JPqfCOpRucX7TIUm3eBPmWZFue2UcTkrOgLz+OO4KNdUrr/ D0rXFq0tf7gpjd1NwglFspUtBXBtpmVJ7rYHCtrKELZF0NNAcM04UddWx505G1I3JX NRSb8cn/bpjLw== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1l0-rTxCWbJ9; Thu, 24 Sep 2020 11:01:07 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 4B2BD2D5175; Thu, 24 Sep 2020 11:01:07 -0400 (EDT) Date: Thu, 24 Sep 2020 11:01:07 -0400 (EDT) From: Mathieu Desnoyers To: Boqun Feng Cc: Peter Zijlstra , linux-kernel , Will Deacon , paulmck , Andy Lutomirski , Andrew Morton , Alan Stern , Nicholas Piggin , Thomas Gleixner , Linus Torvalds , linux-mm Message-ID: <1511468187.68016.1600959667218.JavaMail.zimbra@efficios.com> In-Reply-To: <20200816152330.GA87259@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net> References: <20200814164358.4783-1-mathieu.desnoyers@efficios.com> <20200814164358.4783-2-mathieu.desnoyers@efficios.com> <20200816152330.GA87259@debian-boqun.qqnc3lrjykvubdpftowmye0fmh.lx.internal.cloudapp.net> Subject: Re: [RFC PATCH 1/3] sched: fix exit_mm vs membarrier (v2) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3965 (ZimbraWebClient - FF80 (Linux)/8.8.15_GA_3963) Thread-Topic: sched: fix exit_mm vs membarrier (v2) Thread-Index: 9mxzdZP9+5HX7oIp3aImuECyfGJLug== 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 Aug 16, 2020, at 11:23 AM, Boqun Feng boqun.feng@gmail.com wrote: > Hi Mathieu, > > On Fri, Aug 14, 2020 at 12:43:56PM -0400, Mathieu Desnoyers wrote: >> exit_mm should issue memory barriers after user-space memory accesses, >> before clearing current->mm, to order user-space memory accesses >> performed prior to exit_mm before clearing tsk->mm, which has the >> effect of skipping the membarrier private expedited IPIs. >> >> The membarrier system call can be issued concurrently with do_exit >> if we have thread groups created with CLONE_VM but not CLONE_THREAD. >> >> Here is the scenario I have in mind: >> >> Two thread groups are created, A and B. Thread group B is created by >> issuing clone from group A with flag CLONE_VM set, but not CLONE_THREAD. >> Let's assume we have a single thread within each thread group (Thread A >> and Thread B). >> >> The AFAIU we can have: >> >> Userspace variables: >> >> int x = 0, y = 0; >> >> CPU 0 CPU 1 >> Thread A Thread B >> (in thread group A) (in thread group B) >> >> x = 1 >> barrier() >> y = 1 >> exit() >> exit_mm() >> current->mm = NULL; >> r1 = load y >> membarrier() >> skips CPU 0 (no IPI) because its current mm is NULL >> r2 = load x >> BUG_ON(r1 == 1 && r2 == 0) >> >> Signed-off-by: Mathieu Desnoyers >> Cc: Peter Zijlstra (Intel) >> Cc: Will Deacon >> Cc: Paul E. McKenney >> Cc: Nicholas Piggin >> Cc: Andy Lutomirski >> Cc: Thomas Gleixner >> Cc: Linus Torvalds >> Cc: Alan Stern >> Cc: linux-mm@kvack.org >> --- >> Changes since v1: >> - Use smp_mb__after_spinlock rather than smp_mb. >> - Document race scenario in commit message. >> --- >> kernel/exit.c | 8 ++++++++ >> 1 file changed, 8 insertions(+) >> >> diff --git a/kernel/exit.c b/kernel/exit.c >> index 733e80f334e7..fe64e6e28dd5 100644 >> --- a/kernel/exit.c >> +++ b/kernel/exit.c >> @@ -475,6 +475,14 @@ static void exit_mm(void) >> BUG_ON(mm != current->active_mm); >> /* more a memory barrier than a real lock */ >> task_lock(current); >> + /* >> + * When a thread stops operating on an address space, the loop >> + * in membarrier_{private,global}_expedited() may not observe > > Is it accurate to say that the correctness of > membarrier_global_expedited() relies on the observation of ->mm? Because > IIUC membarrier_global_expedited() loop doesn't check ->mm. Good point, I was wrong. Will instead reword as: /* * When a thread stops operating on an address space, the loop * in membarrier_private_expedited() may not observe that * tsk->mm, and the loop in membarrier_global_expedited() may * not observe a MEMBARRIER_STATE_GLOBAL_EXPEDITED * rq->membarrier_state, so those would not issue an IPI. * Membarrier requires a memory barrier after accessing * user-space memory, before clearing tsk->mm or the * rq->membarrier_state. */ And I'll make sure exit_mm clears this_rq()->membarrier_state as well. Thanks, Mathieu > > Regards, > Boqun > >> + * that tsk->mm, and not issue an IPI. Membarrier requires a >> + * memory barrier after accessing user-space memory, before >> + * clearing tsk->mm. >> + */ >> + smp_mb__after_spinlock(); >> current->mm = NULL; >> mmap_read_unlock(mm); >> enter_lazy_tlb(mm, current); >> -- >> 2.11.0 -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com