Received: by 2002:adf:e804:0:0:0:0:0 with SMTP id o4csp4054790wrm; Mon, 7 Oct 2019 10:06:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmDneYMuK5ca6gio11bwpzMT7onSJ7wt3M1aOBWRBLCpkvqIwQPjzfT6RQgkKqBCTNrsNG X-Received: by 2002:a17:906:5acd:: with SMTP id x13mr25007750ejs.186.1570468008364; Mon, 07 Oct 2019 10:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570468008; cv=none; d=google.com; s=arc-20160816; b=piUwTRGU/ER2SgqvewJXdxnYe8fEzntcTbdEOazfS9sCUbp1sygbkRZv3bimlVd28l RraZvB990RgqGGOHBK8TkO/FgzEFRF+0LdwUo+LlQEQ7tBdgqw9TOKrtrQciPFqQxC4B feIIDjUxZ46A1mTLbrjLJp26KDK1lTbqT03FpUE0V3iszp0CBEjguDNBKUKF/AcLn3OT Puv4Hseq2RsRShl6aIIT8vM4REq6SbCQw0YqxkY2Acho9Xtn+1pz6JLj9TGUEwcgFzxE 8kpy10QvM9cbvAct4f4krOw1TxlFJUbz4zQ1V6If9Mr9Y41GGyZ9pONf1BCNwRHJPBY9 Smkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from; bh=GhsnYfbb/BhsjnXEO5kxxkBKlZ3+E41fmet4Cc0OGe8=; b=rS+gfS+tiWTsVEr9n2kYZbGD9m7YICFu3kIA/9aTbMe+cscFnClNrkhMnG7KQ/scuH pHWhL+5NBtWsFVqYfNFgXLiTe95FwZQIGmRwhb9glZXqEu8Zp4pERXbY6SEwq7/01Z6F KPIQt+qRbYtPqxBZpae/cgy5jqVD1DUSsoECfR4yrpafn8zru2zii3A1fkPomaZEXcBR EIGDAg91xJ2uHQ2+7ych0sqav/AMV3srsMe/74XYL7ouGf7KFRk5z2ZNUHzXq9xSiJNS 4tSLoYlFwvtkGVBR78sWJ4ixodih5wHU26ejz8+FAoghjGzGnb4udqiOtfO+PN342/8D MrrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j21si2347148eja.5.2019.10.07.10.06.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 10:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:47878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWT8-0006F3-Lm for alex.bennee@linaro.org; Mon, 07 Oct 2019 13:06:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36819) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWSq-0006Ew-7J for qemu-arm@nongnu.org; Mon, 07 Oct 2019 13:06:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHWSo-0004nK-Nx for qemu-arm@nongnu.org; Mon, 07 Oct 2019 13:06:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iHWSo-0004mF-Eg; Mon, 07 Oct 2019 13:06:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76F5C308FF23; Mon, 7 Oct 2019 17:06:25 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217635D9C9; Mon, 7 Oct 2019 17:06:23 +0000 (UTC) From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [RFC PATCH 0/5] target/arm/kvm: Provide an option to adjust virtual time Date: Mon, 7 Oct 2019 19:06:17 +0200 Message-Id: <20191007170622.1814-1-drjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 07 Oct 2019 17:06:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, bijan.mottahedeh@oracle.com, maz@kernel.org Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: ks5DguzOtcuF This series is inspired by a series[1] posted by Bijan Mottahedeh about a year ago. The problem described in the cover letter of [1] is easily reproducible and some users would like to have the option to avoid it. However the solution, which is to adjust the virtual counter offset each time the VM transitions to the running state, introduces a different problem, which is that the virtual and physical counters diverge. As described in the cover letter of [1] this divergence is easily observed when comparing the output of `date` and `hwclock` after suspending the guest, waiting a while, and then resuming it. Because this different problem may actually be worse for some users, unlike [1], the series posted here makes the virtual counter offset adjustment optional and not even enabled by default. Besides the adjustment being optional, this series approaches the needed changes differently to apply them in more appropriate locations. Finally, unlike [1], this series doesn't attempt to measure "pause time" itself. Simply using QEMU_CLOCK_VIRTUAL, which only ticks when the VM is not stopped, is sufficient. I've based this series on the SVE series[2] because we're adding a new CPU feature (kvm-adjvtime) and the SVE series introduces CPU feature documentation, probing, and tests that we can then immediately apply to kvm-adjvtime. Additional notes ---------------- Note 1 ------ As described above, when running a guest with kvm-adjtime enabled it will be less likely the guest OS and guest applications get surprise time jumps when they use the virtual counter. However the counter will no longer reflect real time. It will lag behind. If this is a problem then the guest can resynchronize its time from an external source or even from its physical counter. If the suspend/resume is done with libvirt's virsh, and the guest is running the guest agent, then it's also possible to use a sequence like this $ virsh suspend $GUEST $ virsh resume $GUEST $ virsh domtime --sync $GUEST in order to resynchronize a guest right after the resume. Of course there will still be time when the clock is not right, possibly creating confusing timestamps in logs, for example, and the guest must still be tolerant to the time synchronizations. Note 2 ------ Userspace that wants to set KVM_REG_ARM_TIMER_CNT should beware that the KVM register ID is not correct. This cannot be fixed because it's UAPI and if the UAPI headers are used then it can't be a problem. However, if a userspace attempts to create the ID themselves from the register's specification, then they will get KVM_REG_ARM_TIMER_CVAL instead, as the _CNT and _CVAL definitions have their register parameters swapped. Note 3 ------ I didn't test this with a 32-bit KVM host, but the changes to kvm32.c are the same as kvm64.c. So what could go wrong? Test results would be appreciated. =20 [1] https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg05713.html [2] https://patchew.org/QEMU/20191001125845.8793-1-drjones@redhat.com/ Thanks, drew Andrew Jones (5): target/arm/kvm64: kvm64 cpus have timer registers timer: arm: Introduce functions to get the host cntfrq target/arm/kvm: Implement cpu feature kvm-adjvtime tests/arm-cpu-features: Check feature default values target/arm/cpu: Add the kvm-adjvtime CPU property docs/arm-cpu-features.rst | 27 +++++++++++++++++++++- include/qemu/timer.h | 16 +++++++++++++ target/arm/cpu.c | 2 ++ target/arm/cpu.h | 3 +++ target/arm/cpu64.c | 1 + target/arm/kvm.c | 47 ++++++++++++++++++++++++++++++++++++++ target/arm/kvm32.c | 15 ++++++++++++ target/arm/kvm64.c | 16 +++++++++++++ target/arm/kvm_arm.h | 23 +++++++++++++++++++ target/arm/monitor.c | 1 + tests/arm-cpu-features.c | 48 +++++++++++++++++++++++++++++++-------- 11 files changed, 189 insertions(+), 10 deletions(-) --=20 2.20.1