summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@fingolfin.org>2020-07-09 19:24:55 -0700
committerRobert Mustacchi <rm@fingolfin.org>2020-07-21 08:13:32 -0700
commit6edddafdeaa7f4e95b88c106b4825057c934d52c (patch)
tree24f1a271665a5df5bf171b2f07f718ecd7fff304
parente98a9323520af2d37dd05c47dd174826c71b0c3a (diff)
downloadillumos-joyent-6edddafdeaa7f4e95b88c106b4825057c934d52c.tar.gz
12946 want ability to dump smbios data from crash dump
Reviewed by: Rich Lowe <richlowe@richlowe.net> Reviewed by: Yuri Pankov <yuripv@yuripv.dev> Reviewed by: Toomas Some <tsoome@me.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/cmd/mdb/intel/modules/Makefile1
-rw-r--r--usr/src/cmd/mdb/intel/modules/smbios/Makefile20
-rw-r--r--usr/src/cmd/mdb/intel/modules/smbios/amd64/Makefile28
-rw-r--r--usr/src/cmd/mdb/intel/modules/smbios/smbios.c136
-rw-r--r--usr/src/pkg/manifests/developer-debug-mdb.mf1
5 files changed, 186 insertions, 0 deletions
diff --git a/usr/src/cmd/mdb/intel/modules/Makefile b/usr/src/cmd/mdb/intel/modules/Makefile
index 96ccc108d6..0337032b76 100644
--- a/usr/src/cmd/mdb/intel/modules/Makefile
+++ b/usr/src/cmd/mdb/intel/modules/Makefile
@@ -27,6 +27,7 @@ SUBDIRS = mdb_kb \
generic_cpu \
amd_opteron \
sata \
+ smbios \
xhci
include ../../Makefile.subdirs
diff --git a/usr/src/cmd/mdb/intel/modules/smbios/Makefile b/usr/src/cmd/mdb/intel/modules/smbios/Makefile
new file mode 100644
index 0000000000..542ef6cffe
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/modules/smbios/Makefile
@@ -0,0 +1,20 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2020 Oxide Computer Company
+#
+
+include $(SRC)/Makefile.master
+
+$(BUILD64)SUBDIRS += $(MACH64)
+
+include ../../../Makefile.subdirs
diff --git a/usr/src/cmd/mdb/intel/modules/smbios/amd64/Makefile b/usr/src/cmd/mdb/intel/modules/smbios/amd64/Makefile
new file mode 100644
index 0000000000..94658c0d38
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/modules/smbios/amd64/Makefile
@@ -0,0 +1,28 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2020 Oxide Computer Company
+#
+
+
+MODULE = smbios.so
+MDBTGT = kvm
+
+MODSRCS = smbios.c
+
+include ../../../../../Makefile.cmd
+include ../../../../../Makefile.cmd.64
+include ../../../Makefile.amd64
+include ../../../../Makefile.module
+
+MODULE_BUILD_TYPE = mdb
+LDLIBS += -lsmbios
diff --git a/usr/src/cmd/mdb/intel/modules/smbios/smbios.c b/usr/src/cmd/mdb/intel/modules/smbios/smbios.c
new file mode 100644
index 0000000000..429a5fba0e
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/modules/smbios/smbios.c
@@ -0,0 +1,136 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2020 Oxide Computer Company
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/mdb_modapi.h>
+#include <sys/smbios_impl.h>
+#include <unistd.h>
+
+/*
+ * Unfortunately, we're in a bit of a bind. Because of the situation we're in,
+ * we cannot use string.h directly as it declares ffs() which is also declared
+ * in sys/systm.h. sys/systm.h is being pulled in because mdb is building with
+ * _KERNEL. Therefore we have to manually declare an extern delaration for
+ * strerror().
+ */
+extern const char *strerror(int);
+
+/*
+ * Take an existing smbios_hdl_t from a dump and slurp out its memory so we can
+ * open up a new smbios handle to perform operations on.
+ */
+static int
+smbios_mdb_write(const char *path, uintptr_t addr)
+{
+ smbios_hdl_t shp, *hdl;
+ void *buf;
+ int err, fd = -1;
+ int ret = DCMD_ERR;
+
+ if (mdb_vread(&shp, sizeof (shp), addr) != sizeof (shp)) {
+ mdb_warn("failed to read smbios_hdl_t at %p", addr);
+ return (DCMD_ERR);
+ }
+
+ buf = mdb_alloc(shp.sh_buflen, UM_NOSLEEP | UM_GC);
+ if (buf == NULL) {
+ mdb_warn("failed to allocate %zu bytes for the smbios "
+ "data buffer", shp.sh_buflen);
+ return (DCMD_ERR);
+ }
+
+ if (mdb_vread(buf, shp.sh_buflen, (uintptr_t)shp.sh_buf) !=
+ shp.sh_buflen) {
+ mdb_warn("failed to copy smbios data at %p", shp.sh_buf);
+ return (DCMD_ERR);
+ }
+
+ hdl = smbios_bufopen(&shp.sh_ent, buf, shp.sh_buflen, SMB_VERSION, 0,
+ &err);
+ if (hdl == NULL) {
+ mdb_warn("failed to load smbios data: %s\n",
+ smbios_errmsg(err));
+ return (DCMD_ERR);
+ }
+
+ if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
+ mdb_warn("failed to open output file %s: %s\n", path,
+ strerror(errno));
+ goto out;
+ }
+
+ if (smbios_write(hdl, fd) != 0) {
+ mdb_warn("failed to write smbios data to %s: %s\n", path,
+ smbios_errmsg(smbios_errno(hdl)));
+ ret = DCMD_ERR;
+ } else {
+ ret = DCMD_OK;
+ }
+out:
+ if (fd != -1) {
+ (void) close(fd);
+ }
+ smbios_close(hdl);
+ return (ret);
+}
+
+static int
+smbios_mdb_smbios(uintptr_t addr, uint_t flags, int argc,
+ const mdb_arg_t *argv)
+{
+ const char *wpath = NULL;
+
+ if (!(flags & DCMD_ADDRSPEC)) {
+ mdb_warn("missing required smbios_hdl_t\n");
+ return (DCMD_USAGE);
+ }
+
+ if (mdb_getopts(argc, argv, 'w', MDB_OPT_STR, &wpath, NULL) != argc) {
+ return (DCMD_USAGE);
+ }
+
+ if (wpath != NULL) {
+ return (smbios_mdb_write(wpath, addr));
+ }
+
+ return (DCMD_USAGE);
+}
+
+static void
+smbios_mdb_help(void)
+{
+ mdb_printf("Given a pointer to an smbios_hdl_t take the following "
+ "actions:\n\n"
+ "\t-w path\t\tWrite SMBIOS data out to path\n");
+}
+
+static const mdb_dcmd_t smbios_dcmds[] = {
+ { "smbios", ":[-w path]", "Manipulate an smbios handle",
+ smbios_mdb_smbios, smbios_mdb_help },
+ { NULL }
+};
+
+static const mdb_modinfo_t smbios_modinfo = {
+ MDB_API_VERSION, smbios_dcmds, NULL
+};
+
+const mdb_modinfo_t *
+_mdb_init(void)
+{
+ return (&smbios_modinfo);
+}
diff --git a/usr/src/pkg/manifests/developer-debug-mdb.mf b/usr/src/pkg/manifests/developer-debug-mdb.mf
index df8ea7b2b0..af99982b2c 100644
--- a/usr/src/pkg/manifests/developer-debug-mdb.mf
+++ b/usr/src/pkg/manifests/developer-debug-mdb.mf
@@ -200,6 +200,7 @@ $(i386_ONLY)file path=usr/lib/mdb/kvm/$(ARCH64)/sata.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/scsi_vhci.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/sctp.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/sd.so group=sys mode=0555
+$(i386_ONLY)file path=usr/lib/mdb/kvm/$(ARCH64)/smbios.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/sockfs.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/specfs.so group=sys mode=0555
file path=usr/lib/mdb/kvm/$(ARCH64)/sppp.so group=sys mode=0555