From patchwork Tue Jun 13 12:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 107351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp506359vqr; Tue, 13 Jun 2023 05:31:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VjpUp5Tvut4AwOUtd298CmHZhe9dOrvgA/0SEzZjQj4Yd2rAFWxEFA4gnoVpsZ7LJNGhj X-Received: by 2002:aa7:d60e:0:b0:50a:11ce:4d24 with SMTP id c14-20020aa7d60e000000b0050a11ce4d24mr6722418edr.15.1686659470467; Tue, 13 Jun 2023 05:31:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686659470; cv=none; d=google.com; s=arc-20160816; b=LE+ryY8wjlUZZ7uRaiYryzzuN/Zjbdn4DPmXI4TCf4Z0YTY1gxZL3sIEKCEAnKMMTV +sPWn2Qj/NNtOPoKEVIHLf/5Y66rWdtaqypSr6BWUW8v1IgJ9VgmTDVvWPz07bhbYe4a JK3FbiuNxOA6dwCz+sbjDRjfDvgzhODM95bXMJxNuxyDOL0sx/6Vg1VvcsccleUIUkOk W5ch57hvJR5Ua1wGC95Yab8ewljWkok5Wy5GxfXqvzbJfKSi9v/1SdXgOkE3lVDDE1Uc BqbFRZJa1om2s/cVthP6vpGjyeb0997GSG7fzOuLtLHQiThJHScJCHN77IK+o1ci1FyY ztwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=5gDoXglY/QeknUv64+zoXgi0Yj9FIJUXTEG9+0wz2Ho=; b=WkI96rVyKhlkOpG/i2rBOP+z7EzkJoeqGEckv3sjxjsWl1tRuLx4Qaw531gnGm3Fbu GbbF5dqavz/LO/9aKcU7//Mjdjs/75YXdiV3sOx7gqD8Hdbi37Ru+HPVcCAPB3Zhe6ri AmVtFZCZYzteuAYY9R7SwBjoaqkqLowdtBSX2EcgHRC01xlgLLkBnjBWdDSgR/LdN8A2 ULoE3QaotnpUcrbxk8efEF986ahFL3wHvIfovBRC4swtJnrGUCFT+ufvxa2qz5RaWklF IzIiQKh0Yf0dodE5gZ673ZdWNylz8r3Up5S7W580DWZOYhltsQ7RSMm4EOmnWtX7g6em 9mOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HDk3SkzL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n5-20020aa7db45000000b00514be2f2355si7204259edt.109.2023.06.13.05.30.32; Tue, 13 Jun 2023 05:31:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HDk3SkzL; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242352AbjFMMSM (ORCPT + 99 others); Tue, 13 Jun 2023 08:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242277AbjFMMSC (ORCPT ); Tue, 13 Jun 2023 08:18:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D5EDCE for ; Tue, 13 Jun 2023 05:18:01 -0700 (PDT) Message-ID: <20230613121615.820042015@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686658679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5gDoXglY/QeknUv64+zoXgi0Yj9FIJUXTEG9+0wz2Ho=; b=HDk3SkzLXmBKoEWWYdQhk62//czfpnloAdjufIsu9ln9M1Ia/twdJgubGCHXveDMBLSNoE LcBehRNNf84MCUSreODAFngI8vbo5637kUizdmU11YQUkLMBe3dJ5H4qozl7NIwF926g4v wX9JzZ/FoxH2riOgkVUFD9OcFG+ZITkwbm0TemDdm8QjlvAYEiZZ3hgNpvc0jVP6fWGNku pxm7wv4RNQSIUdSOYJ7NDMMkuGhH/9hFmX53oIsFzR+n8MXD2MuvpfQu6Cn0QmPgOE2MhQ SWf+ZWcbJkxe/q6+biIZolgD+kuNNrPqqgxy9dg8eaK8mJ/5rqOz86XU7WOPeg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686658679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=5gDoXglY/QeknUv64+zoXgi0Yj9FIJUXTEG9+0wz2Ho=; b=He364tdunJPaA7wqlPfGXiIfHsYqZG8Q3qlaaiQgoJafWURCpUyvS8b5vE+6oVNLgXvshQ rsW/e3A/5tZYG/CQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Mario Limonciello , Tom Lendacky , Tony Battersby , Ashok Raj , Tony Luck , Arjan van de Veen , Eric Biederman , Ashok Raj Subject: [patch V2 4/8] x86/smp: Acquire stopping_cpu unconditionally References: <20230613115353.599087484@linutronix.de> MIME-Version: 1.0 Date: Tue, 13 Jun 2023 14:17:59 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768590641287012673?= X-GMAIL-MSGID: =?utf-8?q?1768590641287012673?= There is no reason to acquire the stopping_cpu atomic_t only when there is more than one online CPU. Make it unconditional to prepare for fixing the kexec() problem when there are present but "offline" CPUs which play dead in mwait_play_dead(). They need to be brought out of mwait before kexec() as kexec() can overwrite text, pagetables, stacks and the monitored cacheline of the original kernel. The latter causes mwait to resume execution which obviously causes havoc on the kexec kernel which results usually in triple faults. Move the acquire out of the num_online_cpus() > 1 condition so the upcoming 'kick mwait' fixup is properly protected. Signed-off-by: Thomas Gleixner Reviewed-by: Ashok Raj --- arch/x86/kernel/smp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/arch/x86/kernel/smp.c +++ b/arch/x86/kernel/smp.c @@ -153,6 +153,12 @@ static void native_stop_other_cpus(int w if (reboot_force) return; + /* Only proceed if this is the first CPU to reach this code */ + if (atomic_cmpxchg(&stopping_cpu, -1, safe_smp_processor_id()) != -1) + return; + + atomic_set(&stop_cpus_count, num_online_cpus() - 1); + /* * Use an own vector here because smp_call_function * does lots of things not suitable in a panic situation. @@ -167,13 +173,7 @@ static void native_stop_other_cpus(int w * code. By syncing, we give the cpus up to one second to * finish their work before we force them off with the NMI. */ - if (num_online_cpus() > 1) { - /* did someone beat us here? */ - if (atomic_cmpxchg(&stopping_cpu, -1, safe_smp_processor_id()) != -1) - return; - - atomic_set(&stop_cpus_count, num_online_cpus() - 1); - + if (atomic_read(&stop_cpus_count) > 0) { apic_send_IPI_allbutself(REBOOT_VECTOR); /*