From patchwork Mon Feb 26 08:20:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 129586 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3358027lja; Mon, 26 Feb 2018 00:25:21 -0800 (PST) X-Google-Smtp-Source: AH8x226wfNusMvKS8R9F9NCfBHHDpI/g92qE7lqM55yJ/1Uvh+6u1oOv7gOPyYrg2qalIP0XbY/n X-Received: by 10.98.137.147 with SMTP id n19mr9919604pfk.193.1519633520870; Mon, 26 Feb 2018 00:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633520; cv=none; d=google.com; s=arc-20160816; b=0RG//emZ9iShK8JFg5uSsNFGON1wGtnemSfdSAZka6TjJ0JNgUxOsBnoJ9Awn/qk/c nJQHCngRWQqbchvyCnzZhlujyCYXWnAO7B7ERCkrNI2o7hcG21Kzf6e3wXUdPmJmW3ig S4IKThhpc4aS/EXU3rO/utIbdguiquVZtBhO95/0og2MaeL1v8lWadxAjYFBz0D7xSWC ifg6QTk9nZQ85qCnVNEwMUb9w8grQOqyGW/AXhaEo5HiIEa1hwDvx1l9cR4ImEdgLDbb kXemFsVJIdHMCPX4oVAllclqMMMyU0+v6Mj1lhCQ0i8Dd2imLLM+Zo7WfR1jokHDRWOR 8F5g== 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=l4gE12Cx+WzzR165F9Q91i+QJet+6VDPPWfaw6jeWI0Bm2UV/e7akUdAZEsSWJ/Wcp xqALDl1un/ftyjvF/FoyAb9WIHMJUx6JtWhhu7vUSqlxl2o96YgosNSVitasJWtMtiOZ crk6mcTlQTUyQS75fXjjLnDS2cpnH16u1XqFGt1bKdhfC4cAeH9T7GPdbz+4ZoAJ/L9V L82vsiqwBwxZXFXudGw7o3GOWS1T3ii1l2OZtifk5nZoutc0eNslu+RjFuZ64uMlq18L jcxw0VMmCNvi0rkxewMu/w8o+z1SaBNKsXe4pS/rlJtSF5q0w7gBz5Neq3H7fkCnFpoM f/QA== 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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 o64si1254960pga.160.2018.02.26.00.25.20; Mon, 26 Feb 2018 00:25:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1752664AbeBZIZS (ORCPT + 10 others); Mon, 26 Feb 2018 03:25:18 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:44644 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752284AbeBZIZN (ORCPT ); Mon, 26 Feb 2018 03:25:13 -0500 Received: by mail-pg0-f68.google.com with SMTP id l4so5907206pgp.11 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=rCry9+MOehfZDoBvEse4BwCFnEOQZluedb08ULDu+SW8ES8b7ybus9cXWbVSAMVIo0 7+goDW4smd1w6kxZ9FxgoaOT1v6ncgBwGuT9NDxvBygf9AIa97gNz0JhB7GKWi9ejDsH ckYtDYGVDl2EXpzpgLmvh+lhJhI0CWqSaZ2h4sYZTAWo3B+UdFMqJQhQomAx7smyXc00 RRHjFIsz0fmJdv7527wGAus+xj7l27rEuU7SX5zcU5VWtA0/MBtKzGg8yVFv8tl6vWAh FpQdZoV0zLiTQgyTLxqfiR2OmU24z+Ldgp0d3RDAaOHj8kqV5I/a5jdkqCptKqvcb4u+ OgRQ== X-Gm-Message-State: APf1xPCuZq+E4PovewzkGz76+OoFeDxCTrOF6PeDXq67o/w4NPnHqQtL /ef2iCVniSj2LvSfumB1kO7F3oeoRFg= 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?b?UmFkaW0gS3LEjW3DocWZ?= , 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: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.7.4 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; }