Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1173811rdb; Fri, 20 Oct 2023 10:19:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEWAFSnxbwv1+67UkqGJLJEDUpHnHfAUy4aQAES3qYfj/gOZSWCl4DnWTcao4hV1YKSjTR X-Received: by 2002:a17:903:23c8:b0:1c9:b2c1:139c with SMTP id o8-20020a17090323c800b001c9b2c1139cmr2547240plh.62.1697822361249; Fri, 20 Oct 2023 10:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822361; cv=none; d=google.com; s=arc-20160816; b=i4LPVHqnKT8Fy5bQsHaq0RFiemDj2dGl4q6Mqzb6O0dR4RrUeZiqCZd7cTFDmsC/Gu dgXZ/NW4E3YeNBJjoINpG4bEY1ffnoAeOgNEMNTrYYYUib+7IrmKFu1gX6k7H22dA5M9 IazJKnRzWV6O41j9qjIT/+zuISIstx5qiCQwWFei6YhQ31QvTzJZGID7qhv2Z+q/W5l6 3tZWPIrK6vOWxuqH02mTW1tP0lgzUufJ+9iVqWDV2P1TOIpUlxQoCRWPeGAtGbbX0RJ8 Oe6tiSt/fHI6VGiazAh/LbKTjns5Z7Isi9xe+fOq7CD3jrzjswF82nIEuvNHAQiNxYh3 tYJg== 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=YODr4Q7bvv0v2SnalWzn/+ZP8U/KDaYy14o8DsvmcC4=; fh=S5Bg2IlDb3soc5zc85pq7iQxxbe/ZpvR8LNdssOxBig=; b=LPF5Zb01Xd1HODobdASHLqd/egqMGDv/t+fUi4BpgJ+9nLfWFG4hnW1i60MJdOahoJ 83sWYx1s5pX57ywP4Z6RfdloXsGHyMgKKHT+vIJrhOvCCVh/kkMtvzD1RH/nGjfN8tTA dzPQFgQYPzK0AMHH9fDx3Hmrrbotd1Wnbe56agMpGjVIdJflbmpuAmhMa1tNd9bFyLXb wBibIXOcRdc/OYB1KTOdSEV0g6aoOvvinjlSFQFzni5Zk00EOaWbdm2vQ+s6xm7Jc+YF 3H3P6pF7ln3xzMaLzlsJsayZpb+vf2IvSuf1efbZtdAE5qND3wHpAWGUKZMHaeK02nsW BKog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZtO5ia0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b9-20020a170903228900b001c9abb72958si2315445plh.590.2023.10.20.10.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZtO5ia0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 6315D82DAB7E; Fri, 20 Oct 2023 10:19:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbjJTRTN (ORCPT + 99 others); Fri, 20 Oct 2023 13:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbjJTRTK (ORCPT ); Fri, 20 Oct 2023 13:19:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1924FD6B for ; Fri, 20 Oct 2023 10:19:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45A5FC433C7; Fri, 20 Oct 2023 17:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822343; bh=hlMCZswAeW4ccJFBbACI6PkjYN5gySJRK7nIvHrFtHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZtO5ia0wmqJHeYNzWciWtWsLxNbHGiBlcLMyPFb6hXavXjgv5VnP4lfJ52q0tgsOd tF0Uet6ldgFGLrp5CW04DQxCFjnipDwL96aMLqx2SeFiYguJvWDwmqIAotzUwAH1BX nB6dz3poX4KLG+C2odATiZdRMdqQvBzOMXXpanjRFwA0+n+uZHArnwRMP+hf4s97NZ tuZQlKTksfR72h3efgJydVRr9aNIT3XmBt5RO9Dh3pIlawkfaUdmD0gmBDccYEPytX 6NYSI2Ski0mlHbQZBCRG/qWkvR8hqSk9TqaLoagnTPoMHCb2OqGcKzKgqd31ey7Fcm 1EAWXywmPKm+w== From: SeongJae Park To: SeongJae Park Cc: Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, acsjakub@amazon.de Subject: Re: [PATCH 0/5] avoid divide-by-zero due to max_nr_accesses overflow Date: Fri, 20 Oct 2023 17:19:01 +0000 Message-Id: <20231020171901.63994-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:19:18 -0700 (PDT) On Thu, 19 Oct 2023 19:49:19 +0000 SeongJae Park wrote: > 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. Actually, the issue was reported by Jakub, and I didn't add 'Reported-by:' tags for him. I sure Andrew could add that on his own, but I want to minimize Andrew's load, so will send v2 of this patchset. Andrew, please let me know if that doesn't help but only increasing your load. Thanks, SJ > > Avoid the divide-by-zero by implementing a function that handles the > corner case (first patch), and replaces the vulnerable direct max > nr_accesses calculations (remaining patches). > > Note that the patches for the replacements are divided for broken > commits, to make backporting on required tres easier. Especially, the > last patch is for a patch that not yet merged into the mainline but in > mm tree. > > SeongJae Park (5): > mm/damon: implement a function for max nr_accesses safe calculation > mm/damon/core: avoid divide-by-zero during monitoring results update > mm/damon/ops-common: avoid divide-by-zero during region hotness > calculation > mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation > mm/damon/core: avoid divide-by-zero from pseudo-moving window length > calculation > > include/linux/damon.h | 7 +++++++ > mm/damon/core.c | 12 +++--------- > mm/damon/lru_sort.c | 4 +--- > mm/damon/ops-common.c | 5 ++--- > 4 files changed, 13 insertions(+), 15 deletions(-) > > > base-commit: e845524c56a529768a8793e96304db09134eafdf > -- > 2.34.1 > >