From patchwork Wed Jun 9 00:44:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12308465 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 CEA3AC48BCF for ; Wed, 9 Jun 2021 00:44:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83642613C0 for ; Wed, 9 Jun 2021 00:44:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83642613C0 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 797396B0078; Tue, 8 Jun 2021 20:44:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 746656B007B; Tue, 8 Jun 2021 20:44:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54DAC6B007D; Tue, 8 Jun 2021 20:44:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id 17FBA6B0078 for ; Tue, 8 Jun 2021 20:44:33 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B1E9A181AC9CB for ; Wed, 9 Jun 2021 00:44:32 +0000 (UTC) X-FDA: 78232339584.07.2976199 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf29.hostedemail.com (Postfix) with ESMTP id EB518FF for ; Wed, 9 Jun 2021 00:44:26 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id i67so22146682qkc.4 for ; Tue, 08 Jun 2021 17:44:32 -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=47E64LQi31/l0SbhpKLyQRIg6WVPVm2IY96rfzQk1i8=; b=gSI2NZdHfnGG7iF/y/V7CBej6XZmDa58BGu9PceFBJIJisYmwa0gEPxdJo/wOGrV4Q DCw213nxdINz2hzYgbQd98n5EBVTV1tMhLW4bFYfrmdopeY2gyTxYqm9Oo6yZQ57yQ+U MPsNZR+0qm0p/6Je3ijxB5f7MoKWQ9iMkaJbdr07EeTd2QipyJDeDXWlOmgFrKz6/Sb1 qEjoQDpNOrkwmvplw3TgEbIxfbOiBNMdUAqIE6ZutdQu9HtfBp24+4kPE6HkIu8jQTBa GU3OgEqPrnDs44zWvrf3qQiVp8k2jppYVtzZzfv/PSYDMm6Uh5HbefJk2P5nOcaGd2jU 8MfQ== 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=47E64LQi31/l0SbhpKLyQRIg6WVPVm2IY96rfzQk1i8=; b=Ip+CHlgvMiP3M9qCii9ZZKq1iTB3v0Yl8Gi0Ywx98wIZcT/IRJmeCBEcMfUZ3JKY45 /V9wFeNhmJv0Doj85wJsW4kDTvrLBwu6GR2MApokOIpDCeeJVFoN45LaN88VrBLnTyUn Plhxag1muAaoVml1e/pdC8TiSMe6IshiLX5UVM7l1S0ZJAI4HBvSPBj4DalPlC/fKrAv /JAbkgcy7Dp6j/AKsDrnJWvG6MjGTC1mJxq84RST1S+dMLo/yyR+qHSRLXcXi8T+8kL2 sKvqw/V58dTImT9LSdHA6vBmklocvFkXflXY2xrl8M/GTu0+GKRIw+pfgjp7+KBriIrz eF4w== X-Gm-Message-State: AOAM533obZnxq7iFmINlidl0Uw0if3zhAvf3FNgsP5eZnqYT6CnIPimJ BeoTHjBtlcCAkfG/g26nB1rlBw== X-Google-Smtp-Source: ABdhPJwuE8iYBSswaYmBE6s54oqCaDrbIDyDAYyBTNjVtLyhDfoYUnbq5wMn278HggBIcJh4KYl6TQ== X-Received: by 2002:a37:2e07:: with SMTP id u7mr24502829qkh.489.1623199471709; Tue, 08 Jun 2021 17:44:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 17:44:31 -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 07/15] arm64: kexec: pass kimage as the only argument to relocation function Date: Tue, 8 Jun 2021 20:44:11 -0400 Message-Id: <20210609004419.936873-8-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: EB518FF X-Stat-Signature: ippxfu3fiois8gugizp5ghiu9rbsbk64 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=gSI2NZdH; dmarc=none; spf=pass (imf29.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: 1623199466-900805 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, kexec relocation function (arm64_relocate_new_kernel) accepts the following arguments: head: start of array that contains relocation information. entry: entry point for new kernel or purgatory. dtb_mem: first and only argument to entry. The number of arguments cannot be easily expended, because this function is also called from HVC_SOFT_RESTART, which preserves only three arguments. And, also arm64_relocate_new_kernel is written in assembly but called without stack, thus no place to move extra arguments to free registers. Soon, we will need to pass more arguments: once we enable MMU we will need to pass information about page tables. Pass kimage to arm64_relocate_new_kernel, and teach it to get the required fields from kimage. Signed-off-by: Pavel Tatashin --- arch/arm64/kernel/asm-offsets.c | 7 +++++++ arch/arm64/kernel/machine_kexec.c | 6 ++++-- arch/arm64/kernel/relocate_kernel.S | 10 ++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 0cb34ccb6e73..92c2ed846730 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -155,6 +156,12 @@ int main(void) DEFINE(PTRAUTH_USER_KEY_APIA, offsetof(struct ptrauth_keys_user, apia)); DEFINE(PTRAUTH_KERNEL_KEY_APIA, offsetof(struct ptrauth_keys_kernel, apia)); BLANK(); +#endif +#ifdef CONFIG_KEXEC_CORE + DEFINE(KIMAGE_ARCH_DTB_MEM, offsetof(struct kimage, arch.dtb_mem)); + DEFINE(KIMAGE_HEAD, offsetof(struct kimage, head)); + DEFINE(KIMAGE_START, offsetof(struct kimage, start)); + BLANK(); #endif return 0; } diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 15c126e09686..e88d5cfbef40 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -83,6 +83,8 @@ static void kexec_list_flush(struct kimage *kimage) { kimage_entry_t *entry; + __flush_dcache_area(kimage, sizeof(*kimage)); + for (entry = &kimage->head; ; entry++) { unsigned int flag; void *addr; @@ -198,8 +200,8 @@ void machine_kexec(struct kimage *kimage) restart(is_hyp_nvhe(), kimage->start, kimage->arch.dtb_mem, 0, 0); } else { - cpu_soft_restart(kimage->arch.kern_reloc, kimage->head, - kimage->start, kimage->arch.dtb_mem); + cpu_soft_restart(kimage->arch.kern_reloc, virt_to_phys(kimage), + 0, 0); } BUG(); /* Should never get here. */ diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S index 718037bef560..36b4496524c3 100644 --- a/arch/arm64/kernel/relocate_kernel.S +++ b/arch/arm64/kernel/relocate_kernel.S @@ -27,9 +27,7 @@ */ SYM_CODE_START(arm64_relocate_new_kernel) /* Setup the list loop variables. */ - mov x18, x2 /* x18 = dtb address */ - mov x17, x1 /* x17 = kimage_start */ - mov x16, x0 /* x16 = kimage_head */ + ldr x16, [x0, #KIMAGE_HEAD] /* x16 = kimage_head */ mov x14, xzr /* x14 = entry ptr */ mov x13, xzr /* x13 = copy dest */ raw_dcache_line_size x15, x1 /* x15 = dcache line size */ @@ -63,12 +61,12 @@ SYM_CODE_START(arm64_relocate_new_kernel) isb /* Start new image. */ - mov x0, x18 + ldr x4, [x0, #KIMAGE_START] /* relocation start */ + ldr x0, [x0, #KIMAGE_ARCH_DTB_MEM] /* dtb address */ mov x1, xzr mov x2, xzr mov x3, xzr - br x17 - + br x4 SYM_CODE_END(arm64_relocate_new_kernel) .align 3 /* To keep the 64-bit values below naturally aligned. */