From patchwork Wed Aug 12 18:42:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1343844 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 4BRdql08Hcz9sTS; Thu, 13 Aug 2020 04:42:59 +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 1k5viB-0003U4-Pc; Wed, 12 Aug 2020 18:42:55 +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 1k5vi9-0003T2-Tm for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:53 +0000 Received: from mail-oo1-f70.google.com ([209.85.161.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k5vi9-0006yn-I0 for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:53 +0000 Received: by mail-oo1-f70.google.com with SMTP id d20so1681512ooh.2 for ; Wed, 12 Aug 2020 11:42:53 -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=ok/L9oMT3RIjO6gitY8t1g/YoIs2Xm6q03bOmxFsGJg=; b=Y0MZf+hz+ny3mlGh016wnngIc3Rjhc8lpAHAujbXMmQmgHJW4rorljbXYcctKr6sZz kg+ud6ulvh3cGl5IwvKKXT6s2xj14rEM+A68ZV5/xtXBOd4Iq29LpEG7bpC0hYJYwDUf IbOpFEIYJP0sq19dH4TdhNDpJQ9c4CUelq3NnQgWJG/zq0MGXQrQ1qGmzu7JhluwGx4U Ay1Y7ubV+m4q3sH7fb/E89SHmVlEhlsy41u1zZnwDNi2NcY07wokJCm7o+8xw1QdYSu3 2X4Wb2fPJbbIzxFCn/t20+isJbnCekK9hxOPlQpJlmp1xeeGnNlgGtEHxhuDkA+PUKaS 9uNw== X-Gm-Message-State: AOAM533Y+CaLwrPTtSYQLVh1VBcJMz0JNDC73mkKyqJ8a1wvaRNhHY4p d0eZ+wUWRAkfzP/6QxzHsrTB09qZ5JsaG5xOlWCLQTwXDlvHuQorGvoqZLaqbPfd8sSqqJUnN7Q +8RV4Ylnb9IiKVy/6Co5YMPF4g/Q2ZhUzslmS8qlN+w== X-Received: by 2002:aca:2818:: with SMTP id 24mr400015oix.83.1597257771904; Wed, 12 Aug 2020 11:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd5Ht6H276v9T73Y3oY7MWOKRnX15Gr0EgBCqDHsV+OptKMQaoaQmG1Zu+XPG4I+8jV7HADg== X-Received: by 2002:aca:2818:: with SMTP id 24mr400004oix.83.1597257771680; Wed, 12 Aug 2020 11:42:51 -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.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 11:42:50 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][SRU][PATCH v2 3/4] x86/hyperv: Allow guests to enable InvariantTSC Date: Wed, 12 Aug 2020 12:42:45 -0600 Message-Id: <20200812184246.14738-4-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 (cherry picked from commit dce7cd62754b5d4a6e401b8b0769ec94cf971041) 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 7741e211f7f5..5f10f7f2098d 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -86,6 +86,8 @@ #define HV_X64_ACCESS_FREQUENCY_MSRS BIT(11) /* AccessReenlightenmentControls privilege */ #define HV_X64_ACCESS_REENLIGHTENMENT BIT(13) +/* AccessTscInvariantControls privilege */ +#define HV_X64_ACCESS_TSC_INVARIANT BIT(15) /* * Feature identification: indicates which flags were specified at partition @@ -278,6 +280,9 @@ #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 + /* * Declare the MSR used to setup pages used to communicate with the hypervisor. */ diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 1c2f9baf8483..ebf34c7bc8bc 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -300,7 +300,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