From patchwork Thu Sep 5 16:24:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13792677 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 E7882CD5BD7 for ; Thu, 5 Sep 2024 16:24:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B8B36B0088; Thu, 5 Sep 2024 12:24:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 341726B0089; Thu, 5 Sep 2024 12:24:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2E06B008A; Thu, 5 Sep 2024 12:24:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F25806B0088 for ; Thu, 5 Sep 2024 12:24:38 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A95F680439 for ; Thu, 5 Sep 2024 16:24:38 +0000 (UTC) X-FDA: 82531207836.04.C54EAE6 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf22.hostedemail.com (Postfix) with ESMTP id 15C4EC0017 for ; Thu, 5 Sep 2024 16:24:35 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RC361kxC; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725553378; 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=pp19hewdLupBT45/trz75FWDAEA1iGnwEd9K+d6ne4E=; b=mMRYMz/4MCd1C0u/QKlxPBaf/nIQNWxelrKks3JyXfmWBEusE+S81aZFqTmCM7c9ztSiWb TMTnwD2ZZKlu/v2M1dJlOZ81TfMlTlkmNk1TnywlyTVB89BPlpSKBJ66FJPs0PJvGVpVAP 3lbnsFJ6YSOEIN7eUwYqrPIByeZYsQw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725553378; a=rsa-sha256; cv=none; b=VYKUjO+irg6K/MvDmUJK92jjGdQHC9JLLLDa10E8xj7hFdrwYdZlcWgk8StLZFzhi9WUCb 2bE6+z0a2Z1u99g/tqEi9sMafA1BoQv7xPsvH4CLqvb8Td1CLgTnIjxNmRsiheo1uLWnci 9DDNLjov2JhhDC//LsdYPqt7+hakSG0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RC361kxC; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id EF854A44DB9; Thu, 5 Sep 2024 16:24:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17F3EC4CEC3; Thu, 5 Sep 2024 16:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553474; bh=fqMbyiPOPWXkEPOx14J7eYz98VVS1VH43XBaqNJ6PmM=; h=From:To:Cc:Subject:Date:From; b=RC361kxC4yaIbdnqo4wbAJzrWBPc0e7jPmVDZEoqIJ2y+Dj8Sz6sbt2zMTEyPnQnP 4nIg2jqI5mOYmPVYcXgDS7UbKV965aF4ttZEj879KGiXx6kzt7/odkHiZep5/2VQ3J s5SGuEPod5QOzFoUhKK4C3nVBHmA91ksU0Lohvb+7kvbIiwyqMtvidNfTYEtTJqqnm OTxS8G2pYi7Pd2UgfkWRTUwqbr2kbdSrtIk04562i1lsn08SnRJXQUy/RT3GCTPC5A NH/B0ZVFhRJQBA+Dov6aOk6m5cmF0ghp5KK5BNmczUKF9IL2zKcqjgvnujWf3X3QUE J9pI5UtJxaRmw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Brendan Higgins , David Gow , Guenter Roeck , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] mm/damon/tests/core-kunit: skip damon_test_nr_accesses_to_accesses_bp() if aggr_interval is zero Date: Thu, 5 Sep 2024 09:24:23 -0700 Message-Id: <20240905162423.74053-1-sj@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 15C4EC0017 X-Stat-Signature: 3co7unn53tosmuo7hyjnn1oyrrxwybuj X-HE-Tag: 1725553475-663739 X-HE-Meta: U2FsdGVkX1/hYNHVDRk5MlP0ymZU6yujE1lAoNvWGI3ltz6coIn5wVFgG/W1uLxjEb+Eh8YEwIzaNW5hkLAisN2+ObDfiO/1Ja9c1cLYT2V1i1yUm6qBOJglUzfbAGw595q5Pg6urye/6smXwuglbN82Xk1tkPPp4lyNam/vwE+gdwIz8vK2Jli2WXQ4Sr2T3yh4z6vD3QBTlNOF414lBvzQI/QAaW6JlvUYHFPaGk7/+xLqiYfNRgM+k/+smvZIIDO6zVAZFysXO3cjEXopuEMXvXBOOsJ85lhGiLd55bD0fy7oXxAC4DxjVhZQK+6JYC3BKsBcJzQrCJ5yIgZt1kO2m9FGpj5cylEULrL8PoSQycvdJDnYHbNsprDhKDYu1JAcIdwdclX6L8Bk0Fd2SeORI/fnA/39XZiNBHLCDOEeKoY0JgLh5/MQg8npCkx3fF2MB67GArLTrAI2/ZzzSV4ZwqAff61tKLb/FEP/RyHuFNIfSmBt3GGb5qLIWOH5HiHhqDWfXEulyi26k3V0sFyy1xNjZzO2nk8ZEBCGxPkG0nMH4RR/pAGNj6LogYb8iVpHB6tzVDZTCiJDlpF4JZSPlrPt/0TH2NnguyYa54piBtOqv87h3irYAatucaB/cdLrXdyMmsXl1lj067vTrUzQ9UZf07tB0wvXFRW2rViRGzXhkkPBON1W/a7CEz+vbfKZgD2LAAfnUVEgYzgek+Hz0IDoMNozQsz+6q+MRkVg+7N4r7hXMc/A4K36i2KDSkj1cpTYUk9EIIyI03kvsk+PcwLGGfnUsouoivALRGuGM7QmHOUfnL9EY1IXycVZaSA8XAN/WHiNwXvYbWaUKkZ9ut2yAOCQ1HywvYqqli3LEL2vfPujDdUHwPf/OvIg7kBX8u016wB1S5wvX0+igxzTDyzNGas737R4eOSZ9z6thVRTMY80hSnOakdF8YPYlV/HYfhXdj8HcSwqAmm mnROaEWK GXbpdKP1/Mf8uGUZt+/EZE+HDBYZTXNoZgkEZ4vPwjFU9sJ4KRoMtTd7UUdVpyGQyt0b6pguVWYUMkH9kNcUOzyN6vneyYQEpARBdW+Wz0cri5woNKnQeR9uZ81WQiluGZqoJP6c6HIEfUqPtW/d8njddlZWB3iuMvUmo/6jcMbhK+LojbAfD/eK6fh5jZfBkO6YNlGkn0kJjNUyq2vrsNi0eK+an96q7Tqo5BsrcencU6SbDVBgxsEiT1dTOpWx1zBBT8jolJAAOp9W1Fnhq9Tgcn7vqNHoBh846f2jLKSAAi20Jjdp455p6Ge2Uwa5PmpoF/V5dA9LtXCO53zWn8ttCoA== 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: The aggregation interval of test purpose damon_attrs for damon_test_nr_accesses_to_accesses_bp() becomes zero on 32 bit architecture, since size of int and long types are same. As a result, damon_nr_accesses_to_accesses_bp() call with the test data triggers divide-by-zero exception. damon_nr_accesses_to_accesses_bp() shouldn't be called with such data, and the non-test code avoids that by checking the case on damon_update_monitoring_results(). Skip the test code in the case, and add an explicit caution of the case on the comment for the test target function. Reported-by: Guenter Roeck Closes: https://lore.kernel.org/c771b962-a58f-435b-89e4-1211a9323181@roeck-us.net Fixes: 5e06ad590096 ("mm/damon/core-test: test max_nr_accesses overflow caused divide-by-zero") Signed-off-by: SeongJae Park --- mm/damon/core.c | 8 +++++++- mm/damon/tests/core-kunit.h | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 8b99c5a99c38..a83f3b736d51 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -552,7 +552,13 @@ static unsigned int damon_accesses_bp_to_nr_accesses( return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } -/* convert nr_accesses to access ratio in bp (per 10,000) */ +/* + * Convert nr_accesses to access ratio in bp (per 10,000). + * + * Callers should ensure attrs.aggr_interval is not zero, like + * damon_update_monitoring_results() does . Otherwise, divide-by-zero would + * happen. + */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index ae03df71737e..cf22e09a3507 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -320,6 +320,18 @@ static void damon_test_nr_accesses_to_accesses_bp(struct kunit *test) .aggr_interval = ((unsigned long)UINT_MAX + 1) * 10 }; + /* + * In some cases such as 32bit architectures where UINT_MAX is + * ULONG_MAX, attrs.aggr_interval becomes zero. Calling + * damon_nr_accesses_to_accesses_bp() in the case will cause + * divide-by-zero. Such case is prohibited in normal execution since + * the caution is documented on the comment for the function, and + * damon_update_monitoring_results() does the check. Skip the test in + * the case. + */ + if (!attrs.aggr_interval) + kunit_skip(test, "aggr_interval is zero."); + KUNIT_EXPECT_EQ(test, damon_nr_accesses_to_accesses_bp(123, &attrs), 0); }