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 D3805E7717F for ; Tue, 17 Dec 2024 09:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D9556B0093; Tue, 17 Dec 2024 04:31:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 188E06B0095; Tue, 17 Dec 2024 04:31:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 002CA6B009A; Tue, 17 Dec 2024 04:31:21 -0500 (EST) 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 D35CB6B0093 for ; Tue, 17 Dec 2024 04:31:21 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 227C0120594 for ; Tue, 17 Dec 2024 09:31:21 +0000 (UTC) X-FDA: 82903931586.13.1B9D8E4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id C1F23100005 for ; Tue, 17 Dec 2024 09:30:45 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dbpo9mDe; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of a.hindborg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=a.hindborg@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734427865; 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=CZj817z2/JB6dlzGEXcduIXNCGOFF/WVPA7FDBbE6y8=; b=cDndrUUhsx3oChPYroGcniReDrUqzexLynPc/N7vZwTIBwfAyG0G5Yw98d2UBhmJhhLzX6 TNWG9ot5mxxGrXhwXTW4JSM7hWcGMc3BJMTANQTR+yL+2eCfjgS29UoHp1tomwdQ6DLY/i pnH/2hHZsQeWAvpgQZ/ycvr7pe99oY4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734427865; a=rsa-sha256; cv=none; b=gEq3JYELwC/8tHmH8bLUbd4DLIihsoXygmGdLxMg0WXS2cxr8YjqdoYnAQ/5RSOgLELwZH j4leKRbg2cwtj/KK18zdWCUFQAcg/iomB4zITHVA9b0oq2GSjTCn4GegEm1sIChJklPFAN rHOe9EVPMLg1xaEChJJoY9AOgxLO9J4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Dbpo9mDe; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of a.hindborg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=a.hindborg@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 047025C65F4; Tue, 17 Dec 2024 09:30:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7FFFC4CEDE; Tue, 17 Dec 2024 09:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734427877; bh=ervJxKyQZmVDHzYCEh7bR4br9+een6B1D7MUqP8OFoQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Dbpo9mDeoh+GbNtjrusvndCYMBEWAOy60nGCeyZmQxE3yKllcWLkyAyrTVbJXi5iR g2Cg3DVc/Aqx0g3hgkoFZ5cz2hEov9lerHg2NEqYOtqmS3TCCM80+I1xKckC7EP0f7 PR21PUrg7hI09WpVZUorjWjdqmNR5H8kte58vOFN5R1DnTaOlQIKqU4iB+wGVjY2lh GT6gOGJxS5GTi2MBjUY1tN4ZQw/iorCyG30PDZdOKAkUXkM2mydvWBEy1W3HR8o5Qy HtptbJdAbB9y70qc0ZYfQ0BguM+IodOuQvZgo0jm6GrVSCF3HbKVSsjGkWBtwlZUPf SOZEbM2x9FPSQ== 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: <20241211-vma-v11-6-466640428fc3@google.com> (Alice Ryhl's message of "Wed, 11 Dec 2024 10:37:10 +0000") References: <20241211-vma-v11-0-466640428fc3@google.com> <20241211-vma-v11-6-466640428fc3@google.com> Date: Tue, 17 Dec 2024 10:31:00 +0100 Message-ID: <87zfku8xm3.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain X-Stat-Signature: 4e1sn8f3qt6n9mn98r88cijhcz51nfun X-Rspamd-Queue-Id: C1F23100005 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734427845-20724 X-HE-Meta: U2FsdGVkX1/8V7yEZ6zhA+K18WxhsEBVcggYRm0Wy/xTuleh/vANDDpYrtHYU29Xr93ASs1ixPHwPu7RiAtKELH5Oz5GvxpKrvA8g0kSSDw2GI2MAAkOsnGaDZcJBKh6zqjd6DwIboCS22YPjxV2gjKEP7z6FDst4wDFSHPBGNajovOe8TRFaEabAcTF8rNF9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uyMxG+EDU7CAeseH6S9/Mm/jRYQCeeVqoGnuJ2nrqZxHYW9EIjBAtZnPEbYPi3LGjOERfuOqmVqZG7VXkBCOyc9336bzvxCTSuZu8V4rpkqmff7jUxg1yAlgfa74= X-Bogosity: Ham, tests=bogofilter, spamicity=0.349681, 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: > 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 error > 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 [cut] > + /// Returns whether `VM_READ` is set. > + /// > + /// This flag indicates whether userspace is mapping this vma as readable. > + #[inline] > + pub fn get_read(&self) -> bool { > + (self.flags() & flags::READ) != 0 > + } As an afterthought, should we name these getters according to RFC344 [1] (remove get_ prefix)? Best regards, Andreas Hindborg [1] https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#gettersetter-apis