From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F36DC3DA61 for ; Mon, 29 Jul 2024 16:03:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03E0E10E427; Mon, 29 Jul 2024 16:03:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="lu/40p42"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82E7310E427 for ; Mon, 29 Jul 2024 16:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1722269025; x=1753805025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5JOOBHn3jxXk+oOFtEEFl7b1MITuTnRl4MainG3tcL0=; b=lu/40p42aGasNoDRuteAiH/jWvUzSjZcAalItPeMp/qHVkcKLyCY/drq ILumllnUFd3vI1sSyv243DZbYWWv8gmENB2wa27ko8MYag8viqeb1qxXN +DMfHyv8exBs58k26XLxj09YIP800xyepdlVewVFkb4wW0NLiMN4yRziI OlzQgxV2G4r0TimVOpBlUemCuWMYJoxCA6ZsvDa50u04JwE/1AgS48zB5 JlJDgxfVRi/uNQh71ZMxgH3QLXC2BKLVlE78kxSWbNzCinJ8LwgDPo3qd bRI68pKo9XI1STHLf+aCw5l0+E5eKgfJhTUnsdKxp3cIXMghbLv8ZtKIc g==; X-CSE-ConnectionGUID: f88pyU4URKiyyJwkNZ6FnQ== X-CSE-MsgGUID: zE7sfQCPQraMMwdJwjhUiQ== X-IronPort-AV: E=McAfee;i="6700,10204,11148"; a="31427129" X-IronPort-AV: E=Sophos;i="6.09,246,1716274800"; d="scan'208";a="31427129" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2024 09:03:45 -0700 X-CSE-ConnectionGUID: G3GluwHKTNGGBx/vFjD/ng== X-CSE-MsgGUID: IH3EofhmRGuZE4BlVEwyfA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,246,1716274800"; d="scan'208";a="53737984" Received: from sschumil-mobl2.ger.corp.intel.com (HELO localhost.localdomain) ([10.245.246.217]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2024 09:03:42 -0700 From: Christoph Manszewski To: igt-dev@lists.freedesktop.org Cc: =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Kamil Konieczny , Dominik Grzegorzek , Maciej Patelczyk , =?UTF-8?q?Dominik=20Karol=20Pi=C4=85tkowski?= , Pawel Sikora , Andrzej Hajda , Kolanupaka Naveena , Mika Kuoppala , Gwan-gyeong Mun , Christoph Manszewski Subject: [PATCH 26/66] tests/xe_eudebug: Add basic-vm-access-parameters test Date: Mon, 29 Jul 2024 18:01:19 +0200 Message-Id: <20240729160159.37036-27-christoph.manszewski@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240729160159.37036-1-christoph.manszewski@intel.com> References: <20240729160159.37036-1-christoph.manszewski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Pawel Sikora This new test checks negative scenarios of VM_OPEN ioctl and pread/pwrite usage. Signed-off-by: Pawel Sikora Cc: Christoph Manszewski --- tests/intel/xe_eudebug.c | 143 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/tests/intel/xe_eudebug.c b/tests/intel/xe_eudebug.c index 50c944ba9..37b4f4e27 100644 --- a/tests/intel/xe_eudebug.c +++ b/tests/intel/xe_eudebug.c @@ -1167,6 +1167,146 @@ static void test_vm_access(int fd, unsigned int flags, int num_clients) false, XE_EUDEBUG_FILTER_EVENT_VM_BIND_OP); } +static void debugger_test_vma_parameters(struct xe_eudebug_debugger *d, + uint64_t client_handle, + uint64_t vm_handle, + uint64_t va_start, + uint64_t va_length) +{ + struct drm_xe_eudebug_vm_open vo = { 0, }; + uint64_t *v; + uint64_t items = va_length / sizeof(uint64_t); + int fd; + int r, i; + + v = malloc(va_length); + igt_assert(v); + + /* Negative VM open - bad client handle */ + vo.client_handle = client_handle + 123; + vo.vm_handle = vm_handle; + fd = igt_ioctl(d->fd, DRM_XE_EUDEBUG_IOCTL_VM_OPEN, &vo); + igt_assert(fd < 0); + + /* Negative VM open - bad vm handle */ + vo.client_handle = client_handle; + vo.vm_handle = vm_handle + 123; + fd = igt_ioctl(d->fd, DRM_XE_EUDEBUG_IOCTL_VM_OPEN, &vo); + igt_assert(fd < 0); + + /* Positive VM open */ + vo.client_handle = client_handle; + vo.vm_handle = vm_handle; + fd = igt_ioctl(d->fd, DRM_XE_EUDEBUG_IOCTL_VM_OPEN, &vo); + igt_assert_lte(0, fd); + + /* Negative pread - bad fd */ + r = pread(fd + 123, v, va_length, va_start); + igt_assert(r < 0); + + /* Negative pread - bad va_start */ + r = pread(fd, v, va_length, 0); + igt_assert(r < 0); + + /* Negative pread - bad va_start */ + r = pread(fd, v, va_length, va_start - 1); + igt_assert(r < 0); + + /* Positive pread - zero va_length */ + r = pread(fd, v, 0, va_start); + igt_assert_eq(r, 0); + + /* Negative pread - out of range */ + r = pread(fd, v, va_length + 1, va_start); + igt_assert_eq(r, va_length); + + /* Negative pread - bad va_start */ + r = pread(fd, v, 1, va_start + va_length); + igt_assert(r < 0); + + /* Positive pread - whole range */ + r = pread(fd, v, va_length, va_start); + igt_assert_eq(r, va_length); + + /* Positive pread */ + r = pread(fd, v, 1, va_start + va_length - 1); + igt_assert_eq(r, 1); + + for (i = 0; i < items; i++) + igt_assert_eq(v[i], va_start + i); + + for (i = 0; i < items; i++) + v[i] = va_start + i + 1; + + /* Negative pwrite - bad fd */ + r = pwrite(fd + 123, v, va_length, va_start); + igt_assert(r < 0); + + /* Negative pwrite - bad va_start */ + r = pwrite(fd, v, va_length, -1); + igt_assert(r < 0); + + /* Negative pwrite - zero va_start */ + r = pwrite(fd, v, va_length, 0); + igt_assert(r < 0); + + /* Negative pwrite - bad va_length */ + r = pwrite(fd, v, va_length + 1, va_start); + igt_assert_eq(r, va_length); + + /* Positive pwrite - zero va_length */ + r = pwrite(fd, v, 0, va_start); + igt_assert_eq(r, 0); + + /* Positive pwrite */ + r = pwrite(fd, v, va_length, va_start); + igt_assert_eq(r, va_length); + fsync(fd); + + close(fd); + free(v); +} + +static void vm_trigger_access_parameters(struct xe_eudebug_debugger *d, + struct drm_xe_eudebug_event *e) +{ + struct drm_xe_eudebug_event_vm_bind_op *eo = (void *)e; + + if (e->flags & DRM_XE_EUDEBUG_EVENT_CREATE) { + struct drm_xe_eudebug_event_vm_bind *eb; + + igt_debug("vm bind op event received with ref %lld, addr 0x%llx, range 0x%llx\n", + eo->vm_bind_ref_seqno, + eo->addr, + eo->range); + + eb = (struct drm_xe_eudebug_event_vm_bind *) + xe_eudebug_event_log_find_seqno(d->log, eo->vm_bind_ref_seqno); + igt_assert(eb); + + debugger_test_vma_parameters(d, eb->client_handle, eb->vm_handle, + eo->addr, eo->range); + xe_eudebug_debugger_signal_stage(d, eo->addr); + } +} + +/** + * SUBTEST: basic-vm-access-parameters + * Description: + * Check negative scenarios of VM_OPEN ioctl and pread/pwrite usage. + */ +static void test_vm_access_parameters(int fd, unsigned int flags, int num_clients) +{ + struct drm_xe_engine_class_instance *hwe; + + xe_for_each_engine(fd, hwe) + test_client_with_trigger(fd, flags, num_clients, + vm_access_client, + DRM_XE_EUDEBUG_EVENT_VM_BIND_OP, + vm_trigger_access_parameters, hwe, + false, XE_EUDEBUG_FILTER_EVENT_VM_BIND_OP); +} + #define PAGE_SIZE 4096 #define MDATA_SIZE (WORK_IN_PROGRESS_DRM_XE_DEBUG_METADATA_NUM * PAGE_SIZE) static void metadata_access_client(struct xe_eudebug_client *c) @@ -1331,6 +1471,9 @@ igt_main igt_subtest("basic-vm-access") test_vm_access(fd, 0, 1); + igt_subtest("basic-vm-access-parameters") + test_vm_access_parameters(fd, 0, 1); + igt_subtest("multiple-sessions") test_basic_sessions(fd, CREATE_VMS | CREATE_EXEC_QUEUES, 4, true); -- 2.34.1