From patchwork Mon Apr 15 19:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxwell Bland X-Patchwork-Id: 13632239 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]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7421C04FF6 for ; Tue, 16 Apr 2024 17:25:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C5496B008C; Tue, 16 Apr 2024 13:25:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 675A76B0093; Tue, 16 Apr 2024 13:25:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5189B6B0095; Tue, 16 Apr 2024 13:25:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 33FB26B008C for ; Tue, 16 Apr 2024 13:25:31 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 012F9160BCD for ; Tue, 16 Apr 2024 17:25:30 +0000 (UTC) X-FDA: 82016071662.07.3C4FA43 Received: from mx0b-00823401.pphosted.com (mx0b-00823401.pphosted.com [148.163.152.46]) by imf20.hostedemail.com (Postfix) with ESMTP id 283E11C0004 for ; Tue, 16 Apr 2024 17:25:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=motorola.com header.s=DKIM202306 header.b="f VFZT85"; spf=pass (imf20.hostedemail.com: domain of mbland@motorola.com designates 148.163.152.46 as permitted sender) smtp.mailfrom=mbland@motorola.com; dmarc=pass (policy=none) header.from=motorola.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713288329; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=Oc2SUwX6uzMkXCJf4ZSU5CLVXrP2N2CrXvm6EA3BRc0=; b=jLFVU0lKIhxPVNpuj4scpG9QJT1p+eFGyFiYxrmrTOUc7LoYp/ZcGSrULBp8YWv35b+xHc zG/sKNsb64SAvjTPBwBRbiVLkmyLHL9irQtShCb5aCAed+l0GQHmGeKwHHtIVjIvjDHnYw /oQCB3wuIJUAy2Zr1ZR9zjTPuFkqNFA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=motorola.com header.s=DKIM202306 header.b="f VFZT85"; spf=pass (imf20.hostedemail.com: domain of mbland@motorola.com designates 148.163.152.46 as permitted sender) smtp.mailfrom=mbland@motorola.com; dmarc=pass (policy=none) header.from=motorola.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713288329; a=rsa-sha256; cv=none; b=P/5zS8KH66kUZt6ADrBYZaUHv+S3/MKdPNrIKta3SBq3bMJ/mZSnldHDYTeig+YJgcz6o+ FyZcpdse8rFa+cpqUmPpayLOOevjrpm+tDjZQb+2cnCR0D8zvqW8FWTTlWEfbn7CYKzBmQ ix6r825UqRqKoLabfz2us+59ULOXjcQ= Received: from pps.filterd (m0355091.ppops.net [127.0.0.1]) by mx0b-00823401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 43GFQBHE026682; Tue, 16 Apr 2024 17:24:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=motorola.com; h= message-id:in-reply-to:references:to:cc:from:date:subject; s= DKIM202306; bh=Oc2SUwX6uzMkXCJf4ZSU5CLVXrP2N2CrXvm6EA3BRc0=; b=f VFZT85i9fG9UZIMquW7lOcKAq20DOeCPjOdPiSoX40Uy/gdhpas7agKPawUQhT7x jlu6AEhZt7ljLk2n20UpKTnolmUli9RA4S94pfqgo82LJmyfQGSWX+2ckqN3E3a6 jp+/jciyo6S9UM3hNfRiVNfOIKTGmn3Gd7Kqf7Fg+ODOygCLrVJKEFbUu3tVWAti fadgXso/3HtOEdqpW7Sq+tQ8RIqcbtaSSGSjhS7q9YsinUy0LnphQn2+GK2iDP1m aaqJyHM7uz4vWoEonBp43YZWPoTF4kyTlWY8hHQneojPAs3B2gfooI2z9rSq2qK+ 8Td0+HxT5kbdpLFNyLd1A== Received: from va32lpfpp04.lenovo.com ([104.232.228.24]) by mx0b-00823401.pphosted.com (PPS) with ESMTPS id 3xhjbek979-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 16 Apr 2024 17:24:57 +0000 (GMT) Received: from va32lmmrp01.lenovo.com (va32lmmrp01.mot.com [10.62.177.113]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by va32lpfpp04.lenovo.com (Postfix) with ESMTPS id 4VJrWs1Wv3zj9hH; Tue, 16 Apr 2024 17:24:57 +0000 (UTC) Received: from ilclbld243.mot.com (ilclbld243.mot.com [100.64.22.29]) (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 va32lmmrp01.lenovo.com (Postfix) with ESMTPSA id 4VJrWs17Mmz2VZS6; Tue, 16 Apr 2024 17:24:57 +0000 (UTC) Message-Id: <20240416122254.868007168-6-mbland@motorola.com> In-Reply-To: <20240416122254.868007168-1-mbland@motorola.com> References: <20240416122254.868007168-1-mbland@motorola.com> To: linux-mm@kvack.org Cc: Maxwell Bland , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , Ard Biesheuvel , Mark Rutland , Maxwell Bland , Alexandre Ghiti , Yu Chien Peter Lin , Song Shuai , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org From: Maxwell Bland Date: Mon, 15 Apr 2024 14:51:32 -0500 Subject: [PATCH 5/5] ptdump: add state parameter for non-leaf callback X-Proofpoint-ORIG-GUID: Obuaco9Ts8gQobghqAGopelkIlnGG11N X-Proofpoint-GUID: Obuaco9Ts8gQobghqAGopelkIlnGG11N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-16_14,2024-04-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 impostorscore=0 suspectscore=0 bulkscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 adultscore=0 mlxlogscore=960 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2404160108 X-Stat-Signature: fsxrj9zbnc5gjkg61dgrn7tqcnebtoia X-Rspamd-Queue-Id: 283E11C0004 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1713288328-239941 X-HE-Meta: U2FsdGVkX1/NPxmdNY+zvw2HaevNzAAE/vlgRJg9c01T1BN88F5TkNYidL1CfS03ro3wyyLThzPxfPuPT8vJoMJMcRvGugfqHMiQN0Pj1ux+107NyT0Iwyl8dwQBlJ9Ekta8qUsxeWX5PcMiq2U1jGi9HE3/q3DMydznXbcMb6OgC3YZkPDmaSJBj6zqN3IMldbbawRntF2z7YUmsVjsT2ebLiUUc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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: ptdump can now note non-leaf descriptor entries, a useful addition for debugging table descriptor permissions when working on related code Signed-off-by: Maxwell Bland --- arch/arm64/mm/ptdump.c | 6 ++++-- arch/powerpc/mm/ptdump/ptdump.c | 2 ++ arch/riscv/mm/ptdump.c | 6 ++++-- arch/s390/mm/dump_pagetables.c | 6 ++++-- arch/x86/mm/dump_pagetables.c | 3 ++- include/linux/ptdump.h | 1 + mm/ptdump.c | 13 +++++++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 796231a4fd63..1a6f4a3513e5 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -299,7 +299,8 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) .range = (struct ptdump_range[]){ {info->base_addr, end}, {0, 0} - } + }, + .note_non_leaf = false } }; @@ -335,7 +336,8 @@ bool ptdump_check_wx(void) .range = (struct ptdump_range[]) { {_PAGE_OFFSET(vabits_actual), ~0UL}, {0, 0} - } + }, + .note_non_leaf = false } }; diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c index 9dc239967b77..89e673f5fd3d 100644 --- a/arch/powerpc/mm/ptdump/ptdump.c +++ b/arch/powerpc/mm/ptdump/ptdump.c @@ -307,6 +307,7 @@ static int ptdump_show(struct seq_file *m, void *v) .ptdump = { .note_page = note_page, .range = ptdump_range, + .note_non_leaf = false } }; @@ -340,6 +341,7 @@ bool ptdump_check_wx(void) .ptdump = { .note_page = note_page, .range = ptdump_range, + .note_non_leaf = false } }; diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index 1289cc6d3700..b355633afcaf 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -328,7 +328,8 @@ static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo) .range = (struct ptdump_range[]) { {pinfo->base_addr, pinfo->end}, {0, 0} - } + }, + .note_non_leaf = false } }; @@ -350,7 +351,8 @@ bool ptdump_check_wx(void) .range = (struct ptdump_range[]) { {KERN_VIRT_START, ULONG_MAX}, {0, 0} - } + }, + .note_non_leaf = false } }; diff --git a/arch/s390/mm/dump_pagetables.c b/arch/s390/mm/dump_pagetables.c index ffd07ed7b4af..6468cfd53e2a 100644 --- a/arch/s390/mm/dump_pagetables.c +++ b/arch/s390/mm/dump_pagetables.c @@ -200,7 +200,8 @@ bool ptdump_check_wx(void) .range = (struct ptdump_range[]) { {.start = 0, .end = max_addr}, {.start = 0, .end = 0}, - } + }, + .note_non_leaf = false }, .seq = NULL, .level = -1, @@ -239,7 +240,8 @@ static int ptdump_show(struct seq_file *m, void *v) .range = (struct ptdump_range[]) { {.start = 0, .end = max_addr}, {.start = 0, .end = 0}, - } + }, + .note_non_leaf = false }, .seq = m, .level = -1, diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 89079ea73e65..43f00dfb955f 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -380,7 +380,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .ptdump = { .note_page = note_page, .effective_prot = effective_prot, - .range = ptdump_ranges + .range = ptdump_ranges, + .note_non_leaf = false }, .level = -1, .to_dmesg = dmesg, 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; }; 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 addr, if (st->effective_prot) st->effective_prot(st, 0, pgd_val(val)); + 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 = ACTION_CONTINUE; @@ -64,6 +67,9 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, if (st->effective_prot) st->effective_prot(st, 1, p4d_val(val)); + 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 = ACTION_CONTINUE; @@ -87,6 +93,9 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, if (st->effective_prot) st->effective_prot(st, 2, pud_val(val)); + 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 = ACTION_CONTINUE; @@ -108,6 +117,10 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr, 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 = ACTION_CONTINUE;