From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 35981C433E0 for ; Wed, 27 Jan 2021 16:48:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9893764D9E for ; Wed, 27 Jan 2021 16:48:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9893764D9E 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 BD4816B0005; Wed, 27 Jan 2021 11:48:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B860B6B0006; Wed, 27 Jan 2021 11:48:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A26C56B006C; Wed, 27 Jan 2021 11:48:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 8CA236B0005 for ; Wed, 27 Jan 2021 11:48:02 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 51E9E180AD82F for ; Wed, 27 Jan 2021 16:48:02 +0000 (UTC) X-FDA: 77752137204.30.crook05_560ef3327598 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 2A178180B3C83 for ; Wed, 27 Jan 2021 16:48:02 +0000 (UTC) X-HE-Tag: crook05_560ef3327598 X-Filterd-Recvd-Size: 9204 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 16:48:01 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id gx5so3589180ejb.7 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=QI9GS6/4+E7Uq5Ue+I2ddUeKeeXZkjBQEB3isKsT01IquCIS57gJHUO7YaDT65veAT cMT+AqKHy3HELwQ5rEXLa6jr1D8Gwtj7tX445ugjVMO9i9OvWUvAooeRVyUp5Q/Fewn6 mbOiomr9FTvr8RLQdZ/TqNSQkoKiArBu0hWv+13s3NSdKEv7pQwdFtD4CEYUS7Uo1WKd 2g3EejOldQm4kLkc1Onmg9+LAETe/oQMKWR6kYnLv3Ht9hem4waiKB7ErbZb45GlsY1g ZamFodwQogCQOSQwBJISm5vGVZHO2CEeV3aEqFqJpEb1nPt/g+a7D9aMU//4+z7LTJNp BI5g== X-Gm-Message-State: AOAM532LXDqw58MxfSDVQjkKzJtQ8QlEwrFp3qosVyxNZcrSjJdQ5KEJ 3HrsQZueJCtlu6dDSqdlMWG6xK1EPekig3utEnxEmA== X-Google-Smtp-Source: ABdhPJzY/0E7pKaHXMugYVU++KnMNQWLvbtaXIlDKuzPhoWRjT3DXhIBF/1wneCQyLEivHzmXwnOjEa4rc1XacysGE4= 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" 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: 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