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 88160C44507 for ; Mon, 13 Jul 2026 14:57:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 514C510EA12; Mon, 13 Jul 2026 14:57:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="O9IgtRRI"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0D5B310E5FF; Mon, 13 Jul 2026 14:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783954666; x=1815490666; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=vGr1Y0YREj7u0VXJVlpLH/+1i6FIEq1VaYnIMWDINsY=; b=O9IgtRRIbt+u4nbaffGFO0YVRhTJGVqX8/ntPclsX6dGFW/51xQj3SKT jpiVazYwvnsCxcd39bJCLgNma9ZXR5Vf77luZ00wzJtStgmp0VpknSUN7 JP6t/u2FzTtB3qBdmC9s1mETjlGY5V2mlqQnen48va6/X6NR7yfdx/E9Y txoxBoZHu+BAzyhMdIiVDwMULYJ+1/vv9F+AS5q/gyDhND1EEOMARXHCK oIEPsBV2/BNwdbdeGrgAgAIrBfI/gyQNLE3Gnrj2NUX6URPfgRhIwxcbI BU53TR5hwX81rOlYA1vgd/cY8LKxROdkCZH/7yHZTeUCCm5dYyN2I8LhL Q==; X-CSE-ConnectionGUID: tMYA7rysSXuac6Da5+nxPA== X-CSE-MsgGUID: dINhVRDSSy21G82cJ86mkA== X-IronPort-AV: E=McAfee;i="6800,10657,11841"; a="95713856" X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="95713856" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2026 07:57:46 -0700 X-CSE-ConnectionGUID: 3QhNCQeIR569pRTugrD7QQ== X-CSE-MsgGUID: ZSNnfrmrTIG8I0oXtwNxCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="251629916" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by fmviesa010.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2026 07:57:45 -0700 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by fmsmsx903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Mon, 13 Jul 2026 07:57:45 -0700 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) by FMSMSX903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43 via Frontend Transport; Mon, 13 Jul 2026 07:57:45 -0700 Received: from PH7PR06CU001.outbound.protection.outlook.com (52.101.201.24) by edgegateway.intel.com (192.55.55.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Mon, 13 Jul 2026 07:57:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UZimCcbyYPB9c+njVrEP0RkZURGdKrkylixTQi48miIdQsJBAEj7ocNOCdGLRxuW/SgqQIem4NNV5RHeQlNtXACBH1PWidSZF1a4msAIzY02lz07GGSbsjHwbhm9hgUg36j+dSShp0f9XdBAebem3gTn0VYlubc6uV7FCSB/orBabvlQoV796cCPB5lztTXInLcupwFPN4DAIPsv0DniymhAsuztNNdXsw+IDFUko3zmnx1puhcyF5p5DkCuCB5+pb2Fx4GMw5uVB02Jto+LyN2Z5fIFTxihEdAEygnK68xueyUOhBOYE2YURxohdlZLsuKGMkP/yaDCwAnuZ1sGmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jKG/PPgJKnF2REyCXY2MNdYTYcHNkRvGNZrcWD+S5O8=; b=sKA1ejNFDs5YfecLkikPz+KCs3UOKybWeYbnA9Y6eC7o9yu/WCEWu4Tl726j/kmlxt4wMXs5vNmD85yfUUC4RweeDUDEEeS+AFzW6uFb5C/aC+P+s+/HvgTNIIzz1pyAuiFoLu2Gtccqv0vv67KC5Tlc/ALnj662br6KXXv+DmSu79TvgF1ZF8wPxq2teubvxcKJk4Z2mLfWQWVo2cDgGE9gBCGuT5NTCXBO0eJWKkDn6kZPOJ67a01z5mo4xSbXTEfuG6qXLTc5Nr41Wy9yslaPchpk91EfHtJt44/rK7YasNU8aPx4PgzOJiEtMMp9Mmj71dV1+BrRbg/U7yDFQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from PH7PR11MB6522.namprd11.prod.outlook.com (2603:10b6:510:212::12) by CH3PR11MB7324.namprd11.prod.outlook.com (2603:10b6:610:14f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.202.18; Mon, 13 Jul 2026 14:57:41 +0000 Received: from PH7PR11MB6522.namprd11.prod.outlook.com ([fe80::e0c5:6cd8:6e67:dc0c]) by PH7PR11MB6522.namprd11.prod.outlook.com ([fe80::e0c5:6cd8:6e67:dc0c%4]) with mapi id 15.21.0202.014; Mon, 13 Jul 2026 14:57:41 +0000 Date: Mon, 13 Jul 2026 07:57:38 -0700 From: Matthew Brost To: Christian =?iso-8859-1?Q?K=F6nig?= CC: Danilo Krummrich , , , , , , , , , , Subject: Re: [PATCH 01/12] dma-buf: Add reference counting to dma_resv Message-ID: References: <20260710190752.2355-1-christian.koenig@amd.com> <20260710190752.2355-2-christian.koenig@amd.com> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: MW4PR04CA0289.namprd04.prod.outlook.com (2603:10b6:303:89::24) To PH7PR11MB6522.namprd11.prod.outlook.com (2603:10b6:510:212::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR11MB6522:EE_|CH3PR11MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: 513c015f-fc27-4de3-8720-08dee0ef165c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|7416014|23010399003|376014|18002099003|22082099003|6133799003|56012099006|4143699003|11063799006; X-Microsoft-Antispam-Message-Info: z6cjybvjv9WxQnzd6NDuOmCDH+NwDxy3sBhLC0hA+prj6kFMXtKSSbVZ9H5JxtzRdyCsLCNDXcaBszqnUIxvlds1+HO3Y3M5IEmd/pUnpTQwZ9l+Id6zc4E09MgSIfXIf1XZ3kofCy/dKjyirw9zmBSEkQo3Bkl2NSbSqjc6Dgca9iOeM4DaJk/Czqo2NJ9mOsObvmrPHJWFbo3mJWa3HLSXfL3Oz4XMYMtjCf0WaeG2wvoqq7Xu6AJmNhJN4rmJs3pALtqWQxywpx3vAhLmqO/u8TvRmPrKHMoTdGwJRBS2AAoQie2N7Ew03NDyR9N3xZmP9ifLdYl9/WXsDOhL6oKE8KIw0DJ1FhnDAxMiZou4ML0GHq1pPDTUt9yAdUtA5hsY+zRfai5gulcLshwC7za/7z8Zgds68iMVQlXdBO51EEZdyWH6K22Upj9hLSyDFpsJ5leBWQ3CQAXhQvbZil2cfK2slQDbZcr67mrmL+f2FbVOPIrImfn8GKCAfdiyHoAQMC+XarUFtfbhjViby3cxk107QxvDrP3fEKYCBlNhM8gR3NYj3WtqLyD7rt6uxog6l9OUz4DnwvBxApoM8d2kdh57oGGfK3+l+peJvJNCoMyRchFkDO31GprbM3BvFc6mi0n4T4OR/DT0MscUakFlGMYrZcglWqbcWlElgY4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH7PR11MB6522.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(7416014)(23010399003)(376014)(18002099003)(22082099003)(6133799003)(56012099006)(4143699003)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?eH2mnTaVBaV/L8J9v/o/JMVts3phvJglkhhgEuLFfv5smWs5qhv3Z+14p8?= =?iso-8859-1?Q?khpD8t9+7eYYsAvOlpKNd/k51SVtj7qrXA3w4eIQQFkM6Xj5zNBtifbhJY?= =?iso-8859-1?Q?o/L1LN3dlJdejnqevl3oiw2xykkf9V6aTyXxDebu/KM1qTDNvS2zSWdLVm?= =?iso-8859-1?Q?CJ1Lx9WvsIMru0sjvPujSlcjuFHCVT9B+W/PBARc37IG2I0PQyHy/kPdxZ?= =?iso-8859-1?Q?YhdZbCl/8TxJOgxJYj+ny21k3i7V367tHQ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MFThe2/GvSKgvlsfgTaOr1KlgMZZgCRHEqQfo6Xd2FQ5gE77LE8L+YzQGumOCKnPJsmg4jsjGtcWOKw1Zm4qVe4K+L8APkpawjfwMqbDbcqjTg== X-MS-Exchange-CrossTenant-Network-Message-Id: 513c015f-fc27-4de3-8720-08dee0ef165c X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB6522.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2026 14:57:41.2616 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: g21noJe9wLacBqzf/vvDn5MaoCqJp12Apzo36aX5rNYbDo655tnbnDWO5vnu08AnvOQMWXYq32Yi5oXxp7MNLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB7324 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On Mon, Jul 13, 2026 at 11:25:43AM +0200, Christian König wrote: > On 7/12/26 21:51, Matthew Brost wrote: > > On Sat, Jul 11, 2026 at 03:10:58PM +0200, Danilo Krummrich wrote: > >> On Sat Jul 11, 2026 at 3:27 AM CEST, Matthew Brost wrote: > >>> On Fri, Jul 10, 2026 at 08:52:41PM +0200, Christian König wrote: > >>>> This provides clearer ownership semantics and makes the code more > >>>> maintainable by removing the embedded allocation hack. > >>>> > >>> > >>> This looks a lot better to me. In particular, I agree with the last > >>> sentence in the commit message. > >> > >> I have to disagree with this, it is the opposite. As long as the struct > > > > Daniilo is of course correct here, completely missed this when I looked. > > > >> dma_resv::allocated fields and the corresponding semantics exists, this does > >> result into less clear ownership semantics. > >> > >> When the dma_resv is embedded in another object the reference count becomes > >> meaningless. If the object embedding the dma_resv is freed it doesn't matter > >> whether I have a reference count, it would a UAF regardless. > >> > > > > Yes, I agree. The allocated field would need to be dropped to make this > > viable, and we would disallow embedding a dma-resv object into other > > objects (which I believe is the suggestion). > > Yeah completely agree as well. This was basically just the first hacky version. > > > This doesn't look too painful, as I can only find two instances of > > embedding in the kernel: drm_gem_object and i915_address_space and > > handful of stack variables. > > The use case in the TTM BO deletion path is the only really ugly one as far as I can see. > > It uses the drm_gem_object embedded reservation object to make sure memory allocation can't fail during deletion. > Can't you just preallocate, during gem initialization, what is currently the embedded reservation as a separate pointer, drop the reference to the shared reservation, copy the fences, and then perform a pointer swap during individualization? Maybe I'm missing some details here, but when I briefly thought about the individualization, it seemed fairly straightforward. Matt > We need something like a dummy delete_resv allocated for each TTM BO during creation or something like that to avoid this. > > But that in turn means potentially means taking a look at all TTM using drivers if/when they use this in their deletion path. > > Doable but a bit more work. Probably also a good job for AI. > > Question is also who is taking that work? @Natalie can you pick up from here? > > Regards, > Christian. > > > > > Matt > > > >> It is misleading (and hence error prone) to have an API where one can obtain a > >> reference count of an object where the underlying memory can be freed regardless > >> of the obtained reference count. > >> > >> A refernece count represents a shared ownership model, which is undermined if > >> the underlying memory is not owned by the reference count. > >> > >> That said, I don't mind the reference count, but we can't mix up exclusive > >> ownership (embedding a structure) and shared ownership (reference count). > >> > >>>> +static void dma_resv_release(struct kref *kref) > >>>> { > >>>> - /* > >>>> - * This object should be dead and all references must have > >>>> - * been released to it, so no need to be protected with rcu. > >>>> - */ > >>>> + struct dma_resv *obj = container_of(kref, struct dma_resv, refcount); > >>>> + > >>>> dma_resv_list_free(rcu_dereference_protected(obj->fences, true)); > >>>> ww_mutex_destroy(&obj->lock); > >>>> + if (obj->allocated) > >>>> + kfree(obj); > >>>> +} >