From patchwork Wed Mar 3 00:22:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12113909 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 DC179C433E0 for ; Wed, 3 Mar 2021 16:48:41 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 34F64614A7 for ; Wed, 3 Mar 2021 16:48:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34F64614A7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type: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:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=w4tjLuT88XI7esg9mATGYdwrDDwW4QIa1+frpU2SCPY=; b=S2uyEpEJ42GyZFxkPpayYG2O/ sR45IPPmsnOhqgriU4VQ8vThByvwVhpteH8pCREpd8fGQ1bS7694vGe/1DWNWgcJPeB7CBZojdWip 3pfQHiakLAFJn7LcZTgmOpE779KrdyS33LCHweUB2kSWpK/aGLccSGmxg0tv7zIR6epbDQ7xbiEwG 8FuhGvXCJ0zHV0O3nJqYZ95LTJXDqVENeSUSrJp7B/2mTHI9G7Jh+nYueP9cmG9vxNOTX+hfZ4i/I 4lgvsfXO/Yc15YHlqirlBjQQTRH9ZWXpBxD1UuU6PZIpd8Hib9H50bQU90ugL3975oa7aPUmrfE65 rvza3lfaA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHUd6-005euB-1l; Wed, 03 Mar 2021 16:45:44 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSqu-005EME-BK for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:51:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=ATHDsIlQRij0i8p3z1/oZchje9DfRT1VSEQgV22ghC4=; b=wWRoz+XbR8tPPhasmzh2AGk+yB EuRAy3IBDuC86ZLeI+cQjlxKytX8HF57PjgEsAUoFFDWCWUje72RleQ+CoyQJDf6Rg0zSYhelLkMo ufYY4FKB/KQS+QVpJcfqRjb5KOusS98Ulk/zDjZazN5EeVu+jFj4RxgO5qAcPJ85A86KQxp5P4FE1 EzC4Xkw+L9QFP1YM7gjGpDI3nuyjAq+tukPOCe72VYXNpp8kaub77/u8ex6T/Lgim0gtJ6oKZld1Y sSbIX50RY4wOne81dL0Ld9wpoJ3/tBrIdpNR7cC437rK5DLUKrN/4l6o4fyA99P4i7y2hg0t1cXSz N2j7Bo9Q==; Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFIv-000jdk-EW for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:23:54 +0000 Received: by mail-qt1-x82b.google.com with SMTP id d11so15555696qtx.9 for ; Tue, 02 Mar 2021 16:23:51 -0800 (PST) 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=ATHDsIlQRij0i8p3z1/oZchje9DfRT1VSEQgV22ghC4=; b=FBdyqZaIcDyDYLlxElrZkuvpRkRku/nV1NAZj9UA7Kl0fuBORRQply+OelppUmA5/X YdOr7jgb6xCxZMVvxMAcCH+UB76E2UqPr8+Unv7yNzOfN0g/mRQJU850K0bipeneaRdC 0WfXYfl0XdrewOTEEVkNkr4Lc/IGmFcluOa3uHtSXXXbq7gKZ5vwgyBe/7c9xGU1wiFK Q38hSdvjT0G2vbcJ1e+1tLkWB8lGsOtC1XnvGT+Bg/yC/a1whgpNW0yKjwt/kUY1FC93 zcHgH6K4aNPWKbx2D1PifjppE8zXUC4vlX60NN8LCSNtkLWhJOCrvpiJkGwJyeoZ6GOV CuTQ== 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=ATHDsIlQRij0i8p3z1/oZchje9DfRT1VSEQgV22ghC4=; b=A3quC9GajXSfJNTbigFlhqjEAGHbFLOa26NGSETz3j9nahhPEi9p4JpiRgjZJVRiZb 2el1W7X0Vc3s2eHOplVHLm6kq5b3uOOr+I+Ei/jI2h+kDJ+1r4IW8BFLBYWeW89jTDkz P+oeKNLx8GjHxBzOKdnnWcrzUA7ijSPViDl6ppvRp3En/Y8JlZYed7vLsn9zbTP5SjvM 4QrizbA5MTBZuG2HU51A4IoykH29dubz3Rn8gaR0RmQIsejusVqKkIzJJD0+eo5R7Ld+ rAd0JYY+su0zJ2b5wYTJnb7yYY20xQDQXm+wK8wMIyWmWTuiQGq7lsRLyztNXD9cgOJh EZpg== X-Gm-Message-State: AOAM5314/mKo/inMb3E6MH0EvX8nj2rOcwjYx0rcZYh2d0/3qL8mWHUx uWOoKyli9uSGJQSYIr75RGjWxg== X-Google-Smtp-Source: ABdhPJyyN8JxnvqauMS4QIYOtU4flOLUY/VfPIcIZzPJfu3L3JbZXHRoVShtyq5YtQyvU4C/7Kg4+A== X-Received: by 2002:ac8:5953:: with SMTP id 19mr20290245qtz.263.1614730968594; Tue, 02 Mar 2021 16:22:48 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id r3sm16690512qkm.129.2021.03.02.16.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:48 -0800 (PST) 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 Subject: [PATCH v12 12/17] arm64: kexec: relocate in EL1 mode Date: Tue, 2 Mar 2021 19:22:25 -0500 Message-Id: <20210303002230.1083176-13-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303002230.1083176-1-pasha.tatashin@soleen.com> References: <20210303002230.1083176-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210303_002354_705125_DB7B86EB X-CRM114-Status: GOOD ( 12.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 enterying 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 1922e7a690f8..f6d95512fec6 100644 --- a/arch/arm64/kernel/cpu-reset.h +++ b/arch/arm64/kernel/cpu-reset.h @@ -20,11 +20,10 @@ static inline void __noreturn cpu_soft_restart(unsigned long entry, { typeof(__cpu_soft_restart) *restart; - unsigned long el2_switch = is_hyp_callable(); restart = (void *)__pa_symbol(__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 fb03b6676fb9..d5940b7889f8 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_callable()) __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. */