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 9E827C43458 for ; Tue, 30 Jun 2026 06:19:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 456C410E176; Tue, 30 Jun 2026 06:19:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DLqnbDwD"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3EA910E176 for ; Tue, 30 Jun 2026 06:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1782800316; x=1814336316; h=message-id:date:subject:to:cc:references:from: in-reply-to:mime-version; bh=vELJIdH3PoRq1YSaBagr6AAgMFYy9fOZ4LexLqpWigw=; b=DLqnbDwDywj8gTFonKIzNqGjeZLGc9Ghe8QH3Row+GCsNxizgp/+zNbp UugXODtEOp6ArV8PJ0v0ObMjzdCB8/yClGO21FpLBButlUQS1c114zy2s mHa3evXxC8RyT3ROsTOeT5E9dH7SrpQ5h402qMgeYzoeGBe8JuC09C50L OGtoWgY7f4BEtPljxwdgP5ONC+fnLQSRpoyaHPllBA9F2sQ0EcX+wm3fb eG41Jf1zTISuImKIPNBercST17kjfZvlL4lGYgRVGS7Q4IUYm9y4WN0u1 cWXbWKOvDoroGWNlwFWAKbHu1o6t0chgDo/RazWAavttSoSjTsXjH1kDJ Q==; X-CSE-ConnectionGUID: WX6QycpnRFCIMTiCKTV3AQ== X-CSE-MsgGUID: sHDiqaY5Ty2KXUWZPsJ4/A== X-IronPort-AV: E=McAfee;i="6800,10657,11832"; a="101049652" X-IronPort-AV: E=Sophos;i="6.24,233,1774335600"; d="scan'208,217";a="101049652" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2026 23:18:29 -0700 X-CSE-ConnectionGUID: 9wNx21QfRIiIv6hTGV5NbQ== X-CSE-MsgGUID: wh1yIQUoQSqI99QOK5k8Eg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,233,1774335600"; d="scan'208,217";a="257087908" Received: from fmsmsx903.amr.corp.intel.com ([10.18.126.92]) by fmviesa005.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jun 2026 23:18:28 -0700 Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) by fmsmsx903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Mon, 29 Jun 2026 23:18:28 -0700 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43 via Frontend Transport; Mon, 29 Jun 2026 23:18:28 -0700 Received: from CH5PR02CU005.outbound.protection.outlook.com (40.107.200.65) by edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.43; Mon, 29 Jun 2026 23:18:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=epYAzcWk1HMNP/COdWHl0bcH3mVy91g8TBUVLes4BJoogg5X3t9kxNdMXUkXyZDeT0a+0p0wbbU6fmZ0dlMep4pN4hs47E9QuON1y+iIytcXxwPh4ekd/xMze4epFE0/dR0YIK+YlZFAOGuMbrbcGp0eF9qr9vDNlT6YD8wZYwJBhcpesjqSF54jks2wMdW4Dowf2dl7mXUi1yWorQuSW0OK4js67ibI1NjKUXVDYinmRyOoMrOaLsVSDTAiStWrmGJy+MU+/JN9uACcDdELChdc9/1G4v2CN8z88RL9WHoujnC/3de5UrxZtcnEQyX+ZilLBTxTM38HB0qPiCurVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5ultVbC8hstU43je5Gbh633oSGV8Tk66xg1dh9G78z0=; b=tFWQrl9K/Wkdf1mB92E/VVkIa/jVirybXrt8m2ngHtSjRcm1H60cFIjAZr+HFsE1d5ExWTUTfZTJBAv9TMF1AzXbka5HZlosQ4gmxp6RXEuInOWb33ljUezybzjYiG4g/1z2RrNrxY/OQWKYWB5fuqEzMX3zt9reiKtvjlttXUOENcbJGqW7J3B9QyUtQ34XIbwmOkhnJuen+nEdRbRJcoSP2q3TFNKnU0JWXZYGFk8daat2OAW2PGB+7Ocnmokr7h243bQekZP++nHnP6/9xBpReV4kjbbOPrQ9b+vFpHJTyNry6B36fXTucixhSXYSWz2K7xl9FAK1eZwjLJuLwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from IA3PR11MB9037.namprd11.prod.outlook.com (2603:10b6:208:580::14) by SA3PR11MB8073.namprd11.prod.outlook.com (2603:10b6:806:301::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.139.20; Tue, 30 Jun 2026 06:18:19 +0000 Received: from IA3PR11MB9037.namprd11.prod.outlook.com ([fe80::397:50af:2184:932c]) by IA3PR11MB9037.namprd11.prod.outlook.com ([fe80::397:50af:2184:932c%7]) with mapi id 15.21.0159.018; Tue, 30 Jun 2026 06:18:18 +0000 Content-Type: multipart/alternative; boundary="------------xTIwCqSKlKwRIoovdwFAAXGv" Message-ID: Date: Tue, 30 Jun 2026 11:48:12 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH i-g-t] test/intel/xe_vm: Add oversubscribe concurrent bind stress subtest To: Sobin Thomas , CC: , References: <20260616124029.619373-1-sobin.thomas@intel.com> Content-Language: en-US From: "Sharma, Nishit" In-Reply-To: <20260616124029.619373-1-sobin.thomas@intel.com> X-ClientProxiedBy: MA5P287CA0163.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:1ba::11) To IA3PR11MB9037.namprd11.prod.outlook.com (2603:10b6:208:580::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR11MB9037:EE_|SA3PR11MB8073:EE_ X-MS-Office365-Filtering-Correlation-Id: 886616e2-073c-4ad1-6bbb-08ded66f605b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|376014|366016|1800799024|11063799006|22082099003|56012099006|18002099003|8096899003; X-Microsoft-Antispam-Message-Info: rTxxvA/LEK/qNtnZI8QPiIM5nbzorc/faIkUVhvd/DhPIp5MU/pbJl6MR0jsv3xZwdixToV+h6dtioNXlEdbNS9NruzRi076ijfBWnS2Ui6xeJHtLhq30dH237MLqWTrV2yJ8I6+Q6NZMrb15FxF1WNIKJIGDCkVuSQQYHc3+Qv74p4D3dSKSSAv405UVuuRPh5zwqnZ/vhsUy++uXkhpsrDIVcGwf4CFyToYSTZnc4e8OhJw88c8wfvTYDvLfOGeSEV23SetL/7854mjIS8VnaxbAP+qOrOOcdom9eaKRkbT8e6WTuLyACn/9GHRVoex43cbaQ/604l1FdB4tW/+d7wo6WTAfNc7xtozjf0dVtkiBvnQae+O7VPjrwYaHs4HjklXw8Wa6a666U9hQ1bg+SV4efBN0AgnYTMml854tjcvHAy6Ug+2mMx+z/zyzCU6XC8NnWkcqDLOIArj4w/UR/Bnao+pBO9TA/QB7j17lt4Y5xgys5JUcuimGPtts9eXfwWl0LAbE2unThiWNccPpCtcrTtEXInT1K7Zll3vH11PSp2XMvxKbYF36LHwfySUyO9RChB8Y9du9KchsxycXf1Mm7ZgQBkfOvL4iC5dwdWeBH+OgfJk4yhY7tB8T0X3Ncke3EsMvllG1j1wYtAl6ElD+T0p+6/kUXuiDIbHes= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR11MB9037.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(376014)(366016)(1800799024)(11063799006)(22082099003)(56012099006)(18002099003)(8096899003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WFRUcVAreFFuNHhGb2pmTkRVYlJueDdRR09PcWNzSGJSZjFyemhYa294cHZX?= =?utf-8?B?dm5KUmZGenRyM2ZLRTBxYVVrTEhOZHJzVi9KK1RyajZORWVqSWJPc0Y4YXZF?= =?utf-8?B?YThjai96Z1puMER0TlVRTm5YRzIzdTBPT3EvRVRtc01zZnJ6UjIrb3AxajRz?= =?utf-8?B?RzVkQ3dYNE5uUGZMd1UrS3k4UFpJUjM3UU5YaWVpOUVFNHB1d0FveUppY3Y1?= =?utf-8?B?MHUwMHgrNjRodzlOTWRadG9RcVRIY2k1T0FoM1FyMytLVVBlbnQ2Y2FOMEhW?= =?utf-8?B?eDRFOENKdEd3eEo2Vk5LRFRWTnp2Yng4aThhNVN6MDNCeHc4Qmt1enoyTjcr?= =?utf-8?B?d3pKSEFBbmFZY2dJT0MxNDBKdFpVOExDbXJUdmxtSW00SHc1Y0F3MGVUS2d2?= =?utf-8?B?TVEyRTdEUHdFa0x5OTRNc1pPUnljZnlpQjFoVzQyajY3L1NZb1J0Y0hPUHM0?= =?utf-8?B?MjZpYnlwNFVCSGErOXF6UGpzeFpVcVNtV1I3S2pMQXdJR0V5OFRJTHpuTUhW?= =?utf-8?B?czBWUHpPK2IyMjNuVThIbUdsMWZiT29FWERQdkwwcUNHVHkyTmlNRk0vRVlO?= =?utf-8?B?RW1zNGh2eE05aTFiNUprUWdsZmVnb2U1c1RZVHd6RTBRdG0rc0dRdkJ2Sk1t?= =?utf-8?B?N3dpRjNjYWxZUEd6L3YvcHZtU3dETmdIVExLNnpOcHdpZjRZV0pZdG9Leko4?= =?utf-8?B?Rm94QWVaSG8rOXlTMndoalZab2dKMmEwcjAzcDlzS3pIM0FSYlcvbFdndkwx?= =?utf-8?B?c25SaE5QUjA3UG81cmk2NWpTbktreWx4VklUMWk3YTBkYXVQbmU0RkU5eE8v?= =?utf-8?B?L281OFcvUnJBN2t2UktweUxFaGlNVVBrNm44cXRkSzBCVXZCSDRQMlREWE5G?= =?utf-8?B?cEVVYXlqOFRtYXAwb3FIbC8ycU4rUHJ0UW5xQ0VOcHpDL3FPSm1iK2EwZEpL?= =?utf-8?B?SDl3RkhtREhWY1RxOEIwSjRseGhLS3RsdWZCSHJWWVZidDBIdnVxRUZjQXg3?= =?utf-8?B?aGw2VkRXQVVvUDlHRmxLVHM5c3IwdG14M1BHVXdpbFBJU2dqZDYwM250NjZQ?= =?utf-8?B?K21MMHdlOWdmUGVHcjNRZG9XU3hER1VkTGNXQTFoVmxuUTlteHRNTUVvT2xj?= =?utf-8?B?NW9ZK1JTR3RpNmFzaU1rRkJqbGtuODJQTk9wek9RTXMxTStzakowbGFPT0l3?= =?utf-8?B?OW5lZG1BRG56bmVSWlBaVXZBY29WY3Y0OUxkU1RlZUszTkkxZzBnZ0JLbmxC?= =?utf-8?B?UzRUWURPckJwSGkvS2tjanB3UXg1RTNqZ0RVbU9WYXlsS3hlQkhEN0ZtZW85?= =?utf-8?B?RTFYckM1MHRiYzZIUU14bVFjVUd4TTRtazE4V29mZ1k3SmFEN1FBVkpPMzcv?= =?utf-8?B?aFg1UlN3Rm9BV2pYNEV2UmlpY3FPQklOQ1JOblBSVis5bzZpTDVRSmFxQ0xo?= =?utf-8?B?bEdqTFlkSXlRbk5pR2w5L3BvWG5FUGdTSEZkTmYyckhad3VtbmdxM0RzV0JH?= =?utf-8?B?KzI1RUZjQ1VjOERNdTN0N2JTNm1SWGxxVURweSt1M2c4ZWc2SDczM3RCY1oy?= =?utf-8?B?R01nMFduZjJBNWNEVzYzMVROV1NiMS9BMlNLdVl1OXljcnVBOGlkdlBjY0dm?= =?utf-8?B?ak4zcEx6Nmh5aFFpeVRaYXg0ZnIxa0RIWUtINWFiL1pyci8vbldtaVdNZy9z?= =?utf-8?B?M1d6VENtd25jVFRKWkdIYytodHBEWTRmdVRWbm9RRFl6R1piWnpyY3IzRDhj?= =?utf-8?B?ZWVNdmR4TEViR05EdU1HNVprdHd1VUdWYzZFVmQ2emtGVkhGa0Z5Y1Ara2d1?= =?utf-8?B?RzdxS1U4dzhNZ1VUOHY0S2VxcnpBTFowOE9Zbm4xTEk4YkNsM0RIdzQrRjNO?= =?utf-8?B?QTRNYzVJMGlCWWx5S2l1Z3JaVWNwOXhjYVIvK2NWN1lLNmtJSnhrUExNUVRh?= =?utf-8?B?K0RpUW5HNFVJRmdGTjVuejlUbWhMcno3dEVvTFRmTnhtV2ZsbjY0bC95SkpZ?= =?utf-8?B?bXRsQ25NNHNZWXFiNTVIR1hUeUVsckdZbEhobEtXNVJodkdsMWlsYkRRVXV4?= =?utf-8?B?OWVoZ0lpbVpQT1pDOXFBdlpvNWxUR3FwTm5lbStJU3NVRzFUODZuenhxSHJu?= =?utf-8?B?S241WE9jNXNPdUhLRW1RWUMySzBtTnhtZzBjTHlmZ2diUmxqY2lMZEZYQ2FJ?= =?utf-8?B?aWJjRmc3NmFLS2pPajcrelRpSEI3aFBURDdYL2VWWTRpUkdmNHdxcjhhU0xk?= =?utf-8?B?VHc4OGRTUGpkZUptekd4K0tBRGVKN3UrcVZrTWpxWnFBUFExN3RkMVJBRCsx?= =?utf-8?B?RXVmZm1hRlFWSSsvZ05EWWFmL1pEWW9EMmthSVVTODU0OEtnSTdzZz09?= X-Exchange-RoutingPolicyChecked: LYEsqT75sSA1F5OWAGSbjQK7Q/nbIixHL6FHAB19QlxzAhgIoL703u5NGXHeCKGkXDdjn16kpVURCDleJw+tUc/3EZVLCPWoaFN2G1XfAGW5Yxc4CSroCZj6h6WoTHe2WJ1+Y0iPoHecykqAhxCZl06uGPMhxGzRiJXRekkMtN8F5LA+gcbEwX8etrLGfrnmfV1vFDeUXOS2vkvWklT+F/UKytkqVLAbcY4QJLutyU/GxDZhwOawDZh4mUJgqXpu45XOAGvuNxhlTo6TDJoPCWzWbrAt7nN0+/4RuO7dYd01D7vz6AvL0GoQB7tl/93efP2/ZaC4GrTVZBPmYgSo/A== X-MS-Exchange-CrossTenant-Network-Message-Id: 886616e2-073c-4ad1-6bbb-08ded66f605b X-MS-Exchange-CrossTenant-AuthSource: IA3PR11MB9037.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2026 06:18:18.8425 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NU4KBPyEu255d3uiNlW2WJkOQrUosU8x9jrH/nYsMS/M5fIma9QGMK2j4qjlZqs5shvcyqNl+8f6kVN5sFpCXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR11MB8073 X-OriginatorOrg: intel.com 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" --------------xTIwCqSKlKwRIoovdwFAAXGv Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit On 6/16/2026 6:10 PM, Sobin Thomas wrote: > Previous coverage lacked a scenario combining multi-process bind > with VRAM oversubscription. This generates memory pressure with > multi-process VM Bind activity and concurrent submission, exercising > the bind pipeline under eviction pressure. > > v7: Save errno immediately in create_test_bos before it can be clobbered. > Handle non-ENOMEM/ENOSPC failures in create_test_bos. > Remove dead code (retries == 0 check) in xe_exec_with_retry. > Add igt_skip when both vram and sram n_bufs are 0. > Add MAP_FAILED check on result_bo.ptr after xe_bo_map. (Nishit) > v8: Add error check while performing vmbind. > v9: Assert if vmbind fails for VRAM/ SRAM. > Moved wait fence for vm bind immediately after call. > > Signed-off-by: Sobin Thomas > --- > tests/intel/xe_vm.c | 456 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 456 insertions(+) > > diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c > index 408bfdb71..198ae1b99 100644 > --- a/tests/intel/xe_vm.c > +++ b/tests/intel/xe_vm.c > @@ -21,6 +21,8 @@ > #include "xe/xe_spin.h" > #include > #define USER_FENCE_VALUE 0xdeadbeefdeadbeefull > +#define GB(x) (1024ULL * 1024ULL * 1024ULL * (x)) > +#define TIMEOUT_NS (30ULL * 1000000000ULL) > > enum overcommit_stage { > EXPECT_NONE, > @@ -29,6 +31,93 @@ enum overcommit_stage { > EXPECT_EXEC, > }; > > +struct gem_bo { > + uint32_t handle; > + uint64_t size; > + int *ptr; > + uint64_t addr; > +}; > + > +struct xe_test_ctx { > + uint32_t vm_id; > + uint32_t exec_queue_id; > +}; > + > +struct mem_bind_sync { > + struct gem_bo *bufs; > + int n_bufs; > + uint64_t *binds_ufence; > +}; > + > +static void create_exec_queue(int fd, struct xe_test_ctx *ctx) > +{ > + struct drm_xe_engine_class_instance *hwe; > + struct drm_xe_engine_class_instance eci = { 0 }; > + > + /* Use first available engine */ > + xe_for_each_engine(fd, hwe) { > + eci = *hwe; > + break; > + } > + ctx->exec_queue_id = xe_exec_queue_create(fd, ctx->vm_id, &eci, 0); > +} > + > +static int xe_vm_bind_array_get_err(int fd, uint32_t vm, > + struct drm_xe_vm_bind_op *bind_ops, > + uint32_t num_bind, struct drm_xe_sync *sync, > + uint32_t num_syncs) > +{ > + struct drm_xe_vm_bind bind = { > + .vm_id = vm, > + .num_binds = num_bind, > + .vector_of_binds = (uintptr_t)bind_ops, > + .num_syncs = num_syncs, > + .syncs = (uintptr_t)sync, > + .exec_queue_id = 0, > + }; > + > + igt_assert(num_bind > 0); > + > + if (igt_ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind)) > + return -errno; > + > + return 0; > +} > + > +static uint64_t * > +vm_bind_bo_batch(int fd, struct xe_test_ctx *ctx, struct gem_bo *bos, int size, int *out_err) > +{ > + uint64_t *ufence; > + struct drm_xe_sync bind_sync; > + struct drm_xe_vm_bind_op binds[size]; > + int i, ret; > + > + ufence = calloc(1, sizeof(uint64_t)); > + igt_assert(ufence); > + *ufence = 0; > + bind_sync = (struct drm_xe_sync) { > + .type = DRM_XE_SYNC_TYPE_USER_FENCE, > + .flags = DRM_XE_SYNC_FLAG_SIGNAL, > + .addr = to_user_pointer(ufence), > + .timeline_value = 1, > + }; > + > + for (i = 0; i < size; i++) { > + binds[i] = (struct drm_xe_vm_bind_op) { > + .obj = bos[i].handle, > + .obj_offset = 0, > + .range = bos[i].size, > + .addr = bos[i].addr, > + .op = DRM_XE_VM_BIND_OP_MAP, > + .flags = 0, > + }; > + } > + ret = xe_vm_bind_array_get_err(fd, ctx->vm_id, binds, size, &bind_sync, 1); if bind fails it should return ENOMEM/ENOSPC and that should be handled gracefully. Idea is if bind() fails in memory pressure it should be handled gravefully. > + if (out_err) > + *out_err = ret; > + return ufence; > +} > + > static uint32_t > addr_low(uint64_t addr) > { > @@ -3073,6 +3162,368 @@ static void test_get_property(int fd, void (*func)(int fd, uint32_t vm)) > xe_vm_destroy(fd, vm); > } > > +static int build_add_batch(struct gem_bo *batch_bo, struct gem_bo *integers_bo, > + struct gem_bo *result_bo, int ints_to_add) > +{ > + int pos = 0; > + uint64_t tmp_addr; > + #define GPR_RX_ADDR(x) (0x600 + (x) * 8) > + > + batch_bo->ptr[pos++] = MI_LOAD_REGISTER_MEM_CMD | MI_LRI_LRM_CS_MMIO | 2; > + batch_bo->ptr[pos++] = GPR_RX_ADDR(0); > + tmp_addr = integers_bo->addr + 0 * sizeof(uint32_t); > + batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF; > + batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF; > + for (int i = 1; i < ints_to_add; i++) { > + /* r1 = integers_bo[i] */ > + batch_bo->ptr[pos++] = MI_LOAD_REGISTER_MEM_CMD | MI_LRI_LRM_CS_MMIO | 2; > + batch_bo->ptr[pos++] = GPR_RX_ADDR(1); > + tmp_addr = integers_bo->addr + i * sizeof(uint32_t); > + batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF; > + batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF; > + /* r0 = r0 + r1 */ > + batch_bo->ptr[pos++] = MI_MATH(4); > + batch_bo->ptr[pos++] = MI_MATH_LOAD(MI_MATH_REG_SRCA, MI_MATH_REG(0)); > + batch_bo->ptr[pos++] = MI_MATH_LOAD(MI_MATH_REG_SRCB, MI_MATH_REG(1)); > + batch_bo->ptr[pos++] = MI_MATH_ADD; > + batch_bo->ptr[pos++] = MI_MATH_STORE(MI_MATH_REG(0), MI_MATH_REG_ACCU); > + } > + /* result_bo[0] = r0 */ > + batch_bo->ptr[pos++] = MI_STORE_REGISTER_MEM_GEN8 | MI_LRI_LRM_CS_MMIO; > + batch_bo->ptr[pos++] = GPR_RX_ADDR(0); > + tmp_addr = result_bo->addr + 0 * sizeof(uint32_t); > + batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF; > + batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF; > + > + batch_bo->ptr[pos++] = MI_BATCH_BUFFER_END; > + while (pos % 4 != 0) > + batch_bo->ptr[pos++] = MI_NOOP; > + return pos; > +} > + > +static void create_test_bos(int fd, struct xe_test_ctx *ctx, struct mem_bind_sync *bind, > + uint32_t placement, uint64_t *addr) > +{ > + const char *mem_type = (placement & vram_memory(fd, 0)) ? "VRAM" : "SRAM"; > + uint32_t ret; > + > + for (int i = 0; i < bind->n_bufs; i++) { > + struct gem_bo *bo = &bind->bufs[i]; > + > + bo->size = GB(1); > + ret = __xe_bo_create_caching(fd, ctx->vm_id, bo->size, placement, 0, > + DRM_XE_GEM_CPU_CACHING_WC, &bo->handle); > + if (ret) { > + int saved_errno = errno; /* capture before anything can clobber it */ > + > + bind->n_bufs = i; > + if (saved_errno == ENOMEM || saved_errno == ENOSPC) > + igt_debug("%s allocation failed at buffer %d (OOM)\n", mem_type, i); > + else > + igt_assert_f(false, "%s allocation failed at buffer %d: %s", > + mem_type, i, strerror(saved_errno)); > + break; > + } > + bo->ptr = NULL; > + bo->addr = *addr; > + *addr += bo->size; > + igt_debug("%s buffer %d created at 0x%016lx\n", mem_type, i, bo->addr); > + } > +} > + > +static int fill_random_integers(struct gem_bo *int_bo, int ints_to_add) > +{ > + uint32_t expected_result = 0; > + > + for (int i = 0; i < ints_to_add; i++) { > + int random_int = rand() % 8; > + > + int_bo->ptr[i] = random_int; > + expected_result += random_int; > + > + igt_debug("%d", random_int); > + if (i + 1 != ints_to_add) > + igt_debug(" + "); > + else > + igt_debug(" = "); > + } > + igt_debug("%d\n", expected_result); > + return expected_result; > +} > + > +/* > + * In concurrent VM bind stress tests, multiple threads simultaneously bind > + * buffers to GPU virtual address space and submit batch operations. This > + * creates significant GPU memory pressure where the kernel may transiently > + * fail batch submission when: > + * - GPU page tables are being updated across multiple bindings > + * - GPU memory is fragmented across many concurrent buffer mappings > + * - Multiple processes compete for finite GPU resources > + * > + * Without retries, transient ENOMEM/ENOSPC failures cause false test failures. > + * Retrying lets us distinguish temporary resource exhaustion from actual > + * driver bugs. Non ENOMEM/ENOSPC errors still fail immediately and are properly > + * reported with full errno context for debugging. > + */ > +static int xe_exec_with_retry(int fd, struct drm_xe_exec *exec, int max_retries) > +{ > + int rc = 0, retries; > + > + for (retries = 1; retries < max_retries; retries++) { > + rc = igt_ioctl(fd, DRM_IOCTL_XE_EXEC, exec); > + > + if (!(rc && (errno == ENOMEM || errno == ENOSPC))) This condition should be in bind arrays as per requirement. For the graceful-failure requirement, expected ENOMEM/ENOSPC from bind path must be explicitly accepted and handled gracefully, not retried away at exec > + break; > + > + igt_warn("got %s, retrying (%d/%d)\n", strerror(errno), retries, max_retries); > + usleep(100 * retries); > + } > + > + if (retries == max_retries) > + igt_warn("gave up after %d retries\n", retries); > + > + if (rc) > + igt_warn("errno: %d (%s)\n", errno, strerror(errno)); > + > + return rc; > +} > + > +static void cleanup_bo_resources(int fd, struct gem_bo *bo) > +{ > + if (bo->ptr) { > + igt_assert_eq(munmap(bo->ptr, bo->size), 0); > + bo->ptr = NULL; > + } > + if (bo->handle) > + gem_close(fd, bo->handle); > +} > + > +static void cleanup_sram_vram_objs(int fd, struct mem_bind_sync *vram_bind, > + struct mem_bind_sync *sram_bind) > +{ > + for (int i = 0; i < vram_bind->n_bufs; i++) > + gem_close(fd, vram_bind->bufs[i].handle); > + for (int i = 0; i < sram_bind->n_bufs; i++) > + gem_close(fd, sram_bind->bufs[i].handle); > + free(vram_bind->bufs); > + free(sram_bind->bufs); > + if (vram_bind->n_bufs) > + free(vram_bind->binds_ufence); > + if (sram_bind->n_bufs) > + free(sram_bind->binds_ufence); > +} > + > +/** > + * SUBTEST: oversubscribe-concurrent-bind > + * Description: Test for oversubscribing the VM with multiple processes > + * doing binds at the same time, and ensure they all complete successfully. > + * Functionality: This check is for a specific bug where if multiple processes > + * oversubscribe the VM, some of the binds may fail with ENOMEM due to > + * deadlock in the bind code. > + * Test category: stress test > + */ > +static void test_vm_oversubscribe_concurrent_bind(int fd) > +{ > + #define MIN_BUFS_PER_PROC 2 > + #define MAX_THREADS 20 > + /* > + * Cap SRAM test usage on large-RAM platforms (e.g. PVC). On small-RAM > + * platforms (e.g. BMG with ~32 GB RAM) 50% of RAM is ~16 GB which is > + * below this cap, so behavior is unchanged. On large-RAM platforms > + * 50% can be hundreds of GB; cap it to a bounded value that still > + * provides meaningful memory pressure for the concurrent bind test. > + */ > + #define MAX_SRAM_TEST_SIZE GB(32) Make macros as global for better readability. > + int n_proc = 0, n_vram_bufs = 0, n_sram_bufs = 0; > + uint32_t max_by_mem; > + uint64_t total_vram_demand = 0; > + uint64_t vram_size = xe_visible_available_vram_size(fd, 0); > + uint64_t sram_avail = (uint64_t)igt_get_avail_ram_mb() << 20; > + uint64_t target_vram = vram_size * 2; > + uint64_t target_sram, total_vram_bufs, total_sram_bufs; > + pthread_barrier_t *barrier; > + pthread_barrierattr_t attr; > + /* > + * Dynamically cap VRAM oversubscription so the overflow into system > + * RAM stays within 25% of available RAM. On small-VRAM platforms > + * (e.g. BMG) the 2x target fits within the cap and behavior is > + * unchanged; on large-VRAM platforms (e.g. PVC) this prevents OOM. > + */ > + target_vram = min(target_vram, vram_size + sram_avail / 4); > + target_sram = min_t(uint64_t, sram_avail * 50 / 100, > + MAX_SRAM_TEST_SIZE); > + > + total_vram_bufs = target_vram / GB(1); > + total_sram_bufs = target_sram / GB(1); > + > + /* determine concurrency from memory pressure */ > + > + max_by_mem = min(total_vram_bufs / MIN_BUFS_PER_PROC, > + total_sram_bufs / MIN_BUFS_PER_PROC); > + n_proc = min_t(uint32_t, max_by_mem, MAX_THREADS); > + igt_require_f(n_proc > 0, "Not enough VRAM/RAM for oversubscription test\n"); > + > + n_vram_bufs = max_t(int, 2, total_vram_bufs / n_proc); > + n_sram_bufs = max_t(int, 2, total_sram_bufs / n_proc); > + total_vram_demand = (uint64_t)n_proc * n_vram_bufs * GB(1); > + > + igt_debug("VRAM size: %" PRIu64 "MB, System RAM available: %" PRIu64 "MB\n", > + vram_size >> 20, sram_avail >> 20); > + > + igt_debug(" n_proc = %d\n", n_proc); > + igt_debug("VRAM: %" PRIu64 "GB\n", vram_size >> 30); > + igt_debug("VRAM demand: %" PRIu64 "MB (%.2fx oversubscription)\n", > + total_vram_demand >> 20, (double)total_vram_demand / vram_size); > + igt_debug("Processes=%d VRAM_bufs=%d SRAM_bufs=%d\n", n_proc, > + n_vram_bufs, n_sram_bufs); > + > + barrier = mmap(NULL, sizeof(pthread_barrier_t), > + PROT_READ | PROT_WRITE, > + MAP_SHARED | MAP_ANONYMOUS, -1, 0); No need of mmap here. MMAP required if need to write something from CPU on address > + igt_assert(barrier != MAP_FAILED); > + pthread_barrierattr_init(&attr); > + pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); > + pthread_barrier_init(barrier, &attr, n_proc); SimpleĀ  pthread_barrier_t barrier and pthread_barrier_init(&barrier, Arg2, Arg3); can serve > + > + igt_fork(child, n_proc) { > + struct xe_test_ctx ctx = {0}; > + int rc; > + uint64_t addr = 0x40000000; > + int expected_result = 0, ints_to_add = 4; > + int max_retries = 1024; > + struct gem_bo integers_bo, result_bo, batch_bo, *vram_bufs, *sram_bufs; > + int pos = 0; > + struct mem_bind_sync vram_bind = {0}; > + struct mem_bind_sync sram_bind = {0}; > + struct drm_xe_sync batch_syncs[1]; > + struct drm_xe_exec exec; > + struct gem_bo ufence_bo = {0}; > + int vram_bind_err = 0, sram_bind_err = 0; > + > + vram_bufs = (struct gem_bo *)calloc(n_vram_bufs, sizeof(struct gem_bo)); > + sram_bufs = (struct gem_bo *)calloc(n_sram_bufs, sizeof(struct gem_bo)); > + srand(child); > + > + igt_assert(vram_bufs && sram_bufs); > + > + ctx.vm_id = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE, 0); > + create_exec_queue(fd, &ctx); > + vram_bind.bufs = vram_bufs; > + vram_bind.n_bufs = n_vram_bufs; > + sram_bind.bufs = sram_bufs; > + sram_bind.n_bufs = n_sram_bufs; > + > + create_test_bos(fd, &ctx, &vram_bind, vram_memory(fd, 0), &addr); > + create_test_bos(fd, &ctx, &sram_bind, system_memory(fd), &addr); > + > + if (!vram_bind.n_bufs && !sram_bind.n_bufs) > + igt_skip("No BOs allocated; VRAM/SRAM unavailable, skipping\n"); if vram_bind.n_bufs = 0 and sram_bind.n_bufs = 1 then igt_skip() will not be called which is not expected, right? If either of them is 0 then igt_skip() should be called. if (!vram_bind.n_bufs || !sram_bind.n_bufs) should be checked, If either is 0 igt_skip() will be called > + > + pthread_barrier_wait(barrier); > + > + if (vram_bind.n_bufs) { > + vram_bind.binds_ufence = > + vm_bind_bo_batch(fd, &ctx, vram_bufs, > + vram_bind.n_bufs, &vram_bind_err); > + xe_wait_ufence(fd, vram_bind.binds_ufence, 1, 0, TIMEOUT_NS); > + } > + if (vram_bind_err) > + igt_assert_f(0, "Unexpected VRAM bind error: %d", vram_bind_err); > + > + if (sram_bind.n_bufs) { > + sram_bind.binds_ufence = > + vm_bind_bo_batch(fd, &ctx, sram_bufs, > + sram_bind.n_bufs, &sram_bind_err); > + xe_wait_ufence(fd, sram_bind.binds_ufence, 1, 0, TIMEOUT_NS); > + } > + > + /* Assert if there is any bind error in SRAM */ > + if (sram_bind_err) > + igt_assert_f(0, "Unexpected SRAM bind error: %d", sram_bind_err); > + > + integers_bo.size = ALIGN(sizeof(int) * ints_to_add, 4096); What's the significance of ints_to_add here? If it's required then it should be in MACRO. Otherwise #define INT_SIZE 16 ALIGN(INT_SIZE, 4096) can serve. > + integers_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, integers_bo.size, > + system_memory(fd), 0, > + DRM_XE_GEM_CPU_CACHING_WC); > + integers_bo.ptr = (int *)xe_bo_map(fd, integers_bo.handle, integers_bo.size); > + integers_bo.addr = 0x100000; > + > + expected_result = fill_random_integers(&integers_bo, ints_to_add); > + igt_debug("%d\n", expected_result); > + > + result_bo.size = ALIGN(sizeof(int), 4096); > + result_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, result_bo.size, > + system_memory(fd), 0, > + DRM_XE_GEM_CPU_CACHING_WC); > + result_bo.ptr = NULL; > + result_bo.addr = 0x200000; > + > + batch_bo.size = 4096; > + batch_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, batch_bo.size, > + system_memory(fd), 0, > + DRM_XE_GEM_CPU_CACHING_WC); > + > + batch_bo.ptr = (int *)xe_bo_map(fd, batch_bo.handle, batch_bo.size); > + batch_bo.addr = 0x300000; > + > + pos = build_add_batch(&batch_bo, &integers_bo, &result_bo, ints_to_add); > + > + igt_assert(pos * sizeof(int) <= batch_bo.size); > + > + > + xe_vm_bind_lr_sync(fd, ctx.vm_id, integers_bo.handle, 0, integers_bo.addr, > + integers_bo.size, 0); > + xe_vm_bind_lr_sync(fd, ctx.vm_id, result_bo.handle, 0, result_bo.addr, > + result_bo.size, 0); > + xe_vm_bind_lr_sync(fd, ctx.vm_id, batch_bo.handle, 0, batch_bo.addr, > + batch_bo.size, 0); > + > + ufence_bo.size = 4096; > + ufence_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, ufence_bo.size, > + system_memory(fd), 0, > + DRM_XE_GEM_CPU_CACHING_WB); > + ufence_bo.ptr = (int *)xe_bo_map(fd, ufence_bo.handle, ufence_bo.size); > + ufence_bo.addr = 0x400000; > + memset(ufence_bo.ptr, 0, ufence_bo.size); > + xe_vm_bind_lr_sync(fd, ctx.vm_id, ufence_bo.handle, 0, ufence_bo.addr, > + ufence_bo.size, 0); > + > + batch_syncs[0] = (struct drm_xe_sync){ > + .type = DRM_XE_SYNC_TYPE_USER_FENCE, > + .flags = DRM_XE_SYNC_FLAG_SIGNAL, > + .addr = ufence_bo.addr, > + .timeline_value = 1, > + }; > + > + exec = (struct drm_xe_exec) { > + .exec_queue_id = ctx.exec_queue_id, > + .num_syncs = 1, > + .syncs = (uintptr_t)batch_syncs, > + .address = batch_bo.addr, > + .num_batch_buffer = 1, > + }; > + > + rc = xe_exec_with_retry(fd, &exec, max_retries); > + igt_assert_eq(rc, 0); > + xe_wait_ufence(fd, (uint64_t *)ufence_bo.ptr, 1, ctx.exec_queue_id, TIMEOUT_NS); > + result_bo.ptr = (int *)xe_bo_map(fd, result_bo.handle, result_bo.size); > + igt_assert(result_bo.ptr != MAP_FAILED); > + igt_assert_eq(result_bo.ptr[0], expected_result); > + cleanup_bo_resources(fd, &ufence_bo); > + cleanup_bo_resources(fd, &result_bo); > + cleanup_bo_resources(fd, &batch_bo); > + cleanup_bo_resources(fd, &integers_bo); > + cleanup_sram_vram_objs(fd, &vram_bind, &sram_bind); > + xe_exec_queue_destroy(fd, ctx.exec_queue_id); > + xe_vm_destroy(fd, ctx.vm_id); > + close(fd); > + } > + igt_waitchildren(); > + pthread_barrier_destroy(barrier); > + pthread_barrierattr_destroy(&attr); > + igt_assert_eq(munmap(barrier, sizeof(pthread_barrier_t)), 0); > +} > + > int igt_main() > { > struct drm_xe_engine_class_instance *hwe, *hwe_non_copy = NULL; > @@ -3486,6 +3937,11 @@ int igt_main() > igt_assert(xe_visible_vram_size(fd, 0)); > test_oom(fd); > } add one space and the call subtest > + igt_subtest("oversubscribe-concurrent-bind") > + { > + igt_require(xe_has_vram(fd)); > + test_vm_oversubscribe_concurrent_bind(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) --------------xTIwCqSKlKwRIoovdwFAAXGv Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 8bit


On 6/16/2026 6:10 PM, Sobin Thomas wrote:
Previous coverage lacked a scenario combining multi-process bind
with VRAM oversubscription. This generates memory pressure with
multi-process VM Bind activity and concurrent submission, exercising
the bind pipeline under eviction pressure.

v7:  Save errno immediately in create_test_bos before it can be clobbered.
     Handle non-ENOMEM/ENOSPC failures in create_test_bos.
     Remove dead code (retries == 0 check) in xe_exec_with_retry.
     Add igt_skip when both vram and sram n_bufs are 0.
     Add MAP_FAILED check on result_bo.ptr after xe_bo_map. (Nishit)
v8: Add error check while performing vmbind.
v9: Assert if vmbind fails for VRAM/ SRAM.
    Moved wait fence for vm bind immediately after call.

Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
---
 tests/intel/xe_vm.c | 456 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 456 insertions(+)

diff --git a/tests/intel/xe_vm.c b/tests/intel/xe_vm.c
index 408bfdb71..198ae1b99 100644
--- a/tests/intel/xe_vm.c
+++ b/tests/intel/xe_vm.c
@@ -21,6 +21,8 @@
 #include "xe/xe_spin.h"
 #include <string.h>
 #define USER_FENCE_VALUE 0xdeadbeefdeadbeefull
+#define GB(x) (1024ULL * 1024ULL * 1024ULL * (x))
+#define TIMEOUT_NS (30ULL * 1000000000ULL)
 
 enum overcommit_stage {
 	EXPECT_NONE,
@@ -29,6 +31,93 @@ enum overcommit_stage {
 	EXPECT_EXEC,
 };
 
+struct gem_bo {
+	uint32_t handle;
+	uint64_t size;
+	int *ptr;
+	uint64_t addr;
+};
+
+struct xe_test_ctx {
+	uint32_t vm_id;
+	uint32_t exec_queue_id;
+};
+
+struct mem_bind_sync {
+	struct gem_bo *bufs;
+	int n_bufs;
+	uint64_t *binds_ufence;
+};
+
+static void create_exec_queue(int fd, struct xe_test_ctx *ctx)
+{
+	struct drm_xe_engine_class_instance *hwe;
+	struct drm_xe_engine_class_instance eci = { 0 };
+
+	/* Use first available engine */
+	xe_for_each_engine(fd, hwe) {
+		eci = *hwe;
+		break;
+	}
+	ctx->exec_queue_id = xe_exec_queue_create(fd, ctx->vm_id, &eci, 0);
+}
+
+static int xe_vm_bind_array_get_err(int fd, uint32_t vm,
+				    struct drm_xe_vm_bind_op *bind_ops,
+				    uint32_t num_bind, struct drm_xe_sync *sync,
+				    uint32_t num_syncs)
+{
+	struct drm_xe_vm_bind bind = {
+		.vm_id = vm,
+		.num_binds = num_bind,
+		.vector_of_binds = (uintptr_t)bind_ops,
+		.num_syncs = num_syncs,
+		.syncs = (uintptr_t)sync,
+		.exec_queue_id = 0,
+	};
+
+	igt_assert(num_bind > 0);
+
+	if (igt_ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind))
+		return -errno;
+
+	return 0;
+}
+
+static uint64_t *
+vm_bind_bo_batch(int fd, struct xe_test_ctx *ctx, struct gem_bo *bos, int size, int *out_err)
+{
+	uint64_t *ufence;
+	struct drm_xe_sync bind_sync;
+	struct drm_xe_vm_bind_op binds[size];
+	int i, ret;
+
+	ufence = calloc(1, sizeof(uint64_t));
+	igt_assert(ufence);
+	*ufence = 0;
+	bind_sync = (struct drm_xe_sync) {
+		.type = DRM_XE_SYNC_TYPE_USER_FENCE,
+		.flags = DRM_XE_SYNC_FLAG_SIGNAL,
+		.addr = to_user_pointer(ufence),
+		.timeline_value = 1,
+	};
+
+	for (i = 0; i < size; i++) {
+		binds[i] = (struct drm_xe_vm_bind_op) {
+			.obj = bos[i].handle,
+			.obj_offset = 0,
+			.range = bos[i].size,
+			.addr = bos[i].addr,
+			.op = DRM_XE_VM_BIND_OP_MAP,
+			.flags = 0,
+		};
+	}
+	ret = xe_vm_bind_array_get_err(fd, ctx->vm_id, binds, size, &bind_sync, 1);
if bind fails it should return ENOMEM/ENOSPC and that should be handled gracefully. Idea is if bind() fails in memory pressure it should be handled gravefully.
+	if (out_err)
+		*out_err = ret;
+	return ufence;
+}
+
 static uint32_t
 addr_low(uint64_t addr)
 {
@@ -3073,6 +3162,368 @@ static void test_get_property(int fd, void (*func)(int fd, uint32_t vm))
 	xe_vm_destroy(fd, vm);
 }
 
+static int build_add_batch(struct gem_bo *batch_bo, struct gem_bo *integers_bo,
+			   struct gem_bo *result_bo, int ints_to_add)
+{
+	int pos = 0;
+	uint64_t tmp_addr;
+	#define GPR_RX_ADDR(x)		(0x600 + (x) * 8)
+
+	batch_bo->ptr[pos++] =  MI_LOAD_REGISTER_MEM_CMD | MI_LRI_LRM_CS_MMIO | 2;
+	batch_bo->ptr[pos++] = GPR_RX_ADDR(0);
+	tmp_addr = integers_bo->addr + 0 * sizeof(uint32_t);
+	batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF;
+	batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF;
+	for (int i = 1; i < ints_to_add; i++) {
+		/* r1 = integers_bo[i] */
+		batch_bo->ptr[pos++] =  MI_LOAD_REGISTER_MEM_CMD | MI_LRI_LRM_CS_MMIO | 2;
+		batch_bo->ptr[pos++] = GPR_RX_ADDR(1);
+		tmp_addr = integers_bo->addr + i * sizeof(uint32_t);
+		batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF;
+		batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF;
+		/* r0 = r0 + r1 */
+		batch_bo->ptr[pos++] = MI_MATH(4);
+		batch_bo->ptr[pos++] = MI_MATH_LOAD(MI_MATH_REG_SRCA, MI_MATH_REG(0));
+		batch_bo->ptr[pos++] = MI_MATH_LOAD(MI_MATH_REG_SRCB, MI_MATH_REG(1));
+		batch_bo->ptr[pos++] = MI_MATH_ADD;
+		batch_bo->ptr[pos++] = MI_MATH_STORE(MI_MATH_REG(0), MI_MATH_REG_ACCU);
+	}
+	/* result_bo[0] = r0 */
+	batch_bo->ptr[pos++] = MI_STORE_REGISTER_MEM_GEN8 | MI_LRI_LRM_CS_MMIO;
+	batch_bo->ptr[pos++] = GPR_RX_ADDR(0);
+	tmp_addr = result_bo->addr + 0 * sizeof(uint32_t);
+	batch_bo->ptr[pos++] = tmp_addr & 0xFFFFFFFF;
+	batch_bo->ptr[pos++] = (tmp_addr >> 32) & 0xFFFFFFFF;
+
+	batch_bo->ptr[pos++] = MI_BATCH_BUFFER_END;
+	while (pos % 4 != 0)
+		batch_bo->ptr[pos++] = MI_NOOP;
+	return pos;
+}
+
+static void create_test_bos(int fd, struct xe_test_ctx *ctx, struct mem_bind_sync *bind,
+			    uint32_t  placement, uint64_t *addr)
+{
+	const char *mem_type = (placement & vram_memory(fd, 0)) ? "VRAM" : "SRAM";
+	uint32_t ret;
+
+	for (int i = 0; i < bind->n_bufs; i++) {
+		struct gem_bo *bo = &bind->bufs[i];
+
+		bo->size = GB(1);
+		ret = __xe_bo_create_caching(fd, ctx->vm_id, bo->size, placement, 0,
+					     DRM_XE_GEM_CPU_CACHING_WC, &bo->handle);
+		if (ret) {
+			int saved_errno = errno; /* capture before anything can clobber it */
+
+			bind->n_bufs = i;
+			if (saved_errno == ENOMEM || saved_errno == ENOSPC)
+				igt_debug("%s allocation failed at buffer %d (OOM)\n", mem_type, i);
+			else
+				igt_assert_f(false, "%s allocation failed at buffer %d: %s",
+					     mem_type, i, strerror(saved_errno));
+			break;
+		}
+		bo->ptr = NULL;
+		bo->addr = *addr;
+		*addr += bo->size;
+		igt_debug("%s buffer %d created at 0x%016lx\n", mem_type, i, bo->addr);
+	}
+}
+
+static int fill_random_integers(struct gem_bo *int_bo, int ints_to_add)
+{
+	uint32_t expected_result = 0;
+
+	for (int i = 0; i < ints_to_add; i++) {
+		int random_int = rand() % 8;
+
+		int_bo->ptr[i] = random_int;
+		expected_result += random_int;
+
+		igt_debug("%d", random_int);
+		if (i + 1 != ints_to_add)
+			igt_debug(" + ");
+		else
+			igt_debug(" = ");
+	}
+	igt_debug("%d\n", expected_result);
+	return expected_result;
+}
+
+/*
+ * In concurrent VM bind stress tests, multiple threads simultaneously bind
+ * buffers to GPU virtual address space and submit batch operations. This
+ * creates significant GPU memory pressure where the kernel may transiently
+ * fail batch submission when:
+ *   - GPU page tables are being updated across multiple bindings
+ *   - GPU memory is fragmented across many concurrent buffer mappings
+ *   - Multiple processes compete for finite GPU resources
+ *
+ * Without retries, transient ENOMEM/ENOSPC failures cause false test failures.
+ * Retrying lets us distinguish temporary resource exhaustion from actual
+ * driver bugs. Non ENOMEM/ENOSPC errors still fail immediately and are properly
+ * reported with full errno context for debugging.
+ */
+static int xe_exec_with_retry(int fd, struct drm_xe_exec *exec, int max_retries)
+{
+	int rc = 0, retries;
+
+	for (retries = 1; retries < max_retries; retries++) {
+		rc = igt_ioctl(fd, DRM_IOCTL_XE_EXEC, exec);
+
+		if (!(rc && (errno == ENOMEM || errno == ENOSPC)))

This condition should be in bind arrays as per requirement. For the graceful-failure requirement, expected ENOMEM/ENOSPC


from bind path must be explicitly accepted and handled gracefully, not retried away at exec


+			break;
+
+		igt_warn("got %s, retrying (%d/%d)\n", strerror(errno), retries, max_retries);
+		usleep(100 * retries);
+	}
+
+	if (retries == max_retries)
+		igt_warn("gave up after %d retries\n", retries);
+
+	if (rc)
+		igt_warn("errno: %d (%s)\n", errno, strerror(errno));
+
+	return rc;
+}
+
+static void cleanup_bo_resources(int fd, struct gem_bo *bo)
+{
+	if (bo->ptr) {
+		igt_assert_eq(munmap(bo->ptr, bo->size), 0);
+		bo->ptr = NULL;
+	}
+	if (bo->handle)
+		gem_close(fd, bo->handle);
+}
+
+static void cleanup_sram_vram_objs(int fd, struct mem_bind_sync *vram_bind,
+				   struct mem_bind_sync *sram_bind)
+{
+	for (int i = 0; i < vram_bind->n_bufs; i++)
+		gem_close(fd, vram_bind->bufs[i].handle);
+	for (int i = 0; i < sram_bind->n_bufs; i++)
+		gem_close(fd, sram_bind->bufs[i].handle);
+	free(vram_bind->bufs);
+	free(sram_bind->bufs);
+	if (vram_bind->n_bufs)
+		free(vram_bind->binds_ufence);
+	if (sram_bind->n_bufs)
+		free(sram_bind->binds_ufence);
+}
+
+/**
+ * SUBTEST: oversubscribe-concurrent-bind
+ * Description: Test for oversubscribing the VM with multiple processes
+ * doing binds at the same time, and ensure they all complete successfully.
+ * Functionality: This check is for a specific bug where if multiple processes
+ * oversubscribe the VM, some of the binds may fail with  ENOMEM due to
+ * deadlock in the bind code.
+ * Test category: stress test
+ */
+static void test_vm_oversubscribe_concurrent_bind(int fd)
+{
+	#define MIN_BUFS_PER_PROC 2
+	#define MAX_THREADS 20
+	/*
+	 * Cap SRAM test usage on large-RAM platforms (e.g. PVC). On small-RAM
+	 * platforms (e.g. BMG with ~32 GB RAM) 50% of RAM is ~16 GB which is
+	 * below this cap, so behavior is unchanged. On large-RAM platforms
+	 * 50% can be hundreds of GB; cap it to a bounded value that still
+	 * provides meaningful memory pressure for the concurrent bind test.
+	 */
+	#define MAX_SRAM_TEST_SIZE GB(32)

Make macros as global for better readability.

+	int n_proc = 0, n_vram_bufs = 0, n_sram_bufs = 0;
+	uint32_t max_by_mem;
+	uint64_t total_vram_demand = 0;
+	uint64_t vram_size = xe_visible_available_vram_size(fd, 0);
+	uint64_t sram_avail = (uint64_t)igt_get_avail_ram_mb() << 20;
+	uint64_t target_vram = vram_size * 2;
+	uint64_t target_sram, total_vram_bufs, total_sram_bufs;
+	pthread_barrier_t *barrier;
+	pthread_barrierattr_t attr;
+	/*
+	 * Dynamically cap VRAM oversubscription so the overflow into system
+	 * RAM stays within 25% of available RAM. On small-VRAM platforms
+	 * (e.g. BMG) the 2x target fits within the cap and behavior is
+	 * unchanged; on large-VRAM platforms (e.g. PVC) this prevents OOM.
+	 */
+	target_vram = min(target_vram, vram_size + sram_avail / 4);
+	target_sram = min_t(uint64_t, sram_avail * 50 / 100,
+			    MAX_SRAM_TEST_SIZE);
+
+	total_vram_bufs = target_vram / GB(1);
+	total_sram_bufs = target_sram / GB(1);
+
+	/* determine concurrency from memory pressure */
+
+	max_by_mem = min(total_vram_bufs / MIN_BUFS_PER_PROC,
+			 total_sram_bufs / MIN_BUFS_PER_PROC);
+	n_proc = min_t(uint32_t, max_by_mem, MAX_THREADS);
+	igt_require_f(n_proc > 0, "Not enough VRAM/RAM for oversubscription test\n");
+
+	n_vram_bufs = max_t(int, 2, total_vram_bufs / n_proc);
+	n_sram_bufs = max_t(int, 2, total_sram_bufs / n_proc);
+	total_vram_demand = (uint64_t)n_proc * n_vram_bufs * GB(1);
+
+	igt_debug("VRAM size: %" PRIu64 "MB, System RAM available: %" PRIu64 "MB\n",
+		  vram_size >> 20, sram_avail >> 20);
+
+	igt_debug(" n_proc = %d\n", n_proc);
+	igt_debug("VRAM: %" PRIu64 "GB\n", vram_size >> 30);
+	igt_debug("VRAM demand: %" PRIu64 "MB (%.2fx oversubscription)\n",
+		  total_vram_demand >> 20, (double)total_vram_demand / vram_size);
+	igt_debug("Processes=%d VRAM_bufs=%d SRAM_bufs=%d\n", n_proc,
+		  n_vram_bufs, n_sram_bufs);
+
+	barrier = mmap(NULL, sizeof(pthread_barrier_t),
+		       PROT_READ | PROT_WRITE,
+		       MAP_SHARED | MAP_ANONYMOUS, -1, 0);
No need of mmap here. MMAP required if need to write something from CPU on address
+	igt_assert(barrier != MAP_FAILED);
+	pthread_barrierattr_init(&attr);
+	pthread_barrierattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+	pthread_barrier_init(barrier, &attr, n_proc);
Simple  pthread_barrier_t barrier and pthread_barrier_init(&barrier, Arg2, Arg3); can serve
+
+	igt_fork(child, n_proc) {
+		struct xe_test_ctx ctx = {0};
+		int rc;
+		uint64_t addr = 0x40000000;
+		int expected_result = 0, ints_to_add = 4;
+		int max_retries = 1024;
+		struct gem_bo integers_bo, result_bo, batch_bo, *vram_bufs, *sram_bufs;
+		int pos = 0;
+		struct mem_bind_sync vram_bind = {0};
+		struct mem_bind_sync sram_bind = {0};
+		struct drm_xe_sync batch_syncs[1];
+		struct drm_xe_exec exec;
+		struct gem_bo ufence_bo = {0};
+		int vram_bind_err = 0, sram_bind_err = 0;
+
+		vram_bufs = (struct gem_bo *)calloc(n_vram_bufs, sizeof(struct gem_bo));
+		sram_bufs = (struct gem_bo *)calloc(n_sram_bufs, sizeof(struct gem_bo));
+		srand(child);
+
+		igt_assert(vram_bufs && sram_bufs);
+
+		ctx.vm_id = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE, 0);
+		create_exec_queue(fd, &ctx);
+		vram_bind.bufs = vram_bufs;
+		vram_bind.n_bufs = n_vram_bufs;
+		sram_bind.bufs = sram_bufs;
+		sram_bind.n_bufs = n_sram_bufs;
+
+		create_test_bos(fd, &ctx, &vram_bind, vram_memory(fd, 0), &addr);
+		create_test_bos(fd, &ctx, &sram_bind, system_memory(fd), &addr);
+
+		if (!vram_bind.n_bufs && !sram_bind.n_bufs)
+			igt_skip("No BOs allocated; VRAM/SRAM unavailable, skipping\n");

if vram_bind.n_bufs = 0 and sram_bind.n_bufs = 1 then igt_skip() will not be called which is not expected, right? If either of them is 0

 

then igt_skip() should be called. if (!vram_bind.n_bufs ||

!sram_bind.n_bufs) should be checked, If either is 0 igt_skip() will be called


+
+		pthread_barrier_wait(barrier);
+
+		if (vram_bind.n_bufs) {
+			vram_bind.binds_ufence =
+				vm_bind_bo_batch(fd, &ctx, vram_bufs,
+						 vram_bind.n_bufs, &vram_bind_err);
+			xe_wait_ufence(fd, vram_bind.binds_ufence, 1, 0, TIMEOUT_NS);
+		}
+		if (vram_bind_err)
+			igt_assert_f(0, "Unexpected VRAM bind error: %d", vram_bind_err);
+
+		if (sram_bind.n_bufs) {
+			sram_bind.binds_ufence =
+				vm_bind_bo_batch(fd, &ctx, sram_bufs,
+						 sram_bind.n_bufs, &sram_bind_err);
+			xe_wait_ufence(fd, sram_bind.binds_ufence, 1, 0, TIMEOUT_NS);
+		}
+
+		/* Assert if there is any bind error in SRAM */
+		if (sram_bind_err)
+			igt_assert_f(0, "Unexpected SRAM bind error: %d", sram_bind_err);
+
+		integers_bo.size = ALIGN(sizeof(int) * ints_to_add, 4096);

What's the significance of ints_to_add here? If it's required then it should be in MACRO. Otherwise

 

#define INT_SIZE 16

 

ALIGN(INT_SIZE, 4096) can serve.


+		integers_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, integers_bo.size,
+							  system_memory(fd), 0,
+							  DRM_XE_GEM_CPU_CACHING_WC);
+		integers_bo.ptr = (int *)xe_bo_map(fd, integers_bo.handle, integers_bo.size);
+		integers_bo.addr = 0x100000;
+
+		expected_result = fill_random_integers(&integers_bo, ints_to_add);
+		igt_debug("%d\n", expected_result);
+
+		result_bo.size = ALIGN(sizeof(int), 4096);
+		result_bo.handle  = xe_bo_create_caching(fd, ctx.vm_id, result_bo.size,
+							 system_memory(fd), 0,
+							 DRM_XE_GEM_CPU_CACHING_WC);
+		result_bo.ptr = NULL;
+		result_bo.addr = 0x200000;
+
+		batch_bo.size = 4096;
+		batch_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, batch_bo.size,
+						       system_memory(fd), 0,
+						       DRM_XE_GEM_CPU_CACHING_WC);
+
+		batch_bo.ptr = (int *)xe_bo_map(fd, batch_bo.handle, batch_bo.size);
+		batch_bo.addr = 0x300000;
+
+		pos = build_add_batch(&batch_bo, &integers_bo, &result_bo, ints_to_add);
+
+		igt_assert(pos * sizeof(int) <= batch_bo.size);
+
+
+		xe_vm_bind_lr_sync(fd, ctx.vm_id, integers_bo.handle, 0, integers_bo.addr,
+				   integers_bo.size, 0);
+		xe_vm_bind_lr_sync(fd, ctx.vm_id, result_bo.handle, 0, result_bo.addr,
+				   result_bo.size, 0);
+		xe_vm_bind_lr_sync(fd, ctx.vm_id, batch_bo.handle, 0, batch_bo.addr,
+				   batch_bo.size, 0);
+
+		ufence_bo.size = 4096;
+		ufence_bo.handle = xe_bo_create_caching(fd, ctx.vm_id, ufence_bo.size,
+							system_memory(fd), 0,
+							DRM_XE_GEM_CPU_CACHING_WB);
+		ufence_bo.ptr = (int *)xe_bo_map(fd, ufence_bo.handle, ufence_bo.size);
+		ufence_bo.addr = 0x400000;
+		memset(ufence_bo.ptr, 0, ufence_bo.size);
+		xe_vm_bind_lr_sync(fd, ctx.vm_id, ufence_bo.handle, 0, ufence_bo.addr,
+				   ufence_bo.size, 0);
+
+		batch_syncs[0] = (struct drm_xe_sync){
+			.type = DRM_XE_SYNC_TYPE_USER_FENCE,
+			.flags = DRM_XE_SYNC_FLAG_SIGNAL,
+			.addr = ufence_bo.addr,
+			.timeline_value = 1,
+		};
+
+		exec = (struct drm_xe_exec) {
+			.exec_queue_id = ctx.exec_queue_id,
+			.num_syncs = 1,
+			.syncs = (uintptr_t)batch_syncs,
+			.address = batch_bo.addr,
+			.num_batch_buffer = 1,
+		};
+
+		rc = xe_exec_with_retry(fd, &exec, max_retries);
+		igt_assert_eq(rc, 0);
+		xe_wait_ufence(fd, (uint64_t *)ufence_bo.ptr, 1, ctx.exec_queue_id, TIMEOUT_NS);
+		result_bo.ptr = (int *)xe_bo_map(fd, result_bo.handle, result_bo.size);
+		igt_assert(result_bo.ptr != MAP_FAILED);
+		igt_assert_eq(result_bo.ptr[0], expected_result);
+		cleanup_bo_resources(fd, &ufence_bo);
+		cleanup_bo_resources(fd, &result_bo);
+		cleanup_bo_resources(fd, &batch_bo);
+		cleanup_bo_resources(fd, &integers_bo);
+		cleanup_sram_vram_objs(fd, &vram_bind, &sram_bind);
+		xe_exec_queue_destroy(fd, ctx.exec_queue_id);
+		xe_vm_destroy(fd, ctx.vm_id);
+		close(fd);
+	}
+	igt_waitchildren();
+	pthread_barrier_destroy(barrier);
+	pthread_barrierattr_destroy(&attr);
+	igt_assert_eq(munmap(barrier, sizeof(pthread_barrier_t)), 0);
+}
+
 int igt_main()
 {
 	struct drm_xe_engine_class_instance *hwe, *hwe_non_copy = NULL;
@@ -3486,6 +3937,11 @@ int igt_main()
 		igt_assert(xe_visible_vram_size(fd, 0));
 		test_oom(fd);
 	}
add one space and the call subtest
+	igt_subtest("oversubscribe-concurrent-bind")
+	{
+		igt_require(xe_has_vram(fd));
+		test_vm_oversubscribe_concurrent_bind(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)
--------------xTIwCqSKlKwRIoovdwFAAXGv--