git: 60688f592d9f - stable/13 - kboot: Implement mount(2)

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:11:02 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=60688f592d9fcde35b623b9759f4fd61cd796b48

commit 60688f592d9fcde35b623b9759f4fd61cd796b48
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-06-30 18:16:46 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:24 +0000

    kboot: Implement mount(2)
    
    Create a wrapper for the mount system call. To ensure a sane early boot
    environment and to gather data we need for kexec, we may need to mount
    some special filesystems.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit 8138a766b068a17ad8f13ddcb850f356c04d9074)
---
 stand/kboot/arch/amd64/syscall_nr.h     | 1 +
 stand/kboot/arch/powerpc64/syscall_nr.h | 1 +
 stand/kboot/host_syscall.h              | 5 +++++
 stand/kboot/host_syscalls.c             | 7 +++++++
 4 files changed, 14 insertions(+)

diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h
index b847b21efa88..4e2f686e7ae5 100644
--- a/stand/kboot/arch/amd64/syscall_nr.h
+++ b/stand/kboot/arch/amd64/syscall_nr.h
@@ -7,6 +7,7 @@
 #define SYS_lseek		  8
 #define	SYS_mkdirat		258
 #define SYS_mmap		  9
+#define SYS_mount		165
 #define	SYS_munmap		 11
 #define SYS_newfstat		  5
 #define SYS_newfstatat		262
diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h
index b86874b92e76..404a6f15fafc 100644
--- a/stand/kboot/arch/powerpc64/syscall_nr.h
+++ b/stand/kboot/arch/powerpc64/syscall_nr.h
@@ -8,6 +8,7 @@
 #define SYS_llseek		140
 #define	SYS_mkdirat		287
 #define SYS_mmap		 90
+#define SYS_mount		 21
 #define	SYS_munmap		 91
 #define SYS_newfstat		SYS_fstat
 #define SYS_newfstatat		291
diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h
index 76a5efb0a091..1ce74d3f393d 100644
--- a/stand/kboot/host_syscall.h
+++ b/stand/kboot/host_syscall.h
@@ -88,6 +88,9 @@ struct host_timeval {
 
 #define HOST_AT_FDCWD		-100		/* Relative to current directory */
 
+/* Mount flags from uapi */
+#define MS_RELATIME (1 << 21)
+
 /*
  * System Calls
  */
@@ -101,6 +104,8 @@ int host_kexec_load(uint32_t start, int nsegs, uint32_t segs, uint32_t flags);
 ssize_t host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence);
 int host_mkdir(const char *, host_mode_t);
 void *host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off);
+int host_mount(const char *src, const char *target, const char *type,
+    unsigned long flags, void *data);
 int host_munmap(void *addr, size_t len);
 int host_open(const char *path, int flags, int mode);
 ssize_t host_read(int fd, void *buf, size_t nbyte);
diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c
index 99f5444eb469..1dd7aeb1963b 100644
--- a/stand/kboot/host_syscalls.c
+++ b/stand/kboot/host_syscalls.c
@@ -75,6 +75,13 @@ host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off)
 	return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off);
 }
 
+int
+host_mount(const char *src, const char *target, const char *type, unsigned long flags,
+    void *data)
+{
+	return host_syscall(SYS_mount, src, target, type, flags, data);
+}
+
 int
 host_munmap(void *addr, size_t len)
 {