From patchwork Thu Sep 29 21:32:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9357141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 44DE560757 for ; Thu, 29 Sep 2016 21:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3611F29C58 for ; Thu, 29 Sep 2016 21:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 283FC29C68; Thu, 29 Sep 2016 21:35:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 768B129C58 for ; Thu, 29 Sep 2016 21:35:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpixo-0003KX-EE; Thu, 29 Sep 2016 21:33:56 +0000 Received: from mail-pa0-f50.google.com ([209.85.220.50]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpixV-0003Dd-G2 for linux-arm-kernel@lists.infradead.org; Thu, 29 Sep 2016 21:33:39 +0000 Received: by mail-pa0-f50.google.com with SMTP id cd13so28126617pac.0 for ; Thu, 29 Sep 2016 14:33:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RQ3RKAATzLvAwKxfb/D2tk2O8uUrjokk9xa6iyAPxW8=; b=eSKfF3nN+TACUnQZgx2nz/R9w5hmQZhyuQH/fpg2bxhaBUhH0CVJp7I1KIJ0Gf5TWd F6ZQMVLkkyDe20NS5f9fWrvqBLkGZHqbGpjHlGGG9tY4Cbpk06/G4XmVVKFQWwvQjv+C bEJSu5j+q7wpD2CRSYC2ffZuhsQZpwV/H8TkkpUSD8BBkULQ6E2XWsuyRKGS8+STN7dy wXSUSkUVG1G7VckiD0jdlNzllq+2Wxk2T9RJbYO7mVRpgjqjaDUZ5S1IN7kuYfllPZ2d ut89Pqb2U4LFn4GVTtHaF1Qgk0WGHtTG9t+SVKCkZK+AHaDGPaqboUhVN2wirykBpyEz 5Hpw== X-Gm-Message-State: AA6/9RmMCkTzTe8i0x9GtJOAm/o6fcmg+Srta55j6yARnvf1T3x0fKImSmL4/0SXGzon9wTt X-Received: by 10.66.235.100 with SMTP id ul4mr6067171pac.50.1475184796696; Thu, 29 Sep 2016 14:33:16 -0700 (PDT) Received: from localhost.localdomain ([67.238.99.186]) by smtp.gmail.com with ESMTPSA id q8sm22463933pac.32.2016.09.29.14.33.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2016 14:33:15 -0700 (PDT) From: Laura Abbott To: AKASHI Takahiro , Mark Rutland , Ard Biesheuvel , David Brown , Will Deacon , Catalin Marinas Subject: [PATCH 1/3] arm64: dump: Make ptdump debugfs a separate option Date: Thu, 29 Sep 2016 14:32:55 -0700 Message-Id: <20160929213257.30505-2-labbott@redhat.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160929213257.30505-1-labbott@redhat.com> References: <20160929213257.30505-1-labbott@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160929_143337_682427_7E64B2EC X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-hardening@lists.openwall.com, Laura Abbott , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kees Cook MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP ptdump_register currently initializes a set of page table information and registers debugfs. There are uses for the ptdump option without wanting the debugfs options. Split this out to make it a separate option. Signed-off-by: Laura Abbott --- arch/arm64/Kconfig.debug | 6 +++++- arch/arm64/include/asm/ptdump.h | 15 +++++++++++++-- arch/arm64/mm/Makefile | 3 ++- arch/arm64/mm/dump.c | 30 +++++++++--------------------- arch/arm64/mm/ptdump_debugfs.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 arch/arm64/mm/ptdump_debugfs.c diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug index 0cc758c..9015f02 100644 --- a/arch/arm64/Kconfig.debug +++ b/arch/arm64/Kconfig.debug @@ -2,9 +2,13 @@ menu "Kernel hacking" source "lib/Kconfig.debug" -config ARM64_PTDUMP +config ARM64_PTDUMP_CORE + def_bool n + +config ARM64_PTDUMP_DEBUGFS bool "Export kernel pagetable layout to userspace via debugfs" depends on DEBUG_KERNEL + select ARM64_PTDUMP_CORE select DEBUG_FS help Say Y here if you want to show the kernel pagetable layout in a diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 07b8ed0..b18a62c 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -16,8 +16,9 @@ #ifndef __ASM_PTDUMP_H #define __ASM_PTDUMP_H -#ifdef CONFIG_ARM64_PTDUMP +#ifdef CONFIG_ARM64_PTDUMP_CORE +#include #include struct addr_marker { @@ -33,12 +34,22 @@ struct ptdump_info { }; int ptdump_register(struct ptdump_info *info, const char *name); +void ptdump_walk_pgd(struct seq_file *s, struct ptdump_info *info); +#ifdef CONFIG_ARM64_PTDUMP_DEBUGFS +int ptdump_debugfs_create(struct ptdump_info *info, const char *name); +#else +static inline int ptdump_debugfs_create(struct ptdump_info *info, + const char *name) +{ + return 0; +} +#endif #else static inline int ptdump_register(struct ptdump_info *info, const char *name) { return 0; } -#endif /* CONFIG_ARM64_PTDUMP */ +#endif /* CONFIG_ARM64_PTDUMP_CORE */ #endif /* __ASM_PTDUMP_H */ diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile index 54bb209..e703fb9 100644 --- a/arch/arm64/mm/Makefile +++ b/arch/arm64/mm/Makefile @@ -3,7 +3,8 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ ioremap.o mmap.o pgd.o mmu.o \ context.o proc.o pageattr.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o -obj-$(CONFIG_ARM64_PTDUMP) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_CORE) += dump.o +obj-$(CONFIG_ARM64_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_KASAN) += kasan_init.o diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index 9c3e75d..29e0838 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -286,7 +286,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) } } -static void walk_pgd(struct pg_state *st, struct mm_struct *mm, +static void __walk_pgd(struct pg_state *st, struct mm_struct *mm, unsigned long start) { pgd_t *pgd = pgd_offset(mm, 0UL); @@ -304,44 +304,32 @@ static void walk_pgd(struct pg_state *st, struct mm_struct *mm, } } -static int ptdump_show(struct seq_file *m, void *v) +void ptdump_walk_pgd(struct seq_file *m, struct ptdump_info *info) { - struct ptdump_info *info = m->private; struct pg_state st = { .seq = m, .marker = info->markers, }; - walk_pgd(&st, info->mm, info->base_addr); + __walk_pgd(&st, info->mm, info->base_addr); note_page(&st, 0, 0, 0); - return 0; } -static int ptdump_open(struct inode *inode, struct file *file) +static void ptdump_initialize(struct ptdump_info *info) { - return single_open(file, ptdump_show, inode->i_private); -} - -static const struct file_operations ptdump_fops = { - .open = ptdump_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -int ptdump_register(struct ptdump_info *info, const char *name) -{ - struct dentry *pe; unsigned i, j; for (i = 0; i < ARRAY_SIZE(pg_level); i++) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; +} - pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); - return pe ? 0 : -ENOMEM; +int ptdump_register(struct ptdump_info *info, const char *name) +{ + ptdump_initialize(info); + return ptdump_debugfs_create(info, name); } static struct ptdump_info kernel_ptdump_info = { diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c new file mode 100644 index 0000000..03e161f --- /dev/null +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -0,0 +1,33 @@ +#include +#include + +#include + +static int ptdump_show(struct seq_file *m, void *v) +{ + struct ptdump_info *info = m->private; + ptdump_walk_pgd(m, info); + return 0; +} + +static int ptdump_open(struct inode *inode, struct file *file) +{ + return single_open(file, ptdump_show, inode->i_private); +} + +static const struct file_operations ptdump_fops = { + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +int ptdump_debugfs_create(struct ptdump_info *info, const char *name) +{ + struct dentry *pe; + pe = debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); + return pe ? 0 : -ENOMEM; + +} + +