From patchwork Tue Jun 27 22:33:42 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: 781401 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 3wy11Y0CkNz9s81; Wed, 28 Jun 2017 08:34:09 +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="zSfCBHtm"; 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 1dPz3e-00018x-7C; Tue, 27 Jun 2017 22:34:06 +0000 Received: from mail-qt0-f180.google.com ([209.85.216.180]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1dPz3W-00017f-Hm for kernel-team@lists.ubuntu.com; Tue, 27 Jun 2017 22:33:58 +0000 Received: by mail-qt0-f180.google.com with SMTP id r30so36777539qtc.0 for ; Tue, 27 Jun 2017 15:33:58 -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=zSfCBHtm47vN/e4DhJK89EkW1THZ/OyRJ+CznpzhwEhcJeWy5nu5W/DtUCoU6Wt53T D94aoOMaFB/g1a1CSVqTCFTD6KdPW8hmu8ZFK2Dedy8RhPfRtekZNx/Mi6u4vIe83Pjj 3hNaQeHmZURTemrSrmTFNjLCCUqSSEZrC6INVvqdeLCTiejhYu48iCWLqHG3kcpJQvZ/ 79aMknC+LmRkXKhEhUH68r8JZaEYUH1xdfVTQ5ee51URRlLOFE7HgGWD5OVmEhHJTrsz TnU9az/hG1U1O4AYEai32vS9xIdp6AlbWK+sn05sFGFieNUt0aTQfaAkevayNrfj0wlS uMEQ== 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=L4qxvF2C/MNNeX98cge/sfi9+MXf6RAJ7Skn1F8E17E2qbqG+rwdBOARfl2KHhZI/i RMhBdfS6GTdCRWfzONzi7M6ENPVo/WHbwWdSgdKoWq4XuY4xJV1BHHJXVCxK/E0pHvS8 ozuKWYwDD59EpyPPOlD5CZZwZyYTY9Kg9AfXSiKmX27z3/6vXmO4V73R90Of6+/exXQX ZC2WvTFW7vEBzlK8LORhlaZZVmq7KbSriHEoRiWhK43HLtuI94uHJDci7TDPB9oq2huC iLY1R+X6/ZbUc+BcQEDJ68JafBlekwrh0GL14PzdfAkj1NGeLrFd+YziWD5BXVmfFgBx hxNw== X-Gm-Message-State: AKS2vOxaSlJl8fy4CcC9Gwr68fx+iAIyNAM7SVq/BkNyavp4ap16viCo /IPc6F+tyXNcME1gnEY= X-Received: by 10.200.50.249 with SMTP id a54mr9264795qtb.91.1498602837272; Tue, 27 Jun 2017 15:33:57 -0700 (PDT) Received: from localhost.localdomain ([191.8.93.72]) by smtp.gmail.com with ESMTPSA id l88sm390088qte.40.2017.06.27.15.33.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Jun 2017 15:33:56 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [xenial][PATCH 1/4] UBUNTU: SAUCE: hv: make clocksource available for PTP device supporting Date: Tue, 27 Jun 2017 19:33:42 -0300 Message-Id: <1498602825-14211-2-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498602825-14211-1-git-send-email-marcelo.cerri@canonical.com> References: <1498602825-14211-1-git-send-email-marcelo.cerri@canonical.com> Cc: Josh Poulson , "K . Y . Srinivasan" , Stephen Zarkos 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 */