Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3426342pxb; Mon, 16 Nov 2020 14:32:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHqC8s6kuf8nGwCy4F/zXPwHfhFiADhgbOuyEbDJQINiOMBytvH4W1+o11Zf1tOKCscres X-Received: by 2002:a50:bb66:: with SMTP id y93mr17814133ede.244.1605565955797; Mon, 16 Nov 2020 14:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605565955; cv=none; d=google.com; s=arc-20160816; b=0VY9/UfPZHNmvxotkzMlgN31w8NSaGS29iwo5xhniVk50aoLQ480NPL/T+iKd/jPpb PWpeMJMzC7/BSoq61dkI8YhxSt2llZH4q12qHm1LpWUYiGXa+HqM0te5EmAmkxOxJyxn WroDnQoLCn2dCkFJz26ua3lhnBdkiqfyg5aqYjxJa2vqUWKxdQ5FqX8IeGKJL24uNYlD OXq7CPvfC9s6+96hsHbGmD/y1THofXQrHVszW8NaHgOCDCqsIczVXb0TRPerNYBS5l/M Usi3Knya0QSllaR/LX9mJc/rvUh/MddOnrkoTHeas1f/W6DjnFsXrzW2vhfvZLCGiq0t cnjw== 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=1vh/ZyQWPccQlBaf9TiRx0Z2M+/9lMwlUGC5PwlE2iA=; b=g01js2FFjYXiG3f5aifVaR6q6rsamLrj3PLISbLbnuye/FASo0HT4SebCE0KYNbRV4 P24Hqk3FP2wJTvp+wXLDqzt/HgrB9J19p42ogrNXSVS3oFnbo3xPnoHBwS/ckt3r9e5H Ci9Z2dsDfs1Uaht/Vf4HqDPYNnboilWKZBb8kOVLBiLfv+IG2ZAqKproPMPQUU21xh1Y qrRqZrEmWzGCgjuu4VlfnHKYEIy7lT7hFZs8xRxsoOE+IBUq5+EWS6gibfU5FXMCHK4u RSRKIAI0YGbS/AZX5iri+f/pHy1doLjgRVKvn/VVv3C+8DfDTnXfubcTfDYT3OSmDXgx ivgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lYaecYgi; 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 dx6si12458165ejb.698.2020.11.16.14.32.12; Mon, 16 Nov 2020 14:32:35 -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=lYaecYgi; 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 S2387852AbgKPUoC (ORCPT + 99 others); Mon, 16 Nov 2020 15:44:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387503AbgKPUoB (ORCPT ); Mon, 16 Nov 2020 15:44:01 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB61C0613CF for ; Mon, 16 Nov 2020 12:44:00 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id k2so20321053wrx.2 for ; Mon, 16 Nov 2020 12:44:00 -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=1vh/ZyQWPccQlBaf9TiRx0Z2M+/9lMwlUGC5PwlE2iA=; b=lYaecYgiUsVh5Y29T3TA+aUzv2MBsym263hl7v7/lCIsYy/caQZPdpdPDwRun3GkVQ TibEno2QAgL5uGVeuMPYrhhkkwr03mY7fPYSeVkbxTaUfzAqdhHPmokaNPXImivnNQCH 1e4MxfRd8KuJ8d9Rh83Mg1aQHNrCYYGSVoLDsZw0m+gnmtehTXh21pCK7K8z2USUdjyr eIAVkt9IfAXZl4ZRzVlgVQwmVP+MxCSvApzQmWgu5Fmjn/Mdv4Nf2cIZW+x88Q8FRESy 1iTTnAUdmQzvgQHuJ/g6EZ7YT5cIPjXxfJnpaTBHkUaxmCGS1kVEKvD4sc6GjQ6h/ZFj lTww== 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=1vh/ZyQWPccQlBaf9TiRx0Z2M+/9lMwlUGC5PwlE2iA=; b=f2Qhh7AIBLQcENu8c46huAtvV2rZRyoT5Eowln4j9jd3AmYzu33rz2p2M0hhRnCA+o 6VrR+Q3YlqqT8tPPqFmeETfO7168HX7zUkdElXUyGh5N6/MO/oeO5TUBq+Xwym6SGhIv EsED++epI4RaDeNOyLFkNwJdEh0IhfMi8jl5QL+/5xP69Xm2HxqZHR93zEG/DZ/EK9OO qKl1tCFs9XaIPQ51eGPGCqdVdOfaHSTJvlaulA5VXYyNpA8arWy/Vis0lgiDDGrDWMEh CwdrJzZUe9Cg2toGIsHybM9w+AjsTRLF32IXmwc48Pqqhscf3fyMqzOOTmQs2huwrCuw 59Bg== X-Gm-Message-State: AOAM533r9exqRZpJdemGmp5L7CDHtjDqbWZHxoTMMrqxiCQ9c4KbkZeW i/PkxovME8ySBkS5nsxQwCQy6g== X-Received: by 2002:adf:8366:: with SMTP id 93mr21195149wrd.321.1605559439365; Mon, 16 Nov 2020 12:43:59 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:bc40:bd71:373a:1b33]) by smtp.gmail.com with ESMTPSA id u14sm21439797wrq.93.2020.11.16.12.43.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Nov 2020 12:43:58 -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 17/24] kvm: arm64: Add CPU entry point in nVHE hyp Date: Mon, 16 Nov 2020 20:43:11 +0000 Message-Id: <20201116204318.63987-18-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 When nVHE hyp starts interception host's PSCI CPU_ON SMCs, it will need to install KVM on the newly booted CPU before returning to the host. Add an entry point which expects the same kvm_nvhe_init_params struct as the __kvm_hyp_init HVC in the CPU_ON context argument (x0). The entry point initializes EL2 state with the same init_el2_state macro used by the kernel's entry point. It then initializes KVM using the same helper function used in the __kvm_hyp_init HVC. When done, the entry point branches to a function provided in the init params. Signed-off-by: David Brazdil --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/kernel/asm-offsets.c | 1 + arch/arm64/kvm/hyp/nvhe/hyp-init.S | 32 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 01904e88cead..109867fb76f6 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -154,6 +154,7 @@ struct kvm_nvhe_init_params { unsigned long tpidr_el2; unsigned long vector_hyp_va; unsigned long stack_hyp_va; + unsigned long entry_hyp_va; phys_addr_t pgd_pa; }; diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 4435ad8be938..9752100bf01f 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -113,6 +113,7 @@ int main(void) DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); DEFINE(NVHE_INIT_VECTOR_HYP_VA, offsetof(struct kvm_nvhe_init_params, vector_hyp_va)); DEFINE(NVHE_INIT_STACK_HYP_VA, offsetof(struct kvm_nvhe_init_params, stack_hyp_va)); + DEFINE(NVHE_INIT_ENTRY_HYP_VA, offsetof(struct kvm_nvhe_init_params, entry_hyp_va)); DEFINE(NVHE_INIT_PGD_PA, offsetof(struct kvm_nvhe_init_params, pgd_pa)); #endif #ifdef CONFIG_CPU_PM diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index d4a71ac34254..6d8202d2bdfb 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -159,6 +160,37 @@ alternative_else_nop_endif ret SYM_CODE_END(___kvm_hyp_init) +SYM_CODE_START(__kvm_hyp_cpu_entry) + msr SPsel, #1 // We want to use SP_EL{1,2} + + /* Check that the core was booted in EL2. */ + mrs x1, CurrentEL + cmp x1, #CurrentEL_EL2 + b.eq 2f + + /* The core booted in EL1. KVM cannot be initialized on it. */ +1: wfe + wfi + b 1b + + /* Initialize EL2 CPU state to sane values. */ +2: mov x29, x0 + init_el2_state nvhe + mov x0, x29 + + /* + * Load hyp VA of C entry function. Must do so before switching on the + * MMU because the struct pointer is PA and not identity-mapped in hyp. + */ + ldr x29, [x0, #NVHE_INIT_ENTRY_HYP_VA] + + /* Enable MMU, set vectors and stack. */ + bl ___kvm_hyp_init + + /* Leave idmap. */ + br x29 +SYM_CODE_END(__kvm_hyp_cpu_entry) + SYM_CODE_START(__kvm_handle_stub_hvc) cmp x0, #HVC_SOFT_RESTART b.ne 1f -- 2.29.2.299.gdc1121823c-goog