2023-01-22 17:07:38

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 1/8] eventfs: introducing struct tracefs_inode

Introducing tracefs_inode structure, this will help eventfs
to keep track of inode, flags and pointer to private date.

Renaming, removing static property from some function name.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/inode.c | 20 ++++++++++----------
fs/tracefs/internal.h | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+), 10 deletions(-)
create mode 100644 fs/tracefs/internal.h

diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index da85b39..015b7b8 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -127,7 +127,7 @@ static const struct inode_operations tracefs_dir_inode_operations = {
.rmdir = tracefs_syscall_rmdir,
};

-static struct inode *tracefs_get_inode(struct super_block *sb)
+struct inode *tracefs_get_inode(struct super_block *sb)
{
struct inode *inode = new_inode(sb);
if (inode) {
@@ -399,7 +399,7 @@ static struct file_system_type trace_fs_type = {
};
MODULE_ALIAS_FS("tracefs");

-static struct dentry *start_creating(const char *name, struct dentry *parent)
+struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
{
struct dentry *dentry;
int error;
@@ -437,7 +437,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
return dentry;
}

-static struct dentry *failed_creating(struct dentry *dentry)
+struct dentry *tracefs_failed_creating(struct dentry *dentry)
{
inode_unlock(d_inode(dentry->d_parent));
dput(dentry);
@@ -445,7 +445,7 @@ static struct dentry *failed_creating(struct dentry *dentry)
return NULL;
}

-static struct dentry *end_creating(struct dentry *dentry)
+struct dentry *tracefs_end_creating(struct dentry *dentry)
{
inode_unlock(d_inode(dentry->d_parent));
return dentry;
@@ -490,14 +490,14 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,
if (!(mode & S_IFMT))
mode |= S_IFREG;
BUG_ON(!S_ISREG(mode));
- dentry = start_creating(name, parent);
+ dentry = tracefs_start_creating(name, parent);

if (IS_ERR(dentry))
return NULL;

inode = tracefs_get_inode(dentry->d_sb);
if (unlikely(!inode))
- return failed_creating(dentry);
+ return tracefs_failed_creating(dentry);

inode->i_mode = mode;
inode->i_fop = fops ? fops : &tracefs_file_operations;
@@ -506,13 +506,13 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode,
inode->i_gid = d_inode(dentry->d_parent)->i_gid;
d_instantiate(dentry, inode);
fsnotify_create(d_inode(dentry->d_parent), dentry);
- return end_creating(dentry);
+ return tracefs_end_creating(dentry);
}

static struct dentry *__create_dir(const char *name, struct dentry *parent,
const struct inode_operations *ops)
{
- struct dentry *dentry = start_creating(name, parent);
+ struct dentry *dentry = tracefs_start_creating(name, parent);
struct inode *inode;

if (IS_ERR(dentry))
@@ -520,7 +520,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent,

inode = tracefs_get_inode(dentry->d_sb);
if (unlikely(!inode))
- return failed_creating(dentry);
+ return tracefs_failed_creating(dentry);

/* Do not set bits for OTH */
inode->i_mode = S_IFDIR | S_IRWXU | S_IRUSR| S_IRGRP | S_IXUSR | S_IXGRP;
@@ -534,7 +534,7 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent,
d_instantiate(dentry, inode);
inc_nlink(d_inode(dentry->d_parent));
fsnotify_mkdir(d_inode(dentry->d_parent), dentry);
- return end_creating(dentry);
+ return tracefs_end_creating(dentry);
}

/**
diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h
new file mode 100644
index 0000000..27869ea
--- /dev/null
+++ b/fs/tracefs/internal.h
@@ -0,0 +1,25 @@
+#ifndef _TRACEFS_INTERNAL_H
+#define _TRACEFS_INTERNAL_H
+
+enum {
+ TRACEFS_EVENT_INODE = BIT(1),
+};
+
+struct tracefs_inode {
+ unsigned long flags;
+ void *private;
+ struct inode vfs_inode;
+};
+
+static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
+{
+ return container_of(inode, struct tracefs_inode, vfs_inode);
+}
+
+struct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
+struct dentry *tracefs_end_creating(struct dentry *dentry);
+struct dentry *tracefs_failed_creating(struct dentry *dentry);
+struct inode *tracefs_get_inode(struct super_block *sb);
+
+#endif
+
--
2.7.4



2023-01-22 17:07:47

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 2/8] eventfs: adding eventfs dir add functions

Adding eventfs_file structure which will hold properties of file or dir.

Adding following functions to add dir in eventfs:

eventfs_create_events_dir() will directly create events dir with-in
tracing folder.

eventfs_add_subsystem_dir() will adds the info of subsystem_dir to
eventfs and dynamically create subsystem_dir as and when requires.

eventfs_add_dir() will add the info of dir (which is with-in
subsystem_dir) to eventfs and dynamically create these dir as
and when requires.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/Makefile | 1 +
fs/tracefs/event_inode.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/tracefs.h | 26 +++++++
3 files changed, 200 insertions(+)
create mode 100644 fs/tracefs/event_inode.c

diff --git a/fs/tracefs/Makefile b/fs/tracefs/Makefile
index 7c35a28..73c56da 100644
--- a/fs/tracefs/Makefile
+++ b/fs/tracefs/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
tracefs-objs := inode.o
+tracefs-objs += event_inode.o

obj-$(CONFIG_TRACING) += tracefs.o

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
new file mode 100644
index 0000000..ef3b435
--- /dev/null
+++ b/fs/tracefs/event_inode.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * event_inode.c - part of tracefs, a pseudo file system for activating tracing
+ *
+ * Copyright (C) 2020-22 VMware Inc, author: Steven Rostedt (VMware) <[email protected]>
+ * Copyright (C) 2020-22 VMware Inc, author: Ajay Kaher <[email protected]>
+ *
+ * eventfs is used to show trace events with one set of dentries
+ *
+ * eventfs stores meta-data of files/dirs and skip to create object of
+ * inodes/dentries. As and when requires, eventfs will create the
+ * inodes/dentries for only required files/directories. Also eventfs
+ * would delete the inodes/dentries once no more requires but preserve
+ * the meta data.
+ */
+#include <linux/fsnotify.h>
+#include <linux/fs.h>
+#include <linux/namei.h>
+#include <linux/security.h>
+#include <linux/tracefs.h>
+#include <linux/kref.h>
+#include "internal.h"
+
+static const struct file_operations eventfs_file_operations = {
+};
+
+const struct inode_operations eventfs_root_dir_inode_operations = {
+};
+
+/**
+ * eventfs_create_events_dir - create the trace event structure
+ * @name: a pointer to a string containing the name of the directory to
+ * create.
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is NULL, then the
+ * directory will be created in the root of the tracefs filesystem.
+ *
+ * This function creates the top of the trace event directory.
+ */
+struct dentry *eventfs_create_events_dir(const char *name, struct dentry *parent)
+{
+ struct dentry *dentry = tracefs_start_creating(name, parent);
+ struct eventfs_inode *ei;
+ struct tracefs_inode *ti;
+ struct inode *inode;
+
+ if (IS_ERR(dentry))
+ return dentry;
+
+ ei = kzalloc(sizeof(*ei), GFP_KERNEL);
+ if (!ei)
+ return ERR_PTR(-ENOMEM);
+ inode = tracefs_get_inode(dentry->d_sb);
+ if (unlikely(!inode)) {
+ kfree(ei);
+ tracefs_failed_creating(dentry);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ INIT_LIST_HEAD(&ei->e_top_files);
+
+ ti = get_tracefs(inode);
+ ti->flags |= TRACEFS_EVENT_INODE;
+ ti->private = ei;
+
+ inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
+ inode->i_op = &eventfs_root_dir_inode_operations;
+ inode->i_fop = &eventfs_file_operations;
+
+ /* directory inodes start off with i_nlink == 2 (for "." entry) */
+ inc_nlink(inode);
+ d_instantiate(dentry, inode);
+ inc_nlink(dentry->d_parent->d_inode);
+ fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
+ return tracefs_end_creating(dentry);
+}
+
+/**
+ * eventfs_add_subsystem_dir - add eventfs subsystem_dir to list to create later
+ * @name: a pointer to a string containing the name of the file to create.
+ * @parent: a pointer to the parent dentry for this dir.
+ *
+ * This function adds eventfs subsystem dir to list.
+ * And all these dirs are created on the fly when they are looked up,
+ * and the dentry and inodes will be removed when they are done.
+ */
+struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct dentry *parent)
+{
+ struct eventfs_file *ef;
+ struct tracefs_inode *ti_parent;
+ struct eventfs_inode *ei_parent;
+
+ if (!parent)
+ return ERR_PTR(-EINVAL);
+
+ ti_parent = get_tracefs(parent->d_inode);
+ ei_parent = ti_parent->private;
+
+ ef = kzalloc(sizeof(*ef), GFP_KERNEL);
+ if (!ef)
+ return ERR_PTR(-ENOMEM);
+
+ ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL);
+ if (!ef->ei) {
+ kfree(ef);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ INIT_LIST_HEAD(&ef->ei->e_top_files);
+
+ ef->name = kstrdup(name, GFP_KERNEL);
+ if (!ef->name) {
+ kfree(ef);
+ kfree(ef->ei);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
+ ef->iop = &eventfs_root_dir_inode_operations;
+ ef->fop = &eventfs_file_operations;
+ ef->dentry = NULL;
+ ef->created = false;
+ ef->d_parent = parent;
+
+ list_add_tail(&ef->list, &ei_parent->e_top_files);
+ return ef;
+}
+
+/**
+ * eventfs_add_dir - add eventfs dir to list to create later
+ * @name: a pointer to a string containing the name of the file to create.
+ * @eventfs_file: a pointer to the parent eventfs_file for this dir.
+ *
+ * This function adds eventfs dir to list.
+ * And all these dirs are created on the fly when they are looked up,
+ * and the dentry and inodes will be removed when they are done.
+ */
+struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_parent)
+{
+ struct eventfs_file *ef;
+
+ if (!ef_parent)
+ return ERR_PTR(-EINVAL);
+
+ ef = kzalloc(sizeof(*ef), GFP_KERNEL);
+ if (!ef)
+ return ERR_PTR(-ENOMEM);
+
+ ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL);
+ if (!ef->ei) {
+ kfree(ef);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ INIT_LIST_HEAD(&ef->ei->e_top_files);
+
+ ef->name = kstrdup(name, GFP_KERNEL);
+ if (!ef->name) {
+ kfree(ef->ei);
+ kfree(ef);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
+ ef->iop = &eventfs_root_dir_inode_operations;
+ ef->fop = &eventfs_file_operations;
+ ef->created = false;
+ ef->dentry = NULL;
+ ef->d_parent = NULL;
+
+ list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
+ return ef;
+}
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 9991244..6983409 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -21,6 +21,32 @@ struct file_operations;

#ifdef CONFIG_TRACING

+struct eventfs_inode {
+ struct list_head e_top_files;
+};
+
+struct eventfs_file {
+ const char *name;
+ struct dentry *d_parent;
+ struct dentry *dentry;
+ struct list_head list;
+ struct eventfs_inode *ei;
+ const struct file_operations *fop;
+ const struct inode_operations *iop;
+ void *data;
+ umode_t mode;
+ bool created;
+};
+
+struct dentry *eventfs_create_events_dir(const char *name,
+ struct dentry *parent);
+
+struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
+ struct dentry *parent);
+
+struct eventfs_file *eventfs_add_dir(const char *name,
+ struct eventfs_file *ef_parent);
+
struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
--
2.7.4


2023-01-22 17:07:49

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 3/8] eventfs: adding eventfs file add functions

Adding following function to eventfs to add files:

eventfs_add_top_file() will add the info of top file
to eventfs and dynamically create these files as and
when required.

eventfs_add_file() will add the info of nested files
to eventfs and dynamically create these dir as and
when required.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/event_inode.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/tracefs.h | 8 ++++
2 files changed, 116 insertions(+)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index ef3b435..e479712 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -171,3 +171,111 @@ struct eventfs_file *eventfs_add_dir(const char *name, struct eventfs_file *ef_p
list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
return ef;
}
+
+/**
+ * eventfs_add_top_file - add event top file to list to create later
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have.
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is NULL, then the
+ * file will be created in the root of the tracefs filesystem.
+ * @data: a pointer to something that the caller will want to get to later
+ * on. The inode.i_private pointer will point to this value on
+ * the open() call.
+ * @fop: a pointer to a struct file_operations that should be used for
+ * this file.
+ *
+ * This function adds top files of event dir to list.
+ * And all these files are created on the fly when they are looked up,
+ * and the dentry and inodes will be removed when they are done.
+ */
+int eventfs_add_top_file(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fop)
+{
+ struct tracefs_inode *ti;
+ struct eventfs_inode *ei;
+ struct eventfs_file *ef;
+
+ if (!parent)
+ return -EINVAL;
+
+ if (!(mode & S_IFMT))
+ mode |= S_IFREG;
+
+ if (!parent->d_inode)
+ return -EINVAL;
+
+ ti = get_tracefs(parent->d_inode);
+ if (!(ti->flags & TRACEFS_EVENT_INODE))
+ return -EINVAL;
+
+ ei = ti->private;
+ ef = kzalloc(sizeof(*ef), GFP_KERNEL);
+ if (!ef)
+ return -ENOMEM;
+
+ ef->name = kstrdup(name, GFP_KERNEL);
+ if (!ef->name) {
+ kfree(ef);
+ return -ENOMEM;
+ }
+
+ ef->mode = mode;
+ ef->data = data;
+ ef->fop = fop;
+ ef->dentry = NULL;
+ ef->ei = NULL;
+ ef->created = false;
+ ef->d_parent = parent;
+ list_add_tail(&ef->list, &ei->e_top_files);
+ return 0;
+}
+
+/**
+ * eventfs_add_file - add eventfs file to list to create later
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have.
+ * @ef_parent: a pointer to the parent eventfs_file for this file.
+ * @data: a pointer to something that the caller will want to get to later
+ * on. The inode.i_private pointer will point to this value on
+ * the open() call.
+ * @fop: a pointer to a struct file_operations that should be used for
+ * this file.
+ *
+ * This function adds top files of event dir to list.
+ * And all these files are created on the fly when they are looked up,
+ * and the dentry and inodes will be removed when they are done.
+ */
+int eventfs_add_file(const char *name, umode_t mode,
+ struct eventfs_file *ef_parent,
+ void *data,
+ const struct file_operations *fop)
+{
+ struct eventfs_file *ef;
+
+ if (!ef_parent)
+ return -EINVAL;
+
+ if (!(mode & S_IFMT))
+ mode |= S_IFREG;
+
+ ef = kzalloc(sizeof(*ef), GFP_KERNEL);
+ if (!ef)
+ return -ENOMEM;
+
+ ef->name = kstrdup(name, GFP_KERNEL);
+ if (!ef->name) {
+ kfree(ef);
+ return -ENOMEM;
+ }
+
+ ef->mode = mode;
+ ef->data = data;
+ ef->fop = fop;
+ ef->dentry = NULL;
+ ef->ei = NULL;
+ ef->created = false;
+ list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
+ return 0;
+}
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 6983409..7d390d2 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -47,6 +47,14 @@ struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
struct eventfs_file *eventfs_add_dir(const char *name,
struct eventfs_file *ef_parent);

+int eventfs_add_file(const char *name, umode_t mode,
+ struct eventfs_file *ef_parent, void *data,
+ const struct file_operations *fops);
+
+int eventfs_add_top_file(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops);
+
struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
--
2.7.4


2023-01-22 17:07:51

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories

Adding eventfs_create_file(), eventfs_create_dir()
to create file, dir at runtime as and when requires.

These function will be called either from lookup
of inode_operations or open of file_operations.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/event_inode.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++-
fs/tracefs/inode.c | 47 ++++++++++++++++
include/linux/tracefs.h | 6 +++
3 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 4d47da0..28866c0 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -21,6 +21,141 @@
#include <linux/kref.h>
#include "internal.h"

+/**
+ * eventfs_create_file - create a file in the tracefs filesystem
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have.
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is NULL, then the
+ * file will be created in the root of the tracefs filesystem.
+ * @data: a pointer to something that the caller will want to get to later
+ * on. The inode.i_private pointer will point to this value on
+ * the open() call.
+ * @fops: a pointer to a struct file_operations that should be used for
+ * this file.
+ *
+ * This is the basic "create a file" function for tracefs. It allows for a
+ * wide range of flexibility in creating a file.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the tracefs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If tracefs is not enabled in the kernel, the value -%ENODEV will be
+ * returned.
+ */
+struct dentry *eventfs_create_file(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fop,
+ bool anon)
+{
+ struct tracefs_inode *ti;
+ struct dentry *dentry;
+ struct inode *inode;
+
+ if (security_locked_down(LOCKDOWN_TRACEFS))
+ return NULL;
+
+ if (!(mode & S_IFMT))
+ mode |= S_IFREG;
+
+ if (WARN_ON_ONCE(!S_ISREG(mode)))
+ return NULL;
+
+ dentry = eventfs_start_creating(name, parent);
+
+ if (IS_ERR(dentry))
+ return dentry;
+
+ inode = tracefs_get_inode(dentry->d_sb);
+ if (unlikely(!inode))
+ return eventfs_failed_creating(dentry);
+
+ inode->i_mode = mode;
+ inode->i_fop = fop;
+ inode->i_private = data;
+
+ ti = get_tracefs(inode);
+ ti->flags |= TRACEFS_EVENT_INODE;
+
+ if (anon)
+ d_instantiate_anon(dentry, inode);
+ else
+ d_instantiate(dentry, inode);
+
+ fsnotify_create(dentry->d_parent->d_inode, dentry);
+ return eventfs_end_creating(dentry);
+}
+
+/**
+ * eventfs_create_dir - create a dir in the tracefs filesystem
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have.
+ * @parent: a pointer to the parent dentry for this file. This should be a
+ * directory dentry if set. If this parameter is NULL, then the
+ * file will be created in the root of the tracefs filesystem.
+ * @data: a pointer to something that the caller will want to get to later
+ * on. The inode.i_private pointer will point to this value on
+ * the open() call.
+ * @fop: a pointer to a struct file_operations that should be used for
+ * this dir.
+ * @iop: a pointer to a struct inode_operations that should be used for
+ * this dir.
+ *
+ * This is the basic "create a dir" function for eventfs. It allows for a
+ * wide range of flexibility in creating a dir.
+ *
+ * This function will return a pointer to a dentry if it succeeds. This
+ * pointer must be passed to the tracefs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.) If an error occurs, %NULL will be returned.
+ *
+ * If tracefs is not enabled in the kernel, the value -%ENODEV will be
+ * returned.
+ */
+struct dentry *eventfs_create_dir(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fop,
+ const struct inode_operations *iop,
+ bool anon)
+{
+ struct tracefs_inode *ti;
+ struct dentry *dentry;
+ struct inode *inode;
+
+ if (security_locked_down(LOCKDOWN_TRACEFS))
+ return NULL;
+
+ WARN_ON(!S_ISDIR(mode));
+
+ dentry = eventfs_start_creating(name, parent);
+
+ if (IS_ERR(dentry))
+ return dentry;
+
+ inode = tracefs_get_inode(dentry->d_sb);
+ if (unlikely(!inode))
+ return eventfs_failed_creating(dentry);
+
+ inode->i_mode = mode;
+ inode->i_op = iop;
+ inode->i_fop = fop;
+ inode->i_private = data;
+
+ ti = get_tracefs(inode);
+ ti->flags |= TRACEFS_EVENT_INODE;
+
+ inc_nlink(inode);
+ if (anon)
+ d_instantiate_anon(dentry, inode);
+ else
+ d_instantiate(dentry, inode);
+ inc_nlink(dentry->d_parent->d_inode);
+ fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
+ return eventfs_end_creating(dentry);
+}
+
static const struct file_operations eventfs_file_operations = {
};

@@ -86,9 +221,9 @@ struct dentry *eventfs_create_events_dir(const char *name, struct dentry *parent
*/
struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct dentry *parent)
{
- struct eventfs_file *ef;
struct tracefs_inode *ti_parent;
struct eventfs_inode *ei_parent;
+ struct eventfs_file *ef;

if (!parent)
return ERR_PTR(-EINVAL);
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 015b7b8..6d950d1 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -451,6 +451,53 @@ struct dentry *tracefs_end_creating(struct dentry *dentry)
return dentry;
}

+struct dentry *eventfs_start_creating(const char *name, struct dentry *parent)
+{
+ struct dentry *dentry;
+ int error;
+
+ error = simple_pin_fs(&trace_fs_type, &tracefs_mount,
+ &tracefs_mount_count);
+ if (error)
+ return ERR_PTR(error);
+
+ /*
+ * If the parent is not specified, we create it in the root.
+ * We need the root dentry to do this, which is in the super
+ * block. A pointer to that is in the struct vfsmount that we
+ * have around.
+ */
+ if (!parent)
+ parent = tracefs_mount->mnt_root;
+
+ if (unlikely(IS_DEADDIR(parent->d_inode)))
+ dentry = ERR_PTR(-ENOENT);
+ else
+ dentry = lookup_one_len(name, parent, strlen(name));
+
+ if (!IS_ERR(dentry) && dentry->d_inode) {
+ dput(dentry);
+ dentry = ERR_PTR(-EEXIST);
+ }
+
+ if (IS_ERR(dentry))
+ simple_release_fs(&tracefs_mount, &tracefs_mount_count);
+
+ return dentry;
+}
+
+struct dentry *eventfs_failed_creating(struct dentry *dentry)
+{
+ dput(dentry);
+ simple_release_fs(&tracefs_mount, &tracefs_mount_count);
+ return NULL;
+}
+
+struct dentry *eventfs_end_creating(struct dentry *dentry)
+{
+ return dentry;
+}
+
/**
* tracefs_create_file - create a file in the tracefs filesystem
* @name: a pointer to a string containing the name of the file to create.
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index b02cbba..52201f3 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -38,6 +38,12 @@ struct eventfs_file {
bool created;
};

+struct dentry *eventfs_start_creating(const char *name, struct dentry *parent);
+
+struct dentry *eventfs_failed_creating(struct dentry *dentry);
+
+struct dentry *eventfs_end_creating(struct dentry *dentry);
+
struct dentry *eventfs_create_events_dir(const char *name,
struct dentry *parent);

--
2.7.4


2023-01-22 17:07:55

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 4/8] eventfs: adding eventfs file, directory remove function

Adding eventfs_remove(), this function will recursively remove
dir or file info from eventfs.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/event_inode.c | 26 ++++++++++++++++++++++++++
include/linux/tracefs.h | 2 ++
2 files changed, 28 insertions(+)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index e479712..4d47da0 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -279,3 +279,29 @@ int eventfs_add_file(const char *name, umode_t mode,
list_add_tail(&ef->list, &ef_parent->ei->e_top_files);
return 0;
}
+
+/**
+ * eventfs_remove - remove eventfs dir or file from list
+ * @eventfs_file: a pointer to eventfs_file to be removed.
+ *
+ * This function recursively remove eventfs_file which
+ * contains info of file or dir.
+ */
+void eventfs_remove(struct eventfs_file *ef)
+{
+ struct eventfs_file *ef_child, *n;
+
+ if (!ef)
+ return;
+
+ if (ef->ei) {
+ /* search for nested folders or files */
+ list_for_each_entry_safe(ef_child, n, &ef->ei->e_top_files, list) {
+ eventfs_remove(ef_child);
+ }
+ kfree(ef->ei);
+ }
+ list_del(&ef->list);
+ kfree(ef->name);
+ kfree(ef);
+}
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 7d390d2..b02cbba 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -55,6 +55,8 @@ int eventfs_add_top_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);

+void eventfs_remove(struct eventfs_file *ef);
+
struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
--
2.7.4


2023-01-22 17:07:58

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions

Adding following functions to eventfs:
eventfs_set_ef_status_free()
eventfs_post_create_dir()
eventfs_root_lookup()
eventfs_release()
dcache_dir_open_wrapper()

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/event_inode.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/tracefs.h | 2 +
2 files changed, 181 insertions(+)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 28866c0..bcee34e 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -156,10 +156,189 @@ struct dentry *eventfs_create_dir(const char *name, umode_t mode,
return eventfs_end_creating(dentry);
}

+/**
+ * eventfs_set_ef_status_free - set the ef->status to free
+ * @dentry: dentry who's status to be freed
+ *
+ * eventfs_set_ef_status_free will be called if no more
+ * reference remains
+ */
+void eventfs_set_ef_status_free(struct dentry *dentry)
+{
+ struct tracefs_inode *ti_parent;
+ struct eventfs_inode *ei_parent;
+ struct eventfs_file *ef;
+
+ ti_parent = get_tracefs(dentry->d_parent->d_inode);
+ if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE))
+ return;
+ ei_parent = ti_parent->private;
+
+ list_for_each_entry(ef, &ei_parent->e_top_files, list) {
+ if (!strcmp(ef->name, dentry->d_name.name)) {
+ ef->created = false;
+ ef->dentry = NULL;
+ break;
+ }
+ }
+}
+
+/**
+ * eventfs_post_create_dir - post create dir routine
+ * @eventfs_file: eventfs_file of recently created dir
+ *
+ * Files with-in eventfs dir should know dentry of parent dir
+ */
+void eventfs_post_create_dir(struct eventfs_file *ef)
+{
+ struct eventfs_file *ef_child;
+ struct tracefs_inode *ti;
+
+ /* fill parent-child relation */
+ list_for_each_entry(ef_child, &ef->ei->e_top_files, list) {
+ ef_child->d_parent = ef->dentry;
+ }
+
+ ti = get_tracefs(ef->dentry->d_inode);
+ ti->private = ef->ei;
+}
+
+/**
+ * eventfs_root_lookup - lookup routine to create file/dir
+ * @dir: directory in which lookup to be done
+ * @dentry: file/dir dentry
+ * @flags:
+ *
+ * Used to create dynamic file/dir with-in @dir, search with-in ei
+ * list, if @dentry found go ahead and create the file/dir
+ */
+
+static struct dentry *eventfs_root_lookup(struct inode *dir,
+ struct dentry *dentry,
+ unsigned int flags)
+{
+ struct tracefs_inode *ti;
+ struct eventfs_inode *ei;
+ struct eventfs_file *ef;
+ struct dentry *ret = simple_lookup(dir, dentry, flags);
+
+ ti = get_tracefs(dir);
+ if (!(ti->flags & TRACEFS_EVENT_INODE))
+ return NULL;
+
+ ei = ti->private;
+ list_for_each_entry(ef, &ei->e_top_files, list) {
+ if (strcmp(ef->name, dentry->d_name.name))
+ continue;
+
+ if(ef->created)
+ continue;
+
+ ef->created = true;
+
+ if (ef->ei)
+ ef->dentry = eventfs_create_dir(ef->name, ef->mode, ef->d_parent,
+ ef->data, ef->fop, ef->iop, 0);
+ else
+ ef->dentry = eventfs_create_file(ef->name, ef->mode, ef->d_parent,
+ ef->data, ef->fop, 0);
+
+ if (IS_ERR_OR_NULL(ef->dentry)) {
+ ef->created = false;
+ } else {
+ if (ef->ei)
+ eventfs_post_create_dir(ef);
+ ef->dentry->d_fsdata = ef;
+ dput(ef->dentry);
+ }
+ break;
+ }
+ return ret;
+}
+
+/**
+ * eventfs_release - called to release eventfs file/dir
+ * @inode: inode to be released
+ * @file: file to be released (not used)
+ */
+static int eventfs_release(struct inode *inode, struct file *file)
+{
+ struct tracefs_inode *ti;
+ struct eventfs_inode *ei;
+ struct eventfs_file *ef;
+
+ ti = get_tracefs(inode);
+ if (!(ti->flags & TRACEFS_EVENT_INODE))
+ return -EINVAL;
+
+ ei = ti->private;
+ list_for_each_entry(ef, &ei->e_top_files, list) {
+ if (ef->created)
+ dput(ef->dentry);
+ }
+ return dcache_dir_close(inode, file);
+}
+
+/**
+ * dcache_dir_open_wrapper - eventfs open wrapper
+ * @inode: not used
+ * @file: dir to be opened (to create it's child)
+ *
+ * Used to dynamic create file/dir with-in @file, all the
+ * file/dir will be created. If already created then reference
+ * will be increased
+ */
+int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
+{
+ struct tracefs_inode *ti;
+ struct eventfs_inode *ei;
+ struct eventfs_file *ef;
+ struct inode *f_inode = file_inode(file);
+ struct dentry *dentry = file_dentry(file);
+
+ ti = get_tracefs(f_inode);
+ if (!(ti->flags & TRACEFS_EVENT_INODE))
+ return -EINVAL;
+
+ ei = ti->private;
+ list_for_each_entry(ef, &ei->e_top_files, list) {
+ if (ef->created) {
+ dget(ef->dentry);
+ continue;
+ }
+
+ ef->created = true;
+
+ inode_lock(dentry->d_inode);
+ if (ef->ei)
+ ef->dentry = eventfs_create_dir(ef->name, ef->mode, dentry,
+ ef->data, ef->fop, ef->iop, 1);
+ else
+ ef->dentry = eventfs_create_file(ef->name, ef->mode, dentry,
+ ef->data, ef->fop, 1);
+ inode_unlock(dentry->d_inode);
+
+ if (IS_ERR_OR_NULL(ef->dentry)) {
+ ef->created = false;
+ } else {
+ if (ef->ei)
+ eventfs_post_create_dir(ef);
+ ef->dentry->d_fsdata = ef;
+ }
+ }
+ return dcache_dir_open(inode, file);
+}
+
static const struct file_operations eventfs_file_operations = {
+ .open = dcache_dir_open_wrapper,
+ .read = generic_read_dir,
+ .iterate_shared = dcache_readdir,
+ .llseek = generic_file_llseek,
+ .release = eventfs_release,
};

const struct inode_operations eventfs_root_dir_inode_operations = {
+ .lookup = eventfs_root_lookup,
};

/**
diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h
index 52201f3..952d248 100644
--- a/include/linux/tracefs.h
+++ b/include/linux/tracefs.h
@@ -63,6 +63,8 @@ int eventfs_add_top_file(const char *name, umode_t mode,

void eventfs_remove(struct eventfs_file *ef);

+void eventfs_set_ef_status_free(struct dentry *dentry);
+
struct dentry *tracefs_create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
const struct file_operations *fops);
--
2.7.4


2023-01-22 17:08:02

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 7/8] eventfs: creating tracefs_inode_cache

Creating tracefs_inode_cache which is a cache of tracefs_inode.
Adding helping functions:
tracefs_alloc_inode()
tracefs_free_inode()

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/inode.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 6d950d1..8fdbd81 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -21,13 +21,33 @@
#include <linux/parser.h>
#include <linux/magic.h>
#include <linux/slab.h>
+#include "internal.h"

#define TRACEFS_DEFAULT_MODE 0700
+static struct kmem_cache *tracefs_inode_cachep __ro_after_init;

static struct vfsmount *tracefs_mount;
static int tracefs_mount_count;
static bool tracefs_registered;

+static struct inode *tracefs_alloc_inode(struct super_block *sb)
+{
+ struct tracefs_inode *ti;
+
+ ti = kmem_cache_alloc(tracefs_inode_cachep, GFP_KERNEL);
+ if (!ti)
+ return NULL;
+
+ ti->flags = 0;
+
+ return &ti->vfs_inode;
+}
+
+static void tracefs_free_inode(struct inode *inode)
+{
+ kmem_cache_free(tracefs_inode_cachep, get_tracefs(inode));
+}
+
static ssize_t default_read_file(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
@@ -346,6 +366,9 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root)
}

static const struct super_operations tracefs_super_operations = {
+ .alloc_inode = tracefs_alloc_inode,
+ .free_inode = tracefs_free_inode,
+ .drop_inode = generic_delete_inode,
.statfs = simple_statfs,
.remount_fs = tracefs_remount,
.show_options = tracefs_show_options,
@@ -675,10 +698,26 @@ bool tracefs_initialized(void)
return tracefs_registered;
}

+static void init_once(void *foo)
+{
+ struct tracefs_inode *ti = (struct tracefs_inode *) foo;
+
+ inode_init_once(&ti->vfs_inode);
+}
+
static int __init tracefs_init(void)
{
int retval;

+ tracefs_inode_cachep = kmem_cache_create("tracefs_inode_cache",
+ sizeof(struct tracefs_inode),
+ 0, (SLAB_RECLAIM_ACCOUNT|
+ SLAB_MEM_SPREAD|
+ SLAB_ACCOUNT),
+ init_once);
+ if (!tracefs_inode_cachep)
+ return -ENOMEM;
+
retval = sysfs_create_mount_point(kernel_kobj, "tracing");
if (retval)
return -EINVAL;
--
2.7.4


2023-01-22 17:08:13

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 8/8] eventfs: moving tracing/events to eventfs

Till now /sys/kernel/debug/tracing/events is a part of tracefs,
with-in this patch creating 'events' and it's sub-dir as eventfs.
Basically replacing tracefs calls with eventfs calls for 'events'.

Signed-off-by: Ajay Kaher <[email protected]>
Co-developed-by: Steven Rostedt (VMware) <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
Tested-by: Ching-lin Yu <[email protected]>
---
fs/tracefs/inode.c | 18 +++++++++++++
include/linux/trace_events.h | 1 +
kernel/trace/trace.h | 2 +-
kernel/trace/trace_events.c | 64 +++++++++++++++++++++++---------------------
4 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 8fdbd81..44b4344 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -374,6 +374,23 @@ static const struct super_operations tracefs_super_operations = {
.show_options = tracefs_show_options,
};

+static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode)
+{
+ struct tracefs_inode *ti;
+
+ if (!dentry || !inode)
+ return;
+
+ ti = get_tracefs(inode);
+ if (ti && ti->flags & TRACEFS_EVENT_INODE)
+ eventfs_set_ef_status_free(dentry);
+ iput(inode);
+}
+
+const struct dentry_operations tracefs_dentry_operations = {
+ .d_iput = tracefs_dentry_iput,
+};
+
static int trace_fill_super(struct super_block *sb, void *data, int silent)
{
static const struct tree_descr trace_files[] = {{""}};
@@ -396,6 +413,7 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent)
goto fail;

sb->s_op = &tracefs_super_operations;
+ sb->s_d_op = &tracefs_dentry_operations;

tracefs_apply_options(sb, false);

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 4342e99..0a810ab 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -634,6 +634,7 @@ struct trace_event_file {
struct list_head list;
struct trace_event_call *event_call;
struct event_filter __rcu *filter;
+ struct eventfs_file *ef;
struct dentry *dir;
struct trace_array *tr;
struct trace_subsystem_dir *system;
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index e46a492..97d2e35 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1302,7 +1302,7 @@ struct trace_subsystem_dir {
struct list_head list;
struct event_subsystem *subsystem;
struct trace_array *tr;
- struct dentry *entry;
+ struct eventfs_file *ef;
int ref_count;
int nr_events;
};
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 33e0b4f..b441f6a 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -973,7 +973,8 @@ static void remove_subsystem(struct trace_subsystem_dir *dir)
return;

if (!--dir->nr_events) {
- tracefs_remove(dir->entry);
+ if (dir->ef)
+ eventfs_remove(dir->ef);
list_del(&dir->list);
__put_system_dir(dir);
}
@@ -994,7 +995,8 @@ static void remove_event_file_dir(struct trace_event_file *file)

tracefs_remove(dir);
}
-
+ if (file->ef)
+ eventfs_remove(file->ef);
list_del(&file->list);
remove_subsystem(file->system);
free_event_filter(file->filter);
@@ -2277,13 +2279,13 @@ create_new_subsystem(const char *name)
return NULL;
}

-static struct dentry *
+static struct eventfs_file *
event_subsystem_dir(struct trace_array *tr, const char *name,
struct trace_event_file *file, struct dentry *parent)
{
struct event_subsystem *system, *iter;
struct trace_subsystem_dir *dir;
- struct dentry *entry;
+ int res;

/* First see if we did not already create this dir */
list_for_each_entry(dir, &tr->systems, list) {
@@ -2291,7 +2293,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name,
if (strcmp(system->name, name) == 0) {
dir->nr_events++;
file->system = dir;
- return dir->entry;
+ return dir->ef;
}
}

@@ -2315,8 +2317,8 @@ event_subsystem_dir(struct trace_array *tr, const char *name,
} else
__get_system(system);

- dir->entry = tracefs_create_dir(name, parent);
- if (!dir->entry) {
+ dir->ef = eventfs_add_subsystem_dir(name, parent);
+ if (IS_ERR(dir->ef)) {
pr_warn("Failed to create system directory %s\n", name);
__put_system(system);
goto out_free;
@@ -2331,22 +2333,22 @@ event_subsystem_dir(struct trace_array *tr, const char *name,
/* the ftrace system is special, do not create enable or filter files */
if (strcmp(name, "ftrace") != 0) {

- entry = tracefs_create_file("filter", TRACE_MODE_WRITE,
- dir->entry, dir,
+ res = eventfs_add_file("filter", TRACE_MODE_WRITE,
+ dir->ef, dir,
&ftrace_subsystem_filter_fops);
- if (!entry) {
+ if (res) {
kfree(system->filter);
system->filter = NULL;
pr_warn("Could not create tracefs '%s/filter' entry\n", name);
}

- trace_create_file("enable", TRACE_MODE_WRITE, dir->entry, dir,
+ eventfs_add_file("enable", TRACE_MODE_WRITE, dir->ef, dir,
&ftrace_system_enable_fops);
}

list_add(&dir->list, &tr->systems);

- return dir->entry;
+ return dir->ef;

out_free:
kfree(dir);
@@ -2399,6 +2401,7 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
{
struct trace_event_call *call = file->event_call;
struct trace_array *tr = file->tr;
+ struct eventfs_file *ef_subsystem = NULL;
struct dentry *d_events;
const char *name;
int ret;
@@ -2408,26 +2411,26 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
* then the system would be called "TRACE_SYSTEM".
*/
if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
- d_events = event_subsystem_dir(tr, call->class->system, file, parent);
- if (!d_events)
+ ef_subsystem = event_subsystem_dir(tr, call->class->system, file, parent);
+ if (!ef_subsystem)
return -ENOMEM;
} else
d_events = parent;

name = trace_event_name(call);
- file->dir = tracefs_create_dir(name, d_events);
- if (!file->dir) {
+ file->ef = eventfs_add_dir(name, ef_subsystem);
+ if (IS_ERR(file->ef)) {
pr_warn("Could not create tracefs '%s' directory\n", name);
return -1;
}

if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
- trace_create_file("enable", TRACE_MODE_WRITE, file->dir, file,
+ eventfs_add_file("enable", TRACE_MODE_WRITE, file->ef, file,
&ftrace_enable_fops);

#ifdef CONFIG_PERF_EVENTS
if (call->event.type && call->class->reg)
- trace_create_file("id", TRACE_MODE_READ, file->dir,
+ eventfs_add_file("id", TRACE_MODE_READ, file->ef,
(void *)(long)call->event.type,
&ftrace_event_id_fops);
#endif
@@ -2443,27 +2446,27 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
* triggers or filters.
*/
if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) {
- trace_create_file("filter", TRACE_MODE_WRITE, file->dir,
+ eventfs_add_file("filter", TRACE_MODE_WRITE, file->ef,
file, &ftrace_event_filter_fops);

- trace_create_file("trigger", TRACE_MODE_WRITE, file->dir,
+ eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef,
file, &event_trigger_fops);
}

#ifdef CONFIG_HIST_TRIGGERS
- trace_create_file("hist", TRACE_MODE_READ, file->dir, file,
+ eventfs_add_file("hist", TRACE_MODE_READ, file->ef, file,
&event_hist_fops);
#endif
#ifdef CONFIG_HIST_TRIGGERS_DEBUG
- trace_create_file("hist_debug", TRACE_MODE_READ, file->dir, file,
+ eventfs_add_file("hist_debug", TRACE_MODE_READ, file->ef, file,
&event_hist_debug_fops);
#endif
- trace_create_file("format", TRACE_MODE_READ, file->dir, call,
+ eventfs_add_file("format", TRACE_MODE_READ, file->ef, call,
&ftrace_event_format_fops);

#ifdef CONFIG_TRACE_EVENT_INJECT
if (call->event.type && call->class->reg)
- trace_create_file("inject", 0200, file->dir, file,
+ eventfs_add_file("inject", 0200, file->ef, file,
&event_inject_fops);
#endif

@@ -3616,21 +3619,22 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
{
struct dentry *d_events;
struct dentry *entry;
+ int error = 0;

entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent,
tr, &ftrace_set_event_fops);
if (!entry)
return -ENOMEM;

- d_events = tracefs_create_dir("events", parent);
- if (!d_events) {
+ d_events = eventfs_create_events_dir("events", parent);
+ if (IS_ERR(d_events)) {
pr_warn("Could not create tracefs 'events' directory\n");
return -ENOMEM;
}

- entry = trace_create_file("enable", TRACE_MODE_WRITE, d_events,
+ error = eventfs_add_top_file("enable", TRACE_MODE_WRITE, d_events,
tr, &ftrace_tr_enable_fops);
- if (!entry)
+ if (error)
return -ENOMEM;

/* There are not as crucial, just warn if they are not created */
@@ -3643,11 +3647,11 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
&ftrace_set_event_notrace_pid_fops);

/* ring buffer internal formats */
- trace_create_file("header_page", TRACE_MODE_READ, d_events,
+ eventfs_add_top_file("header_page", TRACE_MODE_READ, d_events,
ring_buffer_print_page_header,
&ftrace_show_header_fops);

- trace_create_file("header_event", TRACE_MODE_READ, d_events,
+ eventfs_add_top_file("header_event", TRACE_MODE_READ, d_events,
ring_buffer_print_entry_header,
&ftrace_show_header_fops);

--
2.7.4


2023-01-22 17:08:15

by Ajay Kaher

[permalink] [raw]
Subject: [PATCH 0/8] tracing: introducing eventfs

Events Tracing infrastructure contains lot of files, directories
(internally in terms of inodes, dentries). And ends up by consuming
memory in MBs. We can have multiple events of Events Tracing, which
further requires more memory.

Instead of creating inodes/dentries, eventfs could keep meta-data and
skip the creation of inodes/dentries. As and when require, eventfs will
create the inodes/dentries only for required files/directories.
Also eventfs would delete the inodes/dentries once no more requires
but preserve the meta data.

Tracing events took ~9MB, with this approach it took ~4.5MB
for ~10K files/dir.

[PATCH 1/8]: Introducing struct tracefs_inode
[PATCH 2/8]: Adding eventfs-dir-add functions
[PATCH 3/8]: Adding eventfs-file-add function
[PATCH 4/8]: Adding eventfs-file-directory-remove function
[PATCH 5/8]: Adding functions to create-eventfs-files
[PATCH 6/8]: Adding eventfs lookup, read, open functions
[PATCH 7/8]: Creating tracefs_inode_cache
[PATCH 8/8]: Moving tracing events to eventfs


2023-01-22 18:45:45

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230120]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories
config: arc-defconfig (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/950ac8561471b622eac5555b4a7502bcd8c20663
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout 950ac8561471b622eac5555b4a7502bcd8c20663
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash fs/tracefs/ kernel/trace/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> fs/tracefs/event_inode.c:48:16: warning: no previous prototype for 'eventfs_create_file' [-Wmissing-prototypes]
48 | struct dentry *eventfs_create_file(const char *name, umode_t mode,
| ^~~~~~~~~~~~~~~~~~~
>> fs/tracefs/event_inode.c:117:16: warning: no previous prototype for 'eventfs_create_dir' [-Wmissing-prototypes]
117 | struct dentry *eventfs_create_dir(const char *name, umode_t mode,
| ^~~~~~~~~~~~~~~~~~


vim +/eventfs_create_file +48 fs/tracefs/event_inode.c

23
24 /**
25 * eventfs_create_file - create a file in the tracefs filesystem
26 * @name: a pointer to a string containing the name of the file to create.
27 * @mode: the permission that the file should have.
28 * @parent: a pointer to the parent dentry for this file. This should be a
29 * directory dentry if set. If this parameter is NULL, then the
30 * file will be created in the root of the tracefs filesystem.
31 * @data: a pointer to something that the caller will want to get to later
32 * on. The inode.i_private pointer will point to this value on
33 * the open() call.
34 * @fops: a pointer to a struct file_operations that should be used for
35 * this file.
36 *
37 * This is the basic "create a file" function for tracefs. It allows for a
38 * wide range of flexibility in creating a file.
39 *
40 * This function will return a pointer to a dentry if it succeeds. This
41 * pointer must be passed to the tracefs_remove() function when the file is
42 * to be removed (no automatic cleanup happens if your module is unloaded,
43 * you are responsible here.) If an error occurs, %NULL will be returned.
44 *
45 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
46 * returned.
47 */
> 48 struct dentry *eventfs_create_file(const char *name, umode_t mode,
49 struct dentry *parent, void *data,
50 const struct file_operations *fop,
51 bool anon)
52 {
53 struct tracefs_inode *ti;
54 struct dentry *dentry;
55 struct inode *inode;
56
57 if (security_locked_down(LOCKDOWN_TRACEFS))
58 return NULL;
59
60 if (!(mode & S_IFMT))
61 mode |= S_IFREG;
62
63 if (WARN_ON_ONCE(!S_ISREG(mode)))
64 return NULL;
65
66 dentry = eventfs_start_creating(name, parent);
67
68 if (IS_ERR(dentry))
69 return dentry;
70
71 inode = tracefs_get_inode(dentry->d_sb);
72 if (unlikely(!inode))
73 return eventfs_failed_creating(dentry);
74
75 inode->i_mode = mode;
76 inode->i_fop = fop;
77 inode->i_private = data;
78
79 ti = get_tracefs(inode);
80 ti->flags |= TRACEFS_EVENT_INODE;
81
82 if (anon)
83 d_instantiate_anon(dentry, inode);
84 else
85 d_instantiate(dentry, inode);
86
87 fsnotify_create(dentry->d_parent->d_inode, dentry);
88 return eventfs_end_creating(dentry);
89 }
90
91 /**
92 * eventfs_create_dir - create a dir in the tracefs filesystem
93 * @name: a pointer to a string containing the name of the file to create.
94 * @mode: the permission that the file should have.
95 * @parent: a pointer to the parent dentry for this file. This should be a
96 * directory dentry if set. If this parameter is NULL, then the
97 * file will be created in the root of the tracefs filesystem.
98 * @data: a pointer to something that the caller will want to get to later
99 * on. The inode.i_private pointer will point to this value on
100 * the open() call.
101 * @fop: a pointer to a struct file_operations that should be used for
102 * this dir.
103 * @iop: a pointer to a struct inode_operations that should be used for
104 * this dir.
105 *
106 * This is the basic "create a dir" function for eventfs. It allows for a
107 * wide range of flexibility in creating a dir.
108 *
109 * This function will return a pointer to a dentry if it succeeds. This
110 * pointer must be passed to the tracefs_remove() function when the file is
111 * to be removed (no automatic cleanup happens if your module is unloaded,
112 * you are responsible here.) If an error occurs, %NULL will be returned.
113 *
114 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
115 * returned.
116 */
> 117 struct dentry *eventfs_create_dir(const char *name, umode_t mode,
118 struct dentry *parent, void *data,
119 const struct file_operations *fop,
120 const struct inode_operations *iop,
121 bool anon)
122 {
123 struct tracefs_inode *ti;
124 struct dentry *dentry;
125 struct inode *inode;
126
127 if (security_locked_down(LOCKDOWN_TRACEFS))
128 return NULL;
129
130 WARN_ON(!S_ISDIR(mode));
131
132 dentry = eventfs_start_creating(name, parent);
133
134 if (IS_ERR(dentry))
135 return dentry;
136
137 inode = tracefs_get_inode(dentry->d_sb);
138 if (unlikely(!inode))
139 return eventfs_failed_creating(dentry);
140
141 inode->i_mode = mode;
142 inode->i_op = iop;
143 inode->i_fop = fop;
144 inode->i_private = data;
145
146 ti = get_tracefs(inode);
147 ti->flags |= TRACEFS_EVENT_INODE;
148
149 inc_nlink(inode);
150 if (anon)
151 d_instantiate_anon(dentry, inode);
152 else
153 d_instantiate(dentry, inode);
154 inc_nlink(dentry->d_parent->d_inode);
155 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
156 return eventfs_end_creating(dentry);
157 }
158

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

2023-01-22 19:38:47

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230120]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-6-git-send-email-akaher%40vmware.com
patch subject: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions
config: arc-defconfig (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/bdfb24dc39f183eda75dc7c6ad54798181ad4a94
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout bdfb24dc39f183eda75dc7c6ad54798181ad4a94
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash fs/tracefs/ kernel/trace/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

fs/tracefs/event_inode.c:48:16: warning: no previous prototype for 'eventfs_create_file' [-Wmissing-prototypes]
48 | struct dentry *eventfs_create_file(const char *name, umode_t mode,
| ^~~~~~~~~~~~~~~~~~~
fs/tracefs/event_inode.c:117:16: warning: no previous prototype for 'eventfs_create_dir' [-Wmissing-prototypes]
117 | struct dentry *eventfs_create_dir(const char *name, umode_t mode,
| ^~~~~~~~~~~~~~~~~~
>> fs/tracefs/event_inode.c:192:6: warning: no previous prototype for 'eventfs_post_create_dir' [-Wmissing-prototypes]
192 | void eventfs_post_create_dir(struct eventfs_file *ef)
| ^~~~~~~~~~~~~~~~~~~~~~~
>> fs/tracefs/event_inode.c:291:5: warning: no previous prototype for 'dcache_dir_open_wrapper' [-Wmissing-prototypes]
291 | int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
| ^~~~~~~~~~~~~~~~~~~~~~~


vim +/eventfs_post_create_dir +192 fs/tracefs/event_inode.c

23
24 /**
25 * eventfs_create_file - create a file in the tracefs filesystem
26 * @name: a pointer to a string containing the name of the file to create.
27 * @mode: the permission that the file should have.
28 * @parent: a pointer to the parent dentry for this file. This should be a
29 * directory dentry if set. If this parameter is NULL, then the
30 * file will be created in the root of the tracefs filesystem.
31 * @data: a pointer to something that the caller will want to get to later
32 * on. The inode.i_private pointer will point to this value on
33 * the open() call.
34 * @fops: a pointer to a struct file_operations that should be used for
35 * this file.
36 *
37 * This is the basic "create a file" function for tracefs. It allows for a
38 * wide range of flexibility in creating a file.
39 *
40 * This function will return a pointer to a dentry if it succeeds. This
41 * pointer must be passed to the tracefs_remove() function when the file is
42 * to be removed (no automatic cleanup happens if your module is unloaded,
43 * you are responsible here.) If an error occurs, %NULL will be returned.
44 *
45 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
46 * returned.
47 */
> 48 struct dentry *eventfs_create_file(const char *name, umode_t mode,
49 struct dentry *parent, void *data,
50 const struct file_operations *fop,
51 bool anon)
52 {
53 struct tracefs_inode *ti;
54 struct dentry *dentry;
55 struct inode *inode;
56
57 if (security_locked_down(LOCKDOWN_TRACEFS))
58 return NULL;
59
60 if (!(mode & S_IFMT))
61 mode |= S_IFREG;
62
63 if (WARN_ON_ONCE(!S_ISREG(mode)))
64 return NULL;
65
66 dentry = eventfs_start_creating(name, parent);
67
68 if (IS_ERR(dentry))
69 return dentry;
70
71 inode = tracefs_get_inode(dentry->d_sb);
72 if (unlikely(!inode))
73 return eventfs_failed_creating(dentry);
74
75 inode->i_mode = mode;
76 inode->i_fop = fop;
77 inode->i_private = data;
78
79 ti = get_tracefs(inode);
80 ti->flags |= TRACEFS_EVENT_INODE;
81
82 if (anon)
83 d_instantiate_anon(dentry, inode);
84 else
85 d_instantiate(dentry, inode);
86
87 fsnotify_create(dentry->d_parent->d_inode, dentry);
88 return eventfs_end_creating(dentry);
89 }
90
91 /**
92 * eventfs_create_dir - create a dir in the tracefs filesystem
93 * @name: a pointer to a string containing the name of the file to create.
94 * @mode: the permission that the file should have.
95 * @parent: a pointer to the parent dentry for this file. This should be a
96 * directory dentry if set. If this parameter is NULL, then the
97 * file will be created in the root of the tracefs filesystem.
98 * @data: a pointer to something that the caller will want to get to later
99 * on. The inode.i_private pointer will point to this value on
100 * the open() call.
101 * @fop: a pointer to a struct file_operations that should be used for
102 * this dir.
103 * @iop: a pointer to a struct inode_operations that should be used for
104 * this dir.
105 *
106 * This is the basic "create a dir" function for eventfs. It allows for a
107 * wide range of flexibility in creating a dir.
108 *
109 * This function will return a pointer to a dentry if it succeeds. This
110 * pointer must be passed to the tracefs_remove() function when the file is
111 * to be removed (no automatic cleanup happens if your module is unloaded,
112 * you are responsible here.) If an error occurs, %NULL will be returned.
113 *
114 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
115 * returned.
116 */
117 struct dentry *eventfs_create_dir(const char *name, umode_t mode,
118 struct dentry *parent, void *data,
119 const struct file_operations *fop,
120 const struct inode_operations *iop,
121 bool anon)
122 {
123 struct tracefs_inode *ti;
124 struct dentry *dentry;
125 struct inode *inode;
126
127 if (security_locked_down(LOCKDOWN_TRACEFS))
128 return NULL;
129
130 WARN_ON(!S_ISDIR(mode));
131
132 dentry = eventfs_start_creating(name, parent);
133
134 if (IS_ERR(dentry))
135 return dentry;
136
137 inode = tracefs_get_inode(dentry->d_sb);
138 if (unlikely(!inode))
139 return eventfs_failed_creating(dentry);
140
141 inode->i_mode = mode;
142 inode->i_op = iop;
143 inode->i_fop = fop;
144 inode->i_private = data;
145
146 ti = get_tracefs(inode);
147 ti->flags |= TRACEFS_EVENT_INODE;
148
149 inc_nlink(inode);
150 if (anon)
151 d_instantiate_anon(dentry, inode);
152 else
153 d_instantiate(dentry, inode);
154 inc_nlink(dentry->d_parent->d_inode);
155 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
156 return eventfs_end_creating(dentry);
157 }
158
159 /**
160 * eventfs_set_ef_status_free - set the ef->status to free
161 * @dentry: dentry who's status to be freed
162 *
163 * eventfs_set_ef_status_free will be called if no more
164 * reference remains
165 */
166 void eventfs_set_ef_status_free(struct dentry *dentry)
167 {
168 struct tracefs_inode *ti_parent;
169 struct eventfs_inode *ei_parent;
170 struct eventfs_file *ef;
171
172 ti_parent = get_tracefs(dentry->d_parent->d_inode);
173 if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE))
174 return;
175 ei_parent = ti_parent->private;
176
177 list_for_each_entry(ef, &ei_parent->e_top_files, list) {
178 if (!strcmp(ef->name, dentry->d_name.name)) {
179 ef->created = false;
180 ef->dentry = NULL;
181 break;
182 }
183 }
184 }
185
186 /**
187 * eventfs_post_create_dir - post create dir routine
188 * @eventfs_file: eventfs_file of recently created dir
189 *
190 * Files with-in eventfs dir should know dentry of parent dir
191 */
> 192 void eventfs_post_create_dir(struct eventfs_file *ef)
193 {
194 struct eventfs_file *ef_child;
195 struct tracefs_inode *ti;
196
197 /* fill parent-child relation */
198 list_for_each_entry(ef_child, &ef->ei->e_top_files, list) {
199 ef_child->d_parent = ef->dentry;
200 }
201
202 ti = get_tracefs(ef->dentry->d_inode);
203 ti->private = ef->ei;
204 }
205
206 /**
207 * eventfs_root_lookup - lookup routine to create file/dir
208 * @dir: directory in which lookup to be done
209 * @dentry: file/dir dentry
210 * @flags:
211 *
212 * Used to create dynamic file/dir with-in @dir, search with-in ei
213 * list, if @dentry found go ahead and create the file/dir
214 */
215
216 static struct dentry *eventfs_root_lookup(struct inode *dir,
217 struct dentry *dentry,
218 unsigned int flags)
219 {
220 struct tracefs_inode *ti;
221 struct eventfs_inode *ei;
222 struct eventfs_file *ef;
223 struct dentry *ret = simple_lookup(dir, dentry, flags);
224
225 ti = get_tracefs(dir);
226 if (!(ti->flags & TRACEFS_EVENT_INODE))
227 return NULL;
228
229 ei = ti->private;
230 list_for_each_entry(ef, &ei->e_top_files, list) {
231 if (strcmp(ef->name, dentry->d_name.name))
232 continue;
233
234 if(ef->created)
235 continue;
236
237 ef->created = true;
238
239 if (ef->ei)
240 ef->dentry = eventfs_create_dir(ef->name, ef->mode, ef->d_parent,
241 ef->data, ef->fop, ef->iop, 0);
242 else
243 ef->dentry = eventfs_create_file(ef->name, ef->mode, ef->d_parent,
244 ef->data, ef->fop, 0);
245
246 if (IS_ERR_OR_NULL(ef->dentry)) {
247 ef->created = false;
248 } else {
249 if (ef->ei)
250 eventfs_post_create_dir(ef);
251 ef->dentry->d_fsdata = ef;
252 dput(ef->dentry);
253 }
254 break;
255 }
256 return ret;
257 }
258
259 /**
260 * eventfs_release - called to release eventfs file/dir
261 * @inode: inode to be released
262 * @file: file to be released (not used)
263 */
264 static int eventfs_release(struct inode *inode, struct file *file)
265 {
266 struct tracefs_inode *ti;
267 struct eventfs_inode *ei;
268 struct eventfs_file *ef;
269
270 ti = get_tracefs(inode);
271 if (!(ti->flags & TRACEFS_EVENT_INODE))
272 return -EINVAL;
273
274 ei = ti->private;
275 list_for_each_entry(ef, &ei->e_top_files, list) {
276 if (ef->created)
277 dput(ef->dentry);
278 }
279 return dcache_dir_close(inode, file);
280 }
281
282 /**
283 * dcache_dir_open_wrapper - eventfs open wrapper
284 * @inode: not used
285 * @file: dir to be opened (to create it's child)
286 *
287 * Used to dynamic create file/dir with-in @file, all the
288 * file/dir will be created. If already created then reference
289 * will be increased
290 */
> 291 int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
292 {
293 struct tracefs_inode *ti;
294 struct eventfs_inode *ei;
295 struct eventfs_file *ef;
296 struct inode *f_inode = file_inode(file);
297 struct dentry *dentry = file_dentry(file);
298
299 ti = get_tracefs(f_inode);
300 if (!(ti->flags & TRACEFS_EVENT_INODE))
301 return -EINVAL;
302
303 ei = ti->private;
304 list_for_each_entry(ef, &ei->e_top_files, list) {
305 if (ef->created) {
306 dget(ef->dentry);
307 continue;
308 }
309
310 ef->created = true;
311
312 inode_lock(dentry->d_inode);
313 if (ef->ei)
314 ef->dentry = eventfs_create_dir(ef->name, ef->mode, dentry,
315 ef->data, ef->fop, ef->iop, 1);
316 else
317 ef->dentry = eventfs_create_file(ef->name, ef->mode, dentry,
318 ef->data, ef->fop, 1);
319 inode_unlock(dentry->d_inode);
320
321 if (IS_ERR_OR_NULL(ef->dentry)) {
322 ef->created = false;
323 } else {
324 if (ef->ei)
325 eventfs_post_create_dir(ef);
326 ef->dentry->d_fsdata = ef;
327 }
328 }
329 return dcache_dir_open(inode, file);
330 }
331

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

2023-01-22 20:09:46

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories
config: riscv-buildonly-randconfig-r003-20230123 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 4196ca3278f78c6e19246e54ab0ecb364e37d66a)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/950ac8561471b622eac5555b4a7502bcd8c20663
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout 950ac8561471b622eac5555b4a7502bcd8c20663
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> fs/tracefs/event_inode.c:48:16: warning: no previous prototype for function 'eventfs_create_file' [-Wmissing-prototypes]
struct dentry *eventfs_create_file(const char *name, umode_t mode,
^
fs/tracefs/event_inode.c:48:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct dentry *eventfs_create_file(const char *name, umode_t mode,
^
static
>> fs/tracefs/event_inode.c:117:16: warning: no previous prototype for function 'eventfs_create_dir' [-Wmissing-prototypes]
struct dentry *eventfs_create_dir(const char *name, umode_t mode,
^
fs/tracefs/event_inode.c:117:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct dentry *eventfs_create_dir(const char *name, umode_t mode,
^
static
2 warnings generated.

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for IOMMU_IO_PGTABLE_LPAE
Depends on [n]: IOMMU_SUPPORT [=y] && (ARM || ARM64 || COMPILE_TEST [=y] && !GENERIC_ATOMIC64 [=y])
Selected by [y]:
- IPMMU_VMSA [=y] && IOMMU_SUPPORT [=y] && (ARCH_RENESAS [=y] || COMPILE_TEST [=y] && !GENERIC_ATOMIC64 [=y])


vim +/eventfs_create_file +48 fs/tracefs/event_inode.c

23
24 /**
25 * eventfs_create_file - create a file in the tracefs filesystem
26 * @name: a pointer to a string containing the name of the file to create.
27 * @mode: the permission that the file should have.
28 * @parent: a pointer to the parent dentry for this file. This should be a
29 * directory dentry if set. If this parameter is NULL, then the
30 * file will be created in the root of the tracefs filesystem.
31 * @data: a pointer to something that the caller will want to get to later
32 * on. The inode.i_private pointer will point to this value on
33 * the open() call.
34 * @fops: a pointer to a struct file_operations that should be used for
35 * this file.
36 *
37 * This is the basic "create a file" function for tracefs. It allows for a
38 * wide range of flexibility in creating a file.
39 *
40 * This function will return a pointer to a dentry if it succeeds. This
41 * pointer must be passed to the tracefs_remove() function when the file is
42 * to be removed (no automatic cleanup happens if your module is unloaded,
43 * you are responsible here.) If an error occurs, %NULL will be returned.
44 *
45 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
46 * returned.
47 */
> 48 struct dentry *eventfs_create_file(const char *name, umode_t mode,
49 struct dentry *parent, void *data,
50 const struct file_operations *fop,
51 bool anon)
52 {
53 struct tracefs_inode *ti;
54 struct dentry *dentry;
55 struct inode *inode;
56
57 if (security_locked_down(LOCKDOWN_TRACEFS))
58 return NULL;
59
60 if (!(mode & S_IFMT))
61 mode |= S_IFREG;
62
63 if (WARN_ON_ONCE(!S_ISREG(mode)))
64 return NULL;
65
66 dentry = eventfs_start_creating(name, parent);
67
68 if (IS_ERR(dentry))
69 return dentry;
70
71 inode = tracefs_get_inode(dentry->d_sb);
72 if (unlikely(!inode))
73 return eventfs_failed_creating(dentry);
74
75 inode->i_mode = mode;
76 inode->i_fop = fop;
77 inode->i_private = data;
78
79 ti = get_tracefs(inode);
80 ti->flags |= TRACEFS_EVENT_INODE;
81
82 if (anon)
83 d_instantiate_anon(dentry, inode);
84 else
85 d_instantiate(dentry, inode);
86
87 fsnotify_create(dentry->d_parent->d_inode, dentry);
88 return eventfs_end_creating(dentry);
89 }
90
91 /**
92 * eventfs_create_dir - create a dir in the tracefs filesystem
93 * @name: a pointer to a string containing the name of the file to create.
94 * @mode: the permission that the file should have.
95 * @parent: a pointer to the parent dentry for this file. This should be a
96 * directory dentry if set. If this parameter is NULL, then the
97 * file will be created in the root of the tracefs filesystem.
98 * @data: a pointer to something that the caller will want to get to later
99 * on. The inode.i_private pointer will point to this value on
100 * the open() call.
101 * @fop: a pointer to a struct file_operations that should be used for
102 * this dir.
103 * @iop: a pointer to a struct inode_operations that should be used for
104 * this dir.
105 *
106 * This is the basic "create a dir" function for eventfs. It allows for a
107 * wide range of flexibility in creating a dir.
108 *
109 * This function will return a pointer to a dentry if it succeeds. This
110 * pointer must be passed to the tracefs_remove() function when the file is
111 * to be removed (no automatic cleanup happens if your module is unloaded,
112 * you are responsible here.) If an error occurs, %NULL will be returned.
113 *
114 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
115 * returned.
116 */
> 117 struct dentry *eventfs_create_dir(const char *name, umode_t mode,
118 struct dentry *parent, void *data,
119 const struct file_operations *fop,
120 const struct inode_operations *iop,
121 bool anon)
122 {
123 struct tracefs_inode *ti;
124 struct dentry *dentry;
125 struct inode *inode;
126
127 if (security_locked_down(LOCKDOWN_TRACEFS))
128 return NULL;
129
130 WARN_ON(!S_ISDIR(mode));
131
132 dentry = eventfs_start_creating(name, parent);
133
134 if (IS_ERR(dentry))
135 return dentry;
136
137 inode = tracefs_get_inode(dentry->d_sb);
138 if (unlikely(!inode))
139 return eventfs_failed_creating(dentry);
140
141 inode->i_mode = mode;
142 inode->i_op = iop;
143 inode->i_fop = fop;
144 inode->i_private = data;
145
146 ti = get_tracefs(inode);
147 ti->flags |= TRACEFS_EVENT_INODE;
148
149 inc_nlink(inode);
150 if (anon)
151 d_instantiate_anon(dentry, inode);
152 else
153 d_instantiate(dentry, inode);
154 inc_nlink(dentry->d_parent->d_inode);
155 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
156 return eventfs_end_creating(dentry);
157 }
158

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

2023-01-22 21:00:49

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 8/8] eventfs: moving tracing/events to eventfs

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230120]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-8-git-send-email-akaher%40vmware.com
patch subject: [PATCH 8/8] eventfs: moving tracing/events to eventfs
config: arc-defconfig (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: arc-elf-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/be995c36ba2232edcd4fa64e4581b9a6763c75e6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout be995c36ba2232edcd4fa64e4581b9a6763c75e6
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash kernel/trace/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

kernel/trace/trace_events.c: In function 'event_create_dir':
>> kernel/trace/trace_events.c:2405:24: warning: variable 'd_events' set but not used [-Wunused-but-set-variable]
2405 | struct dentry *d_events;
| ^~~~~~~~


vim +/d_events +2405 kernel/trace/trace_events.c

ac343da7bc9048 Masami Hiramatsu 2020-09-10 2398
1473e4417c79f1 Steven Rostedt 2009-02-24 2399 static int
7f1d2f8210195c Steven Rostedt (Red Hat 2015-05-05 2400) event_create_dir(struct dentry *parent, struct trace_event_file *file)
1473e4417c79f1 Steven Rostedt 2009-02-24 2401 {
2425bcb9240f8c Steven Rostedt (Red Hat 2015-05-05 2402) struct trace_event_call *call = file->event_call;
ae63b31e4d0e2e Steven Rostedt 2012-05-03 2403 struct trace_array *tr = file->tr;
be995c36ba2232 Ajay Kaher 2023-01-22 2404 struct eventfs_file *ef_subsystem = NULL;
ae63b31e4d0e2e Steven Rostedt 2012-05-03 @2405 struct dentry *d_events;
de7b2973903c6c Mathieu Desnoyers 2014-04-08 2406 const char *name;
fd99498989f3b3 Steven Rostedt 2009-02-28 2407 int ret;
1473e4417c79f1 Steven Rostedt 2009-02-24 2408
6ecc2d1ca39177 Steven Rostedt 2009-02-27 2409 /*
6ecc2d1ca39177 Steven Rostedt 2009-02-27 2410 * If the trace point header did not define TRACE_SYSTEM
6ecc2d1ca39177 Steven Rostedt 2009-02-27 2411 * then the system would be called "TRACE_SYSTEM".
6ecc2d1ca39177 Steven Rostedt 2009-02-27 2412 */
ae63b31e4d0e2e Steven Rostedt 2012-05-03 2413 if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
be995c36ba2232 Ajay Kaher 2023-01-22 2414 ef_subsystem = event_subsystem_dir(tr, call->class->system, file, parent);
be995c36ba2232 Ajay Kaher 2023-01-22 2415 if (!ef_subsystem)
ae63b31e4d0e2e Steven Rostedt 2012-05-03 2416 return -ENOMEM;
ae63b31e4d0e2e Steven Rostedt 2012-05-03 2417 } else
ae63b31e4d0e2e Steven Rostedt 2012-05-03 2418 d_events = parent;
6ecc2d1ca39177 Steven Rostedt 2009-02-27 2419
687fcc4aee4567 Steven Rostedt (Red Hat 2015-05-13 2420) name = trace_event_name(call);
be995c36ba2232 Ajay Kaher 2023-01-22 2421 file->ef = eventfs_add_dir(name, ef_subsystem);
be995c36ba2232 Ajay Kaher 2023-01-22 2422 if (IS_ERR(file->ef)) {
8434dc9340cd2e Steven Rostedt (Red Hat 2015-01-20 2423) pr_warn("Could not create tracefs '%s' directory\n", name);
1473e4417c79f1 Steven Rostedt 2009-02-24 2424 return -1;
1473e4417c79f1 Steven Rostedt 2009-02-24 2425 }
1473e4417c79f1 Steven Rostedt 2009-02-24 2426
9b63776fa3ca96 Steven Rostedt 2012-05-10 2427 if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
be995c36ba2232 Ajay Kaher 2023-01-22 2428 eventfs_add_file("enable", TRACE_MODE_WRITE, file->ef, file,
620a30e97febc8 Oleg Nesterov 2013-07-31 2429 &ftrace_enable_fops);
1473e4417c79f1 Steven Rostedt 2009-02-24 2430

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

2023-01-23 02:06:57

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/8] eventfs: adding eventfs dir add functions

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230120]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-2-git-send-email-akaher%40vmware.com
patch subject: [PATCH 2/8] eventfs: adding eventfs dir add functions
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/db5e58a9349f39590a8fb39f0c3373c4c483e064
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout db5e58a9349f39590a8fb39f0c3373c4c483e064
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
>> fs/tracefs/event_inode.c:27:31: sparse: sparse: symbol 'eventfs_root_dir_inode_operations' was not declared. Should it be static?

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

2023-01-23 05:42:08

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/8] eventfs: introducing struct tracefs_inode

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-1-git-send-email-akaher%40vmware.com
patch subject: [PATCH 1/8] eventfs: introducing struct tracefs_inode
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/926ba0e4029baa4bbc7c283854148d1769642d50
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout 926ba0e4029baa4bbc7c283854148d1769642d50
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> fs/tracefs/inode.c:130:15: warning: no previous prototype for function 'tracefs_get_inode' [-Wmissing-prototypes]
struct inode *tracefs_get_inode(struct super_block *sb)
^
fs/tracefs/inode.c:130:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct inode *tracefs_get_inode(struct super_block *sb)
^
static
>> fs/tracefs/inode.c:402:16: warning: no previous prototype for function 'tracefs_start_creating' [-Wmissing-prototypes]
struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
^
fs/tracefs/inode.c:402:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
^
static
>> fs/tracefs/inode.c:440:16: warning: no previous prototype for function 'tracefs_failed_creating' [-Wmissing-prototypes]
struct dentry *tracefs_failed_creating(struct dentry *dentry)
^
fs/tracefs/inode.c:440:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct dentry *tracefs_failed_creating(struct dentry *dentry)
^
static
>> fs/tracefs/inode.c:448:16: warning: no previous prototype for function 'tracefs_end_creating' [-Wmissing-prototypes]
struct dentry *tracefs_end_creating(struct dentry *dentry)
^
fs/tracefs/inode.c:448:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
struct dentry *tracefs_end_creating(struct dentry *dentry)
^
static
4 warnings generated.


vim +/tracefs_get_inode +130 fs/tracefs/inode.c

129
> 130 struct inode *tracefs_get_inode(struct super_block *sb)
131 {
132 struct inode *inode = new_inode(sb);
133 if (inode) {
134 inode->i_ino = get_next_ino();
135 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
136 }
137 return inode;
138 }
139

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

2023-01-23 06:02:12

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/8] eventfs: introducing struct tracefs_inode

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230120]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-1-git-send-email-akaher%40vmware.com
patch subject: [PATCH 1/8] eventfs: introducing struct tracefs_inode
config: x86_64-rhel-8.3-func (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/926ba0e4029baa4bbc7c283854148d1769642d50
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout 926ba0e4029baa4bbc7c283854148d1769642d50
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> fs/tracefs/inode.c:130:15: warning: no previous prototype for 'tracefs_get_inode' [-Wmissing-prototypes]
130 | struct inode *tracefs_get_inode(struct super_block *sb)
| ^~~~~~~~~~~~~~~~~
>> fs/tracefs/inode.c:402:16: warning: no previous prototype for 'tracefs_start_creating' [-Wmissing-prototypes]
402 | struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
| ^~~~~~~~~~~~~~~~~~~~~~
>> fs/tracefs/inode.c:440:16: warning: no previous prototype for 'tracefs_failed_creating' [-Wmissing-prototypes]
440 | struct dentry *tracefs_failed_creating(struct dentry *dentry)
| ^~~~~~~~~~~~~~~~~~~~~~~
>> fs/tracefs/inode.c:448:16: warning: no previous prototype for 'tracefs_end_creating' [-Wmissing-prototypes]
448 | struct dentry *tracefs_end_creating(struct dentry *dentry)
| ^~~~~~~~~~~~~~~~~~~~


vim +/tracefs_get_inode +130 fs/tracefs/inode.c

129
> 130 struct inode *tracefs_get_inode(struct super_block *sb)
131 {
132 struct inode *inode = new_inode(sb);
133 if (inode) {
134 inode->i_ino = get_next_ino();
135 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
136 }
137 return inode;
138 }
139

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

2023-01-23 07:45:30

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/8] eventfs: adding eventfs dir add functions

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230123]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-2-git-send-email-akaher%40vmware.com
patch subject: [PATCH 2/8] eventfs: adding eventfs dir add functions
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/db5e58a9349f39590a8fb39f0c3373c4c483e064
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout db5e58a9349f39590a8fb39f0c3373c4c483e064
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
>> fs/tracefs/event_inode.c:27:31: sparse: sparse: symbol 'eventfs_root_dir_inode_operations' was not declared. Should it be static?

vim +/eventfs_root_dir_inode_operations +27 fs/tracefs/event_inode.c

26
> 27 const struct inode_operations eventfs_root_dir_inode_operations = {
28 };
29

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

2023-01-23 09:27:13

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230123]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-5-git-send-email-akaher%40vmware.com
patch subject: [PATCH 5/8] eventfs: adding functions to create eventfs files and directories
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/950ac8561471b622eac5555b4a7502bcd8c20663
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout 950ac8561471b622eac5555b4a7502bcd8c20663
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
>> fs/tracefs/event_inode.c:48:15: sparse: sparse: symbol 'eventfs_create_file' was not declared. Should it be static?
>> fs/tracefs/event_inode.c:117:15: sparse: sparse: symbol 'eventfs_create_dir' was not declared. Should it be static?
fs/tracefs/event_inode.c:162:31: sparse: sparse: symbol 'eventfs_root_dir_inode_operations' was not declared. Should it be static?

vim +/eventfs_create_file +48 fs/tracefs/event_inode.c

23
24 /**
25 * eventfs_create_file - create a file in the tracefs filesystem
26 * @name: a pointer to a string containing the name of the file to create.
27 * @mode: the permission that the file should have.
28 * @parent: a pointer to the parent dentry for this file. This should be a
29 * directory dentry if set. If this parameter is NULL, then the
30 * file will be created in the root of the tracefs filesystem.
31 * @data: a pointer to something that the caller will want to get to later
32 * on. The inode.i_private pointer will point to this value on
33 * the open() call.
34 * @fops: a pointer to a struct file_operations that should be used for
35 * this file.
36 *
37 * This is the basic "create a file" function for tracefs. It allows for a
38 * wide range of flexibility in creating a file.
39 *
40 * This function will return a pointer to a dentry if it succeeds. This
41 * pointer must be passed to the tracefs_remove() function when the file is
42 * to be removed (no automatic cleanup happens if your module is unloaded,
43 * you are responsible here.) If an error occurs, %NULL will be returned.
44 *
45 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
46 * returned.
47 */
> 48 struct dentry *eventfs_create_file(const char *name, umode_t mode,
49 struct dentry *parent, void *data,
50 const struct file_operations *fop,
51 bool anon)
52 {
53 struct tracefs_inode *ti;
54 struct dentry *dentry;
55 struct inode *inode;
56
57 if (security_locked_down(LOCKDOWN_TRACEFS))
58 return NULL;
59
60 if (!(mode & S_IFMT))
61 mode |= S_IFREG;
62
63 if (WARN_ON_ONCE(!S_ISREG(mode)))
64 return NULL;
65
66 dentry = eventfs_start_creating(name, parent);
67
68 if (IS_ERR(dentry))
69 return dentry;
70
71 inode = tracefs_get_inode(dentry->d_sb);
72 if (unlikely(!inode))
73 return eventfs_failed_creating(dentry);
74
75 inode->i_mode = mode;
76 inode->i_fop = fop;
77 inode->i_private = data;
78
79 ti = get_tracefs(inode);
80 ti->flags |= TRACEFS_EVENT_INODE;
81
82 if (anon)
83 d_instantiate_anon(dentry, inode);
84 else
85 d_instantiate(dentry, inode);
86
87 fsnotify_create(dentry->d_parent->d_inode, dentry);
88 return eventfs_end_creating(dentry);
89 }
90
91 /**
92 * eventfs_create_dir - create a dir in the tracefs filesystem
93 * @name: a pointer to a string containing the name of the file to create.
94 * @mode: the permission that the file should have.
95 * @parent: a pointer to the parent dentry for this file. This should be a
96 * directory dentry if set. If this parameter is NULL, then the
97 * file will be created in the root of the tracefs filesystem.
98 * @data: a pointer to something that the caller will want to get to later
99 * on. The inode.i_private pointer will point to this value on
100 * the open() call.
101 * @fop: a pointer to a struct file_operations that should be used for
102 * this dir.
103 * @iop: a pointer to a struct inode_operations that should be used for
104 * this dir.
105 *
106 * This is the basic "create a dir" function for eventfs. It allows for a
107 * wide range of flexibility in creating a dir.
108 *
109 * This function will return a pointer to a dentry if it succeeds. This
110 * pointer must be passed to the tracefs_remove() function when the file is
111 * to be removed (no automatic cleanup happens if your module is unloaded,
112 * you are responsible here.) If an error occurs, %NULL will be returned.
113 *
114 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
115 * returned.
116 */
> 117 struct dentry *eventfs_create_dir(const char *name, umode_t mode,
118 struct dentry *parent, void *data,
119 const struct file_operations *fop,
120 const struct inode_operations *iop,
121 bool anon)
122 {
123 struct tracefs_inode *ti;
124 struct dentry *dentry;
125 struct inode *inode;
126
127 if (security_locked_down(LOCKDOWN_TRACEFS))
128 return NULL;
129
130 WARN_ON(!S_ISDIR(mode));
131
132 dentry = eventfs_start_creating(name, parent);
133
134 if (IS_ERR(dentry))
135 return dentry;
136
137 inode = tracefs_get_inode(dentry->d_sb);
138 if (unlikely(!inode))
139 return eventfs_failed_creating(dentry);
140
141 inode->i_mode = mode;
142 inode->i_op = iop;
143 inode->i_fop = fop;
144 inode->i_private = data;
145
146 ti = get_tracefs(inode);
147 ti->flags |= TRACEFS_EVENT_INODE;
148
149 inc_nlink(inode);
150 if (anon)
151 d_instantiate_anon(dentry, inode);
152 else
153 d_instantiate(dentry, inode);
154 inc_nlink(dentry->d_parent->d_inode);
155 fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
156 return eventfs_end_creating(dentry);
157 }
158

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

2023-01-23 11:50:13

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230123]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-6-git-send-email-akaher%40vmware.com
patch subject: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/bdfb24dc39f183eda75dc7c6ad54798181ad4a94
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout bdfb24dc39f183eda75dc7c6ad54798181ad4a94
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
fs/tracefs/event_inode.c:48:15: sparse: sparse: symbol 'eventfs_create_file' was not declared. Should it be static?
fs/tracefs/event_inode.c:117:15: sparse: sparse: symbol 'eventfs_create_dir' was not declared. Should it be static?
>> fs/tracefs/event_inode.c:192:6: sparse: sparse: symbol 'eventfs_post_create_dir' was not declared. Should it be static?
>> fs/tracefs/event_inode.c:291:5: sparse: sparse: symbol 'dcache_dir_open_wrapper' was not declared. Should it be static?
fs/tracefs/event_inode.c:340:31: sparse: sparse: symbol 'eventfs_root_dir_inode_operations' was not declared. Should it be static?

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

2023-01-23 12:04:24

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 2/8] eventfs: adding eventfs dir add functions

Hi Ajay,

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-2-git-send-email-akaher%40vmware.com
patch subject: [PATCH 2/8] eventfs: adding eventfs dir add functions
config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
fs/tracefs/event_inode.c:114 eventfs_add_subsystem_dir() error: dereferencing freed memory 'ef'

vim +/ef +114 fs/tracefs/event_inode.c

db5e58a9349f39 Ajay Kaher 2023-01-22 87 struct eventfs_file *eventfs_add_subsystem_dir(const char *name, struct dentry *parent)
db5e58a9349f39 Ajay Kaher 2023-01-22 88 {
db5e58a9349f39 Ajay Kaher 2023-01-22 89 struct eventfs_file *ef;
db5e58a9349f39 Ajay Kaher 2023-01-22 90 struct tracefs_inode *ti_parent;
db5e58a9349f39 Ajay Kaher 2023-01-22 91 struct eventfs_inode *ei_parent;
db5e58a9349f39 Ajay Kaher 2023-01-22 92
db5e58a9349f39 Ajay Kaher 2023-01-22 93 if (!parent)
db5e58a9349f39 Ajay Kaher 2023-01-22 94 return ERR_PTR(-EINVAL);
db5e58a9349f39 Ajay Kaher 2023-01-22 95
db5e58a9349f39 Ajay Kaher 2023-01-22 96 ti_parent = get_tracefs(parent->d_inode);
db5e58a9349f39 Ajay Kaher 2023-01-22 97 ei_parent = ti_parent->private;
db5e58a9349f39 Ajay Kaher 2023-01-22 98
db5e58a9349f39 Ajay Kaher 2023-01-22 99 ef = kzalloc(sizeof(*ef), GFP_KERNEL);
db5e58a9349f39 Ajay Kaher 2023-01-22 100 if (!ef)
db5e58a9349f39 Ajay Kaher 2023-01-22 101 return ERR_PTR(-ENOMEM);
db5e58a9349f39 Ajay Kaher 2023-01-22 102
db5e58a9349f39 Ajay Kaher 2023-01-22 103 ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL);
db5e58a9349f39 Ajay Kaher 2023-01-22 104 if (!ef->ei) {
db5e58a9349f39 Ajay Kaher 2023-01-22 105 kfree(ef);
db5e58a9349f39 Ajay Kaher 2023-01-22 106 return ERR_PTR(-ENOMEM);
db5e58a9349f39 Ajay Kaher 2023-01-22 107 }
db5e58a9349f39 Ajay Kaher 2023-01-22 108
db5e58a9349f39 Ajay Kaher 2023-01-22 109 INIT_LIST_HEAD(&ef->ei->e_top_files);
db5e58a9349f39 Ajay Kaher 2023-01-22 110
db5e58a9349f39 Ajay Kaher 2023-01-22 111 ef->name = kstrdup(name, GFP_KERNEL);
db5e58a9349f39 Ajay Kaher 2023-01-22 112 if (!ef->name) {
db5e58a9349f39 Ajay Kaher 2023-01-22 113 kfree(ef);
db5e58a9349f39 Ajay Kaher 2023-01-22 @114 kfree(ef->ei);

kfree(ef->ei); first to avoid a use after free.

db5e58a9349f39 Ajay Kaher 2023-01-22 115 return ERR_PTR(-ENOMEM);
db5e58a9349f39 Ajay Kaher 2023-01-22 116 }
db5e58a9349f39 Ajay Kaher 2023-01-22 117
db5e58a9349f39 Ajay Kaher 2023-01-22 118 ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
db5e58a9349f39 Ajay Kaher 2023-01-22 119 ef->iop = &eventfs_root_dir_inode_operations;
db5e58a9349f39 Ajay Kaher 2023-01-22 120 ef->fop = &eventfs_file_operations;
db5e58a9349f39 Ajay Kaher 2023-01-22 121 ef->dentry = NULL;
db5e58a9349f39 Ajay Kaher 2023-01-22 122 ef->created = false;
db5e58a9349f39 Ajay Kaher 2023-01-22 123 ef->d_parent = parent;
db5e58a9349f39 Ajay Kaher 2023-01-22 124
db5e58a9349f39 Ajay Kaher 2023-01-22 125 list_add_tail(&ef->list, &ei_parent->e_top_files);
db5e58a9349f39 Ajay Kaher 2023-01-22 126 return ef;
db5e58a9349f39 Ajay Kaher 2023-01-22 127 }

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


2023-01-23 14:15:23

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 8/8] eventfs: moving tracing/events to eventfs

Hi Ajay,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.2-rc5 next-20230123]
[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/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
patch link: https://lore.kernel.org/r/1674407228-49109-8-git-send-email-akaher%40vmware.com
patch subject: [PATCH 8/8] eventfs: moving tracing/events to eventfs
config: x86_64-randconfig-s022 (https://download.01.org/0day-ci/archive/20230123/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/be995c36ba2232edcd4fa64e4581b9a6763c75e6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
git checkout be995c36ba2232edcd4fa64e4581b9a6763c75e6
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/tracefs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

sparse warnings: (new ones prefixed by >>)
>> fs/tracefs/inode.c:390:32: sparse: sparse: symbol 'tracefs_dentry_operations' was not declared. Should it be static?

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

2023-01-23 16:51:19

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 0/8] tracing: introducing eventfs

On Sun, 22 Jan 2023 22:37:08 +0530
Ajay Kaher <[email protected]> wrote:

> Events Tracing infrastructure contains lot of files, directories
> (internally in terms of inodes, dentries). And ends up by consuming
> memory in MBs. We can have multiple events of Events Tracing, which
> further requires more memory.
>
> Instead of creating inodes/dentries, eventfs could keep meta-data and
> skip the creation of inodes/dentries. As and when require, eventfs will
> create the inodes/dentries only for required files/directories.
> Also eventfs would delete the inodes/dentries once no more requires
> but preserve the meta data.
>
> Tracing events took ~9MB, with this approach it took ~4.5MB
> for ~10K files/dir.
>
> [PATCH 1/8]: Introducing struct tracefs_inode
> [PATCH 2/8]: Adding eventfs-dir-add functions
> [PATCH 3/8]: Adding eventfs-file-add function
> [PATCH 4/8]: Adding eventfs-file-directory-remove function
> [PATCH 5/8]: Adding functions to create-eventfs-files
> [PATCH 6/8]: Adding eventfs lookup, read, open functions
> [PATCH 7/8]: Creating tracefs_inode_cache
> [PATCH 8/8]: Moving tracing events to eventfs

Hi Ajay,

Thanks a lot for sending these out.

Note, something went wrong with your threading, as all the patches should
be a reply to this one, but instead, they all (including this email) are a
reply to patch 1 ??

Also, for v2, can you address all the kernel test robot issues as well as
what Dan Carpenter wrote. There's also a couple of whitespace issues.

Finally, when I run the ftrace selftests that are in the kernel repository:

# cd linux.git
# cd tools/testing/selftests/ftrace
# ./ftracetests

It crashes with a NULL kernel dereference:

[ 1021.844973] general protection fault, probably for non-canonical address 0x626f7270747365a6: 0000 [#1] PREEMPT SMP PTI
[ 1021.848900] CPU: 2 PID: 1160 Comm: ftracetest Not tainted 6.2.0-rc3-test-00014-g1a351602422d #152
[ 1021.852384] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-debian-1.16.0-5 04/01/2014
[ 1021.855716] RIP: 0010:dcache_dir_open_wrapper+0x6b/0x1b0
[ 1021.857700] Code: 75 28 e9 f7 00 00 00 48 8b 7b 10 48 85 ff 74 09 48 83 c7 58 e8 36 ad 0c 00 48 8b 43 18 48 8d 58 e8 49 39 c4 0f 84 d4 00 00 00 <80> 7b 4a 00 75 d7 c6 43 4a 01 48 8b 45 30 48 8d b8 a0 00 00 00 e8
[ 1021.864170] RSP: 0018:ffffa68b40f0fcb0 EFLAGS: 00010296
[ 1021.866133] RAX: 626f727074736574 RBX: 626f72707473655c RCX: ffff9c6bc08cb000
[ 1021.868797] RDX: ffffffff89058dc0 RSI: ffff9c6bc09f6f00 RDI: ffff9c6bceef2810
[ 1021.871389] RBP: ffff9c6bcee223c0 R08: ffffffff8a3b2da0 R09: ffff9c6bceef2810
[ 1021.873953] R10: 0000000000000007 R11: 0000000000000002 R12: ffff9c6bc3664980
[ 1021.876669] R13: ffff9c6bc09f6f00 R14: ffff9c6bceef2810 R15: ffff9c6bc09f6f00
[ 1021.880350] FS: 00007f58e39ba740(0000) GS:ffff9c6d37c80000(0000) knlGS:0000000000000000
[ 1021.883289] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1021.885401] CR2: 000055a0c1465000 CR3: 000000010f5a8003 CR4: 0000000000170ee0
[ 1021.888117] Call Trace:
[ 1021.889227] <TASK>
[ 1021.890216] ? __pfx_dcache_dir_open_wrapper+0x10/0x10
[ 1021.892088] do_dentry_open+0x1e5/0x410
[ 1021.893501] path_openat+0xd7f/0x1220
[ 1021.894863] ? asm_exc_page_fault+0x22/0x30
[ 1021.896325] ? trace_hardirqs_on+0x2a/0xe0
[ 1021.897715] do_filp_open+0xaf/0x160
[ 1021.898972] do_sys_openat2+0xaf/0x170
[ 1021.900211] __x64_sys_openat+0x6a/0xa0
[ 1021.901451] do_syscall_64+0x3a/0x90
[ 1021.902636] entry_SYSCALL_64_after_hwframe+0x72/0xdc
[ 1021.904145] RIP: 0033:0x7f58e3ab9e41
[ 1021.905255] Code: 44 24 18 31 c0 41 83 e2 40 75 3e 89 f0 25 00 00 41 00 3d 00 00 41 00 74 30 89 f2 b8 01 01 00 00 48 89 fe bf 9c ff ff ff 0f 05 <48> 3d 00 f0 ff ff 77 3f 48 8b 54 24 18 64 48 2b 14 25 28 00 00 00
[ 1021.910033] RSP: 002b:00007ffdfae49b40 EFLAGS: 00000287 ORIG_RAX: 0000000000000101
[ 1021.913838] RAX: ffffffffffffffda RBX: 000055a0c145bfb1 RCX: 00007f58e3ab9e41
[ 1021.915613] RDX: 0000000000090800 RSI: 000055a0c1463380 RDI: 00000000ffffff9c
[ 1021.917358] RBP: 000055a0c146338f R08: 0000000000000001 R09: 000000000000000f
[ 1021.919110] R10: 0000000000000000 R11: 0000000000000287 R12: 000055a0c1463380
[ 1021.920864] R13: 000055a0c145bfb1 R14: 0000000000000000 R15: 000055a0c145bfb2
[ 1021.922613] </TASK>
[ 1021.923331] Modules linked in: vmw_vsock_virtio_transport vmw_vsock_virtio_transport_common vsock ip_tables
[ 1021.925741] Dumping ftrace buffer:
[ 1021.926709] (ftrace buffer empty)
[ 1021.927754] ---[ end trace 0000000000000000 ]---
[ 1021.928993] RIP: 0010:dcache_dir_open_wrapper+0x6b/0x1b0

Could you see what happened there?

Thanks!

-- Steve

2023-01-23 16:54:16

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 6/8] eventfs: adding eventfs lookup, read, open functions

On Sun, 22 Jan 2023 22:37:05 +0530
Ajay Kaher <[email protected]> wrote:

> +int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
> +{
> + struct tracefs_inode *ti;
> + struct eventfs_inode *ei;
> + struct eventfs_file *ef;
> + struct inode *f_inode = file_inode(file);
> + struct dentry *dentry = file_dentry(file);
> +
> + ti = get_tracefs(f_inode);
> + if (!(ti->flags & TRACEFS_EVENT_INODE))
> + return -EINVAL;
> +
> + ei = ti->private;
> + list_for_each_entry(ef, &ei->e_top_files, list) {
> + if (ef->created) {
> + dget(ef->dentry);
> + continue;
> + }
> +
> + ef->created = true;
> +
> + inode_lock(dentry->d_inode);

> + if (ef->ei)

There's an extra space at the end of the above line.

-- Steve


> + ef->dentry = eventfs_create_dir(ef->name, ef->mode, dentry,
> + ef->data, ef->fop, ef->iop, 1);
> + else
> + ef->dentry = eventfs_create_file(ef->name, ef->mode, dentry,
> + ef->data, ef->fop, 1);
> + inode_unlock(dentry->d_inode);
> +
> + if (IS_ERR_OR_NULL(ef->dentry)) {
> + ef->created = false;
> + } else {
> + if (ef->ei)
> + eventfs_post_create_dir(ef);
> + ef->dentry->d_fsdata = ef;
> + }
> + }
> + return dcache_dir_open(inode, file);
> +}
> +

2023-01-29 18:07:42

by Ajay Kaher

[permalink] [raw]
Subject: Re: [PATCH 0/8] tracing: introducing eventfs



> On 23-Jan-2023, at 10:21 PM, Steven Rostedt <[email protected]> wrote:
>
> !! External Email
>
> On Sun, 22 Jan 2023 22:37:08 +0530
> Ajay Kaher <[email protected]> wrote:
>
>> Events Tracing infrastructure contains lot of files, directories
>> (internally in terms of inodes, dentries). And ends up by consuming
>> memory in MBs. We can have multiple events of Events Tracing, which
>> further requires more memory.
>>
>> Instead of creating inodes/dentries, eventfs could keep meta-data and
>> skip the creation of inodes/dentries. As and when require, eventfs will
>> create the inodes/dentries only for required files/directories.
>> Also eventfs would delete the inodes/dentries once no more requires
>> but preserve the meta data.
>>
>> Tracing events took ~9MB, with this approach it took ~4.5MB
>> for ~10K files/dir.
>>
>> [PATCH 1/8]: Introducing struct tracefs_inode
>> [PATCH 2/8]: Adding eventfs-dir-add functions
>> [PATCH 3/8]: Adding eventfs-file-add function
>> [PATCH 4/8]: Adding eventfs-file-directory-remove function
>> [PATCH 5/8]: Adding functions to create-eventfs-files
>> [PATCH 6/8]: Adding eventfs lookup, read, open functions
>> [PATCH 7/8]: Creating tracefs_inode_cache
>> [PATCH 8/8]: Moving tracing events to eventfs
>
> Hi Ajay,
>
> Thanks a lot for sending these out.
>
> Note, something went wrong with your threading, as all the patches should
> be a reply to this one, but instead, they all (including this email) are a
> reply to patch 1 ??

Not sure why this is happenning, but I will try to fix in v2.

> Also, for v2, can you address all the kernel test robot issues as well as
> what Dan Carpenter wrote. There's also a couple of whitespace issues.
>

Sure, in v2.

> Finally, when I run the ftrace selftests that are in the kernel repository:
>
> # cd linux.git
> # cd tools/testing/selftests/ftrace
> # ./ftracetests

Thanks. I was looking some utility to test eventfs.

> It crashes with a NULL kernel dereference:
>
> [ 1021.844973] general protection fault, probably for non-canonical address 0x626f7270747365a6: 0000 [#1] PREEMPT SMP PTI
> [ 1021.848900] CPU: 2 PID: 1160 Comm: ftracetest Not tainted 6.2.0-rc3-test-00014-g1a351602422d #152
> [ 1021.852384] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-debian-1.16.0-5 04/01/2014
> [ 1021.855716] RIP: 0010:dcache_dir_open_wrapper+0x6b/0x1b0
> [ 1021.857700] Code: 75 28 e9 f7 00 00 00 48 8b 7b 10 48 85 ff 74 09 48 83 c7 58 e8 36 ad 0c 00 48 8b 43 18 48 8d 58 e8 49 39 c4 0f 84 d4 00 00 00 <80> 7b 4a 00 75 d7 c6 43 4a 01 48 8b 45 30 48 8d b8 a0 00 00 00 e8
> [ 1021.864170] RSP: 0018:ffffa68b40f0fcb0 EFLAGS: 00010296
> [ 1021.866133] RAX: 626f727074736574 RBX: 626f72707473655c RCX: ffff9c6bc08cb000
> [ 1021.868797] RDX: ffffffff89058dc0 RSI: ffff9c6bc09f6f00 RDI: ffff9c6bceef2810
> [ 1021.871389] RBP: ffff9c6bcee223c0 R08: ffffffff8a3b2da0 R09: ffff9c6bceef2810
> [ 1021.873953] R10: 0000000000000007 R11: 0000000000000002 R12: ffff9c6bc3664980
> [ 1021.876669] R13: ffff9c6bc09f6f00 R14: ffff9c6bceef2810 R15: ffff9c6bc09f6f00
> [ 1021.880350] FS: 00007f58e39ba740(0000) GS:ffff9c6d37c80000(0000) knlGS:0000000000000000
> [ 1021.883289] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [ 1021.885401] CR2: 000055a0c1465000 CR3: 000000010f5a8003 CR4: 0000000000170ee0
> [ 1021.888117] Call Trace:
> [ 1021.889227] <TASK>
> [ 1021.890216] ? __pfx_dcache_dir_open_wrapper+0x10/0x10
> [ 1021.892088] do_dentry_open+0x1e5/0x410
> [ 1021.893501] path_openat+0xd7f/0x1220
> [ 1021.894863] ? asm_exc_page_fault+0x22/0x30
> [ 1021.896325] ? trace_hardirqs_on+0x2a/0xe0
> [ 1021.897715] do_filp_open+0xaf/0x160
> [ 1021.898972] do_sys_openat2+0xaf/0x170
> [ 1021.900211] __x64_sys_openat+0x6a/0xa0
> [ 1021.901451] do_syscall_64+0x3a/0x90
> [ 1021.902636] entry_SYSCALL_64_after_hwframe+0x72/0xdc
> [ 1021.904145] RIP: 0033:0x7f58e3ab9e41
> [ 1021.905255] Code: 44 24 18 31 c0 41 83 e2 40 75 3e 89 f0 25 00 00 41 00 3d 00 00 41 00 74 30 89 f2 b8 01 01 00 00 48 89 fe bf 9c ff ff ff 0f 05 <48> 3d 00 f0 ff ff 77 3f 48 8b 54 24 18 64 48 2b 14 25 28 00 00 00
> [ 1021.910033] RSP: 002b:00007ffdfae49b40 EFLAGS: 00000287 ORIG_RAX: 0000000000000101
> [ 1021.913838] RAX: ffffffffffffffda RBX: 000055a0c145bfb1 RCX: 00007f58e3ab9e41
> [ 1021.915613] RDX: 0000000000090800 RSI: 000055a0c1463380 RDI: 00000000ffffff9c
> [ 1021.917358] RBP: 000055a0c146338f R08: 0000000000000001 R09: 000000000000000f
> [ 1021.919110] R10: 0000000000000000 R11: 0000000000000287 R12: 000055a0c1463380
> [ 1021.920864] R13: 000055a0c145bfb1 R14: 0000000000000000 R15: 000055a0c145bfb2
> [ 1021.922613] </TASK>
> [ 1021.923331] Modules linked in: vmw_vsock_virtio_transport vmw_vsock_virtio_transport_common vsock ip_tables
> [ 1021.925741] Dumping ftrace buffer:
> [ 1021.926709] (ftrace buffer empty)
> [ 1021.927754] ---[ end trace 0000000000000000 ]---
> [ 1021.928993] RIP: 0010:dcache_dir_open_wrapper+0x6b/0x1b0
>
> Could you see what happened there?

For some cases, eventfs keeps file/folder (in form of node/dentry) with-in VFS
even last dput has been called. This will be deleted while executing drop_cache()
and eventfs_set_ef_status_free() will be called.

Above GPF happens when something deleted from eventfs link-list (removal of
dynamic events) but present with-in VFS (because of earlier access) and when
VFS will try to access and call dcache_dir_open_wrapper().

Solution: while deleting from eventfs link-list, needs to detect and delete from VFS.

I will fix in v2. Thanks for reporting this bug.

-Ajay



2023-01-30 06:43:47

by Nadav Amit

[permalink] [raw]
Subject: Re: [PATCH 0/8] tracing: introducing eventfs


> On Jan 29, 2023, at 8:07 PM, Ajay Kaher <[email protected]> wrote:
>
>> Hi Ajay,
>>
>> Thanks a lot for sending these out.
>>
>> Note, something went wrong with your threading, as all the patches should
>> be a reply to this one, but instead, they all (including this email) are a
>> reply to patch 1 ??
>
> Not sure why this is happenning, but I will try to fix in v2.

I suspect it happens since you create the cover letter manually.

If that is the case, instead use 'git format-patch --cover-letter …’.

2023-01-31 08:08:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 8/8] eventfs: moving tracing/events to eventfs


Greeting,

FYI, we noticed BUG:KASAN:use-after-free_in_dcache_dir_open_wrapper due to commit (built with gcc-11):

commit: be995c36ba2232edcd4fa64e4581b9a6763c75e6 ("[PATCH 8/8] eventfs: moving tracing/events to eventfs")
url: https://github.com/intel-lab-lkp/linux/commits/Ajay-Kaher/eventfs-adding-eventfs-dir-add-functions/20230123-010956
base: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git 2241ab53cbb5cdb08a6b2d4688feb13971058f65
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH 8/8] eventfs: moving tracing/events to eventfs

in testcase: kernel-selftests
version: kernel-selftests-x86_64-d4cf28ee-1_20230110
with following parameters:

group: ftrace

test-description: The kernel contains a set of "self tests" under the tools/testing/selftests/ directory. These are intended to be small unit tests to exercise individual code paths in the kernel.
test-url: https://www.kernel.org/doc/Documentation/kselftest.txt


on test machine: 4 threads Intel(R) Xeon(R) CPU E3-1225 v5 @ 3.30GHz (Skylake) with 16G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):


If you fix the issue, kindly add following tag
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-lkp/[email protected]


[ 218.042115][ T2485] BUG: KASAN: use-after-free in dcache_dir_open_wrapper (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:304)
[ 218.049977][ T2485] Read of size 8 at addr ffff8881bf289000 by task ftracetest/2485
[ 218.057664][ T2485]
[ 218.059869][ T2485] CPU: 1 PID: 2485 Comm: ftracetest Not tainted 6.2.0-rc5-00008-gbe995c36ba22 #5
[ 218.068863][ T2485] Hardware name: HP HP Z238 Microtower Workstation/8183, BIOS N51 Ver. 01.63 10/05/2017
[ 218.078463][ T2485] Call Trace:
[ 218.081623][ T2485] <TASK>
[ 218.084431][ T2485] dump_stack_lvl (kbuild/src/x86_64-3/lib/dump_stack.c:107 (discriminator 4))
[ 218.088814][ T2485] print_address_description+0x87/0x2a1
[ 218.095300][ T2485] print_report (kbuild/src/x86_64-3/mm/kasan/report.c:418)
[ 218.099696][ T2485] ? kasan_addr_to_slab (kbuild/src/x86_64-3/mm/kasan/common.c:35)
[ 218.104511][ T2485] ? dcache_dir_open_wrapper (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:304)
[ 218.110027][ T2485] kasan_report (kbuild/src/x86_64-3/mm/kasan/report.c:184 kbuild/src/x86_64-3/mm/kasan/report.c:519)
[ 218.114322][ T2485] ? dcache_dir_open_wrapper (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:304)
[ 218.119838][ T2485] dcache_dir_open_wrapper (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:304)
[ 218.125177][ T2485] ? fsnotify_perm+0x13b/0x4a0
[ 218.130426][ T2485] do_dentry_open (kbuild/src/x86_64-3/fs/open.c:883)
[ 218.135077][ T2485] ? eventfs_create_dir (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:292)
[ 218.140157][ T2485] ? may_open (kbuild/src/x86_64-3/fs/namei.c:3186)
[ 218.144283][ T2485] do_open (kbuild/src/x86_64-3/fs/namei.c:3558)
[ 218.148249][ T2485] path_openat (kbuild/src/x86_64-3/fs/namei.c:3714)
[ 218.152545][ T2485] ? do_open (kbuild/src/x86_64-3/fs/namei.c:3696)
[ 218.156667][ T2485] ? __lock_acquire (kbuild/src/x86_64-3/kernel/locking/lockdep.c:5055)
[ 218.161484][ T2485] do_filp_open (kbuild/src/x86_64-3/fs/namei.c:3741)
[ 218.165865][ T2485] ? may_open_dev (kbuild/src/x86_64-3/fs/namei.c:3735)
[ 218.170267][ T2485] ? alloc_fd (kbuild/src/x86_64-3/fs/file.c:555 (discriminator 10))
[ 218.174478][ T2485] ? do_raw_spin_lock (kbuild/src/x86_64-3/arch/x86/include/asm/atomic.h:202 kbuild/src/x86_64-3/include/linux/atomic/atomic-instrumented.h:543 kbuild/src/x86_64-3/include/asm-generic/qspinlock.h:111 kbuild/src/x86_64-3/kernel/locking/spinlock_debug.c:115)
[ 218.179379][ T2485] ? lock_is_held_type (kbuild/src/x86_64-3/kernel/locking/lockdep.c:5409 kbuild/src/x86_64-3/kernel/locking/lockdep.c:5711)
[ 218.184298][ T2485] ? alloc_fd (kbuild/src/x86_64-3/fs/file.c:555 (discriminator 10))
[ 218.188517][ T2485] ? _raw_spin_unlock (kbuild/src/x86_64-3/arch/x86/include/asm/preempt.h:85 kbuild/src/x86_64-3/include/linux/spinlock_api_smp.h:143 kbuild/src/x86_64-3/kernel/locking/spinlock.c:186)
[ 218.193265][ T2485] ? alloc_fd (kbuild/src/x86_64-3/fs/file.c:555 (discriminator 10))
[ 218.197478][ T2485] ? getname_flags (kbuild/src/x86_64-3/fs/namei.c:205)
[ 218.202642][ T2485] do_sys_openat2 (kbuild/src/x86_64-3/fs/open.c:1310)
[ 218.207197][ T2485] ? lock_is_held_type (kbuild/src/x86_64-3/kernel/locking/lockdep.c:5409 kbuild/src/x86_64-3/kernel/locking/lockdep.c:5711)
[ 218.212093][ T2485] ? build_open_flags (kbuild/src/x86_64-3/fs/open.c:1296)
[ 218.216995][ T2485] ? __might_fault (kbuild/src/x86_64-3/mm/memory.c:5647 kbuild/src/x86_64-3/mm/memory.c:5640)
[ 218.221550][ T2485] ? lock_release (kbuild/src/x86_64-3/kernel/locking/lockdep.c:466 kbuild/src/x86_64-3/kernel/locking/lockdep.c:5690)
[ 218.226011][ T2485] ? rseq_ip_fixup (kbuild/src/x86_64-3/kernel/rseq.c:228 kbuild/src/x86_64-3/kernel/rseq.c:262)
[ 218.230651][ T2485] __x64_sys_openat (kbuild/src/x86_64-3/fs/open.c:1337)
[ 218.235382][ T2485] ? __x64_sys_open (kbuild/src/x86_64-3/fs/open.c:1337)
[ 218.240110][ T2485] ? lockdep_hardirqs_on_prepare (kbuild/src/x86_64-3/kernel/locking/lockdep.c:4528)
[ 218.246579][ T2485] ? syscall_enter_from_user_mode (kbuild/src/x86_64-3/arch/x86/include/asm/irqflags.h:45 kbuild/src/x86_64-3/arch/x86/include/asm/irqflags.h:80 kbuild/src/x86_64-3/kernel/entry/common.c:111)
[ 218.252351][ T2485] ? trace_hardirqs_on (kbuild/src/x86_64-3/kernel/trace/trace_preemptirq.c:50 (discriminator 22))
[ 218.257273][ T2485] do_syscall_64 (kbuild/src/x86_64-3/arch/x86/entry/common.c:50 kbuild/src/x86_64-3/arch/x86/entry/common.c:80)
[ 218.261566][ T2485] ? syscall_exit_to_user_mode (kbuild/src/x86_64-3/kernel/entry/common.c:131 kbuild/src/x86_64-3/kernel/entry/common.c:298)
[ 218.267072][ T2485] ? lockdep_hardirqs_on_prepare (kbuild/src/x86_64-3/kernel/locking/lockdep.c:4528)
[ 218.273544][ T2485] ? do_syscall_64 (kbuild/src/x86_64-3/arch/x86/entry/common.c:87)
[ 218.278012][ T2485] ? do_syscall_64 (kbuild/src/x86_64-3/arch/x86/entry/common.c:87)
[ 218.282475][ T2485] ? do_user_addr_fault (kbuild/src/x86_64-3/arch/x86/mm/fault.c:1457)
[ 218.287556][ T2485] ? irqentry_exit_to_user_mode (kbuild/src/x86_64-3/kernel/entry/common.c:131 kbuild/src/x86_64-3/kernel/entry/common.c:311)
[ 218.293069][ T2485] ? lockdep_hardirqs_on_prepare (kbuild/src/x86_64-3/kernel/locking/lockdep.c:4528)
[ 218.299541][ T2485] entry_SYSCALL_64_after_hwframe (kbuild/src/x86_64-3/arch/x86/entry/entry_64.S:120)
[ 218.305327][ T2485] RIP: 0033:0x7f25686e8e41
[ 218.309637][ T2485] Code: 44 24 18 31 c0 41 83 e2 40 75 3e 89 f0 25 00 00 41 00 3d 00 00 41 00 74 30 89 f2 b8 01 01 00 00 48 89 fe bf 9c ff ff ff 0f 05 <48> 3d 00 f0 ff ff 77 3f 48 8b 54 24 18 64 48 2b 14 25 28 00 00 00
All code
========
0: 44 24 18 rex.R and $0x18,%al
3: 31 c0 xor %eax,%eax
5: 41 83 e2 40 and $0x40,%r10d
9: 75 3e jne 0x49
b: 89 f0 mov %esi,%eax
d: 25 00 00 41 00 and $0x410000,%eax
12: 3d 00 00 41 00 cmp $0x410000,%eax
17: 74 30 je 0x49
19: 89 f2 mov %esi,%edx
1b: b8 01 01 00 00 mov $0x101,%eax
20: 48 89 fe mov %rdi,%rsi
23: bf 9c ff ff ff mov $0xffffff9c,%edi
28: 0f 05 syscall
2a:* 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax <-- trapping instruction
30: 77 3f ja 0x71
32: 48 8b 54 24 18 mov 0x18(%rsp),%rdx
37: 64 48 2b 14 25 28 00 sub %fs:0x28,%rdx
3e: 00 00

Code starting with the faulting instruction
===========================================
0: 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax
6: 77 3f ja 0x47
8: 48 8b 54 24 18 mov 0x18(%rsp),%rdx
d: 64 48 2b 14 25 28 00 sub %fs:0x28,%rdx
14: 00 00
[ 218.329163][ T2485] RSP: 002b:00007ffe4be3f710 EFLAGS: 00000287 ORIG_RAX: 0000000000000101
[ 218.337457][ T2485] RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007f25686e8e41
[ 218.345319][ T2485] RDX: 0000000000090800 RSI: 0000558c50eafef0 RDI: 00000000ffffff9c
[ 218.353183][ T2485] RBP: 00007ffe4be3f8a0 R08: 0000000000000000 R09: 0000000000000000
[ 218.361045][ T2485] R10: 0000000000000000 R11: 0000000000000287 R12: 0000558c50eae789
[ 218.368906][ T2485] R13: 0000558c50eae788 R14: 0000558c50eca760 R15: 0000000000000800
[ 218.376772][ T2485] </TASK>
[ 218.379669][ T2485]
[ 218.381867][ T2485] Allocated by task 2337:
[ 218.386070][ T2485] kasan_save_stack (kbuild/src/x86_64-3/mm/kasan/common.c:46)
[ 218.390626][ T2485] kasan_set_track (kbuild/src/x86_64-3/mm/kasan/common.c:52)
[ 218.395089][ T2485] __kasan_kmalloc (kbuild/src/x86_64-3/mm/kasan/common.c:381)
[ 218.399557][ T2485] eventfs_add_subsystem_dir (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:417)
[ 218.404985][ T2485] event_subsystem_dir (kbuild/src/x86_64-3/kernel/trace/trace_events.c:2320)
[ 218.409970][ T2485] event_create_dir (kbuild/src/x86_64-3/kernel/trace/trace_events.c:2414)
[ 218.414608][ T2485] trace_add_event_call (kbuild/src/x86_64-3/kernel/trace/trace_events.c:3597 kbuild/src/x86_64-3/kernel/trace/trace_events.c:2910)
[ 218.419593][ T2485] trace_probe_register_event_call (kbuild/src/x86_64-3/kernel/trace/trace_probe.c:1128)
[ 218.425628][ T2485] register_trace_kprobe (kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:1736 kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:646)
[ 218.430793][ T2485] __trace_kprobe_create (kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:882)
[ 218.435950][ T2485] trace_probe_create (kbuild/src/x86_64-3/kernel/trace/trace_probe.c:1234)
[ 218.440680][ T2485] create_or_delete_trace_kprobe (kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:918)
[ 218.446368][ T2485] trace_parse_run_command (kbuild/src/x86_64-3/kernel/trace/trace.c:10133)
[ 218.451707][ T2485] vfs_write (kbuild/src/x86_64-3/fs/read_write.c:582)
[ 218.455831][ T2485] ksys_write (kbuild/src/x86_64-3/fs/read_write.c:637)
[ 218.459952][ T2485] do_syscall_64 (kbuild/src/x86_64-3/arch/x86/entry/common.c:50 kbuild/src/x86_64-3/arch/x86/entry/common.c:80)
[ 218.464260][ T2485] entry_SYSCALL_64_after_hwframe (kbuild/src/x86_64-3/arch/x86/entry/entry_64.S:120)
[ 218.470040][ T2485]
[ 218.472258][ T2485] Freed by task 2337:
[ 218.476112][ T2485] kasan_save_stack (kbuild/src/x86_64-3/mm/kasan/common.c:46)
[ 218.480663][ T2485] kasan_set_track (kbuild/src/x86_64-3/mm/kasan/common.c:52)
[ 218.485133][ T2485] kasan_save_free_info (kbuild/src/x86_64-3/mm/kasan/generic.c:520)
[ 218.490040][ T2485] __kasan_slab_free (kbuild/src/x86_64-3/mm/kasan/common.c:238 kbuild/src/x86_64-3/mm/kasan/common.c:200 kbuild/src/x86_64-3/mm/kasan/common.c:244)
[ 218.494857][ T2485] slab_free_freelist_hook (kbuild/src/x86_64-3/mm/slub.c:1807)
[ 218.500110][ T2485] __kmem_cache_free (kbuild/src/x86_64-3/mm/slub.c:3787 kbuild/src/x86_64-3/mm/slub.c:3800)
[ 218.504928][ T2485] eventfs_remove (kbuild/src/x86_64-3/fs/tracefs/event_inode.c:618)
[ 218.509396][ T2485] remove_event_file_dir (kbuild/src/x86_64-3/include/linux/list.h:134 kbuild/src/x86_64-3/include/linux/list.h:148 kbuild/src/x86_64-3/kernel/trace/trace_events.c:978 kbuild/src/x86_64-3/kernel/trace/trace_events.c:1001)
[ 218.514553][ T2485] event_remove (kbuild/src/x86_64-3/kernel/trace/trace_events.c:2481 kbuild/src/x86_64-3/kernel/trace/trace_events.c:2520)
[ 218.518928][ T2485] trace_remove_event_call (kbuild/src/x86_64-3/kernel/trace/trace_events.c:2924 kbuild/src/x86_64-3/kernel/trace/trace_events.c:2960 kbuild/src/x86_64-3/kernel/trace/trace_events.c:2980)
[ 218.524270][ T2485] trace_kprobe_release (kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:547 kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:1091)
[ 218.529347][ T2485] dyn_events_release_all (kbuild/src/x86_64-3/kernel/trace/trace_dynevent.c:213)
[ 218.534596][ T2485] probes_open (kbuild/src/x86_64-3/kernel/trace/trace_kprobe.c:1151)
[ 218.538717][ T2485] do_dentry_open (kbuild/src/x86_64-3/fs/open.c:883)
[ 218.543349][ T2485] do_open (kbuild/src/x86_64-3/fs/namei.c:3558)
[ 218.547309][ T2485] path_openat (kbuild/src/x86_64-3/fs/namei.c:3714)
[ 218.551612][ T2485] do_filp_open (kbuild/src/x86_64-3/fs/namei.c:3741)
[ 218.555993][ T2485] do_sys_openat2 (kbuild/src/x86_64-3/fs/open.c:1310)
[ 218.560548][ T2485] __x64_sys_openat (kbuild/src/x86_64-3/fs/open.c:1337)
[ 218.565284][ T2485] do_syscall_64 (kbuild/src/x86_64-3/arch/x86/entry/common.c:50 kbuild/src/x86_64-3/arch/x86/entry/common.c:80)
[ 218.569573][ T2485] entry_SYSCALL_64_after_hwframe (kbuild/src/x86_64-3/arch/x86/entry/entry_64.S:120)
[ 218.575340][ T2485]
[ 218.577545][ T2485] The buggy address belongs to the object at ffff8881bf289000
[ 218.577545][ T2485] which belongs to the cache kmalloc-16 of size 16
[ 218.591321][ T2485] The buggy address is located 0 bytes inside of
[ 218.591321][ T2485] 16-byte region [ffff8881bf289000, ffff8881bf289010)
[ 218.604229][ T2485]
[ 218.606431][ T2485] The buggy address belongs to the physical page:
[ 218.612722][ T2485] page:0000000007538459 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1bf289
[ 218.622847][ T2485] flags: 0x17ffffc0000200(slab|node=0|zone=2|lastcpupid=0x1fffff)
[ 218.630534][ T2485] raw: 0017ffffc0000200 ffff8881000423c0 dead000000000122 0000000000000000
[ 218.639008][ T2485] raw: 0000000000000000 0000000000800080 00000001ffffffff 0000000000000000
[ 218.647478][ T2485] page dumped because: kasan: bad access detected
[ 218.653773][ T2485]
[ 218.655978][ T2485] Memory state around the buggy address:
[ 218.661485][ T2485] ffff8881bf288f00: 00 00 00 fc fc 00 00 00 fc fc 00 00 00 fc fc 00
[ 218.669446][ T2485] ffff8881bf288f80: 00 00 fc fc 00 00 00 fc fc 00 00 00 fc fc fc fc
[ 218.677389][ T2485] >ffff8881bf289000: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
[ 218.685333][ T2485] ^
[ 218.689278][ T2485] ffff8881bf289080: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc
[ 218.697237][ T2485] ffff8881bf289100: fa fb fc fc fa fb fc fc fa fb fc fc fa fb fc fc


To reproduce:

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
sudo bin/lkp install job.yaml # job file is attached in this email
bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
sudo bin/lkp run generated-yaml-file

# if come across any failure that blocks the test,
# please remove ~/.lkp and /lkp dir to run from a clean state.



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



Attachments:
(No filename) (14.45 kB)
config-6.2.0-rc5-00008-gbe995c36ba22 (165.80 kB)
job-script (6.39 kB)
dmesg.xz (47.61 kB)
kernel-selftests (205.79 kB)
job.yaml (4.98 kB)
Download all attachments

2023-03-28 23:05:14

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH 0/8] tracing: introducing eventfs

On Sun, 22 Jan 2023 22:37:08 +0530
Ajay Kaher <[email protected]> wrote:

> Events Tracing infrastructure contains lot of files, directories
> (internally in terms of inodes, dentries). And ends up by consuming
> memory in MBs. We can have multiple events of Events Tracing, which
> further requires more memory.
>
> Instead of creating inodes/dentries, eventfs could keep meta-data and
> skip the creation of inodes/dentries. As and when require, eventfs will
> create the inodes/dentries only for required files/directories.
> Also eventfs would delete the inodes/dentries once no more requires
> but preserve the meta data.
>

Hi Ajay,

Is there going to be any more work on this?

-- Steve

> Tracing events took ~9MB, with this approach it took ~4.5MB
> for ~10K files/dir.
>
> [PATCH 1/8]: Introducing struct tracefs_inode
> [PATCH 2/8]: Adding eventfs-dir-add functions
> [PATCH 3/8]: Adding eventfs-file-add function
> [PATCH 4/8]: Adding eventfs-file-directory-remove function
> [PATCH 5/8]: Adding functions to create-eventfs-files
> [PATCH 6/8]: Adding eventfs lookup, read, open functions
> [PATCH 7/8]: Creating tracefs_inode_cache
> [PATCH 8/8]: Moving tracing events to eventfs

2023-03-29 18:03:37

by Ajay Kaher

[permalink] [raw]
Subject: Re: [PATCH 0/8] tracing: introducing eventfs



> On 29-Mar-2023, at 4:17 AM, Steven Rostedt <[email protected]> wrote:
>
> !! External Email
>
> On Sun, 22 Jan 2023 22:37:08 +0530
> Ajay Kaher <[email protected]> wrote:
>
>> Events Tracing infrastructure contains lot of files, directories
>> (internally in terms of inodes, dentries). And ends up by consuming
>> memory in MBs. We can have multiple events of Events Tracing, which
>> further requires more memory.
>>
>> Instead of creating inodes/dentries, eventfs could keep meta-data and
>> skip the creation of inodes/dentries. As and when require, eventfs will
>> create the inodes/dentries only for required files/directories.
>> Also eventfs would delete the inodes/dentries once no more requires
>> but preserve the meta data.
>>
>
> Hi Ajay,
>
> Is there going to be any more work on this?
>
> -- Steve

Yes, Steve.

While running tools/testing/selftests/ftrace/ftracetests got crashes, as you also mentioned.
These crashes are because of lack of synchronisation and bugs in eventfs clean up path.

Locally I have fixed all these crashes with the help of Alexey.
I need one internal review round, once done I will post v2.

-Ajay


>
>> Tracing events took ~9MB, with this approach it took ~4.5MB
>> for ~10K files/dir.
>>
>> [PATCH 1/8]: Introducing struct tracefs_inode
>> [PATCH 2/8]: Adding eventfs-dir-add functions
>> [PATCH 3/8]: Adding eventfs-file-add function
>> [PATCH 4/8]: Adding eventfs-file-directory-remove function
>> [PATCH 5/8]: Adding functions to create-eventfs-files
>> [PATCH 6/8]: Adding eventfs lookup, read, open functions
>> [PATCH 7/8]: Creating tracefs_inode_cache
>> [PATCH 8/8]: Moving tracing events to eventfs
>
>
> !! External Email: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender.