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 D678AC44501 for ; Sun, 12 Jul 2026 19:51:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFEFF10E4D6; Sun, 12 Jul 2026 19:51:57 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DaSK+04J"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1E90510E09A; Sun, 12 Jul 2026 19:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1783885916; x=1815421916; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=HZ8NsAWtdobIBdxWuhiMzYbMRfQmysjbYGnXugAYl9k=; b=DaSK+04J5A6mIBBkh08UD4kQciiTYRRS0qJAPnw+QONo+h8azRtY8qZl 3JbGFN7wT4qlSx67PGZS6iGoDaK+c3hLVFWSVYKymqjNUr5xpUY1SWJwf Y0HOxgYIB2JLG6GDoFESy13q3zfubvf23aMaRjAwMuTk0paojbTcQ71z4 vUjOPKWdvSeCzy1UFUqNSH2AxC+CAld7+MwK6IQQouX4B8sU84AKvApqN GxeW6bzDzDKRX3aJFHBgMtdwXYtixy8hv5LICSHjhCyJbf9dVCOTPHEK4 EsAwjXy6mzkTUGPP2a1ygBsDQptkuiHw8KOjv0wjE2VutEQJVncv+CKA8 Q==; X-CSE-ConnectionGUID: w+B1fx18S0Gn7OOP5MU5/Q== X-CSE-MsgGUID: W7HnoAV0Q+CunfJ4ojVKTw== X-IronPort-AV: E=McAfee;i="6800,10657,11841"; a="95151603" X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="95151603" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2026 12:51:55 -0700 X-CSE-ConnectionGUID: VKNr20QPQu+WnFp3kKUGkQ== X-CSE-MsgGUID: U36qkqSvQ8mY2LhmZ3BRdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,154,1779174000"; d="scan'208";a="293562327" Received: from orsmsx903.amr.corp.intel.com ([10.22.229.25]) by orviesa001.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2026 12:51:55 -0700 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Sun, 12 Jul 2026 12:51:54 -0700 Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43 via Frontend Transport; Sun, 12 Jul 2026 12:51:54 -0700 Received: from PH8PR06CU001.outbound.protection.outlook.com (40.107.209.51) by edgegateway.intel.com (134.134.137.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Sun, 12 Jul 2026 12:51:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qKp0RQqcnA3SHv+Ufdw14mpAcN2PJ/G7yahkvz4H8V05vbZs+C9B7AThliqxe1JgEnVTNcs/zYO7XpPon/FcCFuWKoN55+9mxqZPBB9PFs/HvtcbE2mydKWr2XxHMkvPKFGA2ORW5a3oWc3vXI0ki5JFJSKp0xqZRVJj670lszNMOlVmHIQIx/h6W7z3TJAd5z3w4r1LdFtlJrmIr1p0vAvF/pH6/fnlYuMVcEGjrG3gtwZGc0loIk33NMtRoYo84tC6tM7kXUEMDkUQnB8ysjDQ1Cygx3UKGNf+vW+eXh4wK/g+kjr2WvQJ/T4mf1S1E5UzuMFxOhv4CSl/YEQ53A== 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=1nOqmFTNu0t0B1IuKMOH3pxSfkC08X5WfAHXjkRb7rw=; b=ucodOdskRu9i+duvDH4jhVzajp4ANiVAZr232G3eXHhiGfCHb7OvVKxaWSkk3ksf1V9JiEvfgPNeRZfjrGcAYTtnDnWdKFWknuYJP/oN1WPgBNATaOhx36knyozvxzqyqesm8ofzqGQrtjXYYp/MzrqjkeIowN7zrBS82s6rhgcVXlvbRyrKMCY3nNY0KG845U7R83FZENcTRykaMbdREsUtq53QsAnFKdQmY6TPhnPzrAz2E7zO9kFamlMzRU/SagiVQWTeKiaiKhw+bWob85wum+n+jatSaMKoHH6N3vkNT+192zPUSh52Jd3YdWxhyN2fM14oFdZVr8VlW+tKqg== 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 SA0PR11MB4590.namprd11.prod.outlook.com (2603:10b6:806:96::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.23; Sun, 12 Jul 2026 19:51:46 +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; Sun, 12 Jul 2026 19:51:46 +0000 Date: Sun, 12 Jul 2026 12:51:43 -0700 From: Matthew Brost To: Danilo Krummrich CC: , , , , , , , , , , 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: MW4PR04CA0256.namprd04.prod.outlook.com (2603:10b6:303:88::21) To PH7PR11MB6522.namprd11.prod.outlook.com (2603:10b6:510:212::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR11MB6522:EE_|SA0PR11MB4590:EE_ X-MS-Office365-Filtering-Correlation-Id: ac622cd9-19c1-4535-71c4-08dee04f015b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|7416014|366016|23010399003|1800799024|56012099006|11063799006|4143699003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: VYDw5rUEN/ZEXgPhpHTeZ6/iJb6ZD1jRbbSPGGBA8aeqXJ2W+shlpe8YD8scaLR8EQLetSiC8zT+uWW3gSefvno5KHGH2BRRF6VulwMPE/JujfzNUaQXOZ36QA6Dd+5oue0YMiNG8h8YJiEfeUHNU1TYsuRSJphm0tgwaQ/EvHg9ncWIPy8RUv/clQgEuhcQDC/SRiChuDi/m0z5K9VLEfqWoI+hgNjCOmLqEDMags+fE/Q26CFwJoT0Es7ykH7+Bain0Bq1lXatdRaG3R+xDofBp6f2pKfP/y7ERl6xqTgD/r5vjMbNi2XHKJhbk9WnFnKUiz8mfbJSlGsYLEZ7ZcxJeiT6bTbP20ezWq0BSNwu042SErBARkdqqMYPijfOAtSQV9XxhGVJZXOlQxmhTNP3Sc/Izj6r3RjOWeA+B9Acm+Uwif3xPfDi7SP6HbbUOWclWRR0SyTKckP9jafUaJ7w13qtZCM3sVOBh9uCiqDH4SB6uOgt+cic5NIYi46ZG4YkdA1T86V73XwNuW2p/LhtD6/B2qgV8W7Nb1BovZ3pS0MYdzUx6m5O0pMuQuJ6aPr92LaLwwi+wW0olUV/wLLo0+agxli1I1SFpOfhaTyCqUGW2ceyge101XrED3fyQCxf/eUVS1JDffd9YXibm2bseGLEaYW2LqUbNwiB/XE= 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)(376014)(7416014)(366016)(23010399003)(1800799024)(56012099006)(11063799006)(4143699003)(18002099003)(22082099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?1MfoB3a/gr1IMOigbc8zZKdtic/7mwNq08bf0fD34TFcvz+5nAjxG0Kr3g?= =?iso-8859-1?Q?lMb0MeQ6sgBvGqdI+i0oIBO3+zjqhJL23VXirZ8oSuSwCUbGYnpdbbGY+j?= =?iso-8859-1?Q?7gvklEYO894KqxuyEr/3EXM6UqX7OxzDNHaA065DVt8j0uJniWWDqCReGt?= =?iso-8859-1?Q?JImUT8lnBbdOQ8gItEfNnIzXD7RKMRKVSjWVz5hJsdBalbuHvVz1xIeXum?= =?iso-8859-1?Q?od9eKJR/sydvP/kbpgkPZLZ/5qAYo0XOr/dAWZ3qScBkzcDDihB3IpFwwV?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iFju9s1WmiP1BYZxr8YqrOsCPOovNWWNu3/nqzS9Zw3BVSNZ2pdTSX9wdQ0cir5TSbD+eH08JfrRVtHQ== X-MS-Exchange-CrossTenant-Network-Message-Id: ac622cd9-19c1-4535-71c4-08dee04f015b X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB6522.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2026 19:51:46.5324 (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: 2ATUWsspNUzGa+64Jv6JJQfKihrmWFF+PBTzHKYfu5+qxOsaqW7LUNn/voOAvyK068sCHFMVgriKvH9DXDKn4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4590 X-OriginatorOrg: intel.com X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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). 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. 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); > >> +}