Skip to contentSkip to conversation

tools/libxc: Fix construction of HVM guests with non-default firmware

PATCH In review Andrew Cooper 3 participants 7 messages Nov 11, 2015 – Nov 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: Fix construction of HVM guests with non-default firmware

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers" introduced a regression building HVM domains in combination with the libxl "firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would happily load ELF64 images which contained a stub to switch into long mode.

It is convenient for the ELF file to match the intended runmode rather than the starting runmode. As such, don't make an arbitrary restriction.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

My Xen Test Framework (which is almost ready to be formally presented on xen-devel) uses ELF32/ELF64 for the intended runmode to make compiling/disassembling easier.

At the point that the developer is specifying firmware_override, they are into "just do what I tell you" territory, and can keep both pieces if they have actually passed a broken firmware.

This change has actually regressed XenServers automated testing against xen-upstream, which does make use of the Test Framework.

---
 tools/libxc/xc_dom_hvmloader.c | 7 -------
 1 file changed, 7 deletions(-)
tools/libxc/xc_dom_hvmloader.c +0 -7
index 79a3b99..0cf9887 100644
@@ -107,13 +107,6 @@ static elf_errorstatus xc_dom_parse_hvm_kernel(struct xc_dom_image *dom)
         return rc;
     }
 
-    if ( !elf_32bit(elf) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image is not 32bit",
-                     __func__);
-        return -EINVAL;
-    }
-
     /* parse binary and get xen meta info */
     elf_parse_binary(elf);
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw

El 11/11/15 a les 21.18, Andrew Cooper ha escrit:

Quoted 11 lines

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers" introduced a regression building HVM domains in combination with the libxl "firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would happily load ELF64 images which contained a stub to switch into long mode.

It is convenient for the ELF file to match the intended runmode rather than the starting runmode. As such, don't make an arbitrary restriction.

Sorry for the breakage, I actually added that check to make the domain building more sane, but didn't know there where such use cases, so:

TBH, I though that ELF64 binaries that have a 32bit entry point would always specify their type as ELF32 (IIRC that's what Xen itself does).

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers" introduced a regression building HVM domains in combination with the libxl
"firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would happily load ELF64 images which contained a stub to switch into long mode.

IOW a ELF64 with 32-bit code at its entry point? Is that entry point the ELF entry point or the special Xen entry point located via the notes?

I think you likely mean the latter, in which case I'm ok with this change if that entry point is explicitly documented to be 32-bit irrespective of the containing ELF file (either the commit message should mention this is already the case or the patch should update the docs to make it so).

I'm sure I saw this getting documented in patches at some point but I can't actually find them. All I found was docs/misc/pvh-readme.txt which discusses original pvh and not dmlite, so I'm pretty sure that is the wrong place to be looking.

In any case I think for the purposes of supporting users who have done something odd by accident rather than design it would be worthwhile to log the type of ELF file somewhere, perhaps we already do, but I couldn't find it if so.

Quoted 37 lines

It is convenient for the ELF file to match the intended runmode rather than the starting runmode.  As such, don't make an arbitrary restriction.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

My Xen Test Framework (which is almost ready to be formally presented on xen-devel) uses ELF32/ELF64 for the intended runmode to make compiling/disassembling easier.

At the point that the developer is specifying firmware_override, they are into "just do what I tell you" territory, and can keep both pieces if they have actually passed a broken firmware.

This change has actually regressed XenServers automated testing against xen-upstream, which does make use of the Test Framework.
---
 tools/libxc/xc_dom_hvmloader.c | 7 -------

 1 file changed, 7 deletions(-)
tools/libxc/xc_dom_hvmloader.c +0 -0
index 79a3b99..0cf9887 100644
@@ -107,13 +107,6 @@ static elf_errorstatus
 xc_dom_parse_hvm_kernel(struct xc_dom_image *dom)
          return rc;
      }


-    if ( !elf_32bit(elf) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image is not

Quoted 8 lines

32bit",
-                     __func__);
-        return -EINVAL;
-    }
-
     /* parse binary and get xen meta info */
     elf_parse_binary(elf);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Andrew Cooper

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers" introduced a regression building HVM domains in combination with the libxl
"firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would happily load ELF64 images which contained a stub to switch into long mode.

Quoted 7 lines

IOW a ELF64 with 32-bit code at its entry point? Is that entry point the ELF entry point or the special Xen entry point located via the notes?

I think you likely mean the latter, in which case I'm ok with this change if that entry point is explicitly documented to be 32-bit irrespective of the containing ELF file (either the commit message should mention this is already the case or the patch should update the docs to make it so).

I mean the former. This has nothing to do with DMLite guests, so no elfnotes are involved.

I realise that strictly speaking the elf check should match. However, it always used to work, and is sufficiently convenient for development purposes that I feel the check is more problematic than helpful. (Postprocessing the linked binary from 64bit to 32bit elf is an extra step which also makes it harder to disassemble.)

~Andrew

#4 lore raw
Quoted 24 lines · Andrew Cooper
Quoted 15 lines · Ian Campbell
Quoted 10 lines · Andrew Cooper

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers"
introduced a regression building HVM domains in combination with the libxl
"firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would
happily load ELF64 images which contained a stub to switch into long mode.

IOW a ELF64 with 32-bit code at its entry point? Is that entry point the
ELF entry point or the special Xen entry point located via the notes?

Quoted 7 lines

I think you likely mean the latter, in which case I'm ok with this change
if that entry point is explicitly documented to be 32-bit irrespective of
the containing ELF file (either the commit message should mention this is
already the case or the patch should update the docs to make it so).

Quoted 8 lines

I mean the former.  This has nothing to do with DMLite guests, so no elfnotes are involved.

I realise that strictly speaking the elf check should match.  However, it always used to work, and is sufficiently convenient for development purposes that I feel the check is more problematic than helpful. (Postprocessing the linked binary from 64bit to 32bit elf is an extra step which also makes it harder to disassemble.)

An ELF file which says it is class ELF32 but has 64bit code at the entry point is IMHO malformed.

I think that the fact this used to work is a misfeature, however convenient you may have found it.

Kernels which wish to do this should IMHO do as Xen does and have a mkelf32.c step. You can still run gdb or whatever using the original ELF file.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 35 lines · Ian Campbell
Quoted 23 lines · Andrew Cooper
Quoted 15 lines · Ian Campbell
Quoted 10 lines · Andrew Cooper

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers"
introduced a regression building HVM domains in combination with the libxl
"firmware_override=" option.

The older HVM building code (now removed) had no 32bit ELF check, so would
happily load ELF64 images which contained a stub to switch into long mode.

IOW a ELF64 with 32-bit code at its entry point? Is that entry point the
ELF entry point or the special Xen entry point located via the notes?

Quoted 7 lines

I think you likely mean the latter, in which case I'm ok with this change
if that entry point is explicitly documented to be 32-bit irrespective of
the containing ELF file (either the commit message should mention this is
already the case or the patch should update the docs to make it so).

Quoted 8 lines

I mean the former. This has nothing to do with DMLite guests, so no elfnotes are involved.

I realise that strictly speaking the elf check should match. However, it always used to work, and is sufficiently convenient for development purposes that I feel the check is more problematic than helpful. (Postprocessing the linked binary from 64bit to 32bit elf is an extra step which also makes it harder to disassemble.)

An ELF file which says it is class ELF32 but has 64bit code at the entry point is IMHO malformed.

Quoted 6 lines

I think that the fact this used to work is a misfeature, however convenient you may have found it.

Kernels which wish to do this should IMHO do as Xen does and have a mkelf32.c step. You can still run gdb or whatever using the original ELF file.

It turns out that

OUTPUT_FORMAT("elf32-x86-64")

is a thing for linker scripts.

I have updated the framework to use that for 64bit hvm tests, and everything appears to be working.

~Andrew

#6 lore raw
Quoted 56 lines · Andrew Cooper
Quoted 46 lines · Ian Campbell
Quoted 34 lines · Andrew Cooper
Quoted 20 lines · Ian Campbell
Quoted 7 lines · Andrew Cooper

c/s 1ee15d7 "libxl: switch HVM domain building to use xc_dom_* helpers"
introduced a regression building HVM domains in combination with the
libxl
"firmware_override=" option.

Quoted 6 lines

The older HVM building code (now removed) had no 32bit ELF check, so
would
happily load ELF64 images which contained a stub to switch into long
mode.

IOW a ELF64 with 32-bit code at its entry point? Is that entry point
the
ELF entry point or the special Xen entry point located via the notes?

Quoted 10 lines

I think you likely mean the latter, in which case I'm ok with this change
if that entry point is explicitly documented to be 32-bit irrespective
of
the containing ELF file (either the commit message should mention this
is
already the case or the patch should update the docs to make it so).

I mean the former.  This has nothing to do with DMLite guests, so no elfnotes are involved.

Quoted 7 lines

I realise that strictly speaking the elf check should match.  However,
it always used to work, and is sufficiently convenient for development
purposes that I feel the check is more problematic than helpful. (Postprocessing the linked binary from 64bit to 32bit elf is an extra step which also makes it harder to disassemble.)

An ELF file which says it is class ELF32 but has 64bit code at the entry
point is IMHO malformed.

Quoted 8 lines

I think that the fact this used to work is a misfeature, however convenient
you may have found it.

Kernels which wish to do this should IMHO do as Xen does and have a mkelf32.c step. You can still run gdb or whatever using the original ELF
file.

Quoted 8 lines

It turns out that

OUTPUT_FORMAT("elf32-x86-64")

is a thing for linker scripts.

I have updated the framework to use that for 64bit hvm tests, and everything appears to be working.

Great. I shall consider this patch withdrawn then.

Thanks for letting us know.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel