From patchwork Thu Mar 1 12:54:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10251395 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 CBB2D602B5 for ; Thu, 1 Mar 2018 13:29:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAA9D2015F for ; Thu, 1 Mar 2018 13:29:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB0D2201F5; Thu, 1 Mar 2018 13:29:23 +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 B23D72015F for ; Thu, 1 Mar 2018 13:29:22 +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=z+CXg/DmuAxpEkAga8E5JDSA3y97rrf+6VgrCf46Gg8=; b=E80OEmmoSxyQlF5KSUCVcEIhAt Ju4jmRb8PI3XyAFmI02T3ih0HeurSXGteIinUGCzNC7rTWO5n03HtNeWx5VSGYf6Gysyy7sHHZXIC FNScuI40vcs/EyNVDYLIT+zf7kmJKLKjRXnhOO3GwO5AB1DcdBbVl1y+M4EPuYfmwEnw+UZNp9hdS uIhiSLF+x1Ssucpyf812lwhoMzPQpWNJLnsI2ZXRkSfsd9GWjf+JjwzgUq77/0yJ2sRTkmeDxGfhG u6pRjncuKW8BreFDuWHJG+nL2hwS1p16v3rraQSbnVwdGumy/932qWkV3gFZywaUjg90wwoFbQDAY H3DttOvw==; 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 1erOGf-0001a0-BB; Thu, 01 Mar 2018 13:29:05 +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 1erO0P-0005Ub-MG for linux-arm-kernel@bombadil.infradead.org; Thu, 01 Mar 2018 13:12:17 +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=J+5mFS5YG0Z6B4feNaUOGsgL/hJiqYMdZY2VyVL7BU0=; b=InO6aT43jj20vzI8Tgk3SUV8Q jzXrosE89raMkMVgDtF3OI8SYHMT3kna0RDt8mq2DX9pCddPLeBi53VKc4iv01y0cExma76dm9w9I pFne0KeoSI+4vbD44018Z+sxuXji36FyDE3cfra8j3lsXQ8yZvlsQe0vUnklbRdZnSvrSZZiPFuVQ Y1p7hl0sQGCUOBtGIsDpuQr86lSOYTQ8KTlhTzGz9WuG39X7U1BCTkKs/dzwZzjSwXoHZO7KjlRZK sofQSY7lKtY9a8pvejl76qG78RHNUctkGoq3KsYbkE9u/2UahqkGWuUTQdTA7tjP1buTIyCai+YkN VfJ/ipZ3A==; Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erNoe-0005CU-Gl for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 13:00:10 +0000 Received: by mail-pg0-x243.google.com with SMTP id w16so1377334pgv.6 for ; Thu, 01 Mar 2018 04:59:58 -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=J+5mFS5YG0Z6B4feNaUOGsgL/hJiqYMdZY2VyVL7BU0=; b=cNliJQE+mVOBsVb8LMhpi351PjVm9gqEDlFXQWMMXNNaqbPBsy4oK/0vk9cVUXNkm2 I+ojSopeItSzHa2lqOac6u6cEXjJ5RXwip9bjvc1YILoj4Gfh/ernqEk7iOl0xYqUkDp 9ALGtgQxoadLu1NrtZs4AaZxjAlGW1urE2jNM= 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=J+5mFS5YG0Z6B4feNaUOGsgL/hJiqYMdZY2VyVL7BU0=; b=tcrOBYIMsUWh0fWeuREUOWl9+W9ZEJLqKlffHr8GQn5DG2HK6OSuONZD+zC5Unjsuh Mtk7QTWpzx4OCwmEj2RNEyLwp5vNilmkvgBBQXwt3ZTkj97A0GyqTi1jX7g3m/Ae/SZu A/KLzY1xwKjpgNHHdRvGFglhr9GZjVYu6gIcmmUu8Iy52DrSwXs0gsUb6C+SqB9dKH86 hKUnBKOso9SLyr2G9dxsHaCzO7zm27VsB8u0OgmuEGuIw/FhdHr3iSXAUJlr+hPbVSue LHtzMecLdTDvMznXfZ3DhWyV20Y0LdvoP+V0N8TnrjM4rn4Ehph0dteHGxIz1DM21W9O 5AQw== X-Gm-Message-State: APf1xPDjixlq/HwhPAjO3vzZtEPhCzSl5S5t5kpdFbFQqwYmyUK4cqI8 er+oyf21QgMUsdcsQ642V7he0A== X-Google-Smtp-Source: AG47ELvKp4Clz97eme3mdjWQnxvda2WgRLRApIFE4uP/5+Rx5eBiail9K7eRDPa2cBNTS+RNp1oT7A== X-Received: by 10.101.77.69 with SMTP id j5mr1494347pgt.352.1519909196927; Thu, 01 Mar 2018 04:59:56 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:59:56 -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 34/45] arm/arm64: KVM: Implement PSCI 1.0 support Date: Thu, 1 Mar 2018 20:54:11 +0800 Message-Id: <1519908862-11425-35-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_130008_543331_69EA9C12 X-CRM114-Status: GOOD ( 17.42 ) 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 58e0b2239a4d upstream. PSCI 1.0 can be trivially implemented by providing the FEATURES call on top of PSCI 0.2 and returning 1.0 as the PSCI version. We happily ignore everything else, as they are either optional or are clarifications that do not require any additional change. PSCI 1.0 is now the default until we decide to add a userspace selection API. 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 | 45 ++++++++++++++++++++++++++++++++++++++++++++- include/kvm/arm_psci.h | 3 +++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index bc334d6..097632c 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -233,7 +233,7 @@ static void kvm_psci_system_reset(struct kvm_vcpu *vcpu) int kvm_psci_version(struct kvm_vcpu *vcpu) { if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) - return KVM_ARM_PSCI_0_2; + return KVM_ARM_PSCI_LATEST; return KVM_ARM_PSCI_0_1; } @@ -312,6 +312,47 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) return ret; } +static int kvm_psci_1_0_call(struct kvm_vcpu *vcpu) +{ + u32 psci_fn = smccc_get_function(vcpu); + u32 feature; + unsigned long val; + int ret = 1; + + switch(psci_fn) { + case PSCI_0_2_FN_PSCI_VERSION: + val = KVM_ARM_PSCI_1_0; + break; + case PSCI_1_0_FN_PSCI_FEATURES: + feature = smccc_get_arg1(vcpu); + switch(feature) { + case PSCI_0_2_FN_PSCI_VERSION: + case PSCI_0_2_FN_CPU_SUSPEND: + case PSCI_0_2_FN64_CPU_SUSPEND: + case PSCI_0_2_FN_CPU_OFF: + case PSCI_0_2_FN_CPU_ON: + case PSCI_0_2_FN64_CPU_ON: + case PSCI_0_2_FN_AFFINITY_INFO: + case PSCI_0_2_FN64_AFFINITY_INFO: + case PSCI_0_2_FN_MIGRATE_INFO_TYPE: + case PSCI_0_2_FN_SYSTEM_OFF: + case PSCI_0_2_FN_SYSTEM_RESET: + case PSCI_1_0_FN_PSCI_FEATURES: + val = 0; + break; + default: + val = PSCI_RET_NOT_SUPPORTED; + break; + } + break; + default: + return kvm_psci_0_2_call(vcpu); + } + + 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; @@ -354,6 +395,8 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) int kvm_psci_call(struct kvm_vcpu *vcpu) { switch (kvm_psci_version(vcpu)) { + case KVM_ARM_PSCI_1_0: + return kvm_psci_1_0_call(vcpu); case KVM_ARM_PSCI_0_2: return kvm_psci_0_2_call(vcpu); case KVM_ARM_PSCI_0_1: diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index 5659343..3236043 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -22,6 +22,9 @@ #define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1) #define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2) +#define KVM_ARM_PSCI_1_0 PSCI_VERSION(1, 0) + +#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0 int kvm_psci_version(struct kvm_vcpu *vcpu); int kvm_psci_call(struct kvm_vcpu *vcpu);