Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp267382pxy; Fri, 30 Apr 2021 05:08:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwINxghYd92lzJfP2M1moPLgZHvHWifSYc+XDvFL3qkk+/uek+5nwn2miGLxtZ9YGIjVd1T X-Received: by 2002:a05:6402:1547:: with SMTP id p7mr5555487edx.319.1619784535543; Fri, 30 Apr 2021 05:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619784535; cv=none; d=google.com; s=arc-20160816; b=N7t7ChMcodzKmnH2gdxjh3LETOF5gFomQNF7ZcuhKMAA1fyRsui7Ra8wWOlD/Z63xs 8ea03O8P2gL/ZLRqYOWCw7B2PDvrkltnT8nPXOIhQMX5p7pktteavemj3Y+NmiKRcVOa JBvpSG6DR6vbS7ZYbLU+vhSHWKCPHC1KFVG4zONffV3uZJnSmVTogSL98vHCUxkfqpJ6 H6hytra1LvZve6duyUruPtW+jyfa75MXoqYZu/PXZq/FBlX6xZXx7UGkvt6MBSWtONu0 XJxczjQx9pICjhBO4R5WBnMa+8gyaU/hW+VTZga14bUzr01GqxMrFL2riVRHIFLe26UM ZuaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NcOJzmy6gAjS3Och51hWtGgtigCtRIoMvFe4KlmC6I0=; b=FM6lHHWf8TyRBIb5KAH80q7Yor0tUNyZSwLrQJxjdIyY3zA6TQkqOXjh/aMmFIRozw gSN4mUOZGhFtZoXDIMZn0a/ym9zcaEPjEf/6yFrziRSJB2g0+4kThd0zEjZBm0YmhuwV pKcDdCE9zm1+c5ly7TOLDSCMDFW3eh/Tdov8aLT09b71GdAuUvvCOt7sMVO8N4SdRxC8 u0WcxACmXhEo8mIFpNdCy1OvZ8w9fpLKUi6FTotXQ18TXKVZJ5zsdgJ6UVzL/OGji5/R 4y4XZaGXZ4QGClogxS75e5IneAf+bKdP8rMFc2pMfWoU0HoqI4L/xz+ZhiAljO0R4CVL hOYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hpsGpSCO; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si1617094edv.294.2021.04.30.05.08.08; Fri, 30 Apr 2021 05:08:55 -0700 (PDT) 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=@linaro.org header.s=google header.b=hpsGpSCO; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231894AbhD3ME5 (ORCPT + 99 others); Fri, 30 Apr 2021 08:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbhD3ME4 (ORCPT ); Fri, 30 Apr 2021 08:04:56 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9009CC06174A for ; Fri, 30 Apr 2021 05:04:08 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id a13so26635845ljp.2 for ; Fri, 30 Apr 2021 05:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NcOJzmy6gAjS3Och51hWtGgtigCtRIoMvFe4KlmC6I0=; b=hpsGpSCOe81NOr363oM1c77yVHUGeH+sL66lOefAHBh+8xwARpwG0BvFrmapBq0m5b sqMlTQcpvhE88vAhYcwA6Czi78HK9ubTfXmF55tBCmYYvSUIv5fCxLqSFdoNERhjFJHj 8PZuFg4gJ9I/hqbvZysrkbrIitqEQ6oHUJc4ZHwOuLSdx0qry6b/kHTc6GR1g0Lod+54 /XYADXxSPBnnMQeDkGzWVRaAxdh6CNOZPmblxGiP2YtBP1wGMXK/274W3C0Ij/e1c7Mx qM4wbcPYCXfu+VsJIKxOQcfQyxxUyUNr5L38W83QdTaneAxToovIAHqw90O4IpijlCE6 MaEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NcOJzmy6gAjS3Och51hWtGgtigCtRIoMvFe4KlmC6I0=; b=NfriHhxcallHcuyXinGHyENlZmfZxbFLVQKsfFaqlKlIwJYiMyiAgBW6xWUmTe1FFn f6JbL4FKRgY+exmBC2hGZJ95aZyB2Ku/4xve6ki4P1uNgb6oZiZvHL/4pO5PGXevi2kd oG1O8wLZyrYgvLQxRQLS8h+mD6RqxVDJ0WvTds60Qbi87YcsMpzCFYIy9BAlBFUxkbui 0n5fOizrsY37LeseXRRapQt1eWmlUZ37d0VKnWe/L/6DeRnvFL3Q2mikFy0EPEPogHse RWAkbDVMRFz7oKZ7SfUXvKLkyzD4Q0Kr9kc2kWkKbT7HGZsQ1ILEWyGQtMkaHSHJjNAC ihlQ== X-Gm-Message-State: AOAM532QR+KDDlj6ofWPWI44cYfiLYFvp7VaypXGqWcw/fHl9b8eYuvA 6HlUiik2bVLa4XmWpNb6eXs4RnuS2C1z+q7B/LS38g== X-Received: by 2002:a2e:9f47:: with SMTP id v7mr3427568ljk.176.1619784245696; Fri, 30 Apr 2021 05:04:05 -0700 (PDT) MIME-Version: 1.0 References: <20210429152656.4118460-1-qperret@google.com> In-Reply-To: From: Vincent Guittot Date: Fri, 30 Apr 2021 14:03:54 +0200 Message-ID: Subject: Re: [PATCH v2] sched: Fix out-of-bound access in uclamp To: Quentin Perret Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Qais Yousef , Android Kernel Team , linux-kernel , Patrick Bellasi Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Apr 2021 at 11:40, Quentin Perret wrote: > > On Friday 30 Apr 2021 at 10:49:50 (+0200), Vincent Guittot wrote: > > 20 buckets is probably not the best example because of the rounding of > > the division. With 16 buckets, each bucket should be exactly 64 steps > > large except the last one which will have 65 steps because of the > > value 1024. With your change, buckets will be 65 large and the last > > one will be only 49 large > > OK, so what do you think of this? Looks good to me > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index c5fb230dc604..dceeb5821797 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -920,14 +920,14 @@ static struct uclamp_se uclamp_default[UCLAMP_CNT]; > */ > DEFINE_STATIC_KEY_FALSE(sched_uclamp_used); > > -#define UCLAMP_BUCKET_DELTA (SCHED_CAPACITY_SCALE / UCLAMP_BUCKETS + 1) > +#define UCLAMP_BUCKET_DELTA DIV_ROUND_CLOSEST(SCHED_CAPACITY_SCALE, UCLAMP_BUCKETS) > > #define for_each_clamp_id(clamp_id) \ > for ((clamp_id) = 0; (clamp_id) < UCLAMP_CNT; (clamp_id)++) > > static inline unsigned int uclamp_bucket_id(unsigned int clamp_value) > { > - return clamp_value / UCLAMP_BUCKET_DELTA; > + return min(clamp_value / UCLAMP_BUCKET_DELTA, UCLAMP_BUCKETS - 1); > } > > static inline unsigned int uclamp_none(enum uclamp_id clamp_id)