From patchwork Wed Feb 7 14:48:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13548612 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF9CAC4828F for ; Wed, 7 Feb 2024 14:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p7BSuk+nTHRaA7j7T2+3Kf/XS9+VohDWHPhlYMqGXxc=; b=4HuHutjs19OMC0/192hPUEcrAN U5Hm8YEwCeewBryxmcqR2JV+tZF4rjDTzXdPZjB2KwF3n3pk6ZS78SA2GTleIeahjj8icGcem2mjL DEF7sTwl2jqvQrkL8tmyzElTEztIWlipzh/pYsWPdiLFNYuyJ9Xf3skVmCTue7Yi7OmTGbIkfOlz5 Sq7JrolNuD/dx2XO/xUSSKXclcAjkwSSw4yWekS+/qHnTbh4/TCGoLPavOdqR84tfxpJOp3qXgII2 Q9Vn3hxVtgPNHsa4e0ToY8Q6YLrfc8TgJTyVgjGhPX5y1YtQash2mHC1iGRB4P0TKj80/Th4cmCLm 1YpBDAxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXjEp-0000000AxjU-1268; Wed, 07 Feb 2024 14:49:23 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXjEn-0000000Axim-0RkB for linux-arm-kernel@lists.infradead.org; Wed, 07 Feb 2024 14:49:22 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a541b720aso1174028276.0 for ; Wed, 07 Feb 2024 06:49:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707317359; x=1707922159; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KuSad3U75XWRyrG0hVFC7e1TsgCe+6P5oSqEz6h0Hdo=; b=IyfBaGRpyw3d+2e3hQiZ338qKzCebR7pGBfaGl5Ae3s1qdcnTtWP/orOwtK0B2UVX6 QrszturJKcbkEWaHQInVt8qmjy4aE3aWV94Ta95LUPCD6BS/XCrDjR2Dt8kqcbvDHk4w 47O3XDEyQ/pHW3pXSSShaenaU4UbhdN1QckMeSd+e7WUNT/tOimtJOFOot9a63GsZjKd vXpkzHgNafGVPP4OMRtyjfOPwDv716NhCcUHK4fXweP9p35TiU+OnDpUtZ7RbqNtdAj+ vYINbHdf/J/h/6WgnMAtMbT4sEWZyeRLo33/7BhUhNQDIdD2YVZFbk6nIIgllupEhRLI szoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317359; x=1707922159; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KuSad3U75XWRyrG0hVFC7e1TsgCe+6P5oSqEz6h0Hdo=; b=gbKhRho4cJJyYHPNw8VZBpaUhu6Oa1QuIvRdEbbuakbF6Ty28+AT545JyhmBbt/Ev0 ZG8uIlvzM3sQqk3nf3pyEkc2Ad+RFfoYu0kg3qgCL2UysJjq9z/JZXHP2Z9GXpr3iP1B eLOfdky9NDWoSvfBlt3Q0XmcA8bS+NKHDnJNjmvGDxF30I478ZF9x4PBRC4wyGD7Z430 CT/jq8eaKESGejZttPW8vU0lnhO9yTwQGTLv8Uaugh6GLS6WSUVDEMsTjagu9fpwzXyZ A6LsgMoTBcuKg9i/90aAW5ennLo46DnD19wBrMacderXYs7IZLi56iD4izEWTCKFL+Ze QdWg== X-Forwarded-Encrypted: i=1; AJvYcCXEmvYpPNI4m/Z0RX2F2uX61FroT9llNeJk00z6OjK+a1pR51hBOl0pOPVN47a3tfTeq7r45Fl4XETVNSOqGEIFgsJlWeIIvdNaJQ38kQouIIm/Vmw= X-Gm-Message-State: AOJu0YxC1ky/M1nluxNag8XPSz0Mz5YApND1TNI5yr0YUEFE5GCKVcjT Xj0gPO/1LY/q8ol8bjtc/6OpExPUggg0gWZPNuY8nQkYi+BK6hGdEVZx3XYyBU6HWNCnNI7UBjk xlUtiGCVUcPbkImcP+W38sNY4+A== X-Google-Smtp-Source: AGHT+IFtCuGfAeqFdgjl+E/TRR4RFQ5mbVlens49Mh0ShuT1nuemqiHaz2jdZNbdKjru2453mCpm44BAccO7UGz0AYU= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:200c:b0:dc6:53c3:bcbd with SMTP id dh12-20020a056902200c00b00dc653c3bcbdmr1272474ybb.7.1707317359551; Wed, 07 Feb 2024 06:49:19 -0800 (PST) Date: Wed, 7 Feb 2024 14:48:30 +0000 In-Reply-To: <20240207144832.1017815-2-sebastianene@google.com> Mime-Version: 1.0 References: <20240207144832.1017815-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Message-ID: <20240207144832.1017815-3-sebastianene@google.com> Subject: [PATCH v5 1/4] arm64: ptdump: Expose the attribute parsing functionality From: Sebastian Ene To: catalin.marinas@arm.com, gshan@redhat.com, james.morse@arm.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ricarkol@google.com, ryan.roberts@arm.com, shahuang@redhat.com, suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240207_064921_170185_5E54295D X-CRM114-Status: GOOD ( 18.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To keep the same output format as the arch specific ptdump and for the sake of reusability, move the parser's state tracking code out of the arch specific. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 41 ++++++++++++++++++++++++++++++++- arch/arm64/mm/ptdump.c | 36 ++--------------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 581caac525b0..23510be35084 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -9,6 +9,8 @@ #include #include +#include + struct addr_marker { unsigned long start_address; @@ -21,15 +23,52 @@ struct ptdump_info { unsigned long base_addr; }; +struct prot_bits { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +struct pg_level { + const struct prot_bits *bits; + const char *name; + size_t num; + u64 mask; +}; + +/* + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the pte entries. When the continuity is broken it then + * dumps out a description of the range. + */ +struct pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + int level; + u64 current_prot; + bool check_wx; + unsigned long wx_pages; + unsigned long uxn_pages; +}; + void ptdump_walk(struct seq_file *s, struct ptdump_info *info); +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val); #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); #else static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } -#endif +#endif /* CONFIG_PTDUMP_DEBUGFS */ void ptdump_check_wx(void); +#else +static inline void note_page(void *pt_st, unsigned long addr, + int level, u64 val) { } #endif /* CONFIG_PTDUMP_CORE */ #ifdef CONFIG_DEBUG_WX diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index e305b6593c4e..64127c70b109 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -66,31 +66,6 @@ static struct addr_marker address_markers[] = { seq_printf(m, fmt); \ }) -/* - * The page dumper groups page table entries of the same type into a single - * description. It uses pg_state to track the range information while - * iterating over the pte entries. When the continuity is broken it then - * dumps out a description of the range. - */ -struct pg_state { - struct ptdump_state ptdump; - struct seq_file *seq; - const struct addr_marker *marker; - unsigned long start_address; - int level; - u64 current_prot; - bool check_wx; - unsigned long wx_pages; - unsigned long uxn_pages; -}; - -struct prot_bits { - u64 mask; - u64 val; - const char *set; - const char *clear; -}; - static const struct prot_bits pte_bits[] = { { .mask = PTE_VALID, @@ -170,13 +145,6 @@ static const struct prot_bits pte_bits[] = { } }; -struct pg_level { - const struct prot_bits *bits; - const char *name; - size_t num; - u64 mask; -}; - static struct pg_level pg_level[] = { { /* pgd */ .name = "PGD", @@ -248,8 +216,8 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) st->wx_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, - u64 val) +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); static const char units[] = "KMGTPE";