From patchwork Fri Nov 11 11:45:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Wiecaszek X-Patchwork-Id: 18701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp692926wru; Fri, 11 Nov 2022 03:51:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7T+iXcbEyMydaHImL6dVjHpTr4Np3EGvn7zepvV7afZqKERrsiyE7jn+mMDPM4wNtqyAvQ X-Received: by 2002:aa7:c64d:0:b0:45c:fca7:e094 with SMTP id z13-20020aa7c64d000000b0045cfca7e094mr1096018edr.314.1668167485874; Fri, 11 Nov 2022 03:51:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668167485; cv=none; d=google.com; s=arc-20160816; b=ZHgPY2gYiNFTN3EglbaXhtyiHQoHuKWsNAOyCO+9KgbIyCZ/LvxGzcaYgl+S7//fAh gxLnchH2A/NUpLqoqI+LFeWC+4G4/auQUucMNVGzUDovN88pr1LffgEL6aAshD6qJxxW kGKOHxHU5AxU0sXdVazIuxN/C1lg30+VVdJwX9vh8tS85C20i7yl18X03iwNpKkFCzQ+ /MT8HB+A3STx7QYjU0jcgAoCsbBSTftBCJV5KRZpdwazxrkcxiLcR+521niXyUEE67yT UzJvAEOi1qrWGwF7hTZTNbb6+32QQozhAgFeNoVSMPLjigNd6PFAk7qxOPhq1izTG9b7 4e9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8+TGbcI0QMZONMioawRdiUS9+5vmjoD8ChogAY21Oa0=; b=yYQRF0Xjr98js1tbw8wulSFxYp1fKdLi60onevY0YvQR1HcWVDJvjINYZQ2tuniUlE tC1vNQDsv/6TvqO162xsUuIUhGyB4adqXM7soSbipfU1VAf7vEIJPOG5eEIGNwN1JanE NCspR/86xjW+EAmaCea27dH2umXkvAwWC1iV0ZejraZsIaNL2z4afuvdLFxtkX45QL3d 5uRgCIhiehtoTq0ZRGfxdOO82gggOFh1gJrtIgryF1llUJsQ/w5fpdsnaPsF2dN1nUBj kosoXr5dcofHREXIsbslyrZUv2LrJzxnn8SPIFcF+6aHk+tnjQZxgOI5AKVfUGbkp7/T a+hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=K5nlJPYQ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc10-20020a056402204a00b00457f5aa9dc6si1883080edb.528.2022.11.11.03.51.02; Fri, 11 Nov 2022 03:51:25 -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=@googlemail.com header.s=20210112 header.b=K5nlJPYQ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbiKKLqh (ORCPT + 99 others); Fri, 11 Nov 2022 06:46:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbiKKLqf (ORCPT ); Fri, 11 Nov 2022 06:46:35 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FFBE0BB; Fri, 11 Nov 2022 03:46:34 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id j4so8027906lfk.0; Fri, 11 Nov 2022 03:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8+TGbcI0QMZONMioawRdiUS9+5vmjoD8ChogAY21Oa0=; b=K5nlJPYQZx78+Mgn7RBBkCqYmu3Rn6ArgOwGOf2XXY7HAgZoJ9QjWVGhyg1cE6r9Rw kEQDEI+qTn83kiYVLHOOLrwoMQ5SCSru6awifHCwiI1tmWgqW7b1oa8ab36hG/fMWV2W ciFYrd6x3q5OcT7sYB9b0as4UqBgI9MAe5/vyuoHAKS+qPV89g6qVnLb3NKIrYMFZye3 rxHA0LvaUTUFkaLK+k7im6nbFwPvI3Ek1hPhrTbUpu4WR+sZQoDcnxBXKugB0Le3HpUc TQgeC4cYZWc3HBPSa5vA3e3mgnb2b5GWUkLAmkF2qtIscMbhLPxFP3N2xXIiVGAV8bxm BE0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8+TGbcI0QMZONMioawRdiUS9+5vmjoD8ChogAY21Oa0=; b=gDjDMohFLwoQEA+MMURID1VYGv5tFmQgRwg7K0GwiTFS3DhzY/Amm0ZmO8q/YlY/sF jg63RiW2y4Sfgqy/tcPikvO1aY5H/mi7bxHUs1Sc7efDefCPkRXO6B6VxSyI+F3USlPB fp2Knj3fUOG5620URMTsPe/mLYtjvVIrUOXY83c36rfLmY2byWdH0uQdBUbmDvvudXWG kEAFXMrCYdSqJMnbNewUhkyL/J7aVMdnSgW2tL1DzNklDJbUDzngjx8MxJoigAn19i/S agNIDtJ9tAfzLAIzdutOAMooSNjz8HduR3Y/Q5qAKDB/VG/OEhmyhw25D0hLZ3Zrrdca OyzA== X-Gm-Message-State: ANoB5pmxG+lU/1ptncTX8MhWUkxv6Rv9t3eEe5nZQZ+vOht4AygUOaMB aqVwpo1rFd7T+8lKPagWX8I= X-Received: by 2002:a19:e601:0:b0:4a8:e955:77e7 with SMTP id d1-20020a19e601000000b004a8e95577e7mr565011lfh.573.1668167192277; Fri, 11 Nov 2022 03:46:32 -0800 (PST) Received: from localhost.localdomain ([78.133.163.249]) by smtp.googlemail.com with ESMTPSA id 10-20020ac25f4a000000b004979ec19380sm281616lfz.285.2022.11.11.03.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 03:46:31 -0800 (PST) From: Lukasz Wiecaszek X-Google-Original-From: Lukasz Wiecaszek To: kraxel@redhat.com Cc: Lukasz Wiecaszek , 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 Subject: [PATCH] udmabuf: add vmap method to udmabuf_ops Date: Fri, 11 Nov 2022 12:45:28 +0100 Message-Id: <20221111114528.608801-1-lukasz.wiecaszek@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749200389737075201?= X-GMAIL-MSGID: =?utf-8?q?1749200389737075201?= 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 --- drivers/dma-buf/udmabuf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 2bcdb935a3ac..8649fcbd05c4 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -12,6 +12,7 @@ #include #include #include +#include static int list_limit = 1024; module_param(list_limit, int, 0644); @@ -26,6 +27,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 +59,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 dma_buf_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; + } + + dma_buf_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 +176,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, };