From patchwork Mon Jun 12 21:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13277363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97B08C88CB5 for ; Mon, 12 Jun 2023 21:05:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3312E94001B; Mon, 12 Jun 2023 17:05:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8A394000B; Mon, 12 Jun 2023 17:05:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BD0694001B; Mon, 12 Jun 2023 17:05:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ED63994000B for ; Mon, 12 Jun 2023 17:05:27 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 97B3940365 for ; Mon, 12 Jun 2023 21:05:27 +0000 (UTC) X-FDA: 80895326694.04.97C47BC Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) by imf28.hostedemail.com (Postfix) with ESMTP id BF914C0016 for ; Mon, 12 Jun 2023 21:05:25 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=amnQXBB4; spf=pass (imf28.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686603925; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZOzPn7Z2jtK8/Rr5ywaEqtGlE/ejlN/QX/LQ5us0iZw=; b=pJxKL+DuJwglAwUMZu49+/lv5LFZTJnUB3nXIA8v5QM+m7pVatZDEV8H01mTh5vcF7REF4 lOoUxK+fclRvSd4ES3cZuqQpZIXPuyHBU0pOIz44NJVS5x0TK3NFh9sU5K8O78S6MY5kRj LJxCHFAwem3i5waDRBOn1lHABuqXUfE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686603925; a=rsa-sha256; cv=none; b=bpbgBTm5zt45W9NjeynPXuA/HxlRyZoOG/AoIBZupNe7ARMVhdWTRbFWKZJI3BG/hoctJs oU3BVUA5zsEw9iGd+dXq7H9AGaFy98C9/rUh62bx6uc1BJrePMe5muzen/6KCs1/gPYdLd uAeoqzmlvnixDhIfuwubW4wW5cwrkes= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=amnQXBB4; spf=pass (imf28.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.128.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-56cf916aaa2so27690217b3.3 for ; Mon, 12 Jun 2023 14:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686603925; x=1689195925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZOzPn7Z2jtK8/Rr5ywaEqtGlE/ejlN/QX/LQ5us0iZw=; b=amnQXBB4tikUqyZuYm66ERDrt0MonFbKGOEZfuTs2nAKMZrZX44zBIkrZ9ZRA+fa06 AyRj50rDxNfHhQPMlo167Gc41a6L1LuDKJ258/2NPg0RLjnehfyC8Q3Sm9AoXuOB8wna AK82U9SCt1rBakvYMiJ/vf5JAUixz4Ru3K2k7WFZarIq7YpCiX1p1YPhbePfgV7HLqZ+ kNFkfK9EfSJ1kUzZet7nsXlMsD1vEo9vMFOs67Cs6PkQ7Z4TWwViMHDRmAjVmKbDbb6h AGLOD6SK7T6AuaFbMvMXKIFXkvVjI92aE3GZuD3T4HWNlPXuHq87MICVALiAwdvuGzfw BW+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686603925; x=1689195925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZOzPn7Z2jtK8/Rr5ywaEqtGlE/ejlN/QX/LQ5us0iZw=; b=dEA/h5DAsD6RvgzKGW31mRDNBYi1eZE5J7aZY5ZZaznUpTQnba59m4MChRCAvpg/im o2aijwuyY/7BE7Epi3ANeYRbu5ng70EKh+JbAnn+yST6ICOmG/gWKTsX/Y+vJocI/Mui Lm8ga49Nk1bAmZL765WI0nSCwjGwZCKOgFJ2Si5VtmcY/Y6ttTdTX8NbhXlVEATUNkvG RPdB2O1pVyDMDqvs4AIV7Q104ojjCsqgpSNQlRf4F4H+9L5JlYckhKeFpTS0fTJ7Cpu5 bgw2rq2BK4hDDdVoIxUBHUm3wgP5D3w6+rGI7PqJ9VSF7I0HVKWMfkZV93NJtDs9RFCc fUug== X-Gm-Message-State: AC+VfDziqh3HvHTq7K4GRiqOm1aB4ArhUgMYILHMB9RjA9loCrKqqcml rS1RiK1VUXVkzpbF7SUJoHA= X-Google-Smtp-Source: ACHHUZ6Cwt/E6dG3WFyoFqOmBAzPgcTMvw0zuz67x28fyF+Rzf5uGkmgtov/aqSyP68nWBC9sA7rZQ== X-Received: by 2002:a81:84ce:0:b0:56d:4f2e:6f83 with SMTP id u197-20020a8184ce000000b0056d4f2e6f83mr1630242ywf.4.1686603924760; Mon, 12 Jun 2023 14:05:24 -0700 (PDT) Received: from unknowna0e70b2ca394.attlocal.net ([2600:1700:2f7d:1800::16]) by smtp.googlemail.com with ESMTPSA id s125-20020a817783000000b00569eb609458sm2757115ywc.81.2023.06.12.14.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 14:05:24 -0700 (PDT) From: "Vishal Moola (Oracle)" To: Andrew Morton , Matthew Wilcox Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Hugh Dickins , "Vishal Moola (Oracle)" Subject: [PATCH v4 19/34] pgalloc: Convert various functions to use ptdescs Date: Mon, 12 Jun 2023 14:04:08 -0700 Message-Id: <20230612210423.18611-20-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612210423.18611-1-vishal.moola@gmail.com> References: <20230612210423.18611-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Stat-Signature: tyrpwsxcquobbnkynyc8u6hsm4xxscu8 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BF914C0016 X-Rspam-User: X-HE-Tag: 1686603925-314790 X-HE-Meta: U2FsdGVkX1/H7zgO24Il+Nt2fmeoPWlthU3SZoisCX4iq8L+WmfQOD6CB8QBUnUsiwW6OpZo/D93/15tz0HGvYn2P66n2fxxzWY7IMu3RlewbyRLqSo1phjYFtwv6PiYbItSNpC3iblUvNZFjnpKrrb5VGBKaHseX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ab2hMINXwnxc4b+8ubapKVNL3WZM0j0XcIx2SqV3LNK2ikcEElNpfLR0brtRrk3unqLa+3wFWiFalpXqDpAtZZ5Adk7ujpBwuSI9nhnxBydPbcsj32ON9RngjtwYZZE3fY50xd0oTXD4npUZSWYuGvo9XvVr7vUvfvPDJia6eI4svW3ep6JQP287RteAT+G3242qOi05d26URYdrjXeLt49QyBet2b8b4nl8QG2GG6P4nJMvjNnBKynhBfxUR7ZPjgMcV0piA7teAILs8kdjN+oFCXaECw== 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: As part of the conversions to replace pgtable constructor/destructors with ptdesc equivalents, convert various page table functions to use ptdescs. Some of the functions use the *get*page*() helper functions. Convert these to use pagetable_alloc() and ptdesc_address() instead to help standardize page tables further. Signed-off-by: Vishal Moola (Oracle) --- include/asm-generic/pgalloc.h | 62 +++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h index a7cf825befae..3fd6ce79e654 100644 --- a/include/asm-generic/pgalloc.h +++ b/include/asm-generic/pgalloc.h @@ -18,7 +18,11 @@ */ static inline pte_t *__pte_alloc_one_kernel(struct mm_struct *mm) { - return (pte_t *)__get_free_page(GFP_PGTABLE_KERNEL); + struct ptdesc *ptdesc = pagetable_alloc(GFP_PGTABLE_KERNEL, 0); + + if (!ptdesc) + return NULL; + return ptdesc_address(ptdesc); } #ifndef __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL @@ -41,7 +45,7 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) */ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) { - free_page((unsigned long)pte); + pagetable_free(virt_to_ptdesc(pte)); } /** @@ -49,7 +53,7 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) * @mm: the mm_struct of the current context * @gfp: GFP flags to use for the allocation * - * Allocates a page and runs the pgtable_pte_page_ctor(). + * Allocates a ptdesc and runs the pagetable_pte_ctor(). * * This function is intended for architectures that need * anything beyond simple page allocation or must have custom GFP flags. @@ -58,17 +62,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) */ static inline pgtable_t __pte_alloc_one(struct mm_struct *mm, gfp_t gfp) { - struct page *pte; + struct ptdesc *ptdesc; - pte = alloc_page(gfp); - if (!pte) + ptdesc = pagetable_alloc(gfp, 0); + if (!ptdesc) return NULL; - if (!pgtable_pte_page_ctor(pte)) { - __free_page(pte); + if (!pagetable_pte_ctor(ptdesc)) { + pagetable_free(ptdesc); return NULL; } - return pte; + return ptdesc_page(ptdesc); } #ifndef __HAVE_ARCH_PTE_ALLOC_ONE @@ -76,7 +80,7 @@ static inline pgtable_t __pte_alloc_one(struct mm_struct *mm, gfp_t gfp) * pte_alloc_one - allocate a page for PTE-level user page table * @mm: the mm_struct of the current context * - * Allocates a page and runs the pgtable_pte_page_ctor(). + * Allocates a ptdesc and runs the pagetable_pte_ctor(). * * Return: `struct page` initialized as page table or %NULL on error */ @@ -98,8 +102,10 @@ static inline pgtable_t pte_alloc_one(struct mm_struct *mm) */ static inline void pte_free(struct mm_struct *mm, struct page *pte_page) { - pgtable_pte_page_dtor(pte_page); - __free_page(pte_page); + struct ptdesc *ptdesc = page_ptdesc(pte_page); + + pagetable_pte_dtor(ptdesc); + pagetable_free(ptdesc); } @@ -110,7 +116,7 @@ static inline void pte_free(struct mm_struct *mm, struct page *pte_page) * pmd_alloc_one - allocate a page for PMD-level page table * @mm: the mm_struct of the current context * - * Allocates a page and runs the pgtable_pmd_page_ctor(). + * Allocates a ptdesc and runs the pagetable_pmd_ctor(). * Allocations use %GFP_PGTABLE_USER in user context and * %GFP_PGTABLE_KERNEL in kernel context. * @@ -118,28 +124,30 @@ static inline void pte_free(struct mm_struct *mm, struct page *pte_page) */ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) { - struct page *page; + struct ptdesc *ptdesc; gfp_t gfp = GFP_PGTABLE_USER; if (mm == &init_mm) gfp = GFP_PGTABLE_KERNEL; - page = alloc_page(gfp); - if (!page) + ptdesc = pagetable_alloc(gfp, 0); + if (!ptdesc) return NULL; - if (!pgtable_pmd_page_ctor(page)) { - __free_page(page); + if (!pagetable_pmd_ctor(ptdesc)) { + pagetable_free(ptdesc); return NULL; } - return (pmd_t *)page_address(page); + return ptdesc_address(ptdesc); } #endif #ifndef __HAVE_ARCH_PMD_FREE static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) { + struct ptdesc *ptdesc = virt_to_ptdesc(pmd); + BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); - pgtable_pmd_page_dtor(virt_to_page(pmd)); - free_page((unsigned long)pmd); + pagetable_pmd_dtor(ptdesc); + pagetable_free(ptdesc); } #endif @@ -149,11 +157,15 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) static inline pud_t *__pud_alloc_one(struct mm_struct *mm, unsigned long addr) { - gfp_t gfp = GFP_PGTABLE_USER; + gfp_t gfp = GFP_PGTABLE_USER | __GFP_ZERO; + struct ptdesc *ptdesc; if (mm == &init_mm) gfp = GFP_PGTABLE_KERNEL; - return (pud_t *)get_zeroed_page(gfp); + ptdesc = pagetable_alloc(gfp, 0); + if (!ptdesc) + return NULL; + return ptdesc_address(ptdesc); } #ifndef __HAVE_ARCH_PUD_ALLOC_ONE @@ -175,7 +187,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) static inline void __pud_free(struct mm_struct *mm, pud_t *pud) { BUG_ON((unsigned long)pud & (PAGE_SIZE-1)); - free_page((unsigned long)pud); + pagetable_free(virt_to_ptdesc(pud)); } #ifndef __HAVE_ARCH_PUD_FREE @@ -190,7 +202,7 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud) #ifndef __HAVE_ARCH_PGD_FREE static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) { - free_page((unsigned long)pgd); + pagetable_free(virt_to_ptdesc(pgd)); } #endif