Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp592666pxb; Wed, 27 Jan 2021 16:07:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvzJdQrSb5xR6feZRNz05z2SqvA/5x12wns6hBZ8c+BHzGmeJDiGGYBi+1NiM0xTWcQ9WA X-Received: by 2002:a17:906:2496:: with SMTP id e22mr8010559ejb.99.1611792433778; Wed, 27 Jan 2021 16:07:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611792433; cv=none; d=google.com; s=arc-20160816; b=wm3KKqY++8FZ/QnVOpuufXFh9IR3N76C+qy76JHpmTJLWTtcxsbKjX6OdsyhpyegFz sNsabgLVOJEhDfbRayEldSsVKcw2RfaK/LLWsxGwwrj2ZX0aSJ9GwT+lU6Ars6+Mc4CQ 4+cjFWRa6ueyfgUOmsVpnpy+kjHOVqpFfyL/SzN9r+Rp7ZWahoRJX596Fez1X0YtwcZe QUvmYg4yObz3rnPvHcAkAl+ogL/SpiUGfA0Wad0TQIthQnbJh+8uUn67/jMf8b00crMn nSJd9R1pVZsQVXHTyI/oEOVut1LHtC8Pblv6AacnNW7q/VsIrJ9+N5cLcsUhNWgVdL9w PCSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=95TSrifribrBiQvYeW7oeDR3coDlFThL26tZkibpkw0=; b=s3QZjJTudH31ZZSbCgaio5rq6wDBqpJwUazguceTeeZqJVH93LkX/SozoQszhOjeJn 94HsmBKSMKAkrzEwy++glMg/W6S7uia9u/5f44KRfX9emCAn1jMeYY4lgd8qb4y7N9wD DnGED0kyBELCvArc1BKBey2odmzuueVIG3OQEtugHP4+PNbrk6exQBpmsVc31w5RoPyr lN1zyiVzA9yf7u1/jHZUtFDWz3jl6OTMIuPSvUgtQ6fXZC8qHHPfSxaOEDDP5HZgv+pO crfWwRyJ8MM38qD0tqg2rpZFZlSlFC480BsFuhVE41S1lnyBe77RrrpLc8JFnAY7NVPN zmYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="Ei/vSaVv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si1439572ejb.213.2021.01.27.16.06.49; Wed, 27 Jan 2021 16:07:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="Ei/vSaVv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbhA0Qsy (ORCPT + 99 others); Wed, 27 Jan 2021 11:48:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233074AbhA0Qsl (ORCPT ); Wed, 27 Jan 2021 11:48:41 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73446C06174A for ; Wed, 27 Jan 2021 08:48:01 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id r12so3578774ejb.9 for ; Wed, 27 Jan 2021 08:48:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=95TSrifribrBiQvYeW7oeDR3coDlFThL26tZkibpkw0=; b=Ei/vSaVvlagR765TYOxKEyRxm/djxNDTo1eo93ZrR9L73SOEhERzxBHGW790RPCtxf 3hx/J60PakltGTz93hCnlG6DfSgc8fFrgzrMlBwmF2AM1k0VNetctFdvViJQE9DrwrI+ sXr0XZVnfGDN6fJzhZBeEfVk+XnBnIg4MpnqKeAFgoh76jxqJrp7jrUUpJoeMWOO9sb0 0Y3C/9s9+iBnM5SUtLe7HRSX9W7rAG/NrPfQKWhwpEkRLkCYVCY9g/ve+BY8V3R33S7S XwkeSS9SzEzGBYCUKSjGtAdR/EzOfPw5aoNb6XjO6dhg2C2+yjKAfvnra5oefOF3wta1 GzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=95TSrifribrBiQvYeW7oeDR3coDlFThL26tZkibpkw0=; b=Y17clgqZPgf3RtcsCquydpypq2gQAALhpKYx5rsb6IeIb7+tutEcFA0ZsLAQweYm+r liIDLWU/Y9BxFRjHcl8rNFX0pr2aPjDYcrOhKGa327qhhHY6CgBeZ5H5dMHRkFSo1/e5 RASLESeLR+5QzMgVA0xQgCr45H1O2YqTUEr9vLyGKjAV0eL2ltf4QGGQsuBfXPAaWiRN 2AK1sEs63SQA9vxW04WG8Ki/xggoSyhTSZE3rU83FIoBYurgepvs2h2YR5vRO7d5fZpd PGkGQ+Jz0NGIW2vCTs96tECWCcIr1h+QFw5L84DRLVk1Jf8cfGl1lwm2ME1h+u5Zv/ZL YBQw== X-Gm-Message-State: AOAM532YwFQAttApXkkaXoxiMKTWQYK6pzq+t1VnmAVNHp9QIMnR1RLH 10AL/hW3D7wkGQDO22XD1ly+3ed3m8YDMLBjV3NWNQ== X-Received: by 2002:a17:906:eb95:: with SMTP id mh21mr7778201ejb.175.1611766080094; Wed, 27 Jan 2021 08:48:00 -0800 (PST) MIME-Version: 1.0 References: <20210125191923.1060122-1-pasha.tatashin@soleen.com> <20210125191923.1060122-17-pasha.tatashin@soleen.com> <20210127164230.GA584465@sequoia> In-Reply-To: <20210127164230.GA584465@sequoia> From: Pavel Tatashin Date: Wed, 27 Jan 2021 11:47:24 -0500 Message-ID: Subject: Re: [PATCH v10 16/18] arm64: kexec: configure trans_pgd page table for kexec To: Tyler Hicks Cc: James Morris , Sasha Levin , "Eric W. Biederman" , kexec mailing list , LKML , Jonathan Corbet , Catalin Marinas , Will Deacon , Linux ARM , Marc Zyngier , James Morse , Vladimir Murzin , Matthias Brugger , linux-mm , Mark Rutland , steve.capper@arm.com, rfontana@redhat.com, Thomas Gleixner , Selin Dag Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 27, 2021 at 11:42 AM Tyler Hicks wrote: > > On 2021-01-25 19:21:22, Pavel Tatashin wrote: > > I forgot to make changes to arch/arm64/Kconfig. The correct patch is > > below. > > > > --- > > > > From a2bc374320d7c7efd3c40644ad3d6d59a024b301 Mon Sep 17 00:00:00 2001 > > From: Pavel Tatashin > > Date: Mon, 29 Jul 2019 21:24:25 -0400 > > Subject: [PATCH v10 16/18] arm64: kexec: configure trans_pgd page table for > > kexec > > > > Configure a page table located in kexec-safe memory that has > > the following mappings: > > > > 1. identity mapping for text of relocation function with executable > > permission. > > 2. va mappings for all source ranges > > 3. va mappings for all destination ranges. > > > > Signed-off-by: Pavel Tatashin > > --- > > arch/arm64/Kconfig | 2 +- > > arch/arm64/include/asm/kexec.h | 12 ++++ > > arch/arm64/kernel/asm-offsets.c | 6 ++ > > arch/arm64/kernel/machine_kexec.c | 91 ++++++++++++++++++++++++++++++- > > 4 files changed, 109 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > > index fc0ed9d6e011..440abd0c0ee1 100644 > > --- a/arch/arm64/Kconfig > > +++ b/arch/arm64/Kconfig > > @@ -1134,7 +1134,7 @@ config CRASH_DUMP > > > > config TRANS_TABLE > > def_bool y > > - depends on HIBERNATION > > + depends on HIBERNATION || KEXEC_CORE > > > > config XEN_DOM0 > > def_bool y > > diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h > > index b96d8a6aac80..049cde429b1b 100644 > > --- a/arch/arm64/include/asm/kexec.h > > +++ b/arch/arm64/include/asm/kexec.h > > @@ -105,6 +105,12 @@ extern const char arm64_kexec_el2_vectors[]; > > * el2_vector If present means that relocation routine will go to EL1 > > * from EL2 to do the copy, and then back to EL2 to do the jump > > * to new world. > > + * trans_ttbr0 idmap for relocation function and its argument > > + * trans_ttbr1 map for source/destination addresses. > > + * trans_t0sz t0sz for idmap page in trans_ttbr0 > > + * src_addr start address for source pages. > > + * dst_addr start address for destination pages. > > + * copy_len Number of bytes that need to be copied > > */ > > struct kern_reloc_arg { > > phys_addr_t head; > > @@ -114,6 +120,12 @@ struct kern_reloc_arg { > > phys_addr_t kern_arg2; > > phys_addr_t kern_arg3; > > phys_addr_t el2_vector; > > + phys_addr_t trans_ttbr0; > > + phys_addr_t trans_ttbr1; > > + unsigned long trans_t0sz; > > + unsigned long src_addr; > > + unsigned long dst_addr; > > + unsigned long copy_len; > > }; > > > > #define ARCH_HAS_KIMAGE_ARCH > > diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c > > index 8a9475be1b62..06278611451d 100644 > > --- a/arch/arm64/kernel/asm-offsets.c > > +++ b/arch/arm64/kernel/asm-offsets.c > > @@ -160,6 +160,12 @@ int main(void) > > DEFINE(KEXEC_KRELOC_KERN_ARG2, offsetof(struct kern_reloc_arg, kern_arg2)); > > DEFINE(KEXEC_KRELOC_KERN_ARG3, offsetof(struct kern_reloc_arg, kern_arg3)); > > DEFINE(KEXEC_KRELOC_EL2_VECTOR, offsetof(struct kern_reloc_arg, el2_vector)); > > + DEFINE(KEXEC_KRELOC_TRANS_TTBR0, offsetof(struct kern_reloc_arg, trans_ttbr0)); > > + DEFINE(KEXEC_KRELOC_TRANS_TTBR1, offsetof(struct kern_reloc_arg, trans_ttbr1)); > > + DEFINE(KEXEC_KRELOC_TRANS_T0SZ, offsetof(struct kern_reloc_arg, trans_t0sz)); > > + DEFINE(KEXEC_KRELOC_SRC_ADDR, offsetof(struct kern_reloc_arg, src_addr)); > > + DEFINE(KEXEC_KRELOC_DST_ADDR, offsetof(struct kern_reloc_arg, dst_addr)); > > + DEFINE(KEXEC_KRELOC_COPY_LEN, offsetof(struct kern_reloc_arg, copy_len)); > > #endif > > return 0; > > } > > diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c > > index 41d1e3ca13f8..dc1b7e5a54fb 100644 > > --- a/arch/arm64/kernel/machine_kexec.c > > +++ b/arch/arm64/kernel/machine_kexec.c > > @@ -21,6 +21,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "cpu-reset.h" > > > > @@ -71,11 +72,91 @@ static void *kexec_page_alloc(void *arg) > > return page_address(page); > > } > > > > +/* > > + * Map source segments starting from src_va, and map destination > > + * segments starting from dst_va, and return size of copy in > > + * *copy_len argument. > > + * Relocation function essentially needs to do: > > + * memcpy(dst_va, src_va, copy_len); > > + */ > > +static int map_segments(struct kimage *kimage, pgd_t *pgdp, > > + struct trans_pgd_info *info, > > + unsigned long src_va, > > + unsigned long dst_va, > > + unsigned long *copy_len) > > +{ > > + unsigned long *ptr = 0; > > + unsigned long dest = 0; > > + unsigned long len = 0; > > + unsigned long entry, addr; > > + int rc; > > + > > + for (entry = kimage->head; !(entry & IND_DONE); entry = *ptr++) { > > + addr = entry & PAGE_MASK; > > + > > + switch (entry & IND_FLAGS) { > > + case IND_DESTINATION: > > + dest = addr; > > + break; > > + case IND_INDIRECTION: > > + ptr = __va(addr); > > + if (rc) > > We're checking a potentially uninitialized value here. I think this > whole "if (rc) return rc;" conditional can go away. Thank you Tyler. This is indeed not needed. Pasha