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 662D7C77B7C for ; Wed, 2 Jul 2025 18:16:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4B596B00AE; Wed, 2 Jul 2025 14:16:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFC0C6B00B0; Wed, 2 Jul 2025 14:16:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A11C46B00B1; Wed, 2 Jul 2025 14:16:43 -0400 (EDT) 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 926D06B00AE for ; Wed, 2 Jul 2025 14:16:43 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B82571A03AF for ; Wed, 2 Jul 2025 18:16:42 +0000 (UTC) X-FDA: 83620130244.07.490C4F6 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf09.hostedemail.com (Postfix) with ESMTP id 0E0EF140009 for ; Wed, 2 Jul 2025 18:16:40 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZUGrthuu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751480201; a=rsa-sha256; cv=none; b=B0exf9kWoStVXcSTndH6W3lCdX2Q9H00NQ9DUpxMWnsjOhbwHFEUQLpMnXBIHxReZR6vEp SvqEUIeQ1AYFXGLNOV0pDKIZO1se58BW2B4W2D8HjRSGCn4piGL+vuuzvZKzJJxZ9e1Jam 69uRUN2SDvpf7qRUJP41tEvpcHn84ow= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZUGrthuu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf09.hostedemail.com: domain of rppt@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751480201; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DlRlRxhXb2l8x7bq6na+pBleJXMMvk/1HyXgD8pjDWs=; b=gny018UwGgig8SAK/CRNkulYGrB5jzIUpraeGXxEocL+uuhN+zIQVYtULUtSeV6zzNsqsB 01vzEZWuagog2A0p612dAoBoYG9/+2gfwwkmtPMZ6OIgGyaV57Wd8A9CiyDqQVrLVZFMKA myh9E+HwsyRob/SDPyDwd3hnigesutg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 4EFC2A53238; Wed, 2 Jul 2025 18:16:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4AFDC4CEE7; Wed, 2 Jul 2025 18:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751480200; bh=mo/coVNz2exJHdqFowDYNra/bNpVUtQBGFYebIEfbIo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZUGrthuu99We5h4+ZEH6Ob8quGIahQ5SCVVrjASu51OjQi83kL1wxo1J6JWYiVxzC Crkj7Ldl2ZokOjE0lcb4kcof2sxN7ic98Ue4Aw7gFpFfHuj3mfZ8DUuYVJjud2KJ/c Lb5/rYriNHSIe47ldXwVkg00YWmJhZxGkfCzc5EanVVGca9QcpduGIVzWuXIuTu/Xh hlb6JkCfwQ7QGDd3P6CSrxuS+3SKhZfnAOcxZedDmswKpWOFv7sir+4uiY+ZL4+5Xw R7q34YAdz2LEtGV/my6lu/zCTxOk3mmeDio3lliOviv8IL7y/i1RGn1jGKyfBEfL9S N3y0TiltKehLQ== Date: Wed, 2 Jul 2025 21:16:31 +0300 From: Mike Rapoport To: Suren Baghdasaryan Cc: Lorenzo Stoakes , Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Muchun Song , Hugh Dickins , Andrew Morton , James Houghton , "Liam R . Howlett" , Nikita Kalyazin , Michal Hocko , David Hildenbrand , Andrea Arcangeli , Oscar Salvador , Axel Rasmussen , Ujwal Kundur Subject: Re: [PATCH v2 1/4] mm: Introduce vm_uffd_ops API Message-ID: References: <20250627154655.2085903-1-peterx@redhat.com> <20250627154655.2085903-2-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: hrw1aaixxuwxabjim8mg489stmwdxpfu X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0E0EF140009 X-Rspam-User: X-HE-Tag: 1751480200-830504 X-HE-Meta: U2FsdGVkX1/e2pRXmXPriXq8nxxm7LJAohwOf1gMHyxi5pUdkRps69lYMP9jGXLDKuWYBBBUPL5I3HOnXYyZvZIms265FZ5Bq7TFafxhjuDA1rW387stEm+uq5MEGRE6jC2fHlBhOfU74cayccrxNCARHqbQm1gUu0RNFo2iWH9NIQQ0ShwliGjSwatmfMG2Y4SAOsmEjAe9CJU88KQDe2Hz3d1QD6HhReUBxsX7Ue1d4+x5XFkkBp2qTFghjhWE17hMvd6Ka1hmRPZWXXN1QQ2esqBHwnU4wKPnVt06f33SZnf1Niw6Sr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C39GzgiPeEMk0m82LnPSsKwFDNRw7D1/FqsuKLad 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 Tue, Jul 01, 2025 at 10:04:28AM -0700, Suren Baghdasaryan wrote: > On Mon, Jun 30, 2025 at 3:16 AM Lorenzo Stoakes > wrote: > > > > It seems like we're assuming a _lot_ of mm understanding in the underlying > > driver here. > > > > I'm not sure it's really normal to be handing around page table state and > > folios etc. to a driver like this, this is really... worrying to me. > > > > This feels like you're trying to put mm functionality outside of mm? > > To second that, two things stick out for me here: > 1. uffd_copy and uffd_get_folio seem to be at different abstraction > levels. uffd_copy is almost the entire copy operation for VM_SHARED > VMAs while uffd_get_folio is a small part of the continue operation. > 2. shmem_mfill_atomic_pte which becomes uffd_copy for shmem in the > last patch is quite a complex function which itself calls some IMO > pretty internal functions like mfill_atomic_install_pte(). Expecting > modules to implement such functionality seems like a stretch to me but > maybe this is for some specialized modules which are written by mm > experts only? Largely shmem_mfill_atomic_pte() differs from anonymous memory version (mfill_atomic_pte_copy()) by the way the allocated folio is accounted and whether it's added to the page cache. So instead of uffd_copy(...) we might add int (*folio_alloc)(struct vm_area_struct *vma, unsigned long dst_addr); void (*folio_release)(struct vm_area_struct *vma, struct folio *folio); and then use them in mfill_atomic_pte_copy(): diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index bc473ad21202..6bad0dd70d3d 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -247,8 +247,11 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, if (!*foliop) { ret = -ENOMEM; - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, dst_vma, - dst_addr); + if (uffd_ops(dst_vma) && uffd_ops(dst_vma)->folio_alloc) + folio = uffd_ops(dst_vma)->folio_alloc(dst_vma, dst_addr); + else + folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, dst_vma, + dst_addr); if (!folio) goto out; @@ -307,6 +310,8 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, return ret; out_release: folio_put(folio); + if (uffd_ops(dst_vma) && uffd_ops(dst_vma)->folio_release) + uffd_ops(dst_vma)->folio_release(dst_vma, folio); goto out; } -- Sincerely yours, Mike.