Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Aug 2022 13:38:52 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        FreeBSD User <freebsd@walstatt-de.de>
Cc:        Warner Losh <imp@freebsd.org>, src-committers <src-committers@freebsd.org>,  "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   Re: git: 39fdad34e220 - main - stand: impose 510,000 byte limit for /boot/loader and /boot/pxeldr
Message-ID:  <CANCZdfpkVewkLGwxrsNxf44tLxTbEeQQMC9SEQaChXFxYqcytg@mail.gmail.com>
In-Reply-To: <20220811211807.0b9c8a75@thor.intern.walstatt.dynvpn.de>
References:  <202208110331.27B3Va7M007335@gitrepo.freebsd.org> <20220811211807.0b9c8a75@thor.intern.walstatt.dynvpn.de>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Thu, Aug 11, 2022 at 1:18 PM FreeBSD User <freebsd@walstatt-de.de> wrote:

> Am Thu, 11 Aug 2022 03:31:36 GMT
> Warner Losh <imp@FreeBSD.org> schrieb:
>
> > The branch main has been updated by imp:
> >
> > URL:
> https://cgit.FreeBSD.org/src/commit/?id=39fdad34e220c52a433e78f20c8c39412429014e
> >
> > commit 39fdad34e220c52a433e78f20c8c39412429014e
> > Author:     Warner Losh <imp@FreeBSD.org>
> > AuthorDate: 2022-08-11 03:19:01 +0000
> > Commit:     Warner Losh <imp@FreeBSD.org>
> > CommitDate: 2022-08-11 03:29:20 +0000
> >
> >     stand: impose 510,000 byte limit for /boot/loader and /boot/pxeldr
> >
> >     The BIOS method of booting imposes an absolute limit of 640k for the
> >     size of the program being run due to btx. In practice, this means
> that
> >     programs larger than about 500kiB will fail in odd ways as the stack
> /
> >     heap will overflow.
> >
> >     Pick 510,000 as the cutoff line semi-arbitrarily. loader_lua is now
> >     almost too big and we want to break the build when it crosses this
> >     threshold. In my experience, below 500,000 always works, above
> 520,000
> >     always seems to fail with things getting bad somewhere between
> 512,000
> >     to 515,000. 510,000 is as close to the line as I think we can go,
> though
> >     experience may dictate we need to lower this in the future.
> >
> >     This is at-best a stop-breakage until we have a better way to subset
> the
> >     boot loader for BIOS booting to allow better, more fined-tuned
> >     /boot/loaders for the many different environments they have to run
> >     in. This likely means we'll have a graphical loader than understands
> a
> >     few filesystmes for installation, and a non-graphical loader that
> >     understands the most filesystems possible for everything else in the
> >     future. Our build infrastructure needs some work before we can do
> that,
> >     however.
> >
> >     At this late date, it likely isn't worth the efforts to move parts of
> >     the loader into high memory. There's a number of assumptions about
> where
> >     the stack is, where buffers reside, etc that are fulfilled when it
> lives
> >     in the first 640k that would need bounce buffers and/or other counter
> >     measures if we were to split it up. All BIOS calls are done in 16-bit
> >     mode with SEG:OFF addresses, requiring them to be in the first 640k
> of
> >     RAM. And nearly all machines in the last decade can boot with UEFI
> >     (though there's some exceptions, so it isn't worth killing outright
> >     yet).
> >
> >     Sponsored by:           Netflix
> >     Reviewed by:            kevans
> >     Differential Revision:  https://reviews.freebsd.org/D36129
> > ---
> >  stand/i386/loader/Makefile | 5 +++++
> >  stand/i386/pxeldr/Makefile | 3 +++
> >  2 files changed, 8 insertions(+)
> >
> > diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile
> > index 3685281ffd2c..cde1513aac06 100644
> > --- a/stand/i386/loader/Makefile
> > +++ b/stand/i386/loader/Makefile
> > @@ -19,6 +19,8 @@ PROG=               ${LOADER}.sym
> >  INTERNALPROG=
> >  NEWVERSWHAT?=        "bootstrap loader" x86
> >  VERSION_FILE=        ${.CURDIR}/../loader/version
> > +LOADERSIZE=  510000          # Largest known safe size
> > +
> >
> >  .PATH:               ${BOOTSRC}/i386/loader
> >
> > @@ -79,9 +81,12 @@ CFLAGS+=   -I${BOOTSRC}/i386
> >  8x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf
> >       vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}
> >
> > +
> >  ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}
> >       btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
> >               -b ${BTXKERN} ${LOADER}.bin
> > +     @set -- `${SIZE} ${.TARGET} | tail -1` ;
> x=$$((${LOADERSIZE}-$$4)); \
> > +         echo "$$x bytes available"; test $$x -ge 0
> >
> >  ${LOADER}.bin: ${LOADER}.sym
> >       ${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}
> > diff --git a/stand/i386/pxeldr/Makefile b/stand/i386/pxeldr/Makefile
> > index a44dc0de2885..f8bc1eae9a31 100644
> > --- a/stand/i386/pxeldr/Makefile
> > +++ b/stand/i386/pxeldr/Makefile
> > @@ -13,6 +13,7 @@ BOOT=       pxeboot
> >  LDR= pxeldr
> >  ORG= 0x7c00
> >  LOADER=      loader
> > +PXELDRSIZE= 510000           # Largest known safe size
> >
> >  .if defined(BOOT_PXELDR_PROBE_KEYBOARD)
> >  CFLAGS+=-DPROBE_KEYBOARD
> > @@ -41,5 +42,7 @@ CLEANFILES+= ${LOADER}
> >  ${LOADER}: ${LOADERBIN} ${BTXLDR} ${BTXKERN}
> >       btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \
> >           -b ${BTXKERN} ${LOADERBIN}
> > +     @set -- `${SIZE} ${.TARGET} | tail -1` ;
> x=$$((${PXELDRSIZE}-$$4)); \
> > +         echo "$$x bytes available"; test $$x -ge 0
> >
> >  .include <bsd.prog.mk>
> >
>
> To make a long story short:
>
> Having WITH_BEARSSL=YES
>
> in /etc/src.conf blow off the loader. Can this be fixed?
>

I think so. But now you have to either choose not to do that, use the
loader_4th or wait for things like making the frame buffer code optional to
come to fruition. If you aren't actually using this, the latest changes in
the tree allow you to override the limit to keep it 'building' but being
over by 56k means it can't possibly work.

Warner

[-- Attachment #2 --]
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Aug 11, 2022 at 1:18 PM FreeBSD User &lt;<a href="mailto:freebsd@walstatt-de.de">freebsd@walstatt-de.de</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am Thu, 11 Aug 2022 03:31:36 GMT<br>
Warner Losh &lt;imp@FreeBSD.org&gt; schrieb:<br>
<br>
&gt; The branch main has been updated by imp:<br>
&gt; <br>
&gt; URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=39fdad34e220c52a433e78f20c8c39412429014e" rel="noreferrer" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=39fdad34e220c52a433e78f20c8c39412429014e</a><br>;
&gt; <br>
&gt; commit 39fdad34e220c52a433e78f20c8c39412429014e<br>
&gt; Author:     Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; AuthorDate: 2022-08-11 03:19:01 +0000<br>
&gt; Commit:     Warner Losh &lt;imp@FreeBSD.org&gt;<br>
&gt; CommitDate: 2022-08-11 03:29:20 +0000<br>
&gt; <br>
&gt;     stand: impose 510,000 byte limit for /boot/loader and /boot/pxeldr<br>
&gt;     <br>
&gt;     The BIOS method of booting imposes an absolute limit of 640k for the<br>
&gt;     size of the program being run due to btx. In practice, this means that<br>
&gt;     programs larger than about 500kiB will fail in odd ways as the stack /<br>
&gt;     heap will overflow.<br>
&gt;     <br>
&gt;     Pick 510,000 as the cutoff line semi-arbitrarily. loader_lua is now<br>
&gt;     almost too big and we want to break the build when it crosses this<br>
&gt;     threshold. In my experience, below 500,000 always works, above 520,000<br>
&gt;     always seems to fail with things getting bad somewhere between 512,000<br>
&gt;     to 515,000. 510,000 is as close to the line as I think we can go, though<br>
&gt;     experience may dictate we need to lower this in the future.<br>
&gt;     <br>
&gt;     This is at-best a stop-breakage until we have a better way to subset the<br>
&gt;     boot loader for BIOS booting to allow better, more fined-tuned<br>
&gt;     /boot/loaders for the many different environments they have to run<br>
&gt;     in. This likely means we&#39;ll have a graphical loader than understands a<br>
&gt;     few filesystmes for installation, and a non-graphical loader that<br>
&gt;     understands the most filesystems possible for everything else in the<br>
&gt;     future. Our build infrastructure needs some work before we can do that,<br>
&gt;     however.<br>
&gt;     <br>
&gt;     At this late date, it likely isn&#39;t worth the efforts to move parts of<br>
&gt;     the loader into high memory. There&#39;s a number of assumptions about where<br>
&gt;     the stack is, where buffers reside, etc that are fulfilled when it lives<br>
&gt;     in the first 640k that would need bounce buffers and/or other counter<br>
&gt;     measures if we were to split it up. All BIOS calls are done in 16-bit<br>
&gt;     mode with SEG:OFF addresses, requiring them to be in the first 640k of<br>
&gt;     RAM. And nearly all machines in the last decade can boot with UEFI<br>
&gt;     (though there&#39;s some exceptions, so it isn&#39;t worth killing outright<br>
&gt;     yet).<br>
&gt;     <br>
&gt;     Sponsored by:           Netflix<br>
&gt;     Reviewed by:            kevans<br>
&gt;     Differential Revision:  <a href="https://reviews.freebsd.org/D36129" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D36129</a><br>;
&gt; ---<br>
&gt;  stand/i386/loader/Makefile | 5 +++++<br>
&gt;  stand/i386/pxeldr/Makefile | 3 +++<br>
&gt;  2 files changed, 8 insertions(+)<br>
&gt; <br>
&gt; diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile<br>
&gt; index 3685281ffd2c..cde1513aac06 100644<br>
&gt; --- a/stand/i386/loader/Makefile<br>
&gt; +++ b/stand/i386/loader/Makefile<br>
&gt; @@ -19,6 +19,8 @@ PROG=               ${LOADER}.sym<br>
&gt;  INTERNALPROG=<br>
&gt;  NEWVERSWHAT?=        &quot;bootstrap loader&quot; x86<br>
&gt;  VERSION_FILE=        ${.CURDIR}/../loader/version<br>
&gt; +LOADERSIZE=  510000          # Largest known safe size<br>
&gt; +<br>
&gt;  <br>
&gt;  .PATH:               ${BOOTSRC}/i386/loader<br>
&gt;  <br>
&gt; @@ -79,9 +81,12 @@ CFLAGS+=   -I${BOOTSRC}/i386<br>
&gt;  8x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf<br>
&gt;       vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC}<br>
&gt;  <br>
&gt; +<br>
&gt;  ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN}<br>
&gt;       btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \<br>
&gt;               -b ${BTXKERN} ${LOADER}.bin<br>
&gt; +     @set -- `${SIZE} ${.TARGET} | tail -1` ; x=$$((${LOADERSIZE}-$$4)); \<br>
&gt; +         echo &quot;$$x bytes available&quot;; test $$x -ge 0<br>
&gt;  <br>
&gt;  ${LOADER}.bin: ${LOADER}.sym<br>
&gt;       ${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC}<br>
&gt; diff --git a/stand/i386/pxeldr/Makefile b/stand/i386/pxeldr/Makefile<br>
&gt; index a44dc0de2885..f8bc1eae9a31 100644<br>
&gt; --- a/stand/i386/pxeldr/Makefile<br>
&gt; +++ b/stand/i386/pxeldr/Makefile<br>
&gt; @@ -13,6 +13,7 @@ BOOT=       pxeboot<br>
&gt;  LDR= pxeldr<br>
&gt;  ORG= 0x7c00<br>
&gt;  LOADER=      loader<br>
&gt; +PXELDRSIZE= 510000           # Largest known safe size<br>
&gt;  <br>
&gt;  .if defined(BOOT_PXELDR_PROBE_KEYBOARD)<br>
&gt;  CFLAGS+=-DPROBE_KEYBOARD<br>
&gt; @@ -41,5 +42,7 @@ CLEANFILES+= ${LOADER}<br>
&gt;  ${LOADER}: ${LOADERBIN} ${BTXLDR} ${BTXKERN}<br>
&gt;       btxld -v -f elf -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \<br>
&gt;           -b ${BTXKERN} ${LOADERBIN}<br>
&gt; +     @set -- `${SIZE} ${.TARGET} | tail -1` ; x=$$((${PXELDRSIZE}-$$4)); \<br>
&gt; +         echo &quot;$$x bytes available&quot;; test $$x -ge 0<br>
&gt;  <br>
&gt;  .include &lt;<a href="http://bsd.prog.mk" rel="noreferrer" target="_blank">bsd.prog.mk</a>&gt;<br>
&gt; <br>
<br>
To make a long story short:<br>
<br>
Having WITH_BEARSSL=YES<br>
<br>
in /etc/src.conf blow off the loader. Can this be fixed?<br></blockquote><div><br></div><div>I think so. But now you have to either choose not to do that, use the loader_4th or wait for things like making the frame buffer code optional to come to fruition. If you aren&#39;t actually using this, the latest changes in the tree allow you to override the limit to keep it &#39;building&#39; but being over by 56k means it can&#39;t possibly work.</div><div><br></div><div>Warner<br></div></div></div>

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