From nobody Fri May 30 15:57:22 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4b87D32RZgz5xqBc; Fri, 30 May 2025 15:57:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b87D25Fpkz3RVq; Fri, 30 May 2025 15:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748620642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n2KFMScQkaC4qiOLcmDkwS+08YfkaVA0ReUGp0sZk/Y=; b=CF/Y5QWfDn6soIKCC8U9GUVxNSWF4HF/xAMQdUGSiZCMNJrrDdymrkEN6uSoakkvGFiC3e A+96GWUh7L69QkkBTXf7o1l2L/7icPQArTMQ6OSOeWDW46HYhcstMnP4b807tUjATji37r g+oBe+mjeQrigot9efGwpoe/bXr22vq5GU8C0u/0gLORgKpHBijEk+hlD2WfmJcVBaJ86p YvHCO9CxZDGD5Kl0xnp7Q7ZhO21SY63SVcWo8G5mYFZc1S2X00coUU+/sglRPSTze6hRkQ kMsq/jQXd8YvxRdXMZsxBSjVE1YhRBXbho2efAXFdDRIODv4IRChmksS8AAT5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748620642; a=rsa-sha256; cv=none; b=Gwrau70yEgb046PgamJlh2jCkfusNQHOVr+V0PMTskKs/E8m9pHyC23zaRFSnOBOWZ43vd t4IiBdJeydKHleCQQnOK6MLCf972cotVSd7+8x20ZvV1BDJStas3eToJ0CtLEFQ8e1NsOP igRTRLQasA1It5xHli+xWOBD4aD3AtKRHQvahZjoPcwfE2Pg5kwWaLLVCk23uBH+NIYo5k SZS4umKUdXdPjF8RBFqWOWuNk4kfOP9cqU2Yu46TmTbbMkq6VT6DJwVic7avv2zWwlEGbs WoZ1wMkVHKRdymXW29gzbv7jQpcgeEFvlzJDgG5abbjLeYEqRU9bGo1/nyqeBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748620642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n2KFMScQkaC4qiOLcmDkwS+08YfkaVA0ReUGp0sZk/Y=; b=onsYbCzs1VV22Q1N3jVQTAOdN3zZCWiKtZCIlMvmgAad/DipsjT4QWJgr5GA+1FFjP2cUF 7jT3K7gsNuAL4TqDcXFtpIXKE8NcHUTm9o+31HzhU6129N/zMqIrWsD8yejAGskS1Y3qUT JO8/uvvbrxJENpFSCetBct6xacxAWqTJDcJWDWzUcPSZSyLRh8XF5RopxH3W4z/gpL8oHs 1b6QqZ6MgKpW6OuklXV8joky9k2TaTblp7wcQmDbqxnY0rZQLcwnoqIf5iPlGvM73fw+5Y j8EV9kDtyBGT/CpgP3FpeRYaS/88sv0kVqlIJATUud5Gc74mu0dAMtAhgQgyIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4b87D24sKCz101q; Fri, 30 May 2025 15:57:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54UFvMPB079328; Fri, 30 May 2025 15:57:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54UFvMdO079325; Fri, 30 May 2025 15:57:22 GMT (envelope-from git) Date: Fri, 30 May 2025 15:57:22 GMT Message-Id: <202505301557.54UFvMdO079325@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: a3bdf33f3e46 - main - stand: Introduce md_align List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a3bdf33f3e46d37a2288faa0391e59ce65d430cb Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a3bdf33f3e46d37a2288faa0391e59ce65d430cb commit a3bdf33f3e46d37a2288faa0391e59ce65d430cb Author: Warner Losh AuthorDate: 2025-05-30 14:14:29 +0000 Commit: Warner Losh CommitDate: 2025-05-30 15:56:50 +0000 stand: Introduce md_align When we're loading metadata, we need to align it in a certain way. Right now that way is hard-coded to be PAGE_SIZE. Rather than do the actual physical thing in all these places, move this into a wrapper routine. We may want to load a 16k kernel and align all these on 16k or a 4k kernel and align on 4k on aarch64 (today you have to compile the loader with the right page size). This will also reduce the number of places we might have to touch to do that. Sponsored by: Netflix Reviewed by: tsoome, jhibbits Differential Revision: https://reviews.freebsd.org/D50585 --- stand/common/metadata.c | 8 ++++---- stand/common/modinfo.c | 22 ++++++++++++++++++++++ stand/common/modinfo.h | 1 + stand/efi/loader/bootinfo.c | 12 ++++++------ stand/i386/libi386/bootinfo32.c | 6 +++--- stand/i386/libi386/bootinfo64.c | 6 +++--- stand/userboot/userboot/bootinfo32.c | 6 +++--- stand/userboot/userboot/bootinfo64.c | 6 +++--- 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/stand/common/metadata.c b/stand/common/metadata.c index 715354aedd04..3b2ba3e4d790 100644 --- a/stand/common/metadata.c +++ b/stand/common/metadata.c @@ -123,14 +123,14 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64) addr = xp->f_addr + xp->f_size; } /* Pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* Copy our environment */ envp = addr; addr = md_copyenv(addr); /* Pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #if defined(LOADER_FDT_SUPPORT) /* Copy out FDT */ @@ -141,7 +141,7 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64) { size = fdt_copy(addr); fdtp = addr; - addr = roundup(addr + size, PAGE_SIZE); + addr = md_align(addr + size); } #endif @@ -176,7 +176,7 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offset_t *dtb, int kern64) *modulep = addr; size = md_copymodules(0, kern64); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); md = file_findmetadata(kfp, MODINFOMD_KERNEND); if (kern64) { diff --git a/stand/common/modinfo.c b/stand/common/modinfo.c index d00548c91c57..100f2c704d8f 100644 --- a/stand/common/modinfo.c +++ b/stand/common/modinfo.c @@ -194,3 +194,25 @@ md_copyenv(vm_offset_t start) last = start; return(last); } + +/* + * Take the ending address and round it up to the currently required + * alignment. This typically is the page size, but is the larger of the compiled + * kernel page size, the loader page size, and the typical page size on the + * platform. + * + * XXX For the moment, it's just PAGE_SIZE to make the refactoring go faster, + * but needs to hook-in arch_loadaddr (or its replacement) functionality. + * + * Also, we may need other logical things when dealing with different types of + * page sizes and/or masking or sizes. This works well for addr and sizes, but + * not for masks. + * + * Also, this is different than the MOD_ALIGN macro above, which is used for + * aligning elements in the metadata lists, not for whare modules can begin. + */ +vm_offset_t +md_align(vm_offset_t addr) +{ + return (roundup(addr, PAGE_SIZE)); +} diff --git a/stand/common/modinfo.h b/stand/common/modinfo.h index d26129089fb6..d613d8e27f1f 100644 --- a/stand/common/modinfo.h +++ b/stand/common/modinfo.h @@ -16,5 +16,6 @@ int md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtb); vm_offset_t md_copymodules(vm_offset_t addr, bool kern64); vm_offset_t md_copyenv(vm_offset_t addr); +vm_offset_t md_align(vm_offset_t addr); #endif /* COMMON_MODINFO_H */ diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 75d755686658..b8f1a2ffd56c 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -389,18 +389,18 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) } /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #ifdef EFI addr = build_font_module(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_splash_module(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #endif /* Copy our environment. */ @@ -408,7 +408,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) addr = md_copyenv(addr); /* Pad to a page boundary. */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); #if defined(LOADER_FDT_SUPPORT) /* Handle device tree blob */ @@ -417,7 +417,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) /* Pad to a page boundary */ if (dtb_size) - addr += roundup(dtb_size, PAGE_SIZE); + addr += md_align(dtb_size); #endif kfp = file_findfile(NULL, md_kerntype); @@ -461,7 +461,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs) #endif size = md_copymodules(0, is64); /* Find the size of the modules */ - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/i386/libi386/bootinfo32.c b/stand/i386/libi386/bootinfo32.c index 37b227b913bd..6655e62f8065 100644 --- a/stand/i386/libi386/bootinfo32.c +++ b/stand/i386/libi386/bootinfo32.c @@ -118,7 +118,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_font_module(addr); @@ -127,7 +127,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -145,7 +145,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, false); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/i386/libi386/bootinfo64.c b/stand/i386/libi386/bootinfo64.c index f7181dcd599f..7d74a865ff40 100644 --- a/stand/i386/libi386/bootinfo64.c +++ b/stand/i386/libi386/bootinfo64.c @@ -136,7 +136,7 @@ bi_load64(char *args, vm_offset_t *modulep, addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); addr = build_font_module(addr); @@ -161,11 +161,11 @@ bi_load64(char *args, vm_offset_t *modulep, size = md_copymodules(0, true); /* copy our environment */ - envp = roundup(addr + size, PAGE_SIZE); + envp = md_align(addr + size); addr = md_copyenv(envp); /* set kernend */ - kernend = roundup(addr, PAGE_SIZE); + kernend = md_align(addr); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/userboot/userboot/bootinfo32.c b/stand/userboot/userboot/bootinfo32.c index 750574912172..6ba76cc56479 100644 --- a/stand/userboot/userboot/bootinfo32.c +++ b/stand/userboot/userboot/bootinfo32.c @@ -99,14 +99,14 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* copy our environment */ envp = addr; addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -123,7 +123,7 @@ bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, vm_offset_t /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, false); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */ diff --git a/stand/userboot/userboot/bootinfo64.c b/stand/userboot/userboot/bootinfo64.c index d20202bf4fbb..3e289bbebba0 100644 --- a/stand/userboot/userboot/bootinfo64.c +++ b/stand/userboot/userboot/bootinfo64.c @@ -131,14 +131,14 @@ bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernendp) addr = xp->f_addr + xp->f_size; } /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); /* copy our environment */ envp = addr; addr = md_copyenv(addr); /* pad to a page boundary */ - addr = roundup(addr, PAGE_SIZE); + addr = md_align(addr); kfp = file_findfile(NULL, md_kerntype); if (kfp == NULL) @@ -152,7 +152,7 @@ bi_load64(char *args, vm_offset_t *modulep, vm_offset_t *kernendp) /* Figure out the size and location of the metadata */ *modulep = addr; size = md_copymodules(0, true); - kernend = roundup(addr + size, PAGE_SIZE); + kernend = md_align(addr + size); *kernendp = kernend; /* patch MODINFOMD_KERNEND */