libxc: Replace alloca() with mmap() for large array sizes

Replace alloca() with mmap() for array sizes greater than a page in
xc_linux_osdep.c.

When mapping in large amounts of pages (in the GB range) from a guest
in to Dom0 using xc_map_foreign_bulk(), a segfault occurs in the libxc
client application. This is because the pfn array in
linux_privcmd_map_foreign_bulk() is being allocated using alloca() and
the subsequent memcpy causes the stack to blow. This patch replaces
the alloca() with mmap() for pfn array sizes greater than a page.

Fix an error print with the correct function name.

Do the same for the map array in linux_gnttab_grant_map()

Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com>
Acked-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: use qemu-xen with PV guests by default

qemu-xen offers better disk performances than qemu-xen-traditional
because it supports Linux native AIO: use it for PV guests if it is
available.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
xl: add support for vif rate limiting

The `rate` keyword specifies the rate at which the outgoing traffic
will be limited to. The default if this keyword is not specified
is unlimited.

The `rate` keyword supports an optional replenishment interval
parameter for specifying the granularity of credit replenishment.
It determines the frequency at which the vif transmission credit
is replenished. The default interval is 50ms.

For example:

        'rate=10Mb/s'
        'rate=250KB/s'
        'rate=1MB/s@20ms'

Signed-off-by: Mathieu Gagne <mgagne@iweb.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
xl: add "check-xl-vif-parse" test script

This test script runs "xl -N network-attach 0 <foobar>" against various
rate syntax and checks that the output is as expected.

[ Added entries to .hgignore and .gitignore for tools/libxl/tmp.* -iwj ]

Signed-off-by: Mathieu Gagne <mgagne@iweb.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
autoconf: add ovmf, rombios and seabios and configure options

Move this hardcoded options from Config.mk to config/Tools.mk and add the
appropiate configure options.

Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: Remove libxl_tmem_destroy and associated xl command

Dan Magenheimer explains in <4c2f7fca-dda2-4598-aaab-3a6a3fe532cd@default>:

	I think the tmem_destroy functionality pre-dates the
	existence of tmem "freeable" memory* and was a way for
	a toolset to force the hypervisor to free up the hypervisor
	memory used by some or all ephemeral tmem pools.  Once the
	tmem allocation/free process was directly linked into
	alloc_heap_pages() in the hypervisor (see call to
	tmem_relinquish_pages()), this forcing function was
	no longer needed.

	So, bottom line, I *think* it can be ripped out, or at least
	for now removed from the definition of the stable xl API/UI.
	The libxl.c routine libxl_tmem_destroy() could also be
	removed if you like, but I guess I'd prefer to leave the
	lower level droppings in xc.c and in the hypervisor in case
	I am misremembering.

Accordingly remove this interface from libxl and xl but don't touch libxc or
the hypervisor.

This is the only libxl_tmem_* function which might potentially have required
conversion to be asynchronous and which therefore might have been a potential
API stability concern.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
libxl: fix rtc_timeoffset setting

libxl__domain_build_info_setdefault may be called several times,
so rtc_timeoffset can't be setted in it.

Move rtc_timeoffset setting logic to libxl__build_pre.

Reported-by: Teck Choon Giam <giamteckchoon@gmail.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Lin Ming <mlin@ss.pku.edu.cn>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---
 tools/libxl/libxl_create.c |    9 ---------
 tools/libxl/libxl_dom.c    |   17 +++++++++++++++--
 2 files changed, 15 insertions(+), 11 deletions(-)
tools/blktap: fix build error w/o MEMSHR

Do not include memshr.h when MEMSHR is not defined.
Fixes build error when MEMSHR is disabled.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools: xen-access: Check return values and clean up on errors during init

Check the return values of the libxc mem_access calls.  Free allocated
structures (platform_info, domain_info) on errors during
initialization and exit.  Unbind VIRQ, close event channel and
connection to Xen on errors during initialization

Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/build: fix distclean

distclean removed config/Tools.mk which was needed by tools/Rules.mk, thus
preventing distclean from running properly in the tools directory. This patch
only enforces config/Tools.mk presence when not performing a clean/distclean
target

Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Cc: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools: Fix FPU save area definition in xen-hvmctx

Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Tim Deegan <tim@xen.org>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: mark internal functions hidden

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
autoconf: use python-config when present, if not switch to distuti

Use python-config utility when possible, and if it is not present switch to
distutils.

Should fix the bug reported by Olaf Hering on SuSE.

Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: make most libxl_FOO_path() functions internal.

Only libxl_xen_config_dir_path and libxl_lock_dir_path are used outside the
library. Also bindir, sbindir, sharedir and xenpagingdir appeared to be
completely unused so nuke them.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
xl, cpupools: Create empty pool if no cpus are specified

Currently, if "xl cpupool-create" is called with no cpus configured,
xl will choose a cpu at random from the list of unassigned cpus, and
if no unassigned cpus are available, it will fail.

This seems to me to be a poor interface.  For one, it makes it impossible
to create an empty cpupool using the xl command-line, except by creating
a pool and then removing the cpus from it.  For two, I don't think assigning
a random cpu is a feature; it's not unreasonable for the user to specify
which cpus to add to which pools.

This patch changes the behavior of "xl cpupool-create" to create an empty
pool if no cpus are specified.  I believe this interface to be more expected
and more script-friendly.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
[v2] xl: Don't require a config file for cpupools

Since the key information can be fairly simply put on the command-line,
there's no need to require an actual config file.

Also improve the help to cross-reference the xlcpupool.cfg manpage.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: provide libxl_domain_config_init.

Currently this struct is too complicated for the IDL to represent (arrays) so
for now implement by hand.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
x86/mem_sharing: Clean up debugging calls

- Remove debug_mfn from the user-space interface
- Clean up errno codes

Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxc: Document the sharing interface

(also make note about AMD support's experimental status)

Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla>
Acked-by: Tim Deegan <tim@xen.org>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
libxl: passthrough: avoid passing through devices not owned by pciback

This patch makes sure the passthrough device belongs to pciback before
allow them passthrough to the guest.  There are still many other
checks missing.

xm terminates the guest startup process when this type of condition is
found.  This patch just allows the guest to continue to boot but with
no device passthrough.

Signed-off-by: Allen Kay <allen.m.kay@intel.com>
Signed-off-by: Xudong Hao <xudong.hao@intel.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>