Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1953980pxy; Mon, 2 Aug 2021 14:59:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7a0IGTV9LoBFp4OQ/7r5aqRJi6BAz1OnXi3tdpR5VsB8FFN5zgeMeYVxKod1ojxwHPCae X-Received: by 2002:a05:6402:28a4:: with SMTP id eg36mr22228559edb.84.1627941559654; Mon, 02 Aug 2021 14:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627941559; cv=none; d=google.com; s=arc-20160816; b=Ewt3Fx6/XcrfxzPH2Dqnn5mYy9+tnYTEorbQL+ASysiRH9AqsFOZT7+qaE23Czc1C/ 6x7w3kSVro3dp3WTE+vX2ynuf7VsgEHfDIgEAESuagiIwQB6CY8720uE+JioQ0xHeawu d2/v+PEtPfUfA30IiP9PijhhXmI6QvYohV3diOad8V2cp77YdOGI+IwvedN6iei0PLDV Qqv8gmKyNMoNwvFu29hcIierlCfEndMRxsf1Pd+JxLpF/hNxXEYIS3Bpaf5AL01oE+kM 73jAQ0AHZG78GKfLK7lrjsJHnDO0tfguBRgnxqDxa0u/7CqfDWgs/tOYq5GrHKspRfCy 4zzQ== 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:to:from :dkim-signature; bh=Wj2NAixWvJ4nO1FkxHbUkwp7sIToaWThfISCCFg6+8g=; b=Q8DkNIr1QF8T4iAZ3pbG5EB597mhBwW3aPX0JIb0FXLUGq1fK868Dv0E9PaLFZRGmO xSPexacGy4QTQrg3lfbiN+68UlPFKtoZl8BcfOQ0hIfdcZB7rKYs364xhak3K61GRPTP VvTSEuVkw8NyQr54BnE2xFww7NnxV/FHNHDCqWnEjoAh5gfnw9OBF3GSmSuBnRFOZxco N93RxcxrARd503NrYO9HOrQrLAsChG6p9LfHNkzst5PUXePmvjFK00vGpnV56niUN6kg UEONgroNO8VDWfu4l/i+bkfjLIQ86pefg69PAv6NWQStUrFEtGzteq6XytICMlEF+ovF Yt5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=GscCSfNw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hy4si10015705ejc.285.2021.08.02.14.58.55; Mon, 02 Aug 2021 14:59:19 -0700 (PDT) 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=@soleen.com header.s=google header.b=GscCSfNw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233412AbhHBVzA (ORCPT + 99 others); Mon, 2 Aug 2021 17:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232965AbhHBVye (ORCPT ); Mon, 2 Aug 2021 17:54:34 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E75C0613D5 for ; Mon, 2 Aug 2021 14:54:24 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id t66so18180691qkb.0 for ; Mon, 02 Aug 2021 14:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Wj2NAixWvJ4nO1FkxHbUkwp7sIToaWThfISCCFg6+8g=; b=GscCSfNwt44SsxAiPP7NgcgGNAXIbZIzPwC6/zqeK9kfqT8QLhkAwdkgkT2aZY087m 5KxwAVR12ZBJ/ZeCQcNoNKBBF9L+Ds0Hj+DcneIUI8ImzTrkqH9HxKuMPLFmwQsIL2XK bwuxoBK+4RmtzMm5BflhOQZqEsmZxQ0o70Zz2BcWeFPjp8YlBy4MF8vqjY80xbZLZ2jR T/2CwFLk0SR/DPY1g0sIDtYy50PCkJHFZYvSBfOmijbPnYSoHafv4h7czA+iRWjP/ZpV B1cOUnKsTAIUEMluLV/clockW2VvJCE1ndGhTSzVJhSqYABRu+HrJeFpQnkXSVhM/GCk O37Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wj2NAixWvJ4nO1FkxHbUkwp7sIToaWThfISCCFg6+8g=; b=Plui3lwrqJRJkx+pjBsy3DKYRD48Tmmgc/Dx+br/oBjYPymhZcBmURpRZvSXz6FXtT 0nrbyPaTIzSB3bTrGEvHCxL/IfILNeM13aa7QZ6FUDtozJh18WDlTAKy+at3tvCWgVUq 0Hb+wnSyxT+75FcHbnlM/TzheGdk9naVMEt08fHzgLC05zguAbBbCQIIOdhdnl+npLFO ZEDlU1XjfUq5WgujcCXYA9za6OpcxFuHD5EKRAXRsGCXcWbNuODCeVcoQ0MiofGUB3+w rCm/4AwBKHmTQcHqW3+ikefs6MmIwuh+OVdrBMxLvjxVOzkRVdVTJnlaPwukZ2leSWhg GBmg== X-Gm-Message-State: AOAM531SJapTMIKUtbvQ+i7Y5B7QSw1sdqvjSRV6MPTesvxY9WoHwd5v KCYqdidF0RstbhqxDxbJno4Rhg== X-Received: by 2002:a05:620a:a8f:: with SMTP id v15mr17503007qkg.257.1627941263546; Mon, 02 Aug 2021 14:54:23 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id v11sm5479216qtc.0.2021.08.02.14.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 14:54:23 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, maz@kernel.org, james.morse@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com, tyhicks@linux.microsoft.com, kernelfans@gmail.com, akpm@linux-foundation.org, madvenka@linux.microsoft.com Subject: [PATCH v16 09/15] arm64: kexec: relocate in EL1 mode Date: Mon, 2 Aug 2021 17:54:02 -0400 Message-Id: <20210802215408.804942-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210802215408.804942-1-pasha.tatashin@soleen.com> References: <20210802215408.804942-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since we are going to keep MMU enabled during relocation, we need to keep EL1 mode throughout the relocation. Keep EL1 enabled, and switch EL2 only before entering the new world. Suggested-by: James Morse Signed-off-by: Pavel Tatashin --- arch/arm64/kernel/cpu-reset.h | 3 +-- arch/arm64/kernel/machine_kexec.c | 4 ++-- arch/arm64/kernel/relocate_kernel.S | 13 +++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/cpu-reset.h b/arch/arm64/kernel/cpu-reset.h index 81b3d0fe7a63..296abbac7192 100644 --- a/arch/arm64/kernel/cpu-reset.h +++ b/arch/arm64/kernel/cpu-reset.h @@ -20,11 +20,10 @@ static inline void __noreturn __nocfi cpu_soft_restart(unsigned long entry, { typeof(__cpu_soft_restart) *restart; - unsigned long el2_switch = is_hyp_nvhe(); restart = (void *)__pa_symbol(function_nocfi(__cpu_soft_restart)); cpu_install_idmap(); - restart(el2_switch, entry, arg0, arg1, arg2); + restart(0, entry, arg0, arg1, arg2); unreachable(); } diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 59a4b4172b68..cf5d6f22a041 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -240,8 +240,8 @@ void machine_kexec(struct kimage *kimage) } else { if (is_hyp_nvhe()) __hyp_set_vectors(kimage->arch.el2_vectors); - cpu_soft_restart(kimage->arch.kern_reloc, virt_to_phys(kimage), - 0, 0); + cpu_soft_restart(kimage->arch.kern_reloc, + virt_to_phys(kimage), 0, 0); } BUG(); /* Should never get here. */ diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index 63ea19868f63..b4fb97312a80 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -13,6 +13,7 @@ #include #include #include +#include /* * arm64_relocate_new_kernel - Put a 2nd stage image in place and boot it. @@ -61,12 +62,20 @@ SYM_CODE_START(arm64_relocate_new_kernel) isb /* Start new image. */ + ldr x1, [x0, #KIMAGE_ARCH_EL2_VECTORS] /* relocation start */ + cbz x1, .Lel1 + ldr x1, [x0, #KIMAGE_START] /* relocation start */ + ldr x2, [x0, #KIMAGE_ARCH_DTB_MEM] /* dtb address */ + mov x3, xzr + mov x4, xzr + mov x0, #HVC_SOFT_RESTART + hvc #0 /* Jumps from el2 */ +.Lel1: ldr x4, [x0, #KIMAGE_START] /* relocation start */ ldr x0, [x0, #KIMAGE_ARCH_DTB_MEM] /* dtb address */ - mov x1, xzr mov x2, xzr mov x3, xzr - br x4 + br x4 /* Jumps from el1 */ SYM_CODE_END(arm64_relocate_new_kernel) .align 3 /* To keep the 64-bit values below naturally aligned. */ -- 2.25.1