Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp746897imu; Fri, 11 Jan 2019 08:22:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN7/YKhD2xgYDKwlkVTYNRY3q4AZ69izdFEJIfC1icB19cU7Cur+csb/PS2VvqUCs8tLJcZ1 X-Received: by 2002:a62:6503:: with SMTP id z3mr14781766pfb.169.1547223750114; Fri, 11 Jan 2019 08:22:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547223750; cv=none; d=google.com; s=arc-20160816; b=h18LD/xrSMcm+UhCajAa60fJfP9ItR2JM4LVMft26FZ196jbtkdXZ2z3T9rTiROo+f Qf6G9UrRq+CDmwdu3LL11abgr4zFkS8CD3QYYaJQr0umZo6RN/KIcXCa5aIv5CYc88do K0GXmxo/pSDKlWWtiyaPC63JnoePlszK6W6GTtX/W3NPWCQN/zzW+cNLAug1z1CHQw5n w5RMdFYuZnau+3GVbvbezWj/r0UcaDUkYnqzdLAUnZjNbcoZLGUjWurL2Oq9FwMSf5GW t1Nostb2PTkcdOKwP5vP2UHvA+tm9kYTvzMk3fg9b5JOfTBj64FcbJhhBr+JAZEm6zc7 bOuA== 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=gcD654zNo8WchOi7c6NFPSEocDiW3W14oMJJDq92KwA=; b=UfrKF+8UdJWt31/a87RHPhu7kPrLzedi/zsk2fWlshadKsG7LQ7EhFnilaJWRw3Qpt jeL8SLBYxEQoeeK84rzQrfJcu59tn3EevqcxFi7NNgNEBtecvSbwv7R2kOPeoc2I3qKq aDvmT/15eTpeXEifw8lhuPjcuEY/ey365ZRUNqqR6X2CIKa8LcrDiclKgQ117kY6lW3V EuzLRkt4ARK7UFMTuCXybT5CIU7BM4vMewS4aaVywBDal/LUsXAaX0F4czj8p/Kd32ie mgwPVaKPh2fDTWvUGu+CLi+BvN21ExWSTPcP5fLKJpUX3BiHKCqpQzy8gHWdJeOB98zz pjKg== 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 d11si6630273pla.335.2019.01.11.08.22.14; Fri, 11 Jan 2019 08:22:30 -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 S1731743AbfAKMIJ (ORCPT + 99 others); Fri, 11 Jan 2019 07:08:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:45808 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726201AbfAKMII (ORCPT ); Fri, 11 Jan 2019 07:08:08 -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 7653AABD4; Fri, 11 Jan 2019 12:08:07 +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 v2] xen: Fix x86 sched_clock() interface for xen Date: Fri, 11 Jan 2019 13:08:05 +0100 Message-Id: <20190111120805.24852-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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 72bf446c3fee..3c1dfdf26284 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -379,12 +379,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 +407,7 @@ void xen_restore_time_memory_area(void) int ret; if (!xen_clock) - return; + goto out; t.addr.v = &xen_clock->pvti; @@ -421,6 +424,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