From patchwork Thu Sep 30 14:31:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C68C8C433EF for ; Thu, 30 Sep 2021 14:31:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7EAB560551 for ; Thu, 30 Sep 2021 14:31:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7EAB560551 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 63CF09400A9; Thu, 30 Sep 2021 10:31:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C46094003A; Thu, 30 Sep 2021 10:31:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 444169400A9; Thu, 30 Sep 2021 10:31:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 2C82F94003A for ; Thu, 30 Sep 2021 10:31:26 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DC2C38249980 for ; Thu, 30 Sep 2021 14:31:25 +0000 (UTC) X-FDA: 78644477730.16.27BB5D8 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf19.hostedemail.com (Postfix) with ESMTP id 92448B000446 for ; Thu, 30 Sep 2021 14:31:25 +0000 (UTC) Received: by mail-qk1-f174.google.com with SMTP id 194so5935111qkj.11 for ; Thu, 30 Sep 2021 07:31:25 -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=8cW/IVlTGR5Obb7nU8rBJjg2uf8tpcGiOc+9iw339z8=; b=LGZ+V3ieH2k3Ak86m2WgJk69Yb4/UpPLxocU8YOxOu6VywnSRkV5tG6QX1CZAFVkjH IdxIVertagbOxiCikHfXeI+gyRxyIK4n4WNp1gD2dM3hVmXHeWY/0MZVIVU7p16dt0EE kQyfCpW5wHlohwk4aa6PjA7uPCBnCZ3aqzRo52eBJjEIs/y+7yHsylM6P6A0lmWxLvdl W4ughsB3UmWmnmLbk1MTeuaS/nugc+CYzDd6T7qr/a1d7xhATy3542wZgxbkBlmDuy4P Vz0qwo0+V3u7WtKUnsS7vgeAv3YUSK4CE8SJAitCqTQ88TYgfnftSHQblwWyCxVgwAFj 5hNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8cW/IVlTGR5Obb7nU8rBJjg2uf8tpcGiOc+9iw339z8=; b=zrwRgk77IZdBMUJ801UI81FysYVQpF4m7kmTWyr3uMo7xZxYWOzSxCQwLfNzcYJYkA WmTHly2YEdou7QTOJqX+jGhZmfucK7qJ1zJ+tC4qhey/s9rVD8Da66kta3udTQsfHHKb 5UrKSIyfjiboEqsdDPMB6zoZeXsqxVL2cQLrbGDjjkw4maZ5xZrz40JowU6G5reqD0Lq Z/DWsPCJLZmbv0CtO1/0okEMHJ+7b8/08f00ehUeqWmivNqtTpq1EMvrkejkDtFZ5LNJ pREP/Tf3LxR34EirRU6VWA28n587vRdcGN/Ll1/3CgUBbfM2z+HAdTpuXf5BJ0gQtpwy ZGjg== X-Gm-Message-State: AOAM530JK9B9yTc29Ii4Apy59NLN4Fztm3IkSdErkv3g0bzvOa9PP39f ggY/mM9q+yXPr9gUdWGSCNU3Rw== X-Google-Smtp-Source: ABdhPJyVmacE1sVXxqp5kGQ3RLtcUFdTcFqDSjNppAD3P445XkdfyacytvCYjB45IVcqvbFv/tXoJQ== X-Received: by 2002:a37:9e8d:: with SMTP id h135mr5202679qke.189.1633012284930; Thu, 30 Sep 2021 07:31:24 -0700 (PDT) Received: from soleen.c.googlers.com.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id l195sm1528731qke.98.2021.09.30.07.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:24 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, 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, kernelfans@gmail.com, akpm@linux-foundation.org Subject: [PATCH v18 09/15] arm64: kexec: relocate in EL1 mode Date: Thu, 30 Sep 2021 14:31:07 +0000 Message-Id: <20210930143113.1502553-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog In-Reply-To: <20210930143113.1502553-1-pasha.tatashin@soleen.com> References: <20210930143113.1502553-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 92448B000446 X-Stat-Signature: r4sfxcjr77rmqwh55e66ip11tgtx1pir Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=LGZ+V3ie; dmarc=none; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1633012285-473975 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: Pasha Tatashin Acked-by: Catalin Marinas --- 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. */