From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65640F5581D for ; Mon, 20 Apr 2026 11:43:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB0A46B0005; Mon, 20 Apr 2026 07:43:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A615E6B00A8; Mon, 20 Apr 2026 07:43:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 976F66B00A9; Mon, 20 Apr 2026 07:43:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 864EE6B0005 for ; Mon, 20 Apr 2026 07:43:41 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 157DD140A27 for ; Mon, 20 Apr 2026 11:43:41 +0000 (UTC) X-FDA: 84678749442.01.337D786 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) by imf30.hostedemail.com (Postfix) with ESMTP id 7C48080004 for ; Mon, 20 Apr 2026 11:43:37 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=huawei.com header.s=dkim header.b=r8etD1aG; spf=pass (imf30.hostedemail.com: domain of yintirui@huawei.com designates 113.46.200.222 as permitted sender) smtp.mailfrom=yintirui@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1776685419; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A9DayyiGCs7J5S4uoemxf+H1vRd9DRT+SAr6sjgTgzo=; b=DUR108+rgEzwKIx9S0uXG83/Kv3nDGkJY39Ax1J0Sc6njwtXp//r/IwxLwbQ9DUmAxuInT zrMwsDYrgoKLI4AnFGhRbq6AkD1TRp2v3Q4GfEz8DFqS4BKdwcxITlFYSeDVszlFbHnpnR KNINaWuTDRPrfOltkWlG01UoMRcDiCM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=huawei.com header.s=dkim header.b=r8etD1aG; spf=pass (imf30.hostedemail.com: domain of yintirui@huawei.com designates 113.46.200.222 as permitted sender) smtp.mailfrom=yintirui@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1776685419; a=rsa-sha256; cv=none; b=T2awW9NnEqyoSFVzMdepKzyAq8HnySHUL25Xm3169O5KJAYbydvhVY70cjLztTHufBOIj/ sBqJn34+Q3O6wQhmeuklMyjG9RL8EJ3ZkubOTUhRzFvUJEc4cRoD3oipfA/doXR4WbCW7w ProWQnDkteoB3CPT8Wk46zUxGgAeBlc= dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=A9DayyiGCs7J5S4uoemxf+H1vRd9DRT+SAr6sjgTgzo=; b=r8etD1aG+Mc7JjIr4DZoc+k7bzpFfJnAXZ85nO514eN8BXYo5noW3gM83UgYjqWHyDRfs7ebD 0kEmWu+ahgPRPlCGy/at6tBU6Mc6RyE2mSAVExXGFPe5vWknmlZGE4h63mAgE0fR/tsMLaialxw 6r+vbgF/46AoS+hYJ+H4nCM= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4fzk3p6tkxzLlYX; Mon, 20 Apr 2026 19:37:10 +0800 (CST) Received: from kwepemr500001.china.huawei.com (unknown [7.202.194.229]) by mail.maildlp.com (Postfix) with ESMTPS id A1F0D40573; Mon, 20 Apr 2026 19:43:31 +0800 (CST) Received: from [10.174.179.248] (10.174.179.248) by kwepemr500001.china.huawei.com (7.202.194.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 20 Apr 2026 19:43:29 +0800 Message-ID: Date: Mon, 20 Apr 2026 19:43:20 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v3 2/4] mm/pgtable: Make pfn_pte() filter out huge page attributes To: Will Deacon CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260228070906.1418911-1-yintirui@huawei.com> <20260228070906.1418911-3-yintirui@huawei.com> From: Yin Tirui In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.248] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemr500001.china.huawei.com (7.202.194.229) X-Stat-Signature: t7xw9ujzedru45tdhiwwoo51ruidcrh7 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7C48080004 X-HE-Tag: 1776685417-185366 X-HE-Meta: U2FsdGVkX18hNHOuXgAZwwFpTWMA+HHrFScCY4WI90NNFpRoN2p463tYwQGWiDNO0T9HogUsswBqONssxqC062Wc7aYi4wBUXk6c8fLdUAvSVPmL+1sYyXsIM2ydOj0b9OmSXEQ+z/X9zPj8F7ryjNUEuj6/J+nHAKjdxnGKNPOk0xPBuG8T9dU5argg12/6t0KUc1TuRSxGoCHNKNYgAmYZ7DBNA0vGpif2TfyeOVnIlwasJYVJmHNNTd8WfqfPuPRgZWVCf2HFyko/0UKoOrc6FQ7cZRHKRBYfKVbtqekslM6S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O7x9wufV2L7p+apj1enH4My/6iK2rCxVNVCQ== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Will, On 4/20/2026 4:48 PM, Will Deacon wrote: > On Sat, Feb 28, 2026 at 03:09:04PM +0800, Yin Tirui wrote: >> A fundamental principle of page table type safety is that `pte_t` represents >> the lowest level page table entry and should never carry huge page attributes. >> >> Currently, passing a pgprot with huge page bits (e.g., extracted via >> pmd_pgprot()) into pfn_pte() creates a malformed PTE that retains the huge >> attribute, leading to the necessity of the ugly `pte_clrhuge()` anti-pattern. >> >> Enforce type safety by making `pfn_pte()` inherently filter out huge page >> attributes: >> - On x86: Strip the `_PAGE_PSE` bit. >> - On ARM64: Mask out the block descriptor bits in `PTE_TYPE_MASK` and >> enforce the `PTE_TYPE_PAGE` format. >> - On RISC-V: No changes required, as RISC-V leaf PMDs and PTEs share the >> exact same hardware format and do not use a distinct huge bit. >> >> Signed-off-by: Yin Tirui >> --- >> arch/arm64/include/asm/pgtable.h | 4 +++- >> arch/x86/include/asm/pgtable.h | 4 ++++ >> 2 files changed, 7 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h >> index b3e58735c49b..f2a7a40106d2 100644 >> --- a/arch/arm64/include/asm/pgtable.h >> +++ b/arch/arm64/include/asm/pgtable.h >> @@ -141,7 +141,9 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t phys) >> >> #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT) >> #define pfn_pte(pfn,prot) \ >> - __pte(__phys_to_pte_val((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot)) >> + __pte(__phys_to_pte_val((phys_addr_t)(pfn) << PAGE_SHIFT) | \ >> + ((pgprot_val(prot) & ~(PTE_TYPE_MASK & ~PTE_VALID)) | \ >> + (PTE_TYPE_PAGE & ~PTE_VALID))) > Why are you touching arch/arm64? We don't implement pte_clrhuge() afaict. > What does this actually fix? Originally, this patch aimed to ensure that pfn_pte() always returns a PTE without any huge page attributes by embedding the logic of pte_clrhuge() directly into pfn_pte(). However, we found this approach doesn't work well on x86, so we've abandoned this design. Following Matthew Wilcox's suggestion, the current approach is instead to have pmd_pgprot() return a 4K–formatted pgprot_t (i.e., without huge pageĀ attributes), and then explicitly add the huge page attributes when constructing a PMD via pfn_pmd(). I've already implemented this in my recent commit: https://github.com/torvalds/linux/commit/5b8ce6d33822dd7776432e03a08fe6d2dedac079 > > Will -- Yin Tirui