From patchwork Mon Nov 16 20:43:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brazdil X-Patchwork-Id: 11910819 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 37620C2D0A3 for ; Mon, 16 Nov 2020 20:48:45 +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 7630D2223D for ; Mon, 16 Nov 2020 20:48:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GQ62Qvx9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="lYaecYgi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7630D2223D 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=3MtvhmBtAG3TiUW+BhWU/99NNdQgVjAyMM1NGCHunR0=; b=GQ62Qvx9/MEc9ybM/JjA8v1ru I1JJdCFUqf5DijoMEbydw3gOYlOqUSFMGdcmYz24mkpVE7am8gruYMkCnvDdpKbr9dnNYogFGdmYa tB2ymXG4hu8WWkMuo0F+IyKMRxvdLRMl5LVBvGySMN8+4RTisFu3C3NNInnhzneoHfMw6YBQDr12A gCDIQfTO//yhoHf8wpEsYoHOt3UM8k/vCp1hoU570RXBDJX+7kH7N+G66hYi6LvBEBLKzByTZEniY 7gR+7bpEG57B78k57WvSvxWericpHImOeqaKXS0Q+dbiyL39ka8xC1pR+278noFGS5lD6FOZkkCFE TFDqOW0vA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kelPk-0001Ds-L1; Mon, 16 Nov 2020 20:47:52 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kelM0-0007og-PF for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 20:44:07 +0000 Received: by mail-wr1-x443.google.com with SMTP id o15so20282469wru.6 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=eThHbCqLuOoh2mRd/5rUkit82Mztnmn9SWN6L2vLGGwHFoawQtA35wtwAdL3xh1TcG btPQKBpeDtns0u9tBp5oaveX3YlJESLrciilnGYLQ6juIVnLXurznAuhvSUl8i0znJJc ieKGwEzMA8LREetDQqS/tNhGWaWRElm4SPiXXYgngxON3utQbNQomMfARplVFMBkwRpt HU5SSQML90SCeBKw91av7MA+cD0o3ptKod+uwh+LHz5QztmdPQDm/nP0ZezQY9jaYrzf Xmq1+PvoyYtT0+tCWTq3y+yNZRN3t7+19nRZm9w5qrGWaE5+iOYdGmh6rxnYT4Oo0fok ft5g== X-Gm-Message-State: AOAM533S+LQqqodX485caZvkuVdyUEpxccseSGPOBjKpl5qx1Sm2vrDx X3EFL9nRvETEUakf3Lq0T3PEJg== X-Google-Smtp-Source: ABdhPJz+z6lHUZHhLRo8hPqDD5egPFyYy5Oa9Q7KVNb2Md2cVBffXmyb9o9Xy5q1uJzaghGQ8wBNnw== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201116_154400_943727_FB13F36D X-CRM114-Status: GOOD ( 18.43 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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