From patchwork Thu Apr 3 17:48:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14037058 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 A5D29C369A1 for ; Thu, 3 Apr 2025 17:49:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1FCB210EA51; Thu, 3 Apr 2025 17:48:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="K8WAWYNz"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD1B610EA52; Thu, 3 Apr 2025 17:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743702538; x=1775238538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=riqy8J20mP4mPs+vLOW0NeReQgl8jku2ktz7ZCUL1xY=; b=K8WAWYNzvSy6FcwXiDCaaH5C1QTOyYyUU5AmbbR/pVJrPp1sKPoJ5Ros 6edBoSZ1Lz+sEOnyAQ8XYTQLqO7WhbvhKlLZzNnQBSa6/0QKpoBIuy+ov dpK5RALhFkST3mH5Lkb2HtWrfi2jZg3RThCbBBtXR5Kv3cBHZ9ySjlf6T Ne0couzkKhz1ZuPjNV93MyjXxdx2tv7W8k2pogNiVGFhnLUTOcq9VwsIL YDnjfojgYZKpf/sYRxyGMQ15xneWq6nf56VGUG94jZsDot8bwennQUAAW sMEWYEcFGCVqcify+ljdLw4QC0CLZgMQpANqN4mZ0Mf3OLADtoOoP8vJO g==; X-CSE-ConnectionGUID: tiCDFgmlRwCENNJ/J1+lOw== X-CSE-MsgGUID: y6GE+0UMQzyBJcFhUVE+RA== X-IronPort-AV: E=McAfee;i="6700,10204,11393"; a="55758510" X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="55758510" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:57 -0700 X-CSE-ConnectionGUID: O549+9/FR2e156mQvvLdpQ== X-CSE-MsgGUID: 2YeRg3B6SDim6EuAksMOCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="158057922" Received: from dut138lnl.fm.intel.com ([10.105.23.23]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:57 -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 v3 1/4] drm-uapi/xe: Declare xe_vm_get_property_ioctl Date: Thu, 3 Apr 2025 17:48:53 +0000 Message-ID: <20250403174856.75458-2-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403174856.75458-1-jonathan.cavitt@intel.com> References: <20250403174856.75458-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 20250403173614.67195-4-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) v3: - Add declares for fault type, access type, and fault level (Matt Brost, Ivan) Signed-off-by: Jonathan Cavitt Cc: Ivan Briano --- include/drm-uapi/xe_drm.h | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/include/drm-uapi/xe_drm.h b/include/drm-uapi/xe_drm.h index 154f947ef0..8380508d18 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,88 @@ 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 */ +#define FAULT_ACCESS_TYPE_READ 0 +#define FAULT_ACCESS_TYPE_WRITE 1 +#define FAULT_ACCESS_TYPE_ATOMIC 2 + __u8 access_type; + /** @fault_type: Type of fault reported */ +#define FAULT_TYPE_NOT_PRESENT 0 +#define FAULT_TYPE_WRITE_ACCESS 1 +#define FAULT_TYPE_ATOMIC_ACCESS 2 + __u8 fault_type; + /** @fault_level: fault level of the fault */ +#define FAULT_LEVEL_PTE 0 +#define FAULT_LEVEL_PDE 1 +#define FAULT_LEVEL_PDP 2 +#define FAULT_LEVEL_PML4 3 +#define FAULT_LEVEL_PML5 4 + __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 Thu Apr 3 17:48:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14037059 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 708C2C369A2 for ; Thu, 3 Apr 2025 17:49:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A8CA510EA52; Thu, 3 Apr 2025 17:48:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JtWcQyXf"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id EEB8D10EA4C; Thu, 3 Apr 2025 17:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743702538; x=1775238538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EegjHAouIXYQ7gyWNayidzRBJxX19BdfHBV9I1UGOJg=; b=JtWcQyXfdBxiRM6s0NuYVUzPYjFTJJF5FnFDm6CE77kHnYSWJv5pIueE o85IxSMJsEYxP2VmmI69ydUgIPBpyjko/V3t/Nf6UNIrbyep3HncU1ByX CdKEJh7tepWLscLXA83RmPJwT6kzKzp+dv/XTYo9O52Z+VUlymqi2WkCQ 45JE6TJEVvthVQ+k4ZNoAfDmNd4KxFgy+i7rszguEnnU56kNUB2jaJcl+ 4rz6Ovnah74Ssd+dB5NoH86GSUzol1RJtpUM0wiZedS1bhY3DNyPJrwNC G7DHOaM015hGNkqfPhFSqPDnc1avdyvqWyCj5AT99CkZWzInaWQlx/WR7 Q==; X-CSE-ConnectionGUID: Gq02+w7cQJKmhVZVQhc6Sw== X-CSE-MsgGUID: ovjzoeV3RvaCgpK84XY7sw== X-IronPort-AV: E=McAfee;i="6700,10204,11393"; a="55758512" X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="55758512" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:58 -0700 X-CSE-ConnectionGUID: +VXl0ys4TaW3MyMABKQK/Q== X-CSE-MsgGUID: 4eLg9drcQkqsuzgyYvZprg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="158057925" Received: from dut138lnl.fm.intel.com ([10.105.23.23]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:57 -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 v3 2/4] lib/xe/xe_ioctl: Add xe_vm_get_property helper function Date: Thu, 3 Apr 2025 17:48:54 +0000 Message-ID: <20250403174856.75458-3-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403174856.75458-1-jonathan.cavitt@intel.com> References: <20250403174856.75458-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 Thu Apr 3 17:48:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14037061 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 BB700C3601A for ; Thu, 3 Apr 2025 17:49:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5FEA710EA57; Thu, 3 Apr 2025 17:49:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="iqQUrIRe"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 89B0B10EA4D; Thu, 3 Apr 2025 17:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743702538; x=1775238538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPB5OphYqrPK1wfSHf8eGz06pgpyDHehb6JsvFPTtRc=; b=iqQUrIReUr7biqKZe9Tz/1Vi7ZlgAuNpCSZPK0IEwC4TboIOn/QuzncC XyzwK2vppGN1tEIahqdswCCOzc8z6LsXkZMzOq5Et74VhbOEGDxRrsKQX qUC1kWA4MWWhnusv5HdyFlhrx7/FPSn2tdrBo1EWqThsSjK6EGQkrH7JF CIc4ZcSe2B8pE9bxeGvwT3hw9xvpgdOjjAvWIVHuILKMryrIq6x2ujCyZ GJNt9bDtkEXb95vRfuqL37kuKEEOvgrPFX1lx2IRvW9rI8rbiRiloCxK1 JHczm4PTUSIK0YNTrqJl2aVx63klciU4z30OerYRnkQ+I3tOLNTUPSscp w==; X-CSE-ConnectionGUID: 6SbXKqduSNyg5X86ARXesA== X-CSE-MsgGUID: cck870P9SJS+Ih/zoDsuwg== X-IronPort-AV: E=McAfee;i="6700,10204,11393"; a="55758513" X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="55758513" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:58 -0700 X-CSE-ConnectionGUID: xsWjHTwORMSL0srfUW9jPA== X-CSE-MsgGUID: iVOo8TlwRWGRGdFN/CxbKg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="158057929" Received: from dut138lnl.fm.intel.com ([10.105.23.23]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:58 -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 v3 3/4] tests/intel/xe_vm: Add DRM_IOCTL_XE_VM_GET_PROPERTY validation tests Date: Thu, 3 Apr 2025 17:48:55 +0000 Message-ID: <20250403174856.75458-4-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403174856.75458-1-jonathan.cavitt@intel.com> References: <20250403174856.75458-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 Thu Apr 3 17:48:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cavitt, Jonathan" X-Patchwork-Id: 14037060 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 C0984C369A3 for ; Thu, 3 Apr 2025 17:49:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BBB110EA56; Thu, 3 Apr 2025 17:49:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="NSqoa1AT"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id D92AF10EA4D; Thu, 3 Apr 2025 17:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743702539; x=1775238539; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BP0hpLs2me+nkjEi7CKXG8TX+mVtTdPjcMD2b4sYkCY=; b=NSqoa1ATUEYe71BSauFlnce44IKviGmlIC+aHu/TuObF6YTjWgKNA7Rs C118F7hWfu6zOab7Ae8QBhC/UZxFJXiViN+IlmwskcjGGTjx3sEhfWlQH wpPT0mVoCsG682eBP1SwRVZt5don7EGuQkQkcW7mzVuuDx/00VkoIjcwO 9L5UCHpYKiLr6SGeS9A60nIRlxaCAx6MA8Zh2E90UXIb0JDO04akDbQYO is3pjaKMi9dMLtxSSzbPePIJKpmAIGXCFPuFcQt0BIVR+aKRMH0oU54tA w1AlqDoPwYrUVxkm7M/kKRuhkxsgUNcfQexBqEwrM7yDQrccuWrcam02g A==; X-CSE-ConnectionGUID: bis+TiGzQyqWH+8RZ7yGhA== X-CSE-MsgGUID: b1fgbddwSWKVQHCMorNJMw== X-IronPort-AV: E=McAfee;i="6700,10204,11393"; a="55758514" X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="55758514" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:59 -0700 X-CSE-ConnectionGUID: pagAfMdGT5G6s0YXr4Z10g== X-CSE-MsgGUID: C7eM9NlXTdyc2u+cvIIszg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,186,1739865600"; d="scan'208";a="158057932" Received: from dut138lnl.fm.intel.com ([10.105.23.23]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2025 10:48:58 -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 v3 4/4] tests/intel/xe_vm: Test DRM_IOCTL_XE_VM_GET_PROPERTY fault reporting Date: Thu, 3 Apr 2025 17:48:56 +0000 Message-ID: <20250403174856.75458-5-jonathan.cavitt@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250403174856.75458-1-jonathan.cavitt@intel.com> References: <20250403174856.75458-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 }, { } };