From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793440052; b=ehsSKD6T2L4OviuCQrWPOxduhj4Bm9Wru7TRkYRetBg1qOnvfPzsSHggQzF4FjLgh8bq 3Sb8HYHTLREt8r5U2SkhFMtR7eKV9zVgG7sDElp7qUbBzdEBzDuo9NgHL9ArHCqo3ywPE a67DKd8kdZKrl6KQMZaW/9FFNOT2Vtcdb1lsgwQBqDsDqn3PEm72HFMWF/3q3+u6kwvLK OUS1Ea8QLKy6AY44Hp5Ym2uQyJKVHPidnK8LFcOF7+nOVxrs0fRTz633mmbgYJaYiZVe5 8OUYIaHbPkQchlYNvFDKK7WvKJ93UR56+RlE3Ge5C6wSiGMHN/uDf/GAKAVk6tejHDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793440052; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=Xc81+pQCpvOEFV1SjV2hvWtNjfruVqO4qaaYMBxu1qU=; b=ndEXBYLihQBEQoODkDFhjqVGPEcgLqiBHLUFVVkaqEXC0qN6Vr9nDRhiKBOqOES2TixN wVlvadZWBr9gsvsZW6ZN1spDp1msZLXFdA1YKsmQK/8R+Vd2YEFq/mDCf9gMMGmaWkeL0 y6e06nzwJC3gnYULlY7exw9eCi/uUFu3DZ8atNecPkDDcY9cL14taGpTvA1DH3L6PzsEh Z0axLdNC3D3ghdhuSUwELPqTx+lqgo/ULU7fPaHvRQm+8DR7ycnzeZTTzyuSz/jw2Coe+ yOPa0zzym1G23MXj2NpJsF0pW8P7dvfKejpwgDIQVzsSZMdcaymEqi7Fn7AmWRgeEIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=H+Zu2OmD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0569606A327; Sat, 31 Oct 2026 09:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=H+Zu2OmD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B3531F00919; Sat, 31 Oct 2026 09:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793440052; bh=Xc81+pQCpvOEFV1SjV2hvWtNjfruVqO4qaaYMBxu1qU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=H+Zu2OmDANIogo0KydYV684DDgB6E/JPWdC8WKGejHwloLgYyBl4uyENmjkOgd+6z OpHcmg49k4+J99+rvf3R9wI6eHcjtYL+GrE5zpm+mr76ayPfV9ZLRnX3oK2Y37qgQ2 1aYeP4op/vYaWDQOw+1+5AqmWmgTC3hF095aAs2CFn2+kGIewLHko2nddZ74GOdzqr e5nZGqckvv1VpUgOe0qZ+KqE9Ew47LvziANO06udnWQOvHD49NDmNyJBy3EBFe25ax CzMxvJ8U3MUD3xbw/ySjXDB5JQeks8KgBBk5OPWhDWliDuB9GvinW+iv1tqP5vDc5P CGgb4Dm/lalVg== From: "David Hildenbrand (Arm)" Date: Sat, 31 Oct 2026 10:39:57 +0100 Subject: [PATCH v3 28/47] mm/mmu_notifier: finish non-blocking interval invalidation on error X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261031-fixes_core-v3-28-d6437171ecc3@kernel.org> References: <20261031-fixes_core-v3-0-d6437171ecc3@kernel.org> In-Reply-To: <20261031-fixes_core-v3-0-d6437171ecc3@kernel.org> To: Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Dev Jain , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, Josef Bacik , stable@vger.kernel.org, Muhammad Usama Anjum , "David Hildenbrand (Arm)" X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3161; i=david@kernel.org; h=from:subject:message-id; bh=zlFjez9kL2dtssRVxiCEM6wJKA5W9Xa0kYQZPudLU3A=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLKebs+wdVs899LDdv233UvDPnaf8rB/f2qO2Bvdcx/W+ xUeu+T4oaOUhUGMg0FWTJElKPi+wcuX62qr3fiYYeawMoEMYeDiFICJCHcxMtyOuKqxIr/t32zJ XNNZu1k4Pxj8v/h3rZRusULpUtbDVfKMDLsOv2T88yi9dnvL5JBVGziT32oftbzySfi4epSisuW pQF4A X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Josef Bacik When an ordinary MMU notifier rejects a non-blocking invalidation, the interval invalidation started beforehand is left unfinished: the caller skips mmu_notifier_invalidate_range_end(). Subsequent interval notifier operations can then wait forever. The only in-tree trigger is nouveau SVM, which uses both notifier types and rejects non-blocking invalidations. Reaping via the OOM reaper or process_mrelease() can therefore leave the GPU fault worker stuck, holding a reference that prevents the dying process's address space and memory from being freed. End the interval invalidation when an ordinary notifier fails a non-blocking invalidation, like mn_itree_invalidate() already does when an interval notifier fails. Make that handling clearer in the documentation of mmu_notifier_invalidate_range_start_nonblock(). Fix generated by an LLM and sent by Josef Bacik in private. Fixes: 99cb252f5e68 ("mm/mmu_notifier: add an interval tree notifier") Cc: stable@vger.kernel.org Signed-off-by: Josef Bacik [ david: simplify description, update function doc ] Acked-by: Lorenzo Stoakes (ARM) Tested-by: Muhammad Usama Anjum Signed-off-by: David Hildenbrand (Arm) --- include/linux/mmu_notifier.h | 3 ++- mm/mmu_notifier.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index a11a44eef521e..5db78e5761c5c 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -483,7 +483,8 @@ mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) /* * This version of mmu_notifier_invalidate_range_start() avoids blocking, but it * can return an error if a notifier can't proceed without blocking, in which - * case you're not allowed to modify PTEs in the specified range. + * case you're not allowed to modify PTEs in the specified range or call + * mmu_notifier_invalidate_range_end(). * * This is mainly intended for OOM handling. */ diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index df69ba6e797f7..2e20f88e162d7 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -569,16 +569,25 @@ int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { struct mmu_notifier_subscriptions *subscriptions = range->mm->notifier_subscriptions; - int ret; + const bool has_itree = subscriptions->has_itree; + int ret = 0; - if (subscriptions->has_itree) { + if (has_itree) { ret = mn_itree_invalidate(subscriptions, range); if (ret) return ret; } if (!hlist_empty(&subscriptions->list)) - return mn_hlist_invalidate_range_start(subscriptions, range); - return 0; + ret = mn_hlist_invalidate_range_start(subscriptions, range); + + /* + * On error, the non-blocking caller is not allowed to call + * invalidate_range_end(), as in mn_itree_invalidate(). + */ + if (ret && has_itree && !mmu_notifier_range_blockable(range)) + mn_itree_inv_end(subscriptions); + + return ret; } static void -- 2.43.0