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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 D1B56C83004 for ; Wed, 29 Apr 2020 17:01:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B07C208FE for ; Wed, 29 Apr 2020 17:01:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B07C208FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4CE038E000A; Wed, 29 Apr 2020 13:01:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 456448E0001; Wed, 29 Apr 2020 13:01:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3452D8E000A; Wed, 29 Apr 2020 13:01:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id 185868E0001 for ; Wed, 29 Apr 2020 13:01:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CA14A180AD804 for ; Wed, 29 Apr 2020 17:01:24 +0000 (UTC) X-FDA: 76761508488.20.sock65_63979bbbe285e X-HE-Tag: sock65_63979bbbe285e X-Filterd-Recvd-Size: 4813 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Apr 2020 17:01:24 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D33E1045; Wed, 29 Apr 2020 10:01:23 -0700 (PDT) Received: from [192.168.0.14] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 03D103F73D; Wed, 29 Apr 2020 10:01:20 -0700 (PDT) Subject: Re: [PATCH v9 07/18] arm64: trans_pgd: hibernate: idmap the single page that holds the copy page routines To: Pavel Tatashin References: <20200326032420.27220-1-pasha.tatashin@soleen.com> <20200326032420.27220-8-pasha.tatashin@soleen.com> From: James Morse Cc: 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, vladimir.murzin@arm.com, matthias.bgg@gmail.com, bhsharma@redhat.com, linux-mm@kvack.org, mark.rutland@arm.com, steve.capper@arm.com, rfontana@redhat.com, tglx@linutronix.de, selindag@gmail.com Message-ID: Date: Wed, 29 Apr 2020 18:01:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200326032420.27220-8-pasha.tatashin@soleen.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit 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: Hi Pavel, On 26/03/2020 03:24, Pavel Tatashin wrote: > From: James Morse > > To resume from hibernate, the contents of memory are restored from > the swap image. This may overwrite any page, including the running > kernel and its page tables. > > Hibernate copies the code it uses to do the restore into a single > page that it knows won't be overwritten, and maps it with page tables > built from pages that won't be overwritten. > > Today the address it uses for this mapping is arbitrary, but to allow > kexec to reuse this code, it needs to be idmapped. To idmap the page > we must avoid the kernel helpers that have VA_BITS baked in. > > Convert create_single_mapping() to take a single PA, and idmap it. > The page tables are built in the reverse order to normal using > pfn_pte() to stir in any bits between 52:48. T0SZ is always increased > to cover 48bits, or 52 if the copy code has bits 52:48 in its PA. > > Pasha: The original patch from James > inux-arm-kernel/20200115143322.214247-4-james.morse@arm.com -EBROKENLINK The convention is to use a 'Link:' tag in the signed-off area. e.g. 5a3577039cbe > Adopted it to trans_pgd, so it can be commonly used by both Kexec > and Hibernate. Some minor clean-ups. Please describe your changes just before your SoB. This means each author sign's off on the stuff above their SoB, and its obvious who made which changes. Search for 'Lucky K Maintainer' in process/submitting-patches.rst for an example. > diff --git a/arch/arm64/include/asm/trans_pgd.h b/arch/arm64/include/asm/trans_pgd.h > index 97a7ea73b289..4912d3caf0ca 100644 > --- a/arch/arm64/include/asm/trans_pgd.h > +++ b/arch/arm64/include/asm/trans_pgd.h > @@ -32,4 +32,7 @@ int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **trans_pgd, > int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, > void *page, unsigned long dst_addr, pgprot_t pgprot); This trans_pgd_map_page() used to be create_single_mapping(), which is where the original patch made its changes. You should only need one of these, not both. > +int trans_pgd_idmap_page(struct trans_pgd_info *info, phys_addr_t *trans_ttbr0, > + unsigned long *t0sz, void *page); > + > #endif /* _ASM_TRANS_TABLE_H */ > diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c > index 37d7d1c60f65..c2517d1af2af 100644 > --- a/arch/arm64/mm/trans_pgd.c > +++ b/arch/arm64/mm/trans_pgd.c > @@ -242,3 +242,52 @@ int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, > > return 0; > } > + > +/* > + * The page we want to idmap may be outside the range covered by VA_BITS that > + * can be built using the kernel's p?d_populate() helpers. As a one off, for a > + * single page, we build these page tables bottom up and just assume that will > + * need the maximum T0SZ. > + * > + * Returns 0 on success, and -ENOMEM on failure. > + * On success trans_ttbr0 contains page table with idmapped page, t0sz is set to > + * maxumum T0SZ for this page. maxumum > + */ Thanks, James