From patchwork Sun Feb 26 11:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 61595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1897993wrd; Sun, 26 Feb 2023 03:09:46 -0800 (PST) X-Google-Smtp-Source: AK7set/JzozjrJQvthIbKSn5NkPT5P4ZZhDyG3/p3ad0JxLadzQwHUaJAxrDavFpuhPGaJYmUG2c X-Received: by 2002:a05:6a00:2e83:b0:5d9:bfc9:a4f with SMTP id fd3-20020a056a002e8300b005d9bfc90a4fmr12797954pfb.3.1677409786151; Sun, 26 Feb 2023 03:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677409786; cv=none; d=google.com; s=arc-20160816; b=CXUdxZJ8tc0e6wa2GcDow7GQMURcCeZFmdVpwFTZxs0rwtnGblQbsB7/zNW51/Gvh4 i2/wNNKCbpjfEX30tHIV/3HtnHzUxsNJASr0LXxeUyf0Yh/QVgPvaI0+ySr+cZDGeU0P rkOhrpyCitIT46AOR32vw6uUA8QUL0lWu/Tj6u/Ee+M6okL0QSTrVcZbb4zMNcJMKZ33 e/C4s1ExP+ZxxTeFNEFO9kdOD3oVXcTE27KN7JVtpauxl2t9Qj895yLnvkCErmv/HVnP MxMefdLu05ss8y6wp6GWnga5vPcXWX88nIJoIhdIRU6m/dQa1wmtu0s4P1zvYOmbfneu bY7w== 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=OivBWw2fC0XPAqVFrKNNGqM4Zo9U9YwXqHaW8wBeEGc=; b=Zae7fgwoK2wVfH29eRDkEAA/fYfqE3UYIXSk1zf3ZpaZOC9hVh7z26IZjvnfrTOBvB Ag4f18JqCISreUTbMDdt3wZ71nFA1svKHC/15HT6W6s/PV9Me0uQFcLXy7fz4OKR7GU+ gqeRj6lNlkh4cm6ofliRfcMKW1JvAP1qE3qek3FgkMP9Q7VsI+io4Bjr2zsfjnhJ+OW0 DhDjA/NAS0dGHC/453TNHBZl+Rdsirn7k6aaeRobb7T2HXCeGHSKZtAJ1g9NIUCKsRTJ NQMSFXctk0EKwrrJDIXl+buXh6GE+EUwrWnz+iR1neKOvxsxhAxlbYUyiLw1CmZ/mqGQ ky4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VxCrwOsO; 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 j124-20020a62c582000000b005a8bdfeef8csi4010314pfg.367.2023.02.26.03.09.32; Sun, 26 Feb 2023 03:09:46 -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=VxCrwOsO; 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 S229703AbjBZLIr (ORCPT + 99 others); Sun, 26 Feb 2023 06:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbjBZLIj (ORCPT ); Sun, 26 Feb 2023 06:08:39 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6184CE07F for ; Sun, 26 Feb 2023 03:08:10 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id v16so628847wrn.0 for ; Sun, 26 Feb 2023 03:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; 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=OivBWw2fC0XPAqVFrKNNGqM4Zo9U9YwXqHaW8wBeEGc=; b=VxCrwOsO5d51D+qxGU56U12/Bi1oSWb2V8N/WSXUn/RfWrQ6Ei6ewkTrmwmzWXtlEf 5PWKmXL//w+gNJ2lBwzUfLYDtc4Nljo6tLaTFo0UimNjQT0Agj4KY1YVu0iHm4b7uqM7 q2aS+BoZEGmMeqk7lq/8cDQvl6gJe3R/50HoLK9X79Ap54V0GqPfCvrJRVPrsg5N3e3v GzPn5YVhsu7Ox6p1K3jcqvLMPshqVmLucNu8EWcjGlK5lnyETbXiQtf0dp3EygPOIsRk YrwYlukZIIGQTeKCOhY9l0lf5gm5uvndbv58YwfVyOdobjwp/nkuyUZMli2uW6KQU1Nx uh/Q== 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=OivBWw2fC0XPAqVFrKNNGqM4Zo9U9YwXqHaW8wBeEGc=; b=qxK+npeyriv7n2bYkTBkzr7R3jqyHdBwfO25JqNqp73cxktvAzJoqyeUaQO7f3uKyj wlkkHRNONtnOYVkueYu4l/+XZPYOa+44hvQ+Exz83FmNSdUxtSncREyjsIMJcjJ2/TSq ZOHOCuOy3OvVqut3AuDK2X8owUysRKWXsUbydKQadUffFjbWlQHdKXyqI9kKiPhwYwYX 7RwkNf6jobyojlX74rz807ZYOlb0p4DBKZD0nyceN8kX62gOqywVvpe9C/0B56mQtzhq GpL3sJA2HaEG2QY254MQY2v67X70bYj7kcTrirx30suzJi65OlA7+C+03vP7LWecgc33 51IA== X-Gm-Message-State: AO0yUKVCUDNMcHgUGfV7u+wM0e0YPxKMD7q3Qw3+bdidOHBbq0e0T3Wz MuWjAPWRsjXq4+33/qmXf1UP7w== X-Received: by 2002:a5d:45c6:0:b0:2c7:aed:b981 with SMTP id b6-20020a5d45c6000000b002c70aedb981mr12298110wrs.30.1677409688797; Sun, 26 Feb 2023 03:08:08 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b566:0:df7b:4668:3e23:d0c9]) by smtp.gmail.com with ESMTPSA id v22-20020a1cf716000000b003e1fee8baacsm9157318wmh.25.2023.02.26.03.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Feb 2023 03:08:08 -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 Subject: [PATCH v12 04/11] x86/smpboot: Reference count on smpboot_setup_warm_reset_vector() Date: Sun, 26 Feb 2023 11:07:55 +0000 Message-Id: <20230226110802.103134-5-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230226110802.103134-1-usama.arif@bytedance.com> References: <20230226110802.103134-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 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?1758891644054738119?= X-GMAIL-MSGID: =?utf-8?q?1758891644054738119?= 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 --- 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; } /*