Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1176138rdb; Fri, 20 Oct 2023 10:23:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvR9DawXL9PZPfxwfZGSyuzPgAwr9B8GGiB0c9ym88OdYCMRQRKEF31N01LgQclLF2J3jt X-Received: by 2002:a17:902:e741:b0:1c9:c951:57f9 with SMTP id p1-20020a170902e74100b001c9c95157f9mr1893771plf.68.1697822609506; Fri, 20 Oct 2023 10:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822609; cv=none; d=google.com; s=arc-20160816; b=lRs7ZEliR7TqlE51b1ovYhWmZbAeCOeFVfE//ZrhxxZtAwqWlj8RP52CG4vGvT6VSu iIflzxZPiL9srdquRn222Nk62SRiHvehCmr4RnRzbTXulyckQHf6JVZbx8U5CWIdqElV K6QTwpNFBluJT/Tqy5lWSpleA9u+UI3rwGAGO3kacX6b35COo6kvvCacpKQoddZp2XJr QPloh43s2zPTgDzDOIlNEu8Rx5rb2tKlDR3w/ifbPjfbYGYSeXxq1GmONRbnEqCwz/Hj zr3waLDpdZFJa4DJwg+wiwVjubm6iyIaMr6QbcF9nLtdl+79U8RG3CEemEpw66YbdwZ4 EPJg== 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=9HtPxx/ZTHCGoGxSifwetWG6HfXF9zUo9CxFU0ta5d0=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=EDrOvvO6ki4DTgpqbycrZyhTp3qojCQK3jWO9Qb7G7B+ai/9PbPXn3EHAr7cKxeKf/ aU1+XZwi3UoH+LZQP7UxiA6CLGdOKX8SARj5ndM9owSbpd8n9jS9woNeZwxvM6awYO7f 8u8mycjNueiWTQaR5+Fe266KvrrKi+hB02j63wgAXE8Evw98Y+YnZ21ku/as+vMVRS8z 7kB5/2s5LUQNdjsowP2dpWVpLZerfx9bYKRcEkx4U/chd03Kty1srlCoakGZIkg220YM pUjtBkQE1VLDlnL0rJJyaRk+ngLW0T7T6bV66vYVt2s/uutJADYGVkiDZ+TblLYnBK+4 sPZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lk1FqpYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b4-20020a170902d30400b001bb9370760fsi2193701plc.90.2023.10.20.10.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lk1FqpYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 5E831830C31D; Fri, 20 Oct 2023 10:23:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377908AbjJTRX1 (ORCPT + 99 others); Fri, 20 Oct 2023 13:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjJTRXY (ORCPT ); Fri, 20 Oct 2023 13:23:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DA651A3; Fri, 20 Oct 2023 10:23:23 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5437EC433C8; Fri, 20 Oct 2023 17:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822602; bh=Rn9BHGv/kMTRWnOOhqqlR6v0d9H0u3tnTjx9VDJfJCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lk1FqpYByQMbf59yh0U8YLgrRJ43zTSnfY5ztYkNwJxmOlrcYYzGMmulb64GWPd27 WDnr/ul64sOEPEBEX/FpDD7+OZxQ8uoE0Z3aJRmivH6ITsRSScdktkyKelkVw9EWzz /YvbiC+RTKd5QA6LA86beLXArsehV6tLDXXWVWr1ZBYHK8TVlWJvgdQu8eDE1kLNFp Y09FFWInvtPhlAqZAV2wcN8olPgLL4o0Xj8ujhKXQCa21H/maEShe4WpqSSEIrcXg/ zChMs5xWAxN9PsyWly2J4u8y1YAbo07mJij27Eu/Tj0CAYBsIe7S6DVGlYjXB2W8SE DJbKUg/VjiXzA== 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 1/5] mm/damon: implement a function for max nr_accesses safe calculation Date: Fri, 20 Oct 2023 17:23:13 +0000 Message-Id: <20231020172317.64192-2-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:23:28 -0700 (PDT) The maximum nr_accesses of given DAMON context can be calculated by dividing the aggregation interval by the sampling interval. Some logics in DAMON uses the maximum nr_accesses as a divisor. Hence, the value shouldn't be zero. Such case is avoided since DAMON avoids setting the agregation interval as samller than the sampling interval. However, since nr_accesses is unsigned int while the intervals are unsigned long, the maximum nr_accesses could be zero while casting. Implement a function that handles the corner case. Note that this commit is not fixing the real issue since this is only introducing the safe function that will replaces the problematic divisions. The replacements will be made by followup commits, to make backporting on stable series easier. Reported-by: Jakub Acs Fixes: 198f0f4c58b9 ("mm/damon/vaddr,paddr: support pageout prioritization") Cc: # 5.16.x Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 27b995c22497..ab2f17d9926b 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -681,6 +681,13 @@ static inline bool damon_target_has_pid(const struct damon_ctx *ctx) return ctx->ops.id == DAMON_OPS_VADDR || ctx->ops.id == DAMON_OPS_FVADDR; } +static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs) +{ + /* {aggr,sample}_interval are unsigned long, hence could overflow */ + return min(attrs->aggr_interval / attrs->sample_interval, + (unsigned long)UINT_MAX); +} + int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); -- 2.34.1