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 07F31D7830F for ; Mon, 2 Dec 2024 12:03:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B4ED6B0082; Mon, 2 Dec 2024 07:03:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 33DAC6B0083; Mon, 2 Dec 2024 07:03:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DE746B0085; Mon, 2 Dec 2024 07:03:23 -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 F06216B0082 for ; Mon, 2 Dec 2024 07:03:22 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 79D821A0BFC for ; Mon, 2 Dec 2024 12:03:22 +0000 (UTC) X-FDA: 82849883592.18.FC860B5 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by imf15.hostedemail.com (Postfix) with ESMTP id F0400A0019 for ; Mon, 2 Dec 2024 12:03:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=asahilina.net header.s=default header.b="f98/YX0L"; spf=pass (imf15.hostedemail.com: domain of lina@asahilina.net designates 212.63.210.85 as permitted sender) smtp.mailfrom=lina@asahilina.net; dmarc=pass (policy=quarantine) header.from=asahilina.net ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733140989; a=rsa-sha256; cv=none; b=S+5BgzZ0jpsI4B/Bj8Y4vbXBdeZIpza/ecHrMJfa+XMz2ofYilKLZFG+I0BDwOIHs6SV5X obbS7brbr967ZCnyvpwEWXu2KNkqKrV2JUQr6ijuALkSyubFn+IToNj9X88BkoCy4JYU85 kmMQwy6u3HSb98WtYVMwCk6JHAQqbQM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=asahilina.net header.s=default header.b="f98/YX0L"; spf=pass (imf15.hostedemail.com: domain of lina@asahilina.net designates 212.63.210.85 as permitted sender) smtp.mailfrom=lina@asahilina.net; dmarc=pass (policy=quarantine) header.from=asahilina.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733140989; 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=a4WsotNrLocqxP4UEviREeVuQYth86IwC3+KHI1vhEQ=; b=2GSWcmr9jU2rcKfa1+7/rbqtw+ERtbWYQAExrERa/kZ2+Mm7HcpZCn+6m4aSgmWXI/I7O+ MpdJUIsbreOqFUe63gAQQlL5x2h4iT0gGbMChDVKYXHpYI70+9sn28AVmsQxyq7KA/mjOM vIN6YQYzW1Xz/SPrrn+V19xSMtfBKjA= Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: lina@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id 9F3F041F5F; Mon, 2 Dec 2024 12:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1733140997; bh=onS7sMEZzhB3hatzLxUuQi9CQ2E6VuzwtA57t/RQsVk=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=f98/YX0LZ94SDNc5clXjsqU6GG73u+HVJXUJuZqNU7Epauwq62L8EQQiNcRUkxt8F K5V0OtD7vncPCPqb3coENjgoyRVcM4KQzwVuG8hPsEK679BhlefNV5jYDr8fGp7vdC TRHGdKbOmakPZAoLa9yGJcwdWtqTecv/CSEfmH2uhP0yC8V8lW2jYdCFnPabNlmSPD sVOhxGRt2qz9W8IomGvcQPXCwb8uJexdPknBWPszkJIiPl+8Ay6Rs0IB71JgOSoD62 v+bHMOsY9zwRG2Gwvp4WkNVr96DGy9FK0a5ETeM3BDcUvErfJNLOkYe5O4ae4Q49At NnygM/rk0Ux3Q== Message-ID: <4c58b3b7-0c2a-441d-9b2c-7be65cb39bf2@asahilina.net> Date: Mon, 2 Dec 2024 21:03:13 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings To: Abdiel Janulgue , rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> Content-Language: en-US From: Asahi Lina In-Reply-To: <20241119112408.779243-1-abdiel.janulgue@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: F0400A0019 X-Stat-Signature: tpityqj8wgwo8t39gcaqumpbu1ga4w55 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733140987-147941 X-HE-Meta: U2FsdGVkX18O4rReB2ce57tOW7vjVKzIyE8DLplvrlhU5ETGpVDca2FIqVYqZ9g0vOxYwx4Vp1Q9CzSlL7eiR6Y/HqNFIBVo+XcanUnXvqjCAkPwi95cD/Kxi0/qUTCIvZ2dQsfCs6HKxXbGmnAr9ny5wBD5z4TrHwi/z0P3TEyuih8cK327roLbgnNWncQ2YovzKE+yMG008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rZAS/rka5jqo/MnqG3wyHAF32ZeRLc3mJrOUmYVLOGFx7IPhlrpFKVM+Kqs2H0K4gsWtqVzb2YmGQo8UPvN1/i9T2PLupDm51iqfA== 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 11/19/24 8:24 PM, Abdiel Janulgue wrote: > This series aims to add support for pages that are not constructed by an > 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-abdiel.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.3096472-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". 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