From patchwork Fri Aug 14 16:43:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 11714803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60BBB739 for ; Fri, 14 Aug 2020 16:44:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D8C320838 for ; Fri, 14 Aug 2020 16:44:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="R1hiTHwf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D8C320838 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 2C99B6B0006; Fri, 14 Aug 2020 12:44:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 279CE6B0007; Fri, 14 Aug 2020 12:44:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 168636B0008; Fri, 14 Aug 2020 12:44:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id F283E6B0006 for ; Fri, 14 Aug 2020 12:44:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A687821F0 for ; Fri, 14 Aug 2020 16:44:06 +0000 (UTC) X-FDA: 77149746492.02.jeans09_231826026ffe Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 7147910074C37 for ; Fri, 14 Aug 2020 16:44:06 +0000 (UTC) X-Spam-Summary: 1,0,0,107e261117c5eb55,d41d8cd98f00b204,mathieu.desnoyers@efficios.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1261:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:1801:2198:2199:2393:2553:2559:2562:2693:2731:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3874:4250:4321:4605:5007:6120:6261:6653:6742:7514:7875:7901:7903:7904:8660:8957:9121:10004:11026:11232:11233:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13095:13148:13161:13169:13229:13230:13846:14096:14181:14664:14721:14877:21080:21250:21433:21451:21627:21795:21939:30003:30054:30055:30090,0,RBL:167.114.26.124:@efficios.com:.lbl8.mailshell.net-62.14.55.100 64.201.201.201;04y8cud8s3ugbsbjad4ni73wkqnbmychodi93t5tnhekxwkmj4m7h7ru1wofctu.tbc1ximiokb9zzjxe98p1638o6kch3har733yq9yh8o453exfug3759texjq9ci.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:33,LU A_SUMMAR X-HE-Tag: jeans09_231826026ffe X-Filterd-Recvd-Size: 5125 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Fri, 14 Aug 2020 16:44:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 69835298CCF; Fri, 14 Aug 2020 12:44:05 -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 m8xIlR6s5KER; Fri, 14 Aug 2020 12:44:05 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2BA7D298F08; Fri, 14 Aug 2020 12:44:05 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 2BA7D298F08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1597423445; bh=gWMfYz3pTPNPAFbvbx6cVT/WalgvXWmMXDyplE97vOU=; h=From:To:Date:Message-Id; b=R1hiTHwfeuCsuFYTexf4jJWTC+bhRFma3Qsx1ilOigYhmOOklty9mBnqtOq1c8H5T iuRUc4aEU1bFCB4sNuHzwpKyuQEXUyTjiQHE4Psmukka0rQ7kcf3+kJ2AI5LPMOoRL Hd0DVRB68ErLtai2I818A5SkWLB5qmB0T3Xu4TaTplTHlywhmWKy2oCvCiKfLJ58Jm KbX5O/FVToG8HbP0KVBxf4mZWei1fOcd7KuFLzj4tWw1+PrzYiZ30qFy1QJV1RcdSR BwbdTWMBlpgnqJFHg+6fcmEN2dcUrmVKk/2Hg3D/7PZvaXnM5oY47e3uB9yvsVslcP yIv2KbKvQP5ug== 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 cLUW4hHJ8BLb; Fri, 14 Aug 2020 12:44:05 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by mail.efficios.com (Postfix) with ESMTPSA id E2935298E3B; Fri, 14 Aug 2020 12:44:04 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Will Deacon , "Paul E . McKenney" , Andy Lutomirski , Andrew Morton , Alan Stern , Nicholas Piggin , Mathieu Desnoyers , Thomas Gleixner , Linus Torvalds , linux-mm@kvack.org Subject: [RFC PATCH 1/3] sched: fix exit_mm vs membarrier (v2) Date: Fri, 14 Aug 2020 12:43:56 -0400 Message-Id: <20200814164358.4783-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200814164358.4783-1-mathieu.desnoyers@efficios.com> References: <20200814164358.4783-1-mathieu.desnoyers@efficios.com> X-Rspamd-Queue-Id: 7147910074C37 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: 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 + * 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);