From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 43DFB33A9F3 for ; Fri, 6 Mar 2026 09:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772789351; cv=none; b=i4i+sEjT951yHRlGkSNz4wqzoJAJEPB9e6LBCnmn+UJX30ZY/tQ+Pja+ZQza+CyuiDl26l9N6OQEQluesH9Hb4Zy9O/I/gLz3lP+i0TRQitTG3aXuyQGxryPR+yEmMG5hErE4JkSdFrmDRfyA93LSklk6QJqglCx/8l6aMBBf9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772789351; c=relaxed/simple; bh=Yu2T2FWuh/xaCYSNC4z8YtAjId+UScKSGFTD4oOREwY=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HshWrBJUmkyhf+8EaaLXunA5NfBkp0EU2a8IMTI5HEE9lN1jZysEW2alDO2r9XoLwwAU4omTM7JOvBjOThI1yfsd2tan8+ccdgufCJZjfOdpf+tJr0v39fg7O58MB/j/OhY7k5rzecD41EBEvHI4GGddhRHz0zE0UOk2nFJlE6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.224.150]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4fS1L42yYLzJ46cD; Fri, 6 Mar 2026 17:28:28 +0800 (CST) Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207]) by mail.maildlp.com (Postfix) with ESMTPS id 302324056A; Fri, 6 Mar 2026 17:29:06 +0800 (CST) Received: from localhost (10.203.177.15) by dubpeml500005.china.huawei.com (7.214.145.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 6 Mar 2026 09:29:04 +0000 Date: Fri, 6 Mar 2026 09:29:03 +0000 From: Jonathan Cameron To: Yin Tirui CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH RFC v3 1/4] x86/mm: Use proper page table helpers for huge page generation Message-ID: <20260306092903.0000268f@huawei.com> In-Reply-To: <20260228070906.1418911-2-yintirui@huawei.com> References: <20260228070906.1418911-1-yintirui@huawei.com> <20260228070906.1418911-2-yintirui@huawei.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100012.china.huawei.com (7.191.174.184) To dubpeml500005.china.huawei.com (7.214.145.207) On Sat, 28 Feb 2026 15:09:03 +0800 Yin Tirui wrote: > Historically, several core x86 mm subsystems (vmemmap, vmalloc, and CPA) > have abused `pfn_pte()` to generate PMD and PUD entries by passing > pgprot values containing the _PAGE_PSE flag, and then casting the > resulting pte_t to a pmd_t or pud_t. > > This violates strict type safety and prevents us from enforcing the rule > that `pfn_pte()` should strictly generate pte without huge page attributes. > > Fix these abuses by explicitly using the correct level-specific helpers > (`pfn_pmd()` and `pfn_pud()`) and their corresponding setters > (`set_pmd()`, `set_pud()`). > > For the CPA (Change Page Attribute) code, which uses `pte_t` as a generic > container for page table entries across all levels in > __should_split_large_page(), pack the correctly generated PMD/PUD values > into the pte_t container. > > This cleanup prepares the ground for making `pfn_pte()` strictly filter > out huge page attributes. > > Signed-off-by: Yin Tirui Hi. A tiny drive by review comment below. > --- > arch/x86/mm/init_64.c | 6 +++--- > arch/x86/mm/pat/set_memory.c | 6 +++++- > arch/x86/mm/pgtable.c | 4 ++-- > 3 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c > index df2261fa4f98..d65f3d05c66f 100644 > --- a/arch/x86/mm/init_64.c > +++ b/arch/x86/mm/init_64.c > @@ -1518,11 +1518,11 @@ static int __meminitdata node_start; > void __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node, > unsigned long addr, unsigned long next) > { > - pte_t entry; > + pmd_t entry; > > - entry = pfn_pte(__pa(p) >> PAGE_SHIFT, > + entry = pfn_pmd(__pa(p) >> PAGE_SHIFT, > PAGE_KERNEL_LARGE); Whilst you are here, can we make that a one liner. entry = pfn_pmd(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL_LARGE); Could even do pmd_t entry = pfn_pmd(__pa(p) >> PAGE_SHIFT, PAGE_KERNEL_LARGE); but that's more of a question of taste. > - set_pmd(pmd, __pmd(pte_val(entry))); > + set_pmd(pmd, entry); > > /* check to see if we have contiguous blocks */