From patchwork Wed Jun 10 05:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1306462 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 49hbHT5Qqvz9sSd; Wed, 10 Jun 2020 15:33:08 +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 1jitMD-0000w4-VW; Wed, 10 Jun 2020 05:33:01 +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 1jitMC-0000vH-DQ for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 05:33:00 +0000 Received: from mail-oi1-f200.google.com ([209.85.167.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jitMC-0005IX-2s for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 05:33:00 +0000 Received: by mail-oi1-f200.google.com with SMTP id v8so536771oiv.16 for ; Tue, 09 Jun 2020 22:33:00 -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=vleuLdXy3RFsLr7Bbwv1CVbzjIeL4uitC8BQNz5Dni8=; b=HVeP58d0eR1PJ0iXoxS/LaHkx/JJn0R2NJN3dvTu91g3W+hj5p/oNWUbxbt5hqeifC r5Y59gMiXhjwbZ10SupUpRNSPO290r6HKCwYjxx28driRjZM9/ewIt4dZ40ncDQawLtR OVCkJzjCOPjmPJFBX58W0WMRwhnpeU6kWWMHa9WDCucCzil9LjptjapLSVHVb64uY51X Gf2obvoqN4DMfKP88qc3BnLu4ETdWep49X2yALuaFW6ZL8ae/i3psugz05bgiKbj6gfv O8DYEI/dV0RhCkPpc/CAuPmFRbv7LUruARsgsZt0me81MzZiSXcGhvFXtzEwG24iMirF CPig== X-Gm-Message-State: AOAM532yUeFVZ5+q5DCfV/RZHfSq7JHgsACU+kw9zJmrSKBNOu1s/Mc3 Ct8tCpoVB3ogNPTsem0/35kEAOJZffeirq55pMGuyiLeBgD02RUPwpmRbb/cbzZz7mM3elO3dii 2F3jWxO9y6vPh38FXt4gnSUx5J1i/osNodIETjWhHgA== X-Received: by 2002:a4a:c56:: with SMTP id n22mr1083733ooe.72.1591767178847; Tue, 09 Jun 2020 22:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwleEqHnBfLFBxSztUSeA665LuzbxgKJ7HkBy9WBY1YS3ap+1w+r3ypmT57jeX4TvUTJFUvtg== X-Received: by 2002:a4a:c56:: with SMTP id n22mr1083719ooe.72.1591767178452; Tue, 09 Jun 2020 22:32:58 -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 w185sm3696583oiw.14.2020.06.09.22.32.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 22:32:58 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure/eoan:linux-azure][PATCH 1/2] x86/hyperv: Allow guests to enable InvariantTSC Date: Tue, 9 Jun 2020 23:32:54 -0600 Message-Id: <20200610053255.68140-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200610053255.68140-1-kelsey.skunberg@canonical.com> References: <20200610053255.68140-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: http://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 af78cd72b8f3..740b71efc912 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -76,6 +76,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 @@ -260,6 +262,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 f561f01d9813..f6611dad2fc3 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -295,7 +295,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 Jun 10 05:32:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1306464 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 49hbHT56SVz9sSF; Wed, 10 Jun 2020 15:33:08 +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 1jitMF-0000wq-ES; Wed, 10 Jun 2020 05:33:03 +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 1jitMD-0000vV-I6 for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 05:33:01 +0000 Received: from mail-oi1-f197.google.com ([209.85.167.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jitMD-0005If-6O for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 05:33:01 +0000 Received: by mail-oi1-f197.google.com with SMTP id l197so541716oih.11 for ; Tue, 09 Jun 2020 22:33:01 -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=8+gwsbUY3Bv9Sy0uj3B0ieURV7I8eJp8KWRp4QC9bdc=; b=EYPGraZN03jQmWYR+7us0jQUmWXtFLL23mX7hPe6cJ9zEMovrE7/0QxVjtLkmC5AHx vCaZir/c7dCIbmybAutnZdSmvZ9Sp6Mk9JA6LP94wDAqctxfq8sOdYLU0t/NtCdNJNAp F/J9QtcoOGs0Ef5inGuydAgEW6C5qG8va69FUtWDAQMnxiMrAp6sbzJt+Vr9WzZeQsBy ZVCwX6mPeHvTXe0gRRC+5sxRM/0oeNRXuYN8z0D+3SsFKeBP1t0bl18BrmKsAEATfh4O wRrNg5Jo1v4VCJIZtsgacjuY0A1JgSZ7KQmMNHenUkUr9Q2DhFHIYdfZTEQDqN14Y8+E xWqQ== X-Gm-Message-State: AOAM532kWCvEsJrknsDH1XX/Ga1hrp6rDAca3naZrfttgJboo6LCyj6k dpEid9/bBrFDhV8Y1J9HHFLFNZyGbT33H/U+nBEvTTChs2JEJTOwrFrcBN5ZieCCEeeympxPTFm hY+TqlTJF2LY1oCC23JRHyNCx8qUU9rkCVLeGwcnZkQ== X-Received: by 2002:a05:6830:6:: with SMTP id c6mr1308033otp.62.1591767179879; Tue, 09 Jun 2020 22:32:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlKTt0Wdodt2FmCwUMrXVtiiyyLzBoezBG87N0TrY2lL6Z1SEe69eD+QottiuDRFgkRDzlLA== X-Received: by 2002:a05:6830:6:: with SMTP id c6mr1308025otp.62.1591767179608; Tue, 09 Jun 2020 22:32:59 -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 w185sm3696583oiw.14.2020.06.09.22.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 22:32:59 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [focal:linux-azure/eoan:linux-azure][PATCH 2/2] clocksource/drivers/hyper-v: Set TSC clocksource as default w/ InvariantTSC Date: Tue, 9 Jun 2020 23:32:55 -0600 Message-Id: <20200610053255.68140-3-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200610053255.68140-1-kelsey.skunberg@canonical.com> References: <20200610053255.68140-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: http://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 (cherry picked from commit 9e0333ae38eeb42249e10f95d209244a6e22ac9f) 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 ba2c79e6a0ee..5abc3872bba1 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -207,6 +207,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; @@ -239,7 +247,7 @@ static u64 read_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, @@ -265,7 +273,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,