All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH] x86: mmap kernel for direct kernel boot
Date: Sat, 7 Nov 2026 08:12:11 -0500	[thread overview]
Message-ID: <20261107080917-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CAFn=p-ZKX81fjQH8OdGAq7ErJ9bc2BsLtn2jEicUmgwWdjQYEA@mail.gmail.com>

On Fri, Nov 06, 2026 at 01:02:33PM -0500, John Snow wrote:
> On Wed, Oct 21, 2026 at 12:02 PM John Snow <jsnow@redhat.com> wrote:
> >
> > On Wed, Oct 21, 2026 at 2:31 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
> > >
> > > Reduce memory footprint by mapping the kernel into memory instead of
> > > reading into allocated memory in the common case (no -dtb $file on the
> > > qemu command line).
> > >
> > > Cc: John Snow <jsnow@redhat.com>
> > > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> >
> > Tested-by: John Snow <jsnow@redhat.com>
> >
> 
> Ping, is someone going to pick up this patch?
> 
> --js

ok

> > Using this patch, I shifted about 19MiB of resources from RssAnon to
> > RssFile. This theoretically allows sharing resources between multiple
> > QEMU instances in the trivial case using -kernel and -initrd. This
> > matches how we already load initrd.
> >
> > --js
> >
> > > ---
> > >  hw/i386/x86-common.c | 25 ++++++++++++++++++++-----
> > >  1 file changed, 20 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
> > > index fa18bf1aeceb..25e141aa8537 100644
> > > --- a/hw/i386/x86-common.c
> > > +++ b/hw/i386/x86-common.c
> > > @@ -911,16 +911,31 @@ void x86_load_linux(X86MachineState *x86ms,
> > >      }
> > >
> > >      setup  = g_malloc(setup_size);
> > > -    kernel = g_malloc(kernel_size);
> > >      fseek(f, 0, SEEK_SET);
> > >      if (fread(setup, 1, setup_size, f) != setup_size) {
> > >          fprintf(stderr, "fread() failed\n");
> > >          exit(1);
> > >      }
> > > -    fseek(f, 0, SEEK_SET);
> > > -    if (fread(kernel, 1, kernel_size, f) != kernel_size) {
> > > -        fprintf(stderr, "fread() failed\n");
> > > -        exit(1);
> > > +    if (dtb_filename) {
> > > +        /* read kernel into allocated memory, so we can realloc for the dtb */
> > > +        kernel = g_malloc(kernel_size);
> > > +        fseek(f, 0, SEEK_SET);
> > > +        if (fread(kernel, 1, kernel_size, f) != kernel_size) {
> > > +            fprintf(stderr, "fread() failed\n");
> > > +            exit(1);
> > > +        }
> > > +    } else {
> > > +        /* mmap kernel */
> > > +        GMappedFile *mapped_file;
> > > +        GError *gerr = NULL;
> > > +
> > > +        mapped_file = g_mapped_file_new(kernel_filename, false, &gerr);
> > > +        if (!mapped_file) {
> > > +            fprintf(stderr, "qemu: error reading kernel %s: %s\n",
> > > +                    kernel_filename, gerr->message);
> > > +            exit(1);
> > > +        }
> > > +        kernel = (uint8_t *)g_mapped_file_get_contents(mapped_file);
> > >      }
> > >      fclose(f);
> > >
> > > --
> > > 2.56.0
> > >



  reply	other threads:[~2026-11-07 13:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  6:31 [PATCH] x86: mmap kernel for direct kernel boot Gerd Hoffmann
2026-10-21 16:02 ` John Snow
2026-11-06 18:02   ` John Snow
2026-11-07 13:12     ` Michael S. Tsirkin [this message]
2026-11-07 13:24     ` Michael S. Tsirkin
2026-11-07 18:59       ` John Snow
2026-11-08  0:09         ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261107080917-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.