From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f1.google.com (mail-pj2-f1.google.com [74.125.227.129]) (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 9803F36683B for ; Tue, 28 Jul 2026 16:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.129 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785255331; cv=none; b=N/ZTZULAxDn+oXtEnrR2w7P62hQYUmY5z8sOge908dy5VEkubjXMXFDFT3sOMN8YZUeANcec/fH2Pyfdh8dKezRkU3v2gF/aJb8mb9GmGNusEOT6ZpIgfrU9oElN+HYFG0xv2v4JMPLibxtjDyyURA6Opyll9zdloV4w5wOA/Rc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785255331; c=relaxed/simple; bh=lMPhclar841uMJ0GBnwOF3+QTLkWoYZXkBqtzRZw4Wg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MaWZztHLm9+ZbLq3cDgkuO9z9RkWDtM/Bh5xy7+ExBiiWniapqh5epo1XF8Si90UmDGRXE49rB8pH/gdSwW4uxurN1b1lR7eUkB68ewR9FMrAREXrAneh75NnpK493vh+38aTht2tD8o4j2/nU/PMt/Gu/5coi/6SHVtMD8s1Vw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kH1wYvzX; arc=none smtp.client-ip=74.125.227.129 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kH1wYvzX" Received: by mail-pj2-f1.google.com with SMTP id 98e67ed59e1d1-383390e7584so1953a91.0 for ; Tue, 28 Jul 2026 09:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785255322; x=1785860122; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=upXRv+tWWPrMoVucIXngMrJVs24x1WlX2PUogXgOPbc=; b=kH1wYvzXylrLaXoi/oXiDd7HiSeGC+NaG+OsXGfbWZqdpWYYi5/AMhEFUQS+JCOkYI sUnAc+8of1+BpJle4IZZM/99rvck+9ivLQO2DIDleztHEMmnU4oBS1x9gm2rT0cjNYdF NorrtUYBeAG8BDKoKzcUCD54xdyeie0lRfw8ihmzV27yb2NEXPE5Th1bFK1rA0grdJhJ YQ6Eip2owxF1sMOCTZDPoshurfCUuRgkgQWN2LXARha7fgyKG7IGykwlp7weiii97OpW voRV9vmqlsVHXR0RCTjc0Ls9H81bkxvZJbMUCU5p18scF0eQarMLESD0Yd1JLVFejKjc cHOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785255322; x=1785860122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=upXRv+tWWPrMoVucIXngMrJVs24x1WlX2PUogXgOPbc=; b=O9OAIuz4kfvwIWOc/nAa42d7VH7GNrnFEWqQaebfe8qGlLJ+X6UXH3CoBOc/tIE/Kk lB0B4nDyQZ9FuCDuyOM0m9IIrSrvk3K4Rmy6CsogyEyIYJzVcKhptFI01e8dJPa0kfqC mpgS1d7CKi72E/K6vpjeNfywVlbwSADFDblsaxmFfxhw0HKa6L0pTegDNTWZFojr4oQC UlETe7nyDo3ah4LWqUacJ1XAHE6YSQr6e9SZburuwH5ippBvH0gmpZPb07oKBlOZgY2p iC6Jl9iG15eVt4ZSh1VIywKX4Z3hXcGw42ZYw5HO2ngGwX+Xss959i2k/S3XDAQaMlg3 MCmg== X-Forwarded-Encrypted: i=1; AHgh+Rr56ryaMWL/eSlBdmWcvzCtsaHPCKIZGLSpOuELr//ncCWI32LrpST7VtVHpZWqlrsbrcmD75rSV9SjDsw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2LsntdOkKUDJkcWTYYLKDr4XkGI/xTLMoNz86Wcfuw9uqlFOt kCbKHFQr8MEV+Yry20o4N8ncbyjrWLr/hPX9VTkVitaCcDJ/tXG7ByEx X-Gm-Gg: AR+sD102/XZBg1ae6st/aSdR5dpmx1VS1hJuB0TsY1eb/FoXZfkvT9Z07PW+IC6e4j7 bqsMIfgkkKT64YhehJxLWCYkgFQaYsn1ZrZCU9trRcLzcgW39gybdKJ59DWccAAKAigc8gsVjww KE5uVBktX95OnYZJH4FmR/y7pRgfZWRcf0lFJlLtuBW+yqtat4WqnoXiOt1LozJqVsJ3Pjkrqau BqUCBlCLOD1bp6miBjNwzdkbKYdIiKTYuW73Wa02a1uuAKsXTEhL9BULG6bM8GbY2nAMRo2Lm1t JLriWEuexYe1YZB3eKf800hbAICD+6FBwHQSLIWTkd/nCtIwmfO6bLwhCcaEvcEwDQsfsw57FFD MrGXiyESMe65ph1n5VuEe7olz+VGcidUUrW1fXc0SNtEEPMKWjz7Eyhpt0FW/OzOmHUuKxtzmKO KaO9TONA== X-Received: by 2002:a17:90b:3ccf:b0:38e:7f22:f674 with SMTP id 98e67ed59e1d1-38f6a30cf0bmr3139540a91.11.1785255321550; Tue, 28 Jul 2026 09:15:21 -0700 (PDT) Received: from wud.. ([218.194.32.52]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38f7f292b06sm161141a91.10.2026.07.28.09.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 09:15:21 -0700 (PDT) From: "Dylan.Wu" To: paul.walmsley@sifive.com, pjw@kernel.org Cc: palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, anup@brainfault.org, atish.patra@linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, "Dylan.Wu" , Quan Zhou Subject: [PATCH v3 1/3] riscv: ptdump: Create ptdump.h and move declarations Date: Tue, 28 Jul 2026 12:14:47 -0400 Message-Id: <20260728161449.190058-2-fredwudi0305@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260728161449.190058-1-fredwudi0305@gmail.com> References: <3bb2f519-c70b-6c35-c404-6fbfe8adbeb1@kernel.org> <20260728161449.190058-1-fredwudi0305@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Create a new arch/riscv/include/asm/ptdump.h header file and move the pagetable walking state structures and level definitions there. This allows other parts of the kernel (like KVM) to reuse the ptdump data structures. Also export the note_page() symbol so it can be used by other kernel components. No functional changes - structures are moved verbatim. Assisted-by: YuanSheng: deepseek-v4-pro Co-developed-by: Quan Zhou Signed-off-by: Quan Zhou Signed-off-by: Dylan.Wu --- arch/riscv/include/asm/ptdump.h | 40 ++++++++++++++++++++++++++++++ arch/riscv/mm/ptdump.c | 44 +++------------------------------ 2 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 arch/riscv/include/asm/ptdump.h diff --git a/arch/riscv/include/asm/ptdump.h b/arch/riscv/include/asm/ptdump.h new file mode 100644 index 000000000..90dce9f64 --- /dev/null +++ b/arch/riscv/include/asm/ptdump.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_PTDUMP_H +#define _ASM_RISCV_PTDUMP_H + +#include +#include + +struct addr_marker { + unsigned long start_address; + const char *name; +}; + +struct prot_bits { + u64 mask; + const char *set; + const char *clear; +}; + +struct pg_level { + const char *name; + u64 mask; +}; + +struct pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + unsigned long start_pa; + unsigned long last_pa; + int level; + u64 current_prot; + bool check_wx; + unsigned long wx_pages; +}; + +void note_page(struct ptdump_state *pt_st, unsigned long addr, + int level, u64 val); + +#endif /* _ASM_RISCV_PTDUMP_H */ diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index f4b4a9fcb..d9a955b8a 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -11,6 +11,7 @@ #include #include +#include #include #define pt_dump_seq_printf(m, fmt, args...) \ @@ -25,31 +26,6 @@ seq_puts(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; - unsigned long start_pa; - unsigned long last_pa; - int level; - u64 current_prot; - bool check_wx; - unsigned long wx_pages; -}; - -/* Address marker */ -struct addr_marker { - unsigned long start_address; - const char *name; -}; - /* Private information for debugfs */ struct ptd_mm_info { struct mm_struct *mm; @@ -126,13 +102,6 @@ static struct ptd_mm_info efi_ptd_info = { }; #endif -/* Page Table Entry */ -struct prot_bits { - u64 mask; - const char *set; - const char *clear; -}; - static const struct prot_bits pte_bits[] = { { #ifdef CONFIG_64BIT @@ -183,12 +152,6 @@ static const struct prot_bits pte_bits[] = { } }; -/* Page Level */ -struct pg_level { - const char *name; - u64 mask; -}; - static struct pg_level pg_level[] = { { /* pgd */ .name = "PGD", @@ -276,8 +239,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); u64 pa = PFN_PHYS(pte_pfn(__pte(val))); @@ -317,6 +280,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, st->last_pa = pa; } } +EXPORT_SYMBOL_GPL(note_page); static void note_page_pte(struct ptdump_state *pt_st, unsigned long addr, pte_t pte) { -- 2.34.1