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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DEB2C6FD1C for ; Wed, 22 Mar 2023 19:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbjCVTpy (ORCPT ); Wed, 22 Mar 2023 15:45:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbjCVTpu (ORCPT ); Wed, 22 Mar 2023 15:45:50 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445D45D8B8 for ; Wed, 22 Mar 2023 12:45:47 -0700 (PDT) Date: Wed, 22 Mar 2023 19:45:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1679514343; x=1679773543; bh=/v9oDE916vQI/IBBeEPmllUZ4S7M1LCi5CtPdEJwk9c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Iy/Z9x2RKCW3uFBwqlb6XCBDufnSgpVe2ku0e4B8/jlgOnocF9rSWiFWB7hk2F8xu dAZFFtFk97ts3oIquYDFeiSiuhOxkJ9Cq4TeDkVBb5hqJUPPpFznQQKwHK+P/js0OY y3FUwpGU6KFnOxri5s/c5RBYcmAAwkyRy2Buf9OS2kTb+fq8n+fCXNQKvVm+MI+cDH ed1D3ba7SH1l8O9c/eB0tQElFqyy7cvbenM7qlSw6dBKp/xw/ho1znGfDfyF9GDmg9 Tq8VnUSgg5jcZmqjWEgL9szCjTu7bfpYrEvULLGrmfkzn/mUUE/kmq3wfAvKyA2KCk inzzGCew1cF4g== To: =?utf-8?Q?Ma=C3=ADra_Canal?= From: =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , Asahi Lina , Faith Ekstrand , rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, Melissa Wen Subject: Re: [RFC PATCH 2/9] rust: drm: gem: add method to return DmaResv from GEMObject Message-ID: In-Reply-To: <20230317121213.93991-3-mcanal@igalia.com> References: <20230317121213.93991-1-mcanal@igalia.com> <20230317121213.93991-3-mcanal@igalia.com> Feedback-ID: 27884398:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On Friday, March 17th, 2023 at 13:12, Ma=C3=ADra Canal = wrote: > A GEMObject, related to struct drm_gem_object, holds a pointer > to reservation object associated with the this GEM object. Therefore, > expose this reservation object through the DmaResv safe abstraction. >=20 > Signed-off-by: Ma=C3=ADra Canal > --- > rust/kernel/drm/gem/mod.rs | 7 +++++++ > 1 file changed, 7 insertions(+) >=20 > diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs > index c4a42bb2f718..dae95e5748a7 100644 > --- a/rust/kernel/drm/gem/mod.rs > +++ b/rust/kernel/drm/gem/mod.rs > @@ -11,6 +11,7 @@ use alloc::boxed::Box; >=20 > use crate::{ > bindings, > + dma_resv::DmaResv, > drm::{device, drv, file}, > error::{to_result, Result}, > prelude::*, > @@ -136,6 +137,12 @@ pub trait BaseObject: IntoGEMObject { > self.gem_obj().size > } >=20 > + /// Returns the pointer to reservation object associated with this G= EM object. > + fn resv(&self) -> DmaResv { > + // SAFETY: Every GEM object holds a reference to a reservation o= bject > + unsafe { DmaResv::from_raw(self.gem_obj().resv) } > + } There is nothing ensuring that DmaResv doesn't outlive self and thus may ha= ve been deallocated. You could change DmaResv to be a newtype around Unsafe= Cell and then return an &DmaResv here. This way &DmaResv can't ou= tlive &self. > + > /// Sets the exportable flag, which controls whether the object can = be exported via PRIME. > fn set_exportable(&mut self, exportable: bool) { > self.mut_gem_obj().exportable =3D exportable; > -- > 2.39.2 Cheers, Bjorn