Mesa (staging/19.3): radv: add a secure_compile_open_fifo_fds() helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 27 00:43:35 UTC 2019


Module: Mesa
Branch: staging/19.3
Commit: 0b0c500ad12aedf558e368d6ab3a7734821e1c3f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0b0c500ad12aedf558e368d6ab3a7734821e1c3f

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Nov 13 14:51:48 2019 +1100

radv: add a secure_compile_open_fifo_fds() helper

This will be used to create a communication pipe between the user
facing device and a freshly forked (per pipeline compile) slim copy
of that device.

We can't use pipe() here because the fork will not be a direct fork
of the user facing process. Instead we use a previously forked
copy of the process that was forked at device creation in order to
reduce the resources required for the fork and avoid performance
issues.

Fixes: cff53da3748d ("radv: enable secure compile support")
(cherry picked from commit 1663bb1f772dacadaec2d80f8286cfb76c4bb200)

---

 src/amd/vulkan/radv_device.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 2dc64186cc8..06e4a52ff05 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -2098,6 +2098,49 @@ static bool radv_close_all_fds(const int *keep_fds, int keep_fd_count)
 	return true;
 }
 
+static bool secure_compile_open_fifo_fds(struct radv_secure_compile_state *sc,
+					 int *fd_server, int *fd_client,
+					 unsigned process, bool make_fifo)
+{
+	bool result = false;
+	char *fifo_server_path = NULL;
+	char *fifo_client_path = NULL;
+
+	if (asprintf(&fifo_server_path, "/tmp/radv_server_%s_%u", sc->uid, process) == -1)
+		goto open_fifo_exit;
+
+	if (asprintf(&fifo_client_path, "/tmp/radv_client_%s_%u", sc->uid, process) == -1)
+		goto open_fifo_exit;
+
+	if (make_fifo) {
+		int file1 = mkfifo(fifo_server_path, 0666);
+		if(file1 < 0)
+			goto open_fifo_exit;
+
+		int file2 = mkfifo(fifo_client_path, 0666);
+		if(file2 < 0)
+			goto open_fifo_exit;
+	}
+
+	*fd_server = open(fifo_server_path, O_RDWR);
+	if(*fd_server < 1)
+		goto open_fifo_exit;
+
+	*fd_client = open(fifo_client_path, O_RDWR);
+	if(*fd_client < 1) {
+		close(*fd_server);
+		goto open_fifo_exit;
+	}
+
+	result = true;
+
+open_fifo_exit:
+	free(fifo_server_path);
+	free(fifo_client_path);
+
+	return result;
+}
+
 static void run_secure_compile_device(struct radv_device *device, unsigned process,
 				      int fd_secure_input, int fd_secure_output)
 {




More information about the mesa-commit mailing list