From patchwork Fri Mar 9 09:07:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270205 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 8C9DA60236 for ; Fri, 9 Mar 2018 09:29:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86E3529D7C for ; Fri, 9 Mar 2018 09:29:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B22B29D97; Fri, 9 Mar 2018 09:29:36 +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=ham 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 59A1529D9B for ; Fri, 9 Mar 2018 09:29:35 +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=WdgUXnQIbbxf3xsQaX1Lq8ru3RXvmSv4Q0p+qt3rmEw=; b=gtuENP7XiV9UOytBkTPjDdZrNe GZsBfGT7N1qFRgXuCFcbnKEm6hEEstYIp90omRaQzsKBWbxKkuJjmIJgTLeR4OORrPxNgj/qB+AVP gKLmtJGXTRLA5m+ObAlZRDAT52Y6IzhshPSP+QxQaWs70uFH1scVcDg0Qi/EIDaizXVndsyYlEodc 7wkZFe5zBgTi/IqpRc+8UKUTPp+KYCqth0U5IRgkz+7145DRU98PzWuXJWSwm+L3QljTde1Wge0UT m6EWkolpXFYD5QxyAO3Tenpus1SvCjmLQlIgfdHU7cpSmGu9QrvLw1EGOolgyza2Cbg6kw2vPv53L 1Y6NlDRQ==; 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 1euEL7-0001sp-BE; Fri, 09 Mar 2018 09:29:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euEHu-0006YZ-Vq for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 09:26:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=tTEWRfYgNraJRDKKRApFS+pBL11ukL+6Yhts58+zYjQ=; b=Y46U1gF1Y+tbtHHaJed+NZljH KzYvUXjiEIRDLdlINaB+74sXKmm0shD5mfkoYF5gUlGydkr/UtIyfVyhZPyieeyN46AyXRVjY5NOm awjXza2FcBn7U7/ymA5lEVyXuOT0ZHNPoHqj3Ngy5mL+qyHE8FfaPlhc36lczwdOQpCkwFxaktG6j UV3CfFRTR90hTCVxNyyu61SW+OJBDW2ESNWUBGRl1vMPG1m4jwlAT6KqXEuDXetaX4+WJCV8B8O/w YXZV9j10WV3KNEE5/Rbi1FdJ+al8MPyS2vrAwd0cGOtZDeRn7x+r+P59aTRtQ3WlkNifR2di6GhFh m1z3mw6Vg==; Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE3O-0001gh-K7 for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:11:10 +0000 Received: by mail-pg0-x241.google.com with SMTP id y26so3335793pgv.4 for ; Fri, 09 Mar 2018 01:10:56 -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=tTEWRfYgNraJRDKKRApFS+pBL11ukL+6Yhts58+zYjQ=; b=EsO72+2jWcQSFHZLkkaGkeqxRq5NY9c9Daa1XDwWV7194lwYpX4k2iqIhR3f4GIqp6 dSl1dmfcbxYUD2ZVTSYJQ+GDP9+PShtbI5koan21zIyM4B8tDZJOFtizeJPUrL71jPg6 1glmW/6/7quFnsV0M0AXYl32rGMUu+NWhpAWM= 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=tTEWRfYgNraJRDKKRApFS+pBL11ukL+6Yhts58+zYjQ=; b=pjJucF/08aWgOusN0AD/YMtOosSwTsVrJzT3rBPae0c162dNeVn9LMYRsCRj3qwcoS EzSX/FFb7Y5xnQTdEp2TAN1hMitM1qX3V6UWWsRfQZkQTyH4khD+bb5W268oEhXlIeH8 WsShTE/i7B9Pc8A0Mn3rxsxyOVGHt3C/MSmHPhda/uuDhtjInwFlU80BMGlgrbQol446 WOFf5HpeoMYCLQHSF3IfSdH2ouRkjKY1HmgIE6DOD2RDIpb2w8lKgzNlegBpqwXtnrD6 cekyOJ7ZOoyS9VTPD1sgGAOvOCXj+PvBuLUQmg+2qvuCWiQh4x//3zZT/bL16twyndxp pi3Q== X-Gm-Message-State: AElRT7FqCb1MJ00UP2g3KvRwa9tuQxkgPcu3JUs1JIbRwHChYdsDLM33 4FbXfdRJcJYaGO60EzKRXmdD1w== X-Google-Smtp-Source: AG47ELujvsepKZ4B5FDSQWyACj+5emzxWx0tgyrOUNHn5D2vn9nXgznlPp4CNE/MQK4tvxzpODE+wQ== X-Received: by 10.99.114.81 with SMTP id c17mr9709787pgn.314.1520586654931; Fri, 09 Mar 2018 01:10:54 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.10.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:10:54 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 25/39] arm/arm64: KVM: Add smccc accessors to PSCI code Date: Fri, 9 Mar 2018 17:07:08 +0800 Message-Id: <20180309090722.26279-26-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_091106_663892_113F5622 X-CRM114-Status: GOOD ( 17.03 ) 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 85fc21b43f6f..946acf69a021 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; }