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 C0998C25B76 for ; Tue, 11 Jun 2024 08:59:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D8B86B0089; Tue, 11 Jun 2024 04:59:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 088AF6B008A; Tue, 11 Jun 2024 04:59:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6B556B0093; Tue, 11 Jun 2024 04:59:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C74446B0089 for ; Tue, 11 Jun 2024 04:59:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6CEA4120133 for ; Tue, 11 Jun 2024 08:59:51 +0000 (UTC) X-FDA: 82218010182.19.57D8484 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf14.hostedemail.com (Postfix) with ESMTP id 98F78100002 for ; Tue, 11 Jun 2024 08:59:49 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YMPEYgxg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=aliceryhl@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718096389; 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=lWmRJ+DS9QOyVc/Vbdc3INhVnAvdDE8ka30qlfy9z30=; b=0uCNu7407PFOdUY1L7xjOZF0ZkoPBB6glrzVpPoDBt32vAgkg5MfZxS4aCo3+sLHS+k3tJ OvN5D7pYb75WBj1a9HmDL6F/oMP6S1Zyfr58klgBlkocTdNgYo1sWXObVGXUmieNEnh+hX iVWTA1QZgQbJzY84TavCu2cYJdopdYQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YMPEYgxg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=aliceryhl@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718096389; a=rsa-sha256; cv=none; b=yW6Pzg6s6ziegoZsjaMujy2GqsafWu/RZUUeLWhzXxxH5pP2pasJTaNGOIyUl8jfQH1SFo YeNuTIUhLsn2IGYwLbwQAPruOnFi/O+dNqLwCqoY9HyOxXECDPSvWkU171QpKy8s/0pOdo aL9IjllYdl3SL0OSQlyQyMosETCCQWQ= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4218008c613so6734635e9.2 for ; Tue, 11 Jun 2024 01:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718096388; x=1718701188; 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=lWmRJ+DS9QOyVc/Vbdc3INhVnAvdDE8ka30qlfy9z30=; b=YMPEYgxgmxHOvZaQU19f0Q+cUK3wHZIT4YPTsqp+BLURW2ErA1UdXoHFfPXRwn4LT1 gQrGHZxcvhkEXkQJbFVyPEGCDKZs4bktb0efdyZ1fmw+b5aOInX4WorX5AhVDksZN36W VvClgXLt6r2lj/9rpIpjmEBPdMX3PvRXmeM9WkasajG7e/vxI6EOxkuMpg4DNxJhFN14 DGBW6F00Mdlga+UtSq69Hy837rpATT0dXFRUpHkcX8gjIpqVKOAeUzOMeuCMboFDgS/E ncX61Dnq2H3wCrZokGic2OsNdGpIt85wQy4/+9VU7I6zvPoKohyaLuVFWMKodUs7S+ly PCXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718096388; x=1718701188; 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=lWmRJ+DS9QOyVc/Vbdc3INhVnAvdDE8ka30qlfy9z30=; b=OBLPMHL4yy55rGiOlJ+YNV6nRj350HkvhOl6pPEFUwyaJDcBrE/BweN6NKTfkbXD3I RQnsM6RMVKnXkGhjjgrb22eB8Hf/ztq91ih9YrSDPhjjpQ/DsdXpcHuJKU8KRBhZ8LHC /8s/hxdywRtNBmTlhYfcbd1sjsdq1SEmKJQWqJmQiBCEYcHGEAog52qCbUY2fROuf2b4 Mc4gBJWh7AcBbDxEb1GWbFjLHIjn/aVabqb2y0ToxP6h5zqQ7aMxBHh3ZMvHDPsrwuwr OR6qeLpsTBl0liTEpGKOYsFN84Be7U4cTRbg78sjz4HJzYgRz3nJIJ4UK0qfUndoZ+zH Bckw== X-Forwarded-Encrypted: i=1; AJvYcCUzw0RAvq0PeJ2g5+QL6vp+hbqAtYePcJyY7w6/0ZSu+sisEZQs3wX8nfX71GV4M9NKCn4FGGeKB/ArJFkYUjpMp1E= X-Gm-Message-State: AOJu0YwD6+NcWiujeRduVb3lO0QxvYVF+fWHW0V86DEW+CCWeGdaSJya o5bwyxZU/2K2QLevtia6kjUJZMhP3eja28GntxH5uWgRZQmzZxT6I464d7b0OGr1LjEt0+VrODX dLm4rFZcmqMDI8V53q+GEcOt5NTZ3KqFPzEbWYW3S8Ne2oaBT2abT X-Google-Smtp-Source: AGHT+IHbMb+7XlG53W12WXEF6AXFOPxNGQEg+5JLxaoMvIxZkN5MKxJsr00B1X4JZqpKLyAwyqD2mrvFQITfqkWsnzw= X-Received: by 2002:adf:e74c:0:b0:35f:2b1d:433 with SMTP id ffacd0b85a97d-35f2b1d04a9mr1545251f8f.26.1718095892531; Tue, 11 Jun 2024 01:51:32 -0700 (PDT) MIME-Version: 1.0 References: <20240528-alice-mm-v7-0-78222c31b8f4@google.com> <20240528-alice-mm-v7-4-78222c31b8f4@google.com> <882a4ba5-b0ef-4c21-8167-e2949424912c@redhat.com> In-Reply-To: <882a4ba5-b0ef-4c21-8167-e2949424912c@redhat.com> From: Alice Ryhl Date: Tue, 11 Jun 2024 10:51:19 +0200 Message-ID: Subject: Re: [PATCH v7 4/4] rust: add abstraction for `struct page` To: Abdiel Janulgue Cc: Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Arnd Bergmann , Trevor Gross , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner , Danilo Krummrich Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 98F78100002 X-Stat-Signature: tn1t6befukaieu4o874x6nq4p6tkpuws X-Rspam-User: X-HE-Tag: 1718096389-527476 X-HE-Meta: U2FsdGVkX19vJo9sBy8Q1qVI402qWnO5xrwhUvVFj1Hsncb56+ifHPZcy8zZTxNInfMFYVACZs8fgOP3A78qnzMXgHSF9uZvX3Yiu6+rXGMtFz87E6SEO9T6MBk4/HNyAhyE4uZYABor3RJAw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nrz 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, Jun 10, 2024 at 10:47=E2=80=AFPM Abdiel Janulgue wrote: > > Hi, > > On 28/05/2024 17:58, Alice Ryhl wrote: > > Adds a new struct called `Page` that wraps a pointer to `struct page`. > > This struct is assumed to hold ownership over the page, so that Rust > > code can allocate and manage pages directly. > > > > + > > +impl Drop for Page { > > + fn drop(&mut self) { > > + // SAFETY: By the type invariants, we have ownership of the pa= ge and can free it. > > + unsafe { bindings::__free_pages(self.page.as_ptr(), 0) }; > > + } > > +} > > > > What about cases where the struct page pointer is not owned or allocated > by this wrapper? For example, pages returned vmalloc_to_page()? > Any thoughts about exposing a provision to avoid freeing those pages > during Drop? > > We've been experimenting in adapting this Page wrapper in advance for > page management within the Nova DRM driver. That would make a lot of sense, but this Page wrapper doesn't support it. You are very welcome to extend it. There are essentially two ways to go about it: 1. Change the Page struct to be a `Opaque` and use the types &Page and BoxLikeType for these two purposes. Here, BoxLikeType would be a new type that is to Box in the same way as how ARef is to Arc. 2. Introduce a new PageRef<'a> type that's like a reference to a page. You can have Page deref to PageRef so that they share methods. The second solution is easiest right now. The first solution is probably what we want long-term. Alice