From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8628148310 for ; Thu, 23 Jan 2025 17:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737653079; cv=none; b=jSyVea1AszY5yFyXti0bXlACUm0Ohxjnd0ge1otYxQoisJ2cohcW63XV/ppzEqgd1UOE8aHbyWqT/zOkQm0b+lBnYH+iYqJfbcCNyXx9SwqxJBOjUnJP528GNlhXboS+LRa8w3z8p0IVvNMDCP1w4AnYyjfCpy+Nb2INDhbxHkU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737653079; c=relaxed/simple; bh=kZXx1u3viNpW/En53aZ/AVSCpslGCcGcOeFSoS9e3Cw=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=uDO4pXNtLx/OHTnw3itxUhWna8XoDIRltea9NsDOHs/RkzVhjZ8hvOYZoEmqwjK+X+hKOWS/qTDNQRdw3mB5aittK+aiW3L1u05GilYwFD4YwuN4JhDdVjS2jN9PoI1jl7qQe5PBMoB3px1890PF3WkpTEbynxLUjfgZLh5V2xQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WRG0GWC0; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WRG0GWC0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737653078; x=1769189078; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=kZXx1u3viNpW/En53aZ/AVSCpslGCcGcOeFSoS9e3Cw=; b=WRG0GWC0F+ZFjbHNHHL3V1WjwsbR0kqt4x50Y0K0l2IUIuzoJtwjXxLb Wbzojw2ZauFBgyhPet/7bj733/ifqyoNTd3Mpbaugm/by2dDylflReloO us53ND6kDK/DkD5F8RRmpJ2dVdIGATYIDdJYWv2bOCJL72Zpo3a1xJjDp iKOUQksRad8d5By756wy2J0jijzEhq4uuRdC5FBxRog9artXs3x2a1tBW Z0W2jBCgchLK7Ps+gOybjloa6CWUhWli+dDDQe6o4QmrvbNknuntwAE09 2CVhBp0BGAfcxnSkwxDKEeBgjRpmrIst6Qxa+PENFG8vsrVrbgA4I17EA Q==; X-CSE-ConnectionGUID: /azlrGIsTKGgkyDN5WsxrA== X-CSE-MsgGUID: 1anKgirXTiOnSzu80MOzIg== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="49583825" X-IronPort-AV: E=Sophos;i="6.12,310,1728975600"; d="scan'208";a="49583825" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2025 09:24:31 -0800 X-CSE-ConnectionGUID: b7gQFEg9Qzuhz8VLIqQqhg== X-CSE-MsgGUID: rxC8PphkRauHzw8Lw5KIgg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,229,1732608000"; d="scan'208";a="107649956" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa008.fm.intel.com with ESMTP; 23 Jan 2025 09:24:30 -0800 Subject: [RFC][PATCH 1/8] x86/mm: Always allocate a whole page for PAE PGDs To: linux-kernel@vger.kernel.org Cc: x86@kernel.org,tglx@linutronix.de,bp@alien8.de,joro@8bytes.org,luto@kernel.org,peterz@infradead.org,kirill.shutemov@linux.intel.com,rick.p.edgecombe@intel.com,jgross@suse.com,Dave Hansen From: Dave Hansen Date: Thu, 23 Jan 2025 09:24:30 -0800 References: <20250123172428.D6D8C8D9@davehans-spike.ostc.intel.com> In-Reply-To: <20250123172428.D6D8C8D9@davehans-spike.ostc.intel.com> Message-Id: <20250123172430.E948520B@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen A hardware PAE PGD is only 32 bytes. A PGD is PAGE_SIZE in the other paging modes. But for reasons*, the kernel _sometimes_ allocates a whole page even though it only ever uses 32 bytes. Make PAE less weird. Just allocate a page like the other paging modes. This was already being done for PTI (and Xen in the past) and nobody screamed that loudly about it so it can't be that bad. * The original reason for PAGE_SIZE allocations for the PAE PGDs was Xen's need to detect page table writes. But 32-bit PTI forced it too for reasons I'm unclear about. Signed-off-by: Dave Hansen --- b/arch/x86/mm/pgtable.c | 63 +++--------------------------------------------- 1 file changed, 4 insertions(+), 59 deletions(-) diff -puN arch/x86/mm/pgtable.c~no-pae-kmem_cache arch/x86/mm/pgtable.c --- a/arch/x86/mm/pgtable.c~no-pae-kmem_cache 2025-01-23 09:20:50.202330636 -0800 +++ b/arch/x86/mm/pgtable.c 2025-01-23 09:20:50.206330781 -0800 @@ -357,69 +357,15 @@ static void pgd_prepopulate_user_pmd(str { } #endif -/* - * Xen paravirt assumes pgd table should be in one page. 64 bit kernel also - * assumes that pgd should be in one page. - * - * But kernel with PAE paging that is not running as a Xen domain - * only needs to allocate 32 bytes for pgd instead of one page. - */ -#ifdef CONFIG_X86_PAE - -#include - -#define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t)) -#define PGD_ALIGN 32 - -static struct kmem_cache *pgd_cache; - -void __init pgtable_cache_init(void) -{ - /* - * When PAE kernel is running as a Xen domain, it does not use - * shared kernel pmd. And this requires a whole page for pgd. - */ - if (!SHARED_KERNEL_PMD) - return; - - /* - * when PAE kernel is not running as a Xen domain, it uses - * shared kernel pmd. Shared kernel pmd does not require a whole - * page for pgd. We are able to just allocate a 32-byte for pgd. - * During boot time, we create a 32-byte slab for pgd table allocation. - */ - pgd_cache = kmem_cache_create("pgd_cache", PGD_SIZE, PGD_ALIGN, - SLAB_PANIC, NULL); -} static inline pgd_t *_pgd_alloc(void) { /* - * If no SHARED_KERNEL_PMD, PAE kernel is running as a Xen domain. - * We allocate one page for pgd. + * PTI and Xen need a whole page for the PAE PGD + * even though the hardware only needs 32 bytes. + * + * For simplicity, allocate a page for all users. */ - if (!SHARED_KERNEL_PMD) - return (pgd_t *)__get_free_pages(GFP_PGTABLE_USER, - PGD_ALLOCATION_ORDER); - - /* - * Now PAE kernel is not running as a Xen domain. We can allocate - * a 32-byte slab for pgd to save memory space. - */ - return kmem_cache_alloc(pgd_cache, GFP_PGTABLE_USER); -} - -static inline void _pgd_free(pgd_t *pgd) -{ - if (!SHARED_KERNEL_PMD) - free_pages((unsigned long)pgd, PGD_ALLOCATION_ORDER); - else - kmem_cache_free(pgd_cache, pgd); -} -#else - -static inline pgd_t *_pgd_alloc(void) -{ return (pgd_t *)__get_free_pages(GFP_PGTABLE_USER, PGD_ALLOCATION_ORDER); } @@ -428,7 +374,6 @@ static inline void _pgd_free(pgd_t *pgd) { free_pages((unsigned long)pgd, PGD_ALLOCATION_ORDER); } -#endif /* CONFIG_X86_PAE */ pgd_t *pgd_alloc(struct mm_struct *mm) { _