From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02FAF199E98 for ; Tue, 27 Aug 2024 08:46:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724748366; cv=none; b=pU4pjnjpSi/EmYOHgCkuMmzb3Y+C007ogz+Ff2zk9+fYO1ialXtVx7LLjvn3YwiWgns31TOPwV0nUTNOo+0+v3FXzvZXgpGwRnjQ5gZivmbhSXyLLVnk7ooL9aZlYhRq3VJP4ntPUmp10jdKeyExTHw+y0bZX+DfMoQamfglGGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724748366; c=relaxed/simple; bh=Qr08QM26q8tDe51syMaE8h89/HxW9A0cYqV9q7lV/20=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rKji0FvDdvvNAZaDG2xfJFc72QUQb1yomHF7x8ROfMLlM6XwEPZKCe2TULgfRVd33WsTY8nniukPY27g8Y5J7UynKOr8AgrSXidx8vzxoO3ft2gh7qpZSH0DTqlVDCAfiNvKqXW7N0tZipRZKPr0/5hGn61K562VaYhyFp6EvkI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oUdrNca1; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oUdrNca1" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-42b8a5b7fd9so30372775e9.0 for ; Tue, 27 Aug 2024 01:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724748363; x=1725353163; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SMXEDoUiwiu4q/DZdkFbUl9+xm4eWjv4+UrgfxPU2W4=; b=oUdrNca1FGmAnhLCFBupUCC8MN5R05jd49szqCrFKsWUvtt6f1IpdZ7uL9QhEnTV0y q4FNYBrV0U8GOTSN0wjDY+DuUXDo/sKLiQdjYilh5qdHAMBOjF8RtWx7AOMmlieONsAw 6SmI7vBC2NDMpGKjaXn/eqyQWiXOTZbHpYck8GJj8FkAoV/wXR0YzNgt1zBV05vzV44p Ep4AUXvjQqfC22ht3S5IbezD2tt0e/mSLZaezqi6qA4lgpr2BzwtrftXASViKv8j1mKm leht2EdCd7YEMoScmLSdfQNzLZeFQHpBDXfHzJRQ3BWrxxFtCI+jIlSI4eXTSLJba1k0 Z3BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724748363; x=1725353163; 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=SMXEDoUiwiu4q/DZdkFbUl9+xm4eWjv4+UrgfxPU2W4=; b=Iz8z/v0V92rBaJgojJ+awxYktkmBUFNFpbeXyIZRtLND2JLxY7CooHXQdDoGbAgF05 /uXgklXm0dzg2yRcAXnQFD4XS0xvDRXpAv1FomU6LixsVpbT4xNXNVLXsdgbk78k4ZCZ 6f2W1dkR8JalrSzDCybuE+kHap3nlEWROp0m2GfkjzL/SKcz24tNIUp/s8xMvHn0l+Xj YczP/fe1sLrCMOw39Mm5iZZ2Rv20GQ5VaF0FzYr/0QGd6V80wI7EWMAw2cyE1luJ1OTW OGlOQxp0Rn9wAMg+4K5RT6R+AofdWosvmqDm89o6+YK6KJLpEqMsSXWCej4fOJUzAU9H H3Pw== X-Gm-Message-State: AOJu0Yw/wASvo0FnLSlvtKpJy4/QeYKMzZnwP6g03rZ7vAoxsSTY3aGM p+wg0aS54d8Eug438dPAhgkvDda1HSiRg8gGTSsnrTP4XHgNylcJigAdECsX6tcFKAVeqyEkrZX SPEC6OVsAhZBRBEdYExl/ejiUlg== X-Google-Smtp-Source: AGHT+IHY4rt/KDG8jBlRHZVjqb4Z3O2aMXhgahv4zi33s4tbXCpBDS46J6SJnoaHeJNB1+fTQfKkZHV28U+bNgbGPq8= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:600c:3b0f:b0:426:6619:943 with SMTP id 5b1f17b1804b1-42b9ae1da4dmr63725e9.3.1724748363256; Tue, 27 Aug 2024 01:46:03 -0700 (PDT) Date: Tue, 27 Aug 2024 08:45:45 +0000 In-Reply-To: <20240827084549.45731-1-sebastianene@google.com> Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240827084549.45731-1-sebastianene@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Message-ID: <20240827084549.45731-3-sebastianene@google.com> Subject: [PATCH v9 2/5] arm64: ptdump: Expose the attribute parsing functionality From: Sebastian Ene To: akpm@linux-foundation.org, alexghiti@rivosinc.com, ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, james.morse@arm.com, vdonnefort@google.com, mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev, rananta@google.com, ryan.roberts@arm.com, sebastianene@google.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 Content-Type: text/plain; charset="UTF-8" Reuse the descriptor parsing functionality to keep the same output format as the original ptdump code. In order for this to happen, move the state tracking objects into a common header. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 41 +++++++++++++++++++++++- arch/arm64/mm/ptdump.c | 55 +++++++-------------------------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 5b1701c76d1c..bd5d3ee3e8dc 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -9,6 +9,7 @@ #include #include +#include struct addr_marker { unsigned long start_address; @@ -21,14 +22,52 @@ struct ptdump_info { unsigned long base_addr; }; +struct ptdump_prot_bits { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +struct ptdump_pg_level { + const struct ptdump_prot_bits *bits; + char name[4]; + int 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 ptdump_pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + const struct mm_struct *mm; + 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 */ +#else +static inline void note_page(void *pt_st, unsigned long addr, + int level, u64 val) { } #endif /* CONFIG_PTDUMP_CORE */ #endif /* __ASM_PTDUMP_H */ diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 6986827e0d64..404751fd30fe 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -38,33 +38,7 @@ 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; - const struct mm_struct *mm; - 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[] = { +static const struct ptdump_prot_bits pte_bits[] = { { .mask = PTE_VALID, .val = PTE_VALID, @@ -143,14 +117,7 @@ static const struct prot_bits pte_bits[] = { } }; -struct pg_level { - const struct prot_bits *bits; - char name[4]; - int num; - u64 mask; -}; - -static struct pg_level pg_level[] __ro_after_init = { +static struct ptdump_pg_level pg_level[] __ro_after_init = { { /* pgd */ .name = "PGD", .bits = pte_bits, @@ -174,7 +141,7 @@ static struct pg_level pg_level[] __ro_after_init = { }, }; -static void dump_prot(struct pg_state *st, const struct prot_bits *bits, +static void dump_prot(struct ptdump_pg_state *st, const struct ptdump_prot_bits *bits, size_t num) { unsigned i; @@ -192,7 +159,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, } } -static void note_prot_uxn(struct pg_state *st, unsigned long addr) +static void note_prot_uxn(struct ptdump_pg_state *st, unsigned long addr) { if (!st->check_wx) return; @@ -206,7 +173,7 @@ static void note_prot_uxn(struct pg_state *st, unsigned long addr) st->uxn_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_prot_wx(struct pg_state *st, unsigned long addr) +static void note_prot_wx(struct ptdump_pg_state *st, unsigned long addr) { if (!st->check_wx) return; @@ -221,10 +188,10 @@ 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); + struct ptdump_pg_state *st = container_of(pt_st, struct ptdump_pg_state, ptdump); static const char units[] = "KMGTPE"; u64 prot = 0; @@ -286,12 +253,12 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, void ptdump_walk(struct seq_file *s, struct ptdump_info *info) { unsigned long end = ~0UL; - struct pg_state st; + struct ptdump_pg_state st; if (info->base_addr < TASK_SIZE_64) end = TASK_SIZE_64; - st = (struct pg_state){ + st = (struct ptdump_pg_state){ .seq = s, .marker = info->markers, .mm = info->mm, @@ -324,7 +291,7 @@ static struct ptdump_info kernel_ptdump_info __ro_after_init = { bool ptdump_check_wx(void) { - struct pg_state st = { + struct ptdump_pg_state st = { .seq = NULL, .marker = (struct addr_marker[]) { { 0, NULL}, -- 2.46.0.295.g3b9ea8a38a-goog