From patchwork Wed Jun 9 00:44:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12308469 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 9064EC4743D for ; Wed, 9 Jun 2021 00:44:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 459CF613B9 for ; Wed, 9 Jun 2021 00:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 459CF613B9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1F1F86B007D; Tue, 8 Jun 2021 20:44:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1800F6B007E; Tue, 8 Jun 2021 20:44:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9B176B0080; Tue, 8 Jun 2021 20:44:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id B3D8B6B007D for ; Tue, 8 Jun 2021 20:44:35 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4681A8249980 for ; Wed, 9 Jun 2021 00:44:35 +0000 (UTC) X-FDA: 78232339710.35.7B9224D Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf20.hostedemail.com (Postfix) with ESMTP id 6888D37A for ; Wed, 9 Jun 2021 00:44:30 +0000 (UTC) Received: by mail-qv1-f48.google.com with SMTP id c10so9168468qvo.9 for ; Tue, 08 Jun 2021 17:44:34 -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=ZPSVbTnhn1kzrM4k6yG1hZdalcOX13NxNhzKc5GCg3M=; b=LGgj1DSeN2dBtzalXLyd/X7N/RCTiZa3EUru9uNeWdpVQJnvQ9bVsOe+hpBq10aBS+ aY1IEnfFr3j+uNpDjtIRX15IWRmDkCAmORZVFue5KNHoK9ciqWHqDq8PCBfaG/bKQ9PX H4wnXAYOwb47RzvJL85RhAzTQ4swYnk5uLiqv1RevSgZBxDenYt+PNKEP6Xg8h9NdGQ/ 3DLpUIt2K7tm2CzWfhFt6+tTbTdPRHX38gq3dsPGJUfHALsxCr1UcjF9n5kDaIFRgbym rbYrqPpH4MczVux3IZZxQkckEORpurxOSkjx4dSeN6myWV528RbdrQVhFzdB/rchvYEp Mpzw== 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=ZPSVbTnhn1kzrM4k6yG1hZdalcOX13NxNhzKc5GCg3M=; b=UlGLnm3em/pLBQct+KIM33KDM1BJ+35tsTSJ7BYgazzqdwjNYXadOjKbrTPTRcqxFM tpdE2GptUy87HSiQ+qb7Jc95sBGjF1jO7uC33If/w8ZLpsRtXgfr0BC+peLGRZA9b/ki 3phMlIB46buu58HY4qemOl0qVuPW8tnVE+3rvzpqFur9xlCRATJTwY6lhUmgPINQv7iy 6z+2U3sEbQEbSVvdt3u1IYYgozKj+zZU/Iud2HWJdyxxf32KzZrLGxr6N/76m2Kpj9X8 EahyCyhuOw2VMSZxGI4nfQ+mINxnsvHHQSgU4OwThBuGFtNbd4AtiPJIEFHqYDrV0hlb TCYg== X-Gm-Message-State: AOAM531uBY+nmvWgea1xStNUAvZqNU1kqcGiWtZDTgar34ynBEhwUbA/ LtxrFvHQJXqoMVRR2pHPosaioQ== X-Google-Smtp-Source: ABdhPJx9mZ6UlFMdNKDraoLwthZ4OWu6MUyQRTHx+1rf8HWW0BNaBOPk307SDiklwhYTyx05MvoNSA== X-Received: by 2002:ad4:4713:: with SMTP id k19mr3379354qvz.26.1623199474423; Tue, 08 Jun 2021 17:44:34 -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 n194sm12869011qka.66.2021.06.08.17.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 17:44:34 -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 v15 09/15] arm64: kexec: relocate in EL1 mode Date: Tue, 8 Jun 2021 20:44:13 -0400 Message-Id: <20210609004419.936873-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210609004419.936873-1-pasha.tatashin@soleen.com> References: <20210609004419.936873-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6888D37A X-Stat-Signature: a7ucjtgq5u5khwhszuccic3ixanibom4 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=LGgj1DSe; dmarc=none; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1623199470-759856 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 e0ef88cc57d2..152fb00bcccc 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -231,8 +231,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 36b4496524c3..df023b82544b 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. */