From patchwork Wed Aug 12 18:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1343843 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BRdqj24xbz9sTQ; Thu, 13 Aug 2020 04:42:57 +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 1k5viA-0003TH-Hw; Wed, 12 Aug 2020 18:42:54 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k5vi7-0003SX-Mw for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:51 +0000 Received: from mail-ot1-f71.google.com ([209.85.210.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k5vi7-0006yc-BO for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:51 +0000 Received: by mail-ot1-f71.google.com with SMTP id y9so1233535otq.8 for ; Wed, 12 Aug 2020 11:42:51 -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:mime-version:content-transfer-encoding; bh=Nis1K/7ADB3yb/yGABRmK3tlkZLko8b4VRD+2UF1l1A=; b=FOAx98M9PTd/ZrZNn0SE3qcdukPD7P8fvCVXHe9XIAadoe05Xkruyn1Pqat63WkeFz 4EXDe5xgV0kYtftvOMepeIMLWpaCq+NuQLUxGnrxdUm+7maPLKwmwGojM6Xet4anAP2M U9T2EZ2cXwnEVE/xgxzm+vlisqihmPHJZ+gChpEkznzyzOOo3nYfNEAxhc9t3ELGeWuL rJmjzNUwsc5+FJHg2g0t5LlJK3tuBYLKFSQtBgNeAIxRh/TVHcZmAFJ6gnvDWgBPLERB Q0xNCkGAOLy+C27bKt9b5HKQJBbQ9BXe7Gz5WuOXfVr86aen9G10t6yABRYnOrdnDMO1 JcHA== X-Gm-Message-State: AOAM531MIk0P4mxO7BOrdCbKuAiC5BByV9vmpdi6LRHRf7yJ7yTqOnhR k+orSngX1y09T/h2VikOi6qbm3Kof5qFGlgF5kttGbTemk5xI1P9qb6/Cuit4DLbL9nLkF4Yjo4 Z4Uy0jzqPwPo+9HwMb8sS1SxMQ/gO8EdtjZPA7ou/Iw== X-Received: by 2002:a9d:3d77:: with SMTP id a110mr968500otc.11.1597257769844; Wed, 12 Aug 2020 11:42:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvp0KfLrmVHAYRK/jW1hTy1s/fovs6qKleH9h5oh90HG50w4w+WEolJF172GoVn5vnmu1SDg== X-Received: by 2002:a9d:3d77:: with SMTP id a110mr968483otc.11.1597257769582; Wed, 12 Aug 2020 11:42:49 -0700 (PDT) Received: from localhost.localdomain (c-73-243-191-173.hsd1.co.comcast.net. [73.243.191.173]) by smtp.gmail.com with ESMTPSA id x70sm644522oif.3.2020.08.12.11.42.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 11:42:49 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [bionic:linux-azure-4.15][SRU][PATCH v2 1/4] x86/hyperv: Allow guests to enable InvariantTSC Date: Wed, 12 Aug 2020 12:42:43 -0600 Message-Id: <20200812184246.14738-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200812184246.14738-1-kelsey.skunberg@canonical.com> References: <20200812184246.14738-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 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: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Andrea Parri BugLink: https://bugs.launchpad.net/bugs/1875467 If the hardware supports TSC scaling, Hyper-V will set bit 15 of the HV_PARTITION_PRIVILEGE_MASK in guest VMs with a compatible Hyper-V configuration version. Bit 15 corresponds to the AccessTscInvariantControls privilege. If this privilege bit is set, guests can access the HvSyntheticInvariantTscControl MSR: guests can set bit 0 of this synthetic MSR to enable the InvariantTSC feature. After setting the synthetic MSR, CPUID will enumerate support for InvariantTSC. Signed-off-by: Andrea Parri Signed-off-by: Thomas Gleixner Reviewed-by: Michael Kelley Reviewed-by: Vitaly Kuznetsov Link: https://lkml.kernel.org/r/20191003155200.22022-1-parri.andrea@gmail.com (backported from commit dce7cd62754b5d4a6e401b8b0769ec94cf971041) [KelseyS: context changes to allow backporting.] Signed-off-by: Kelsey Skunberg --- arch/x86/include/asm/hyperv-tlfs.h | 5 +++++ arch/x86/kernel/cpu/mshyperv.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index e1e0acb68a61..0ffd581c9041 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -49,6 +49,8 @@ /* AccessReenlightenmentControls privilege */ #define HV_X64_ACCESS_REENLIGHTENMENT BIT(13) +/* AccessTscInvariantControls privilege */ +#define HV_X64_ACCESS_TSC_INVARIANT BIT(15) /* * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM @@ -315,6 +317,9 @@ struct hv_reenlightenment_control { #define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107 #define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108 +/* TSC invariant control */ +#define HV_X64_MSR_TSC_INVARIANT_CONTROL 0x40000118 + struct hv_tsc_emulation_control { u64 enabled:1; u64 reserved:63; diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index a06aeb529eda..a58ed12f7342 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -236,7 +236,12 @@ static void __init ms_hyperv_init_platform(void) machine_ops.shutdown = hv_machine_shutdown; machine_ops.crash_shutdown = hv_machine_crash_shutdown; #endif - mark_tsc_unstable("running on Hyper-V"); + if (ms_hyperv.features & HV_X64_ACCESS_TSC_INVARIANT) { + wrmsrl(HV_X64_MSR_TSC_INVARIANT_CONTROL, 0x1); + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); + } else { + mark_tsc_unstable("running on Hyper-V"); + } /* * Generation 2 instances don't support reading the NMI status from