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 5C896C0218D for ; Mon, 27 Jan 2025 02:34:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A8A52800D8; Sun, 26 Jan 2025 21:34:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 858982800D4; Sun, 26 Jan 2025 21:34:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F8FF2800D8; Sun, 26 Jan 2025 21:34:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4B0952800D4 for ; Sun, 26 Jan 2025 21:34:56 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ACF7DB18DE for ; Mon, 27 Jan 2025 02:34:55 +0000 (UTC) X-FDA: 83051664150.20.633497D Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf07.hostedemail.com (Postfix) with ESMTP id D8BE74000D for ; Mon, 27 Jan 2025 02:34:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FTyagb4q; spf=pass (imf07.hostedemail.com: domain of hughd@google.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737945293; 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=Hitrp1AjY/PBANuAUPERQVfYWmKYms3ba5pS3m1h084=; b=PdFgdxqiWHbMBFBQUvJKiBl2Zb/Q/dPLR0KMrEhqa14QSLZtEZ6OThBBAuqRCF4NOUJden Uv4fh6NYe6FRvlmVJ+gQYBjkfyR7CjjMUAkmpUw9fDQqUQ5u6yKnd8G37okca6VUpKKFew nJYPbBAraz/6JRG/uToX3pPoaIzA7B4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737945293; a=rsa-sha256; cv=none; b=KrOBadmVtCnPx+a2uVcGEFPLUhnAUjmgtlh+hmDQvNInJLad69/PT9HDNwDq9yniWEyjH2 gRjT3bki1Zv4M26ub2SmOkY1og7xm4qTy+ZPx7wuNX2Cp65usrpmQQvcfp77kMJw8hX21c 98d3UiFalhtF6ddaqis2b1WSDH70YwY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FTyagb4q; spf=pass (imf07.hostedemail.com: domain of hughd@google.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2161eb95317so67010305ad.1 for ; Sun, 26 Jan 2025 18:34:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737945292; x=1738550092; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=Hitrp1AjY/PBANuAUPERQVfYWmKYms3ba5pS3m1h084=; b=FTyagb4qLcEqqTzej41rrjNW2HNbMchuAqQSvdtXsJEdmC1gLvtI20p28aleliYsn8 syYRZv9MtBPUwpt+ZHKBu9Mw2AOTAP5RIP8j0GCbWbFxKzei2oUpkNuv39XuY7RDoEZq aHSSjZIroSOLQTYk2VUfp0CDTKZwc8yRTX2ml2GkfMypPbqqISn/aEMoCwwogwOWjo9P 5zHjSkTHcLbhNE1gTPG2HbCR1EwtuJcEmiSQHORlSnpxYw7wSxMdPt0SQQq/s/0kCeYg a9F4TOW5SwtNML5TOgMNrC6uQj3YiflZtbjJL90RfMPuIx6wu4yBqAckJ6XIoTv/k2F1 RQ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737945292; x=1738550092; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hitrp1AjY/PBANuAUPERQVfYWmKYms3ba5pS3m1h084=; b=vU+1mIGOe+T9Wl+vJC+gL0GJYci37lNI+3/RJFmNk9O4JvpmaKxgeHgPVrLfhSbLWO Y4A5M0thJ/q4NtV3dcqED/KH9v1laP8QhMe3Wc1wygVfhNgHAyK486fQjqIHszOU8Dv3 WxA5CCI5vAlzfkcplTJ2GLQDvzPerfaX2oCd6xNGCkO23zrgToHzJ/kEh6VXJV39DNzP Lfzv2gSIbtTndZfoNIs5BAYImxYBIlH/ICEsw9qekAqz+QWCFWQRkdE+Cs/mEU3wlSCv LRduLejwH4vSv7/SWGrGT3eBNw+WnhECYEESIoLLYOvV4ZL+MkzotB2HmiEoiuyruU8+ TTPA== X-Forwarded-Encrypted: i=1; AJvYcCWcH1N7dXRrT1rcC4F76zbG2dHX4jnF/KShR1ZAjDpb0/X+Qy5i0sdo4Pg3YkhhnCL1TCKe5nN9kg==@kvack.org X-Gm-Message-State: AOJu0Yzoi+SSHgFR4m0dy9mtRTmA0grwtoDPp+h9iPkYaiDOPJ0hh7s0 XexyQGy+vO2rwqPLI7fbAJyup2pWSc5Zj1CfTOX8zbY22iYH2P6+rQg+eBdYUQ== X-Gm-Gg: ASbGncuFwmr8qOJ1LG/EyVPYvBB5lrUU0QLDRLaSi1k0ZcqrSjkwti4/mKSf5LaX9SF if/M3T51oINOG4jAUK/FMUVAWBc2xOuc8Lgz4WZyeTTsiDvC5l/oJACJaItULwIgrQNrcb9dNKC 3wT9mL33psYh7Mt4PyskgfmUb9beFvhHnDo/SpTHbN8dXhOpk0SKMOS5zkL7Wp1Frv7p3Tu8fQS As94oA5Lig0NaqAZHnpLnysIQkMkd9FhRIQnXa3Yrk1tPte2rgktuN7aoSPYIVDHr/Vssy4AfKc GatrpN5JITzXYwdeaWp7psZ62WEdCS1IClOOzUEioPu+A5hAEodifrX6RpFz8/hY X-Google-Smtp-Source: AGHT+IGiu/swikkYWFBdEOfZ7nvltJFv4cFRPVj2396mtucRyMQnsKqob3RQxYYlmInvmFhb24glhw== X-Received: by 2002:a17:903:22c6:b0:205:4721:19c with SMTP id d9443c01a7336-21c355b73b2mr499638665ad.37.1737945290852; Sun, 26 Jan 2025 18:34:50 -0800 (PST) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da3ea3076sm52457395ad.68.2025.01.26.18.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2025 18:34:49 -0800 (PST) Date: Sun, 26 Jan 2025 18:34:48 -0800 (PST) From: Hugh Dickins To: Peter Zijlstra cc: Hugh Dickins , 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() In-Reply-To: <20250124083139.GB13226@noisy.programming.kicks-ass.net> Message-ID: 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 X-Rspamd-Queue-Id: D8BE74000D X-Stat-Signature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pb OoVKvRJ0 b0CBk809H5x9/3x2cvIk7mMBZPV77IZ+erfo6dFSzIIv93GNpilUkpbZ45YzdZkLgZk31n3Fht0791Y1Zvkco5C+pBv/ZudFuWEZGIxcBAZEx+8gCI60ft4UdaSbhPw7+PelquxbRloAwoV0d/VQSQLAe4vo6CF9v4rQtntBfsIdh/xmO8lAIkUAomAxiQSWtVwKNDh7Efn/Y4qxClzkWNfrxYvKuyU9NJuVAVDQkcLyUrERpO6sW3ZzMhLSTzXBdETQOJ21556RYd5VfFlDiYkMPUXKVXm43/fz4a/5mX1ntZ8yisq9IoG0UR9dUW+cAGk3P7KguozjGSd1135y+0WveZL0bxxI/6V3I4gDstF7KoQsOJIZnBZSeQcVneyT+oB17mcWFh+JaAR2NSN8WB1PgwA== 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 Fri, 24 Jan 2025, Peter Zijlstra wrote: > On Thu, Jan 23, 2025 at 08:42:36PM -0800, Hugh Dickins wrote: > > The changelog of commit b67fbebd4cf9 ("mmu_gather: Force tlb-flush > > VM_PFNMAP vmas") has not helped me either. Nor could I locate any > > discussion (Jann, Linus, Peter, Will?) that led up to it. > > Hmm, that was probably on security -- I should have those mails around > somewhere, I'll see if I can dig them up. That was very helpful, thank you: I've gone through a lot of confusion, but feeling more confident about it all today. > > > To me, Peter's patch looks much like yours, except wth different > > names and comments, plus the "vma" error you point out below. > > Yes, 3 differences: > > - naming; > - the extra check; > - the vma_pfn clearing condition. > > Under the assumption that this is all about those PFNs, the argument > (as also outlined in the email to Roman just now) is that you only need > to flush if both: you have pending TLBI for PFN and are indeed about to > unlink a PFN vma. > > 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. > > 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; 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). 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(). Hugh