From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D4C9158202; Tue, 9 Jul 2024 11:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720523737; cv=none; b=ok5PxVUoIKhh+fcxoaI0T60D+4AG5VmkyP9C9blyNXolBfZgiDgBrr3exJ+qPyJt/8bjsigmWYzjt4afLUEUmxWTpBS4zHi59OzSXhc13s22zVRT6pKkPzwK6wT4Qy/lglfwdKQ9954L24WUCohXZzKkOf6NEgtUvVpm5OI8U+s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720523737; c=relaxed/simple; bh=/TmOCOhyGVjZLNyz7qFSAZ4+FlSGLoAuSFogXnvENfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oBpLyP6GZuSK7GFTn5u/EqQP8+x6FUPJ0ZePzFkNpddbxi6Q1HM4gihHsA+f4Ij+iAli9yPuKK4tZgQtmYBBUtFG+3bhMvv0cY80qQmQH18UzZE0pdzPdp9/p0AuXIU/FZHqATxdEouElpwxOU7bos08GoFhuC9sW4OGMBLWTeE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=FS38qL9Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="FS38qL9Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 978B7C3277B; Tue, 9 Jul 2024 11:15:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720523737; bh=/TmOCOhyGVjZLNyz7qFSAZ4+FlSGLoAuSFogXnvENfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FS38qL9ZVkAlkY1QVvPGGpi1m2sBU/v+k4LGmcd3sc/ZXiyaFfcOVe1h34l6sh2yT hfcie0aUvakceOIYwGHEacydvHoMVE+NvstmEmSsr+pRTP/jkNOKA8bZwVPPsfO7AM eliGe5c+gjP1c1PYh/ZXoWokpbbuH3atvxln1RPU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jinliang Zheng , Michal Hocko , Christian Brauner , Jens Axboe , Mateusz Guzik , "Matthew Wilcox (Oracle)" , Oleg Nesterov , Tycho Andersen , Andrew Morton Subject: [PATCH 6.6 092/139] mm: optimize the redundant loop of mm_update_owner_next() Date: Tue, 9 Jul 2024 13:09:52 +0200 Message-ID: <20240709110701.737402162@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240709110658.146853929@linuxfoundation.org> References: <20240709110658.146853929@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jinliang Zheng commit cf3f9a593dab87a032d2b6a6fb205e7f3de4f0a1 upstream. When mm_update_owner_next() is racing with swapoff (try_to_unuse()) or /proc or ptrace or page migration (get_task_mm()), it is impossible to find an appropriate task_struct in the loop whose mm_struct is the same as the target mm_struct. If the above race condition is combined with the stress-ng-zombie and stress-ng-dup tests, such a long loop can easily cause a Hard Lockup in write_lock_irq() for tasklist_lock. Recognize this situation in advance and exit early. Link: https://lkml.kernel.org/r/20240620122123.3877432-1-alexjlzheng@tencent.com Signed-off-by: Jinliang Zheng Acked-by: Michal Hocko Cc: Christian Brauner Cc: Jens Axboe Cc: Mateusz Guzik Cc: Matthew Wilcox (Oracle) Cc: Oleg Nesterov Cc: Tycho Andersen Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- kernel/exit.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/exit.c +++ b/kernel/exit.c @@ -485,6 +485,8 @@ retry: * Search through everything else, we should not get here often. */ for_each_process(g) { + if (atomic_read(&mm->mm_users) <= 1) + break; if (g->flags & PF_KTHREAD) continue; for_each_thread(g, c) {