From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 476AC3644A1 for ; Sat, 11 Jul 2026 13:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783775464; cv=none; b=gVGnFfXgn8jcK6OaPsuDCSr/Gzox0roUSo/by3kAu7Fz5wS2wPrLfs1hO7s/RBDEMRftQkBP/VzDC8Dby8c7IuxQHu1fmFIeuSCks+zsZ47tcMZDVVyzllxbnD9o467FueIrfCQU/BSyR+OKEF2gziLmsmxyDhNDPixSLilvdgQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783775464; c=relaxed/simple; bh=E2pBgSBPbwwV4pxrlPXZ9/3vDY4yGitYmY/jIZKuS0Y=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=Mz+uCnO2yQCrhE+7RGFwaoQdrdzm24PlL2o+AnF6xekUm6gJx6e06azpHzxslW36RirUGe8tGKp4AHcuIaZ6vd66MXAxmB/KjqHVAVYhNPDRFpmGnbL6lKw+HAoPKeDfzrnLaWXQaJ12pILdbi2S9k7/8AzVaCqyI7kZxrfmAmk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UuM7M/Kq; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UuM7M/Kq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A9B1F000E9; Sat, 11 Jul 2026 13:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783775462; bh=iCb53dcsCcB5dATh8qDXwvKoRgx+avhB4VmAxBBy4JQ=; h=Date:Subject:Cc:To:From:References:In-Reply-To; b=UuM7M/KqVFuJ3M8oaDUH18u3GqTYP/pBo3nYH64+xJZu9uUZaP20F8jXVLR5UMXzp xJ4pHfSt9MMyJd+qDujO8QR7ktR999yhRpS4hZPR3nEuSloObatSs1QtAQA3I5tBqo oy/InfwNoQQu3rnchmqeUkvpXJadp0plU9epZS7ioE2dpli3QdV/QjsD+OYyCImAr2 kHS5PBJUyti1wgRxn9VJZda9/NgS6mAjh8IkikuaoP9t06ZogqbWIJSbZU3F1NGgWR MZr5Jb9Od6V3O5dXsSg/tQRxqJXZ7iZNR7AMNMqtyH+1E8w6ErVQ3FOneHz3knGPkL p+jY90FUDad/A== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 11 Jul 2026 15:10:58 +0200 Message-Id: Subject: Re: [PATCH 01/12] dma-buf: Add reference counting to dma_resv Cc: , , , , , , , , , , To: "Matthew Brost" From: "Danilo Krummrich" References: <20260710190752.2355-1-christian.koenig@amd.com> <20260710190752.2355-2-christian.koenig@amd.com> In-Reply-To: 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=C3=B6nig wrote: >> This provides clearer ownership semantics and makes the code more >> maintainable by removing the embedded allocation hack. >>=20 > > 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 dma_resv::allocated fields and the corresponding semantics exists, this doe= s 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 matte= r whether I have a reference count, it would a UAF regardless. It is misleading (and hence error prone) to have an API where one can obtai= n a reference count of an object where the underlying memory can be freed regar= dless 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 =3D 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); >> +}