Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3529043imu; Mon, 14 Jan 2019 04:46:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN6vv6Fdsb8vmm/XldcYuZcHOus/kj10tVOIJPOUcz2hld6RFTcy074di2K20ijVEViW88ZU X-Received: by 2002:a63:1013:: with SMTP id f19mr22833881pgl.38.1547469965324; Mon, 14 Jan 2019 04:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547469965; cv=none; d=google.com; s=arc-20160816; b=sDlB3kRcOkuUwEnwrAbtNO/ko6qsu3+HyvnJ+maqdHOR0wPuSGHFE6xAIbR5/62nNA e0ZT3Dgv331RWyC2d53iTG6Va68pbxs6UsP/VGPE8ONjbduPGNCAYimUY+m/M744gstI yKr/FTm46FvY7Zx4SmGWD+YkysPA40XpiwV8VMr+LPxtZ9se+xfIg/ltkhsajMnK7QBY icvKZm1gCS4CmjVvh1bUkG+hfzQj+nHPt4usTWosigSsS+X5swTZtIUVmnjBzPi6zPyh 4ulF8bOkaLRQrG5rAN4GUbrh2h4P3Gg02FYKpMn0gGyuV+0EHJmlWVMLGErqBVfKVlvS wlog== 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=w4Mbt4cwnADeCiiel4qj1pAa0zgbAQaxNJqntkqzodY=; b=uyXsAGaf5ekRdY2xR3JAuPCALXuQmFzOPpZx7K4uP7b2536jemxpgjxz4hPkU1z4nk m7tDla9MdMNXpUOKj441IxMLcbt+AY3Olw3QkayWfk0dTjMqpRDZ93QDnknEDUdgBSb5 UMtHE83P8piROAzXOTydVXuiptcHUau78COB81deK4oIpd7+EPCX4zsSVu6cdBEANJF/ +intE+IFbeYxjBs8CbWzBe04U8m6CW0H/GL92YY5bG21K0Qjv8t6KncU4TYVYC8BVfWj GJ8q5BReas4JUvp1okJ5mc6SVwBTSc1/0CVvjALbELouwpeNF8HdEt3V+Yt9fvLEWXCn OjGg== 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 b12si286512plx.159.2019.01.14.04.45.49; Mon, 14 Jan 2019 04:46:05 -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 S1726631AbfANMoR (ORCPT + 99 others); Mon, 14 Jan 2019 07:44:17 -0500 Received: from mx2.suse.de ([195.135.220.15]:34934 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726467AbfANMoQ (ORCPT ); Mon, 14 Jan 2019 07:44:16 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 522C1AB7D; Mon, 14 Jan 2019 12:44:15 +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 v3] xen: Fix x86 sched_clock() interface for xen Date: Mon, 14 Jan 2019 13:44:13 +0100 Message-Id: <20190114124413.3742-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/time.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 72bf446c3fee..6e29794573b7 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -361,8 +361,6 @@ void xen_timer_resume(void) { int cpu; - pvclock_resume(); - if (xen_clockevent != &xen_vcpuop_clockevent) return; @@ -379,12 +377,15 @@ static const struct pv_time_ops xen_time_ops __initconst = { }; static struct pvclock_vsyscall_time_info *xen_clock __read_mostly; +static u64 xen_clock_value_saved; void xen_save_time_memory_area(void) { struct vcpu_register_time_memory_area t; int ret; + xen_clock_value_saved = xen_clocksource_read() - xen_sched_clock_offset; + if (!xen_clock) return; @@ -404,7 +405,7 @@ void xen_restore_time_memory_area(void) int ret; if (!xen_clock) - return; + goto out; t.addr.v = &xen_clock->pvti; @@ -421,6 +422,11 @@ void xen_restore_time_memory_area(void) if (ret != 0) pr_notice("Cannot restore secondary vcpu_time_info (err %d)", ret); + +out: + /* Need pvclock_resume() before using xen_clocksource_read(). */ + pvclock_resume(); + xen_sched_clock_offset = xen_clocksource_read() - xen_clock_value_saved; } static void xen_setup_vsyscall_time_info(void) -- 2.16.4