bcm27xx: update to latest patches from RPi foundation
[openwrt/staging/wigyori.git] / target / linux / bcm27xx / patches-5.4 / 950-0729-udmabuf-fix-dma-buf-cpu-access.patch
1 From 153f1e1def226f87cc4c307d2806b000a820f64b Mon Sep 17 00:00:00 2001
2 From: Gurchetan Singh <gurchetansingh@chromium.org>
3 Date: Tue, 17 Dec 2019 15:02:28 -0800
4 Subject: [PATCH] udmabuf: fix dma-buf cpu access
5
6 Commit 1ffe09590121fbb3786d6c860acdd200f7ab095c upstream.
7
8 I'm just going to put Chia's review comment here since it sums
9 the issue rather nicely:
10
11 "(1) Semantically, a dma-buf is in DMA domain. CPU access from the
12 importer must be surrounded by {begin,end}_cpu_access. This gives the
13 exporter a chance to move the buffer to the CPU domain temporarily.
14
15 (2) When the exporter itself has other means to do CPU access, it is
16 only reasonable for the exporter to move the buffer to the CPU domain
17 before access, and to the DMA domain after access. The exporter can
18 potentially reuse {begin,end}_cpu_access for that purpose.
19
20 Because of (1), udmabuf does need to implement the
21 {begin,end}_cpu_access hooks. But "begin" should mean
22 dma_sync_sg_for_cpu and "end" should mean dma_sync_sg_for_device.
23
24 Because of (2), if userspace wants to continuing accessing through the
25 memfd mapping, it should call udmabuf's {begin,end}_cpu_access to
26 avoid cache issues."
27
28 Reported-by: Chia-I Wu <olvaffe@gmail.com>
29 Suggested-by: Chia-I Wu <olvaffe@gmail.com>
30 Fixes: 284562e1f348 ("udmabuf: implement begin_cpu_access/end_cpu_access hooks")
31 Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
32 Link: http://patchwork.freedesktop.org/patch/msgid/20191217230228.453-1-gurchetansingh@chromium.org
33 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
34 ---
35 drivers/dma-buf/udmabuf.c | 7 +++----
36 1 file changed, 3 insertions(+), 4 deletions(-)
37
38 --- a/drivers/dma-buf/udmabuf.c
39 +++ b/drivers/dma-buf/udmabuf.c
40 @@ -122,9 +122,8 @@ static int begin_cpu_udmabuf(struct dma_
41 if (IS_ERR(ubuf->sg))
42 return PTR_ERR(ubuf->sg);
43 } else {
44 - dma_sync_sg_for_device(dev, ubuf->sg->sgl,
45 - ubuf->sg->nents,
46 - direction);
47 + dma_sync_sg_for_cpu(dev, ubuf->sg->sgl, ubuf->sg->nents,
48 + direction);
49 }
50
51 return 0;
52 @@ -139,7 +138,7 @@ static int end_cpu_udmabuf(struct dma_bu
53 if (!ubuf->sg)
54 return -EINVAL;
55
56 - dma_sync_sg_for_cpu(dev, ubuf->sg->sgl, ubuf->sg->nents, direction);
57 + dma_sync_sg_for_device(dev, ubuf->sg->sgl, ubuf->sg->nents, direction);
58 return 0;
59 }
60