Commit Graph
23508 Commits
Author SHA1 Message Date
Keir Fraser 4515d7bd13 xenpaging: update machine_to_phys_mapping[] during page deallocation
The machine_to_phys_mapping[] array needs updating during page
deallocation.  If that page is allocated again, a call to
get_gpfn_from_mfn() will still return an old gfn from another guest.
This will cause trouble because this gfn number has no or different
meaning in the context of the current guest.

This happens when the entire guest ram is paged-out before
xen_vga_populate_vram() runs.  Then XENMEM_populate_physmap is called
with gfn 0xff000.  A new page is allocated with alloc_domheap_pages.
This new page does not have a gfn yet.  However, in
guest_physmap_add_entry() the passed mfn maps still to an old gfn
(perhaps from another old guest).  This old gfn is in paged-out state
in this guests context and has no mfn anymore.  As a result, the
ASSERT() triggers because p2m_is_ram() is true for p2m_ram_paging*
types.  If the machine_to_phys_mapping[] array is updated properly,
both loops in guest_physmap_add_entry() turn into no-ops for the new
page and the mfn/gfn mapping will be done at the end of the function.

If XENMEM_add_to_physmap is used with XENMAPSPACE_gmfn,
get_gpfn_from_mfn() will return an appearently valid gfn.  As a
result, guest_physmap_remove_page() is called.  The ASSERT in
p2m_remove_page triggers because the passed mfn does not match the old
mfn for the passed gfn.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
2011-06-10 08:19:07 +01:00
Keir Fraser 922626d29f x86: Disable set_gpfn_from_mfn until m2p table is allocated.
This is a prerequisite for calling set_gpfn_from_mfn() unconditionally
from free_heap_pages().

Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-10 08:18:33 +01:00
Keir Fraser 3d94875683 x86: Fix argument checking in (privileged) function cpu_add().
Thanks to John McDermott <john.mcdermott@nrl.navy.mil> for spotting.

Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-10 08:08:44 +01:00
Tim Deegan 89c9f78710 x86/hvm: add SMEP support to HVM guest
Intel new CPU supports SMEP (Supervisor Mode Execution Protection). SMEP
prevents software operating with CPL < 3 (supervisor mode) from fetching
instructions from any linear address with a valid translation for which the U/S
flag (bit 2) is 1 in every paging-structure entry controlling the translation
for the linear address.

This patch adds SMEP support to HVM guest.

Signed-off-by: Yang Wei <wei.y.yang@intel.com>
Signed-off-by: Shan Haitao <haitao.shan@intel.com>
Signed-off-by: Li Xin <xin.li@intel.com>
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-06 13:46:48 +01:00
Ian Campbell 95fad62ad6 hvmloader: add missing emacs local variables.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-08 13:40:46 +01:00
Ian Campbell d021c77cb4 hvmloader: reduce unnecessary e820 reservations for SeaBIOS
SeaBIOS will reserve memory in the e820 as necessary, including BIOS
data structures such as the EBDA, any tables it creates or copies into
pleace etc.  Therefore arrange that the memory map provided by
hvmloader to SeaBIOS reserves only things which HVMloader has created.

Since ROMBIOS is more tightly coupled with hvmloader we retain the
ability to reserve BIOS regions in the hvmloader produced e820 and use
that from the ROMBIOS backend.

The code for this could probably have been simpler but the existing
code avoids overlapping e820 areas and so the new code does the same
(many guest OSes sanitize the e820 map to handle this, but I wouldn't
trust that all do, so I didn't take the risk)

For ROMBIOS the resulting e820 map as seen by the guest is the same
except the reserved regions at 0x9e000-0x9fc00,0x9fc00-0xa0000 are
merged into a single region 0x9e000-0xa0000 (Linux guests sanitize the
e820 to look like this anyway).

For SeaBIOS the result is that the lowmem reserved region is from
0x9f000-0xa0000 rather than 0x9e000-0xa0000 which correctly reflects
SeaBIOS's actual usage.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-08 13:40:23 +01:00
Christoph Egger 7096575dcd nestedsvm: Support Decodeassist
Offer l1 guest to use decode assist if available in hardware.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
2011-06-08 13:39:31 +01:00
Tim Deegan f488040222 Fix 32-bit build after p2m series
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-06 09:56:08 +01:00
Tim Deegan fff9b78e1a Merge 2011-06-06 09:49:57 +01:00
Keir Fraser a2e5546098 x86: Enable Supervisor Mode Execution Protection (SMEP)
Intel new CPU supports SMEP (Supervisor Mode Execution
Protection). SMEP prevents software operating with CPL < 3 (supervisor
mode) from fetching instructions from any linear address with a valid
translation for which the U/S flag (bit 2) is 1 in every
paging-structure entry controlling the translation for the linear
address.

This patch enables SMEP in Xen to protect Xen hypervisor from
executing pv guest instructions, whose translation paging-structure
entries' U/S flags are all set.

Signed-off-by: Yang Wei <wei.y.yang@intel.com>
Signed-off-by: Shan Haitao <haitao.shan@intel.com>
Signed-off-by: Li Xin <xin.li@intel.com>
Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-03 21:39:00 +01:00
Keir Fraser 997f96a28b libxc: Don't refer to meaningless 'word offsets' in xc_cpufeature.h
Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-03 17:27:01 +01:00
Ian Campbell d22b23ec11 hvmloader: reinstate datastructure shared with DSDT in SeaBIOS case.
I mistakenly thought that the "struct bios_info" was a ROMBIOS
specific data structure and so caused it to be populated only in the
ROMBIOS case.

However it turns out that the majority of the struct's fields are
actually referenced from the ACPI DSDT and hence are needed for
SeaBIOS too.

While in principal it might have been possible to continue to mix
ROMBIOS and ACPI bits in this datastructure this is, evidently,
confusing but also leads to header file dependencies from
ROMBIOS->hvmloader which I had been hoping to avoid so as to head-off
future accidental re-entanglement of ROMBIOS and hvmloader.

So instead I have split the ACPI parts into a new "struct acpi_info"
which is defined entirely within the acpi building code in hvmloader
and which comes with a big comment pointing to the DSDT interaction.

This new ACPI info is placed at 0x9F000 which is available under both
ROMBIOS and SeaBIOS. This address is in a reserved region of the E820
and is just above the ROMBIOS stack.

The resulting "struct rombios_info" is hardly worthy of its own
structure but keep it anyway.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-03 17:22:51 +01:00
Ian Campbell 967ea77fcb hvmloader: allocate ACPI tables as we go
Rather than building the tables twice, once purely to figure out the
size, just allocate each individual table as we go.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-03 17:21:57 +01:00
Ian Campbell 95aa1ed069 hvmloader: removed unused/incorrect define.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-03 17:21:40 +01:00
Ian Campbell ab0e7218e7 hvmloader: reduce minimum allocation alignment from 1024 bytes to 16.
1024 bytes create a lot of wastage when the majority of allocations
are of BIOS table data structures which are generally happy with much
lower alignment. I conservatively chose 16 bytes.

Most callers pass 0 for the alignment anyway, for the rombios high
code allocation I kept it 1024 byte aligned since it was the only case
that didn't seem obviously ok with a smaller alignment.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-03 17:21:28 +01:00
Ian Jackson 4bf3ca7bdb tools/hotplug: Fix hotplug hook script arrangements not to always fail
The new feature introduced in 23401:a44b12ee2fd3 was broken; it in
general always fails, at least if there are no hotplug scripts.

If there are no hooks, call_hooks ends up running this:
  [ -x ".....*.hook" ] && . "..... *.hook"

This does not directly trigger set -e and sigerr.  However, it is the
last command exected in call_hooks.  So the return status of
call_hooks is an error, and thus a sigerr happens when call_hooks
returns.

The bug affects xl and xm.  However xl does not detect failure of the
hotplug script.

Change the script to use if...then rather than &&, as the latter has
very confusing and undesirable semantics.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-03 15:04:30 +01:00
Ian Jackson 46051f0c1c libxl: disks: rename disk param "unpluggable" to "removable"
This property corresponds to what is called "removable" in xenstore,
and is the conventional meaning of "removable": ie, the _media_ can be
removed even as the _device_ remains present.

"unpluggable" is a misleading name for this.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:35 +01:00
Ian Jackson 3c54832f67 libxl: disks: expose new "script" parameter for external block scripts
This is not currently implemented.  Applications setting it to
anything but NULL will cause an error.  Code to set it from xl
configuration files will appear later in this series.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:34 +01:00
Ian Jackson f1c76c0160 libxl: make libxl_ctx_free tolerate NULL ctx argument
This is purely for convenience (eg, when debugging).

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:33 +01:00
Ian Jackson d72ede734d libxl: provide TOSTRING in libxl_internal.h and libxlu_internal.h
Provide a copy of the standard TOSTRING macro in libxlu_internal.h,
for the benefit of patches later in this series.

Also, move TOSTRING to libxl_internal.h from a .c file for the
benefit of future other callers in libxl proper.

(These cannot be combined because libxlu cannot include
libxl_internal.h and libxl should not include libxlu_internal.h.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:32 +01:00
Ian Jackson dc7f5bd00c libxl: add missing copyright notices to autogenerated files
Copyright notices in libxlu_cfg_[ly].[ly] end up in the .[ch] files,
copied there by flex and bison.  Regenerate those files (flex 2.5.35
and bison 2.3, from Debian lenny i386).

No manual edits in this patch.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:32 +01:00
Ian Jackson d32e1379d6 libxl: add missing copyright notices to some files
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
2011-06-02 18:46:31 +01:00
Yang Zhang c6386a7eec libxl: fix wrong mask of function number
Function number is 3 bits. So the mask should be 0x7 instead 0x3.

Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-02 17:42:03 +01:00
Ian Campbell 83cd67d589 xl: print sxp on dry-run of create.
The help text for xm create's --dry-run says "Dry run - prints the
resulting configuration in SXP but does not create the domain." so
update xl implementation to match. At least the xendomains initscript
relies on this (for better or worse).

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Tested-by: Carsten Schiers <carsten@schiers.de>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-02 17:36:02 +01:00
Machon Gregory 8acc9d512e libxl: flask xsm support
Adds support for assigning a label to domains, obtaining and setting the
current enforcing mode, and loading a policy with xl command and libxl
header when the Flask XSM is in use. Adheres to the changes made by the
patch to remove exposure of libxenctrl/libxenstore headers via libxl.h.

Signed-Off-By: Machon Gregory <mbgrego@tycho.ncsc.mil>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-02 17:32:18 +01:00
Ian Campbell 7b7866eb26 libxl: check return values of read/write
Some distros enable -D_FORTIFY_SOURCE=2 by default
(https://wiki.ubuntu.com/CompilerFlags) which adds the warn_unused_result
attribute to several functions including read(2) and write(2)

Although we don't really care about error reading or writing the libxl spawn fd
catch them anyway to keep this warning happy.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-02 17:26:10 +01:00
Ian Campbell d586037ac3 libxl: avoid build warning when _libxl_types.h does not initially exist.
Olaf Hering reports:
	if ! cmp _libxl_paths.h.2.tmp _libxl_paths.h; then mv -f _libxl_paths.h.2.tmp _libxl_paths.h; fi
	cmp: _libxl_paths.h: No such file or directory

Use "cmp -s" to silence the error. cmp returns 2 in this case and so the mv
does occur.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
2011-06-02 17:25:27 +01:00
Ian Campbell 79e6a12b20 libxl: remove stray "atoi" in debug code.
I switched from atoi to strtol but failed to actually remove it...

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>
2011-06-02 17:24:41 +01:00
Keir Fraser 0f0230e4fb libxc: Simplify and clean up xc_cpufeature.h
* Remove Linux-private defns with no direct relation to CPUID
 * Remove word offsets into Linux-defined cpu_caps array
 * Hard tabs -> soft tabs

Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-02 15:01:04 +01:00
Keir Fraser 72cc91540e x86: Hide CPUID leaf 7 from PV guests.
Except for the whitelisted FSGSBASE feature.

Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-02 14:39:50 +01:00
Keir Fraser 7a21e8ea1d x86: Replace ad-hoc bitmaskof() macro with single cpufeat_mask() defn.
Signed-off-by: Keir Fraser <keir@xen.org>
2011-06-02 14:34:34 +01:00
Tim Deegan 090f81d3f5 x86/mm/shadow: emulated writes are always guest-originated actions
and never happen with the paging lock held.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan c859ee4eb9 x86/mm: simplify log-dirty page allocation.
Now that the log-dirty code is covered by the same lock as shadow and
hap activity, we no longer need to avoid doing allocs and frees with
the lock held.  Simplify the code accordingly.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan eca988de73 x86/mm: merge the shadow, hap and log-dirty locks into a single paging lock.
This will allow us to simplify the locking around calls between
hap/shadow and log-dirty code.  Many log-dirty paths already need the
shadow or HAP lock so it shouldn't increase contention that much.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 5bf494a7bf x86/mm: Make MM locks recursive.
This replaces a lot of open coded 'if (!locked) {lock()}' instances
by making the mm locks recursive locks, but only allowing them
to be taken recursively in the places that they were before.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 301493fb02 x86/mm: dedup the various copies of the shadow lock functions
Define the lock and unlock functions once, and list all the locks in one
place so (a) it's obvious what the locking discipline is and (b) none of
the locks are visible to non-mm code.  Automatically enforce that these
locks never get taken in the wrong order.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan eed8876543 x86/mm/p2m: Fix locking discipline around log-dirty teardown.
It's not safe to call paging_free_log_dirty_page with the
log-dirty lock held.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 3b0bcb8909 x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c
It uses p2m internals like the p2m lock and function pointers so belongs
behind the p2m interface.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 801827bf8d x86/mm/p2m: Fix locking discipline around p2m lookups.
All gfn_to_mfn* functions except _query() might take the p2m lock,
so can't be called with a p2m, shadow, hap or log_dirty lock held.
The remaining offender is the memory sharing code, which calls
_unshare() from inside the pagetable walker!  Fixing that is too big
for a cleanup patch like this one.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan eb4fb7f1e4 x86/mm/p2m: Fix locking discipline around p2m updates.
Direct callers of the p2m setting functions must hold the p2m lock.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan ab4c750822 x86/mm/p2m: Remove recursive-locking code from set_shared_p2m_entry().
It should no longer be needed now that the shr_lock discipline is fixed.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 50407c8653 x86/mm: Fix memory-sharing code's locking discipline.
memshr_audit is sometimes called with the shr_lock held.  Make it so for
every call.

Move the unsharing loop in p2m_teardown out of the p2m_lock to avoid
deadlocks.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 2e11350a2c x86/mm/p2m: paging_p2m_ga_to_gfn() doesn't need so many arguments
It has only one caller and is always called with p2m == hostp2m and mode
== hostmode.  Also, since it's only called from nested HAP code, remove
the check of paging_mode_hap().  Then rename it to reflect its new
interface.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 4ce6c4a455 x86/mm/p2m: Make p2m interfaces take struct domain arguments.
As part of the nested HVM patch series, many p2m functions were changed
to take pointers to p2m tables rather than to domains.  This patch
reverses that for almost all of them, which:
 - gets rid of a lot of "p2m_get_hostp2m(d)" in code which really
   shouldn't have to know anything about how gfns become mfns.
 - ties sharing and paging interfaces to a domain, which is
   what they actually act on, rather than a particular p2m table.

In developing this patch it became clear that memory-sharing and nested
HVM are unlikely to work well together.  I haven't tried to fix that
here beyond adding some assertions around suspect paths (as this patch
is big enough with just the interface changes)

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 8c7d0b2620 x86/mm/p2m: merge gfn_to_mfn_unshare with other gfn_to_mfn paths.
gfn_to_mfn_unshare() had its own function despite all other lookup types
being handled in one place. Merge it into _gfn_to_mfn_type(), so that it
gets the benefit of broken-page protection, for example, and tidy its
interfaces up to fit.

The unsharing code still has a lot of bugs, e.g.
 - failure to alloc for unshare on a foreign lookup still BUG()s,
 - at least one race condition in unshare-and-retry
 - p2m_* lookup types should probably be flags, not enum
but it's cleaner and will make later p2m cleanups easier.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 9929807325 x86/mm/p2m: hide the current-domain fast-path inside the p2m-pt code.
The other implementations of the p2m interface don't have this, and
it will go away entirely when 32-bit builds go away, so take it out
of the interface.

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan 58923a7203 x86/mm/p2m: little fixes and tidying up
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:52 +01:00
Tim Deegan d5ce4dacf0 x86/mm/p2m: Mark internal functions static
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
2011-06-02 13:16:51 +01:00
Ian Campbell e894fe2367 hvmloader: add code to generate a $PIR table.
Does not replace the table hardcoded in ROMBIOS (it ain't broke) but
is used for SeaBIOS.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-01 16:50:16 +01:00
Ian Campbell 0f165d2645 hvmloader: allow the possibility to allocate the size of smbios table
we actually need.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
2011-06-01 16:49:23 +01:00