Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Apr 2025 21:59:15 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 0c48531b4698 - main - kboot: Account for machine specific padding
Message-ID:  <202504172159.53HLxF7R002694@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=0c48531b4698c62d3553d75b283b3ebc26e19063

commit 0c48531b4698c62d3553d75b283b3ebc26e19063
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2025-04-17 04:04:13 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-04-17 21:56:46 +0000

    kboot: Account for machine specific padding
    
    AMD64 kernels have an extra 2MB of padding that we need to account
    for. So make the padding proper on a per-architecture basis.
    
    Sponsored by:           Netflix
    Reviewed by:            kevans, jhibbits
    Differential Revision:  https://reviews.freebsd.org/D49861
---
 stand/kboot/kboot/main.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/stand/kboot/kboot/main.c b/stand/kboot/kboot/main.c
index 65f7b77f1ace..5b7bfa246f55 100644
--- a/stand/kboot/kboot/main.c
+++ b/stand/kboot/kboot/main.c
@@ -49,9 +49,23 @@ static void kboot_zfs_probe(void);
 
 extern int command_fdt_internal(int argc, char *argv[]);
 
+/*
+ * On amd64, KERNSTART is where the first actual kernel page is mapped, after
+ * the compatibility mapping. We reserve 2MB at the start of the address space
+ * for the page tables, etc, and so need to offset this there (and only there).
+ * The loader needs to know about this so we can pad everything to the proper
+ * place in PA. Ideally, we'd include vmparam.h to figure this out, but the
+ * macros it uses are not easily available in this compile environment, so we
+ * hard code that knowledge here.
+ */
+#if defined(__amd64__)
+#define KERN_PADDING (2 << 20)
+#else
+#define KERN_PADDING 0
+#endif
+
 #define PA_INVAL (vm_offset_t)-1
 static vm_offset_t pa_start = PA_INVAL;
-static vm_offset_t padding;
 static vm_offset_t offset;
 
 static uint64_t commit_limit;
@@ -386,6 +400,8 @@ main(int argc, const char **argv)
 			bootdev = getenv("currdev");
 	}
 #endif
+	if (bootdev == NULL)
+		bootdev = "host:/";
 	if (bootdev != NULL) {
 		/*
 		 * Otherwise, honor what's on the command line. If we've been
@@ -514,15 +530,13 @@ kboot_copyin(const void *src, vm_offset_t dest, const size_t len)
 
 	if (pa_start == PA_INVAL) {
 		pa_start = kboot_get_phys_load_segment();
-//		padding = 2 << 20; /* XXX amd64: revisit this when we make it work */
-		padding = 0;
 		offset = dest;
 		get_phys_buffer(pa_start, len, &destbuf);
 	}
 
 	remainder = len;
 	do {
-		segsize = get_phys_buffer(dest + pa_start + padding - offset, remainder, &destbuf);
+		segsize = get_phys_buffer(dest + pa_start + KERN_PADDING - offset, remainder, &destbuf);
 		bcopy(src, destbuf, segsize);
 		remainder -= segsize;
 		src += segsize;
@@ -540,7 +554,7 @@ kboot_copyout(vm_offset_t src, void *dest, const size_t len)
 
 	remainder = len;
 	do {
-		segsize = get_phys_buffer(src + pa_start + padding - offset, remainder, &srcbuf);
+		segsize = get_phys_buffer(src + pa_start + KERN_PADDING - offset, remainder, &srcbuf);
 		bcopy(srcbuf, dest, segsize);
 		remainder -= segsize;
 		src += segsize;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202504172159.53HLxF7R002694>