Keir Fraser [Wed, 7 Oct 2009 14:58:26 +0000 (15:58 +0100)]
Fix hypervisor crash with unpopulated NUMA nodes
On NUMA systems with memory-less nodes Xen crashes quite early in the
hypervisor (while initializing the heaps). This is not an issue if
this happens to be the last node, but "inner" nodes trigger this
reliably. On multi-node processors it is much more likely to leave a
node unequipped. The attached patch fixes this by enumerating the
node via the node_online_map instead of counting from 0 to num_nodes.
The resulting NUMA setup is still somewhat strange, but at least it
does not crash. In lowlevel/xc/xc.c there is again this enumeration
bug, but I suppose we cannot access the HV's node_online_map from this
context, so the xm info output is not correct (but xm debug-keys H
is). I plan to rework the handling of memory-less nodes later.
Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Keir Fraser [Wed, 7 Oct 2009 14:56:05 +0000 (15:56 +0100)]
x86 shadow: fix the check for having killed the guest in the fault handler.
We care only about when we have called domain_crash() (and therefore
shadow invariants may not hold) and shouldn't spuriously inject
pagefaults into guests that are shutting down for other reasons.
Keir Fraser [Wed, 7 Oct 2009 06:45:39 +0000 (07:45 +0100)]
Optimize memcpy for x86 arch. If source buffers does not start at a 64
bit boundary, copy a few bytes at the beginnig up to next 64-bit
boundary and then does an aligned copy for the remaining data. This
can reduce the copy cost by up to 50%.
Signed-off-by: Jose Renato Santos <jsantos@hpl.hp.com>
Keir Fraser [Wed, 7 Oct 2009 06:45:14 +0000 (07:45 +0100)]
Slightly more accurate dependency tracking for the .c and .h files in
include/compat. They should depend on the scripts which generate
them, as well as the inputs to those scripts.
Signed-off-by: Steven Smith <steven.smith@citrix.com>
Keir Fraser [Wed, 7 Oct 2009 06:43:50 +0000 (07:43 +0100)]
x86 vtsc: use debug-key to check/test reliable tsc
Previous attempt was rejected as too intrusive, but
further app rdtsc optimization work is very dependent
on Xen being able to determine if TSC is reliable
or not.
This patch starts to introduce the concept of
X86_FEATURE_TSC_RELIABLE as it is defined and
used by Linux, but uses it and tests it only in
a debug-key for now, so that a wide variety of
hardware can be measured by the broader Xen
community to confirm/deny TSC assumptions.
The eventual goal is for the evaluation of
TSC reliability to be exported to userland
so that apps can use rdtsc natively if and when
it is safe to do so.
(See http://lists.xensource.com/archives/html/xen-devel/2009-10/msg00056.html)
Note that the original Linux code for tsc_sync.c
uses a raw spinlock to ensure the "fastest, inlined,
non-debug version of a critical section". Xen
doesn't provide a _raw_spin_lock() so I used
regular spinlocks, but I would prefer the code
to use something more strict as Linux does.
(Also includes a minor nit: "NOSTOP" was used in
an early version of a Linux patch, but mainline
now uses "NONSTOP"... correct this for consistency.)
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Keir Fraser [Fri, 2 Oct 2009 08:10:27 +0000 (09:10 +0100)]
credit scheduler: fix credits overflow
In changing credits-per-tick from 100 to 1000000, a possible overflow
was introduced in the accounting algorithm, when credit totals (which
can be in the millions) gets multiplied by a weight (typically 256):
th eresult can easily overflow a signed 32-bit variable.
Fix this by reverting to 100 credits per tick, and maintain long-term
fairness/correctness by tracking at the nanosecond level exactly how
much execution time has been accounted to each VCPU. We do this by
rounding execution time so far to nearest number of credits, but then
remember the VCPU's 'partial credit balance'.
Keir Fraser [Thu, 1 Oct 2009 11:29:33 +0000 (12:29 +0100)]
Fix recursive lock p2m lock acquisition in POD code
The POD code can take the p2m lock from inside a lookup. This causes
a crash if anyone calls gfn_to_mfn* with the p2m lock held, which is
quite a few places. Make the POD code understand that it may be
called with the lock held, and DTRT about talking or releasing it.
Keir Fraser [Thu, 1 Oct 2009 11:26:15 +0000 (12:26 +0100)]
Fix memory leak in libxenstore python bindings
Temporary tuple0 python object was not freed at the end of
xspy_set_permissions() in case no error occurred. To reduce code
duplication, this path reuses the cleanup code.
Keir Fraser [Thu, 1 Oct 2009 11:25:36 +0000 (12:25 +0100)]
Disable HPET broadcast mode on kexec.
Without this the new kernel cannot receive timer interrupts from the
legacy sources. Hangs are observed in the second kernel's
"check_timer()" routing or at "Checking 'hlt' instruction."
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Reference counters are not correctly decreased for python object in
several places in python bindings for libxc. Most of them are around
PyList_Append(), which unlike PyList_SetItem() does increment
reference counter of the object being added to a list.
XSAVE/XRSTOR manages the existing and future processor extended states
on x86 architecture.
The XSAVE/XRSTOR infrastructure is defined in Intel SDMs:
http://www.intel.com/products/processor/manuals/
The patch uses the classical CR0.TS based algorithm to manage the
states on context switch. At present, we know 3 bits in the
XFEATURE_ENABLED_MASK: FPU, SSE and YMM. YMM is defined in Intel AVX
Programming Reference: http://software.intel.com/sites/avx/
x86: Make assigned devices' interrupts delivery to right vcpu.
This patch targets for reducing IPIs when delivery VT-d's devices'
intrs to target vcpus. According to the experiments leveraging 10G
Oplin NIC card, CPU utilization can reduce 5%-6% and NIC's bandwidth
keeps unchanged through testings. And this patch can always benefit
UP guests with MSI-capable devices assigned and SMP guests whose
lapic's destination mode is physical mode. And also it can benefit
SMP guests whose lapic's dest_mode is logical mode but only one
destination is specified. So it should cover major cases in real
environment. Currenlty, this patch intercepts the programming for MSI
intr status, and caculate the destination id for the pirq when do the
programming in advance. When vcpu migratio n occurs or guest
re-programe MSI status, it checks that whether needs to set the
corresponding pirq's affinity of assigned devices and make vcpu's
affinity and pirq's consistent to reduce the IPIs eventually.
In p2m_pod_set_cache_target:
* If a 2-meg allocation fails, try a 4k allocation
* If both allocations fail, return -ENOMEM so that the domain build
will fail.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
VBD information in xend does not have a VDI value if XenAPI mode
is invalid. A new patch confirms the VDI value is valid. So, the new
patch cuts off VDI->VBD links if the VDI value is valid.
x86, mce: Control Machine Check Log output verbosity
This small patch is for controlling machine check related Xen log
output. When set mce_verbosity=verbose in command line, all mce
related logs will be printed. Otherwise, those logs will be
eliminated.
While working on TSC-handling code, I missed an important
piece of code that writes to TSC because it does it
differently than other pieces of code. Fix that,
and also cleanup a bit to avoid hardcoded constants
and use wrmsrl instead of wrmsr plus handwritten 64-bit
dismembering code.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Some large system may have many ioapics which
have more than 256 pins totally. To support this
case, just let pirq == irq and build 1:1 mapping
between them, and this is based on the assumpation
that pirq == GSI number in dom0 for iopaic IRQs.
Thank Jan Beulich from Novell for reporting the issue
in pv_ops dom0.
Rather than always flushing all CPUs, only flush CPUs this domain is
currently active on, and defer flushing other CPUs until this domain
is scheduled onto them (or the domain is destroyed).
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com> Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
mca: Fix several issues for MCA UCR error handling
This patch is for fixing several issues for MCA UCR error handling on
latest Intel platforms, including:
1) For UCR error, the is 0xC0 ~ 0xCF instead of just C0
2) Synchronization issues for clearing error finding flag and clearing
global MCIP flag. Otherwise, in some cases, MCIP flag can't be cleared.
This patch used fixmap to get TXT heap base/size and SINIT base/size
from TXT pub config registers (whose address starts from 0xfed20000),
and get DMAR table copy from TXT heap (whose address may start from
0x7d520000) for tboot, instead of using map_pages_to_xen(), which will
cause panic on x86_32.
The grant table code had some particularly frequent repetitions of
mfn_to_page() on each time the same input arguments. To help the
compiler (which can do only a limited job on CSE), this adds explicit
caching of the transformation result in a few places.
Introduce a variant of map_domain_page() directly getting passed a
struct page_info * argument, based on the observation that in many
places the argument to this function so far simply was the result of
page_to_mfn(). This is meaningful for the x86-64 case where
map_domain_page() really just is an invocation of mfn_to_virt(), and
hence the combined mfn_to_virt(page_to_mfn()) now represents a
needless round trip conversion compressed -> uncompressed ->
compressed of the MFN representation.
Avoid backing M2P table holes with memory, when those holes are large
enough to cover an exact multiple of large pages.
For the sake of saving and migrating guests, XENMEM_machphys_mfn_list
fills the holes in the array it returns with the MFN for the previous
range returned (thanks to Keir pointing out that it really doesn't
matter *what* MFN gets returned for invalid ranges). Using the most
recently encountered MFN (rather than e.g. always the first one)
represents an attempt to cut down on the number of references these
pages will get when they get mapped into a privileged domain's address
space.
This also allows for saving a couple of 2M pages even on certain
"normal" systems.
Avoid backing frame table holes with memory, when those holes are
large enough to cover an exact multiple of large pages. This is based
on the introduction of a bit map, where each bit represents one such
range, thus allowing mfn_valid() checks to easily filter out those
MFNs that now shouldn't be used to index the frame table.
This allows for saving a couple of 2M pages even on "normal" systems.
x86-64: reduce range spanned by 1:1 mapping and frame table indexes
Introduces a virtual space conserving transformation on the MFN thus
far used to index 1:1 mapping and frame table, removing the largest
range of contiguous bits (below the most significant one) which are
zero for all valid MFNs from the MFN representation, to be used to
index into those arrays, thereby cutting the virtual range these
tables must cover approximately by half with each bit removed.
Since this should account for hotpluggable memory (in order to not
requiring a re-write when that gets supported), the determination of
which bits are candidates for removal must not be based on the E820
information, but instead has to use the SRAT. That in turn requires a
change to the ordering of steps done during early boot.
Extend the virtual range reserved for the 1:1 mapping to cover 5Tb,
and make the virtual size of the frame table gets match whatever the
1:1 table can cover.
Add code to get fully virtualized performance counters with newer
processors (which I'am able to test!) The most stuff is to check for
reserved bits in the control and counter register.
iommu: Fix pirq conflict issue when guest adopts per-cpu vector.
Latest Linux and Windows may adopt per-cpu vector instead of global
vector, so same vector in different vcpu may correspond to different
interrupt sources. That is to say, vector and pirq should be 1:n
mapping, and the array msi_gvec_pirq can't meet the mapping
requirement, so need to improve the related logic, otherwise it may
introduce strange issues.
x86 hvm: suspend platform timer emulation while its IRQ is masked
This patch gets rid of a timer which IRQ is masked from vcpu's timer
list. It reduces the overhead of VM EXIT and context switch of vm.
Also fixes a potential bug.
(1) VCPU#0: mask the IRQ of a timer. (ex. vioapic.redir[2].mask=1)
(2) VCPU#1: pt_timer_fn() is invoked by expiration of the timer.
(3) VCPU#1: pt_update_irq() is called but does nothing by
pt_irq_masked()==1.
(4) VCPU#1: sleep by halt.
(5) VCPU#0: unmask the IRQ of the timer.
After that, no one wakes up the VCPU#1.
IRQ of ISA is masked by:
- PIC's IMR
- IOAPIC's redir[0]
- IOAPIC's redir[N].mask
- LAPIC's LVT0
- LAPIC enabled/disabled
IRQ of LAPIC timer is masked by:
- LAPIC's LVTT
- LAPIC disabled
When above stuffs are changed, the corresponding vcpu is kicked and
suspended timer emulation is resumed.
In addition, a small bug fix in pt_adjust_global_vcpu_target().
x86 hvm: don't set periodical timer again until its IRQ is delivered.
Modern Windows OS (ex XP,2003,2008) never use the PIT timer,
and neither cpu#0's LAPIC timer after boot.
Despite that, xen emulates them busily. It's inefficient.
With this patch, setting a timer is defered while its IRQ is masked.
The reasons why pt_timer_fn() simply calls vcpu_kick() are:
- checking by pt_irq_masked() is duplicated. pt_update_irq() also
does.
- pt_timer_fn() is likely called on the same processor
as pt->vcpu->processor. Hence vcpu_kick() hardly send IPI.
Remove "buffer half full" check from guest_console_write
Checks are made at a lower level in the serial code, and teh policy
there is to drop rather than wait. So boot makes progress even when
serial hardware is problematic.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
1) Parsing IVRS special device entry in order to handle ioapic
remapping correctly.
2) Allocating per-device interrupt remapping tables instead of using a
global interrupt remapping table.
3) Some system devices like io-apic for north-bridge cannot be
discovered during pci device enumeration procedure. To remap interrupt
of those devices, device table update is split into 2 steps, so
that interrupt tables can be bound to device table entry earlier than
I/O page tables.
This patch adds the feature of irq ratelimit. It temporarily masks
the interrupt (guest) if too many irqs are observed in a short
period (irq storm), to ensure responsiveness of Xen and other guests.
As for now, the threshold can be adjusted at boot time using command-
line option irq_ratelimit=xxx.
Signed-off-by: Qing He <qing.he@intel.com> Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
As well as freeing data pages for impossible cpus, we also free pages
of all other cpus which contain no actual data (because of too-large
statically-defined PERCPU_SHIFT).
I met the following panic message in mcheck_mca_logout().
MSR_IA32_MCi_ADDR might take the values other than the machine
address. FATAL PAGE FAULT occured when the non-existent address is
passed to maddr_get_owner().
This patch cleans up queued invalidation, including round wrap
check, multiple polling status and other minor changes. This version
uses local variable as the polling address, which is clean.
This is the patch to correct pygrub return value for checkPassword()
function. It didn't return False at the end of the function. It
returned None so it was working fine and it's most likely just a
cosmetic issue.
Also, the missing () were added to checkPassword() function when
calling hasPassword and the unnecessary comment was removed.
Signed-off-by: Michal Novotny <minovotn@redhat.com>
xend: Receive error message of migration from destination server
The following error message was shown by xm migrate command.
In fact, I caused the command error by intention. I prepared a
destination server where free memory was insufficient, and then
I tried to migrate a VM to the destination server. As I had
expected, the command error occurred. However the error message
was different from my expectation. I would like to show an error
message from the destination server if an error occurred on the
destination server.
# xm migrate --live vm3 bx339
Error: (107, 'Transport endpoint is not connected')
Usage: xm migrate <Domain> <Host>
Migrate a domain to another machine.
Options:
-h, --help Print this help.
-l, --live Use live migration.
-p=3Dportnum, --port=3Dportnum
Use specified port for migration.
-n=3Dnodenum, --node=3Dnodenum
Use specified NUMA node on target.
-s, --ssl Use ssl connection for migration.
If a destination server sends an error message, this patch shows=20
the error message. For example, the following error message is=20
shown if free memory of the destination server is insufficient.
# xm migrate --live vm3 bx339
Error: I need 262144 KiB, but dom0_min_mem is 716800 and shrinking
to=20
716800 KiB would leave only 50368 KiB free. (from bx339)
Usage: xm migrate <Domain> <Host>
Migrate a domain to another machine.
Options:
-h, --help Print this help.
-l, --live Use live migration.
-p=3Dportnum, --port=3Dportnum
Use specified port for migration.
-n=3Dnodenum, --node=3Dnodenum
Use specified NUMA node on target.
-s, --ssl Use ssl connection for migration.