From patchwork Fri Dec 4 12:03:14 2015
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pavel Fedin
X-Patchwork-Id: 7767651
Return-Path:
X-Original-To: patchwork-kvm@patchwork.kernel.org
Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org
Received: from mail.kernel.org (mail.kernel.org [198.145.29.136])
by patchwork2.web.kernel.org (Postfix) with ESMTP id E5B8BBEEE1
for ;
Fri, 4 Dec 2015 12:03:36 +0000 (UTC)
Received: from mail.kernel.org (localhost [127.0.0.1])
by mail.kernel.org (Postfix) with ESMTP id F1F4B205B4
for ;
Fri, 4 Dec 2015 12:03:35 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
by mail.kernel.org (Postfix) with ESMTP id CEF39205B3
for ;
Fri, 4 Dec 2015 12:03:34 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1756416AbbLDMDb (ORCPT
);
Fri, 4 Dec 2015 07:03:31 -0500
Received: from mailout3.w1.samsung.com ([210.118.77.13]:61740 "EHLO
mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1755344AbbLDMDZ (ORCPT );
Fri, 4 Dec 2015 07:03:25 -0500
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout3.w1.samsung.com
(Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5
2014)) with ESMTP id <0NYU0002Y1HLXJ00@mailout3.w1.samsung.com> for
kvm@vger.kernel.org; Fri, 04 Dec 2015 12:03:21 +0000 (GMT)
X-AuditID: cbfec7f5-f79b16d000005389-7c-56618109c3c9
Received: from eusync2.samsung.com ( [203.254.199.212])
by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 46.44.21385.90181665;
Fri, 4 Dec 2015 12:03:21 +0000 (GMT)
Received: from fedinw7x64.rnd.samsung.ru ([106.109.131.169])
by eusync2.samsung.com
(Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5
2014)) with ESMTPA id <0NYU00L0V1HEET00@eusync2.samsung.com>; Fri,
04 Dec 2015 12:03:21 +0000 (GMT)
From: Pavel Fedin
To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: Marc Zyngier
Subject: [PATCH v4 4/4] KVM: arm64: Get rid of old vcpu_reg()
Date: Fri, 04 Dec 2015 15:03:14 +0300
Message-id:
<37aa6d529ed5c6df02b885eb7f791cddbccd02d7.1449230499.git.p.fedin@samsung.com>
X-Mailer: git-send-email 2.4.4
In-reply-to:
References:
In-reply-to:
References:
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e/4FV3OxsQwg0fbxSzmTC20+HjqOLvF
3zv/2ByYPdbMW8PocX7TGmaPz5vkApijuGxSUnMyy1KL9O0SuDJWPXvEVvBJqWJpwy3GBsbj
Ml2MnBwSAiYSO3a+ZoawxSQu3FvP1sXIxSEksJRR4v6cc+wQThuTxJH9q5hAqtgE1CVOf/3A
AmKLCJhKPP/3lhXEZgaKP949Bcjm4BAWsJVo3RcFEmYRUJXo7jzMBmLzCkRLPF04iRFimZzE
levTweKcAuYSXxt62EFsIQEziX0TD7HgEp/AyL+AkWEVo2hqaXJBcVJ6rpFecWJucWleul5y
fu4mRkgYfd3BuPSY1SFGAQ5GJR5ehk0JYUKsiWXFlbmHGCU4mJVEeJllEsOEeFMSK6tSi/Lj
i0pzUosPMUpzsCiJ887c9T5ESCA9sSQ1OzW1ILUIJsvEwSnVwKjEXMe+T+Hjg+fJ2Y8YNq07
ODkh7t/EprdHr37Jn91i59e+W+k5W9GkTQ/UhU/e/F9r8Z1h4ZbkrZmLJDUrGJwfzPD+8l4n
s3pNiWlj1W39wOsr2zwm+f2edPXV5JYXVRLleoqZpVpNxoqPd7DcORByemGdf+bPqVaCqwTS
DpTr+8bHT+DaxabEUpyRaKjFXFScCAADp1mlHwIAAA==
Sender: kvm-owner@vger.kernel.org
Precedence: bulk
List-ID:
X-Mailing-List: kvm@vger.kernel.org
X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI,
T_RP_MATCHES_RCVD,
UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org
X-Virus-Scanned: ClamAV using ClamSMTP
Using oldstyle vcpu_reg() accessor is proven to be inappropriate and
unsafe on ARM64. This patch converts the rest of use cases to new
accessors and completely removes vcpu_reg() on ARM64.
Signed-off-by: Pavel Fedin
Reviewed-by: Marc Zyngier
---
arch/arm/kvm/psci.c | 20 ++++++++++----------
arch/arm64/include/asm/kvm_emulate.h | 11 +++--------
arch/arm64/kvm/handle_exit.c | 2 +-
3 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
index 0b55696..a9b3b90 100644
--- a/arch/arm/kvm/psci.c
+++ b/arch/arm/kvm/psci.c
@@ -75,7 +75,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
unsigned long context_id;
phys_addr_t target_pc;
- cpu_id = *vcpu_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK;
+ cpu_id = vcpu_get_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK;
if (vcpu_mode_is_32bit(source_vcpu))
cpu_id &= ~((u32) 0);
@@ -94,8 +94,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
return PSCI_RET_INVALID_PARAMS;
}
- target_pc = *vcpu_reg(source_vcpu, 2);
- context_id = *vcpu_reg(source_vcpu, 3);
+ target_pc = vcpu_get_reg(source_vcpu, 2);
+ context_id = vcpu_get_reg(source_vcpu, 3);
kvm_reset_vcpu(vcpu);
@@ -114,7 +114,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
* NOTE: We always update r0 (or x0) because for PSCI v0.1
* the general puspose registers are undefined upon CPU_ON.
*/
- *vcpu_reg(vcpu, 0) = context_id;
+ vcpu_set_reg(vcpu, 0, context_id);
vcpu->arch.power_off = false;
smp_mb(); /* Make sure the above is visible */
@@ -134,8 +134,8 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu)
struct kvm *kvm = vcpu->kvm;
struct kvm_vcpu *tmp;
- target_affinity = *vcpu_reg(vcpu, 1);
- lowest_affinity_level = *vcpu_reg(vcpu, 2);
+ target_affinity = vcpu_get_reg(vcpu, 1);
+ lowest_affinity_level = vcpu_get_reg(vcpu, 2);
/* Determine target affinity mask */
target_affinity_mask = psci_affinity_mask(lowest_affinity_level);
@@ -209,7 +209,7 @@ int kvm_psci_version(struct kvm_vcpu *vcpu)
static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
{
int ret = 1;
- unsigned long psci_fn = *vcpu_reg(vcpu, 0) & ~((u32) 0);
+ unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
unsigned long val;
switch (psci_fn) {
@@ -273,13 +273,13 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
break;
}
- *vcpu_reg(vcpu, 0) = val;
+ vcpu_set_reg(vcpu, 0, val);
return ret;
}
static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
{
- unsigned long psci_fn = *vcpu_reg(vcpu, 0) & ~((u32) 0);
+ unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0);
unsigned long val;
switch (psci_fn) {
@@ -295,7 +295,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
break;
}
- *vcpu_reg(vcpu, 0) = val;
+ vcpu_set_reg(vcpu, 0, val);
return 1;
}
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 5a182af..25a4021 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -100,15 +100,10 @@ static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
}
/*
- * vcpu_reg should always be passed a register number coming from a
- * read of ESR_EL2. Otherwise, it may give the wrong result on AArch32
- * with banked registers.
+ * vcpu_get_reg and vcpu_set_reg should always be passed a register number
+ * coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
+ * AArch32 with banked registers.
*/
-static inline unsigned long *vcpu_reg(const struct kvm_vcpu *vcpu, u8 reg_num)
-{
- return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.regs[reg_num];
-}
-
static inline unsigned long vcpu_get_reg(const struct kvm_vcpu *vcpu,
u8 reg_num)
{
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 68a0759..15f0477 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -37,7 +37,7 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)
{
int ret;
- trace_kvm_hvc_arm64(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0),
+ trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0),
kvm_vcpu_hvc_get_imm(vcpu));
ret = kvm_psci_call(vcpu);