Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp588315ybh; Tue, 21 Jul 2020 03:02:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy65LO4uIPAEOMMrLYBEzrA3HkjTTNCEAONY3Yq0CzWonWFlvUiueKEZBwDHx+4NMRBzgN X-Received: by 2002:a17:906:4757:: with SMTP id j23mr23265560ejs.431.1595325754493; Tue, 21 Jul 2020 03:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595325754; cv=none; d=google.com; s=arc-20160816; b=JiFyeCp5Y+/+mI7gw1Ai+UYKuFAoVaRqOuTs8Rrqm/JgXZypoDUWMlFobgfgizYLKD /Ofehxi1xlXg2KaLGvA7DL1/ARdOLr3+RybgahgXouOnfgoGhHK98uYY+9UK6BcAn/WU ccUnU4r5iKHQRI/IGCfyzyN5KnmrMkZGV44Sn0HiApjV+7bMZgGxXEcqShYyDFNup4/7 UM2/lASyr+CZGrPtM2bl4pBScs/hVR+YCvSrsU5dWY7n4tQRbUGoV3ofdRQcIdZDbIpM fGh8ekPddjXDbuO0GRgIEApLjvGU0omHJgaaJfcimP4sMg8iFoggtzqlOBK+LweNEIIB v9TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yP1uJoI21Rbfzo70kXdWKMcf4bAqWsAr/5WFUnp4Wps=; b=tyT7evW1h4WnYbM30fzJCYo+Q/bvNip7p3sjbykZsQ7gxF1I5bKX5pwiP+1gWIkhEv rQJynSdALBv0EZT1pO+pK3oCI8eV4w0xb6ZNDrCpr0xvQAZcDFvqTnAX0F5WPtNuCrM4 bhEkBCscxnijlivXImoSyk5TUswAaOsbIrpZBg5VUlfucwxo+TRzuedc4HVqLoRFBEje b/8/U5ulw/ONT8mZPVEifT7+Nox7dxkhoa10h7CaLiEtxiMwydAsfpM8IrclW871KTLb 3R3wW7cLRU8wpR/kPOTHCWZvYS1EoyHqVbX2O9/DLtoViYtuQQoLfSx662MHoiRPVhxl fH0A== 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 z20si12612566ejb.342.2020.07.21.03.02.11; Tue, 21 Jul 2020 03:02:34 -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 S1729119AbgGUKAI (ORCPT + 99 others); Tue, 21 Jul 2020 06:00:08 -0400 Received: from 8bytes.org ([81.169.241.247]:58336 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgGUKAI (ORCPT ); Tue, 21 Jul 2020 06:00:08 -0400 Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id CEA732C8; Tue, 21 Jul 2020 12:00:06 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: hpa@zytor.com, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Mike Rapoport , Joerg Roedel , joro@8bytes.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] x86/mm: Pre-allocate p4d/pud pages for vmalloc area Date: Tue, 21 Jul 2020 11:59:51 +0200 Message-Id: <20200721095953.6218-2-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200721095953.6218-1-joro@8bytes.org> References: <20200721095953.6218-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-64, which is P4D for 5-level and PUD for 4-level paging. Doing this at boot makes sure all no synchronization of that area is necessary at runtime. The synchronization 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 | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index dbae185511cd..e76bdb001460 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1238,6 +1238,56 @@ 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; + + 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; + } + } + + 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; + } + } + } + + return; + +failed: + + /* + * The pages have to be there now or they will be missing in + * process page-tables later. + */ + panic("Failed to pre-allocate %s pages for vmalloc area\n", lvl); +} + void __init mem_init(void) { pci_iommu_alloc(); @@ -1261,6 +1311,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