From patchwork Sun Feb 23 19:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Arcangeli X-Patchwork-Id: 11399005 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 127E492A for ; Sun, 23 Feb 2020 19:25:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D216020656 for ; Sun, 23 Feb 2020 19:25:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KWIm41Dr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D216020656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8A2DF6B0007; Sun, 23 Feb 2020 14:25:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 82DD86B0008; Sun, 23 Feb 2020 14:25:33 -0500 (EST) 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 6CA7F6B000A; Sun, 23 Feb 2020 14:25:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 5541A6B0007 for ; Sun, 23 Feb 2020 14:25:33 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 13A73824556B for ; Sun, 23 Feb 2020 19:25:33 +0000 (UTC) X-FDA: 76522370946.05.cub46_87bc0c9061f3e X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,aarcange@redhat.com,,RULES_HIT:30026:30054:30070,0,RBL:207.211.31.120:@redhat.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: cub46_87bc0c9061f3e X-Filterd-Recvd-Size: 3730 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Sun, 23 Feb 2020 19:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582485932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WdAkDw0jQFrUByye8xgaI8zjWL8waIYULZhRupYTANc=; b=KWIm41Dr4PCgJ8lKtHQdx2eGcYTMTuK5CBWtUya2fOCR42OTJVGpDnELB6YqjxS+kIjf6l dHQWxDQWQe/bwnCu26HRTaGGcvB+50zbbB1FgNT/aF/0cp+VoYfU7Gbx+o9tPJaSdK4DU4 Is45a8tXCbrgR03caurIFcznAhZXWA0= 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-383-2r8xQ-VeOtOrXPcYfZce8A-1; Sun, 23 Feb 2020 14:25:26 -0500 X-MC-Unique: 2r8xQ-VeOtOrXPcYfZce8A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F1BF107ACC5; Sun, 23 Feb 2020 19:25:24 +0000 (UTC) Received: from mail (ovpn-120-118.rdu2.redhat.com [10.10.120.118]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C33A5C1B2; Sun, 23 Feb 2020 19:25:21 +0000 (UTC) From: Andrea Arcangeli To: Will Deacon , Catalin Marinas , Rafael Aquini , Mark Salter Cc: Jon Masters , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Michal Hocko , QI Fuli Subject: [PATCH 1/3] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes Date: Sun, 23 Feb 2020 14:25:18 -0500 Message-Id: <20200223192520.20808-2-aarcange@redhat.com> In-Reply-To: <20200223192520.20808-1-aarcange@redhat.com> References: <20200223192520.20808-1-aarcange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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: 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 Acked-by: Rafael Aquini --- 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);