Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2997896ybx; Sun, 3 Nov 2019 08:28:01 -0800 (PST) X-Google-Smtp-Source: APXvYqy7BCv3CavaMMOC8q6o7yoHHOm24iNNrX645jTuL5DWoTQNHyWNI7g0LfUNNWB7hItLvpe0 X-Received: by 2002:a05:6402:160f:: with SMTP id f15mr15597513edv.41.1572798481129; Sun, 03 Nov 2019 08:28:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572798481; cv=none; d=google.com; s=arc-20160816; b=mfIfP472bYMD30McpqIsOa/lmuUNI3PZOcTIS/6HrSAWfdl4gBmw37mCPq0NeHKadD GC+ffhs3XcxHR70CO1ywCh0uKT9fwyEWKawUY2tKEMYLHe7WqGj75lu32cdXF4JycfPX HljhpIYG5rjhe8FClyVZBRO1Xh68H7IyoCUdXf3pyPjtswp/VgHlEoz2HeXlHjpXJz0D ocEFkcIGkdnQqwEwXf7JK3GFJ1RFZiMBYkz04FkkdnX4s18K6DvxAmW2DVJpqZ7hsp3F ppFBNjMhK5qKScGtPc/AP+z9kyPH+li4dhvpnQmQtFE+avV0UxcUYMCx/Btg93VqITz9 Anmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hrCICX4lUD1hzXvbY2RMWLfwu7sfeKbrgL9ER2BsDkA=; b=PT0VTZS/Dh44AnoyoxG1ZA1YPlVlLjh8lggWJgY74TbSIYdyYFbi7IAILUzP6+fPHi aHYsdgBNrerLwPXAzb2FhggrgT8gPgQ6Y58CnqRZQ8EJUjwBM784o/vpLvA7dvNr4+mK OLHCOrZyK9F8jqyAT0p7w7jLlkNa1D/RC/Wc60acSz9IsfXiywPINB+MpI2ZPxxMlK/0 yb+ZiGXMOub6mtS8byQwnNkDAp/Jzih6sPQWu3qP2mUpKqaFrXeUlpyCtl/QWwYg0cDs S5ifEiNLJBmztj6hPFz7/HwOGc2rRRFGUHk7krMfQ+lN8zDvKsPFBiMfE4JmHBoEeG9Z zBVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=c7cqFcEh; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si5474021edj.43.2019.11.03.08.27.37; Sun, 03 Nov 2019 08:28:01 -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=@android.com header.s=20161025 header.b=c7cqFcEh; 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=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbfKCQZv (ORCPT + 99 others); Sun, 3 Nov 2019 11:25:51 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36145 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727710AbfKCQZu (ORCPT ); Sun, 3 Nov 2019 11:25:50 -0500 Received: by mail-pg1-f193.google.com with SMTP id j22so9684941pgh.3 for ; Sun, 03 Nov 2019 08:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hrCICX4lUD1hzXvbY2RMWLfwu7sfeKbrgL9ER2BsDkA=; b=c7cqFcEhhoOez+81C90RV0pANxFTaEQwP6LSKMhMV+7GWHnC0omhitVB7FZjbKC99N rWoRDnNtBUKTBtKao7T5uQ/N1q/GBnAq9ZvT/cghD00ZxQRn0vwvlY7tbW+REL1U3wvw pjrOt+yp8T/nyGgjDSqKvrYLCluE49qTZ4kOZlakzGrQjan96bZTpC+PeZTCNUMwl//K z88E5n/X9PPr8CIUvnfU2pUkNmXkGU+1bgrqmT4tUc/X+wwT7TpUoWTYfy43jMLiaZEG 7s7yW/cG8mkBYYlpWu4dBfNIwhH7Xe+ltWHrCsmnPv/0XVC3SJFqOAUB2uNKzhSRd5e2 yJxA== 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:user-agent; bh=hrCICX4lUD1hzXvbY2RMWLfwu7sfeKbrgL9ER2BsDkA=; b=MzSNUbPnQR4pwPI30Gv40dqqxwtgrvGd3XznI6SaAGGW6fsZn1oC2k3hVIg2hysUTZ vYYeY+/dqxSKgRWCZ04Z2Oqwmrsbo8cIftf4HVb623IgMLD8Fay0PmwrXrSrttF3O6Ui DbOZtgVBJJYB9tX2/tJzf2dMYx5WBL9KayzL808DLJRdZJI6ecPFvLy/6EQ+mwSYYNlC f3rhstKMFFYFNIXdtWbhmfMvtIq+uecwQhYxsaZTXF33LUfyt0/YiWYE2H6q0Q35gxU7 xv7yiW/q1ZG02olH62TNrQHLtD+bv6PlstkK8pokWWPg8Knqe4WnxdZhQmxE13vGvIEv n5Og== X-Gm-Message-State: APjAAAUcwPRQTmiNqdxHqPn7+TCuv/jAtBuBd+5+WxGC/OtMOUQUR1ah TbcNr1JHR6qSz0irMB9bM5na5w== X-Received: by 2002:aa7:95ad:: with SMTP id a13mr26470776pfk.216.1572798350048; Sun, 03 Nov 2019 08:25:50 -0800 (PST) Received: from localhost ([66.167.121.235]) by smtp.gmail.com with ESMTPSA id r185sm13302728pfr.68.2019.11.03.08.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2019 08:25:49 -0800 (PST) Date: Sun, 3 Nov 2019 08:25:45 -0800 From: Sandeep Patil To: John Stultz Cc: lkml , Benjamin Gaignard , Sumit Semwal , Liam Mark , Pratik Patel , Brian Starkey , Vincent Donnefort , Sudipto Paul , "Andrew F . Davis" , Christoph Hellwig , Chenbo Feng , Alistair Strachan , Hridya Valsaraju , Hillf Danton , Dave Airlie , dri-devel@lists.freedesktop.org Subject: Re: [PATCH v14 5/5] kselftests: Add dma-heap test Message-ID: <20191103162545.GB116247@google.com> References: <20191101214238.78015-1-john.stultz@linaro.org> <20191101214238.78015-6-john.stultz@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191101214238.78015-6-john.stultz@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 01, 2019 at 09:42:38PM +0000, John Stultz wrote: > Add very trivial allocation and import test for dma-heaps, > utilizing the vgem driver as a test importer. > > A good chunk of this code taken from: > tools/testing/selftests/android/ion/ionmap_test.c > Originally by Laura Abbott > > Cc: Benjamin Gaignard > Cc: Sumit Semwal > Cc: Liam Mark > Cc: Pratik Patel > Cc: Brian Starkey > Cc: Vincent Donnefort > Cc: Sudipto Paul > Cc: Andrew F. Davis > Cc: Christoph Hellwig > Cc: Chenbo Feng > Cc: Alistair Strachan > Cc: Hridya Valsaraju > Cc: Sandeep Patil > Cc: Hillf Danton > Cc: Dave Airlie > Cc: dri-devel@lists.freedesktop.org > Reviewed-by: Benjamin Gaignard > Reviewed-by: Brian Starkey > Acked-by: Laura Abbott > Tested-by: Ayan Kumar Halder > Signed-off-by: John Stultz > --- > v2: > * Switched to use reworked dma-heap apis > v3: > * Add simple mmap > * Utilize dma-buf testdev to test importing > v4: > * Rework to use vgem > * Pass in fd_flags to match interface changes > * Skip . and .. dirs > v6: > * Number of style/cleanups suggested by Brian > v7: > * Whitespace fixup for checkpatch > v8: > * More checkpatch whitespace fixups > v9: > * Better handling error returns out to main, suggested > by Brian Starkey > * Switch to using snprintf, suggested by Brian > v14: > * Fix a missing return value > * Add calls to test the GET_FEATURES ioctl > * Build fix reported by kernel test robot > and fixed by Xiao Yang > * Minor Makefile cleanups > --- > tools/testing/selftests/dmabuf-heaps/Makefile | 6 + > .../selftests/dmabuf-heaps/dmabuf-heap.c | 255 ++++++++++++++++++ > 2 files changed, 261 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 000000000000..607c2acd2082 > --- /dev/null > +++ b/tools/testing/selftests/dmabuf-heaps/Makefile > @@ -0,0 +1,6 @@ > +# SPDX-License-Identifier: GPL-2.0 > +CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include > + > +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 000000000000..ec47901ef2e2 > --- /dev/null > +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c > @@ -0,0 +1,255 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include "../../../../include/uapi/linux/dma-heap.h" > + > +#define DEVPATH "/dev/dma_heap" > + > +static int check_vgem(int fd) > +{ > + drm_version_t version = { 0 }; > + char name[5]; > + int ret; > + > + version.name_len = 4; > + version.name = name; > + > + ret = ioctl(fd, DRM_IOCTL_VERSION, &version); > + if (ret) > + return 0; > + > + return !strcmp(name, "vgem"); > +} > + > +static int open_vgem(void) > +{ > + int i, fd; > + const char *drmstr = "/dev/dri/card"; > + > + fd = -1; > + for (i = 0; i < 16; i++) { > + char name[80]; > + > + snprintf(name, 80, "%s%u", drmstr, i); > + > + fd = open(name, O_RDWR); > + if (fd < 0) > + continue; > + > + if (!check_vgem(fd)) { > + close(fd); > + fd = -1; > + continue; > + } else { > + break; > + } > + } > + return fd; > +} > + > +static int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle) > +{ > + struct drm_prime_handle import_handle = { > + .fd = dma_buf_fd, > + .flags = 0, > + .handle = 0, > + }; > + int ret; > + > + ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle); > + if (ret == 0) > + *handle = import_handle.handle; > + return ret; > +} > + > +static void close_handle(int vgem_fd, uint32_t handle) > +{ > + struct drm_gem_close close = { > + .handle = handle, > + }; > + > + ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close); > +} > + > +static int dmabuf_heap_open(char *name) > +{ > + int ret, fd; > + char buf[256]; > + > + ret = snprintf(buf, 256, "%s/%s", DEVPATH, name); > + if (ret < 0) { > + printf("snprintf failed!\n"); > + return ret; > + } > + > + fd = open(buf, O_RDWR); > + if (fd < 0) > + printf("open %s failed!\n", buf); > + return fd; > +} > + > +static int dmabuf_heap_get_features(int fd, unsigned long long *features) > +{ > + struct dma_heap_get_features_data data = {0}; I'm curious if the test continues to work if you don't zero initialize here? (See my comment in patch 1/5) Acked-by: Sandeep Patil