x86: fix i8259A_resume()

On systems that have an IO-APIC, we generally run the PIC in AEOI
mode, yet i8259A_resume() so far failed to put it back into that mode.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
x86: adjust handling of interrupts coming in via legacy vectors

The debugging code added in c/s 24707:96987c324a4f was hit a (small)
number of times (one report being
http://lists.xen.org/archives/html/xen-devel/2012-05/msg00332.html),
apparently always with a vector within the legacy range. Obviously,
besides legacy vectors not normally expected to be in use on systems
with IO-APIC(s), they should never make it to the IRQ migration logic.

This wasn't being prevented so far: Since we don't have a one-to-one
mapping between vectors and IRQs - legacy IRQs may have two vectors
associated with them (one used in either 8259A, the other used in one
of the IO-APICs) -, vector-to-IRQ translations for legacy vectors (as
used in do_IRQ()) would yield a valid IRQ number despite the IRQ
really being handled via an IO-APIC.

This gets changed here - disable_8259A_irq() zaps the legacy vector-to-
IRQ mapping, and enable_8259A_irq(), should it ever be called for a
particular interrupts, restores it.

The spurious interrupt logic in do_IRQ() gets adjusted too: Interrupts
coming in via legacy vectors presumably didn't get reported through the
IO-APIC/LAPIC pair (as we never program these vectors into any RTE or
LVT). Call ack_APIC_irq() only when the LAPIC's ISR bit says an
interrupt is pending at the given vector. Plus, a new function (pointer)
bogus_8259A_irq() gets used to have the 8259A driver take care of the
bogus interrupt (as outside of automatic EOI mode it may need an EOI to
be issued for it to prevent other interrupts legitimately going through
the 8259As from getting masked out).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xl: introduce specific VCPU to PCPU mapping in config file

xm supports the following syntax (in the config file) for
specific VCPU to PCPU mapping:

cpus = "0-3,5,^1" # all vcpus run on cpus 0,2,3,5
cpus = ["2", "3"] # VCPU0 runs on CPU2, VCPU1 runs on CPU3

Allow for the same in xl.

This fixes what happened in changeset 54000bca7a6a, which
introduced suppot for the `cpus=` option within xl, but used
both the list (cpus=[2, 3]) and the string (cpus="2,3") syntax
for achieving the same behaviour (pin all guest's vcpus to the
pcpus in the list/string).

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: code motion of vncviewer() and `struct domain_create`

Signed-off-by: Goncalo Gomes <Goncalo.Gomes@EU.CITRIX.COM>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: Introduce vncviewer xm compatibility options

Signed-off-by: Goncalo Gomes <Goncalo.Gomes@EU.CITRIX.COM>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxl: Look for bootloader in libexec path

If the full path for a bootloader (such as pygrub or xenpvnetboot) is not
given, check for it first in the libexec path before falling back to the
PATH variable.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools: Install pv bootloaders in libexec rather than /usr/bin

pygrub and xenpvnetboot are meant to be run by tools, and not by the user,
and thus should be in /usr/lib/xen/bin rather than /usr/bin.

Because most config files will still have an absolute path pointing to
/usr/bin/pygrub, make a symbolic link that we will deprecate.

Signed-off-by: George Dunlap <george.dunlap@eu.ctirix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxl: Warn that /usr/bin/pygrub is deprecated

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxlu: Rename filename to config_source

The "filename" is a bit of a misnomer, as it's only used during error
messages, and in most instances cases is actually set to "command
line".

Rename it to "config_source" to make it clear that it's not used to
actually open any files.

No functional changes.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: Make clear distinction between "filename" and "data source"

Many places in xl there's a variable or element named "filename" which
does not contain a filename, but the source of the data for reporting
purposes.  Worse, there are variables which are sometimes actually
used or interpreted as a filename depending on what other variables
are set.  This makes it difficult to tell when a string is purely
cosmetic, and when another bit of code may actually attempt to call
"open" with the string.

This patch makes a consistent distinction between "filename" (which
always refers to the name of an actual file, and may be interpreted as
such at some point) and "source" (which may be a filename, or may be
another data source such as a migration stream or saved data).

This does add some variables and reshuffle where assignments happen;
most notably, the "restore_filename" element of struct domain_create
is now only set when restoring from a file.

But at a high level, there should be no funcitonal changes.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxl: Make a helper function write a BDF to a sysfs path

This functionality will be used several times in subsequent patches.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxl: Rename pci_list_assignable to pci_assignable_list

...to prepare for a consistent "pci_assignable_*" naming scheme.

Also move the man page entry into the PCI PASS-THROUGH section, rather
than the XEN HOST section.

No functional changes.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
libxl: Introduce pci_assignable_add and pci_assignable_remove

Introduce libxl helper functions to prepare devices to be passed
through to guests.  This is meant to replace of all the manual sysfs
commands which are currently required.

pci_assignable_add accepts a BDF for a device and will:
* Unbind a device from its current driver, if any
* If "rebind" is set, it will store the path of the driver from which we
  unplugged it in /libxl/pciback/$BDF/driver_path
* If create a slot for it in pciback if one doesn't yet exist
* Bind the device to pciback

At this point it will show up in pci_assignable_list, and is ready to
be passed through to a guest.

pci_assignable_remove accepts a BDF for a device and will:
* Unbind the device from pciback
* Remove the slot from pciback
* If "rebind" is set, and /libx/pciback/$BDF/driver_path exists, it
  will attempt to rebind the device to its original driver.

Both functions are idempotent: if the desired end state has already
been reached, they return SUCCESS.

NB that "$BDF" in this case uses '-' instead of ':' and '.', because
':' and '.' are illegal characters in xenstore paths.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: Add pci_assignable_add and remove commands

pci-assignable-add will always store the driver rebind path, but
pci-assignable-remove will only actually rebind if asked to do so.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
xl: Fixup filename->source after 25344:0f3b1e13d6af

Because of conflicts with another patch, changeset 25344:0f3b1e13d6af missed
one change.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
x86/mm: make p2m lock into an rwlock

Because the p2m lock was already recursive, we need to add a new
mm-lock class of recursive rwlocks.

Signed-off-by: Tim Deegan <tim@xen.org>
x86/mm: Introduce get_page_from_gfn().

This new function does a p2m lookup under the read lock, falling back
to the write lock only if it needs to make a change.  If the GFN is
backed by RAM, it takes a refcount on the underlying page.

The following patches will convert many paths that currently use
get_gfn/put_gfn to use the new interface.  That will avoid serializing
p2m accesses in the common case where no updates are needed (i.e. no
page-sharing, VM paging or other p2m trickery).

Signed-off-by: Tim Deegan <tim@xen.org>
arm: Implement get_page_from_gfn()

We will be calling this from common code, so add a basic
implementation to arch/arm.

After 4.2 we should reshuffle some of the p2m interface out of
arch/x86 into common headers; for now duplicate a little bit of it.

Signed-off-by: Tim Deegan <tim@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
x86/hvm: Use get_page_from_gfn() instead of get_gfn()/put_gfn.

Signed-off-by: Tim Deegan <tim@xen.org>
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
x86/mm: Use get_page_from_gfn() instead of get_gfn()/put_gfn.

Signed-off-by: Tim Deegan <tim@xen.org>
Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>