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: 10251425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 365B160211 for ; Thu, 1 Mar 2018 13:36:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 227241FFE5 for ; Thu, 1 Mar 2018 13:36:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14B21201F5; Thu, 1 Mar 2018 13:36:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 891511FFE5 for ; Thu, 1 Mar 2018 13:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WDao5EVjslTdcfZpBK3ZgIK0pxAkaVr0Abz5MKevlVM=; b=MK/NaOCeszWzGQhO1wEqWjY9SH Vlu0G+iFcKkDaw0dI7SneTzeNRN52AwsWd/m4R6WpeasaP9CIGW6H+8yckTs6QLRuIEcAYWfpsBXg 3tk/rL8jKrV92A/WnS8FAtLFN05lnLjIpT7Sb/bsOic6YJZe30LKMSKs9hgypFGfvTKnMQwJ5RIbF wMFJxw5iNgB67bjfFobTXYxSW6xQE6t9yMZo07DmkNUoSgiqWzG6zN0LsGUUaYcKX8YdJUj5q3uqD hYWUt1PN7rGHIf0HdfIhw/hDC2coYIoKxxYSAAbFanL922Bq1/yOzCDgrzU9yIV3ufXdMTrflSRI6 dduUn1Eg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erONS-0008AS-3O; Thu, 01 Mar 2018 13:36:06 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOHF-0001sV-Tg for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:29:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zjBJQZwCtp0hGrc4gv51u2xDzBZtNutKZ6u7sQOebOs=; b=xcSBkjVdR7FTo55vuYoknYTpU j0nMOwrNXinwJV4Sk7Dpg2lQCv6B1gQDmbNEna1h8hPfCdrXJVbbahq52aUHOmwZzfkkcAy3ZaPFm gj6X2MoTGY/GVCrpOG1ICkJD9XYCbYNUnaVu9g+QivJN5/MZLydFfjcixmSuVmVMbz+5yUppYJSgS ke5n3dUCeyRPcGiA20zBeDbm5On1cl/GhXmP/Kxg2PXCNmjPmhky8CCSExQho97LZT5Vyil2PwXVn Z5ZVwvYBAITD6aCOMmIwQj4C6NEI6Cr8JXrfoUN0rMMRafBEmbBJ9sz8JgQX4G6omHb2pTxDo4mtC ONdvf/XeQ==; Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNoY-0002L9-08 for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:07 +0000 Received: by mail-pg0-x242.google.com with SMTP id l24so2275839pgc.5 for ; Thu, 01 Mar 2018 04:59:51 -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=tIHcBhiJIKMGEEldIjgFpJRJ4/6RXs38f/RbCMDqxinHpAPjEzZpOR/EtadlBAgceP doKJ0TI0RUGunOyxJ5zColLsUTxYVLo5fhmWoNBja/YvSUZ940ZX5eSSqJsPwBGrIr4b hI5/VAZKLKk6wvLIJ0adwuh8jEhTkYYklXyKa/oLcyLCoX/9Rdy6TyhFC/o4yv+kcMSJ dc/3u8/z5KcGBBh/spvyPxfaqxvjf0n+FXP0kQXIS9hhTSquSdigEfB6p2xU2HXgpw2H Ka+TZfc4tg1hvSrGWKVIBxb5QjSWpQ9gxR9bhq8H7WBO+GQWyhsB5r8LsnfKVKtgv1a6 /WwQ== X-Gm-Message-State: APf1xPACOELn6hivlSnp6NLYsuW4Kw3qWzhuH0M8HniK1g/RnsKEnOQh iUWDhYJsQtRw/aaD+v8OqHvY9g== X-Google-Smtp-Source: AG47ELuQBr+GTLMgXYzS3KxepkIju7CfTyeQxoJAISMICoR1Xe+uWIBD/LJx0VR9yrcl7m+prdM8Dw== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_080002_093361_33331941 X-CRM114-Status: GOOD ( 15.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; }