From patchwork Wed Nov 6 13:47:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 2007566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Wn3UOhjc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=ax0a=sb=vger.kernel.org=linux-ext4+bounces-4977-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xk69C5l1Gz1xyX for ; Thu, 7 Nov 2024 00:53:03 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Xk6943KW3z4wc4 for ; Thu, 7 Nov 2024 00:52:56 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Xk6943HM2z4wxx; Thu, 7 Nov 2024 00:52:56 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:40f1:3f00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1730901172; cv=pass; b=QrWggRQYO9YBjbCYzXKtJuPNmatLWN44vrzj803YpWiAWLElAJTkQwJtRuVooT8EHIUU2DAuax14f05zhW0CHAC8PuQGQXbYIqiGVeQ5tQ/FhojI6EfPLzpjDY8LpvbYszfytv5chx7t8riPUCblebDX9L4/jat9vccY0FtmwIngj/oNp0UJ24OYEYCyA4f6PPceS2vdbDnLde36W1aIxv9pFzZ5vRwuI97sBItR0q7h/dhHxIv5jyW0IOgSRmY47B07+FJesv7R5/2CicNIFUtC7PvFYVtb3WSa0ncy/JnV57Xavm9H7d5ZSrcB9hVajHKhA0f4Gl8V3hb3Wain1Q== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1730901172; c=relaxed/relaxed; bh=dqWk5AJnz/jo2LVdopcpW+APPxryZDyUyYYPqJnsvak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ir08AYrnMYAXUdMnDvPoD3Vc8OKJIFZPBwtK2PTYQ/olPSdDm3V2GKiPHGflm1dhJP2xcDXinGOA95l39FY3+Nzvi3VxmKzA2U22nT7hDoWlcEgRGxEoZQuasExIA3xqMG/L5v6h/SgA7ZTfE93Xo98iwvvuaocG5g44c5WwDWpbYHeOuXlJ+cPAkl60fpsNKdI/T6QojkZsJk2Au+1bZecoHnCqhDDJCj7twMIk8b+PHliHrdiyAutojJHzhF0bs3LLewxw9Nc3kfWt7ybjQtzcKx/o0vO2f2exYlaOhlPoxwk+IxVUrG92RYEhJihQyfSHEoPCeoZLSi7nzuuR8Q== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gnu.org; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Wn3UOhjc; dkim-atps=neutral; spf=pass (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4977-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Wn3UOhjc; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4977-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Xk6901MWmz4wc4 for ; Thu, 7 Nov 2024 00:52:52 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8E88EB21CFE for ; Wed, 6 Nov 2024 13:52:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20F4B201018; Wed, 6 Nov 2024 13:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnu.org header.i=@gnu.org header.b="Wn3UOhjc" X-Original-To: linux-ext4@vger.kernel.org Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) (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 4A2801DEFD7; Wed, 6 Nov 2024 13:52:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.51.188.92 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730901161; cv=none; b=NxlpWnVEoudr5p41xSx+oUgplxyK69Ne7RnQ5Sh7WYn2a6CcrWjy9AI/WHzqbod7F58QlS2T241muDjF4SKa2o/e2r4Z+ImY5sH4uNPnh5zpmhix16zXEljHwW1I5l5J2TupnN6G5xbReVcbZZNrS/pyTovTed7l0B4aN50vP/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730901161; c=relaxed/simple; bh=hsDm8riYcjMPE60i/Lbnnj638ErPNKlm74Hu/6HiOzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CdniPRnNNoTaHUhVYR123eCVSaKK2RPfTkDdF0SDr+7dG2IUCfKQe2qte8QOeoCjJHZya1UZPK/RiC7mF4mdYdfZmX8sisE1Tc4iCKArHBmsLMtwUq1PbnfcWqDklLQiUhq5chsABGEDnd81yH7I28u1ad+dr1S7Ow4lgHKWmvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gnu.org; spf=pass smtp.mailfrom=gnu.org; dkim=pass (2048-bit key) header.d=gnu.org header.i=@gnu.org header.b=Wn3UOhjc; arc=none smtp.client-ip=209.51.188.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8gSd-00085t-3a; Wed, 06 Nov 2024 08:52:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=dqWk5AJnz/jo2LVdopcpW+APPxryZDyUyYYPqJnsvak=; b=Wn3UOhjcEtqc8xPOrQNL WRJmkQRPABAVJo1smeE6jLie6Utn+UGteNKoGFYMv/bwpXJqcWWcDvdnsTqgAr/fIwKyiVNP0Ptk+ IaanfYQDDsVGMRQgsRVCZE+WryRfY53qwbzeg6GiaIS69fDYOgvxp95vDdTawhLTygWwei+I/feiU qsmq9MGlad0VeVRPtu4B+S8CtGD5mfwaMVA9UPjdn6hXlOOl1OlkVby6cVzWRNe51uyOTzn4QJ79L UvQk82NZw3PlKn0PDenq4In3nwKEFNOou5kz1POAoAw7Okbq6dmpYM5Z3wnvIn7NCXaKFg52leuio xa3Mqxt+eNWPXQ==; From: Mathieu Othacehe To: Theodore Ts'o , Andreas Dilger Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, lukas.skupinski@landisgyr.com, anton.reding@landisgyr.com, Mathieu Othacehe Subject: [PATCH 1/1] ext4: Prevent an infinite loop in the lazyinit thread. Date: Wed, 6 Nov 2024 14:47:41 +0100 Message-ID: <20241106134741.26948-2-othacehe@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241106134741.26948-1-othacehe@gnu.org> References: <20241106134741.26948-1-othacehe@gnu.org> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-3.7 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on gandalf.ozlabs.org Use ktime_get_ns instead of ktime_get_real_ns when computing the lr_timeout not to be affected by system time jumps. Use a boolean instead of the MAX_JIFFY_OFFSET value to determine whether the next_wakeup value has been set. Comparing elr->lr_next_sched to MAX_JIFFY_OFFSET can cause the lazyinit thread to loop indefinitely. Co-developed-by: Lukas Skupinski Signed-off-by: Lukas Skupinski Signed-off-by: Mathieu Othacehe Reviewed-by: Jan Kara --- fs/ext4/super.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9fcf44064c6a6..b4839ccd83ad5 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3712,12 +3712,12 @@ static int ext4_run_li_request(struct ext4_li_request *elr) ret = 1; if (!ret) { - start_time = ktime_get_real_ns(); + start_time = ktime_get_ns(); ret = ext4_init_inode_table(sb, group, elr->lr_timeout ? 0 : 1); trace_ext4_lazy_itable_init(sb, group); if (elr->lr_timeout == 0) { - elr->lr_timeout = nsecs_to_jiffies((ktime_get_real_ns() - start_time) * + elr->lr_timeout = nsecs_to_jiffies((ktime_get_ns() - start_time) * EXT4_SB(elr->lr_super)->s_li_wait_mult); } elr->lr_next_sched = jiffies + elr->lr_timeout; @@ -3777,8 +3777,9 @@ static int ext4_lazyinit_thread(void *arg) cont_thread: while (true) { - next_wakeup = MAX_JIFFY_OFFSET; + bool next_wakeup_initialized = false; + next_wakeup = 0; mutex_lock(&eli->li_list_mtx); if (list_empty(&eli->li_request_list)) { mutex_unlock(&eli->li_list_mtx); @@ -3791,8 +3792,11 @@ static int ext4_lazyinit_thread(void *arg) lr_request); if (time_before(jiffies, elr->lr_next_sched)) { - if (time_before(elr->lr_next_sched, next_wakeup)) + if (!next_wakeup_initialized || + time_before(elr->lr_next_sched, next_wakeup)) { next_wakeup = elr->lr_next_sched; + next_wakeup_initialized = true; + } continue; } if (down_read_trylock(&elr->lr_super->s_umount)) { @@ -3820,16 +3824,18 @@ static int ext4_lazyinit_thread(void *arg) elr->lr_next_sched = jiffies + get_random_u32_below(EXT4_DEF_LI_MAX_START_DELAY * HZ); } - if (time_before(elr->lr_next_sched, next_wakeup)) + if (!next_wakeup_initialized || + time_before(elr->lr_next_sched, next_wakeup)) { next_wakeup = elr->lr_next_sched; + next_wakeup_initialized = true; + } } mutex_unlock(&eli->li_list_mtx); try_to_freeze(); cur = jiffies; - if ((time_after_eq(cur, next_wakeup)) || - (MAX_JIFFY_OFFSET == next_wakeup)) { + if (!next_wakeup_initialized || time_after_eq(cur, next_wakeup)) { cond_resched(); continue; }