From mboxrd@z Thu Jan 1 00:00:00 1970 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 7813B606A31A for ; Tue, 1 Dec 2026 14:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.a=rsa-sha256 header.s=google header.b=am9DtHoV Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D459110E2C9; Tue, 1 Dec 2026 14:07:23 +0000 (UTC) Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB27510F918 for ; Tue, 1 Dec 2026 14:07:17 +0000 (UTC) Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-9213fddb596so88511956d6.2 for ; Tue, 01 Dec 2026 06:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1796134036; x=1796738836; darn=lists.freedesktop.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=cqssT+PhfahDmQpev1XUIcvj7Kqm3190QbXwwR8856o=; b=am9DtHoVTtIcE+mrjDS4uEPAE953NBR+MTf1RLYqhOqnfIBB663oLS44f39S9qKyk/ l2Ljybz0xuWdWZZ6JxDFHQOwJjtv3ITzyyn1pFMn+NkDAXnt8/3wYIe0N3r9h+4+7uBO PYADhUDYP+EfPeR0j3vB6StNKJWKUNhh3uy+cmuFgDnPj1ZAYc/xYUi75YHktflrGOy0 JEVmzgQaEXkmRIQHDZWID+civGGwNzfcZDRijmft8Z4vD8m5juSjVrL0zA6v7fX/5L5F UTgxymxwESsH4RzbSAklZwmYaIQ3ZCEe+xeqsznaMa8k0Y72T1xQQ89dxVW1PuzFp1vd uHmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796134036; x=1796738836; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cqssT+PhfahDmQpev1XUIcvj7Kqm3190QbXwwR8856o=; b=l647+pa5ITHv5be0npGPYn3f8vq9mI8wj6cTzUIJv7r7mHbXfl9LJQAIN584Gj7VAJ ZEexh1xahmC3gSPOn+JiW2Zu+0KFdrxUr0+9MhFfDdKWB03L95QBy+jzz4WHLWO3y8BK KF+q+RIQt7TjCNPHlGNLg+axHXB1xXpzEVq+x6IBOs13jkqir3y1ULfMhiqZqtqigrD8 p3dUfkPa2dfZZ7KUDeP0NIwSyAojyiihjb3CB2mRpsZfg7Pziz7arx1dHD88Y32BrxVO 7SuuR9hMmsyRFyMBH0eQm8Ernq/djX6QnVRV6GSWEGiXY4qrZUxxy+qWPPrGKL9sLZTn yrHw== X-Forwarded-Encrypted: i=1; AL+hErFJ/ZjFQ87Ks3AKSPSWA8pkiaHcPdm6TpzK2evzDay4/ZSYAxFffjxQYANPyx88vjsUnpB7zjSqgo0=@lists.freedesktop.org X-Gm-Message-State: APuU4Z+vFLZRf5Jv9h1CJOnUVSzUGRHOq4SkJn/fIs7CHMhNZV0GWjuQ gtoCmJfm46ZQoqQ1iFN8fAvWtyKxp8YQK3J2VvbxrcvkddG0xRhZ7TRSa2k0Q49O0iA= X-Gm-Gg: AZFdTZeZAV5LlZpGNb5V7MGH8N53j3NV+NH/TDL0b/4b0Wo43PZBAp9MhKZ5z0m9/Ky 0NglBfOTcQ/jvK/K7ASCWLgQJYI9Wtm4UpkOCFOUJilrGfsn1dtz/13QWifIICQYmrCa0IpVe0k baTUhOGVCn9ghybu28RQr/jNsNUpp19suRGqN16WW2Ju6t3GGmlycg2EOTQaQ/jXA03GEOK2aF5 SGO3wC4GLcgx6kPFnJ+ZyYxILV9ewsFOMXaCndV4Qjcwg8iRc5CBVNARq/L2geCoZCauN5Lnx73 7I2d+hQTfcDlxDia/9b91rnc5cEOGMr5LOoDOjbZ2CeMfnWFONOl4FWk3m1yMDtYOMY0zE6m4h0 bZoppx9ntAZ8oZNPMAdoowzHxwE2Swy9cJALobjTUCdUdc5ak8EvuPoo2wkl98lX96CF6EX5i+a VEoPuvR4V8XrOOebmb+zcRR+QPjwhkQNWlFuxchAtUIaeQYa6uaua5ChcWQ0OI3GyoPVD/OYSpv L/7PXeJdnkHVJzDjc8hvQi3UgZVB+rbcSOBNzMGJYD6gLwzTJ7Y3FgkH6JDhfgn87eQfhz0OkkZ 7kEE X-Received: by 2002:a05:620a:5411:10b0:94a:4246:d608 with SMTP id af79cd13be357-94a4246d62amr955257385a.15.1796134036476; Tue, 01 Dec 2026 06:07:16 -0800 (PST) Received: from ziepe.ca ([142.177.118.84]) by smtp.gmail.com with ESMTPSA id af79cd13be357-94a0c18267esm1587245585a.4.2026.12.01.06.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 06:07:15 -0800 (PST) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1xYOVn-00000000slo-1CdU; Tue, 01 Dec 2026 10:07:15 -0400 Date: Tue, 1 Dec 2026 10:07:15 -0400 From: Jason Gunthorpe To: Nitin Gote Cc: intel-xe@lists.freedesktop.org, Stanislav Kinsburskii , Leon Romanovsky , Andrew Morton , Matthew Brost , Thomas Hellstrom , linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH] mm/hmm: fix premature -EBUSY in hmm_range_fault_unlocked_timeout() Message-ID: <20261201140715.GG1856591@ziepe.ca> References: <20261130143148.2164561-2-nitin.r.gote@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130143148.2164561-2-nitin.r.gote@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 On Mon, Nov 30, 2026 at 08:01:49PM +0530, Nitin Gote wrote: > 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(-) Reviewed-by: Jason Gunthorpe Jason