Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3023253pxj; Mon, 17 May 2021 15:50:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvOvYKVE/PV64A2DzhHGIpULG0JwCeTyZd4kQya9t0LxZ7J8Y7asojLfPjkoTr0uyMvQi9 X-Received: by 2002:a05:6602:3146:: with SMTP id m6mr1918033ioy.158.1621291810559; Mon, 17 May 2021 15:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621291810; cv=none; d=google.com; s=arc-20160816; b=HWr7wYWdO9ic3/k5+HbSiP989K+Y2jViR3Ac7mnpoihZOlrPDTBkLB8uYCR17vBv+j /ZRZHiaF50hiUHirYxMuZemGzKtpOvvu6R7OT1e4dW9bbhctTkRbFYf1GoFuH6XmC0T8 VMqdy1Eiv1rlaA+gM0COcrs6YCGCIOxh72JcYk0cQUruP4j3YwvwL4eXSKA/oWwnNdje HwWyoeymn6RCwAj+7EaVhg5KK6xSRQ2eD28QXT6+AWDoYe0PhLPf9LK01EL5NaDprQAz ik9xPNZ9mZPshrSRtasoWKWAOyn2VVS4dq8/cWFTUt4ccoekpjYxUE3T1tStBIRs4GmU soIw== 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=V7D6FZkgFq0Wic2ZLQCM51pH2ZMWtE7Q8XyoKKTPJ+k=; b=Um4JtA8LX09PlS3hbIBc886O0RhPsNJdiI+kmXbm/czPVwMrja/2SUeH6baqmX/vVp ZLfB6fyOYz67RxspzwXWgjmOP0xtCl9Y6Tw71xu+pBkkV9gw/61r12OMojg3V1d3YK+4 X0FezLSd21xjLc5f9sFDe3fNtT+sD1HS1s5llS1oZEtw3GuMMdTlL5dLl5ZLNOaNHW+d sZGRoIC3vdBEKZyLOkZoTWUqQcVuVRI1Go2wWtmi1wbetm3fAAaVP8qSMHhr/q9gHRtt ttuV/OlKXIUat3+pC3KtgEUNZ8/K1EYn84Cej7x51AM8R+wnF53uuErZ9F22kIGhNUT0 Y4Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rbgeh8sI; 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 i14si5968762ilq.76.2021.05.17.15.49.56; Mon, 17 May 2021 15:50:10 -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=Rbgeh8sI; 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 S238853AbhEQOQc (ORCPT + 99 others); Mon, 17 May 2021 10:16:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:49986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238829AbhEQOOK (ORCPT ); Mon, 17 May 2021 10:14:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE1F9613E2; Mon, 17 May 2021 14:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260529; bh=0OLzhgNg6Yx/Mcmtj6kddngeM0hyvGo6LAnM/BpS5B4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rbgeh8sI41JDtlg6mfuLG7LwP4mVk1UsX8hNBk3O7excL8tvSylUcap/IgekXO7VC sPa9lsVlHq4oJggVHyaMRigVm19FfMeN0JEB6LgqXyy7FCwaCTIqafPsfCNr3nwOVE KJKvVsfRGDxkpPJT41UzPhOQG6Pn5diidfbG95bg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Petr Mladek , "Peter Zijlstra (Intel)" , Ingo Molnar , Laurence Oberman , Michal Hocko , Thomas Gleixner , Vincent Whitchurch , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.12 122/363] watchdog: fix barriers when printing backtraces from all CPUs Date: Mon, 17 May 2021 15:59:48 +0200 Message-Id: <20210517140306.751014454@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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: Petr Mladek [ Upstream commit 9f113bf760ca90d709f8f89a733d10abb1f04a83 ] Any parallel softlockup reports are skipped when one CPU is already printing backtraces from all CPUs. The exclusive rights are synchronized using one bit in soft_lockup_nmi_warn. There is also one memory barrier that does not make much sense. Use two barriers on the right location to prevent mixing two reports. [pmladek@suse.com: use bit lock operations to prevent multiple soft-lockup reports] Link: https://lkml.kernel.org/r/YFSVsLGVWMXTvlbk@alley Link: https://lkml.kernel.org/r/20210311122130.6788-6-pmladek@suse.com Signed-off-by: Petr Mladek Acked-by: Peter Zijlstra (Intel) Cc: Ingo Molnar Cc: Laurence Oberman Cc: Michal Hocko Cc: Thomas Gleixner Cc: Vincent Whitchurch Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/watchdog.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/kernel/watchdog.c b/kernel/watchdog.c index b8d4182d14cc..8cf0678378d2 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -410,11 +410,12 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) if (kvm_check_and_clear_guest_paused()) return HRTIMER_RESTART; + /* + * Prevent multiple soft-lockup reports if one cpu is already + * engaged in dumping all cpu back traces. + */ if (softlockup_all_cpu_backtrace) { - /* Prevent multiple soft-lockup reports if one cpu is already - * engaged in dumping cpu back traces - */ - if (test_and_set_bit(0, &soft_lockup_nmi_warn)) + if (test_and_set_bit_lock(0, &soft_lockup_nmi_warn)) return HRTIMER_RESTART; } @@ -432,14 +433,8 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer) dump_stack(); if (softlockup_all_cpu_backtrace) { - /* Avoid generating two back traces for current - * given that one is already made above - */ trigger_allbutself_cpu_backtrace(); - - clear_bit(0, &soft_lockup_nmi_warn); - /* Barrier to sync with other cpus */ - smp_mb__after_atomic(); + clear_bit_unlock(0, &soft_lockup_nmi_warn); } add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK); -- 2.30.2