From patchwork Sat Oct 28 21:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 159305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1408107vqb; Sat, 28 Oct 2023 14:39:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTsk4fW+DoQ6Lk36JzDsQeCzvowj+hnIzfeomEhk57INNKr49OAcLtTWLRzx/uMCoSRhlv X-Received: by 2002:a05:6a21:9998:b0:17b:8404:96df with SMTP id ve24-20020a056a21999800b0017b840496dfmr7098060pzb.41.1698529189686; Sat, 28 Oct 2023 14:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698529189; cv=none; d=google.com; s=arc-20160816; b=FaCeJYMmqKXjJRRy6Ya9R7VwhjEshLB8JrFdpycAkpF9dQ/muqEITZR3cBCYcFp1Oy ytoLSv9+O2xegGcE+0v7lBcq7HfFJ1bwMcSDoRHbqdiEWltXGN2JQi8k122Qhp+p8vgd ts8TprMZqjAOV+3XNX3k4SnRL6LBy27srMYk7zAHRl+X5LYzbD2O0S54a63t7vOphK3H 0yacCcutPXKcHPA6lJw28lNT/mdGZuq70GrBsNDe/a4eSjDesgbBUwZg8TLSjbpK6AiX UqKhnASteCSDl1v9Pj5h/YE+Xc5SI9kuKZoIYki68yrPtZTV3jW3ucTY92QZjBlbnLSL LCPA== 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=ndj9RpWKLjmaN6h4b1KczlaSDuqVReR8l0rZv2PiqIc=; fh=Jyyol/ssziWjsYDXIQK0KfGX7CB+K2Pkzeg43+AD2nc=; b=Ma2xhyA39XMTa2XbJ/H6MlkRq7xLgHEWybkETwPDnyA6hIt1sYthFUxcLZ+mfW+Rxa oAWaHDqBG2H/hV4/o4OvscGwVNHHeoB0qZh607Uj/WKfrLutotcAWYm9qYgsLcIGa4rf UbUa4c1zg58hwFLDeMOtcnztSizcTgdkvrrQvPBcpFcrFu6jfPhakNSFURjSxEzr3JOs C3q5uXa42btvuvR6q9eWpy32zS6YJrwlqmQEMfwf80jXGG31VF1ZCM9DGAXTUx3RgvDg BhinfMnx7mkenlkS7mDXeTbIntSTnimRYveiSSG5exDF90KSSoncl5vw46y6D0zP/Yg8 p5ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rsad3ncu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id az1-20020a056a02004100b005b979990808si452554pgb.75.2023.10.28.14.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 14:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rsad3ncu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CCC65804E83E; Sat, 28 Oct 2023 14:39:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbjJ1Vjp (ORCPT + 29 others); Sat, 28 Oct 2023 17:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbjJ1Vjo (ORCPT ); Sat, 28 Oct 2023 17:39:44 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4D99CF; Sat, 28 Oct 2023 14:39:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA845C433C7; Sat, 28 Oct 2023 21:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698529182; bh=YFw3MuSD8O4HGkh6VW7jNYSusxafWxc4LG1WG2XEIak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rsad3ncuTFb6Blb8uETRa8p2CrI/WfNNLFwR0mZNxGykNUbSS+QvH+riGsKiA/N4I pgDnA9qEyefcQjn3Y0aQoGoCKbzFfDsXFieWDkz/Zt1M8OXnvPGQkcs22EmMFpqCAl kEMUvhZXBWtWtl2qhcN0Txqab/AHdTar1m12mJFoOisu3sMJhKabSsPB9tLfTfNpP5 H+592qZf/CrUEm3ogVWHSOZl/r55BRqd/GGqawbIZ78Qd/ls7VwZlwAWwCwwLeyUoJ I6deb0IxPsc6gyH9W1WzehsLUoE3B3eJq1vGy3O+3RSbYaXgpu1dW1a1V0y5heXOt4 CPfozpxbJi8tw== From: SeongJae Park To: stable@vger.kernel.org Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND 6.5.y] mm/damon/sysfs: check DAMOS regions update progress from before_terminate() Date: Sat, 28 Oct 2023 21:39:36 +0000 Message-Id: <20231028213936.45621-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <2023102716-prudishly-reggae-1b29@gregkh> References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 28 Oct 2023 14:39:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781036943733012850 X-GMAIL-MSGID: 1781036943733012850 DAMON_SYSFS can receive DAMOS tried regions update request while kdamond is already out of the main loop and before_terminate callback (damon_sysfs_before_terminate() in this case) is not yet called. And damon_sysfs_handle_cmd() can further be finished before the callback is invoked. Then, damon_sysfs_before_terminate() unlocks damon_sysfs_lock, which is not locked by anyone. This happens because the callback function assumes damon_sysfs_cmd_request_callback() should be called before it. Check if the assumption was true before doing the unlock, to avoid this problem. Link: https://lkml.kernel.org/r/20231007200432.3110-1-sj@kernel.org Fixes: f1d13cacabe1 ("mm/damon/sysfs: implement DAMOS tried regions update command") Signed-off-by: SeongJae Park Cc: [6.2.x] Signed-off-by: Andrew Morton (cherry picked from commit 76b7069bcc89dec33f03eb08abee165d0306b754) --- I sent this patch yesterday, but seems not archived in lore.kernel.org. Sending again Cc-ing more mailing lists, to ensure it is sent and others can find it, to avoid any duplicated works. mm/damon/sysfs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 33e1d5c9cb54..df165820c605 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1202,6 +1202,8 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx, return 0; } +static bool damon_sysfs_schemes_regions_updating; + static void damon_sysfs_before_terminate(struct damon_ctx *ctx) { struct damon_target *t, *next; @@ -1209,10 +1211,12 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) /* damon_sysfs_schemes_update_regions_stop() might not yet called */ kdamond = damon_sysfs_cmd_request.kdamond; - if (kdamond && damon_sysfs_cmd_request.cmd == + if (kdamond && (damon_sysfs_cmd_request.cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS && + damon_sysfs_schemes_regions_updating) && ctx == kdamond->damon_ctx) { damon_sysfs_schemes_update_regions_stop(ctx); + damon_sysfs_schemes_regions_updating = false; mutex_unlock(&damon_sysfs_lock); } @@ -1331,7 +1335,6 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) static int damon_sysfs_cmd_request_callback(struct damon_ctx *c) { struct damon_sysfs_kdamond *kdamond; - static bool damon_sysfs_schemes_regions_updating; int err = 0; /* avoid deadlock due to concurrent state_store('off') */