Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4414751imb; Wed, 6 Mar 2019 12:51:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyESjG1EyJKMfcW3fGHaB32WZbsOmAgk5hyJNE1jfGrqvaLElOTTNprqA+uJ7f+0m3tv72w X-Received: by 2002:a65:6654:: with SMTP id z20mr7871850pgv.390.1551905465518; Wed, 06 Mar 2019 12:51:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551905465; cv=none; d=google.com; s=arc-20160816; b=m8t5mt49PwXNQQ4qljTg6Gq0as8+lLr1wCshc0DH8PB6ZINLihBljAMkCT9Lb+TO3r SSU5NyHwsgzZ7qQv3bK+Bxr19fa1RfwfjMAR+XJpCCkArZFN4muTezDHPV82593S5CGT Zf3gMgYdQf3hO0OBReLMy40Un040Jt9pazT1RjF5wf0vNwEdAygVXs9rFDAdvtvSZNYo 9/tMLiUR5bU2MmBydXjPnnn3i9/NJp21Wjtwn05AFzF7O68T/oEH0ogRuLrmsqQoeh+M QNg29kcI65ReCRmgq1nqk9U2es/4Bk+K3ceQaRw23WvMuGHUphHH7j9flCXTHYheriT6 aANQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=oBIn2LlCBeVvQa2EAXWKLEE2er0kFV9nytsYYqpmFao=; b=n1Lqyk6DEWD2ss3tMXYzoR15coWKkk2v8Q83gUtVaNBE6xbUiqABYBbyOS57bhvuDc rw9aXjL5fY9pPaYuXcW3m7nyKD7RusTkJDBeN7B4UuGkSWDsRk4805E0XncToL5drQw+ wztyFNAP8zFE0Bc3bjkhWLA7qt5CB0AJIXDL3oEFD58wd6UMky0Xj5IUgmI3UNTa0BMo ovYec0AELwby+a9LJC7yN+86wp/BWIF97fVuw7xKJcT8x0HK0QBvRHviC7219Pv5dLml 0Z7DahAhlcIxYdsaDqoD5ImfQc0NtuaeR39ZCgtBLBWNFY+NxAfloAC+UsWkxgvyfKto oYGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="FMYDGQ/W"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21si2222895plr.297.2019.03.06.12.50.47; Wed, 06 Mar 2019 12:51:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="FMYDGQ/W"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728677AbfCFSdR (ORCPT + 99 others); Wed, 6 Mar 2019 13:33:17 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:35192 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728582AbfCFSdR (ORCPT ); Wed, 6 Mar 2019 13:33:17 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x26IWsSL043085; Wed, 6 Mar 2019 12:32:55 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1551897175; bh=oBIn2LlCBeVvQa2EAXWKLEE2er0kFV9nytsYYqpmFao=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=FMYDGQ/WUUlnRuMsnJejWYP915h8ajK9udf1P1Ckko6414IXn8TogS+GU3MnNQeq6 lVVhfyF4cDfYjZf6jZBjRCGbK/Y/3DgtEMeUVC5vcgEY2zEg5fWA7wDCprfmgTRbMW kJQ36cRIMUMF2Z8ubDEz/onDs51G+TiOuH1bwE/Y= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x26IWs7F094264 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Mar 2019 12:32:54 -0600 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Wed, 6 Mar 2019 12:32:54 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Wed, 6 Mar 2019 12:32:54 -0600 Received: from [172.22.114.173] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x26IWrsb032111; Wed, 6 Mar 2019 12:32:53 -0600 Subject: Re: [RFC][PATCH 5/5 v2] kselftests: Add dma-heap test To: John Stultz CC: Benjamin Gaignard , lkml , Laura Abbott , Greg KH , Sumit Semwal , Liam Mark , Brian Starkey , Chenbo Feng , Alistair Strachan , ML dri-devel References: <1551819273-640-1-git-send-email-john.stultz@linaro.org> <1551819273-640-6-git-send-email-john.stultz@linaro.org> <7deadc25-c8b2-3b58-1867-86f7db3188fa@ti.com> From: "Andrew F. Davis" Message-ID: <5fbeb711-62f9-1619-cc50-15594713551f@ti.com> Date: Wed, 6 Mar 2019 12:32:53 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/6/19 12:19 PM, John Stultz wrote: > On Wed, Mar 6, 2019 at 10:15 AM Andrew F. Davis wrote: >> >> On 3/6/19 10:14 AM, Benjamin Gaignard wrote: >>> Le mar. 5 mars 2019 à 21:54, John Stultz a écrit : >>>> >>>> Add very trivial allocation test for dma-heaps. >>>> >>>> TODO: Need to actually do some validation on >>>> the returned dma-buf. >>>> >>>> Cc: Laura Abbott >>>> Cc: Benjamin Gaignard >>>> Cc: Greg KH >>>> Cc: Sumit Semwal >>>> Cc: Liam Mark >>>> Cc: Brian Starkey >>>> Cc: Andrew F. Davis >>>> Cc: Chenbo Feng >>>> Cc: Alistair Strachan >>>> Cc: dri-devel@lists.freedesktop.org >>>> Signed-off-by: John Stultz >>>> --- >>>> v2: Switched to use reworked dma-heap apis >>>> --- >>>> tools/testing/selftests/dmabuf-heaps/Makefile | 11 +++ >>>> tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 96 ++++++++++++++++++++++ >>>> 2 files changed, 107 insertions(+) >>>> create mode 100644 tools/testing/selftests/dmabuf-heaps/Makefile >>>> create mode 100644 tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c >>>> >>>> diff --git a/tools/testing/selftests/dmabuf-heaps/Makefile b/tools/testing/selftests/dmabuf-heaps/Makefile >>>> new file mode 100644 >>>> index 0000000..c414ad3 >>>> --- /dev/null >>>> +++ b/tools/testing/selftests/dmabuf-heaps/Makefile >>>> @@ -0,0 +1,11 @@ >>>> +# SPDX-License-Identifier: GPL-2.0 >>>> +CFLAGS += -static -O3 -Wl,-no-as-needed -Wall >>>> +#LDLIBS += -lrt -lpthread -lm >>>> + >>>> +# these are all "safe" tests that don't modify >>>> +# system time or require escalated privileges >>>> +TEST_GEN_PROGS = dmabuf-heap >>>> + >>>> + >>>> +include ../lib.mk >>>> + >>>> diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c >>>> new file mode 100644 >>>> index 0000000..06837a4 >>>> --- /dev/null >>>> +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c >>>> @@ -0,0 +1,96 @@ >>>> +// SPDX-License-Identifier: GPL-2.0 >>>> + >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> +#include "../../../../include/uapi/linux/dma-heap.h" >>>> + >>>> +#define DEVPATH "/dev/dma_heap" >>>> + >>>> +int dmabuf_heap_open(char *name) >>>> +{ >>>> + int ret, fd; >>>> + char buf[256]; >>>> + >>>> + ret = sprintf(buf, "%s/%s", DEVPATH, name); >>>> + if (ret < 0) { >>>> + printf("sprintf failed!\n"); >>>> + return ret; >>>> + } >>>> + >>>> + fd = open(buf, O_RDWR); >>>> + if (fd < 0) >>>> + printf("open %s failed!\n", buf); >>>> + return fd; >>>> +} >>>> + >>>> +int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags, int *dmabuf_fd) >>>> +{ >>>> + struct dma_heap_allocation_data data = { >>>> + .len = len, >>>> + .flags = flags, >>>> + }; >>>> + int ret; >>>> + >>>> + if (dmabuf_fd == NULL) >>>> + return -EINVAL; >>>> + >>>> + ret = ioctl(fd, DMA_HEAP_IOC_ALLOC, &data); >>>> + if (ret < 0) >>>> + return ret; >>>> + *dmabuf_fd = (int)data.fd; >>>> + return ret; >>>> +} >>>> + >>>> +#define ONE_MEG (1024*1024) >>>> + >>>> +void do_test(char *heap_name) >>>> +{ >>>> + int heap_fd = -1, dmabuf_fd = -1; >>>> + int ret; >>>> + >>>> + printf("Testing heap: %s\n", heap_name); >>>> + >>>> + heap_fd = dmabuf_heap_open(heap_name); >>>> + if (heap_fd < 0) >>>> + return; >>>> + >>>> + printf("Allocating 1 MEG\n"); >>>> + ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); >>>> + if (ret) >>>> + goto out; >>>> + >>>> + /* DO SOMETHING WITH THE DMABUF HERE? */ >>> >>> You can do a call to mmap and write a pattern in the buffer. >>> >> >> mmap is optional for DMA-BUFs, only attach/map are required. To test >> those we would need a dummy device, so a test kernel module may be >> needed to really exercise this. >> >> I have one I use for ION buffer testing, it consumes a DMA-BUF passed >> from userspace, attach/maps it to a dummy device then return the >> physical address of the first page of the buffer for validation. Might >> be a good test, but dummy devices don't always have the proper dma >> attributes set like a real device does, so it may also fail for some >> otherwise valid buffers. > > Cool! Do you mind sharing that? I might try to rework and integrate it > into this patchset? > Sure, top two patches here: > https://git.ti.com/ti-analog-linux-kernel/afd-analog/commits/dma-buf-to-phys Andrew > thanks > -john >