From patchwork Sat Oct 7 20:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13412466 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 D32EFE95A65 for ; Sat, 7 Oct 2023 20:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB6366B00FB; Sat, 7 Oct 2023 16:04:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A66D66B0103; Sat, 7 Oct 2023 16:04:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9188D6B00FB; Sat, 7 Oct 2023 16:04:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7ACC76B0101 for ; Sat, 7 Oct 2023 16:04:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 41B72140157 for ; Sat, 7 Oct 2023 20:04:45 +0000 (UTC) X-FDA: 81319743330.02.D5B7F95 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id 42227C000A for ; Sat, 7 Oct 2023 20:04:42 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jblyM3cE; spf=pass (imf28.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=1696709083; 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:references:dkim-signature; bh=1FGT+tz308sNzamGlJ4Lq740ho0hdw/cgGCONtIVBNQ=; b=h8o0vTQ9GigUGlXGGsxRmvNBziWWfSz3KZLjl9RfPyak6Qpi53OX3LSY280+miqJgOfxQ2 +m7kHLL6wNAHzOnDJJyDoirrAKMrfLyD+jfF4PeSzel9DSiu5xhWfGttmBdxy37BK/qOuw QI/X94FZUexh5FAcPOgskf6ox5UkiJ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696709083; a=rsa-sha256; cv=none; b=Rw8ErgDSsMqzAqb5XROPUYYMJQ8dtA5MyxJQdrTaGF1wMfAuJuUdZQqAB7T97yPGTEPy1u 8JIflnnLjsLeGxdKZrRyZptsSg5f63Ti3wMX8diQbD+LS0EA1dO22H2oSw37mgsILepj95 plp/goO02kptjkhSzmG3a1HHWREkY9w= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jblyM3cE; spf=pass (imf28.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 0BA11CE094E; Sat, 7 Oct 2023 20:04:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C135EC433C7; Sat, 7 Oct 2023 20:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696709077; bh=k+E7o4trRwpUVpsgiWw9zd/8lmV+kOwn1CHhDi4J/Yo=; h=From:To:Cc:Subject:Date:From; b=jblyM3cEtrib/74xHI17sH3ZJytEYYeAjCDJPFD3KBCStlKs9wJ2HGxDFdvarbqFx P36i22ZGZM67vyqEdfO9Ad3jx1oaK//GGZA5uBXorrNyJvqkq5qnAKDP3V+ZaLnAh2 lnmDVYg1qVN84i7cblbu/rhsRCro+/X6M3LTbksmIv1zXohwfC6C2WMYnKpP5LF3nw VMkFPEsWGWpg5KxdeWJFzPh8lQX0cgNxP7+f1bOspOyGrTM+fU2vkjw3ycEjAq5AIE O7yLzUTUHvd33/7pklmbQ53JP1Ni2pVLHSs0yw0YoLHOV0pPcH2ij2q6ez5KgWvQWF JrOsensvDSjTg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/1] mm/damon/sysfs: check DAMOS regions update progress from before_terminate() Date: Sat, 7 Oct 2023 20:04:32 +0000 Message-Id: <20231007200432.3110-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 42227C000A X-Rspam-User: X-Stat-Signature: yzxieomt56dm9ysarri9xbb614damuiq X-Rspamd-Server: rspam03 X-HE-Tag: 1696709082-271966 X-HE-Meta: U2FsdGVkX18WvOq368XAT+8cBGKzVFFGm5yQ8fI9PkugOjwSzBNmM7F2875J56fxVGbqAHbPIoofbVlrYZrz7OyGuUDNxnUsE+4CpBHr+d9xJ+5jWkPZNmtla2toKOpspLKzAeBb8p6Rhs9DDRjwjkg86ZgmYqbp8hwuOXzLPLESSfG82iili/lStbks7ImNdRT1exXCR4Jj+0GSmj+RNixYP3sehaCrahEI6L/ObSdX/Zc1bAYFd6td8MKJJ1QEGYISHIDokmn22jUzrAYLabWZhiP9+Oaamw/BgIqYXSCgxdHFvrOyqHb1HkByPbUTht0v2jtpYjzVW2xQZW1ix4u5/twuXPLrxRTBaPqV3mlZDO9qnPR1euUNLgcVfiR3+28+Y7ZqcVM6e5ucurzb8w8mAh2P4otqgbzoQd/2GPowV+ztalsupayq2uUiqlkp0pQGqTF8oaxBzxXj3uylZdLhHs/0+ojI9W40XpZW63IYQc270FyK21BjJZgzur8ffWX00QRa1whTJMSKPdWLWl3Aj9gIUdh+jf8rqaOuH5xyRgEFZHhYOjD+lJwS6sobDYeMVrLdiYy9eHeL73NsmeXGWqHhp28Oc9KR4nHj/daJ1MtWfEAlb0AsfumdbnQwJ+ZESvh4CIhpHDf8RmTn7prVMW5uYPkGAqX8VAjGe3JFI5lRQNTbFji1PV2fDmsoQN2/TGpo2e4igP471PdcKoqC32w0xHCbFqW9nYUBUYxFDFjMCftNzYqooWOh85OXvMCaEdv5LlzerStj6/U6UFN0Vam7CSyhWktOiFvaanAWUkERaF88KNfw2iElmaUvI9f+6D7USsP2cbjDbRbKxMqos3a0Bl64pN/qJt3PpoZKsVcUTk7ywSzOuDTFGMAGoHI7wP0N9RpjuRysNyA0sDMy0gUtUgP2cirya4RSZhWLJdDPpC6B6lwrnsuo75rV077o5qnrYg1LQBKIhjq JMD/MlqY pA5SKf0jqxMKw0GRyYDZSuHf3nu+hpHPrmFSfsG5KKH8rGFcaTBuYrYxJCRI5zYzKrdmSS74dhIHiGdgR7h39uuxuZ/QmL/Do1rpYH7rxW4OpTXgpZcSxOspMsI/QAFfWDWkF5KHPfBlPUKIS4q48ZKDOC681KWCQ79lvr1JfvOzenQDQykP7T3UY717n1E/9Uer6Bw92Nsm0jGk7ZWPYSTiPrAsnqdX8cSv33rHlYByJoiST8g6pdqLctodwk8WXbhWr8eFnVZuUaavJiIth4tLn8icpbLMuHrt/ 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: 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. Fixes: f1d13cacabe1 ("mm/damon/sysfs: implement DAMOS tried regions update command") Cc: # 6.2.x Signed-off-by: SeongJae Park --- 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 b86ba7b0a921..f60e56150feb 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1208,6 +1208,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; @@ -1219,8 +1221,10 @@ static void damon_sysfs_before_terminate(struct damon_ctx *ctx) cmd = damon_sysfs_cmd_request.cmd; if (kdamond && ctx == kdamond->damon_ctx && (cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_REGIONS || - cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES)) { + cmd == DAMON_SYSFS_CMD_UPDATE_SCHEMES_TRIED_BYTES) && + damon_sysfs_schemes_regions_updating) { damon_sysfs_schemes_update_regions_stop(ctx); + damon_sysfs_schemes_regions_updating = false; mutex_unlock(&damon_sysfs_lock); } @@ -1340,7 +1344,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; bool total_bytes_only = false; int err = 0;