Received: by 10.223.185.116 with SMTP id b49csp4058831wrg; Mon, 19 Feb 2018 10:19:17 -0800 (PST) X-Google-Smtp-Source: AH8x227ADGutt4f/4NHLHyPgc+OR7bVwDBpo0YYJD1hf1Jp2hdw9allIBMh19zB7n0nZMLY0Ca7V X-Received: by 10.98.139.145 with SMTP id e17mr9512869pfl.53.1519064357875; Mon, 19 Feb 2018 10:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519064357; cv=none; d=google.com; s=arc-20160816; b=cdKzDJnngsyyaGIPpTFshAnZ1nzKWcUZNAywm78TlcG95rajBKok74flhWLi6dfLYL 6pIhRq+nHwrOVlFCCakZyeVca/C6G7Tx2RhdqvU4ItRnkWwyjgxYl0gO2oD64Gw+W0AG iLQiAJDHLRmf4H+/211deaTb9qSPUXM6moYRQ7l2lKTlh6X06PXU64Lh7OFnLDmu4W7B H8M9laOLyEmafFMeZAyOtAh/T9Bk1bgfgP29OCRdpNMnyRhg1gdZtTKNnQ3S+vO6l8EW dpKvSnvOts2jvFVECDNV2sOXKB6dex51QfsCwnC7xzw0x1EBrcTTt88WIglrT/a97MRG caNA== 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:to:subject:arc-authentication-results; bh=VSz46buVpcsaqgW1L1AtkutgdJENGtpIjQ5OSBPMfrE=; b=onl3ZrJyIqqwiVH1ud9Ppy6y4w3a6HXwgMckf5TPMOHsIYe6ILUcy0ozqUIkZr091P 858NRKUajp9aU9rSIstD9fgEbsQlLOrhPL07FYGAHQdURUGoXIFlnGKvNfYollRkTkg+ 07Pe5epSSgnIvkaYA2HcspFbbEIF0FRyQ2QISAMsB7LPgYkFg++SsAM+nShZkPok/VT6 CpzJ/0zyezXDLLV6TOzO7D+UbJ4APDAZSN3Uy2pEWEk7V/qXOU/edmiTYSomZQCp172h SrSm8IqD3cM7n0PNf1YjvwyQDPHYSKi76aHDlp8mxTM8ztemI0wGSV4/XQiY+r5YSVci RLAA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e92-v6si7596949pld.643.2018.02.19.10.19.03; Mon, 19 Feb 2018 10:19:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753469AbeBSSS0 (ORCPT + 99 others); Mon, 19 Feb 2018 13:18:26 -0500 Received: from mail-ot0-f195.google.com ([74.125.82.195]:45654 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753099AbeBSSSY (ORCPT ); Mon, 19 Feb 2018 13:18:24 -0500 Received: by mail-ot0-f195.google.com with SMTP id f11so3713627otj.12 for ; Mon, 19 Feb 2018 10:18:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VSz46buVpcsaqgW1L1AtkutgdJENGtpIjQ5OSBPMfrE=; b=T1yw9YnMYazQfEU0rtIC0Io0+ZYQovKvy5TI+XHygZl8AZFDZQ72gVwK6u+pYJzK0q dD1Z670xwkqNVbAUxSKti/fOwAOzU1hZE41fm3jKVTcEbX4P6aGIYiM0Z+54Q70ZykRw 3jBCHzZkUrmRhkTrMUF3zy8RYQu46EFKcuU9ijK6X5Ebwa+pV0sy+M/t0iVphwLB73SO z+RSHPOkl1s7SppaBqeRjkS8a2JsBRAk3OUFbEWJGc6rH8dphcnKgET6yTypFgo37tFe HYT62/KNOzKoIq0d2LQWSDsRn6keh/j7er1pdDUYoyFv+jVM1apVK2F3qvBFNQQsZkeZ Ymtg== X-Gm-Message-State: APf1xPCZgQsWIlPNyl3ePzLKk9Q3Q+MR6btuBdWbuzdEGr7qB8WMvw1I q7g4cAV9MEuSfAxy97unYvfjzA== X-Received: by 10.157.65.219 with SMTP id v27mr9958682oti.70.1519064303898; Mon, 19 Feb 2018 10:18:23 -0800 (PST) Received: from ?IPv6:2601:602:9802:a8dc::f21a? ([2601:602:9802:a8dc::f21a]) by smtp.gmail.com with ESMTPSA id u23sm9870979oiv.15.2018.02.19.10.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 10:18:22 -0800 (PST) Subject: Re: [PATCH 2/2] selftests: ion: Add simple test with the vgem driver To: 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> <20180219153143.GS22199@phenom.ffwll.local> From: Laura Abbott Message-ID: Date: Mon, 19 Feb 2018 10:18:21 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180219153143.GS22199@phenom.ffwll.local> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/19/2018 07:31 AM, Daniel Vetter wrote: > 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 Thanks for the review. The reason I didn't use the standard drmIoctl was because I didn't want to introduce a dependency on libdrm. I don't see an example of another selftest having a dependency on an external library. Is adding a dependencies on fairly standard but still external userspace libraries okay for kernel self tests? Thanks, Laura