Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2470357imj; Mon, 18 Feb 2019 06:35:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ77P6fXKj/wNu5Hh4rmM3wzQHMS2ak65E7LTv67W+34z7NLfg1Bxwwag0qqYyTZcF7L3VV X-Received: by 2002:a63:f5f:: with SMTP id 31mr18723761pgp.186.1550500512004; Mon, 18 Feb 2019 06:35:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550500511; cv=none; d=google.com; s=arc-20160816; b=xaLmRkKSaaXKObXcI1V/qpz4Y9F3vahbJ+91qlK/2n/tnfE8/270bL4bbxrAbn2ykW EoNQ+I/f5qqYTaR5x6Tr0fo7vsr6guxLN3388Qurmh2oTGDHC1ySJLmPH6UILTSnipwG LcDgbxuKHsNgGOd2d24FKVT1FzmEnc7Tt/RUlFamAGX3Oi0RXjg/PqGQzelClqP7iVhJ nZeZRsuIohiQc3u0ArbhRj8j5qm1TYtFIAvWlC4UE6gyWjHX2ec1OFaWBHIooIiBCZ8F NK8ZnzpsOCk2oH8FQGiWv9yt87dzvn37bpjPKgMnjOpBeykJCCo9bcRDLxuvGWZbSqoy vzOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+PR3yQ0WrMZWW0SVgOKB1w5r8Cne80PZeuJA+qeUms4=; b=wichIE0wv0jWtqUa6jZqmXCq1xWNRn55KDB995nsGSPaVud4oKqERVQDr8LwBQlbCQ WCGbvqPIN+ckcAeO7kW8WLMEGXsZBdkxLI7cOSH74kPkWL8X7sngUrKFO6HCW7RzQoSs pKUKKrpoBizvHbv1pLtirDpxGF7MZgEBvwlqXW1uFkMfWoD5asEmUkDpyK9MuKDzBM5t Zx3ep3zF70RQy//8u/tngcbowNYCTuVj4f5hEw+7zxRupUm4TdfjucHq673KN6Wrx765 PExEui5QyO3LcObbmkcX82W4Is3BIWeevrBnWEU5Kjm/Xj6w9E77DeseMTjebuqUepmT NZ7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BVxzTQkK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i35si11779950plg.396.2019.02.18.06.34.56; Mon, 18 Feb 2019 06:35:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BVxzTQkK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387945AbfBRN47 (ORCPT + 99 others); Mon, 18 Feb 2019 08:56:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:37258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732840AbfBRN4y (ORCPT ); Mon, 18 Feb 2019 08:56:54 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 CDC7D2077B; Mon, 18 Feb 2019 13:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498214; bh=w7PE5pTB+23ZTx0dFRdbQK+KJ0+18+FL3r/7zqju1w8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BVxzTQkK8O7vw5BlJWBsDFmbKOtpdnLEPvdjCp3ziFDpy+vwt/GPEKdgaeaL2VxBH ZYGBr3SEz6whqnL2pqljPWnGpeOQg9fOAqym/z/ATQI2uDLzF3VZTUp69tAYxZgOyb ljonkzDx4LfAKpuw+/FF007jNzfTCTD0/+FGqLlU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavankumar Kondeti , "Steven Rostedt (VMware)" , Sudip Mukherjee Subject: [PATCH 4.14 60/62] sched, trace: Fix prev_state output in sched_switch tracepoint Date: Mon, 18 Feb 2019 14:44:06 +0100 Message-Id: <20190218133510.921592262@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pavankumar Kondeti commit 3054426dc68e5d63aa6a6e9b91ac4ec78e3f3805 upstream. commit 3f5fe9fef5b2 ("sched/debug: Fix task state recording/printout") tried to fix the problem introduced by a previous commit efb40f588b43 ("sched/tracing: Fix trace_sched_switch task-state printing"). However the prev_state output in sched_switch is still broken. task_state_index() uses fls() which considers the LSB as 1. Left shifting 1 by this value gives an incorrect mapping to the task state. Fix this by decrementing the value returned by __get_task_state() before shifting. Link: http://lkml.kernel.org/r/1540882473-1103-1-git-send-email-pkondeti@codeaurora.org Cc: stable@vger.kernel.org Fixes: 3f5fe9fef5b2 ("sched/debug: Fix task state recording/printout") Signed-off-by: Pavankumar Kondeti Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- include/trace/events/sched.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -107,6 +107,8 @@ DEFINE_EVENT(sched_wakeup_template, sche #ifdef CREATE_TRACE_POINTS static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p) { + unsigned int state; + #ifdef CONFIG_SCHED_DEBUG BUG_ON(p != current); #endif /* CONFIG_SCHED_DEBUG */ @@ -118,7 +120,15 @@ static inline long __trace_sched_switch_ if (preempt) return TASK_REPORT_MAX; - return 1 << __get_task_state(p); + /* + * task_state_index() uses fls() and returns a value from 0-8 range. + * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using + * it for left shift operation to get the correct task->state + * mapping. + */ + state = __get_task_state(p); + + return state ? (1 << (state - 1)) : state; } #endif /* CREATE_TRACE_POINTS */