Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp256019pxx; Wed, 28 Oct 2020 04:14:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF2uyGRpAHM4/IHV63IgXrbFOxOaAlOoD9Ush7ce4FTqcESbbRpGtgsGsUN/fF6/5HieEp X-Received: by 2002:a17:906:1418:: with SMTP id p24mr6924377ejc.46.1603883676915; Wed, 28 Oct 2020 04:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603883676; cv=none; d=google.com; s=arc-20160816; b=i4tiIvdcpTScNGNvgjSpP4bmdYBwfFroml54+8Y84rWMze9vVRzHBrnQqvEdFviZg9 OEo2uHVmt0IH3DgJCjVMKCO1YfV9F2h4n8ZVwEiaOUZg9wG3iHmTYI+nkqof528wSNRt lNQZv2CtxYwlIcbndR7LEvlAEm+apI8x2LuACNYHlHfGKFUNFGLfkeHBF67roeT+/7yn Xa8gatmhqsR2bykIvcFas2mGw2bcMiZ1wJ8Pnz5HuUfeAy7CKWXYOirrLJ+mlGjyLctP O4iVpHBt86JTzOwyJPjkwrcvikuse7wY0moRSp74+T+jUYHs0x68Q8wEVrvh/ro4Yv0F iojQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YtFx6LTKCTeIz3/OOq0oe+hfFMHAiO9PsplO1ATHFMo=; b=F7BmWnYlLwabvAzLKLdGJFkJjr/CQM7UVBM4HQcnQLI52MkgV7na/wHrw6TGMCcsub C8+1IE4zXr46DEkytTs0WUrnK5ugJYeBGX8HblCEykalOfO215s/ElQYsYz8B7Rw8J5d Veza6Uzmztse7iW1FZjzHc9xQq/wQC8P4UPRX1ULl7jrXRZyO8FyDqeg33GwqNjOHznO qerMtWAwW69jIpuN51U4RaZ4/FRVBbmwRLeLxfaKID2RiGT7qZcPyMS8sjeZqqSIvojp cajs+xMYInGNADQ3rOlzutstZk2zityi3zB2pWmozEVPfGCe9DYBF1lkOPK4sRRwFpnb geYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S+suT2qu; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si3402013edu.343.2020.10.28.04.14.14; Wed, 28 Oct 2020 04:14:36 -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=@kernel.org header.s=default header.b=S+suT2qu; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1787375AbgJ0PAH (ORCPT + 99 others); Tue, 27 Oct 2020 11:00:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:52604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1740625AbgJ0Owk (ORCPT ); Tue, 27 Oct 2020 10:52:40 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D62BD20773; Tue, 27 Oct 2020 14:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810358; bh=83pEo1S7D1IwnxpOqE7t6gjf+YFk9V8DIqqxSYYN6Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S+suT2qufEQmfHKSrdrkKpkoxdNVfKj+pVYhjk1MXmv2HvscLv9GC4nRjmRyfWDEP aXwwVfz0Z7FLhGBzn0jATyAoLMaVKi2lraILJwryNoj3qS+W3/JMlLr5O2KTQAboEI m+t/9xKH+MKER8hl3GZUJocLUaUG9EpWbrh59JZ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukasz Luba , "Peter Zijlstra (Intel)" , Valentin Schneider , Sasha Levin Subject: [PATCH 5.8 080/633] sched/fair: Fix wrong negative conversion in find_energy_efficient_cpu() Date: Tue, 27 Oct 2020 14:47:03 +0100 Message-Id: <20201027135526.447517817@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukasz Luba [ Upstream commit da0777d35f47892f359c3f73ea155870bb595700 ] In find_energy_efficient_cpu() 'cpu_cap' could be less that 'util'. It might be because of RT, DL (so higher sched class than CFS), irq or thermal pressure signal, which reduce the capacity value. In such situation the result of 'cpu_cap - util' might be negative but stored in the unsigned long. Then it might be compared with other unsigned long when uclamp_rq_util_with() reduced the 'util' such that is passes the fits_capacity() check. Prevent this situation and make the arithmetic more safe. Fixes: 1d42509e475cd ("sched/fair: Make EAS wakeup placement consider uclamp restrictions") Signed-off-by: Lukasz Luba Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Link: https://lkml.kernel.org/r/20200810083004.26420-1-lukasz.luba@arm.com Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6b3b59cc51d6c..f71e8b0e0346a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6586,7 +6586,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) util = cpu_util_next(cpu, p, cpu); cpu_cap = capacity_of(cpu); - spare_cap = cpu_cap - util; + spare_cap = cpu_cap; + lsub_positive(&spare_cap, util); /* * Skip CPUs that cannot satisfy the capacity request. -- 2.25.1