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 82AC5E77197 for ; Thu, 9 Jan 2025 08:20:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F30CE6B007B; Thu, 9 Jan 2025 03:20:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE0706B0082; Thu, 9 Jan 2025 03:20:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA8746B0083; Thu, 9 Jan 2025 03:20:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BD7A06B007B for ; Thu, 9 Jan 2025 03:20:00 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 24BB41216E4 for ; Thu, 9 Jan 2025 08:20:00 +0000 (UTC) X-FDA: 82987215360.22.B995B55 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf26.hostedemail.com (Postfix) with ESMTP id 74D3A140009 for ; Thu, 9 Jan 2025 08:19:58 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NVl7MpYQ; spf=pass (imf26.hostedemail.com: domain of a.hindborg@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=a.hindborg@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736410798; 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=1fOyiayA+LifzfeckVRj9gxrY1pGvg/Kku5uR66sALY=; b=JzxY6BhiBDhIoNGOEUPfUULU1Xj+793n+xoEJuPXP4K8Cr+BGqimgWvuAIyHOFsXaxRrgv c2KSX2UIEpLG1qqtJftPRFRL7c2yWjmS7cKuCUmyy8GBjApb4C3f8VbwadRCW7lrGTSuV1 9RLfXG5gij/FrSvwBK1P3sHw1BR13/E= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NVl7MpYQ; spf=pass (imf26.hostedemail.com: domain of a.hindborg@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=a.hindborg@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736410798; a=rsa-sha256; cv=none; b=sntdZ5Z7t+UxU8qYOLDC6P+385/v3W4Hg7quuDgjgjbRyhDf01iUkKwM7IFvS+ktvlzKdi rSuvABvDzESn24h9Wme6GhazUlpowfgldD+a2DE9kybYTc3GZhf2jOtW+BQnedYWp7vuN8 3fhokfJqO6JkRARveLrQxL1Lz/7Tghs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DBB5BA412C0; Thu, 9 Jan 2025 08:18:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67926C4CED2; Thu, 9 Jan 2025 08:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736410797; bh=Md+mNVPfVwVeK8yUZS5LLyfhVUilsz8vzI6QSleGKTc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NVl7MpYQ8jRj9UzUHSSqZNRzUMguqKZ+nE8YMkwV5sx1i/fIXUzdPaL2nm6q3hy7i 5RmFwUWLn/J1r867x/8Q1K7fjvWREtW4Yl+T0sh4mh1vK/lp25NKVSaHUxCXLYIO2r DE3fx6IUz5Hgt1kDZRnitOHfH0MxnQGcjKS/uBujrm73qLKT5UQiOo/x6VpHLBBf9S LpDBNESuyw/GnG62U6PuJ393lKZaE8+n9N6Hvzj+bxayLLje64fUziXTr2PXqXQX+E VOEWKqtFSuJrOWyEQ03AnofjtDpn8ou0owzEQlX+ux9Biu72fTP1BLvSIQZMhdH2w0 1Ywgyj+rL9hnQ== From: Andreas Hindborg To: "Alice Ryhl" Cc: "Miguel Ojeda" , "Matthew Wilcox" , "Lorenzo Stoakes" , "Vlastimil Babka" , "John Hubbard" , "Liam R. Howlett" , "Andrew Morton" , "Greg Kroah-Hartman" , "Arnd Bergmann" , "Christian Brauner" , "Jann Horn" , "Suren Baghdasaryan" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , "Benno Lossin" , "Trevor Gross" , , , Subject: Re: [PATCH v11 6/8] mm: rust: add VmAreaNew for f_ops->mmap() In-Reply-To: (Alice Ryhl's message of "Wed, 08 Jan 2025 13:23:40 +0100") References: <20241211-vma-v11-0-466640428fc3@google.com> <20241211-vma-v11-6-466640428fc3@google.com> <87o71bagpf.fsf@kernel.org> User-Agent: mu4e 1.12.7; emacs 29.4 Date: Thu, 09 Jan 2025 09:19:47 +0100 Message-ID: <87a5c0bdr0.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 74D3A140009 X-Rspam-User: X-Stat-Signature: mfaz5pnxynn39eqw1kqmhxrwo5ce9afe X-HE-Tag: 1736410798-738334 X-HE-Meta: U2FsdGVkX19kJRnLk839eY+XSGBWzeqOpf0spsRVrzG3C2tWhPVUKBeO79MSB7Sn1BPLIPXs28Pzye/0fw5EDWdYhjiuGptxqdb2Nmb8gM67K9d4as+6a567aGzcSoisQL+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iaHCYGfX0+L/FoUgYtQ+Db5rlPVjyayW6GBmXhYA1oIaq+YPfUw0x9Lo7vHEsNiwSKLGCC184pjPh3AK3IbLjHS2Czn7eEaJq2IClXK5nM5A/XTJhdMw/5fj/HKD4vki0/YXs1rkHgW9pvbMevw7p4haCFr8TI9PoTgslpPHOx7Ck+Bn8/XAxeV7OIDxEpXDBXzZgkc X-Bogosity: Ham, tests=bogofilter, spamicity=0.435305, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: "Alice Ryhl" writes: > On Mon, Dec 16, 2024 at 3:51=E2=80=AFPM Andreas Hindborg wrote: >> >> "Alice Ryhl" writes: >> >> > This type will be used when setting up a new vma in an f_ops->mmap() >> > hook. Using a separate type from VmAreaRef allows us to have a separate >> > set of operations that you are only able to use during the mmap() hook. >> > For example, the VM_MIXEDMAP flag must not be changed after the initial >> > setup that happens during the f_ops->mmap() hook. >> > >> > To avoid setting invalid flag values, the methods for clearing >> > VM_MAYWRITE and similar involve a check of VM_WRITE, and return an err= or >> > if VM_WRITE is set. Trying to use `try_clear_maywrite` without checking >> > the return value results in a compilation error because the `Result` >> > type is marked #[must_use]. >> > >> > For now, there's only a method for VM_MIXEDMAP and not VM_PFNMAP. When >> > we add a VM_PFNMAP method, we will need some way to prevent you from >> > setting both VM_MIXEDMAP and VM_PFNMAP on the same vma. >> > >> > Acked-by: Lorenzo Stoakes (for mm bits) >> > Reviewed-by: Jann Horn >> > Signed-off-by: Alice Ryhl >> > --- >> > rust/kernel/mm/virt.rs | 181 ++++++++++++++++++++++++++++++++++++++++= ++++++++- >> > 1 file changed, 180 insertions(+), 1 deletion(-) >> > >> > diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs >> > index 3a23854e14f4..6d9ba56d4f95 100644 >> > --- a/rust/kernel/mm/virt.rs >> > +++ b/rust/kernel/mm/virt.rs >> > @@ -6,7 +6,7 @@ >> > >> > use crate::{ >> > bindings, >> > - error::{to_result, Result}, >> > + error::{code::EINVAL, to_result, Result}, >> > mm::MmWithUser, >> > page::Page, >> > types::Opaque, >> > @@ -171,6 +171,185 @@ pub fn vm_insert_page(&self, address: usize, pag= e: &Page) -> Result { >> > } >> > } >> > >> > +/// A builder for setting up a vma in an `f_ops->mmap()` hook. >> >> Reading this line, I would expect to be able to chain update methods as >> in `Builder::new().prop_a().prop_b().build()`. Could/should this type >> accommodate a proper builder pattern? Or is "builder" not the right word >> to use here? > > You cannot create values of this type yourself. Only the C > infrastructure can do so. > > What would you call it if not "builder"? It looks more like a newtype with a bunch of setters and getters. It also does not have a method to instantiate (`build()` or similar). So how about newtype? Best regards, Andreas Hindborg