Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp878135pxb; Thu, 5 Nov 2020 15:51:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJylD90qXKMr4SsftA4p267stnLwxuag0nMaGFujfVkQ4+gbkJKtpL3ikN8tTrRR5W/TP88E X-Received: by 2002:a17:906:3a59:: with SMTP id a25mr5079097ejf.546.1604620294108; Thu, 05 Nov 2020 15:51:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604620294; cv=none; d=google.com; s=arc-20160816; b=O+3mSt/gW6oZQlU9vDk1zu4Nq2yObrBFurhewVmxkMBKUWxw9u6ZfJpsJ9WCWC72D9 5upzfl8ugfZcCQNaDZ/BFY1O88Sqd8PiDgrH0yQFyLPytHtDBRZczj44L8e5BMeF6g7N vnU6ow4z2ZmsXqYfcWoM3ZA+CGAqMOb4LfDkoKQcP40Dhr0E5CqcJfZTUivqq0cXLz3r brAr9Tci+fGPNtOpQBBQUwvwmNYyad03Z0orr4Zo23bx9g3ruJL/T5Rx2lrw4+GXm7cu Y30Yc8VDhfKSr0d4+jRofakdOyFlJaKLopqxzvCJgs7MMnJLzIrLNeHnsToeGcawXzbI iSRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=xQHc+f1qTFUVKtzrdbVxZ2mKoB9rXpSdpw04RnS3x4k=; b=k8EtawNf5FK75xSBoHgt2MYDVaTRePDifSdyyN3iz6MwpeT9w8Og+kPi8S2Jvqmzcn Q/48EbYerwpcfzD45BE9/hgRz1LroVysaxfeQpaNC85Lnix+ugdcaI1/Q7oM53nqXq4J k0YwtSvItlb+1WQaSti9eoM2lcsaS/T/wUEWRfvhvhDr/Mds2MO7eGauMJK49T5K5GX8 wldjgcWIvrLoshZpZyHU5wNmgVvaIzLuyUSYLLohzfMUjf1JxLyAOQ0muHQ6CpGXn02N lRBK4VLlcSXZxT9Qalqi9n7Oqxa1KiHOr3o++2ZHCfqNqEu260O/WHB5ZL+CUeYMRyrS FYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cYXFNrNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si2256195eju.273.2020.11.05.15.51.11; Thu, 05 Nov 2020 15:51:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cYXFNrNc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732415AbgKEXrX (ORCPT + 99 others); Thu, 5 Nov 2020 18:47:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:45860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbgKEXrW (ORCPT ); Thu, 5 Nov 2020 18:47:22 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE70320756; Thu, 5 Nov 2020 23:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604620042; bh=cHPyby7pAr8kcs5Rx52a5F9TaNyVrHGa7UCBfNWtirg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cYXFNrNcfDfo0+WAVqIfjD2ElsanHYyXMO8Di9RG1Pu6ikaevmTENFbIoofIjCFm/ Km0M9xxe6mxT1t42ghoS4Ru/9eRra3//eFZtS/xnerNCU1E8rYG1wy6OOAXXhcuyUr 6N9VuA2ojGuugqnXKcFcVslBUQWmhve0pc771Fb0= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, "Paul E. McKenney" Subject: [PATCH tip/core/rcu 01/28] refscale: Bounds-check module parameters Date: Thu, 5 Nov 2020 15:46:52 -0800 Message-Id: <20201105234719.23307-1-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201105234658.GA23142@paulmck-ThinkPad-P72> References: <20201105234658.GA23142@paulmck-ThinkPad-P72> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Paul E. McKenney" The default value for refscale.nreaders is -1, which results in the code setting the value to three-quarters of the number of CPUs. On single-CPU systems, this results in three-quarters of the value one, which the C language's integer arithmetic rounds to zero. This in turn results in a divide-by-zero error. This commit therefore adds bounds checking to the refscale module parameters, so that if they are less than one, they are set to the value one. Reported-by: kernel test robot Tested-by "Chen, Rong A" Signed-off-by: Paul E. McKenney --- kernel/rcu/refscale.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index 952595c..fb5f20d 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -681,6 +681,12 @@ ref_scale_init(void) // Reader tasks (default to ~75% of online CPUs). if (nreaders < 0) nreaders = (num_online_cpus() >> 1) + (num_online_cpus() >> 2); + if (WARN_ONCE(loops <= 0, "%s: loops = %ld, adjusted to 1\n", __func__, loops)) + loops = 1; + if (WARN_ONCE(nreaders <= 0, "%s: nreaders = %d, adjusted to 1\n", __func__, nreaders)) + nreaders = 1; + if (WARN_ONCE(nruns <= 0, "%s: nruns = %d, adjusted to 1\n", __func__, nruns)) + nruns = 1; reader_tasks = kcalloc(nreaders, sizeof(reader_tasks[0]), GFP_KERNEL); if (!reader_tasks) { -- 2.9.5