From mboxrd@z Thu Jan 1 00:00:00 1970 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 ED9D1C433EF for ; Thu, 16 Sep 2021 23:13:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9AF7F61212 for ; Thu, 16 Sep 2021 23:13:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9AF7F61212 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 6B35E94000A; Thu, 16 Sep 2021 19:13:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63BAE940007; Thu, 16 Sep 2021 19:13:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32C7994000A; Thu, 16 Sep 2021 19:13:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 23675940007 for ; Thu, 16 Sep 2021 19:13:35 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C9FA0181AEF30 for ; Thu, 16 Sep 2021 23:13:34 +0000 (UTC) X-FDA: 78594990348.37.56C409E Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 8CF826001983 for ; Thu, 16 Sep 2021 23:13:34 +0000 (UTC) Received: by mail-qk1-f172.google.com with SMTP id bk29so11633233qkb.8 for ; Thu, 16 Sep 2021 16:13:34 -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=Gd/bGj4Nwzpg1oqGDK3dKyYdSLy7Idt++VqAt+4ZWi4=; b=PdS3WIztg0/FRRtRRTtPPxtFIldbe++n6HCVMM6V0yGOpBq5XsN2nTiu23qMmZdl8q UA5t8YTZtjM0INsMm1j5XpUeJQCvNSXi4Rq+hRSx8IZ2tKHgAeE6k1wOiFqeKPRpYTGj zRK1b3KP5CjtP6keZb3NU4vaQeXPW1AEYLAEn2/dz1SITPu6y8Td5DSwFsE+M2382rk0 cfy3A1wF4r2QdsnvixiMLxjZsAm3BnZjF692O3QVY4jYrCvOzUBT/aeQWJUMtPNwhut0 mSdS9tjivQ9eqe5Ke36xs36CO+CdTVkXk7rAL7kWFu+iMdYsA/i/iS9kUia9rdNF6KX3 BPOw== 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=Gd/bGj4Nwzpg1oqGDK3dKyYdSLy7Idt++VqAt+4ZWi4=; b=f4x1UYzczHVyfmpLMHBKuTX+HmLIgSkYR4Z/eiRuTPOcEJ6kMbHPIDZE1+/sutvFZH qA7f0f+aff61PbIx5J1KCkVLD/maAZZVZe9fJ1V/UrGyBaDKm7LDY3I+LKSlIvQUMW+5 EsPuIGYqDS5/jtD6jZawB1YjEX1GfgenZ3qan2eeomf50LB/kixZfFPjqdeQowo3Gkbz xtx6ZOutM536bpbhOtIeGQ/h3uuX6qCgDk6MOBgnZybHi1EI4Nt47O6z/n/7xmwB5+XY 2WFRLYBdWaEhBACWman2BgKdzggWgL+z6iyfrKByALunXNK8LJIK381uAh5jkkYt3AV6 klAg== X-Gm-Message-State: AOAM5324qxUOTqtf/Knum0yrBFokhT8HiBDmaB+iR4PMorPeTMTiTVPX sY5IWoEnDezO1cg2w1zVYn9xNw== X-Google-Smtp-Source: ABdhPJxpsmcX5Y/ALpzZd3SrKNGuslXcDYHnRWX9AFYJaIjAKYK0WUYvvI7zcdvzBL3J+s6eb2VL7w== X-Received: by 2002:a05:620a:1998:: with SMTP id bm24mr7898451qkb.444.1631834013914; Thu, 16 Sep 2021 16:13:33 -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 az6sm3312891qkb.70.2021.09.16.16.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 16:13:33 -0700 (PDT) From: Pasha 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 v17 04/15] arm64: kexec: flush image and lists during kexec load time Date: Thu, 16 Sep 2021 19:13:14 -0400 Message-Id: <20210916231325.125533-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210916231325.125533-1-pasha.tatashin@soleen.com> References: <20210916231325.125533-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: 44a1us7kp5a9j1t1pbnhhkm6fcykb3uh Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=PdS3WIzt; dmarc=none; spf=pass (imf10.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.172 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8CF826001983 X-HE-Tag: 1631834014-696844 Content-Transfer-Encoding: quoted-printable 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: Pasha 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/machin= e_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. */ } =20 -int machine_kexec_post_load(struct kimage *kimage) -{ - void *reloc_code =3D page_to_virt(kimage->control_code_page); - - memcpy(reloc_code, arm64_relocate_new_kernel, - arm64_relocate_new_kernel_size); - kimage->arch.kern_reloc =3D __pa(reloc_code); - kexec_image_info(kimage); - - /* - * For execution with the MMU off, reloc_code needs to be cleaned to th= e - * 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) } } =20 +int machine_kexec_post_load(struct kimage *kimage) +{ + void *reloc_code =3D 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 =3D __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"); =20 - /* Flush the kimage list and its buffers. */ - kexec_list_flush(kimage); - - /* Flush the new image if already in place. */ - if ((kimage !=3D kexec_crash_image) && (kimage->head & IND_DONE)) - kexec_segment_flush(kimage); - pr_info("Bye!\n"); =20 local_daif_mask(); @@ -261,8 +257,6 @@ void arch_kexec_protect_crashkres(void) { int i; =20 - kexec_segment_flush(kexec_crash_image); - for (i =3D 0; i < kexec_crash_image->nr_segments; i++) set_memory_valid( __phys_to_virt(kexec_crash_image->segment[i].mem), --=20 2.25.1