From patchwork Thu Sep 30 14:31:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528509 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 2A9FCC433EF for ; Thu, 30 Sep 2021 14:31:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D17FE61A0D for ; Thu, 30 Sep 2021 14:31:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D17FE61A0D 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 A34F79400A5; Thu, 30 Sep 2021 10:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BF7194003A; Thu, 30 Sep 2021 10:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8104D9400A5; Thu, 30 Sep 2021 10:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 6D32894003A for ; Thu, 30 Sep 2021 10:31:22 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 180128249980 for ; Thu, 30 Sep 2021 14:31:22 +0000 (UTC) X-FDA: 78644477604.12.9D5EA5A Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by imf04.hostedemail.com (Postfix) with ESMTP id B96245001046 for ; Thu, 30 Sep 2021 14:31:21 +0000 (UTC) Received: by mail-qv1-f47.google.com with SMTP id dk4so3693790qvb.2 for ; Thu, 30 Sep 2021 07:31:21 -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=2byFwZTqL6H5T1HwZ3UMFR9jHqf1akMl4mBN/vDMX94=; b=CnuAcVa/z2KIcemUvmuCQG3R70S7y0YjOx0S55gdxctiytScgPrJDP6M1fLmRGPYXJ YAT3mIXZVlLiki2mw9xhu8NnySDq7DVByfEQjdj7oIecSzThsjjHYPVJQ4VGIOBh5cqz VlYyGJ6x1aJFFhC+csTa7NfnPJGU6R7oBZD8MmNrJ4z6rW5X+/OgtPXmPF9tCdlDw8iv 5gBfKad8IQFE/KHebxTVW7m95rJ16FTAVG6bAoPT9dRSVK92yIipf0bAMwhKETG99lhJ JBbcprcZPUyjLRS4jyYAX+2cwdviTgJKdrRmaXT6Z1jEDDgCDbBiPpKZPoxA4uQvLe6A kMFA== 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=2byFwZTqL6H5T1HwZ3UMFR9jHqf1akMl4mBN/vDMX94=; b=uic+dROYQG4ZB8mmdnKPOPAGD0/+hJV+Xjnc1u72Ux4141wBhA4sXZyJUU6hKvgI+W miFKQfbTpzmK0GVHlClwg6eUk7UbE9gb04RBvhgSL/iKI3al4j3ursiZiQFI2I9u3vBr dArU4EFKlivdCbX5qFjclgLFg/IGo/KfKnCOEg8uzsQgW2wcKvkEv/fYlyEfCUaOlVyn 91mkEWQZTQCTGmaFirdEDHZj4k6/vNpYa7vgU79zb8sANrOqf8HC6LByM7pYxdWWO57T Yh8cMJv0y3rk6gfFEP/25vGTuAoVXS9iPX9f4G6FXJaxbsxXR86KLlgt+pLyjlHx3eVL aMIg== X-Gm-Message-State: AOAM531Khyi2vueXjh/RbGbf7rHZoNuJopWqGMXqGTKpZyYpd43R3mIX j4akNEhCATtXdHDgMNMDyCLvsA== X-Google-Smtp-Source: ABdhPJx2GA26RZN03kRYmBDCi/gcboAxmrhaWBYq1chXopjjFm1J8tvOWaWK45xUGQBMAOa3uCnDFA== X-Received: by 2002:ad4:45f0:: with SMTP id q16mr331461qvu.4.1633012281074; Thu, 30 Sep 2021 07:31:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:20 -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 05/15] arm64: kexec: skip relocation code for inplace kexec Date: Thu, 30 Sep 2021 14:31:03 +0000 Message-Id: <20210930143113.1502553-6-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-Queue-Id: B96245001046 X-Stat-Signature: 3mckgrj7ps1jy9tsysqiuuo1mrakiyre Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="CnuAcVa/"; spf=pass (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Server: rspam06 X-HE-Tag: 1633012281-290265 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: Pasha Tatashin Suggested-by: James Morse Acked-by: Catalin Marinas --- 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 b6d5a02cba2e..7f1cb5a2a463 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -144,16 +144,16 @@ 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. */ dcache_clean_inval_poc((unsigned long)reloc_code, @@ -162,6 +162,8 @@ int machine_kexec_post_load(struct kimage *kimage) icache_inval_pou((uintptr_t)reloc_code, (uintptr_t)reloc_code + arm64_relocate_new_kernel_size); + kexec_list_flush(kimage); + kexec_image_info(kimage); return 0; } @@ -188,19 +190,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