From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 330D3C388CF for ; Fri, 9 Oct 2020 19:51:26 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F40E122282 for ; Fri, 9 Oct 2020 19:51:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F40E122282 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EAA15159A284C; Fri, 9 Oct 2020 12:51:25 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=ira.weiny@intel.com; receiver= Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E8767159A284A for ; Fri, 9 Oct 2020 12:51:23 -0700 (PDT) IronPort-SDR: NrQMHTwvR9hCGU59S3GqkUujIjv78bui+qu+sR+RqDTHiijKF4elhGpy1jhjxIWO8wJu8sxjYr bopskpvLpYDw== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="165592004" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="165592004" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 Message-ID-Hash: GK6RYO3UNF7LP2MCXWVEUW4KBXABQSGJ X-Message-ID-Hash: GK6RYO3UNF7LP2MCXWVEUW4KBXABQSGJ X-MailFrom: ira.weiny@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , x86@kernel.org, Dave Hansen , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, kexec@lists.infradead.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, devel@driverdev.osuosl.org, linux-efi@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-aio@kvack.org, io-uring@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-um@lists.infr adead.org, linux-ntfs-dev@lists.sourceforge.net, reiserfs-devel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, cluster-devel@redhat.com, ecryptfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-afs@lists.infradead.org, linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, xen-devel@lists.xenproject.org, linux-cachefs@redhat.com, samba-technical@lists.samba.org, intel-wired-lan@lists.osuosl.org X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1203C71156 for ; Fri, 9 Oct 2020 19:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 853DD223BE for ; Fri, 9 Oct 2020 19:51:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403918AbgJITv1 (ORCPT ); Fri, 9 Oct 2020 15:51:27 -0400 Received: from mga11.intel.com ([192.55.52.93]:40417 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403855AbgJITvJ (ORCPT ); Fri, 9 Oct 2020 15:51:09 -0400 IronPort-SDR: 5U3LdD8JD30Qiz2Xw/HSuDHohT2eTnGXIdf1M2uidm99cBYL2HhALZbtzhz8H9lsGnLyzZh9ts a1oLaFItUWyw== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="162067789" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="162067789" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Cc: Ira Weiny , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , x86@kernel.org, Dave Hansen , Dan Williams , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, kexec@lists.infradead.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, devel@driverdev.osuosl.org, linux-efi@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-aio@kvack.org, io-uring@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-um@lists.infradead.org, linux-ntfs-dev@lists.sourceforge.net, reiserfs-devel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nilfs@vger.kernel.org, cluster-devel@redhat.com, ecryptfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-afs@lists.infradead.org, linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, xen-devel@lists.xenproject.org, linux-cachefs@redhat.com, samba-technical@lists.samba.org, intel-wired-lan@lists.osuosl.org Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: ira.weiny@intel.com Date: Fri, 09 Oct 2020 19:49:41 +0000 Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> List-Id: References: <20201009195033.3208459-1-ira.weiny@intel.com> In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C8C6C6379F for ; Fri, 9 Oct 2020 19:51:21 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C1DA22365; Fri, 9 Oct 2020 19:51:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="SIURVGa3"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="FFxWb98S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C1DA22365 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kQyQC-00019m-LF; Fri, 09 Oct 2020 19:51:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQyQA-00019M-MC; Fri, 09 Oct 2020 19:51:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jypab59Lq0ntK4MKWjIH2b/ZxlCJfqyQrf2fhSavYeQ=; b=SIURVGa3Jd7My/pfOBJOTp5Lhb Lti4uayyxzB+swyutS+mTgCClZ12LMquliLCb+FA9RdA8WY97b7PJJPRfOeDLmRehfTw2fZz0HJNu NoKjgfcJjjIHiG9+eZKNADxPCQA1g7Z3/YIJqqD8qK3B98bBkN8bMH3pfJ19yxrMce1U=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=jypab59Lq0ntK4MKWjIH2b/ZxlCJfqyQrf2fhSavYeQ=; b=FFxWb98SIOLdGXvPhDDeNjzNhr dywMlV9giGTBY0fzNA+UBobxwlAOXQ2W3S8N6joqcj2Y7pA6VxKP44ZUS6mOsPCNlkCMWxYs0Koc4 hr9RisA2XKVjk6NB6KbnknK/D+la+Mu4oc6fKAtOgC3pBtIKjxd7rlQ7T0M4UUXacZdI=; Received: from mga05.intel.com ([192.55.52.43]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kQyQ5-008rgk-Gg; Fri, 09 Oct 2020 19:51:18 +0000 IronPort-SDR: rCPHLtPTMaBrf5URttFBHQgGX4IGfKvZnLQH2QK7NG8Z7i3BzMwDaiACZWqUvKWANKGRgltjC9 aXbteJZGfE9w== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="250225924" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="250225924" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 X-Headers-End: 1kQyQ5-008rgk-Gg Subject: [f2fs-dev] [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80871C8302C for ; Fri, 9 Oct 2020 19:51:43 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E370223FB for ; Fri, 9 Oct 2020 19:51:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E370223FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=driverdev-devel-bounces@linuxdriverproject.org Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0606F87636; Fri, 9 Oct 2020 19:51:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 97CpbDK8n60M; Fri, 9 Oct 2020 19:51:42 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 22B0087726; Fri, 9 Oct 2020 19:51:42 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id F2CD71BF2F3 for ; Fri, 9 Oct 2020 19:51:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id EDCA220349 for ; Fri, 9 Oct 2020 19:51:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kPktZqXtJ0jO for ; Fri, 9 Oct 2020 19:51:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by silver.osuosl.org (Postfix) with ESMTPS id 001AE2E2E1 for ; Fri, 9 Oct 2020 19:51:07 +0000 (UTC) IronPort-SDR: NGRFe0++l52bUxPLI7Hfi71dqWz746C9Y9pdCG6zhkbooLheFU9zIG5cAaAOqmhErqtmE+kXa3 YvB4Udar0LEA== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="164743644" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="164743644" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 X-BeenThere: driverdev-devel@linuxdriverproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , linux-mm@kvack.org, target-devel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kselftest@vger.kernel.org, samba-technical@lists.samba.org, 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB2DC433DF for ; Sat, 10 Oct 2020 01:53:19 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 521102225B for ; Sat, 10 Oct 2020 01:53:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 521102225B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C7SdR4Xh9zDqjd for ; Sat, 10 Oct 2020 12:53:15 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=intel.com (client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=ira.weiny@intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C7Jbf4c2HzDqbf; Sat, 10 Oct 2020 06:51:09 +1100 (AEDT) IronPort-SDR: k9CCtxvPFiVBAA9TxKf0R2JQ0AUH/ywKTPNIKq7ka6m5Edz2eobUtZyh7Dxcnvy56hiZhH5g1B WxRLG0wUpxgw== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="162067788" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="162067788" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 10 Oct 2020 12:49:24 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CCE6C56201 for ; Fri, 9 Oct 2020 19:52:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 905D2223FB for ; Fri, 9 Oct 2020 19:52:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uQ2Q5DOa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 905D2223FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fv2IWmg3jMsUOZjCDgfFEiIvP4Rz32AUhYJJjdUWnUY=; b=uQ2Q5DOa+DalwmsxFDQfNXbUf JctJMuQbWcmSHKmWey00wxDFKbV4/ke1yFCR2fZwe8gr+dEHmbYhAEWs7SrAAToaJ7A8W4USHJxs7 QJVGRBJh7Os1BCRKzZ/dfEdSHdAcnVm8o2o66Hozghck9LEjhSWzp7BPLbn/K5EPuaxnZyQH6SJR+ 7BMt3lcK8eRkktSfRG7Fn3hIynY4r9nMVT32tPXf8+3tQJwcvcxZHIQSeIgX3lfyQP8diozGM0/J7 ZJSUfXYbTx5EvNJwVb4axrf1NwDwxChWcjMPosFdgZjRl7EjtslwQuS59YdKfjKZsmqcB0+4dSaia WaCW9PavA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQyQL-0000Z4-1d; Fri, 09 Oct 2020 19:51:29 +0000 Received: from mga02.intel.com ([134.134.136.20]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQyQ0-0000OI-I3; Fri, 09 Oct 2020 19:51:20 +0000 IronPort-SDR: u0yeyfBdpIaWoyphXcSWflz1J7SF8uaF6Ry0BPwgTq6eSZcsnSP+WyBOI3DcnYtmgrkkwi5YRD +xdTC+2nEMyQ== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="152450784" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="152450784" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_155108_750450_CD955E53 X-CRM114-Status: GOOD ( 23.86 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E3B9C352B8 for ; Fri, 9 Oct 2020 19:51:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3A6C222282 for ; Fri, 9 Oct 2020 19:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A6C222282 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4CC7C6EDA6; Fri, 9 Oct 2020 19:51:10 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2BA736EDA7; Fri, 9 Oct 2020 19:51:08 +0000 (UTC) IronPort-SDR: cOWeRMbknWILT93vFCMYY+7xAm/2WF2Q8HBEcWlHfJPjh+8GfoGopFJD2PIEm/i987JxVpIILW X1SOBZZ4gCKQ== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="145397241" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="145397241" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB9BC388F9 for ; Fri, 9 Oct 2020 19:51:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFE1D22282 for ; Fri, 9 Oct 2020 19:51:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFE1D22282 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 40BA46EDA3; Fri, 9 Oct 2020 19:51:10 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2BA736EDA7; Fri, 9 Oct 2020 19:51:08 +0000 (UTC) IronPort-SDR: cOWeRMbknWILT93vFCMYY+7xAm/2WF2Q8HBEcWlHfJPjh+8GfoGopFJD2PIEm/i987JxVpIILW X1SOBZZ4gCKQ== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="145397241" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="145397241" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , ceph-devel@vger.kernel.org, drbd-dev@lists.linbit.com, devel@driverdev.osuosl.org, linux-cifs@vger.kernel.org, linux-nilfs@vger.kernel.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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E10A6C04EBE for ; Fri, 9 Oct 2020 21:11:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9EE1222C3 for ; Fri, 9 Oct 2020 21:11:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9EE1222C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EE586EE36; Fri, 9 Oct 2020 21:10:43 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2BA736EDA7; Fri, 9 Oct 2020 19:51:08 +0000 (UTC) IronPort-SDR: cOWeRMbknWILT93vFCMYY+7xAm/2WF2Q8HBEcWlHfJPjh+8GfoGopFJD2PIEm/i987JxVpIILW X1SOBZZ4gCKQ== X-IronPort-AV: E=McAfee;i="6000,8403,9769"; a="145397241" X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="145397241" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:07 -0700 IronPort-SDR: q86t8daZNt+V6d8RNukEYKSCMEs+oCo1U1vd6Yq1DOlnqrvHVUOvZ3CGMAsBzz1plldsK41yyY 6uUXC42AACQg== X-IronPort-AV: E=Sophos;i="5.77,355,1596524400"; d="scan'208";a="317146961" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2020 12:51:06 -0700 From: ira.weiny@intel.com To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.28.0.rc0.12.gb6a658bd00c9 In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 09 Oct 2020 21:10:40 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx From mboxrd@z Thu Jan 1 00:00:00 1970 From: ira.weiny@intel.com Date: Fri, 9 Oct 2020 12:49:41 -0700 Subject: [Intel-wired-lan] [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> Message-ID: <20201009195033.3208459-7-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: intel-wired-lan@osuosl.org List-ID: From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: From: ira.weiny@intel.com Subject: [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging Date: Fri, 9 Oct 2020 12:49:41 -0700 Message-Id: <20201009195033.3208459-7-ira.weiny@intel.com> In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Cc: Juri Lelli , 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 , dri-devel@lists.freedesktop.org, Ben Segall , 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 , 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 , 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 , xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, Fenghua Yu , 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 , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, Dan Williams , Dietmar Eggemann , 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 From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec From mboxrd@z Thu Jan 1 00:00:00 1970 From: ira.weiny@intel.com Date: Fri, 9 Oct 2020 12:49:41 -0700 Subject: [Cluster-devel] [PATCH RFC PKS/PMEM 06/58] kmap: Introduce k[un]map_thread debugging In-Reply-To: <20201009195033.3208459-1-ira.weiny@intel.com> References: <20201009195033.3208459-1-ira.weiny@intel.com> Message-ID: <20201009195033.3208459-7-ira.weiny@intel.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Ira Weiny 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 Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Signed-off-by: Ira Weiny --- 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 + +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 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 + +#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