Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1743604imu; Thu, 10 Jan 2019 02:12:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN64MWbZGPwpiHbAovTsDsBHNvpr/CUzu41EdwIoU+lNI6CES1RJzeE6C2pvRRF2hP6O8YZm X-Received: by 2002:a63:4b60:: with SMTP id k32mr8730669pgl.186.1547115145602; Thu, 10 Jan 2019 02:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547115145; cv=none; d=google.com; s=arc-20160816; b=MBRZ134hrUIsQN5SwZisMVoLfsSxzIeRqYUMnUeX61dEcuchwiO2qQAESAD0jvr7Jt CWxoKhoI/DqHq9UsnLVxbXqMV4Ib+vpq8EEiN2RemGKuTVQwUPzokfMhWMQuqat2Mw+6 h+vNFljuiBA9hs34Kw/ruNv2qk2x67tuXeb6e1Ul8XjL/77idO81mTT2MZO11f1kN7UI +qXrYKqSrUvZDxy1oAs6vpQJcvFVKyof03S9CJDT+JQE/ynfs6G61I5Ld1rV6b341KZR Qm67OZE2e8srLX9Zsucy0PIYJNUK7Kf50lxRx/2tsiXcuX2AsSanG1ONLkleNVHvJ6Ui /4nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=LDxKR0z3syNzmOAbI2+vfzOSU/34FxwCnsWQn1phs3k=; b=I+8HtrFIV6hECe3GeL3fgtbcIGxuvZjxjWIPspd8TtmV/B2jdxtKJ7QmbW9T1cRNmB B6O7DcC6YHzgSTrgiduZZ/R2tQBjh5YHeVIpRU27mN0SJcvTO101I8kKRBt2itziL5Z5 UP6Uf/7uxqpsd14b6kUW7oeTPyNwTbLWbm/Alwiyi7jrJTaJuaIUGUQb6tW3gdo7UeTD aJX77qLKP8zbZxujsHE7ZMZaMzb0+GolF3bDJTMHRGN+zsCPNbHdfyWMP8GTaIV/UaFo 3OflFoJ5IGv3YvxXo+cYzJLAUymRsXktLYZ1oLV4eVLpW2DhzJ6c9t1ec1dsATPH2+IL h3CQ== 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 l7si10911539pgk.169.2019.01.10.02.12.10; Thu, 10 Jan 2019 02:12:25 -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 S1727694AbfAJKH0 (ORCPT + 99 others); Thu, 10 Jan 2019 05:07:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:36044 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727328AbfAJKH0 (ORCPT ); Thu, 10 Jan 2019 05:07:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A72FAACD1; Thu, 10 Jan 2019 10:07:24 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, x86@kernel.org Cc: boris.ostrovsky@oracle.com, sstabellini@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hans@knorrie.org, Juergen Gross , stable@vger.kernel.org Subject: [PATCH] xen: Fix x86 sched_clock() interface for xen Date: Thu, 10 Jan 2019 11:07:22 +0100 Message-Id: <20190110100722.11216-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit f94c8d11699759 ("sched/clock, x86/tsc: Rework the x86 'unstable' sched_clock() interface") broke Xen guest time handling across migration: [ 187.249951] Freezing user space processes ... (elapsed 0.001 seconds) done. [ 187.251137] OOM killer disabled. [ 187.251137] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. [ 187.252299] suspending xenstore... [ 187.266987] xen:grant_table: Grant tables using version 1 layout [18446743811.706476] OOM killer enabled. [18446743811.706478] Restarting tasks ... done. [18446743811.720505] Setting capacity to 16777216 Fix that by setting xen_sched_clock_offset at resume time to ensure a monotonic clock value. Fixes: f94c8d11699759 ("sched/clock, x86/tsc: Rework the x86 'unstable' sched_clock() interface") Cc: # 4.11 Reported-by: Hans van Kranenburg Signed-off-by: Juergen Gross --- arch/x86/xen/suspend.c | 4 ++++ arch/x86/xen/time.c | 11 +++++++++++ arch/x86/xen/xen-ops.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index 1d83152c761b..45fc9caf3880 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -67,6 +67,8 @@ void xen_arch_resume(void) { int cpu; + xen_clocksource_resume(); + on_each_cpu(xen_vcpu_notify_restore, NULL, 1); for_each_online_cpu(cpu) @@ -81,4 +83,6 @@ void xen_arch_suspend(void) xen_pmu_finish(cpu); on_each_cpu(xen_vcpu_notify_suspend, NULL, 1); + + xen_clocksource_suspend(); } diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 72bf446c3fee..117ce958ffe6 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -32,6 +32,7 @@ #define TIMER_SLOP 100000 static u64 xen_sched_clock_offset __read_mostly; +static u64 xen_clock_value_saved; /* Get the TSC speed from Xen */ static unsigned long xen_tsc_khz(void) @@ -54,6 +55,16 @@ static u64 xen_clocksource_read(void) return ret; } +void xen_clocksource_suspend(void) +{ + xen_clock_value_saved = xen_clocksource_read() - xen_sched_clock_offset; +} + +void xen_clocksource_resume(void) +{ + xen_sched_clock_offset = xen_clocksource_read() - xen_clock_value_saved; +} + static u64 xen_clocksource_get_cycles(struct clocksource *cs) { return xen_clocksource_read(); diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 0e60bd918695..a17d3bdab6b8 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -63,6 +63,8 @@ void __init xen_build_dynamic_phys_to_machine(void); void __init xen_vmalloc_p2m_tree(void); void xen_init_irq_ops(void); +void xen_clocksource_suspend(void); +void xen_clocksource_resume(void); void xen_setup_timer(int cpu); void xen_setup_runstate_info(int cpu); void xen_teardown_timer(int cpu); -- 2.16.4