summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Bazanski <q3k@q3k.org>2021-01-21 17:19:48 +0100
committerSerge Bazanski <q3k@q3k.org>2021-01-21 17:19:48 +0100
commit18ecccc62e367bf919e18a03bb67cf0eced97d0a (patch)
tree663684b31c1ed87d7243439db2376dcd83cfc565
downloadnix-phi-master.tar.gz
nix-phi-master.tar.bz2
nix-phi-master.tar.xz
nix-phi-master.zip
-rw-r--r--default.nix106
-rw-r--r--mpss-daemon.patch323
-rw-r--r--mpss-modules-4.4.patch39
3 files changed, 468 insertions, 0 deletions
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..3c2c117
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,106 @@
+with builtins;
+let
+ nixpkgs = import <nixpkgs> {};
+ version = "3.8.6";
+ srcs = {
+ mpss-src = fetchTarball {
+ url = "http://registrationcenter-download.intel.com/akdlm/irc_nas/15904/mpss-src-${version}.tar";
+ sha256 = "017g67yc9zqviilryxvq31vzj9hp0lxxrlir8j9vs9l83sw8dfx5";
+ };
+ };
+ kernel = nixpkgs.linuxPackages_4_4.kernel;
+
+in with nixpkgs;
+let
+ modules = stdenv.mkDerivation rec {
+ name = "mpss-modules";
+ inherit version;
+
+ src = "${srcs.mpss-src}/src/mpss-modules-${version}.tar.bz2";
+ patches = [
+ ./mpss-modules-4.4.patch
+ ];
+
+ hardeningDisable = [ "pic" "format" ];
+ nativeBuildInputs = kernel.moduleBuildDependencies;
+ builtInputs = [ kmod ];
+ enableParallelBuilding = true;
+
+ makeFlags = [
+ "KERNELRELEASE=${kernel.modDirVersion}"
+ "KERNEL_SRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+ "DESTDIR=$(out)"
+ "MIC_CARD_ARCH=k1om"
+ ];
+
+ outputs = [ "out" "dev" ];
+
+ installPhase = ''
+ install -m644 -b -D mic.ko $out/lib/modules/${kernel.modDirVersion}/extra/mic.ko
+ install -d $dev/include/mic
+ install -m644 include/scif_ioctl.h $dev/include
+ install -m644 include/mic/io_interface.h $dev/include/mic
+ install -m644 include/mic/mic_pm.h $dev/include/mic
+ install -m644 ras/micras_api.h $dev/include/mic
+ install -m644 ras/micmca_api.h $dev/include/mic
+ '';
+ };
+ metadata = stdenv.mkDerivation rec {
+ name = "mpss-metadata";
+ inherit version;
+
+ src = "${srcs.mpss-src}/src/mpss-metadata-${version}.tar.bz2";
+
+ installPhase = ''
+ mkdir -p $out
+ install -m644 -b -D mpss-metadata.c $out/include/mpss-metadata.c
+ install -m644 -b -D mpss-metadata.mk $out/include/mpss-metadata.mk
+ install -m644 -b -D mpss-metadata.props $out/include/mpss-metadata.props
+ '';
+ };
+ gen-symver-map = stdenv.mkDerivation rec {
+ name = "gen-symver-map";
+ inherit version;
+
+ src = "${srcs.mpss-src}/src/gen-symver-map-${version}.tar.bz2";
+ buildInputs = [
+ pkgs.python27
+ ];
+ installPhase = ''
+ mkdir -p $out
+ install -m755 -b -D gen-symver-map $out/bin/gen-symver-map
+ '';
+ };
+ libscif = stdenv.mkDerivation rec {
+ name = "libscif";
+ inherit version;
+
+ nativeBuildInputs = [ gen-symver-map asciidoc-full ];
+ buildInputs = [ modules.dev ];
+ enableParallelBuilding = true;
+ src = "${srcs.mpss-src}/src/libscif-${version}.tar.bz2";
+ makeFlags = [
+ "-I${metadata}/include"
+ "DESTDIR=$(out)"
+ "prefix="
+ ];
+ };
+ daemon = stdenv.mkDerivation rec {
+ name = "mpss-daemon";
+ inherit version;
+
+ patches = [ ./mpss-daemon.patch ];
+ buildInputs = [ libscif ];
+ enableParallelBuilding = true;
+ src = "${srcs.mpss-src}/src/mpss-daemon-${version}.tar.bz2";
+ makeFlags = [
+ "DESTDIR=$(out)"
+ "prefix="
+ ];
+ preBuild = ''
+ makeFlagsArray+=(INSTALL_s="install -m 755")
+ '';
+ };
+in {
+ inherit modules daemon libscif metadata gen-symver-map;
+}
diff --git a/mpss-daemon.patch b/mpss-daemon.patch
new file mode 100644
index 0000000..09bfbfe
--- /dev/null
+++ b/mpss-daemon.patch
@@ -0,0 +1,323 @@
+diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/genfs.c mpss-daemon-3.8.6/libmpssconfig/genfs.c
+--- mpss-daemon-3.8.6.orig/libmpssconfig/genfs.c 2021-01-21 01:46:48.337522089 +0100
++++ mpss-daemon-3.8.6/libmpssconfig/genfs.c 2021-01-21 04:05:30.895228099 +0100
+@@ -481,6 +481,8 @@
+ struct dirent *file;
+ DIR *dp;
+
++ printf("handle_common %s\n", dir);
++
+ switch (type) {
+ case SRCTYPE_DIR:
+ mpssut_filename(menv, NULL, comname, PATH_MAX, "%s", dir);
+@@ -1682,10 +1684,10 @@
+
+ pid = fork();
+ if (pid == 0) {
+- ifargv[0] = "/bin/gzip";
++ ifargv[0] = "/run/current-system/sw/bin/gzip";
+ ifargv[1] = name;
+ ifargv[2] = NULL;
+- execve("/bin/gzip", ifargv, NULL);
++ execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
+ }
+
+ waitpid(pid, &status, 0);
+@@ -1699,11 +1701,11 @@
+
+ pid = fork();
+ if (pid == 0) {
+- ifargv[0] = "/bin/gzip";
++ ifargv[0] = "/run/current-system/sw/bin/gzip";
+ ifargv[1] = "-d";
+ ifargv[2] = name;
+ ifargv[3] = NULL;
+- execve("/bin/gzip", ifargv, NULL);
++ execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
+ }
+
+ waitpid(pid, NULL, 0);
+@@ -1724,7 +1726,7 @@
+
+ fclose(stdout);
+ fclose(stderr);
+- ifargv[0] = "/bin/cpio";
++ ifargv[0] = "/run/current-system/sw/bin/cpio";
+ ifargv[1] = "-i";
+ ifargv[2] = "-F";
+ ifargv[3] = cfile;
+@@ -1734,7 +1736,7 @@
+ } else {
+ ifargv[4] = NULL;
+ }
+- execve("/bin/cpio", ifargv, NULL);
++ execve("/run/current-system/sw/bin/cpio", ifargv, NULL);
+ }
+
+ if (waitpid(pid, &status, 0) < 0)
+diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/micenv.c mpss-daemon-3.8.6/libmpssconfig/micenv.c
+--- mpss-daemon-3.8.6.orig/libmpssconfig/micenv.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/libmpssconfig/micenv.c 2021-01-21 02:27:02.788081574 +0100
+@@ -106,6 +106,8 @@
+ menv->dist = DISTRIB_SUSE;
+ else if (!strcasecmp(dist, "ubuntu"))
+ menv->dist = DISTRIB_UBUNTU;
++ else if (!strcasecmp(dist, "nixos"))
++ menv->dist = DISTRIB_NIXOS;
+ else
+ return (SETENV_FUNC_DIST << 16) | SETENV_CMDLINE_DIST;
+ } else if ((dist = getenv("MPSS_DIST")) != NULL) {
+@@ -117,6 +119,8 @@
+ menv->dist = DISTRIB_SUSE;
+ else if (!strcasecmp(dist, "ubuntu"))
+ menv->dist = DISTRIB_UBUNTU;
++ else if (!strcasecmp(dist, "nixos"))
++ menv->dist = DISTRIB_NIXOS;
+ else
+ return (SETENV_FUNC_DIST << 16) | SETENV_ENV_DIST;
+ } else {
+@@ -126,12 +130,15 @@
+ menv->dist = DISTRIB_SUSE;
+ else if ((stat(UBUNTU_NETWORK_DIR, &sbuf) == 0) && S_ISDIR(sbuf.st_mode))
+ menv->dist = DISTRIB_UBUNTU;
++ else if ((stat(NIXOS_RUN_DIR, &sbuf) == 0) && S_ISDIR(sbuf.st_mode))
++ menv->dist = DISTRIB_NIXOS;
+ else
+ return (SETENV_FUNC_DIST << 16) | SETENV_PROBE_DIST;
+ }
+
+ switch(menv->dist) {
+ case DISTRIB_REDHAT:
++ case DISTRIB_NIXOS:
+ case DISTRIB_SUSE:
+ menv->lockfile = LSB_LOCK_FILENAME;
+ break;
+diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/mpssconfig.h mpss-daemon-3.8.6/libmpssconfig/mpssconfig.h
+--- mpss-daemon-3.8.6.orig/libmpssconfig/mpssconfig.h 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/libmpssconfig/mpssconfig.h 2021-01-21 02:10:37.013513734 +0100
+@@ -218,6 +218,7 @@
+ #define REDHAT_NETWORK_DIR "/etc/sysconfig/network-scripts"
+ #define SUSE_NETWORK_DIR "/etc/sysconfig/network"
+ #define UBUNTU_NETWORK_DIR "/etc/network"
++#define NIXOS_RUN_DIR "/var/run/nixos"
+
+ /**
+ * Mic family
+@@ -239,6 +240,7 @@
+ #define DISTRIB_REDHAT 1
+ #define DISTRIB_SUSE 2
+ #define DISTRIB_UBUNTU 3
++#define DISTRIB_NIXOS 4
+ char *home;
+ char *confdir;
+ char *destdir;
+diff -ur mpss-daemon-3.8.6.orig/libmpssconfig/verify_bzimage.c mpss-daemon-3.8.6/libmpssconfig/verify_bzimage.c
+--- mpss-daemon-3.8.6.orig/libmpssconfig/verify_bzimage.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/libmpssconfig/verify_bzimage.c 2021-01-21 03:00:35.816162608 +0100
+@@ -173,17 +173,18 @@
+ do_gunzip(char *name)
+ {
+ pid_t pid;
+- char *ifargv[4];
++ char *ifargv[5];
+
+ pid = fork();
+ if (pid == 0) {
+ fclose(stdout);
+ fclose(stderr);
+- ifargv[0] = "/bin/gzip";
+- ifargv[1] = "-d";
+- ifargv[2] = name;
+- ifargv[3] = NULL;
+- execve("/bin/gzip", ifargv, NULL);
++ ifargv[0] = "/usr/bin/env";
++ ifargv[1] = "gzip";
++ ifargv[2] = "-d";
++ ifargv[3] = name;
++ ifargv[4] = NULL;
++ execve("/usr/bin/env", ifargv, NULL);
+ }
+
+ waitpid(pid, NULL, 0);
+diff -ur mpss-daemon-3.8.6.orig/micctrl/init.c mpss-daemon-3.8.6/micctrl/init.c
+--- mpss-daemon-3.8.6.orig/micctrl/init.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/micctrl/init.c 2021-01-21 01:52:24.195846483 +0100
+@@ -1016,7 +1016,7 @@
+ }
+
+ fprintf(fp, defconf, mpssenv.vardir, DEF_SHUTDOWN_TIMEOUT, DEF_CRASHDUMP_DIR, DEF_CRASHDUMP_LIMITGB);
+- fprintf(fp, kncextracmd);
++ fprintf(fp, "%s", kncextracmd);
+ fclose(fp);
+ display(PFS, "%s: Created %s\n", mic->name, filename);
+ } else {
+diff -ur mpss-daemon-3.8.6.orig/micctrl/network.c mpss-daemon-3.8.6/micctrl/network.c
+--- mpss-daemon-3.8.6.orig/micctrl/network.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/micctrl/network.c 2021-01-21 02:38:42.021016226 +0100
+@@ -101,6 +101,13 @@
+ void ubuntu_unattach_hostbridge(char *name, char *bridge);
+ void ubuntu_remove_bridges(void);
+
++void nixos_net_remove(char *name, char *bridge, int modhost);
++void nixos_br_remove(struct mbridge *br);
++void nixos_attach_hostbridge(char *name, char *bridge, char *mac, char *mtu, int saveresolv);
++void nixos_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac);
++void nixos_unattach_hostbridge(char *name, char *bridge);
++void nixos_remove_bridges(void);
++
+ struct netinfo {
+ char *netdir;
+ char *defnetdir;
+@@ -141,7 +148,15 @@
+ ubuntu_br_remove,
+ ubuntu_attach_hostbridge,
+ ubuntu_host_addif,
+- ubuntu_remove_bridges}
++ ubuntu_remove_bridges},
++ { "/tmp/notreally",
++ "/tmp/notreally",
++ "/tmp/yeahstillno",
++ nixos_net_remove,
++ nixos_br_remove,
++ nixos_attach_hostbridge,
++ nixos_host_addif,
++ nixos_remove_bridges}
+ };
+
+ #define MIC_DEFAULT_BIG_MTU "64512";
+@@ -995,7 +1010,7 @@
+ (mic->config.rootdev.type == ROOT_TYPE_PFS)) {
+ mpssut_filename(&mpssenv, NULL, oname, PATH_MAX, "%s/etc/ssh/%s",
+ strchr(mic->config.rootdev.target, ':') + 1, name);
+- if ((fd = open(oname, O_WRONLY|O_CREAT) & 0777) < 0) {
++ if (fd = open(oname, O_WRONLY|O_CREAT, 0755) < 0) {
+ display(PERROR, "%s: Could not open %s\n", mic->name, oname);
+ free(buffer);
+ return 0;
+@@ -2571,6 +2586,37 @@
+ }
+
+ void
++nixos_net_remove(char *name, char *bridge, int modhost)
++{
++ printf("STUB: nixos_net_remove(%s, %s, %d)\n", name, bridge, modhost);
++}
++
++void
++nixos_br_remove(struct mbridge *br)
++{
++ printf("STUB: nixos_br_remove(%p)\n", br);
++}
++
++void
++nixos_attach_hostbridge(char *name, char *bridge, char *mac, char *mtu, int saveresolv)
++{
++ printf("STUB: nixos_attach_hostbridge(%s, %s, %s, %s, %d)\n", name, bridge, mac, mtu, saveresolv);
++}
++
++void
++nixos_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac)
++{
++ printf("STUB: nixos_host_addif(%s, %s, %s, %s, _)\n", name, ip, netbits, mtu, mac);
++}
++
++void
++nixos_remove_bridges(void)
++{
++ printf("STUB: nixos_remove_bridges()\n");
++ // TODO
++}
++
++void
+ common_host_addif(char *name, char *ip, char *netbits, char *mtu, char *mac)
+ {
+ char filename[PATH_MAX];
+diff -ur mpss-daemon-3.8.6.orig/micctrl/user.c mpss-daemon-3.8.6/micctrl/user.c
+--- mpss-daemon-3.8.6.orig/micctrl/user.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/micctrl/user.c 2021-01-21 03:36:40.330342110 +0100
+@@ -2344,14 +2344,18 @@
+
+ if ((hpwfp = fopen("/etc/passwd", "r")) == NULL)
+ return;
++ printf("opened /etc/passwd\n");
+
+ while (fgets(line, PWBUF_SIZE, hpwfp)) {
+ user = line;
++ printf("line: %s\n", user);
+ if (parse_pwfile(user, &pw, &uid, &gid, &name, &home, &app))
+ continue;
++ printf("parsed pwfile\n");
+
+ if ((uid < get_min_uid()) || (uid == 65534))
+ continue;
++ printf("uid okay\n");
+
+ while (ulist) {
+ if (!strcmp(ulist->user, user)) {
+@@ -2858,7 +2862,7 @@
+ if (pid == 0) {
+ fclose(stdout);
+ fclose(stderr);
+- ifargv[0] = "/usr/bin/ssh-keygen";
++ ifargv[0] = "/run/current-system/sw/bin/ssh-keygen";
+ ifargv[1] = "-q";
+ ifargv[2] = "-t";
+ ifargv[3] = type;
+@@ -2869,7 +2873,7 @@
+ ifargv[8] = "-N";
+ ifargv[9] = "";
+ ifargv[10] = NULL;
+- execve("/usr/bin/ssh-keygen", ifargv, NULL);
++ execve("/run/current-system/sw/bin/ssh-keygen", ifargv, NULL);
+ exit(errno);
+ }
+
+@@ -2885,9 +2889,9 @@
+ char *name;
+ char *type;
+ int optional;
+-} hkeys[] = {{"ssh_host_key", "rsa1", FALSE},
++} hkeys[] = {/*{"ssh_host_key", "rsa1", FALSE},*/
+ {"ssh_host_rsa_key", "rsa", FALSE},
+- {"ssh_host_dsa_key", "dsa", FALSE},
++ /*{"ssh_host_dsa_key", "dsa", FALSE},*/
+ {"ssh_host_ecdsa_key", "ecdsa", TRUE},
+ {NULL, NULL}};
+
+diff -ur mpss-daemon-3.8.6.orig/micctrl/utilfuncs.c mpss-daemon-3.8.6/micctrl/utilfuncs.c
+--- mpss-daemon-3.8.6.orig/micctrl/utilfuncs.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/micctrl/utilfuncs.c 2021-01-21 01:56:35.453755052 +0100
+@@ -238,7 +238,7 @@
+ mpssut_filename(&mpssenv, NULL, permfile, PATH_MAX, "/permfile");
+ tmpname = mpssut_tempnam(permfile);
+
+- if ((fd = open(tmpname, O_RDWR | O_CREAT)) < 0) {
++ if ((fd = open(tmpname, O_RDWR | O_CREAT, 0644)) < 0) {
+ free(tmpname);
+ display(PERROR, "Failed permissions test - cannot determine if %s is secure\n", mpssenv.destdir);
+ exit(errno);
+diff -ur mpss-daemon-3.8.6.orig/mpssd/mpssd.c mpss-daemon-3.8.6/mpssd/mpssd.c
+--- mpss-daemon-3.8.6.orig/mpssd/mpssd.c 2021-01-21 01:46:48.338522081 +0100
++++ mpss-daemon-3.8.6/mpssd/mpssd.c 2021-01-21 03:52:50.930892803 +0100
+@@ -729,10 +729,10 @@
+
+ pid = fork();
+ if (pid == 0) {
+- ifargv[0] = "/bin/gzip";
++ ifargv[0] = "/run/current-system/sw/bin/gzip";
+ ifargv[1] = name;
+ ifargv[2] = NULL;
+- execve("/bin/gzip", ifargv, NULL);
++ execve("/run/current-system/sw/bin/gzip", ifargv, NULL);
+ }
+
+ return pid;
+@@ -1418,7 +1418,7 @@
+ len = read(fd, cookie, MPSS_COOKIE_SIZE);
+ close(fd);
+
+- if ((fd = open(cookiename, O_WRONLY|O_CREAT)) < 0) {
++ if ((fd = open(cookiename, O_WRONLY|O_CREAT, 0755)) < 0) {
+ mpsslog(PERROR, "Failed to open %s: %s\n", cookiename, strerror(errno));
+ goto cookie_done;
+ }
diff --git a/mpss-modules-4.4.patch b/mpss-modules-4.4.patch
new file mode 100644
index 0000000..79c02e3
--- /dev/null
+++ b/mpss-modules-4.4.patch
@@ -0,0 +1,39 @@
+diff -ur mpss-modules-3.8.6/host/tools_support.c mpss-modules-3.8.6.patched.4.4/host/tools_support.c
+--- mpss-modules-3.8.6/host/tools_support.c 2019-07-01 22:45:06.000000000 +0200
++++ mpss-modules-3.8.6.patched.4.4/host/tools_support.c 2021-01-20 23:36:28.705203711 +0100
+@@ -89,8 +89,13 @@
+
+ // pin the user pages; use semaphores on linux for doing the same
+ down_read(&current->mm->mmap_sem);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,168)
++ *nf_pages = (int32_t)get_user_pages(current, current->mm, (uint64_t)data,
++ nr_pages, FOLL_WRITE|FOLL_FORCE, pages, NULL);
++#else
+ *nf_pages = (int32_t)get_user_pages(current, current->mm, (uint64_t)data,
+ nr_pages, PROT_WRITE, 1, pages, NULL);
++#endif
+ up_read(&current->mm->mmap_sem);
+
+ // compare if the no of final pages is equal to no of requested pages
+diff -ur mpss-modules-3.8.6/micscif/micscif_api.c mpss-modules-3.8.6.patched.4.4/micscif/micscif_api.c
+--- mpss-modules-3.8.6/micscif/micscif_api.c 2019-07-01 22:45:06.000000000 +0200
++++ mpss-modules-3.8.6.patched.4.4/micscif/micscif_api.c 2021-01-20 23:36:28.702203741 +0100
+@@ -1980,14 +1980,17 @@
+ goto error_unmap;
+ }
+ }
+-
+ pinned_pages->nr_pages = get_user_pages(
+ current,
+ mm,
+ (uint64_t)addr,
+ nr_pages,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,168)
++ (prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0,
++#else
+ !!(prot & SCIF_PROT_WRITE),
+ 0,
++#endif
+ pinned_pages->pages,
+ pinned_pages->vma);
+ up_write(&mm->mmap_sem);