libxl: build a device tree for ARM guests

Uses xc_dom_devicetree_mem which was just added. The call to this needs to be
carefully sequenced to be after xc_dom_parse_image (so we can tell which kind
of guest we are building, although we don't use this yet) and before
xc_dom_mem_init which tries to decide where to place the FDT in guest RAM.

Removes libxl_noarch which would only have been used by IA64 after this
change. Remove IA64 as part of this patch.

There is no attempt to expose this as a configuration setting for the user.

Includes a debug hook to dump the dtb to a file for inspection.

On v7 the CPU compat is currently hardcoded to cortex-a15. This likely wants
to change at some point.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Merge branch 'staging' of ssh://xenbits.xen.org/home/xen/git/xen into staging
xen/arm: gic: don't use dom0 variable in gicv_setup

The commit 99bf30a "xen: arm: define guest virtual platform in API headers"
modifies gicv_setup to either use harcoded addresses for guest or hardware
addresses for dom0. In the latter case, the variable dom0 is not yet
initialized. dom0 receives assignment by the return of domain_create which
calls gicv_setup.
Use the ID to know whether the domain is dom0 or not.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen: Check if the range is valid in init_domheap_pages

On ARM, when an initrd is given to xen by U-boot, it will reserve the memory
in the device tree.
In this case, when xen decides to free unused memory, dt_unreserved_regions
will call init_domheap_pages with the start and the end of range equals. But
the latter assumes that (start > end), if not Xen will hang because the
number of pages is equals to (unsigned)-1.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Keir Fraser <keir@xen.org>
Acked-by: Ian Campbell <Ian.campbell@citrix.com>
CC: Jan Beulich <jbeulich@suse.com>
libxl: arm: ensure DTB is page aligned

xc_dom_alloc_segment requires this. Since rambase and ramend are both page
aligned, rounding up the DTB is sufficient.

Reported-by: Julien Grall <julien.grall@linaro.org>
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
libxl: fix use of aodev->dev after free

Coverity-ID: 1130521
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
hotplug/Linux: update to new ip command syntax.

The current usage prevents naming a vif "dev". Although the current syntax is
documented in Squeeze's ip(8) it appears that this was a documentation bug.
Newer versions of the man page describe the new syntax used here and Squeeze's
implementation accepts it as well.

This is Debian bug #705659.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705659

Mike provided the initial patch to tools/hotplug/Linux/xen-network-common.sh
and Ian extended it to catch some cases in vif-* too.

Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Mike <debian@good-with-numbers.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: George Dunlap <george.dunlap@eu.citrix.com>
libxl: event system: pass gc, not just ctx, to internal sigchld manipulators

We are going to want the gc for libxl__ev_fd_register.

No functional change in this patch.  Simply change the argument types,
and the actual arguments from ctx to gc.  Inside these functions, use
CTX (the macro which uses gc) rather than the old formal parameter
ctx.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
libxl: event system: Make libxl_sigchld_owner_libxl_always work

Previously, libxl_sigchld_owner_libxl_always was mishandled.  It would
result in libxl paying no attention to the sigchld self pipe.

Fix this by fixing chldmode_ours so that it returns true iff we are
supposed to be handling SIGCHLD.

Additionally, we arrange to use chldmode_ours everywhere where we are
installing/removing signal handlers and/or deciding whether to check
the self pipe, etc.  This means it needs a new "creating" flag
argument for the benefit of libxl__ev_child_fork, which needs to
install the signal handler in libxl_sigchld_owner_libxl even if there
are not currently any children.

ctx->childproc_hooks->chldowner is now interpreted only by
chldmode_ours.

Reported-by: Bamvor Jian Zhang <bjzhang@suse.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Bamvor Jian Zhang <bjzhang@suse.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>

---
v2: Get sense of chldmode test right in perhaps_removehandler (!)
libxl: event system: properly register the SIGCHLD self-pipe

An application which uses libxl_osevent_register_hooks, and doesn't
use libxl_sigchld_owner_mainloop, would never properly experience the
deaths of its (libxl) children.

This is because the SIGCHLD self pipe would be handled using ad-hoc
code in beforepoll_internal and afterpoll_internal.  However, this is
no good if application is using the fd registration system instead; in
that case these functions would not be called and nothing would deal
with readability of the self pipe.

Fix this as follows:

The SIGCHLD self pipe now is now dealt with by a standard libxl__ev_fd
handler, which is registered and deregistered along with the SIGCHLD
handler itself.  The handler function subsumes the ad-hoc response
code removed from beforepoll_internal, and the functionality of
libxl__fork_selfpipe_woken.

This is also tidier as the SIGCHLD self pipe is no longer touched
outside libxl_fork.c other than in ctx initialisation and teardown.

(The ad-hoc arrangements for poller->wakeup_pipe in
beforepoll_internal and afterpoll_internal are OK because the
libxl__poller mechanism exists to wake up threads which are sitting
inside libxl's poll loop, so is not applicable to the application's
event loop.)

Reported-by: Bamvor Jian Zhang <bjzhang@suse.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Bamvor Jian Zhang <bjzhang@suse.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
.gitignore: Ignore tools/ocaml/libs/xentoollog/ build outputs

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
x86/stack: refactor show_trace()

Before, show_trace() had two implementations depending on
CONFIG_FRAME_POINTER.  Some parts were common, while the loops to wander up
the stack were different.

The version aided by frame pointers had a special case for function calls on
wild function pointers, but this doesn't need to be a special case.

After the refactoring, there are now two implementations of _show_trace()
which differ depending on CONFIG_FRAME_POINTER, and a single show_trace()
with the common bits, including the logic for wild function pointers.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
x86/stack: adjust boundary conditions for printed stacks

Move the boundary into current.h along with the other stack manipulation code.
The boundary is now the word adjacent to a struct cpu_info on the stack.

This also fixes the somewhat spurious bounds for the case with frame pointers.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
x86/stack: change show_stack_overflow() to use frame pointers if available

Pass a full set of cpu_user_regs, and defer the hand-coded stack printing to
_show_trace(), which will correctly use frame pointers if available.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
x86/hvm: reset TSC to 0 after domain resume from S3

Host S3 implicitly resets the host TSC to 0, but the tsc offset for hvm
domains is not recalculated when they resume, causing it to go into
negative values. In Linux guest using tsc clocksource, this results in
a hang after wrap back to positive values since the tsc clocksource
implementation expects it reset.

Signed-off-by: Tomasz Wroblewski <tomasz.wroblewski@citrix.com>
x86/crash: disable the watchdog NMIs on the crashing cpu

nmi_shootdown_cpus() is called during a crash to park all the other
CPUs.  This changes the NMI trap handlers which means there's no point
in having the watchdog still running.

This also disables the watchdog before executing any crash kexec image
and prevents the image from receiving unexpected NMIs.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>

PVOps Linux as a kexec image shoots itself in the foot otherwise.

On a Core2 system, Linux declares a firmware bug and tries to invert some bits
in the performance counter register.  It ends up setting the number of retired
instructions to generate another NMI to fewer instructions than the NMI
interrupt path itself, and ceases to make any useful progress.

The call to disable_lapic_nmi_watchdog() must be this late into the kexec path
to be sure that this cpu is the one which will execute the kexec image.
Otherwise there are race conditions where the NMIs might be disabled on the
wrong cpu, resulting in the kexec image still receiving NMIs.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Merge branch 'for-4.4.tmem' of git://xenbits.xen.org/people/konradwilk/xen into staging
xen: arm: remove /xen-core-devices node from dom0 dtb

The intention of adding this node to contain the GIC, timer and memory nodes
(in 1c08d6004ea7) was to allow us to control the #address-cells and

However in the case of the memory node the #*-cells are always taken from the
root node (see ePAPR 3.1, "the following nodes shall be present at the root...
memory node"). This caused breakage on the arndale platform.

In addition it is not valid to just create sub-nodes like this. Unless they
declare themselves as a bus then they will not necessarily be enumerated
(although Linux currently does so in practice).

Therefore:
 - Move the memory node back to the top level.
 - Insert the timer and primary gic nodes in the same location as the host
   DTB, replacing the originals. Note that the nodes here may be marked as in
   use by Xen and therefore the check must be before we discard nodes used by
   Xen.
 - Drop any secondary gics.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Tested-by: Julien Grall <julien.grall@linaro.org>
xen: arm: correct name of the dt node passed around when building dom0 DT

In the case of the GIC, timer and write_properties the argument is the node,
not the parent. Rename the argument to "node" in this case.

I think this stems from the use of the name "np" in other places (confusing
"node parent" for "node pointer").  Therefore replace all uses of "np" with
"node".

In addition in write_properties now that np=>node the name pp makes no sense.
Rename it to "prop".

No semantic change.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
xen: arm: early logging of command line

Helpful for diagnosis of bad console= parameters.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>