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 CD45027713; Tue, 9 Jul 2024 11:26:31 +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=1720524391; cv=none; b=QvOwJRMMvG0GQF6dZe8QPWkxn3YvpjLvtljZDfafHVYxarDlrW5Y/M/wossLpzgQQ7XZ8WhUSLI9jNzP6vzEL3EkUZJbkp8kLK6YFKlKPr2982/cOYG1fnO2GqKDUWUdXMIljNmBA1evqUg0zolmjzK2o6T1P1j8zSHH3WWojUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720524391; c=relaxed/simple; bh=rVQi0oPcmmBahZgZK8WOjPU0N5EVXDt0lozT3IohROI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ti5UX4f8yZY+htkL2v65X55Lq3XKQ8ZvyIw79jZjBMoqeAXGqnKAnPCpjJmqz5UUFGLkfBlduK2vbPq0iJ2GvSYJzy6ZO2VJ9jO0l/7Vj2aRV6JKvz0ptuoWuIeyvwSl/BYdO0LwwnX+G8PuKPmiRL95zN0bI3UdZBM9G4MX/hU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=g00PHKSL; 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="g00PHKSL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55FCDC3277B; Tue, 9 Jul 2024 11:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720524391; bh=rVQi0oPcmmBahZgZK8WOjPU0N5EVXDt0lozT3IohROI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g00PHKSLHOn88D/ex8CITAi02Sq6+P9m/mH61e3sMn5paA1WStq6axHZkD0ZTwc6T L5GmSlOSy/SbiwB7VwB0p0vc9QszkVGqtAiOt781+QvCI+edEwMOiCkZxQ9IQYRr2q 8kv0lRP+JXeOggp51ZWznmBnFGFqApLmRmSDnrqY= 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.9 136/197] mm: optimize the redundant loop of mm_update_owner_next() Date: Tue, 9 Jul 2024 13:09:50 +0200 Message-ID: <20240709110714.212618047@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240709110708.903245467@linuxfoundation.org> References: <20240709110708.903245467@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.9-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 @@ -488,6 +488,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) {