From patchwork Wed Jun 9 00:44:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12308459 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 87EECC48BCD for ; Wed, 9 Jun 2021 00:44:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C83A613C0 for ; Wed, 9 Jun 2021 00:44:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C83A613C0 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 3EF6D6B0073; Tue, 8 Jun 2021 20:44:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39FAE6B0074; Tue, 8 Jun 2021 20:44:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01A9A6B0075; Tue, 8 Jun 2021 20:44:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id BA9616B0074 for ; Tue, 8 Jun 2021 20:44:28 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 43F7E99B5 for ; Wed, 9 Jun 2021 00:44:28 +0000 (UTC) X-FDA: 78232339416.35.012CF76 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf24.hostedemail.com (Postfix) with ESMTP id 32B0AA000245 for ; Wed, 9 Jun 2021 00:44:24 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id d196so17025873qkg.12 for ; Tue, 08 Jun 2021 17:44:27 -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=FcIEg/sDUKkdURMCkTF1KW5fxOPpkw674yFxDZdydcg=; b=QeK9i9pdmaa5nrGaHB0x+uBs1hguggMbvBuQFu3ngSXQDb/b76nSpsoWSwBEz1ZACF 8ZX9NJFTN6TDfgF/DKMPtvjN3Ytjy+7x9eRS9YkXaGNzJPpop9/fOLqR31ZeGJJ2e7mA +esyIRxbARxZLUdDBflzEqprasBY+fb3LOQqwfPL1M7t0uOBFj8ptNfgn7d6wbFX6nH6 sU/95ZCHJH2gX/SZiMrYBybdiyc7mOapL8IpuTw4ayFFpfIhy7lwlU/pCpKcMBKMIY5l GmNfsInXoZvl4nLA4vJg/YckdTiEwOA7CGMnn5e7ZmQg6RlxfdZk83AjSftF1dPIm3j6 5m0g== 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=FcIEg/sDUKkdURMCkTF1KW5fxOPpkw674yFxDZdydcg=; b=FGLIGy3ak3w5NjoP73bEDPYahkCz+Cjfp/dnKm9aL/3k7v/olnJBVLW8rQRXtBHrsu Tk9oP96ZyA56/BttUw+5/FYagYYje0z/egkQtT0NXCB+DdAsnIxrhXJxOqfE55M64tR5 t8/+eN7Cz0qcI1+HZPNpvte1CKZuTWWomWDV5iBymnp8Dqi1NY6zfFzHmOH/xOSTjtMK 7iL6nu4tPDz2SkWHUr5LHAc5JK5/I02p2NdVQ8UgFy6oIOHpTlnCNQt8R/3mc7xnaEwN wqBobXedkybfdw9cb2bmB14ZIk91r2zYX/CkdCBfB3Tse3NaXxhJ+ggAr+BFfxv8BTpu 3FKA== X-Gm-Message-State: AOAM533Hfmb0JURd39UPDyYRiCQY3yJbem3AnjVvCDe1kIkA4+XuW1zz 0TT8NyxmGkZ8ji929AwAPbJKUA== X-Google-Smtp-Source: ABdhPJzgsboPEWF+K2hwsvp2uYA2cq6gLqfyoPJs2qRhodktFoeQ6z2ViDG81uQldPhedYPiyLuRrw== X-Received: by 2002:a37:5dc4:: with SMTP id r187mr23745072qkb.174.1623199467407; Tue, 08 Jun 2021 17:44:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 17:44:27 -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 04/15] arm64: kexec: flush image and lists during kexec load time Date: Tue, 8 Jun 2021 20:44:08 -0400 Message-Id: <20210609004419.936873-5-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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 32B0AA000245 X-Stat-Signature: x7wti4eufybwzj4rpdbnerjchdgnijnc Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=QeK9i9pd; dmarc=none; spf=pass (imf24.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1623199464-360914 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: 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 | 49 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 90a335c74442..3a034bc25709 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -59,23 +59,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); - - /* 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); - - return 0; -} - /** * machine_kexec_prepare - Prepare for a kexec reboot. * @@ -152,6 +135,29 @@ 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. */ + __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); + + return 0; +} + /** * machine_kexec - Do the kexec reboot. * @@ -169,13 +175,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(); @@ -250,8 +249,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),