Paul Durrant [Fri, 27 Feb 2015 13:48:46 +0000 (13:48 +0000)]
Fix event channel unmasking for two-level ABI
The two-level ABI requires that an event is masked for the unmask
hypercall to raise the event, so the test-and-clear operation in the
guest basically means that pending events get stuck. The simple fix
is to re-mask pending events before making the hypercall. This is
unnecessary when the FIFO ABI is used, but it's safe. Hence this patch
unconditionally re-masks pending events, regardless of ABI, before
making the unmask hypercall.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 26 Feb 2015 14:23:43 +0000 (14:23 +0000)]
Re-instate bus enumation filtering in XENFILT
The filtering code was removed in commit ff034f7ebd4010f7b502c56cb1cca6ba40a7f1aa when it was realized that
simply modifying the reported instance ID of the active device to be
constant, even if it moves location on the PCI bus was sufficient to
keep PV drivers binding. However, this does not protect against the
active device going away so you can still end up with a non-bootable VM.
This patch re-instates the code, modified to check for presence of the
active device with a wildcard instance rather than a fixed instance.
NOTE: This patch does include a change to emulated_interface.h, to allow
a NULL instance ID to be passed to IsDevicePresent. Whilst this is
a new semantic, it does not affect compatibility so there is no
change to the interface version.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 9 Feb 2015 13:12:39 +0000 (13:12 +0000)]
Fix SDV build
SDV builds are failing with this error:
..\..\src\xenbus\fdo.c(758) : error C2220: warning treated as error - no 'object' file generated
c:\git\xenbus\src\xenbus\fdo.c(744) : warning C6246: Local declaration of 'status' hides declaration of the same name in outer scope. For additional information, see previous declaration at line '675' of 'c:\git\xenbus\src\xenbus\fdo.c'.: Lines: 675
This patch removes the erroneous declaration.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 3 Feb 2015 11:38:33 +0000 (11:38 +0000)]
EVTCHN FIFO ABI should keep per-vcpu queue head shadow
There is currently only one shadow head per priority which means that
polling event channels of the same priority on different CPUs can conflict,
leading to lost events. This patch fixes the problem.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 28 Jan 2015 16:27:36 +0000 (16:27 +0000)]
Remove use of KeNumberProcessors from EVTCHN code
The crucial things are the virtual CPUs to which the ABI can steer
interrupts and the number of interrupts which the FDO code successfully
allocated. By using an intersection of these two things we can drop any
use of KeNumberProcessors.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 28 Jan 2015 14:47:31 +0000 (14:47 +0000)]
Remove use of KeNumberProcessors from SYSTEM code
The Xen SYSTEM module queries system information, including per-cpu
information. It is therefore best to make use if processor callback
functions rather than iterating over boot-time active processors, as this
makes the code robust to processors hot-added after boot.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 20 Jan 2015 17:39:58 +0000 (17:39 +0000)]
Re-work EVTCHN Close
When using the FIFO ABI, the Close operation needs to be synchronized with
polling. This requires some re-structuring of the close code to defer the
actual closure of the event channel in Xen until at least one poll after
masking and starting the tear-down.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 20 Jan 2015 11:40:39 +0000 (11:40 +0000)]
Re-work EVTCHN Trigger
By re-working the event channel poll callback to add pending channels to a
list and then service them, we can tidy up Trigger by forcibly appending a
channel to the same list and then scheduling a DPC on the correct cpu to
service in the list (unless an interrupt callback came along in the interim
and did the job).
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 16 Jan 2015 15:09:40 +0000 (15:09 +0000)]
Use a DPC per CPU for EVTCHN Trigger
Using a single DPC potentially means re-afinitizing it for each use, and
this potentially means Windows could try to insert it onto multiple CPU
queues at the same time, which probably won't end well. Using a DPC per
CPU seems a lot safer.
Also add a DPC flush before we zero out data structures.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 19 Jan 2015 09:54:38 +0000 (09:54 +0000)]
Eagerly enable and disable interrupts
There's really no need to lazily enable event channel interrupts. It makes
the code simpler to enable at the end of the first acquire and disable at
the start of the last release.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 19 Jan 2015 16:18:05 +0000 (16:18 +0000)]
Get rid of per-channel interrupt pointer
It's kind of redundant as we have a Cpu index value. Also, remove code that
tries to ensure everything is on the right cpu even across an event channel
re-bind. Since we now always use the hypercall to handle unmasking then we
don't need to care so much.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 20 Jan 2015 15:11:28 +0000 (15:11 +0000)]
Fix EvtchnOpen() error path
It's possible for an error in the latter stages of EvtchnOpen() to cause the
channel to be left open in Xen. Also the Mask boolean was not being cleared
which would lead to ASSERTion failures in checked builds.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 26 Jan 2015 15:48:04 +0000 (15:48 +0000)]
Fix type mismatch
The size of PWCHAR and the size of ULONG are the same for 32-bit
installations so this bug only affects 64-bit installations, but the
symptom is a crash on PDO destruction due to a corrupted heap.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 14 Jan 2015 09:49:01 +0000 (09:49 +0000)]
Reserve some grant entries for the crash kernel
The xencrsh driver (which is loaded into the crash kernel) needs some grant
entries to write out the dump file. It is important that these entries are
guaranteed to be unused by any backend other than the one the xencrsh uses
so reserve them in the normal grant table.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 9 Jan 2015 13:42:57 +0000 (13:42 +0000)]
Reflect interface versions in PDO description
For convenience add a string containing the latest versions of all the
interfaces exported by the driver into the PDO description. This can be
seen in Device Manager as the 'Bus reported device description' detail.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 18 Dec 2014 17:18:48 +0000 (17:18 +0000)]
Map Local APIC IDs to Processor IDs through the MADT
To use the FIFO EVTCHN ABI the frontend code needs to know the vcpu id of
the guest CPUs. This mapping is currently done by taking the the CPU local
APIC ID and dividing by 2. This currently works on most Xen installations
but Matt Wilson advises that this will not work on AWS.
This patch introduces code to map and parse the ACPI RSDP, XSDT and MADT
(APIC) tables such that the local APIC substructures present in the latter
can be used to map local APIC ID to processor ID (which is identical to
vcpu id).
Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Cc: Matt Wilson <msw@linux.com>
Paul Durrant [Tue, 16 Dec 2014 11:07:00 +0000 (11:07 +0000)]
Fix free-at-wrong-IRQL bug
The hash table code introduced for the FIFO EVTCHN ABI work tries to free
memory at HIGH IRQL. This causes a bugcheck when verifier is turned on. This
patch re-orders the unlock (which drops IRQL back to DISPATCH) and the free.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 15 Dec 2014 14:07:20 +0000 (14:07 +0000)]
Fix 0xD6 bugcheck found with verifier
PdoAddRevision() reads beyond the end of an allocation when copying the old
revision table to the new one. This is becaause it is incorrectly using the
Count stack variable rather then the Count field in the Pdo structure. This
patch fixes the problem.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Owen Smith [Fri, 28 Nov 2014 13:36:34 +0000 (13:36 +0000)]
Add registry setting for removable capability of PDOs
Setting "Removable" to 0 under the key
HKLM/System/CurrentControlSet/services/XENBUS/Parameters/<PDO-Name>
will disable the PDOs removable and surprise removable capability.
Signed-off-by: Owen Smith <owen.smith@citrix.com> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 20 Nov 2014 15:56:32 +0000 (15:56 +0000)]
Avoid making hypercalls in the SyncWorker DPC
The code has to run with interrupts disabled on all CPUs apart from 0 to
corale them across a suspend/resume. Making hypercalls from within that
code is thus incompatible with re-populating the hypercall table on resume
since it transpites then Xen writes each byte in the page to 0xcc (int 3)
before actually setting up the hypercall thunks. The only hypercall that the
code was actually making was a SCHEDOP_yield and this is trivially replaced
by an _mm_pause intrinsic which calls through to SCHEDOP_yield in the
VMEXIT handler.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 12 Nov 2014 15:02:46 +0000 (15:02 +0000)]
Fix ASSERTion failure in EVTCHN Close
The EVTCHN Channel structure contains a BOOLEAN Mask field that specifies
whether the Channel is aut0-masked on event upcall. The Close method was
failing to zero then and then falling over a later assertion that the
Channel structure had been zeroed out.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 11 Nov 2014 13:33:48 +0000 (13:33 +0000)]
Use EVTCHNOP_unmask to unmask in some cases
If the EVTCHN Unmask method is called in context of the event channel
upcall, or on a CPU to which the event is not bound then use the unmask
hypercall. In the former case not doing this may lead to priorty
inversion once setting event channel priorities is enabled. In the latter
case not doing it again stops a lower priority event handler trigger from
blocking a higher priority event injection.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 6 Nov 2014 12:44:26 +0000 (12:44 +0000)]
Use per-CPU event channel upcalls if available
A recent patch to Xen introduced a new HVM op to set a per-vcpu event
channel upcall. This patch adds code to make use of the latched interrupts
allocated by the FDO code to enable per-vcpu upcalls and adds an extra
EvtchnBind operation to a new v2 EVTCHN interface so that events can be
steered to a specified CPU.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 6 Nov 2014 10:30:58 +0000 (10:30 +0000)]
Re-work interrupt code in FDO
This patch adds code to the FDO handler to acquire extra message signaled
(i.e. edge triggered) interrupt vectors that can be used for per-CPU event
channel upcalls (with extra support in Xen).
The existing callback via is also limited to upcall on CPU 0 meaning the
interrupt callback in the EVTCHN code can pass the current CPU value through
to the ABI.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 5 Nov 2014 18:00:12 +0000 (18:00 +0000)]
Re-populate hypercall page on resume from suspend/hibernate
Doing this has the side effect of latching the shared info page width,
which is currently done when the callback via is set. When we move to a
per-cpu event channel upcall then this side effect will be lost, so
doing this makes sure that the shared info is still of the correct width.
Additionally in this patch the reporting of the Xen version is improved
by using the XENVER hypercalls to get major, minor and extra version
informattion. As part of that change, more headers have been copied in
from Xen.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 7 Nov 2014 12:40:16 +0000 (12:40 +0000)]
Remove needless checks on ParametersKey validity
It used to be the case that XENBUS would tolerate a lack of Parameters key
in its Service key but that has not been true for some time, so remove
validity checks that are no longer needed.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 7 Nov 2014 10:56:32 +0000 (10:56 +0000)]
Add registry override for EVTCHN ABI
Add a registry parameter DWORD:UseEvtchnFifoAbi than can be set to zero
to prevent use of the FIFO ABI or non-zero to allow it. The default value is
non-zero.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 5 Nov 2014 17:38:32 +0000 (17:38 +0000)]
Add support for the FIFO event channel ABI
If it is available then the fifo ABI will be used. If it is not then the
two-level ABI will be used instead.
The ABI is released and re-acquired across suspend/resume so this should
allow moving between hosts with different capabilities.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 5 Nov 2014 17:04:16 +0000 (17:04 +0000)]
Separate event channel ABI from core evtchn interface code
The event channel ABI now known as two-level is implemented using the
domain shared info. Use of the SHARED_INFO interface is therefore baked
into the EVTCHN interface.
Xen has recently acquired a new event channel ABI called fifo, which
improves on both scalability and performance as compared to two-level.
Hence this patch separates the ABI code from the core EVTCHN interface
code so that a subsequent patch can add support for the fifo ABI on
capable versions of Xen.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 5 Nov 2014 16:31:03 +0000 (16:31 +0000)]
Make auto-masking a generic event channel property
Keeping the Mask boolean in the per-type event channel parameters makes the
code needlessly complex in several places. Just make it a generic property.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 5 Nov 2014 15:50:10 +0000 (15:50 +0000)]
Use a hash table for event channel lookup
Rather than using a large array for mapping port values to channel
structures, use a hash table. This means we no longer need to code a
hard port number limit into the EVTCHN implementation.
Because the hash table implementation manages its own locking, we also no
longer need to make such liberal use of the interrupt lock in the EVTCHN
implementation and can use the spinlock instead.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 28 Oct 2014 10:23:25 +0000 (10:23 +0000)]
Separate checking upcall_pending in shared info from EvtchnPoll
The current EvtchnPoll routine in in the shared info code is tied to
the two level event channel ABI, wheras checking upcall_pending is ABI
independent. Hence the check should be separated into its own method.
This patch therefore introduces version 2 of the SHARED_INFO interface,
which has a new EvtchnUpcallPending method. Version 1 is still
supported by having its EvtchnPoll variant call EvtchnUpcallPending
method internally.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 28 Oct 2014 09:13:44 +0000 (09:13 +0000)]
Use InterlockedBitTestAnd[Set|Reset] in SHARED_INFO
Rather then using InterlockedCompareAndExchange to set and clear bits
in the SHARED_INFO event channel masks, use
InterlockedBitTestAnd[Set|Reset] as these will resolve to instrinsics
when available.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 6 Nov 2014 12:53:23 +0000 (12:53 +0000)]
Fix bug in EVTCHN interrupt enabling
The code in EvtchnOpen attempts to enable interrupts on demand when new
channels are added to a list. However there is a bug in the logic that
means interrupts will not be enabled until the second channel is opened.
This patch fixes the bug.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Mon, 6 Oct 2014 16:37:16 +0000 (17:37 +0100)]
Add missing acquisition of the UNPLUG interface
Commit cba6dad2df306885dfc65908f14ce6e2d8a86211 changed the way that
emulated devices are unplugged. It used to be that XENFILT waited until it
detected the presence of the 'active' device that XENBUS bound to before
deciding whether to unplug, but that commit simply made sure that the
'active' device always appears unless something has drastically changed in
the VM configuration. Unfortunately, in making that change, the code that
acquired the initial reference to the unplug interface - and thereby caused
emulated devices to be unplugged - was lost. This patch adds in the missing
acquisition.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 5 Sep 2014 16:58:51 +0000 (17:58 +0100)]
Update active device's instance id at point of PDO filter creation
It's tidier to have xenfilt simply return its own versions of device and
instance id when it intercepts IRP_MN_QUERY_ID. The override of the instance
id can be done and logged once when the PDO filter device object is created.
This patch does that, and also replaces the rather vacuuous Name field in
the filter device object extensions with DeviceID and InstanceID fields.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 3 Sep 2014 16:23:41 +0000 (17:23 +0100)]
Squash changes in active platform device instance id
If the instance id of the platform device changes then Windows will need
to rebind the xenbus driver. This means that if the system disk is hanging
off a child of xenbus then we get a 0x7B BSOD before the rebind (which is
done in user space) can occur.
This patch makes sure that the instance id of the platform device remains
invariant after initial driver installation.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 13 Aug 2014 14:26:15 +0000 (15:26 +0100)]
Update branding
Remove the use of the 'XenServer' product name except where it is
still appropriate.
Remove use of 'Citrix' from all places except source file
copyrights.
Allow company and product name to be set at build time.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Thu, 24 Jul 2014 08:01:23 +0000 (09:01 +0100)]
Implement new API version scheme
This patch changes the way APIs work in an incompatible way. (See README.md
for details).
The patch also includes a *lot* of code tidying and movement and as such
is not really suitable for review as a patch; the resulting code should
itself be reviewed.
Given the scale of the change, the major version number has been revised to
8 and other version numbers reset to zero.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 30 May 2014 08:54:38 +0000 (09:54 +0100)]
Modify GNTTAB interface to support caches
Remove the Get/Set methods and replace with CreateCache/DestroyCache methods.
The PermitForeignAccess method the uses a cache to allocate an entry as it
requires. Also, as we're not only using grant table v1, we can get rid of
the idea of different types of permit and drop the use of varargs.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Fri, 23 May 2014 15:10:12 +0000 (16:10 +0100)]
It's not necessarily safe to access interfaces when device is not in D0
The Scan, Suspend and Balloon threads should not try to access interfaces
such as STORE when the device is not in D0 as the interfaces are not there
if the system is at S4 or higher.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Wed, 30 Apr 2014 10:47:01 +0000 (11:47 +0100)]
Fix RangeSet cursor problem
When the last or first range in the set is removed then the cursor may end
up pointing back at the anchor point. This confused RangeSetPop() so we
need to make sure that the cursor wraps round when this happens, such that
the only valid reason for the cursor to ever point at the anchor is when
the set goes empty.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Paul Durrant [Tue, 29 Apr 2014 14:46:17 +0000 (15:46 +0100)]
Add FIST capability for pools
By setting xenstore parameters 'fist/pool/<name>/defer' to X and
'fist/pool/<name>/probability' to Y you can now cause failures of PoolGet()
such that it will fail with probability Y% after X initial invocations.
The name of the grant table pool has been set to 'gnttab' to make typing it
in more convenients, and some debug-keys output has been added to give
the PoolGet() failure count.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>