From patchwork Thu Sep 30 14:31:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12528513 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 4CF87C433EF for ; Thu, 30 Sep 2021 14:31:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E870C61A10 for ; Thu, 30 Sep 2021 14:31:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E870C61A10 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 4DDCD9400A7; Thu, 30 Sep 2021 10:31:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49FDA94003A; Thu, 30 Sep 2021 10:31:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 307709400A7; Thu, 30 Sep 2021 10:31:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 1B21394003A for ; Thu, 30 Sep 2021 10:31:24 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C3EEE2C6B5 for ; Thu, 30 Sep 2021 14:31:23 +0000 (UTC) X-FDA: 78644477646.38.E964628 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf21.hostedemail.com (Postfix) with ESMTP id 7D46CD0345A6 for ; Thu, 30 Sep 2021 14:31:23 +0000 (UTC) Received: by mail-qt1-f174.google.com with SMTP id a13so5814490qtw.10 for ; Thu, 30 Sep 2021 07:31:23 -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=5tAiOQNbsPwYQy1X9AyljFW/jKh8PdcAlWcG2o1mwWI=; b=XCzx76XQyqYzRm1ibea0WoCNtcgtXq1gejadijr7/Tsm8GnPNst3oyZj3R9I9AnbJG lrBnaIGN9DLqClY6Iu3a0cPk49EhlCdK/rDuxQQYANtGNfP8HFek80IgFaJdn1NGVLDJ 27ChNmLpSzUczm8ERB32kFy54GWlk57lRkLWF4zD1P65qWvy/Iad8ko3u57FmlRhAxP9 hho1onk8yY5gm6Iw+NSNJ1q5UqXxrZlGyOQYSWjs498DAm/VFk2pIkmf5qWtWOKGMdgF ygnW+Ww/+cSezwh8z/XfxMhB2qr8HyapKNi3SW/qFQ+y1Vy8tWorf86vcsOyv9ttqucp +12Q== 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=5tAiOQNbsPwYQy1X9AyljFW/jKh8PdcAlWcG2o1mwWI=; b=jVamrOmIYluLDnBL6xWAGDpgLsg40X6vuWa/raDgjddFCl5Nsr6Xr4Xjy0nnMLIjr1 2orjERgZEP4+6C9SR0qXuMFcbNdTO6iOL/Avo0qePb+o3W225BlI4BkM/bI71FnPLQ1B kJB93fI/kPjTIV0v2OkEVJjR0sIx/LbJ+0z1p/HgrnxGls4bnDJJyzGnr/oZw7upehfr /NC54mDtciDHYD/gQiXj7EiaYh/k1+aJfsYHN10CtyGqsr9xztHTyjuHkqQA/FEMNo5o Lc7Y/khmW1hFt51QlfNlVAKGJWenEF+AFjzkCD3i/0klHZ+dvEsWknDj822nqP9oYmC0 LPrg== X-Gm-Message-State: AOAM532Vxo98U/LPA5LBUGjQnDshEtkucM0YVaQM/gd5Hn23TEV8JMa1 jOsYJ1eLJuWfcdW0gyWk+F2xUg== X-Google-Smtp-Source: ABdhPJy8KG5Co2knAgWKxrqUz+zTSFnivorQOkpsDEWq0y8x/CqeHR1bJLHAsbozgKtfArAnLhmX4Q== X-Received: by 2002:ac8:4e8f:: with SMTP id 15mr6748304qtp.189.1633012282856; Thu, 30 Sep 2021 07:31:22 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 07:31:22 -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 07/15] arm64: kexec: pass kimage as the only argument to relocation function Date: Thu, 30 Sep 2021 14:31:05 +0000 Message-Id: <20210930143113.1502553-8-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 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=XCzx76XQ; spf=pass (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7D46CD0345A6 X-Stat-Signature: weofmsw3k6s31bnxkzbzqrs38wbsdfzb X-HE-Tag: 1633012283-886801 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: Pasha Tatashin Acked-by: Catalin Marinas --- arch/arm64/kernel/asm-offsets.c | 7 +++++++ arch/arm64/kernel/machine_kexec.c | 7 +++++-- arch/arm64/kernel/relocate_kernel.S | 10 ++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 551427ae8cc5..1d3319c7518e 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 @@ -170,6 +171,12 @@ int main(void) DEFINE(PTRAUTH_KERNEL_KEY_APIA, offsetof(struct ptrauth_keys_kernel, apia)); #endif 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 7f1cb5a2a463..e210b19592c6 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -84,6 +84,9 @@ static void kexec_list_flush(struct kimage *kimage) { kimage_entry_t *entry; + dcache_clean_inval_poc((unsigned long)kimage, + (unsigned long)kimage + sizeof(*kimage)); + for (entry = &kimage->head; ; entry++) { unsigned int flag; unsigned long addr; @@ -206,8 +209,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 8c43779e8cc6..63ea19868f63 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. */