Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7270838rdb; Wed, 3 Jan 2024 09:58:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGqLWrvQEkPi5arMvDV0TcJrezWTfbDM+LQYS+bVDUTBJsQBbIdxBIakYru1EROeC7Xd8f X-Received: by 2002:a05:6a21:a5a3:b0:197:8e11:f55c with SMTP id gd35-20020a056a21a5a300b001978e11f55cmr1008718pzc.52.1704304688380; Wed, 03 Jan 2024 09:58:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704304688; cv=none; d=google.com; s=arc-20160816; b=dgLeajamgr+aDo7hXavePRhhD41scShf4qsObCS4XtvAYPr/eiah18XvSXLotk4t8U 9yDTn8VqnemgKeBkuIXJVFrHPmmnAcLQjs5lUFDYUp7uWTqkkLIXaJ+yGnhKU0TpNKJ5 lt2JgV1Gq8i0t+4GTTpPIrQmKcg4yPABd11jJ4GMRTvZN+lzMni41McCE+aem4DjiKg0 LuSTWK1BI1r0hMVCZ7Edfb/RcDX+gbsXMEupyBy4kMEg7bydm0iNYWj2JtIPS3CEUHX7 sqYY+twSOViV/OMxP/Tp2cbsj75KwqJBYHKb5L+FksR8sb4nHRf5Ct5rv0DiWBo+/Agx O7wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=hYNafHUEYV8G4T/aZ3ZKHOLVBpUFqEhKl2Z5XvnZASY=; fh=YxzPfiqeAIB6E5+Bhk3gaNpwZGCtx/yxZqEqIMDGNOk=; b=zukhiOkpCHhdcH5pNwCCpxNr/AJ6SyrEb843U5xixOUz9H2eBpp9WYrdlBxW/RCYmu 0p41rOwBq9nzI1StWa3vcRbVkmPQ/TRfPyZVg/ZC22jLWP5Fx3mvsa4EMaJQHovEKIT4 aqfrW8Iwraf+410of8qN2XVmF2KvM21/UJb2ysLIkJzW/Rzgn/APg2YqzKniTaENGHji ggAJ2iPS7T519aHMsCJz8FtU8TVQ+cnDxbwUpd2fPfx/qpZ89a4Lmm4niOi2vRBQoAPp bIofvCg2UE5Cb3npIofqhR1sYcE24Et338NL7uaOBE5yrhzhhqOPT5O4T2ZBEQ3pU/e1 jmXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PQ61WSOk; spf=pass (google.com: domain of linux-kernel+bounces-15830-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bz39-20020a056a02062700b005c67e10f238si17612052pgb.492.2024.01.03.09.58.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:58:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15830-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PQ61WSOk; spf=pass (google.com: domain of linux-kernel+bounces-15830-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15830-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0A2C6286EFD for ; Wed, 3 Jan 2024 17:58:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DAEF1D542; Wed, 3 Jan 2024 17:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PQ61WSOk" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 803B61D52A; Wed, 3 Jan 2024 17:57:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25872C433CB; Wed, 3 Jan 2024 17:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704304671; bh=EQmqIwt5epCeJn4AJ4OZUCyNlDG/sWGPlg++mDoiWxE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PQ61WSOkYHvDu+NAujBX1iKQQZ8LBc7cOd7ZSkJdNDefaZuBx9ynYYZVtX4jJdGb+ 7XOT6chUxOsHLsEnmmvvdLULKAFhQAYEnDaeLySVJ4sicSBeTl1tnAmJxJOG36YvXX Ms9+4/7u7PMcapNSeVrTinr/tC5NoN2SrdI6TT4Y1/nJCvPFNr90TPRnY4X++JGbln dp6/3BqX3NvceDJ1L6d9p4FcLzK+bE6jV5LWDAamgcqerXB0coCHYs6xCp4t1vOTc5 GJ700QXwCSqBl067oofTfdRi3BHCUE+ZrADAp/W+bEhUxVqMQidoVCPQFTYFgr5ua0 q6BvF2SdkCRUw== Date: Wed, 3 Jan 2024 17:57:43 +0000 From: Will Deacon To: Jisheng Zhang Cc: "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Catalin Marinas , Paul Walmsley , Palmer Dabbelt , Albert Ou , Arnd Bergmann , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Nadav Amit , Andrea Arcangeli , Andy Lutomirski , Dave Hansen , Thomas Gleixner , Yu Zhao , x86@kernel.org Subject: Re: [PATCH 1/2] mm/tlb: fix fullmm semantics Message-ID: <20240103175743.GG5954@willie-the-truck> References: <20231228084642.1765-1-jszhang@kernel.org> <20231228084642.1765-2-jszhang@kernel.org> <20240103175001.GF5954@willie-the-truck> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103175001.GF5954@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) On Wed, Jan 03, 2024 at 05:50:01PM +0000, Will Deacon wrote: > On Thu, Dec 28, 2023 at 04:46:41PM +0800, Jisheng Zhang wrote: > > From: Nadav Amit > > > > fullmm in mmu_gather is supposed to indicate that the mm is torn-down > > (e.g., on process exit) and can therefore allow certain optimizations. > > However, tlb_finish_mmu() sets fullmm, when in fact it want to say that > > the TLB should be fully flushed. > > > > Change tlb_finish_mmu() to set need_flush_all and check this flag in > > tlb_flush_mmu_tlbonly() when deciding whether a flush is needed. > > > > At the same time, bring the arm64 fullmm on process exit optimization back. > > > > Signed-off-by: Nadav Amit > > Signed-off-by: Jisheng Zhang > > Cc: Andrea Arcangeli > > Cc: Andrew Morton > > Cc: Andy Lutomirski > > Cc: Dave Hansen > > Cc: Peter Zijlstra > > Cc: Thomas Gleixner > > Cc: Will Deacon > > Cc: Yu Zhao > > Cc: Nick Piggin > > Cc: x86@kernel.org > > --- > > arch/arm64/include/asm/tlb.h | 5 ++++- > > include/asm-generic/tlb.h | 2 +- > > mm/mmu_gather.c | 2 +- > > 3 files changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h > > index 846c563689a8..6164c5f3b78f 100644 > > --- a/arch/arm64/include/asm/tlb.h > > +++ b/arch/arm64/include/asm/tlb.h > > @@ -62,7 +62,10 @@ static inline void tlb_flush(struct mmu_gather *tlb) > > * invalidating the walk-cache, since the ASID allocator won't > > * reallocate our ASID without invalidating the entire TLB. > > */ > > - if (tlb->fullmm) { > > + if (tlb->fullmm) > > + return; > > + > > + if (tlb->need_flush_all) { > > if (!last_level) > > flush_tlb_mm(tlb->mm); > > return; > > Why isn't the 'last_level' check sufficient here? In other words, when do > we perform a !last_level invalidation with 'fullmm' set outside of teardown? Sorry, logic inversion typo there. I should've said: When do we perform a last_level invalidation with 'fullmm' set outside of teardown? I remember this used to be the case for OOM ages ago, but 687cb0884a71 ("mm, oom_reaper: gather each vma to prevent leaking TLB entry") sorted that out. I'm not against making this clearer and/or more robust, I'm just trying to understand whether this is fixing a bug (as implied by the subject) or not. Will