From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A95C2D0A3 for ; Mon, 9 Nov 2020 11:39:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B738D206B6 for ; Mon, 9 Nov 2020 11:39:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MFPorr2p"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="NGM9T7Cg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B738D206B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=UEmeRi3nac6rJO3P+bNHeB+qlJ7JPIYEKUOVOdHfqAg=; b=MFPorr2p3aGwbcJTqUbs4oQPh 32JCMivvUS0njNL7J5craMlVpP2U7FXqt1TtWB+mKXV+VxW+YXUc06IRM3eKOHD8lLeTO5Y35gy2S oaI7qBgvoFCwTUrCoqKnW3Jzyq8ofopblvJpy1QYUzp9Rs2so8GaWRmYXOsKIeTeSUR+p9WsPwLyO TxaT/dX3+BO8uIpzk8Zz16Iny3gVTCMqaVASAfln/nX/TbU7/WYKoqGWGvJwSdtQUCAmPMCK0UmqV aoK2v/9eKVKstcYS2z2dGiFQkSjrDpHyT+FKCNfxfbrg74aXzFnFu1Z2gw/wloVoWhk0GpECPL+G7 sUAfJaw7w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5UN-0006WX-BN; Mon, 09 Nov 2020 11:37:35 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5QE-0004XA-1a for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:33:31 +0000 Received: by mail-wm1-x342.google.com with SMTP id c16so7605372wmd.2 for ; Mon, 09 Nov 2020 03:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=STxT3I0oev0DTBptKuUq67e2wlovKGTClvKfrgZni/w=; b=NGM9T7CgfmsasqmbWaORXlR/xBoFk5aIVmGIzm/UQUh9KDC2NVnsXrzyALlYGiluq8 GJgsNYDUOrP5L4fORcs8BdEIG+XBni3PtySqYnhjWsUPd4AvX+Y953HDbf1nsu261T88 oXHv9mrV7U9q9w9sAcyCrHQsjIqCmhjXWjCzHgesmo1+PF4JxxIFaOeWSDOZvBJ89grs XoV6ePNuO77GLT2ml6GBIr4UIKtXyvvVJk0Gz86ScJn1KCXSMqOUx4LOCkqDWVqqVFjq KQAjw/Eyc7XiFLROohIV3JrVJSDETxRfdgdyGay/7tMMS7RRK+oMQAH5l4bWw/pR+5/w VyHg== 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:mime-version:content-transfer-encoding; bh=STxT3I0oev0DTBptKuUq67e2wlovKGTClvKfrgZni/w=; b=AYpZM9+5eb+1zhAXtOt+31nVFxANFaRr9/Pc957PtcRMFA3goo7UkfDK5nOaYRUrdX 7V8stmBQ4l3EpIfCx+4fQDR7t2AfV7NgHhCjD051k9Ulf9gViSOgxtgn5bLPgisQhwTn eLB2TXNCwUx27tKI8KQgJ9xZBWroHXuFb5eHYTZfAhaWYy1nCJYH+subY0QRlKQhwnkB duzVlJTHQLO+1SqDPrzt/hG70Ed65+xteJ7lNTgVHmjUjvlkteJp7GjBd43XVuG69OTo Ac0FFb1bK9scmFiv5eSi0OtrTMp0TYOekIbDavgEn61oOZBqf1agVDFoemlsOwZP+UG5 f4Pg== X-Gm-Message-State: AOAM530IgTUcsrvoWScTL3b64YYtuaMvgY6msuKxSqlxYoA2SgrOq1SV 0naMadgTit6jtfVxYZZ+Re7PpA== X-Google-Smtp-Source: ABdhPJxqqBns67atj2fda4ruhApA8uhNwaLMzwBAgerwaILtvzmidmLAUfyEIiuw6wHIFXtvfZHSGA== X-Received: by 2002:a1c:99d3:: with SMTP id b202mr13871173wme.0.1604921596533; Mon, 09 Nov 2020 03:33:16 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id b124sm12777961wmh.13.2020.11.09.03.33.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:15 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 18/24] kvm: arm64: Forward safe PSCI SMCs coming from host Date: Mon, 9 Nov 2020 11:32:27 +0000 Message-Id: <20201109113233.9012-19-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_063318_408047_096F8020 X-CRM114-Status: GOOD ( 18.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , David Brazdil , Will Deacon , Julien Thierry , Andrew Scull Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Forward the following PSCI SMCs issued by host to EL3 as they do not require the hypervisor's intervention. This assumes that EL3 correctly implements the PSCI specification. Only function IDs implemented in Linux are included. Where both 32-bit and 64-bit variants exist, it is assumed that the host will always use the 64-bit variant. * SMCs that only return information about the system * PSCI_VERSION - PSCI version implemented by EL3 * PSCI_FEATURES - optional features supported by EL3 * AFFINITY_INFO - power state of core/cluster * MIGRATE_INFO_TYPE - whether Trusted OS can be migrated * MIGRATE_INFO_UP_CPU - resident core of Trusted OS * operations which do not affect the hypervisor * MIGRATE - migrate Trusted OS to a different core * SET_SUSPEND_MODE - toggle OS-initiated mode * system shutdown/reset * SYSTEM_OFF * SYSTEM_RESET * SYSTEM_RESET2 Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/psci.c | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 7510b9e174e9..05a34a152069 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -63,14 +63,51 @@ static bool is_psci_call(u64 func_id) return is_psci_0_2_fn_call(func_id); } +static unsigned long psci_call(unsigned long fn, unsigned long arg0, + unsigned long arg1, unsigned long arg2) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(fn, arg0, arg1, arg2, &res); + return res.a0; +} + +static unsigned long psci_forward(struct kvm_cpu_context *host_ctxt) +{ + return psci_call(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3]); +} + +static __noreturn unsigned long psci_forward_noreturn(struct kvm_cpu_context *host_ctxt) +{ + psci_forward(host_ctxt); + hyp_panic(); /* unreachable */ +} + static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { - return PSCI_RET_NOT_SUPPORTED; + if (func_id == kvm_host_psci_function_id[PSCI_FN_CPU_OFF]) + return psci_forward(host_ctxt); + else if (func_id == kvm_host_psci_function_id[PSCI_FN_MIGRATE]) + return psci_forward(host_ctxt); + else + return PSCI_RET_NOT_SUPPORTED; } static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { switch (func_id) { + case PSCI_0_2_FN_PSCI_VERSION: + case PSCI_0_2_FN_CPU_OFF: + case PSCI_0_2_FN64_AFFINITY_INFO: + case PSCI_0_2_FN64_MIGRATE: + case PSCI_0_2_FN_MIGRATE_INFO_TYPE: + case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: + return psci_forward(host_ctxt); + case PSCI_0_2_FN_SYSTEM_OFF: + case PSCI_0_2_FN_SYSTEM_RESET: + psci_forward_noreturn(host_ctxt); + unreachable(); default: return PSCI_RET_NOT_SUPPORTED; } @@ -85,6 +122,10 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ return ret; switch (func_id) { + case PSCI_1_0_FN_PSCI_FEATURES: + case PSCI_1_0_FN_SET_SUSPEND_MODE: + case PSCI_1_1_FN64_SYSTEM_RESET2: + return psci_forward(host_ctxt); default: return PSCI_RET_NOT_SUPPORTED; } -- 2.29.2.222.g5d2a92d10f8-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel