Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2487857pxj; Mon, 10 May 2021 04:18:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+G+eIMSkdn1iKMJVay7sJiNgQqPTgzAhZvtHqR7IaG2a3N3ckjB6hZ7OX4FJEwja4h4tB X-Received: by 2002:a02:ccbc:: with SMTP id t28mr20992754jap.21.1620645484096; Mon, 10 May 2021 04:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645484; cv=none; d=google.com; s=arc-20160816; b=zG6xmSA0KHmP3VYS2ZBkLYwD0GmaXqCkwhwEDrcBQoJIzgZPyuD0zt5FryLOcKqQMj seSnacffuvp7Mpofqjy+z2HDUzjEQBp1ZapgbAjN66tcFxYv+u7RvXuOEyh6uFj3JJIu RkOwfag44kT8SNSJ80m441YbJFrVi4V80AJcZr6R5qB7BXkQxecctKpr5I8EtknVHiCl oQy7o8wZpulmaH3JwJEvcOjgacCq93eK+rf4xxYcDgUD11crVhi73WtoOAajksYMHRH1 znk+yDHT+bmcsDyEFUUI/FfsLr4mcC3j+jO797SDg/812BRnrboKuVyWS0sT6CagyYYc unnQ== 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=0vHEZmWrz9wDEKKGK8P8ozbMQhtCpmT+WLYTdxOB7mE=; b=vR0AlyUSKjoDgWH56wvpKttC9lfRTXF5Y0+C3J5eOVFfhCBwy5tdLC6RLbxXMTklCw Fj824fuqALBYZNQ7beY4wrN9Gh/NHJnyu5+lLj4TxW7kw7RX+qH8iesvqk7KF2gRfaHP ABwSM+pG4+jRqd9et8iP4ukZ5bTzW8louci7xyBK7HrrTv2xB/bJh9u3PuDSwiKiHvm9 ROCPq1uN96PB8LK7ZtnSTNf2lT6IJ/87c5f96ycxUSKVyjwBCN1yRF9HOQcPIR0RavIj +BU6Pgt8aoFkwD8/Cmk7LhdqtC114iRBHkk59TnbpNWcl372ZdNotrA8/RfXIEQCiGCe 83og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gyi4m4Qr; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si16982930ild.152.2021.05.10.04.17.51; Mon, 10 May 2021 04:18:04 -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=@linuxfoundation.org header.s=korg header.b=Gyi4m4Qr; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236935AbhEJLLA (ORCPT + 99 others); Mon, 10 May 2021 07:11:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:41824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233546AbhEJKuN (ORCPT ); Mon, 10 May 2021 06:50:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC67F61948; Mon, 10 May 2021 10:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643170; bh=kwOyVJpLtd8gheGbQRqdFlIORGINOYnXM+3NvNS/wfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gyi4m4Qrbd6WyosYs2jMk9nkIOQawpfipyz1LhHjBdJht3Khm0iC2OUvsiW1y3kSe EXvz3Po9BeE8h2PL85WDQME9e0bSp/YlmrxlbLhQbBkM5pT//b6QGOHurLfdDf+oMg 6u0mLrqQssqZvhhPZRMgk8YGLB6+uAT5KpsjFhEw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Charan Teja Reddy , "Peter Zijlstra (Intel)" , Johannes Weiner , Sasha Levin Subject: [PATCH 5.10 207/299] sched,psi: Handle potential task count underflow bugs more gracefully Date: Mon, 10 May 2021 12:20:04 +0200 Message-Id: <20210510102011.779777963@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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: Charan Teja Reddy [ Upstream commit 9d10a13d1e4c349b76f1c675a874a7f981d6d3b4 ] psi_group_cpu->tasks, represented by the unsigned int, stores the number of tasks that could be stalled on a psi resource(io/mem/cpu). Decrementing these counters at zero leads to wrapping which further leads to the psi_group_cpu->state_mask is being set with the respective pressure state. This could result into the unnecessary time sampling for the pressure state thus cause the spurious psi events. This can further lead to wrong actions being taken at the user land based on these psi events. Though psi_bug is set under these conditions but that just for debug purpose. Fix it by decrementing the ->tasks count only when it is non-zero. Signed-off-by: Charan Teja Reddy Signed-off-by: Peter Zijlstra (Intel) Acked-by: Johannes Weiner Link: https://lkml.kernel.org/r/1618585336-37219-1-git-send-email-charante@codeaurora.org Signed-off-by: Sasha Levin --- kernel/sched/psi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 967732c0766c..651218ded981 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -711,14 +711,15 @@ static void psi_group_change(struct psi_group *group, int cpu, for (t = 0, m = clear; m; m &= ~(1 << t), t++) { if (!(m & (1 << t))) continue; - if (groupc->tasks[t] == 0 && !psi_bug) { + if (groupc->tasks[t]) { + groupc->tasks[t]--; + } else if (!psi_bug) { printk_deferred(KERN_ERR "psi: task underflow! cpu=%d t=%d tasks=[%u %u %u %u] clear=%x set=%x\n", cpu, t, groupc->tasks[0], groupc->tasks[1], groupc->tasks[2], groupc->tasks[3], clear, set); psi_bug = 1; } - groupc->tasks[t]--; } for (t = 0; set; set &= ~(1 << t), t++) -- 2.30.2