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 From patchwork Wed Aug 12 18:42:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1343846 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 4BRdqn5VSXz9sR4; Thu, 13 Aug 2020 04:43:01 +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 1k5viE-0003WF-K7; Wed, 12 Aug 2020 18:42:58 +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 1k5vi8-0003Sq-VB for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:52 +0000 Received: from mail-oo1-f71.google.com ([209.85.161.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k5vi8-0006yj-Ka for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:52 +0000 Received: by mail-oo1-f71.google.com with SMTP id v21so1666914ooq.12 for ; Wed, 12 Aug 2020 11:42:52 -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=AOz3/nQChb0eQn7c10/a9KcBjjDvNOOU5Aw6o1bUeh0=; b=nF5sLv2voiP+G6ggJzsM7IScA/AXq35nhIvlgEFiOlH89A1+dl0Ta2nQWel59GdafA 2vKotB7S0hutWa3/Bp1JLRzwRzzva3d6h07N06wxbkiw34OyxUAvOcOvFGjiKCEtdRbE A3PE/yys9zU4b7mktv8p3BhI8Ekyqs6ZUbzXxEzRkNaTF7swhdrlROwS9hC7WnIsjruO Ao/Euumrs68kb98KRDALCIJ1kN6pfZFaUdhijwJPZIJqK6yIJ9eTWo13igI+FANaF/u7 Hm8y6A1fFtd/D4otO2AwHIhfWX5huF1DaPYPGFn9XSOFSwVk+Dy0N0VVBEeQKD3M0FXa cyww== X-Gm-Message-State: AOAM5317JUT1tO6H+9/RHtHoBUngqjQNiFeob92a+MwvFdctELWC6/5R jAjykOeSB/KbC3Ax8Kx2nWsFE0SlFwQaGTufq24xnNQ8SeeQdSGXO2E2vEZqg3fpECq47MYgeA0 FgTXYucpR4Wubv82MVY6u32q4aqC9Cg1OdRRspFjmMg== X-Received: by 2002:aca:b2d4:: with SMTP id b203mr432531oif.88.1597257771045; Wed, 12 Aug 2020 11:42:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDXPHl+WHHlCRwfzdc/Q6zzSoxiDCFhRny1Hod5xa1ZWx3KhKSrBoATRW9F70wFYckFou0cA== X-Received: by 2002:aca:b2d4:: with SMTP id b203mr432503oif.88.1597257770508; Wed, 12 Aug 2020 11:42:50 -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.49 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 2/4] x86/hyperv: Set TSC clocksource as default w/ InvariantTSC Date: Wed, 12 Aug 2020 12:42:44 -0600 Message-Id: <20200812184246.14738-3-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 Change the Hyper-V clocksource ratings to 250, below the TSC clocksource rating of 300. In configurations where Hyper-V offers an InvariantTSC, the TSC is not marked "unstable", so the TSC clocksource is available and preferred. With the higher rating, it will be the default. On older hardware and Hyper-V versions, the TSC is marked "unstable", so no TSC clocksource is created and the selected Hyper-V clocksource will be the default. Signed-off-by: Andrea Parri Reviewed-by: Michael Kelley Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20200109160650.16150-3-parri.andrea@gmail.com (backported from commit 9e0333ae38eeb42249e10f95d209244a6e22ac9f) [KelseyS: changes done in arch/x86/hyperv/hv_init.c instead of drivers/clocksource/hyperv_timer.c] Signed-off-by: Kelsey Skunberg --- arch/x86/hyperv/hv_init.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index ce3bb175d739..a4e61bdfd6f0 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -60,9 +60,18 @@ static u64 read_hv_clock_tsc(struct clocksource *arg) return current_tick; } +/* The Hyper-V clocksource ratings of 250 are chosen to be below the + * TSC clocksource rating of 300. In configurations where Hyper-V offers + * an InvariantTSC, the TSC is not marked "unstable", so the TSC clocksource + * is available and preferred. With the higher rating, it will be the + * default. On older hardware and Hyper-V versions, the TSC is marked + * "unstable", so no TSC clocksource is created and the selected Hyper-V + * clocksource will be the default. + */ + static struct clocksource hyperv_cs_tsc = { .name = "hyperv_clocksource_tsc_page", - .rating = 400, + .rating = 250, .read = read_hv_clock_tsc, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, @@ -83,7 +92,7 @@ static u64 read_hv_clock_msr(struct clocksource *arg) static struct clocksource hyperv_cs_msr = { .name = "hyperv_clocksource_msr", - .rating = 400, + .rating = 250, .read = read_hv_clock_msr, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, 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 From patchwork Wed Aug 12 18:42:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1343845 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 4BRdqm71Bjz9sTN; Thu, 13 Aug 2020 04:43:00 +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 1k5viD-0003V1-36; Wed, 12 Aug 2020 18:42:57 +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 1k5viB-0003Ty-N9 for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:55 +0000 Received: from mail-oi1-f198.google.com ([209.85.167.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k5viB-0006ys-Ba for kernel-team@lists.ubuntu.com; Wed, 12 Aug 2020 18:42:55 +0000 Received: by mail-oi1-f198.google.com with SMTP id c137so1576418oig.6 for ; Wed, 12 Aug 2020 11:42:55 -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=d3j9lWMiTHnqq6rfmZZivNpyTmkNUcHj4USMa6dXB9g=; b=MB6UxCzOS0tJo2pC/3PPngp5Rp5uFULl1NRn+cqJhwZX0CVgOfk//q8qhuvmd7ShmY VV3dTyxsv+ZV6HSxdXiLbvfsdLfUiajp3hXfcjheCEgcDZXmUXSW9Vvw5ZzbUqsWzmuM b1H61y4MB7j5qGJPW6wPZzl+UJ8GNDT1Mb+bXmcXO5p6GDQTACbtQqjM5iJVzs4HtECt xLF3qx8MJ4/FiAQyS44HGVgYr6qra+TCMKdXc2AqjQmXMZaSOH2PbY5BqZ2fIwDIatTq K0Gpo+D99in1bJWKdKQL1oelIsHlJFSuQBxvlXZeZ8aC47cbUqaRbcL1J2xlPXPyMqlR ZGQQ== X-Gm-Message-State: AOAM5335kM5mws1QRsVJZnJKcFtFqZ+bR2zGsXWjdlBnPuVwZ2afce/U VTIVSfRwhUPkINh9DVmlalZmD4rlSu5g1SyQawvazu0M68t+CwG9vU1E9jKm14KBSyY7gj2ZPQt QARIt9tNdR23vkzsT6dihGj9i/1Zl6GC2wKAgsbsPoA== X-Received: by 2002:a9d:53c1:: with SMTP id i1mr991037oth.161.1597257773548; Wed, 12 Aug 2020 11:42:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbvSmiquZwIbe+ZDQ6Wo19mRPio98d/ItX6PtAV9MJWNETM3emWmlflAfxIMW8pizRsjnejw== X-Received: by 2002:a9d:53c1:: with SMTP id i1mr991021oth.161.1597257773244; Wed, 12 Aug 2020 11:42:53 -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.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 11:42:52 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure][SRU][PATCH v2 4/4] clocksource/drivers/hyper-v: Set TSC clocksource as default w/ InvariantTSC Date: Wed, 12 Aug 2020 12:42:46 -0600 Message-Id: <20200812184246.14738-5-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 Change the Hyper-V clocksource ratings to 250, below the TSC clocksource rating of 300. In configurations where Hyper-V offers an InvariantTSC, the TSC is not marked "unstable", so the TSC clocksource is available and preferred. With the higher rating, it will be the default. On older hardware and Hyper-V versions, the TSC is marked "unstable", so no TSC clocksource is created and the selected Hyper-V clocksource will be the default. Signed-off-by: Andrea Parri Reviewed-by: Michael Kelley Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20200109160650.16150-3-parri.andrea@gmail.com (backported from commit 9e0333ae38eeb42249e10f95d209244a6e22ac9f) [KelseyS: context changes to allow backporting] Signed-off-by: Kelsey Skunberg --- drivers/clocksource/hyperv_timer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 3325ec9bc67e..038539ab019a 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -302,6 +302,14 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup); * the other that uses the TSC reference page feature as defined in the * TLFS. The MSR version is for compatibility with old versions of * Hyper-V and 32-bit x86. The TSC reference page version is preferred. + * + * The Hyper-V clocksource ratings of 250 are chosen to be below the + * TSC clocksource rating of 300. In configurations where Hyper-V offers + * an InvariantTSC, the TSC is not marked "unstable", so the TSC clocksource + * is available and preferred. With the higher rating, it will be the + * default. On older hardware and Hyper-V versions, the TSC is marked + * "unstable", so no TSC clocksource is created and the selected Hyper-V + * clocksource will be the default. */ struct clocksource *hyperv_cs; @@ -356,7 +364,7 @@ static void resume_hv_clock_tsc(struct clocksource *arg) static struct clocksource hyperv_cs_tsc = { .name = "hyperv_clocksource_tsc_page", - .rating = 400, + .rating = 250, .read = read_hv_clock_tsc, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, @@ -384,7 +392,7 @@ static u64 read_hv_sched_clock_msr(void) static struct clocksource hyperv_cs_msr = { .name = "hyperv_clocksource_msr", - .rating = 400, + .rating = 250, .read = read_hv_clock_msr, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS,