From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DE7B25A64A for ; Mon, 27 Jan 2025 02:34:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737945294; cv=none; b=Le0DRds6B5yJIIEapTveYWzh2iaQWDxL+OlL/x/cFQsLlmMNJac50ojyAHEiJPhhQb4fX+n/ZJ0agYHjaoGXdDQrrqRRVc0jyy9ubzCz7ALzMtj0mbL8DJ9hHDJDB9jlcWNTrqyS4EaGIvDZNPP9ubPskZD1uVaswUi/pcX6HPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737945294; c=relaxed/simple; bh=dC6O6GeUCt78YeHesy6iGFtCDtu8eSs5PaqWsyww2Zo=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=s1OkjDJCXr2tK+xehZZyaGOt0+ItAM8TD9pwF0FOkB8wtuYM7PKp9cL7fkPDVauB0cQjLLpeTk/wSn5JhLJ9Fejry3nQ+Yqfq6lqLicaWHV95q2VonAMgtzl0bs/Horr21Hqks70khO8G18OEXPcqR8e0DZjCV9p31XqYjAs8y8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dCWHNA03; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dCWHNA03" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2161eb95317so67010315ad.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=vger.kernel.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=dCWHNA03nmKEZNDTBAneA5iTED6BM+j1ikzN9HPQvLkcCATms+iYB0de+OETZTY+B0 fYaOF8nhU/o4ySi3VOUWao5FBZopj4/7yNVMK14/JE5id9rX6sg0y/sMU5dssAoVlyMT YyAlD4dXHbl5/j7/1KY4V06bGfDBkUpyO+CXEjjHKxk147xH8nLfxZWPnpwkaAIJ3odn Q2F992z9QPbWvKHmdE8jtcxjxcdA4/tLI5bEvSYEXXCJs+hKElUK/Eo90pQAbrj9Lh7O o7D2mndBKbdW34fQf5nrjd9Mo8LGgtMXVD9wW1M+zUU7F8nI3jL7Cqxwt+Q8Uy3IPH0Y NTtQ== 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=FSiFEvh9EEZMHNVC5vNhPfQy2b39UT1zo3f8MrrUlxRMtTOQ502jd8NqWXlG9afGD8 xUriU+w5QwTeu+xePffjAr96JTGj0PozofL2IGpRMvKhuZbK9Mdxm7thdrBLNLCQkJN7 fgs2DNo0KweBAyc9/6WaySTk+RCUQ+hMuots4i2X8hxYo8SfmxU0ZCEOQpJU1K3uVTom OtulEdTD0nUv7gT2TiSnBr5T5kc+/9xx2uFGDzgo/3STMXezYLrvbMGVVaz4tpOhlM4a IdGjM70tez0gcCWL8sZhbBCebRc6wmqcDA/qUYZa/1R2MsrC6yPBFDawueSV2Cwr9ir8 5/UA== X-Forwarded-Encrypted: i=1; AJvYcCWt6v4hLtwMBW74DTvnrDokfp0rJdSKbnlZbVCZcq8VanD6gvbHkPN9zBgjsP6ytE1FfKleEvvl7MvtSn4=@vger.kernel.org X-Gm-Message-State: AOJu0YzFKcvv7YSPHZYsENVrWHW4lbSZBdllkdRmMPvSdXoxdaTAw4+t KBcvMWXLwl7TeG8bPAor+1NOccxbFYowusAxliRn3px+1Gi/kcufxbFE+smnLQ== X-Gm-Gg: ASbGnctfMI7NM9rb41beiNh0/3krz1uY8geggvoif/h+Bvnan3byPBTJFvVW98vAuDN k/RABXkedwEvDmeM+YWdS/ntp3yS2iU9i+K95sSSAqVvpFDbjpU8vv1j1EodxyV4UgTDxxJh2jQ mIORrZx1V1GxYUr9b2lqoWcm6yLlxng2RtEbMGvSS3wluWFu+iIxaMXHseGENuVdTOUVZp10CFL KrMcDZwDpJZNY6S8/2BJC8f0HFICRmS/NVoxnoM4xDCsSdHL3UPE+3qkMKk6LOTSx/2C7w0EpGf kFi92wSAuI5d7PmpJKAH57xPEW2sVlQDk5l+DLsmaRZ3RrI5G1vvgucQwKPWs7P1 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> 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 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