Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp942399imi; Thu, 21 Jul 2022 14:03:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tv3hID23Hl3pyVUSzqH5d144Fdu2E1j6jphyApZvDO2ctn2NjOn++1qH4tLNTlxgxIwtx6 X-Received: by 2002:a05:6402:3201:b0:43a:b203:219c with SMTP id g1-20020a056402320100b0043ab203219cmr211177eda.371.1658437408380; Thu, 21 Jul 2022 14:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658437408; cv=none; d=google.com; s=arc-20160816; b=OHn6SqWb/qqWPC4oTWj5FroNZs7p8+MtSOpR4tNTJ6Q6YEKWn8TvIk99lRiShxAbjB 1ws1irq00pbwlkLY5rHtqNZ9m/4iUnYrwprQv3xgY3GMAKrW4IBIzA9zSxgAErRkq3Ze e8Cqsev5s/S8BK5ihOJKMVycmNsHIy11qECMxr8zbtph7BtZuZm5HGWVT0/u9/V6QMFB wk+opbVVs7lYURYI0RgGiljF9yeec8hdOWEomXrXVjBwgsD9f67lfhShFGloyC2fQ3xP GBeAgISFfEPQr00z9hNULm0473943k2yCoFu8q0FpBZTJSlfHnB7DE+cKJw1LV/xTBgu Ss2g== 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 :user-agent:message-id:date:cc:to:from:subject; bh=f7E1NV4wrHpumpLNoWkWkzq2EARszf6HY85p9P3s4CY=; b=SZ0VCBFL2rVQRM+5G11kyjqlGzUiIWDRjAdGyLmapkVU8tHYNX9QZ/5Kzr7xz2bFss mcWcOA0nXYUehoR/z3Q925z6E57iNlZFllQKR67yatFumuzghGeScadKocAPYsGIxM2+ aiN6/ROhiphTVaetuEmc27PpOLuIOYrJsDO1Azk7DuX/OLYeMvu+sIxxVAOpgTrsB9gl BXrRmJ6PXMaUfapEEdNxcTaddETsBK/N+e1+3+8QRyDTiTtXzkCitnOAXCxQZkcJAkqJ AqI0ULZlYT1nhWBmewS57FLzTaQUzaaIPPe1AeT1B2W7H3P/YYXpqdOpRq0Q4i8Mq7ic UCTQ== ARC-Authentication-Results: i=1; mx.google.com; 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=csail.mit.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x25-20020a170906b09900b0072b6d7ea71asi3554038ejy.282.2022.07.21.14.02.40; Thu, 21 Jul 2022 14:03:28 -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; 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=csail.mit.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbiGUUkq (ORCPT + 99 others); Thu, 21 Jul 2022 16:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiGUUkp (ORCPT ); Thu, 21 Jul 2022 16:40:45 -0400 Received: from outgoing-stata.csail.mit.edu (outgoing-stata.csail.mit.edu [128.30.2.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 386C42983D for ; Thu, 21 Jul 2022 13:40:44 -0700 (PDT) Received: from [128.177.82.146] (helo=[10.118.101.22]) by outgoing-stata.csail.mit.edu with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1oEcxv-0004qr-Rg; Thu, 21 Jul 2022 16:40:11 -0400 Subject: [PATCH] smp/hotplug, x86/vmware: Put offline vCPUs in halt instead of mwait From: "Srivatsa S. Bhat" To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Alexey Makhalov , Juergen Gross , x86@kernel.org, VMware PV-Drivers Reviewers , ganb@vmware.com, sturlapati@vmware.com, bordoloih@vmware.com, ankitja@vmware.com, keerthanak@vmware.com, namit@vmware.com, srivatsa@csail.mit.edu, srivatsab@vmware.com Date: Thu, 21 Jul 2022 13:44:33 -0700 Message-ID: <165843627080.142207.12667479241667142176.stgit@csail.mit.edu> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 From: Srivatsa S. Bhat (VMware) VMware ESXi allows enabling a passthru mwait CPU-idle state in the guest using the following VMX option: monitor_control.mwait_in_guest = "TRUE" This lets a vCPU in mwait to remain in guest context (instead of yielding to the hypervisor via a VMEXIT), which helps speed up wakeups from idle. However, this runs into problems with CPU hotplug, because the Linux CPU offline path prefers to put the vCPU-to-be-offlined in mwait state, whenever mwait is available. As a result, since a vCPU in mwait remains in guest context and does not yield to the hypervisor, an offline vCPU *appears* to be 100% busy as viewed from ESXi, which prevents the hypervisor from running other vCPUs or workloads on the corresponding pCPU (particularly when vCPU - pCPU mappings are statically defined by the user). [ Note that such a vCPU is not actually busy spinning though; it remains in mwait idle state in the guest ]. Fix this by overriding the CPU offline play_dead() callback for VMware hypervisor, by putting the CPU in halt state (which actually yields to the hypervisor), even if mwait support is available. Signed-off-by: Srivatsa S. Bhat (VMware) Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Alexey Makhalov Cc: Juergen Gross Cc: x86@kernel.org Cc: VMware PV-Drivers Reviewers --- arch/x86/kernel/cpu/vmware.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index c04b933f48d3..420e359ed9bb 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -312,6 +313,21 @@ static int vmware_cpu_down_prepare(unsigned int cpu) local_irq_enable(); return 0; } + +static void vmware_play_dead(void) +{ + play_dead_common(); + tboot_shutdown(TB_SHUTDOWN_WFS); + + /* + * Put the vCPU going offline in halt instead of mwait (even + * if mwait support is available), to make sure that the + * offline vCPU yields to the hypervisor (which may not happen + * with mwait, for example, if the guest's VMX is configured + * to retain the vCPU in guest context upon mwait). + */ + hlt_play_dead(); +} #endif static __init int activate_jump_labels(void) @@ -349,6 +365,7 @@ static void __init vmware_paravirt_ops_setup(void) #ifdef CONFIG_SMP smp_ops.smp_prepare_boot_cpu = vmware_smp_prepare_boot_cpu; + smp_ops.play_dead = vmware_play_dead; if (cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/vmware:online", vmware_cpu_online,