Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2510218pxj; Mon, 10 May 2021 04:52:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyz+73peJ+3EfEfDTxrKO9B/gdJGBc7OUQfVXmHaGyI3zuaZi7riBeX4fGBIrLCcuG0cE2 X-Received: by 2002:aa7:d146:: with SMTP id r6mr29330547edo.344.1620647537718; Mon, 10 May 2021 04:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620647537; cv=none; d=google.com; s=arc-20160816; b=rKjF1IMWR9nFoy30ksHwhGBIRdB5TmkaCJWHjjNwNpDHdPJL6xHjeZChd+koJJ0bbm 81fL8IwE/g2xyxO7DIPCu3RJldV4thD4kzOGXT0twGkCctDhLkUyEd3wQ6riVUSojx1F QXStYO1bx7vXRn79bdVOsuwRzH4EDR5PqvkEdKFBL89PQbpOUZa8NEtA4VYQSO1Xtaf7 CDx+V3eJjzt6w7Y6CaWqa+BM+R+G+KSYXxbsxPNAPxGdFr+q2gQ8wpkbDRhNW2kuPkWf 3lk2kWXWGaozLcvIFCC8IV3aW1x+b6Krk5MwXQniZZ19AFVkQ/Gb3Ss4dsnP6LhkqfiS OjAg== 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=nFEFCRVUEjJqv95SAxrdIebmDv8m7gcY8DPvzkd3VJxHjc5b3sO8MfT/5ovgxowT6d 0SmG9T6BvFsD7AMuK4V2M4LH5KvlZQpYwATxcAwTdemWmlDzGQ+sGeGudGrbsPnzMG0g OBUpC6ffhmx41rDx87ecmxGPU9XVIec3rAhLDzYCNZFCi88NdZZLXBZyjdsKWi63U5a6 aOfb4fESJanyz/iT4113zsjdF1LGd8RBqXkwea1cZS4rYavB0nnI+WMAPAp+66r7K1Fp W7iRdpNOHIofeY1t/gqkTREyt38mMKHoYUXGUlByiK78YozdwuWn31Ioufo4XUCeTy/5 ErQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QtQPx4JC; 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 hg4si12170001ejc.442.2021.05.10.04.51.46; Mon, 10 May 2021 04:52:17 -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=QtQPx4JC; 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 S242705AbhEJLrj (ORCPT + 99 others); Mon, 10 May 2021 07:47:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:53004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233874AbhEJK7s (ORCPT ); Mon, 10 May 2021 06:59:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1E04361613; Mon, 10 May 2021 10:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643981; bh=kwOyVJpLtd8gheGbQRqdFlIORGINOYnXM+3NvNS/wfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QtQPx4JCbFpwhGpWlxQAGCAoBcvjfi/79Ftr/LKO3zm2d9NErpFTFcey1xyYEiCFf bzq3b6FzO8NY4jZdlUao4+ZaA3Me1jBfghvI797B/sJ2hdl2X6KTPjAArGq62TPmwv dLQH7cjvlTRjaWDa9vLplXIf+ajvg49YhOhIhDz4= 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.11 238/342] sched,psi: Handle potential task count underflow bugs more gracefully Date: Mon, 10 May 2021 12:20:28 +0200 Message-Id: <20210510102017.949638928@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@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