aboutsummaryrefslogtreecommitdiffstats
path: root/hw/virtio-balloon.c
AgeCommit message (Collapse)AuthorFilesLines
2012-01-03virtio-balloon: avoid cpu_get_physical_page_desc()Avi Kivity1-4/+9
This reaches into the innards of the memory core, which are being changed. Switch to a memory API version. Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-27qapi: Convert query-balloonLuiz Capitulino1-64/+14
Please, note that some of the code supporting memory statistics is still around (eg. virtio_balloon_receive_stats() and reset_stats()). Also, the qmp_query_balloon() function is synchronous and thus doesn't make any use of the (not fully working) monitor's asynchronous command support (the old non-qapi implementation did). Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-09virtio-balloon: Disassociate from the balloon handlers on unplugAmit Shah1-0/+2
Adding a 2nd balloon device after unplugging the first one doesn't work. Also, the 'info balloon' command should indicate an error mentioning no balloon device is registered after unplug. Reproduction steps given by Shaolong Hu: (qemu) info balloon Device 'balloon' has not been activated by the guest (qemu) device_add virtio-balloon-pci,id=balloon1 (qemu) info balloon balloon: actual=4096 (qemu) balloon 2048 (qemu) info balloon balloon: actual=2048 (qemu) device_del balloon1 (qemu) info balloon balloon: actual=4096 (qemu) balloon 2048 (qemu) info balloon balloon: actual=4096 (qemu) device_del balloon1 Device 'balloon1' not found (qemu) device_add virtio-balloon-pci,id=balloon1 Another balloon device already registered Device 'virtio-balloon-pci' could not be initialized (qemu) device_add virtio-balloon-pci,id=balloon2 Another balloon device already registered Device 'virtio-balloon-pci' could not be initialized Reported-by: Shaolong Hu <shu@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-04virtio-balloon: Unregister savevm section on device unplugAmit Shah1-0/+4
Migrating after unplugging a virtio-balloon device resulted in an error message on the destination: Unknown savevm section or instance '0000:00:04.0/virtio-balloon' 0 load of migration failed Fix this by unregistering the section on device unplug. Signed-off-by: Amit Shah <amit.shah@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com>
2011-08-04virtio-balloon: Add exit handler, fix memleaksAmit Shah1-0/+5
Add an exit handler that will free up RAM after a virtio-balloon device is unplugged. Signed-off-by: Amit Shah <amit.shah@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com>
2011-08-04virtio-balloon: Check if balloon registration failedAmit Shah1-1/+8
Multiple balloon registrations are not allowed; check if the registration with the qemu balloon api succeeded. If not, fail the device init. Signed-off-by: Amit Shah <amit.shah@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com>
2011-08-04virtio-balloon: Fix header comment; add CopyrightAmit Shah1-1/+3
Signed-off-by: Amit Shah <amit.shah@redhat.com>
2011-08-04balloon: Separate out stat and balloon handlingAmit Shah1-5/+2
Passing on '0' as ballooning target to indicate retrieval of stats is bad API. It also makes 'balloon 0' in the monitor cause a segfault. Have two different functions handle the different functionality instead. Detailed explanation from Markus's review: 1. do_info_balloon() is an info_async() method. It receives a callback with argument, to be called exactly once (callback frees the argument). It passes the callback via qemu_balloon_status() and indirectly through qemu_balloon_event to virtio_balloon_to_target(). virtio_balloon_to_target() executes its balloon stats half. It stores the callback in the device state. If it can't send a stats request, it resets stats and calls the callback right away. Else, it sends a stats request. The device model runs the callback when it receives the answer. Works. 2. do_balloon() is a cmd_async() method. It receives a callback with argument, to be called when the command completes. do_balloon() calls it right before it succeeds. Odd, but should work. Nevertheless, it passes the callback on via qemu_ballon() and indirectly through qemu_balloon_event to virtio_balloon_to_target(). a. If the argument is non-zero, virtio_balloon_to_target() executes its balloon half, which doesn't use the callback in any way. Odd, but works. b. If the argument is zero, virtio_balloon_to_target() executes its balloon stats half, just like in 1. It either calls the callback right away, or arranges for it to be called later. Thus, the callback runs twice: use after free and double free. Test case: start with -S -device virtio-balloon, execute "balloon 0" in human monitor. Runs the callback first from virtio_balloon_to_target(), then again from do_balloon(). Reported-by: Mike Cao <bcao@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
2011-08-04virtio-balloon: Separate status handling into separate functionAmit Shah1-20/+31
Separate out the code to retrieve balloon info from the code that sets balloon values. This will be used to separate the two callbacks from balloon.c and help cope with 'balloon 0' on the monitor. Currently, 'balloon 0' causes a segfault in monitor_resume(). Signed-off-by: Amit Shah <amit.shah@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
2011-04-15Remove unused sysemu.h include directivesBlue Swirl1-1/+0
Remove unused sysemu.h include directives to speed up build with the following patches. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-04-07virtio-balloon: fixed endianness bug in the config spaceAlexey Kardashevskiy1-1/+1
The specification for the virtio balloon device requres that the values in the config space be encoded little-endian. This differs from most virtio things, where guest-native endian is the norm. Currently, the qemu virtio-balloon code correctly makes the conversion on get_config(), but doesn't on set_config for the 'actual' field. The kernel driver, on the other hand, correctly converts when setting the actual field, but does not convert when reading the config space. The upshot is that virtio-balloon will only work correctly if both host and guest are LE, making all the conversions nops. This patch corrects the qemu side, correctly doing host-native <-> LE conversions when accessing the config space. This won't break any setups that aren't already broken, and fixes the case of BE host, LE guest. Fixing the BE guest case will require kernel fixes as well. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-10-01disable guest-provided stats on "info balloon" commandEduardo Habkost1-1/+7
The addition of memory stats reporting to the virtio balloon causes the 'info balloon' command to become asynchronous. This is a regression because in some cases it can hang the user monitor. This is an alternative to Adam Litke's patch. Adam's patch disabled the corresponding (guest-visible) virtio feature bit, causing issues for migration. Original discussion is available at: http://marc.info/?l=qemu-devel&m=128448124328314&w=2 Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Acked-by: Adam Litke <agl@us.ibm.com Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2010-09-25Introduce qemu_madvise()Andreas Färber1-2/+2
vl.c has a Sun-specific hack to supply a prototype for madvise(), but the call site has apparently moved to arch_init.c. Haiku doesn't implement madvise() in favor of posix_madvise(). OpenBSD and Solaris 10 don't implement posix_madvise() but madvise(). MinGW implements neither. Check for madvise() and posix_madvise() in configure and supply qemu_madvise() as wrapper. Prefer madvise() over posix_madvise() due to flag availability. Convert all callers to use qemu_madvise() and QEMU_MADV_*. Note that on Solaris the warning is fixed by moving the madvise() prototype, not by qemu_madvise() itself. It helps with porting though, and it simplifies most call sites. v7 -> v8: * Some versions of MinGW have no sys/mman.h header. Reported by Blue Swirl. v6 -> v7: * Adopt madvise() rather than posix_madvise() semantics for returning errors. * Use EINVAL in place of ENOTSUP. v5 -> v6: * Replace two leftover instances of POSIX_MADV_NORMAL with QEMU_MADV_INVALID. Spotted by Blue Swirl. v4 -> v5: * Introduce QEMU_MADV_INVALID, suggested by Alexander Graf. Note that this relies on -1 not being a valid advice value. v3 -> v4: * Eliminate #ifdefs at qemu_advise() call sites. Requested by Blue Swirl. This will currently break the check in kvm-all.c by calling madvise() with a supported flag, which will not fail. Ideas/patches welcome. v2 -> v3: * Reuse the *_MADV_* defines for QEMU_MADV_*. Suggested by Alexander Graf. * Add configure check for madvise(), too. Add defines to Makefile, not QEMU_CFLAGS. Convert all callers, untested. Suggested by Blue Swirl. * Keep Solaris' madvise() prototype around. Pointed out by Alexander Graf. * Display configure check results. v1 -> v2: * Don't rely on posix_madvise() availability, add qemu_madvise(). Suggested by Blue Swirl. Signed-off-by: Andreas Färber <afaerber@opensolaris.org> Cc: Blue Swirl <blauwirbel@gmail.com> Cc: Alexander Graf <agraf@suse.de> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-07-06savevm: Add DeviceState paramAlex Williamson1-1/+2
When available, we'd like to be able to access the DeviceState when registering a savevm. For buses with a get_dev_path() function, this will allow us to create more unique savevm id strings. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-04-28iov: Add iov_to_buf and iov_size helpersAmit Shah1-31/+4
iov_to_buf() puts the buffer contents in the iov in a linearized buffer. iov_size() gets the length of the contents in the iov. The iov_to_buf() function is the memcpy_to_iovec() function that was used in virtio-ballon.c. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-27balloon: Fix overflow when reporting actual memory sizeAdam Litke1-1/+2
Beginning with its introduction, the virtio balloon has had an overflow error that causes 'info balloon' to misreport the actual memory size when the balloon itself becomes larger than 4G. Use a cast when converting dev->actual from pages to kB to prevent overflows. Before: (qemu) info balloon balloon: actual=5120 (qemu) balloon 1025 (qemu) info balloon balloon: actual=1025 (qemu) balloon 1024 (qemu) info balloon balloon: actual=5120 After: (qemu) info balloon balloon: actual=5120 (qemu) balloon 1025 (qemu) info balloon balloon: actual=1025 (qemu) balloon 1024 (qemu) info balloon balloon: actual=1024 Signed-off-by: Adam Litke <agl@us.ibm.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-03-17balloon: Do not save VM state wrt asynchronous virtio operationsAdam Litke1-9/+0
When working with the VM state (for loadvm/savevm and migration), it is not valid to load and store pointers since the validity of those pointers cannot be assured in the new qemu address space. Therefore, virtio_balloon_save() and virtio_balloon_load() must not handle the stats-related fields in struct VirtIOBalloon. If a memory stats request is in-flight at the time of a migration or savevm, the request will not complete and should be resubmitted once migration or loadvm completes. Note that this extremely small race window can only be triggered using QMP so it is not possible to hang the user monitor. Signed-off-by: Adam Litke <agl@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-26virtio: Add memory statistics reporting to the balloon driverAdam Litke1-4/+123
When using ballooning to manage overcommitted memory on a host, a system for guests to communicate their memory usage to the host can provide information that will minimize the impact of ballooning on the guests. The current method employs a daemon running in each guest that communicates memory statistics to a host daemon at a specified time interval. The host daemon aggregates this information and inflates and/or deflates balloons according to the level of host memory pressure. This approach is effective but overly complex since a daemon must be installed inside each guest and coordinated to communicate with the host. A simpler approach is to collect memory statistics in the virtio balloon driver and communicate them directly to the hypervisor. Signed-off-by: Adam Litke <agl@us.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-11virtio: add features as qdev propertiesMichael S. Tsirkin1-2/+2
Add feature bits as properties to virtio. This makes it possible to e.g. define machine without indirect buffer support, which is required for 0.10 compatibility, or without hardware checksum support, which is required for 0.11 compatibility. Since default values for optional features are now set by qdev, get_features callback has been modified: it sets non-optional bits, and clears bits not supported by host. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01Revert "Get rid of _t suffix"Anthony Liguori1-4/+4
In the very least, a change like this requires discussion on the list. The naming convention is goofy and it causes a massive merge problem. Something like this _must_ be presented on the list first so people can provide input and cope with it. This reverts commit 99a0949b720a0936da2052cb9a46db04ffc6db29. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01Get rid of _t suffixmalc1-4/+4
Some not so obvious bits, slirp and Xen were left alone for the time being. Signed-off-by: malc <av1474@comtv.ru>
2009-05-18Separate virtio PCI codePaul Brook1-15/+5
Split the PCI host bindings from the VRing transport implementation. Signed-off-by: Paul Brook <paul@codesourcery.com>
2009-05-14Virtio-balloon qdev conversionPaul Brook1-9/+9
Signed-off-by: Paul Brook <paul@codesourcery.com>
2009-05-14Virtio-net qdev conversionPaul Brook1-4/+8
Signed-off-by: Paul Brook <paul@codesourcery.com>
2009-04-10Yet more phys_ram_base elimination.pbrook1-1/+3
Signed-off-by: Paul Brook <paul@cofdesourcery.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7067 c046a42c-6fe2-441c-8c8c-71466251a162
2009-02-01Add and use #defines for PCI device classesblueswir11-1/+1
This patch adds and uses #defines for PCI device classes and subclases, using a new pci_config_set_class() function, similar to the recently added pci_config_set_vendor_id() and pci_config_set_device_id(). Change since v1: fixed compilation of hw/sun4u.c Signed-off-by: Stuart Brady <stuart.brady@gmail.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6491 c046a42c-6fe2-441c-8c8c-71466251a162
2009-01-26Use the default subsystem vendor ID for virtio devices (Mark McLoughlin)aliguori1-1/+2
A subsystem vendor ID of zero isn't allowed, so we use our default ID. Gerd points out that although the PCI subsystem vendor ID is treated by the guest as the virtio vendor ID: /* we use the subsystem vendor/device id as the virtio vendor/device * id. this allows us to use the same PCI vendor/device id for all * virtio devices and to identify the particular virtio driver by * the subsytem ids */ vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor; vp_dev->vdev.id.device = pci_dev->subsystem_device; it looks like only the device ID is used right now: # grep virtio modules.alias alias virtio:d00000001v* virtio_net alias virtio:d00000002v* virtio_blk alias virtio:d00000003v* virtio_console alias virtio:d00000004v* virtio-rng alias virtio:d00000005v* virtio_balloon alias pci:v00001AF4d*sv*sd*bc*sc*i* virtio_pci alias virtio:d00000009v* 9pnet_virtio so setting the subsystem vendor id to something != zero shouldn't cause trouble. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6440 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-11pci: virtio: use pci id defines (Gerd Hoffman)aliguori1-1/+2
Use the defines added by the previous patch in the virtio drivers. Also remove the pointless vendor and device args from the virtio_blk_init() function. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5987 c046a42c-6fe2-441c-8c8c-71466251a162
2008-12-04Add virtio-balloon supportaliguori1-0/+194
This adds a VirtIO based balloon driver. It uses madvise() to actually balloon the memory when possible. Until 2.6.27, KVM forced memory pinning so we must disable ballooning unless the kernel actually supports it when using KVM. It's always safe when using TCG. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5874 c046a42c-6fe2-441c-8c8c-71466251a162