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 2E5A4C47404 for ; Fri, 11 Oct 2019 18:18:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DBF772190F for ; Fri, 11 Oct 2019 18:18:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBF772190F 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 847748E0008; Fri, 11 Oct 2019 14:18:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F9448E0007; Fri, 11 Oct 2019 14:18:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E678E0008; Fri, 11 Oct 2019 14:18:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 4FFF48E0007 for ; Fri, 11 Oct 2019 14:18:39 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id DC5BF45A3 for ; Fri, 11 Oct 2019 18:18:38 +0000 (UTC) X-FDA: 76032314316.24.slip67_85a3c69df6b4b X-HE-Tag: slip67_85a3c69df6b4b X-Filterd-Recvd-Size: 5121 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Fri, 11 Oct 2019 18:18:38 +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 C9AF2142F; Fri, 11 Oct 2019 11:18:37 -0700 (PDT) Received: from [10.1.196.105] (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E19183F703; Fri, 11 Oct 2019 11:18:35 -0700 (PDT) Subject: Re: [PATCH v6 08/17] arm64: hibernate: add trans_pgd public functions To: Pavel Tatashin References: <20191004185234.31471-1-pasha.tatashin@soleen.com> <20191004185234.31471-9-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, marc.zyngier@arm.com, vladimir.murzin@arm.com, matthias.bgg@gmail.com, bhsharma@redhat.com, linux-mm@kvack.org, mark.rutland@arm.com Message-ID: <2ea69969-154d-fa55-767d-43ea8971dd0e@arm.com> Date: Fri, 11 Oct 2019 19:18:34 +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: <20191004185234.31471-9-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 04/10/2019 19:52, Pavel Tatashin wrote: > trans_pgd_create_copy() and trans_pgd_map_page() are going to be > the basis for new shared code that handles page tables for cases > which are between kernels: kexec, and hibernate. > > Note: Eventually, get_safe_page() will be moved into a function pointer > passed via argument, but for now keep it as is. > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c > index ce60bceed357..ded9034b9d39 100644 > --- a/arch/arm64/kernel/hibernate.c > +++ b/arch/arm64/kernel/hibernate.c > @@ -242,6 +218,44 @@ static int create_safe_exec_page(void *src_start, size_t length, > +/* > + * Copies length bytes, starting at src_start into an new page, > + * perform cache maintenance, then maps it at the specified address low > + * address as executable. > + * > + * This is used by hibernate to copy the code it needs to execute when > + * overwriting the kernel text. This function generates a new set of page > + * tables, which it loads into ttbr0. > + * > + * Length is provided as we probably only want 4K of data, even on a 64K > + * page system. > + */ > +static int create_safe_exec_page(void *src_start, size_t length, > + unsigned long dst_addr, > + phys_addr_t *phys_dst_addr) > +{ > + void *page = (void *)get_safe_page(GFP_ATOMIC); > + pgd_t *trans_pgd; > + int rc; > + > + if (!page) > + return -ENOMEM; > + > + memcpy(page, src_start, length); > + __flush_icache_range((unsigned long)page, (unsigned long)page + length); > + > + trans_pgd = (void *)get_safe_page(GFP_ATOMIC); > + if (!trans_pgd) > + return -ENOMEM; > + > + rc = trans_pgd_map_page(trans_pgd, page, dst_addr, > + PAGE_KERNEL_EXEC); > + if (rc) > + return rc; > + > /* > * Load our new page tables. A strict BBM approach requires that we > * ensure that TLBs are free of any entries that may overlap with the (I suspect you are going to to duplicate this in the kexec code. Kexec has the same pattern: instructions that have to be copied to do the relocation of the rest of memory) > @@ -462,6 +476,24 @@ static int copy_page_tables(pgd_t *dst_pgdp, unsigned long start, > +int trans_pgd_create_copy(pgd_t **dst_pgdp, unsigned long start, > + unsigned long end) > +{ > + int rc; > + pgd_t *trans_pgd = (pgd_t *)get_safe_page(GFP_ATOMIC); > + > + if (!trans_pgd) { > + pr_err("Failed to allocate memory for temporary page tables.\n"); > + return -ENOMEM; > + } > + > + rc = copy_page_tables(trans_pgd, start, end); > + if (!rc) > + *dst_pgdp = trans_pgd; *dst_pgdp was already allocated in swsusp_arch_resume(). > + > + return rc; > +} > + > /* > * Setup then Resume from the hibernate image using swsusp_arch_suspend_exit(). > * > @@ -488,7 +520,7 @@ int swsusp_arch_resume(void) > pr_err("Failed to allocate memory for temporary page tables.\n"); > return -ENOMEM; > } If the allocation moves into 'trans_pgd_create_copy()', please move the code just above here (cut off by the diff) that allocates it in swsusp_arch_resume(). Its actually okay to leak memory like this, hibernate's allocator acts as a memory pool. It either gets freed if we fail to resume, or vanishes when the resumed kernel takes over. Reviewed-by: James Morse > - rc = copy_page_tables(tmp_pg_dir, PAGE_OFFSET, PAGE_END); > + rc = trans_pgd_create_copy(&tmp_pg_dir, PAGE_OFFSET, PAGE_END); > if (rc) > return rc; Thanks, James