From: Xuesen Guo Subject: Re: [PATCH] readnote: Add bzImage kernel support Date: Thu, 26 Apr 2012 17:51:11 +0800 Message-ID: <1335433871.4742.18.camel@goosenl-desktop> References: <27a6422ac06df8bef75d.1335430449@localhost6.localdomain6> <4F992DCF0200007800080283@nat28.tlf.novell.com> <1335432002.28015.78.camel@zakaz.uk.xensource.com> Reply-To: Xuesen.Guo@hitachiconsulting.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3467935560755890166==" Return-path: In-Reply-To: <1335432002.28015.78.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: Stefano Stabellini , Ian Jackson , Jan Beulich , xen-devel List-Id: xen-devel@lists.xenproject.org --===============3467935560755890166== Content-Type: multipart/alternative; boundary="=-aZaC9Ufja/c88rSEtweD" --=-aZaC9Ufja/c88rSEtweD Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I fixed the confusion, shall I need to resend this patch? ------------------------------------------------------------------------ readnote: Add bzImage kernel support Add the check of bzImage kernel and make it work with RHEL 6 big zImage kernel Signed-off-by: Xuesen Guo Acked-by: Ian Campbell --- Changed since v1: * add additional checks of the offset and length * not changing st.st_size, use size instead of st.st_size =20 --- Changed since v2: * changing decription bzipped kernels to big zImage kernel Thanks! Xuesen=20 On Thu, 2012-04-26 at 10:20 +0100, Ian Campbell wrote: > On Thu, 2012-04-26 at 10:13 +0100, Jan Beulich wrote: > > >>> On 26.04.12 at 10:54, Xuesen Guo = wrote: > > > Add the check of bzImage kernel and make it work > > > with RHEL 6 bzipped kernels > >=20 > > I fail to see the relation of the term "bzipped" above to the actual pa= tch. >=20 > Oh yes, this is a common misconception (which I failed to notice in my > review). >=20 > The "bz" in bzImage does not refer to the bzip compression algorithm. > Rather it refers to "big zImage". It's a historical thing because the > original zImage compressor was restricted to <1M (or something) of RAM > at decompression time and bzImage was introduced to cope with more and > therefore worked for larger kernels. Obviously 1M is very limiting to in > practice everyone uses bzImage today... >=20 > Now of course today, just to add to the confusion, bzImage can support > multiple compression algorithms, including the original z, but also > bzip2, lzma and xz. >=20 > Ian >=20 > >=20 > > Jan > >=20 > > > Signed-off-by: Xuesen Guo > > >=20 > > > --- > > > Changed since v1: > > > * add additional checks of the offset and length > > > * not changing st.st_size, use size instead of st.st_size > > >=20 > > > diff -r d690c7e896a2 -r 27a6422ac06d tools/xcutils/readnotes.c > > > --- a/tools/xcutils/readnotes.c=09Thu Apr 05 11:06:03 2012 +0100 > > > +++ b/tools/xcutils/readnotes.c=09Thu Apr 26 16:53:17 2012 +0800 > > > @@ -18,6 +18,48 @@ > > > =20 > > > static xc_interface *xch; > > > =20 > > > +/* According to the implemation of xc_dom_probe_bzimage_kernel() fun= ction=20 > > > */ > > > +/* We add support of bzImage kernel */ > > > +/* Copied from tools/libxc/xc_doom_bzImageloader.c */ > > > +struct setup_header { > > > +=09uint8_t _pad0[0x1f1]; /* skip uninteresting stuff */ > > > +=09uint8_t setup_sects; > > > +=09uint16_t root_flags; > > > +=09uint32_t syssize; > > > +=09uint16_t ram_size; > > > +=09uint16_t vid_mode; > > > +=09uint16_t root_dev; > > > +=09uint16_t boot_flag; > > > +=09uint16_t jump; > > > +=09uint32_t header; > > > +#define HDR_MAGIC "HdrS" > > > +#define HDR_MAGIC_SZ 4 > > > +=09uint16_t version; > > > +#define VERSION(h,l) (((h)<<8) | (l)) > > > +=09uint32_t realmode_swtch; > > > +=09uint16_t start_sys; > > > +=09uint16_t kernel_version; > > > +=09uint8_t type_of_loader; > > > +=09uint8_t loadflags; > > > +=09uint16_t setup_move_size; > > > +=09uint32_t code32_start; > > > +=09uint32_t ramdisk_image; > > > +=09uint32_t ramdisk_size; > > > +=09uint32_t bootsect_kludge; > > > +=09uint16_t heap_end_ptr; > > > +=09uint16_t _pad1; > > > +=09uint32_t cmd_line_ptr; > > > +=09uint32_t initrd_addr_max; > > > +=09uint32_t kernel_alignment; > > > +=09uint8_t relocatable_kernel; > > > +=09uint8_t _pad2[3]; > > > +=09uint32_t cmdline_size; > > > +=09uint32_t hardware_subarch; > > > +=09uint64_t hardware_subarch_data; > > > +=09uint32_t payload_offset; > > > +=09uint32_t payload_length; > > > +} __attribute__((packed)); > > > + > > > static void print_string_note(const char *prefix, struct elf_binary = *elf, > > > =09=09=09 const elf_note *note) > > > { > > > @@ -131,6 +173,9 @@ int main(int argc, char **argv) > > > =09const elf_shdr *shdr; > > > =09int notes_found =3D 0; > > > =20 > > > +=09struct setup_header *hdr; > > > +=09uint64_t payload_offset, payload_length; > > > + > > > =09if (argc !=3D 2) > > > =09{ > > > =09=09fprintf(stderr, "Usage: readnotes \n"); > > > @@ -159,13 +204,45 @@ int main(int argc, char **argv) > > > =09=09fprintf(stderr, "Unable to map %s: %s\n", f, strerror(errno)); > > > =09=09return 1; > > > =09} > > > -=09size =3D st.st_size; > > > +=09 > > > +=09/* Check the magic of bzImage kernel */ > > > +=09hdr =3D (struct setup_header *)image; > > > +=09if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) =3D=3D 0 ) > > > +=09{ > > > +=09=09if ( hdr->version < VERSION(2,8) ) > > > +=09=09{ > > > +=09=09=09printf("%s: boot protocol too old (%04x)", __FUNCTION__, hd= r->version); > > > +=09=09=09return 1; > > > +=09=09} > > > =20 > > > -=09usize =3D xc_dom_check_gzip(xch, image, st.st_size); > > > +=09=09/* upcast to 64 bits to avoid overflow */ > > > +=09=09/* setup_sects is u8 and so cannot overflow */ > > > +=09=09payload_offset =3D (hdr->setup_sects + 1) * 512; > > > +=09=09payload_offset +=3D hdr->payload_offset; > > > +=09=09payload_length =3D hdr->payload_length; > > > +=09=09 > > > +=09=09if ( payload_offset >=3D st.st_size ) > > > +=09=09{ > > > +=09=09=09printf("%s: payload offset overflow", __FUNCTION__); > > > +=09=09=09return 1; > > > +=09=09} > > > +=09=09if ( (payload_offset + payload_length) > st.st_size ) > > > +=09=09{ > > > +=09=09=09printf("%s: payload length overflow", __FUNCTION__); > > > +=09=09=09return 1; > > > +=09=09} > > > + > > > +=09=09image =3D image + payload_offset; > > > +=09=09size =3D payload_length; > > > +=09} else { > > > +=09=09size =3D st.st_size; > > > +=09} > > > + > > > +=09usize =3D xc_dom_check_gzip(xch, image, size); > > > =09if (usize) > > > =09{ > > > =09=09tmp =3D malloc(usize); > > > -=09=09xc_dom_do_gunzip(xch, image, st.st_size, tmp, usize); > > > +=09=09xc_dom_do_gunzip(xch, image, size, tmp, usize); > > > =09=09image =3D tmp; > > > =09=09size =3D usize; > > > =09} > > >=20 > > > This e-mail is intended solely for the person or entity to which it i= s=20 > > > addressed > > > and may contain confidential and/or privileged information. Any revie= w,=20 > > > dissemination, > > > copying, printing or other use of this e-mail by persons or entities = other=20 > > > than the=20 > > > addressee is prohibited. If you have received this e-mail in error, p= lease=20 > > > contact > > > the sender immediately and delete the material from any computer. > > > To unsubscribe send an email to: Unsubscribe@hitachiconsulting.com=20 > > > Hitachi Consulting (China) Co., Ltd. (HCCD0411) > > >=20 > > >=20 > > >=20 > > > _______________________________________________ > > > Xen-devel mailing list > > > Xen-devel@lists.xen.org=20 > > > http://lists.xen.org/xen-devel=20 > >=20 > >=20 > >=20 > > _______________________________________________ > > Xen-devel mailing list > > Xen-devel@lists.xen.org > > http://lists.xen.org/xen-devel >=20 >=20 >=20 --=-aZaC9Ufja/c88rSEtweD Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I fixed the confusion, shall I need to resend this patch?
------------------------------------------------------------------------ readnote: Add bzImage kernel support

Add the check of bzImage kernel and make it work
with RHEL 6 big zImage kernel

Signed-off-by: Xuesen Guo <Xuesen.Guo@hitachiconsulting.com>
Acked-by: Ian Campbell <ian.c= ampbell@citrix.com>

---
Changed since v1:
  * add additional checks of the offset and length
  * not changing st.st_size, use size instead of st.st_size
 
---
Changed since v2:
  * changing decription bzipped kernels to big zImage kernel


Thanks!
Xuesen

On Thu, 2012-04-26 at 10:20 +0100, Ian Campbell wrote:
On Thu, 2012-04-26 at 10:13 +0100, Jan Beulich wrote:
> >>> On 26.04.12 at 10:54, Xuesen Guo <Xuesen.Guo@hitachiconsulting.com> wr=
ote:
> > Add the check of bzImage kernel and make it work
> > with RHEL 6 bzipped kernels
>=20
> I fail to see the relation of the term "bzipped" above to th=
e actual patch.

Oh yes, this is a common misconception (which I failed to notice in my
review).

The "bz" in bzImage does not refer to the bzip compression algori=
thm.
Rather it refers to "big zImage". It's a historical thing because=
 the
original zImage compressor was restricted to <1M (or something) of RAM
at decompression time and bzImage was introduced to cope with more and
therefore worked for larger kernels. Obviously 1M is very limiting to in
practice everyone uses bzImage today...

Now of course today, just to add to the confusion, bzImage can support
multiple compression algorithms, including the original z, but also
bzip2, lzma and xz.

Ian

>=20
> Jan
>=20
> > Signed-off-by: Xuesen Guo <Xuesen.Guo@hitachiconsulting.com>
> >=20
> > ---
> > Changed since v1:
> >   * add additional checks of the offset and length
> >   * not changing st.st_size, use size instead of st.st_size
> >=20
> > diff -r d690c7e896a2 -r 27a6422ac06d tools/xcutils/readnotes.c
> > --- a/tools/xcutils/readnotes.c=09Thu Apr 05 11:06:03 2012 +0100
> > +++ b/tools/xcutils/readnotes.c=09Thu Apr 26 16:53:17 2012 +0800
> > @@ -18,6 +18,48 @@
> > =20
> >  static xc_interface *xch;
> > =20
> > +/* According to the implemation of xc_dom_probe_bzimage_kernel()=
 function=20
> > */
> > +/* We add support of bzImage kernel */
> > +/* Copied from tools/libxc/xc_doom_bzImageloader.c */
> > +struct setup_header {
> > +=09uint8_t  _pad0[0x1f1];  /* skip uninteresting stuff */
> > +=09uint8_t  setup_sects;
> > +=09uint16_t root_flags;
> > +=09uint32_t syssize;
> > +=09uint16_t ram_size;
> > +=09uint16_t vid_mode;
> > +=09uint16_t root_dev;
> > +=09uint16_t boot_flag;
> > +=09uint16_t jump;
> > +=09uint32_t header;
> > +#define HDR_MAGIC  "HdrS"
> > +#define HDR_MAGIC_SZ 4
> > +=09uint16_t version;
> > +#define VERSION(h,l) (((h)<<8) | (l))
> > +=09uint32_t realmode_swtch;
> > +=09uint16_t start_sys;
> > +=09uint16_t kernel_version;
> > +=09uint8_t  type_of_loader;
> > +=09uint8_t  loadflags;
> > +=09uint16_t setup_move_size;
> > +=09uint32_t code32_start;
> > +=09uint32_t ramdisk_image;
> > +=09uint32_t ramdisk_size;
> > +=09uint32_t bootsect_kludge;
> > +=09uint16_t heap_end_ptr;
> > +=09uint16_t _pad1;
> > +=09uint32_t cmd_line_ptr;
> > +=09uint32_t initrd_addr_max;
> > +=09uint32_t kernel_alignment;
> > +=09uint8_t  relocatable_kernel;
> > +=09uint8_t  _pad2[3];
> > +=09uint32_t cmdline_size;
> > +=09uint32_t hardware_subarch;
> > +=09uint64_t hardware_subarch_data;
> > +=09uint32_t payload_offset;
> > +=09uint32_t payload_length;
> > +} __attribute__((packed));
> > +
> >  static void print_string_note(const char *prefix, struct elf_bin=
ary *elf,
> >  =09=09=09      const elf_note *note)
> >  {
> > @@ -131,6 +173,9 @@ int main(int argc, char **argv)
> >  =09const elf_shdr *shdr;
> >  =09int notes_found =3D 0;
> > =20
> > +=09struct setup_header *hdr;
> > +=09uint64_t payload_offset, payload_length;
> > +
> >  =09if (argc !=3D 2)
> >  =09{
> >  =09=09fprintf(stderr, "Usage: readnotes <elfimage>\n&=
quot;);
> > @@ -159,13 +204,45 @@ int main(int argc, char **argv)
> >  =09=09fprintf(stderr, "Unable to map %s: %s\n", f, str=
error(errno));
> >  =09=09return 1;
> >  =09}
> > -=09size =3D st.st_size;
> > +=09
> > +=09/* Check the magic of bzImage kernel */
> > +=09hdr =3D (struct setup_header *)image;
> > +=09if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) =3D=
=3D 0 )
> > +=09{
> > +=09=09if ( hdr->version < VERSION(2,8) )
> > +=09=09{
> > +=09=09=09printf("%s: boot protocol too old (%04x)", __=
FUNCTION__, hdr->version);
> > +=09=09=09return 1;
> > +=09=09}
> > =20
> > -=09usize =3D xc_dom_check_gzip(xch, image, st.st_size);
> > +=09=09/* upcast to 64 bits to avoid overflow */
> > +=09=09/* setup_sects is u8 and so cannot overflow */
> > +=09=09payload_offset =3D (hdr->setup_sects + 1) * 512;
> > +=09=09payload_offset +=3D hdr->payload_offset;
> > +=09=09payload_length =3D hdr->payload_length;
> > +=09=09
> > +=09=09if ( payload_offset >=3D st.st_size )
> > +=09=09{
> > +=09=09=09printf("%s: payload offset overflow", __FUNCT=
ION__);
> > +=09=09=09return 1;
> > +=09=09}
> > +=09=09if ( (payload_offset + payload_length) > st.st_size )
> > +=09=09{
> > +=09=09=09printf("%s: payload length overflow", __FUNCT=
ION__);
> > +=09=09=09return 1;
> > +=09=09}
> > +
> > +=09=09image =3D image + payload_offset;
> > +=09=09size =3D payload_length;
> > +=09} else {
> > +=09=09size =3D st.st_size;
> > +=09}
> > +
> > +=09usize =3D xc_dom_check_gzip(xch, image, size);
> >  =09if (usize)
> >  =09{
> >  =09=09tmp =3D malloc(usize);
> > -=09=09xc_dom_do_gunzip(xch, image, st.st_size, tmp, usize);
> > +=09=09xc_dom_do_gunzip(xch, image, size, tmp, usize);
> >  =09=09image =3D tmp;
> >  =09=09size =3D usize;
> >  =09}
> >=20
> > This e-mail is intended solely for the person or entity to which =
it is=20
> > addressed
> > and may contain confidential and/or privileged information. Any r=
eview,=20
> > dissemination,
> > copying, printing or other use of this e-mail by persons or entit=
ies other=20
> > than the=20
> > addressee is prohibited. If you have received this e-mail in erro=
r, please=20
> > contact
> > the sender immediately and delete the material from any computer.
> > To unsubscribe send an email to: Unsubscribe@hitachiconsulting.com=20
> > Hitachi Consulting (China) Co., Ltd. (HCCD0411)
> >=20
> >=20
> >=20
> > _______________________________________________
> > Xen-devel mailing list
> > Xen-devel@lists.xen.or=
g=20
> > http://lists.xen.org/x=
en-devel=20
>=20
>=20
>=20
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-de=
vel




--=-aZaC9Ufja/c88rSEtweD-- --===============3467935560755890166== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============3467935560755890166==--