Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8366054ybl; Thu, 16 Jan 2020 15:26:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzCmqBO2N5/yVAFVbe5VldJ8pxyk8Xe3tiTM9wGlRbsEYTIl/MOovGQ+07//6SsZ7+x2TG/ X-Received: by 2002:aca:481:: with SMTP id 123mr1357841oie.110.1579217199750; Thu, 16 Jan 2020 15:26:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579217199; cv=none; d=google.com; s=arc-20160816; b=oksndPan/8GwgHt4USVkUtzGx28NSdEqarwz5X4mhoLWxk7JgF8zMWL2AX+L5/dD+k NG3WSLpT0YPrrQiMOB8E7NDLEZHPJAF38LLMigBEFD0du5HcY/zJ6vSUOgzvwzWnBPSG /6zmoy/ax1T0MG/+y9mr423s2s6Ek5vzWmSoBBAGSMNzN8YVSz1n//YGn2UM0PGmMa1T 7+d+VJzCARysR7n/W3OdIbYdDJ/GZGuluJRm8pNFSSeIAjzjFkIHA3op1kkrGhnQwZIj fmP8h/6oz7ex0vuu2f5n3OAE+vzqMlnTdzSCJET8E/ZX5QD1AoaRgfKdn9IadP1TuMls x/JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=y5bVS4783RdII9YMpZSh6XJNjOlYJUoR9+raMertSYc=; b=SvSKaiVxkZMR80mfRAP9LiyJgT0QrC9uDztHErJqv1KTI2y+eeq/nbBUfPTbh1ncnm uJyA+6lktO6eSyBd1ar5zyOM7CmPJfiDdsUawgVB+EZ9IT9r548YscvM2KDFJHeaZXz/ 1EmszANrH7q4RomrGhagRp/qtxnaCI5m+3yOsbr9Dp75ZVAT38XDt3BC3pzXE3N/MSSI YCf3xK4/NybjSHpumOY186XaE8lWgLNHddJBK7Q4Oz+30/wrrAru/civfawN0uRDpdmx 2VUO11I78+42puz7gfKT9fmlfi11PABTQbyxzgkBOCj1rEwPwCC/Uy4hU5hsWz1LnejA CEAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7si14478326otl.133.2020.01.16.15.26.28; Thu, 16 Jan 2020 15:26:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389186AbgAPVbV (ORCPT + 99 others); Thu, 16 Jan 2020 16:31:21 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:53577 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389023AbgAPVbM (ORCPT ); Thu, 16 Jan 2020 16:31:12 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1isCjL-0001Zr-N2; Thu, 16 Jan 2020 22:31:07 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 9C4A01C1997; Thu, 16 Jan 2020 22:31:03 +0100 (CET) Date: Thu, 16 Jan 2020 21:31:03 -0000 From: "tip-bot2 for Dexuan Cui" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] clocksource/drivers/hyper-v: Suspend/resume Hyper-V clocksource for hibernation Cc: Dexuan Cui , Michael Kelley , Daniel Lezcano , x86 , LKML In-Reply-To: <1574233946-48377-1-git-send-email-decui@microsoft.com> References: <1574233946-48377-1-git-send-email-decui@microsoft.com> MIME-Version: 1.0 Message-ID: <157921026342.396.802266094475126495.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the timers/core branch of tip: Commit-ID: 1349401ff1aa425e7381ed26feb63e0d6b557fc6 Gitweb: https://git.kernel.org/tip/1349401ff1aa425e7381ed26feb63e0d6b557fc6 Author: Dexuan Cui AuthorDate: Tue, 19 Nov 2019 23:12:26 -08:00 Committer: Daniel Lezcano CommitterDate: Thu, 16 Jan 2020 19:06:57 +01:00 clocksource/drivers/hyper-v: Suspend/resume Hyper-V clocksource for hibernation This is needed for hibernation, e.g. when we resume the old kernel, we need to disable the "current" kernel's TSC page and then resume the old kernel's. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/1574233946-48377-1-git-send-email-decui@microsoft.com --- drivers/clocksource/hyperv_timer.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 287d8d5..1aec08e 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -330,12 +330,37 @@ static u64 read_hv_sched_clock_tsc(void) return read_hv_clock_tsc(NULL) - hv_sched_clock_offset; } +static void suspend_hv_clock_tsc(struct clocksource *arg) +{ + u64 tsc_msr; + + /* Disable the TSC page */ + hv_get_reference_tsc(tsc_msr); + tsc_msr &= ~BIT_ULL(0); + hv_set_reference_tsc(tsc_msr); +} + + +static void resume_hv_clock_tsc(struct clocksource *arg) +{ + phys_addr_t phys_addr = virt_to_phys(&tsc_pg); + u64 tsc_msr; + + /* Re-enable the TSC page */ + hv_get_reference_tsc(tsc_msr); + tsc_msr &= GENMASK_ULL(11, 0); + tsc_msr |= BIT_ULL(0) | (u64)phys_addr; + hv_set_reference_tsc(tsc_msr); +} + static struct clocksource hyperv_cs_tsc = { .name = "hyperv_clocksource_tsc_page", .rating = 400, .read = read_hv_clock_tsc, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, + .suspend= suspend_hv_clock_tsc, + .resume = resume_hv_clock_tsc, }; static u64 notrace read_hv_clock_msr(struct clocksource *arg)