From patchwork Fri Jul 10 11:00:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 51031 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A197B2290A for ; Fri, 10 Jul 2015 11:01:30 +0000 (UTC) Received: by lbbei7 with SMTP id ei7sf9474596lbb.3 for ; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=X9ZyVvNNm6KNak2WjMVg3xo/52ciTTIv+aaG39umdEk=; b=CkNdDESnvNyL+dTHkBpkYqj76bX6s3WVmdHlfXp9rsK+OmAQtzpDOIW3Bxp6SN4lDm YoctuQmhSaZV4ZGAV/v9R/csm8/uD9C8OzGTvqnJ+MfkDVxQdlKSS1nUSpBujJmnjwB2 ii2a8+FBjLWV9GWPMUniguHdU65rq6lLHLW4Ky1kSPIUDlkNNMPyissRs6DGxn04TrV+ nt48XxBf0iGeSH2WHL8a57Ltwna3Q76itlr7LeemSpJH50/sW8hWehQrOG1uL791eSkl xYpyt7rIquPr3YOdAjxOve5V23lJufxaK+0AqG/GNaAYyM+IZ4Hhgnq6v20GxRVSO52X v44g== X-Gm-Message-State: ALoCoQl/7hTQMaq8EfrqPhsel6PmQVIdmPXUB3F+UP73YyLLHC5e3Tu4lroyijCbvVBlXC59uQ7x X-Received: by 10.112.189.131 with SMTP id gi3mr10450827lbc.6.1436526089566; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.182.228 with SMTP id eh4ls1143022lac.45.gmail; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) X-Received: by 10.112.138.100 with SMTP id qp4mr19384854lbb.62.1436526089341; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id t9si7050713laj.106.2015.07.10.04.01.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jul 2015 04:01:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lagc2 with SMTP id c2so260153811lag.3 for ; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr19358086lbc.19.1436526089234; Fri, 10 Jul 2015 04:01:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1296620lbb; Fri, 10 Jul 2015 04:01:28 -0700 (PDT) X-Received: by 10.66.119.239 with SMTP id kx15mr41443207pab.156.1436526087372; Fri, 10 Jul 2015 04:01:27 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id qx6si14112135pab.13.2015.07.10.04.01.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 10 Jul 2015 04:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:44076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDW3Z-0008Q8-HW for patch@linaro.org; Fri, 10 Jul 2015 07:01:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDW32-00088H-OV for qemu-devel@nongnu.org; Fri, 10 Jul 2015 07:00:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZDW2z-0005kw-Gv for qemu-devel@nongnu.org; Fri, 10 Jul 2015 07:00:52 -0400 Received: from mail-la0-f45.google.com ([209.85.215.45]:34357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDW2z-0005kg-4o for qemu-devel@nongnu.org; Fri, 10 Jul 2015 07:00:49 -0400 Received: by lagx9 with SMTP id x9so262948534lag.1 for ; Fri, 10 Jul 2015 04:00:48 -0700 (PDT) X-Received: by 10.112.50.66 with SMTP id a2mr19534043lbo.68.1436526048045; Fri, 10 Jul 2015 04:00:48 -0700 (PDT) Received: from localhost.localdomain (0187900153.0.fullrate.dk. [2.110.55.193]) by smtp.gmail.com with ESMTPSA id cy1sm2207355lac.22.2015.07.10.04.00.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Jul 2015 04:00:47 -0700 (PDT) From: Christoffer Dall To: qemu-devel@nongnu.org Date: Fri, 10 Jul 2015 13:00:53 +0200 Message-Id: <1436526053-4516-1-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.45 Cc: Peter Maydell , Marc Zyngier , Claudio Fontana , Jan Kiszka , kvmarm@lists.cs.columbia.edu, Christoffer Dall Subject: [Qemu-devel] [RFC PATCH] target-arm: kvm: Differentiate registers based on write-back levels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Some registers like the CNTVCT register should only be written to the kernel as part of machine initialization or on vmload operations, but never during runtime, as this can potentially make time go backwards or create inconsistent time observations between VCPUs. Introduce a list of registers that should not be written back at runtime and check this list on syncing the register state to the KVM state. Signed-off-by: Christoffer Dall --- target-arm/kvm.c | 34 +++++++++++++++++++++++++++++++++- target-arm/kvm32.c | 2 +- target-arm/kvm64.c | 2 +- target-arm/kvm_arm.h | 3 ++- target-arm/machine.c | 2 +- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 548bfd7..2e92699 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -409,7 +409,35 @@ bool write_kvmstate_to_list(ARMCPU *cpu) return ok; } -bool write_list_to_kvmstate(ARMCPU *cpu) +typedef struct cpreg_state_level { + uint64_t kvm_idx; + int level; +} cpreg_state_level; + +/* All system registers not listed in the following table are assumed to be + * of the level KVM_PUT_RUNTIME_STATE, a register should be written less + * often, you must add it to this table with a state of either + * KVM_PUT_RESET_STATE or KVM_PUT_FULL_STATE. + */ +cpreg_state_level non_runtime_cpregs[] = { + { KVM_REG_ARM_TIMER_CNT, KVM_PUT_FULL_STATE }, +}; + +static int cpreg_level(uint64_t kvm_idx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(non_runtime_cpregs); i++) { + cpreg_state_level *l = &non_runtime_cpregs[i]; + if (l->kvm_idx == kvm_idx) { + return l->level; + } + } + + return KVM_PUT_RUNTIME_STATE; +} + +bool write_list_to_kvmstate(ARMCPU *cpu, int level) { CPUState *cs = CPU(cpu); int i; @@ -421,6 +449,10 @@ bool write_list_to_kvmstate(ARMCPU *cpu) uint32_t v32; int ret; + if (cpreg_level(regidx) > level) { + continue; + } + r.id = regidx; switch (regidx & KVM_REG_SIZE_MASK) { case KVM_REG_SIZE_U32: diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c index d7e7d68..9fbd5fd 100644 --- a/target-arm/kvm32.c +++ b/target-arm/kvm32.c @@ -367,7 +367,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) * managed to update the CPUARMState with, and only allowing those * to be written back up into the kernel). */ - if (!write_list_to_kvmstate(cpu)) { + if (!write_list_to_kvmstate(cpu, level)) { return EINVAL; } diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index ac34f51..2911679 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -280,7 +280,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) return ret; } - if (!write_list_to_kvmstate(cpu)) { + if (!write_list_to_kvmstate(cpu, level)) { return EINVAL; } diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h index 5abd591..ce03e97 100644 --- a/target-arm/kvm_arm.h +++ b/target-arm/kvm_arm.h @@ -71,6 +71,7 @@ bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx); /** * write_list_to_kvmstate: * @cpu: ARMCPU + * @level: the state level to sync * * For each register listed in the ARMCPU cpreg_indexes list, write * its value from the cpreg_values list into the kernel (via ioctl). @@ -83,7 +84,7 @@ bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx); * Note that we do not stop early on failure -- we will attempt * writing all registers in the list. */ -bool write_list_to_kvmstate(ARMCPU *cpu); +bool write_list_to_kvmstate(ARMCPU *cpu, int level); /** * write_kvmstate_to_list: diff --git a/target-arm/machine.c b/target-arm/machine.c index 9eb51df..32adfe7 100644 --- a/target-arm/machine.c +++ b/target-arm/machine.c @@ -251,7 +251,7 @@ static int cpu_post_load(void *opaque, int version_id) } if (kvm_enabled()) { - if (!write_list_to_kvmstate(cpu)) { + if (!write_list_to_kvmstate(cpu, KVM_PUT_FULL_STATE)) { return -1; } /* Note that it's OK for the TCG side not to know about