linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] export symbols for process and memory related functions
@ 2023-06-14  3:20 Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 1/3] kernel : process fork/exit: export symbol for fork/exit tracing functions Wei Chin Tsai
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Wei Chin Tsai @ 2023-06-14  3:20 UTC (permalink / raw)
  To: linux-kernel, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng, Wei Chin Tsai,
	linux-arm-kernel, linux-mediatek


v1 -> v2: Add export symbol for "smap_gather_stats" and "arch_vma_name".
	  Modify the mbraink_main.c class and device register flow.

v1:       Export symbol for "sched_process_fork" and "sched_process_exit".
          attached the mediatek_mbraink data collect driver which uses
          these export symbols. 

Wei Chin Tsai (3):
  kernel : process fork/exit: export symbol for fork/exit tracing
    functions
  memory: export symbols for memory related functions
  misc : mediatek_mbraink : Collect the system process and memory data

 arch/arm/kernel/process.c                     |   1 +
 drivers/misc/mediatek_mbraink/Kconfig         |  15 +
 drivers/misc/mediatek_mbraink/Makefile        |   5 +
 drivers/misc/mediatek_mbraink/mbraink_data.c  | 417 ++++++++++++++++++
 drivers/misc/mediatek_mbraink/mbraink_data.h  |  66 +++
 .../mbraink_ioctl_struct_define.h             |  44 ++
 drivers/misc/mediatek_mbraink/mbraink_main.c  | 239 ++++++++++
 drivers/misc/mediatek_mbraink/mbraink_main.h  |  36 ++
 fs/proc/task_mmu.c                            |   5 +-
 kernel/exit.c                                 |   2 +
 kernel/fork.c                                 |   2 +
 kernel/signal.c                               |   1 +
 12 files changed, 831 insertions(+), 2 deletions(-)
 create mode 100644 drivers/misc/mediatek_mbraink/Kconfig
 create mode 100644 drivers/misc/mediatek_mbraink/Makefile
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.c
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.h
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.c
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.h

-- 
2.18.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 1/3] kernel : process fork/exit: export symbol for fork/exit tracing functions
  2023-06-14  3:20 [PATCH v2 0/3] export symbols for process and memory related functions Wei Chin Tsai
@ 2023-06-14  3:20 ` Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data Wei Chin Tsai
  2 siblings, 0 replies; 17+ messages in thread
From: Wei Chin Tsai @ 2023-06-14  3:20 UTC (permalink / raw)
  To: linux-kernel, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng, Wei Chin Tsai,
	linux-arm-kernel, linux-mediatek

In ths Patch, we export symbols for two functions of
"sched_process_fork" and "sched_process_exit" for
process statistics. During the system running,
some process will run in a second and then terminate.
We hope that we can capture those processes' jiffies
information for system performance analysis.

Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
---
 kernel/exit.c | 2 ++
 kernel/fork.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/kernel/exit.c b/kernel/exit.c
index edb50b4c9972..410a3de14e09 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -81,6 +81,8 @@
  */
 static unsigned int oops_limit = 10000;
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(sched_process_exit);
+
 #ifdef CONFIG_SYSCTL
 static struct ctl_table kern_exit_table[] = {
 	{
diff --git a/kernel/fork.c b/kernel/fork.c
index f81985dcc4bd..8fba356fb7c2 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -142,6 +142,8 @@ DEFINE_PER_CPU(unsigned long, process_counts) = 0;
 
 __cacheline_aligned DEFINE_RWLOCK(tasklist_lock);  /* outer */
 
+EXPORT_TRACEPOINT_SYMBOL_GPL(sched_process_fork);
+
 #ifdef CONFIG_PROVE_RCU
 int lockdep_tasklist_lock_is_held(void)
 {
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  3:20 [PATCH v2 0/3] export symbols for process and memory related functions Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 1/3] kernel : process fork/exit: export symbol for fork/exit tracing functions Wei Chin Tsai
@ 2023-06-14  3:20 ` Wei Chin Tsai
  2023-06-14  7:16   ` Russell King (Oracle)
                     ` (3 more replies)
  2023-06-14  3:20 ` [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data Wei Chin Tsai
  2 siblings, 4 replies; 17+ messages in thread
From: Wei Chin Tsai @ 2023-06-14  3:20 UTC (permalink / raw)
  To: linux-kernel, Russell King, Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng, Wei Chin Tsai,
	linux-arm-kernel, linux-fsdevel, linux-mediatek

In this patch, we modified 3 files and export symbols
for 2 functions.
Export symbols for "smap_gather_stats" functions so that
user can have an idea for each user process memory's usage.
Export symbols for "arch_vma_name" functions so that
user can know the heap usage for each user process.
According to these two information, user can do the memory
statistics and anaysis.

Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
---
 arch/arm/kernel/process.c | 1 +
 fs/proc/task_mmu.c        | 5 +++--
 kernel/signal.c           | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 0e8ff85890ad..df91412a1069 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -343,6 +343,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)
 {
 	return is_gate_vma(vma) ? "[vectors]" : NULL;
 }
+EXPORT_SYMBOL_GPL(arch_vma_name);
 
 /* If possible, provide a placement hint at a random offset from the
  * stack for the sigpage and vdso pages.
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 6259dd432eeb..814d7829a20b 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -773,8 +773,8 @@ static const struct mm_walk_ops smaps_shmem_walk_ops = {
  *
  * Use vm_start of @vma as the beginning address if @start is 0.
  */
-static void smap_gather_stats(struct vm_area_struct *vma,
-		struct mem_size_stats *mss, unsigned long start)
+void smap_gather_stats(struct vm_area_struct *vma,
+		       struct mem_size_stats *mss, unsigned long start)
 {
 	const struct mm_walk_ops *ops = &smaps_walk_ops;
 
@@ -809,6 +809,7 @@ static void smap_gather_stats(struct vm_area_struct *vma,
 	else
 		walk_page_range(vma->vm_mm, start, vma->vm_end, ops, mss);
 }
+EXPORT_SYMBOL_GPL(smap_gather_stats);
 
 #define SEQ_PUT_DEC(str, val) \
 		seq_put_decimal_ull_width(m, str, (val) >> 10, 8)
diff --git a/kernel/signal.c b/kernel/signal.c
index b5370fe5c198..a1abe77fcdc3 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct vm_area_struct *vma)
 {
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(arch_vma_name);
 
 static inline void siginfo_buildtime_checks(void)
 {
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data
  2023-06-14  3:20 [PATCH v2 0/3] export symbols for process and memory related functions Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 1/3] kernel : process fork/exit: export symbol for fork/exit tracing functions Wei Chin Tsai
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
@ 2023-06-14  3:20 ` Wei Chin Tsai
  2023-06-14 11:14   ` AngeloGioacchino Del Regno
  2 siblings, 1 reply; 17+ messages in thread
From: Wei Chin Tsai @ 2023-06-14  3:20 UTC (permalink / raw)
  To: linux-kernel, Arnd Bergmann, Greg Kroah-Hartman,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng, Wei Chin Tsai,
	linux-arm-kernel, linux-mediatek

In this patch, we add the mediatek_mbrain folder
including 7 files. Apart from Makefile and Kconfig,
the aim of the other 5 files is to collect the
process fork/exit tracing data and process memory
pss, uss, rss, swap, and heap usage.
User could use these kind of data to do the system
analysis, and detect the unexpected process/memory
issues. Furthermore, user can make use of process
memory data to detect the memory leak issues.
From memory heap aspect, user could know the java
and native layer heap usage.
Also, user can capture those processes which run
in a second and then terminate immediately by add
the hook functions in "sched_process_fork" and
"sched_process_exit".

Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
---
 drivers/misc/mediatek_mbraink/Kconfig         |  15 +
 drivers/misc/mediatek_mbraink/Makefile        |   5 +
 drivers/misc/mediatek_mbraink/mbraink_data.c  | 417 ++++++++++++++++++
 drivers/misc/mediatek_mbraink/mbraink_data.h  |  66 +++
 .../mbraink_ioctl_struct_define.h             |  44 ++
 drivers/misc/mediatek_mbraink/mbraink_main.c  | 239 ++++++++++
 drivers/misc/mediatek_mbraink/mbraink_main.h  |  36 ++
 7 files changed, 822 insertions(+)
 create mode 100644 drivers/misc/mediatek_mbraink/Kconfig
 create mode 100644 drivers/misc/mediatek_mbraink/Makefile
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.c
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.h
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.c
 create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.h

diff --git a/drivers/misc/mediatek_mbraink/Kconfig b/drivers/misc/mediatek_mbraink/Kconfig
new file mode 100644
index 000000000000..4a96059e4c57
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/Kconfig
@@ -0,0 +1,15 @@
+config MTK_MBRAINK
+	tristate "MTK MBRAINK support"
+	help
+          MBRAINK is a MediaTek in-house kernel module which can
+          communicate with android MBrain.
+          Set Y to enable this feature.
+          If unsure, Set N to stay with legancy feature.
+
+config MTK_MBRAINK_EXPORT_DEPENDED
+	tristate "MTK MBRAINK EXPORT DEPENDED support"
+	help
+	  MBRAINK EXPORT DEPENDED option which
+	  needs to export extra function in upstram kernel.
+	  Set Y to enable this feature.
+	  If unsure, Set N to stay with legancy feature.
diff --git a/drivers/misc/mediatek_mbraink/Makefile b/drivers/misc/mediatek_mbraink/Makefile
new file mode 100644
index 000000000000..8d75b41a8097
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/Makefile
@@ -0,0 +1,5 @@
+subdir-ccflags-y += -Wformat
+
+obj-${CONFIG_MTK_MBRAINK} += mtk_mbraink.o
+
+mtk_mbraink-objs += mbraink_data.o mbraink_main.o
diff --git a/drivers/misc/mediatek_mbraink/mbraink_data.c b/drivers/misc/mediatek_mbraink/mbraink_data.c
new file mode 100644
index 000000000000..dad03124820a
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/mbraink_data.c
@@ -0,0 +1,417 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/rtc.h>
+#include <linux/sched/clock.h>
+#include <linux/kernel.h>
+#include <linux/uaccess.h>
+#include <linux/cdev.h>
+#include <linux/proc_fs.h>
+#include <linux/sched/signal.h>
+#include <linux/pid_namespace.h>
+#include <linux/mm.h>
+#include <linux/sched/mm.h>
+#include <linux/sched/task.h>
+#include <linux/pagewalk.h>
+#include <linux/shmem_fs.h>
+#include <linux/pagemap.h>
+#include <linux/mempolicy.h>
+#include <linux/rmap.h>
+#include <linux/sched/cputime.h>
+#include <linux/math64.h>
+#include <linux/refcount.h>
+#include <linux/ctype.h>
+#include <linux/stddef.h>
+#include <linux/cred.h>
+#include <linux/spinlock.h>
+#include <linux/rtc.h>
+#include <linux/sched/clock.h>
+#include <trace/events/sched.h>
+#include <linux/mm_inline.h>
+
+#include "mbraink_data.h"
+
+/*spinlock for mbraink tracing pidlist*/
+static DEFINE_SPINLOCK(tracing_pidlist_lock);
+/*Please make sure that tracing pidlist is protected by spinlock*/
+struct mbraink_tracing_pidlist mbraink_tracing_pidlist_data[MAX_TRACE_NUM];
+
+#if IS_ENABLED(CONFIG_ANON_VMA_NAME)
+struct anon_vma_name *mbraink_anon_vma_name(struct vm_area_struct *vma)
+{
+	if (vma->vm_file)
+		return NULL;
+
+	return vma->anon_name;
+}
+#else
+struct anon_vma_name *mbraink_anon_vma_name(struct vm_area_struct *vma)
+{
+	return NULL;
+}
+#endif
+
+void mbraink_map_vma(struct vm_area_struct *vma, unsigned long cur_pss,
+		     unsigned long *native_heap, unsigned long *java_heap)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	const char *name = NULL;
+
+	if (vma->vm_file)
+		return;
+	/*
+	 * Print the dentry name for named mappings, and a
+	 * special [heap] marker for the heap:
+	 */
+
+	if (vma->vm_ops && vma->vm_ops->name) {
+		name = vma->vm_ops->name(vma);
+		if (name) {
+			if (strncmp(name, "dev/ashmem/libc malloc", 23) == 0)
+				(*native_heap) += cur_pss;
+			return;
+		}
+	}
+
+	name = arch_vma_name(vma);
+	if (!name) {
+		struct anon_vma_name *anon_name;
+
+		if (!mm)
+			return;
+
+		if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
+			(*native_heap) += cur_pss;
+			return;
+		}
+
+		if (vma->vm_start <= vma->vm_mm->start_stack &&
+		    vma->vm_end >= vma->vm_mm->start_stack)
+			return;
+
+		anon_name = mbraink_anon_vma_name(vma);
+		if (anon_name) {
+			if (strstr(anon_name->name, "scudo"))
+				(*native_heap) += cur_pss;
+			else if (strstr(anon_name->name, "libc_malloc"))
+				(*native_heap) += cur_pss;
+			else if (strstr(anon_name->name, "GWP-ASan"))
+				(*native_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-alloc space"))
+				(*java_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-main space"))
+				(*java_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-large object space"))
+				(*java_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-free list large object space"))
+				(*java_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-non moving space"))
+				(*java_heap) += cur_pss;
+			else if (strstr(anon_name->name, "dalvik-zygote space"))
+				(*java_heap) += cur_pss;
+		}
+	}
+}
+
+void mbraink_get_process_memory_info(pid_t current_pid,
+				     struct mbraink_process_memory_data *process_memory_buffer)
+{
+	struct task_struct *t = NULL;
+	struct mm_struct *mm = NULL;
+	struct vm_area_struct *vma = NULL;
+	struct mem_size_stats mss;
+	unsigned short pid_count = 0;
+	unsigned long pss, uss, rss, swap, cur_pss;
+	unsigned long java_heap = 0, native_heap = 0;
+	struct vma_iterator vmi;
+
+	memset(process_memory_buffer, 0, sizeof(struct mbraink_process_memory_data));
+	process_memory_buffer->pid = 0;
+
+	read_lock(&tasklist_lock);
+	for_each_process(t) {
+		if (t->pid <= current_pid)
+			continue;
+
+		mm = t->mm;
+		if (mm) {
+			java_heap = 0;
+			native_heap = 0;
+			pid_count = process_memory_buffer->pid_count;
+
+			process_memory_buffer->drv_data[pid_count].pid =
+				(unsigned short)(t->pid);
+			process_memory_buffer->pid =
+				(unsigned short)(t->pid);
+
+			memset(&mss, 0, sizeof(mss));
+			get_task_struct(t);
+			mmgrab(mm);
+			read_unlock(&tasklist_lock);
+			mmap_read_lock(mm);
+			vma_iter_init(&vmi, mm, 0);
+			for_each_vma(vmi, vma) {
+				cur_pss = (unsigned long)(mss.pss >> PSS_SHIFT);
+				smap_gather_stats(vma, &mss, 0);
+				cur_pss =
+					((unsigned long)(mss.pss >> PSS_SHIFT)) - cur_pss;
+				cur_pss = cur_pss / 1024;
+				mbraink_map_vma(vma, cur_pss, &native_heap, &java_heap);
+			}
+			mmap_read_unlock(mm);
+			read_lock(&tasklist_lock);
+			mmdrop(mm);
+			put_task_struct(t);
+
+			pss = (unsigned long)(mss.pss >> PSS_SHIFT) / 1024;
+			uss = (mss.private_clean + mss.private_dirty) / 1024;
+			rss = (mss.resident) / 1024;
+			swap = (mss.swap) / 1024;
+
+			process_memory_buffer->drv_data[pid_count].pss = pss;
+			process_memory_buffer->drv_data[pid_count].uss = uss;
+			process_memory_buffer->drv_data[pid_count].rss = rss;
+			process_memory_buffer->drv_data[pid_count].swap = swap;
+			process_memory_buffer->drv_data[pid_count].java_heap =
+									java_heap;
+			process_memory_buffer->drv_data[pid_count].native_heap =
+									native_heap;
+			process_memory_buffer->pid_count++;
+
+			break;
+		}
+	}
+	read_unlock(&tasklist_lock);
+}
+
+/*****************************************************************
+ * Note: this function can only be used during tracing function
+ * This function is only used in tracing function so that there
+ * is no need for task t spinlock protection
+ *****************************************************************/
+static u64 mbraink_get_specific_process_jiffies(struct task_struct *t)
+{
+	u64 stime = 0, utime = 0, cutime = 0, cstime = 0;
+	u64 process_jiffies = 0;
+
+	if (t->pid == t->tgid) {
+		cutime = t->signal->cutime;
+		cstime = t->signal->cstime;
+		if (t->flags & PF_KTHREAD)
+			task_cputime_adjusted(t, &utime, &stime);
+		else
+			thread_group_cputime_adjusted(t, &utime, &stime);
+
+		process_jiffies = nsec_to_clock_t(utime) +
+				nsec_to_clock_t(stime) +
+				nsec_to_clock_t(cutime) +
+				nsec_to_clock_t(cstime);
+	} else {
+		task_cputime_adjusted(t, &utime, &stime);
+		process_jiffies = nsec_to_clock_t(utime) + nsec_to_clock_t(stime);
+	}
+
+	return process_jiffies;
+}
+
+/***************************************************************
+ * Note: this function can only be used during tracing function
+ * This function is only used in tracing function so that there
+ * is no need for task t spinlock protection
+ **************************************************************/
+static u16 mbraink_get_specific_process_uid(struct task_struct *t)
+{
+	const struct cred *cred = NULL;
+	u16 val = 0;
+
+	cred = get_task_cred(t);
+	val = cred->uid.val;
+	put_cred(cred);
+
+	return val;
+}
+
+static void mbraink_trace_sched_process_exit(void *data, struct task_struct *t)
+{
+	int i = 0;
+	struct timespec64 tv = { 0 };
+	unsigned long flags;
+
+	if (t->pid == t->tgid) {
+		spin_lock_irqsave(&tracing_pidlist_lock, flags);
+		for (i = 0; i < MAX_TRACE_NUM; i++) {
+			if (mbraink_tracing_pidlist_data[i].pid == (unsigned short)t->pid) {
+				ktime_get_real_ts64(&tv);
+				mbraink_tracing_pidlist_data[i].end =
+					(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
+				mbraink_tracing_pidlist_data[i].jiffies =
+						mbraink_get_specific_process_jiffies(t);
+				mbraink_tracing_pidlist_data[i].dirty = true;
+
+				break;
+			}
+		}
+		if (i == MAX_TRACE_NUM) {
+			for (i = 0; i < MAX_TRACE_NUM; i++) {
+				if (mbraink_tracing_pidlist_data[i].pid == 0) {
+					mbraink_tracing_pidlist_data[i].pid =
+							(unsigned short)(t->pid);
+					mbraink_tracing_pidlist_data[i].tgid =
+							(unsigned short)(t->tgid);
+					mbraink_tracing_pidlist_data[i].uid =
+							mbraink_get_specific_process_uid(t);
+					mbraink_tracing_pidlist_data[i].priority =
+							t->prio - MAX_RT_PRIO;
+					memcpy(mbraink_tracing_pidlist_data[i].name,
+					       t->comm, TASK_COMM_LEN);
+					ktime_get_real_ts64(&tv);
+					mbraink_tracing_pidlist_data[i].end =
+							(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
+					mbraink_tracing_pidlist_data[i].jiffies =
+							mbraink_get_specific_process_jiffies(t);
+					mbraink_tracing_pidlist_data[i].dirty = true;
+
+					break;
+				}
+			}
+			if (i == MAX_TRACE_NUM) {
+				pr_info("%s pid=%u:%s.\n", __func__, t->pid, t->comm);
+				memset(mbraink_tracing_pidlist_data, 0,
+				       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
+			}
+		}
+		spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
+	}
+}
+
+static void mbraink_trace_sched_process_fork(void *data, struct task_struct *t,
+					     struct task_struct *p)
+{
+	int i = 0;
+	struct timespec64 tv = { 0 };
+	unsigned long flags;
+
+	if (p->pid == p->tgid) {
+		spin_lock_irqsave(&tracing_pidlist_lock, flags);
+		for (i = 0; i < MAX_TRACE_NUM; i++) {
+			if (mbraink_tracing_pidlist_data[i].pid == 0) {
+				mbraink_tracing_pidlist_data[i].pid = (unsigned short)(p->pid);
+				mbraink_tracing_pidlist_data[i].tgid = (unsigned short)(p->tgid);
+				mbraink_tracing_pidlist_data[i].uid =
+						mbraink_get_specific_process_uid(p);
+				mbraink_tracing_pidlist_data[i].priority = p->prio - MAX_RT_PRIO;
+				memcpy(mbraink_tracing_pidlist_data[i].name,
+				       p->comm, TASK_COMM_LEN);
+				ktime_get_real_ts64(&tv);
+				mbraink_tracing_pidlist_data[i].start =
+						(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
+				mbraink_tracing_pidlist_data[i].dirty = true;
+				break;
+			}
+		}
+
+		if (i == MAX_TRACE_NUM) {
+			pr_info("%s child_pid=%u:%s.\n", __func__, p->pid, p->comm);
+			memset(mbraink_tracing_pidlist_data, 0,
+			       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
+		}
+		spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
+	}
+}
+
+int mbraink_process_tracer_init(void)
+{
+	int ret = 0;
+
+	memset(mbraink_tracing_pidlist_data, 0,
+	       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
+
+	ret = register_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
+	if (ret) {
+		pr_notice("register_trace_sched_process_fork failed.\n");
+		goto register_trace_sched_process_fork;
+	}
+	ret = register_trace_sched_process_exit(mbraink_trace_sched_process_exit, NULL);
+	if (ret) {
+		pr_notice("register register_trace_sched_process_exit failed.\n");
+		goto register_trace_sched_process_exit;
+	}
+
+	return ret;
+
+register_trace_sched_process_exit:
+	unregister_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
+register_trace_sched_process_fork:
+	return ret;
+}
+
+void mbraink_process_tracer_exit(void)
+{
+	unregister_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
+	unregister_trace_sched_process_exit(mbraink_trace_sched_process_exit, NULL);
+}
+
+void mbraink_get_tracing_pid_info(unsigned short current_idx,
+				  struct mbraink_tracing_pid_data *tracing_pid_buffer)
+{
+	int i = 0;
+	int ret = 0;
+	unsigned long flags;
+	unsigned short tracing_count = 0;
+
+	spin_lock_irqsave(&tracing_pidlist_lock, flags);
+
+	memset(tracing_pid_buffer, 0, sizeof(struct mbraink_tracing_pid_data));
+
+	for (i = current_idx; i < MAX_TRACE_NUM; i++) {
+		if (mbraink_tracing_pidlist_data[i].dirty == 0) {
+			continue;
+		} else {
+			tracing_count = tracing_pid_buffer->tracing_count;
+			if (tracing_count < MAX_TRACE_PID_NUM) {
+				tracing_pid_buffer->drv_data[tracing_count].pid =
+						mbraink_tracing_pidlist_data[i].pid;
+				tracing_pid_buffer->drv_data[tracing_count].tgid =
+						mbraink_tracing_pidlist_data[i].tgid;
+				tracing_pid_buffer->drv_data[tracing_count].uid =
+						mbraink_tracing_pidlist_data[i].uid;
+				tracing_pid_buffer->drv_data[tracing_count].priority =
+						mbraink_tracing_pidlist_data[i].priority;
+				memcpy(tracing_pid_buffer->drv_data[tracing_count].name,
+				       mbraink_tracing_pidlist_data[i].name, TASK_COMM_LEN);
+				tracing_pid_buffer->drv_data[tracing_count].start =
+						mbraink_tracing_pidlist_data[i].start;
+				tracing_pid_buffer->drv_data[tracing_count].end =
+						mbraink_tracing_pidlist_data[i].end;
+				tracing_pid_buffer->drv_data[tracing_count].jiffies =
+						mbraink_tracing_pidlist_data[i].jiffies;
+				tracing_pid_buffer->tracing_count++;
+				/*Deal with the end process record*/
+				if (mbraink_tracing_pidlist_data[i].end != 0) {
+					mbraink_tracing_pidlist_data[i].pid = 0;
+					mbraink_tracing_pidlist_data[i].tgid = 0;
+					mbraink_tracing_pidlist_data[i].uid = 0;
+					mbraink_tracing_pidlist_data[i].priority = 0;
+					memset(mbraink_tracing_pidlist_data[i].name,
+					       0, TASK_COMM_LEN);
+					mbraink_tracing_pidlist_data[i].start = 0;
+					mbraink_tracing_pidlist_data[i].end = 0;
+					mbraink_tracing_pidlist_data[i].jiffies = 0;
+					mbraink_tracing_pidlist_data[i].dirty = false;
+				} else {
+					mbraink_tracing_pidlist_data[i].dirty = false;
+				}
+			} else {
+				ret = -1;
+				tracing_pid_buffer->tracing_idx = i;
+				break;
+			}
+		}
+	}
+	pr_info("%s: current_idx = %u, count = %u\n",
+		__func__, tracing_pid_buffer->tracing_idx, tracing_pid_buffer->tracing_count);
+	spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
+}
diff --git a/drivers/misc/mediatek_mbraink/mbraink_data.h b/drivers/misc/mediatek_mbraink/mbraink_data.h
new file mode 100644
index 000000000000..2d1a6b488caa
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/mbraink_data.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+#ifndef MBRAINK_DATA_H
+#define MBRAINK_DATA_H
+#include <linux/string_helpers.h>
+#include <linux/sched.h>
+#include <linux/sched/task.h>
+#include <linux/mm_types.h>
+#include <linux/pid.h>
+
+#include "mbraink_ioctl_struct_define.h"
+
+#define PSS_SHIFT			12
+#define MAX_RT_PRIO			100
+#define MAX_TRACE_NUM			3072
+
+struct mbraink_tracing_pidlist {
+	unsigned short pid;
+	unsigned short tgid;
+	unsigned short uid;
+	int priority;
+	char name[TASK_COMM_LEN];
+	long long start;
+	long long end;
+	u64 jiffies;
+	bool dirty;
+};
+
+struct mem_size_stats {
+	unsigned long resident;
+	unsigned long shared_clean;
+	unsigned long shared_dirty;
+	unsigned long private_clean;
+	unsigned long private_dirty;
+	unsigned long referenced;
+	unsigned long anonymous;
+	unsigned long lazyfree;
+	unsigned long anonymous_thp;
+	unsigned long shmem_thp;
+	unsigned long file_thp;
+	unsigned long swap;
+	unsigned long shared_hugetlb;
+	unsigned long private_hugetlb;
+	u64 pss;
+	u64 pss_anon;
+	u64 pss_file;
+	u64 pss_shmem;
+	u64 pss_locked;
+	u64 swap_pss;
+	bool check_shmem_swap;
+};
+
+void mbraink_get_process_memory_info(pid_t current_pid,
+				     struct mbraink_process_memory_data *process_memory_buffer);
+int mbraink_process_tracer_init(void);
+void mbraink_process_tracer_exit(void);
+void mbraink_get_tracing_pid_info(unsigned short current_idx,
+				  struct mbraink_tracing_pid_data *tracing_pid_buffer);
+void smap_gather_stats(struct vm_area_struct *vma,
+		       struct mem_size_stats *mss, unsigned long start);
+void task_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
+void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
+u64 nsec_to_clock_t(u64 x);
+#endif
diff --git a/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h b/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
new file mode 100644
index 000000000000..d655d8893f0f
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+#ifndef MBRAINK_IOCTL_STRUCT_H
+#define MBRAINK_IOCTL_STRUCT_H
+
+#define MAX_MEM_STRUCT_SZ			4
+#define MAX_TRACE_PID_NUM			16
+
+struct mbraink_process_memory_struct {
+	unsigned short pid;
+	unsigned long pss;
+	unsigned long uss;
+	unsigned long rss;
+	unsigned long swap;
+	unsigned long java_heap;
+	unsigned long native_heap;
+};
+
+struct mbraink_process_memory_data {
+	unsigned short pid;
+	unsigned short pid_count;
+	struct mbraink_process_memory_struct drv_data[MAX_MEM_STRUCT_SZ];
+};
+
+struct mbraink_tracing_pid {
+	unsigned short pid;
+	unsigned short tgid;
+	unsigned short uid;
+	int priority;
+	char name[TASK_COMM_LEN];
+	long long start;
+	long long end;
+	u64 jiffies;
+};
+
+struct mbraink_tracing_pid_data {
+	unsigned short tracing_idx;
+	unsigned short tracing_count;
+	struct mbraink_tracing_pid drv_data[MAX_TRACE_PID_NUM];
+};
+
+#endif
diff --git a/drivers/misc/mediatek_mbraink/mbraink_main.c b/drivers/misc/mediatek_mbraink/mbraink_main.c
new file mode 100644
index 000000000000..4e6aac51694a
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/mbraink_main.c
@@ -0,0 +1,239 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/uaccess.h>
+#include <linux/compat.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/pm_runtime.h>
+
+#include "mbraink_main.h"
+#include "mbraink_data.h"
+
+struct mbraink_data mbraink_priv;
+
+static int mbraink_open(struct inode *inode, struct file *filp)
+{
+	return 0;
+}
+
+static int mbraink_release(struct inode *inode, struct file *filp)
+{
+	return 0;
+}
+
+static long mbraink_ioctl(struct file *filp,
+			  unsigned int cmd,
+			  unsigned long arg)
+{
+	long ret = 0;
+
+	switch (cmd) {
+	case RO_PROCESS_MEMORY:
+	{
+		struct mbraink_process_memory_data process_memory_buffer;
+
+		pid_t pid = 1;
+
+		if (copy_from_user(&process_memory_buffer,
+				   (struct mbraink_process_memory_data *)arg,
+				   sizeof(process_memory_buffer))) {
+			pr_notice("copy process memory info from user Err!\n");
+			return -EPERM;
+		}
+
+		if (process_memory_buffer.pid > PID_MAX_DEFAULT ||
+		    process_memory_buffer.pid_count > PID_MAX_DEFAULT) {
+			pr_notice("process memory: Invalid pid_idx %u or pid_count %u\n",
+				  process_memory_buffer.pid, process_memory_buffer.pid_count);
+			return -EINVAL;
+		}
+		pid = process_memory_buffer.pid;
+
+		mbraink_get_process_memory_info(pid, &process_memory_buffer);
+
+		if (copy_to_user((struct mbraink_process_memory_data *)arg,
+				 &process_memory_buffer,
+				 sizeof(process_memory_buffer))) {
+			pr_notice("Copy process_memory_info to UserSpace error!\n");
+			return -EPERM;
+		}
+		break;
+	}
+	case RO_TRACE_PROCESS:
+	{
+		struct mbraink_tracing_pid_data tracing_pid_buffer;
+
+		unsigned short tracing_idx = 0;
+
+		if (copy_from_user(&tracing_pid_buffer,
+				   (struct mbraink_tracing_pid_data *)arg,
+				   sizeof(tracing_pid_buffer))) {
+			pr_notice("copy tracing_pid_buffer data from user Err!\n");
+			return -EPERM;
+		}
+
+		if (tracing_pid_buffer.tracing_idx > MAX_TRACE_NUM) {
+			pr_notice("invalid tracing_idx %u !\n",
+				  tracing_pid_buffer.tracing_idx);
+			return -EINVAL;
+		}
+		tracing_idx = tracing_pid_buffer.tracing_idx;
+
+		mbraink_get_tracing_pid_info(tracing_idx, &tracing_pid_buffer);
+
+		if (copy_to_user((struct mbraink_tracing_pid_data *)arg,
+				 &tracing_pid_buffer,
+				 sizeof(tracing_pid_buffer))) {
+			pr_notice("Copy tracing_pid_buffer to UserSpace error!\n");
+			return -EPERM;
+		}
+		break;
+	}
+	default:
+		pr_notice("illegal ioctl number %u.\n", cmd);
+		return -EINVAL;
+	}
+
+	return ret;
+}
+
+#if IS_ENABLED(CONFIG_COMPAT)
+static long mbraink_compat_ioctl(struct file *filp,
+				 unsigned int cmd, unsigned long arg)
+{
+	return mbraink_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
+static const struct file_operations mbraink_fops = {
+	.owner		= THIS_MODULE,
+	.open		= mbraink_open,
+	.release        = mbraink_release,
+	.unlocked_ioctl = mbraink_ioctl,
+#if IS_ENABLED(CONFIG_COMPAT)
+	.compat_ioctl   = mbraink_compat_ioctl,
+#endif
+};
+
+#if IS_ENABLED(CONFIG_PM_SLEEP)
+static int mbraink_suspend(struct device *dev)
+{
+	int ret;
+
+	pr_info("[MBK_INFO] %s\n", __func__);
+
+	ret = pm_generic_suspend(dev);
+
+	return ret;
+}
+
+static int mbraink_resume(struct device *dev)
+{
+	int ret;
+
+	pr_info("[MBK_INFO] %s\n", __func__);
+
+	ret = pm_generic_resume(dev);
+
+	return ret;
+}
+
+static const struct dev_pm_ops mbraink_class_dev_pm_ops = {
+	.suspend	= mbraink_suspend,
+	.resume	= mbraink_resume,
+};
+
+#define MBRAINK_CLASS_DEV_PM_OPS (&mbraink_class_dev_pm_ops)
+#else
+#define MBRAINK_CLASS_DEV_PM_OPS NULL
+#endif /*end of CONFIG_PM_SLEEP*/
+
+static int mbraink_dev_init(void)
+{
+	mbraink_priv.mbraink_dev_no = 0;
+
+	/*Allocating Major number*/
+	if ((alloc_chrdev_region(&mbraink_priv.mbraink_dev_no, 0, 1, CHRDEV_NAME)) < 0) {
+		pr_notice("Cannot allocate major number %u\n",
+			  mbraink_priv.mbraink_dev_no);
+		return -EBADF;
+	}
+
+	/*Initialize cdev structure*/
+	cdev_init(&mbraink_priv.mbraink_cdev, &mbraink_fops);
+
+	/*Adding character device to the system*/
+	if ((cdev_add(&mbraink_priv.mbraink_cdev, mbraink_priv.mbraink_dev_no, 1)) < 0) {
+		pr_notice("Cannot add the device to the system\n");
+		goto r_class;
+	}
+
+	mbraink_priv.mbraink_class = class_create(THIS_MODULE, "mbraink_host");
+	/*Register mbraink class*/
+	if (IS_ERR(mbraink_priv.mbraink_class)) {
+		pr_notice("Cannot create the mbraink class\n");
+		goto r_class;
+	}
+	mbraink_priv.mbraink_class->pm = MBRAINK_CLASS_DEV_PM_OPS;
+
+	/*Register mbraink device*/
+	if (IS_ERR(device_create(mbraink_priv.mbraink_class,
+				 NULL, mbraink_priv.mbraink_dev_no, NULL, "mbraink"))) {
+		pr_notice("Cannot create the mbraink Device\n");
+		goto r_device;
+	}
+	pr_info("[MBK_INFO] %s: Mbraink device init done.\n", __func__);
+
+	return 0;
+
+r_device:
+	class_destroy(mbraink_priv.mbraink_class);
+r_class:
+	unregister_chrdev_region(mbraink_priv.mbraink_dev_no, 1);
+
+	return -EPERM;
+}
+
+static int mbraink_init(void)
+{
+	int ret = 0;
+
+	ret = mbraink_dev_init();
+	if (ret)
+		pr_notice("mbraink device init failed.\n");
+
+	ret = mbraink_process_tracer_init();
+	if (ret)
+		pr_notice("mbraink tracer init failed.\n");
+
+	return ret;
+}
+
+static void mbraink_dev_exit(void)
+{
+	device_destroy(mbraink_priv.mbraink_class, mbraink_priv.mbraink_dev_no);
+	class_destroy(mbraink_priv.mbraink_class);
+	cdev_del(&mbraink_priv.mbraink_cdev);
+	unregister_chrdev_region(mbraink_priv.mbraink_dev_no, 1);
+
+	pr_info("[MBK_INFO] %s: MBraink device exit done\n", __func__);
+}
+
+static void mbraink_exit(void)
+{
+	mbraink_dev_exit();
+	mbraink_process_tracer_exit();
+}
+
+module_init(mbraink_init);
+module_exit(mbraink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("<Wei-chin.Tsai@mediatek.com>");
+MODULE_DESCRIPTION("MBraink Linux Device Driver");
+MODULE_VERSION("1.0");
diff --git a/drivers/misc/mediatek_mbraink/mbraink_main.h b/drivers/misc/mediatek_mbraink/mbraink_main.h
new file mode 100644
index 000000000000..36549f0d90d1
--- /dev/null
+++ b/drivers/misc/mediatek_mbraink/mbraink_main.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ */
+
+#ifndef MBRAINK_MAIN_H
+#define MBRAINK_MAIN_H
+
+#include <linux/ioctl.h>
+#include <linux/cdev.h>
+#include <linux/pid.h>
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+
+#include "mbraink_ioctl_struct_define.h"
+
+#define IOC_MAGIC		'k'
+
+/*Mbrain Delegate Info List*/
+#define PROCESS_MEMORY_INFO	'4'
+#define TRACE_PROCESS_INFO      'a'
+
+/*Mbrain Delegate IOCTL List*/
+#define RO_PROCESS_MEMORY	_IOR(IOC_MAGIC, PROCESS_MEMORY_INFO, \
+				     struct mbraink_process_memory_data*)
+#define RO_TRACE_PROCESS        _IOR(IOC_MAGIC, TRACE_PROCESS_INFO, \
+				     struct mbraink_tracing_pid_data*)
+
+struct mbraink_data {
+#define CHRDEV_NAME     "mbraink_chrdev"
+	dev_t mbraink_dev_no;
+	struct cdev mbraink_cdev;
+	struct class *mbraink_class;
+};
+
+#endif /*end of MBRAINK_MAIN_H*/
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
@ 2023-06-14  7:16   ` Russell King (Oracle)
  2023-06-14  9:59     ` Wei-chin Tsai (蔡維晉)
  2023-06-14  8:42   ` kernel test robot
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 17+ messages in thread
From: Russell King (Oracle) @ 2023-06-14  7:16 UTC (permalink / raw)
  To: Wei Chin Tsai
  Cc: linux-kernel, Matthias Brugger, AngeloGioacchino Del Regno,
	wsd_upstream, mel.lee, ivan.tseng, linux-arm-kernel,
	linux-fsdevel, linux-mediatek

On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai wrote:
> diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
> index 0e8ff85890ad..df91412a1069 100644
> --- a/arch/arm/kernel/process.c
> +++ b/arch/arm/kernel/process.c
> @@ -343,6 +343,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>  {
>  	return is_gate_vma(vma) ? "[vectors]" : NULL;
>  }
> +EXPORT_SYMBOL_GPL(arch_vma_name);
...
> diff --git a/kernel/signal.c b/kernel/signal.c
> index b5370fe5c198..a1abe77fcdc3 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct vm_area_struct *vma)
>  {
>  	return NULL;
>  }
> +EXPORT_SYMBOL_GPL(arch_vma_name);

Have you confirmed:
1) whether this actually builds
2) whether this results in one or two arch_vma_name exports

?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
  2023-06-14  7:16   ` Russell King (Oracle)
@ 2023-06-14  8:42   ` kernel test robot
  2023-06-14 10:05   ` kernel test robot
  2023-06-14 13:05   ` kernel test robot
  3 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2023-06-14  8:42 UTC (permalink / raw)
  To: Wei Chin Tsai, linux-kernel, Russell King, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: llvm, oe-kbuild-all, wsd_upstream, wei-chin.tsai, mel.lee,
	ivan.tseng, linux-arm-kernel, linux-fsdevel, linux-mediatek

Hi Wei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.4-rc6 next-20230613]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Chin-Tsai/kernel-process-fork-exit-export-symbol-for-fork-exit-tracing-functions/20230614-112218
base:   char-misc/char-misc-testing
patch link:    https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai%40mediatek.com
patch subject: [PATCH v2 2/3] memory: export symbols for memory related functions
config: hexagon-randconfig-r041-20230612 (https://download.01.org/0day-ci/archive/20230614/202306141630.EQtwoD5V-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a)
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git remote add char-misc https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
        git fetch char-misc char-misc-testing
        git checkout char-misc/char-misc-testing
        b4 shazam https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai@mediatek.com
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash fs/proc/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306141630.EQtwoD5V-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from fs/proc/task_mmu.c:3:
   In file included from include/linux/mm_inline.h:7:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from fs/proc/task_mmu.c:3:
   In file included from include/linux/mm_inline.h:7:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from fs/proc/task_mmu.c:3:
   In file included from include/linux/mm_inline.h:7:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
>> fs/proc/task_mmu.c:776:6: warning: no previous prototype for function 'smap_gather_stats' [-Wmissing-prototypes]
     776 | void smap_gather_stats(struct vm_area_struct *vma,
         |      ^
   fs/proc/task_mmu.c:776:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
     776 | void smap_gather_stats(struct vm_area_struct *vma,
         | ^
         | static 
   7 warnings generated.


vim +/smap_gather_stats +776 fs/proc/task_mmu.c

   769	
   770	/*
   771	 * Gather mem stats from @vma with the indicated beginning
   772	 * address @start, and keep them in @mss.
   773	 *
   774	 * Use vm_start of @vma as the beginning address if @start is 0.
   775	 */
 > 776	void smap_gather_stats(struct vm_area_struct *vma,
   777			       struct mem_size_stats *mss, unsigned long start)
   778	{
   779		const struct mm_walk_ops *ops = &smaps_walk_ops;
   780	
   781		/* Invalid start */
   782		if (start >= vma->vm_end)
   783			return;
   784	
   785		if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) {
   786			/*
   787			 * For shared or readonly shmem mappings we know that all
   788			 * swapped out pages belong to the shmem object, and we can
   789			 * obtain the swap value much more efficiently. For private
   790			 * writable mappings, we might have COW pages that are
   791			 * not affected by the parent swapped out pages of the shmem
   792			 * object, so we have to distinguish them during the page walk.
   793			 * Unless we know that the shmem object (or the part mapped by
   794			 * our VMA) has no swapped out pages at all.
   795			 */
   796			unsigned long shmem_swapped = shmem_swap_usage(vma);
   797	
   798			if (!start && (!shmem_swapped || (vma->vm_flags & VM_SHARED) ||
   799						!(vma->vm_flags & VM_WRITE))) {
   800				mss->swap += shmem_swapped;
   801			} else {
   802				ops = &smaps_shmem_walk_ops;
   803			}
   804		}
   805	
   806		/* mmap_lock is held in m_start */
   807		if (!start)
   808			walk_page_vma(vma, ops, mss);
   809		else
   810			walk_page_range(vma->vm_mm, start, vma->vm_end, ops, mss);
   811	}
   812	EXPORT_SYMBOL_GPL(smap_gather_stats);
   813	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  7:16   ` Russell King (Oracle)
@ 2023-06-14  9:59     ` Wei-chin Tsai (蔡維晉)
  2023-06-14 12:11       ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 17+ messages in thread
From: Wei-chin Tsai (蔡維晉) @ 2023-06-14  9:59 UTC (permalink / raw)
  To: linux
  Cc: linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒),
	angelogioacchino.delregno

On Wed, 2023-06-14 at 08:16 +0100, Russell King (Oracle) wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai wrote:
> > diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
> > index 0e8ff85890ad..df91412a1069 100644
> > --- a/arch/arm/kernel/process.c
> > +++ b/arch/arm/kernel/process.c
> > @@ -343,6 +343,7 @@ const char *arch_vma_name(struct vm_area_struct
> *vma)
> >  {
> >  return is_gate_vma(vma) ? "[vectors]" : NULL;
> >  }
> > +EXPORT_SYMBOL_GPL(arch_vma_name);
> ...
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index b5370fe5c198..a1abe77fcdc3 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct
> vm_area_struct *vma)
> >  {
> >  return NULL;
> >  }
> > +EXPORT_SYMBOL_GPL(arch_vma_name);
> 
> Have you confirmed:
> 1) whether this actually builds
> 2) whether this results in one or two arch_vma_name exports
> 
> ?
> 
> -- 
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Hi Russell,

We did confirm that it can be built successfully in kernel 6.1 and run
well in our system.

Actually, we only use this export symbol "arch_vma_name"
from kernel/signal.c in arm64. We also export symbol for arch_vma_name
in arch/arm/kernel/process.c because that, one day in the future,  we
are afraid that we also need this function in arm platform.

Thanks.

Regards,

Jim


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
  2023-06-14  7:16   ` Russell King (Oracle)
  2023-06-14  8:42   ` kernel test robot
@ 2023-06-14 10:05   ` kernel test robot
  2023-06-14 13:05   ` kernel test robot
  3 siblings, 0 replies; 17+ messages in thread
From: kernel test robot @ 2023-06-14 10:05 UTC (permalink / raw)
  To: Wei Chin Tsai, linux-kernel, Russell King, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: oe-kbuild-all, wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng,
	linux-arm-kernel, linux-fsdevel, linux-mediatek

Hi Wei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.4-rc6 next-20230614]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Chin-Tsai/kernel-process-fork-exit-export-symbol-for-fork-exit-tracing-functions/20230614-112218
base:   char-misc/char-misc-testing
patch link:    https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai%40mediatek.com
patch subject: [PATCH v2 2/3] memory: export symbols for memory related functions
config: csky-randconfig-r011-20230612 (https://download.01.org/0day-ci/archive/20230614/202306141627.fYoZPKxi-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git remote add char-misc https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
        git fetch char-misc char-misc-testing
        git checkout char-misc/char-misc-testing
        b4 shazam https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai@mediatek.com
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash fs/proc/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306141627.fYoZPKxi-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> fs/proc/task_mmu.c:776:6: warning: no previous prototype for 'smap_gather_stats' [-Wmissing-prototypes]
     776 | void smap_gather_stats(struct vm_area_struct *vma,
         |      ^~~~~~~~~~~~~~~~~


vim +/smap_gather_stats +776 fs/proc/task_mmu.c

   769	
   770	/*
   771	 * Gather mem stats from @vma with the indicated beginning
   772	 * address @start, and keep them in @mss.
   773	 *
   774	 * Use vm_start of @vma as the beginning address if @start is 0.
   775	 */
 > 776	void smap_gather_stats(struct vm_area_struct *vma,
   777			       struct mem_size_stats *mss, unsigned long start)
   778	{
   779		const struct mm_walk_ops *ops = &smaps_walk_ops;
   780	
   781		/* Invalid start */
   782		if (start >= vma->vm_end)
   783			return;
   784	
   785		if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) {
   786			/*
   787			 * For shared or readonly shmem mappings we know that all
   788			 * swapped out pages belong to the shmem object, and we can
   789			 * obtain the swap value much more efficiently. For private
   790			 * writable mappings, we might have COW pages that are
   791			 * not affected by the parent swapped out pages of the shmem
   792			 * object, so we have to distinguish them during the page walk.
   793			 * Unless we know that the shmem object (or the part mapped by
   794			 * our VMA) has no swapped out pages at all.
   795			 */
   796			unsigned long shmem_swapped = shmem_swap_usage(vma);
   797	
   798			if (!start && (!shmem_swapped || (vma->vm_flags & VM_SHARED) ||
   799						!(vma->vm_flags & VM_WRITE))) {
   800				mss->swap += shmem_swapped;
   801			} else {
   802				ops = &smaps_shmem_walk_ops;
   803			}
   804		}
   805	
   806		/* mmap_lock is held in m_start */
   807		if (!start)
   808			walk_page_vma(vma, ops, mss);
   809		else
   810			walk_page_range(vma->vm_mm, start, vma->vm_end, ops, mss);
   811	}
   812	EXPORT_SYMBOL_GPL(smap_gather_stats);
   813	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data
  2023-06-14  3:20 ` [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data Wei Chin Tsai
@ 2023-06-14 11:14   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 17+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-06-14 11:14 UTC (permalink / raw)
  To: Wei Chin Tsai, linux-kernel, Arnd Bergmann, Greg Kroah-Hartman,
	Matthias Brugger
  Cc: wsd_upstream, mel.lee, ivan.tseng, linux-arm-kernel, linux-mediatek

Il 14/06/23 05:20, Wei Chin Tsai ha scritto:
> In this patch, we add the mediatek_mbrain folder
> including 7 files. Apart from Makefile and Kconfig,
> the aim of the other 5 files is to collect the
> process fork/exit tracing data and process memory
> pss, uss, rss, swap, and heap usage.
> User could use these kind of data to do the system
> analysis, and detect the unexpected process/memory
> issues. Furthermore, user can make use of process
> memory data to detect the memory leak issues.
>  From memory heap aspect, user could know the java
> and native layer heap usage.
> Also, user can capture those processes which run
> in a second and then terminate immediately by add
> the hook functions in "sched_process_fork" and
> "sched_process_exit".
> 

How is MediaTek MBrain different from the already existing debugging/tracing and
memory analysis infrastructure of the Linux kernel, and why is it needed?
If there's little difference, as in that you need some more features, you may as
well implement the missing features in the standard infra.

Another issue with this driver is that I can't find any source code for the
MediaTek MBrain userspace part (which is totally needed to use this driver).

Regards,
Angelo

> Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
> ---
>   drivers/misc/mediatek_mbraink/Kconfig         |  15 +
>   drivers/misc/mediatek_mbraink/Makefile        |   5 +
>   drivers/misc/mediatek_mbraink/mbraink_data.c  | 417 ++++++++++++++++++
>   drivers/misc/mediatek_mbraink/mbraink_data.h  |  66 +++
>   .../mbraink_ioctl_struct_define.h             |  44 ++
>   drivers/misc/mediatek_mbraink/mbraink_main.c  | 239 ++++++++++
>   drivers/misc/mediatek_mbraink/mbraink_main.h  |  36 ++
>   7 files changed, 822 insertions(+)
>   create mode 100644 drivers/misc/mediatek_mbraink/Kconfig
>   create mode 100644 drivers/misc/mediatek_mbraink/Makefile
>   create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.c
>   create mode 100644 drivers/misc/mediatek_mbraink/mbraink_data.h
>   create mode 100644 drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
>   create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.c
>   create mode 100644 drivers/misc/mediatek_mbraink/mbraink_main.h
> 
> diff --git a/drivers/misc/mediatek_mbraink/Kconfig b/drivers/misc/mediatek_mbraink/Kconfig
> new file mode 100644
> index 000000000000..4a96059e4c57
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/Kconfig
> @@ -0,0 +1,15 @@
> +config MTK_MBRAINK
> +	tristate "MTK MBRAINK support"
> +	help
> +          MBRAINK is a MediaTek in-house kernel module which can
> +          communicate with android MBrain.
> +          Set Y to enable this feature.
> +          If unsure, Set N to stay with legancy feature.
> +
> +config MTK_MBRAINK_EXPORT_DEPENDED
> +	tristate "MTK MBRAINK EXPORT DEPENDED support"
> +	help
> +	  MBRAINK EXPORT DEPENDED option which
> +	  needs to export extra function in upstram kernel.
> +	  Set Y to enable this feature.
> +	  If unsure, Set N to stay with legancy feature.
> diff --git a/drivers/misc/mediatek_mbraink/Makefile b/drivers/misc/mediatek_mbraink/Makefile
> new file mode 100644
> index 000000000000..8d75b41a8097
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/Makefile
> @@ -0,0 +1,5 @@
> +subdir-ccflags-y += -Wformat
> +
> +obj-${CONFIG_MTK_MBRAINK} += mtk_mbraink.o
> +
> +mtk_mbraink-objs += mbraink_data.o mbraink_main.o
> diff --git a/drivers/misc/mediatek_mbraink/mbraink_data.c b/drivers/misc/mediatek_mbraink/mbraink_data.c
> new file mode 100644
> index 000000000000..dad03124820a
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/mbraink_data.c
> @@ -0,0 +1,417 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023 MediaTek Inc.
> + */
> +#include <linux/module.h>
> +#include <linux/fs.h>
> +#include <linux/rtc.h>
> +#include <linux/sched/clock.h>
> +#include <linux/kernel.h>
> +#include <linux/uaccess.h>
> +#include <linux/cdev.h>
> +#include <linux/proc_fs.h>
> +#include <linux/sched/signal.h>
> +#include <linux/pid_namespace.h>
> +#include <linux/mm.h>
> +#include <linux/sched/mm.h>
> +#include <linux/sched/task.h>
> +#include <linux/pagewalk.h>
> +#include <linux/shmem_fs.h>
> +#include <linux/pagemap.h>
> +#include <linux/mempolicy.h>
> +#include <linux/rmap.h>
> +#include <linux/sched/cputime.h>
> +#include <linux/math64.h>
> +#include <linux/refcount.h>
> +#include <linux/ctype.h>
> +#include <linux/stddef.h>
> +#include <linux/cred.h>
> +#include <linux/spinlock.h>
> +#include <linux/rtc.h>
> +#include <linux/sched/clock.h>
> +#include <trace/events/sched.h>
> +#include <linux/mm_inline.h>
> +
> +#include "mbraink_data.h"
> +
> +/*spinlock for mbraink tracing pidlist*/
> +static DEFINE_SPINLOCK(tracing_pidlist_lock);
> +/*Please make sure that tracing pidlist is protected by spinlock*/
> +struct mbraink_tracing_pidlist mbraink_tracing_pidlist_data[MAX_TRACE_NUM];
> +
> +#if IS_ENABLED(CONFIG_ANON_VMA_NAME)
> +struct anon_vma_name *mbraink_anon_vma_name(struct vm_area_struct *vma)
> +{
> +	if (vma->vm_file)
> +		return NULL;
> +
> +	return vma->anon_name;
> +}
> +#else
> +struct anon_vma_name *mbraink_anon_vma_name(struct vm_area_struct *vma)
> +{
> +	return NULL;
> +}
> +#endif
> +
> +void mbraink_map_vma(struct vm_area_struct *vma, unsigned long cur_pss,
> +		     unsigned long *native_heap, unsigned long *java_heap)
> +{
> +	struct mm_struct *mm = vma->vm_mm;
> +	const char *name = NULL;
> +
> +	if (vma->vm_file)
> +		return;
> +	/*
> +	 * Print the dentry name for named mappings, and a
> +	 * special [heap] marker for the heap:
> +	 */
> +
> +	if (vma->vm_ops && vma->vm_ops->name) {
> +		name = vma->vm_ops->name(vma);
> +		if (name) {
> +			if (strncmp(name, "dev/ashmem/libc malloc", 23) == 0)
> +				(*native_heap) += cur_pss;
> +			return;
> +		}
> +	}
> +
> +	name = arch_vma_name(vma);
> +	if (!name) {
> +		struct anon_vma_name *anon_name;
> +
> +		if (!mm)
> +			return;
> +
> +		if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
> +			(*native_heap) += cur_pss;
> +			return;
> +		}
> +
> +		if (vma->vm_start <= vma->vm_mm->start_stack &&
> +		    vma->vm_end >= vma->vm_mm->start_stack)
> +			return;
> +
> +		anon_name = mbraink_anon_vma_name(vma);
> +		if (anon_name) {
> +			if (strstr(anon_name->name, "scudo"))
> +				(*native_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "libc_malloc"))
> +				(*native_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "GWP-ASan"))
> +				(*native_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-alloc space"))
> +				(*java_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-main space"))
> +				(*java_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-large object space"))
> +				(*java_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-free list large object space"))
> +				(*java_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-non moving space"))
> +				(*java_heap) += cur_pss;
> +			else if (strstr(anon_name->name, "dalvik-zygote space"))
> +				(*java_heap) += cur_pss;
> +		}
> +	}
> +}
> +
> +void mbraink_get_process_memory_info(pid_t current_pid,
> +				     struct mbraink_process_memory_data *process_memory_buffer)
> +{
> +	struct task_struct *t = NULL;
> +	struct mm_struct *mm = NULL;
> +	struct vm_area_struct *vma = NULL;
> +	struct mem_size_stats mss;
> +	unsigned short pid_count = 0;
> +	unsigned long pss, uss, rss, swap, cur_pss;
> +	unsigned long java_heap = 0, native_heap = 0;
> +	struct vma_iterator vmi;
> +
> +	memset(process_memory_buffer, 0, sizeof(struct mbraink_process_memory_data));
> +	process_memory_buffer->pid = 0;
> +
> +	read_lock(&tasklist_lock);
> +	for_each_process(t) {
> +		if (t->pid <= current_pid)
> +			continue;
> +
> +		mm = t->mm;
> +		if (mm) {
> +			java_heap = 0;
> +			native_heap = 0;
> +			pid_count = process_memory_buffer->pid_count;
> +
> +			process_memory_buffer->drv_data[pid_count].pid =
> +				(unsigned short)(t->pid);
> +			process_memory_buffer->pid =
> +				(unsigned short)(t->pid);
> +
> +			memset(&mss, 0, sizeof(mss));
> +			get_task_struct(t);
> +			mmgrab(mm);
> +			read_unlock(&tasklist_lock);
> +			mmap_read_lock(mm);
> +			vma_iter_init(&vmi, mm, 0);
> +			for_each_vma(vmi, vma) {
> +				cur_pss = (unsigned long)(mss.pss >> PSS_SHIFT);
> +				smap_gather_stats(vma, &mss, 0);
> +				cur_pss =
> +					((unsigned long)(mss.pss >> PSS_SHIFT)) - cur_pss;
> +				cur_pss = cur_pss / 1024;
> +				mbraink_map_vma(vma, cur_pss, &native_heap, &java_heap);
> +			}
> +			mmap_read_unlock(mm);
> +			read_lock(&tasklist_lock);
> +			mmdrop(mm);
> +			put_task_struct(t);
> +
> +			pss = (unsigned long)(mss.pss >> PSS_SHIFT) / 1024;
> +			uss = (mss.private_clean + mss.private_dirty) / 1024;
> +			rss = (mss.resident) / 1024;
> +			swap = (mss.swap) / 1024;
> +
> +			process_memory_buffer->drv_data[pid_count].pss = pss;
> +			process_memory_buffer->drv_data[pid_count].uss = uss;
> +			process_memory_buffer->drv_data[pid_count].rss = rss;
> +			process_memory_buffer->drv_data[pid_count].swap = swap;
> +			process_memory_buffer->drv_data[pid_count].java_heap =
> +									java_heap;
> +			process_memory_buffer->drv_data[pid_count].native_heap =
> +									native_heap;
> +			process_memory_buffer->pid_count++;
> +
> +			break;
> +		}
> +	}
> +	read_unlock(&tasklist_lock);
> +}
> +
> +/*****************************************************************
> + * Note: this function can only be used during tracing function
> + * This function is only used in tracing function so that there
> + * is no need for task t spinlock protection
> + *****************************************************************/
> +static u64 mbraink_get_specific_process_jiffies(struct task_struct *t)
> +{
> +	u64 stime = 0, utime = 0, cutime = 0, cstime = 0;
> +	u64 process_jiffies = 0;
> +
> +	if (t->pid == t->tgid) {
> +		cutime = t->signal->cutime;
> +		cstime = t->signal->cstime;
> +		if (t->flags & PF_KTHREAD)
> +			task_cputime_adjusted(t, &utime, &stime);
> +		else
> +			thread_group_cputime_adjusted(t, &utime, &stime);
> +
> +		process_jiffies = nsec_to_clock_t(utime) +
> +				nsec_to_clock_t(stime) +
> +				nsec_to_clock_t(cutime) +
> +				nsec_to_clock_t(cstime);
> +	} else {
> +		task_cputime_adjusted(t, &utime, &stime);
> +		process_jiffies = nsec_to_clock_t(utime) + nsec_to_clock_t(stime);
> +	}
> +
> +	return process_jiffies;
> +}
> +
> +/***************************************************************
> + * Note: this function can only be used during tracing function
> + * This function is only used in tracing function so that there
> + * is no need for task t spinlock protection
> + **************************************************************/
> +static u16 mbraink_get_specific_process_uid(struct task_struct *t)
> +{
> +	const struct cred *cred = NULL;
> +	u16 val = 0;
> +
> +	cred = get_task_cred(t);
> +	val = cred->uid.val;
> +	put_cred(cred);
> +
> +	return val;
> +}
> +
> +static void mbraink_trace_sched_process_exit(void *data, struct task_struct *t)
> +{
> +	int i = 0;
> +	struct timespec64 tv = { 0 };
> +	unsigned long flags;
> +
> +	if (t->pid == t->tgid) {
> +		spin_lock_irqsave(&tracing_pidlist_lock, flags);
> +		for (i = 0; i < MAX_TRACE_NUM; i++) {
> +			if (mbraink_tracing_pidlist_data[i].pid == (unsigned short)t->pid) {
> +				ktime_get_real_ts64(&tv);
> +				mbraink_tracing_pidlist_data[i].end =
> +					(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
> +				mbraink_tracing_pidlist_data[i].jiffies =
> +						mbraink_get_specific_process_jiffies(t);
> +				mbraink_tracing_pidlist_data[i].dirty = true;
> +
> +				break;
> +			}
> +		}
> +		if (i == MAX_TRACE_NUM) {
> +			for (i = 0; i < MAX_TRACE_NUM; i++) {
> +				if (mbraink_tracing_pidlist_data[i].pid == 0) {
> +					mbraink_tracing_pidlist_data[i].pid =
> +							(unsigned short)(t->pid);
> +					mbraink_tracing_pidlist_data[i].tgid =
> +							(unsigned short)(t->tgid);
> +					mbraink_tracing_pidlist_data[i].uid =
> +							mbraink_get_specific_process_uid(t);
> +					mbraink_tracing_pidlist_data[i].priority =
> +							t->prio - MAX_RT_PRIO;
> +					memcpy(mbraink_tracing_pidlist_data[i].name,
> +					       t->comm, TASK_COMM_LEN);
> +					ktime_get_real_ts64(&tv);
> +					mbraink_tracing_pidlist_data[i].end =
> +							(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
> +					mbraink_tracing_pidlist_data[i].jiffies =
> +							mbraink_get_specific_process_jiffies(t);
> +					mbraink_tracing_pidlist_data[i].dirty = true;
> +
> +					break;
> +				}
> +			}
> +			if (i == MAX_TRACE_NUM) {
> +				pr_info("%s pid=%u:%s.\n", __func__, t->pid, t->comm);
> +				memset(mbraink_tracing_pidlist_data, 0,
> +				       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
> +			}
> +		}
> +		spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
> +	}
> +}
> +
> +static void mbraink_trace_sched_process_fork(void *data, struct task_struct *t,
> +					     struct task_struct *p)
> +{
> +	int i = 0;
> +	struct timespec64 tv = { 0 };
> +	unsigned long flags;
> +
> +	if (p->pid == p->tgid) {
> +		spin_lock_irqsave(&tracing_pidlist_lock, flags);
> +		for (i = 0; i < MAX_TRACE_NUM; i++) {
> +			if (mbraink_tracing_pidlist_data[i].pid == 0) {
> +				mbraink_tracing_pidlist_data[i].pid = (unsigned short)(p->pid);
> +				mbraink_tracing_pidlist_data[i].tgid = (unsigned short)(p->tgid);
> +				mbraink_tracing_pidlist_data[i].uid =
> +						mbraink_get_specific_process_uid(p);
> +				mbraink_tracing_pidlist_data[i].priority = p->prio - MAX_RT_PRIO;
> +				memcpy(mbraink_tracing_pidlist_data[i].name,
> +				       p->comm, TASK_COMM_LEN);
> +				ktime_get_real_ts64(&tv);
> +				mbraink_tracing_pidlist_data[i].start =
> +						(tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
> +				mbraink_tracing_pidlist_data[i].dirty = true;
> +				break;
> +			}
> +		}
> +
> +		if (i == MAX_TRACE_NUM) {
> +			pr_info("%s child_pid=%u:%s.\n", __func__, p->pid, p->comm);
> +			memset(mbraink_tracing_pidlist_data, 0,
> +			       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
> +		}
> +		spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
> +	}
> +}
> +
> +int mbraink_process_tracer_init(void)
> +{
> +	int ret = 0;
> +
> +	memset(mbraink_tracing_pidlist_data, 0,
> +	       sizeof(struct mbraink_tracing_pidlist) * MAX_TRACE_NUM);
> +
> +	ret = register_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
> +	if (ret) {
> +		pr_notice("register_trace_sched_process_fork failed.\n");
> +		goto register_trace_sched_process_fork;
> +	}
> +	ret = register_trace_sched_process_exit(mbraink_trace_sched_process_exit, NULL);
> +	if (ret) {
> +		pr_notice("register register_trace_sched_process_exit failed.\n");
> +		goto register_trace_sched_process_exit;
> +	}
> +
> +	return ret;
> +
> +register_trace_sched_process_exit:
> +	unregister_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
> +register_trace_sched_process_fork:
> +	return ret;
> +}
> +
> +void mbraink_process_tracer_exit(void)
> +{
> +	unregister_trace_sched_process_fork(mbraink_trace_sched_process_fork, NULL);
> +	unregister_trace_sched_process_exit(mbraink_trace_sched_process_exit, NULL);
> +}
> +
> +void mbraink_get_tracing_pid_info(unsigned short current_idx,
> +				  struct mbraink_tracing_pid_data *tracing_pid_buffer)
> +{
> +	int i = 0;
> +	int ret = 0;
> +	unsigned long flags;
> +	unsigned short tracing_count = 0;
> +
> +	spin_lock_irqsave(&tracing_pidlist_lock, flags);
> +
> +	memset(tracing_pid_buffer, 0, sizeof(struct mbraink_tracing_pid_data));
> +
> +	for (i = current_idx; i < MAX_TRACE_NUM; i++) {
> +		if (mbraink_tracing_pidlist_data[i].dirty == 0) {
> +			continue;
> +		} else {
> +			tracing_count = tracing_pid_buffer->tracing_count;
> +			if (tracing_count < MAX_TRACE_PID_NUM) {
> +				tracing_pid_buffer->drv_data[tracing_count].pid =
> +						mbraink_tracing_pidlist_data[i].pid;
> +				tracing_pid_buffer->drv_data[tracing_count].tgid =
> +						mbraink_tracing_pidlist_data[i].tgid;
> +				tracing_pid_buffer->drv_data[tracing_count].uid =
> +						mbraink_tracing_pidlist_data[i].uid;
> +				tracing_pid_buffer->drv_data[tracing_count].priority =
> +						mbraink_tracing_pidlist_data[i].priority;
> +				memcpy(tracing_pid_buffer->drv_data[tracing_count].name,
> +				       mbraink_tracing_pidlist_data[i].name, TASK_COMM_LEN);
> +				tracing_pid_buffer->drv_data[tracing_count].start =
> +						mbraink_tracing_pidlist_data[i].start;
> +				tracing_pid_buffer->drv_data[tracing_count].end =
> +						mbraink_tracing_pidlist_data[i].end;
> +				tracing_pid_buffer->drv_data[tracing_count].jiffies =
> +						mbraink_tracing_pidlist_data[i].jiffies;
> +				tracing_pid_buffer->tracing_count++;
> +				/*Deal with the end process record*/
> +				if (mbraink_tracing_pidlist_data[i].end != 0) {
> +					mbraink_tracing_pidlist_data[i].pid = 0;
> +					mbraink_tracing_pidlist_data[i].tgid = 0;
> +					mbraink_tracing_pidlist_data[i].uid = 0;
> +					mbraink_tracing_pidlist_data[i].priority = 0;
> +					memset(mbraink_tracing_pidlist_data[i].name,
> +					       0, TASK_COMM_LEN);
> +					mbraink_tracing_pidlist_data[i].start = 0;
> +					mbraink_tracing_pidlist_data[i].end = 0;
> +					mbraink_tracing_pidlist_data[i].jiffies = 0;
> +					mbraink_tracing_pidlist_data[i].dirty = false;
> +				} else {
> +					mbraink_tracing_pidlist_data[i].dirty = false;
> +				}
> +			} else {
> +				ret = -1;
> +				tracing_pid_buffer->tracing_idx = i;
> +				break;
> +			}
> +		}
> +	}
> +	pr_info("%s: current_idx = %u, count = %u\n",
> +		__func__, tracing_pid_buffer->tracing_idx, tracing_pid_buffer->tracing_count);
> +	spin_unlock_irqrestore(&tracing_pidlist_lock, flags);
> +}
> diff --git a/drivers/misc/mediatek_mbraink/mbraink_data.h b/drivers/misc/mediatek_mbraink/mbraink_data.h
> new file mode 100644
> index 000000000000..2d1a6b488caa
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/mbraink_data.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2023 MediaTek Inc.
> + */
> +#ifndef MBRAINK_DATA_H
> +#define MBRAINK_DATA_H
> +#include <linux/string_helpers.h>
> +#include <linux/sched.h>
> +#include <linux/sched/task.h>
> +#include <linux/mm_types.h>
> +#include <linux/pid.h>
> +
> +#include "mbraink_ioctl_struct_define.h"
> +
> +#define PSS_SHIFT			12
> +#define MAX_RT_PRIO			100
> +#define MAX_TRACE_NUM			3072
> +
> +struct mbraink_tracing_pidlist {
> +	unsigned short pid;
> +	unsigned short tgid;
> +	unsigned short uid;
> +	int priority;
> +	char name[TASK_COMM_LEN];
> +	long long start;
> +	long long end;
> +	u64 jiffies;
> +	bool dirty;
> +};
> +
> +struct mem_size_stats {
> +	unsigned long resident;
> +	unsigned long shared_clean;
> +	unsigned long shared_dirty;
> +	unsigned long private_clean;
> +	unsigned long private_dirty;
> +	unsigned long referenced;
> +	unsigned long anonymous;
> +	unsigned long lazyfree;
> +	unsigned long anonymous_thp;
> +	unsigned long shmem_thp;
> +	unsigned long file_thp;
> +	unsigned long swap;
> +	unsigned long shared_hugetlb;
> +	unsigned long private_hugetlb;
> +	u64 pss;
> +	u64 pss_anon;
> +	u64 pss_file;
> +	u64 pss_shmem;
> +	u64 pss_locked;
> +	u64 swap_pss;
> +	bool check_shmem_swap;
> +};
> +
> +void mbraink_get_process_memory_info(pid_t current_pid,
> +				     struct mbraink_process_memory_data *process_memory_buffer);
> +int mbraink_process_tracer_init(void);
> +void mbraink_process_tracer_exit(void);
> +void mbraink_get_tracing_pid_info(unsigned short current_idx,
> +				  struct mbraink_tracing_pid_data *tracing_pid_buffer);
> +void smap_gather_stats(struct vm_area_struct *vma,
> +		       struct mem_size_stats *mss, unsigned long start);
> +void task_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
> +void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st);
> +u64 nsec_to_clock_t(u64 x);
> +#endif
> diff --git a/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h b/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
> new file mode 100644
> index 000000000000..d655d8893f0f
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/mbraink_ioctl_struct_define.h
> @@ -0,0 +1,44 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2023 MediaTek Inc.
> + */
> +#ifndef MBRAINK_IOCTL_STRUCT_H
> +#define MBRAINK_IOCTL_STRUCT_H
> +
> +#define MAX_MEM_STRUCT_SZ			4
> +#define MAX_TRACE_PID_NUM			16
> +
> +struct mbraink_process_memory_struct {
> +	unsigned short pid;
> +	unsigned long pss;
> +	unsigned long uss;
> +	unsigned long rss;
> +	unsigned long swap;
> +	unsigned long java_heap;
> +	unsigned long native_heap;
> +};
> +
> +struct mbraink_process_memory_data {
> +	unsigned short pid;
> +	unsigned short pid_count;
> +	struct mbraink_process_memory_struct drv_data[MAX_MEM_STRUCT_SZ];
> +};
> +
> +struct mbraink_tracing_pid {
> +	unsigned short pid;
> +	unsigned short tgid;
> +	unsigned short uid;
> +	int priority;
> +	char name[TASK_COMM_LEN];
> +	long long start;
> +	long long end;
> +	u64 jiffies;
> +};
> +
> +struct mbraink_tracing_pid_data {
> +	unsigned short tracing_idx;
> +	unsigned short tracing_count;
> +	struct mbraink_tracing_pid drv_data[MAX_TRACE_PID_NUM];
> +};
> +
> +#endif
> diff --git a/drivers/misc/mediatek_mbraink/mbraink_main.c b/drivers/misc/mediatek_mbraink/mbraink_main.c
> new file mode 100644
> index 000000000000..4e6aac51694a
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/mbraink_main.c
> @@ -0,0 +1,239 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023 MediaTek Inc.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/fs.h>
> +#include <linux/uaccess.h>
> +#include <linux/compat.h>
> +#include <linux/errno.h>
> +#include <linux/slab.h>
> +#include <linux/pm_runtime.h>
> +
> +#include "mbraink_main.h"
> +#include "mbraink_data.h"
> +
> +struct mbraink_data mbraink_priv;
> +
> +static int mbraink_open(struct inode *inode, struct file *filp)
> +{
> +	return 0;
> +}
> +
> +static int mbraink_release(struct inode *inode, struct file *filp)
> +{
> +	return 0;
> +}
> +
> +static long mbraink_ioctl(struct file *filp,
> +			  unsigned int cmd,
> +			  unsigned long arg)
> +{
> +	long ret = 0;
> +
> +	switch (cmd) {
> +	case RO_PROCESS_MEMORY:
> +	{
> +		struct mbraink_process_memory_data process_memory_buffer;
> +
> +		pid_t pid = 1;
> +
> +		if (copy_from_user(&process_memory_buffer,
> +				   (struct mbraink_process_memory_data *)arg,
> +				   sizeof(process_memory_buffer))) {
> +			pr_notice("copy process memory info from user Err!\n");
> +			return -EPERM;
> +		}
> +
> +		if (process_memory_buffer.pid > PID_MAX_DEFAULT ||
> +		    process_memory_buffer.pid_count > PID_MAX_DEFAULT) {
> +			pr_notice("process memory: Invalid pid_idx %u or pid_count %u\n",
> +				  process_memory_buffer.pid, process_memory_buffer.pid_count);
> +			return -EINVAL;
> +		}
> +		pid = process_memory_buffer.pid;
> +
> +		mbraink_get_process_memory_info(pid, &process_memory_buffer);
> +
> +		if (copy_to_user((struct mbraink_process_memory_data *)arg,
> +				 &process_memory_buffer,
> +				 sizeof(process_memory_buffer))) {
> +			pr_notice("Copy process_memory_info to UserSpace error!\n");
> +			return -EPERM;
> +		}
> +		break;
> +	}
> +	case RO_TRACE_PROCESS:
> +	{
> +		struct mbraink_tracing_pid_data tracing_pid_buffer;
> +
> +		unsigned short tracing_idx = 0;
> +
> +		if (copy_from_user(&tracing_pid_buffer,
> +				   (struct mbraink_tracing_pid_data *)arg,
> +				   sizeof(tracing_pid_buffer))) {
> +			pr_notice("copy tracing_pid_buffer data from user Err!\n");
> +			return -EPERM;
> +		}
> +
> +		if (tracing_pid_buffer.tracing_idx > MAX_TRACE_NUM) {
> +			pr_notice("invalid tracing_idx %u !\n",
> +				  tracing_pid_buffer.tracing_idx);
> +			return -EINVAL;
> +		}
> +		tracing_idx = tracing_pid_buffer.tracing_idx;
> +
> +		mbraink_get_tracing_pid_info(tracing_idx, &tracing_pid_buffer);
> +
> +		if (copy_to_user((struct mbraink_tracing_pid_data *)arg,
> +				 &tracing_pid_buffer,
> +				 sizeof(tracing_pid_buffer))) {
> +			pr_notice("Copy tracing_pid_buffer to UserSpace error!\n");
> +			return -EPERM;
> +		}
> +		break;
> +	}
> +	default:
> +		pr_notice("illegal ioctl number %u.\n", cmd);
> +		return -EINVAL;
> +	}
> +
> +	return ret;
> +}
> +
> +#if IS_ENABLED(CONFIG_COMPAT)
> +static long mbraink_compat_ioctl(struct file *filp,
> +				 unsigned int cmd, unsigned long arg)
> +{
> +	return mbraink_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
> +}
> +#endif
> +
> +static const struct file_operations mbraink_fops = {
> +	.owner		= THIS_MODULE,
> +	.open		= mbraink_open,
> +	.release        = mbraink_release,
> +	.unlocked_ioctl = mbraink_ioctl,
> +#if IS_ENABLED(CONFIG_COMPAT)
> +	.compat_ioctl   = mbraink_compat_ioctl,
> +#endif
> +};
> +
> +#if IS_ENABLED(CONFIG_PM_SLEEP)
> +static int mbraink_suspend(struct device *dev)
> +{
> +	int ret;
> +
> +	pr_info("[MBK_INFO] %s\n", __func__);
> +
> +	ret = pm_generic_suspend(dev);
> +
> +	return ret;
> +}
> +
> +static int mbraink_resume(struct device *dev)
> +{
> +	int ret;
> +
> +	pr_info("[MBK_INFO] %s\n", __func__);
> +
> +	ret = pm_generic_resume(dev);
> +
> +	return ret;
> +}
> +
> +static const struct dev_pm_ops mbraink_class_dev_pm_ops = {
> +	.suspend	= mbraink_suspend,
> +	.resume	= mbraink_resume,
> +};
> +
> +#define MBRAINK_CLASS_DEV_PM_OPS (&mbraink_class_dev_pm_ops)
> +#else
> +#define MBRAINK_CLASS_DEV_PM_OPS NULL
> +#endif /*end of CONFIG_PM_SLEEP*/
> +
> +static int mbraink_dev_init(void)
> +{
> +	mbraink_priv.mbraink_dev_no = 0;
> +
> +	/*Allocating Major number*/
> +	if ((alloc_chrdev_region(&mbraink_priv.mbraink_dev_no, 0, 1, CHRDEV_NAME)) < 0) {
> +		pr_notice("Cannot allocate major number %u\n",
> +			  mbraink_priv.mbraink_dev_no);
> +		return -EBADF;
> +	}
> +
> +	/*Initialize cdev structure*/
> +	cdev_init(&mbraink_priv.mbraink_cdev, &mbraink_fops);
> +
> +	/*Adding character device to the system*/
> +	if ((cdev_add(&mbraink_priv.mbraink_cdev, mbraink_priv.mbraink_dev_no, 1)) < 0) {
> +		pr_notice("Cannot add the device to the system\n");
> +		goto r_class;
> +	}
> +
> +	mbraink_priv.mbraink_class = class_create(THIS_MODULE, "mbraink_host");
> +	/*Register mbraink class*/
> +	if (IS_ERR(mbraink_priv.mbraink_class)) {
> +		pr_notice("Cannot create the mbraink class\n");
> +		goto r_class;
> +	}
> +	mbraink_priv.mbraink_class->pm = MBRAINK_CLASS_DEV_PM_OPS;
> +
> +	/*Register mbraink device*/
> +	if (IS_ERR(device_create(mbraink_priv.mbraink_class,
> +				 NULL, mbraink_priv.mbraink_dev_no, NULL, "mbraink"))) {
> +		pr_notice("Cannot create the mbraink Device\n");
> +		goto r_device;
> +	}
> +	pr_info("[MBK_INFO] %s: Mbraink device init done.\n", __func__);
> +
> +	return 0;
> +
> +r_device:
> +	class_destroy(mbraink_priv.mbraink_class);
> +r_class:
> +	unregister_chrdev_region(mbraink_priv.mbraink_dev_no, 1);
> +
> +	return -EPERM;
> +}
> +
> +static int mbraink_init(void)
> +{
> +	int ret = 0;
> +
> +	ret = mbraink_dev_init();
> +	if (ret)
> +		pr_notice("mbraink device init failed.\n");
> +
> +	ret = mbraink_process_tracer_init();
> +	if (ret)
> +		pr_notice("mbraink tracer init failed.\n");
> +
> +	return ret;
> +}
> +
> +static void mbraink_dev_exit(void)
> +{
> +	device_destroy(mbraink_priv.mbraink_class, mbraink_priv.mbraink_dev_no);
> +	class_destroy(mbraink_priv.mbraink_class);
> +	cdev_del(&mbraink_priv.mbraink_cdev);
> +	unregister_chrdev_region(mbraink_priv.mbraink_dev_no, 1);
> +
> +	pr_info("[MBK_INFO] %s: MBraink device exit done\n", __func__);
> +}
> +
> +static void mbraink_exit(void)
> +{
> +	mbraink_dev_exit();
> +	mbraink_process_tracer_exit();
> +}
> +
> +module_init(mbraink_init);
> +module_exit(mbraink_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("<Wei-chin.Tsai@mediatek.com>");
> +MODULE_DESCRIPTION("MBraink Linux Device Driver");
> +MODULE_VERSION("1.0");
> diff --git a/drivers/misc/mediatek_mbraink/mbraink_main.h b/drivers/misc/mediatek_mbraink/mbraink_main.h
> new file mode 100644
> index 000000000000..36549f0d90d1
> --- /dev/null
> +++ b/drivers/misc/mediatek_mbraink/mbraink_main.h
> @@ -0,0 +1,36 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2023 MediaTek Inc.
> + */
> +
> +#ifndef MBRAINK_MAIN_H
> +#define MBRAINK_MAIN_H
> +
> +#include <linux/ioctl.h>
> +#include <linux/cdev.h>
> +#include <linux/pid.h>
> +#include <linux/device.h>
> +#include <linux/kdev_t.h>
> +
> +#include "mbraink_ioctl_struct_define.h"
> +
> +#define IOC_MAGIC		'k'
> +
> +/*Mbrain Delegate Info List*/
> +#define PROCESS_MEMORY_INFO	'4'
> +#define TRACE_PROCESS_INFO      'a'
> +
> +/*Mbrain Delegate IOCTL List*/
> +#define RO_PROCESS_MEMORY	_IOR(IOC_MAGIC, PROCESS_MEMORY_INFO, \
> +				     struct mbraink_process_memory_data*)
> +#define RO_TRACE_PROCESS        _IOR(IOC_MAGIC, TRACE_PROCESS_INFO, \
> +				     struct mbraink_tracing_pid_data*)
> +
> +struct mbraink_data {
> +#define CHRDEV_NAME     "mbraink_chrdev"
> +	dev_t mbraink_dev_no;
> +	struct cdev mbraink_cdev;
> +	struct class *mbraink_class;
> +};
> +
> +#endif /*end of MBRAINK_MAIN_H*/


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  9:59     ` Wei-chin Tsai (蔡維晉)
@ 2023-06-14 12:11       ` AngeloGioacchino Del Regno
  2023-06-14 15:53         ` Wei-chin Tsai (蔡維晉)
  2023-06-14 16:21         ` Russell King (Oracle)
  0 siblings, 2 replies; 17+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-06-14 12:11 UTC (permalink / raw)
  To: Wei-chin Tsai (蔡維晉), linux
  Cc: linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒)

Il 14/06/23 11:59, Wei-chin Tsai (蔡維晉) ha scritto:
> On Wed, 2023-06-14 at 08:16 +0100, Russell King (Oracle) wrote:
>>   	
>> External email : Please do not click links or open attachments until
>> you have verified the sender or the content.
>>   On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai wrote:
>>> diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
>>> index 0e8ff85890ad..df91412a1069 100644
>>> --- a/arch/arm/kernel/process.c
>>> +++ b/arch/arm/kernel/process.c
>>> @@ -343,6 +343,7 @@ const char *arch_vma_name(struct vm_area_struct
>> *vma)
>>>   {
>>>   return is_gate_vma(vma) ? "[vectors]" : NULL;
>>>   }
>>> +EXPORT_SYMBOL_GPL(arch_vma_name);
>> ...
>>> diff --git a/kernel/signal.c b/kernel/signal.c
>>> index b5370fe5c198..a1abe77fcdc3 100644
>>> --- a/kernel/signal.c
>>> +++ b/kernel/signal.c
>>> @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct
>> vm_area_struct *vma)
>>>   {
>>>   return NULL;
>>>   }
>>> +EXPORT_SYMBOL_GPL(arch_vma_name);
>>
>> Have you confirmed:
>> 1) whether this actually builds
>> 2) whether this results in one or two arch_vma_name exports
>>
>> ?
>>
>> -- 
>> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
>> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
> 
> Hi Russell,
> 
> We did confirm that it can be built successfully in kernel 6.1 and run
> well in our system.
> 

It runs well in your system and can be built successfully because you're building
for ARM64, not for ARM...

> Actually, we only use this export symbol "arch_vma_name"
> from kernel/signal.c in arm64. We also export symbol for arch_vma_name
> in arch/arm/kernel/process.c because that, one day in the future,  we
> are afraid that we also need this function in arm platform.
> 
> Thanks.
> 
> Regards,
> 
> Jim
> 



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
                     ` (2 preceding siblings ...)
  2023-06-14 10:05   ` kernel test robot
@ 2023-06-14 13:05   ` kernel test robot
  2023-06-14 15:39     ` [PATCH v3 1/1] memory: Fix export symbol twice compiler error for "export symbols for memory related functions" patch Wei Chin Tsai
  3 siblings, 1 reply; 17+ messages in thread
From: kernel test robot @ 2023-06-14 13:05 UTC (permalink / raw)
  To: Wei Chin Tsai, linux-kernel, Russell King, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: oe-kbuild-all, wsd_upstream, wei-chin.tsai, mel.lee, ivan.tseng,
	linux-arm-kernel, linux-fsdevel, linux-mediatek

Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.4-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Chin-Tsai/kernel-process-fork-exit-export-symbol-for-fork-exit-tracing-functions/20230614-112218
base:   char-misc/char-misc-testing
patch link:    https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai%40mediatek.com
patch subject: [PATCH v2 2/3] memory: export symbols for memory related functions
config: arm-randconfig-r033-20230612 (https://download.01.org/0day-ci/archive/20230614/202306142030.GjGWnIkY-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        git remote add char-misc https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
        git fetch char-misc char-misc-testing
        git checkout char-misc/char-misc-testing
        b4 shazam https://lore.kernel.org/r/20230614032038.11699-3-Wei-chin.Tsai@mediatek.com
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306142030.GjGWnIkY-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: vmlinux: 'arch_vma_name' exported twice. Previous export was in vmlinux
WARNING: modpost: EXPORT symbol "arch_vma_name" [vmlinux] version generation failed, symbol will not be versioned.
Is "arch_vma_name" prototyped in <asm/asm-prototypes.h>?

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v3 1/1] memory: Fix export symbol twice compiler error for "export symbols for memory related functions" patch
  2023-06-14 13:05   ` kernel test robot
@ 2023-06-14 15:39     ` Wei Chin Tsai
  2023-06-14 16:24       ` Russell King (Oracle)
  0 siblings, 1 reply; 17+ messages in thread
From: Wei Chin Tsai @ 2023-06-14 15:39 UTC (permalink / raw)
  To: lkp
  Cc: Wei-chin.Tsai, angelogioacchino.delregno, ivan.tseng,
	linux-arm-kernel, linux-fsdevel, linux-kernel, linux-mediatek,
	linux, matthias.bgg, mel.lee, oe-kbuild-all, wsd_upstream

User could not add the export symbol "arch_vma_name"
in arch/arm/kernel/process.c and kernel/signal.c both.
It would cause the export symbol twice compiler error
Reported-by: kernel test robot <lkp@intel.com>

Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
---
 arch/arm/kernel/process.c | 3 +++
 kernel/signal.c           | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index df91412a1069..d71a9bafb584 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -343,7 +343,10 @@ const char *arch_vma_name(struct vm_area_struct *vma)
 {
 	return is_gate_vma(vma) ? "[vectors]" : NULL;
 }
+
+#ifdef CONFIG_ARM
 EXPORT_SYMBOL_GPL(arch_vma_name);
+#endif
 
 /* If possible, provide a placement hint at a random offset from the
  * stack for the sigpage and vdso pages.
diff --git a/kernel/signal.c b/kernel/signal.c
index a1abe77fcdc3..f7d03450781e 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4700,7 +4700,10 @@ __weak const char *arch_vma_name(struct vm_area_struct *vma)
 {
 	return NULL;
 }
+
+#ifdef CONFIG_ARM64
 EXPORT_SYMBOL_GPL(arch_vma_name);
+#endif
 
 static inline void siginfo_buildtime_checks(void)
 {
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14 12:11       ` AngeloGioacchino Del Regno
@ 2023-06-14 15:53         ` Wei-chin Tsai (蔡維晉)
  2023-06-14 16:21         ` Russell King (Oracle)
  1 sibling, 0 replies; 17+ messages in thread
From: Wei-chin Tsai (蔡維晉) @ 2023-06-14 15:53 UTC (permalink / raw)
  To: linux, angelogioacchino.delregno
  Cc: linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒)

On Wed, 2023-06-14 at 14:11 +0200, AngeloGioacchino Del Regno wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  Il 14/06/23 11:59, Wei-chin Tsai (蔡維晉) ha scritto:
> > On Wed, 2023-06-14 at 08:16 +0100, Russell King (Oracle) wrote:
> >>   
> >> External email : Please do not click links or open attachments
> until
> >> you have verified the sender or the content.
> >>   On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai wrote:
> >>> diff --git a/arch/arm/kernel/process.c
> b/arch/arm/kernel/process.c
> >>> index 0e8ff85890ad..df91412a1069 100644
> >>> --- a/arch/arm/kernel/process.c
> >>> +++ b/arch/arm/kernel/process.c
> >>> @@ -343,6 +343,7 @@ const char *arch_vma_name(struct
> vm_area_struct
> >> *vma)
> >>>   {
> >>>   return is_gate_vma(vma) ? "[vectors]" : NULL;
> >>>   }
> >>> +EXPORT_SYMBOL_GPL(arch_vma_name);
> >> ...
> >>> diff --git a/kernel/signal.c b/kernel/signal.c
> >>> index b5370fe5c198..a1abe77fcdc3 100644
> >>> --- a/kernel/signal.c
> >>> +++ b/kernel/signal.c
> >>> @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct
> >> vm_area_struct *vma)
> >>>   {
> >>>   return NULL;
> >>>   }
> >>> +EXPORT_SYMBOL_GPL(arch_vma_name);
> >>
> >> Have you confirmed:
> >> 1) whether this actually builds
> >> 2) whether this results in one or two arch_vma_name exports
> >>
> >> ?
> >>
> >> -- 
> >> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> >> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
> > 
> > Hi Russell,
> > 
> > We did confirm that it can be built successfully in kernel 6.1 and
> run
> > well in our system.
> > 
> 
> It runs well in your system and can be built successfully because
> you're building
> for ARM64, not for ARM...
> 
> > Actually, we only use this export symbol "arch_vma_name"
> > from kernel/signal.c in arm64. We also export symbol for
> arch_vma_name
> > in arch/arm/kernel/process.c because that, one day in the
> future,  we
> > are afraid that we also need this function in arm platform.
> > 
> > Thanks.
> > 
> > Regards,
> > 
> > Jim
> > 
> 

Hi Russell and Angelo,

Please use the following patch to see if the problem still exists.
Thanks.

From 150162ce2365557710e9ac8ef62c59f870ffbbb0 Mon Sep 17 00:00:00 2001
From: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
Date: Wed, 14 Jun 2023 23:31:02 +0800
Subject: [PATCH v3 1/1] memory: Fix export symbol twice compiler error
for
 "export symbols for memory related functions" patch

User could not add the export symbol "arch_vma_name"
in arch/arm/kernel/process.c and kernel/signal.c both.
It would cause the export symbol twice compiler error
Reported-by: kernel test robot <lkp@intel.com>

Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>
---
 arch/arm/kernel/process.c | 3 +++
 kernel/signal.c           | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index df91412a1069..d71a9bafb584 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -343,7 +343,10 @@ const char *arch_vma_name(struct vm_area_struct
*vma)
 {
 	return is_gate_vma(vma) ? "[vectors]" : NULL;
 }
+
+#ifdef CONFIG_ARM
 EXPORT_SYMBOL_GPL(arch_vma_name);
+#endif
 
 /* If possible, provide a placement hint at a random offset from the
  * stack for the sigpage and vdso pages.
diff --git a/kernel/signal.c b/kernel/signal.c
index a1abe77fcdc3..f7d03450781e 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4700,7 +4700,10 @@ __weak const char *arch_vma_name(struct
vm_area_struct *vma)
 {
 	return NULL;
 }
+
+#ifdef CONFIG_ARM64
 EXPORT_SYMBOL_GPL(arch_vma_name);
+#endif
 
 static inline void siginfo_buildtime_checks(void)
 {
-- 
2.18.0

Regards,

Jim
> 

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14 12:11       ` AngeloGioacchino Del Regno
  2023-06-14 15:53         ` Wei-chin Tsai (蔡維晉)
@ 2023-06-14 16:21         ` Russell King (Oracle)
  2023-06-14 17:11           ` Matthew Wilcox
  2023-06-15  2:08           ` Wei-chin Tsai (蔡維晉)
  1 sibling, 2 replies; 17+ messages in thread
From: Russell King (Oracle) @ 2023-06-14 16:21 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno
  Cc: Wei-chin Tsai (蔡維晉),
	linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒)

On Wed, Jun 14, 2023 at 02:11:25PM +0200, AngeloGioacchino Del Regno wrote:
> Il 14/06/23 11:59, Wei-chin Tsai (蔡維晉) ha scritto:
> > On Wed, 2023-06-14 at 08:16 +0100, Russell King (Oracle) wrote:
> > >   	
> > > External email : Please do not click links or open attachments until
> > > you have verified the sender or the content.
> > >   On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai wrote:
> > > > diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
> > > > index 0e8ff85890ad..df91412a1069 100644
> > > > --- a/arch/arm/kernel/process.c
> > > > +++ b/arch/arm/kernel/process.c
> > > > @@ -343,6 +343,7 @@ const char *arch_vma_name(struct vm_area_struct
> > > *vma)
> > > >   {
> > > >   return is_gate_vma(vma) ? "[vectors]" : NULL;
> > > >   }
> > > > +EXPORT_SYMBOL_GPL(arch_vma_name);
> > > ...
> > > > diff --git a/kernel/signal.c b/kernel/signal.c
> > > > index b5370fe5c198..a1abe77fcdc3 100644
> > > > --- a/kernel/signal.c
> > > > +++ b/kernel/signal.c
> > > > @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct
> > > vm_area_struct *vma)
> > > >   {
> > > >   return NULL;
> > > >   }
> > > > +EXPORT_SYMBOL_GPL(arch_vma_name);
> > > 
> > > Have you confirmed:
> > > 1) whether this actually builds
> > > 2) whether this results in one or two arch_vma_name exports
> > > 
> > > ?
> > > 
> > > -- 
> > > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
> > 
> > Hi Russell,
> > 
> > We did confirm that it can be built successfully in kernel 6.1 and run
> > well in our system.
> > 
> 
> It runs well in your system and can be built successfully because you're building
> for ARM64, not for ARM...
> 
> > Actually, we only use this export symbol "arch_vma_name"
> > from kernel/signal.c in arm64. We also export symbol for arch_vma_name
> > in arch/arm/kernel/process.c because that, one day in the future,  we
> > are afraid that we also need this function in arm platform.

What I'm trying to get at is that we have arch_vma_name in
arch/arm/kernel/process.c and also a weak function in kernel/signal.c.

Both of these end up adding an entry into the __ksymtab_strings
section and a ___ksymtab section for this symbol. So we end up with
two entries in each.

Now, if the one from kernel/signal.c points at its own weak function,
and that is found first, then that's the function that is going to be
bound, not the function that's overriding it.

If, instead, the export in kernel/signal.c ends up pointing at the
overriden function, then the export in arch/arm/kernel/process.c is
entirely redundant.

So, you need to get to the bottom of this... and until you do I'm
afraid I'll have to NAK this patch.

For the record, I suspect it's the latter scenario (we end up with
two entries pointing at the same function) but that's nothing more
than a hunch.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v3 1/1] memory: Fix export symbol twice compiler error for "export symbols for memory related functions" patch
  2023-06-14 15:39     ` [PATCH v3 1/1] memory: Fix export symbol twice compiler error for "export symbols for memory related functions" patch Wei Chin Tsai
@ 2023-06-14 16:24       ` Russell King (Oracle)
  0 siblings, 0 replies; 17+ messages in thread
From: Russell King (Oracle) @ 2023-06-14 16:24 UTC (permalink / raw)
  To: Wei Chin Tsai
  Cc: lkp, angelogioacchino.delregno, ivan.tseng, linux-arm-kernel,
	linux-fsdevel, linux-kernel, linux-mediatek, matthias.bgg,
	mel.lee, oe-kbuild-all, wsd_upstream

On Wed, Jun 14, 2023 at 11:39:02PM +0800, Wei Chin Tsai wrote:
> User could not add the export symbol "arch_vma_name"
> in arch/arm/kernel/process.c and kernel/signal.c both.
> It would cause the export symbol twice compiler error
> Reported-by: kernel test robot <lkp@intel.com>
> 
> Signed-off-by: Wei Chin Tsai <Wei-chin.Tsai@mediatek.com>

I'm sorry, but this patch is silly.

> diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
> index df91412a1069..d71a9bafb584 100644
> --- a/arch/arm/kernel/process.c
> +++ b/arch/arm/kernel/process.c
> @@ -343,7 +343,10 @@ const char *arch_vma_name(struct vm_area_struct *vma)
>  {
>  	return is_gate_vma(vma) ? "[vectors]" : NULL;
>  }
> +
> +#ifdef CONFIG_ARM
>  EXPORT_SYMBOL_GPL(arch_vma_name);
> +#endif

CONFIG_ARM will always be set here, so adding this ifdef is useless.

> diff --git a/kernel/signal.c b/kernel/signal.c
> index a1abe77fcdc3..f7d03450781e 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -4700,7 +4700,10 @@ __weak const char *arch_vma_name(struct vm_area_struct *vma)
>  {
>  	return NULL;
>  }
> +
> +#ifdef CONFIG_ARM64
>  EXPORT_SYMBOL_GPL(arch_vma_name);
> +#endif

Sorry, but no.

Please do the research I've now twice asked for.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14 16:21         ` Russell King (Oracle)
@ 2023-06-14 17:11           ` Matthew Wilcox
  2023-06-15  2:08           ` Wei-chin Tsai (蔡維晉)
  1 sibling, 0 replies; 17+ messages in thread
From: Matthew Wilcox @ 2023-06-14 17:11 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: AngeloGioacchino Del Regno,
	Wei-chin Tsai (蔡維晉),
	linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒)

On Wed, Jun 14, 2023 at 05:21:43PM +0100, Russell King (Oracle) wrote:
> What I'm trying to get at is that we have arch_vma_name in
> arch/arm/kernel/process.c and also a weak function in kernel/signal.c.
> 
> Both of these end up adding an entry into the __ksymtab_strings
> section and a ___ksymtab section for this symbol. So we end up with
> two entries in each.
> 
> Now, if the one from kernel/signal.c points at its own weak function,
> and that is found first, then that's the function that is going to be
> bound, not the function that's overriding it.
> 
> If, instead, the export in kernel/signal.c ends up pointing at the
> overriden function, then the export in arch/arm/kernel/process.c is
> entirely redundant.
> 
> So, you need to get to the bottom of this... and until you do I'm
> afraid I'll have to NAK this patch.

I think the patch should be NAKed indefinitely.  I had a quick look at
the user, and it seems like something is being done in the kernel that
should be done in userspace.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/3] memory: export symbols for memory related functions
  2023-06-14 16:21         ` Russell King (Oracle)
  2023-06-14 17:11           ` Matthew Wilcox
@ 2023-06-15  2:08           ` Wei-chin Tsai (蔡維晉)
  1 sibling, 0 replies; 17+ messages in thread
From: Wei-chin Tsai (蔡維晉) @ 2023-06-15  2:08 UTC (permalink / raw)
  To: linux, angelogioacchino.delregno
  Cc: linux-kernel, Mel Lee (李奇錚),
	linux-mediatek, wsd_upstream, linux-arm-kernel, linux-fsdevel,
	matthias.bgg, Ivan Tseng (曾志軒)

On Wed, 2023-06-14 at 17:21 +0100, Russell King (Oracle) wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  On Wed, Jun 14, 2023 at 02:11:25PM +0200, AngeloGioacchino Del Regno
> wrote:
> > Il 14/06/23 11:59, Wei-chin Tsai (蔡維晉) ha scritto:
> > > On Wed, 2023-06-14 at 08:16 +0100, Russell King (Oracle) wrote:
> > > >   
> > > > External email : Please do not click links or open attachments
> until
> > > > you have verified the sender or the content.
> > > >   On Wed, Jun 14, 2023 at 11:20:34AM +0800, Wei Chin Tsai
> wrote:
> > > > > diff --git a/arch/arm/kernel/process.c
> b/arch/arm/kernel/process.c
> > > > > index 0e8ff85890ad..df91412a1069 100644
> > > > > --- a/arch/arm/kernel/process.c
> > > > > +++ b/arch/arm/kernel/process.c
> > > > > @@ -343,6 +343,7 @@ const char *arch_vma_name(struct
> vm_area_struct
> > > > *vma)
> > > > >   {
> > > > >   return is_gate_vma(vma) ? "[vectors]" : NULL;
> > > > >   }
> > > > > +EXPORT_SYMBOL_GPL(arch_vma_name);
> > > > ...
> > > > > diff --git a/kernel/signal.c b/kernel/signal.c
> > > > > index b5370fe5c198..a1abe77fcdc3 100644
> > > > > --- a/kernel/signal.c
> > > > > +++ b/kernel/signal.c
> > > > > @@ -4700,6 +4700,7 @@ __weak const char *arch_vma_name(struct
> > > > vm_area_struct *vma)
> > > > >   {
> > > > >   return NULL;
> > > > >   }
> > > > > +EXPORT_SYMBOL_GPL(arch_vma_name);
> > > > 
> > > > Have you confirmed:
> > > > 1) whether this actually builds
> > > > 2) whether this results in one or two arch_vma_name exports
> > > > 
> > > > ?
> > > > 
> > > > -- 
> > > > RMK's Patch system: 
> https://www.armlinux.org.uk/developer/patches/
> > > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at
> last!
> > > 
> > > Hi Russell,
> > > 
> > > We did confirm that it can be built successfully in kernel 6.1
> and run
> > > well in our system.
> > > 
> > 
> > It runs well in your system and can be built successfully because
> you're building
> > for ARM64, not for ARM...
> > 
> > > Actually, we only use this export symbol "arch_vma_name"
> > > from kernel/signal.c in arm64. We also export symbol for
> arch_vma_name
> > > in arch/arm/kernel/process.c because that, one day in the
> future,  we
> > > are afraid that we also need this function in arm platform.
> 
> What I'm trying to get at is that we have arch_vma_name in
> arch/arm/kernel/process.c and also a weak function in
> kernel/signal.c.
> 
> Both of these end up adding an entry into the __ksymtab_strings
> section and a ___ksymtab section for this symbol. So we end up with
> two entries in each.
> 
> Now, if the one from kernel/signal.c points at its own weak function,
> and that is found first, then that's the function that is going to be
> bound, not the function that's overriding it.
> 
> If, instead, the export in kernel/signal.c ends up pointing at the
> overriden function, then the export in arch/arm/kernel/process.c is
> entirely redundant.
> 
> So, you need to get to the bottom of this... and until you do I'm
> afraid I'll have to NAK this patch.
> 
> For the record, I suspect it's the latter scenario (we end up with
> two entries pointing at the same function) but that's nothing more
> than a hunch.
> 
> -- 
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/

Hi Russell,

OK, I will do the research for your questions...

Thanks.


> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-06-15  2:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14  3:20 [PATCH v2 0/3] export symbols for process and memory related functions Wei Chin Tsai
2023-06-14  3:20 ` [PATCH v2 1/3] kernel : process fork/exit: export symbol for fork/exit tracing functions Wei Chin Tsai
2023-06-14  3:20 ` [PATCH v2 2/3] memory: export symbols for memory related functions Wei Chin Tsai
2023-06-14  7:16   ` Russell King (Oracle)
2023-06-14  9:59     ` Wei-chin Tsai (蔡維晉)
2023-06-14 12:11       ` AngeloGioacchino Del Regno
2023-06-14 15:53         ` Wei-chin Tsai (蔡維晉)
2023-06-14 16:21         ` Russell King (Oracle)
2023-06-14 17:11           ` Matthew Wilcox
2023-06-15  2:08           ` Wei-chin Tsai (蔡維晉)
2023-06-14  8:42   ` kernel test robot
2023-06-14 10:05   ` kernel test robot
2023-06-14 13:05   ` kernel test robot
2023-06-14 15:39     ` [PATCH v3 1/1] memory: Fix export symbol twice compiler error for "export symbols for memory related functions" patch Wei Chin Tsai
2023-06-14 16:24       ` Russell King (Oracle)
2023-06-14  3:20 ` [PATCH v2 3/3] misc : mediatek_mbraink : Collect the system process and memory data Wei Chin Tsai
2023-06-14 11:14   ` AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).