Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4999714imm; Tue, 18 Sep 2018 02:42:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaO3BYCRwSD7BHO+B6dwiuB+DD2w+2z+vPqIqJDAU0xntQDvUgOtN4HuLH95v67yhZ3bw9t X-Received: by 2002:a63:4f64:: with SMTP id p36-v6mr26283580pgl.210.1537263729783; Tue, 18 Sep 2018 02:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537263729; cv=none; d=google.com; s=arc-20160816; b=jqjLx4dnjQDBlVn358hxgVDvSiwe2jn6gJzZjBRLOvMg3sRbjGEutl+4ZC1SulaRYQ W/jw53hoQ+MKWDsGrkZ2am3jAP2P4dD2eABJn4V1IHfumYxRfYi5O83OTwcpsDZAvZw4 +kAPNoQrIC3mXpxahUgf7IAxPs0Vdb3Z8rPct0kkvbLd26L9unX9IDWU9sNreNmLvPTu 2E0zvTR6z+16anaKnYlZGb7wGc8nJhqPRpoJvgRVu5+re3t7vGbxwwoRvdNUFahXTl9V HNNU786SbiwZ3VQkxFfFci2O9ojJgi7adP0h50UVlH692A6nEqtz2pR7dgW0GBPUFo92 kROg== 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=JYFRL3w+KM83ixs8hsdhMVKed+sEge7Y3umGuriyaMA=; b=dOIosuT8FRRSnBZQm4Yyv7jVJS3EJo+J4vGSaODPKcRrAbeDc6uAY1ChSH5JL1+nJI wMff3DSGGzQl3syYM8lnzgNzHo+rj/Yu+jzn5mWu0F+hLfX5Gb6YotEjXBb4foZSge4s tYV58uWF9AB1ZRTYVAkRL1QPgdqFoeONHrL2fQUI1am7AXv4gF/ls0DylEjcIWf6Xl6I 7S5PR/1vjATlfHWcWNNxbsu4MIXFYRwXgXSC4cCvmOAADJf4UMLNaPWrGKPjMITx7z6S aiT5KaWFrXypRvFrtYHpoZhwB+63N1BPMeyHyiZ2RpOO1w694374wF5KVaaJxoLlXPB9 S53w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=URA8hDIj; 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 p16-v6si17688024pgb.38.2018.09.18.02.41.54; Tue, 18 Sep 2018 02:42:09 -0700 (PDT) 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=URA8hDIj; 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 S1729560AbeIRPNh (ORCPT + 99 others); Tue, 18 Sep 2018 11:13:37 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:36447 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728780AbeIRPNh (ORCPT ); Tue, 18 Sep 2018 11:13:37 -0400 Received: by mail-yb1-f196.google.com with SMTP id 5-v6so532607ybf.3 for ; Tue, 18 Sep 2018 02:41:48 -0700 (PDT) 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=JYFRL3w+KM83ixs8hsdhMVKed+sEge7Y3umGuriyaMA=; b=URA8hDIj59xQN5Hk+wYMlLE8CE641ZGx2oyLf16BEpGsupWvDsDzhAeJJkQfCoi2NB aauS6tHaUFSTrg+zF2xgGAIcBWpF21Fsook79HINCi6NbmTKqdhGKlNZ7HdbpRlIvWST X/aT9VTwH5EvXdCq0g5QVGsjkMFbXKEqt4UzQ= 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=JYFRL3w+KM83ixs8hsdhMVKed+sEge7Y3umGuriyaMA=; b=B1MZgrV2ANr7a6+27RMCh4EAbb6kAekiYI9xcL+5uRtY3iPWb99ZCToe2IL90LLCck wpdqaGPToayAuXhQpoiPKKzwQzUEYpb40COnzWUJp56d7xipP8c6k2HFkdlpnAq2CRPl 9ccmgh8L22+zm5HyJ+jh6yHK+Wn/UMEHbp646TMwaYfBFMAWIUg2dGZEQVH5t1tal7w9 aGyexlNHyhO0pdYtiMdo3NmpwVbf7vcmIKnc1/Rs6zFXOKdB6lt+yBPOw5w2bLJcrd20 jTcMMK3lXdklXRcgKKuSgshPRomCCwVVKbMusHWfaSnMlDyC2nlni+BRBe8dBLZxxC0q OGmA== X-Gm-Message-State: APzg51DpW/ymwAKWTa+F1D1uAQEGOHYUmMGS07WHEbhxbku5An5b8M7O MYhNK84mGF7XWDL7KmpCEl27Zq4W+V4= X-Received: by 2002:a5b:44b:: with SMTP id s11-v6mr11937569ybp.505.1537263708203; Tue, 18 Sep 2018 02:41:48 -0700 (PDT) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com. [209.85.219.182]) by smtp.gmail.com with ESMTPSA id p190-v6sm708316ywg.95.2018.09.18.02.41.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 02:41:47 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id w7-v6so525955ybm.7 for ; Tue, 18 Sep 2018 02:41:46 -0700 (PDT) X-Received: by 2002:a25:7613:: with SMTP id r19-v6mr7271466ybc.204.1537263706632; Tue, 18 Sep 2018 02:41:46 -0700 (PDT) MIME-Version: 1.0 References: <1477471926-15796-1-git-send-email-thierry.escande@collabora.com> <1477471926-15796-3-git-send-email-thierry.escande@collabora.com> <89fe7216-d391-5a5c-424e-df1a2679f3cf@xs4all.nl> In-Reply-To: <89fe7216-d391-5a5c-424e-df1a2679f3cf@xs4all.nl> From: Tomasz Figa Date: Tue, 18 Sep 2018 18:41:35 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/2] [media] videobuf2-dc: Support cacheable MMAP To: Hans Verkuil , Sakari Ailus Cc: Thierry Escande , Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , Pawel Osciak , Marek Szyprowski , Kyungmin Park 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 Hi Hans, On Mon, Sep 17, 2018 at 11:41 PM Hans Verkuil wrote: > > I'm going through old patches in patchwork that fell through the > cracks, and this is one of them. > > If this is still desired, please rebase and repost. > > I'm marking this series as Obsoleted in patchwork, since it no longer > applies anyway. The ability to have cached mappings of MMAP buffers is strongly desired, but I'm afraid not the way this patch does it. First of all, it's not a decision for the driver to make, but for the user space, depending on the access pattern it does. It also isn't something specific to vb2-dma-contig only. I remember Sakari had a series that attempted to solve this in a more comprehensive way[1]. I remember it had some minor problems when I reviewed it, but generally the idea seemed sane. Sakari, do you have any plans to revive that work? [1] https://www.mail-archive.com/linux-media@vger.kernel.org/msg112459.html Best regards, Tomasz > > Regards, > > Hans > > > On 10/26/2016 10:52 AM, Thierry Escande wrote: > > From: Heng-Ruey Hsu > > > > DMA allocations for MMAP type are uncached by default. But for > > some cases, CPU has to access the buffers. ie: memcpy for format > > converter. Supporting cacheable MMAP improves huge performance. > > > > This patch enables cacheable memory for DMA coherent allocator in mmap > > buffer allocation if non-consistent DMA attribute is set and kernel > > mapping is present. Even if userspace doesn't mmap the buffer, sync > > still should be happening if kernel mapping is present. > > If not done in allocation, it is enabled when memory is mapped from > > userspace (if non-consistent DMA attribute is set). > > > > Signed-off-by: Heng-Ruey Hsu > > Tested-by: Heng-ruey Hsu > > Reviewed-by: Tomasz Figa > > Signed-off-by: Thierry Escande > > --- > > drivers/media/v4l2-core/videobuf2-dma-contig.c | 16 ++++++++++++++++ > > 1 file changed, 16 insertions(+) > > > > diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c > > index 0d9665d..89b534a 100644 > > --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c > > +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c > > @@ -151,6 +151,10 @@ static void vb2_dc_put(void *buf_priv) > > sg_free_table(buf->sgt_base); > > kfree(buf->sgt_base); > > } > > + if (buf->dma_sgt) { > > + sg_free_table(buf->dma_sgt); > > + kfree(buf->dma_sgt); > > + } > > dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, > > buf->attrs); > > put_device(buf->dev); > > @@ -192,6 +196,14 @@ static void *vb2_dc_alloc(struct device *dev, unsigned long attrs, > > buf->handler.put = vb2_dc_put; > > buf->handler.arg = buf; > > > > + /* > > + * Enable cache maintenance. Even if userspace doesn't mmap the buffer, > > + * sync still should be happening if kernel mapping is present. > > + */ > > + if (!(buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) && > > + buf->attrs & DMA_ATTR_NON_CONSISTENT) > > + buf->dma_sgt = vb2_dc_get_base_sgt(buf); > > + > > atomic_inc(&buf->refcount); > > > > return buf; > > @@ -227,6 +239,10 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) > > > > vma->vm_ops->open(vma); > > > > + /* Enable cache maintenance if not enabled in allocation. */ > > + if (!buf->dma_sgt && buf->attrs & DMA_ATTR_NON_CONSISTENT) > > + buf->dma_sgt = vb2_dc_get_base_sgt(buf); > > + > > pr_debug("%s: mapped dma addr 0x%08lx at 0x%08lx, size %ld\n", > > __func__, (unsigned long)buf->dma_addr, vma->vm_start, > > buf->size); > > >