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 A0E9EC02194 for ; Tue, 4 Feb 2025 18:39:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EA9228000E; Tue, 4 Feb 2025 13:39:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19A3D280008; Tue, 4 Feb 2025 13:39:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03A3928000E; Tue, 4 Feb 2025 13:39:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D8B7F280008 for ; Tue, 4 Feb 2025 13:39:37 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9184C4A1EC for ; Tue, 4 Feb 2025 18:39:37 +0000 (UTC) X-FDA: 83083125594.02.35956F9 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf23.hostedemail.com (Postfix) with ESMTP id 4C8C9140016 for ; Tue, 4 Feb 2025 18:39:35 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=HcrHr4FV; spf=pass (imf23.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.222.181 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738694375; 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=NIOzsVL38g1sJ/ZUBOZhRNBuZ1s1V6W+JXIpoF2R4YY=; b=aOIaDoqB+tMgcRvAA7qwHhQyxmsUfahvjBbYgKS/AM22PHNgUk0jEx+xKcrYF6kN9dt1Lg lDDr+DGqjGn3ZBTQtNmagbOsF8iGSQeHJM1f515cW3mi90b+T93zu0KBeubuWqPBDM66co I3w/wxWnkOWfKNpXOLpQuacFVg2VlZQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=HcrHr4FV; spf=pass (imf23.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.222.181 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738694375; a=rsa-sha256; cv=none; b=PrM/iZ9sdG5p4lr9AX6SVytawHXzap9E+7jHRF59JA/OhDRp8iagYGHnClcXaB86MY5hzf XBWlswy0rfSuG37r/FDAyBwbw/2y9ImNPeZTpo3SwgTBroNvDKMwrD0vRfsG2CLyjruRSY vc/0DgbhCn1HeMESWuc1hc2eKMMK/dw= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7be8f28172dso305317385a.3 for ; Tue, 04 Feb 2025 10:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1738694374; x=1739299174; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=NIOzsVL38g1sJ/ZUBOZhRNBuZ1s1V6W+JXIpoF2R4YY=; b=HcrHr4FVc1OTzMHHN3Gp2gy3YeBPg5mvR4uxJSFv/eTUl7mzgLBgOg5PuIjSRA++Sk E8KZGKvUByJop5LlOfWRUn6k/C/BEhOgj9CLquboBDexaZDKNa5rVSdHTWuiiLBS9u+d 48JsCDMVTB4nRUpN/MfAR47Rp6GotjG7/9lfyOt+U82Je6huNCElW4qp7NH6JmzbcJrl 0w8qA0eFqy0a++JtSj3a1eMO4YoEiUMYMth8+TIcBsMFLVkFyTHv6B6YbMnhDdNkBpfU avkFHMh995ns8zFo0rsTl/dpNXVgbu6jkwNCJDoU+mwsFCe8F3QTSHSTkaW0H94AuKEF OFMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738694374; x=1739299174; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NIOzsVL38g1sJ/ZUBOZhRNBuZ1s1V6W+JXIpoF2R4YY=; b=nCfwOnzVCd9vts4by/H1U5hs7UwJKz3VRqNTE0cHxEzGfvrg1kxvxR5N2RRMrraxeV qQ/Dm9YNiohQjbfh6egPT23nLFFJB5o5ofoAQCJGUFpiRLcxkk3HkNEGt84BjL2rEjoC E80kEzTGyWuBl6yTFpKpWWmS00x8+vOrKrzNiaGWkYXMfNtHdkoQ6P3erTzOc7nCI+I3 v0XiGt4KjjSMlKVTTOiWCHm7rvmfLbkeCTGpFqnXS1H3ZJ7WWZzRxX00GCj79TILo/3a ivwnMjYBUmPEHG1qEGifA1Fn6s0kUFh4KQ783xO8hJLJZHZFuvJqJZPaPCiLSma3i6Eu X83A== X-Forwarded-Encrypted: i=1; AJvYcCUgSwOQwlTMlyDztb/+Iu2MlKYYitAFq70ITotUhSy8Q7+9CV7MfOEJLyxschh9NXnVSDPQPN0QEA==@kvack.org X-Gm-Message-State: AOJu0Yy4BGNxkKQP+ZzFl4YB7y/GRsJnZu1GSazMdnFol0BnV1zOMts+ aCZ1HhtZ1kr7ybnyttknW7GVke5CH9QavTTSCsI7VE/FV9ndGPq5aYQC9yw5azg= X-Gm-Gg: ASbGncvPGaQtRjE8tbLfxnWQ/4pIP+By7egSSovUl9yBqx9RpTxBouUvGweTJoLjCbz YNVCl+7wjB1SVTD9BQMvXWnYIoq1tG9//M5Hoja0mDC1X7uCQ52sxjOAnK2/vS04x3fe+2N8vTX t0v2xNqPyYotpJ2sJgtJggvje9As1duJqcmhNYs5H+lrCDQ/uz3rHjm9g88bQiKzHwbSBsVawKP oM8fl3uZqlyZfwz84oQoCcYdBfwQy+me8xb4Dh9cAOUsGyTdHg5SRghlhWHefmKl0jYsgB5vrjE p/PmhQJuFem0yKpT5tmIUHKAh14Q/tRb7aegfo48HUppUdekJaUxS9pChlNEa/vW X-Google-Smtp-Source: AGHT+IGe86LJbhfodbSk2b2jGfTFxFUtn8so+wGv/gOJaU4HL5gvynsh/jzDxiFtVbtWWBBV/9+02A== X-Received: by 2002:a05:6214:2385:b0:6d4:22fc:ce3e with SMTP id 6a1803df08f44-6e243c7e125mr344942586d6.44.1738694374325; Tue, 04 Feb 2025 10:39:34 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-128-5.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.128.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6e2548141b5sm64420416d6.39.2025.02.04.10.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 10:39:33 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1tfNpd-0000000CBTB-0Jbn; Tue, 04 Feb 2025 14:39:33 -0400 Date: Tue, 4 Feb 2025 14:39:33 -0400 From: Jason Gunthorpe To: David Hildenbrand Cc: Asahi Lina , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Jann Horn , Matthew Wilcox , Paolo Bonzini , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , Andrew Morton , linux-mm@kvack.org, airlied@redhat.com, Abdiel Janulgue , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev Subject: Re: [PATCH 0/6] rust: page: Support borrowing `struct page` and physaddr conversion Message-ID: <20250204183933.GJ2296753@ziepe.ca> References: <20250202-rust-page-v1-0-e3170d7fe55e@asahilina.net> <1eaf66ba-b2d3-448f-938b-913f17ca98a4@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1eaf66ba-b2d3-448f-938b-913f17ca98a4@redhat.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4C8C9140016 X-Stat-Signature: nqpn7rsgp3dnxez1cs8ytccku18bsgzb X-Rspam-User: X-HE-Tag: 1738694375-39765 X-HE-Meta: U2FsdGVkX1/DqFKepZVY2GQZoxSiC0QeGX0RgT3UAaLnDK9XvA+z8jLoPiuCgHYXzhQv+7sz74I5xUQkKYI95NpeHXAl2AWLItUsg5mat+aXiLNfwZTR3d51rFCsZXHLoYDvl6H6f4vjbvZEBZLSWrEpGRoeF2mxBSFYvuSufvKOriSzGSW6eC83apfgnfpn7V8ZcAcqm6a8OdMUESPvID/J9ww8+WX+mr8jbyrZRIPARtEBiHK2y4CVrHubv+1HWbjvcKfZ6SsJfXgvTOfHnLc6okiHStZzRnaH4jSsm/atLc5icahxbo+HDfjVg1xqfvKkWCU3g4kpExowGLCx14igtkzhiiDv1sK9yQWCbpZIfEuQyXdgLliqxzj0bsn+pcd7j84XBk/9rVjlZgDZL5pVUdVQeHJRYr1H7eee6hw0ijL6NjMX2+euHLIjC7Hq/E9efu2LZoPBXWGeyWh3TOmHj+mY5abK4vXw/qJAmpDNYD0Jb0zbw0i0Vvsb0CsXYSORkctRyH/HrXicmGLRzKLodTnFuImk+iGbEylw6ImtzbtksAKGhPiOyeslZPxyM6P0NlbUehBl6MqJV066wfYFAuZwSV/ZLFt3jEVeVGuW82Mxu8kxKDA79kjB0WWD5hWd1ddQMduFC1ag++ytmCpXbkrSAc3u4nMdTe3WpSbMU92bSlralc8KRYNXn8i43DW/WXJ8VrsXldX4MaRQqjCiX0HcF1y0mDCaLbJJd+8lSdwMT4oZAeS3DJNLi21CnZ+/KBU9SLNh2fyNsAjU6U/Ge6YiZPbZP7A5kJcdKbwfD7+17vNlo414pvhYeZoxvSK3hv6TX0ldQVP5cJzmmuGTgrF46zUaITtifJDzEUflDRlWzHndGX4T0oCk3Yk2JNAANiJm3pFh/K6T9XJmxItFegsx4CDeR9qZhdk86ECzpqGyKKpHEJTE+4BV0TA4JCQUXU/ZcpEiYyUGKx/ x0OiLLrk vvQjPTUw/7cy9+1e2c1Du2/hOB2KJgp96RfgdelGuE+7841e40tzcm5tN6VzBXoZcytXNP5efyDBFGNyX3X+5e5fSm62SBIICd+ZlnrsrQJi43X8k09IG4yvlOfTyULgJz6YvWuh6/fxNfMvYibZstXKVLqPrmlSNOaCP+7fwqyO7PCsz95GZCYU9OgYouUHkyPMsW4HqAdt1sBNPE4sWtmdZHmgbnCs6qKyLsWdmjoD4T3G+vnp7Leg1cYsPyqp65yTsM2V9Mwrabi9+ex+Ul/1nz4Z3OZqmY3EPKYDwl61x2RzDcPoMNjQGefOG/bQnUyXxJOmLZ6T1hciQk5ab4gr3+yOSxN4oArg+weN9FC1P/H49yJ44+uyT+/oaMKJGQln7twPXhRwGdZ/Nv+Ru0CfvKA== X-Bogosity: Unsure, tests=bogofilter, spamicity=0.493523, 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 Tue, Feb 04, 2025 at 11:33:24AM +0100, David Hildenbrand wrote: > On 03.02.25 10:58, Simona Vetter wrote: > > On Sun, Feb 02, 2025 at 10:05:42PM +0900, Asahi Lina wrote: > > > This series refactors the existing Page wrapper to support borrowing > > > `struct page` objects without ownership on the Rust side, and converting > > > page references to/from physical memory addresses. > > > > > > The series overlaps with the earlier submission in [1] and follows a > > > different approach, based on the discussion that happened there. > > > > > > The primary use case for this is implementing IOMMU-style page table > > > management in Rust. This allows drivers for IOMMUs and MMU-containing > > > SoC devices to be written in Rust (such as embedded GPUs). The intended > > > logic is similar to how ARM SMMU page tables are managed in the > > > drivers/iommu tree. > > > > > > First, introduce a concept of Owned and an Ownable trait. These are > > > similar to ARef and AlwaysRefCounted, but are used for types which > > > are not ref counted but rather have a single intended owner. > > > > > > Then, refactor the existing Page support to use the new mechanism. Pages > > > returned from the page allocator are not intended to be ref counted by > > > consumers (see previous discussion in [1]), so this keeps Rust's view of > > > page ownership as a simple "owned or not". Of course, this is still > > > composable as Arc> if Rust code needs to reference count its > > > own Page allocations for whatever reason. > > > > I think there's a bit a potential mess here because the conversion to > > folios isn't far enough yet that we can entirely ignore page refcounts and > > just use folio refcounts. But I guess we can deal with that oddity if we > > hit it (maybe folio conversion moves fast enough), since this only really > > starts to become relevant for hmm/svm gpu stuff. > > I'll note that in the future only selected things will be folios (e.g., > pagecache, anonymous memory). Everything else will either get a separate > memdesc (e.g., ptdesc), or work on bare pages. > > Likely, when talking about page tables, "ptdesc" might be what you want to > allocate here, and not "folios". I just posted a series to clean up the iommu code that this is cribbing the interface from: add an ioptdesc, remove all the struct page from the API and so forth: https://lore.kernel.org/all/0-v1-416f64558c7c+2a5-iommu_pages_jgg@nvidia.com/ I strongly suggest that rust not expose these old schemes that will need another cleanup like the above. Page tables just need an allocator using simple void *, kmalloc is good enough for simple cases. Drivers should not be exposing or touching struct page just to implement a page table. Jason