From patchwork Mon Aug 2 21:53:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12414863 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=-17.4 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 888C1C4338F for ; Mon, 2 Aug 2021 21:57:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5357860F9C for ; Mon, 2 Aug 2021 21:57:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5357860F9C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=iWvh0SExoF7yPoTycyoO3Vxkge9P6e+vLOLVwiAmITw=; b=Rfeh/D27qLA1QU 6HygbVU1MPDa3OXmCwqpCZhboCtfeRxeCl5zwPzk6hYV0mJm4TYcB04qeo+P65EkR/Hzobxg8Wc9X /kZHVvTjIvJKX5ld1YasXZuQo6CK6YNtRgjZBdWUUGRjUvMuT+gieTSp2LxmL/sae0q6NROW4AlOh 37SIvA+IWpZ2mktg6olKK44owzjqiLcuvUWVDi/JgRHmec1/PamXpXbRYgfb0H0i0acWpIUUorpBl KOOqtsiLZKpK1yN31bKoqNGZBavHdzm4K8lvsqdv+9JitkcgaizdAPoVGnbQJ98npDY5wjL2KEjX5 nqN98iWfDVcqYixvVQ+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAfu8-000KHt-4j; Mon, 02 Aug 2021 21:55:24 +0000 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAft4-000JmS-2q for linux-arm-kernel@lists.infradead.org; Mon, 02 Aug 2021 21:54:20 +0000 Received: by mail-qt1-x833.google.com with SMTP id d2so12701452qto.6 for ; Mon, 02 Aug 2021 14:54:17 -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=j+M5hF4GoTM52s3DZq4Ce8jXkOdwrhiLtHbwgSj+FD0=; b=l6aqL1CM2TQZNGjxlG/OMB4a6O9NQjV7sXgli2BxOuiZqOg1+R4L39Hu+XxA1MP2s5 t4dP5Us1cylcgLhIaClJU45qlE2AWSN05gLhWbNEddIvUnvOppiFWBMN2dBLty8Bu7WE 6gaf3VroJKSsrw0OpzaZNzXBElExwfW5ATW9eqbqeBEBmhBNUHbqNvkji2FfJ/IGEybJ ZpKuE68zFf/xMo0Q4srgWww79rMfb7cNXt6JS4zZ6O5a2P7HnD1tEpc/dGa5a406/pco wPgUP5aLSqk1c0Bu/yhNnpFj30p70V3WrBAZsa/YupGYPMXcilEBYoBGGqiU7xVgLZb1 yBcQ== 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=j+M5hF4GoTM52s3DZq4Ce8jXkOdwrhiLtHbwgSj+FD0=; b=mMGc164qBn3v56n+Y8kk/S6LVgWrAltTk0+drlzlUBHyA7gQD0oBlJ04R1iC5F8bCI pYpl7qimeAY+p4lWS0Z4hvjA7nWXKzo9fZorXcJkv7fSit7rdH9zHbzPn0D9Eih6GAK5 gDKwV5m+oPQoZlr5QlvPbyV8IzHS0nIdY8JrD+sPPYcGFHU8wLainn3p93W32j7OKANf Djes8ojyyYbrDeii65d5FYmdMgVBxd3/gKrBqKXPTND08LKoYHkbEsgPtngGUBtHA1Ph 8CUZPA1EOjAwQrpB9cWqN4iObhU66tzlC03AXW2P7m5n84ip7cIELVPWDodJVJNViNmX T5FQ== X-Gm-Message-State: AOAM5301MDaPS7vs/kEzZ2yrbQidf3+n8SmmwsSN60MjJm/h0lI6aA81 9WEVyW5I75uDWEJ/AkjMy4FLaw== X-Google-Smtp-Source: ABdhPJzftvfeQfBpD80+56bQsic+tvcE4+ki6fuiemQ88Y64RUc79X5wGWVVM3Jr7aFMFqrTIyjfxw== X-Received: by 2002:ac8:57c4:: with SMTP id w4mr15810018qta.39.1627941256639; Mon, 02 Aug 2021 14:54:16 -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 v11sm5479216qtc.0.2021.08.02.14.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Aug 2021 14:54:16 -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 v16 04/15] arm64: kexec: flush image and lists during kexec load time Date: Mon, 2 Aug 2021 17:53:57 -0400 Message-Id: <20210802215408.804942-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210802215408.804942-1-pasha.tatashin@soleen.com> References: <20210802215408.804942-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-20210802_145418_169090_ECA8C757 X-CRM114-Status: GOOD ( 16.86 ) 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 Currently, during kexec load we are copying relocation function and flushing it. However, we can also flush kexec relocation buffers and if new kernel image is already in place (i.e. crash kernel), we can also flush the new kernel image itself. Signed-off-by: Pavel Tatashin --- arch/arm64/kernel/machine_kexec.c | 58 ++++++++++++++----------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 213d56c14f60..b6d5a02cba2e 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -60,29 +60,6 @@ void machine_kexec_cleanup(struct kimage *kimage) /* Empty routine needed to avoid build errors. */ } -int machine_kexec_post_load(struct kimage *kimage) -{ - void *reloc_code = page_to_virt(kimage->control_code_page); - - memcpy(reloc_code, arm64_relocate_new_kernel, - arm64_relocate_new_kernel_size); - kimage->arch.kern_reloc = __pa(reloc_code); - kexec_image_info(kimage); - - /* - * For execution with the MMU off, reloc_code needs to be cleaned to the - * PoC and invalidated from the I-cache. - */ - dcache_clean_inval_poc((unsigned long)reloc_code, - (unsigned long)reloc_code + - arm64_relocate_new_kernel_size); - icache_inval_pou((uintptr_t)reloc_code, - (uintptr_t)reloc_code + - arm64_relocate_new_kernel_size); - - return 0; -} - /** * machine_kexec_prepare - Prepare for a kexec reboot. * @@ -163,6 +140,32 @@ static void kexec_segment_flush(const struct kimage *kimage) } } +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) + kexec_segment_flush(kimage); + else + kexec_list_flush(kimage); + + 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, + (unsigned long)reloc_code + + arm64_relocate_new_kernel_size); + icache_inval_pou((uintptr_t)reloc_code, + (uintptr_t)reloc_code + + arm64_relocate_new_kernel_size); + + return 0; +} + /** * machine_kexec - Do the kexec reboot. * @@ -180,13 +183,6 @@ void machine_kexec(struct kimage *kimage) WARN(in_kexec_crash && (stuck_cpus || smp_crash_stop_failed()), "Some CPUs may be stale, kdump will be unreliable.\n"); - /* Flush the kimage list and its buffers. */ - kexec_list_flush(kimage); - - /* Flush the new image if already in place. */ - if ((kimage != kexec_crash_image) && (kimage->head & IND_DONE)) - kexec_segment_flush(kimage); - pr_info("Bye!\n"); local_daif_mask(); @@ -261,8 +257,6 @@ void arch_kexec_protect_crashkres(void) { int i; - kexec_segment_flush(kexec_crash_image); - for (i = 0; i < kexec_crash_image->nr_segments; i++) set_memory_valid( __phys_to_virt(kexec_crash_image->segment[i].mem),