Skip to contentSkip to conversation

libxl: initialize vfb defbools in libxlMakeVfb

PATCH Olaf Hering 3 participants 21 messages Apr 17, 2015 – May 6, 2015 7 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

  libxl_defbool_val(vfb.sdl.opengl));

If not, it should be initialized to false in libxlMakeVfb.

Olaf

#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

The assertion seems harsh considering the offense...

Quoted 17 lines

Initialize the relevant defbool variables in libxl_device_vfb.

---

Seen in 1.2.14.

  src/libxl/libxl_conf.c | 2 ++
  1 file changed, 2 insertions(+)
src/libxl/libxl_conf.c +0 -0
index 9b3c949..6feb7d9 100644

src/libxl/libxl_conf.c libxlMakeVfb(virPortAllocatorPtr graphicsports, · line 1235

Quoted 4 lines
src/libxl/libxl_conf.c +1 -0
@@ -1232,6 +1232,7 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
      switch (l_vfb->type) {
          case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
              libxl_defbool_set(&x_vfb->sdl.enable, 1);
+            libxl_defbool_set(&x_vfb->vnc.enable, 0);

Not shown here, but just before the switch is

     libxl_device_vfb_init(x_vfb);

which IIUC (looking at the impl in $xensrc/tools/libxl/_libxl_types.c) should initialize the vfb struct with default values.

Regards,
Jim

Quoted 12 lines
src/libxl/libxl_conf.c +1 -0
              if (VIR_STRDUP(x_vfb->sdl.display, l_vfb->data.sdl.display) < 0)
                  return -1;
              if (VIR_STRDUP(x_vfb->sdl.xauthority, l_vfb->data.sdl.xauth) < 0)
@@ -1239,6 +1240,7 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
              break;
          case  VIR_DOMAIN_GRAPHICS_TYPE_VNC:
              libxl_defbool_set(&x_vfb->vnc.enable, 1);
+            libxl_defbool_set(&x_vfb->sdl.enable, 0);
              /* driver handles selection of free port */
              libxl_defbool_set(&x_vfb->vnc.findunused, 0);
              if (l_vfb->data.vnc.autoport) {

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 11 lines · Olaf Hering
Quoted 4 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

   libxl_defbool_val(vfb.sdl.opengl));

I'm not aware of any way to specify OpenGL in libvirt domXML.

Quoted 1 line

If not, it should be initialized to false in libxlMakeVfb.

As before, seems like the init function should handle this.

Regards,
Jim

#5 lore raw
Quoted 6 lines · Jim Fehlig
Quoted 5 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

  libxl_defbool_val(vfb.sdl.opengl));

I'm not aware of any way to specify OpenGL in libvirt domXML.

The qemu-dm process runs without DISPLAY=0:0, which leads to a failure if sdl is enabled.

Once I will try to find the time I will see if setting DISPLAY= will actually help. xl.cfg(5) states that display= and xauthority= are currently not handled anyway. And libvirt lacks such functionality as well if I understand the docs correctly.

Olaf

#6 lore raw
In reply to Jim Fehlig
Quoted 11 lines · Jim Fehlig
Quoted 10 lines · Olaf Hering
Quoted 4 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

Quoted 7 lines
Quoted 1 line
   libxl_defbool_val(vfb.sdl.opengl));

I'm not aware of any way to specify OpenGL in libvirt domXML.

Quoted 1 line

If not, it should be initialized to false in libxlMakeVfb.

As before, seems like the init function should handle this.

As before, _not_ the init function, the setdefault within libxl should ensure that this is set to some value _before_ it is used. These changes are just hiding libxl bugs.

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

Ian.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 21 lines · Ian Campbell
Quoted 19 lines · Jim Fehlig
Quoted 6 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Quoted 8 lines
Quoted 2 lines

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

   libxl_defbool_val(vfb.sdl.opengl));

I'm not aware of any way to specify OpenGL in libvirt domXML.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

If not, it should be initialized to false in libxlMakeVfb.

As before, seems like the init function should handle this.

As before, _not_ the init function, the setdefault within libxl should ensure that this is set to some value _before_ it is used. These changes are just hiding libxl bugs.

Yes, I agree.

Quoted 5 lines

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

I was torn on committing Olaf's changes to the libvirt libxl driver, but in the end did so for the compatibility you noted.

Regards,
Jim

#9 lore raw
Quoted 34 lines · Jim Fehlig
Quoted 21 lines · Ian Campbell
Quoted 19 lines · Jim Fehlig
Quoted 6 lines · Olaf Hering
Quoted 3 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Quoted 8 lines
Quoted 2 lines

Initialize the relevant defbool variables in libxl_device_vfb.

Fix one crash, find another:

Does libvirt have a representation for this one?

   libxl_defbool_val(vfb.sdl.opengl));

I'm not aware of any way to specify OpenGL in libvirt domXML.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

If not, it should be initialized to false in libxlMakeVfb.

As before, seems like the init function should handle this.

As before, _not_ the init function, the setdefault within libxl should ensure that this is set to some value _before_ it is used. These changes are just hiding libxl bugs.

Yes, I agree.

Quoted 8 lines
Quoted 5 lines

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

I was torn on committing Olaf's changes to the libvirt libxl driver, but in the end did so for the compatibility you noted.

I just fear that the underlying issue will now not be diagnosed.

Ian.

#10 lore raw
In reply to a message not in the archive
Quoted 4 lines · Ian Campbell

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

The code flow was essentially like this:

libxl_device_vfb_init(libxl);
switch(libvirt->type) {
case SDL:

    libxl_defbool_set(libxl->sdl.enable, 1);
    break;
  case VNC:
    libxl_defbool_set(libxl->vnc.enable, 1);
    break;
}

if (libvirt->os.type == HVM) {

  if (libxl_defbool_val(libxl->vnc.enable)) {
    /* do VNC things */
  } else if (libxl_defbool_val(libxl->sdl.enable)) {
    /* do SDL things */
    if (libxl_defbool_val(libxl->opengl.enable))
      /* do openGL things */

}
}

The first crash was because I had SDL enabled, and the SDL case did not initialize the defbool for VNC. Once it did the next crash was the openGL part which was not initialized either.

I see nothing wrong with libxl in such usage.

Olaf

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw
Quoted 30 lines · Olaf Hering
Quoted 4 lines · Ian Campbell

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

The code flow was essentially like this:

libxl_device_vfb_init(libxl);
switch(libvirt->type) {
case SDL:

    libxl_defbool_set(libxl->sdl.enable, 1);
    break;
  case VNC:
    libxl_defbool_set(libxl->vnc.enable, 1);
    break;
}

if (libvirt->os.type == HVM) {

  if (libxl_defbool_val(libxl->vnc.enable)) {
    /* do VNC things */
  } else if (libxl_defbool_val(libxl->sdl.enable)) {
    /* do SDL things */
    if (libxl_defbool_val(libxl->opengl.enable))
      /* do openGL things */

}
}

Quoted 5 lines

The first crash was because I had SDL enabled, and the SDL case did not initialize the defbool for VNC. Once it did the next crash was the openGL part which was not initialized either.

I see nothing wrong with libxl in such usage.

I've explained this repeatedly now, it is a bug in libxl if the above ends up crashing in libxl.

It is always a *libxl bug* for a libxl code path to lead a use of libxl_defbool_val on a value which has not had the appropriate setdefault called on it *by libxl*. It is not required for the user of libxl to initialise any defbool (other than via the libxl_TYPE_init function, which should set it to the explicit "default" value).

It is therefore a bug if libxl reaches this code without having ensured that libxl_defbool_setdefault has been called *by libxl* on libxl->opengl.enable (perhaps on if libxl->sdl.enable is true).

I see no code in libxl which matches what you have above, the only call to libxl_device_vfb_init has no switch statement or if == HVM anywhere near it.

Please provide the actual stack trace as requested so we can see which code path in libxl is failing to properly initialise the defbools.

Ian.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw
Quoted 31 lines · Ian Campbell
Quoted 30 lines · Olaf Hering
Quoted 4 lines · Ian Campbell

Olaf, please can you use gdb to capture the stack trace so we can fix this (and the other issue) properly in libxl instead of just hacking around it in libvirt (which might also be appropriate for compat with old libxl but shouldn't be done without also fixing libxl IMHO).

The code flow was essentially like this:

libxl_device_vfb_init(libxl);
switch(libvirt->type) {
case SDL:

    libxl_defbool_set(libxl->sdl.enable, 1);
    break;
  case VNC:
    libxl_defbool_set(libxl->vnc.enable, 1);
    break;
}

if (libvirt->os.type == HVM) {

  if (libxl_defbool_val(libxl->vnc.enable)) {
    /* do VNC things */
  } else if (libxl_defbool_val(libxl->sdl.enable)) {
    /* do SDL things */
    if (libxl_defbool_val(libxl->opengl.enable))
      /* do openGL things */

}
}

Quoted 8 lines
Quoted 5 lines

The first crash was because I had SDL enabled, and the SDL case did not initialize the defbool for VNC. Once it did the next crash was the openGL part which was not initialized either.

I see nothing wrong with libxl in such usage.

Please provide the actual stack trace as requested so we can see which code path in libxl is failing to properly initialise the defbools.

Ah, one moment, are you saying that all this code is within libvirt and not in libxl and that the "libxl->" object here hasn't yet been passed to a libxl function?

If so then yes it is a libvirt bug to use libxl_defbool_val(libxl->opengl.enable) without having called set on it first. If you passed such a thing to libxl and it crashed then that would be a libxl bug, but it seems you aren't getting that far.

I was confused by the initial message because the assert says libxl.c, but that's just because it is out of line, which lead to a confusing error message. Sorry for leading the conversation down the wrong alley way.

Ian.

#15 lore raw
In reply to a message not in the archive
Quoted 22 lines · Ian Campbell
Quoted 13 lines · Olaf Hering

The code flow was essentially like this:

libxl_device_vfb_init(libxl);
switch(libvirt->type) {
case SDL:

    libxl_defbool_set(libxl->sdl.enable, 1);
    break;
  case VNC:
    libxl_defbool_set(libxl->vnc.enable, 1);
    break;
}

if (libvirt->os.type == HVM) {

Quoted 8 lines
  if (libxl_defbool_val(libxl->vnc.enable)) {
    /* do VNC things */
  } else if (libxl_defbool_val(libxl->sdl.enable)) {
    /* do SDL things */
    if (libxl_defbool_val(libxl->opengl.enable))
      /* do openGL things */

}
}

Quoted 3 lines

I see no code in libxl which matches what you have above, the only call to libxl_device_vfb_init has no switch statement or if == HVM anywhere near it.

This is libvirt code, no libxl involved other than using the defbool API.

Olaf

#16 lore raw
In reply to a message not in the archive
Quoted 9 lines · Olaf Hering
Quoted 5 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Initialize the relevant defbool variables in libxl_device_vfb.

Quoted 8 lines

Fix one crash, find another:

Does libvirt have a representation for this one?

  libxl_defbool_val(vfb.sdl.opengl));

If not, it should be initialized to false in libxlMakeVfb.

Hrm, missed adding this before pushing your original patch. I'm going to push a trivial follow-up.

Regards,
Jim

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw
Quoted 8 lines · Jim Fehlig
Quoted 1 line · Olaf Hering

+ libxl_defbool_set(&x_vfb->vnc.enable, 0);

Not shown here, but just before the switch is

     libxl_device_vfb_init(x_vfb);

which IIUC (looking at the impl in $xensrc/tools/libxl/_libxl_types.c) should initialize the vfb struct with default values.

Yes, but the default values lead to the assert.

Olaf

#19 lore raw
In reply to a message not in the archive
Quoted 5 lines · Jim Fehlig
Quoted 2 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

The assertion seems harsh considering the offense...

libxl should be setting a default for this value if the application hasn't, by calling libxl__device_vfb_setdefault at some correct point.

Not to say the application shouldn't also set it if it has a different default preference, but there is a libxl bug here somewhere too.

Ian.

#20 lore raw
Quoted 9 lines · Ian Campbell
Quoted 5 lines · Jim Fehlig
Quoted 2 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

The assertion seems harsh considering the offense...

libxl should be setting a default for this value if the application hasn't, by calling libxl__device_vfb_setdefault at some correct point.

This is an internal function. Its up to the caller of libxl_device_vfb_init to initialize the defbool members.

Olaf

#21 lore raw
Quoted 7 lines · Olaf Hering
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Jim Fehlig
Quoted 2 lines · Olaf Hering

If the domU configu has sdl enabled libvirtd crashes:
libvirtd[5158]: libvirtd: libxl.c:343: libxl_defbool_val: Assertion `!libxl_defbool_is_default(db)' failed.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

The assertion seems harsh considering the offense...

libxl should be setting a default for this value if the application hasn't, by calling libxl__device_vfb_setdefault at some correct point.

This is an internal function. Its up to the caller of libxl_device_vfb_init to initialize the defbool members.

No, it isn't. It's up to libxl to call libxl__device_vfb_setdefault somewhere on the code path between entering the library and actually using this defbool. (Possibly indirectly via the containing struct in this case)

We normally do this as close to entry into the library as we can, e.g. in the libxl_device_FOO_add or e.g. in libxl_domain_create.

It is always a libxl bug if a defbool gets used without having had a defaulted value applied by the library first, hence the assert.

If what you said were true then an assert would be a rather harsh overreaction to an application coding error.

Ian.

#22 lore raw
Quoted 2 lines · Ian Campbell

If what you said were true then an assert would be a rather harsh overreaction to an application coding error.

Currently both libxl and libvirt are coded that way. Since the sdl code path in libvirt was never executed the crash in libxlMakeVfbList was not noticed.

So you are saying that an external user of libxl_device_vfb_init has to call yet another function to initialize all defbool to give them either true of false? Or should libxl_device_vfb_init call libxl__device_vfb_setdefault directly?

Olaf

#23 lore raw
Quoted 5 lines · Olaf Hering
Quoted 2 lines · Ian Campbell

If what you said were true then an assert would be a rather harsh overreaction to an application coding error.

Quoted 9 lines

Currently both libxl and libvirt are coded that way. Since the sdl code path in libvirt was never executed the crash in libxlMakeVfbList was not noticed.

So you are saying that an external user of libxl_device_vfb_init has to call yet another function to initialize all defbool to give them either true of false? Or should libxl_device_vfb_init call libxl__device_vfb_setdefault directly?

Neither.

Any code within libxl which consumes a libxl_device_vfb must, at some point before touching the defbools therein, have arranged to call the appropriate setdefaults function.

It makes no sense to do that at init time, the whole purpose of a defbool is to allow the calling application to choose a value or to explicitly leave it as a request to for the default (which might vary depending on other selections).

It is up to *libxl* to convert such requests for default behaviour into a specific value before trying to use it, that is the purpose of the internal setdefaults functions and for the assert when reading a defbool.

Ian.

#24 lore raw
Quoted 4 lines · Ian Campbell

It makes no sense to do that at init time, the whole purpose of a defbool is to allow the calling application to choose a value or to explicitly leave it as a request to for the default (which might vary depending on other selections).

Yes, and thats why my patch does?

libxl_device_vfb_init(x_vfb);
+libxl_defbool_set(&x_vfb->sdl.opengl, 0);
if (libxl_defbool_val(vfb.sdl.opengl))
;

Olaf

#25 lore raw
Quoted 8 lines · Olaf Hering
Quoted 4 lines · Ian Campbell

It makes no sense to do that at init time, the whole purpose of a defbool is to allow the calling application to choose a value or to explicitly leave it as a request to for the default (which might vary depending on other selections).

Yes, and thats why my patch does?

This is a libvirt patch. It might be correct in its own right, if libvirt has different ideas about the defaults to libxl, but it is also masking an underlying libxl bug.

Ian.

Quoted 7 lines

libxl_device_vfb_init(x_vfb);
+libxl_defbool_set(&x_vfb->sdl.opengl, 0);
if (libxl_defbool_val(vfb.sdl.opengl))
;

Olaf

A message that is not in the archive (sent off-list or not yet received): [email protected]

#27 lore raw
Quoted 9 lines · Olaf Hering
Quoted 6 lines · Jim Fehlig
Quoted 2 lines · Olaf Hering

+ libxl_defbool_set(&x_vfb->vnc.enable, 0);

Not shown here, but just before the switch is

Quoted 8 lines
Quoted 5 lines
     libxl_device_vfb_init(x_vfb);

which IIUC (looking at the impl in $xensrc/tools/libxl/_libxl_types.c) should initialize the vfb struct with default values.

Yes, but the default values lead to the assert.

Ok, best to be a bit defensive. I've pushed the patch now.

Regards,
Jim