From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (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 B5F7136C9ED for ; Tue, 10 Mar 2026 03:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773113554; cv=none; b=Ykii7eVdLfSHVFv7GxOJZnyVWcTMeOo/GdvvTX1YezDRP6WnErsNwjFmtsvk96rBkk7mVfH8UnlWJWn7+/GQrbHBtT+IO0IE/bKfC6baoJKhAEp5XUf7ZVOF6QfaugaP0Hyk9N309zQnI9eRkNcrFx9/AduZ570mfo9NqFykGcU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773113554; c=relaxed/simple; bh=XzotwdX4xpA8e5Z21RHFKXx8117FHpdLVsDypyUT7jI=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=CoE0AHUyxckjUFxtztRj4olKZkQU1LrFjvSRN980VNf1VvfVduJ6X3OHi8hqgWqboDrE1FsM/D1Vu3fNlUZwSxNyW7Xb51avGSFogWUUEDBbtDyFk8zUaQWa50WJp+6kORrIC9TDzhOjbMYJ2odQJ8K0PhhxNVQwE/JrAzTI+sQ= 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; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=25WpgtJU; arc=none smtp.client-ip=113.46.200.217 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="25WpgtJU" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=ukfr+AuSSjalhcEuGd775EwrTPxyhTtDQGkfF9cnnoI=; b=25WpgtJUdMU4EPFULH4K6br31HYc+68SzizJgcjOO0/WwTWrFm0I23gaAhtwXnemVVXog/D/6 BKz/296PrNYryXCSs7MiOe69iLEyRVgoaq5Khg5lETGv3V86EtVXKGw/JnmgCWQ0KZKoJSPlifM iFUEDnQb9cUjb9lEiLhCOWk= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4fVK7D71ZgzcbS0; Tue, 10 Mar 2026 11:27:04 +0800 (CST) Received: from kwepemr500001.china.huawei.com (unknown [7.202.194.229]) by mail.maildlp.com (Postfix) with ESMTPS id 0A90840569; Tue, 10 Mar 2026 11:32:29 +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; Tue, 10 Mar 2026 11:32:26 +0800 Message-ID: <875a5d1b-4bed-4f70-a122-acd625265bfa@huawei.com> Date: Tue, 10 Mar 2026 11:32:26 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= , Matthew Wilcox CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Kefeng Wang , References: <20260228070906.1418911-1-yintirui@huawei.com> <20260228070906.1418911-3-yintirui@huawei.com> <5eaf3846-01db-471e-9903-b0b239d7838d@suse.com> <4d7c396a-6a48-4e56-b8d1-3ac7bd5d10fb@suse.com> From: Yin Tirui In-Reply-To: <4d7c396a-6a48-4e56-b8d1-3ac7bd5d10fb@suse.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemr500001.china.huawei.com (7.202.194.229) On 3/5/2026 6:05 PM, Jürgen Groß wrote: >> Hi Willy and Jürgen, >> >> Following up on the x86 _PAGE_PSE and _PAGE_PAT aliasing issue. >> >> To achieve the goal of keeping pfn_pte() pure and completely >> eradicating the pte_clrhuge() anti-pattern, we need a way to ensure >> pfn_pte() never receives a pgprot with the huge bit set. >> >> @Jürgen: >> Just to be absolutely certain: is there any safe way to filter out the >> huge page attributes directly inside x86's pfn_pte() without breaking >> PAT? Or does the hardware bit-aliasing make this strictly impossible >> at the pfn_pte() level? > > There is no huge bit at the PTE level. It is existing only at the PMD > and the > PUD level. > > So: yes, it is absolutely impossible to filter it out, as the bit has a > different meaning in "real" PTEs (with "PTE" having the meaning: a > translation > entry in a page referenced by a PMD entry not having the PSE bit set). > Hi Jürgen, Thank you for your confirmation. >> >> @Willy @Jürgen: >> Assuming it is impossible to filter this safely inside pfn_pte() on >> x86, we must translate the pgprot before passing it down. To maintain >> strict type-safety and still drop pte_clrhuge(), I plan to introduce >> two arch-neutral wrappers: >> >> x86: >> /* Translates large prot to 4K. Shifts PAT back to bit 7, inherently >> clearing _PAGE_PSE */ >> #define pgprot_huge_to_pte(prot)    pgprot_large_2_4k(prot) >> /* Translates 4K prot to large. Shifts PAT to bit 12, strictly sets >> _PAGE_PSE */ >> #define pgprot_pte_to_huge(prot) >> __pgprot(pgprot_val(pgprot_4k_2_large(prot)) | _PAGE_PSE) > > Seems to be okay. While the wrapper approach handles the aliasing, Willy recently suggested taking it a step further by embedding this translation directly into `pfn_pmd()` and `pmd_pgprot()`. I am going to explore this embedded approach for the v4 respin. -- Yin Tirui