Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp492708ybt; Fri, 26 Jun 2020 04:38:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxezO6BcdUPvMbjBE5oh/tYB+11eN3jiM0vjbyd4dtZrgbzKFrKF8vHHehKzrZH0OhSLC/E X-Received: by 2002:a17:906:fc20:: with SMTP id ov32mr1993109ejb.531.1593171494918; Fri, 26 Jun 2020 04:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593171494; cv=none; d=google.com; s=arc-20160816; b=QK3My37CvpImX1E/aXQ2StfDowbkhgtrFHRfLmjv5YNBJSHQmQd16gC6fou16VdwJY /X+9bEtmoFJTO+kPEagK5SpAT1TBnHyUIRNmK2jhOaJRyE68xJKLRgFGH8yUHExUN6QE Zh3gPGxSyVfenuh/Qzr7eERjNuLCBBU8yJsCMRQ9cdXLJzZKp5BipyA8/2BfnSX1Ij5s J6YIQqH7Sj2ctBrBNWoSMLwF++IunwPtCqHgQ+XBQlisNfSCPEL0Xiy/ytL+QV4YOdt2 8cU9odUv4lZ2qD6p6hkq8chuzwd8wyBZLpYL4LiZ93GCPMJr7H+JGSieQSIOlvGneJxL Y9mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=+BlcZbRYJxbVM8aQXjxUPuL3+oZ8hHcEV/ws9iZaJl4=; b=TNCD1zdSooasCWGuIOSrmFQ6nN+fr2wbvUmnYYpDVAEJU86PvNAauJHf4DRlEZ/IFU YZ1+T8mtD0IrXOK5YR5mcF8Os9lUzW9yg3jRlH4+O/bvzm2T4xPOr70L4MpBdzPJ7/5W gbPTsLLJvzYydkYHRtyEgyvkaSeC8K8F5aE1FQxFkqU5wrO3afJw/HmbNfQa5jO7qo7M Hy0JRFd0JqhqzEGzRjWd/+CmEb/E05GcElp/U0JbHFT++PyISwQ22G4rE5rZeMkSuFom 84yWI2b/BKjMl+KE/Vf/q/NwCJLUbW57bhyiRnMiF+pbg16HM+axJM6jdz740pkwxSw/ eIGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k6si8327577edn.299.2020.06.26.04.37.51; Fri, 26 Jun 2020 04:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbgFZJe6 (ORCPT + 99 others); Fri, 26 Jun 2020 05:34:58 -0400 Received: from 8bytes.org ([81.169.241.247]:50210 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgFZJe6 (ORCPT ); Fri, 26 Jun 2020 05:34:58 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 72182391; Fri, 26 Jun 2020 11:34:57 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: hpa@zytor.com, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Steven Rostedt , joro@8bytes.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Joerg Roedel Subject: [PATCH] x86/mm: Pre-allocate p4d/pud pages for vmalloc area Date: Fri, 26 Jun 2020 11:34:50 +0200 Message-Id: <20200626093450.27741-1-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Pre-allocate the page-table pages for the vmalloc area at the level which needs synchronization on x86. This is P4D for 5-level and PUD for 4-level paging. Doing this at boot makes sure all page-tables in the system have these pages already and do not need to be synchronized at runtime. The runtime synchronizatin takes the pgd_lock and iterates over all page-tables in the system, so it can take quite long and is better avoided. Signed-off-by: Joerg Roedel --- arch/x86/mm/init_64.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index dbae185511cd..475a4008445b 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1238,6 +1238,59 @@ static void __init register_page_bootmem_info(void) #endif } +/* + * Pre-allocates page-table pages for the vmalloc area in the kernel page-table. + * Only the level which needs to be synchronized between all page-tables is + * allocated because the synchronization can be expensive. + */ +static void __init preallocate_vmalloc_pages(void) +{ + unsigned long addr; + const char *lvl; + int count = 0; + + for (addr = VMALLOC_START; addr <= VMALLOC_END; addr = ALIGN(addr + 1, PGDIR_SIZE)) { + pgd_t *pgd = pgd_offset_k(addr); + p4d_t *p4d; + pud_t *pud; + + p4d = p4d_offset(pgd, addr); + if (p4d_none(*p4d)) { + /* Can only happen with 5-level paging */ + p4d = p4d_alloc(&init_mm, pgd, addr); + if (!p4d) { + lvl = "p4d"; + goto failed; + } + count += 1; + } + + if (pgtable_l5_enabled()) + continue; + + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) { + /* Ends up here only with 4-level paging */ + pud = pud_alloc(&init_mm, p4d, addr); + if (!pud) { + lvl = "pud"; + goto failed; + } + count += 1; + } + } + + return; + +failed: + + /* + * A failure here is not fatal - If the pages can be allocated later it + * will be synchronized to other page-tables. + */ + pr_err("Failed to pre-allocate %s pages for vmalloc area\n", lvl); +} + void __init mem_init(void) { pci_iommu_alloc(); @@ -1261,6 +1314,8 @@ void __init mem_init(void) if (get_gate_vma(&init_mm)) kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, PAGE_SIZE, KCORE_USER); + preallocate_vmalloc_pages(); + mem_init_print_info(NULL); } -- 2.27.0