interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / uvme_kernel.c

85 lines · 3774 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 * Test-only Linux ioctl consumer. NEVER run without explicit CUSE-node authority.
3 * No NVIDIA headers or implementation: measured uvm_ioctl.h ABI in uvms-abi.txt.
4 * Production endpoint is entirely Omega. This checks the remaining kernel hop.
5 */
6#include <errno.h>
7#include <fcntl.h>
8#include <stdint.h>
9#include <stdio.h>
10#include <string.h>
11#include <sys/ioctl.h>
12#include <sys/wait.h>
13#include <unistd.h>
14
15static void u32(unsigned char *p, uint32_t v) { memcpy(p, &v, sizeof v); }
16static void u64(unsigned char *p, uint64_t v) { memcpy(p, &v, sizeof v); }
17static int request(int fd, unsigned long cmd, unsigned char *arg, size_t status, uint32_t want) {
18 uint32_t got;
19 int r = ioctl(fd, cmd, arg);
20 if (r != 0) { perror("ioctl kernel hop"); return 1; }
21 memcpy(&got, arg + status, sizeof got);
22 if (got != want) { fprintf(stderr, "cmd=%lu rmStatus=%u expected=%u\n", cmd, got, want); return 1; }
23 return 0;
24}
25static int client(const char *path) {
26 unsigned char arg[9264];
27 int fd = open(path, O_RDWR | O_CLOEXEC);
28 if (fd < 0) { perror("open explicit CUSE test node"); return 1; }
29 memset(arg, 0, sizeof arg);
30 if (request(fd, 805306369UL, arg, 8, 0)) return 1;
31 memset(arg, 0, sizeof arg);
32 if (request(fd, 805306369UL, arg, 8, 23)) return 1;
33 memset(arg, 0, sizeof arg);
34 for (unsigned int i = 0; i < 16; ++i) arg[i] = (unsigned char)(i + 1);
35 u32(arg + 24, 7); u32(arg + 28, 11);
36 if (request(fd, 37, arg, 36, 0)) return 1;
37 memset(arg, 0, sizeof arg);
38 if (request(fd, 23, arg, 8, 0)) return 1;
39 uint64_t group; memcpy(&group, arg, sizeof group);
40 if (group != 1) { fprintf(stderr, "range-group namespace leaked\n"); return 1; }
41 memset(arg, 0, sizeof arg);
42 for (unsigned int i = 0; i < 16; ++i) arg[i] = (unsigned char)(i + 1);
43 u32(arg + 16, 7); u32(arg + 20, 11); u32(arg + 24, 19);
44 if (request(fd, 25, arg, 28, 0)) return 1;
45 memset(arg, 0, sizeof arg);
46 u64(arg, UINT64_C(4294967296)); u64(arg + 8, 4096);
47 for (unsigned int i = 0; i < 16; ++i) arg[24 + i] = (unsigned char)(i + 1);
48 u64(arg + 9240, 1); u32(arg + 9248, 7); u32(arg + 9252, 11); u32(arg + 9256, 23);
49 /* No production trusted RM resolver yet: must REFUSE, never fabricate a PA. */
50 if (request(fd, 33, arg, 9260, 31)) return 1;
51 memset(arg, 0, sizeof arg); u64(arg, UINT64_C(4294967296)); u64(arg + 8, 4096);
52 if (request(fd, 34, arg, 16, 31)) return 1;
53 memset(arg, 0, sizeof arg);
54 for (unsigned int i = 0; i < 16; ++i) arg[i] = (unsigned char)(i + 1);
55 if (request(fd, 38, arg, 16, 0)) return 1;
56 memset(arg, 0, sizeof arg);
57 if (request(fd, 39, arg, 4, 0)) return 1;
58 errno = 0;
59 if (ioctl(fd, 999UL, arg) != -1 || errno != EINVAL) {
60 fprintf(stderr, "unknown command not refused\n"); return 1;
61 }
62 errno = 0;
63 if (ioctl(fd, 39UL, (void *)0) != -1 || errno != EFAULT) {
64 fprintf(stderr, "null user pointer not refused\n"); return 1;
65 }
66 if (close(fd) != 0) return 1;
67 return 0;
68}
69int main(int argc, char **argv) {
70 if (argc != 2 || strcmp(argv[1], "/dev/omega-uvm-test") != 0) {
71 fprintf(stderr, "explicit authorized /dev/omega-uvm-test path required\n"); return 64;
72 }
73 pid_t children[2];
74 for (unsigned int i = 0; i < 2; ++i) {
75 children[i] = fork();
76 if (children[i] < 0) return 1;
77 if (children[i] == 0) _exit(client(argv[1]));
78 }
79 for (unsigned int i = 0; i < 2; ++i) {
80 int status;
81 if (waitpid(children[i], &status, 0) != children[i] || !WIFEXITED(status) || WEXITSTATUS(status) != 0) return 1;
82 }
83 puts("UVME KERNEL PASS two real ioctl clients; trusted RM mapping and chip NOT_RUN");
84 return 0;
85}