Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp74626iof; Sun, 5 Jun 2022 21:34:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEQ2+MvIw318X2uA4pr6irCWAH8P0cEvbXa1qimU0qOMymrifG6GRcD4S5l6Or//N/72s9 X-Received: by 2002:a17:90b:4f8d:b0:1e8:38f5:e199 with SMTP id qe13-20020a17090b4f8d00b001e838f5e199mr15602271pjb.64.1654490043958; Sun, 05 Jun 2022 21:34:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654490043; cv=none; d=google.com; s=arc-20160816; b=N8DWNm7i+GQQH9EPdkv3yua1uydtqFWVj/5oZers5sBdyPfo6V6048jGvKSeFzvJQX os0BEUQyvoEImdPqG3s1s8WMr+PaQwN1ugwMaG9qmE9nePu3xiXO5uNYOfHR0LEfACpF KKGIqjA9odRFVPHmy21O1nQbwHbhHI2KMrolCiBzZx82/OwKRLuGKtFzWRK2wysTM4iI BNIdgD95CIj7Fg3KOy/HsnkFHVb5Xpb46CbHM1leD/m7i1wXc790tvAumEZXVM0FASnx ngAdyeiLNXTrN5Ebrgz/gKtjwSskfq+d+VTguTaSCkwb2AYs8LsI6sxLbJJHlCe/ne1J XoJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mMonbLu/XM6YgtQcBraljrxJ/IE0ZiXZb72pvU5nVI0=; b=y+RE/5ttbGJBpZ1j5dgfJTVjHEnD+CjNfbYuQb8cRbwPelVe57IMMx8+DmpBHbGP+B fv63HpAVbDn9zjJWie4jZyNltU/R2Z8544zRziLtii1e3iP6k68AJecBy4t6qNmDjdZf acDjFPnajL3bBauRUVs6hVXVz5PpHiEVUmuqvd/m07OFTbwetCiQQKdA1pC/w+JGz96M KYL7NFf61oYzrSq6xyQTlhw7fxxQfJsQ3uhzwlquC28ZdUth7ybeO8bOL8BxgAJ72Kro KWST3R9jWu1b7vr75LuNBLkVTLpt6SaS9ZP/wyZmVO55VbNuiigLrXclSwe4WEa+6EAx lAog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rGZUpulp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e193-20020a6369ca000000b003fd4f39aad6si8933800pgc.427.2022.06.05.21.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:34:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rGZUpulp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E8F45A09A; Sun, 5 Jun 2022 20:59:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240123AbiFDTvJ (ORCPT + 99 others); Sat, 4 Jun 2022 15:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236272AbiFDTvH (ORCPT ); Sat, 4 Jun 2022 15:51:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F1DD30565 for ; Sat, 4 Jun 2022 12:51:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D8C961016 for ; Sat, 4 Jun 2022 19:51:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C59A6C385B8; Sat, 4 Jun 2022 19:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654372264; bh=iQ//p9c/Jarv4oc2irqnX8yb/qL+olIDk7ZmaJFDVzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rGZUpulpWojW0NV2I0rfR8FwABz0mwJuzwrvy3E9SYeiLV8GxE3vMsOBxOF7lJVS8 /lYgQGuHFKZMBzzXoPG2IMa07+3V12DeV6Uf/xG4ojlV6fxpQ9QoBz1VBrhAsksxK/ MV8uDYBATHl0BN3YQ1V6SUokrTJEfkmzG3RcGUEb9Y0o1D7EKk5zDIhQJgDiaLsWfD 7QsW+YOEXidk0EsDjgFJe7D5viaV/SCl+1PTfrbS4P/K8qhGxzgFg1aqQhS+p1YUdj 25cwL9kA0McJgHRz7lGGdqdOXK6Mp76gQ1gGxiBHTyq612go2i+4rAcnMuTqxAyfOk kO0zUJlbgBVeQ== From: SeongJae Park To: akpm@linux-foundation.org Cc: tuhailong@gmail.com, gwhite@kupulau.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bugzilla-daemon@kernel.org, SeongJae Park Subject: [PATCH] mm/damon/reclaim: schedule 'damon_reclaim_timer' only after 'system_wq' is initialized Date: Sat, 4 Jun 2022 19:50:51 +0000 Message-Id: <20220604195051.1589-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220604192222.1488-1-sj@kernel.org> References: <20220604192222.1488-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 059342d1dd4e ("mm/damon/reclaim: fix the timer always stays active") made DAMON_RECLAIM's 'enabled' parameter store callback, 'enabled_store()', to schedule 'damon_reclaim_timer'. The scheduling uses 'system_wq', which is initialized in 'workqueue_init_early()'. As kernel parameters parsing function ('parse_args()') is called before 'workqueue_init_early()', 'enabled_store()' can be executed before 'workqueue_init_early()' and end up accessing the uninitialized 'system_wq'. As a result, the booting hang[1]. This commit fixes the issue by checking if the initialization is done before scheduling the timer. [1] https://lkml.kernel.org/20220604192222.1488-1-sj@kernel.org/ Fixes: 059342d1dd4e ("mm/damon/reclaim: fix the timer always stays active") Reported-by: Greg White Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 8efbfb24f3a1..4b07c29effe9 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -374,6 +374,8 @@ static void damon_reclaim_timer_fn(struct work_struct *work) } static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn); +static bool damon_reclaim_initialized; + static int enabled_store(const char *val, const struct kernel_param *kp) { @@ -382,6 +384,10 @@ static int enabled_store(const char *val, if (rc < 0) return rc; + /* system_wq might not initialized yet */ + if (!damon_reclaim_initialized) + return rc; + if (enabled) schedule_delayed_work(&damon_reclaim_timer, 0); @@ -449,6 +455,8 @@ static int __init damon_reclaim_init(void) damon_add_target(ctx, target); schedule_delayed_work(&damon_reclaim_timer, 0); + + damon_reclaim_initialized = true; return 0; } -- 2.25.1