Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp643078pxu; Thu, 26 Nov 2020 07:57:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3tJOHW8glHeGArcTbksIPkk+lLdHi8LKtP9J0Xp4e8dB5iKY0o5KR9DXhxZoxGVZ/awdk X-Received: by 2002:a17:907:a8c:: with SMTP id by12mr3276210ejc.196.1606406269405; Thu, 26 Nov 2020 07:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606406269; cv=none; d=google.com; s=arc-20160816; b=Oi+5dWY6b89UwsJlSIxrfrOraXlzyX3jywstlRqZA/Ti0wFPUA0UDhWydNU7NCxxRm IPOnq1k3yeh0HloKeNWHqBrB5B48/9H8b6MW6zMJIozzDXNuVWRMYSrDeJnVATsOEDP0 s3B8E1WZYEtnb3E1NYob/WNiyayzjMqjlnCm2KS+1hAcz3jYgBHmaat3SLuCUv0zqoLY LtHPeavg+ZjOWNapyMRp5zt4Nlclk+ftS4mdixDllHs7rRs52U0JZ2IKzRwtKX+PzccO e2w9ncYT6v1PuMqZFrkN+CPr9sjLO0mpraskyAwTt96kFWPhwFR+9l17zTVESw/1TB4T pg4w== 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=SfJedK8TmdKV/cyl1d120ny+FNMOujRjMwXhHWy7kEg=; b=tnjivu8xRJIwYUdWkYVSXWiOz1w38RO5futNR6Jml29DIkbdOaXEg4+1rBD8P4UAVt rLq2xPq31BssFYtSIaHNJt7s3pWQTjKNXhwUziaYNDSlqaLL4H5IMSdXoffXqTZkcwD/ SE0Qv/8X56XAK1pPUSW9ARfcdJy/aPVNf7DjU5CRkbm/uqOXVErx3o1Ao5QJ7dSH4HFh NczJ+wlmd2+vM35VnM8BEdhkfrORYzT+QE65Z0K4BRkKu2t2YJ9wofPwwPqrYqIooCi8 nmAsyty3PUVg7vmJGcz/6n5mN17+hFMeM4i9NYm40/X/aQJyJqtBRJZ7/b1zJmiZ3r09 wFGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bpKTMIQ4; 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 a5si3199295ejs.534.2020.11.26.07.57.26; Thu, 26 Nov 2020 07:57:49 -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=bpKTMIQ4; 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 S2403801AbgKZPzD (ORCPT + 99 others); Thu, 26 Nov 2020 10:55:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403782AbgKZPzC (ORCPT ); Thu, 26 Nov 2020 10:55:02 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6672BC0613D4 for ; Thu, 26 Nov 2020 07:55:02 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id 64so2617409wra.11 for ; Thu, 26 Nov 2020 07:55:02 -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=SfJedK8TmdKV/cyl1d120ny+FNMOujRjMwXhHWy7kEg=; b=bpKTMIQ45FtDnN1sJCDvWAIZ7n/djBhSnLXzmY+GV3rFxtQaEk/jg/HB36CWMm495r 9dyFHXoPlu/6QutYqpZJmOg6wUa99TMcYimuqBqgMfHfcuSGIsViQw1MXVzV82LPd82i Pj43fk2YHVp4/nrQzaAV15yi8dEl9y91D9o67oVTUxotstSuybJnE7DzvY+syCsPyZ0r i7K6L+NiAdodloJMqgZapUI8KuVSrpzLBeQTSEwO+ivclJL7Bslw5QTQUjmKfRssPExa yYzn1XdS7tNvkiZzCkmHrTStfaA2Bdj1iMTHoEVd8DzcAOU0FEV8TW3U03uWNpqgVrWJ v3xw== 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=SfJedK8TmdKV/cyl1d120ny+FNMOujRjMwXhHWy7kEg=; b=gdh9V9vZWBsQUSzXdFLjqCq7AfJl7YXsjabdvPu9mg2CC/Yu3tbRrmeQs/uZ2XSOnm 6RiyfD0QjJCPS67Ej9zXuFQkn8LI1Uy9wtBMe5rsfHUP6s17RpQGGSBdEZybacyiMJch 94NBq98Rp3lklcl0QZy75S8NFR4nWjNRNIK0wb6vo86Yn8v2Grlq0gXVa5hKOYpqwWj7 lujiLoow2RaaZKVBrp4UZ3TJDQvoqig5uJ+azoRO74qe1MWSOfmaBQQctRyT2evNozRs CrbEug2u2Jf5EfY8r3/l1Tt+yiyuPKCBK3jU329tjr5oW7dtntqInkbkIUFk3/mTT5E7 XUqg== X-Gm-Message-State: AOAM530tuKbN+DRCE7oeiQVQi7wueoo3PCmgMHBFWHH0nH8T3Jk7XS0U RRqnpfva3550DiYOarcp/TLlqw== X-Received: by 2002:a5d:6743:: with SMTP id l3mr4652330wrw.82.1606406100935; Thu, 26 Nov 2020 07:55:00 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:f008:704d:8d4b:9951]) by smtp.gmail.com with ESMTPSA id z11sm10645961wmc.39.2020.11.26.07.54.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 07:54:59 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: Jonathan Corbet , Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, David Brazdil Subject: [PATCH v3 16/23] kvm: arm64: Forward safe PSCI SMCs coming from host Date: Thu, 26 Nov 2020 15:54:14 +0000 Message-Id: <20201126155421.14901-17-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201126155421.14901-1-dbrazdil@google.com> References: <20201126155421.14901-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 e7091d89f0fc..7aa87ab7f5ce 100644 --- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c +++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c @@ -57,14 +57,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(cpu_reg(host_ctxt, 0), cpu_reg(host_ctxt, 1), + cpu_reg(host_ctxt, 2), cpu_reg(host_ctxt, 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; } @@ -73,6 +110,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.454.gaff20da3a2-goog