From patchwork Wed Mar 8 17:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 66391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp460700wrd; Wed, 8 Mar 2023 09:17:57 -0800 (PST) X-Google-Smtp-Source: AK7set/GRVm3luvljm+L4efBjQb83mpJuqF2xKF6QZGQ00oUaX0PYT71GTp6Bg51GuizmT1no8jp X-Received: by 2002:a17:902:e842:b0:19e:4173:38b3 with SMTP id t2-20020a170902e84200b0019e417338b3mr25200977plg.46.1678295876730; Wed, 08 Mar 2023 09:17:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678295876; cv=none; d=google.com; s=arc-20160816; b=AdKAHCLYbSGe7kguL+L+qCubJEj8bNAnDmFJS7mpwZqrhij37JVo2qud0SJnBYzlfC Hbe9ff67aXiEkvBTH4L4wbp3AAEEGKpKMDDqwO9xKWmuwuFH75S2bSljZBmWAWri5uWs WWCOUSo4mq5TSJaHu0K5LGAEDuyh/VKhqdc491DM9/CTxlvS3LucfkMPGvWi05hSc2i6 ymhNva5sTvR9A8MHLDQJJaYqrl0LWwrIr/xXuM8J3geO2FPlveGL1tDUmJOOb3kAP/uw LeW+TwL8w8VwoMjGZc49RPU0oVy3cyPZrOcLV+Poo5t3a8BvrpvHRCN/MP3gbHgOB2Tf 3nSw== 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=QbZumu4dMY0Za38bxLjojwYOtrQ4rJ/sJrcRrt0N9M0=; b=Y6Bq7XFej6iTjkUxl0St0MTGC6pyG5rlHds2ZWeN3qyfN5lFukOFnalgBAXG42KCwI Lawg3gDJ+zEcHJYC+YP4UlhGrWtAhj9tPeddRx2g/G+dblT2GnHCAbGBj9BEGO0C1Mqu SOqJJhJq5QvznhK0gT7CJz7ED+krYs07Xo66fgPliSWQbGoIiPbkczuDOr7HBpfmS5Zz N+1TA0IKbhG5WFI4B6exH2Dh5j30Je2Zx8kdZq89q/tuYwy9vOESMw9B0ehi1vJiKo5U MEizqVIUfhAn5WY3DyYjZB8guOpOPO3jMzGHeuxZGQIcPwO4mqzLML5dbqRz7KDftQUz VUhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=O64WP2DR; 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=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 y3-20020a170902864300b0019cec83ecd5si14958832plt.66.2023.03.08.09.17.41; Wed, 08 Mar 2023 09:17:56 -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 header.s=google header.b=O64WP2DR; 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=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjCHROo (ORCPT + 99 others); Wed, 8 Mar 2023 12:14:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjCHROT (ORCPT ); Wed, 8 Mar 2023 12:14:19 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 766C8618AF for ; Wed, 8 Mar 2023 09:13:36 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id k37so10292650wms.0 for ; Wed, 08 Mar 2023 09:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678295615; 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=QbZumu4dMY0Za38bxLjojwYOtrQ4rJ/sJrcRrt0N9M0=; b=O64WP2DRtVFcNc4IQE0SwpXBtLtDxnt2+hKQ7Ic3oyB6nA4LZQ4crGlcXofcwUiWaX oz2LblDsppUMDbOFUlMtjvynmJviJpQyvD7PX8ra1yToflb8ieDBL7flFaIEwZiSAKhf FN0/Fz8zg/Zl1GWMuza8Yo4jNJVD++IqzvobyGknpPhqCwM6bc3KqG6T/KHIYxFzBxvm 7s6QWunEvCBTqgfULHZFKinWpZKLL0jp6FGU5qQZSjVJJBvvZEWAZhOU875+707E57hs +NPwtRHnFND2g4FnPZU2Sru5GgwTAE1NTDFenEeug9hTct6s/nKwltCA0v9gL+BvhOW8 /mwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678295615; 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=QbZumu4dMY0Za38bxLjojwYOtrQ4rJ/sJrcRrt0N9M0=; b=WKPSRZmExHvyBsefzKueBTczxu3aSumyPP6FMDwxJ8RL+cPNim13HIsbYYQQrEH7cb k47nQ92S3BZoktUfDrSqVsiOWy82DQAF3JJ59e2pp60+J7sZZBuqKyh/vKU8xISP7SpP C/wPWK8+xzBwCf0ks2Rs/3uMNiPMWy82thyPVfNBSaY5ULp4VyAet5jq3Q0oPcNcSOyY xKl63goMZCH0SMUXgumVOGfSBUmQH34bihOCJO/TSoAFAB4LOLDcXzAh2Luwi56bIojD OXfePXh8VRagh2U3/Wi2B3jCdLow6hI818wWikmnp2xy0cJsTwZAiMk0sZWbu/wmxpi5 ohdw== X-Gm-Message-State: AO0yUKWhGcYaHFBehBOLjbXVhX7jhFqtBX/GSKHOmVa6Jwz5H1LIzn1Q cqOpytfVlMW0jKlqFGOS9jJFFA== X-Received: by 2002:a05:600c:4e92:b0:3e2:5c3:bcfc with SMTP id f18-20020a05600c4e9200b003e205c3bcfcmr17503117wmq.18.1678295614936; Wed, 08 Mar 2023 09:13:34 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b566:0:fe40:3ba4:afe4:4609]) by smtp.gmail.com with ESMTPSA id l15-20020a1c790f000000b003e0238d9101sm11668wme.31.2023.03.08.09.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 09:13:34 -0800 (PST) From: Usama Arif To: dwmw2@infradead.org, tglx@linutronix.de, kim.phillips@amd.com, brgerst@gmail.com Cc: piotrgorski@cachyos.org, oleksandr@natalenko.name, 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 , "Guilherme G . Piccoli" Subject: [PATCH v14 04/12] x86/smpboot: Reference count on smpboot_setup_warm_reset_vector() Date: Wed, 8 Mar 2023 17:13:20 +0000 Message-Id: <20230308171328.1562857-5-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230308171328.1562857-1-usama.arif@bytedance.com> References: <20230308171328.1562857-1-usama.arif@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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?1759820777435493544?= X-GMAIL-MSGID: =?utf-8?q?1759820777435493544?= 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. Signed-off-by: David Woodhouse Signed-off-by: Usama Arif Tested-by: Paul E. McKenney Tested-by: Kim Phillips Tested-by: Oleksandr Natalenko Tested-by: Guilherme G. Piccoli --- 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; } /*