From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36B2FC4363A for ; Tue, 27 Oct 2020 17:11:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF92821D42 for ; Tue, 27 Oct 2020 17:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603818690; bh=8xO6donlWuaYx3A3j8ilplaJ2DqNwh8NLzOUZ7XGuyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zOyfEocnwcq8n2Lv9bU4ESKztpsUq0MM9dVAQ81LfINNM7+XjamXiXtnc1z8AgtJT vj3nsnUCzt9efNB0eg5wiI3f/unlH+ODIdFgq2Ktg/3aBUC/fWptMs70Ufjiegk3Uo dAADbo4OCDGU/+DqQW4vEfl7WO9PIbm/oWZ5mRrs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1786344AbgJ0O7v (ORCPT ); Tue, 27 Oct 2020 10:59:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:51264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1773334AbgJ0Ov5 (ORCPT ); Tue, 27 Oct 2020 10:51:57 -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 AA4DF20773; Tue, 27 Oct 2020 14:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810316; bh=8xO6donlWuaYx3A3j8ilplaJ2DqNwh8NLzOUZ7XGuyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BuWwPrSe9fS0fOlUeCjJTK6RTq3j7z/xQIp+RdAtHUv3kO5QGqkE+6nDBWROxKD6r I3WOlaJulwsA7gIaLjYUfD/ePoM+E6rPL6pwc7SYlqoj1R1L1QuVbsAlHtb6eurcR6 OyWxitUVwdjxi7GB/7gQlktD6RqIBss7bL6kHxb4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Libing Zhou , Borislav Petkov , Changbin Du , Sasha Levin Subject: [PATCH 5.8 096/633] x86/nmi: Fix nmi_handle() duration miscalculation Date: Tue, 27 Oct 2020 14:47:19 +0100 Message-Id: <20201027135527.204805198@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: Libing Zhou [ Upstream commit f94c91f7ba3ba7de2bc8aa31be28e1abb22f849e ] When nmi_check_duration() is checking the time an NMI handler took to execute, the whole_msecs value used should be read from the @duration argument, not from the ->max_duration, the latter being used to store the current maximal duration. [ bp: Rewrite commit message. ] Fixes: 248ed51048c4 ("x86/nmi: Remove irq_work from the long duration NMI handler") Suggested-by: Peter Zijlstra (Intel) Signed-off-by: Libing Zhou Signed-off-by: Borislav Petkov Cc: Changbin Du Link: https://lkml.kernel.org/r/20200820025641.44075-1-libing.zhou@nokia-sbell.com Signed-off-by: Sasha Levin --- arch/x86/kernel/nmi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index d7c5e44b26f73..091752c3a19e2 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c @@ -102,7 +102,6 @@ fs_initcall(nmi_warning_debugfs); static void nmi_check_duration(struct nmiaction *action, u64 duration) { - u64 whole_msecs = READ_ONCE(action->max_duration); int remainder_ns, decimal_msecs; if (duration < nmi_longest_ns || duration < action->max_duration) @@ -110,12 +109,12 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration) action->max_duration = duration; - remainder_ns = do_div(whole_msecs, (1000 * 1000)); + remainder_ns = do_div(duration, (1000 * 1000)); decimal_msecs = remainder_ns / 1000; printk_ratelimited(KERN_INFO "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n", - action->handler, whole_msecs, decimal_msecs); + action->handler, duration, decimal_msecs); } static int nmi_handle(unsigned int type, struct pt_regs *regs) -- 2.25.1