Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3564831pxb; Mon, 16 Nov 2020 19:24:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOr9F+rc9GOmtD0akn93OZjpRLDbnvnEDcfPLY8t5n0pvUEn/l8PXBNRgGhyqJzJgIMQAZ X-Received: by 2002:a17:906:d784:: with SMTP id pj4mr16965030ejb.78.1605583478119; Mon, 16 Nov 2020 19:24:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605583478; cv=none; d=google.com; s=arc-20160816; b=s+SB6NVtDpkRAhqic14SqLU9QZK/QcEsYUt9kaeTj4TItpyRzmj/HjcD4ajmBLkVsN YSenyuBwuDRZAcLRDVMX8pr7gvaTdPAE+Atc24qp9eDUQo6UNwAQzpFRSW5gS5r6wYy6 4zBJxtWhBoI4ao1QflSFXBkQAZwiXzp/kU9diST1VUoaJDfI2W5iYtKm4VIbzllIL6PV 9mFTPcYgMWX/Nz0GUHEF5aNMfEifxzWdcJt2EDitTh8CXEOWPutwbhPMBHwGjbZ1C/83 1BLTfxZ3HNyvG47DjP1qPidfm+/ytyjKzLjN8dTTNN4u/S1EJUemrwSBXts4dBLZEccZ vLWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jBVm/LArO1AVdRcZ+q3L0QCd8OGhOWzJGyI1ZWbTM+k=; b=ny8BHVGUjN2QuGMBQ12Cw436W5y93EgSCFV5LDpEIMhWFZEphRGhBxFgNa8mrdmEHW dQ34choC+ZpVCZ4+e+j1svo17+HdF4WBXh8yO1pXGmd4sqI+8TzqEtn76WZIp0VC0iYN ci3f5Ck6t1pyJv9AIA6LTuoiSG706Yv4r9CogJ4/aaheiS2fhzvO/Zz7lddEsBtpgAFo d/w5t2oP01mm3yR0d3QoQ/RnKHVBAJnyKE951cuccWmHQdDbfxbLlQm3FiIiIQssue4G 5VjVjZ1K1sfGEd64PJQlEFEBJUsRrE9ekXJF3xjYZhDf8sY45r2sAOriOT6bXee0SOtU pB7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jgslmvmt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si698194ejj.517.2020.11.16.19.24.15; Mon, 16 Nov 2020 19:24:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jgslmvmt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387770AbgKPUn5 (ORCPT + 99 others); Mon, 16 Nov 2020 15:43:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387727AbgKPUny (ORCPT ); Mon, 16 Nov 2020 15:43:54 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32121C0613CF for ; Mon, 16 Nov 2020 12:43:54 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id p8so20291932wrx.5 for ; Mon, 16 Nov 2020 12:43:54 -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=jBVm/LArO1AVdRcZ+q3L0QCd8OGhOWzJGyI1ZWbTM+k=; b=jgslmvmt8eyl07t0cwWGpbSH4YO9VXaPfVOOgDE4ZLJZdfxC1arFjcoVmUcA8bERW2 LpjgCO2IomJfdN5wcTNCxzu6/ACvAMfzfYR1xDcg4JV+U7+/rACINJhLTnv+gQRMMAR9 RlXzbFg91geSG4d9QWPIcsQaZNBXxpYjN0bCuwZ5BV9hehTkUFB6WcQUXfoai6so36ba yMn6V4g6VBYFjP3+86GJBswJ3YdqydvCyHRKvrjkBRwNOxyFTnJ62T9rZXoOuF8STe5D QYSvT0l3RZ3uwSF/C8Z3t696VxTLaxi7R84OUo8LqD1GgrIT4HEgDr9/yqhcYuVXiZsA mBrA== 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=jBVm/LArO1AVdRcZ+q3L0QCd8OGhOWzJGyI1ZWbTM+k=; b=FIwt2I7oX7E81pB9PiGNcJYbKuXkeiSlBVdG/TglY/f8WgHv8RYyHARqML0ENy0Xgi W9b0/IZm4BreBwTi8HJZOmEU76STHpwF8Od1oSJuM9OrqNp3y26xA/6hEcXl7wsTFL9O awpAAFfhSrPG75rviMXZco2c+Vn5au/fckmdisaiB6e06zNSJwA79BCw2VRz3ArwA0IJ x+vx6B2FKALWjA98H7r2AelUSdigswJzK6sYgDMYlwd0V05tA+zbC3dnVslfbUY8Duwd s3DpNYdjUSl1k3Lf+fP+roOJ5+7T4ZkPcrSE9KV7FUs4M47SlXmxouq11RGDRCjofyG6 tNnw== X-Gm-Message-State: AOAM530zpr6ngDZo3jSVIcTh6fh5UpQox0sQkTT8G1Pgoa1XpnGpcGx0 jBhNLgkDeIfH12Ci+IKmC18EkA== X-Received: by 2002:a5d:6688:: with SMTP id l8mr22511702wru.360.1605559432765; Mon, 16 Nov 2020 12:43:52 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:bc40:bd71:373a:1b33]) by smtp.gmail.com with ESMTPSA id 60sm21908566wrs.69.2020.11.16.12.43.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2020 12:43:51 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Quentin Perret , Andrew Scull , Andrew Walbran , kernel-team@android.com, David Brazdil Subject: [PATCH v2 14/24] kvm: arm64: Forward safe PSCI SMCs coming from host Date: Mon, 16 Nov 2020 20:43:08 +0000 Message-Id: <20201116204318.63987-15-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201116204318.63987-1-dbrazdil@google.com> References: <20201116204318.63987-1-dbrazdil@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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-relay.c | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c index 1583b63322c4..7542de8bd679 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -55,14 +55,51 @@ static bool is_psci_call(u64 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; } @@ -71,6 +108,10 @@ static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ctxt) { 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_0_2_handler(func_id, host_ctxt); } -- 2.29.2.299.gdc1121823c-goog