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: 13439607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 282F1C4332F for ; Sat, 28 Oct 2023 21:39:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4FF26B033C; Sat, 28 Oct 2023 17:39:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FFF96B033F; Sat, 28 Oct 2023 17:39:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EEE06B0341; Sat, 28 Oct 2023 17:39:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8388A6B033C for ; Sat, 28 Oct 2023 17:39:51 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5EB0F1204C3 for ; Sat, 28 Oct 2023 21:39:51 +0000 (UTC) X-FDA: 81396187782.24.B6CFC40 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 4F25940009 for ; Sat, 28 Oct 2023 21:39:48 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rsad3ncu; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698529189; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ndj9RpWKLjmaN6h4b1KczlaSDuqVReR8l0rZv2PiqIc=; b=pP15qW0zWqivEB7SvLPgQQw3A4Ck1nZZAF23owcPxRKIm2Z0lzDOQgzUeAQakYNHt3kFdi 1qvLmZZgTPFAz/7afOLWXTxX3P2pwN5hav57qv0kH2a7GyKZTv4kW+BpkTQH6FXcrvv5GO VmQQzJ7rrUbNZ/O7dMVWqrq1bTIxRZg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698529189; a=rsa-sha256; cv=none; b=CJ9mj8+4ktgZGWT1mkRejqiQEeLyRa6TEm+hSSt+g/xAwKnW0moiLbzsBi7GWU40WAn1fU l4KZGCWRBJv5rADLgo/+0ELi3X1cTEvNiMKFJgJHwMJVzu+hEWyHlejG1Y3+cyYqZJjC+D HeuKuxqM2UGmF6tmQjSPtryPf5fbmOE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rsad3ncu; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 137AECE16F9; Sat, 28 Oct 2023 21:39:43 +0000 (UTC) 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-Rspamd-Queue-Id: 4F25940009 X-Rspam-User: X-Stat-Signature: g5nbgf67ynrg6fqzzpq7feo53ijwfqc7 X-Rspamd-Server: rspam03 X-HE-Tag: 1698529188-701762 X-HE-Meta: U2FsdGVkX1/K0ks2BB2U+PsnBUxscNRt7MMUhiLXJ7ueCXinRSe4Pi0P2/MFNJokZCgkfNBrMEAY4bhLwddRNfPEEbBXKQTCgeRz2cpT4a41eEqjfgoT81XLFVQWtWxnfEQPX7yXsXbgQrHI58soLi4z5YzaTjzZ7WPI1wCYmpmJbgUIqXdLWjAN8FrGedoap5DEQFe9MRcjLkES9y3NDKIuRyPjgowJ0FXU0SyzHXiGuDuaaTOaZorMYUaVjghpGfKG08YPVC4Hdk5fa6OnFY4oOaVx3eZqG4vJcU1b6IElZ44gRzl4qPZgMIhUzEW4hCsVZACkV5Fnm1UWvLO/Eqa6fvWRWoBJRj/QBRr+ttYJEr0NXvM1UyY+i7Yi1WJZglfzPoNrnqhMi8N02V7HbIljhsUh3VhWiT/gEGsVKFq7uZbrOMrHTglbYV3tpkxsc7m3NbPpcNw3UuowjPwSGYseyUq4Z+FYMJ+BZ18+nhX87Cd0F3I0uM8C1bKU/uoroceGBAVj/wcMIit9ksqfUhn5hpXN2ExPY/v0HueR3KIUK+d4JqqFvv8gPBavzGKMEcZYASV/geKyr8MM/fVjbY9VPQ3b6EFDhoi7gCSFM2l8bb89+r+n5PCbxYmLjp1LBXgiKsscwMXjuNq+6+zw1F1IcHoq7m9QcRpbjYl8LSVPFDSCgUknoofSOepuCUr2yi9OH5jP0fCD0X9FXMyjbm7Ml57PuJGhVxD5MLr7jaXeg4cW9prYBrL+PqVU7mT11NdU2W8ALgPCsbGX7J9KfLcD1nVtDJmphq+ZJldPSyi3gKL03sVfxeQEg/wdsIl5oG/zt/N6czweEarEuH2f8TSSjvRm6JuqcH8dptkFWye/QOgHGIgZNAE4GmpPijBgCPZpsFf0L9b102u4aCT+TYeXodXzvpW1Oaxpm4dF9PquGvW3DJZaWY+PKgoMlESRwkkpUZhfWQy7KQOp+OT +MwXyK5D u2/sOc2B4SWtgwE0JyImdYRZLFpblD5SMt8aTjm+19oHBD5iZn8PJuAysN5ys+2DIjl7mQAbAQaI/ZcpWOahvgtnsDZnWVgff2WBpdYdzbhvNY/8+DHZLSyUdv8W8h1JF02VMb9L5bUjhoYtbgc6TlksCeK8KQFxHch/jd8fW8kGiI+V9zhafbWGDZ8x9kS2f8pOZTtcq4wzcNqWOzT558ZlKOk5XbHMLwq1uGRS0mAd0HMRdCYvK01FJ4epirbP9caRF5QXQB/5uzzvBw+9epLquyyXgs5omIWwHO+qkF9cbBA58s5lf45BsjhtvoRw3mqNM2Rebmw3pWYMeL27rG+b8jQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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') */