From patchwork Tue Feb 7 23:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 54103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3127575wrn; Tue, 7 Feb 2023 15:06:48 -0800 (PST) X-Google-Smtp-Source: AK7set/793gSGKEwjYTdrx2NCbXBz9O8BltA+5Y5ewMgZG2w0FDdK7XfEDcfB1KKQdukOB7ZWyLV X-Received: by 2002:a17:906:3950:b0:887:3c7e:5df with SMTP id g16-20020a170906395000b008873c7e05dfmr5383507eje.73.1675811208167; Tue, 07 Feb 2023 15:06:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675811208; cv=none; d=google.com; s=arc-20160816; b=oJb+EvQ2zbI23oNV2YNajaf09RnBoiCH57TMx/b1GoZYbrCisnspXLkDmdlyb/Gppa l4wNU9r4M0AprlNyQrSnob9QHV7Q9WkjIEFGKNndwYt2OrK2NPgOmxVUOLwF1ttXs1/y 2Ohrhahr0vq/3U72apRusxSY0iZ52Tsuim7vQkp34R28R5bxQjQN2lLc/9I/VS3cUaOl Fh9Kk2T6q4DYftMgbaj1q3WdrjJYvFdConqObluXtvHplqQN2UnayZd4P2I1STZAQW1l 2yA1rvAqV3JlmGf7zYXW9w9UuXU4cpI1G87QSGMsMZv/xVqFRmyrDO+ijKH6i/mAFGEj 8Kuw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L+woZryxcmbb99mupmnna5okozeg16DDHF5Mj8G3upM=; b=y1+OjlvTpZxTyD9ww5CTK6HmaVH1IOkLqdMRuTaAd+g6VPGRtWU2dWeSzNpysQzhWu AwLIWfPYl2aLgMFpS3aSa4REsdaGHBQO68lCJd/OFCyMt63cBV5VimespBMb8IqS/Tjb wR0xihTBiiNdcyNnIdG4mKIRZLZLyuxRSj4epHx/27rPexpEJ1ohg7nj5IpP7RjqQBiD 6KtL3dk2gPt8NETYVVaxdY6MXwIzQHWOkHWLzFdipjMzvEFTdfeMxAxLyvXFhNmBeF3P AbpT2k1ufWI+Dad8DzVR92bZtrxYf3RvIFs7fJAKpqLWhU5ZeNR9+21H3+DnQGoYtdH3 lo9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="I6OGmp/z"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 17-20020a170906001100b00881984b0f41si21212040eja.291.2023.02.07.15.06.24; Tue, 07 Feb 2023 15:06:48 -0800 (PST) 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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="I6OGmp/z"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjBGXEt (ORCPT + 99 others); Tue, 7 Feb 2023 18:04:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjBGXEq (ORCPT ); Tue, 7 Feb 2023 18:04:46 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9BA13FF2B for ; Tue, 7 Feb 2023 15:04:45 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id z11so1090443wrl.8 for ; Tue, 07 Feb 2023 15:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L+woZryxcmbb99mupmnna5okozeg16DDHF5Mj8G3upM=; b=I6OGmp/zf+SXm16RpuuHG0Cs0grAvvCacNPO9dKsk1CnGRmdMFu6+0NJdJhyZFTM4X t222CAl7UR84WcZsi9vxKoozrPUuo3JLOzCIH9sxnbaS2E1xVnpxE5522R2XhnSGXoAq H4dMxa2K3aJcC4yIroI+hFKQ3ShkEp8NGiIlepnXYdQeZXr63YjWL9GWbYxgDjB8SqFq 6hSMRm3TCfJwjZPwZVHhxdN9/3ajo3kOYvz8TDCXvwpUD7+G2VBebFw/w20A52rvxJgq tohCQW4m433T31Ja45QB9CYTeV4/Ljp7ac0MTuuxzvTX9xUgS2fkFqmLhmlrsnEBHe/T tISw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L+woZryxcmbb99mupmnna5okozeg16DDHF5Mj8G3upM=; b=CfRCNwybFMLY5G3B2mfDrU8ZKkyGRUctmWl3eLT0fqvG/VSq1g2soH5D/Z3WowsHW0 9cxJL9h9MPx+3/MGUworFb+nMFhH0JVhACKoEbdXkiDGiRhkzJVRRlXg2XqY16V/jYIP 1NV1JAebYH7WookmHGyONJyTvisSw4LIO1dN8wIv9uheDJPNVAOQI7X45Q8ZpM4X/TEU U4RgiZcEl5itn5H55PQ4aQKHvEJ1vwF9XlBPSyugBNBc5gNoTkmNW9HnafHsPD3wT339 B4mq1Jf4YNMENhuzcIQ0x8UIrae5OY5NDw8bE89L4LhL9wnAUwTJEVfzxzA/P1BV+opP vJag== X-Gm-Message-State: AO0yUKUEEJ3RkE3OyJDJrQaoaQHbfw5E6X/ri53aq1vXGhJGnPo2hzt6 sIS6zA8GIsfaoVME22XR9PrVlg== X-Received: by 2002:a5d:5183:0:b0:2bf:b5ec:4844 with SMTP id k3-20020a5d5183000000b002bfb5ec4844mr4689320wrv.19.1675811084196; Tue, 07 Feb 2023 15:04:44 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b566:0:c04f:2463:c151:8b87]) by smtp.gmail.com with ESMTPSA id j14-20020a05600c190e00b003dcc82ce53fsm146485wmq.38.2023.02.07.15.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 15:04:43 -0800 (PST) From: Usama Arif To: dwmw2@infradead.org, tglx@linutronix.de, kim.phillips@amd.com Cc: arjan@linux.intel.com, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, paulmck@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, rcu@vger.kernel.org, mimoja@mimoja.de, hewenliang4@huawei.com, thomas.lendacky@amd.com, seanjc@google.com, pmenzel@molgen.mpg.de, fam.zheng@bytedance.com, punit.agrawal@bytedance.com, simon.evans@bytedance.com, liangma@liangbit.com, David Woodhouse , Usama Arif Subject: [PATCH v7 4/9] x86/smpboot: Reference count on smpboot_setup_warm_reset_vector() Date: Tue, 7 Feb 2023 23:04:31 +0000 Message-Id: <20230207230436.2690891-5-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230207230436.2690891-1-usama.arif@bytedance.com> References: <20230207230436.2690891-1-usama.arif@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1757215413339722888?= X-GMAIL-MSGID: =?utf-8?q?1757215413339722888?= From: David Woodhouse When bringing up a secondary CPU from do_boot_cpu(), the warm reset flag is set in CMOS and the starting IP for the trampoline written inside the BDA at 0x467. Once the CPU is running, the CMOS flag is unset and the value in the BDA cleared. To allow for parallel bringup of CPUs, add a reference count to track the number of CPUs currently bring brought up, and clear the state only when the count reaches zero. Since the RTC spinlock is required to write to the CMOS, it can be used for mutual exclusion on the refcount too. [Usama Arif: fixed rebase conflict] Signed-off-by: David Woodhouse Signed-off-by: Usama Arif --- arch/x86/kernel/smpboot.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 55cad72715d9..3a793772a2aa 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -121,17 +121,20 @@ int arch_update_cpu_topology(void) return retval; } + +static unsigned int smpboot_warm_reset_vector_count; + static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip) { unsigned long flags; spin_lock_irqsave(&rtc_lock, flags); - CMOS_WRITE(0xa, 0xf); + if (!smpboot_warm_reset_vector_count++) { + CMOS_WRITE(0xa, 0xf); + *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_HIGH)) = start_eip >> 4; + *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = start_eip & 0xf; + } spin_unlock_irqrestore(&rtc_lock, flags); - *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_HIGH)) = - start_eip >> 4; - *((volatile unsigned short *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = - start_eip & 0xf; } static inline void smpboot_restore_warm_reset_vector(void) @@ -143,10 +146,12 @@ static inline void smpboot_restore_warm_reset_vector(void) * to default values. */ spin_lock_irqsave(&rtc_lock, flags); - CMOS_WRITE(0, 0xf); + if (!--smpboot_warm_reset_vector_count) { + CMOS_WRITE(0, 0xf); + *((volatile u32 *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = 0; + } spin_unlock_irqrestore(&rtc_lock, flags); - *((volatile u32 *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = 0; } /*