From patchwork Mon Jun 5 08:23:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 103185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2530196vqr; Mon, 5 Jun 2023 01:27:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kpmH5kgfmo46spgYHirX0va3kTzuq1DfWa1X/Iithei/hEN1U+70cUCJcFFLR++188+Sj X-Received: by 2002:a05:6808:6393:b0:39a:a880:50dc with SMTP id ec19-20020a056808639300b0039aa88050dcmr3911010oib.52.1685953633181; Mon, 05 Jun 2023 01:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685953633; cv=none; d=google.com; s=arc-20160816; b=sZNZQWqi0o+oBFsucmCFO7jlO9v6RqYlxYsvLPnsDOPPUxcaLloO6IGSMVe2buVf0s 64doyZ//1YUg9pZ9F8+50PaSRxZLMgoLbOvWsMe5Vo11QjrqyGPFT7iVelEYq3GfKwMa igad3xaz6QVVAHQbbikWW4GAshGUAUxX1rQfUStMZf/V2kKTZ/vhVkqaCyExtfQIkQBI bWJurXsS4xMUQTb1Bp5HENr8LfYwoKCXFjma462hEnCufUcmuf8rbNHi85/6xQ6WTQsb CHz9wANV7WWvPOFiM6d6BKsGd0yvT2CmjhJNOKJJZ+S4VsU+golpewOPOiorNRxLKKNx QYWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=7ikEFZzVQhOPStEaidYIowYTuW/g1JDuXRSIEWHVNNI=; b=g1UC7LssY8+4+EBgs8XvQJMD+hKQcUzu1IiC9CS6vwynzGigJTrcr4Im5t4YHRpj19 BbdBjCpOjo3gO+O9pel3s6D8ICJ21btBH3m6Gzvrm+WFs+KItOwKuZNz3nWCkQAIJBsr 4DmIeEGN06JEOwohvsmW4Q/VF8uZ1ZsB5Ptt2cKREg1aAiLbOev1fDEIadm9KIJMlllt YztwoU1dRph5OwKZzrdVqJMYNODbTkyf86PF8XrqplE9c8H0FSiRCPE5SyG8hGeqPxon Vnp+LcksevdP5EZfT68mQ3CCB0mdCulPc/yq2185eGnF8Vs2K7dpV89lMCXw2JWpT80x e7cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xi0TDDSR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a636b06000000b00543c1b10f44si533380pgc.41.2023.06.05.01.27.01; Mon, 05 Jun 2023 01:27:13 -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=Xi0TDDSR; 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 S229546AbjFEIXL (ORCPT + 99 others); Mon, 5 Jun 2023 04:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjFEIXJ (ORCPT ); Mon, 5 Jun 2023 04:23:09 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BF59AF for ; Mon, 5 Jun 2023 01:23:08 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1685953387; 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: in-reply-to:in-reply-to:references:references; bh=7ikEFZzVQhOPStEaidYIowYTuW/g1JDuXRSIEWHVNNI=; b=Xi0TDDSRp9vUi3aceigQJ55s3ACdlO1VRQiOJmZx7L5t5n6GPgwK0Mwsk5In4TackPsCeE H6I+nrX+V9NiWOSY56TPdIlFBzxIHSvwQq0DNlFiKubMxlrFg42n+n+2x+UghlNlGkhpP4 8jMau7/Ys5V3Wl+YKTs7iuk3ksRv/uer/K3+u+3EXJIvK9f4kdmOrlNUI8d8fEEN50h9+3 mFb5dRMc9CQhvrY7+xJuRqhnbZvGhwJlZdfdxT8z5JogybU404qxOxZj9V0cJJTp7GU1o/ g+t8Bfo1ivr2YzAd5dl53kV3LsH2PIboVuj32vCc9xhgSB7YuG3jFGn7soItzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1685953387; 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: in-reply-to:in-reply-to:references:references; bh=7ikEFZzVQhOPStEaidYIowYTuW/g1JDuXRSIEWHVNNI=; b=icYcEYkVFIN7vhQZhtD/feADYqeR33tbO6Nj6rkQtJ3V9T55gKZ5IGFsCLc0A74urNt7G1 d3qAkkAXpzjklRCQ== To: LKML Cc: x86@kernel.org, Ashok Raj , Dave Hansen , Tony Luck , Arjan van de Veen , Peter Zijlstra , Eric Biederman Subject: [patch v2 5/6] x86/smp: Split sending INIT IPI out into a helper function In-Reply-To: <20230603200459.889612295@linutronix.de> References: <20230603193439.502645149@linutronix.de> <20230603200459.889612295@linutronix.de> Date: Mon, 05 Jun 2023 10:23:06 +0200 Message-ID: <87a5xe8gid.ffs@tglx> MIME-Version: 1.0 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 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?1767713525888430471?= X-GMAIL-MSGID: =?utf-8?q?1767850516812985501?= Subject: x86/smp: Split sending INIT IPI out into a helper function From: Thomas Gleixner Date: Fri, 02 Jun 2023 15:04:10 +0200 Putting CPUs into INIT is a safer place during kexec() to park CPUs. Split the INIT assert/deassert sequence out so it can be reused. Signed-off-by: Thomas Gleixner --- V2: Fix rebase screwup --- arch/x86/kernel/smpboot.c | 49 ++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -853,47 +853,38 @@ wakeup_secondary_cpu_via_nmi(int apicid, return (send_status | accept_status); } -static int -wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) +static void send_init_sequence(int phys_apicid) { - unsigned long send_status = 0, accept_status = 0; - int maxlvt, num_starts, j; - - maxlvt = lapic_get_maxlvt(); + int maxlvt = lapic_get_maxlvt(); - /* - * Be paranoid about clearing APIC errors. - */ + /* Be paranoid about clearing APIC errors. */ if (APIC_INTEGRATED(boot_cpu_apic_version)) { - if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ + /* Due to the Pentium erratum 3AP. */ + if (maxlvt > 3) apic_write(APIC_ESR, 0); apic_read(APIC_ESR); } - pr_debug("Asserting INIT\n"); - - /* - * Turn INIT on target chip - */ - /* - * Send IPI - */ - apic_icr_write(APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT, - phys_apicid); - - pr_debug("Waiting for send to finish...\n"); - send_status = safe_apic_wait_icr_idle(); + /* Assert INIT on the target CPU */ + apic_icr_write(APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT, phys_apicid); + safe_apic_wait_icr_idle(); udelay(init_udelay); - pr_debug("Deasserting INIT\n"); - - /* Target chip */ - /* Send IPI */ + /* Deassert INIT on the target CPU */ apic_icr_write(APIC_INT_LEVELTRIG | APIC_DM_INIT, phys_apicid); + safe_apic_wait_icr_idle(); +} + +/* + * Wake up AP by INIT, INIT, STARTUP sequence. + */ +static int wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) +{ + unsigned long send_status = 0, accept_status = 0; + int num_starts, j, maxlvt = lapic_get_maxlvt(); - pr_debug("Waiting for send to finish...\n"); - send_status = safe_apic_wait_icr_idle(); + send_init_sequence(phys_apicid); mb();