From nobody Sat Oct 4 17:34:12 2025 Received: from fllvem-ot03.ext.ti.com (fllvem-ot03.ext.ti.com [198.47.19.245]) (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 60BE217D346; Thu, 14 Aug 2025 16:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755187867; cv=none; b=rDn6a0cPaimVkOSBkQB2bbCV3qSYXslckI/Mu/VHw2swsKt5YBG/jw5+WySH5EY/boFIqytoarU0lnABv63NPDkHO4Tunlq7mD0BZHkro9rxHeqbYNnzsyzjcPLXoPNuXr89nlPQcs/b5c/4lO9yzNtZTbZeuean4CId+snU1vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755187867; c=relaxed/simple; bh=A0jG8wOd7Hat1JLqO4ngknfrGOTBOMaGZuwjPaIHNTU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kb6PHFcMvQXfnP+d8NuHQ5QeSv/qFNYuNpi7dYcsZJY51EWorIybNDVxJ1OoDdKfMEFEuWVZBeIYpYnuM8TvIWPt7xLc4ew8M09LCu6LzRHpJR7/9DRnWK2eMgUxLseOZPDjXsADwls51vHrYYQXGlbet9qiJdf50KDkQkHv1ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=REiJyXhb; arc=none smtp.client-ip=198.47.19.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="REiJyXhb" Received: from fllvem-sh03.itg.ti.com ([10.64.41.86]) by fllvem-ot03.ext.ti.com (8.15.2/8.15.2) with ESMTP id 57EGApFV1916359; Thu, 14 Aug 2025 11:10:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1755187851; bh=2Ig6l3paNM4Nw8JsMQGv/kPeljj1hI9QWQbQPT8/jcE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=REiJyXhb1QBaC7QWdN1cY2FkQId2g/WGpcR70iGO+x/FmqvaPIv8a+SE8BgyuA03N GPv15OjQ/ONcSn82Vm/QUl0TVJ9FpE3VBsDHWX71puodO6O7EBPP+qJV1TXrP/JmPW /PB/Y9VfNHPBMRNhF9acXaMzQGFUuDvSOJpw/sXQ= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by fllvem-sh03.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 57EGApQ61264126 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 14 Aug 2025 11:10:51 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 14 Aug 2025 11:10:51 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55 via Frontend Transport; Thu, 14 Aug 2025 11:10:50 -0500 Received: from lelvem-mr06.itg.ti.com ([10.249.42.149]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 57EGAndl4172380; Thu, 14 Aug 2025 11:10:50 -0500 From: Andrew Davis To: Gerd Hoffmann , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Paul Cercueil , Vivek Kasireddy , Daniel Vetter CC: , , , , Andrew Davis Subject: [PATCH v2 1/3] udmabuf: Keep track current device mappings Date: Thu, 14 Aug 2025 11:10:47 -0500 Message-ID: <20250814161049.678672-2-afd@ti.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250814161049.678672-1-afd@ti.com> References: <20250814161049.678672-1-afd@ti.com> 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 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" When a device attaches to and maps our buffer we need to keep track of this mapping/device. This is needed for synchronization with these devices when beginning and ending CPU access for instance. Add a list that tracks device mappings as part of {map,unmap}_udmabuf(). Signed-off-by: Andrew Davis --- drivers/dma-buf/udmabuf.c | 45 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 40399c26e6be6..cc5c1cc42c7f2 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -42,6 +42,14 @@ struct udmabuf { struct sg_table *sg; struct miscdevice *device; pgoff_t *offsets; + struct list_head attachments; + struct mutex lock; /* for attachments list */ +}; + +struct udmabuf_attachment { + struct device *dev; + struct sg_table *table; + struct list_head list; }; =20 static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) @@ -185,14 +193,44 @@ static void put_sg_table(struct device *dev, struct s= g_table *sg, static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, enum dma_data_direction direction) { - return get_sg_table(at->dev, at->dmabuf, direction); + struct udmabuf *ubuf =3D at->dmabuf->priv; + struct udmabuf_attachment *a; + struct sg_table *table; + + a =3D kzalloc(sizeof(*a), GFP_KERNEL); + if (!a) + return ERR_PTR(-ENOMEM); + + table =3D get_sg_table(at->dev, at->dmabuf, direction); + if (IS_ERR(table)) { + kfree(a); + return table; + } + + a->dev =3D at->dev; + a->table =3D table; + + mutex_lock(&ubuf->lock); + list_add(&a->list, &ubuf->attachments); + mutex_unlock(&ubuf->lock); + + return a->table; } =20 static void unmap_udmabuf(struct dma_buf_attachment *at, struct sg_table *sg, enum dma_data_direction direction) { - return put_sg_table(at->dev, sg, direction); + struct udmabuf_attachment *a =3D at->priv; + struct udmabuf *ubuf =3D at->dmabuf->priv; + + mutex_lock(&ubuf->lock); + list_del(&a->list); + mutex_unlock(&ubuf->lock); + + put_sg_table(at->dev, sg, direction); + + kfree(a); } =20 static void unpin_all_folios(struct udmabuf *ubuf) @@ -384,6 +422,9 @@ static long udmabuf_create(struct miscdevice *device, if (!ubuf) return -ENOMEM; =20 + INIT_LIST_HEAD(&ubuf->attachments); + mutex_init(&ubuf->lock); + pglimit =3D ((u64)size_limit_mb * 1024 * 1024) >> PAGE_SHIFT; for (i =3D 0; i < head->count; i++) { pgoff_t subpgcnt; --=20 2.39.2