Received: by 10.223.185.116 with SMTP id b49csp3490927wrg; Mon, 26 Feb 2018 00:28:02 -0800 (PST) X-Google-Smtp-Source: AH8x225s8UEE+4LgBkWfOdPEFYecYdeGs3xftFV0kw3eIIA36CL7PrOdBd749bklQyA7EC7GnSnc X-Received: by 10.167.129.67 with SMTP id d3mr9832164pfn.108.1519633682445; Mon, 26 Feb 2018 00:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633682; cv=none; d=google.com; s=arc-20160816; b=VFR/auqVoEouDrL3uWmRDWzcehRWvxlH9808sf5j9c6C7kWiiuQ6SYLirwEw0e4KBJ x/mI1JEmlOH1GAGyfp3Sa+BD77joj5PxhKHvED6QV9J0MhdNCkwghWnpYzdDN00bRIVo i9mkZJdvV5JXZN4fQTBJ195dqv4AluwOVKQcfI4WOZNEq7OURKTkBZf3mb7vjoWk4xGn F5W49YI3VqhyAFbiJtURIAm3hzzYFjx30tqvaFqdvKaDUKAH9LmTjUZ4Mw8Wi5O4FVD6 UqW5KsfZvt8TW0pmRqF6xz/Uajde43p/lHZikF19uHO44LAiCzZYYvOktlGiDZIj69/N QjKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=joq1LHzXEIs9X9WqC4BlIrH4LbSvJY9OeFalK8l0bao=; b=NyYXQ26ThsX7WlwdN4LrqkkTrkv+Kv+qBhRhuSAkWXFSz93/2jMk2UpXtjnM6wVVZY hOMMp9DIIj3mhtetChQNSDLWeMg4vmhFOqBNhltU44qdxnk5QO4CDG+orcVgUcGtUkKs UHIsfFPHXwmfC1TeYECU9fkt57MxwaE+TXEsDUIocDb6Wje19eweckJUQE4CuudzO5OK KNfl9f8phHwTPpSZBhKH91K65IiAmNI39S7iTGg8k1Al0/e5Of6JvlhoPxJwykgT7/FJ wMcr0FkYfgaAC8BWnxKVm8tDnJlK1OzolKjLw7xdVm09ChB3h0sUaGu20jviRyIYgybT hFgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SNpo7E61; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2si1169952pgc.260.2018.02.26.00.27.48; Mon, 26 Feb 2018 00:28:02 -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; dkim=pass header.i=@linaro.org header.s=google header.b=SNpo7E61; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752681AbeBZIZW (ORCPT + 99 others); Mon, 26 Feb 2018 03:25:22 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34209 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752392AbeBZIZN (ORCPT ); Mon, 26 Feb 2018 03:25:13 -0500 Received: by mail-pg0-f65.google.com with SMTP id m19so5919069pgn.1 for ; Mon, 26 Feb 2018 00:25:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=joq1LHzXEIs9X9WqC4BlIrH4LbSvJY9OeFalK8l0bao=; b=SNpo7E61DVpWIdqOveOEXVYZ8EErZAZw5te1BCQUaq1y3eaARi0QQo+n/ewB6Jw45g E3HK7ag/EnBvUN4H/ezxDxKUwdpijE3MDGYCH1DapoR5A2tm9V+DCM2G32KpM+Qa1TBR 7BEzdPLgQk1bbk/rTjGa49HJBxdF9QpTDjr6Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=joq1LHzXEIs9X9WqC4BlIrH4LbSvJY9OeFalK8l0bao=; b=tFIrqjl9zIu8DXRJidQQAIYapjLmYnuVkyRHe7ckMKt5o+0ftJyU4DMNIQPQFoPCKB ZgAexwX56O9UprCNvO5jOlHRI2hOBdczu9rleB8zm+PI8HB6UhKauV4QZCsHUdaYj2nY czlGJng3JU0ZsPKRIum+WaImFPShVlsBqwiySghIWR6ihEGzcHClukewNTL9x/6CeaOs r7ppySZ8RbqmF8srz/KRv1nZ15sNf3+U5VSkjlG6BBR2/Yy6sPQBaTX2RA3FXomFQiuS ozxCo4XxDLd53FshCyS6Lr3oi23OAtFQJ8fuFFeSWakJVXsrKticWZ4DXSrOxv4urh4M 6NBw== X-Gm-Message-State: APf1xPCHQhAuKGJPOA3t+USCqGZcqeNDXrGt89vIDGtymkjcYvll1XKi riNFt973F7Xce6NiEU88BBplNg== X-Received: by 10.99.103.133 with SMTP id b127mr7722713pgc.155.1519633513030; Mon, 26 Feb 2018 00:25:13 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.25.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:25:12 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Christoffer Dall , Russell King , kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 33/52] arm/arm64: KVM: Add smccc accessors to PSCI code Date: Mon, 26 Feb 2018 16:20:07 +0800 Message-Id: <1519633227-29832-34-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit 84684fecd7ea upstream. Instead of open coding the accesses to the various registers, let's add explicit SMCCC accessors. Reviewed-by: Christoffer Dall Tested-by: Ard Biesheuvel Signed-off-by: Marc Zyngier Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: mv change from virt/kvm/arm/psci.c to arch/arm/kvm/psci.c --- arch/arm/kvm/psci.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 4adfa28..bc334d6 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -33,6 +33,38 @@ #define AFFINITY_MASK(level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1) +static u32 smccc_get_function(struct kvm_vcpu *vcpu) +{ + return vcpu_get_reg(vcpu, 0); +} + +static unsigned long smccc_get_arg1(struct kvm_vcpu *vcpu) +{ + return vcpu_get_reg(vcpu, 1); +} + +static unsigned long smccc_get_arg2(struct kvm_vcpu *vcpu) +{ + return vcpu_get_reg(vcpu, 2); +} + +static unsigned long smccc_get_arg3(struct kvm_vcpu *vcpu) +{ + return vcpu_get_reg(vcpu, 3); +} + +static void smccc_set_retval(struct kvm_vcpu *vcpu, + unsigned long a0, + unsigned long a1, + unsigned long a2, + unsigned long a3) +{ + vcpu_set_reg(vcpu, 0, a0); + vcpu_set_reg(vcpu, 1, a1); + vcpu_set_reg(vcpu, 2, a2); + vcpu_set_reg(vcpu, 3, a3); +} + static unsigned long psci_affinity_mask(unsigned long affinity_level) { if (affinity_level <= 3) @@ -75,7 +107,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_get_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK; + cpu_id = smccc_get_arg1(source_vcpu) & MPIDR_HWID_BITMASK; if (vcpu_mode_is_32bit(source_vcpu)) cpu_id &= ~((u32) 0); @@ -94,8 +126,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) return PSCI_RET_INVALID_PARAMS; } - target_pc = vcpu_get_reg(source_vcpu, 2); - context_id = vcpu_get_reg(source_vcpu, 3); + target_pc = smccc_get_arg2(source_vcpu); + context_id = smccc_get_arg3(source_vcpu); kvm_reset_vcpu(vcpu); @@ -114,7 +146,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_set_reg(vcpu, 0, context_id); + smccc_set_retval(vcpu, context_id, 0, 0, 0); vcpu->arch.power_off = false; smp_mb(); /* Make sure the above is visible */ @@ -134,8 +166,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_get_reg(vcpu, 1); - lowest_affinity_level = vcpu_get_reg(vcpu, 2); + target_affinity = smccc_get_arg1(vcpu); + lowest_affinity_level = smccc_get_arg2(vcpu); /* Determine target affinity mask */ target_affinity_mask = psci_affinity_mask(lowest_affinity_level); @@ -209,7 +241,7 @@ int kvm_psci_version(struct kvm_vcpu *vcpu) static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; - unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); + u32 psci_fn = smccc_get_function(vcpu); unsigned long val; int ret = 1; @@ -276,14 +308,14 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) break; } - vcpu_set_reg(vcpu, 0, val); + smccc_set_retval(vcpu, val, 0, 0, 0); return ret; } static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; - unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); + u32 psci_fn = smccc_get_function(vcpu); unsigned long val; switch (psci_fn) { @@ -301,7 +333,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) break; } - vcpu_set_reg(vcpu, 0, val); + smccc_set_retval(vcpu, val, 0, 0, 0); return 1; } -- 2.7.4