Re: [PATCH v2 11/18] powerpc/vas: Export HVWC to debugfs

2017-11-07 Thread Michael Ellerman
Sukadev Bhattiprolu  writes:

> diff --git a/arch/powerpc/platforms/powernv/vas-window.c 
> b/arch/powerpc/platforms/powernv/vas-window.c
> index 23c13a7..088ce56 100644
> --- a/arch/powerpc/platforms/powernv/vas-window.c
> +++ b/arch/powerpc/platforms/powernv/vas-window.c
> @@ -145,24 +145,42 @@ static void unmap_paste_region(struct vas_window 
> *window)
>  }
>  
>  /*
> - * Unmap the MMIO regions for a window.
> + * Unmap the MMIO regions for a window. Hold the vas_mutex so we don't
> + * unmap when the window's debugfs dir is in use. This serializes close
> + * of a window even on another VAS instance but since its not a critical
> + * path, just minimize the time we hold the mutex for now. We can add
> + * a per-instance mutex later if necessary.
>   */
>  static void unmap_winctx_mmio_bars(struct vas_window *window)
>  {
>   int len;
> + void *uwc_map;
> + void *hvwc_map;
>   u64 busaddr_start;
>  
> + mutex_lock(_mutex);
> +
>   if (window->hvwc_map) {
> - get_hvwc_mmio_bar(window, _start, );
> - unmap_region(window->hvwc_map, busaddr_start, len);
> + hvwc_map = window->hvwc_map;
>   window->hvwc_map = NULL;
>   }
>  
>   if (window->uwc_map) {
> - get_uwc_mmio_bar(window, _start, );
> - unmap_region(window->uwc_map, busaddr_start, len);
> + uwc_map = window->uwc_map;
>   window->uwc_map = NULL;
>   }
> +
> + mutex_unlock(_mutex);
> +
> + if (hvwc_map) {
> + get_hvwc_mmio_bar(window, _start, );
> + unmap_region(hvwc_map, busaddr_start, len);
> + }
> +
> + if (uwc_map) {
> + get_uwc_mmio_bar(window, _start, );
> + unmap_region(uwc_map, busaddr_start, len);
> + }

arch/powerpc/platforms/powernv/vas-window.c: In function 
'unmap_winctx_mmio_bars':
arch/powerpc/platforms/powernv/vas-window.c:137:2: error: 'uwc_map' may be used 
uninitialized in this function [-Werror=maybe-uninitialized]
  iounmap(addr);
  ^
arch/powerpc/platforms/powernv/vas-window.c:168:8: note: 'uwc_map' was declared 
here
  void *uwc_map;
^
arch/powerpc/platforms/powernv/vas-window.c:137:2: error: 'hvwc_map' may be 
used uninitialized in this function [-Werror=maybe-uninitialized]
  iounmap(addr);
  ^
arch/powerpc/platforms/powernv/vas-window.c:169:8: note: 'hvwc_map' was 
declared here
  void *hvwc_map;
^
cc1: all warnings being treated as errors


cheers


[PATCH v2 11/18] powerpc/vas: Export HVWC to debugfs

2017-10-06 Thread Sukadev Bhattiprolu
Export the VAS Window context information to debugfs.

We need to hold a mutex when closing the window to prevent a race
with the debugfs read(). Rather than introduce a per-instance mutex,
we use the global vas_mutex for now, since it is not heavily contended.

The window->cop field is only relevant to a receive window so we were
not setting it for a send window (which is is paired to a receive window
anyway). But to simplify reporting in debugfs, set the 'cop' field for the
send window also.

Signed-off-by: Sukadev Bhattiprolu 
---
 arch/powerpc/platforms/powernv/Makefile |   3 +-
 arch/powerpc/platforms/powernv/vas-debug.c  | 209 
 arch/powerpc/platforms/powernv/vas-window.c |  34 -
 arch/powerpc/platforms/powernv/vas.c|   6 +-
 arch/powerpc/platforms/powernv/vas.h|  14 ++
 5 files changed, 259 insertions(+), 7 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/vas-debug.c

diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index 37d60f7..17921c4 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -14,4 +14,5 @@ obj-$(CONFIG_TRACEPOINTS) += opal-tracepoints.o
 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
+obj-$(CONFIG_PPC_VAS)  += vas.o vas-window.o vas-debug.o
+obj-$(CONFIG_PPC_FTW)  += nx-ftw.o
diff --git a/arch/powerpc/platforms/powernv/vas-debug.c 
b/arch/powerpc/platforms/powernv/vas-debug.c
new file mode 100644
index 000..ca22f1e
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/vas-debug.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2016-17 IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) "vas: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include "vas.h"
+
+static struct dentry *vas_debugfs;
+
+static char *cop_to_str(int cop)
+{
+   switch (cop) {
+   case VAS_COP_TYPE_FAULT:return "Fault";
+   case VAS_COP_TYPE_842:  return "NX-842 Normal Priority";
+   case VAS_COP_TYPE_842_HIPRI:return "NX-842 High Priority";
+   case VAS_COP_TYPE_GZIP: return "NX-GZIP Normal Priority";
+   case VAS_COP_TYPE_GZIP_HIPRI:   return "NX-GZIP High Priority";
+   case VAS_COP_TYPE_FTW:  return "Fast Thread-wakeup";
+   default:return "Unknown";
+   }
+}
+
+static int info_dbg_show(struct seq_file *s, void *private)
+{
+   struct vas_window *window = s->private;
+
+   mutex_lock(_mutex);
+
+   /* ensure window is not unmapped */
+   if (!window->hvwc_map)
+   goto unlock;
+
+   seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop),
+   window->tx_win ? "Send" : "Receive");
+   seq_printf(s, "Pid : %d\n", window->pid);
+
+unlock:
+   mutex_unlock(_mutex);
+   return 0;
+}
+
+static int info_dbg_open(struct inode *inode, struct file *file)
+{
+   return single_open(file, info_dbg_show, inode->i_private);
+}
+
+static const struct file_operations info_fops = {
+   .open   = info_dbg_open,
+   .read   = seq_read,
+   .llseek = seq_lseek,
+   .release= single_release,
+};
+
+static inline void print_reg(struct seq_file *s, struct vas_window *win,
+   char *name, u32 reg)
+{
+   seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name);
+}
+
+static int hvwc_dbg_show(struct seq_file *s, void *private)
+{
+   struct vas_window *window = s->private;
+
+   mutex_lock(_mutex);
+
+   /* ensure window is not unmapped */
+   if (!window->hvwc_map)
+   goto unlock;
+
+   print_reg(s, window, VREG(LPID));
+   print_reg(s, window, VREG(PID));
+   print_reg(s, window, VREG(XLATE_MSR));
+   print_reg(s, window, VREG(XLATE_LPCR));
+   print_reg(s, window, VREG(XLATE_CTL));
+   print_reg(s, window, VREG(AMR));
+   print_reg(s, window, VREG(SEIDR));
+   print_reg(s, window, VREG(FAULT_TX_WIN));
+   print_reg(s, window, VREG(OSU_INTR_SRC_RA));
+   print_reg(s, window, VREG(HV_INTR_SRC_RA));
+   print_reg(s, window, VREG(PSWID));
+   print_reg(s, window, VREG(LFIFO_BAR));
+   print_reg(s, window, VREG(LDATA_STAMP_CTL));
+   print_reg(s, window, VREG(LDMA_CACHE_CTL));
+   print_reg(s, window, VREG(LRFIFO_PUSH));
+   print_reg(s, window, VREG(CURR_MSG_COUNT));
+   print_reg(s, window, VREG(LNOTIFY_AFTER_COUNT));
+   print_reg(s, window, VREG(LRX_WCRED));
+   print_reg(s, window, VREG(LRX_WCRED_ADDER));
+