Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB1DE606A320 for ; Mon, 30 Nov 2026 13:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=bSrH/HPW Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9C87510E8D1; Mon, 30 Nov 2026 13:52:25 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFE8D10E8D1; Mon, 30 Nov 2026 13:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796046740; x=1827582740; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MjxkRDYPO9XtAVAPTG/WXZjK19sHR5ZoEfnlxS8JxJQ=; b=bSrH/HPWdSoFcyNgQMrVDC4vlCu5IOcqO/+49TQWQVaJemRFuCz36mKg FYV649PY/5bGyD8mrpa5mUT3jKkq2yGFTuuzb3NSFbzohOmf51J7Fzf3x erD5s5QI/ahHUq13NQva6rikEPJ87akdqo98IcyBqtpBnNB524Dyxy8gv FcrKmHQGO5B/jvX8Yar4r5CI1JsfQP+uJaO68rgoCmnO43Id8wSMXDtLq ARX2OD+iIuIHjRnJD4AKUeOC//Qox3yu090e+/djhOLXSMNqIjU/r3wsb XyVzK20r2j8KIM1FsLKlxh3EHCvemFqVZgh+3Mpi/UXPCcnbSP1g3+JV6 w==; X-CSE-ConnectionGUID: 05yLgm9tQdq/1KBkYWr8Yw== X-CSE-MsgGUID: FrstTbbEQwap8mKzDsczzg== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4768714" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4768714" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 05:52:19 -0800 X-CSE-ConnectionGUID: FSO5HuZUS8KwuqwTJ6UDjw== X-CSE-MsgGUID: KKW1qbLhSmmTps0G+Yl2ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="14943652" Received: from nitin-super-server.iind.intel.com ([10.190.238.72]) by fmviesa013.fm.intel.com with ESMTP; 30 Nov 2026 05:52:16 -0800 From: Nitin Gote To: intel-xe@lists.freedesktop.org Cc: Nitin Gote , Stanislav Kinsburskii , Jason Gunthorpe , Leon Romanovsky , Andrew Morton , Matthew Brost , Thomas Hellstrom , linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH] mm/hmm: fix premature -EBUSY in hmm_range_fault_unlocked_timeout() Date: Mon, 30 Nov 2026 20:01:49 +0530 Message-ID: <20261130143148.2164561-2-nitin.r.gote@intel.com> X-Mailer: git-send-email 2.50.1 X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 hmm_range_fault_unlocked_timeout() starts its retry deadline before mmu_interval_read_begin() and mmap_read_lock_killable(), and checks it before calling hmm_range_fault_locked(). Both calls can sleep for a long time if another thread is invalidating or holds mmap_lock for write. Today, if that sleep is longer than the timeout, we return -EBUSY without even trying the fault, although nothing invalidated our range. The open-coded loops that the helper replaced only checked the deadline after hmm_range_fault() had actually returned -EBUSY, so lock waits never consumed the retry budget. This is seen with igt@xe_exec_threads@threads-hang-*userptr-invalidate*: one thread's mmap(MAP_FIXED) holds mmap_lock for write while the xe notifier waits for a hung job to time out. Another thread repinning its own userptr waits behind it for more than HMM_RANGE_DEFAULT_TIMEOUT, and DRM_IOCTL_XE_EXEC fails with -EBUSY: xe/xe_ioctl-CRITICAL: Failed assertion: __xe_exec(fd, exec) == 0 xe/xe_ioctl-CRITICAL: error: -16 != 0 Keep the retry timeout, but check it only when hmm_range_fault_locked() returns -EBUSY with mmap_lock still held, i.e. on a real invalidation collision. This restores the behaviour callers had before the conversion, and keeps the deadline reset when a fault drops mmap_lock. Assisted-by: LLM Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/work_items/9096 Fixes: 121170831228 ("mm/hmm: add hmm_range_fault_unlocked_timeout() for mmap lock-drop support") Cc: Stanislav Kinsburskii Cc: Jason Gunthorpe Cc: Leon Romanovsky Cc: Andrew Morton Cc: Matthew Brost Cc: Thomas Hellstrom Cc: linux-mm@kvack.org Cc: dri-devel@lists.freedesktop.org Signed-off-by: Nitin Gote --- mm/hmm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 9871d3c3cd07..e520424394af 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -815,15 +815,15 @@ int hmm_range_fault_unlocked_timeout(struct hmm_range *range, return -EFAULT; } - if (timeout && time_after(jiffies, deadline)) { - mmap_read_unlock(mm); - return -EBUSY; - } - locked = true; ret = hmm_range_fault_locked(range, &locked); - if (locked) + if (locked) { mmap_read_unlock(mm); + /* Only invalidation collisions count against the timeout */ + if (ret == -EBUSY && timeout && + time_after(jiffies, deadline)) + return -EBUSY; + } } while (ret == -EBUSY); return ret; -- 2.50.1