From patchwork Wed Mar 3 00:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12114139 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 BF336C433DB for ; Wed, 3 Mar 2021 19:23:41 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF601601FB for ; Wed, 3 Mar 2021 19:23:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF601601FB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vyymY05vH7RqsRKuKQoYiIt3jnphnFyU8lJil/qCQZU=; b=gSOrJcozd+jtGsfxaffRFqnbf mqD7NKsT+q1AHtKcoMm6bzqe/X+qz0hRj2U2xclDlJcbsJECQjYPd1g+l3kReiImaWQN03f5wiBjR ZuMoYD/u72f2mvBxvFxTTEmsXxS5XkqilQ/gwSUWE01NEvOar5m06w/76mbMgDM4MQKldy5+V2F4F sBHCaMZ81eGMLKwkEldHIO3GXqyshHV5ltwVCzhCem4NRn0yKLfoEVvMLHmUv6M4Lau9kpw6kwHQx 0wHAxr1B1JitJsdkGkknK+Cok6+dDG1l7V2HsbchpR+LessjOXNcgaKgo/0aqfqgSJj5gq4VdXj85 X7jjdqxvA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHX3O-006Bnd-B3; Wed, 03 Mar 2021 19:21:02 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT32-005HvB-JT for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 15:04:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=tCKT8dQy3j0JXLfUAkLHptP8jUCHy5Mtlem3XeT2uzw=; b=OPH3ilIIo1QVRT5mlIK+FYVb+e dq+tnNygHL6B8mlGcAmJKPndJm6vRhOGLzDJNPyj3wvb4H4/btoc1u0rZggT3O+OyHWHHJkd0BQD4 LsgcELVNGqKcE8HJY7BmOHVoyJUXHbU9H+Qnst9hFAeF00Eie0MZUmB0cCStxG5/EDwSRi5JhKCkW hWwS0LJ0DqkHQG0bVjwJaN/Gpy/Zogo06gSG+VpJDEbJ8xeLwWtD/HP+VPzKraiglAZBCxj9N6Tw5 +Uh/CFibkCb7ih0AkS72TEo+eFWHm79Xb2fF1koF1jVdTVkrLk1w9iqhbB24fExzP4K8GCgdtu368 9xHTG2rw==; Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHFRd-000kvK-9M for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 00:32:54 +0000 Received: by mail-qt1-x836.google.com with SMTP id h9so6423697qtq.7 for ; Tue, 02 Mar 2021 16:32:53 -0800 (PST) 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=tCKT8dQy3j0JXLfUAkLHptP8jUCHy5Mtlem3XeT2uzw=; b=DhKQLAF9gGWy+VQ4vEFv8vyOX67wEL5g+Ibv7M6YGg2GyOsWVpcLrO8l/KN0L5IZAc RxUn6cVCLaJEnn1GP49dKDyfXS2S5pAiSCfkfdBs3217gnmAIZ5KJF9kQwUjn08WVXoD eVb/xAgyG6HCeSJF560IMqYfvfngZgwPC0Gmto4sET2VI1otYwBlS0xkYWwsZi+5Y5wu CiGi9fY2dPpyuaQ0XGJefCQyLBo5uJyBd2Zt5atz0jeIcn/r/0MV3W88wPds72buWKfc OID9WDzMy8wulcxcHzZaME1ROXYkHzAQzPpJnO8T7pARrDaLZCrx6HDCoBT9CIwWJebN jArg== 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=tCKT8dQy3j0JXLfUAkLHptP8jUCHy5Mtlem3XeT2uzw=; b=oGxp25uKno8NPyqKDRiVuqJHdIf5u8LCeVwuzpm01JNYNe3JhQboJ4mmij42H7sw+D Jga85ZeFzrfU0WIInZ1HYjYlL1TdZ5eNPU1HIaQIQzNeSwVtahTkEX5PHj8IY1DUCOKb 32UOhxyzjyoW7GsSdsETmmT+qSZML+IaAoIyBaZMajmPXonHo2DrByw2TbUXh3DI0gm3 7oedTdlry7bQZNuEGVc3GVVXINEKDjPJXzMm27o7Aly7RMqDJWhSAUw0uzHzjJIubv3/ 8m6aVUh2pHt1a8Uv8e8prnFFnCoS6h7jSBDuit4aKArxyf9e4/b/u7h0/hiQh3wQ743l XmgA== X-Gm-Message-State: AOAM532lMG6bziJqmS2kUtGBFbwetlS5PG99MysD/AC5i3vFMaP4KX/U vrFPA5yevm8ClalZ/nPsriu1T5nzZpgImQ== X-Google-Smtp-Source: ABdhPJz8rw5a4BVvRDYMXLHg55FhSEneNbuZ0yxoLq7h3VikY6X4yYzXWKIMomKucbL+q9Rc23LaTA== X-Received: by 2002:a05:620a:13a5:: with SMTP id m5mr2243290qki.498.1614730966050; Tue, 02 Mar 2021 16:22:46 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id r3sm16690512qkm.129.2021.03.02.16.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 16:22:45 -0800 (PST) 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 Subject: [PATCH v12 10/17] arm64: kexec: pass kimage as the only argument to relocation function Date: Tue, 2 Mar 2021 19:22:23 -0500 Message-Id: <20210303002230.1083176-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303002230.1083176-1-pasha.tatashin@soleen.com> References: <20210303002230.1083176-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210303_003254_759385_D7BD776F X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Suggested-by: James Morse 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 a36e2fc330d4..0c92e193f866 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 @@ -153,6 +154,12 @@ int main(void) DEFINE(PTRAUTH_USER_KEY_APGA, offsetof(struct ptrauth_keys_user, apga)); 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 b150b65f0b84..2e734e4ae12e 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_callable(), 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. */