From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 BA6A51A6814 for ; Thu, 6 Aug 2026 19:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786044077; cv=none; b=EXr7gvcg1gujJJ4e2UxnmmlnZSSXtaHeEfdMa6UIYJL1M7DVEZ1gOyqSgJ2D/1wlB+sDy/MwkSKUomGaRg2L30Qblh+jcUnfGBkkGPRglmTZ3FhttxGWsyupN9r1MRWOOo/D+/DGn4qrpUQVhfAsTTa9Ko/59YzhoEyPOrfBsuA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786044077; c=relaxed/simple; bh=UXDVifHrZXKspFpdcTpIle03/KKu1d0XGdWNUw0H4Yg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=qXrw2vAoNxyHutxnqfeEHysGhTA6X/NIeZjU9FyY04eo+s/4C43bS0OqyeOWppnMQoNFV/NW2OrrETH3jVMx54yj7r8nw+SVqc0yFPxIZM+79uRSTDWds1bXAQ+L459Mfxpo94ndEGkT4wd3k6vifYayx3IgpzPKBHom3YaycVw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=dvwwpvhI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="dvwwpvhI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AD8C1F000E9; Thu, 6 Aug 2026 19:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1786044076; bh=yqBkOHdmSbNw3BiGir7LVReVfGTE5RkU8HN/8SqdD8g=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=dvwwpvhItmXXrDc+qw6UfX4yhZ9ob0lyXGI8vfSCAUmiQesp88b57y7TxqS+DQdDR 68SGrqYvdLD35KMkVYYsXHcMFMzkVpGL7AwiYALGfcmA+EM3ZU1TUwZ9a3X2zk3d5f GxnhHE96A6Dk1oM/+cUXcQt/je3DLlDuaqKk7CY8= Date: Thu, 6 Aug 2026 12:21:15 -0700 From: Andrew Morton To: "David Hildenbrand (Arm)" Cc: Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jason Gunthorpe , John Hubbard , Peter Xu , Ackerley Tng , Sean Christopherson , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/gup: factor out LRU cache draining for folio into lru_cache_drain_for_folio() Message-Id: <20260806122115.1bde36d4885803a6c370880a@linux-foundation.org> In-Reply-To: <20260806-lru_cache_drain_for_folio-v1-1-c6287d295e99@kernel.org> References: <20260806-lru_cache_drain_for_folio-v1-1-c6287d295e99@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 06 Aug 2026 20:09:06 +0200 "David Hildenbrand (Arm)" wrote: > KVM with guest_memfd wants to remove any folio references due to LRU > caches, as it really must only allow to convert folios from shared to > private when there are no unexpected folio references (e.g., from GUP > references). > > So, to drive the refcount down, it needs a way to flush the LRU caches. > Let's factor out what we have in lru_cache_drain_for_folio(). Document > it, and also mention that concurrent folio (un)mapping might, in theory, > miss detecting LRU cache references. Keep obtaining the expected refcount > twice to minimize the possibility. For the current and future user that > should work, and we don't really have a better alternative: we could > detect if the mapcount changed, but it would still be racy and add more > complexity with questionable benefit. > > Maybe there is a chance to avoid the draining entirely in the future, > by avoiding extra references from the LRU cache: Hugh thinks there might > be a way. But for the time being, this handling is unfortunately > required. > > Make folio_may_be_lru_cached() accept a const pointer so > lru_cache_drain_for_folio() can accept a const pointer as well. > Thanks, I'll put this straight into mm-unstable next to your [1]. > This is based on the fix [1] that is already on its way upstream. > > guest_memfd will need this for the work they are now targeting for > 7.4. I expect the guest_memfd user to add a KVM-only export of the > symbol. > > So either we get this into 7.3-rc1 as well, or Ackerley can carry the > patch as his stuff goes upstream through the x86 KVM tree. I expect both [1] and this patch will be in the second week of merge window batch. > [1] https://lore.kernel.org/r/20260731-check_and_migrate_movable_folios-v1-1-e0002d7b791e@kernel.org > [2] https://lore.kernel.org/r/20260728-gmem-inplace-conversion-v9-14-35f9aec2aed2@google.com