From patchwork Fri Jun 30 19:21:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 782955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3wzmcP14sqz9s81; Sat, 1 Jul 2017 05:21:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b="y5eiZTsj"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1dR1UI-0003dr-CW; Fri, 30 Jun 2017 19:21:54 +0000 Received: from mail-qk0-f181.google.com ([209.85.220.181]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1dR1UA-0003bC-Ju for kernel-team@lists.ubuntu.com; Fri, 30 Jun 2017 19:21:46 +0000 Received: by mail-qk0-f181.google.com with SMTP id d78so108382585qkb.1 for ; Fri, 30 Jun 2017 12:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CiQf4MWsWgWNGay4rbJB5UW0h7v9cLeXHmQH0yPyZlw=; b=y5eiZTsj9AnPieUbNVFr8hqtQOa7E8r77ClNrqWEEI/xK9dCsnFmpC55M97eEcJzPq dvcntDoFwcQ4xjywmjtiM5v2NS2gp4fhBML+I738XeUf7SGtjHxce6XCH+gMGYgcwdRw R/RwJeliUa5NhuVxar59X1zjQYvL4z9vIKTFlemYnJg3tAVjfp7/nYdHjhKKgk1Lsba5 E9V1+C2xKy8oucfHLuOwPNNsPPWyrGcGu5pJxHsMUhueG/8T91ledE84V2w7Bp0Aot8M 3T30FPZnKG9I3izIZB0X0PIuTOiLJNyXCWFHFf628blRehoJsnx/UO6oQEFVeW5wMYRI kD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CiQf4MWsWgWNGay4rbJB5UW0h7v9cLeXHmQH0yPyZlw=; b=fenvwogLNTsyIw9cTMnsAwIgA92zdlNhTIrJ/S39jQBuYbz+dSsMwllfa1r3bpcDxl HlZ9U88DErKPyE94oUIXauXa4iAt+TuO3JmXd+yGF/eak0umBwxKmHzEFP+GpvPXmwG5 TlQPJepUpy+eysCa2jnsLdR6nz1CPC2C45dVER3dpm0UReMLx1xHkjW7bTbaEvlTpSsi 2kWb2O1+YNbOJl6hkyvLPPg/AzsZMIuFmeH9uwygxorubRX/M7xLUnAZ+i91jMEfN7XN 5y3BZk581q9dlsJSEtPUyM/UbzUSd5d0QPObB9c+JJTbn5NvJTkjv1G0WAl0UQpMF3lS KR0A== X-Gm-Message-State: AKS2vOwzg7aL+Abvixp2b3VTo/rQgCq9ag1RPaloDV/M91w+UxJoOHcT F1Y8ubpWadeaogIc6P4= X-Received: by 10.55.80.2 with SMTP id e2mr28289758qkb.43.1498850505313; Fri, 30 Jun 2017 12:21:45 -0700 (PDT) Received: from localhost.localdomain ([191.8.93.72]) by smtp.gmail.com with ESMTPSA id p24sm6945617qki.49.2017.06.30.12.21.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jun 2017 12:21:44 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [xenial][PATCH v2 1/8] UBUNTU: SAUCE: hv: make clocksource available for PTP device supporting Date: Fri, 30 Jun 2017 16:21:27 -0300 Message-Id: <1498850494-31277-2-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498850494-31277-1-git-send-email-marcelo.cerri@canonical.com> References: <1498850494-31277-1-git-send-email-marcelo.cerri@canonical.com> Cc: alexng@microsoft.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com BugLink: http://bugs.launchpad.net/bugs/1676635 Make the MSR and TSC clock sources available during the hv_init() and export them via hyperv_cs in a similar way as the following upstream commit does: commit dee863b571b0 ("hv: export current Hyper-V clocksource") Signed-off-by: Marcelo Henrique Cerri --- arch/x86/kernel/cpu/mshyperv.c | 23 ----------------------- drivers/hv/hv.c | 36 +++++++++++++++++++++++++++++++++++- drivers/hv/hyperv_vmbus.h | 3 +++ 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 668df428f8ad..8ffd894d4b8e 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -134,26 +134,6 @@ static uint32_t __init ms_hyperv_platform(void) return 0; } -static cycle_t read_hv_clock(struct clocksource *arg) -{ - cycle_t current_tick; - /* - * Read the partition counter to get the current tick count. This count - * is set to 0 when the partition is created and is incremented in - * 100 nanosecond units. - */ - rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick); - return current_tick; -} - -static struct clocksource hyperv_cs = { - .name = "hyperv_clocksource", - .rating = 400, /* use this when running on Hyperv*/ - .read = read_hv_clock, - .mask = CLOCKSOURCE_MASK(64), - .flags = CLOCK_SOURCE_IS_CONTINUOUS, -}; - static unsigned char hv_get_nmi_reason(void) { return 0; @@ -209,9 +189,6 @@ static void __init ms_hyperv_init_platform(void) "hv_nmi_unknown"); #endif - if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE) - clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100); - #ifdef CONFIG_X86_IO_APIC no_timer_check = 1; #endif diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 176ee7d4c243..92fb168a6633 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -191,6 +191,28 @@ static struct clocksource hyperv_cs_tsc = { }; #endif +static cycle_t read_hv_clock_msr(struct clocksource *arg) +{ + cycle_t current_tick; + /* + * Read the partition counter to get the current tick count. This count + * is set to 0 when the partition is created and is incremented in + * 100 nanosecond units. + */ + rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick); + return current_tick; +} + +static struct clocksource hyperv_cs_msr = { + .name = "hyperv_clocksource_msr", + .rating = 400, /* use this when running on Hyperv*/ + .read = read_hv_clock_msr, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +struct clocksource *hyperv_cs; +EXPORT_SYMBOL_GPL(hyperv_cs); /* * hv_init - Main initialization routine. @@ -254,9 +276,11 @@ int hv_init(void) va_tsc = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL); if (!va_tsc) - goto cleanup; + goto register_msr_cs; hv_context.tsc_page = va_tsc; + hyperv_cs = &hyperv_cs_tsc; + rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr.as_uint64); tsc_msr.enable = 1; @@ -266,6 +290,16 @@ int hv_init(void) clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); } #endif + /* + * For 32 bit guests just use the MSR based mechanism for reading + * the partition counter. + */ + +register_msr_cs: + hyperv_cs = &hyperv_cs_msr; + if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE) + clocksource_register_hz(&hyperv_cs_msr, NSEC_PER_SEC/100); + return 0; cleanup: diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 8d7f865c1133..f75729b5aed6 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -29,6 +29,7 @@ #include #include #include +#include /* * Timeout for services such as KVP and fcopy. @@ -719,4 +720,6 @@ enum hvutil_device_state { HVUTIL_DEVICE_DYING, /* driver unload is in progress */ }; +extern struct clocksource *hyperv_cs; + #endif /* _HYPERV_VMBUS_H */