Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp431698pxj; Tue, 18 May 2021 06:40:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3WRe+iJETkE8tlGC0wBIUXdv0uSfzp5G4ptZ/HZrauJgK61KZzPtC+E5bi1G2zrFqLU2V X-Received: by 2002:a5d:9f0c:: with SMTP id q12mr4245581iot.210.1621345209384; Tue, 18 May 2021 06:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621345209; cv=none; d=google.com; s=arc-20160816; b=06NWvv0gJOvXMc68z24I1YDqPSC5KPlcy8y0p8gwecuUPfoddDSUrsQJNcC78txiKx k9D6G6KkGjK+I7r2KlLC+l4MfmoiouHpUH7bR6JlyuzLvHalwShCeOzQyYjD/uhEJ8hb dTBGFdH+bODwoic7bYjzztfot0hFOZjsJbvsXS9PSkyuwJ1OM1kFGeSAyKFe+OsSn3Ps XVxf+JirG82aQaHP62F3guVs9sUyDORw2iX8v0GiwrXWklIWSEhjOWga2qEuRzGiJMLA cIplZX8/3yKxfBT/s/7IBfuxcz2IxVbdcBiYlp5KoY8IGQkeO5YrGxav17mReisgCwvC 5Jqw== 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=Tky9dQlPTrbBlMmoqNGuQoLqkD5uVylb2jKaaKHIPnA=; b=u055P2G+hwHYsRPPVGg4kr22sv5HTLKIIZZdX/+vQmMLi/bVoL7Yx3oeoEiQNyENTc WwkRjod9sazjtKkeMbAivcgH+rkX8zK2RsToKT6Ywvnqhhch8/lX3uiRXcKbliZm/37q 39YhJlNymCvfYSAEPj3WdDQzGV35uMqUqDwhR6AKVwbV0nTh5gTigmfCvKQ/+XX/Soqw 3hgWQ+gatLga/p0Ssmmeqjt9d2J0wCYpA9T7bXD/BMRsVr1rY5owl6NiuX3I658TSnj3 rkHQd2KE3xJukB4oT+YgMPrAP1jQiFlsdScCWEKV67+unVCpMJa/WrWGpe6yv9uNVYMP vB8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c7ZRFoDp; 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 f12si21875815jat.88.2021.05.18.06.39.56; Tue, 18 May 2021 06:40:09 -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=c7ZRFoDp; 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 S244150AbhEQPi4 (ORCPT + 99 others); Mon, 17 May 2021 11:38:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:41894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245049AbhEQPW5 (ORCPT ); Mon, 17 May 2021 11:22:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E4C9F61C9F; Mon, 17 May 2021 14:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262114; bh=N+cDqyWaNRu7Fs6ee6v1kiQ73FqSCuRxLtsnmHdnzyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c7ZRFoDp6HGKHiRnlNE0wV9+NnoM2b6IXBfZSDn2zlGsQKh2zJqBoXtCNC5b+b3so sbBAwXe1kp472Cu1rnJmCL9wymiDaV0OQnBSOPLNrgyNvtAYEUzLUaiHYaMyY76zrn ZPPZF04lljv9m4KI+SX5E7Q4QA8rZmffMIPw7BII= 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.10 092/289] watchdog: fix barriers when printing backtraces from all CPUs Date: Mon, 17 May 2021 16:00:17 +0200 Message-Id: <20210517140308.284047046@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 122e272ad7f2..01bf977090dc 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -393,11 +393,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; } @@ -415,14 +416,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