diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 996b774..02b570b 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -44,7 +44,7 @@ static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)
 	return strlcpy(buf, kn->parent ? kn->name : "/", buflen);
 }
 
-static char * __must_check kernfs_path_locked(struct kernfs_node *kn, char *buf,
+static char * __must_check __kernfs_path(struct kernfs_node *kn, char *buf,
 					      size_t buflen)
 {
 	char *p = buf + buflen;
@@ -131,12 +131,33 @@ char *kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
 	char *p;
 
 	spin_lock_irqsave(&kernfs_rename_lock, flags);
-	p = kernfs_path_locked(kn, buf, buflen);
+	p = __kernfs_path(kn, buf, buflen);
 	spin_unlock_irqrestore(&kernfs_rename_lock, flags);
 	return p;
 }
 EXPORT_SYMBOL_GPL(kernfs_path);
 
+/* Raw version. Used by tracepoints only without acquiring lock */
+size_t kernfs_path_len_unlocked(struct kernfs_node *kn)
+{
+	size_t len = 0;
+
+	do {
+		len += strlen(kn->name) + 1;
+		kn = kn->parent;
+	} while (kn && kn->parent);
+
+	return len;
+}
+
+char *kernfs_path_unlocked(struct kernfs_node *kn, char *buf, size_t buflen)
+{
+	char *p;
+
+	p = __kernfs_path(kn, buf, buflen);
+	return p;
+}
+
 /**
  * pr_cont_kernfs_name - pr_cont name of a kernfs_node
  * @kn: kernfs_node of interest
@@ -168,7 +189,7 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)
 
 	spin_lock_irqsave(&kernfs_rename_lock, flags);
 
-	p = kernfs_path_locked(kn, kernfs_pr_cont_buf,
+	p = __kernfs_path(kn, kernfs_pr_cont_buf,
 			       sizeof(kernfs_pr_cont_buf));
 	if (p)
 		pr_cont("%s", p);
@@ -1397,6 +1418,9 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
 	kn->hash = kernfs_name_hash(kn->name, kn->ns);
 	kernfs_link_sibling(kn);
 
+	/* Tracepoints are protected by rcu_read_lock_sched */
+	synchronize_sched();
+
 	kernfs_put(old_parent);
 	kfree_const(old_name);
 
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 2162dca..52a19cd 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -538,6 +538,16 @@ static inline char * __must_check cgroup_path(struct cgroup *cgrp, char *buf,
 	return kernfs_path(cgrp->kn, buf, buflen);
 }
 
+/*
+ * Without acquiring kernfs_rename_lock in _kernfs_path.
+ * Used by tracepoints only.
+ */
+static inline char * __must_check cgroup_path_unlocked(struct cgroup *cgrp, char *buf,
+					      size_t buflen)
+{
+	return kernfs_path_unlocked(cgrp->kn, buf, buflen);
+}
+
 static inline void pr_cont_cgroup_name(struct cgroup *cgrp)
 {
 	pr_cont_kernfs_name(cgrp->kn);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index af51df3..7c10530 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -267,8 +267,11 @@ static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
 
 int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
 size_t kernfs_path_len(struct kernfs_node *kn);
+size_t kernfs_path_len_unlocked(struct kernfs_node *kn);
 char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
 				size_t buflen);
+char * __must_check kernfs_path_unlocked(struct kernfs_node *kn, char *buf,
+				size_t buflen);
 void pr_cont_kernfs_name(struct kernfs_node *kn);
 void pr_cont_kernfs_path(struct kernfs_node *kn);
 struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
@@ -338,10 +341,17 @@ static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
 static inline size_t kernfs_path_len(struct kernfs_node *kn)
 { return 0; }
 
+static inline size_t kernfs_path_len_unlocked(struct kernfs_node *kn)
+{ return 0; }
+
 static inline char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
 					      size_t buflen)
 { return NULL; }
 
+static inline char * __must_check kernfs_path_unlocked(struct kernfs_node *kn, char *buf,
+					      size_t buflen)
+{ return NULL; }
+
 static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
 static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
 
diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
index fff846b..3620624 100644
--- a/include/trace/events/writeback.h
+++ b/include/trace/events/writeback.h
@@ -136,7 +136,7 @@ DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode,
 
 static inline size_t __trace_wb_cgroup_size(struct bdi_writeback *wb)
 {
-	return kernfs_path_len(wb->memcg_css->cgroup->kn) + 1;
+	return kernfs_path_len_unlocked(wb->memcg_css->cgroup->kn) + 1;
 }
 
 static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
@@ -144,7 +144,8 @@ static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
 	struct cgroup *cgrp = wb->memcg_css->cgroup;
 	char *path;
 
-	path = cgroup_path(cgrp, buf, kernfs_path_len(cgrp->kn) + 1);
+	path = cgroup_path_unlocked(cgrp, buf,
+				    kernfs_path_len_unlocked(cgrp->kn) + 1);
 	WARN_ON_ONCE(path != buf);
 }
 
