Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 617711 - Domain XML parser doesn't reject invalid memory values
Domain XML parser doesn't reject invalid memory values
Status: CLOSED NEXTRELEASE
Product: Virtualization Tools
Classification: Community
Component: libvirt (Show other bugs)
unspecified
All Linux
low Severity medium
: ---
: ---
Assigned To: Eric Blake
:
Depends On:
Blocks: 813972
  Show dependency treegraph
 
Reported: 2010-07-23 15:20 EDT by jrodriguez
Modified: 2012-04-19 21:24 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-04-19 21:24:03 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description jrodriguez 2010-07-23 15:20:14 EDT
I defined how many RAM i want in a virtual machine in the XML of libvirt, but when i start this machine it say me other amount of RAM different with respect to XML. The line that construct libvirt to launch the kvm has a modifier (-m) that you can put the amount of RAM in megabytes that ou want, if in the XML you specified a 512MB of RAM, in the kvm line appear -m 0, and if you want 1024MB of ram, in the kvm line appear -m 1.

I use Libvirt 0.8.2 and qemu 0.12.3

The XML

<?xml version="1.0" encoding="UTF-8"?>
<domain type="kvm">
  <name>uml2</name>
  <memory>780M</memory>
  <vcpu>1</vcpu>
  <os>
    <type arch="i686">hvm</type>
    <boot dev="hd"/>
    <boot dev="cdrom"/>
  </os>
  <features>
    <pae/>
    <acpi/>
    <apic/>
  </features>
  <clock sync="localtime"/>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type="file" device="disk">
      <source file="/root/.vnx/simulations/tutorial-r1_xp/vms/uml2/fs/root_cow_fs"/>
      <target dev="hda"/>
    </disk>
    <disk type="file" device="cdrom">
      <source file="/root/.vnx/simulations/tutorial-r1_xp/vms/uml2/fs/opt_fs.iso"/>
      <target dev="hdb"/>
    </disk>
    <interface type="bridge" name="eth1" onboot="yes">
      <source bridge="Net0"/>
      <mac address="fe:fd:00:00:01:01"/>
    </interface>
    <graphics type="vnc" listen=""/>
    <serial type="unix">
      <source mode="bind" path="/root/.vnx/simulations/tutorial-r1_xp/vms/uml2/uml2_socket"/>
      <target port="1"/>
    </serial>
  </devices>
</domain>

The kvm line in /var/log/libvirt/qemu/uml2

LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin QEMU_AUDIO_DRV=none /usr/bin/kvm -S -M pc-0.12 -cpu qemu32 -enable-kvm -m 0 -smp 1 -name host1 -uuid 7c6fcf9b-ab6e-274f-8cd3-7a6a4aa17209 -chardev socket,id=monitor,path=/var/lib/libvirt/qemu/host1.monitor,server,nowait -monitor chardev:monitor -boot cd -drive file=/root/.vnx/simulations/simple_w7/vms/host1/fs/root_cow_fs,if=ide,index=0,boot=on -drive file=/root/.vnx/simulations/simple_w7/vms/host1/fs/opt_fs.iso,if=ide,media=cdrom,index=1 -net none -chardev socket,id=serial0,path=/root/.vnx/simulations/simple_w7/vms/host1/host1_socket,server,nowait -serial chardev:serial0 -parallel none -usb -vnc :0 -vga cirrus
Comment 1 Chris Lalancette 2010-07-23 17:49:28 EDT
(In reply to comment #0)
> <domain type="kvm">
>   <name>uml2</name>
>   <memory>780M</memory>

You've got two problems here.  The first is that the memory parameter is specified in kilobytes, not megabytes.  The second is that libvirt doesn't understand the M notation, so it's interpreting this as 780kb, essentially 0 (which is probably what it passes to kvm).

The only bug here is that we should reject invalid XML like yours; I'll change the subject and leave the bug open to track the error reporting.

Chris Lalancette
Comment 2 jrodriguez 2010-07-24 07:58:14 EDT
Thx!
Comment 3 Eric Blake 2012-04-18 17:51:10 EDT
I added support for libvirt XML to take input in megabytes (as in <memory unit='M'>780</memory>), and make it clear that output is in kibibytes, as of this patch in 0.9.11:

commit 2e22f23bde0ad6630a29d06ce164b6db8395f72c
Author: Eric Blake <eblake@redhat.com>
Date:   Mon Mar 5 14:52:07 2012 -0700

    xml: allow scaled memory on input
    
    Output is still in kibibytes, but input can now be in different
    scales for ease of typing.

However, I just checked that we _still_ don't reject <memory>780M</memory> as invalid, so I'll keep this bug open and add another patch.
Comment 4 Eric Blake 2012-04-18 20:17:04 EDT
Upstream patch posted:
https://www.redhat.com/archives/libvir-list/2012-April/msg00954.html
Comment 5 Eric Blake 2012-04-19 21:24:03 EDT
Now committed:

commit c09acad352039d896f45374a8241910fb207ae56
Author: Eric Blake <eblake@redhat.com>
Date:   Wed Apr 18 17:58:44 2012 -0600

    conf: tighten up XML integer parsing
    
    https://bugzilla.redhat.com/show_bug.cgi?id=617711 reported that
    even with my recent patched to allow <memory unit='G'>1</memory>,
    people can still get away with trying <memory>1G</memory> and
    silently get <memory unit='KiB'>1</memory> instead.  While
    virt-xml-validate catches the error, our C parser did not.
    
    Not to mention that it's always fun to fix bugs while reducing
    lines of code.  :)
    
    * src/conf/domain_conf.c (virDomainParseMemory): Check for parse error.
    (virDomainDefParseXML): Avoid strtoll.
    * src/conf/storage_conf.c (virStorageDefParsePerms): Likewise.
    * src/util/xml.c (virXPathLongBase, virXPathULongBase)
    (virXPathULongLong, virXPathLongLong): Likewise.

Note You need to log in before you can comment on or make changes to this bug.