Skip to contentSkip to conversation

powerpc/vas: Fix order of cleanup in debugfs dir

PATCH RESEND Applied Sukadev Bhattiprolu 3 participants 8 messages Feb 10, 2018 – Mar 19, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/4 powerpc/vas: Fix order of cleanup in debugfs dir

Fix the order of cleanup to ensure we free the name buffer in case of an error creating 'hvwc' or 'info' files.

---
 arch/powerpc/platforms/powernv/vas-debug.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/platforms/powernv/vas-debug.c +4 -4
index ca22f1e..b4de4c6 100644
@@ -166,13 +166,13 @@ void vas_window_init_dbgdir(struct vas_window *window)
 
 	return;
 
-free_name:
-	kfree(window->dbgname);
-	window->dbgname = NULL;
-
 remove_dir:
 	debugfs_remove_recursive(window->dbgdir);
 	window->dbgdir = NULL;
+
+free_name:
+	kfree(window->dbgname);
+	window->dbgname = NULL;
 }
 
 void vas_instance_init_dbgdir(struct vas_instance *vinst)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/4 powerpc/vas: Fix cleanup when VAS is not configured

When VAS is not configured in the system, make sure to remove the VAS debugfs directory and unregister the platform driver.

---
 arch/powerpc/platforms/powernv/vas-debug.c | 5 +++++
 arch/powerpc/platforms/powernv/vas.c       | 5 ++++-
 arch/powerpc/platforms/powernv/vas.h       | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/vas-debug.c +5 -0
index b4de4c6..e6e4067 100644
@@ -207,3 +207,8 @@ void vas_init_dbgdir(void)
 	if (IS_ERR(vas_debugfs))
 		vas_debugfs = NULL;
 }
+
+void vas_cleanup_dbgdir(void)
+{
+	debugfs_remove_recursive(vas_debugfs);
+}
arch/powerpc/platforms/powernv/vas.c +4 -1
index aebbe95..f83e27d8 100644
@@ -169,8 +169,11 @@ static int __init vas_init(void)
 		found++;
 	}
 
-	if (!found)
+	if (!found) {
+		platform_driver_unregister(&vas_driver);
+		vas_cleanup_dbgdir();
 		return -ENODEV;
+	}
 
 	pr_devel("Found %d instances\n", found);
 
arch/powerpc/platforms/powernv/vas.h +1 -0
index ae0100f..2645613 100644
@@ -406,6 +406,7 @@ extern struct mutex vas_mutex;
 
 extern struct vas_instance *find_vas_instance(int vasid);
 extern void vas_init_dbgdir(void);
+extern void vas_cleanup_dbgdir(void);
 extern void vas_instance_init_dbgdir(struct vas_instance *vinst);
 extern void vas_window_init_dbgdir(struct vas_window *win);
 extern void vas_window_free_dbgdir(struct vas_window *win);
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 2/4] powerpc/vas: Fix cleanup when VAS is not configured

Quoted 4 lines · Sukadev Bhattiprolu

When VAS is not configured in the system, make sure to remove the VAS debugfs directory and unregister the platform driver.

...

Quoted 5 lines
arch/powerpc/platforms/powernv/vas.c +0 -0
index aebbe95..f83e27d8 100644

arch/powerpc/platforms/powernv/vas.c static int __init vas_init(void) · line 176

Quoted 9 lines
arch/powerpc/platforms/powernv/vas.c +4 -1
@@ -169,8 +169,11 @@ static int __init vas_init(void)
 		found++;
 	}
 
-	if (!found)
+	if (!found) {
+		platform_driver_unregister(&vas_driver);
+		vas_cleanup_dbgdir();
 		return -ENODEV;
+	}

The better patch would be to move the call to vas_init_dbgdir() down here, where we know we have successfully registered the driver.

cheers

#3 lore raw

Re: [PATCH 2/4] powerpc/vas: Fix cleanup when VAS is not configured

Quoted 15 lines · Michael Ellerman [[email protected]] wrote:
Quoted 4 lines · Sukadev Bhattiprolu

When VAS is not configured in the system, make sure to remove the VAS debugfs directory and unregister the platform driver.

...

Quoted 8 lines
arch/powerpc/platforms/powernv/vas.c +0 -0
index aebbe95..f83e27d8 100644
@@ -169,8 +169,11 @@ static int __init vas_init(void)
 		found++;
 	}
 
Quoted 9 lines

arch/powerpc/platforms/powernv/vas.c static int __init vas_init(void) · line 176

Quoted 6 lines
arch/powerpc/platforms/powernv/vas.c +4 -1
-	if (!found)
+	if (!found) {
+		platform_driver_unregister(&vas_driver);
+		vas_cleanup_dbgdir();
 		return -ENODEV;
+	}

The better patch would be to move the call to vas_init_dbgdir() down here, where we know we have successfully registered the driver.

Well, when VAS is configured, init_vas_instance() expects the top level "vas" debugfs dir to already be setup.

We could have each init_vas_instance() assume it is the first and unconditionally call vas_init_dbgdir(). vas_init_dbgdir() could make sure to initialize only once.

Or, we could make a separate pass countng "ibm,vas" nodes. If there are none, skip both steps (dbgdir and registering platform driver).

Sukadev

#4 lore raw

Re: [PATCH 2/4] powerpc/vas: Fix cleanup when VAS is not configured

Quoted 26 lines · Sukadev Bhattiprolu
Quoted 15 lines · Michael Ellerman [[email protected]] wrote:
Quoted 4 lines · Sukadev Bhattiprolu

When VAS is not configured in the system, make sure to remove the VAS debugfs directory and unregister the platform driver.

...

Quoted 8 lines
arch/powerpc/platforms/powernv/vas.c +0 -0
index aebbe95..f83e27d8 100644
@@ -169,8 +169,11 @@ static int __init vas_init(void)
 		found++;
 	}
 
Quoted 9 lines

arch/powerpc/platforms/powernv/vas.c static int __init vas_init(void) · line 176

Quoted 6 lines
arch/powerpc/platforms/powernv/vas.c +4 -1
-	if (!found)
+	if (!found) {
+		platform_driver_unregister(&vas_driver);
+		vas_cleanup_dbgdir();
 		return -ENODEV;
+	}

The better patch would be to move the call to vas_init_dbgdir() down here, where we know we have successfully registered the driver.

Quoted 2 lines

Well, when VAS is configured, init_vas_instance() expects the top level "vas" debugfs dir to already be setup.

OK.

Quoted 3 lines

We could have each init_vas_instance() assume it is the first and unconditionally call vas_init_dbgdir(). vas_init_dbgdir() could make sure to initialize only once.

Yeah that looks like a good solution.

cheers

#5 lore raw

PATCH RESEND 3/4 powerpc/vas: Remove a stray line in Makefile

In reply to Sukadev Bhattiprolu

Remove a bogus line from arch/powerpc/platforms/powernv/Makefile that was added by commit ece4e51 ("powerpc/vas: Export HVWC to debugfs").

---
 arch/powerpc/platforms/powernv/Makefile | 1 -
 1 file changed, 1 deletion(-)
arch/powerpc/platforms/powernv/Makefile +0 -1
index 6c9d519..703a350 100644
@@ -16,5 +16,4 @@ obj-$(CONFIG_OPAL_PRD)	+= opal-prd.o
 obj-$(CONFIG_PERF_EVENTS) += opal-imc.o
 obj-$(CONFIG_PPC_MEMTRACE)	+= memtrace.o
 obj-$(CONFIG_PPC_VAS)	+= vas.o vas-window.o vas-debug.o
-obj-$(CONFIG_PPC_FTW)	+= nx-ftw.o
 obj-$(CONFIG_OCXL_BASE)	+= ocxl.o
Signature · 1 line
2.7.4
#6 lore raw

PATCH 4/4 powerpc/vas: Add a couple of trace points

In reply to Sukadev Bhattiprolu

Add a couple of trace points in the VAS driver

---
Changelog [v2]
- Make TRACE_INCLUDE_PATH relative to <trace/define_trace.h>

---
 arch/powerpc/platforms/powernv/vas-trace.h  | 112 ++++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/vas-window.c |   9 +++
 2 files changed, 121 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/vas-trace.h
arch/powerpc/platforms/powernv/vas-trace.h new file +112 -0
new file mode 100644
index 0000000..939d85d
@@ -0,0 +1,112 @@
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM	vas
+
+#if !defined(_VAS_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+
+#define _VAS_TRACE_H
+#include <linux/tracepoint.h>
+#include <linux/sched.h>
+#include <asm/vas.h>
+
+TRACE_EVENT(	vas_rx_win_open,
+
+		TP_PROTO(struct task_struct *tsk,
+			 int vasid,
+			 int cop,
+			 struct vas_rx_win_attr *rxattr),
+
+		TP_ARGS(tsk, vasid, cop, rxattr),
+
+		TP_STRUCT__entry(
+			__field(struct task_struct *, tsk)
+			__field(int, pid)
+			__field(int, cop)
+			__field(int, vasid)
+			__field(struct vas_rx_win_attr *, rxattr)
+			__field(int, lnotify_lpid)
+			__field(int, lnotify_pid)
+			__field(int, lnotify_tid)
+		),
+
+		TP_fast_assign(
+			__entry->pid = tsk->pid;
+			__entry->vasid = vasid;
+			__entry->cop = cop;
+			__entry->lnotify_lpid = rxattr->lnotify_lpid;
+			__entry->lnotify_pid = rxattr->lnotify_pid;
+			__entry->lnotify_tid = rxattr->lnotify_tid;
+		),
+
+		TP_printk("pid=%d, vasid=%d, cop=%d, lpid=%d, pid=%d, tid=%d",
+			__entry->pid, __entry->vasid, __entry->cop,
+			__entry->lnotify_lpid, __entry->lnotify_pid,
+			__entry->lnotify_tid)
+);
+
+TRACE_EVENT(	vas_tx_win_open,
+
+		TP_PROTO(struct task_struct *tsk,
+			 int vasid,
+			 int cop,
+			 struct vas_tx_win_attr *txattr),
+
+		TP_ARGS(tsk, vasid, cop, txattr),
+
+		TP_STRUCT__entry(
+			__field(struct task_struct *, tsk)
+			__field(int, pid)
+			__field(int, cop)
+			__field(int, vasid)
+			__field(struct vas_tx_win_attr *, txattr)
+			__field(int, lpid)
+			__field(int, pidr)
+		),
+
+		TP_fast_assign(
+			__entry->pid = tsk->pid;
+			__entry->vasid = vasid;
+			__entry->cop = cop;
+			__entry->lpid = txattr->lpid;
+			__entry->pidr = txattr->pidr;
+		),
+
+		TP_printk("pid=%d, vasid=%d, cop=%d, lpid=%d, pidr=%d",
+			__entry->pid, __entry->vasid, __entry->cop,
+			__entry->lpid, __entry->pidr)
+);
+
+TRACE_EVENT(	vas_paste_crb,
+
+		TP_PROTO(struct task_struct *tsk,
+			struct vas_window *win),
+
+		TP_ARGS(tsk, win),
+
+		TP_STRUCT__entry(
+			__field(struct task_struct *, tsk)
+			__field(struct vas_window *, win)
+			__field(int, pid)
+			__field(int, vasid)
+			__field(int, winid)
+			__field(unsigned long, paste_kaddr)
+		),
+
+		TP_fast_assign(
+			__entry->pid = tsk->pid;
+			__entry->vasid = win->vinst->vas_id;
+			__entry->winid = win->winid;
+			__entry->paste_kaddr = (unsigned long)win->paste_kaddr
+		),
+
+		TP_printk("pid=%d, vasid=%d, winid=%d, paste_kaddr=0x%016lx\n",
+			__entry->pid, __entry->vasid, __entry->winid,
+			__entry->paste_kaddr)
+);
+
+#endif /* _VAS_TRACE_H */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH ../../arch/powerpc/platforms/powernv
+#define TRACE_INCLUDE_FILE vas-trace
+#include <trace/define_trace.h>
arch/powerpc/platforms/powernv/vas-window.c +9 -0
index 2b3eb01..6b2de9e 100644
@@ -21,6 +21,9 @@
 #include "vas.h"
 #include "copy-paste.h"
 
+#define CREATE_TRACE_POINTS
+#include "vas-trace.h"
+
 /*
  * Compute the paste address region for the window @window using the
  * ->paste_base_addr and ->paste_win_id_shift we got from device tree.
@@ -880,6 +883,8 @@ struct vas_window *vas_rx_win_open(int vasid, enum vas_cop_type cop,
 	struct vas_winctx winctx;
 	struct vas_instance *vinst;
 
+	trace_vas_rx_win_open(current, vasid, cop, rxattr);
+
 	if (!rx_win_args_valid(cop, rxattr))
 		return ERR_PTR(-EINVAL);
 
@@ -1008,6 +1013,8 @@ struct vas_window *vas_tx_win_open(int vasid, enum vas_cop_type cop,
 	struct vas_winctx winctx;
 	struct vas_instance *vinst;
 
+	trace_vas_tx_win_open(current, vasid, cop, attr);
+
 	if (!tx_win_args_valid(cop, attr))
 		return ERR_PTR(-EINVAL);
 
@@ -1100,6 +1107,8 @@ int vas_paste_crb(struct vas_window *txwin, int offset, bool re)
 	void *addr;
 	uint64_t val;
 
+	trace_vas_paste_crb(current, txwin);
+
 	/*
 	 * Only NX windows are supported for now and hardware assumes
 	 * report-enable flag is set for NX windows. Ensure software
Signature · 1 line
2.7.4