Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2990487ybf; Mon, 2 Mar 2020 20:28:58 -0800 (PST) X-Google-Smtp-Source: ADFU+vud5QhoSLs6yd/e3kMiKM5gD7croCqxj0LLUOfz6Wfp1Wk7JmWzjmniduugUHxExt/MuFGU X-Received: by 2002:aca:1204:: with SMTP id 4mr1251329ois.143.1583209738209; Mon, 02 Mar 2020 20:28:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583209738; cv=none; d=google.com; s=arc-20160816; b=bEb7w8473GzkwpY1x+3wqJptEVv63+KgLV53x+z4IWLGvHS1QAtXX6orwZTVFxfDtD zmpcXtU/2u70uyJ3TBOOnsoTcflR9SqKLb/0PApfuolI9r7xM031gmoJrlNdE1UOUlpz iEAwM2ilgjaKS1O9FNzxZPWSERGiFGpnMN/eoMyHKq18bpD44gNcxgyJrSvDjy1HTCoM GgHs0ntBE2RujDQjotYBdxyGEdcc6R0hCJE0od39McXqTEYI0Lg0kE/wphe+/Ml06nTD jnjDMKFncekDwMKJyy/2pwSFSOZXsoG+Qu3UlBSzztCzhPGIcFnGNLRRh1In5sea7emx N08w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GDMIPd7v29HF3qLCK2yjuGYjUXKITzcTwLkju8pHxl0=; b=ilTc6vgMU4cjTm8M0zEeUag7X4vYywUc3HUi6IjvLLxcesV1I7/MJvpGiCbsbncZza Q8ogVRhc1yCXUcoGe1PuzpmNahRl8o+U2hcwgf71A5rfL6vO8Ck35kTvn31AcLOEXm5v 6y7yrEc7mDIFcQdTBCI7AXgw5rtDskkLOZ04u57JdRy70k/JqEA+ycBMcZlzlOTnIRjL dEP2qXTjprQk6zYOXRIccunw8VEFKTamQHKyRkWVHgryZh0QvTbyzRNd1jnFZv8vEvE0 U1m0i4zcakRPXCfX8JQ3ZHJhKsF92c374C5QhtCsiuELwMmXZtr1p6AIsuraF5t21h2s UYRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WsZixNvW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si7142363oti.311.2020.03.02.20.28.45; Mon, 02 Mar 2020 20:28:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WsZixNvW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbgCCE2P (ORCPT + 99 others); Mon, 2 Mar 2020 23:28:15 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:50841 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726942AbgCCE2P (ORCPT ); Mon, 2 Mar 2020 23:28:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583209693; h=from:from:reply-to:subject:subject: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=GDMIPd7v29HF3qLCK2yjuGYjUXKITzcTwLkju8pHxl0=; b=WsZixNvWQsrgG7G/9vOGXdWXeIqXuasGYdIJCu/S9qeaueLi22yfHCiBNGawRQCCp52aSt KOp4L6ytwhg/Pazi/Duh8hgTW5KunfMrknfsFvW81Yvl58kyQasTxPic91u0tSnCoAjowu l/I8LXNbwOiqepjt8v1L55P3suWg3wM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-185-BfzygFwcMtmV8FItHabr5g-1; Mon, 02 Mar 2020 23:28:09 -0500 X-MC-Unique: BfzygFwcMtmV8FItHabr5g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 317098017CC; Tue, 3 Mar 2020 04:28:08 +0000 (UTC) Received: from t490s (ovpn-116-88.phx2.redhat.com [10.3.116.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9CB68D568; Tue, 3 Mar 2020 04:28:06 +0000 (UTC) Date: Mon, 2 Mar 2020 23:28:04 -0500 From: Rafael Aquini To: Andrea Arcangeli Cc: Will Deacon , Catalin Marinas , Mark Salter , Jon Masters , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Michal Hocko , QI Fuli Subject: Re: [PATCH 1/3] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes Message-ID: <20200303042804.GA94763@t490s> References: <20200223192520.20808-1-aarcange@redhat.com> <20200223192520.20808-2-aarcange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200223192520.20808-2-aarcange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 23, 2020 at 02:25:18PM -0500, Andrea Arcangeli wrote: > alpha, ia64, mips, powerpc, sh, sparc are relying on a check on > mm->mm_users to know if they can skip some remote TLB flushes for > single threaded processes. > > Most callers of use_mm() tend to invoke mmget_not_zero() or > get_task_mm() before use_mm() to ensure the mm will remain alive in > between use_mm() and unuse_mm(). > > Some callers however don't increase mm_users and they instead rely on > serialization in __mmput() to ensure the mm will remain alive in > between use_mm() and unuse_mm(). Not increasing mm_users during > use_mm() is however unsafe for aforementioned arch TLB flushes > optimizations. So either mmget()/mmput() should be added to the > problematic callers of use_mm()/unuse_mm() or we can embed them in > use_mm()/unuse_mm() which is more robust. > > Signed-off-by: Andrea Arcangeli > --- > mm/mmu_context.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/mmu_context.c b/mm/mmu_context.c > index 3e612ae748e9..ced0e1218c0f 100644 > --- a/mm/mmu_context.c > +++ b/mm/mmu_context.c > @@ -30,6 +30,7 @@ void use_mm(struct mm_struct *mm) > mmgrab(mm); > tsk->active_mm = mm; > } > + mmget(mm); > tsk->mm = mm; > switch_mm(active_mm, mm, tsk); > task_unlock(tsk); > @@ -57,6 +58,7 @@ void unuse_mm(struct mm_struct *mm) > task_lock(tsk); > sync_mm_rss(mm); > tsk->mm = NULL; > + mmput(mm); > /* active_mm is still 'mm' */ > enter_lazy_tlb(mm, tsk); > task_unlock(tsk); Acked-by: Rafael Aquini