From patchwork Wed Jun 9 00:44:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12308461 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 A2CEBC4743D for ; Wed, 9 Jun 2021 00:44:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 35CD6613C0 for ; Wed, 9 Jun 2021 00:44:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35CD6613C0 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 9E0756B0074; Tue, 8 Jun 2021 20:44:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96ABC6B0075; Tue, 8 Jun 2021 20:44:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 749D26B0078; Tue, 8 Jun 2021 20:44:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 37ADF6B0074 for ; Tue, 8 Jun 2021 20:44:30 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D54A88249980 for ; Wed, 9 Jun 2021 00:44:29 +0000 (UTC) X-FDA: 78232339458.17.CCF5868 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf14.hostedemail.com (Postfix) with ESMTP id BB5FBC00CBC0 for ; Wed, 9 Jun 2021 00:44:25 +0000 (UTC) Received: by mail-qt1-f176.google.com with SMTP id p21so4995039qtw.6 for ; Tue, 08 Jun 2021 17:44:29 -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=+rQtvXCRxKOTIz/EZlF+eoC/3R9xTGrhR6gwWFr/7DU=; b=Cw6JYKkMN7njo+Mj8aYXX7ELOe/Z0YqxT5vMM3ZTvVFAbWJGnKRohD82vrII8WNg4F D0I9z+YHniSs564yAlOnK/rUlpDhOCLCJeshp6T9I7pMZhPxTtdgQ2RtrebnjPTIwrRO U5lczcMyVea7KnzBmWqcD0vZiyDjy1rhL8h1g0rnbObUGqG6AQPptj4dHEvi77ttrPc6 gLPMKkk8/Ag2InWRefSkOs9Nmh046fkcd90KZQH8EXO4GFYwZYy73NE5ePutErBiz0In udElGn51BM4wZXIiyQhPp/p77yro83tlcnfVP9KOW5ZMFxbUY+9cYeaPPubpQTpUF22I ov4w== 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=+rQtvXCRxKOTIz/EZlF+eoC/3R9xTGrhR6gwWFr/7DU=; b=ETe1D3lPcNAbJSzB2//pP5Pd7UWwnrb95CfOurFWiROF9/cLSLp4Ttmefd1TYcFyOA dYhprNtiCOnW/h1bavE31h41HHd3sUk3WKnE48AIwJXUnWs2UGr460ScqqJaEAHrRgdL GgJCqxN7XtrXJc/359LdI+IRdOoGz1X6z5M9SGGPXwHqw5SOKvM2D6Frng2jS3W08FQ8 HY50XHK2jeQHtAND2rbo1/UdfWlBFfgFZJb/3Y9iMXL/2ND9JILD6wWC57aszEYBZfO/ mze/mpM+Q8iSVbVsX6jtABWizHCnygkzVzbv3QlGtaYY5UgLlxMVioTdyog8+Sok9ZU9 BbXQ== X-Gm-Message-State: AOAM530MLWvFRW71qn5u47X3HmlRDOF7ghIJiwbnDpIsdJvWT1kHTLie bV5Kui7ezkyZrjK2PCLughdO8w== X-Google-Smtp-Source: ABdhPJxXVHxnf1PDup+eZ76FBqOdGwSPuYwAKL25Z/mZFDlwB7zQWfVE5rSutxxPSstYdHMEj3yKxQ== X-Received: by 2002:ac8:4997:: with SMTP id f23mr5521694qtq.94.1623199468970; Tue, 08 Jun 2021 17:44:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 17:44:28 -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 05/15] arm64: kexec: skip relocation code for inplace kexec Date: Tue, 8 Jun 2021 20:44:09 -0400 Message-Id: <20210609004419.936873-6-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 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=Cw6JYKkM; dmarc=none; spf=pass (imf14.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.176 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Stat-Signature: oyeykx88ptma13khmp9z86espqmb7b4b X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BB5FBC00CBC0 X-HE-Tag: 1623199465-359663 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: In case of kdump or when segments are already in place the relocation is not needed, therefore the setup of relocation function and call to it can be skipped. Signed-off-by: Pavel Tatashin Suggested-by: James Morse --- arch/arm64/kernel/machine_kexec.c | 34 ++++++++++++++++++----------- arch/arm64/kernel/relocate_kernel.S | 3 --- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 3a034bc25709..15c126e09686 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -139,21 +139,23 @@ int machine_kexec_post_load(struct kimage *kimage) { void *reloc_code = page_to_virt(kimage->control_code_page); - /* If in place flush new kernel image, else flush lists and buffers */ - if (kimage->head & IND_DONE) + /* If in place, relocation is not used, only flush next kernel */ + if (kimage->head & IND_DONE) { kexec_segment_flush(kimage); - else - kexec_list_flush(kimage); + kexec_image_info(kimage); + return 0; + } memcpy(reloc_code, arm64_relocate_new_kernel, arm64_relocate_new_kernel_size); kimage->arch.kern_reloc = __pa(reloc_code); - kexec_image_info(kimage); /* Flush the reloc_code in preparation for its execution. */ __flush_dcache_area(reloc_code, arm64_relocate_new_kernel_size); flush_icache_range((uintptr_t)reloc_code, (uintptr_t)reloc_code + arm64_relocate_new_kernel_size); + kexec_list_flush(kimage); + kexec_image_info(kimage); return 0; } @@ -180,19 +182,25 @@ void machine_kexec(struct kimage *kimage) local_daif_mask(); /* - * cpu_soft_restart will shutdown the MMU, disable data caches, then - * transfer control to the kern_reloc which contains a copy of - * the arm64_relocate_new_kernel routine. arm64_relocate_new_kernel - * uses physical addressing to relocate the new image to its final - * position and transfers control to the image entry point when the - * relocation is complete. + * Both restart and cpu_soft_restart will shutdown the MMU, disable data + * caches. However, restart will start new kernel or purgatory directly, + * cpu_soft_restart will transfer control to arm64_relocate_new_kernel * In kexec case, kimage->start points to purgatory assuming that * kernel entry and dtb address are embedded in purgatory by * userspace (kexec-tools). * In kexec_file case, the kernel starts directly without purgatory. */ - cpu_soft_restart(kimage->arch.kern_reloc, kimage->head, kimage->start, - kimage->arch.dtb_mem); + if (kimage->head & IND_DONE) { + typeof(__cpu_soft_restart) *restart; + + cpu_install_idmap(); + restart = (void *)__pa_symbol(function_nocfi(__cpu_soft_restart)); + restart(is_hyp_nvhe(), kimage->start, kimage->arch.dtb_mem, + 0, 0); + } else { + cpu_soft_restart(kimage->arch.kern_reloc, kimage->head, + kimage->start, kimage->arch.dtb_mem); + } BUG(); /* Should never get here. */ } diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index b78ea5de97a4..8058fabe0a76 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -32,8 +32,6 @@ SYM_CODE_START(arm64_relocate_new_kernel) mov x16, x0 /* x16 = kimage_head */ mov x14, xzr /* x14 = entry ptr */ mov x13, xzr /* x13 = copy dest */ - /* Check if the new image needs relocation. */ - tbnz x16, IND_DONE_BIT, .Ldone raw_dcache_line_size x15, x1 /* x15 = dcache line size */ .Lloop: and x12, x16, PAGE_MASK /* x12 = addr */ @@ -65,7 +63,6 @@ SYM_CODE_START(arm64_relocate_new_kernel) .Lnext: ldr x16, [x14], #8 /* entry = *ptr++ */ tbz x16, IND_DONE_BIT, .Lloop /* while (!(entry & DONE)) */ -.Ldone: /* wait for writes from copy_page to finish */ dsb nsh ic iallu