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 66C95C3DA49 for ; Fri, 2 Aug 2024 09:40:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F09DA6B0089; Fri, 2 Aug 2024 05:40:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB8276B008A; Fri, 2 Aug 2024 05:40:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D80106B008C; Fri, 2 Aug 2024 05:40:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B9BB06B0089 for ; Fri, 2 Aug 2024 05:40:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 47B7FA0713 for ; Fri, 2 Aug 2024 09:40:49 +0000 (UTC) X-FDA: 82406811018.27.8F4C618 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by imf13.hostedemail.com (Postfix) with ESMTP id 7B70F20022 for ; Fri, 2 Aug 2024 09:40:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=d3oRZ6wE; spf=pass (imf13.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722591570; 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=N3cnmNQwU8pb9rtU5fDhbpatDtKkxxtawqVfHyOA0XM=; b=1gqGCbHqQEPDFZTkcMvkYwbWC2DTbp3rQHFDTFACBvw+l2jntDKYeO1Nd5gU29OWe5A9+4 x0q9M4WzeDU30Mv9SapGCET4RB3OiMSbLF24bvD8lWxQI7Gl+i+7QSvYNDSbycqIAludVB yDZviwMbRb62273NsAzozZjsnVvH1ec= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=d3oRZ6wE; spf=pass (imf13.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722591570; a=rsa-sha256; cv=none; b=P+SBtT5nuowMUGyw7VyLAf3mP2609uPWzg4XCq1nfa6O+7KxdDZOqsZW+TVN+4Wis8CaRk 7uZsQ4I/XYiJhvVGWGz6j9TN2ZR8tcr2eVElpAKcoInkvMPl2kkhOiC5ibMbXd6lVsQLlf mN1mGGvxm/QRqBYqVsRybD6mwtP+IIs= Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4280b3a7efaso53633225e9.0 for ; Fri, 02 Aug 2024 02:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722591646; x=1723196446; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=N3cnmNQwU8pb9rtU5fDhbpatDtKkxxtawqVfHyOA0XM=; b=d3oRZ6wEb0WLEpdx2GUZmX0xbd9ErXoGxebfbundQeXmJ6OWobtPibnXPm3VNmXcwg 05kMH7rdVaA7LUByAOoM71jrxg/sUH+Ep0ZTa4iH0ZjjK/qus8BP53BisCm1imI1Ya/C p6UYsoao2+slwSpqnbYOJcOAv7rkh89ZUcEyBDUXqQLvCb5qw28eStAYKUn4ZAOlfn9g ePwn7Y0+o/VomfGp6BOmxAqq68ZvBMfKIeAPyE+uhWEyoqW6j337FNhmmyDj6Yqj2lkE Z9Fq1bdulDLnwoFA7K9ZE935PolFiB1kCKw2H/ZyeFU8nSDdtJoKbfW3bTOeczrj9X/4 X3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722591646; x=1723196446; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N3cnmNQwU8pb9rtU5fDhbpatDtKkxxtawqVfHyOA0XM=; b=W3qBZUvVM7770KROk0i1hTuHwPWVFIvLt4umkL4swWZBtG/guurlvD/LifavaJbcnx JCffHCfeN31Z5HvJ7OQ7FCt3jiVyC0/hy/5L4yEx79oU6BD+UoPjsl76iVGkp2WkqhMs Fv+HgPcKsX2tgJBIkw9YlIv+moxY4X9EeICHTBvV7isn22h7KrPrH9SrN3ViFder218h EmmOMuTb7jH3AXKbZmsnq+jPg5tc+wZaTKQwASiLBMOjn6tHww+36HMXlZPC6miCv7IA /9DqZu9+kSV9dGmMcWHQO8+IuXB1em+Bg8IPehpYv0/lmc8hnmzepoPB3Mx0qclUsUum F5VQ== X-Forwarded-Encrypted: i=1; AJvYcCXCLHRcoQGTtBZMc2bCb8+2cRZ6gKQQj+y+B5PKGv0AM+DwDISE5n7umg4F6Qz+n4Mx3/uCKBhOWNjiLF1eeHD6FWI= X-Gm-Message-State: AOJu0YwolxOovsPFP1lfMRguhLolybvjnCVE7uRVtjgeNrQCvY6g3DD5 oRgnh2mkoNhi1yBRrqMk6ug+7oZ0Atn009qV8T6HOxzJMKTztnt38m4njRjTp8YnzJff+8hYL7U j0Y3APPzADdhW7C8xol/h/edDtp82Q4IG0lHM X-Google-Smtp-Source: AGHT+IHM0pPYtPqBjGxEPDHbGbmOT0OVxMOnrmAq18Ps5yNxY4TkpjbzkRsvr91o1g46ECl3PRnOq2ueiV5z85Rov2I= X-Received: by 2002:a5d:664c:0:b0:368:6650:fd16 with SMTP id ffacd0b85a97d-36bbc1bcea9mr1780954f8f.38.1722591645457; Fri, 02 Aug 2024 02:40:45 -0700 (PDT) MIME-Version: 1.0 References: <20240802-vma-v4-1-091a87058a43@google.com> <7f31fa8b-d788-4067-b296-9cdf23df65c7@proton.me> In-Reply-To: <7f31fa8b-d788-4067-b296-9cdf23df65c7@proton.me> From: Alice Ryhl Date: Fri, 2 Aug 2024 11:40:33 +0200 Message-ID: Subject: Re: [PATCH v4] rust: mm: add abstractions for mm_struct and vm_area_struct To: Benno Lossin Cc: Miguel Ojeda , Andrew Morton , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7B70F20022 X-Stat-Signature: odaj96p8caz3p84ktwg5d7apyo97b9u4 X-Rspam-User: X-HE-Tag: 1722591647-439663 X-HE-Meta: U2FsdGVkX1+xxcp2zGRRAdI9Ivo8X4rZev77UFZTxZX4GI7Eqt4rixnGjoa7BpwA0XpxrBEdk+Fw5d56H67B8vAQFV7qKMsQesUUkvud6uCVKKnA313U3wvnZxXzOCSCZFyD9DFV7PTrQeJ9J5+Vpl/YQoj+6W6yHEmBpk8lSYIXVNLG0LnN5fdKppjSadd/GXb4sluOD5ZKiTdE442S2ltZLKUyTygKaCDu9WsKb+WmX/dloXlBaVCEAHA1LtRrFSHapnnZLt8h7rRZxihpF8rXzX0mPlSW/EOA9xnyYInJ+aLhmvXhx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ests=bogofilter, spamicity=0.035631, 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 Fri, Aug 2, 2024 at 11:39=E2=80=AFAM Benno Lossin wrote: > > 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. > > > > 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@goo= gle.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 hol= d the mmap read lock. > > +/// * If the caller has exclusive access to this type, then they must = hold 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_struc= t) -> &'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? Oh, I actually intended to rename it here too. I just forgot that VmArea also had a from_raw. Alice