From: ira.weiny@intel.com To: Andrew Morton <akpm@linux-foundation.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org> Cc: Juri Lelli <juri.lelli@redhat.com>, linux-aio@kvack.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-mmc@vger.kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, dri-devel@lists.freedesktop.org, Ben Segall <bsegall@google.com>, linux-mm@kvack.org, target-devel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kselftest@vger.kernel.org, samba-technical@lists.samba.org, Ira Weiny <ira.weiny@intel.com>, ceph-devel@vger.kernel.org, drbd-dev@lists.linbit.com, devel@driverdev.osuosl.org, linux-cifs@vger.kernel.org, linux-nilfs@vger.kernel.org, Vincent Guittot <vincent.guittot@linaro.org>, linux-scsi@vger.kernel.org, linux-nvdimm@lists.01.org, linux-rdma@vger.kernel.org, x86@kernel.org, amd-gfx@lists.freedesktop.org, io-uring@vger.kernel.org, cluster-devel@redhat.com, linux-cachefs@redhat.com, intel-wired-lan@lists.osuosl.org, Mel Gorman <mgorman@suse.de>, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu <fenghua.yu@intel.com>, linux-afs@lists.infradead.org, linux-um@lists.infradead.org, intel-gfx@lists.freedesktop.org, ecryptfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, reiserfs-devel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>, linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams <dan.j.williams@intel.com>, Dietmar Eggemann <dietmar.eggemann@arm.com>, linux-nfs@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, netdev@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-btrfs@vger.kernel.org Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 09 Oct 2020 19:49:41 +0000 Message-ID: <20201009195033.3208459-7-ira.weiny@intel.com> (raw) In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> From: Ira Weiny <ira.weiny@intel.com> Most kmap() callers use the map within a single thread and have no need for the protection domain to be enabled globally. To differentiate these kmap users, new k[un]map_thread() calls were introduced which are thread local. To aid in debugging the new use of kmap_thread(), add a reference count, a check on that count, and tracing to ID where mapping errors occur. Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Vincent Guittot <vincent.guittot@linaro.org> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Ben Segall <bsegall@google.com> Cc: Mel Gorman <mgorman@suse.de> Signed-off-by: Ira Weiny <ira.weiny@intel.com> --- include/linux/highmem.h | 5 +++ include/linux/sched.h | 5 +++ include/trace/events/kmap_thread.h | 56 ++++++++++++++++++++++++++++++ init/init_task.c | 3 ++ kernel/fork.c | 15 ++++++++ lib/Kconfig.debug | 8 +++++ mm/debug.c | 23 ++++++++++++ 7 files changed, 115 insertions(+) create mode 100644 include/trace/events/kmap_thread.h diff --git a/include/linux/highmem.h b/include/linux/highmem.h index ef7813544719..22d1c000802e 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -247,6 +247,10 @@ static inline void kunmap(struct page *page) __kunmap(page, true); } +#ifdef CONFIG_DEBUG_KMAP_THREAD +void *kmap_thread(struct page *page); +void kunmap_thread(struct page *page); +#else static inline void *kmap_thread(struct page *page) { return __kmap(page, false); @@ -255,6 +259,7 @@ static inline void kunmap_thread(struct page *page) { __kunmap(page, false); } +#endif /* * Prevent people trying to call kunmap_atomic() as if it were kunmap() diff --git a/include/linux/sched.h b/include/linux/sched.h index 25d97ab6c757..4627ea4a49e6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1318,6 +1318,11 @@ struct task_struct { #ifdef CONFIG_ZONE_DEVICE_ACCESS_PROTECTION unsigned int dev_page_access_ref; #endif + +#ifdef CONFIG_DEBUG_KMAP_THREAD + unsigned int kmap_thread_cnt; +#endif + /* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct. diff --git a/include/trace/events/kmap_thread.h b/include/trace/events/kmap_thread.h new file mode 100644 index 000000000000..e7143cfe0daf --- /dev/null +++ b/include/trace/events/kmap_thread.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ + +/* + * Copyright (c) 2020 Intel Corporation. All rights reserved. + * + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM kmap_thread + +#if !defined(_TRACE_KMAP_THREAD_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_KMAP_THREAD_H + +#include <linux/tracepoint.h> + +DECLARE_EVENT_CLASS(kmap_thread_template, + TP_PROTO(struct task_struct *tsk, struct page *page, + void *caller_addr, int cnt), + TP_ARGS(tsk, page, caller_addr, cnt), + + TP_STRUCT__entry( + __field(int, pid) + __field(struct page *, page) + __field(void *, caller_addr) + __field(int, cnt) + ), + + TP_fast_assign( + __entry->pid = tsk->pid; + __entry->page = page; + __entry->caller_addr = caller_addr; + __entry->cnt = cnt; + ), + + TP_printk("PID %d; (%d) %pS %p", + __entry->pid, + __entry->cnt, + __entry->caller_addr, + __entry->page + ) +); + +DEFINE_EVENT(kmap_thread_template, kmap_thread, + TP_PROTO(struct task_struct *tsk, struct page *page, + void *caller_addr, int cnt), + TP_ARGS(tsk, page, caller_addr, cnt)); + +DEFINE_EVENT(kmap_thread_template, kunmap_thread, + TP_PROTO(struct task_struct *tsk, struct page *page, + void *caller_addr, int cnt), + TP_ARGS(tsk, page, caller_addr, cnt)); + + +#endif /* _TRACE_KMAP_THREAD_H */ + +#include <trace/define_trace.h> diff --git a/init/init_task.c b/init/init_task.c index 9b39f25de59b..19f09965eb34 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -212,6 +212,9 @@ struct task_struct init_task #ifdef CONFIG_ZONE_DEVICE_ACCESS_PROTECTION .dev_page_access_ref = 0, #endif +#ifdef CONFIG_DEBUG_KMAP_THREAD + .kmap_thread_cnt = 0, +#endif }; EXPORT_SYMBOL(init_task); diff --git a/kernel/fork.c b/kernel/fork.c index b6a3ee328a89..2c66e49b7614 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -722,6 +722,17 @@ static inline void put_signal_struct(struct signal_struct *sig) free_signal_struct(sig); } +#ifdef CONFIG_DEBUG_KMAP_THREAD +static void check_outstanding_kmap_thread(struct task_struct *tsk) +{ + if (tsk->kmap_thread_cnt) + pr_warn(KERN_ERR "WARNING: PID %d; Failed to kunmap_thread() [cnt %d]\n", + tsk->pid, tsk->kmap_thread_cnt); +} +#else +static void check_outstanding_kmap_thread(struct task_struct *tsk) { } +#endif + void __put_task_struct(struct task_struct *tsk) { WARN_ON(!tsk->exit_state); @@ -734,6 +745,7 @@ void __put_task_struct(struct task_struct *tsk) exit_creds(tsk); delayacct_tsk_free(tsk); put_signal_struct(tsk->signal); + check_outstanding_kmap_thread(tsk); if (!profile_handoff_task(tsk)) free_task(tsk); @@ -943,6 +955,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node) #endif #ifdef CONFIG_ZONE_DEVICE_ACCESS_PROTECTION tsk->dev_page_access_ref = 0; +#endif +#ifdef CONFIG_DEBUG_KMAP_THREAD + tsk->kmap_thread_cnt = 0; #endif return tsk; diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f015c09ba5a1..6507b43d5b0c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -858,6 +858,14 @@ config DEBUG_HIGHMEM This option enables additional error checking for high memory systems. Disable for production systems. +config DEBUG_KMAP_THREAD + bool "Kmap debugging" + depends on DEBUG_KERNEL + help + This option enables additional error checking for kernel mapping code + specifically the k[un]map_thread() calls. Disable for production + systems. + config HAVE_DEBUG_STACKOVERFLOW bool diff --git a/mm/debug.c b/mm/debug.c index ca8d1cacdecc..68d186f3570e 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -320,3 +320,26 @@ void page_init_poison(struct page *page, size_t size) } EXPORT_SYMBOL_GPL(page_init_poison); #endif /* CONFIG_DEBUG_VM */ + +#define CREATE_TRACE_POINTS +#include <trace/events/kmap_thread.h> + +#ifdef CONFIG_DEBUG_KMAP_THREAD +void *kmap_thread(struct page *page) +{ + trace_kmap_thread(current, page, __builtin_return_address(0), + current->kmap_thread_cnt); + current->kmap_thread_cnt++; + return __kmap(page, false); +} +EXPORT_SYMBOL_GPL(kmap_thread); + +void kunmap_thread(struct page *page) +{ + __kunmap(page, false); + current->kmap_thread_cnt--; + trace_kunmap_thread(current, page, __builtin_return_address(0), + current->kmap_thread_cnt); +} +EXPORT_SYMBOL_GPL(kunmap_thread); +#endif -- 2.28.0.rc0.12.gb6a658bd00c9
next prev parent reply index Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-09 19:49 [PATCH RFC PKS/PMEM 00/58] PMEM: Introduce stray write protection for PMEM ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 01/58] x86/pks: Add a global pkrs option ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 02/58] x86/pks/test: Add testing for global option ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 03/58] memremap: Add zone device access protection ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 04/58] kmap: Add stray access protection for device pages ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 05/58] kmap: Introduce k[un]map_thread ira.weiny 2020-11-10 1:13 ` Thomas Gleixner 2020-11-10 4:59 ` Ira Weiny 2020-11-10 8:48 ` Thomas Gleixner 2020-10-09 19:49 ` ira.weiny [this message] 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 07/58] drivers/drbd: Utilize new kmap_thread() ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 08/58] drivers/firmware_loader: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 09/58] drivers/gpu: " ira.weiny 2020-10-09 22:03 ` Daniel Vetter 2020-10-10 23:01 ` Ira Weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 10/58] drivers/rdma: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 11/58] drivers/net: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 12/58] fs/afs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 13/58] fs/btrfs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 14/58] fs/cifs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 15/58] fs/ecryptfs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 16/58] fs/gfs2: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 17/58] fs/nilfs2: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 18/58] fs/hfs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 19/58] fs/hfsplus: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 20/58] fs/jffs2: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 21/58] fs/nfs: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 22/58] fs/f2fs: " ira.weiny 2020-10-09 21:34 ` Eric Biggers 2020-10-10 0:39 ` Matthew Wilcox 2020-10-10 1:30 ` Eric Biggers 2020-10-12 6:56 ` Ira Weiny 2020-10-12 16:19 ` Eric Biggers 2020-10-12 16:28 ` Dave Hansen 2020-10-12 16:44 ` Matthew Wilcox 2020-10-12 19:53 ` Ira Weiny 2020-10-12 20:02 ` Matthew Wilcox 2020-10-12 23:31 ` Ira Weiny 2020-10-10 2:43 ` James Bottomley 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 23/58] fs/fuse: " ira.weiny 2020-10-09 19:49 ` [PATCH RFC PKS/PMEM 24/58] fs/freevxfs: " ira.weiny 2020-10-13 11:25 ` Christoph Hellwig 2020-10-13 20:52 ` Ira Weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 25/58] fs/reiserfs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 26/58] fs/zonefs: " ira.weiny 2020-10-12 2:30 ` Damien Le Moal 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 27/58] fs/ubifs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 28/58] fs/cachefiles: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 29/58] fs/ntfs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 30/58] fs/romfs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 31/58] fs/vboxsf: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 32/58] fs/hostfs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 33/58] fs/cramfs: " ira.weiny 2020-10-13 18:36 ` Nicolas Pitre 2020-10-13 18:44 ` Dan Williams 2020-10-13 19:36 ` Matthew Wilcox 2020-10-13 19:41 ` Dan Williams 2020-10-13 20:01 ` Al Viro 2020-10-13 20:50 ` Ira Weiny 2020-10-13 20:45 ` Ira Weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 34/58] fs/erofs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 35/58] fs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 36/58] fs/ext2: Use ext2_put_page ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 37/58] fs/ext2: Utilize new kmap_thread() ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 38/58] fs/isofs: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 39/58] fs/jffs2: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 40/58] net: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 41/58] drivers/target: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 42/58] drivers/scsi: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 43/58] drivers/mmc: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 44/58] drivers/xen: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 45/58] drivers/firmware: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 46/58] drives/staging: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 47/58] drivers/mtd: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 48/58] drivers/md: " ira.weiny 2020-10-10 2:20 ` Coly Li 2020-10-12 5:28 ` Ira Weiny 2020-10-12 7:40 ` Coly Li 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 49/58] drivers/misc: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 50/58] drivers/android: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 51/58] kernel: " ira.weiny 2020-10-10 3:43 ` Eric W. Biederman 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 52/58] mm: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 53/58] lib: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 54/58] powerpc: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 55/58] samples: " ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 56/58] dax: Stray access protection for dax_direct_access() ira.weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 57/58] nvdimm/pmem: Stray access protection for pmem->virt_addr ira.weiny 2020-10-10 2:53 ` John Hubbard 2020-10-12 5:52 ` Ira Weiny 2020-10-09 19:50 ` [PATCH RFC PKS/PMEM 58/58] [dax|pmem]: Enable stray access protection ira.weiny 2020-10-10 11:36 ` [PATCH RFC PKS/PMEM 10/58] drivers/rdma: Utilize new kmap_thread() Bernard Metzler 2020-10-12 4:47 ` Ira Weiny
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20201009195033.3208459-7-ira.weiny@intel.com \ --to=ira.weiny@intel.com \ --cc=akpm@linux-foundation.org \ --cc=amd-gfx@lists.freedesktop.org \ --cc=bp@alien8.de \ --cc=bpf@vger.kernel.org \ --cc=bsegall@google.com \ --cc=ceph-devel@vger.kernel.org \ --cc=cluster-devel@redhat.com \ --cc=dan.j.williams@intel.com \ --cc=dave.hansen@linux.intel.com \ --cc=devel@driverdev.osuosl.org \ --cc=dietmar.eggemann@arm.com \ --cc=drbd-dev@lists.linbit.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=ecryptfs@vger.kernel.org \ --cc=fenghua.yu@intel.com \ --cc=intel-gfx@lists.freedesktop.org \ --cc=intel-wired-lan@lists.osuosl.org \ --cc=io-uring@vger.kernel.org \ --cc=juri.lelli@redhat.com \ --cc=kexec@lists.infradead.org \ --cc=kvm@vger.kernel.org \ --cc=linux-afs@lists.infradead.org \ --cc=linux-aio@kvack.org \ --cc=linux-bcache@vger.kernel.org \ --cc=linux-block@vger.kernel.org \ --cc=linux-btrfs@vger.kernel.org \ --cc=linux-cachefs@redhat.com \ --cc=linux-cifs@vger.kernel.org \ --cc=linux-doc@vger.kernel.org \ --cc=linux-efi@vger.kernel.org \ --cc=linux-erofs@lists.ozlabs.org \ --cc=linux-ext4@vger.kernel.org \ --cc=linux-f2fs-devel@lists.sourceforge.net \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-kselftest@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=linux-mmc@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=linux-nfs@vger.kernel.org \ --cc=linux-nilfs@vger.kernel.org \ --cc=linux-ntfs-dev@lists.sourceforge.net \ --cc=linux-nvdimm@lists.01.org \ --cc=linux-rdma@vger.kernel.org \ --cc=linux-scsi@vger.kernel.org \ --cc=linux-um@lists.infradead.org \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=luto@kernel.org \ --cc=mgorman@suse.de \ --cc=mingo@redhat.com \ --cc=netdev@vger.kernel.org \ --cc=peterz@infradead.org \ --cc=reiserfs-devel@vger.kernel.org \ --cc=rostedt@goodmis.org \ --cc=samba-technical@lists.samba.org \ --cc=target-devel@vger.kernel.org \ --cc=tglx@linutronix.de \ --cc=vincent.guittot@linaro.org \ --cc=x86@kernel.org \ --cc=xen-devel@lists.xenproject.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Target-devel archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/target-devel/0 target-devel/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 target-devel target-devel/ https://lore.kernel.org/target-devel \ target-devel@vger.kernel.org public-inbox-index target-devel Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.target-devel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git