From patchwork Thu Sep 7 19:06:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 811119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3xp91X1Kwcz9t2x; Fri, 8 Sep 2017 05:07:12 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1dq28r-0000Hs-7k; Thu, 07 Sep 2017 19:07:09 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1dq28p-0000FJ-89 for kernel-team@lists.ubuntu.com; Thu, 07 Sep 2017 19:07:07 +0000 Received: from mail-qt0-f200.google.com ([209.85.216.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1dq28o-0003jP-UB for kernel-team@lists.ubuntu.com; Thu, 07 Sep 2017 19:07:07 +0000 Received: by mail-qt0-f200.google.com with SMTP id h15so786266qta.4 for ; Thu, 07 Sep 2017 12:07:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=sHR4vbp6Gi0bLnXEWsykYlGkdUdXjfEX7zvM8dY1G04=; b=MXeassO3OyAU3Zb9d1SPFNHSx5mkN2f/guvqVZdTQ8abeJYSWhV+cDzN+lkrOoYn0a 9teJdhw6Ui9kjFBcQtLAljdI8dfu9mJeiwIr4xshmTA/tiXPN4KTTrE0ntJ3WJBZZsiA dRYnUnou4NCZ047qEF93v3lNQ3uqY0KRoPndtegaOaPckv/yAcPSjy2sY7gPKrpHbn2P yCmb6HygUE5y83qSaPPGZ82r9K7PR8GD7nAKmZo+5U/Ac4bbc2J7gEH3qnJgfMA6lvQ1 kuK/3xnRpVbTDuNrJWuxcSgW8jFrNGcRSLuYcZZEESghQTSHdisgPe9nBw5TSJAfu/2w 3dbg== X-Gm-Message-State: AHPjjUjR3LMYA+PFpoGtcU6vNULAAASPnggJUP6EigvADcdRCM1UlHAt 1Hbp2gOznJRxzlC1owhECFneXmoaRAj31yAClCHydki5Tab9J5kBXatlAStRYw6Dn6SpKyXYFrP Us/lnycnwFieIGz6T/EAvhl/bd3NfmJyN X-Received: by 10.55.46.70 with SMTP id u67mr550858qkh.230.1504811225803; Thu, 07 Sep 2017 12:07:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAlPpcCUFeqIEbxQ66bIWfAIlDGBq5szpY763OAuulO4F7UDtTGRRWHMhQ7kbXKtrsqNDoR/A== X-Received: by 10.55.46.70 with SMTP id u67mr550831qkh.230.1504811225538; Thu, 07 Sep 2017 12:07:05 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:8080:8580:888e:b710:f89:8386]) by smtp.gmail.com with ESMTPSA id d123sm30163qkc.16.2017.09.07.12.07.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Sep 2017 12:07:04 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [azure][PATCH 2/2] x86/hyperv: Read TSC frequency from a synthetic MSR Date: Thu, 7 Sep 2017 16:06:52 -0300 Message-Id: <1504811212-25188-3-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504811212-25188-1-git-send-email-marcelo.cerri@canonical.com> References: <1504811212-25188-1-git-send-email-marcelo.cerri@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vitaly Kuznetsov BugLink: http://bugs.launchpad.net/bugs/1715489 It was found that SMI_TRESHOLD of 50000 is not enough for Hyper-V guests in nested environment and falling back to counting jiffies is not an option for Gen2 guests as they don't have PIT. As Hyper-V provides TSC frequency in a synthetic MSR we can just use this information instead of doing a error prone calibration. Reported-and-tested-by: Ladi Prosek Signed-off-by: Vitaly Kuznetsov Signed-off-by: Thomas Gleixner Cc: Stephen Hemminger Cc: Haiyang Zhang Cc: Jork Loeser Cc: devel@linuxdriverproject.org Cc: "K. Y. Srinivasan" Link: http://lkml.kernel.org/r/20170622100730.18112-3-vkuznets@redhat.com (cherry picked from commit 71c2a2d0a81f096a2932fccb39a500116fece554) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/kernel/cpu/mshyperv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 884fa7c9f192..42664f944cbc 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -161,6 +161,15 @@ static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) } #endif +static unsigned long hv_get_tsc_khz(void) +{ + unsigned long freq; + + rdmsrl(HV_X64_MSR_TSC_FREQUENCY, freq); + + return freq / 1000; +} + static void __init ms_hyperv_init_platform(void) { int hv_host_info_eax; @@ -199,6 +208,12 @@ static void __init ms_hyperv_init_platform(void) hv_host_info_edx >> 24, hv_host_info_edx & 0xFFFFFF); } + if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS && + ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) { + x86_platform.calibrate_tsc = hv_get_tsc_khz; + x86_platform.calibrate_cpu = hv_get_tsc_khz; + } + #ifdef CONFIG_X86_LOCAL_APIC if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS && ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {