Blob Blame History Raw
From 3470e3d012a2706463cd77afce0a33f3581c2721 Mon Sep 17 00:00:00 2001
From: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
Date: Thu, 15 Jul 2021 01:34:08 -0400
Subject: [PATCH 006/120] criu/plugin: Implement dummy amdgpu plugin hooks

This is just a placeholder dummy plugin and will be replaced by a proper
plugin that implements support for AMD GPU devices. This just
facilitates the initial pull request and CI build test trigger for early
code review of CRIU specific changes. Future PRs will bring in more
support for amdgpu_plugin to enable CRIU with AMD ROCm.

Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
---
 Makefile                      | 12 ++++++++++--
 Makefile.install              |  8 +++++++-
 plugins/amdgpu/Makefile       | 13 +++++++++++++
 plugins/amdgpu/dummy_plugin.c | 36 +++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 3 deletions(-)
 create mode 100644 plugins/amdgpu/Makefile
 create mode 100644 plugins/amdgpu/dummy_plugin.c

diff --git a/Makefile b/Makefile
index a1e3977f8..e361e8a8f 100644
--- a/Makefile
+++ b/Makefile
@@ -294,15 +294,19 @@ clean mrproper:
 	$(Q) $(MAKE) $(build)=crit $@
 .PHONY: clean mrproper
 
+clean-dummy_amdgpu_plugin:
+	$(Q) $(MAKE) -C plugins/amdgpu clean
+.PHONY: clean dummy_amdgpu_plugin
+
 clean-top:
 	$(Q) $(MAKE) -C Documentation clean
 	$(Q) $(MAKE) $(build)=test/compel clean
 	$(Q) $(RM) .gitid
 .PHONY: clean-top
 
-clean: clean-top
+clean: clean-top clean-dummy_amdgpu_plugin
 
-mrproper-top: clean-top
+mrproper-top: clean-top clean-dummy_amdgpu_plugin
 	$(Q) $(RM) $(CONFIG_HEADER)
 	$(Q) $(RM) $(VERSION_HEADER)
 	$(Q) $(RM) $(COMPEL_VERSION_HEADER)
@@ -330,6 +334,10 @@ test: zdtm
 	$(Q) $(MAKE) -C test
 .PHONY: test
 
+dummy_amdgpu_plugin:
+	$(Q) $(MAKE) -C plugins/amdgpu all
+.PHONY: dummy_amdgpu_plugin
+
 #
 # Generating tar requires tag matched CRIU_VERSION.
 # If not found then simply use GIT's describe with
diff --git a/Makefile.install b/Makefile.install
index 3987bcc6f..52e8c06da 100644
--- a/Makefile.install
+++ b/Makefile.install
@@ -7,6 +7,7 @@ MANDIR		?= $(PREFIX)/share/man
 INCLUDEDIR	?= $(PREFIX)/include
 LIBEXECDIR	?= $(PREFIX)/libexec
 RUNDIR		?= /run
+PLUGINDIR	?= /var/lib/criu
 
 #
 # For recent Debian/Ubuntu with multiarch support.
@@ -26,7 +27,7 @@ endif
 LIBDIR ?= $(PREFIX)/lib
 
 export PREFIX BINDIR SBINDIR MANDIR RUNDIR
-export LIBDIR INCLUDEDIR LIBEXECDIR
+export LIBDIR INCLUDEDIR LIBEXECDIR PLUGINDIR
 
 install-man:
 	$(Q) $(MAKE) -C Documentation install
@@ -40,6 +41,10 @@ install-criu: criu
 	$(Q) $(MAKE) $(build)=criu install
 .PHONY: install-criu
 
+install-dummy_amdgpu_plugin: dummy_amdgpu_plugin
+	$(Q) $(MAKE) -C plugins/amdgpu install
+.PHONY: install-dummy_amdgpu_plugin
+
 install-compel: $(compel-install-targets)
 	$(Q) $(MAKE) $(build)=compel install
 	$(Q) $(MAKE) $(build)=compel/plugins install
@@ -54,4 +59,5 @@ uninstall:
 	$(Q) $(MAKE) $(build)=criu $@
 	$(Q) $(MAKE) $(build)=compel $@
 	$(Q) $(MAKE) $(build)=compel/plugins $@
+	$(Q) $(MAKE) -C plugins/amdgpu $@
 .PHONY: uninstall
diff --git a/plugins/amdgpu/Makefile b/plugins/amdgpu/Makefile
new file mode 100644
index 000000000..45a9ec611
--- /dev/null
+++ b/plugins/amdgpu/Makefile
@@ -0,0 +1,13 @@
+all: dummy_plugin.so
+
+dummy_plugin.so: dummy_plugin.c
+	gcc -g -Werror -D _GNU_SOURCE -Wall -shared -nostartfiles dummy_plugin.c -o dummy_plugin.so -iquote ../../../criu/include -iquote ../../criu/include -fPIC
+
+clean:
+	$(Q) $(RM) dummy_plugin.so
+install:
+	$(Q) mkdir -p $(PLUGINDIR)
+	$(Q) install -m 644 dummy_plugin.so $(PLUGINDIR)
+
+uninstall:
+	$(Q) $(RM) $(PLUGINDIR)/dummy_plugin.so
diff --git a/plugins/amdgpu/dummy_plugin.c b/plugins/amdgpu/dummy_plugin.c
new file mode 100644
index 000000000..872276095
--- /dev/null
+++ b/plugins/amdgpu/dummy_plugin.c
@@ -0,0 +1,36 @@
+#include <sys/stat.h>
+
+#include "criu-log.h"
+#include "criu-plugin.h"
+
+int dummy_plugin_handle_device_vma(int fd, const struct stat *stat)
+{
+	pr_info("dummy_plugin: Inside %s for fd = %d\n", __func__, fd);
+	/* let criu report failure for the unsupported mapping */
+	return -ENOTSUP;
+}
+CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__HANDLE_DEVICE_VMA, dummy_plugin_handle_device_vma)
+
+int dummy_plugin_resume_devices_late(int target_pid)
+{
+	pr_info("dummy_plugin: Inside %s for target pid = %d\n", __func__, target_pid);
+	return -ENOTSUP;
+}
+CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__RESUME_DEVICES_LATE, dummy_plugin_resume_devices_late)
+
+/*
+ * return 0 if no match found
+ * return -1 for error or -ENOTSUP.
+ * return 1 if vmap map must be adjusted.
+ */
+int dummy_plugin_update_vmamap(const char *old_path, char *new_path, const uint64_t addr, const uint64_t old_offset,
+			       uint64_t *new_offset)
+{
+	uint64_t temp = 100;
+
+	*new_offset = temp;
+	pr_info("dummy_plugin: old_pgoff= 0x%lu new_pgoff = 0x%lx old_path = %s new_path = %s addr = 0x%lu\n",
+		old_offset, *new_offset, old_path, new_path, addr);
+	return -ENOTSUP;
+}
+CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__UPDATE_VMA_MAP, dummy_plugin_update_vmamap)
-- 
2.34.1