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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 53792C433DB for ; Mon, 25 Jan 2021 19:19:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D453B20E65 for ; Mon, 25 Jan 2021 19:19:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D453B20E65 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 D7DFF8D0020; Mon, 25 Jan 2021 14:19:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D2D558D0001; Mon, 25 Jan 2021 14:19:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1AC18D0020; Mon, 25 Jan 2021 14:19:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AD0068D0001 for ; Mon, 25 Jan 2021 14:19:34 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7B0F8180ACC5A for ; Mon, 25 Jan 2021 19:19:34 +0000 (UTC) X-FDA: 77745261468.21.crow81_200846f27588 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 55F07180442CB for ; Mon, 25 Jan 2021 19:19:34 +0000 (UTC) X-HE-Tag: crow81_200846f27588 X-Filterd-Recvd-Size: 10569 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 Jan 2021 19:19:33 +0000 (UTC) Received: by mail-qv1-f54.google.com with SMTP id es14so2919521qvb.3 for ; Mon, 25 Jan 2021 11:19:33 -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=FGDp7jvUOvQaUtmYsOORS7JatJv8YjyLST8iVKp3uek=; b=MCIWlM9LqtrBZhnKkAMxaF3ZB6y612DYB/9YdT3+aJCN8N2Ped81zgD28h2d7Y2eui M1kCjXBd2IUYY5Wyk+2REfe21/3BZvjMKmy50MwmvYJV75E7R+PJ815FzSmDwolsQ/+t jlzH6h1VWG0WxXPPh/t5QYrP0sv8OosPme/9H8Iwiou9nQxfDuKMIQgpe2JtLd2pX+eB BFJlTpWqsf8V1rCwfzGPAjoaSrlSoDrH3R8qJn6tiYSEnQyOr+NSmm1VaS2m2J1QzlKM RDecp+ibsQWFrMRfWAQ8r7dgwQY5oFFokAh78jU24QV6JnsCbEPYzVXC4FKym3jn74BI 5+Bw== 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=FGDp7jvUOvQaUtmYsOORS7JatJv8YjyLST8iVKp3uek=; b=s7nt28MCPLPp9VedvZ1KS997z/0gPAzwGfsEV1rtnyUOkOkqsAWiF7QGDPo4Z/j8XV rY+DLBwKloZRJCQY3v5Z8dlhsf9uNlZEYetviTJncp8j9bqOFe+MBYfrMlTGERIVYNNJ fmeRHDrA0lagd/gjyCNdYfZC23tWa8Z1gDkancfd3aqyvj9P51UgVd4UmyB2mbOuQRZB bpUXA42SCSFrUTPz/Gv4HDr8WgGHoGRF4H2CymPVzSFpq8QopreDXlv4qZTNy8/gxVIl 1Y2UNtHzWQ3dQMJM3GtvwVeUz6CMNF2ucCP25Zt1Xwi9yo49+Zh8trgmYZcCS6bwB7uB yZVQ== X-Gm-Message-State: AOAM5325xi9EcyOtcORZQeKSWExMqUuXLLsSdKwPAr3XJEeT8FJwwGAJ 74ZIuJlQEimgkBmZJWL79ft6Og== X-Google-Smtp-Source: ABdhPJxxx+xP/tQ5CLVtjlwvppB0m/QNU5v1txKp9ktgaWccMjRmTAmf67LKfYWEvAAHjJJ9HcNAlg== X-Received: by 2002:ad4:4e8a:: with SMTP id dy10mr2245973qvb.36.1611602373235; Mon, 25 Jan 2021 11:19:33 -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 s6sm9047638qtx.63.2021.01.25.11.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 11:19:32 -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 v10 05/18] arm64: trans_pgd: pass allocator trans_pgd_create_copy Date: Mon, 25 Jan 2021 14:19:10 -0500 Message-Id: <20210125191923.1060122-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210125191923.1060122-1-pasha.tatashin@soleen.com> References: <20210125191923.1060122-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Make trans_pgd_create_copy and its subroutines to use allocator that is passed as an argument Signed-off-by: Pavel Tatashin Reviewed-by: James Morse --- arch/arm64/include/asm/trans_pgd.h | 4 +-- arch/arm64/kernel/hibernate.c | 7 ++++- arch/arm64/mm/trans_pgd.c | 49 ++++++++++++++++++------------ 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/arch/arm64/include/asm/trans_pgd.h b/arch/arm64/include/asm/= trans_pgd.h index b46409b25234..7fbf6a3ccff7 100644 --- a/arch/arm64/include/asm/trans_pgd.h +++ b/arch/arm64/include/asm/trans_pgd.h @@ -27,8 +27,8 @@ struct trans_pgd_info { void *trans_alloc_arg; }; =20 -int trans_pgd_create_copy(pgd_t **dst_pgdp, unsigned long start, - unsigned long end); +int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **trans_pgd= , + unsigned long start, unsigned long end); =20 int trans_pgd_map_page(struct trans_pgd_info *info, pgd_t *trans_pgd, void *page, unsigned long dst_addr, pgprot_t pgprot); diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.= c index c173f280bfea..94fc275cdd21 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -437,13 +437,18 @@ int swsusp_arch_resume(void) phys_addr_t phys_hibernate_exit; void __noreturn (*hibernate_exit)(phys_addr_t, phys_addr_t, void *, void *, phys_addr_t, phys_addr_t); + struct trans_pgd_info trans_info =3D { + .trans_alloc_page =3D hibernate_page_alloc, + .trans_alloc_arg =3D (void *)GFP_ATOMIC, + }; =20 /* * Restoring the memory image will overwrite the ttbr1 page tables. * Create a second copy of just the linear map, and use this when * restoring. */ - rc =3D trans_pgd_create_copy(&tmp_pg_dir, PAGE_OFFSET, PAGE_END); + rc =3D trans_pgd_create_copy(&trans_info, &tmp_pg_dir, PAGE_OFFSET, + PAGE_END); if (rc) return rc; =20 diff --git a/arch/arm64/mm/trans_pgd.c b/arch/arm64/mm/trans_pgd.c index f28eceba2242..47b6b7029907 100644 --- a/arch/arm64/mm/trans_pgd.c +++ b/arch/arm64/mm/trans_pgd.c @@ -57,14 +57,14 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_pte= p, unsigned long addr) } } =20 -static int copy_pte(pmd_t *dst_pmdp, pmd_t *src_pmdp, unsigned long star= t, - unsigned long end) +static int copy_pte(struct trans_pgd_info *info, pmd_t *dst_pmdp, + pmd_t *src_pmdp, unsigned long start, unsigned long end) { pte_t *src_ptep; pte_t *dst_ptep; unsigned long addr =3D start; =20 - dst_ptep =3D (pte_t *)get_safe_page(GFP_ATOMIC); + dst_ptep =3D trans_alloc(info); if (!dst_ptep) return -ENOMEM; pmd_populate_kernel(&init_mm, dst_pmdp, dst_ptep); @@ -78,8 +78,8 @@ static int copy_pte(pmd_t *dst_pmdp, pmd_t *src_pmdp, u= nsigned long start, return 0; } =20 -static int copy_pmd(pud_t *dst_pudp, pud_t *src_pudp, unsigned long star= t, - unsigned long end) +static int copy_pmd(struct trans_pgd_info *info, pud_t *dst_pudp, + pud_t *src_pudp, unsigned long start, unsigned long end) { pmd_t *src_pmdp; pmd_t *dst_pmdp; @@ -87,7 +87,7 @@ static int copy_pmd(pud_t *dst_pudp, pud_t *src_pudp, u= nsigned long start, unsigned long addr =3D start; =20 if (pud_none(READ_ONCE(*dst_pudp))) { - dst_pmdp =3D (pmd_t *)get_safe_page(GFP_ATOMIC); + dst_pmdp =3D trans_alloc(info); if (!dst_pmdp) return -ENOMEM; pud_populate(&init_mm, dst_pudp, dst_pmdp); @@ -102,7 +102,7 @@ static int copy_pmd(pud_t *dst_pudp, pud_t *src_pudp,= unsigned long start, if (pmd_none(pmd)) continue; if (pmd_table(pmd)) { - if (copy_pte(dst_pmdp, src_pmdp, addr, next)) + if (copy_pte(info, dst_pmdp, src_pmdp, addr, next)) return -ENOMEM; } else { set_pmd(dst_pmdp, @@ -113,7 +113,8 @@ static int copy_pmd(pud_t *dst_pudp, pud_t *src_pudp,= unsigned long start, return 0; } =20 -static int copy_pud(p4d_t *dst_p4dp, p4d_t *src_p4dp, unsigned long star= t, +static int copy_pud(struct trans_pgd_info *info, p4d_t *dst_p4dp, + p4d_t *src_p4dp, unsigned long start, unsigned long end) { pud_t *dst_pudp; @@ -122,7 +123,7 @@ static int copy_pud(p4d_t *dst_p4dp, p4d_t *src_p4dp,= unsigned long start, unsigned long addr =3D start; =20 if (p4d_none(READ_ONCE(*dst_p4dp))) { - dst_pudp =3D (pud_t *)get_safe_page(GFP_ATOMIC); + dst_pudp =3D trans_alloc(info); if (!dst_pudp) return -ENOMEM; p4d_populate(&init_mm, dst_p4dp, dst_pudp); @@ -137,7 +138,7 @@ static int copy_pud(p4d_t *dst_p4dp, p4d_t *src_p4dp,= unsigned long start, if (pud_none(pud)) continue; if (pud_table(pud)) { - if (copy_pmd(dst_pudp, src_pudp, addr, next)) + if (copy_pmd(info, dst_pudp, src_pudp, addr, next)) return -ENOMEM; } else { set_pud(dst_pudp, @@ -148,7 +149,8 @@ static int copy_pud(p4d_t *dst_p4dp, p4d_t *src_p4dp,= unsigned long start, return 0; } =20 -static int copy_p4d(pgd_t *dst_pgdp, pgd_t *src_pgdp, unsigned long star= t, +static int copy_p4d(struct trans_pgd_info *info, pgd_t *dst_pgdp, + pgd_t *src_pgdp, unsigned long start, unsigned long end) { p4d_t *dst_p4dp; @@ -162,15 +164,15 @@ static int copy_p4d(pgd_t *dst_pgdp, pgd_t *src_pgd= p, unsigned long start, next =3D p4d_addr_end(addr, end); if (p4d_none(READ_ONCE(*src_p4dp))) continue; - if (copy_pud(dst_p4dp, src_p4dp, addr, next)) + if (copy_pud(info, dst_p4dp, src_p4dp, addr, next)) return -ENOMEM; } while (dst_p4dp++, src_p4dp++, addr =3D next, addr !=3D end); =20 return 0; } =20 -static int copy_page_tables(pgd_t *dst_pgdp, unsigned long start, - unsigned long end) +static int copy_page_tables(struct trans_pgd_info *info, pgd_t *dst_pgdp= , + unsigned long start, unsigned long end) { unsigned long next; unsigned long addr =3D start; @@ -181,25 +183,34 @@ static int copy_page_tables(pgd_t *dst_pgdp, unsign= ed long start, next =3D pgd_addr_end(addr, end); if (pgd_none(READ_ONCE(*src_pgdp))) continue; - if (copy_p4d(dst_pgdp, src_pgdp, addr, next)) + if (copy_p4d(info, dst_pgdp, src_pgdp, addr, next)) return -ENOMEM; } while (dst_pgdp++, src_pgdp++, addr =3D next, addr !=3D end); =20 return 0; } =20 -int trans_pgd_create_copy(pgd_t **dst_pgdp, unsigned long start, - unsigned long end) +/* + * Create trans_pgd and copy linear map. + * info: contains allocator and its argument + * dst_pgdp: new page table that is created, and to which map is copied. + * start: Start of the interval (inclusive). + * end: End of the interval (exclusive). + * + * Returns 0 on success, and -ENOMEM on failure. + */ +int trans_pgd_create_copy(struct trans_pgd_info *info, pgd_t **dst_pgdp, + unsigned long start, unsigned long end) { int rc; - pgd_t *trans_pgd =3D (pgd_t *)get_safe_page(GFP_ATOMIC); + pgd_t *trans_pgd =3D trans_alloc(info); =20 if (!trans_pgd) { pr_err("Failed to allocate memory for temporary page tables.\n"); return -ENOMEM; } =20 - rc =3D copy_page_tables(trans_pgd, start, end); + rc =3D copy_page_tables(info, trans_pgd, start, end); if (!rc) *dst_pgdp =3D trans_pgd; =20 --=20 2.25.1