From patchwork Tue Apr 1 22:35:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14035390 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 33454C3601B for ; Tue, 1 Apr 2025 22:35:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A25210E0AC; Tue, 1 Apr 2025 22:35:51 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="mQyczNhZ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1E15810E0AC; Tue, 1 Apr 2025 22:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743546950; x=1775082950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lWor+6pVWB0+BXew89U5BFaL9UK9ZSTnVj+addDNfaw=; b=mQyczNhZl0cm5e9ctnqCpBG3Z6E9jZ5jhU5fPPVpNdCJppMhMX/Q5kfW OKt8spV5BSR8qLtDwSYmsy0nCT91YwbdowYx+68rG5IOtYAjdS42vX52j 38lKDIQRZ6nAdNyFZ/B50s5BTARdwUL9H0Y3V2WEbJWJoQIw2hdjQ+Tgi dodrSULV7Ff8Y7AQji9zwXjWQTW+Crb8JT7NTYuORgIgUAukxzwu6t/Xx PxBFC97MkXkzcEWCExsuMWm3xJPfqj+DrK4nxxfdKq27mu+EE8KSbsSnD sp7nJ+vtNm3p3OtnJc5VAgmdPOG2bICAlMNmAVJligpV+cwdxUYh6Weoj w==; X-CSE-ConnectionGUID: rc//pOtbQpGW450hPmJJjg== X-CSE-MsgGUID: cQpJWna2SoSXW9qdDUXlmw== X-IronPort-AV: E=McAfee;i="6700,10204,11391"; a="44777460" X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="44777460" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:50 -0700 X-CSE-ConnectionGUID: /A5H9YcGQnGg/UF2opqokA== X-CSE-MsgGUID: k91rZMSjQPmCLKnKZ/lvmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="149695991" Received: from dut4066lnl.fm.intel.com ([10.105.8.54]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:49 -0700 From: Jonathan Cavitt To: igt-dev@lists.freedesktop.org Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com, jonathan.cavitt@intel.com, joonas.lahtinen@linux.intel.com, matthew.brost@intel.com, jianxun.zhang@intel.com, shuicheng.lin@intel.com, dri-devel@lists.freedesktop.org, stuart.summers@intel.com, ivan.briano@intel.com Subject: [PATCH v2 1/4] drm-uapi/xe: Declare xe_vm_get_property_ioctl Date: Tue, 1 Apr 2025 22:35:46 +0000 Message-ID: <20250401223549.101028-2-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250401223549.101028-1-jonathan.cavitt@intel.com> References: <20250401223549.101028-1-jonathan.cavitt@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Align with 20250401222657.78545-1-jonathan.cavitt@intel.com Add initial declarations for the xe_vm_get_property_ioctl call, including necessary structures and IOCTL macros. v2: - Remove engine class and instance (Ivan) Signed-off-by: Jonathan Cavitt Cc: Ivan Briano --- include/drm-uapi/xe_drm.h | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/include/drm-uapi/xe_drm.h b/include/drm-uapi/xe_drm.h index 154f947ef0..5c07713d52 100644 --- a/include/drm-uapi/xe_drm.h +++ b/include/drm-uapi/xe_drm.h @@ -81,6 +81,7 @@ extern "C" { * - &DRM_IOCTL_XE_EXEC * - &DRM_IOCTL_XE_WAIT_USER_FENCE * - &DRM_IOCTL_XE_OBSERVATION + * - &DRM_IOCTL_XE_VM_GET_PROPERTY */ /* @@ -102,6 +103,7 @@ extern "C" { #define DRM_XE_EXEC 0x09 #define DRM_XE_WAIT_USER_FENCE 0x0a #define DRM_XE_OBSERVATION 0x0b +#define DRM_XE_VM_GET_PROPERTY 0x0c /* Must be kept compact -- no holes */ @@ -117,6 +119,7 @@ extern "C" { #define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec) #define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence) #define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param) +#define DRM_IOCTL_XE_VM_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_GET_PROPERTY, struct drm_xe_vm_get_property) /** * DOC: Xe IOCTL Extensions @@ -1166,6 +1169,77 @@ struct drm_xe_vm_bind { __u64 reserved[2]; }; +/** struct xe_vm_fault - Describes faults for %DRM_XE_VM_GET_PROPERTY_FAULTS */ +struct xe_vm_fault { + /** @address: Address of the fault */ + __u64 address; + /** @address_precision: Precision of faulted address */ + __u32 address_precision; + /** @access_type: Type of address access that resulted in fault */ + __u8 access_type; + /** @fault_type: Type of fault reported */ + __u8 fault_type; + /** @fault_level: fault level of the fault */ + __u8 fault_level; + /** @pad: MBZ */ + __u8 pad; + /** @reserved: MBZ */ + __u64 reserved[4]; +}; + +/** + * struct drm_xe_vm_get_property - Input of &DRM_IOCTL_XE_VM_GET_PROPERTY + * + * The user provides a VM and a property to query among DRM_XE_VM_GET_PROPERTY_*, + * and sets the values in the vm_id and property members, respectively. This + * determines both the VM to get the property of, as well as the property to + * report. + * + * If size is set to 0, the driver fills it with the required size for the + * requested property. The user is expected here to allocate memory for the + * property structure and to provide a pointer to the allocated memory using the + * data member. For some properties, this may be zero, in which case, the + * value of the property will be saved to the value member and size will remain + * zero on return. + * + * If size is not zero, then the IOCTL will attempt to copy the requested + * property into the data member. + * + * The IOCTL will return -ENOENT if the VM could not be identified from the + * provided VM ID, or -EINVAL if the IOCTL fails for any other reason, such as + * providing an invalid size for the given property or if the property data + * could not be copied to the memory allocated to the data member. + * + * The property member can be: + * - %DRM_XE_VM_GET_PROPERTY_FAULTS + */ +struct drm_xe_vm_get_property { + /** @extensions: Pointer to the first extension struct, if any */ + __u64 extensions; + + /** @vm_id: The ID of the VM to query the properties of */ + __u32 vm_id; + +#define DRM_XE_VM_GET_PROPERTY_FAULTS 0 + /** @property: property to get */ + __u32 property; + + /** @size: Size to allocate for @data */ + __u32 size; + + /** @pad: MBZ */ + __u32 pad; + + union { + /** @data: Pointer to user-defined array of flexible size and type */ + __u64 data; + /** @value: Return value for scalar queries */ + __u64 value; + }; + + /** @reserved: MBZ */ + __u64 reserved[3]; +}; /** * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE * From patchwork Tue Apr 1 22:35:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14035391 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 35B6EC369A0 for ; Tue, 1 Apr 2025 22:35:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1784F10E68C; Tue, 1 Apr 2025 22:35:52 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Bcb98Cz7"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A3AB10E0AC; Tue, 1 Apr 2025 22:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743546951; x=1775082951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EegjHAouIXYQ7gyWNayidzRBJxX19BdfHBV9I1UGOJg=; b=Bcb98Cz7c9q+F+0L9vnxCbpZ8Lvlc1Pfsvx6OCtaE6u3eIP03rSvfbdf 4FEgOo0vZ5gjE/MqRJNWfw/JWaawkRQh7t2Sc98UCJEjHKwQX++NhG1BL O73txAOVJXwzMg1F8Ipyi9YXzCW+zQaSKZtrOIh0qrXUXu2DknWo3oKQd pDo8YptgsNgUAo3SrHPidZvCo7TVrjheIc4rSd03ySAR+EoQ0yfJKKj/L JPZj292YS9LYreEpvGPqV9lhIQLm5HI1Q8va4wn7hMpS9Dis42HyQ2N59 2GEcpgxvwVPhQndp3123N1Y3dTphGnxxlJisvIjbZA33DFB4EZW8OA3SL A==; X-CSE-ConnectionGUID: LJE8mqC6RKaLWT1JNml7GA== X-CSE-MsgGUID: zFNVI49nSaOMAeE0tasw9w== X-IronPort-AV: E=McAfee;i="6700,10204,11391"; a="44777461" X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="44777461" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:50 -0700 X-CSE-ConnectionGUID: BDLpQdE3RCW2NLcurBhNxA== X-CSE-MsgGUID: 1TN5dhGKT6uAv7AHChVu7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="149695995" Received: from dut4066lnl.fm.intel.com ([10.105.8.54]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:49 -0700 From: Jonathan Cavitt To: igt-dev@lists.freedesktop.org Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com, jonathan.cavitt@intel.com, joonas.lahtinen@linux.intel.com, matthew.brost@intel.com, jianxun.zhang@intel.com, shuicheng.lin@intel.com, dri-devel@lists.freedesktop.org, stuart.summers@intel.com, ivan.briano@intel.com Subject: [PATCH v2 2/4] lib/xe/xe_ioctl: Add xe_vm_get_property helper function Date: Tue, 1 Apr 2025 22:35:47 +0000 Message-ID: <20250401223549.101028-3-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250401223549.101028-1-jonathan.cavitt@intel.com> References: <20250401223549.101028-1-jonathan.cavitt@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a helper function, xe_vm_get_property, that calls the drm_xe_vm_get_property ioctl. Since the ioctl behaves similarly to an xe_query in that it needs to be called once to get the size of the return data and again to save the data, the helper function takes the ioctl structure as a parameter. Signed-off-by: Jonathan Cavitt --- lib/xe/xe_ioctl.c | 5 +++++ lib/xe/xe_ioctl.h | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c index 6d83889188..a82714cdfd 100644 --- a/lib/xe/xe_ioctl.c +++ b/lib/xe/xe_ioctl.c @@ -232,6 +232,11 @@ void xe_vm_unbind_sync(int fd, uint32_t vm, uint64_t offset, __xe_vm_bind_sync(fd, vm, 0, offset, addr, size, DRM_XE_VM_BIND_OP_UNMAP); } +void xe_vm_get_property(int fd, uint32_t vm, struct drm_xe_vm_get_property *query) +{ + igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, query), 0); +} + void xe_vm_destroy(int fd, uint32_t vm) { struct drm_xe_vm_destroy destroy = { diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h index 18cc2b72b2..cfeeb79f66 100644 --- a/lib/xe/xe_ioctl.h +++ b/lib/xe/xe_ioctl.h @@ -65,6 +65,7 @@ void xe_vm_bind_array(int fd, uint32_t vm, uint32_t exec_queue, void xe_vm_unbind_all_async(int fd, uint32_t vm, uint32_t exec_queue, uint32_t bo, struct drm_xe_sync *sync, uint32_t num_syncs); +void xe_vm_get_property(int fd, uint32_t vm, struct drm_xe_vm_get_property *query); void xe_vm_destroy(int fd, uint32_t vm); uint32_t __xe_bo_create(int fd, uint32_t vm, uint64_t size, uint32_t placement, uint32_t flags, uint32_t *handle); From patchwork Tue Apr 1 22:35:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14035392 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 C9330C3601E for ; Tue, 1 Apr 2025 22:35:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF6E610E691; Tue, 1 Apr 2025 22:35:53 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="HH6rg3B6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id BC5D310E67A; Tue, 1 Apr 2025 22:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743546951; x=1775082951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPB5OphYqrPK1wfSHf8eGz06pgpyDHehb6JsvFPTtRc=; b=HH6rg3B69LjZGhWg9NKo0B4c1jn+ixYocIGBQxUXjKRlz/5w8WK33mP+ Gy5opwGAoTijH/0iIMrbf2l/ooG56JKIl+jj50jO9ZVOj0h+5mWSHSnNV AmrGsShfABFsivbVXRv5rGEyU524V36RdEjGrrC/CvJXq968ymrpebnWr UfbI93vD2GQpFCFGvv0DGLYW78dLANHu7IwhLUIKw2Vg93QnbYjNuHO2d +UCHNyXwvj3Ete7DBd/xuMPlFz2I0vvR97HEX2CNaIsQfomvdBMguY2x7 3A6ULK+uDG4P7NcKrmDv4m0Dm9aOkWLeIYn44mr3o3A0pHYIz4UM2WVRT A==; X-CSE-ConnectionGUID: jf2kmQ9dSVGGH3pfFRYVZg== X-CSE-MsgGUID: pCAHBoq/QOi7QJVgGSReNw== X-IronPort-AV: E=McAfee;i="6700,10204,11391"; a="44777462" X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="44777462" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:50 -0700 X-CSE-ConnectionGUID: uKbjep6OTtqgB5AZ2y85lg== X-CSE-MsgGUID: 2E3Q8gk0SxWFeOa/aJDYzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="149695997" Received: from dut4066lnl.fm.intel.com ([10.105.8.54]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:49 -0700 From: Jonathan Cavitt To: igt-dev@lists.freedesktop.org Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com, jonathan.cavitt@intel.com, joonas.lahtinen@linux.intel.com, matthew.brost@intel.com, jianxun.zhang@intel.com, shuicheng.lin@intel.com, dri-devel@lists.freedesktop.org, stuart.summers@intel.com, ivan.briano@intel.com Subject: [PATCH v2 3/4] tests/intel/xe_vm: Add DRM_IOCTL_XE_VM_GET_PROPERTY validation tests Date: Tue, 1 Apr 2025 22:35:48 +0000 Message-ID: <20250401223549.101028-4-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250401223549.101028-1-jonathan.cavitt@intel.com> References: <20250401223549.101028-1-jonathan.cavitt@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add tests to xe_vm that exercise the new DRM_IOCTL_XE_VM_GET_PROPERTY ioctl. Specifically, add input validation tests that exercise the return values for improperly formatted ioctl structures. Signed-off-by: Jonathan Cavitt --- tests/intel/xe_vm.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c index fdf74c1140..536532579f 100644 --- a/tests/intel/xe_vm.c +++ b/tests/intel/xe_vm.c @@ -2343,6 +2343,72 @@ static void invalid_vm_id(int fd) do_ioctl_err(fd, DRM_IOCTL_XE_VM_DESTROY, &destroy, ENOENT); } +/** + * SUBTEST: vm-get-property-invalid-reserved + * Functionality: ioctl_input_validation + * Description: Check query with invalid reserved returns expected error code + * + * SUBTEST: vm-get-property-invalid-vm-id + * Functionality: ioctl_input_validation + * Description: Check query with invalid vm_id returns expected error code + * + * SUBTEST: vm-get-property-invalid-size + * Functionality: ioctl_input_validation + * Description: Check query with invalid size return expected error code + * + * SUBTEST: vm-get-property-invalid-property + * Functionality: ioctl_input_validation + * Description: Check query with invalid property returns expected error code + */ +static void get_property_invalid_reserved(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .reserved[0] = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void get_property_invalid_vm_id(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, ENOENT); +} + +static void get_property_invalid_size(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = vm, + .property = DRM_XE_VM_GET_PROPERTY_FAULTS, + .size = -1, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void get_property_invalid_property(int fd, uint32_t vm) +{ + struct drm_xe_vm_get_property query = { + .vm_id = vm, + .property = 0xdeadbeef, + }; + + do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); +} + +static void test_get_property(int fd, void (*func)(int fd, uint32_t vm)) +{ + uint32_t vm; + + vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE || + DRM_XE_VM_CREATE_FLAG_FAULT_MODE, 0); + func(fd, vm); + xe_vm_destroy(fd, vm); +} + igt_main { struct drm_xe_engine_class_instance *hwe, *hwe_non_copy = NULL; @@ -2455,6 +2521,17 @@ igt_main { } }; + const struct vm_get_property { + const char *name; + void (*test)(int fd, uint32_t vm); + } xe_vm_get_property_tests[] = { + { "invalid-reserved", get_property_invalid_reserved }, + { "invalid-vm-id", get_property_invalid_vm_id }, + { "invalid-size", get_property_invalid_size }, + { "invalid-property", get_property_invalid_property }, + { } + }; + igt_fixture { fd = drm_open_driver(DRIVER_XE); @@ -2734,6 +2811,11 @@ igt_main igt_subtest("invalid-vm-id") invalid_vm_id(fd); + for (const struct vm_get_property *f = xe_vm_get_property_tests; f->name; f++) { + igt_subtest_f("vm-get-property-%s", f->name) + test_get_property(fd, f->test); + } + igt_fixture drm_close_driver(fd); } From patchwork Tue Apr 1 22:35:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14035393 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 CBB8EC369A2 for ; Tue, 1 Apr 2025 22:35:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DCDC410E68F; Tue, 1 Apr 2025 22:35:52 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="AyxtTte1"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE08910E0AC; Tue, 1 Apr 2025 22:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743546951; x=1775082951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BP0hpLs2me+nkjEi7CKXG8TX+mVtTdPjcMD2b4sYkCY=; b=AyxtTte1sHtHGJSYY8jZlVPlpQRDjfF7sbUF4Qkqub7ecdrb1m+ux9k1 RGqbhJD+s7kc5OXkNPb9ZcKPqi0rBwBEIATgJly0F0SegUmho+2Y6yM/V KXa1xWxg7XSMtK6IoCElrP2aIDmgUV9CFh9DiU7efpLT2Y0J8SqLuudkV IEKW+jNMg8e9zgixiPnocPTr1F8Q71sgYuV5Dp587LtZ9dU2ZdP+KR3Hm XMoSgYbIrI/X/3VasKTXN5j4HpEZpqiG65S6C3fnye+Zrm1og9tAbYVih f0dmKoSwvoAjBUYlvpFhb6sLR28IFHMNkETS5iUxEykumFn5yTyh+DR+y g==; X-CSE-ConnectionGUID: 9Gg3+K6vScqL9/3rTBX34w== X-CSE-MsgGUID: qVB/K0wVRM64u2850Z+YSQ== X-IronPort-AV: E=McAfee;i="6700,10204,11391"; a="44777463" X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="44777463" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:50 -0700 X-CSE-ConnectionGUID: EVwOlsbxQQOUmuzOOYPWaQ== X-CSE-MsgGUID: duE1W2lES6eDJVnTyMzr/A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,294,1736841600"; d="scan'208";a="149696000" Received: from dut4066lnl.fm.intel.com ([10.105.8.54]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 15:35:49 -0700 From: Jonathan Cavitt To: igt-dev@lists.freedesktop.org Cc: saurabhg.gupta@intel.com, alex.zuo@intel.com, jonathan.cavitt@intel.com, joonas.lahtinen@linux.intel.com, matthew.brost@intel.com, jianxun.zhang@intel.com, shuicheng.lin@intel.com, dri-devel@lists.freedesktop.org, stuart.summers@intel.com, ivan.briano@intel.com Subject: [PATCH v2 4/4] tests/intel/xe_vm: Test DRM_IOCTL_XE_VM_GET_PROPERTY fault reporting Date: Tue, 1 Apr 2025 22:35:49 +0000 Message-ID: <20250401223549.101028-5-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250401223549.101028-1-jonathan.cavitt@intel.com> References: <20250401223549.101028-1-jonathan.cavitt@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a test to xe_vm that determines if pagefaults are correctly tracked and reported by the DRM_IOCTL_XE_VM_GET_PROPERTY. Signed-off-by: Jonathan Cavitt Suggested-by: Jianxun Zhang Suggested-by: Stuart Summers --- tests/intel/xe_vm.c | 159 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c index 536532579f..af62357894 100644 --- a/tests/intel/xe_vm.c +++ b/tests/intel/xe_vm.c @@ -2359,6 +2359,10 @@ static void invalid_vm_id(int fd) * SUBTEST: vm-get-property-invalid-property * Functionality: ioctl_input_validation * Description: Check query with invalid property returns expected error code + * + * SUBTEST: vm-get-property-exercise + * Functionality: drm_xe_vm_get_property + * Description: Check query correctly reports pageproperty on vm */ static void get_property_invalid_reserved(int fd, uint32_t vm) { @@ -2399,12 +2403,162 @@ static void get_property_invalid_property(int fd, uint32_t vm) do_ioctl_err(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query, EINVAL); } +static void +gen_pf(int fd, uint32_t vm, struct drm_xe_engine_class_instance *eci) +{ + int n_exec_queues = 2; + int n_execs = 2; + uint64_t addr = 0x1a0000; + struct drm_xe_sync sync[2] = { + { .type = DRM_XE_SYNC_TYPE_SYNCOBJ, .flags = DRM_XE_SYNC_FLAG_SIGNAL, }, + { .type = DRM_XE_SYNC_TYPE_SYNCOBJ, .flags = DRM_XE_SYNC_FLAG_SIGNAL, }, + }; + struct drm_xe_exec exec = { + .num_batch_buffer = 1, + .num_syncs = 2, + .syncs = to_user_pointer(sync), + }; + uint32_t exec_queues[2]; + uint32_t syncobjs[2]; + size_t bo_size; + uint32_t bo = 0; + struct { + struct xe_spin spin; + uint32_t batch[16]; + uint64_t pad; + uint32_t data; + } *data; + struct xe_spin_opts spin_opts = { .preempt = false }; + int i, b; + + bo_size = sizeof(*data) * n_execs; + bo_size = xe_bb_size(fd, bo_size); + + bo = xe_bo_create(fd, vm, bo_size, + vram_if_possible(fd, eci->gt_id), + DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM); + data = xe_bo_map(fd, bo, bo_size); + + for (i = 0; i < n_exec_queues; i++) { + exec_queues[i] = xe_exec_queue_create(fd, vm, eci, 0); + syncobjs[i] = syncobj_create(fd, 0); + }; + + sync[0].handle = syncobj_create(fd, 0); + xe_vm_bind_async(fd, vm, 0, bo, 0, addr, bo_size, sync, 1); + + for (i = 0; i < n_execs; i++) { + uint64_t base_addr = !i ? addr + bo_size * 128 : addr; + uint64_t batch_offset = (char *)&data[i].batch - (char *)data; + uint64_t batch_addr = base_addr + batch_offset; + uint64_t spin_offset = (char *)&data[i].spin - (char *)data; + uint64_t sdi_offset = (char *)&data[i].data - (char *)data; + uint64_t sdi_addr = base_addr + sdi_offset; + uint64_t exec_addr; + int e = i % n_exec_queues; + + if (!i) { + spin_opts.addr = base_addr + spin_offset; + xe_spin_init(&data[i].spin, &spin_opts); + exec_addr = spin_opts.addr; + } else { + b = 0; + data[i].batch[b++] = MI_STORE_DWORD_IMM_GEN4; + data[i].batch[b++] = sdi_addr; + data[i].batch[b++] = sdi_addr >> 32; + data[i].batch[b++] = 0xc0ffee; + data[i].batch[b++] = MI_BATCH_BUFFER_END; + igt_assert(b <= ARRAY_SIZE(data[i].batch)); + + exec_addr = batch_addr; + } + + sync[0].flags &= ~DRM_XE_SYNC_FLAG_SIGNAL; + sync[1].flags |= DRM_XE_SYNC_FLAG_SIGNAL; + sync[1].handle = syncobjs[e]; + + exec.exec_queue_id = exec_queues[e]; + exec.address = exec_addr; + if (e != i) + syncobj_reset(fd, &syncobjs[e], 1); + xe_exec(fd, &exec); + } + + for (i = 0; i < n_exec_queues && n_execs; i++) + igt_assert(syncobj_wait(fd, &syncobjs[i], 1, INT64_MAX, 0, + NULL)); + igt_assert(syncobj_wait(fd, &sync[0].handle, 1, INT64_MAX, 0, NULL)); + + sync[0].flags |= DRM_XE_SYNC_FLAG_SIGNAL; + xe_vm_unbind_async(fd, vm, 0, 0, addr, bo_size, sync, 1); + igt_assert(syncobj_wait(fd, &sync[0].handle, 1, INT64_MAX, 0, NULL)); + + syncobj_destroy(fd, sync[0].handle); + for (i = 0; i < n_exec_queues; i++) { + syncobj_destroy(fd, syncobjs[i]); + xe_exec_queue_destroy(fd, exec_queues[i]); + } + + munmap(data, bo_size); + gem_close(fd, bo); +} + +static void print_pf(struct xe_vm_fault *fault) +{ + igt_debug("FAULT:\n"); + igt_debug("address = 0x%08x%08x\n", + upper_32_bits(fault->address), + lower_32_bits(fault->address)); + igt_debug("address precision = %u\n", fault->address_precision); + igt_debug("access type = %u\n", fault->access_type); + igt_debug("fault type = %u\n", fault->fault_type); + igt_debug("fault level = %u\n", fault->fault_level); + igt_debug("\n"); +} + +static void get_property_exercise(int fd, uint32_t vm) +{ + struct drm_xe_engine_class_instance *hwe; + struct xe_vm_fault *faults, f0, f; + struct drm_xe_vm_get_property query = { + .vm_id = vm, + .property = DRM_XE_VM_GET_PROPERTY_FAULTS + }; + int i, fault_count; + + igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query), 0); + + igt_assert_eq(query.size, 0); + + xe_for_each_engine(fd, hwe) + gen_pf(fd, vm, hwe); + + igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query), 0); + igt_assert_lt(0, query.size); + + faults = malloc(query.size); + igt_assert(faults); + + query.data = to_user_pointer(faults); + igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_VM_GET_PROPERTY, &query), 0); + + fault_count = query.size / sizeof(struct xe_vm_fault); + f0 = faults[0]; + for (i = 0; i < fault_count; i++) { + f = faults[i]; + print_pf(&f); + igt_assert_eq(f.address, f0.address); + igt_assert_eq(f.access_type, f0.access_type); + igt_assert_eq(f.fault_type, f0.fault_type); + } + free(faults); +} + static void test_get_property(int fd, void (*func)(int fd, uint32_t vm)) { uint32_t vm; - vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE || - DRM_XE_VM_CREATE_FLAG_FAULT_MODE, 0); + vm = xe_vm_create(fd, 0, 0); func(fd, vm); xe_vm_destroy(fd, vm); } @@ -2529,6 +2683,7 @@ igt_main { "invalid-vm-id", get_property_invalid_vm_id }, { "invalid-size", get_property_invalid_size }, { "invalid-property", get_property_invalid_property }, + { "exercise", get_property_exercise }, { } };