From patchwork Wed Nov 4 18:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11881895 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.7 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 60BF9C2D0A3 for ; Wed, 4 Nov 2020 18:40:27 +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 E75712067C for ; Wed, 4 Nov 2020 18:40:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jSbsVwIp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="RUE++rKQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E75712067C 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=hVfS/4VtsLh4XFznoGrAEyUSIM2YOgQtCczf01rzKeU=; b=jSbsVwIpiQKGCb+eyasFn9Dl0 M0UYECprs2oIpSrsNRKb7Ikzzez4tlDGwS1kuTIS/dpuE0NeF58sSou3IvpCeaTj8HikPI3RtN+q4 kH9Lbelk6nGiuGrRsCDD37pfWAcSjjwaTySfH3PIiMFGlHUJE33plES9rjIo/1k4o6Wi14C3Wbscf ikSOwMAoEHnjYrn0wqQEWNyY4pozAoSeRfzMpv4bFpRiFpA/sYnUpWDyRiNAm6hzxjyOQbJqF+sZs Bue5zUCT+48y7ReS0DWjWRt0uyjEIf2Mgph/KuMIAWy1zamBDuc/o+1bJnD45j+DY7ZlavQOvPmkp gYoMJiMqg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNg0-0002XC-FW; Wed, 04 Nov 2020 18:38:32 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaNef-0001nV-9J for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 18:37:10 +0000 Received: by mail-wm1-x343.google.com with SMTP id c18so3358727wme.2 for ; Wed, 04 Nov 2020 10:37:09 -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=9j0VMjjA6zCDdyx35vluqon5elvOXnResZEBXNSr1X0=; b=RUE++rKQXhZNCONaCTR19/HxXtVIIi3oRNevbUdThFpb7lSGOWgZt53CvjYIojGFXp bjoAX5PN9KRdcmvSZhoOooosMjRsjhO3yOCLuFsmXBnGqzHK6fNjiqbiboERhaoR7c65 AMmH+DGH/eYH/7R0jg5d77ub+nd4XbwPgg1O4y2VRz3/Jr8HAi516eAnsOUKhoFimz+U Rygz++/YusK5YxpHxDmVPdIlb5tTRErFbiYlp8wV57FtQTu49uSxeIyuOdoBt1iNhtHe b+NAvqUVRGyEdVlL/l8GZB8iHlSVM8gpAPm9CXxsZbVe2yoe6fVtsZ6ddqmVgU3IIcVq w77A== 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=9j0VMjjA6zCDdyx35vluqon5elvOXnResZEBXNSr1X0=; b=cw+nrwv8s4w/PQLJAWLPVe9HbBe8eTk+z/xNUrZ9h0DVrYcZNmzIzG3nJ0lx+9hovF kfSifPq5/dokYFQ07+t8Ej0ytgSYkAQZ24c96ihaoY5V9l7i3+22QKWVDhDTmxyAPgPX Tv6Weca9p6oH45FyKV1+LMVDYNEpU2mvfdRLVIea3tjt9Wxl3sxiYMGzuh0MGcUZaEC4 rVIhNuIFpCQO0Yat/u00PKoJa1RRffg/nzuHuy5ziasT0q5tlJ09L+9bEUG5s+f97ifp 1b4Bewgq22ZJZYK1SBA1Yw8935Sviro2xAU7FLsrU6eXW5G/YWNvfFdedXjmshw1vDsE tW0Q== X-Gm-Message-State: AOAM531txkWJsiuStvCH45lPugwGDA/k1Ky0Y0z5KqQrIcEJUWsqQyd+ EfaZCQszsd6Gln3DgvbmIjV7Gg== X-Google-Smtp-Source: ABdhPJzlA4HqRs854B2x+X/0kGzJzOL2QkOaSVtVknIKK6zQbS8XLXIwWdn8f9VXnZzMY6cgY+W9ng== X-Received: by 2002:a7b:c748:: with SMTP id w8mr6056505wmk.32.1604515028016; Wed, 04 Nov 2020 10:37:08 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:c8d2:30f2:53c6:bc2]) by smtp.gmail.com with ESMTPSA id 90sm3934768wrl.30.2020.11.04.10.37.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Nov 2020 10:37:06 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 14/26] kvm: arm64: Forward safe PSCI SMCs coming from host Date: Wed, 4 Nov 2020 18:36:18 +0000 Message-Id: <20201104183630.27513-15-dbrazdil@google.com> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201104183630.27513-1-dbrazdil@google.com> References: <20201104183630.27513-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_133709_414800_ACB58D65 X-CRM114-Status: GOOD ( 19.22 ) 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 , Lorenzo Pieralisi , kernel-team@android.com, 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 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 | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci.c b/arch/arm64/kvm/hyp/nvhe/psci.c index 82d3b2c89658..8f779560ab6f 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci.c +++ b/arch/arm64/kvm/hyp/nvhe/psci.c @@ -50,14 +50,48 @@ 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_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_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; } @@ -72,6 +106,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; }