Received: by 10.223.185.116 with SMTP id b49csp4416435wrg; Mon, 26 Feb 2018 17:49:52 -0800 (PST) X-Google-Smtp-Source: AH8x226YrqKmZekTh2xcMQaA7EHLqiq5zKwpn0yjeiZItOdY8b/dK1kdsVZaf1BrLAdP2AW1gYSv X-Received: by 2002:a17:902:6b88:: with SMTP id p8-v6mr12199159plk.261.1519696192056; Mon, 26 Feb 2018 17:49:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519696192; cv=none; d=google.com; s=arc-20160816; b=ctKRQYv1LJLziNFrXss32kRPmLYixiu84g1h4PZTQCf9KzuY5/aWrLcqnIcx1o+tOJ EX0FlanTpCcGQ2vcUnYw/VN4U6yg9MbXkt45vWDg38iNaSS1A88QSrCygqZY0zFsnhCe 3GltMSbvP98auXPDfhou5w0qjM4c6BAhAmLEc10KcUYZKlWZ2wDxAqygX8nwqF4hrNS4 wOvR2Y7jUkBrvucpxIQsLpYT0iNk7f7sg9cJEiVWFqdFaK8m+ZOe56AjZj1XSOqWC4ZE HCqCpFSwO68uIaIf3TFQqgUA+Vp4hmkbiBgAXOgzjwNpkmSykfuGgZJ+TMh8PLE/uQ1g fKfQ== 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=lH6t9yjDwkivmpzQBFdSCm1bYDPiH0XCX65NRyv44r4=; b=lskuqVLkDvE7Y/WbHmYzuJnkIqGoKjaB/NlDib8zycHQd3lpnd78lHp1oSbPaGm7hA 781Bgbui+9+6B0r3sv02gk9rcYvXxj1zlfIQVZRCpqxOT98AEh3DQ6UfWaZh60tICZK2 dVs13fzXvaQxDzt9DFUgrxGwrxdnujAjcL+EB5gvUOae6y4MH2Zw35ob1VSn1uKPYLdI DbTCj4Qvt3spQAQo8QWemf6VjyiN3ZssS2MFnEMrr5JZu/I2JomYVqnYzPTEktjMiZpl 5tlIHIX22hT9Zp1Jg5coIn0RZxT56H1WocKFKM1+BAUBuirxX8iYKgIeAy19lze3wMav Y48Q== 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 a71si6259308pge.378.2018.02.26.17.49.36; Mon, 26 Feb 2018 17:49:52 -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 S1751671AbeB0Bsm (ORCPT + 99 others); Mon, 26 Feb 2018 20:48:42 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:38688 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751448AbeB0Bsl (ORCPT ); Mon, 26 Feb 2018 20:48:41 -0500 Received: by mail-ot0-f196.google.com with SMTP id 95so2377186ote.5 for ; Mon, 26 Feb 2018 17:48:40 -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=lH6t9yjDwkivmpzQBFdSCm1bYDPiH0XCX65NRyv44r4=; b=jA1skh1PVBsl4HM3JeFeWtPXXrxTjrSiRsfJZ5Z80lMhSuraucp0z3dnufY2i86UZz qQN+Zse6v6WoNEF3QLv1gWk3TQRRaTnLoHPEpOyrIn5DvL+UxzHyCdDb96b2hu7igM+6 tngWRCJQUM4NOd+rJreaE2nTsyC/d29dp5Y/68AanU8rG6HHMWw74/7dcLlshEoWvg7r aaaxVKv86Zat4EhFHT1vRXKQvjYa7+SfAE42ZAwL2KoEHnfnumLTR1LlOwHtkrGAbpgd PyCEUQgp2UnMX8uLSShRbGAyFe/hDxnR1KNr07uIgYKIVAvh0QSMtM2MO9OeP11zD99W M43g== X-Gm-Message-State: APf1xPAKKg2z07nF+OviCRUNKFmQKF3XvPJT/kck/0b4ZvDhlpaFYPQx EqvTzDQgczfjjKnU7loRSRt+ow== X-Received: by 10.157.82.104 with SMTP id q40mr9457702otg.332.1519696120414; Mon, 26 Feb 2018 17:48:40 -0800 (PST) Received: from ?IPv6:2601:602:9802:a8dc::f21a? ([2601:602:9802:a8dc::f21a]) by smtp.gmail.com with ESMTPSA id d93sm5235456oic.51.2018.02.26.17.48.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 17:48:39 -0800 (PST) Subject: Re: [PATCH 2/2] selftests: ion: Add simple test with the vgem driver To: shuah@kernel.org, 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> <20180219183333.GD22199@phenom.ffwll.local> From: Laura Abbott Message-ID: Date: Mon, 26 Feb 2018 17:48:37 -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: 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/26/2018 09:07 AM, Shuah Khan wrote: > On 02/19/2018 11:33 AM, Daniel Vetter wrote: >> On Mon, Feb 19, 2018 at 10:18:21AM -0800, Laura Abbott wrote: >>> 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? > > We have cases where external libraries are used. fuse test probably is one > example. > >> >> Yeah adding a dependency isn't good, I'd just copypaste a local static >> version into the test file. That's good enough, the point isn't to use the >> libdrm one, but a wrapper that automatically restarts (every other >> userspace for gfx has their own copy of it since it's so trivial). > > Let's go ahead and use libdrm - It is important to keep them in sync. Maybe > we can check dependency in the ion Makefile and not compile the test. As long > as the rest of the tests run even when libdrm dependency isn't met, we should > be good. > > thanks, > -- Shuah > > The example you gave with fuse doesn't compile if you don't have the fuse library installed. I don't think adding a dependency on libdrm is worth it for a simple wrapper ioctl, especially since Daniel mention it gets copied around anyway. Thanks, Laura