Message ID | 20240119141402.44262-3-paul@crapouillou.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1035902dyb; Fri, 19 Jan 2024 06:15:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKfE5z/DP+o3CKT2mmc1oIFGF3etFpb9SYAKFkrlBblUJ7FhcytpwbmR/fs0fGcpNB3fZP X-Received: by 2002:a50:f60b:0:b0:55a:7d2a:8521 with SMTP id c11-20020a50f60b000000b0055a7d2a8521mr161632edn.0.1705673737127; Fri, 19 Jan 2024 06:15:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705673737; cv=pass; d=google.com; s=arc-20160816; b=xmcYBMxFrNIxa2U5Yq15yhAcR4OFnATLG9VSAU+dHoma01G1VyWL9h8kdqatVzgeOT 1MkLDz62OjiDzFnDoPGCW1158GN0P0lFraHYnr8K4+fda32DjnCNMiesO2GDb/wtIWdb HEw3znkBCXg8Z12279THB3JiIvZm+qDpCy6hNclc8fRgAbSxohnYfMUHqTQld6W/mL18 xy3+92+V4ise21KI4VnzTCiUji6qMhefGooOjEB8tvMXw5/o1OJzjLJyPn8vbxzC10fx 6vLXkQFssOoMFLfPzT5T93BiPb5iU6w23uj5FljShVVP9m9H7VhoE6ZJn7iZLPUM7BKN 9MEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9iIxPbs0dWlzjgcaYm0qZReABojDho1rbr0/l/s8ieo=; fh=3Xwiw3h4BuSZxa4g5nlxoJvEg1Pn4zGp9h0k4mfsabo=; b=PaYl1mevTrR7F7FTCM3FJNmdue2/l/uOaoOHZjl+QgP9qOjyJzdAelKg3UbJ8omDeU Nd3cXPYp8KOMx/Jog7qRCOMwXp91VJZXFhWmHya9R3lU3l2sLAgxFazjTQf/3mumgt/C 52Tf787Y9DdlZuQSB/P0nFhKt9Y3l5BJYKaDlfxNsfwDv3xmKxjKOLYmxlNP9tunwEI/ 7R83F4GKRxx34U4AZ1qYutZSjkaeFEmGzIsYOQYIFrLA4nmmp/FwOv37RrNFRqWuyc4S cuPeGdRNs42DCw0spys2oP/lqte1Wbceaulsl7qdOn0tGK95fIC3jVlb+TLdV2mFHRNR ABKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="VDmw/5dm"; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v3-20020a509543000000b00558be06020dsi7593103eda.25.2024.01.19.06.15.36 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="VDmw/5dm"; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31249-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BC3631F25984 for <ouuuleilei@gmail.com>; Fri, 19 Jan 2024 14:15:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 566F754BCB; Fri, 19 Jan 2024 14:14:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="VDmw/5dm" Received: from aposti.net (aposti.net [89.234.176.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61572524A0; Fri, 19 Jan 2024 14:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.234.176.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673671; cv=none; b=A5TGi5JvxSgo7TbQ1sBhMe7FIOVFfsAs0auDCje0Zjwu/+BaTyty7Am7FYrsDFlkxuG4azpzEzbBR4S4TSEJB36mR9AlPAA63Km0oXaPscepZmUGQuTmhtlvPXMGSfUeIfg5fe34qHVb+erj3ts1B6Wp5MuqzMptgml0tCUl6xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673671; c=relaxed/simple; bh=VQlUP12x+lQZqEvOl/IoBXRKwFSDxM+N+0FlrIbqdY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JnB3xo13iWMwZkKVryrNWAKTLcDZxlM9Pz0d4edsWA6czqTYKds5KW17TXCHYl0rGe6lswWSGI5TWXhpgWN8vC0v3tkoVhAHQiKWEn5x3DTGrJ+x76tCDqUqhgRUPYaULHSihavA5cim1jpk+OqdGKeL5lHR/zA9JI+9GZarCjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net; spf=pass smtp.mailfrom=crapouillou.net; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b=VDmw/5dm; arc=none smtp.client-ip=89.234.176.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crapouillou.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1705673652; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9iIxPbs0dWlzjgcaYm0qZReABojDho1rbr0/l/s8ieo=; b=VDmw/5dmFB8a7DjV5sQY6708zGHT8cN9da4xSjKPmDqd5JoGUoAWZFLA4iBJzYVtLoeMc0 534O4/q85cvb0JyL4RkqR4fcFW36IeUqTLCBrV3EPttmKkeaTxQBZIvVT+hfm/hQr1U2rC b1Gx/QWvHOF3f7bFVi1IGm2UPpG4KrU= From: Paul Cercueil <paul@crapouillou.net> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jonathan Corbet <corbet@lwn.net>, Sumit Semwal <sumit.semwal@linaro.org>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com> Cc: Jonathan Cameron <jic23@kernel.org>, =?utf-8?q?Nuno_S=C3=A1?= <noname.nuno@gmail.com>, Michael Hennerich <Michael.Hennerich@analog.com>, linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Paul Cercueil <paul@crapouillou.net> Subject: [PATCH v5 2/6] dma-buf: udmabuf: Implement .{begin,end}_access Date: Fri, 19 Jan 2024 15:13:58 +0100 Message-ID: <20240119141402.44262-3-paul@crapouillou.net> In-Reply-To: <20240119141402.44262-1-paul@crapouillou.net> References: <20240119141402.44262-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788528544325219505 X-GMAIL-MSGID: 1788528544325219505 |
Series |
usb: gadget: functionfs: DMABUF import interface
|
|
Commit Message
Paul Cercueil
Jan. 19, 2024, 2:13 p.m. UTC
Implement .begin_access() and .end_access() callbacks.
For now these functions will simply sync/flush the CPU cache when
needed.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
v5: New patch
---
drivers/dma-buf/udmabuf.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
Comments
On Fri, Jan 19, 2024 at 03:13:58PM +0100, Paul Cercueil wrote: > Implement .begin_access() and .end_access() callbacks. > > For now these functions will simply sync/flush the CPU cache when > needed. > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > --- > v5: New patch > --- > drivers/dma-buf/udmabuf.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c > index c40645999648..a87d89b58816 100644 > --- a/drivers/dma-buf/udmabuf.c > +++ b/drivers/dma-buf/udmabuf.c > @@ -179,6 +179,31 @@ static int end_cpu_udmabuf(struct dma_buf *buf, > return 0; > } > > +static int begin_udmabuf(struct dma_buf_attachment *attach, > + struct sg_table *sgt, > + enum dma_data_direction dir) > +{ > + struct dma_buf *buf = attach->dmabuf; > + struct udmabuf *ubuf = buf->priv; > + struct device *dev = ubuf->device->this_device; > + > + dma_sync_sg_for_device(dev, sgt->sgl, sg_nents(sgt->sgl), dir); So one thing I've just wondered is whether we've made sure that this is only doing cache coherency maintenance, and not swiotlb bounce buffer copying. The latter would really not be suitable for dma-buf anymore I think. Not sure how to best check for that since it's all in the depths of the dma-api code, but I guess the best way to really make sure is to disable CONFIG_SWIOTLB. Otherwise I guess the way to absolutely make sure is to trace swiotlb_sync_single_for_device/cpu. It would be kinda neat if dma-buf.c code could make sure you never ever get an swiotlb entry from a dma_buf_map_attachment call, but I don't think we can enforce that. There's sg_dma_is_swiotlb, but that won't catch all implementations, only the generic dma-iommu.c one. Cheers, Sima > + return 0; > +} > + > +static int end_udmabuf(struct dma_buf_attachment *attach, > + struct sg_table *sgt, > + enum dma_data_direction dir) > +{ > + struct dma_buf *buf = attach->dmabuf; > + struct udmabuf *ubuf = buf->priv; > + struct device *dev = ubuf->device->this_device; > + > + if (dir != DMA_TO_DEVICE) > + dma_sync_sg_for_cpu(dev, sgt->sgl, sg_nents(sgt->sgl), dir); > + return 0; > +} > + > static const struct dma_buf_ops udmabuf_ops = { > .cache_sgt_mapping = true, > .map_dma_buf = map_udmabuf, > @@ -189,6 +214,8 @@ static const struct dma_buf_ops udmabuf_ops = { > .vunmap = vunmap_udmabuf, > .begin_cpu_access = begin_cpu_udmabuf, > .end_cpu_access = end_cpu_udmabuf, > + .begin_access = begin_udmabuf, > + .end_access = end_udmabuf, > }; > > #define SEALS_WANTED (F_SEAL_SHRINK) > -- > 2.43.0 > > _______________________________________________ > Linaro-mm-sig mailing list -- linaro-mm-sig@lists.linaro.org > To unsubscribe send an email to linaro-mm-sig-leave@lists.linaro.org
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index c40645999648..a87d89b58816 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -179,6 +179,31 @@ static int end_cpu_udmabuf(struct dma_buf *buf, return 0; } +static int begin_udmabuf(struct dma_buf_attachment *attach, + struct sg_table *sgt, + enum dma_data_direction dir) +{ + struct dma_buf *buf = attach->dmabuf; + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->this_device; + + dma_sync_sg_for_device(dev, sgt->sgl, sg_nents(sgt->sgl), dir); + return 0; +} + +static int end_udmabuf(struct dma_buf_attachment *attach, + struct sg_table *sgt, + enum dma_data_direction dir) +{ + struct dma_buf *buf = attach->dmabuf; + struct udmabuf *ubuf = buf->priv; + struct device *dev = ubuf->device->this_device; + + if (dir != DMA_TO_DEVICE) + dma_sync_sg_for_cpu(dev, sgt->sgl, sg_nents(sgt->sgl), dir); + return 0; +} + static const struct dma_buf_ops udmabuf_ops = { .cache_sgt_mapping = true, .map_dma_buf = map_udmabuf, @@ -189,6 +214,8 @@ static const struct dma_buf_ops udmabuf_ops = { .vunmap = vunmap_udmabuf, .begin_cpu_access = begin_cpu_udmabuf, .end_cpu_access = end_cpu_udmabuf, + .begin_access = begin_udmabuf, + .end_access = end_udmabuf, }; #define SEALS_WANTED (F_SEAL_SHRINK)