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 90019C3DA49 for ; Fri, 2 Aug 2024 09:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AAF76B0085; Fri, 2 Aug 2024 05:39:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25B216B0088; Fri, 2 Aug 2024 05:39:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 123CE6B0089; Fri, 2 Aug 2024 05:39:16 -0400 (EDT) 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 EA0CF6B0085 for ; Fri, 2 Aug 2024 05:39:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 929101A107D for ; Fri, 2 Aug 2024 09:39:15 +0000 (UTC) X-FDA: 82406807070.08.F498AC1 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by imf04.hostedemail.com (Postfix) with ESMTP id 9C30F4000B for ; Fri, 2 Aug 2024 09:39:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=proton.me header.s=protonmail header.b=VV3uBCnl; spf=pass (imf04.hostedemail.com: domain of benno.lossin@proton.me designates 185.70.40.131 as permitted sender) smtp.mailfrom=benno.lossin@proton.me; dmarc=pass (policy=quarantine) header.from=proton.me ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722591495; 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=m1QNeER4/O9Nb9QxsEYXTwhiESfbBDeW5e0hMJz/WCw=; b=FaMUrlm5M5tjuOECF3cMGlRMINUFVsuHJjzmUSzqA3cerzJMbL6iwbvMGxiwK4wr7j9t9N ftNLmu0jrUKUaYiBWsTkEASs36+xR6D2k5GCIxTiYTQYJKIliv6OApw9I+aZL70JQTxj06 5W/idbWvR+m2n0OcznWg/3qwXCnd9Cg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722591495; a=rsa-sha256; cv=none; b=Cd2Ln5rT42X/DZuYJ7hoT0v0tx2eYxkmEZ/hqTyQHlbto2M0JoxFVVauUedoANvlD0FWiC M2ulwurjNqYpQTIpjXs7DqTPcplpd68Z4HNTRCWlXmGSxzcfny8r5yidCFFNb8PBIMVNyk b2qS0ZQ60ojSjrfw3aAKjs7Bn6LYFqg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=proton.me header.s=protonmail header.b=VV3uBCnl; spf=pass (imf04.hostedemail.com: domain of benno.lossin@proton.me designates 185.70.40.131 as permitted sender) smtp.mailfrom=benno.lossin@proton.me; dmarc=pass (policy=quarantine) header.from=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1722591551; x=1722850751; bh=m1QNeER4/O9Nb9QxsEYXTwhiESfbBDeW5e0hMJz/WCw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=VV3uBCnlJPNxvWs14rOC+xZdu5TqRnHJA+phOt1m1hgOQ/AsUyRPkYre4cie7TpKN W43niQXnjvnTKI29yuLtUqxcYbp372Jmt9x6GWLILBXP5WaXoBQ3JpKezeW661zadL kc0qrOQTy2mTwUwZnJiSiFjvsGW16FpSPdpo+o4RoHHte6Z/ERrQcCSr+4dRviRevM LC944B7ROW/Z2+yMkgcXsKY9MbATF7APWS0qBJ0dtxFKHI2Hm4dzxpaQhFIYVP6tK5 vNHGPA6Ug2nK2yX19V17foe5tWnawOuQCuaGFrWIUTzKl2kG4F+BxiQdTBQOT0GUFm bTjrw7HtHO7Bg== Date: Fri, 02 Aug 2024 09:39:03 +0000 To: Alice Ryhl , Miguel Ojeda , Andrew Morton From: Benno Lossin Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Matthew Wilcox , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v4] rust: mm: add abstractions for mm_struct and vm_area_struct Message-ID: <7f31fa8b-d788-4067-b296-9cdf23df65c7@proton.me> In-Reply-To: <20240802-vma-v4-1-091a87058a43@google.com> References: <20240802-vma-v4-1-091a87058a43@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 1eea1a3ef92c701c98da726d04b4cde5a36fbe26 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: zeeyhnwgn54hd6i1cyxtbo997a913jmz X-Rspamd-Queue-Id: 9C30F4000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722591553-819293 X-HE-Meta: U2FsdGVkX1/A7O9fYs2A8fWvchxGCuHHx8sVuRrX691dnbJoumbcLTbc5tTSAofvLprEZT3wjo4te+qvlZWN4VqbxO4thu5ZXh0pmMF4qN6UDQDyC763tDHQPGoGVOqXDRqAKdja+MkUXZ5cVvAoPrt5W0vfi7acbcSXOTQLpiQS2QEKy8fYI388Ld8Lm9g/dblghCn8JPsRQQiC4Y2D2QrhjnOSNgwV9c3djsOzz9gp/z3PBAhFGRkQUsPv0tLa5Naf1eQkb2qVAXXVB0Lw71HfwsjuIfnwKdl2x6A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ggrTscMaXDItrJFjHIWcKrefUMbz9gFXJ9sVWUS3dNxGTf9TmI5CkcLxeqbuhcj2DX+uewREC4eL5Q3Y4Bz9nSnGEx0p5E/Z7Mkg0IL0wnv60xOfSRvnnuT/pKrL 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 02.08.24 09:38, Alice Ryhl wrote: > This is a follow-up to the page abstractions [1] that were recently > merged in 6.11. Rust Binder will need these abstractions to manipulate > the vma in its implementation of the mmap fop on the Binder file. >=20 > This patch is based on Wedson's implementation on the old rust branch, > but has been changed significantly. All mistakes are Alice's. >=20 > Link: https://lore.kernel.org/r/20240528-alice-mm-v7-4-78222c31b8f4@googl= e.com [1] > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl I have one nit below, with that fixed: Reviewed-by: Benno Lossin > diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs > new file mode 100644 > index 000000000000..ec8cadb09626 > --- /dev/null > +++ b/rust/kernel/mm/virt.rs > @@ -0,0 +1,204 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +// Copyright (C) 2024 Google LLC. > + > +//! Virtual memory. > + > +use crate::{ > + bindings, > + error::{to_result, Result}, > + page::Page, > + types::Opaque, > +}; > + > +/// A wrapper for the kernel's `struct vm_area_struct`. > +/// > +/// It represents an area of virtual memory. > +/// > +/// # Invariants > +/// > +/// * If the caller has shared access to this type, then they must hold = the mmap read lock. > +/// * If the caller has exclusive access to this type, then they must ho= ld the mmap write lock. > +#[repr(transparent)] > +pub struct VmArea { > + vma: Opaque, > +} > + > +impl VmArea { > + /// Access a virtual memory area given a raw pointer. > + /// > + /// # Safety > + /// > + /// Callers must ensure that `vma` is valid for the duration of 'a, = and that the mmap read lock > + /// (or write lock) is held for at least the duration of 'a. > + #[inline] > + pub unsafe fn from_raw_vma<'a>(vma: *const bindings::vm_area_struct)= -> &'a Self { I think this also should be named `from_raw`. I took a look at your conversation with Christian Brauner and I personally don't see the benefit of `File::from_raw_file` over `File::from_raw`. To me it's clear that this function takes some raw C structure that represents a `File` and turns it into a `File`. In the situation where there are multiple ways of creating something from different C structs, I think we should include the name. But if there is only one possible struct, then the name should be `from_raw`. Do you think we should re-open that discussion/start a new one on a naming convention for this? --- Cheers, Benno > + // SAFETY: The caller ensures that the invariants are satisfied = for the duration of 'a. > + unsafe { &*vma.cast() } > + }