Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5763573ybv; Tue, 18 Feb 2020 03:31:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyBrw2TDljJiNTpOWlHzeADfIYCSNU4ZisTNcQI1Yn/flragKXHZJA8NTdkh/kYYkuSNM9C X-Received: by 2002:a05:6808:4cc:: with SMTP id a12mr957882oie.115.1582025495832; Tue, 18 Feb 2020 03:31:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582025495; cv=none; d=google.com; s=arc-20160816; b=QMwG3DNL4T2w06IiolHc9fvlf/yI6JOIofykPRd4x5lteSV25lpFmUdMTnwFHZ04Ic JekAYdWsbjc67PRnNRrBr1tOPEUEbYtYe04fp1HcL/lY5ebvCNaQmBDtpoxmlVmUp2Zm ZCQg8dg+sADE/zEXNfaYNYEcucSFWFOhPGE4f6/mEpt4JrWS/yRPJ655EiOuZFMIITNm EsPrdoci8VfJRzAq/3R1I5vpIk8NNyTZDyc+q8vXqjbV8lwSfrML34Put8voF9u0hX50 IUf6+FXiZOc0Dal2Mn94AeWFGXphAi+tZ09nKMk91HhFYJloOM7BfRM4DSMS4ha7W05j 2LaA== 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; bh=ZnoR/TIx7fKj96R5zmBvT3nyCVKnUxPHKYaYVRB0FaU=; b=juHqAOSRKzBRXlK1Yw8xLHZuLhH86p2tHgEH9pAfPOp2mykWyJSTxAsxpyvkLq+zhS 49WyUNfQm9U1H+oj8rOFaKDNLrYgzrdn50nmlBoryhHSBTzzdAV/T/eV2C88v5drRJzW bvFI7O0oVpNK7q7d/7ZyEajltvB5W0T1lbzlDKMLvmq+26DKgRuYnN/Lg34P780tjvwU mdUhJeHV5csDjRgPGczyY+RkgDA1mE+fgyYZozA9vQmlpkC06+GsEA31UCyxScusecPl hH2rRrsBxC1Z3DPL7dcRaJLUGunwANq0y8krx3tEdFd+r3qMUdeEvvPoilkPEjYkKluL e4xQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x197si7381304oix.174.2020.02.18.03.31.24; Tue, 18 Feb 2020 03:31:35 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726477AbgBRLbI (ORCPT + 99 others); Tue, 18 Feb 2020 06:31:08 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40260 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgBRLbI (ORCPT ); Tue, 18 Feb 2020 06:31:08 -0500 Received: by mail-wr1-f65.google.com with SMTP id t3so23474438wru.7 for ; Tue, 18 Feb 2020 03:31:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZnoR/TIx7fKj96R5zmBvT3nyCVKnUxPHKYaYVRB0FaU=; b=tuAsaKpiH5UKtLepT9+DL63MHiEmUbjiP2P7isX25GVvOuxZBY8d3y0NJjwZoVstKI VDG/5UiQAOkrxQ0fckMk7xk0pdowr0lWSqF58sBWJhLMYu4VPJrz4KFtK7g2NiBITer7 0mloyJkLaRe6v6JqYAvPxmNxD44wSpJMZ3ujKQXBFa+R4fFLCkccnjHQ4zFAiHnRLFMd XNfHJ5HBr3rxZ7YS3Mipq/Ic1fdoBTUYTsH6/CDMNrRK0dF4FPbufC+ODJDWpoMngVhw xRvq6wU8ZV43/tB1GCUQovyLCH8vb5F7+Ys19MLklL33C1PTJNSTZpRNVSvLO9tpwIUE nCfQ== X-Gm-Message-State: APjAAAULrz5PjVUXWYi02rAxNvGzsCZQA160vafvT0+XUlOr0uz+e3wV aRanoHsPCAy8GPBLNgP80Tk= X-Received: by 2002:adf:f401:: with SMTP id g1mr27996186wro.129.1582025464604; Tue, 18 Feb 2020 03:31:04 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id b18sm5697555wru.50.2020.02.18.03.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 03:31:03 -0800 (PST) Date: Tue, 18 Feb 2020 12:31:03 +0100 From: Michal Hocko To: Andrea Arcangeli Cc: Will Deacon , Catalin Marinas , Jon Masters , Rafael Aquini , Mark Salter , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 1/2] mm: use_mm: fix for arches checking mm_users to optimize TLB flushes Message-ID: <20200218113103.GB4151@dhcp22.suse.cz> References: <20200203201745.29986-1-aarcange@redhat.com> <20200203201745.29986-2-aarcange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200203201745.29986-2-aarcange@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 03-02-20 15:17:44, 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. I would prefer we do not do that because then the real owner of the mm cannot really tear down the address space and the life time of it is bound to a kernel thread doing the use_mm. This is undesirable I would really prefer if the existing few users would use mmget only when they really need to access mm. > 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); > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel -- Michal Hocko SUSE Labs