Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp208590lqp; Tue, 11 Jun 2024 01:53:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW8Wmma/5LtrnvKGZWQflabu6VioY31W9XLPKOrfihI/pHKZ6GCMkGMetd5Bo1BSfi7IvS4iK20AkNmkAtkdInLghv5wlgse4pQr8dHLw== X-Google-Smtp-Source: AGHT+IGaMPobDhtOjGYUGpmJOlgzO4uHHCvBezyU6x3Ea7Si8x9FQzhDzqsSq1OqLaELyKi/JfyL X-Received: by 2002:a05:6358:3a1c:b0:199:2a1a:19d5 with SMTP id e5c5f4694b2df-19f1fe292d4mr1427619355d.9.1718096036440; Tue, 11 Jun 2024 01:53:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718096036; cv=pass; d=google.com; s=arc-20160816; b=V5OoEtb5CUyz5V5zfnWfGqsS/5yNFbSXPiLpearigZjAvYu4z6BI2HOHGEb41EPQIp NNCNKfExMpFNzof50YAqwGXtsaDyNjxU0ZoPOS78N1b/KrjMgxTHvPysIfOlyeoIeP9z qO44ApnQkLd4bktme4cpgPsaVdsZFruiAh41uh1keswmr6L9VoX+dUw8qoBVpxDOvJ8h J3TKLG1Pv+rH43vc7cTJwdkQ9a4yQz5nEP2q3GYGCqUtOitSFUx6FUe0PVeaY1g0l+Dp 8Rkf0fSTBFl0Ex1Z4gYMZqgR5UJX/6ezSSUMi3FU6UOLofp6elGW9Y2X57tNpbN62rAM Y70A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=lWmRJ+DS9QOyVc/Vbdc3INhVnAvdDE8ka30qlfy9z30=; fh=fwHpsTDoH7u8al+6gmlzSzpplBn8Ep/uBTwSXV57Pjc=; b=hgHXL1SfwHJcpDY4JUd/cFSW/lynSEobPzYKf2OU81AvPRi0L18S+iMHrwoTVjk8ki ZF+nW4TadkHXsl3wrxA0PQiqwtTgyPleHr5EArrVMEau9b5Jf20Q6j4aETMAscHMQ+Y7 UTmxpXxqir+JAtxGYn2KcakWAUyl3EBpalfItIS7aBS7pJnfyAyZQsye78ujYpoFCtE+ EKRzc5BVlIh4qcotDKVLltDBkRif9LDAb2a+r36MlcPAJRPtyaOHmvSSFu5RTC6puaN0 RhuVdwP+K5mYGU1xbyhGjoKakiW9NriIiUsGD7psIRBP0M45CCUNtocg0P5cAMFRiLBg kqJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=miaLz83g; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e7c5b0a871si5094017a12.424.2024.06.11.01.53.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=miaLz83g; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209512-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1F98F28230C for ; Tue, 11 Jun 2024 08:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2A4F176228; Tue, 11 Jun 2024 08:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="miaLz83g" Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DBF917554A for ; Tue, 11 Jun 2024 08:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718095895; cv=none; b=fqDWk+q0bVlnNfV3AqOu7B3npclHNSKOgnL4hhEPYOCXnRucnSAKXfRI+9oBOjKmeiL95PEvVxtLf2KYtOT6DQmzngSP0654/Svk786QKkRXTOsYhgVtXADDqltf5CNxjOfhTPjBd673Ii9M68aGvEDfY9FhbUxBq48HxBQ2WFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718095895; c=relaxed/simple; bh=UWU68DxMsnWJ89XSm/fDPJZsxETEh3lhJSfrsW5fAhA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ebxoFVNL6dVdptn4hL78El0szU9I6qYO6DRHbtm3ztqneFs+z2KS6L1+jcrTe3944P8AYjhARXEW5jy0SqkMBWwa/10OewkkG0h9JMEhJVraDK5NkXL2PoDllYP+PIH3UkQCg99p/CDyjjRbTRolDWGHY8IRz0SvQOiv5qqqK9E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=miaLz83g; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-35f2d723ef0so280697f8f.1 for ; Tue, 11 Jun 2024 01:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718095893; x=1718700693; darn=vger.kernel.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=miaLz83gv6NfB94Z6HLCV8X+V8WDSVskQXOezqS4/aBUg8cvSHNQChbdarSeMNadjB tJOMwf00j0EPKbzSWbgt1Zj0Io1K1+JoFDm3+ve2deWoIRiicw7xYVCbmTrG1LGOiOJN lUdnrQ7RfQHGhYegxXG7N/agFRv6SwJ9mnOcbQWrf9NU1D1Yja+Ujswx6NRUGvEgalis vEIS68userFGwLn6Le1Y9iFU4+oAdArn9dMgHRqyFYuYnPDwJhUGGZ+UIdg1c5ZTUSs1 S7dX57cDbfKhcldz/s6IyU9DrA72Fi42P/RQNIbxIcDxBuucEbghFy27LvLrNHej1SiH 7obQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718095893; x=1718700693; 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=KJJ+iJwABF2klvOzL/e0ZantUyf1aEZtTuYyzNqV/Vbmcsz990iBI+BE1KeEI6ltiM 9qIR6Groq1HvXpKrYRH4+Y3mMFdQHMVW7k3qTazr8OUNrM1mo+0PtZGIcKSvGbnyzU+k OXqbi+cr9Vl0q07k0CyWOwOY8WE3NWWQKCs9nOLYw7NaOVq+XVf2Z9EEospojoxiIGrU C872NTNX77PHutCMWWhigtJalwkOpk7R7OZSlbVZRxnskY0ZE4vLxYelYJuIgJh7/zFL NRQP/nh4qqw4/SjeHe8uxADIUCjNsZ49c45jrw0JTS5Yh2IsCL0Oe9G1+/R1mrtsG1Co phoQ== X-Forwarded-Encrypted: i=1; AJvYcCXHVjGAr9BLHo2g14NMhKGl0TQOThoaFsy5CSJ+4qvzDhS466wSy1vVfSrEoGv2PK9dojPd9+Y53ANeqcCD+xCzLo00ddlbbqhgcDah X-Gm-Message-State: AOJu0YyKDUvaRM3ZZECRmmoBKjE3n0mUd8xTVGt1eU9FwOHa5XMR6qzX gQ9mAc/DDpt7k0fmVOHYu2bo7B84U3Gk72mJUFbeiO6VUgTz/EhkQ+Z0hyLtRYKmPVcmdJ53reu 6mKsd7ibs/syk7157qPLsIIiHsUSIAhiQS0B9 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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