From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796162371; b=a4A1Hr5n9uWvYvDqM6xQxv0r7uTYYNEWH79n/c773D6TCZuDMLOOR5sIp6Lv8VuhO9+h HdNXyI6SUtFBXX2VYWtcmi+wJh78zI4qTeVxw6TPF8f/04nHLaJEJ3znUGmukEn74r4yO 2bH7Ly6fDJIEp8DvSb7asJ/PZg0dH+lB0L+w0jtWecnS6oj1oT0ahkyBnYOrXww/aU3SM mgraCTpAWVT8zcAXr+0nLgbIDxlw5Dty+UvUWq5INu8fD0y1QeMKM97nWWh961LstOUxr WAEA3TD7Gn9sqg7Q5xZF4VV0m7eiHoKvmRDQQt2SnXcH/nmJaw/qsUs3z+2cGf3zkFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796162371; h=DMARC-Filter:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=panrMafn8Cdg8SFonq9CP0iEUKfmuidHV3kDI73UxNU=; b=fJPy+zqJGMLYkmhphTapLp0pgBgbRzEw+rxSzVoUR7bOUutcpHgkgsNWJxzPBzhP2H4k iG+PMG6kH5klylPTJvAnTeR0B1efk+FrWRpvIIVAB31vxzR1x+ivTU1Z/7Xr46zj8qaRR XMNoMk5r56X57jJUWURcS9twsQKU47csAyNvm2Ec/Mg0LIBlMfSdW/MEY/0XYknupc2Wg vb1emjBPiEkCdgM3u5GdS1PsHa0FUIEs0nGpmNryTBZHjOTJE21Z6hNf3dohAAd5JYQm3 h+o7K55vPG12aImjSdLz3TdhSJU89rTxsUQqGEqcuRQAMYFmFolGLTK/Ni8YvNqdmDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b="Apy98OV/"; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4764D606A320 for ; Tue, 1 Dec 2026 21:59:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4764D606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=Apy98OV/ Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FF6A152B; Tue, 1 Dec 2026 13:59:20 -0800 (PST) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 727C23F632; Tue, 1 Dec 2026 13:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796162363; bh=fyoT/5IBRGQI5VKcqvjQ83Snu+IC6epu+eSswu8SPSI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Apy98OV/awz34IEqqtTvRnavbEKAb8UCSDvx1JUcZvAnGF8Zkhq6RNchtD6IrOnvF isBkwVpwf5wSHjHtSrmvNSJa8IiyRIc/Ncq5K2ZQ9E0mzQiaUQqOz+n66FdJTiwn6C oaCQ9HHUCKs4//Y6IxXs+X9K7F49o6DjxgbCi+lU= Date: Tue, 1 Dec 2026 21:59:13 +0000 From: Yeoreum Yun To: "David Hildenbrand (Arm)" Cc: sashiko-reviews@lists.linux.dev, Yeoreum Yun , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-mm@kvack.org, kvm@vger.kernel.org, Sohil Mehta Subject: Re: [PATCH v4 12/20] x86/mm: Introduce helper for checking direct map 1G page support Message-ID: References: <20261201-dummy_ptxp3-v4-0-9dec1da6a49a@arm.com> <20261201-dummy_ptxp3-v4-12-9dec1da6a49a@arm.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Dec 01, 2026 at 06:52:08PM +0100, David Hildenbrand (Arm) wrote: > On 12/1/26 18:49, sashiko-bot@kernel.org wrote: > > Thank you for your contribution! Sashiko AI review found 1 potential > > issue to consider: > > - [High] x86/mm: broken >1G fallback in populate_pud() with > > direct_gbpages_enabled() > > -- > > > > commit e848aa5278a55a110f7b37832d4d11e02e068633 > > Author: Dave Hansen > > > > x86/mm: Introduce helper for checking direct map 1G page support > > > > This commit introduces direct_gbpages_enabled() to check > > CONFIG_X86_DIRECT_GBPAGES, X86_FEATURE_GBPAGES, and direct_gbpages, and > > replaces existing direct_gbpages and feature checks with the new helper. > > > > Link: [1] https://lore.kernel.org/all/0019d675-ce3d-4a5c-89ed-f126c45145c9@kernel.org/ > > Link: [2] https://lore.kernel.org/all/20260902-dummy_ptxp3-v3-15-5d8f5b17c25c@arm.com/ > > > >> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c > >> index b1d5c5a0ffb41..f27811e6e00bd 100644 > >> --- a/arch/x86/mm/pat/set_memory.c > >> +++ b/arch/x86/mm/pat/set_memory.c > > > > [ ... ] > > > >> @@ -1737,7 +1737,7 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, p4d_t *p4d, > >> /* > >> * Map everything starting from the Gb boundary, possibly with 1G pages > >> */ > >> - while (boot_cpu_has(X86_FEATURE_GBPAGES) && end - start >= PUD_SIZE) { > >> + while (direct_gbpages_enabled() && end - start >= PUD_SIZE) { > >> set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn, > >> canon_pgprot(pud_pgprot)))); > >> > > > > [Severity: High] > > Can this corrupt page tables in populate_pud() when direct_gbpages is 0 > > (for example with nogbpages or debug_pagealloc=on) and a mapping spans > > more than PUD_SIZE past a 1G boundary, such as when > > kernel_map_pages_in_pgd() populates efi_mm.pgd? > > > > When direct_gbpages_enabled() returns false, the 1G loop is skipped while > > end - start >= PUD_SIZE. The trailing leftover block then resolves only a > > single pud_t entry and passes the entire remaining range to > > populate_pmd(): > > > > arch/x86/mm/pat/set_memory.c:populate_pud() { > > ... > > /* Map trailing leftover */ > > if (start < end) { > > long tmp; > > > > pud = pud_offset(p4d, start); > > if (pud_none(*pud)) > > if (alloc_pmd_page(pud)) > > return -1; > > > > tmp = populate_pmd(cpa, start, end, cpa->numpages - cur_pages, > > pud, pgprot); > > ... > > } > > > > Because populate_pmd() never advances pud across PUD_SIZE boundaries, > > pmd_offset(pud, start) wraps pmd_index(start) modulo PTRS_PER_PMD within > > the first PUD's PMD page, overwriting earlier PMD entries and leaving > > subsequent PUD entries unmapped. If the wrapped range also has a sub-2M > > tail, pmd_none(*pmd) sees the 2M leaf PMD installed earlier in that same > > PMD table and populate_pte() writes 4K PTEs directly into the mapped > > physical data page. > > > > @Dave is that safe our do we need some changes? With direct_gbpages_enabled(), specifying nogbpages can seem to expose an issue in populate_pud(). However, this appears to be a pre-existing issue dating back to commit d367cef0a7f0 ("x86/mm/pat: Fix boot crash when 1GB pages are not supported by the CPU"). it seem to be able to occur on CPUs without X86_FEATURE_GBPAGES. Might below fix above issue? @@ -1750,14 +1750,19 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, p4d_t *p4d, /* Map trailing leftover */ if (start < end) { long tmp; + unsigned long tail_end; + unsigned long nr_pages; pud = pud_offset(p4d, start); if (pud_none(*pud)) if (alloc_pmd_page(pud)) return -1; - tmp = populate_pmd(cpa, start, end, cpa->numpages - cur_pages, - pud, pgprot); + tail_end = min_t(unsigned long, end, start + PUD_SIZE); + nr_pages = min_t(unsigned long, PUD_SIZE >> PAGE_SHIFT, + cpa->numpages - cur_pages); + + tmp = populate_pmd(cpa, start, tail_end, nr_pages, pud, pgprot); if (tmp < 0) return cur_pages; @Dave, am i missing something? -- Sincerely, Yeoreum Yun