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 C57AAC3DA4A for ; Thu, 1 Aug 2024 14:02:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A0A56B00AF; Thu, 1 Aug 2024 10:02:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3511B6B00B0; Thu, 1 Aug 2024 10:02:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F2096B00B1; Thu, 1 Aug 2024 10:02: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 F23076B00AF for ; Thu, 1 Aug 2024 10:02:42 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5CB06A78D5 for ; Thu, 1 Aug 2024 14:02:42 +0000 (UTC) X-FDA: 82403842164.15.48EE754 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id CACB740050 for ; Thu, 1 Aug 2024 14:02:38 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dqMD1JAH; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of dakr@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722520954; a=rsa-sha256; cv=none; b=Dcf2QNnSdyT5KULcx5ll+vrMpf8g47oFrq/FyYnAXbZOS5FhDz1bsCk1t6oxSuHW6Ock2J nZpDRGhyyuolHLgo40FDhuNdEzas8PQgjZCvc5mzgAfZtQ1nfAs4giSCqcsWowZpWlJbUf nmBGOJrc1a2/ftj9WA6KGut9cdaWWJ8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dqMD1JAH; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of dakr@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722520954; 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=56Uj8T7sS1p+JcN6Lu0Go9/DulOGeH7vRN0cFBbSXZM=; b=HzvnWu35K6B6ISUlaNEfd5YkBP7xIfK/OTQwbY2zbThL6+7i+vWUjgCtfi9KvxHQKOllrt vdofenCmvkYQEv7KVcs28o15kxQAE9mOUhS6apK1Y9ZR65gQgDXfA7YCyBE8CL5xFXg9Yy b7Uwpl0F2NmBR1zVYULnVCa6KEiULMI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 45B8ACE19A1; Thu, 1 Aug 2024 14:02:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34783C32786; Thu, 1 Aug 2024 14:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722520953; bh=VdiINaxnbnaYhSdTjoFb4By0McAamaV/qtatA2bkCFQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dqMD1JAHCRf4bPp4ekUD0sWbvUCOfESxAU37GVTDioDHOXUAm0FoaszYBPq9gvUP2 BPpqNQQuSeJw7oK9RNbSc4FUX1H/8jBMwMp2kVPLLozn6afueYG5x4iQink6vb0gzF x4mqERJc8lnrImgMwEZLiYf9njYy1KHSgYRp7vaAZunybAcEwQg9t6G8rB16K6E24B Eb1Qn9nl18SXnQC2X9wTwI8AqG+InYOfQ/cytcFgtFg0vQbuRpBtFzCHRK5XUxUD/8 4qrc40E29sCk11PY2i7ddsM8f1SkE2dKq4APw8DDc5T18KFJ7sgqAW4fm+ANVcTM8T wKfMqhpUsCCyg== Date: Thu, 1 Aug 2024 16:02:27 +0200 From: Danilo Krummrich To: Alice Ryhl Cc: Miguel Ojeda , Andrew Morton , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , 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 v3] rust: mm: add abstractions for mm_struct and vm_area_struct Message-ID: References: <20240801-vma-v3-1-db6c1c0afda9@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240801-vma-v3-1-db6c1c0afda9@google.com> X-Rspam-User: X-Rspamd-Queue-Id: CACB740050 X-Rspamd-Server: rspam01 X-Stat-Signature: rcro3b3enzx7dungtzzi8suzbzkt9ae6 X-HE-Tag: 1722520958-909423 X-HE-Meta: U2FsdGVkX1+pLvgUDAtUU8UQgf4TvfOvcPl6gvJzOATVLxpdND/+xvOZQXhgSgQ/ODsSE+f/392nBjTyzuJJs+A1okKNzGYooQWZcO2yNVFTzJ75dsRGYodTv+PdiZRR7jiKdHDw0tBN3OTG4FSy2mU9qPp7Utvx35kGBAIalXHgW8uJxyK+b7umCUycyjaHiW5SZ71Wzs+8gkDu82XxTtzBQItoVHnJPXEDXtRS+LGEdSbpNiYYTwW0Z5SvTocs2yYA/c/ghmTEhlTUxKpI5XYwgF14Kcf7IShWoe0KKDpKEFLJaZ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uTdWFT8zY0bBsS+DH1m9XyjlXWwUatdvKuuxX8LLOWlT2Z3yCj/lc+9YOWFAIz6TD89pQD1qA== 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 Thu, Aug 01, 2024 at 12:58:45PM +0000, 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. > > This patch is based on Wedson's implementation on the old rust branch, > but has been changed significantly. All mistakes are Alice's. > > Link: https://lore.kernel.org/r/20240528-alice-mm-v7-4-78222c31b8f4@google.com [1] > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl > --- > Changes in v3: > - Reorder entries in mm.rs. > - Use ARef for mmput_async helper. > - Clarify that VmArea requires you to hold the mmap read or write lock. > - Link to v2: https://lore.kernel.org/r/20240727-vma-v2-1-ab3e5927dc3a@google.com > > Changes in v2: > - mm.rs is redesigned from scratch making use of AsRef > - Add notes about whether destructors may sleep > - Rename Area to VmArea > - Link to v1: https://lore.kernel.org/r/20240723-vma-v1-1-32ad5a0118ee@google.com > --- > rust/helpers.c | 61 +++++++++ > rust/kernel/lib.rs | 1 + > rust/kernel/mm.rs | 337 +++++++++++++++++++++++++++++++++++++++++++++++++ > rust/kernel/mm/virt.rs | 204 ++++++++++++++++++++++++++++++ > rust/kernel/types.rs | 9 ++ > 5 files changed, 612 insertions(+) > > diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs > new file mode 100644 > index 000000000000..ed2db893fb79 > --- /dev/null > +++ b/rust/kernel/mm.rs > @@ -0,0 +1,337 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +// Copyright (C) 2024 Google LLC. > + > +//! Memory management. > +//! > +//! C header: [`include/linux/mm.h`](../../../../include/linux/mm.h) NIT: srctree > + > + /// Returns a raw pointer to the inner `mm_struct`. > + #[inline] > + pub fn as_raw(&self) -> *mut bindings::mm_struct { > + self.mm.get() > + } > + > + /// Obtain a reference from a raw pointer. > + /// > + /// # Safety > + /// > + /// The caller must ensure that `ptr` points at an `mm_struct`, and that it is not deallocated > + /// during the lifetime 'a. > + #[inline] > + pub unsafe fn from_raw_mm<'a>(ptr: *const bindings::mm_struct) -> &'a Mm { I'd just call this `from_raw`, like you call the counterpart `as_raw` above. Same goes for `MmWithUser` and `VmArea`. > diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs > index bd189d646adb..143a2bf06941 100644 > --- a/rust/kernel/types.rs > +++ b/rust/kernel/types.rs > @@ -366,6 +366,15 @@ pub unsafe fn from_raw(ptr: NonNull) -> Self { > _p: PhantomData, > } > } > + > + /// Pass ownership of the refcount to a raw pointer. > + pub fn into_raw(self) -> NonNull { > + let ptr = self.ptr; > + // Skip the destructor. > + core::mem::forget(self); > + > + ptr > + } I think this should be a separate patch. > } > > impl Clone for ARef { > > --- > base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b > change-id: 20240723-vma-f80119f9fb35 > > Best regards, > -- > Alice Ryhl > >