From nobody Mon Feb 9 10:32:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570468704; cv=none; d=zoho.com; s=zohoarc; b=ag0JAFAiYNSilf8h1jBZBAffkBwLLjKuT2SHvvkeUzKysag2uJh7IzIWUfLrnCzEuk0LuNXHYExvNCQ1mlqB7ruv1Kns7/BfbE0Apd+jua31waiIBpXutbRd3Bq6NTnRdge1M6wt5ex5QKovoPiI/KVOXzXc7nBLh3o4LoNx9+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570468704; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Rc+crDEzJI9Ct0JbyFQMRMok9bXtrzxvw4oEmUGcqQk=; b=elAMSMuk4pzKF33G5WnnCnaETGeI3JP9ZSVavI0cCEvpWvgyLfhMezysKteQhNkddXW/JNts9Txml9gPHoUMHMsxx2WCoOuDwTGXdhvgVggt3KlwvU4WCV5/enfbkhcqkHlzeVtacYa13PBEVaApC8sY/W+6Sg/S604h6SKbWVk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570468704371234.74432507433482; Mon, 7 Oct 2019 10:18:24 -0700 (PDT) Received: from localhost ([::1]:48038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWeN-0000pj-5V for importer@patchew.org; Mon, 07 Oct 2019 13:18:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36956) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHWT4-0006PP-II for qemu-devel@nongnu.org; Mon, 07 Oct 2019 13:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHWT2-0004s9-VL for qemu-devel@nongnu.org; Mon, 07 Oct 2019 13:06:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iHWSz-0004qW-IU; Mon, 07 Oct 2019 13:06:37 -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 5A21A307CDD1; Mon, 7 Oct 2019 17:06:36 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1275E5D9C9; Mon, 7 Oct 2019 17:06:34 +0000 (UTC) From: Andrew Jones To: qemu-devel@nongnu.org, qemu-arm@nongnu.org Subject: [RFC PATCH 5/5] target/arm/cpu: Add the kvm-adjvtime CPU property Date: Mon, 7 Oct 2019 19:06:22 +0200 Message-Id: <20191007170622.1814-6-drjones@redhat.com> In-Reply-To: <20191007170622.1814-1-drjones@redhat.com> References: <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:36 +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-devel@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-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" kvm-adjvtime is a KVM specific CPU property and a first of its kind. To accommodate it we also add kvm_arm_add_vcpu_properties() and a KVM specific CPU properties description to the CPU features document. Signed-off-by: Andrew Jones Reviewed-by: Richard Henderson --- docs/arm-cpu-features.rst | 27 ++++++++++++++++++++++++++- target/arm/cpu.c | 2 ++ target/arm/cpu64.c | 1 + target/arm/kvm.c | 27 +++++++++++++++++++++++++++ target/arm/kvm_arm.h | 11 +++++++++++ target/arm/monitor.c | 1 + tests/arm-cpu-features.c | 4 ++++ 7 files changed, 72 insertions(+), 1 deletion(-) diff --git a/docs/arm-cpu-features.rst b/docs/arm-cpu-features.rst index 1b367e22e16e..5c317296845f 100644 --- a/docs/arm-cpu-features.rst +++ b/docs/arm-cpu-features.rst @@ -31,7 +31,9 @@ supporting the feature or only supporting the feature und= er certain configurations. For example, the `aarch64` CPU feature, which, when disabled, enables the optional AArch32 CPU feature, is only supported when using the KVM accelerator and when running on a host CPU type that -supports the feature. +supports the feature. While `aarch64` currently only works with KVM, +it could work with TCG. CPU features that are specific to KVM are +prefixed with "kvm-" and are described in "KVM VCPU Features". =20 CPU Feature Probing =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -171,6 +173,29 @@ disabling many SVE vector lengths would be quite verbo= se, the `sve` CPU properties have special semantics (see "SVE CPU Property Parsing Semantics"). =20 +KVM VCPU Features +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +KVM VCPU features are CPU features that are specific to KVM, such as +paravirt features or features that enable CPU virtualization extensions. +The features' CPU properties are only available when KVM is enabled and are +named with the prefix "kvm-". KVM VCPU features may be probed, enabled, a= nd +disabled in the same way as other CPU features. Below is the list of KVM +VCPU features and their descriptions. + + kvm-adjvtime When enabled, each time the VM transitions back + to running state the VCPU's vitual counter is + updated to ensure stopped time is not counted. + This avoids time jumps surprising guest OSes and + applications, as long as they use the virtual + counter for timekeeping, but has the side effect + of the virtual and physical counters diverging. + All timekeeping based on the virtual counter wi= ll + appear to lag behind any timekeeping that does + not subtract VM stopped time. The guest may + resynchronize its virtual counter with other ti= me + sources as needed. + SVE CPU Properties =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 7695ae551218..d8ad26438f9f 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2483,6 +2483,7 @@ static void arm_max_initfn(Object *obj) =20 if (kvm_enabled()) { kvm_arm_set_cpu_features_from_host(cpu); + kvm_arm_add_vcpu_properties(obj); } else { cortex_a15_initfn(obj); =20 @@ -2674,6 +2675,7 @@ static void arm_host_initfn(Object *obj) if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { aarch64_add_sve_properties(obj); } + kvm_arm_add_vcpu_properties(obj); arm_cpu_post_init(obj); } =20 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 68baf0482ffa..c9a657a178ce 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -620,6 +620,7 @@ static void aarch64_max_initfn(Object *obj) =20 if (kvm_enabled()) { kvm_arm_set_cpu_features_from_host(cpu); + kvm_arm_add_vcpu_properties(obj); } else { uint64_t t; uint32_t u; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index f79b9b8ef57a..1652e3febe51 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -17,6 +17,8 @@ #include "qemu/timer.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "qom/object.h" +#include "qapi/error.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" #include "sysemu/kvm_int.h" @@ -179,6 +181,31 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) env->features =3D arm_host_cpu_features.features; } =20 +static bool kvm_adjvtime_get(Object *obj, Error **errp) +{ + return ARM_CPU(obj)->kvm_adjvtime; +} + +static void kvm_adjvtime_set(Object *obj, bool value, Error **errp) +{ + ARM_CPU(obj)->kvm_adjvtime =3D value; +} + +/* KVM VCPU properties should be prefixed with "kvm-". */ +void kvm_arm_add_vcpu_properties(Object *obj) +{ + if (!kvm_enabled()) { + return; + } + + object_property_add_bool(obj, "kvm-adjvtime", kvm_adjvtime_get, + kvm_adjvtime_set, &error_abort); + object_property_set_description(obj, "kvm-adjvtime", + "Set on to enable the adjustment of " + "the virtual counter. VM stopped time " + "will not be counted.", &error_abort); +} + bool kvm_arm_pmu_supported(CPUState *cpu) { KVMState *s =3D KVM_STATE(current_machine->accelerator); diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index d506c4e84be6..5d8077df6a4a 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -232,6 +232,15 @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *= map); */ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu); =20 +/** + * void kvm_arm_add_vcpu_properties: + * @obj: The CPU object to add the properties to + * + * Add all KVM specific CPU properties to the CPU object. These + * are the CPU properties with "kvm-" prefixed names. + */ +void kvm_arm_add_vcpu_properties(Object *obj); + /** * void kvm_arm_set_virtual_time: * @cs: CPUState @@ -308,6 +317,8 @@ static inline void kvm_arm_set_cpu_features_from_host(A= RMCPU *cpu) cpu->host_cpu_probe_failed =3D true; } =20 +static inline void kvm_arm_add_vcpu_properties(Object *obj) {} + static inline bool kvm_arm_aarch32_supported(CPUState *cs) { return false; diff --git a/target/arm/monitor.c b/target/arm/monitor.c index e912ed2cefa0..a89976fe7e4b 100644 --- a/target/arm/monitor.c +++ b/target/arm/monitor.c @@ -103,6 +103,7 @@ static const char *cpu_model_advertised_features[] =3D { "sve128", "sve256", "sve384", "sve512", "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280", "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048", + "kvm-adjvtime", NULL }; =20 diff --git a/tests/arm-cpu-features.c b/tests/arm-cpu-features.c index ee444b04010f..c207a2bec9e9 100644 --- a/tests/arm-cpu-features.c +++ b/tests/arm-cpu-features.c @@ -417,6 +417,8 @@ static void test_query_cpu_model_expansion(const void *= data) assert_has_feature_enabled(qts, "cortex-a15", "pmu"); assert_has_not_feature(qts, "cortex-a15", "aarch64"); =20 + assert_has_not_feature(qts, "max", "kvm-adjvtime"); + if (g_str_equal(qtest_get_arch(), "aarch64")) { assert_has_feature_enabled(qts, "max", "aarch64"); assert_has_feature_enabled(qts, "max", "sve"); @@ -445,6 +447,8 @@ static void test_query_cpu_model_expansion_kvm(const vo= id *data) =20 assert_has_feature_enabled(qts, "host", "pmu"); =20 + assert_has_feature_disabled(qts, "host", "kvm-adjvtime"); + if (g_str_equal(qtest_get_arch(), "aarch64")) { bool kvm_supports_sve; char max_name[8], name[8]; --=20 2.20.1