Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4151382pxu; Mon, 30 Nov 2020 19:41:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRrA2KLtw5tu77gIqsT6jpL/Pn8/TGQeQqshFz6LIOVtA3v7IOn/0XsKTMFCH03FmGWSJt X-Received: by 2002:a05:6402:22e1:: with SMTP id dn1mr1055487edb.142.1606794116781; Mon, 30 Nov 2020 19:41:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606794116; cv=none; d=google.com; s=arc-20160816; b=M6Ei+6MVCvjJqjQZYpu1+6lgPzheyFgT9WI6t8KTgfeGJh/h2Ew/b2lT68Xj9S4M3Z kc63K+gxJOx/B1O+2ZZ8e6DUXofWCJkIWNPCUwUzVNnSSZFaSUvrdlu3NnB7O+/Nk2Gv LhG1Up32//BzH+v4OMIi6jepsGU+FfIuiXm2YrCNWR9o+AjKJcFf5qZcIiJxs4bgZnwN N31NnR7SmgTy64xXTd87xu2PC5jrtE6wxn8TWsanF3SjolMQigKYHswBNsIrKDUw8dru 1X4HsZ0oPWNIeCESnqu7Qm9jnPgPgVdiD3YI90EkCFs0g+eWAkKYzRRDdr6x8IL8wdRm W+Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NL582lgLVSi6KvAu9Utf9CebPYU3CkLIdkP46F4/+EA=; b=I2OROyD0QIoq6K3rOpZQlUgpgc7mb9WOaISbQ5mnkC6De4YQtJfhoWfG2mvjP/qzqW PDbtKEeUUFlw5PiCXMdsdunU/xfCuA2mcAscogI50STe5DoafaF7/2+Vm92EU592WK5i 8S48p55pqqRzQoINl+wHmkyhQm3WfcV3aqhgMLlEqUmMlg6xZle9nBf0+6zjzJhnyPJL gl5bypYq0ogum4V1kmWQwc/0K/E8zUNEmyLvCxUj1ejYMyyvkqDWkasfPa78agGfo+o9 DeDbFM0d6FR+gTsm1ZR+M5PS00IGpamnaKPHQfJXbp6co9V/SfGiXuNG2LevF4N5VK3x vZCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xhga9YlK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si346143edy.450.2020.11.30.19.41.34; Mon, 30 Nov 2020 19:41:56 -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=@gmail.com header.s=20161025 header.b=Xhga9YlK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727753AbgLADhm (ORCPT + 99 others); Mon, 30 Nov 2020 22:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727719AbgLADhl (ORCPT ); Mon, 30 Nov 2020 22:37:41 -0500 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BD22C0613D2; Mon, 30 Nov 2020 19:37:01 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id t21so383244pjw.2; Mon, 30 Nov 2020 19:37:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NL582lgLVSi6KvAu9Utf9CebPYU3CkLIdkP46F4/+EA=; b=Xhga9YlKz842XlE+bb+SVEwobT1WQdwHoo7D7fOlF20D0+a3pLa7mD7wAMBsoNZD92 uuQtPfpMZeW+IlOssf8/rWOw+QKg4PspN2T5/kdsgqzAFOZ/HTDb+IXKvmETtlQE+uV2 lXobZ7ntNQW3D5X2jcCxlPBk3A7ivPUpAfZpczlDxl01oriyRBobJvB++T+NdzzoDFX7 veXQz8MvK4l4UMZubI5hihJlJiCZ99c5RCXeBsHjgSAWU3w/C3tTOv0G4Nrm+05jAcQ5 apm/NsHGqk7+d0Nsg27zQ1AjqTIesG3qtSe40lJruY1ZgMRjOr4KyeRX3RaEahrQ9fce rjmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NL582lgLVSi6KvAu9Utf9CebPYU3CkLIdkP46F4/+EA=; b=jIjVGBf3PYgnL6Hg0bMlYUoZjhA8f2CuXIs0bw21VEJu7w1+evPnaD8xlXu+i09Jvn gLSTlHBrmyyExNvAW6Z4SB82l/kQP5oCDD/N6onoIlRxqoPYbcSJO1MMsPKhjDYUyODD FQ5wrEO4nPzT355inm/1rlJQ3ot+iHNH6solpppkBWSP82nsHkK7v14QYhIG5SEeUGao QpxPjgQRP1sIfHZbV4PWQijLqEpjw6Wvx5H4pIbuEJt2SgQYY0NCPVM2Ciln7enSMBCk 8u6ALTiyuX5wFKru6xzSVOAvvKgytq8LVVU5MjBXkLfg0vXBb6UecGd6QWOYB0IzLoAl pjcw== X-Gm-Message-State: AOAM533UJtQeOe8lev3DiApp2tmdygD2M1naXIzRDlwZQhdA8cKhDeEB S0S/3HYxY4caN569L88+FSk= X-Received: by 2002:a17:90a:c003:: with SMTP id p3mr600818pjt.221.1606793820977; Mon, 30 Nov 2020 19:37:00 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:a6ae:11ff:fe11:4b46]) by smtp.gmail.com with ESMTPSA id w131sm489881pfd.14.2020.11.30.19.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 19:37:00 -0800 (PST) Date: Tue, 1 Dec 2020 12:36:58 +0900 From: Sergey Senozhatsky To: Christoph Hellwig Cc: Ricardo Ribalda , Marek Szyprowski , Robin Murphy , Mauro Carvalho Chehab , IOMMU DRIVERS , Joerg Roedel , Linux Doc Mailing List , Linux Kernel Mailing List , Linux Media Mailing List , Tomasz Figa , Sergey Senozhatsky Subject: Re: [PATCH v3 5/6] media: uvcvideo: Use dma_alloc_noncontiguos API Message-ID: <20201201033658.GE3723071@google.com> References: <20201125221917.150463-1-ribalda@chromium.org> <20201130083410.GD32234@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201130083410.GD32234@lst.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (20/11/30 09:34), Christoph Hellwig wrote: > > > + uvc_urb->pages = dma_alloc_noncontiguous(dma_dev, stream->urb_size, > > + &uvc_urb->dma, > > + gfp_flags | __GFP_NOWARN, 0); > > + if (!uvc_urb->pages) > > + return false; > > + > > + uvc_urb->buffer = vmap(uvc_urb->pages, > > + PAGE_ALIGN(stream->urb_size) >> PAGE_SHIFT, > > + VM_DMA_COHERENT, PAGE_KERNEL); > > + if (!uvc_urb->buffer) { > > + dma_free_noncontiguous(dma_dev, stream->urb_size, > > + uvc_urb->pages, uvc_urb->dma); > > + return false; > > + } > > + > > + if (sg_alloc_table_from_pages(&uvc_urb->sgt, uvc_urb->pages, > > + PAGE_ALIGN(stream->urb_size) >> PAGE_SHIFT, 0, > > + stream->urb_size, GFP_KERNEL)) { > > + vunmap(uvc_urb->buffer); > > + dma_free_noncontiguous(dma_dev, stream->urb_size, > > + uvc_urb->pages, uvc_urb->dma); > > + return false; > > + } > > I wonder if we should lift this into a helper. On the one hand I had > proliferating struct scatterlist usage, on the other hand it is all over > the media and drm code anyway, and duplicating this doesn't help anyone. Not that I have any sound experience in this area, but the helper probably won't hurt. Do you also plan to add vmap() to that helper or dma_alloc_noncontiguous()/sg_alloc_table_from_pages() only? helper() { dma_alloc_noncontiguous(); sg_alloc_table_from_pages(); if ((dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) vmap(); } videobuf2-dma-contig still has to carry around two versions: one that deals with the noncontig pages and sgt (new API); and the current one. But if the helper will include fallback to coherent allocations then this may change, depending on the helper implementation. -ss