Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2784531ybg; Thu, 24 Oct 2019 15:19:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxrnTYA32nCVCzV8QPNDj+mbi+UDR/bFCTHBLyVxrR0hMuwotKZjXuWUn6k9k5mr2sLy+Z X-Received: by 2002:a17:906:ce39:: with SMTP id sd25mr394397ejb.331.1571955569147; Thu, 24 Oct 2019 15:19:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571955569; cv=none; d=google.com; s=arc-20160816; b=HuGv3G0ZiuyqKUM/7FLzIbZQlq6xevc2gu153o+AaBrRlBJQW6i2DQ21m6NMZIjZ8u bufHajmAYCgNIQIUQNqyZ6XJcGZ4WFqrhrUmLDwe6yExlMXs1UXoIa++rhHOfitR7OBj /i9M90K0+0pF0hpK8XtWyD0jYCvws7ttwhOw6Lrmxd00apYoFUEYv/55d4+H9jMd96Ba 8KFWPIrMLMsufgrEcJowwWnzm+ZxcMTKjeZlnAGQv3e+JbcYpO2FvEnzaCGV9wgXKoRo 4DCxtwJXXpcj2orcTh2/ihVz7qGEDn+bWds5OvFvY+K4bgeLL/qtXVWlOTJL0Gq31hvX 9Kuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0VuMfCO+LpYmRgQ97/DW07OKPE7Sj3CHDyRgLDeHJC8=; b=ZtuDlJx6kZIyThKsySv+6Q29+vwJVjCPju8g3WT/Ir7daSMKdV1oBDKZ+zcrqY9roX 5spwKjaS2irualW68XRwY4BdrKi1gt+CqTpV12oyKc0kQ3DsTNTT4xT5kM4s57m174uJ yRfbgDHp5r/HcMBtbKcb4ediefSiaVSi06Z1SrJ4ZVYZC9/AsaTgTeqd0CKsa5HkuYZK +y7pGswtNEXyIVX8jEueS9VYMsRuKFjw5FvS+KnL++jFT55NaLDKZU0yuTIMlQ1VPt02 GuZ4wJb+qH+WAaujpK/ebQr6vPJMRXoxVer2SM0JzkNyy+tk/TcyrFS7WoJ2pCpYbc9r VCxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f51si9718593edb.421.2019.10.24.15.19.05; Thu, 24 Oct 2019 15:19:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437859AbfJXHEY (ORCPT + 99 others); Thu, 24 Oct 2019 03:04:24 -0400 Received: from mga01.intel.com ([192.55.52.88]:61925 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727635AbfJXHEY (ORCPT ); Thu, 24 Oct 2019 03:04:24 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2019 00:04:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,223,1569308400"; d="scan'208";a="201382240" Received: from fyin-dev.sh.intel.com ([10.239.143.122]) by orsmga003.jf.intel.com with ESMTP; 24 Oct 2019 00:04:22 -0700 From: Yin Fengwei To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, rjw@rjwysocki.net, rafael@kernel.org, lenb@kernel.org Cc: fengwei.yin@intel.com Subject: [PATCH v4] ACPI/processor_idle: Remove dummy wait if kernel is in guest Date: Thu, 24 Oct 2019 15:04:20 +0800 Message-Id: <20191024070420.4512-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In function acpi_idle_do_entry(), an ioport access is used for dummy wait to guarantee hardware behavior. But it could trigger unnecessary VMexit if kernel is running as guest in virtualization environment. If it's in virtualization environment, the deeper C state enter operation (inb()) will trap to hypervisor. It's not needed to do dummy wait after the inb() call. So we could just remove the dummy io port access to avoid unnecessary VMexit. And keep dummy io port access to maintain timing for native environment. Signed-off-by: Yin Fengwei --- ChangeLog: v3 -> v4: - Drop overengineered function pointer and do check whether we are in guest before dummy inl call. v2 -> v3: - Remove dummy io port access totally for virtualization env. v1 -> v2: - Use ndelay instead of dead loop for dummy delay. drivers/acpi/processor_idle.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ed56c6d20b08..2ae95df2e74f 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -642,6 +642,19 @@ static int acpi_idle_bm_check(void) return bm_status; } +static void wait_for_freeze(void) +{ +#ifdef CONFIG_X86 + /* No delay is needed if we are in guest */ + if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) + return; +#endif + /* Dummy wait op - must do something useless after P_LVL2 read + because chipsets cannot guarantee that STPCLK# signal + gets asserted in time to freeze execution properly. */ + inl(acpi_gbl_FADT.xpm_timer_block.address); +} + /** * acpi_idle_do_entry - enter idle state using the appropriate method * @cx: cstate data @@ -658,10 +671,7 @@ static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx) } else { /* IO port based C-state */ inb(cx->address); - /* Dummy wait op - must do something useless after P_LVL2 read - because chipsets cannot guarantee that STPCLK# signal - gets asserted in time to freeze execution properly. */ - inl(acpi_gbl_FADT.xpm_timer_block.address); + wait_for_freeze(); } } @@ -682,8 +692,7 @@ static int acpi_idle_play_dead(struct cpuidle_device *dev, int index) safe_halt(); else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) { inb(cx->address); - /* See comment in acpi_idle_do_entry() */ - inl(acpi_gbl_FADT.xpm_timer_block.address); + wait_for_freeze(); } else return -ENODEV; } -- 2.19.1