From patchwork Thu Mar 1 12:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130211 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2764096edc; Thu, 1 Mar 2018 04:59:57 -0800 (PST) X-Google-Smtp-Source: AG47ELudXcBbrA+U3KWjKvpSabsXvDRolsOZpnstqhZ/Q6IAs21+myDFXCA+wfM0EFUOedw3Qd0U X-Received: by 10.98.147.27 with SMTP id b27mr1863974pfe.145.1519909197484; Thu, 01 Mar 2018 04:59:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909197; cv=none; d=google.com; s=arc-20160816; b=rmVQnb9gGyRXeFCnim6JrQYVVokJXBTVodMdFy2Rzuh1e0jpvAKQNqECTcT890V0m7 xxoq2kJuJrXC60UI2mCez64uunt3BMFesaQ/zwINILBPQlJSmhH3sRbb4K0ur9iYW9Rp RhyERNw4cGquRU/pDNZe+lVTEIm24GWZZn+jryafiqUYtSPVKf/zORthOo/JeWiAbKId TZyVgSBree9tjn16RAcHpbCTQz82GCGRz7n/7/qI4ehfShldAGB7UBynKcbTlPucG6jD 5vlfnpO8W5JOIIBwzxAUiXD/mxn7c+MawUXNTUwh3tsME2/luOSUEAAOSakrqVtUsMzD /txA== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=zjBJQZwCtp0hGrc4gv51u2xDzBZtNutKZ6u7sQOebOs=; b=mGSBjPs0Bj8t/JFtZcoC1O+pG5RUXqOw3/OdKBvpTOsPaXZTRvffS8k2e6YXU0By1C 2cWGPgL/nYvuFq/YNYOEpgNGz2V1ljI/Yhf9FtsfZU2ev2H5k4722tO9WSiKdRJYvCyW BrvS9nI644TSfVsr3Qv5gNmyD6vqVDlmftAWIB6dROpIMXRzjMHA9tmneoMYWbDwkYs4 3u9hjhMmmUwCNz2+lljNaTShzvJm4aTv76eWX6mSbE3H7r3XNTsy3zrrXvl4aFbQigeC aBO8DNH8mfEWbfm2f9/ZNhtA52oqFRMZpEErCPaXUsUFmMx0WDauP4nbftkaezpB/vrA 5qyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W122qInO; 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 a4si2448513pgn.327.2018.03.01.04.59.57; Thu, 01 Mar 2018 04:59:57 -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=W122qInO; 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 S1030919AbeCAM7z (ORCPT + 10 others); Thu, 1 Mar 2018 07:59:55 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:32806 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030914AbeCAM7u (ORCPT ); Thu, 1 Mar 2018 07:59:50 -0500 Received: by mail-pg0-f67.google.com with SMTP id g12so2280142pgs.0 for ; Thu, 01 Mar 2018 04:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zjBJQZwCtp0hGrc4gv51u2xDzBZtNutKZ6u7sQOebOs=; b=W122qInOewbxULPjXppE61Y/kDXlxlINb5unjLfvhaH+XUQPlG50QSKlZOnJ++2xYg Wsqs/oDBvfGq15vp/k4DdqYP8J2xuixyt/JaIJcKokP9NAuNa+KeB7g+Smb0TutdY7Dx XKeF+fF3EUoK5yMxj4APpcY0PBwdyIyHPBiXo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zjBJQZwCtp0hGrc4gv51u2xDzBZtNutKZ6u7sQOebOs=; b=IdXQjrOqReopf09/KHI6Nhjak7JrPNfeOvyLKujZfwwuVx3mKmjVfbf1hN5Z+DkIVK 79lzKdHL15JYyAl42N/iNQVW7vV+P8TFEnc8QwVlNcA7y6t8m9IODgKbcho52lLiwqMt u2Iuo1qOBH9NKEEjwXvRXq7LKBnxVYgErSg3Ed8IrVJ2MIwz/BefJvzdPmGJ9grrsnZQ 3w+k8u/Jm7YNDfETmItnQ3RnlMIyhdC9kIrFexqIiM4XDStJIZjNWS354nd+j1TOuh8m n2ubuVthaXNRoJu/mqg//DHoH5+dXhJikDt3WZn10pCNAiyJZiVPG6qw/KJbmvfACcxu 4oNQ== X-Gm-Message-State: APf1xPDgc4DdFBhgSqtNLC769SrdGbqj3+tmB7Tof00iiEri3ekuntef hlgVOzNk4ND4cejhhAOj2GF9hw== X-Received: by 10.101.87.199 with SMTP id q7mr1497712pgr.215.1519909189841; Thu, 01 Mar 2018 04:59:49 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:59:49 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 33/45] arm/arm64: KVM: Add smccc accessors to PSCI code Date: Thu, 1 Mar 2018 20:54:10 +0800 Message-Id: <1519908862-11425-34-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-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 --- 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; }