]> xenbits.xensource.com Git - pvdrivers/win/xenvif.git/log
pvdrivers/win/xenvif.git
19 months agoDelete CoInstaller code
Owen Smith [Wed, 13 Sep 2023 14:15:24 +0000 (15:15 +0100)]
Delete CoInstaller code

With the CoInstaller removed from the INF file, delete the CoInstaller
source code and projects.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
19 months agoRemove CoInstaller from INF
Owen Smith [Wed, 13 Sep 2023 14:15:23 +0000 (15:15 +0100)]
Remove CoInstaller from INF

Windows 11 22H2 WHQL requires INF file pass "InfVerif /k", which highlights
several issues
- PnpLockdown=1 needs to be specified
- CoInstallers are no longer allowed

The CoInstaller has several functions that will need alternative solutions:
- The AllowUpdate mechanism is no longer possible
- The safety checks that ensure interface versionings remain compatible
- The writing of 'current' network identifiers to the registry in order to
  copy network settings.

Interface safety checks need to be handled by changes to child device bindings,
and assuming upgrade via emulated devices is safe. The unplug key is cleared
in the INF to revert to emulated NICs on the next boot, incase the current child
drivers rely on an interface that is no longer present (note: in this case,
child drivers will need updating).

Signed-off-by: Owen Smith <owen.smith@cloud.com>
19 months agoAdd Unplug v2 (REV_0900000A)
Owen Smith [Wed, 13 Sep 2023 14:15:22 +0000 (15:15 +0100)]
Add Unplug v2 (REV_0900000A)

If NICs have not been unplugged, do not start PV network devices and trigger a
required reboot.
This is to avoid the upgrade case where both emulated and PV devices could be
present, due to a 'revert to emulated' policy and emulated NICs not currently
getting IP configurations so the HasAlias value is not determined correctly.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
Adjusted XENBUS_UNPLUG method naming to match XENBUS and re-imported the
header.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
19 months agoRemove REV from DeviceID
Owen Smith [Wed, 13 Sep 2023 14:15:21 +0000 (15:15 +0100)]
Remove REV from DeviceID

Driver upgrades use HardwareIDs (or CompatibleIDs) to match the child INF DDInstall
section (stored as matching device id), but use the DeviceID to generate the device
instance path. By keeping the device instance path the same over upgrades, the network
stack should identify this as an upgrade, rather than 'replacement hardware', and
not generate a new network connection, which would require network settings to be
copied from the existing network connection to the new network connection.

Note: This introduces a strict requirement for child device INF DDInstall sections to
  reference devices by the full (including revision) hardware ID

Signed-off-by: Owen Smith <owen.smith@cloud.com>
19 months agoFix Length calculation in PdoQueryId
Owen Smith [Wed, 13 Sep 2023 14:15:20 +0000 (15:15 +0100)]
Fix Length calculation in PdoQueryId

Decrease Length by the string length of the current ID before moving
the Buffer value to the end of the current ID. Without this, Length
is not decreased, leading to potential issues with the next call to
RtlStringCbPrintfW.
Note: second chunk it to maintain consistent ordering of operations,
  and is not a functional change

Signed-off-by: Owen Smith <owen.smith@cloud.com>
19 months agoAdd script to generate pooltag.txt for debugger use
Owen Smith [Wed, 13 Sep 2023 08:48:35 +0000 (09:48 +0100)]
Add script to generate pooltag.txt for debugger use

Note: script does not correctly handle src/common paths and attributes
  pool tags discovered within to 'common.sys'

Signed-off-by: Owen Smith <owen.smith@cloud.com>
19 months agoAvoid dereferencing NULL cache objects.
Owen Smith [Tue, 22 Aug 2023 11:28:45 +0000 (12:28 +0100)]
Avoid dereferencing NULL cache objects.

XENBUS_CACHE(Get, ...) can fail in low memory conditions. Avoid dereferencing
NULL pointers in ASSERTs
Fix up error path to avoid returning a NULL pointer to the cache.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
23 months agoSet FrontendMaxQueues by default
Owen Smith [Fri, 26 May 2023 08:17:10 +0000 (09:17 +0100)]
Set FrontendMaxQueues by default

Limiting the number of queues to the same value defined in xennet's INF
file prevents xenvif from allocating many more resources than required.

Currently, xenvif will allocate a queue for each active CPU, but xennet
only reports a maximum of 8 RSS queues to Windows. When vCPU count is
greather than 8, additional queues are not used and just consume resources.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
23 months agoDon't allow a frontend to go from Closed to Initialising...
Paul Durrant [Mon, 22 May 2023 13:32:26 +0000 (14:32 +0100)]
Don't allow a frontend to go from Closed to Initialising...

... if the backend is offline.

It's possible for the enumeration thread to spot a device that is in the
process of being removed. In this case the 'online' node in the backend
XenStore area will be 0 and devices in this state should remain Closed.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
23 months agoAlways log during SettingsRestore
Owen Smith [Fri, 12 May 2023 13:56:45 +0000 (14:56 +0100)]
Always log during SettingsRestore

- removes the logging skip if the Settings key is not present
- logs if the interface guid doesnt change

Signed-off-by: Owen Smith <owen.smith@cloud.com>
23 months agoRebuild CodeQL builds
Owen Smith [Tue, 18 Apr 2023 08:50:45 +0000 (09:50 +0100)]
Rebuild CodeQL builds

CodeQL can sometimes fail to detect any source code if the codebase is
not rebuilt. Use the Rebuild target to force all intermediate build artifacts
to be cleaned beforehand.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
23 months agoCheck for zero byte allocations
Owen Smith [Mon, 17 Apr 2023 14:32:46 +0000 (15:32 +0100)]
Check for zero byte allocations

Avoid attempting to allocate zero byte buffers, which can lead to
inefficiencies in pool memory usage.

Suggested-by: Matthew Sykes <matthew.sykes@citrix.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
2 years agoRemove trailing blank lines
Paul Durrant [Thu, 23 Mar 2023 15:22:38 +0000 (15:22 +0000)]
Remove trailing blank lines

Use the following bit of shell to remove a trailing blank line from each
file where such exists.

echo "$(echo "$(tac $file)" | tac)" > $file

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoScripted replacement of Copyright notices in source
Owen Smith [Thu, 23 Feb 2023 09:52:42 +0000 (09:52 +0000)]
Scripted replacement of Copyright notices in source

Due to a transfer of copyright ownership from Citrix to Cloud Software Group,
the copyright notices in all source files should be updated.

Using the powershell script below replace "Copyright (c) Citrix Systems, Inc."
with "Copyright (c) Xen Project." and "Copyright (c) Cloud Software Group, Inc."

Function Multiline-Replace {
    param(
        [string]$Filename,
        [string]$ToReplace,
        [array]$ReplaceWith
    )

    $content = Get-Content $Filename
    $replace = $false
    $output = ""
    $content | ForEach {
        $line = $_
        if ($line.Contains($ToReplace)) {
            $replace = $true
            $ReplaceWith | ForEach {
                $output += $line.Replace($ToReplace, $_) + "`n"
            }
        } else {
            $output += $line + "`n"
        }
    }
    if ($replace) {
        Write-Host "Replacing: " $Filename
        $output | Set-Content $Filename
    } else {
        Write-Host "Ignoring:  " $Filename
    }
}

Function Replace-Filestrings {
    param(
        [array]$FilleTypes,
        [string]$ToReplace,
        [array]$Replacements,
        [array]$ExcludeList
    )

    $FileTypes | ForEach {
        Get-ChildItem $_ -Recurse | ForEach-Object {
            $filename = $_
            if (($ExcludeList | %{ $filename -Like $_ }) -Contains $True) {
                Write-Host "Excluding: " $filename
            } else {
                Multiline-Replace $_ $ToReplace $Replacements
            }
        }
    }
}

$ExcludeList = @("*include\xen\*", "*\obj\*")
$Replace = "Copyright (c) Citrix Systems Inc."

$Replacements = @("/* Copyright (c) Xen Project.", " * Copyright (c) Cloud Software Group, Inc.")
$FileTypes = @("*.c", "*.h", "*.rc")
Replace-Filestrings $FileTypes ('/* ' + $Replace) $Replacements $ExcludeList

$Replacements = @("; // Copyright (c) Xen Project.", "; // Copyright (c) Cloud Software Group, Inc.")
$FileTypes = @("*.mc")
Replace-Filestrings $FileTypes ('; // ' + $Replace) $Replacements $ExcludeList

$Replacements = @("; Copyright (c) Xen Project.", "; Copyright (c) Cloud Software Group, Inc.")
$FileTypes = @("*.inf", "*.def")
Replace-Filestrings $FileTypes ('; ' + $Replace) $Replacements $ExcludeList

$Replacements = @("Copyright (c) Xen Project.", "Copyright (c) Cloud Software Group, Inc.")
$FileTypes = @("LICENSE")
Replace-Filestrings $FileTypes $Replace $Replacements $ExcludeList

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Amended commit comment. Fixed whitespace.

Signed-off-by: Paul Durrant <paul@xen.org>
2 years agoAdd resource file to coinstaller
Owen Smith [Thu, 23 Feb 2023 09:52:41 +0000 (09:52 +0000)]
Add resource file to coinstaller

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoAllow rebranding file copyright string
Owen Smith [Thu, 23 Feb 2023 09:52:40 +0000 (09:52 +0000)]
Allow rebranding file copyright string

Pass COPYRIGHT string from environment to override the copyright string
that is embedded in the output binaries.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoSkip stale device config...
Owen Smith [Tue, 7 Feb 2023 08:11:45 +0000 (08:11 +0000)]
Skip stale device config...

...when checking child compatibility

When a device is updated, the Enum key for the old binding is not deleted.
This can lead to a device binding that is not in use (has been replaced by
a later binding) triggering the coinstaller to fail the upgrade to a newer
version. This is especially prevelent when the older stale information was
bound to a revision that is not present in the new driver INF file.

This fix ignores the stale entries under the Enum key when performing the
compatibility checks.

This is similar to the XenBus commit 16c8ad0c446eded7246cc5f3d72de0bc3ff7baf5
which handles the same failure for XenBus's child devices

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoCorrect return codes during racy destruction.
Martin Harvey [Mon, 5 Dec 2022 09:01:59 +0000 (09:01 +0000)]
Correct return codes during racy destruction.

Errors in PnP retun codes found when testing under driver
verifier with mixed VM lifecycle operations. Under some
rare cases, it is possible to get more than one PnP
"remove-like" operation. This results in a PnP remove
operation being processed whilst the device is already
in the deleted state.

This patch fixes the immediate cause of the bugfixes,
by fixing the return code. Device destruction is
unchanged. Investigation into the root cause is still
ongoing.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
Cosmetic fixes.

Signed-off-by: Paul Durrant <paul@xen.org>
2 years agoFdoCreate: bad memset in failure path.
Rabish Kumar (3P) [Wed, 16 Nov 2022 16:14:21 +0000 (21:44 +0530)]
FdoCreate: bad memset in failure path.

The fail14 exit path attempts to clear the wrong interface which may cause
an ASSERTion failure at fail3.

Signed-off-by: Rabish Kumar <rabish.kumar@citrix.com>
Acked-by: Owen Smith <owen.smith@citrix.com>
2 years agoPass SignMode to MSBuild
Owen Smith [Fri, 18 Nov 2022 10:06:10 +0000 (10:06 +0000)]
Pass SignMode to MSBuild

Allows overriding of SignMode to "Off" to prevent signing binaries with the PFX
file. This is useful if wrapper builds sign binaries with alternative signatures
or when signing is not required.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Small whitespace fix.

Signed-off-by: Paul Durrant <paul@xen.org>
2 years agoAdd build options for EWDK 22621
Paul Durrant [Mon, 31 Oct 2022 12:18:56 +0000 (12:18 +0000)]
Add build options for EWDK 22621

VisualStudioVersion = 17.0 maps to Visual Studio 2022
 * Adds project files for vs2022
 * Adds mapping from VisualStudioVersion 17.0 to "vs2022" project folder
 * Adds mapping from VisualStudioVersion 17.0 to "Windows 10" build target
 * Adds guard to build.ps1 - EWDK 22621 does not build x86 binaries
 * Adds include directive where compiler intrinsics are used
   (and removes re-definition of 'offsetof')

Suggested-by: Owen Smith <owen.smith@citrix.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoCreate SettingsKey SubKeys if needed
Owen Smith [Mon, 24 Oct 2022 10:25:50 +0000 (11:25 +0100)]
Create SettingsKey SubKeys if needed

Use RegistryCreateSubKey to create the settings key, if it does not exist,
when attempting to save the current settings. The SettingsKey's sub keys do
not exist when first installing drivers from emulated devices. This is only
an issue when the emulated devices have had network settings applied before
installing the PV drivers.

Also adds NTSTATUS values to error path logging.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoRework network settings copy code.
Owen Smith [Mon, 26 Sep 2022 09:55:26 +0000 (10:55 +0100)]
Rework network settings copy code.

Rather than copying network settings twice (once on save and once on restore),
stash the current network interface Guid and network Luid on save and copy
settings from the previous Guid and Luid to the new location on restore.
By relying on the current settings, the copy code will always restore the
settings that are current. This will pick up any changes that are made without
requiring a copy from the save.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoStore the current network IDs before upgrade
Owen Smith [Mon, 26 Sep 2022 09:55:25 +0000 (10:55 +0100)]
Store the current network IDs before upgrade

Write the current NetCfgInstanceId and NetLuid to a store location during
the install preprocess step, so that XenVif can restore settings if the
network IDs are changed.
Write NetLuid and NetCfgInstanceId to XenVif's Settings key for this VIF index

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoAdd Svr2019, Svr2022 and Win11 to Inf2Cat
Owen Smith [Thu, 30 Jun 2022 14:24:03 +0000 (15:24 +0100)]
Add Svr2019, Svr2022 and Win11 to Inf2Cat

Signed-off-by: Owen Smith <owen.smith@citrix.com>
2 years agoAdd a Pause flag to the XENVIF_RECEIVER_QUEUE_PACKET callback parameters
Paul Durrant [Tue, 14 Jun 2022 09:04:07 +0000 (10:04 +0100)]
Add a Pause flag to the XENVIF_RECEIVER_QUEUE_PACKET callback parameters

The flag is used by the client driver to ask XENVIF to stop queueing packets
for a short period i.e. the current DPC invocation. Another DPC is scheduled
to process the remainder before any more packets are removed from the
descriptor ring (hence back-pressuring the network backend).

This patch involves bumping XENVIF_VIF_INTERFACE up to version 10. Code
is also added to set the Pause flag on behalf of older client drivers if
more than 1024 packets have been queued by a single DPC invocation.

This code is based on original patches [1] and [2] by Martin Harvey at Citrix.

[1] https://lists.xenproject.org/archives/html/win-pv-devel/2022-05/msg00043.html
[2] https://lists.xenproject.org/archives/html/win-pv-devel/2022-05/msg00042.html

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoAdd version 9 of XENVIF_VIF_INTERFACE
Paul Durrant [Fri, 10 Jun 2022 14:05:57 +0000 (15:05 +0100)]
Add version 9 of XENVIF_VIF_INTERFACE

This changes XENVIF_VIF_CALLBACK from a varargs function into function taking
a pointer to a new XENVIF_VIF_CALLBACK_PARAMETERS union which is now used to
pass all the arguments specific to the callback type.
To maintain support for version 8 clients a VifCallbackVersion8() function is
added as a shim to unpack the parameters structure and call the client's
varargs callback function.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoRetire old versions of XENVIF_VIF_INTERFACE
Paul Durrant [Fri, 10 Jun 2022 13:25:06 +0000 (14:25 +0100)]
Retire old versions of XENVIF_VIF_INTERFACE

Version 8 of the interface has been available since commit 4ccb01e2e24bc
("Pass the receive queue index to XENNET") in 2016. That's ample time for
deployed versions of XENNET to have been updated so let's retire interface
versions older than that.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoFix an IsZeroMemory() ASSERTion failure
Paul Durrant [Mon, 13 Jun 2022 13:20:02 +0000 (14:20 +0100)]
Fix an IsZeroMemory() ASSERTion failure

The TargetProcessor field of the XENVIF_RECEIVER_RING structure is not being
cleared and hence may be non-zero when the buffer is checked. This patch
rectifies the situation.

Fixes: eb83dbd5162d ("Windows PV drivers fail to set up RSS when vCPU index >= 8")
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoFix compiler options
Owen Smith [Thu, 5 May 2022 07:05:32 +0000 (08:05 +0100)]
Fix compiler options

Adds '/ZH:SHA_256' '/CETCOMPAT' '/sdl' to compiler and '/SafeSEH' to x86 linker
command lines
These changes were prompted by binskim https://github.com/microsoft/binskim

Note: Rule BA2004 (Warning_NativeWithInsecureStaticLibraryCompilands) is still
      reported for xenvif_coinst.dll

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoUse STATUS_PNP_REBOOT_REQUIRED in IRP_MN_START_DEVICE when a reboot is required
Owen Smith [Mon, 21 Mar 2022 14:23:07 +0000 (14:23 +0000)]
Use STATUS_PNP_REBOOT_REQUIRED in IRP_MN_START_DEVICE when a reboot is required

Failing IRP_MN_START_DEVICE can lead to WHQL distribution of drivers to be
rejected by MS, as too many VMs in the gradual rollout phase will report this
error on update. Using STATUS_PNP_REBOOT_REQUIRED will indicate that the VM
requires a reboot, and should not be treated as a gating factor (it should also
trigger the Windows Update process to report the reboot to users and/or trigger
an automatic reboot)

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoWindows PV drivers fail to set up RSS when vCPU index >= 8
Martin Harvey [Wed, 23 Mar 2022 10:33:47 +0000 (10:33 +0000)]
Windows PV drivers fail to set up RSS when vCPU index >= 8

The driver only supports at most 8 queues, however Windows
can decide to assign vCPU numbers starting from a non-zero
offset. E.g. vCPU 8,9,10,11 could get assigned to a device
if you have more than one NIC. The total number of vCPUs
used by a single device is still less than 8, but the vCPU
indexes themselves can be greater than 8. The code
previously incorrectly assumed that individual vCPU
indexes cannot exceed 8, however a 1:1 mapping between
vCPU indexes and queues seems to only exist when using
a single NIC.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
Removed unncessary error handling and tidied up.

Signed-off-by: Paul Durrant <paul@xen.org>
3 years agoAdd /CETCOMPAT to linker options
Owen Smith [Mon, 29 Nov 2021 09:58:37 +0000 (09:58 +0000)]
Add /CETCOMPAT to linker options

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoFix CodeQL warnings
Owen Smith [Thu, 12 Aug 2021 12:44:27 +0000 (13:44 +0100)]
Fix CodeQL warnings

- ExAllocatePoolWithTag has been deprecated with Win10 2004, use
    ExAllocatePoolUninitialized instead
- Check return value of _strtoui64 for error condition as indicated by
    _UI64_MAX

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoFix SDV/CodeQL log generation
Owen Smith [Thu, 12 Aug 2021 12:44:26 +0000 (13:44 +0100)]
Fix SDV/CodeQL log generation

- sarif files need to be stored with SDV logs when generating the DVL file
- Disable PREFast and CodeAnalysis by default
- Run a seperate CodeAnalysis build after SDV, but before generating DVL file
    DVL file should contain multiple summary lines for SDV, at least 1 line
    for CodeAnalysis and at least 1 line for Semmle (CodeQL)

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoDocument CodeQL build requirements
Owen Smith [Tue, 7 Sep 2021 08:10:46 +0000 (09:10 +0100)]
Document CodeQL build requirements

CodeQL requires an additional tool and rule set which are seperate from the
EWDK ISOs, and require manual installation and configuration

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoFix build with later WDKs
Owen Smith [Thu, 12 Aug 2021 12:44:25 +0000 (13:44 +0100)]
Fix build with later WDKs

- Adds alias for GetProjectInfoForReference target to version.vcxproj
    Later kits seemed to have renamed the build target, and will fail without
    this alias target.
- Adds "/fd sha256" to signtool command line
    WDK 20344 and later require binaries signed with a SHA256 file digest, or
    the build outputs are deleted
- Disables warning 4061 - switch statement on enum types need to have a case
    for all values of the enumeration

Signed-off-by: Owen Smith <owen.smith@citrix.com>
- Cast enum types used as array indices to avoid bounds check complaint

Signed-off-by: Paul Durrant <paul@xen.org>
3 years agoFix semantics of ASSERT3[P|S|U]
Paul Durrant [Mon, 6 Sep 2021 08:43:46 +0000 (09:43 +0100)]
Fix semantics of ASSERT3[P|S|U]

These ASSERTions are supposed to cast their arguments to pointer, signed or
unsigned values (respectively) before applying the operator. This is not
done correctly; the test and __analysis_assume() directive in the underlying
ASSERT() macro are applied to the un-cast values. This patch rectifies the
situation.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
3 years agoAdd ring disconnect logging.
Martin Harvey [Tue, 17 Aug 2021 08:33:04 +0000 (09:33 +0100)]
Add ring disconnect logging.

Logging to note error cases which would otherwise be silent in release builds.
This aids greatly with customer debugging.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
Cosmetic fixes.

Signed-off-by: Paul Durrant <paul@xen.org>
3 years agoReduce logging of Fdo->NotDisableable
Martin Harvey [Wed, 28 Jul 2021 14:02:47 +0000 (15:02 +0100)]
Reduce logging of Fdo->NotDisableable

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
3 years agoAssert that transmitter not being sent NULL MDL's
Martin Harvey [Wed, 28 Jul 2021 14:02:46 +0000 (15:02 +0100)]
Assert that transmitter not being sent NULL MDL's

An assertion to check that a corresponding fix in XenNet is preventing
NULL MDL's from being queued for transmission.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
3 years agoLog waits for backend state changes.
Martin Harvey [Wed, 28 Jul 2021 14:02:45 +0000 (15:02 +0100)]
Log waits for backend state changes.

In addition to preceding changes to ring disconnects, and
associated logging, we also add some logging to check
whether state change notifications are being sent in a timely
manner between frontend and backend. Also a great assistance
to customer debugging.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
3 years agoImprove transmitter disable.
Martin Harvey [Wed, 28 Jul 2021 14:02:43 +0000 (15:02 +0100)]
Improve transmitter disable.

In some cases, the backend may stop processing Tx ring
requests in a timely manner. If this happens at the same time as ring
disable, then the Tx code could spin forever at dispatch IRQL.

This patch introduces a hard limit on how long the code will spin,
allowing a device disable or power transition to complete, albeit
at the cost of Tx requests being dropped or the ring being in
an indeterminate state. This has normally been seen at guest shutdown
where final ring state is of little consequence.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
3 years agoFail if multi-queue-max-queues is 0
Owen Smith [Wed, 14 Jul 2021 10:39:43 +0000 (11:39 +0100)]
Fail if multi-queue-max-queues is 0

Validate backend has correctly set multi-queue-max-queues, and add ASSERTions
to NumQueues and MaxQueues accessors to validate they are not 0

Signed-off-by: Owen Smith <owen.smith@citrix.com>
4 years agoAdd CodeQL build stage
Owen Smith [Fri, 5 Mar 2021 10:16:20 +0000 (10:16 +0000)]
Add CodeQL build stage

CodeQL logs will be required for future WHQL submissions. Add a stage
that generates the required SARIF files. CodeQL is a semantic code
analysis engine, which will highlight vunerabilities that will need
fixing.

In order to use CodeQL, the CodeQL binaries must be on the path and the
Windows-Driver-Developer-Supplemental-Tools must be on the path defined
by the CODEQL_QUERY_SUITE environment variable (if defined), or under
the parent folder (if CODEQL_QUERY_SUITE variable is not defined)

Note: Due to the way the codeql command line is built, using quotes in a
MSBuild command line is not possible, so generate a batch file to wrap
the command line.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
4 years agoBring XENBUS interface versions up to date...
Paul Durrant [Mon, 22 Feb 2021 10:37:14 +0000 (10:37 +0000)]
Bring XENBUS interface versions up to date...

... and update binding accordlingly.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
4 years agoDon't assume queue numbers can't be larger than 99
Paul Durrant [Tue, 1 Dec 2020 13:37:16 +0000 (13:37 +0000)]
Don't assume queue numbers can't be larger than 99

The theoretical maximum number of receiver or transmitter queues is limited at
the number of vCPUs in the VM, and this can be as many as 128 (limited by
Xen).

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
4 years agoInherit versioning info from environment if present
Nicholas Tsirakis [Fri, 6 Nov 2020 20:48:44 +0000 (15:48 -0500)]
Inherit versioning info from environment if present

As the drivers stabilize and mature, there is an ever-growing
chance that other opensource virtualization projects will adopt
them. Allow external projects to inject their own versioning
into the drivers instead of hardcoding the latest winpv version.

Signed-off-by: Nicholas Tsirakis <tsirakisn@ainfosec.com>
Acked-by: Owen Smith <owen.smith@citrix.com>
4 years agoAllow user to specify desired build architecture
Nicholas Tsirakis [Fri, 6 Nov 2020 20:48:43 +0000 (15:48 -0500)]
Allow user to specify desired build architecture

Often times we only need to build a driver for a single
targeted architecture. Continue to build both by default,
but allow the user to specify one if desired.

Signed-off-by: Nicholas Tsirakis <tsirakisn@ainfosec.com>
Use [string]::IsNullOrEmpty($Arch)

Signed-off-by: Paul Durrant <paul@xen.org>
4 years agoDont mix Exclusive and Shared locking calls
Owen Smith [Tue, 4 Aug 2020 14:49:21 +0000 (15:49 +0100)]
Dont mix Exclusive and Shared locking calls

If the lock is acquired with ExAcquireSpinLockSharedAtDpcLevel(), it
should always be released with ExReleaseSpinLockSharedFromDpcLevel()
(unless the lock is converted to an exclusive lock)

Signed-off-by: Owen Smith <owen.smith@citrix.com>
4 years agoDon't pass MM_DONT_ZERO_ALLOCATION to MmAllocatePagesForMdlEx()...
Paul Durrant [Tue, 16 Jun 2020 12:48:27 +0000 (13:48 +0100)]
Don't pass MM_DONT_ZERO_ALLOCATION to MmAllocatePagesForMdlEx()...

...in __AllocatePages()

See commit 4f85d004 "Replace uses of MmAllocatePagesForMdlEx in
__AllocatePage" for more background.

In summary, it is to avoid BSOD 139 1e with a stack similar to the following:

nt!KeBugCheckEx
nt!KiBugCheckDispatch+0x69
nt!KiFastFailDispatch+0xd0
nt!KiRaiseSecurityCheckFailure+0x30e
nt!KiAcquireThreadStateLock+0x11fa90
nt!KeSetIdealProcessorThreadEx+0xd0
nt!MiZeroInParallelWorker+0x115016
nt!MiZeroInParallel+0x11c
nt!MiInitializeMdlBatchPages+0x2ae
nt!MiAllocatePagesForMdl+0x192
nt!MmAllocatePartitionNodePagesForMdlEx+0xc9
nt!MmAllocatePagesForMdlEx+0x4d

These bugchecks have been observed in recent updates of Server 2019.

This patch, rather than replacing calls to MmAllocatePagesForMdlEx() with
calls to MmMapLockedPagesSpecifyCache(), just avoids passing
MM_DONT_ZERO_ALLOCATION to work round the bug.

The patch instead passes MM_ALLOCATE_FULLY_REQUIRED, which arguably should
have always been passed for allocations larger than a single page. It also
fixes a formatting issue.

Reported-by: Jan Bakuwel <jan.bakuwel@gmail.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---

This fix will also be propogated to all other PV drivers.

5 years agoMake sure fixed size CHAR arrays can fit MAX_ULONGs
Owen Smith [Mon, 27 Apr 2020 10:38:47 +0000 (11:38 +0100)]
Make sure fixed size CHAR arrays can fit MAX_ULONGs

When formatting strings with %u, make sure the target buffer is large
enough to contain MAX_ULONG.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoHandle return codes from MSBuild
Owen Smith [Tue, 10 Mar 2020 10:47:03 +0000 (10:47 +0000)]
Handle return codes from MSBuild

If MSBuild fails, it returns a non-zero return value. Forward this
failure to the calling scripts to fail earlier.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoMAINTAINERS: Update my email address
Paul Durrant [Tue, 10 Mar 2020 10:56:55 +0000 (10:56 +0000)]
MAINTAINERS: Update my email address

My @amazon.com address is no longer convenient to use.

Signed-off-by: Paul Durrant <paul@xen.org>
5 years agobump version to 9.1.0
Paul Durrant [Fri, 6 Dec 2019 12:11:48 +0000 (12:11 +0000)]
bump version to 9.1.0

Now that 9.0 is branched (in staging-9.0) the master version needs to be
advanced.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
5 years agoMAINTAINERS: Update my email address staging-9.0 9.0.0 9.0.0-rc1
Paul Durrant [Thu, 14 Nov 2019 10:11:28 +0000 (10:11 +0000)]
MAINTAINERS: Update my email address

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
5 years agoReduce xenstore churn
Owen Smith [Wed, 13 Nov 2019 15:43:54 +0000 (15:43 +0000)]
Reduce xenstore churn

Only write the complete changes to the xenstore MAC address table. There
is no need to write the complete table for each addition or removal,
when additions and removals are processed in a single update.

Pushes the responsibility for writing the MAC table to
FrontendSetMulticastAddresses() once all changes are made, instead of
for each call to MacAddMulticastAddress() or MacRemoveMulticastAddress()

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoAdd support for EWDK_19h1_release_svc_prod3_18362_190416-1111
Paul Durrant [Thu, 19 Sep 2019 10:49:42 +0000 (11:49 +0100)]
Add support for EWDK_19h1_release_svc_prod3_18362_190416-1111

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
5 years agoMAINTAINERS: Update my email address
Paul Durrant [Thu, 19 Sep 2019 10:20:32 +0000 (11:20 +0100)]
MAINTAINERS: Update my email address

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
5 years agoRemove the old python build scripts and document use of the EWDK
Paul Durrant [Thu, 19 Sep 2019 10:12:12 +0000 (11:12 +0100)]
Remove the old python build scripts and document use of the EWDK

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
5 years agoRemove erroneously committed file
Paul Durrant [Wed, 17 Jul 2019 12:27:15 +0000 (13:27 +0100)]
Remove erroneously committed file

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
5 years agoUpdate cache_interface header
Owen Smith [Wed, 17 Jul 2019 12:18:33 +0000 (13:18 +0100)]
Update cache_interface header

Requires bumping the INF revision and revision table

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoUse genfiles.ps1 to generate inf date
Owen Smith [Wed, 17 Jul 2019 12:24:36 +0000 (13:24 +0100)]
Use genfiles.ps1 to generate inf date

stampinf is no longer used, so genfiles.ps1 must be able to write the
DriverVer field in the inf file.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoAdd PowerShell build scripts, version.vcxproj
Owen Smith [Fri, 14 Jun 2019 16:16:20 +0000 (17:16 +0100)]
Add PowerShell build scripts, version.vcxproj

Based on the sequence of commits to xenbus, add powershell scripts to
build the solution using the EWDK
version.vcxproj generates versioned files (version.h and xenvif.inf) using
 scripts/genfiles.ps1
Strips duplicated functionality from build.py to produce consistant
builds between python and powershell.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoAdd BUILD_NUMBER to reported version
Owen Smith [Fri, 14 Jun 2019 16:05:40 +0000 (17:05 +0100)]
Add BUILD_NUMBER to reported version

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoStop lying about the lock state when calling into XENBUS_CACHE
Paul Durrant [Fri, 31 May 2019 09:53:45 +0000 (10:53 +0100)]
Stop lying about the lock state when calling into XENBUS_CACHE

Various cache access that used to be under protection of the reciver ring
lock are no longer subject to that lock, and thus the 'Locked' parameter
passed to the Get/Put methods needs to be FALSE rather than TRUE.

This bug was not spotted under recent changes applied to the implementation
of XENBUS_CACHE, which removed use of atomic bit operations.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoPort "Ignore unused devices when checking for compatability" from XENBUS
Paul Durrant [Thu, 20 Dec 2018 17:34:49 +0000 (17:34 +0000)]
Port "Ignore unused devices when checking for compatability" from XENBUS

XENBUS commit caf35361 fixes an upgrade issue with dangling references
left in ENUM keys. This patch applies the same fix to XENVIF.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoAllow advertised 'wire' speed to be overridden by a registry value...
Paul Durrant [Fri, 2 Nov 2018 17:16:58 +0000 (17:16 +0000)]
Allow advertised 'wire' speed to be overridden by a registry value...

...and change the default to 100G.

This patch adds code to check for a new 'MacSpeed' XENVIF parameter
(sampled at initialization time), defaulting to a wire speed of 100G if
it is not present (rather than the 1G default prior to this patch).

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoAdd a xenstore watch for the "speed" key...
Paul Durrant [Fri, 2 Nov 2018 15:51:31 +0000 (15:51 +0000)]
Add a xenstore watch for the "speed" key...

...and allow the value to specify units.

The 'wire' speed advertised by XENNET to the Windows network stack can be
controlled by the value of a "speed" key in the xenstore frontend area.
Values of this key are currently interpreted as decimal gigabits-per-second.

This patch sets a watch on the key (meaning changes to it now take
immediate effect) and allows units to be specified: 'G/g' for gigabits-per-
second, 'M/m' for megabits-per-second, and 'K/k' for kilobit-per-second.
Thus, for example, '100M' means 100 megabits-per-second. If no unit is
specified then the value is assumed to be in gigabits-per-second, as before.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoSet packet transmit completion information outside of ring lock
Paul Durrant [Fri, 2 Nov 2018 14:16:40 +0000 (14:16 +0000)]
Set packet transmit completion information outside of ring lock

There is no need to hold the ring lock to update the packet transmit
completion information, or update the frontend statistics. This patch
creates a new __TransmitterSetCompletionInfo() function and calls this
just before returning each packet to XENNET, after the ring lock has been
dropped.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoDon't force event channel unmasking
Paul Durrant [Fri, 2 Nov 2018 11:49:06 +0000 (11:49 +0000)]
Don't force event channel unmasking

The effect of efbe65aa "Make use of possible XENBUS_EVTCHN Unmask failure"
was lost when the poller subsystem was reverted. This patch re-instates
equivalent functionality.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoGet rid of the 'Retry' exit from the ring poll routines
Paul Durrant [Fri, 2 Nov 2018 11:42:47 +0000 (11:42 +0000)]
Get rid of the 'Retry' exit from the ring poll routines

This was supposed to allow better interleaving of receive and transmit
polling, but this does not really seem to help so it really only makes
the code more complex than it needs to be.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoRe-instate 264bde12 "Introduce a threaded DPC into the receiver code"
Paul Durrant [Fri, 2 Nov 2018 11:34:39 +0000 (11:34 +0000)]
Re-instate 264bde12 "Introduce a threaded DPC into the receiver code"

This patch re-works 264bde12 such that it apply (after reversion of the
poller subsystem), including re-naming the unqualified 'Dpc' and 'Dpcs'
fields in the receiver and transmitter ring structures to 'PollDpc' and
'PollDpcs' to disambiguate them from the new threaded 'QueueDpc' and
associated 'QueueDpcs' counter.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoRemove KTIMERS from transmit and receive paths (again)
Paul Durrant [Fri, 2 Nov 2018 11:09:11 +0000 (11:09 +0000)]
Remove KTIMERS from transmit and receive paths (again)

Even though the poller subsystem has been reverted, these still need to
go away as they do not adequately serve the purpose for which they were
added: DPC watchdog avoidance.

A subsequent patch will re-instate the threaded DPC in the receiver to
avoid the DPC watchdog.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoRevert complete poller subsystem
Paul Durrant [Thu, 1 Nov 2018 14:14:38 +0000 (14:14 +0000)]
Revert complete poller subsystem

It seems to have a bad effect on performance that various attempts at
improvement just don't seem to be able fix, so this patch just gets rid
of the whole thing.

This patch reverts the following commits:

 264bde12 "Introduce a threaded DPC into the receiver code"
 129ad516 "Stop using a threaded DPC in the poller"
 5932938b "Don't bump the receiver event counter if the poller is going to retry"
 16002b8f "poller: fix event channels when backends do not support multi-queue"
 bc722edd "Don't use KTIMERs in receive path"
 dfaa68cc "Don't affinitize timer DPC"
 eac9a95a "Move the Receiver and Transmitter event and DPC processing..."
 40be5c12 "Add the boilerplate for a new Poller sub-system"

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoRevert "Replace uses of MmAllocatePagesForMdlEx in __AllocatePage"
Paul Durrant [Thu, 1 Nov 2018 16:43:32 +0000 (16:43 +0000)]
Revert "Replace uses of MmAllocatePagesForMdlEx in __AllocatePage"

This reverts commit 4f85d004. This patch was put in place to work around
a bug in Windows but seems to have a serious negative effect on
performance. The bug in Windows has since been fixed so the patch can now
be reverted to recover performance.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoRevert reversion of "Deferring transmit completion causes...
Paul Durrant [Thu, 1 Nov 2018 14:59:10 +0000 (14:59 +0000)]
Revert reversion of "Deferring transmit completion causes...

... MPE_Ethernet test failures""

This reverts commit 0f91d01d as it is very detrimental to performance. It
appears that deferring transmit completion events roughly halves TCP
throughput.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoAdd missing status to error log
Owen Smith [Fri, 28 Sep 2018 12:12:14 +0000 (13:12 +0100)]
Add missing status to error log

Signed-off-by: Owen Smith <owen.smith@citrix.com>
6 years agoIntroduce a threaded DPC into the receiver code
Paul Durrant [Tue, 18 Sep 2018 13:48:49 +0000 (14:48 +0100)]
Introduce a threaded DPC into the receiver code

To avoid problems with DPC timeouts move the majority of the receiver's
work, and interaction with the network stack, into a threaded DPC. This
leaves the poll entry point (called from the now non-threaded poller DPC)
to simply service responses and build a local packet queue that is then
drained by the threaded DPC.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoAllow FrontendIncrementStatistic() to be called at < DISPATCH_LEVEL
Paul Durrant [Tue, 18 Sep 2018 13:34:23 +0000 (14:34 +0100)]
Allow FrontendIncrementStatistic() to be called at < DISPATCH_LEVEL

Swap the ASSERTion for a KeRaiseIrql().

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoUse a reader/writer lock in the mac module
Paul Durrant [Tue, 18 Sep 2018 13:30:21 +0000 (14:30 +0100)]
Use a reader/writer lock in the mac module

Each receiver thread needs to call MacApplyFilters() but the implementation
uses a normal kernel spin lock and hence the threads will all contend the
lock. Switch the mac code to use a reader/writer lock so that
MacApplyFilters() can acquire the lock as a reader and thus avoid causing
the contention.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoMake sure event counter is updated before finish receiver ring poll
Paul Durrant [Tue, 18 Sep 2018 13:24:15 +0000 (14:24 +0100)]
Make sure event counter is updated before finish receiver ring poll

There was a flaw in commit 5932938b "Don't bump the receiver event counter
if the poller is going to retry" in that it is possible to drop out of
poll without ever updating the event counter (if one attempt requests a
retry and the next attempt finds nothing to do). This patch fixes the
issue by using the RING_FINAL_CHECK_FOR_RESPONSES macro to update the
event counter, which checks for a race with new responses.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoStop using a threaded DPC in the poller
Paul Durrant [Tue, 18 Sep 2018 13:18:14 +0000 (14:18 +0100)]
Stop using a threaded DPC in the poller

The threaded DPC was introduced by commit bc722edd "Don't use KTIMERs in
receive path" but it appears to have too much of an impact on performance.
This patch reverts the poller to a normal DPC but does not introduce any
DPC timeout mitigation. That will be done by a subsequent patch.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoConditionally package DPInst
Owen Smith [Fri, 24 Aug 2018 16:46:43 +0000 (17:46 +0100)]
Conditionally package DPInst

Since DPInst.exe is not shipped with the Windows Driver Kit 10, an
environment variable must point to local copies. Make the inclusion of
DPInst conditional on DPINST_REDIST being defined and that path
existing. This simplifies building packages which do not require DPInst
for installation, and removes a required step to create a working build.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
6 years agoDon't bump the receiver event counter if the poller is going to retry
Paul Durrant [Mon, 6 Aug 2018 12:11:39 +0000 (13:11 +0100)]
Don't bump the receiver event counter if the poller is going to retry

There is little point in bumping rsp_event (to trigger a new event from
the backend) if the poller is going to retry, so we can save modifying the
shared ring in this case.

This patch also adds extra debug code to the poller to make sure it never
exits from the main loop until either there are no retries pending or
the instance has been disabled.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoWork around bug in VS2017 SDV
Paul Durrant [Thu, 19 Jul 2018 09:25:03 +0000 (10:25 +0100)]
Work around bug in VS2017 SDV

XENBUS commit 868cd40f (of the same name) introduced a workaround for a
quoting bug in SDV. This commit applies a similar workaround for XENVIF.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoFix SDV release parameter
Paul Durrant [Wed, 18 Jul 2018 13:30:18 +0000 (14:30 +0100)]
Fix SDV release parameter

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoDisable warning about spectre mitigation
Marek Marczykowski-Górecki [Tue, 10 Jul 2018 13:23:20 +0000 (14:23 +0100)]
Disable warning about spectre mitigation

CL emits a warning about every place that will get spectre mitigation
when compiled with /Qspectre. Even if this option is already used. This
breaks the build if warnings are treated as errors.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Also disable the same warning in the co-installer build.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoReplace uses of MmAllocatePagesForMdlEx in __AllocatePage
Ben Chalmers [Tue, 10 Jul 2018 10:09:59 +0000 (11:09 +0100)]
Replace uses of MmAllocatePagesForMdlEx in __AllocatePage

Windows appears to have an edge case bug in which zeroing
memory using MmAllocatePAgesForMdlEx (which in Win 10 1803
happens even if you specify MM_DONT_ZERO_ALLOCATION) can cause
a BSOD 139 1e.

This commit uses MmAllocateContinguousMemorySpecifyCache
to allocate memory instead, then builds and Mdl to wrap
it up.

__AllocatePages is left unchanged (as we don't want
to allocate multiple contiguous pages).  This issue
has not been seen outside of xenvif calls to
__AllocatePage and we expect a fix to the underlying
Windows problem in the near future

Signed-off-by: Ben.Chalmers <ben.chalmers@citrix.com>
6 years agoUpdate GNTTAB interface header
Owen Smith [Tue, 26 Jun 2018 11:56:26 +0000 (12:56 +0100)]
Update GNTTAB interface header

Also updates revision to 09000004

Signed-off-by: Owen Smith <owen.smith@citrix.com>
7 years agoCheck Mdl, not Controller->Mdl for allocation failure
Ben Chalmers [Mon, 23 Apr 2018 08:46:39 +0000 (09:46 +0100)]
Check Mdl, not Controller->Mdl for allocation failure

Ensure we fall through error handlers, rather than BSOD.

Signed-off-by: Ben Chalmers <ben.chalmers@citrix.com>
Also fix another instance of the incorrect check.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agopoller: fix event channels when backends do not support multi-queue
Chris Patterson [Wed, 21 Feb 2018 09:54:57 +0000 (09:54 +0000)]
poller: fix event channels when backends do not support multi-queue

The event channels for rx & tx are written to a multi-queue formatted
path even when multiple queues are not supported. This results in a hung
VM with the following logs:
XENBUS|EvtchnWait: TIMED OUT: Count = 00000001 Channel->Count = 00000000
...

This can be reproduced by having a Linux VM network backend with 1 vCPU.

If FrontendGetNumQueues() is 1 and multiple queues are not supported,
the following paths are used for the poller event channel:
    device/vif/1/queue-0/event-channel-[rx|tx]

However, the proper xenstore path in this case is:
    device/vif/1/event-channel-[rx|tx]

PollerInstanceInitialize() sets its path using FrontendFormatPath(),
which assumes a multi-queue path layout.  This is done in a fashion
similar to the transmitter and receiver rings.  However, the tx/rx rings
check for the mutually supported number of queues to determine the
actual path written to xenstore, using FrontendGetNumQueues(). See
__TransmitterRingStoreWrite() and __ReceiverRingStoreWrite().  This patch
adds a similar procedure for the poller to write to the appropriate path
in xenstore.

Signed-off-by: Chris Patterson <cjp256@gmail.com>
7 years agoDo more optimization in release builds and add /Qspectre flag
Paul Durrant [Mon, 29 Jan 2018 15:48:17 +0000 (15:48 +0000)]
Do more optimization in release builds and add /Qspectre flag

Spectre mitigations apparently only work on optimized code.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoAdd support for building with Visual Studio 2017
Paul Durrant [Mon, 29 Jan 2018 15:37:56 +0000 (15:37 +0000)]
Add support for building with Visual Studio 2017

Also remove mappings for obsolete versions of VS in build.py.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoDon't use KTIMERs in receive path
Paul Durrant [Fri, 26 Jan 2018 15:08:15 +0000 (15:08 +0000)]
Don't use KTIMERs in receive path

They appear to always defer by at least one timer tick, which is about 16ms
by default... just too long.

Instead, to avoid DPC watchdog issues in the MPE_Ethernet test, use a
threaded DPC. This is a real-time thread that can be pre-empted by normal
DPCs but not by standard system threads.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoFix NDISTest6.5 CheckConnectivity and others
Paul Durrant [Wed, 24 Jan 2018 14:40:53 +0000 (14:40 +0000)]
Fix NDISTest6.5 CheckConnectivity and others

Commit e5e64b57 "Don't try to __FreePages() with local copy of MDL"
introduced subtle breakage into the receive path.

Prior to this patch, for the MDLs embedded in receiver packets, it was
always true that Mdl->MappedSystemVa == Mdl->StartVa + Mdl->ByteOffset.
However, after the commit, Mdl->StartVa was left as NULL in the assumption
that Mdl->MappedSystemVa would always be used to access the buffer. Sadly
this appears not to always be the case and in fact, wdm.h carries this
comment:

// Notice that while in the context of the subject thread, the base virtual
// address of a buffer mapped by an MDL may be referenced using the
// following:
//
//      Mdl->StartVa | Mdl->ByteOffset
//

So the the previous setting of StartVa is indeed documented, and clearly
something in the network tests is relying on it.

This patch modifies the MDL allocator code in util.h to alwasy set StartVa,
and modifies the receiver code to carry this field forward into the
embedded MDLs. It also removes some code duplication in ReceiverPacketCtor()
and __ReceiverRingPutPacket().

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoDon't affinitize timer DPC
Paul Durrant [Fri, 3 Nov 2017 16:09:38 +0000 (16:09 +0000)]
Don't affinitize timer DPC

Instead just use it to schedule the normal DPC from wherever it is run.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoRevert "Deferring transmit completion causes MPE_Ethernet test failures"
Paul Durrant [Thu, 2 Nov 2017 15:27:18 +0000 (15:27 +0000)]
Revert "Deferring transmit completion causes MPE_Ethernet test failures"

This reverts commit 761e6abe, but also adds a low frequency transmit
poller thread to try to avoid an unbounded transmit completion delay.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoMake use of possible XENBUS_EVTCHN Unmask failure
Paul Durrant [Fri, 20 Oct 2017 17:14:28 +0000 (18:14 +0100)]
Make use of possible XENBUS_EVTCHN Unmask failure

Bump up to the latest version of XENBUS_EVTCHN and specify the option
to Unmask that allows it to fail. In this circumstance it is possible to
avoid dropping out of the DPC and thus avoid a context switch and re-queue.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoMove the Receiver and Transmitter event and DPC processing...
Paul Durrant [Wed, 18 Oct 2017 14:02:52 +0000 (15:02 +0100)]
Move the Receiver and Transmitter event and DPC processing...

...into the new Poller sub-system.

For efficiency it is desirable to have a single DPC handle both Receiver
and Transmitter polling, even if there are separate event channels for
the shared rings.

This patch moves all the basic event and DPC code into the Poller
subsystem, which calls back into the Transmitter and Receiver sub-systems
(to poll the shared rings) from its single per-CPU DPC.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>