From nobody Sun May 19 10:14:40 2024 Received: from mx0a-00823401.pphosted.com (mx0a-00823401.pphosted.com [148.163.148.104]) (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 D249F208A9; Tue, 23 Apr 2024 17:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.148.104 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713892824; cv=none; b=sOFZKsjIAzdJbXFI0fZ+2Abeei1pmgi8INo9uKJLPlu5TXSeajRO4FTLb0JwakSj8rrFtbguhItsSrRo6NskonZLDCi8hys5iKNSVDHmecNxHs6pJgvQI2iIeNo7FSUCmOPdYdaSlCUgEyRbAjmbXvRLh2QIbqic1NREimvhqmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713892824; c=relaxed/simple; bh=bhaoMdqp2VU4qCFjkuQfL4m9NZniKQUzcmP/BVHU0Hw=; h=Message-Id:To:Cc:From:Date:Subject; b=EX4FLA0Wcio9SGxrpQm0knWmYJT8iyGaOkCLa/cSZJXSXcJpXqtNrma4gist8pA+YUp5zh/EL0rhvwKSwDZScSDjK8gW+mgNR18pfQMscbK+5p+lDr2r9OguB7vFwrvmgIpSRkmsz+HTt28ruzam6pLzuUZwuStP2aH2O7PnRfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=motorola.com; spf=pass smtp.mailfrom=motorola.com; dkim=fail (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b=n0FYux0a reason="signature verification failed"; arc=none smtp.client-ip=148.163.148.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=motorola.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=motorola.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b="n0FYux0a" Received: from pps.filterd (m0355088.ppops.net [127.0.0.1]) by m0355088.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 43NFvVqF023694; Tue, 23 Apr 2024 17:19:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=motorola.com; h= message-id:to:cc:from:date:subject; s=DKIM202306; bh=zeEoU7dkwCo IiIBp8pJxTA1FJWukJR0hjPW2h/Mabqc=; b=n0FYux0aPq9+q7qBtfOYgWv3cRc mOiBKGypFk6wxiYV5RgUdw0t6t6pNdsYE7k3WFBmF1pKmAaBaBaiJ6EvR6vq96/w 7g4B4vHAELTAdxh4cN67AmZ89bd0evkU4cHbeS2e28J8Wv3LJnSD9WS0ivF9l92d cUVqEr6xa1pKg1SJ14+XONZ/Q4wEe7ye5h96sZkDvVLuFLVLKO1n3UgcjvAGBooP ppcFQrdh2BCdg9jdTqTXBjEJDuCVSPzWtO6MI1IlGvh/kzYNb7Oxy4OZLY4AVi/V n74jJZ4R5/xCK2VCUq/yBhnn1e3pWdlJCqn1ful0dW+SXAdGALVXHJw6saw== Received: from ilclpfpp01.lenovo.com ([144.188.128.67]) by m0355088.ppops.net (PPS) with ESMTPS id 3xnvc2jksv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Apr 2024 17:19:50 +0000 (GMT) Received: from ilclmmrp01.lenovo.com (ilclmmrp01.mot.com [100.65.83.165]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ilclpfpp01.lenovo.com (Postfix) with ESMTPS id 4VP84j6djSzcxpp; Tue, 23 Apr 2024 17:19:49 +0000 (UTC) Received: from ilclasset02.mot.com (ilclasset02.mot.com [100.64.49.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mbland) by ilclmmrp01.lenovo.com (Postfix) with ESMTPSA id 4VP84j6MPSz3n3fr; Tue, 23 Apr 2024 17:19:49 +0000 (UTC) Message-Id: <20240423121820.874441838-1-mbland@motorola.com> To: linux-mm@kvack.org Cc: "Maxwell Bland Catalin Marinas" , Will Deacon , Jonathan Corbet , Andrew Morton , Ard Biesheuvel , Mark Rutland , Christophe Leroy , Maxwell Bland , Alexandre Ghiti , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org From: Maxwell Bland Date: Tue, 23 Apr 2024 12:18:20 -0500 Subject: [PATCH] ptdump: add non-leaf descriptor support X-Proofpoint-GUID: 5dMlSk_-_7UdZApIcbzoFqYjyX64TIwW X-Proofpoint-ORIG-GUID: 5dMlSk_-_7UdZApIcbzoFqYjyX64TIwW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-23_14,2024-04-23_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1011 suspectscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404230039 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add an optional note_non_leaf parameter to ptdump, causing note_page to be called on non-leaf descriptors. Implement this functionality on arm64 by printing table descriptors along with table-specific permission sets. For arm64, break (1) the uniform number of columns for each descriptor, and (2) the coalescing of large PTE regions, which are now split up by PMD. This is a "good" thing since it makes the behavior and protection bits set on page tables, such as PXNTable, more explicit. Examples (spaces condensed and partially truncated) Before: 0xffff008440210000-0xffff008440400000 1984K PTE ro NX SHD AF NG UXN M... 0xffff008440400000-0xffff008441c00000 24M PMD ro NX SHD AF NG BLK UXN M... 0xffff008441c00000-0xffff008441dc0000 1792K PTE ro NX SHD AF NG UXN M... 0xffff008441dc0000-0xffff00844317b000 20204K PTE RW NX SHD AF NG UXN M... After: 0xffff0fb640200000-0xffff0fb640400000 2M PMD TBL RW x NXTbl UXNTbl M... 0xffff0fb640200000-0xffff0fb640210000 64K PTE RW NX SHD AF NG UXN M... 0xffff0fb640210000-0xffff0fb640400000 1984K PTE ro NX SHD AF NG UXN M... 0xffff0fb640400000-0xffff0fb641c00000 24M PMD BLK ro SHD AF NG NX UXN ... 0xffff0fb641c00000-0xffff0fb641e00000 2M PMD TBL RW x NXTbl UXNTbl M... 0xffff0fb641c00000-0xffff0fb641dc0000 1792K PTE ro NX SHD AF NG UXN M... 0xffff0fb641dc0000-0xffff0fb641e00000 256K PTE RW NX SHD AF NG UXN ME... Full dumps available at github.com/maxwell-bland/linux-patch-data/tree/main/ptdump-non-leaf Signed-off-by: Maxwell Bland --- Hi, Thank you for taking the time to review this patch. I made these changes in order to compliment testing 20240220203256.31153-1-mbland@motorola.com and 20240423095843.446565600-1-mbland@motorola.com and figured they might be useful to others. BRs, Maxwell Bland Documentation/arch/arm64/ptdump.rst | 181 ++++++++++++---------- arch/arm64/mm/ptdump.c | 226 +++++++++++++++++++++++++--- include/linux/ptdump.h | 1 + mm/ptdump.c | 13 ++ 4 files changed, 325 insertions(+), 96 deletions(-) diff --git a/Documentation/arch/arm64/ptdump.rst b/Documentation/arch/arm64= /ptdump.rst index 5dcfc5d7cddf..0f38b92fd839 100644 --- a/Documentation/arch/arm64/ptdump.rst +++ b/Documentation/arch/arm64/ptdump.rst @@ -2,25 +2,24 @@ Kernel page table dump =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -ptdump is a debugfs interface that provides a detailed dump of the -kernel page tables. It offers a comprehensive overview of the kernel -virtual memory layout as well as the attributes associated with the -various regions in a human-readable format. It is useful to dump the -kernel page tables to verify permissions and memory types. Examining the -page table entries and permissions helps identify potential security -vulnerabilities such as mappings with overly permissive access rights or -improper memory protections. +ptdump is a debugfs interface that provides a detailed dump of the kernel = page +tables. It offers a comprehensive overview of the kernel virtual memory la= yout +as well as the attributes associated with the various regions in a +human-readable format. It is useful to dump the kernel page tables to veri= fy +permissions and memory types. Examining the page table entries and permiss= ions +helps identify potential security vulnerabilities such as mappings with ov= erly +permissive access rights or improper memory protections. =20 -Memory hotplug allows dynamic expansion or contraction of available -memory without requiring a system reboot. To maintain the consistency -and integrity of the memory management data structures, arm64 makes use -of the mem_hotplug_lock semaphore in write mode. Additionally, in -read mode, mem_hotplug_lock supports an efficient implementation of -get_online_mems() and put_online_mems(). These protect the -offlining of memory being accessed by the ptdump code. +Memory hotplug allows dynamic expansion or contraction of available memory +without requiring a system reboot. To maintain the consistency and integri= ty of +the memory management data structures, arm64 makes use of the +mem_hotplug_lock semaphore in write mode. Additionally, in read mode, +mem_hotplug_lock supports an efficient implementation of +get_online_mems() and put_online_mems(). These protect the offlining of +memory being accessed by the ptdump code. =20 -In order to dump the kernel page tables, enable the following -configurations and mount debugfs:: +In order to dump the kernel page tables, enable the following configuratio= ns +and mount debugfs:: =20 CONFIG_GENERIC_PTDUMP=3Dy CONFIG_PTDUMP_CORE=3Dy @@ -29,68 +28,98 @@ configurations and mount debugfs:: mount -t debugfs nodev /sys/kernel/debug cat /sys/kernel/debug/kernel_page_tables =20 -On analysing the output of cat /sys/kernel/debug/kernel_page_tables -one can derive information about the virtual address range of the entry, -followed by size of the memory region covered by this entry, the -hierarchical structure of the page tables and finally the attributes -associated with each page. The page attributes provide information about -access permissions, execution capability, type of mapping such as leaf -level PTE or block level PGD, PMD and PUD, and access status of a page -within the kernel memory. Assessing these attributes can assist in -understanding the memory layout, access patterns and security -characteristics of the kernel pages. +On analysing the output of cat /sys/kernel/debug/kernel_page_tables one can +derive information about the virtual address range of a contiguous group of +page table entries, followed by size of the memory region covered by this +group, the hierarchical structure of the page tables and finally the attri= butes +associated with each page in the group. Groups are broken up either accord= ing +to a change in attributes or by parent descriptor, such as a PMD. Note tha= t the +set of attributes, and therefore formatting, is not equivalent between ent= ry +types. For example, PMD entries have a separate set of attributes from leaf +level PTE entries, because they support both the UXNTable and PXNTable +permission bits. + +The page attributes provide information about access permissions, execution +capability, type of mapping such as leaf level PTE or block level PGD, PMD= and +PUD, and access status of a page within the kernel memory. Non-PTE block or +page level entries are denoted with either "BLK" or "TBL", respectively. +Assessing these attributes can assist in understanding the memory layout, +access patterns and security characteristics of the kernel pages. =20 Kernel virtual memory layout example:: =20 - start address end address size attributes - +------------------------------------------------------------------------= ---------------+ - | ---[ Linear Mapping start ]--------------------------------------------= -------------- | - | .................. = | - | 0xfff0000000000000-0xfff0000000210000 2112K PTE RW NX SHD AF UXN MEM= /NORMAL-TAGGED | - | 0xfff0000000210000-0xfff0000001c00000 26560K PTE ro NX SHD AF UXN MEM= /NORMAL | - | .................. = | - | ---[ Linear Mapping end ]----------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ - | ---[ Modules start ]---------------------------------------------------= -------------- | - | .................. = | - | 0xffff800000000000-0xffff800008000000 128M PTE = | - | .................. = | - | ---[ Modules end ]-----------------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ - | ---[ vmalloc() area ]--------------------------------------------------= -------------- | - | .................. = | - | 0xffff800008010000-0xffff800008200000 1984K PTE ro x SHD AF UXN= MEM/NORMAL | - | 0xffff800008200000-0xffff800008e00000 12M PTE ro x SHD AF CON UXN= MEM/NORMAL | - | .................. = | - | ---[ vmalloc() end ]---------------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ - | ---[ Fixmap start ]----------------------------------------------------= -------------- | - | .................. = | - | 0xfffffbfffdb80000-0xfffffbfffdb90000 64K PTE ro x SHD AF UXN MEM= /NORMAL | - | 0xfffffbfffdb90000-0xfffffbfffdba0000 64K PTE ro NX SHD AF UXN MEM= /NORMAL | - | .................. = | - | ---[ Fixmap end ]------------------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ - | ---[ PCI I/O start ]---------------------------------------------------= -------------- | - | .................. = | - | 0xfffffbfffe800000-0xfffffbffff800000 16M PTE = | - | .................. = | - | ---[ PCI I/O end ]-----------------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ - | ---[ vmemmap start ]---------------------------------------------------= -------------- | - | .................. = | - | 0xfffffc0002000000-0xfffffc0002200000 2M PTE RW NX SHD AF UXN MEM= /NORMAL | - | 0xfffffc0002200000-0xfffffc0020000000 478M PTE = | - | .................. = | - | ---[ vmemmap end ]-----------------------------------------------------= -------------- | - +------------------------------------------------------------------------= ---------------+ + start address end address size type leaf attributes + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ Linear Mapping start ]--- = | + | ... = | + | 0xffff0d02c3200000-0xffff0d02c3400000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL | + | 0xffff0d02c3200000-0xffff0d02c3218000 96K PTE ro NX SHD AF = NG UXN MEM/NORMAL-TAGGED | + | 0xffff0d02c3218000-0xffff0d02c3250000 224K PTE RW NX SHD AF = NG UXN MEM/NORMAL-TAGGED | + | 0xffff0d02c3250000-0xffff0d02c33b3000 1420K PTE ro NX SHD AF = NG UXN MEM/NORMAL-TAGGED | + | 0xffff0d02c33b3000-0xffff0d02c3400000 308K PTE RW NX SHD AF = NG UXN MEM/NORMAL-TAGGED | + | 0xffff0d02c3400000-0xffff0d02c3600000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL | + | 0xffff0d02c3400000-0xffff0d02c3600000 2M PTE RW NX SHD AF = NG UXN MEM/NORMAL-TAGGED | + | ... = | + | 0xffff0d02c3200000-0xffff0d02c3400000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL | + | ... = | + | ---[ Linear Mapping end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ Modules start ]--- = | + | ... = | + | 0xffff800000000000-0xffff800000000080 128B PGD TBL RW = x UXNTbl MEM/NORMAL | + | 0xffff800000000000-0xffff800080000000 2G PUD F BLK RW = x MEM/NORMAL | + | ... = | + | ---[ Modules end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ vmalloc() area ]--- = | + | ... = | + | 0xffff800080000000-0xffff8000c0000000 1G PUD TBL RW = x UXNTbl MEM/NORMAL | + | ... = | + | 0xffff800080200000-0xffff800080400000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL | + | 0xffff800080200000-0xffff80008022f000 188K PTE RW NX SHD AF N= G UXN MEM/NORMAL | + | 0xffff80008022f000-0xffff800080230000 4K PTE F BLK RW x = MEM/NORMAL | + | 0xffff800080230000-0xffff800080233000 12K PTE RW NX SHD AF N= G UXN MEM/NORMAL | + | 0xffff800080233000-0xffff800080234000 4K PTE F BLK RW x = MEM/NORMAL | + | 0xffff800080234000-0xffff800080237000 12K PTE RW NX SHD AF N= G UXN MEM/NORMAL | + | ... = | + | 0xffff800080400000-0xffff800084000000 60M PMD F BLK RW = x x x MEM/NORMAL | + | ... = | + | ---[ vmalloc() end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ vmemmap start ]--- = | + | ... = | + | 0xfffffe33cb000000-0xfffffe33cc000000 16M PMD BLK RW SHD AF NG = NX UXN x x MEM/NORMAL | + | 0xfffffe33cc000000-0xfffffe3400000000 832M PMD F BLK RW = x x x MEM/NORMAL | + | ... = | + | ---[ vmemmap end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ PCI I/O start ]--- = | + | ... = | + | 0xffffffffc0800000-0xffffffffc0810000 64K PTE RW NX SHD AF NG= UXN DEVICE/nGnRE | + | ... = | + | ---[ PCI I/O end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ + | ---[ Fixmap start ]--- = | + | ... = | + | 0xffffffffff5f6000-0xffffffffff5f9000 12K PTE ro x SHD AF = UXN MEM/NORMAL | + | 0xffffffffff5f9000-0xffffffffff5fa000 4K PTE ro NX SHD AF NG= UXN MEM/NORMAL | + | ... = | + | ---[ Fixmap end ]--- = | + +------------------------------------------------------------------------= -----------------------------------------+ =20 cat /sys/kernel/debug/kernel_page_tables output:: =20 - 0xfff0000001c00000-0xfff0000080000000 2020M PTE RW NX SHD AF UXN = MEM/NORMAL-TAGGED - 0xfff0000080000000-0xfff0000800000000 30G PMD - 0xfff0000800000000-0xfff0000800700000 7M PTE RW NX SHD AF UXN = MEM/NORMAL-TAGGED - 0xfff0000800700000-0xfff0000800710000 64K PTE ro NX SHD AF UXN = MEM/NORMAL-TAGGED - 0xfff0000800710000-0xfff0000880000000 2089920K PTE RW NX SHD AF UXN = MEM/NORMAL-TAGGED - 0xfff0000880000000-0xfff0040000000000 4062G PMD - 0xfff0040000000000-0xffff800000000000 3964T PGD + 0xffff000000000000-0xffff0d0000000000 13T PGD F BLK RW = x MEM/NORMAL + 0xffff0d0000000000-0xffff0d0000000080 128B PGD TBL RW = NXTbl UXNTbl MEM/NORMAL + 0xffff0d0000000000-0xffff0d02c0000000 11G PUD F BLK RW = x MEM/NORMAL + 0xffff0d02c0000000-0xffff0d0300000000 1G PUD TBL RW = NXTbl UXNTbl MEM/NORMAL + 0xffff0d02c0000000-0xffff0d02c0200000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL + 0xffff0d02c0000000-0xffff0d02c0200000 2M PTE RW NX SHD AF NG= UXN MEM/NORMAL-TAGGED + 0xffff0d02c0200000-0xffff0d02c0400000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL + 0xffff0d02c0200000-0xffff0d02c0210000 64K PTE RW NX SHD AF NG= UXN MEM/NORMAL-TAGGED + 0xffff0d02c0210000-0xffff0d02c0400000 1984K PTE ro NX SHD AF NG= UXN MEM/NORMAL + 0xffff0d02c0400000-0xffff0d02c1c00000 24M PMD BLK ro SHD AF NG = NX UXN x x MEM/NORMAL + 0xffff0d02c1c00000-0xffff0d02c1e00000 2M PMD TBL RW = x NXTbl UXNTbl MEM/NORMAL + 0xffff0d02c1c00000-0xffff0d02c1dc0000 1792K PTE ro NX SHD AF NG= UXN MEM/NORMAL + 0xffff0d02c1dc0000-0xffff0d02c1e00000 256K PTE RW NX SHD AF NG= UXN MEM/NORMAL-TAGGED + diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 6986827e0d64..362f3c95d59b 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include =20 =20 #define pt_dump_seq_printf(m, fmt, args...) @@ -70,6 +71,11 @@ static cons= t struct prot_bits pte_bits[] =3D { .val =3D PTE_VALID, .set =3D " ", .clear =3D "F", + }, { + .mask =3D PTE_TABLE_BIT, + .val =3D PTE_TABLE_BIT, + .set =3D " ", + .clear =3D "BLK", }, { .mask =3D PTE_USER, .val =3D PTE_USER, @@ -105,11 +111,6 @@ static const struct prot_bits pte_bits[] =3D { .val =3D PTE_CONT, .set =3D "CON", .clear =3D " ", - }, { - .mask =3D PTE_TABLE_BIT, - .val =3D PTE_TABLE_BIT, - .set =3D " ", - .clear =3D "BLK", }, { .mask =3D PTE_UXN, .val =3D PTE_UXN, @@ -143,34 +144,208 @@ static const struct prot_bits pte_bits[] =3D { } }; =20 +static const struct prot_bits pmd_bits[] =3D { + { + .mask =3D PMD_SECT_VALID, + .val =3D PMD_SECT_VALID, + .set =3D " ", + .clear =3D "F", + }, { + .mask =3D PMD_TABLE_BIT, + .val =3D PMD_TABLE_BIT, + .set =3D "TBL", + .clear =3D "BLK", + }, { + .mask =3D PMD_SECT_USER, + .val =3D PMD_SECT_USER, + .set =3D "USR", + .clear =3D " ", + }, { + .mask =3D PMD_SECT_RDONLY, + .val =3D PMD_SECT_RDONLY, + .set =3D "ro", + .clear =3D "RW", + }, { + .mask =3D PMD_SECT_S, + .val =3D PMD_SECT_S, + .set =3D "SHD", + .clear =3D " ", + }, { + .mask =3D PMD_SECT_AF, + .val =3D PMD_SECT_AF, + .set =3D "AF", + .clear =3D " ", + }, { + .mask =3D PMD_SECT_NG, + .val =3D PMD_SECT_NG, + .set =3D "NG", + .clear =3D " ", + }, { + .mask =3D PMD_SECT_CONT, + .val =3D PMD_SECT_CONT, + .set =3D "CON", + .clear =3D " ", + }, { + .mask =3D PMD_SECT_PXN, + .val =3D PMD_SECT_PXN, + .set =3D "NX", + .clear =3D "x ", + }, { + .mask =3D PMD_SECT_UXN, + .val =3D PMD_SECT_UXN, + .set =3D "UXN", + .clear =3D " ", + }, { + .mask =3D PMD_TABLE_PXN, + .val =3D PMD_TABLE_PXN, + .set =3D "NXTbl", + .clear =3D "x ", + }, { + .mask =3D PMD_TABLE_UXN, + .val =3D PMD_TABLE_UXN, + .set =3D "UXNTbl", + .clear =3D "x ", + }, { + .mask =3D PTE_GP, + .val =3D PTE_GP, + .set =3D "GP", + .clear =3D " ", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_DEVICE_nGnRnE), + .set =3D "DEVICE/nGnRnE", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_DEVICE_nGnRE), + .set =3D "DEVICE/nGnRE", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL_NC), + .set =3D "MEM/NORMAL-NC", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL), + .set =3D "MEM/NORMAL", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL_TAGGED), + .set =3D "MEM/NORMAL-TAGGED", + } +}; + +static const struct prot_bits pud_bits[] =3D { + { + .mask =3D PUD_TYPE_SECT, + .val =3D PUD_TYPE_SECT, + .set =3D " ", + .clear =3D "F", + }, { + .mask =3D PUD_TABLE_BIT, + .val =3D PUD_TABLE_BIT, + .set =3D "TBL", + .clear =3D "BLK", + }, { + .mask =3D PTE_USER, + .val =3D PTE_USER, + .set =3D "USR", + .clear =3D " ", + }, { + .mask =3D PUD_SECT_RDONLY, + .val =3D PUD_SECT_RDONLY, + .set =3D "ro", + .clear =3D "RW", + }, { + .mask =3D PTE_SHARED, + .val =3D PTE_SHARED, + .set =3D "SHD", + .clear =3D " ", + }, { + .mask =3D PTE_AF, + .val =3D PTE_AF, + .set =3D "AF", + .clear =3D " ", + }, { + .mask =3D PTE_NG, + .val =3D PTE_NG, + .set =3D "NG", + .clear =3D " ", + }, { + .mask =3D PTE_CONT, + .val =3D PTE_CONT, + .set =3D "CON", + .clear =3D " ", + }, { + .mask =3D PUD_TABLE_PXN, + .val =3D PUD_TABLE_PXN, + .set =3D "NXTbl", + .clear =3D "x ", + }, { + .mask =3D PUD_TABLE_UXN, + .val =3D PUD_TABLE_UXN, + .set =3D "UXNTbl", + .clear =3D " ", + }, { + .mask =3D PTE_GP, + .val =3D PTE_GP, + .set =3D "GP", + .clear =3D " ", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_DEVICE_nGnRnE), + .set =3D "DEVICE/nGnRnE", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_DEVICE_nGnRE), + .set =3D "DEVICE/nGnRE", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL_NC), + .set =3D "MEM/NORMAL-NC", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL), + .set =3D "MEM/NORMAL", + }, { + .mask =3D PMD_ATTRINDX_MASK, + .val =3D PMD_ATTRINDX(MT_NORMAL_TAGGED), + .set =3D "MEM/NORMAL-TAGGED", + } +}; + struct pg_level { const struct prot_bits *bits; char name[4]; int num; u64 mask; + unsigned long size; }; =20 static struct pg_level pg_level[] __ro_after_init =3D { { /* pgd */ .name =3D "PGD", - .bits =3D pte_bits, - .num =3D ARRAY_SIZE(pte_bits), + .bits =3D pud_bits, + .num =3D ARRAY_SIZE(pud_bits), + .size =3D PGD_SIZE }, { /* p4d */ .name =3D "P4D", - .bits =3D pte_bits, - .num =3D ARRAY_SIZE(pte_bits), + .bits =3D pud_bits, + .num =3D ARRAY_SIZE(pud_bits), + .size =3D P4D_SIZE }, { /* pud */ .name =3D "PUD", - .bits =3D pte_bits, - .num =3D ARRAY_SIZE(pte_bits), + .bits =3D pud_bits, + .num =3D ARRAY_SIZE(pud_bits), + .size =3D PUD_SIZE }, { /* pmd */ .name =3D "PMD", - .bits =3D pte_bits, - .num =3D ARRAY_SIZE(pte_bits), + .bits =3D pmd_bits, + .num =3D ARRAY_SIZE(pmd_bits), + .size =3D PMD_SIZE }, { /* pte */ .name =3D "PTE", .bits =3D pte_bits, .num =3D ARRAY_SIZE(pte_bits), + .size =3D PAGE_SIZE }, }; =20 @@ -225,7 +400,7 @@ static void note_page(struct ptdump_state *pt_st, unsig= ned long addr, int level, u64 val) { struct pg_state *st =3D container_of(pt_st, struct pg_state, ptdump); - static const char units[] =3D "KMGTPE"; + static const char units[] =3D "BKMGTPE"; u64 prot =3D 0; =20 /* check if the current level has been folded dynamically */ @@ -241,8 +416,8 @@ static void note_page(struct ptdump_state *pt_st, unsig= ned long addr, int level, st->current_prot =3D prot; st->start_address =3D addr; pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); - } else if (prot !=3D st->current_prot || level !=3D st->level || - addr >=3D st->marker[1].start_address) { + } else if ((prot !=3D st->current_prot || level !=3D st->level || + addr >=3D st->marker[1].start_address)) { const char *unit =3D units; unsigned long delta; =20 @@ -251,10 +426,20 @@ static void note_page(struct ptdump_state *pt_st, uns= igned long addr, int level, note_prot_wx(st, addr); } =20 - pt_dump_seq_printf(st->seq, "0x%016lx-0x%016lx ", - st->start_address, addr); + /* + * Entries are coalesced into a single line, so non-leaf + * entries have no size relative to start_address + */ + if (st->start_address !=3D addr) { + pt_dump_seq_printf(st->seq, "0x%016lx-0x%016lx ", + st->start_address, addr); + delta =3D (addr - st->start_address); + } else { + pt_dump_seq_printf(st->seq, "0x%016lx-0x%016lx ", addr, + addr + pg_level[st->level].size); + delta =3D (pg_level[st->level].size); + } =20 - delta =3D (addr - st->start_address) >> 10; while (!(delta & 1023) && unit[1]) { delta >>=3D 10; unit++; @@ -301,7 +486,8 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info= *info) .range =3D (struct ptdump_range[]){ {info->base_addr, end}, {0, 0} - } + }, + .note_non_leaf =3D true } }; =20 diff --git a/include/linux/ptdump.h b/include/linux/ptdump.h index 8dbd51ea8626..b3e793a5c77f 100644 --- a/include/linux/ptdump.h +++ b/include/linux/ptdump.h @@ -16,6 +16,7 @@ struct ptdump_state { int level, u64 val); void (*effective_prot)(struct ptdump_state *st, int level, u64 val); const struct ptdump_range *range; + bool note_non_leaf; }; =20 bool ptdump_walk_pgd_level_core(struct seq_file *m, diff --git a/mm/ptdump.c b/mm/ptdump.c index 106e1d66e9f9..97da7a765b22 100644 --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -41,6 +41,9 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long add= r, if (st->effective_prot) st->effective_prot(st, 0, pgd_val(val)); =20 + if (st->note_non_leaf && !pgd_leaf(val)) + st->note_page(st, addr, 0, pgd_val(val)); + if (pgd_leaf(val)) { st->note_page(st, addr, 0, pgd_val(val)); walk->action =3D ACTION_CONTINUE; @@ -64,6 +67,9 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long add= r, if (st->effective_prot) st->effective_prot(st, 1, p4d_val(val)); =20 + if (st->note_non_leaf && !p4d_leaf(val)) + st->note_page(st, addr, 1, p4d_val(val)); + if (p4d_leaf(val)) { st->note_page(st, addr, 1, p4d_val(val)); walk->action =3D ACTION_CONTINUE; @@ -87,6 +93,9 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long add= r, if (st->effective_prot) st->effective_prot(st, 2, pud_val(val)); =20 + if (st->note_non_leaf && !pud_leaf(val)) + st->note_page(st, addr, 2, pud_val(val)); + if (pud_leaf(val)) { st->note_page(st, addr, 2, pud_val(val)); walk->action =3D ACTION_CONTINUE; @@ -108,6 +117,10 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long = addr, =20 if (st->effective_prot) st->effective_prot(st, 3, pmd_val(val)); + + if (st->note_non_leaf && !pmd_leaf(val)) + st->note_page(st, addr, 3, pmd_val(val)); + if (pmd_leaf(val)) { st->note_page(st, addr, 3, pmd_val(val)); walk->action =3D ACTION_CONTINUE; base-commit: 71b1543c83d65af8215d7558d70fc2ecbee77dcf --=20 2.34.1