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 26CCBE6C61A for ; Tue, 3 Dec 2024 09:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9678C6B007B; Tue, 3 Dec 2024 04:08:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 916C66B0083; Tue, 3 Dec 2024 04:08:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DDED6B0085; Tue, 3 Dec 2024 04:08:37 -0500 (EST) 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 5999B6B007B for ; Tue, 3 Dec 2024 04:08:37 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0D6D0AE254 for ; Tue, 3 Dec 2024 09:08:37 +0000 (UTC) X-FDA: 82853071854.24.AF8A6B8 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by imf28.hostedemail.com (Postfix) with ESMTP id 091F0C0007 for ; Tue, 3 Dec 2024 09:08:18 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UN1S2bRj; spf=pass (imf28.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.52 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=1733216901; 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=cFzvdgxxhPyYuZGDVV6pnwFjLTQZ9Vw8KV9E08J3sjM=; b=JEWxLmGwSIeF8NW4CjpCMBBSBAY09WB0HIEVSolVsowShDscmj86f+IcmC/ztk0uQg261Z ukRENlpWpgxCnQ7QRKm5uvjOOhD1hprXbrQyVFvLeWP92iGhqgtZPAauClvtmevWOPacwR UnBkJ1H+e5Am5ej6LIup51MeBU90pJo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UN1S2bRj; spf=pass (imf28.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.52 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=1733216901; a=rsa-sha256; cv=none; b=QVO4fxlPDbFEuwGzd3SyGJPcVjx2vz+3ZUimDr1nhzcbqFTzfmwumWMpPk+tsNQSC2y/it GoSWbRGnQykqNCccavTD9iGfkjR0zN+FDU9J1hr4fW1obdUond2irEFOPnCEUz9BKXiN4y fESjhQGECa0re6J4WSt2FklYFhkuVNk= Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-385eaecc213so1297463f8f.1 for ; Tue, 03 Dec 2024 01:08:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733216914; x=1733821714; 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=cFzvdgxxhPyYuZGDVV6pnwFjLTQZ9Vw8KV9E08J3sjM=; b=UN1S2bRj75mPDDAQS2rMbSulgU2h4+3UJEjSZCGlCZGs20lw1/kRdV5Kav0hxSDiOm 9dBG+h31gv09ajelvALO9lA1gfPyA8+ca8KTt1EnYjBYz/lTpH5prfBDplthrJnbf7Gr Z7Oc+Ty9om+NmRynNcW8cDvbDHDGBKQpXLnXhgGO+s40NJbvZ3Wj3/i1eE1FlfDoM+oI zJfcct3vSdwcwb0f8D6CzmykRPV7Q85ysz8SXx5+dsGfoFel5uGvfnTpoLfpLDdhkijG BRh9+OvdGktKlwHqdQvykvBJwZr9sG4Q9SqXE+L5SQSFSazmIz4db6VnkE0qmI4SeBYv QNzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733216914; x=1733821714; 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=cFzvdgxxhPyYuZGDVV6pnwFjLTQZ9Vw8KV9E08J3sjM=; b=Os4UlRw3xcpu47aFY73KjoYIFQHYisZKL/cFuPpoj8bjqTbx1baHLf+cwee6RFiSLu Y7txgUoBqwP2iVUbmaLaaR2+KFwAkWbMGpkaHMETpTKbGlWmRxy/9hZJPOJdRDpMwPZF eyt1WPzzA3Buq0TsWoEomDJ/eih+14r2nud+NaM25FdtNGcmqsScphLqqqy3dKSpTKUg FKbq7+ZamwTLn97IUKbAYPQ4hskc57zN6hAY9ZuPK6jNT5GL7itOZFqcxAg2jq0717Yq jx1DYJYNE0nY3PGBaePUxfNONM01ptYT65zkxZrGe/H/MBLuNQsrrWTAntuSqbam50eX 0MTg== X-Forwarded-Encrypted: i=1; AJvYcCXtTmvvOKVCqi2zPzlrYwc3L9Cn/G6mLp3AP2ST/lJMXfQXXnhRsURcbb+3JtZHUI/xHk/mXNxKlw==@kvack.org X-Gm-Message-State: AOJu0YxJ1R1xc/0ElhC8mfRe/p6hHkkVRutWNQnscNchzkzm+QSyAyrO fGc+qI7u0HFhAXTy4TKedQWc9Qj0VN7SFRT22a/S0peud+7afnenMfShCy1P29TlY/gwfGP1OLT 9rGahl+4DpvBVTMd3b0sw2ia/DorLfDRyGeM3 X-Gm-Gg: ASbGncvQVqGAcaCzS9mB+kPKZ79eHU8TgtiW8QHW1U++RjRXKFjLklRikOW+iQD6ykB b2RPYaV7GTDA3LTgr0uE7sVbJ2aUq64eINamYVpjBkLV7dqNpJxOzmg0WfXcoAA== X-Google-Smtp-Source: AGHT+IHhYrDB/wb1xEJctCPoLD5SdDr7fE6pSh9gwJ2FOr50D60Fh2pWUtTRrn/qZKQFAckFbG2l+/EGK8cyVIZsKZI= X-Received: by 2002:a5d:47a7:0:b0:382:45db:6a1e with SMTP id ffacd0b85a97d-385fd97edadmr1314617f8f.14.1733216913503; Tue, 03 Dec 2024 01:08:33 -0800 (PST) MIME-Version: 1.0 References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> <4c58b3b7-0c2a-441d-9b2c-7be65cb39bf2@asahilina.net> In-Reply-To: <4c58b3b7-0c2a-441d-9b2c-7be65cb39bf2@asahilina.net> From: Alice Ryhl Date: Tue, 3 Dec 2024 10:08:21 +0100 Message-ID: Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings To: Asahi Lina Cc: Abdiel Janulgue , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 091F0C0007 X-Rspam-User: X-Stat-Signature: dcosu8zfs1579688pog7i9cz9bej8gjw X-HE-Tag: 1733216898-244083 X-HE-Meta: U2FsdGVkX1+fw2uXOegPBN9Gn93JuJCfKZFQ2qPIcpMPgsm+o7/l3vu0AS4nB5ARNXB6f1oqK8zrqq7W65Q5Mj7eSO9gxb08HLzWnBnwOH4dbQgqK7bkrffbr52WeA+1imXoYv/osqD493XJjgtiSKUdhXCdFNGKrES/7tGtgD5J9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v1L9ClUM5EnK06/sBUaoS+fjaFAubkoWS43dC9xiEHvxpsWJtj5es4Rz7ZvAiNaeSef7Wp6dcUEXzjbSfWErL1MTyJuDcY8AbTD644Xq6bqL2dlqx78g== 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 Mon, Dec 2, 2024 at 1:03=E2=80=AFPM Asahi Lina wrot= e: > > On 11/19/24 8:24 PM, Abdiel Janulgue wrote: > > This series aims to add support for pages that are not constructed by a= n > > instance of the rust Page abstraction, for example those returned by > > vmalloc_to_page() or virt_to_page(). > > > > Changes sinve v3: > > - Use the struct page's reference count to decide when to free the > > allocation (Alice Ryhl, Boqun Feng). > > - Make Page::page_slice_to_page handle virt_to_page cases as well > > (Danilo Krummrich). > > - Link to v2: https://lore.kernel.org/lkml/20241022224832.1505432-1-abd= iel.janulgue@gmail.com/ > > > > Changes since v2: > > - Use Owned and Ownable types for constructing Page as suggested in > > instad of using ptr::read(). > > - Link to v1: https://lore.kernel.org/rust-for-linux/20241007202752.309= 6472-1-abdiel.janulgue@gmail.com/ > > > > Abdiel Janulgue (2): > > rust: page: use the page's reference count to decide when to free the > > allocation > > rust: page: Extend support to existing struct page mappings > > > > rust/bindings/bindings_helper.h | 1 + > > rust/helpers/page.c | 20 +++++ > > rust/kernel/page.rs | 135 ++++++++++++++++++++++++++++---- > > 3 files changed, 142 insertions(+), 14 deletions(-) > > > > > > base-commit: b2603f8ac8217bc59f5c7f248ac248423b9b99cb > > Just wanted to comment on an upcoming use case I have that will need > this, to make sure we're aligned. I want to use the page allocator to > manage GPU page tables (currently done via an io-pgtable patch and > abstraction but that's going away because it turned out to be too > intrusive to upstream). > > Since I'm dealing with page tables which are their own tree ownership > structure, and I don't want to duplicate management of the page life > cycles, this means I need to be able to: > > - Convert a Rust-allocated and owned page *into* its physical address > (page_to_phys()). > - Convert a physical address *into* a Rust-allocated and owned page > (phys_to_page()). > - Borrow a Rust Page from a physical address (so I can do read/write > operations on its data without intending to destroy it). > > Conceptually, the first two are like ARef::into_raw() and > ARef::from_raw() (or Box for that matter), while the third would > basically return a &Page with an arbitrary lifetime (up to the caller to > enforce the rules). The latter two would be unsafe functions by nature, > of course. > > I think this would work just as well with some kind of Owned/Ownable > solution. Basically, I just need to be able to express the two concepts > of "Page owned and allocated by Rust" and "Page borrowed from a physical > address". I actually think the Owned/Ownable solution is even better for what you need, because having a borrowed reference to the current Page abstraction is pretty awkward as it assumes that the page is always owned. Alice > This maps to pagetable management like this: > - On PT allocation, a Page is allocated, cleared, and turned into its > physical address (to be populated in the parent PTE or top-level TTB) > - On PT free, a page physical address is converted back to a Page, its > PTEs are walked to recursively free child PTs or verify they are empty > entries for leaf PTs (invariant: no leaf PTEs, all mappings should be > removed before PT free) and dropped. > - On PT walk/PTE insertion and removal, a physical address is borrowed > as a Page, then `Page::with_page_mapped()` is used to perform R/W > operations on the PTEs contained within. > > Tying the lifetime of actual leaf data pages mapped into the page table > to the page table itself is a higher-level concern that isn't relevant > here, drm_gpuvm handles that part and those pages are not allocated > directly via the page allocator, but rather as GEM objects which > ultimately come from shmem) > > (Note: this hardware is always 64-bit without highmem so those concerns > don't apply here.) > > ~~ Lina >