From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCD0B485CC2 for ; Thu, 23 Jul 2026 17:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784828229; cv=none; b=DijMS8/SvrI9WiQBU3uReMsHZ+Tl6jwAHpjgjG7FORiDJx3O1F89xXlOl7s18ig6zxXVy5a+XZ1ZxzkQHKiynWXS6CXh9zH1lx5wR1JOOwpH72bkYZhzYA8ibP2dLs/r+CB9hSczyWI5Qlvn4iJsGzHNgqtFV7mhzSv0VC5/LP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784828229; c=relaxed/simple; bh=Js9Z5fScNTLs9yZDEPq5MMQDWBFdccrrYdkvKMfBR0c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AkwG5dk7RzgfujN/g//kq0l9L2bBe2X/FAU6o7CJfodXLj+glpmCCr9+hF5Lv4MB96DJLN5FepE/5j98iGZuU7se5A05glt+cXue+LVpMKeEYcFhsUk7hbNZ6rPa3XZ1JUmPRl90jWAyYTuUxnKEClfkdFSKevTV7o/tCBL2wPk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BKL6hJTS; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BKL6hJTS" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-84a4d8fd6ecso981446b3a.1 for ; Thu, 23 Jul 2026 10:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784828216; x=1785433016; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/3EHZQlaXq9sLmhVgtuP5ODA2wxc36yvs54yemcncOc=; b=BKL6hJTSZk19OoDFcA63/ZRoV0prsj8yCa4ogkU90ZAlAakTfXuIGGS/iowNK20Shm 48LLdV1VLcRWB+urPSsdyN0SvDg3d5TRjBBZ91VHO9dGcLM7NP5U5NMulOAal5hJ07Q4 J1ds7S3tCtGMQ0nJS4JKg2CXAmTMXTAXD90ceLfgLW81TiwyrV1T0V6qmP7F3+23sGKK ystiPsEBmqOhU53eERSPQWhWZYpis1kHPTqaTAM2/8tKMKtDgkNi4GGJGu6EhArOMTt9 X2otbFigngyTor75rMG2t8eHnCm9TQHuyZEGyW2NqF+eQpSl9GlrB927etwZYxmjpij1 XyUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784828216; x=1785433016; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/3EHZQlaXq9sLmhVgtuP5ODA2wxc36yvs54yemcncOc=; b=EEaXyHENyZLUCLzhQVc/tyTXe+v4S+iKiCGAKscTCApolvifwB5RK7kzChBhoirfEa IqPvjwQwIklDjYIIAGiMlXlBriwDbd2eEN+ShztXMxb84Xx+vem50XmP9Rrz8SnZkIBD 61mXjqC/Sszgg1mvxQYk7h/CXanQprlKgM3MhbINkScB/zZuysFnSKd/wghDyTKXNbgT ls4QsBfbC6T7FxEI+/t/OtTCsyZ5eAdYBCgw2ikcB8DXobnMI/or4jexquA74+ZAalYW NM19ZBusUrBQeWf5i7RReMXHnqE9GbmeKty1OiGRuMzMDzYNuqCPXPhNIjI79VvbhzIo wWoA== X-Forwarded-Encrypted: i=1; AHgh+RqSGW8v6Og6spf5LYfr1jVCRAK9YrMWGhzsVu3xg2LxZXy4drSxtb2F7CwCdqoFsxxcYu7zK+lu/de5whQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywb7mwMwcevwZZvAuIXjyXWfA5AbJxIOTugnh+3BnodLXmLlYhA R8EUdzKrvxnWNLsrY4xfF6C7Fr29Mk/564QX46N2HvmQNvjS1UicgoEt X-Gm-Gg: AR+sD13kMr7dwxFiSdbupxilfJbtckljbKldlcKodbyEqo8StAJiJgAct2GYvbCdCJl 8CVt7vbZLS7qld6Igt1D0GEmkYz10XrOUa5Rwx7wxYrC9axXEk5PW006HO5SqFZ6goYJrBemwf4 dKXRRmEbuDRGL9WWmhmBOhTdBzuG3R68W+zcJLLphn0ZJKUs5U35q71wAFeshmG1ip2QE4luXpw R0ffmRfp3/UMomeEihg//lsH4DUWzbLZSHjF89GLYjumSWA9YMZmoriL1kIvQCPDddcHkwhspfs yWZ/S83AW87hCIMO7EjsOwWerp1azR9W1T8IYKRGGEgAF2/tCWMVR6OFwP6XRoXta7MQneAznX3 +3eR8V8DDFV1uH7otHTuBYdZ9BdbHa20J9AYch4d6wzbo6cC5Bjd/QykSfh80wXEc6BUOSw9uZC PUSxCFr+qPL7Az/3q+zVSBLbK2R+0c+u9Zy4+bxuLJ3t6zaN98 X-Received: by 2002:a05:6a00:4482:b0:848:47d3:47ec with SMTP id d2e1a72fcca58-84e2b8ab6d2mr4797080b3a.31.1784828216068; Thu, 23 Jul 2026 10:36:56 -0700 (PDT) Received: from [192.168.0.160] (c-98-225-44-182.hsd1.wa.comcast.net. [98.225.44.182]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84e20622dedsm2691612b3a.11.2026.07.23.10.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 10:36:55 -0700 (PDT) From: Stanislav Kinsburskii Date: Thu, 23 Jul 2026 10:36:39 -0700 Subject: [PATCH v11 7/8] accel/amdxdna: Use hmm_range_fault_unlocked_timeout() for range population Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260723-hmm-v10-v11-7-c55b003a4b61@gmail.com> References: <20260723-hmm-v10-v11-0-c55b003a4b61@gmail.com> In-Reply-To: <20260723-hmm-v10-v11-0-c55b003a4b61@gmail.com> To: Jason Gunthorpe , Leon Romanovsky , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonathan Corbet , Shuah Khan , Shuah Khan , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Lyude Paul , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Min Ma , Lizhi Hou , Oded Gabbay , skinsburskii@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-rdma@vger.kernel.org, Jason Gunthorpe X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784828202; l=2650; i=skinsburskii@gmail.com; s=20260722; h=from:subject:message-id; bh=Js9Z5fScNTLs9yZDEPq5MMQDWBFdccrrYdkvKMfBR0c=; b=UoKX2QEi16TQG/XSPiXepu/KONklG+8l1kn86LgWhqxQQe32BnNrpIu04JJYOeap8yhmhRNnI Xgchah8NIfnDwgLdxf/plAUECr/N2GDtTgg00z0Czhp7vw9hyXoBoqQ X-Developer-Key: i=skinsburskii@gmail.com; a=ed25519; pk=bDpriHBYgeTdkIDweZDCemxsU93neJBOCn3YLIuJpnE= aie2_populate_range() takes mmap_read_lock() only around hmm_range_fault(). It also open-codes the mmu interval sequence setup before each HMM walk and retries -EBUSY until HMM_RANGE_DEFAULT_TIMEOUT expires. Use hmm_range_fault_unlocked_timeout() instead. The HMM helper now owns the mmap lock and refreshes mapp->range.notifier_seq for its internal retries, so the driver only needs to call the helper and then validate the sequence before marking the mapping populated. Pass HMM_RANGE_DEFAULT_TIMEOUT as the helper retry budget for each HMM population attempt. This scopes the timeout to repeated HMM notifier retries while preserving the existing outer loop that moves between invalid mappings and restarts when the interval is invalidated before the driver updates its mapping state. Keep returning -ETIME when the HMM retry budget expires, matching the driver's existing timeout error convention. Reviewed-by: Jason Gunthorpe Signed-off-by: Stanislav Kinsburskii --- drivers/accel/amdxdna/aie2_ctx.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c index 54486960cbf5..b5b4ca263002 100644 --- a/drivers/accel/amdxdna/aie2_ctx.c +++ b/drivers/accel/amdxdna/aie2_ctx.c @@ -1034,7 +1034,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo) bool found; int ret; - timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT); + timeout = msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT); again: found = false; down_write(&xdna->notifier_lock); @@ -1061,24 +1061,9 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo) return -EFAULT; } - mapp->range.notifier_seq = mmu_interval_read_begin(&mapp->notifier); - mmap_read_lock(mm); - ret = hmm_range_fault(&mapp->range); - mmap_read_unlock(mm); - if (ret) { - if (time_after(jiffies, timeout)) { - ret = -ETIME; - goto put_mm; - } - - if (ret == -EBUSY) { - amdxdna_umap_put(mapp); - mmput(mm); - goto again; - } - + ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout); + if (ret) goto put_mm; - } down_write(&xdna->notifier_lock); if (mmu_interval_read_retry(&mapp->notifier, mapp->range.notifier_seq)) { @@ -1096,7 +1081,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo) put_mm: amdxdna_umap_put(mapp); mmput(mm); - return ret; + return ret == -EBUSY ? -ETIME : ret; } int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, u64 *seq) -- 2.43.0