Received: by 10.223.185.116 with SMTP id b49csp3884087wrg; Mon, 19 Feb 2018 07:33:29 -0800 (PST) X-Google-Smtp-Source: AH8x224G3fKgVLM11kDkrxS49wwTOrHP4kx6WA8vj/QNQA0ZJ2at/xV+rJ+sx9q3vFRIleHtPGnb X-Received: by 10.99.121.5 with SMTP id u5mr10171989pgc.444.1519054409472; Mon, 19 Feb 2018 07:33:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519054409; cv=none; d=google.com; s=arc-20160816; b=q5fmfM5ifMpJZk7JBGu+zsBLETa+23n1Wp7jTNRidhS/j/+IdWcXL+eDkFGYyZjMvz 1A3mc3vhQOor96H3lQMvKugCwokGolg5hdjBXDfMz00wSM0c568InHcOWIx9xauAELs7 9d/Q4WW/LZj6ogF5YG9zWVE70hHwMN8niQVh7oj28MNrQi1/64/gYLtzQogI21QL442r GepUF8WcDPsrt8Ql0ekoHZdlEH++XcKpB8+5k0WKFkXSJMVb5Kvk0+Ui8DPlwu6tIFfl dd6uGn9NaPKxkcXm4swbuB4HxLeH1maA2SKJ5BsBAmVlqvzi+TfBvQs13euO6d5BcDW1 cfAQ== 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:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=1yQtDbURE33b3uqqfy5O5xAsfYFum+4nIQce7Dlqrjc=; b=DVz1Xod2tzhWu5lINAdME9Tcyi+2xlh2pVe3FzkMzb8P0YzZhlmmN5nrSKrLIoy4LX YxMEPEhC5lx3mAbxE7H7jOX0Iq5o9rfbV5wDKc2tlByfB+8HfmHBkdDXjm9CcUlFm3yj iJCqsTAFlrPTlfNpiiweqM36CiT9tdVDayGbC3AuwX+di9dkYO2sH8UxZA2oqCmbRaC2 pVI+xaU4rXcVFxUhH3hFnEMyx6Xp4uep0agv99M5JZCJZhDwavFFgyhw9RpvxpthxmQ2 9xPTHGN/jB9ij7WDcp5qo5558rxIMr490nJ+PbIDVJ1MCTnRtP66qmJgi8dxesLonf3y hxBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=FxQ106J5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si5952603plb.472.2018.02.19.07.33.14; Mon, 19 Feb 2018 07:33:29 -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=fail header.i=@ffwll.ch header.s=google header.b=FxQ106J5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753215AbeBSPbt (ORCPT + 99 others); Mon, 19 Feb 2018 10:31:49 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37280 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753199AbeBSPbr (ORCPT ); Mon, 19 Feb 2018 10:31:47 -0500 Received: by mail-wm0-f67.google.com with SMTP id v71so15818114wmv.2 for ; Mon, 19 Feb 2018 07:31:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=1yQtDbURE33b3uqqfy5O5xAsfYFum+4nIQce7Dlqrjc=; b=FxQ106J54CEW/ffT5cI/khvZOdBt7WybwI/FXw8YvP8RLz6VtKuJumJa13+4fjPOZR N+Hsf9q4acSaMbzAUAJQj/B3W0LSVfCZe4GRtSfsyHa0LY4uQ8Wtimh+8LWIyi+w4uDn RbshS2W0rkjtarNSbGyjApfjrbnT/7n4r6nkI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=1yQtDbURE33b3uqqfy5O5xAsfYFum+4nIQce7Dlqrjc=; b=h75Vt61Ts8UKMUmGdpe5q5uHCDJ2tY5fWPG/uN/CDdzTOs8v8axZCXXII41lJlqf9f Utfr2S1i07aQq29/kISCLGDFTIHHNP82QmFZ3JAPKZQfKZGXfBO3Dy1OTTtRjVpi2v5v 3ko14b97AyQrtZkynLU2wimIUy03mOQWrL7ApJZpIXhX7lUNYwKEBvFu60c51w6ST3ek xw/Kca3R457VeFe5ua7pUpY0ri8atgtzUMN+RXNhWconF+I6NJV/BaPiWqLyZqfD2Mk4 0iE9pYLZiSwzmyP9ot7UJZF8TvpIEf1gizSMGqjyETt5BARzNgy/eEVH6A23TSk/XXsl fYsA== X-Gm-Message-State: APf1xPByngetws0rBnE3D1JcJCm+G1YAbRpevQbWgJQnfSPBx/uRtz99 bshRqDnCbD4YDXwYIrV/efF2VDKh X-Received: by 10.80.177.244 with SMTP id n49mr18837709edd.239.1519054306098; Mon, 19 Feb 2018 07:31:46 -0800 (PST) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id n2sm18733368edl.74.2018.02.19.07.31.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Feb 2018 07:31:45 -0800 (PST) Date: Mon, 19 Feb 2018 16:31:43 +0100 From: Daniel Vetter To: Laura Abbott Cc: Sumit Semwal , devel@driverdev.osuosl.org, Todd Kjos , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Liam Mark , linux-kselftest@vger.kernel.org, Shuah Khan Subject: Re: [PATCH 2/2] selftests: ion: Add simple test with the vgem driver Message-ID: <20180219153143.GS22199@phenom.ffwll.local> Mail-Followup-To: Laura Abbott , Sumit Semwal , devel@driverdev.osuosl.org, Todd Kjos , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Liam Mark , linux-kselftest@vger.kernel.org, Shuah Khan References: <20180216012445.17264-1-labbott@redhat.com> <20180216012445.17264-3-labbott@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180216012445.17264-3-labbott@redhat.com> X-Operating-System: Linux phenom 4.14.0-3-amd64 User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 15, 2018 at 05:24:45PM -0800, Laura Abbott wrote: > Ion is designed to be a framework used by other clients who perform > operations on the buffer. Use the DRM vgem client as a simple consumer. > In conjunction with the dma-buf sync ioctls, this tests the full attach/map > path for the system heap. > > Signed-off-by: Laura Abbott > --- > tools/testing/selftests/android/ion/Makefile | 3 +- > tools/testing/selftests/android/ion/config | 1 + > tools/testing/selftests/android/ion/ionmap_test.c | 136 ++++++++++++++++++++++ > 3 files changed, 139 insertions(+), 1 deletion(-) > create mode 100644 tools/testing/selftests/android/ion/ionmap_test.c > > diff --git a/tools/testing/selftests/android/ion/Makefile b/tools/testing/selftests/android/ion/Makefile > index 96e0c448b39d..d23b6d537d8b 100644 > --- a/tools/testing/selftests/android/ion/Makefile > +++ b/tools/testing/selftests/android/ion/Makefile > @@ -2,7 +2,7 @@ > INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/ > CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g > > -TEST_GEN_FILES := ionapp_export ionapp_import > +TEST_GEN_FILES := ionapp_export ionapp_import ionmap_test > > all: $(TEST_GEN_FILES) > > @@ -14,3 +14,4 @@ include ../../lib.mk > > $(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c > $(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c > +$(OUTPUT)/ionmap_test: ionmap_test.c ionutils.c > diff --git a/tools/testing/selftests/android/ion/config b/tools/testing/selftests/android/ion/config > index 19db6ca9aa2b..b4ad748a9dd9 100644 > --- a/tools/testing/selftests/android/ion/config > +++ b/tools/testing/selftests/android/ion/config > @@ -2,3 +2,4 @@ CONFIG_ANDROID=y > CONFIG_STAGING=y > CONFIG_ION=y > CONFIG_ION_SYSTEM_HEAP=y > +CONFIG_DRM_VGEM=y > diff --git a/tools/testing/selftests/android/ion/ionmap_test.c b/tools/testing/selftests/android/ion/ionmap_test.c > new file mode 100644 > index 000000000000..dab36b06b37d > --- /dev/null > +++ b/tools/testing/selftests/android/ion/ionmap_test.c > @@ -0,0 +1,136 @@ > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include > + > +#include > + > +#include "ion.h" > +#include "ionutils.h" > + > +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 1; > + > + return strcmp(name, "vgem"); > +} > + > +int open_vgem(void) > +{ > + int i, fd; > + const char *drmstr = "/dev/dri/card"; > + > + fd = -1; > + for (i = 0; i < 16; i++) { > + char name[80]; > + > + sprintf(name, "%s%u", drmstr, i); > + > + fd = open(name, O_RDWR); > + if (fd < 0) > + continue; > + > + if (check_vgem(fd)) { > + close(fd); > + continue; > + } else { > + break; > + } > + > + } > + return fd; > +} > + > +int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle) > +{ > + struct drm_prime_handle import_handle = { 0 }; > + int ret; > + > + import_handle.fd = dma_buf_fd; > + import_handle.flags = 0; > + import_handle.handle = 0; > + > + ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle); > + if (ret == 0) > + *handle = import_handle.handle; > + return ret; > +} > + > +void close_handle(int vgem_fd, uint32_t handle) > +{ > + struct drm_gem_close close = { 0 }; > + > + close.handle = handle; > + ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close); > +} > + > +int main() > +{ > + int ret, vgem_fd; > + struct ion_buffer_info info; > + uint32_t handle = 0; > + struct dma_buf_sync sync = { 0 }; > + > + info.heap_type = ION_HEAP_TYPE_SYSTEM; > + info.heap_size = 4096; > + info.flag_type = ION_FLAG_CACHED; > + > + ret = ion_export_buffer_fd(&info); > + if (ret < 0) { > + printf("ion buffer alloc failed\n"); > + return -1; > + } > + > + vgem_fd = open_vgem(); > + if (vgem_fd < 0) { > + ret = vgem_fd; > + printf("Failed to open vgem\n"); > + goto out_ion; > + } > + > + ret = import_vgem_fd(vgem_fd, info.buffd, &handle); > + > + if (ret < 0) { > + printf("Failed to import buffer\n"); > + goto out_vgem; > + } > + > + sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW; > + ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync); > + if (ret) > + printf("sync start failed %d\n", errno); > + > + memset(info.buffer, 0xff, 4096); > + > + sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW; > + ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync); > + if (ret) > + printf("sync end failed %d\n", errno); At least in drm we require that userspace auto-restarts all ioctls when they get interrupt. See https://cgit.freedesktop.org/drm/libdrm/tree/xf86drm.c#n186 not really an issue with vgem (which can't wait for hw or anything else). But good to make sure we don't spread bad copypastas. Actual use of the ioctls looks all good. With the drmIoctl wrapper added and used this is: Reviewed-by: Daniel Vetter > + > + close_handle(vgem_fd, handle); > + ret = 0; > + > +out_vgem: > + close(vgem_fd); > +out_ion: > + ion_close_buffer_fd(&info); > + printf("done.\n"); > + return ret; > +} > -- > 2.14.3 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch