From patchwork Fri Oct 20 17:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 156237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1213304vqb; Fri, 20 Oct 2023 10:23:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6mhwM5dNJdCmR6zmQvVAJ1Yng7KARKtPdqf7zcPB5dPCipr/cJNQbnaTEEtMQ90aukJYU X-Received: by 2002:a05:6a00:812:b0:6b5:6c95:4671 with SMTP id m18-20020a056a00081200b006b56c954671mr2644229pfk.34.1697822627698; Fri, 20 Oct 2023 10:23:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822627; cv=none; d=google.com; s=arc-20160816; b=xvXmKGOlotZb06aXBHhXi789ua98jeUS/Psx5N7KdoSmUZMM/skZRtbLnZXuOU+d09 JbWCexCY1r1x0W/eKjHiWxITmh0aiILLbuctUrt28ucGnj4uPAV8znuVcOm5nzWu9D7d 6laAq4SJJ9pIldrbTtfyQOVpDXrgt4UXTBF2ux6R6uBZNOOp51iBxMK0C9Vi2EYSTlKI MT4i83oghasoYBdYKrMKzpr8KgeYA3V+86wDtudZmJAGPjB/+LgsuhckGyFjadxK3qYT HmujdqgCXlktSWHpvrKyhPFkfB9oxIz2uWHtYCR8sb2Gko/5XT65Z1OqePlwvE1l23VS rWmQ== 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=gHG3JngsXmc6BwWUvB8MOvbIsEavnDuQdNxca10fgBw=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=Y56qHE5UcY7gOVARegbfscYUVd5VQvnpnQCDQlBAP4kqpdOAevHlKPDVj487t92A7t 0z99sD3Eh5wsw+XiE04kuw+fRJo6EOrNaMF903D6PeOlXFFz2iOHK7HEg0QaZx9pcjwp VW/TsLVEQap1h8AVq2k3cQ9LKlL9zXBUWL+2gRuoOAwpAF7XCyTc+lvhmLfpriD+havQ 0tpDfqa2EPHCeczTMYLFESXyGCFfrtb7cCRrROk6RsA0HzFQrFzv3ivjlP5cJO7hvbRK Cz/vW/8lBSqwq63W3pUrbmPcOQ+8oZ+CR6LH3vBKef8XH+xSVfHBVMEylfS2moL5krWX LLCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tibiLrMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id t71-20020a63814a000000b005b106cd44casi2412016pgd.145.2023.10.20.10.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tibiLrMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 6D17F8316EF9; Fri, 20 Oct 2023 10:23:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377926AbjJTRX3 (ORCPT + 26 others); Fri, 20 Oct 2023 13:23:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbjJTRX0 (ORCPT ); Fri, 20 Oct 2023 13:23:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA258D4C; Fri, 20 Oct 2023 10:23:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1487BC433C7; Fri, 20 Oct 2023 17:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822604; bh=OyGTPA4KF2+eYVdgVawdmd836X4nvWEWuxM0J39C7SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tibiLrMDEW1tJPRD83m27OwLCd/3DldWtN6HSY+GRNl2CN2/lGFqdA8TQQ727MbK1 RXghEBiUVpRYW2wWEiF2yiDTw4Mz9aUN/5jKYr74Dv/eki3xYKDE93RdSo9tqctrMh CQYh7C/JT6Pd/m/Lx4jnpiYh3AL+5ZGjJ0Dgwm8qeCTjxEkZ//jSvkKcBywnn8qJsk xIov6mao/lOfYVmBmQThgDh3lKi7Zq5LeWX+G0A45G30D5VHCYpRwm1A1Anhin9GeL YqhXZxPUTshcAwA2xiNxXzGXvG7BgM88reL/1z9rKcS6B3dNgRns0LUK1vsgdWaqlG PvGSzwlgnkpAg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jakub Acs , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Fri, 20 Oct 2023 17:23:14 +0000 Message-Id: <20231020172317.64192-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020172317.64192-1-sj@kernel.org> References: <20231020172317.64192-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:23:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780296059709866905 X-GMAIL-MSGID: 1780296059709866905 When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it divides some values by the maximum nr_accesses. However, due to the type of the related variables, simple division-based calculation of the divisor can return zero. As a result, divide-by-zero is possible. Fix it by using damon_max_nr_accesses(), which handles the case. Reported-by: Jakub Acs Fixes: 2f5bef5a590b ("mm/damon/core: update monitoring results for new monitoring attributes") Cc: # 6.3.x Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9f4f7c378cf3..e194c8075235 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age, static unsigned int damon_accesses_bp_to_nr_accesses( unsigned int accesses_bp, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return accesses_bp * max_nr_accesses / 10000; + return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } /* convert nr_accesses to access ratio in bp (per 10,000) */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return nr_accesses * 10000 / max_nr_accesses; + return nr_accesses * 10000 / damon_max_nr_accesses(attrs); } static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,