From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8A7D33EBF0B for ; Tue, 17 Mar 2026 15:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773761092; cv=none; b=nDV8Nr8WgtcLD04fiUsCaCMqxpDCk92nswRSMy+xpxp8UGUH2L2xEM3DSqpe0ac9k0cENTvvO+nzRokUvyA6WQFqbwS4c0doCwsdROTFYxy8k0UI75uw2mY90oZMs15tvnRBwk3OUUzBWJg+uyaz/7nA+kKkHIgcvU7wl86H4Wo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773761092; c=relaxed/simple; bh=bQzYP+oL7tT/zm7O3THYq/kPW2zfeInrxgDU6BfX1Z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LfzWnYriuHxOEtaS558n35VPX7Vn+0QQIboAyubYhfxQdKlyoF/c0gf9a1cBPckIj7ud51lfKgbO3fyTZuxiZ/+UvJo9xTsWLtg2Y28tnEo0oBxUVsasNnnRqczC6bK1x8IYrcvdsSM+JZXisuNz2S2XQai5tRSV83u3pt4ooNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QpsxTZdj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QpsxTZdj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AF6DC4CEF7; Tue, 17 Mar 2026 15:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773761092; bh=bQzYP+oL7tT/zm7O3THYq/kPW2zfeInrxgDU6BfX1Z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QpsxTZdjkRiMixfxI+6yzwvd0u3KJxfOEZiQHqRExyLDXTaqnUEb4SUwJRouW4h8r g2zqy6DdOhEec681i6FKXHPG0IdOF0yrZM0Az5vu53cYZnAIMPg7JNGpIu2gB2g0jz kjIWk6eSJN1SeubIC2oxFKQcwFrDmopbWTtUym/xRQ6w0tBlpdJZjQ+ZKFQ1Au/x4P 8ZhS5xcdkaq3KkCkwFlLq28zNhFqQAvCy5XUJzrfeexYfBPph4KShqeT94GasziEqW g2OugtrKmn3jQJ9MjehvIae2U8Rng1Ui3yxQBm9UEX/ZjHU6ZkFI/4QROpahDwuCF3 Bv4qtFLdpogPQ== From: Sasha Levin To: stable@vger.kernel.org Cc: SeongJae Park , Quanmin Yan , Andrew Morton , Sasha Levin Subject: [PATCH 6.18.y] mm/damon/core: disallow non-power of two min_region_sz Date: Tue, 17 Mar 2026 11:24:50 -0400 Message-ID: <20260317152450.191424-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031715-scrutiny-refurbish-a751@gregkh> References: <2026031715-scrutiny-refurbish-a751@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: SeongJae Park [ Upstream commit c80f46ac228b48403866d65391ad09bdf0e8562a ] DAMON core uses min_region_sz parameter value as the DAMON region alignment. The alignment is made using ALIGN() and ALIGN_DOWN(), which support only the power of two alignments. But DAMON core API callers can set min_region_sz to an arbitrary number. Users can also set it indirectly, using addr_unit. When the alignment is not properly set, DAMON behavior becomes difficult to expect and understand, makes it effectively broken. It doesn't cause a kernel crash-like significant issue, though. Fix the issue by disallowing min_region_sz input that is not a power of two. Add the check to damon_commit_ctx(), as all DAMON API callers who set min_region_sz uses the function. This can be a sort of behavioral change, but it does not break users, for the following reasons. As the symptom is making DAMON effectively broken, it is not reasonable to believe there are real use cases of non-power of two min_region_sz. There is no known use case or issue reports from the setup, either. In future, if we find real use cases of non-power of two alignments and we can support it with low enough overhead, we can consider moving the restriction. But, for now, simply disallowing the corner case should be good enough as a hot fix. Link: https://lkml.kernel.org/r/20260214214124.87689-1-sj@kernel.org Fixes: d8f867fa0825 ("mm/damon: add damon_ctx->min_sz_region") Signed-off-by: SeongJae Park Cc: Quanmin Yan Cc: [6.18+] Signed-off-by: Andrew Morton [ min_region_sz => min_sz_region ] Signed-off-by: Sasha Levin --- mm/damon/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index b787cdb07cb25..7cb09d4453ceb 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1236,6 +1236,9 @@ int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src) { int err; + if (!is_power_of_2(src->min_sz_region)) + return -EINVAL; + err = damon_commit_schemes(dst, src); if (err) return err; -- 2.51.0