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 8D47AE99056 for ; Fri, 10 Apr 2026 08:28:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3FD4910E1B0; Fri, 10 Apr 2026 08:28:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="MpqZwMxU"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id A17B810E1B0 for ; Fri, 10 Apr 2026 08:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775809679; x=1807345679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TlwMHPBk/+D/gRyz7TZtx12wiifLgmqeb7/xr2+CSj4=; b=MpqZwMxULeNgAZXxM3m0uPChqZAy+m42CUxllaaBVxVk1/StukLmCXmk F1NhbEPJQC4SdR9q2JGZ9EtqZGslvbYYNk4h2yhY6BecQpTS7XdkXRCR8 9VQ/Xe1BCQnaRGjtTHjgkSr1RUlqkoutBChLHKGFDlGJmysaAn+6pUL3H KEqrYdx/RZ7HKBR79IO1H7tBGDbcXQx0QhJjhh2nB+REoWohC5sEHESVv 5itjKehIhW/H9zmqCk23/VQz0tBZh6Pd9XmpyVSvkKhif58+5NZGn9RNJ xuzQ8jGU/Sp3M7wzYObX/6H9JZhk4YDG5nOSLAA615rpgPIJj6h6zy2vk Q==; X-CSE-ConnectionGUID: hhSq7RYISfCV8LqFdS0MCw== X-CSE-MsgGUID: FwDqsofHTUqPoB+TQeFuFw== X-IronPort-AV: E=McAfee;i="6800,10657,11754"; a="64361539" X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="64361539" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 01:27:59 -0700 X-CSE-ConnectionGUID: wtoUigFITDi19Gt0OnSUiA== X-CSE-MsgGUID: pIT9X5jiSQe/kwkB2I1dSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="229301955" Received: from varungup-desk.iind.intel.com ([10.190.238.71]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 01:27:57 -0700 From: Arvind Yadav To: igt-dev@lists.freedesktop.org Cc: matthew.brost@intel.com, himal.prasad.ghimiray@intel.com, thomas.hellstrom@linux.intel.com, nishit.sharma@intel.com, pravalika.gurram@intel.com Subject: [PATCH i-g-t v8 4/8] tests/intel/xe_madvise: Add dontneed-after-mmap subtest Date: Fri, 10 Apr 2026 13:57:21 +0530 Message-ID: <20260410082729.2383886-5-arvind.yadav@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260410082729.2383886-1-arvind.yadav@intel.com> References: <20260410082729.2383886-1-arvind.yadav@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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" This test verifies that an existing mmap becomes invalid after the BO is marked as purgeable and purged. The test creates a BO, maps it, writes data, then marks it DONTNEED and triggers memory pressure. Accessing the previously valid mapping should now trigger SIGBUS or SIGSEGV, confirming that existing mappings are correctly invalidated when the backing store is purged. v4: - Added proper resource cleanup before calling igt_skip(). (Nishit) - Added assertion for xe_bo_map. (Nishit) v6: - Fix sigsetjmp(jmp, SIGBUS | SIGSEGV) to sigsetjmp(jmp, 1). The second argument is a plain boolean savemask, not a signal set. v7: - Move sigtrap/jmp_buf in this patch. (Nishit) Cc: Nishit Sharma Cc: Matthew Brost Cc: Thomas Hellström Cc: Himal Prasad Ghimiray Cc: Pravalika Gurram Signed-off-by: Arvind Yadav --- tests/intel/xe_madvise.c | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/intel/xe_madvise.c b/tests/intel/xe_madvise.c index 619d64b46..2d5acc347 100644 --- a/tests/intel/xe_madvise.c +++ b/tests/intel/xe_madvise.c @@ -153,6 +153,13 @@ static bool purgeable_mark_and_verify_purged(int fd, uint32_t vm, uint64_t addr, return retained == 0; } +static jmp_buf jmp; + +__noreturn static void sigtrap(int sig) +{ + siglongjmp(jmp, sig); +} + /** * SUBTEST: purged-mmap-blocked * Description: After BO is purged, verify mmap() fails with -EINVAL @@ -227,6 +234,64 @@ static void test_dontneed_before_mmap(int fd) xe_vm_destroy(fd, vm); } +/** + * SUBTEST: dontneed-after-mmap + * Description: Mark BO as DONTNEED after mmap, verify SIGBUS on accessing purged mapping + * Test category: functionality test + */ +static void test_dontneed_after_mmap(int fd) +{ + uint32_t bo, vm; + uint64_t addr = PURGEABLE_ADDR; + size_t bo_size = PURGEABLE_BO_SIZE; + void *map; + + purgeable_setup_simple_bo(fd, &vm, &bo, addr, bo_size, true); + + map = xe_bo_map(fd, bo, bo_size); + igt_assert(map != MAP_FAILED); + memset(map, 0xAB, bo_size); + + if (!purgeable_mark_and_verify_purged(fd, vm, addr, bo_size)) { + munmap(map, bo_size); + gem_close(fd, bo); + xe_vm_destroy(fd, vm); + igt_skip("Unable to induce purge on this platform/config"); + } + + /* Access purged mapping - should trigger SIGBUS/SIGSEGV */ + { + sighandler_t old_sigsegv, old_sigbus; + char *ptr = (char *)map; + int sig; + + old_sigsegv = signal(SIGSEGV, (__sighandler_t)sigtrap); + old_sigbus = signal(SIGBUS, (__sighandler_t)sigtrap); + + sig = sigsetjmp(jmp, 1); /* savemask=1: save/restore signal mask */ + switch (sig) { + case SIGBUS: + case SIGSEGV: + /* Expected - purged mapping access failed */ + break; + case 0: + *ptr = 0; + default: + igt_assert_f(false, + "Access to purged mapping should trigger SIGBUS, got sig=%d\n", + sig); + break; + } + + signal(SIGBUS, old_sigbus); + signal(SIGSEGV, old_sigsegv); + } + + munmap(map, bo_size); + gem_close(fd, bo); + xe_vm_destroy(fd, vm); +} + int igt_main() { struct drm_xe_engine_class_instance *hwe; @@ -251,6 +316,12 @@ int igt_main() break; } + igt_subtest("dontneed-after-mmap") + xe_for_each_engine(fd, hwe) { + test_dontneed_after_mmap(fd); + break; + } + igt_fixture() { xe_device_put(fd); drm_close_driver(fd); -- 2.43.0