Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3841009rwd; Sat, 3 Jun 2023 13:09:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7T4i0+SFpkJGoz+UfjkWstZM6QN0gxzADoPjSNTG9p5sdjnjA7UERKueSKRFTExU2Ny/UV X-Received: by 2002:a05:6a00:1996:b0:652:a559:b2c5 with SMTP id d22-20020a056a00199600b00652a559b2c5mr7356911pfl.13.1685822961944; Sat, 03 Jun 2023 13:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685822961; cv=none; d=google.com; s=arc-20160816; b=sNA+0YrkwmavqvMilPcKE7EqgK6PR8kQjZO9HTg2r/L3qgCNuTqBW2wsTfaSgadpnZ JOhIKuwBDmHuiwz+mkbY9kzfQNFKlN6mMWSc4+v1wfJSz920xE5N0XoSpdjCmAWKqrtd MHErQx+AluADoDjx9/0LBEk5VwLZi4lNw8gB2SEPMjRfwqo4KmFi+nJchDYNzPD8fKq6 PWxIeh6v108DTnlM0aigyD1FtaBfK1d8QxdPTc8+5nuBATpI6nszf9ANDyLqb2EkHtKj nIorVbKydZ+IeG8hkSU1tlSZP+NvMJ+6EIEOo7uGAVYeyBTxJLo0MUz3DTBSJg5H8Rw8 a3Rg== 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=I7I2EKoHeo/byjwgLE4HOlJ+wED05lzaQv+BpbzI77U=; b=kr8cyinTLX71uc9JZ3PZvqbpdiSQoGirtfGLslDaxBvuTg9z3kQNkzxqredMhZNtaZ zyfqLrXDg13DyaHevhCEPxkwRJKe2OmUigG1fqQSeD3nxe5fHvkmIcytIdgx1WltCnu4 S287y89HsFZDB3CLGrjN3NrwWSXYXGobqjhdQLrjqL3Rsl/NRzeQLMQMYBPlkbDKLR1i +PU/nggRvFwN7wwtPJ+qB6+NgfkD2KJ/7z/xzigD1ajteGy+GVAcXRAGqZFee5nO2VsJ CuwNoOf9wwab3lha4wCxAmgryLJmgrh+PM5yPZEVZuIFzgsRCBaMKncEq9C3waus/AVN 8bhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IUrevXDa; dkim=neutral (no key) header.i=@linutronix.de; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b0053fc952a02asi3012158pgx.670.2023.06.03.13.09.09; Sat, 03 Jun 2023 13:09:21 -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=IUrevXDa; dkim=neutral (no key) header.i=@linutronix.de; 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 S230350AbjFCUHx (ORCPT + 99 others); Sat, 3 Jun 2023 16:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbjFCUHw (ORCPT ); Sat, 3 Jun 2023 16:07:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC9CAE75 for ; Sat, 3 Jun 2023 13:07:24 -0700 (PDT) Message-ID: <20230603200459.717231106@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685822818; 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=I7I2EKoHeo/byjwgLE4HOlJ+wED05lzaQv+BpbzI77U=; b=IUrevXDafhxQpLh0SuAslVuhafF3e085DF4EC0XDwrP8KirhfW70LxmVA0yQBkAN089fV1 xgb04EKn2nBiZfcWHV5dd+hXBzRkvKtJjfnzqmLOKKeyZVQVx0Hijqxe8a+fqRITiQK6Uy 6rwJNJk4Uekr62dY1ag1j7pylEXmWsP/PGDQGhVrJCilWws69mT0bMHRlqrXlowbUT/xG+ DhArg3tMUWupx+ywukQnAg37tt6FcMEsgrjQINvqgOrZSqe3Z7TtL20/Dze4ygSRVAQQtv 3pFA2DdRTl+ylJ35vrK5DBRkV7SbvE6mb+QakAAnipAa23n6w4vFP6viBqi/1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685822818; 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=I7I2EKoHeo/byjwgLE4HOlJ+wED05lzaQv+BpbzI77U=; b=NSZ+nkDqpgXAzT5LDYYjC92Jhe41A25OJcBNQ50l8zJv063WLDMznbCPeL21GpuzRk1VZ7 ZKh5N99eICdZnGDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Ashok Raj , Dave Hansen , Tony Luck , Arjan van de Veen , Peter Zijlstra , Eric Biederman Subject: [patch 2/6] x86/smp: Acquire stopping_cpu unconditionally References: <20230603193439.502645149@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sat, 3 Jun 2023 22:06:58 +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 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 --- arch/x86/kernel/smp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/arch/x86/kernel/smp.c +++ b/arch/x86/kernel/smp.c @@ -152,6 +152,10 @@ 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; + /* * Use an own vector here because smp_call_function * does lots of things not suitable in a panic situation. @@ -167,10 +171,6 @@ static void native_stop_other_cpus(int w * 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; - apic_send_IPI_allbutself(REBOOT_VECTOR); /*