From mboxrd@z Thu Jan 1 00:00:00 1970 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.8 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 E6EE8C388F7 for ; Mon, 9 Nov 2020 11:38:31 +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 6FA50206B6 for ; Mon, 9 Nov 2020 11:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KdTrLnmj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="jrUqYCAx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FA50206B6 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=dYayGFTcs4ToTha3C+TU3SFkOBs9P4N5eEFcd0tW2MU=; b=KdTrLnmjSO41G6FVaXFDzlW/w napEW2CkZJ4iXPbGQgs0FYrgOtchZEZOUFySqHf8c+w5/xifopTguTqhOqDnMJOUbzeY1NYOXPwDh lHUjrkpKyeOoTnAHehW6IWDcv0fx5x1KRFirO3W+NF/XSCY7dPi9Vjatftx6lP5wxSnBXuMnqJ2+b tY+xvPyZwRE+MRvi/Ui4c+FS5aYE1TkHtwqLG9vS3aVW7JXHlJwOc4ATqYNTo18KyBoZExrPge+kX 5P5qSIHeRlsFt6/t/+QgJjL+noy67K+l/gUEIYFElJ04626q5xvrB6VO/sBBq2MPWROCq52t5n399 P0AiSfhzQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5Sp-0005gS-Ac; Mon, 09 Nov 2020 11:35:59 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5Q3-0004TX-UQ for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:33:20 +0000 Received: by mail-wr1-x444.google.com with SMTP id o15so470075wru.6 for ; Mon, 09 Nov 2020 03:33:07 -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=gwTDypgwUf3rqkSua5uxQzTJijirOP4lU9f1S+usZSk=; b=jrUqYCAxKbMftvyv6EO+CyG7nRBWv1N9ciXM0WTM22HN8ijzC7yryR2lqJGhSbRuOG iwtZf64B+wSe1RFqDZKWDqB/cZ0sAqey2anS57mqhoAJ20bblxIJNt8SlhnR/l4hsN63 vs2yLQ6INp6gpfIL+5SmE6i36GQASly/+2LS6TLFeqqRgjqgsOBKxrRqqkh7Iw1AgMwh HHGaSM3jxkADdB1M0xeCQ9TlxT8iW3y0dO7RzbJY3SeffWP8ZsWfb2PPOUsAGn7hI9rP tJ7M3hRhPTfE06JkGh3e6zEHRr9fFR/9o/IuwJqCwI8nZd6lIb7JeKWU5ISX7viZgUlB 9IPQ== 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=gwTDypgwUf3rqkSua5uxQzTJijirOP4lU9f1S+usZSk=; b=DGiI34XuVLyZmBBSImecoqowLjmjmYGCWVcNt1dO6JjLW4UTXecDkxLydco4kU+4FA sQsHb++QikcYQRtCwSzI+8U9CoYeBYyR2mXPy8OeOpqOLj8TVjQ2rdYUZg2NJrQriKuT HtBbTi9zmQctGdHtp0NxpvJdlYh55mNBIG3dGz2yHY3I5vnfej0RG0C9qV/6xaD19bn+ PpWNhMh9QPmm8vZuHVmERr0GdLFNEoojQRoiOT6QIDO5u7aJx4JMp/15I+axJU9ttsMR vsMzYSWkYgs417B4YbKdlJuTFBc+lXRJiYz7JXCMPbuxfYYxBW9JvaL7GjW2s78xzB5z +wSQ== X-Gm-Message-State: AOAM532bJIkt5/aT/BaJGcbvJj25EHixToS7cIwFTKn2UcvqimtbsfmK qA6U/FGswJ26kOWnXBdb8agmHER6DXCQg8MF X-Google-Smtp-Source: ABdhPJzFLULK2SSOyOQsTmDu18P2ApF4H82covw7VmzC9kWedcZrYGtm7jY72SGBGNtESQ3aE2thsQ== X-Received: by 2002:adf:db4a:: with SMTP id f10mr2709289wrj.420.1604921586733; Mon, 09 Nov 2020 03:33:06 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id n22sm11769101wmk.40.2020.11.09.03.33.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:05 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 13/24] kvm: arm64: Add CPU entry point in nVHE hyp Date: Mon, 9 Nov 2020 11:32:22 +0000 Message-Id: <20201109113233.9012-14-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_063308_160885_D8BFB983 X-CRM114-Status: GOOD ( 19.06 ) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 893327d1e449..efb4872bb29f 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -155,6 +155,7 @@ struct kvm_nvhe_init_params { unsigned long tpidr_el2; unsigned long hyp_stack_ptr; unsigned long vector_ptr; + unsigned long psci_cpu_entry_fn; }; /* Translate a kernel address @ptr into its equivalent linear mapping */ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 0cbb86135c7c..ffc84e68ad97 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -114,6 +114,7 @@ int main(void) DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); DEFINE(NVHE_INIT_STACK_PTR, offsetof(struct kvm_nvhe_init_params, hyp_stack_ptr)); DEFINE(NVHE_INIT_VECTOR_PTR, offsetof(struct kvm_nvhe_init_params, vector_ptr)); + DEFINE(NVHE_INIT_PSCI_CPU_ENTRY_FN, offsetof(struct kvm_nvhe_init_params, psci_cpu_entry_fn)); #endif #ifdef CONFIG_CPU_PM DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp)); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 1697d25756e9..f999a35b2c8c 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -159,6 +160,35 @@ 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. Loop indefinitely if not + * because it cannot be safely given to the host without installing KVM. + */ + mrs x1, CurrentEL + cmp x1, #CurrentEL_EL2 + b.ne . + + /* Initialize EL2 CPU state to sane values. */ + 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_PSCI_CPU_ENTRY_FN] + + /* 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.222.g5d2a92d10f8-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel