From patchwork Wed Jun 10 04:20:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1306389 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 49hYgb3Ds5z9sRW; Wed, 10 Jun 2020 14:20:27 +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 1jisDw-00059s-LI; Wed, 10 Jun 2020 04:20:24 +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 1jisDl-00057P-0g for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 04:20:13 +0000 Received: from mail-ot1-f69.google.com ([209.85.210.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jisDk-0000cl-Le for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 04:20:12 +0000 Received: by mail-ot1-f69.google.com with SMTP id t10so453771otl.19 for ; Tue, 09 Jun 2020 21:20:12 -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=jGMRRWDuiUfuFCb3js6iJEGoazh7rwChaNngNrWPJzs=; b=BKg5JPEHE6naXVPCL2X6kaAt81w2LdVCuylNGQMRbMjsVA2trX8I+naf4akUbuZi/7 hTBGa8D+yPJrLYeIDQeIRIdS5v/UIGh50JFi9xcRgiEDePhjaBVeW9OIoM0gjY6OPKeT E//cKbgRKt20qdAjDErjAc3kzAmfJTlODoyDQKojuodQpS3Se9J1bvAVjR8t9lhE7DUG SlsLAg7WMQ8tM/uR1ILmOzNsVd9AsnmgwX+UMhWUyALF9K8ZdeCW8o5JR4LN9rILOdjc U72rQdZTjOEtQOzTG4SqAVvq6OherU/c2FrrPvgtCKEt+w9Buv7q8yIl9oFqsYiK3xBB bCvQ== X-Gm-Message-State: AOAM530coluxrLkCrO8f80bJk9GLoSbs/YzedBVMn1dIAEUumt4F8aET BShgdJuaVpIEIdG3S8TTtZ2eseLVYAuOkeZhMVP4OZfr/edJMX7YylhWkcAYw/KbITFjdXAYpmg p1NlgsHt0K17+SdvSpqCAiBlwluaUZ1n2Y+uQngfuTg== X-Received: by 2002:a05:6830:60c:: with SMTP id w12mr1103454oti.45.1591762811452; Tue, 09 Jun 2020 21:20:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLYspLaak+KVCYNbK3Ib1DuecjbDQq8xCwD6l309t0cI1L8V28Dk2FVSE2Dx1fimpZH+Y9Rg== X-Received: by 2002:a05:6830:60c:: with SMTP id w12mr1103447oti.45.1591762811224; Tue, 09 Jun 2020 21:20:11 -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 19sm2626688otf.51.2020.06.09.21.20.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 21:20:10 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [bionic:linux-azure-4.15][PATCH 1/2] x86/hyperv: Allow guests to enable InvariantTSC Date: Tue, 9 Jun 2020 22:20:07 -0600 Message-Id: <20200610042008.61336-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200610042008.61336-1-kelsey.skunberg@canonical.com> References: <20200610042008.61336-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 (backported from commit dce7cd62754b5d4a6e401b8b0769ec94cf971041) Signed-off-by: Kelsey Skunberg --- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kernel/cpu/mshyperv.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index e1e0acb68a61..6298f6cdd0f6 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -50,6 +50,9 @@ /* 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 * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available @@ -315,6 +318,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 Jun 10 04:20:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1306387 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 49hYgV4F31z9sSS; Wed, 10 Jun 2020 14:20:22 +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 1jisDr-000587-C9; Wed, 10 Jun 2020 04:20:19 +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 1jisDl-00057W-Tu for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 04:20:13 +0000 Received: from mail-ot1-f69.google.com ([209.85.210.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jisDl-0000ct-KC for kernel-team@lists.ubuntu.com; Wed, 10 Jun 2020 04:20:13 +0000 Received: by mail-ot1-f69.google.com with SMTP id y4so457311oto.15 for ; Tue, 09 Jun 2020 21:20:13 -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=RHdXbUHSU0cZLEvy5qQv/weaS0KZg7kvq9MsHwnLciw=; b=tLLa6pX71FURXSkmA5pT4LRjnTbVgGupPEggVTAF7mVgedw9Q0Gny+R6RD+LACCEXu Anc4ujAUqbF7nM7hoXRM3o3gwCqK9lTTV3oba+4tp8Ju4Ce0+Ff46/Xs2W0mBoPv6vGO rG2MGG0bbGQJKLjDcHVlcKQFweqJHpvEDX3C3+sCcax7VoR8fCYfc8ZiaaIeVfiRMsxC ysZRc1SOf+irkbGgcTeizYwi//ibvcLZzyCVuzHwbdq6C6juFVH1jK8lvF1pT1P1+nY4 2PERsEXWjw21iHGuh0qzxLnUWgF6tVUnNr1U1WpwQaQzYWzYpuQo49w5nMFaBdw9BOhX r3NA== X-Gm-Message-State: AOAM531pzQdPw2KKdtbjXW1qvAtMVubpPqgAxvxNYd8UsC5ypnnQIVWm cIPAQ6YCCoq0PThOL2BuWHSAh732Ha4RKe+NzZGdqsuNHzYcLxjsIZvM3J4zjFHZ8WD5G+kw3wI cQhlg7Z2Uzncdk7UvBZb13XzjbGGPIzCT6+Oe+Hv5XA== X-Received: by 2002:a9d:6546:: with SMTP id q6mr1131908otl.365.1591762812421; Tue, 09 Jun 2020 21:20:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweic/UX0169Vpv/p1uKNiuVhC2n/VnYR3FimKhktxbLsPLJQsWAmKTZxEpSd3DEiND8UgPVw== X-Received: by 2002:a9d:6546:: with SMTP id q6mr1131903otl.365.1591762812150; Tue, 09 Jun 2020 21:20:12 -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 19sm2626688otf.51.2020.06.09.21.20.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 21:20:11 -0700 (PDT) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [bionic:linux-azure-4.15][PATCH 2/2] x86/hyperv: Set TSC clocksource as default w/ InvariantTSC Date: Tue, 9 Jun 2020 22:20:08 -0600 Message-Id: <20200610042008.61336-3-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200610042008.61336-1-kelsey.skunberg@canonical.com> References: <20200610042008.61336-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 (backported from commit 9e0333ae38eeb42249e10f95d209244a6e22ac9f) [KelseyS: Changes are the same, though 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,