From patchwork Mon Jul 31 17:03:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13335111 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 C495CC05052 for ; Mon, 31 Jul 2023 17:04:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA91C6B0176; Mon, 31 Jul 2023 13:04:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D30FF6B0177; Mon, 31 Jul 2023 13:04:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83B36B0178; Mon, 31 Jul 2023 13:04:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A5DF26B0176 for ; Mon, 31 Jul 2023 13:04:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 648A1160B20 for ; Mon, 31 Jul 2023 17:04:07 +0000 (UTC) X-FDA: 81072529734.23.0B4908E Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 25F8A1A0008 for ; Mon, 31 Jul 2023 17:04:04 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=DDv4TKtr; spf=pass (imf19.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.167.182 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=1690823045; 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=sltDOqqNfHEtvz8jLXUjW/r74sJCuRKUMVTEbSHBWCo=; b=QkLzEW8qaNCGUaLzSKRbEmg1y3AN/ON4nv/QBCS7DvIBF8C3k6X3S4Yn6C/QWHMVE1tk9c j8GQOuuAd1sE0ZPwFMRGRb73CnkC9x0M8Z7Ek8jEjCpA8jcZd+KigR32yUUI6HH6MBmLob khmWtY+Ghc0oieaYBHTP5Kvtz3OHJF0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690823045; a=rsa-sha256; cv=none; b=QdC+AgBCG/CyJh4wmPskj4iVI/W3YUtoqRuoHVFyxmMu0oAPD6828rDm4JHB6epyfs9grr 2KVf4EXMc/+juClh8I08geND/8JQ2hhEwgkZlQPk9l2eGoBBJjv5vjh9lsVi7mwKfgfUDe oagYPdqfyNu+I20OqCfpEgGZXoxg9RQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=DDv4TKtr; spf=pass (imf19.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.167.182 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3a3e1152c23so3458363b6e.2 for ; Mon, 31 Jul 2023 10:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690823044; x=1691427844; 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=sltDOqqNfHEtvz8jLXUjW/r74sJCuRKUMVTEbSHBWCo=; b=DDv4TKtr1SQu5KqZfb+k47cCUnTqa2hu0PGvOIZKT6p5w+WOigqgjt3pTCKyoVLOur PNxnRZ3jA0/RzPila/zrL9Ut0S2D7/dzdlixHctnRTEPuULJtPpCXt2sv6EdNGvihlcs y+VItng76gppkBpBjqibZpmruGV1NMM5yu9a5rLJnoNJwEeQ9JDH3AVeubSs7+9WGxCh BgihnLJKz5piH3g7XsbkueQJcQA3Z7Rp93aL/N3tU8RHXtjRG0jvHhNa9PLCdjFnI5G2 GSA2pxYIUUVv4+PcoooKpTBzs2tJHyDwSGkSOMs2tb/nCpuvSVvt1GOnIBWnaMdpcLVw tIUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690823044; x=1691427844; 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=sltDOqqNfHEtvz8jLXUjW/r74sJCuRKUMVTEbSHBWCo=; b=HdmG0Aj6tP907lUjKoCmjLwMauiAyt2zJx7uZ5/wdgGeArTi4XfZwNCaMAIbaZkzOo 7YaEJ+xv8P2eqFQSU3E4TMiSAd3RmPpZ0CCU+lZERKuifeUc2ZHPOvr/A0Z/k67KAbpE a7FLp0jIG/XbTtA7sedWAt7/vq9L1iDV/gpJVgANBs9b/DRUigBet9mdfGEKJp1AAx5e H493cVkYKq4h6qjINQ/zTPTumxI+1xBetP+3fw4YN2kQ7NSaoyHZm8rGpM8rhSW+V7Ru MC0AwYmlM+7P11c9NJNguMAr7DLXaD6ABrouVjerK38xGaP+37rLJWBKy0lzHc0wYcio 5+Pw== X-Gm-Message-State: ABy/qLayafCyipX0NVxI3KKgtdp/6FVdZs+uAnPqKOqeua6ko5Ol0HRs y2d13c+6CbMz3bwsEvY1G3I= X-Google-Smtp-Source: APBJJlHmCcTDPCXO6u+09Bgv6vKTB5JCy6bic+/Xn7A3kI+4k4FzOgutNRH/lGvVTDd+56ojK0po+g== X-Received: by 2002:a05:6808:d4a:b0:3a3:e593:5ac1 with SMTP id w10-20020a0568080d4a00b003a3e5935ac1mr13154690oik.21.1690823043912; Mon, 31 Jul 2023 10:04:03 -0700 (PDT) Received: from unknowna0e70b2ca394.attlocal.net ([2600:1700:2f7d:1800::16]) by smtp.googlemail.com with ESMTPSA id x31-20020a25ac9f000000b00c832ad2e2eesm2511833ybi.60.2023.07.31.10.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 10:04:03 -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)" , Dave Hansen Subject: [PATCH mm-unstable v8 13/31] x86: Convert various functions to use ptdescs Date: Mon, 31 Jul 2023 10:03:14 -0700 Message-Id: <20230731170332.69404-14-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230731170332.69404-1-vishal.moola@gmail.com> References: <20230731170332.69404-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 25F8A1A0008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: s874wia9s5auguj7woxfoxz1chfum787 X-HE-Tag: 1690823044-240460 X-HE-Meta: U2FsdGVkX19PO6tuIUXuvDFrB7bcSXii4gWb8XoVjp0FuXOZNGSKgMMMMAmXopZSkW92O6ppt2EZDsg8ND/OQvOmUaZUF73g9PLDT918iPn/miC9AF7e/hcHrQobzjrH8flcl7ArF6fXsHKDSKj/pG+FU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zgbETbI8eEAU/TJddWsK2RDRu9lr3V8DuYwYXRh7VB6gTeBS275ZzX4wsX+rV5gGSKjfSBF3ZrY0XxyRi9PB25jxsorQxfLcvFj1WbL0ZISJEcpaEUxkI3PTJcXgdoFL1TpqKUHn0YoMF0pDxtodtSQxaXQoDr1cyP86zrAnxpzMRb22CwDMzixHlLzpYt72nAXUNEM4G3EdmU1WjChus2aJy6IGrrIkKHB3MjZHm23Vtj/dnXAFIGFauotj61poBuVo2473WW7oP+ZxLUAY46OlccirKt2LulcVg== 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: In order to split struct ptdesc from struct page, convert various 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) --- arch/x86/mm/pgtable.c | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 15a8009a4480..d3a93e8766ee 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -52,7 +52,7 @@ early_param("userpte", setup_userpte); void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte) { - pgtable_pte_page_dtor(pte); + pagetable_pte_dtor(page_ptdesc(pte)); paravirt_release_pte(page_to_pfn(pte)); paravirt_tlb_remove_table(tlb, pte); } @@ -60,7 +60,7 @@ void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte) #if CONFIG_PGTABLE_LEVELS > 2 void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd) { - struct page *page = virt_to_page(pmd); + struct ptdesc *ptdesc = virt_to_ptdesc(pmd); paravirt_release_pmd(__pa(pmd) >> PAGE_SHIFT); /* * NOTE! For PAE, any changes to the top page-directory-pointer-table @@ -69,8 +69,8 @@ void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd) #ifdef CONFIG_X86_PAE tlb->need_flush_all = 1; #endif - pgtable_pmd_page_dtor(page); - paravirt_tlb_remove_table(tlb, page); + pagetable_pmd_dtor(ptdesc); + paravirt_tlb_remove_table(tlb, ptdesc_page(ptdesc)); } #if CONFIG_PGTABLE_LEVELS > 3 @@ -92,16 +92,16 @@ void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d) static inline void pgd_list_add(pgd_t *pgd) { - struct page *page = virt_to_page(pgd); + struct ptdesc *ptdesc = virt_to_ptdesc(pgd); - list_add(&page->lru, &pgd_list); + list_add(&ptdesc->pt_list, &pgd_list); } static inline void pgd_list_del(pgd_t *pgd) { - struct page *page = virt_to_page(pgd); + struct ptdesc *ptdesc = virt_to_ptdesc(pgd); - list_del(&page->lru); + list_del(&ptdesc->pt_list); } #define UNSHARED_PTRS_PER_PGD \ @@ -112,12 +112,12 @@ static inline void pgd_list_del(pgd_t *pgd) static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm) { - virt_to_page(pgd)->pt_mm = mm; + virt_to_ptdesc(pgd)->pt_mm = mm; } struct mm_struct *pgd_page_get_mm(struct page *page) { - return page->pt_mm; + return page_ptdesc(page)->pt_mm; } static void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) @@ -213,11 +213,14 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) static void free_pmds(struct mm_struct *mm, pmd_t *pmds[], int count) { int i; + struct ptdesc *ptdesc; for (i = 0; i < count; i++) if (pmds[i]) { - pgtable_pmd_page_dtor(virt_to_page(pmds[i])); - free_page((unsigned long)pmds[i]); + ptdesc = virt_to_ptdesc(pmds[i]); + + pagetable_pmd_dtor(ptdesc); + pagetable_free(ptdesc); mm_dec_nr_pmds(mm); } } @@ -230,18 +233,24 @@ static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count) if (mm == &init_mm) gfp &= ~__GFP_ACCOUNT; + gfp &= ~__GFP_HIGHMEM; for (i = 0; i < count; i++) { - pmd_t *pmd = (pmd_t *)__get_free_page(gfp); - if (!pmd) + pmd_t *pmd = NULL; + struct ptdesc *ptdesc = pagetable_alloc(gfp, 0); + + if (!ptdesc) failed = true; - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) { - free_page((unsigned long)pmd); - pmd = NULL; + if (ptdesc && !pagetable_pmd_ctor(ptdesc)) { + pagetable_free(ptdesc); + ptdesc = NULL; failed = true; } - if (pmd) + if (ptdesc) { mm_inc_nr_pmds(mm); + pmd = ptdesc_address(ptdesc); + } + pmds[i] = pmd; } @@ -830,7 +839,7 @@ int pud_free_pmd_page(pud_t *pud, unsigned long addr) free_page((unsigned long)pmd_sv); - pgtable_pmd_page_dtor(virt_to_page(pmd)); + pagetable_pmd_dtor(virt_to_ptdesc(pmd)); free_page((unsigned long)pmd); return 1;