From patchwork Thu Sep 30 14:31:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528507 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 EBC9AC433F5 for ; Thu, 30 Sep 2021 14:31:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8122461A0C for ; Thu, 30 Sep 2021 14:31:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8122461A0C 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 6FF699400A4; Thu, 30 Sep 2021 10:31:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 687DE94003A; Thu, 30 Sep 2021 10:31:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DDED9400A4; Thu, 30 Sep 2021 10:31:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id 3BC3294003A for ; Thu, 30 Sep 2021 10:31:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E194718029DAC for ; Thu, 30 Sep 2021 14:31:20 +0000 (UTC) X-FDA: 78644477520.01.4EDC697 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf11.hostedemail.com (Postfix) with ESMTP id 906BDF000211 for ; Thu, 30 Sep 2021 14:31:20 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id 11so3665565qvd.11 for ; Thu, 30 Sep 2021 07:31:20 -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=wvhp7Shwzj2V1AcHSUNo3T+jO//upg214s/8JF7+8X4=; b=WzTIvObi8BmW8NTQjOqb0FOv0H/1NPIY+oIISBMpm8fDw4WooAALyuQ8nS0FbKt/SD oG484TyexjpEF9PLSUf6FoVGHUmJa7wCuNbtCA+2gWYOBP7IMxuKsxo2SB2qce1734pU xsEoWg7TnfyCy6fwEslgvv5G4WPjSmJb/ebM1dBbO3PAOPhAMBgXqHNADEKlZZw80hfB UHXFu0nSxEI896qgpyWWYjO5i4k8yAw4Zdf5kcNiCy9l3kfnM4g1YbizWJfXBfT0X1pO i58tA/zr32BfcRs2J3R6EKHkuX/khIa1jSiNc1733FUETlk2PlBrtbTQuqXUQUOrPrxJ 0vIw== 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=wvhp7Shwzj2V1AcHSUNo3T+jO//upg214s/8JF7+8X4=; b=ApMUGWMZv5ufbwathDE1+f/m4ORT/jW9BtgL9RzJMoNzmEizd6utIUIWV5CjEaBiGT MaFTByWIwpObdWEO5S+6Jk4iFp8zdbJq52xxheu2A60JQ8Sdf8meeKklc+oZPh+4oFGc 6h2NzbfMLLEk7ms1BhgJYDkGn+o6V1CxEdgtNM9olXiWowVEbREcVD4w39k9nKDOcSE6 NGkLBKjxzL+4ekuxRN6EDPZP/LfRx203D7DdmhMgxW/kuLs8MAeVBobpDmlW+/KYKlI6 ih4SM1XkC0LAvlf9u8JsCipi8nhOSO8hZu1579oG1yLsTWe8QE/R4FdYFZc7yE6Mv3s5 /5Vg== X-Gm-Message-State: AOAM532rQHaV5Y7XFEuZWEkx/fQyQfl9+np1eLKxPyD694MSrOQiR1db 5WH9P1WxdsXw3BjC/C202TqvRg== X-Google-Smtp-Source: ABdhPJyRpe+0jXAcRshmB05WHMM4GvLP/u4h4SOYX1etnyUhK8wl9VzQ7qbqdCBBQWvQ1rXkOCyYsA== X-Received: by 2002:a05:6214:90:: with SMTP id n16mr4150225qvr.1.1633012279941; Thu, 30 Sep 2021 07:31:19 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:19 -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 04/15] arm64: kexec: flush image and lists during kexec load time Date: Thu, 30 Sep 2021 14:31:02 +0000 Message-Id: <20210930143113.1502553-5-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-Server: rspam03 X-Rspamd-Queue-Id: 906BDF000211 X-Stat-Signature: bds5d4qxkyju94hb6rg4su6hfi6udgjf Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=WzTIvObi; dmarc=none; spf=pass (imf11.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-HE-Tag: 1633012280-31717 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 Acked-by: Catalin Marinas --- 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),