Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4579530rwb; Sun, 13 Nov 2022 08:47:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vZgda1Tx7baH9fMhf8+B0XnonsYfUx9G0TxHmVfKx514LdigQ6jWdfOiNFrvewLw+Qrjp X-Received: by 2002:aa7:cf0a:0:b0:44e:cd80:843b with SMTP id a10-20020aa7cf0a000000b0044ecd80843bmr8457530edy.126.1668358057943; Sun, 13 Nov 2022 08:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668358057; cv=none; d=google.com; s=arc-20160816; b=tteA4cGyWxP1AisWsA6hRVtE8ng5o2C/Q4e//3iyRBfKePbPQMIw7aWo8ybivjLWJh G4QO1XpDWQQzW5ZD2RDqBsWj+alzYsnnKqXW238/TWMqKeqex/uE3rjZBop/pty4jMTW 3tU6asNiCzjtUaYROM9eFtq/4JRxwV3nHKOwTmYs/CFUelQj8T64uOoCJANlK8QUl5el fjpzGXspMSkARRMf5j6V3PWVpPvjKt37VApj2tibzxIRdVujR8KvMk+RI0Kyd5GGj6ld 0JZtTXm5lOvy89MihjsRiCxbqcYQTNIhKAcDbSMCWiETz3bm+0FTBUfGXqRyYmQkRIzc QUvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=75II8aVLccErDrODfAuDCdU454DausP6sL7oiS2Sm5k=; b=IvJuaTDZzkV5G7fAtSz5BMfHdhULanQzgKzSeAIRmLneC+PgyiRnCRSu0C6ZeniUgV j/umqILx9j9SN88KFh5vyNlmsJSR/vjz8Fp135c1/7s20QkTeWx+6bz+j7EQFwZ+Zgr1 ObHMwKhzXma2SQ/2J6U8mEhtn2FaS+Cy2FNMqQHZqx+JvDnzk+j8yYDWNbBP8Sy6wsOA oo8LiHcRGPX0ZWD7WNk+a8YxoHyTaw6CMlFirW4ktQ+n3r5/pB5wwDMgVd8nZO1IWdDh 3SyWglVW3I5ru+L65qVxkaXZq3B30Jvwe7hS926FzmJBs4JIjXuBKzAd7lgXvfG4dlAy gsvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gFZK+iuy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c73-20020a509fcf000000b004617df75676si7544956edf.245.2022.11.13.08.47.16; Sun, 13 Nov 2022 08:47:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=gFZK+iuy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235317AbiKMQ1c (ORCPT + 90 others); Sun, 13 Nov 2022 11:27:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbiKMQ13 (ORCPT ); Sun, 13 Nov 2022 11:27:29 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85025FFE; Sun, 13 Nov 2022 08:27:28 -0800 (PST) Received: from [192.168.2.125] (unknown [109.252.117.140]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 6E46F660036D; Sun, 13 Nov 2022 16:27:26 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668356847; bh=depGYhwkKPmSm4U0mvWNMVYV3VfG81IAL1hmomv9Y0g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gFZK+iuy/tTCaxzkIzB0TWH9EBcISskrDZy5noHC46JFBCkB8r5rIr1p9M9Full0S 9vJ5IdE+f3O2K/qhP95QoSOohhWeiLXsobZXetARESBFvl5231xj+FVyA10Yx2LBw6 GCNvRZnvwN32PbFTTDU33gHQlK9VJaPuKhpYRaacjataB6C/Dz/mMDtPeZrr9WJZwU 7Yi4BOaJNe68nA0bwPaO31AF4tghE8T30uf5fnImRIym3JiJ/E61qkovRtOe94B9+9 dl/39/9dUzeSxI2rUgqYkHoMo0IlrXXjHwYBykC9mNdIhuNtHwJzzrs1Dsvl8qFUCZ 1O69e41WwciqQ== Message-ID: <69cff33f-fd6e-f931-c469-a383d816b956@collabora.com> Date: Sun, 13 Nov 2022 19:27:22 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH v2] udmabuf: add vmap method to udmabuf_ops To: Lukasz Wiecaszek , Gerd Hoffmann Cc: Lukasz Wiecaszek , kernel test robot , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org References: <20221113150511.8878-1-lukasz.wiecaszek@gmail.com> Content-Language: en-US From: Dmitry Osipenko In-Reply-To: <20221113150511.8878-1-lukasz.wiecaszek@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 11/13/22 18:05, Lukasz Wiecaszek wrote: > The reason behind that patch is associated with videobuf2 subsystem > (or more genrally with v4l2 framework) and user created > dma buffers (udmabuf). In some circumstances > when dealing with V4L2_MEMORY_DMABUF buffers videobuf2 subsystem > wants to use dma_buf_vmap() method on the attached dma buffer. > As udmabuf does not have .vmap operation implemented, > such dma_buf_vmap() natually fails. > > videobuf2_common: [cap-000000003473b2f1] __vb2_queue_alloc: allocated 3 buffers, 1 plane(s) each > videobuf2_common: [cap-000000003473b2f1] __prepare_dmabuf: buffer for plane 0 changed > videobuf2_common: [cap-000000003473b2f1] __prepare_dmabuf: failed to map dmabuf for plane 0 > videobuf2_common: [cap-000000003473b2f1] __buf_prepare: buffer preparation failed: -14 > > The patch itself seems to be strighforward. > It adds implementation of .vmap method to 'struct dma_buf_ops udmabuf_ops'. > .vmap method itself uses vm_map_ram() to map pages linearly > into the kernel virtual address space (only if such mapping > hasn't been created yet). > > Signed-off-by: Lukasz Wiecaszek > Reported-by: kernel test robot > --- > v1: https://lore.kernel.org/linux-media/202211120352.G7WPASoP-lkp@intel.com/T/#t > > v1 -> v2: Patch prepared and tested against 6.1.0-rc2+ > > drivers/dma-buf/udmabuf.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c > index 2bcdb935a3ac..2ca0e3639360 100644 > --- a/drivers/dma-buf/udmabuf.c > +++ b/drivers/dma-buf/udmabuf.c > @@ -12,6 +12,8 @@ > #include > #include > #include > +#include > +#include > > static int list_limit = 1024; > module_param(list_limit, int, 0644); > @@ -26,6 +28,7 @@ struct udmabuf { > struct page **pages; > struct sg_table *sg; > struct miscdevice *device; > + void *vaddr; > }; > > static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) > @@ -57,6 +60,21 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) > return 0; > } > > +static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) > +{ > + struct udmabuf *ubuf = buf->priv; > + > + if (!ubuf->vaddr) { > + ubuf->vaddr = vm_map_ram(ubuf->pages, ubuf->pagecount, -1); > + if (!ubuf->vaddr) > + return -EINVAL; > + } > + > + iosys_map_set_vaddr(map, ubuf->vaddr); > + > + return 0; > +} > + > static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, > enum dma_data_direction direction) > { > @@ -159,6 +177,7 @@ static const struct dma_buf_ops udmabuf_ops = { > .unmap_dma_buf = unmap_udmabuf, > .release = release_udmabuf, > .mmap = mmap_udmabuf, > + .vmap = vmap_udmabuf, > .begin_cpu_access = begin_cpu_udmabuf, > .end_cpu_access = end_cpu_udmabuf, > }; Where is vunmap? -- Best regards, Dmitry