Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp5521973lfu; Mon, 28 Mar 2022 15:55:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1dBK7ywby3IQkCid8vko2C8g4ZMMk1QYWVwfbcCapoXxDDBskKQdEgfYXsxUv4APraEc5 X-Received: by 2002:a05:6102:f11:b0:325:a45b:e59a with SMTP id v17-20020a0561020f1100b00325a45be59amr5835193vss.12.1648508134725; Mon, 28 Mar 2022 15:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648508134; cv=none; d=google.com; s=arc-20160816; b=pRKi+DlQOfgrLFq/BjYYXYtVyDCru7iWsB5yFtggUabRffZTS4Lcw/ZE5XepZVpvKV 8U5xlAMU5lW60//XuCl9nCSvO8IY8T9IzH1E6IvH9hIhrvB3BVOYK71WPGAVrkJTwHAB HgE9+D3N2hc2lVJc3oc36HnUUpnbdPKONmGtURqb78Gm0YEins5VTWjzM/5IzIY1wFSB R0t7XZT8Vtt0TJ58YLbRWE4bn+oGSGBpg80uTyG5Srkb+Wsoj+EoxFLHFo7SbTXFnyYF EcgWltAFeenEIgurKjmyNSU8cNP5BCA3dCaOsqvLQsXY5COs0D41y5rHqB7dViBIrgTI qTkQ== 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=XpihMQW3ITEGr80CFfEgsPwVbFmNePy8AVTnWzohyno=; b=YtVp54FbQuvoJuSAN1mjaVX6GP3kmb4oKneVyjMEs6vxUfuepxXfSzpJ/NCyFNr5FV Jb66IgMEq33v4VYRUIxRw5JFyTSKqcWF6CqhXPKEDD8s7UdhuJSLWCbaFlNKDulLOTst jXHmymZT8jgGUpFPsBxrzWWrr72aHmlsE48zQTb/R3RMkQhEPRZXAKlv3KgpzNj6ATIt qlXa+7NLZ6i2id33ZJ53lPmEpoJLljl2iOrBj0aTAGMu/fabcR8gLcuyk8CInC4bRv1M U6f5YO6cv/++enY4SS447NIcsXMxkIyv94OBtp1sShu1evehUalTGuReZFqK6IF92efI Vu7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fo6+o9w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d67-20020a1fe646000000b0033e83170295si3288275vkh.255.2022.03.28.15.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:55:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fo6+o9w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7025295251; Mon, 28 Mar 2022 15:01:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbiC1VBA (ORCPT + 99 others); Mon, 28 Mar 2022 17:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiC1VA5 (ORCPT ); Mon, 28 Mar 2022 17:00:57 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BDE56D97B; Mon, 28 Mar 2022 13:59:16 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id r23so18426861edb.0; Mon, 28 Mar 2022 13:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=XpihMQW3ITEGr80CFfEgsPwVbFmNePy8AVTnWzohyno=; b=fo6+o9w1krLj+t9+r6Huq6bmXGajiPbFdocT5kBjC0HNvq2kYhvbOf+nwkdlfWEihJ XFooInFSC2XxwxaaFa5j9dwDixiymZ80ntOov64y6VfCVLgnJO/ZKY2Y57ZVmLhKjQWJ /KiPBhfmc7+I7hQnJ5dkX1W+4t2UZg3u6kMkRFqCqCVPhQ6RAQKAFjgRGHqMLB2uj0J1 bAKOtVu2J7GY58NXTNyhxAYfj6hhJe2dRqp72oCdamCZpoQ8mDte3MIkEJY+8gATJy1v gtJBcT/a+PdVy6KIgnUbTPGh402e++/1EUXLTSuiE81atZEQGIJeIuaDtouqgj4tt2Pu FUjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=XpihMQW3ITEGr80CFfEgsPwVbFmNePy8AVTnWzohyno=; b=JxYnhAcyYoBWzRPwwq5YecQrZXK++pXXuxljOioLi4DMW3cpfhPrnvW3k3EUT2pLfA qAzJf7bW8gJHkMGc2MrjwS7gBcyBkqfg0CLe0KujhR2wv/5GuLb6OsVBVcRGoTo+nIpo Oa2kOIsGKbG8/g67LMuHyPXJioNNVG+zLy1DPdegRgBxM5VD5Mqf2hLVJ005FDIKyuwZ ZRw3XzyzgAAgS/1DxUc0gCFSi6bvp1sizpHS5OA3UNyOY2l/vCOe7XCAISs7nQ+xTUgz CD53p8LhEQHzvDZkxYljZtawGkDEt13fiMjaGLnWFxYWP7kugSUOtqfXwPq1RKVuE0eL qOEw== X-Gm-Message-State: AOAM532Jc/a2RdUlxcK9N4a/UhbKWu7PtbaX0OUw0tFcFFRhjmJ82yis TYLCz9bxiBjyNCtr+4D/rPQK6HxiFoBv1kVSuOI= X-Received: by 2002:a05:6402:d7:b0:413:673:ba2f with SMTP id i23-20020a05640200d700b004130673ba2fmr18962285edu.29.1648501154526; Mon, 28 Mar 2022 13:59:14 -0700 (PDT) MIME-Version: 1.0 References: <20220207125933.81634-1-paul@crapouillou.net> <20220207125933.81634-8-paul@crapouillou.net> <20220328185425.56b51f4a@jic23-huawei> <1VYG9R.1JAKRTCN4I411@crapouillou.net> In-Reply-To: <1VYG9R.1JAKRTCN4I411@crapouillou.net> From: Andy Shevchenko Date: Mon, 28 Mar 2022 23:58:38 +0300 Message-ID: Subject: Re: [PATCH v2 07/12] iio: buffer-dma: Use DMABUFs instead of custom solution To: Paul Cercueil Cc: Jonathan Cameron , Michael Hennerich , Lars-Peter Clausen , =?UTF-8?Q?Christian_K=C3=B6nig?= , Sumit Semwal , Jonathan Corbet , Alexandru Ardelean , dri-devel , linaro-mm-sig@lists.linaro.org, Linux Documentation List , Linux Kernel Mailing List , linux-iio Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 28, 2022 at 11:30 PM Paul Cercueil wrote= : > Le lun., mars 28 2022 at 18:54:25 +0100, Jonathan Cameron > a =C3=A9crit : > > On Mon, 7 Feb 2022 12:59:28 +0000 > > Paul Cercueil wrote: > > > >> Enhance the current fileio code by using DMABUF objects instead of > >> custom buffers. > >> > >> This adds more code than it removes, but: > >> - a lot of the complexity can be dropped, e.g. custom kref and > >> iio_buffer_block_put_atomic() are not needed anymore; > >> - it will be much easier to introduce an API to export these DMABUF > >> objects to userspace in a following patch. > > I'm a bit rusty on dma mappings, but you seem to have > > a mixture of streaming and coherent mappings going on in here. > > That's OK, so am I. What do you call "streaming mappings"? dma_*_coherent() are for coherent mappings (usually you do it once and cache coherency is guaranteed by accessing this memory by device or CPU). dma_map_*() are for streaming, which means that you often want to map arbitrary pages during the transfer (usually used for the cases when you want to keep previous data and do something with a new coming, or when a new coming data is supplied by different virtual address, and hence has to be mapped for DMA). > > Is it the case that the current code is using the coherent mappings > > and a potential 'other user' of the dma buffer might need > > streaming mappings? > > Something like that. There are two different things; on both cases, > userspace needs to create a DMABUF with IIO_BUFFER_DMABUF_ALLOC_IOCTL, > and the backing memory is allocated with dma_alloc_coherent(). > > - For the userspace interface, you then have a "cpu access" IOCTL > (DMA_BUF_IOCTL_SYNC), that allows userspace to inform when it will > start/finish to process the buffer in user-space (which will > sync/invalidate the data cache if needed). A buffer can then be > enqueued for DMA processing (TX or RX) with the new > IIO_BUFFER_DMABUF_ENQUEUE_IOCTL. > > - When the DMABUF created via the IIO core is sent to another driver > through the driver's custom DMABUF import function, this driver will > call dma_buf_attach(), which will call iio_buffer_dma_buf_map(). Since > it has to return a "struct sg_table *", this function then simply > creates a sgtable with one entry that points to the backing memory. ... > >> + ret =3D dma_map_sgtable(at->dev, &dba->sg_table, dma_dir, 0); > >> + if (ret) { > >> + kfree(dba); > >> + return ERR_PTR(ret); > >> + } Missed DMA mapping error check. > >> + > >> + return &dba->sg_table; > >> +} ... > >> - /* Must not be accessed outside the core. */ > >> - struct kref kref; > >> + struct dma_buf *dmabuf; Is it okay to access outside the core? If no, why did you remove (actually not modify) the comment? --=20 With Best Regards, Andy Shevchenko