From patchwork Wed Mar 3 00:22:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12113913 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 3592EC433DB for ; Wed, 3 Mar 2021 16:59:56 +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 482A464ECF for ; Wed, 3 Mar 2021 16:59:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 482A464ECF 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=/fn+ZhrZS9uefso0j1dWPH2tztmDB9rkpEALYq3wuk4=; b=q5/+Fy36hTUcrFQ0ovdbkhkgA sLEkR2cDwwQMKGtxaoxKsdQcpsUjFfmjr7NA7U7Jn8cUD8xE6Qwxibq6TNFwUW7mHkAjJMJlZS9yV meKk1yI8le3HCZNzcqTfxaHF23APYPPm0FesxVc9aNy9+Wvd6kj/0waCfJtAUzIr9/cUbNqAJdqcO ho+58kl6yFCZb4DBHW9iGgNzfSYIFWoFS0rPGDI95p35uIdzEcF3nEzpRMaFgXdLTM3Dfv+k1hCi1 Vv+EcruwXis5uaGUcuK64H9gV/b9G3bxrM2t8U/q4KL1HHU9snFBNfZbp01/DNXfjETy35OczjLcV 5d3ZLJP4w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHUnU-005h2g-9w; Wed, 03 Mar 2021 16:56:29 +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 1lHSrg-005EY7-SJ for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:52:43 +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=hiQbfer3Cy+5MCvp23I2bat0V/tLiwOPOJLrW/6qX9o=; b=quaEZ+HwMhRYGVCgE4qYjrGXd6 kmCQ38Z6fo6tn6sfVn2ENvArnu3mPSGDdyq4d7Us8+KrBdr6O1IKF93ypFdnVI8v3YQMYxMdnmeLT +sd/KBr13QVixy+MGQ+0WQpDCMOrp1x3YEuzUX1RtUsGFeNsXpXhVGr2dATCcasMAcVebVq4fhDoa 7TTR2kxK4JehDqIApqr8BDX+gPMAGPWW4Hfu1ifp1CmddoMO/gYpqfmnqjPPnyTInnXhvJ9aViq7A TQf+7mtYzMC09kQwqqxA3GwY8Bqv32FzDUDKSyNfPNo1c84y1lgK9ltdvizWvdaOgAzqfOAKRBZJN y8iKsmfg==; Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFRa-000kvG-44 for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:32:54 +0000 Received: by mail-qk1-x731.google.com with SMTP id s7so12252466qkg.4 for ; Tue, 02 Mar 2021 16:32:49 -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=hiQbfer3Cy+5MCvp23I2bat0V/tLiwOPOJLrW/6qX9o=; b=UueDkZWeVdt0ZVUeFCaAS95OcbctawuVt2jRXcfNleEQHioaIPsafjb3iN3wPEqMdt J9stLwiFQM/z9W3CKU1wRsTGAe+nD318y5F9IIMtfpYl9ooGJOj9fq3oWyPfDl8EafIQ QkbzJVXwjyMJ3s+WeBV5VvNz7u8LvjFGWo2A0yPGEvKqoLl2EWQ4TA6kdAzhcd0pCOxi bNZKhhZ2PTEsy6gzqf5i+WWcAhW6s6kBywZl2oPrlqd186gvUOmG2SJ5qEzykeb+bgo7 zNWjDcSlC0bR7+IcSuyKZ2OqdH/81WqWH4B4D8mKrZgAcxAnonHq8pCXd9qjhhgHBr97 fnAA== 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=hiQbfer3Cy+5MCvp23I2bat0V/tLiwOPOJLrW/6qX9o=; b=YcI2XKOLf3rnA0/6vKOVI6oL+yzqWYMqactpLKIXpxFoRPXSJr6IWJ134EyfjzHaFz wWPhqXnqbC+5dqVqpxZih9Zh0bEIAt4aJqlhigTqtyge53xESUfN0d062r6iXbrnwC/o JcpVSq8o520xsYCZvScMBPZwZTiuMdGXRngPUbf5pHRjfH6UuuI8vI44awskAeqzMBY0 iHQurdP+xgPjQ6/u8cKtIjFTYQuTVJuTLONYT8obxIHgGhDquXKYqo7SzoJx3QP2A6Lj MS0lJFKofyS8CtxK+qJe4QschmwDXAcUS6ABAgVR152whqTb/NYqFjB+O+pLI/jwLwaw KxPQ== X-Gm-Message-State: AOAM531CgQKQgkT4lqHJ9ASACMspsRo3RLbClKtZ1pkRxHREqxgBS/43 2ETIOb7ebQylgny0+gM6ckKpAzqvl0uJ7A== X-Google-Smtp-Source: ABdhPJx73Id09SRSbyQ7yttHUhQ1XFsUCayEKdjf5Um64FVS0lPYLKHoeNVlJXLwSpbmAURdNlizvQ== X-Received: by 2002:a37:2785:: with SMTP id n127mr12916932qkn.320.1614730963459; Tue, 02 Mar 2021 16:22:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:43 -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 08/17] arm64: kexec: skip relocation code for inplace kexec Date: Tue, 2 Mar 2021 19:22:21 -0500 Message-Id: <20210303002230.1083176-9-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_003254_213898_BC506122 X-CRM114-Status: GOOD ( 17.42 ) 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 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..b150b65f0b84 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(__cpu_soft_restart); + restart(is_hyp_callable(), 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