From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC536C0218C for ; Mon, 27 Jan 2025 09:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 296DA280143; Mon, 27 Jan 2025 04:53:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2479D28013F; Mon, 27 Jan 2025 04:53:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1357E280143; Mon, 27 Jan 2025 04:53:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EA4F228013F for ; Mon, 27 Jan 2025 04:53:51 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 67F3B4C6AD for ; Mon, 27 Jan 2025 09:53:39 +0000 (UTC) X-FDA: 83052769758.08.C0DC62D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 3CEF110000E for ; Mon, 27 Jan 2025 09:53:37 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dhY+XGFE; dmarc=none; spf=none (imf14.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737971617; a=rsa-sha256; cv=none; b=JXpUB0Zl/CA4DvxhnRXBGHM0pj0vrb7/a3iUmuBhA+wvhdZWpg/aaPHd916/XuMWft3x/b 0JXp3sHPBdE90UQMgiSfu+ijdpIocpRKbTvn6q3tH41Es23ehtPG1nyTw036wC4GWNAv/+ aAYA6FIdtyza2kzasl5qgTLr5NgBtV0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dhY+XGFE; dmarc=none; spf=none (imf14.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737971617; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kJGDu6W10NCF/1kHbq9MWN63eWI9W/iOmx8WRJAXCOg=; b=ZmPPlm5o6+RzQmEDTMGKA6OSmW9Tr2y/uoT9ZAQOGJ7YPQ7HHsdsKft/jyDJc+/jXsd11l 7pfqFjLFQvdbWEorO+ZLVnyqH9G6lwXUsH+K0j7ZnbeLYUFdPtAFxoaCcTTh6r+7NE3XH+ g/7wqgyA2CQSV5mfpyMPAUd3LwRyxro= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=kJGDu6W10NCF/1kHbq9MWN63eWI9W/iOmx8WRJAXCOg=; b=dhY+XGFEy3eopIVBJHf10Av56B 6Xkmnx1VQvr6mQp7+jp3RcTV/RFe97oKO5DY+XOrgyGdWgFlJ6bwGastDUA4lSbZljoQWzF9GzDdd xm8pCO5G0bGL+L8FJRJhlkJBkMKlQWddJI21h8Eh0rIj28c0MmyG84AnELKnar+HC+GxjBj/m1z9o qX9x0Gy+cLh7WCU9U40xBMSFZCZCjOSR/TB56jz+6PnWOSF56uKUndBupWk3JvG8Oq0Z7Zwg13uBn Y0tkphhi4yjewRGnBmBLHdrhb1KQE7IbCwPOyCY9uiSti3xN32asvrV9OJw+hKG5vUqliT7Az9f51 MI2ptaTw==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tcLoC-00000009EhB-2INM; Mon, 27 Jan 2025 09:53:32 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 945463004DE; Mon, 27 Jan 2025 10:53:31 +0100 (CET) Date: Mon, 27 Jan 2025 10:53:31 +0100 From: Peter Zijlstra To: Hugh Dickins Cc: Jann Horn , Roman Gushchin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , linux-arch@vger.kernel.org Subject: Re: [PATCH v2] mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables() Message-ID: <20250127095331.GB16742@noisy.programming.kicks-ass.net> References: <20250122232716.1321171-1-roman.gushchin@linux.dev> <20250123214531.GA969@noisy.programming.kicks-ass.net> <26cd41c2-b8b6-0c1d-c36d-28f2f9f369be@google.com> <20250124083139.GB13226@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3CEF110000E X-Stat-Signature: io618o4w43bnjpzreqt181gmsxo59rn6 X-Rspam-User: X-HE-Tag: 1737971617-359436 X-HE-Meta: U2FsdGVkX1+LTCB5VMIbr3DOYJ9fk3nP7oserx2WmBXB9nkiSZnbA96gSNUvdKNcU+SEbH370cWvfmYfdAGX4S8uOLBjMi3ye9QQLos0uhQJQZO+2BoEeXN2FGuk9aHaa5f+oXIgiqWw0dfcpjPf5um/gPoTVEFRWOXmi7eFvUv+6E121BOW0FrT4UR2TCY71ULyNGxoBasepVug/qZPkwb8dHlrcwJ3kGQcCQCiks+Id1oMWzZvpRHuekIQIDYtpaf8Agm1TLudeqw2tsmYulWaHtUkoQus8TGdWW90KA0HV/3yX3MZeZLam1jIrxsNLXeUIsDPJB35pUxL3VtQ859/1u+FafHj9FmerMcXYqnX45BHl3A1rE71TF24VysmFg5olrrpPZebZ3LlpxP4RBZM0scJkKsh0ko05abLA5yfklW87ln+pHDNnzKlIe1y4BFExlCLwyfA8eezPgw6yWxyRdag03VNMkYFkwekhmWLzZyz0OqLOnv0bqqxa3KVDYzXiDVSst9NuhAUDOzH/4x3TwoB64q3eCHxh5rzl6JqSGqKCZeDfXO5u66/+wgFhoKbdehcEYTRTMe0NQqBWSosuQT7R9XkuKAKUe4ZJvcvplaI5MGVpIl4Ka7dIEFhmMYUqnKvrhWo1JS/HS25pkzBlYtDi//Helk0qYKmQm7dXtvPua52gqU+DMF+Ac6qpxRbSHCCJxeiQIXJMAaQZj7RzhryaTpEKnu+j+WQPaxFS1FgvGko3SyiP7wFVb1AkTU+itt3QHHP0BP4B8xOhEGzM6afETnt9NwwaP4pwLWeplmMZ/FK6bzz4n0rcjpjB4D0FHirbSnu2naqNNLt0l++L0/JuuUm7lFzrxY0k7YFDLRJjDdb1Y+/gVqgXyK+mtheOS9cTN7QAIHAMROFjXp/YggfSLT4wrk7DOfPb2Yqe5LdesP1vYfCebuxaz2Qe4KTqI7ntrZgRMSWwli U4Fanek1 j2QUd07oAXXzVrXK8/0Ampbmt/RVJC2zzuK6U4JIQ53Kx4LhP8o17Hr307Me5Xg9CU/eCcqPjXvXvtmXKLRLagOHdkmugAUvaqMwI3hvg6F2zXFH7uvtK47izmZ++Y1EbSsKiVcJVYAIGZhHs8UZqG4in8Ike85yXmUdeVeocQz+mf/fuveJljgjZUOOOMGfLNcbY/MaSrUfWiw2I09U8CLu7LHgTRm43JD2AZqdrialgPlY= 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: List-Subscribe: List-Unsubscribe: On Sun, Jan 26, 2025 at 06:34:48PM -0800, Hugh Dickins wrote: > > If we've flushed the relevant PFNs earlier, for whatever reason, > > batching, or the arch has !MERGE_VMAS or whatever, then we do not need > > to flush again. So clearing vma_pfn in __tlb_reset_range() is the right > > place. > > Yes, Roman moved to clearing vma_pfn in __tlb_reset_range() in his v3: > we are all in agreement on that. Ah, I had not seen v3 yet. > > Similarly, if we don't ever actually free/unlink the PFN vma, we also > > don't care. > > I cannot think of a case in which we arrive at free_pgtables(), but do not > unlink the vma(s) which caused vma_pfn to be set. If there is such a case, > it's not worth optimizing for; Yeah, I suppose it doesn't happen. But I figured why assume stuff. > and wrong to check just the first vma in the > list (don't look only at the stable commit 895428ee124a which Roman cited - > it had to be fixed by 891f03f688de afterwards). Duh, yeah, so tlb_free_vma() wants to be inside the vma loop of free_pgtables(). > Personally, I prefer code inline in free_pgtables() which shows what's > going on, as Roman did in v1, rather than struggling to devise a > self-explanatory function name for something over there in tlb.h. > > But I may be in a minority on that, and his tlb_flush_mmu_pfnmap() > is much more to the point than tlb_free_vma(). I prefer a function over the in-line thing such that mmu-gather is more or less self contained. So my concern is/was maintainability of all this; tlb_flush_mmu_pfnmap() tells me nothing about when this function should be called. Otoh tlb_free_vma() tell me this should be called when we're freeing VMAs -- much harder to misplace etc. If we have hooks placed at, and named after, natural events in the lifetime of things, placement is 'obvious'. Another possible name might be tlb_free_pgtables(), indicating we're about to start freeing pagetables -- but it would need to assert !tlb->freed_tables, and I'm not sure this is a constraint worth imposing. It would bring pain if someone wanted to mix freeing pages and page-tables. And we already have vma based hooks, so I much prefer adding one more of those. This is about funky VMAs after all.