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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D00BCCF9E3 for ; Thu, 30 Oct 2025 21:27:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D839F10EA3C; Thu, 30 Oct 2025 21:27:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="gj21ihIp"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2345D10E91C; Thu, 30 Oct 2025 21:27:53 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id D51CB43EC6; Thu, 30 Oct 2025 21:27:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C99C9C4CEF1; Thu, 30 Oct 2025 21:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761859672; bh=SVxofZBodQMq2edTAlTFELOdmGnbu0QYSQXYY2Xxvj4=; h=Date:From:Subject:Cc:To:References:In-Reply-To:From; b=gj21ihIpi0Frx5U2DXHXyw0i1BL8GIMyFNGu7SLPiUEQ6giI8X/bCxKhW1d9XjijV us2VQd/o1fhWhogEQdaPAxl0q7Y3G3TkaRGx9H0GwbAlWQ+UFBXxkmbQMfBxdyG66m vQJsQBcqwLjQACSBzNWK3dDxEZ1SNeU9PeaEb6d0udOzREGhhUdHEoN7Shi1sp53LF Ob0Aw/hQxa9GZSfrnpnUSUZIbEv3Q7jIyFFqwrt33vyapJaSJqiU8jE54EvTS0GHUQ hgKKXTrJH5Rt+tY6g2bkpT+boKLByo1R+pokToyeQ7RfbDPwI38X86n48Nu9Hz+Kqv w/Fb3sbEMq61Q== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 30 Oct 2025 22:27:46 +0100 Message-Id: From: "Danilo Krummrich" Subject: Re: [PATCH RFC 3/4] rust: drm: Add DRM buddy allocator bindings Cc: , , , "David Airlie" , , "Alistair Popple" , "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Simona Vetter" , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "John Hubbard" , "Timur Tabi" , , "Elle Rhumsaa" , "Daniel Almeida" , "Andrea Righi" , "Philipp Stanner" , To: "Joel Fernandes" References: <20251030190613.1224287-1-joelagnelf@nvidia.com> <20251030190613.1224287-4-joelagnelf@nvidia.com> In-Reply-To: <20251030190613.1224287-4-joelagnelf@nvidia.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu Oct 30, 2025 at 8:06 PM CET, Joel Fernandes wrote: > + /// > + /// Returns an [`AllocatedBlocks`] structure that owns the allocated= blocks and automatically > + /// frees them when dropped. Allocation of `list_head` uses the `gfp= ` flags passed. > + pub fn alloc_blocks( > + &self, > + start: usize, > + end: usize, > + size: usize, > + min_block_size: usize, > + flags: BuddyFlags, > + gfp: Flags, > + ) -> Result> { > + // Allocate list_head on the heap. > + let mut list_head =3D KBox::new(bindings::list_head::default(), = gfp)?; > + > + // SAFETY: list_head is valid and heap-allocated. > + unsafe { > + bindings::INIT_LIST_HEAD(&mut *list_head as *mut _); > + } Not a full review, but a quick drive-by comment: bindings::list_head has to be pinned in memory it should be let list_head =3D KBox::pin_init(Opaque::ffi_init(|slot: *mut bindings::li= st_head| { // SAFETY: `slot` is a valid pointer to uninitialized memory. unsafe { bindings::INIT_LIST_HEAD(slot) }; }), gfp)?; if you're doing it by hand, but as mentioned in a previous patch, I think i= t would be nice to have a transparent wrapper type, CListHead, for this.