Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp123ybl; Mon, 27 Jan 2020 20:41:34 -0800 (PST) X-Google-Smtp-Source: APXvYqybyly8dRCuKC66j2qtyY2mKzGSuYkwrElDiNuscyQX8+TDsx64TkCYnU4ZVzkNuabf7wtS X-Received: by 2002:a9d:68c8:: with SMTP id i8mr8220761oto.34.1580186494338; Mon, 27 Jan 2020 20:41:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580186494; cv=none; d=google.com; s=arc-20160816; b=o+0MmukdQoEVfBDsCPDEP80NTBwqzTfl1lm+V4vbpvw7i3dMrxC5PJQwJ6pEvGXgln GLopIEeeODnv1AhHiHX9PRiwbrIIj8dgp1IWji/ucMZy9CWfJdjv8/a+iKSq7ngSU93u k9+Ddp510UBnZqOGmT+5GII6smKgfKP5xVz7hcSoDL9jnH0kIBPagPhJD+Fd94METd0I DLdwAt36lEFfv/CGoph6InjBWypvZpG8hrIQXAkub4UM9NUk7nnQVaTkRWi7p9xpzH/b zt58G6uRAmw0KZGxKqm2V8hZFEaQFY2lqSTHf0QdzPxWXdj1g7NADhDYVuEWYYDCpESx n6uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oAFKKUbjn4q+w4IFCE+2ZYtzrDlWGmX9O+mEmG7900M=; b=pDL8jCObIYyGt3FQqClQTR5xIz3TMNyUnO0RtMzzQRNFbGB+wCTAochAb/cFpUKXug JVi5EujXEqgJPkPv+5UL3a0AOtwSfwgLLoM87G56J0VgDXvELOyV9O4QFTo5V8o+EIcL YC/BwouxwyNRqFS/Y897zj7wr9iYaM1gwkK5GB3ntZRPqG22b9bkdRiJDN3gvqFxDUDF +LP40bHvMPTyO7jczV5tW+nSQUGWjHVSCJ2W4uCqB0f5zI73VUeWLjEVNdIEKHDnn5AA /EunkLukNQqk2jmMMjErwrMgY52yClBnm5tB8XI/S4K8+PLRUBMHxKYXcq58y9O+h6z4 PEVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EhJHNf5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a14si4892010oid.58.2020.01.27.20.41.15; Mon, 27 Jan 2020 20:41:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EhJHNf5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726871AbgA1EjF (ORCPT + 99 others); Mon, 27 Jan 2020 23:39:05 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39834 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbgA1EjF (ORCPT ); Mon, 27 Jan 2020 23:39:05 -0500 Received: by mail-ed1-f68.google.com with SMTP id m13so13253785edb.6 for ; Mon, 27 Jan 2020 20:39:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oAFKKUbjn4q+w4IFCE+2ZYtzrDlWGmX9O+mEmG7900M=; b=EhJHNf5NF9OU2ztfTNy4zoe2jKSU7opQPS1xvdHmcF7O207hYIZlYPI0Xho0eX7QsH iip007AxmyTGPuO38NtELWs+/4ZmTWN/EoOEKEEmb35XTyFOqLaX3keTnzR1Jc29vKZf hlBWgWSeyf1hmbYCDWJPidIkcBHdzeodeCHzU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oAFKKUbjn4q+w4IFCE+2ZYtzrDlWGmX9O+mEmG7900M=; b=KG7CNFrzvX0SeLYuR7yN/J8FsvqaAmRSbaak0rr2DQaBiFh+WgLJ3eaam3kGteSxK6 ZpyaLUx60RW9cg/ik8z8HHVFY2cx4M6OZY/UPG4lhJJ22TSG2f7tabe42NADrHld3n2X b7K6fiMTU9XTgjBh7/1QwCBnwxVHvjDrM0kAj8vj9VCGzu7YV5W1akYxQ/CR6RsyCNO/ 2I4gCpTwekL28m6KplBvZ1/KyohJVQ2kEaCYqAl/rMzkFwoBfnW8gJZZvV4+FQyxTLZJ RLJmIlZAmmRoSl8d7u2bSuwGS1uZQ2ZgEyMYlh/sdejhHiq8N4w6BqsopcYjuWNZb8QR 0VEA== X-Gm-Message-State: APjAAAW9nqVC6c8ZGiLPgNGOd4RwE4xoyC6bp4YlqUuraukOWQaSMNPl R2Eb6xtH8aK9/7zofBPdPWCqMbZQ4q6Tjw== X-Received: by 2002:a17:906:d926:: with SMTP id rn6mr1590315ejb.213.1580186341583; Mon, 27 Jan 2020 20:39:01 -0800 (PST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id v2sm404232edx.92.2020.01.27.20.39.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jan 2020 20:39:00 -0800 (PST) Received: by mail-wm1-f49.google.com with SMTP id s10so1016013wmh.3 for ; Mon, 27 Jan 2020 20:39:00 -0800 (PST) X-Received: by 2002:a1c:9a8d:: with SMTP id c135mr2228590wme.183.1580186340098; Mon, 27 Jan 2020 20:39:00 -0800 (PST) MIME-Version: 1.0 References: <20191217032034.54897-1-senozhatsky@chromium.org> <20191217032034.54897-13-senozhatsky@chromium.org> <1c5198dc-db4e-47d6-0d8b-259fbbb6372f@xs4all.nl> In-Reply-To: <1c5198dc-db4e-47d6-0d8b-259fbbb6372f@xs4all.nl> From: Tomasz Figa Date: Tue, 28 Jan 2020 13:38:48 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH 12/15] videobuf2: add begin/end cpu_access callbacks to dma-sg To: Hans Verkuil Cc: Sergey Senozhatsky , Hans Verkuil , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , Linux Media Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 10, 2020 at 7:13 PM Hans Verkuil wrote: > > On 12/17/19 4:20 AM, Sergey Senozhatsky wrote: > > Provide begin_cpu_access() and end_cpu_access() dma_buf_ops > > callbacks for cache synchronisation on exported buffers. > > > > Signed-off-by: Sergey Senozhatsky > > --- > > .../media/common/videobuf2/videobuf2-dma-sg.c | 22 +++++++++++++++++++ > > 1 file changed, 22 insertions(+) > > > > diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c > > index 6db60e9d5183..bfc99a0cb7b9 100644 > > --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c > > +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c > > @@ -470,6 +470,26 @@ static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf) > > vb2_dma_sg_put(dbuf->priv); > > } > > > > There is no corresponding vb2_sg_buffer_consistent function here. > > Looking more closely I see that vb2_dma_sg_alloc doesn't pass the dma_attrs > argument to dma_map_sg_attrs, thus V4L2_FLAG_MEMORY_NON_CONSISTENT has no > effect on dma-sg buffers. videobuf2-dma-sg allocates the memory using the page allocator directly, which means that there is no memory consistency guarantee. > > Is there a reason why dma_attrs isn't passed on to dma_map_sg_attrs()? > V4L2_FLAG_MEMORY_NON_CONSISTENT is a flag for dma_alloc_attrs(). It isn't supposed to do anything for dma_map_sg_attrs(), which is only supposed to create the device (e.g. IOMMU) mapping for already allocated memory. > I suspect it was just laziness in the past, and that it should be wired > up, just as for dma-contig. > > Regards, > > Hans > > > +static int vb2_dma_sg_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, > > + enum dma_data_direction direction) > > +{ > > + struct vb2_dma_sg_buf *buf = dbuf->priv; > > + struct sg_table *sgt = buf->dma_sgt; > > + > > + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); > > + return 0; > > +} > > + > > +static int vb2_dma_sg_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, > > + enum dma_data_direction direction) > > +{ > > + struct vb2_dma_sg_buf *buf = dbuf->priv; > > + struct sg_table *sgt = buf->dma_sgt; > > + > > + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); > > + return 0; > > +} > > + > > static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf) > > { > > struct vb2_dma_sg_buf *buf = dbuf->priv; > > @@ -488,6 +508,8 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = { > > .detach = vb2_dma_sg_dmabuf_ops_detach, > > .map_dma_buf = vb2_dma_sg_dmabuf_ops_map, > > .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap, > > + .begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access, > > + .end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access, > > .vmap = vb2_dma_sg_dmabuf_ops_vmap, > > .mmap = vb2_dma_sg_dmabuf_ops_mmap, > > .release = vb2_dma_sg_dmabuf_ops_release, > > >