Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp116447pxy; Fri, 30 Apr 2021 01:27:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBks/TXtWW4iEZNrYIHawpFMs63utMnxD1QUFrHKyxqv3D5NhY33365qoPv/Sp5Vd7t9oW X-Received: by 2002:aa7:c34b:: with SMTP id j11mr4483207edr.188.1619771248631; Fri, 30 Apr 2021 01:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619771248; cv=none; d=google.com; s=arc-20160816; b=wD7a7edYCS0ESwpLDW+F+CGYp2QogYZRFUiudTlzOMzeFvKJfNXlHZImY4RQ7Jekfr /ob3tTsfmEWkXdZtI/pCdwkgmJBYJIzaAmuiFugo4b5k0b6z8XpmGHtC+/Xsxl44IOl4 IGg9bRAERYlLt0R3fqVMuG+9jPvn0jhqUB+Q2yfp0AXuy+1fdM7GebHX9PmiX/G3clOa AxYOYhnzdjHBSjSp0yyzKd5QQPSfcXWSZ9UVQqDsJ/Ctfz5P7Y6lsnme39aT10XSVsGs yguMy63sjaKHjsC4xU7Fkz2+55jqEOTL6KgEDJtz7S4+73DoEfwZYtDLuSzKa55NrcHb wD1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fwsAIi/If273EsXT5ZuVqdKChgrly5h2K/eYVUgxNUw=; b=toUKlV3H2eSVXKrhRfTNY3SSSx0zzL5NpsCw77mj932srjZ57HCIkmIKvfJVx4unEB lNw6XRHYDF5ocCz/ZeAMcMWHlrGGxsT6lV5sk4RIQLsPJLV48mRjO4PUmm7nGEVjkTOM 2lkldWLCVLY/hWB9JhnX2uHz1WYheGGvjtXXPPytQye2i2q9j4/5RHlVSp+T7LXkU60t ng/kiKnvdCxb3eLMbjLrHyzdIBBGoaJUuJOjSKOIMCu504E3ejmTTo9V1on95egIRi8D WCF4QhEaE7ZY4S6lgAr3DbfzarDC7oDbTlEjLa/kQgY4gXQyud4W8eIP5vmWU9e+S5jC wBRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=E2c0n7s7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ze15si2507499ejb.113.2021.04.30.01.27.04; Fri, 30 Apr 2021 01:27:28 -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=@google.com header.s=20161025 header.b=E2c0n7s7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229662AbhD3I0s (ORCPT + 99 others); Fri, 30 Apr 2021 04:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbhD3I0s (ORCPT ); Fri, 30 Apr 2021 04:26:48 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8239C06174A for ; Fri, 30 Apr 2021 01:25:58 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id d4so1147457wru.7 for ; Fri, 30 Apr 2021 01:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fwsAIi/If273EsXT5ZuVqdKChgrly5h2K/eYVUgxNUw=; b=E2c0n7s7oitH0D8Ah/Z9gdAqOZT5sTY5j8ZANpTVQMovagfz1IGTS6a+Mk2yAQONft EiJci43FSglqefb1deZgQ77Fup1OScgoqfsQWP1SzQ2ajakMcDM9vpcnsbQFfCHuFHDQ 1cjDADw6ogFz+xMq/Iary7PBGYKkXU4UBqIuHkVl3WNSpq0nUNHadSrWM9KfgjiD9E/m yBem9MlYIpjAds7zBRTO/beGkl2mXb0CE2HlZw+CkqoYzCs4v4Tos0s76rruvn87DppA eeHM+CVIz27/dR8t3jXsVXtxoGYHTPr7JscncKom3npeTBYs4BgqfvaQVmKwrqy88pRR xfpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fwsAIi/If273EsXT5ZuVqdKChgrly5h2K/eYVUgxNUw=; b=eaT1EFyYPPZnnHQJAiUaXJ2ZktnLYdz7HtsiiVoPjYFNMpRqZh0ZID2XUeSngeavwD /hv/gQjVigGx0/1PSfhMYytFSsxTQM0br2BRzIDVUj4T+c0olbFIEy0ZUcX/GH+cGoYi ThaK65nYd+XfLqVJKXol7e1DT/snsK2Cn55Si/i4OTZSwN0F1uRQgUapab6pPXkg1xqD Dr6yeByoZSwWdIEBDZXFt9mKllftjdtyC4JEnBxh2JbXRmsZNqeQSGJ6mAgYbjNqOdKb YRS7tKYP+mCEGQD35HTgde4Y28WAHnhnlpswrd2jQB5TbPe3zvcuDARa17Lxoj+fHrEc hQvg== X-Gm-Message-State: AOAM531S07rckDgV2ZbCZsqYcE2mEI9NijZlP+ws9a+x3d20R2EYxu7i aS7CirRjkE3G/l6pSYNb512i4Q== X-Received: by 2002:a5d:64e6:: with SMTP id g6mr5224175wri.216.1619771157376; Fri, 30 Apr 2021 01:25:57 -0700 (PDT) Received: from google.com (105.168.195.35.bc.googleusercontent.com. [35.195.168.105]) by smtp.gmail.com with ESMTPSA id z2sm1491345wrg.6.2021.04.30.01.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 01:25:56 -0700 (PDT) Date: Fri, 30 Apr 2021 08:25:54 +0000 From: Quentin Perret To: Vincent Guittot 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 Subject: Re: [PATCH v2] sched: Fix out-of-bound access in uclamp Message-ID: References: <20210429152656.4118460-1-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday 30 Apr 2021 at 09:45:32 (+0200), Vincent Guittot wrote: > On Thu, 29 Apr 2021 at 17:27, Quentin Perret wrote: > > > > Util-clamp places tasks in different buckets based on their clamp values > > for performance reasons. However, the size of buckets is currently > > computed using a rounding division, which can lead to an off-by-one > > error in some configurations. > > > > For instance, with 20 buckets, the bucket size will be 1024/20=51. A > > task with a clamp of 1024 will be mapped to bucket id 1024/51=20. Sadly, > > correct indexes are in range [0,19], hence leading to an out of bound > > memory access. > > > > Fix the math to compute the bucket size. > > > > Fixes: 69842cba9ace ("sched/uclamp: Add CPU's clamp buckets refcounting") > > Suggested-by: Qais Yousef > > Signed-off-by: Quentin Perret > > > > --- > > > > Changes in v2: > > - replaced the DIV_ROUND_UP(a,b) with a/b+1 (Dietmar) > > Doesn't this create unfairness between buckets ? > > If we take your example above of 20 buckets, delta is now 52. Then we > expect the last bucket to get the range [972-1024] but values lower > than 988 will go in the idx 18. Well, that's just the limitation of integer arithmetics isn't it? > And the more bucket you will have, the > worse it will be Sure, but 20 is a hard limit, and if we ever need more than that then maybe we should think about getting rid of the buckets altogether. > Your problem comes from the fact that we use 1025 values instead of > 1024. I don't understand what you mean here. Right now we'll assign bucket id 20 for any clamp in the range [1020-1024], so I don't think we can special case 1024. > Wouldn't it be easier to have a special condition for > SCHED_CAPACITY_SCALE value As per the above, I don't see how that'll work. Thanks, Quentin