Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7263pxb; Tue, 2 Mar 2021 17:13:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzJE4LSLqFpLTMSQF16zjVMP22aHcJQef390zL0SkQaBHE/kRgEguju2zwOjpORToZvYv9 X-Received: by 2002:a17:906:85b:: with SMTP id f27mr16592411ejd.414.1614734014812; Tue, 02 Mar 2021 17:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614734014; cv=none; d=google.com; s=arc-20160816; b=0YUhVtapoLixxOqaeC9ln8ctZLUs9fMzB/0np/xFgTivPMWEr/ah10ISwRYwi06nvU 63cltkn0H6yIaM/yM4retEslQLVGXXFwdlRFl570EolMB2xqkDRPlSxTQ5x+edntj/bN K4FSxfCtE6hM+CZ3oQPaz3VnYNXVS5XeuPy+I63OtzUmi7Yu+WDdfUHMscDuAnj7M2G4 umSES+VUW+kBnW8LGdMUECyurnE9MSOAooPLh9jToOMBIg44vgiewxTAX8++3Bo5CgIZ cxgemJFz+CUFQGwqDvUQTSd888tq0Pz0THvvF13I93Wn8plDmU6Pgb0v9FRylt+3bbYf OADg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2dy7/E8HSGfJiqqdxi761X4q+2hMNs1FHArXFkc+7Lk=; b=pELJAV1k5uZv/CWwMLk6TCVEAoFlivmcDC8k0BB9X9dqUye3PMxjyRZ2TSXAJI4l52 qy/SupLwO+tmhjBfs+7gO3blzHlmv+Ijn0IyA0Wmz6V9VR6tfHBC4nlGmBrZKm7WKFUg hVM12nkAOAY/hE7pFWOBv1LYhbxXE6ko3rz8C1kbJUUMKmIxCvrnckukt2Cqorw7/tf8 exbtfsT4ZqYb2oQXY05q9/9mLQF53tLCJKPVqoiN0WYt27xSdmYf2t1P0mKNXVYg4O66 mhie7XGS9zDZnUmoWDtNR9AeohqiAO4DJCOesWEOJ4wIYuq+IZuWb7beaIdszdYGBGEZ hU7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Hvzar0bi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id cw18si12893747edb.142.2021.03.02.17.13.12; Tue, 02 Mar 2021 17:13:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Hvzar0bi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233712AbhCAJYt (ORCPT + 99 others); Mon, 1 Mar 2021 04:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233853AbhCAJY2 (ORCPT ); Mon, 1 Mar 2021 04:24:28 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BB9CC06174A for ; Mon, 1 Mar 2021 01:23:48 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id l12so19672708edt.3 for ; Mon, 01 Mar 2021 01:23:48 -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:content-transfer-encoding; bh=2dy7/E8HSGfJiqqdxi761X4q+2hMNs1FHArXFkc+7Lk=; b=Hvzar0bi8ZtMKWVof9tAX71NYajdUzeaQEycJkNH1QL2OuHhPvk/W9qwEQCgpIAohM Gr3o8LEoLnXYUW8+acvNLlOZfQuJQHIHlLEgOFrB8BUDF0HEaeiwfWFagCNIZWYVvqyJ +XkhRhxG2VcBA74LtU8QhBcpltTJuZPOxIPA4= 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:content-transfer-encoding; bh=2dy7/E8HSGfJiqqdxi761X4q+2hMNs1FHArXFkc+7Lk=; b=piqO+IDqlReIzsRIjqhq6lqAn6LiDSLeDAHExj6UExSeQCmgbIVkZR64bGmmiLaUeO RHdua8A2R0v84cBCdpC2kqjS6gnPzU4asI865gkS8ZAiEsKGuCD9xIPj6v46CFfTCc2K TmvWzYwEHRQURaz4dbWlKFjcrySiXH0tOvnnvJw06LZAT1H2C6l8aTDjgeyRKwVk8OWU 7kx9ob+p5f24x15AFJ7bK96dCX1pq38Hq7uBvx2Z5EehkR1h3La6RKNMoQ2D9K2CVTIB qGMBC++xgUzewhfoUdDUv87yyPK9MW+Uhp6Ak5geJCAwfcbeAMeDS3/rDKrpI//R3bwK xJ+A== X-Gm-Message-State: AOAM5330NB9B36c2qxwnfHA5JJ1h5dYTM3C9Cetn35aTdfA5dfPwSdlz j0YcpxN3wLo1SVBip88fKe7sIHbmxEhDug== X-Received: by 2002:a05:6402:3590:: with SMTP id y16mr15557125edc.21.1614590626357; Mon, 01 Mar 2021 01:23:46 -0800 (PST) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com. [209.85.221.41]) by smtp.gmail.com with ESMTPSA id x17sm14298226edq.42.2021.03.01.01.23.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Mar 2021 01:23:45 -0800 (PST) Received: by mail-wr1-f41.google.com with SMTP id h98so15280422wrh.11 for ; Mon, 01 Mar 2021 01:23:45 -0800 (PST) X-Received: by 2002:adf:e412:: with SMTP id g18mr15968814wrm.159.1614590625114; Mon, 01 Mar 2021 01:23:45 -0800 (PST) MIME-Version: 1.0 References: <20201214125703.866998-1-acourbot@chromium.org> <5319c101-f4a4-9c99-b15d-4999366f7a63@linaro.org> In-Reply-To: From: Tomasz Figa Date: Mon, 1 Mar 2021 18:23:33 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] media: venus: use contig vb2 ops To: Alexandre Courbot , Stanimir Varbanov Cc: Fritz Koenig , Linux Media Mailing List , Nicolas Dufresne , Linux Kernel Mailing List , linux-arm-msm , Robin Murphy Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alex, Stanimir, On Wed, Dec 16, 2020 at 12:15 PM Tomasz Figa wrote: > > On Wed, Dec 16, 2020 at 4:21 AM Nicolas Dufresne w= rote: > > > > Le mardi 15 d=C3=A9cembre 2020 =C3=A0 15:54 +0200, Stanimir Varbanov a = =C3=A9crit : > > > Hi Tomasz, > > > > > > On 12/15/20 1:47 PM, Tomasz Figa wrote: > > > > On Tue, Dec 15, 2020 at 8:16 PM Stanimir Varbanov > > > > wrote: > > > > > > > > > > Hi, > > > > > > > > > > Cc: Robin > > > > > > > > > > On 12/14/20 2:57 PM, Alexandre Courbot wrote: > > > > > > This driver uses the SG vb2 ops, but effectively only ever acce= sses the > > > > > > first entry of the SG table, indicating that it expects a flat = layout. > > > > > > Switch it to use the contiguous ops to make sure this expected = invariant > > > > > > > > > > Under what circumstances the sg table will has nents > 1? I came = down to > > > > > [1] but not sure I got it right. > > > > > > > > > > I'm afraid that for systems with low amount of system memory and = when > > > > > the memory become fragmented, the driver will not work. That's wh= y I > > > > > started with sg allocator. > > > > > > > > It is exactly the opposite. The vb2-dma-contig allocator is "contig= " > > > > in terms of the DMA (aka IOVA) address space. In other words, it > > > > guarantees that having one DMA address and length fully describes t= he > > > > > > Ahh, I missed that part. Looks like I misunderstood videobu2 contig > > > allocator. > > > > I'm learning everyday too, but I'm surprised I don't see a call to > > vb2_dma_contig_set_max_seg_size() in this driver (I could also just hav= e missed > > a patch when overlooking this thread) ? > > > > The reason I'm asking, doc says it should be called by driver supportin= g IOMMU, > > which seems to be the case for such drivers (MFC, exynos4-is, exynos-gs= c, mtk- > > mdp, s5p-g2d, hantro, rkvdec, zoran, ti-vpe, ..). I posting it, worst c= ase it's > > all covered and we are good, otherwise perhaps a downstream patch didn'= t make it > > ? > > > > /** > > * vb2_dma_contig_set_max_seg_size() - configure DMA max segment size > > * @dev: device for configuring DMA parameters > > * @size: size of DMA max segment size to set > > * > > * To allow mapping the scatter-list into a single chunk in the DMA > > * address space, the device is required to have the DMA max segment > > * size parameter set to a value larger than the buffer size. Otherwise= , > > * the DMA-mapping subsystem will split the mapping into max segment > > * size chunks. This function sets the DMA max segment size > > * parameter to let DMA-mapping map a buffer as a single chunk in DMA > > * address space. > > * This code assumes that the DMA-mapping subsystem will merge all > > * scatterlist segments if this is really possible (for example when > > * an IOMMU is available and enabled). > > * Ideally, this parameter should be set by the generic bus code, but i= t > > * is left with the default 64KiB value due to historical litmiations i= n > > * other subsystems (like limited USB host drivers) and there no good > > * place to set it to the proper value. > > * This function should be called from the drivers, which are known to > > * operate on platforms with IOMMU and provide access to shared buffers > > * (either USERPTR or DMABUF). This should be done before initializing > > * videobuf2 queue. > > */ > > It does call dma_set_max_seg_size() directly: > https://elixir.bootlin.com/linux/latest/source/drivers/media/platform/qco= m/venus/core.c#L230 > > Actually, why do we even need a vb2 helper for this? > What's the plan for this patch? Best regards, Tomasz > > > > regards, > > Nicolas > > > > > > > > > buffer. This seems to be the requirement of the hardware/firmware > > > > handled by the venus driver. If the device is behind an IOMMU, whic= h > > > > is the case for the SoCs in question, the underlying DMA ops will > > > > actually allocate a discontiguous set of pages, so it has nothing t= o > > > > do to system memory amount or fragmentation. If for some reason the > > > > IOMMU can't be used, there is no way around, the memory needs to be > > > > contiguous because of the hardware/firmware/driver expectation. > > > > > > > > On the other hand, the vb2-dma-sg allocator doesn't have any > > > > continuity guarantees for the DMA, or any other, address space. The > > > > current code works fine, because it calls dma_map_sg() on the whole > > > > set of pages and that ends up mapping it contiguously in the IOVA > > > > space, but that's just an implementation detail, not an API guarant= ee. > > > > > > It was good to know. Thanks for the explanation. > > > > > > > > > > > Best regards, > > > > Tomasz > > > > > > > > > > > > > > [1] > > > > > https://elixir.bootlin.com/linux/v5.10.1/source/drivers/iommu/dma= -iommu.c#L782 > > > > > > > > > > > is always enforced. Since the device is supposed to be behind a= n IOMMU > > > > > > this should have little to none practical consequences beyond m= aking the > > > > > > driver not rely on a particular behavior of the SG implementati= on. > > > > > > > > > > > > Reported-by: Tomasz Figa > > > > > > Signed-off-by: Alexandre Courbot > > > > > > --- > > > > > > Hi everyone, > > > > > > > > > > > > It probably doesn't hurt to fix this issue before some actual i= ssue > > > > > > happens. > > > > > > I have tested this patch on Chrome OS and playback was just as = fine as > > > > > > with > > > > > > the SG ops. > > > > > > > > > > > > drivers/media/platform/Kconfig | 2 +- > > > > > > drivers/media/platform/qcom/venus/helpers.c | 9 ++------- > > > > > > drivers/media/platform/qcom/venus/vdec.c | 6 +++--- > > > > > > drivers/media/platform/qcom/venus/venc.c | 6 +++--- > > > > > > 4 files changed, 9 insertions(+), 14 deletions(-) > > > > > > > > > > > > diff --git a/drivers/media/platform/Kconfig > > > > > > b/drivers/media/platform/Kconfig > > > > > > index 35a18d388f3f..d9d7954111f2 100644 > > > > > > --- a/drivers/media/platform/Kconfig > > > > > > +++ b/drivers/media/platform/Kconfig > > > > > > @@ -533,7 +533,7 @@ config VIDEO_QCOM_VENUS > > > > > > depends on INTERCONNECT || !INTERCONNECT > > > > > > select QCOM_MDT_LOADER if ARCH_QCOM > > > > > > select QCOM_SCM if ARCH_QCOM > > > > > > - select VIDEOBUF2_DMA_SG > > > > > > + select VIDEOBUF2_DMA_CONTIG > > > > > > select V4L2_MEM2MEM_DEV > > > > > > help > > > > > > This is a V4L2 driver for Qualcomm Venus video accelera= tor > > > > > > diff --git a/drivers/media/platform/qcom/venus/helpers.c > > > > > > b/drivers/media/platform/qcom/venus/helpers.c > > > > > > index 50439eb1ffea..859d260f002b 100644 > > > > > > --- a/drivers/media/platform/qcom/venus/helpers.c > > > > > > +++ b/drivers/media/platform/qcom/venus/helpers.c > > > > > > @@ -7,7 +7,7 @@ > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > -#include > > > > > > +#include > > > > > > #include > > > > > > #include > > > > > > > > > > > > @@ -1284,14 +1284,9 @@ int venus_helper_vb2_buf_init(struct vb2= _buffer > > > > > > *vb) > > > > > > struct venus_inst *inst =3D vb2_get_drv_priv(vb->vb2_queu= e); > > > > > > struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); > > > > > > struct venus_buffer *buf =3D to_venus_buffer(vbuf); > > > > > > - struct sg_table *sgt; > > > > > > - > > > > > > - sgt =3D vb2_dma_sg_plane_desc(vb, 0); > > > > > > - if (!sgt) > > > > > > - return -EFAULT; > > > > > > > > > > > > buf->size =3D vb2_plane_size(vb, 0); > > > > > > - buf->dma_addr =3D sg_dma_address(sgt->sgl); > > > > > > > > > > Can we do it: > > > > > > > > > > if (WARN_ON(sgt->nents > 1)) > > > > > return -EFAULT; > > > > > > > > > > I understand that logically using dma-sg when the flat layout is > > > > > expected by the hardware is wrong, but I haven't seen issues unti= l now. > > > > > > > > > > > + buf->dma_addr =3D vb2_dma_contig_plane_dma_addr(vb, 0); > > > > > > > > > > > > if (vb->type =3D=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) > > > > > > list_add_tail(&buf->reg_list, &inst->registeredbu= fs); > > > > > > diff --git a/drivers/media/platform/qcom/venus/vdec.c > > > > > > b/drivers/media/platform/qcom/venus/vdec.c > > > > > > index 8488411204c3..3fb277c81aca 100644 > > > > > > --- a/drivers/media/platform/qcom/venus/vdec.c > > > > > > +++ b/drivers/media/platform/qcom/venus/vdec.c > > > > > > @@ -13,7 +13,7 @@ > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > -#include > > > > > > +#include > > > > > > > > > > > > #include "hfi_venus_io.h" > > > > > > #include "hfi_parser.h" > > > > > > @@ -1461,7 +1461,7 @@ static int m2m_queue_init(void *priv, str= uct > > > > > > vb2_queue *src_vq, > > > > > > src_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; > > > > > > src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; > > > > > > src_vq->ops =3D &vdec_vb2_ops; > > > > > > - src_vq->mem_ops =3D &vb2_dma_sg_memops; > > > > > > + src_vq->mem_ops =3D &vb2_dma_contig_memops; > > > > > > src_vq->drv_priv =3D inst; > > > > > > src_vq->buf_struct_size =3D sizeof(struct venus_buffer); > > > > > > src_vq->allow_zero_bytesused =3D 1; > > > > > > @@ -1475,7 +1475,7 @@ static int m2m_queue_init(void *priv, str= uct > > > > > > vb2_queue *src_vq, > > > > > > dst_vq->io_modes =3D VB2_MMAP | VB2_DMABUF; > > > > > > dst_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; > > > > > > dst_vq->ops =3D &vdec_vb2_ops; > > > > > > - dst_vq->mem_ops =3D &vb2_dma_sg_memops; > > > > > > + dst_vq->mem_ops =3D &vb2_dma_contig_memops; > > > > > > dst_vq->drv_priv =3D inst; > > > > > > dst_vq->buf_struct_size =3D sizeof(struct venus_buffer); > > > > > > dst_vq->allow_zero_bytesused =3D 1; > > > > > > diff --git a/drivers/media/platform/qcom/venus/venc.c > > > > > > b/drivers/media/platform/qcom/venus/venc.c > > > > > > index 1c61602c5de1..a09550cd1dba 100644 > > > > > > --- a/drivers/media/platform/qcom/venus/venc.c > > > > > > +++ b/drivers/media/platform/qcom/venus/venc.c > > > > > > @@ -10,7 +10,7 @@ > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > -#include > > > > > > +#include > > > > > > #include > > > > > > #include > > > > > > #include > > > > > > @@ -1001,7 +1001,7 @@ static int m2m_queue_init(void *priv, str= uct > > > > > > vb2_queue *src_vq, > > > > > > src_vq->io_modes =3D VB2_MMAP | VB2_USERPTR | VB2_DMABUF; > > > > > > src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; > > > > > > src_vq->ops =3D &venc_vb2_ops; > > > > > > - src_vq->mem_ops =3D &vb2_dma_sg_memops; > > > > > > + src_vq->mem_ops =3D &vb2_dma_contig_memops; > > > > > > src_vq->drv_priv =3D inst; > > > > > > src_vq->buf_struct_size =3D sizeof(struct venus_buffer); > > > > > > src_vq->allow_zero_bytesused =3D 1; > > > > > > @@ -1017,7 +1017,7 @@ static int m2m_queue_init(void *priv, str= uct > > > > > > vb2_queue *src_vq, > > > > > > dst_vq->io_modes =3D VB2_MMAP | VB2_USERPTR | VB2_DMABUF; > > > > > > dst_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; > > > > > > dst_vq->ops =3D &venc_vb2_ops; > > > > > > - dst_vq->mem_ops =3D &vb2_dma_sg_memops; > > > > > > + dst_vq->mem_ops =3D &vb2_dma_contig_memops; > > > > > > dst_vq->drv_priv =3D inst; > > > > > > dst_vq->buf_struct_size =3D sizeof(struct venus_buffer); > > > > > > dst_vq->allow_zero_bytesused =3D 1; > > > > > > > > > > > > > > > > -- > > > > > regards, > > > > > Stan > > > > > > >