All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size
@ 2017-07-02 23:34 Dongli Zhang
  2017-07-02 23:34 ` [PATCH v2 2/2] tools: utility to dump guest grant table info Dongli Zhang
  2017-07-03 16:26 ` [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Wei Liu
  0 siblings, 2 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-07-02 23:34 UTC (permalink / raw)
  To: xen-devel; +Cc: ian.jackson, wei.liu2

This patch adds new interface for GNTTABOP_query_size in libxc to help
query the current grant table frames and maximum grant table frames for a
specific domain.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
Changed since v1:
  * Change %d to %u in ERROR()

---
 tools/libxc/include/xenctrl.h |  1 +
 tools/libxc/xc_gnttab.c       | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 1629f41..155c69e 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1597,6 +1597,7 @@ int xc_gnttab_op(xc_interface *xch, int cmd,
                  void * op, int op_size, int count);
 /* Logs iff hypercall bounce fails, otherwise doesn't. */
 
+int xc_gnttab_query_size(xc_interface *xch, struct gnttab_query_size *query);
 int xc_gnttab_get_version(xc_interface *xch, int domid); /* Never logs */
 grant_entry_v1_t *xc_gnttab_map_table_v1(xc_interface *xch, int domid, int *gnt_num);
 grant_entry_v2_t *xc_gnttab_map_table_v2(xc_interface *xch, int domid, int *gnt_num);
diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c
index af53fac..9e6f1fb 100644
--- a/tools/libxc/xc_gnttab.c
+++ b/tools/libxc/xc_gnttab.c
@@ -38,6 +38,18 @@ int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
     return ret;
 }
 
+int xc_gnttab_query_size(xc_interface *xch, struct gnttab_query_size *query)
+{
+    int rc;
+
+    rc = xc_gnttab_op(xch, GNTTABOP_query_size, query, sizeof(*query), 1);
+
+    if ( rc || (query->status != GNTST_okay) )
+        ERROR("Could not query dom %u's grant size\n", query->dom);
+
+    return rc;
+}
+
 int xc_gnttab_get_version(xc_interface *xch, int domid)
 {
     struct gnttab_get_version query;
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* [PATCH v2 2/2] tools: utility to dump guest grant table info
  2017-07-02 23:34 [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Dongli Zhang
@ 2017-07-02 23:34 ` Dongli Zhang
  2017-07-03 16:26   ` Wei Liu
  2017-07-04 14:10   ` Wei Liu
  2017-07-03 16:26 ` [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Wei Liu
  1 sibling, 2 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-07-02 23:34 UTC (permalink / raw)
  To: xen-devel; +Cc: ian.jackson, wei.liu2

As both xen-netfront and xen-blkfront support multi-queue, they would
consume a lot of grant table references when there are many paravirtual
devices and vcpus assigned to guest. Guest domU might panic or hang due to
grant allocation failure when nr_grant_frames in guest has reached its max
value.

This utility would help the administrators to diagnose xen issue. There is
only one command gnttab_query_size so far to monitor the guest grant table
frame usage on dom0 side so that it is not required to debug on guest
kernel side for crash/hang analysis anymore.

It is extensible for adding new commands for more diagnostic functions and
the framework of xen-diag.c is from xen-livepatch.c.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
Changed since v1:
  * rewrite xen-gnttab-query.c to xen-diag.c based on livepatch.c framework

---
 tools/misc/Makefile   |   4 ++
 tools/misc/xen-diag.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 tools/misc/xen-diag.c

diff --git a/tools/misc/Makefile b/tools/misc/Makefile
index 8152f7b..c1113b9 100644
--- a/tools/misc/Makefile
+++ b/tools/misc/Makefile
@@ -31,6 +31,7 @@ INSTALL_SBIN                   += xenperf
 INSTALL_SBIN                   += xenpm
 INSTALL_SBIN                   += xenwatchdogd
 INSTALL_SBIN                   += xen-livepatch
+INSTALL_SBIN                   += xen-diag
 INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
@@ -102,6 +103,9 @@ xenwatchdogd: xenwatchdogd.o
 xen-livepatch: xen-livepatch.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xen-diag: xen-diag.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
 xen-lowmemd: xen-lowmemd.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
diff --git a/tools/misc/xen-diag.c b/tools/misc/xen-diag.c
new file mode 100644
index 0000000..1da50e1
--- /dev/null
+++ b/tools/misc/xen-diag.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <xenctrl.h>
+
+#include <xen/errno.h>
+#include <xen-tools/libs.h>
+
+static xc_interface *xch;
+
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+void show_help(void)
+{
+    fprintf(stderr,
+            "xen-diag: xen diagnostic utility\n"
+            "Usage: xen-diag command [args]\n"
+            "Commands:\n"
+            "  help                       display this help\n"
+            "  gnttab_query_size <domid>  dump the current and max grant frames for <domid>\n");
+}
+
+/* wrapper function */
+static int help_func(int argc, char *argv[])
+{
+    show_help();
+    return 0;
+}
+
+static int gnttab_query_size_func(int argc, char *argv[])
+{
+    int domid, rc = 1;
+    struct gnttab_query_size query;
+
+    if ( argc != 1 )
+    {
+        show_help();
+        return rc;
+    }
+
+    domid = strtol(argv[0], NULL, 10);
+    query.dom = domid;
+    rc = xc_gnttab_query_size(xch, &query);
+
+    if ( rc == 0 && (query.status == GNTST_okay) )
+        printf("domid=%d: nr_frames=%d, max_nr_frames=%d\n",
+               query.dom, query.nr_frames, query.max_nr_frames);
+
+    return rc == 0 && (query.status == GNTST_okay) ? 0 : 1;
+}
+
+struct {
+    const char *name;
+    int (*function)(int argc, char *argv[]);
+} main_options[] = {
+    { "help", help_func },
+    { "gnttab_query_size", gnttab_query_size_func},
+};
+
+int main(int argc, char *argv[])
+{
+    int ret, i;
+
+    /*
+     * Set stdout to be unbuffered to avoid having to fflush when
+     * printing without a newline.
+     */
+    setvbuf(stdout, NULL, _IONBF, 0);
+
+    if ( argc <= 1 )
+    {
+        show_help();
+        return 0;
+    }
+
+    for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
+        if ( !strncmp(main_options[i].name, argv[1], strlen(argv[1])) )
+            break;
+
+    if ( i == ARRAY_SIZE(main_options) )
+    {
+        show_help();
+        return 0;
+    }
+    else
+    {
+        xch = xc_interface_open(0, 0, 0);
+        if ( !xch )
+        {
+            fprintf(stderr, "failed to get the handler\n");
+            return 0;
+        }
+
+        ret = main_options[i].function(argc - 2, argv + 2);
+
+        xc_interface_close(xch);
+    }
+
+    /*
+     * Exitcode 0 for success.
+     * Exitcode 1 for an error.
+     * Exitcode 2 if the operation should be retried for any reason (e.g. a
+     * timeout or because another operation was in progress).
+     */
+
+#define EXIT_TIMEOUT (EXIT_FAILURE + 1)
+
+    BUILD_BUG_ON(EXIT_SUCCESS != 0);
+    BUILD_BUG_ON(EXIT_FAILURE != 1);
+    BUILD_BUG_ON(EXIT_TIMEOUT != 2);
+
+    switch ( ret )
+    {
+    case 0:
+        return EXIT_SUCCESS;
+    case EAGAIN:
+    case EBUSY:
+        return EXIT_TIMEOUT;
+    default:
+        return EXIT_FAILURE;
+    }
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size
  2017-07-02 23:34 [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Dongli Zhang
  2017-07-02 23:34 ` [PATCH v2 2/2] tools: utility to dump guest grant table info Dongli Zhang
@ 2017-07-03 16:26 ` Wei Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2017-07-03 16:26 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: ian.jackson, wei.liu2, xen-devel

On Mon, Jul 03, 2017 at 07:34:12AM +0800, Dongli Zhang wrote:
> This patch adds new interface for GNTTABOP_query_size in libxc to help
> query the current grant table frames and maximum grant table frames for a
> specific domain.
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH v2 2/2] tools: utility to dump guest grant table info
  2017-07-02 23:34 ` [PATCH v2 2/2] tools: utility to dump guest grant table info Dongli Zhang
@ 2017-07-03 16:26   ` Wei Liu
  2017-07-04 14:10   ` Wei Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Liu @ 2017-07-03 16:26 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: ian.jackson, wei.liu2, xen-devel

On Mon, Jul 03, 2017 at 07:34:13AM +0800, Dongli Zhang wrote:
> As both xen-netfront and xen-blkfront support multi-queue, they would
> consume a lot of grant table references when there are many paravirtual
> devices and vcpus assigned to guest. Guest domU might panic or hang due to
> grant allocation failure when nr_grant_frames in guest has reached its max
> value.
> 
> This utility would help the administrators to diagnose xen issue. There is
> only one command gnttab_query_size so far to monitor the guest grant table
> frame usage on dom0 side so that it is not required to debug on guest
> kernel side for crash/hang analysis anymore.
> 
> It is extensible for adding new commands for more diagnostic functions and
> the framework of xen-diag.c is from xen-livepatch.c.
> 
> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH v2 2/2] tools: utility to dump guest grant table info
  2017-07-02 23:34 ` [PATCH v2 2/2] tools: utility to dump guest grant table info Dongli Zhang
  2017-07-03 16:26   ` Wei Liu
@ 2017-07-04 14:10   ` Wei Liu
  2017-07-04 14:27     ` Dongli Zhang
  1 sibling, 1 reply; 6+ messages in thread
From: Wei Liu @ 2017-07-04 14:10 UTC (permalink / raw)
  To: Dongli Zhang; +Cc: ian.jackson, wei.liu2, xen-devel

I pushed your two patches and discovered you also need to patch
.gitignore. Could you please send a patch for that? thanks

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH v2 2/2] tools: utility to dump guest grant table info
  2017-07-04 14:10   ` Wei Liu
@ 2017-07-04 14:27     ` Dongli Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Dongli Zhang @ 2017-07-04 14:27 UTC (permalink / raw)
  To: xen-devel

Hi Wei,

I will send the patch based on staging.

Dongli Zhang

On 07/04/2017 10:10 PM, Wei Liu wrote:
> I pushed your two patches and discovered you also need to patch
> .gitignore. Could you please send a patch for that? thanks
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> https://lists.xen.org/xen-devel
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2017-07-04 14:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-02 23:34 [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Dongli Zhang
2017-07-02 23:34 ` [PATCH v2 2/2] tools: utility to dump guest grant table info Dongli Zhang
2017-07-03 16:26   ` Wei Liu
2017-07-04 14:10   ` Wei Liu
2017-07-04 14:27     ` Dongli Zhang
2017-07-03 16:26 ` [PATCH v2 1/2] tools/libxc: add interface for GNTTABOP_query_size Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.