Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp835525pxb; Thu, 15 Apr 2021 07:44:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjl8koxmnCa8lshVx0dYmLvO3J+WRiF/IOqDLFvu/rGow328/UVigIWOmbYAbw7/MOMjHf X-Received: by 2002:a17:90b:715:: with SMTP id s21mr4301814pjz.183.1618497846390; Thu, 15 Apr 2021 07:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618497846; cv=none; d=google.com; s=arc-20160816; b=QpRnC0VBMIPlt6bVlA+IiLJLXB2/nl4P0uAZcTtvvAPEm87/vMncfFpccopvCksxPG z/S49Fl66enDIJR9KzDw49qKEq5TAlY17oQ8GhEUlS1A6TuhvOR9MrLKzqQnQZS3pqS3 6OKWnPMAQOzXVA/iCpYcqy3p2bcr1YlRAbHla9O/C4DjaebYx38LBG9CJqBYgo/LBOQ5 +jLktWYMQnlJX3yzyJGnrCxaJDcM5peJT4QZLOH744ULDdhZsQmN185Wg1C/yS51iajt AonH6J6bYP8tTQ1qMP4W6HeV8tbg3uEIsYa+Zt7R/OPA9hauXK1565y809YEbCVvsd7l fbxw== 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=pUmCri+aAr/3BRvGEMcFWa6v/j3oXvsCBPh6QOca+BM=; b=xsscmoTe1V993BaiKCdy0Nd5UyTH2cEDB4TMkuZeJB6WqWtE56xYTVIIRc4xyIoebr SDoWE2wRF+oZai/nhdzw/HnKHOqo4+n2mNrTRuydrFpvbpjGBK9l3lLY9Ldwdf8e8JdA TXutznOhFyo7pcux8YR2dc6PPs6PFWEt5+j8kaaaQmjhEreN+vvuyfXvnDNMOLac7UV1 9ZGCWznG/2lWzUDgVxe/6AQKcvZQx05c7Gn0F4SrcpyDZwZV606c9g2CVR1jwwTZH73X ShOVuuu2hjXCxPtONbg1QPaZCQdSXdGRRp4Y/+gJr3IwwpPRaVT4obmzm1BotTIlwTg6 LILQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=CAqwJVXX; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q7si3674817plx.31.2021.04.15.07.43.53; Thu, 15 Apr 2021 07:44:06 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=CAqwJVXX; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233454AbhDOOnX (ORCPT + 99 others); Thu, 15 Apr 2021 10:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233201AbhDOOnU (ORCPT ); Thu, 15 Apr 2021 10:43:20 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8C18C061574 for ; Thu, 15 Apr 2021 07:42:56 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d6so37148qtx.13 for ; Thu, 15 Apr 2021 07:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pUmCri+aAr/3BRvGEMcFWa6v/j3oXvsCBPh6QOca+BM=; b=CAqwJVXXXHV9UsITI7oeN41aiJSvPHuVwySb4jFTdw73QJq978n1pLsQsA0ttizUKf 8MwHq91f0miC/140uGBOer19/RyAyu1yqakuO83IajJg6dclM2QcxM7JUFJef+EvCAZK +zIMKHAH2nKocHm6cPOg5Wn3hhw6RYsXBiwDC4k4ZWvaiIOQDu+vxoUKcYx4DYCwxIE8 f9TIYZ/ajYkqmBS1ji0HyPcyCWtnQe670a8/O/tUF1k1tz9MyAF4RzKQynzihNOp6G+k g9StzhiLSLmlsogu4rR5FX1ODUI4Lo1V7DCTVO5xgGdyR//VDf5k79sgD5D2saEd9cts kEEQ== 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=pUmCri+aAr/3BRvGEMcFWa6v/j3oXvsCBPh6QOca+BM=; b=o4D2Cp3Kf7AZlxfCUuZiS8VBEd5Im8NGVGI7sJ20hLDjn2HMlNnfu0cZzQSdtC+uqY CPVP+b3IcdOkisdD4XUmek5k6XOzMNPjXfzFAOB6ZFic9zqX1vW4+xigM5y2s4D2IghH 5gJvvfLi3UAceqyYbsXr37qbGKX8Q3XGjQ8PdHPFohwjV9Fy5vq4BYJsPI52j2kRVkgC 47NEw1X52cJtu8qmJ6TCjbaPw7CxIxk/HM6nE4g+3jiuJIARmuBRyZ69mmUaaHbwoHJd Qyu1sXNJKXdl2iEXxZn3sKIHe+Pm9lC5zM2GsGxqfPCjlr33UbpvaJxFwolq/nj5xOKS g0ow== X-Gm-Message-State: AOAM530b+fEuin88UeeyI3enSjo5fWLqViEvApgxS9A5Po9ZVvcajRbe qKXIvBDf8Bh9VHaMTbWPQuJnTw== X-Received: by 2002:ac8:4899:: with SMTP id i25mr3321147qtq.59.1618497776168; Thu, 15 Apr 2021 07:42:56 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id b1sm1921448qto.36.2021.04.15.07.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 07:42:55 -0700 (PDT) Date: Thu, 15 Apr 2021 10:42:54 -0400 From: Johannes Weiner To: Charan Teja Reddy Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched,psi: fix the 'int' underflow for psi Message-ID: References: <1618496981-6148-1-git-send-email-charante@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1618496981-6148-1-git-send-email-charante@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 07:59:41PM +0530, Charan Teja Reddy wrote: > 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. Makes sense, it's more graceful in the event of a bug. But what motivates this change? Is it something you hit recently with an upstream kernel and we should investigate? > Signed-off-by: Charan Teja Reddy > --- > kernel/sched/psi.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index 967732c..f925468 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -718,7 +718,8 @@ static void psi_group_change(struct psi_group *group, int cpu, > groupc->tasks[3], clear, set); > psi_bug = 1; > } > - groupc->tasks[t]--; > + if (groupc->tasks[t]) > + groupc->tasks[t]--; There is already a branch on the tasks to signal the bug. How about: if (groupc->tasksk[t]) { groupc->tasks[t]--; } else if (!psi_bug) { printk_deferred(... psi_bug = 1; }