]> xenbits.xensource.com Git - pvdrivers/win/xennet.git/log
pvdrivers/win/xennet.git
2 years agoScripted replacement of Copyright notices in source
Owen Smith [Thu, 23 Feb 2023 09:50:43 +0000 (09:50 +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:50:42 +0000 (09:50 +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:50:41 +0000 (09:50 +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 agoAdd annotation to fix SDV failure
Owen Smith [Mon, 30 Jan 2023 15:03:58 +0000 (15:03 +0000)]
Add annotation to fix SDV failure

SDV can detect the BytesNeeded value may be 0, as it cannot determine the value
of some constants.

Signed-off-by: Alex Burke <Alex.Burke@citrix.com>
Signed-off-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 13:17:15 +0000 (13:17 +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 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 agoUpdate to XENVIF_VIF_INTERFACE version 10
Paul Durrant [Tue, 14 Jun 2022 13:33:50 +0000 (14:33 +0100)]
Update to XENVIF_VIF_INTERFACE version 10

This based on an original patch [1] by Martin Harvey at Citrix. The new Pause flag
added to the XENVIF_RECEIVER_QUEUE_PACKET callback parameters is used when 'low
resources' is indicated to NDIS to request that XENVIF stops queueing packets
for a short period of time (i.e. the time taked to re-schedule the DPC).

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

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoUpdate to XENVIF_VIF_INTERFACE version 9
Paul Durrant [Mon, 13 Jun 2022 13:47:37 +0000 (14:47 +0100)]
Update to XENVIF_VIF_INTERFACE version 9

This means we need to re-work the varargs AdapterVifCallback() function into a
new version that deals with the new XENVIF_VIF_CALLBACK_PARAMETERS structure.
Otherwise there is no functional change.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
2 years agoFix compiler options
Owen Smith [Thu, 5 May 2022 07:04:09 +0000 (08:04 +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 xennet_coinst.dll

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoUse NDIS 6.85 interfaces, if available
Owen Smith [Tue, 26 Oct 2021 07:12:11 +0000 (08:12 +0100)]
Use NDIS 6.85 interfaces, if available

NDIS 6.85 was introduced in Server 2022, and the "NICStrictPropertyValidation"
test requires that drivers for Server 2022 declare support for NDIS 6.85.
Conditionally include the minimum NDIS 6.85 support, if available in the WDK,
in order to pass this test. No additional features of NDIS 6.85 have been
included.
NDIS_RUNTIME_VERSION_685 is only defined if the ndis.h header is from WDK 20384
or later, and NDIS685_MINIPORT is defined by the project.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoUse NDIS 6.60 interfaces, if supported
Owen Smith [Tue, 26 Oct 2021 07:12:10 +0000 (08:12 +0100)]
Use NDIS 6.60 interfaces, if supported

Server 2016 introduced NDIS 6.60, update the interfaces to use NDIS 6.60 if
the reported NDIS runtime version supports this. No additional features of
NDIS 6.60 are used.
Also corrects the PhysicalMediaType property, which would otherwise block
functionality

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoUpdate to NDIS 6.30
Owen Smith [Mon, 15 Nov 2021 09:32:14 +0000 (09:32 +0000)]
Update to NDIS 6.30

NDIS 6.30 was introduced in Server 2012. Update XenNet to use the NDIS 6.30
interfaces, including internal changes required by NDIS 6.30. Any new features
introduced in NDIS 6.30 are not implemented, only changes required to complete
the NDIS version update.
- Updates structure header versions and sizes as required
- Changes the indirection table from CPU index to PROCESSOR_NUMBER array, note
  that XenNet handled a conversion from index to PROCESSOR_NUMBER before passing
  to XenVif. Renames TableSize to TableCount for clarity.
- Adds a new INF property 'NumRSSQueues', which limits the number of RSS queues.
  This is a WHQL test requirement (NDIS 6.5 StandardizedKeywords)
- Fixes "NDIS 6.5 GlitchFreeDevice" test by correctly reporting XenNet uses a
  WDM lower edge.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoAdd /CETCOMPAT to linker options
Owen Smith [Tue, 26 Oct 2021 07:12:08 +0000 (08:12 +0100)]
Add /CETCOMPAT to linker options

The "Hardware Enforced Stack Protection Compatability" test introduced with the
Server 2022 HLK requires drivers to be linked with /CETCOMPAT

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoUse vs2019 projects for VS 16.0
Owen Smith [Thu, 23 Sep 2021 14:53:47 +0000 (15:53 +0100)]
Use vs2019 projects for VS 16.0

Fixes SDV build with EWDK22000, which fails with warning 4061

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

- ExAllocatePoolWithTag is deprecated in Win10 2004, use
    ExAllocatePoolUninitialized instead
- QueryCapabilities structure contains padding bytes, using
    __AllocatePoolWithTag zeros this memory

Signed-off-by: Owen Smith <owen.smith@citrix.com>
3 years agoFix SDV/CodeQL log generation
Owen Smith [Thu, 12 Aug 2021 12:39:06 +0000 (13:39 +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:39:05 +0000 (13:39 +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

Signed-off-by: Owen Smith <owen.smith@citrix.com>
- Squash warnings 4061 and 4062 as they lead to a lot of bogus noise.
- Add a somewhat pointless ASSERT for a condition that has already been
  tested to stop the compiler complaining.

Signed-off-by: Paul Durrant <paul@xen.org>
3 years agoPrevent NULL MDL's from being queued for transmission.
Martin Harvey [Wed, 28 Jul 2021 14:02:04 +0000 (15:02 +0100)]
Prevent NULL MDL's from being queued for transmission.

Under conditions of high load and low resources, it was
possible for NDIS (in combination with overlying drivers) to send
NET_BUFFER_LIST structures containing NULL MDL's for transmission.
This resulted in an immediate bugcheck.

This patch prevents NULL MDL's from being sent to XenVif.

Signed-off-by: Martin Harvey <martin.harvey@citrix.com>
4 years agoAdd CodeQL build stage
Owen Smith [Fri, 5 Mar 2021 10:15:49 +0000 (10:15 +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 agoUpdate XENBUS and XENVIF interface versions...
Paul Durrant [Mon, 22 Feb 2021 10:46:42 +0000 (10:46 +0000)]
Update XENBUS and XENVIF interface versions...

... and update binding. No functional change.

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 agoDon't pass MM_DONT_ZERO_ALLOCATION to MmAllocatePagesForMdlEx()...
Paul Durrant [Wed, 17 Jun 2020 08:48:34 +0000 (09:48 +0100)]
Don't pass MM_DONT_ZERO_ALLOCATION to MmAllocatePagesForMdlEx()...

...in __AllocatePages()

See commit 4f85d004 "Replace uses of MmAllocatePagesForMdlEx in
__AllocatePage" in XENVIF 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.

NOTE: Nothing in XENNET currently calls __AllocatePages() so this patch is
      not strictly necessary. However, in case a caller is added in future,
      it is best to keep util.h in sync with the other drivers.

Reported-by: Jan Bakuwel <jan.bakuwel@gmail.com>
Signed-off-by: Paul Durrant <pdurrant@amazon.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-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 agoAdd support for EWDK_19h1_release_svc_prod3_18362_190416-1111 9.0.0
Paul Durrant [Thu, 19 Sep 2019 11:05:07 +0000 (12:05 +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:58:08 +0000 (11:58 +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:54:53 +0000 (11:54 +0100)]
Remove the old python build scripts and document use of the EWDK

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
5 years agoUse genfiles to set DriverVer
Owen Smith [Wed, 17 Jul 2019 12:46:00 +0000 (13:46 +0100)]
Use genfiles to set DriverVer

Signed-off-by: Owen Smith <owen.smith@citrix.com>
5 years agoAdd PowerShell build scripts, version.vcxproj
Owen Smith [Fri, 14 Jun 2019 16:32:33 +0000 (17:32 +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 xennet.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:19:21 +0000 (17:19 +0100)]
Add BUILD_NUMBER to reported version

Signed-off-by: Owen Smith <owen.smith@citrix.com>
6 years agoRemove unused OID
Paul Durrant [Fri, 2 Nov 2018 17:22:21 +0000 (17:22 +0000)]
Remove unused OID

OID_GEN_LINK_SPEED is apparently not used by NDIS 6.0+ stacks so there is
little point in implementing it.

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 agoWork around bug in VS2017 SDV
Paul Durrant [Thu, 19 Jul 2018 09:40:40 +0000 (10:40 +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 XENNET.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
6 years agoFix SDV release parameter
Paul Durrant [Thu, 19 Jul 2018 09:33:35 +0000 (10:33 +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:31:46 +0000 (14:31 +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, as warnings are treated as errors in xennet.

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

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoDo more optimization in release builds and add /Qspectre flag
Paul Durrant [Mon, 29 Jan 2018 16:50:54 +0000 (16:50 +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 16:41:58 +0000 (16:41 +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 agoUpdate util.h
Paul Durrant [Thu, 25 Jan 2018 12:51:06 +0000 (12:51 +0000)]
Update util.h

XENNET does not use much of the functionality in util.h, including the
__AllocatePages()/__FreePages() functions modified by this change, however
it is good to keep the header in-sync with the other drivers.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoFix link state change notifications
Paul Durrant [Thu, 25 May 2017 01:40:04 +0000 (21:40 -0400)]
Fix link state change notifications

These indications were broken by an incorrect size in the status
indication header.

This patch corrects the size field, adjusts the buffer size field and
also corrects the format specifier used to log the link speed.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
7 years agoRemove VS2012 and VS2013 build scripts
Paul Durrant [Thu, 18 May 2017 14:02:21 +0000 (15:02 +0100)]
Remove VS2012 and VS2013 build scripts

This patch removes the scripts for building under VS2013 and VS2013 and
also fixes the package destination when building using VS2015.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix low resources packet leak
Paul Durrant [Wed, 8 Feb 2017 10:47:06 +0000 (10:47 +0000)]
Fix low resources packet leak

When the low resources limit is hit then the NDIS_RECEIVE_FLAGS_RESOURCES
is passed to NdisMIndicateReceiveNetBufferLists(), which means that the
calling code can assume the NET_BUFFER_LIST is immediately released.
The code therefore attempts to immediately release the chain of
NET_BUFFER_LIST, but because __IndicateReceiveNetBufferLists() segmented
the chain, only the first one is actually released. This leads to a
resource leak which also prevents XENVIF from shutting down correctly
(waiting for the leaked packets to be returned).

This patch fixes the issue by handling the release of individual
NET_BUFFER_LISTs directly in __IndicateReceiveNetBufferLists(), if the
NDIS_RECEIVE_FLAGS_RESOURCES is set.

Reported-by: Martin Cerveny <martin@c-home.cz>
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Tested-by: Martin Cerveny <martin@c-home.cz>
8 years agoFix SDV
Paul Durrant [Tue, 10 Jan 2017 17:43:13 +0000 (17:43 +0000)]
Fix SDV

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoMake sure hash metadata is only set when the algorithm is Toeplitz
Paul Durrant [Tue, 10 Jan 2017 17:01:54 +0000 (17:01 +0000)]
Make sure hash metadata is only set when the algorithm is Toeplitz

This is the only supported algorithm.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAdd an up-to-date BUILD.md and modify README.md to reference it
Paul Durrant [Wed, 14 Dec 2016 16:31:37 +0000 (16:31 +0000)]
Add an up-to-date BUILD.md and modify README.md to reference it

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFixes for VS2015/WDK10 build
Paul Durrant [Wed, 14 Dec 2016 15:58:56 +0000 (15:58 +0000)]
Fixes for VS2015/WDK10 build

The package build was not working correctly and caused the overall build
to fail.
At least part of the reason for this is that Microsoft, in their infinite
wisdom, have removed the DIFx redist from WDK10. This patch makes use of
a new environment variable 'DPINST_REDIST' to find the copy of dpinst.exe
to package such that this can be pointed at an older WDK or alternative
location where dpinst.exe can be found.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoSquash erroneous warning
Paul Durrant [Tue, 13 Dec 2016 17:32:01 +0000 (17:32 +0000)]
Squash erroneous warning

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAdd support for building under VS2015/WDK10
Paul Durrant [Tue, 13 Dec 2016 10:13:48 +0000 (10:13 +0000)]
Add support for building under VS2015/WDK10

Moving to the new toolchain also threw up a few new warnings, which this
patch either fixes or squashes. Also, SDV appears to be fragile in new
ways (and whinge about some new things) so there are fixes for that too.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoUpdate driver version from 8.2.0 to 9.0.0
Paul Durrant [Tue, 13 Dec 2016 09:48:06 +0000 (09:48 +0000)]
Update driver version from 8.2.0 to 9.0.0

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAvoid ASSERTion failure caused by sample ordering reversal 8.2.0-rc1
Paul Durrant [Fri, 4 Nov 2016 16:02:07 +0000 (16:02 +0000)]
Avoid ASSERTion failure caused by sample ordering reversal

In __ReceiverPushPackets() the value of Receiver->Indicated is sampled
prior to the value of Receiver->Returned. This allows packets to be
indicated and returned on other CPUs between the two sample points
leading to an ASSERTion failure because the value of Returned will be
greater than that of Indicated.

The solution is simply to reverse the sample ordering.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix NdisTest 6.5 OffloadLSO test on Server 2016
Paul Durrant [Thu, 3 Nov 2016 16:48:22 +0000 (16:48 +0000)]
Fix NdisTest 6.5 OffloadLSO test on Server 2016

This test will cause assertion failures on the server end on Server 2016
when it attempts to send LSOv2 packets to an adapter where LSOv2 has
been disabled. These packets must be binned otherwise the server end
barfs on the fact they have bad checksums.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix build warnings
Paul Durrant [Thu, 3 Nov 2016 10:15:05 +0000 (10:15 +0000)]
Fix build warnings

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix SDV build
Paul Durrant [Thu, 3 Nov 2016 09:19:37 +0000 (09:19 +0000)]
Fix SDV build

Squash some prefast stupidity

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAdd location identifier to Info messages
Paul Durrant [Wed, 2 Nov 2016 13:56:22 +0000 (13:56 +0000)]
Add location identifier to Info messages

Query the PDO location when the Adapter is created and add the location
identifier string to all Info messages.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoLog outstanding packet count when miniport is disabled
Paul Durrant [Thu, 22 Sep 2016 11:04:05 +0000 (12:04 +0100)]
Log outstanding packet count when miniport is disabled

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoShim NdisMIndicateReceiveNetBufferLists() to avoid multiple indications
Paul Durrant [Thu, 22 Sep 2016 10:01:03 +0000 (11:01 +0100)]
Shim NdisMIndicateReceiveNetBufferLists() to avoid multiple indications

It seems that, on some versions of Windows, something in the network
stack does not work properly with receive indications of more than
one NET_BUFFER_LIST at once.

This patch shims NdisMIndicateReceiveNetBufferLists() to iterate over
a chain of NET_BUFFER_LISTS and indicate them separately. Hopefully
this workaround can be removed in future.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoMake sure that a queue of received packets is always pushed
Paul Durrant [Thu, 22 Sep 2016 10:07:17 +0000 (11:07 +0100)]
Make sure that a queue of received packets is always pushed

It's possible that the last received packet may suffer an allocation
failure during processing and, as the code stands, any previously
received packets may then not be indicated to the stack.

This patch makes sure that the '!More' condition always results in an
indication, regardless of whether there is an allocation failure.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoUpdate to XENVIF_VIF interface version 8
Paul Durrant [Tue, 20 Sep 2016 13:19:33 +0000 (14:19 +0100)]
Update to XENVIF_VIF interface version 8

This version of the interface provides an explicit queue index to the
XENVIF_RECEIVER_QUEUE_PACKET callback.

This patch also fixes a leak of NET_BUFFER_LIST structures that can
occur if the low resources threshold is reached.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRevert all settings stealing code
Paul Durrant [Wed, 7 Sep 2016 15:48:22 +0000 (16:48 +0100)]
Revert all settings stealing code

This patch accompanies commit bf92f4b7 to XENVIF. That patch reverts
XENVIF to using the settings copy mechanism employed in the 8.1 driver,
so this patch accordingly removes all relevant modifications to the
XENNET co-installer.

The patches reverted are:

9695e3bd "Re-instate code network settings code in the co-installer"
59901522 "Remove code to clear stolen stack binding"
ed747f69 "Clear stolen linkage on device removal"

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix SDV build
Paul Durrant [Wed, 17 Aug 2016 12:04:46 +0000 (13:04 +0100)]
Fix SDV build

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoMake use of batching support
Paul Durrant [Mon, 15 Aug 2016 13:07:00 +0000 (14:07 +0100)]
Make use of batching support

XENVIF_VIF_INTERFACE version 7 adds support for batch indications on both
the transmit and receive side. This patch imports the updated interface
header and makes use of this new functionality.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRemove update of defunct statistic
Paul Durrant [Wed, 17 Aug 2016 10:22:29 +0000 (11:22 +0100)]
Remove update of defunct statistic

Nothing looks a the 'InNDISMax' value, yet the receiver code still jumps
through potentially performance damaging hoops to update it. This patch
finally blows it away.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRename XenNetDesc to XenNetName in the INF file...
Paul Durrant [Wed, 17 Aug 2016 11:21:08 +0000 (12:21 +0100)]
Rename XenNetDesc to XenNetName in the INF file...

...to more accurately reflect its purpose.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoMake free builds of XENNET less chatty
Paul Durrant [Mon, 15 Aug 2016 13:08:26 +0000 (14:08 +0100)]
Make free builds of XENNET less chatty

Refine logging of offload options and turn the Info() calls into Trace()
calls. Also add similar Trace() calls for RSS settings.

While doing this re-factoring, this patch also breaks out link state logging
into a dedicated function.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRe-instate code network settings code in the co-installer
Paul Durrant [Thu, 11 Aug 2016 14:56:47 +0000 (15:56 +0100)]
Re-instate code network settings code in the co-installer

This functionality was moved into XENVIF when it transpired that it did not
work with Windows 10. However, attempting to mess with network settings in
a driver has also proved to have problematic corner cases.

This patch re-instates old code but changes the mechnism for acquiring
network settings from an emulated device. Instead of attempting to copy
settings to a new stack binding (which failed on Windows 10 because the
stack binding was not set up), the stack binding of the emulated device is
cloned. This is done in post-install phase if the emulated device is online
(otherwise Windows will refuse to start the PV device) or in pre-install
phase if the emulated device is offline, as is the case when re-installing
XENNET. This appears to work reliably across all variants of Windows.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRemove code to clear stolen stack binding
Paul Durrant [Mon, 8 Aug 2016 12:14:59 +0000 (13:14 +0100)]
Remove code to clear stolen stack binding

This is now handled internally by XENVIF.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoFix VS2012 builds
Paul Durrant [Tue, 26 Jul 2016 08:22:37 +0000 (09:22 +0100)]
Fix VS2012 builds

Building for OS earlier than Windows 7 now requires use of procgrp.lib
since KeGetCurrentProcessorEx() is used. Since the base OS of VS2012 builds
is Vista, these have been failing since commit 8cb5c156.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoRemove reboot request from the co-installer
Paul Durrant [Thu, 21 Jul 2016 11:04:31 +0000 (12:04 +0100)]
Remove reboot request from the co-installer

This is now taken care of by XENVIF by way of the XENBUS_MONITOR service.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAdd missing names to the INF file
Paul Durrant [Thu, 21 Jul 2016 10:57:29 +0000 (11:57 +0100)]
Add missing names to the INF file

The package should have a name and the XENVIF driver should also have a
DisplayName.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAvoid lock contention between receiving CPUs
Paul Durrant [Thu, 19 May 2016 11:28:04 +0000 (12:28 +0100)]
Avoid lock contention between receiving CPUs

The single PutList/GetList for cached NET_BUFFER_LIST structures is
currently a point of contention. This patch gets rid of the contention
by keeping per-CPU GetLists.

To access the definition of HVM_MAX_VCPUS, the hvm_info_table.h header
needs to be pulled in the from the Xen source base. This patch therefore
adds the infrastructure for pulling in Xen headers.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
8 years agoAdd support for NDIS RSS
Paul Durrant [Wed, 3 Feb 2016 10:49:22 +0000 (10:49 +0000)]
Add support for NDIS RSS

Update to VIF interface version 6 and make use of the extra functionality
provided to support NDIS RSS.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoClear stolen linkage on device removal
Paul Durrant [Fri, 4 Mar 2016 11:10:33 +0000 (11:10 +0000)]
Clear stolen linkage on device removal

Commit 04c391d9 "Replace copying network settings with identity stealing" to
XENVIF changed the way that network settings are preserved when replacing
an emulated NIC with a PV network device. This change means that both the
emulated NIC and PV device have the same binding to the Windows network
stack. Thus, if we do not destroy that binding prior to uninstallation of
the PV network driver, the stack will be torn down by the network class
uninstall code rather than left in place for the emulated NIC to use after
reboot.

This patch hence adds code to the XENNET co-installer to remove stolen
linkage information from the registry in the pre-remove phase.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoBootFlags should be a parameter, not a subkey
Paul Durrant [Wed, 30 Mar 2016 11:01:26 +0000 (12:01 +0100)]
BootFlags should be a parameter, not a subkey

A misplaced comma in the INF file means that BootFlags is being created as
a subkey under the service key with a default DWORD value, rather than a
DWORD value with the name 'BootFlags'.

This patch moves the comma and fixes the problem.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoGet rid of InitSafeBootMode veto
Paul Durrant [Tue, 1 Mar 2016 16:53:52 +0000 (16:53 +0000)]
Get rid of InitSafeBootMode veto

This should no longer be necessary since XENVIF fails to start PDOs if
emulated devices are present, which they will be in safe mode.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix a typo that causes 'low resources' to erroneously kick in
Paul Durrant [Wed, 24 Feb 2016 10:35:12 +0000 (10:35 +0000)]
Fix a typo that causes 'low resources' to erroneously kick in

This patch fixes a typo which caused XENNET to operate in a 'low resources'
situation most of the time. This was almost certainly causing performance
issues and, oddly, caused the NDISTest 6.5 OffloadChecksum test to fail...
but only on Windows 8.0.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix a warning in the NDISTest 6.0 2c_OidsNdisRequest test
Paul Durrant [Mon, 1 Feb 2016 15:45:14 +0000 (15:45 +0000)]
Fix a warning in the NDISTest 6.0 2c_OidsNdisRequest test

The format of the response to the OID_GEN_VENDOR_DRIVER_VERSION request was
incorrect, and also the OID_GEN_DRIVER_VERSION response has been lying since
the change to NDIS 6.1.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix NDISTest 6.5 OffloadLSO test
Paul Durrant [Mon, 1 Feb 2016 11:06:03 +0000 (11:06 +0000)]
Fix NDISTest 6.5 OffloadLSO test

There are more structure size issues lurking that cause this logo test to
fail. This patch fixes those, others that were found along the way and also
makes sure that any attempt to set IPsecV2 offload parameters fails (since
it is not supported).

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoUse a locally defined StringPrintf
Paul Durrant [Thu, 28 Jan 2016 17:59:26 +0000 (17:59 +0000)]
Use a locally defined StringPrintf

Use of the _snprintf_s symbol fails on Windows 10, where it appears not to
be exported from ntdll. So, for portability's sake it is more robust to
implement a StringPrintf function locally.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoStash a pointer to _snprintf_s in the ADAPTER structure
Paul Durrant [Thu, 28 Jan 2016 09:57:24 +0000 (09:57 +0000)]
Stash a pointer to _snprintf_s in the ADAPTER structure

It is problematic if we don't, as on resume from suspend we need to
re-acquire the function pointer and this seems to lead to a BSOD, despite
there being no documentation to suggest that use of the aux_klib functions
at DISPATCH_LEVEL is disallowed.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoStop using RtlStringCbPrintfA()
Paul Durrant [Wed, 27 Jan 2016 14:52:57 +0000 (14:52 +0000)]
Stop using RtlStringCbPrintfA()

It appears that linking an NDIS driver with any ntstrsafe function (when
building with VS2012 and the 8.0 WDK at least) has the side effect of
requiring use of DbgPrint(). Whilst this may not sound like a problem, it
is. This is because the NDISTest 6.0 1c_KernelCalls test insists that any
use of DbgPrint is illegal and so it's impossible to logo an NDIS driver
using ntstrsafe functions.

This patch works around the issue by dynamically linking (at run-time) to
the ntdll _snprintf_s function as a replacement for calls to
RtlStringCbPrintfA(). This entails importing the dynamic linking code from
XENVIF since MmGetSystemRoutineAddress() doesn't seem to work for that
symbol.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix multiple completion vulnerability in transmit code
Paul Durrant [Tue, 26 Jan 2016 11:34:47 +0000 (11:34 +0000)]
Fix multiple completion vulnerability in transmit code

My previous patch 7c3365d5 "Make transmitter robust against a possible
completion race" did not fix the problem. There is still the possibility
that a NET_BUFFER_LIST containing multiple NET_BUFFERs could lead to
multiple completions if the underlying transmit completes quickly (or indeed
synchrnously). This is because a reference is taken before sending each
NET_BUFFER but, if that transmission completes immediately the reference is
dropped back to zero (leading to the NET_BUFFER_LIST being completed) before
the reference is taken for the next NET_BUFFER.

This patch therefore takes an extra reference before sending any NET_BUFFERs
and then drops it when there are no more NET_BUFFERs to send. This ensures
that the reference count on the NET_BUFFER_LIST can only fall to zero once
the whole thing has been processed.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoAvoid evaluating assertion expressions in free builds
Paul Durrant [Fri, 22 Jan 2016 16:05:40 +0000 (16:05 +0000)]
Avoid evaluating assertion expressions in free builds

The evaluations are pointless and the warnings generated by not evaluating
can be squashed with a couple of #pragmas.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoMake transmitter robust against a possible completion race
Paul Durrant [Tue, 19 Jan 2016 11:21:28 +0000 (11:21 +0000)]
Make transmitter robust against a possible completion race

It's possible that a transmission invoked on one CPU may complete on another
before the transmission invocation as finished. Therefore, once we have queued
a NET_BUFFER for transmission we should not use it's metadata again (including
the 'next' pointer).

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoRemove header/data split support
Paul Durrant [Tue, 19 Jan 2016 09:31:45 +0000 (09:31 +0000)]
Remove header/data split support

During logo testing it became apparent that:

a) This is predicated on support VLAN ID, which is not something we really
   want in a PV driver (since the backend network may actually be a VLAN).
b) Turning on Viridian flags causes NDIS to stop enabling header/data split.
   (There's a call to NdisGetHypervisorInfo() in NdisMSetHDSplitAttributes()).

Issue a) makes it undesirable to implement and b) makes it pretty much
pointless having the code around. Hence this patch removes it.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix various structure sizes
Paul Durrant [Mon, 18 Jan 2016 17:44:01 +0000 (17:44 +0000)]
Fix various structure sizes

NDIS defines 'sizeof' values for various attribute/parameter structures
which are documented for use with different versions of NDIS. This patch
makes sure we are using these defined values in appropriate places.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoUpdate to correct PDO revision
Paul Durrant [Mon, 4 Jan 2016 13:37:48 +0000 (13:37 +0000)]
Update to correct PDO revision

The correct PDO revision for the latest VIF interface is 0x08000009, not
0x08000007.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoUpdate to VIF interface version 5
Paul Durrant [Mon, 4 Jan 2016 13:16:38 +0000 (13:16 +0000)]
Update to VIF interface version 5

Use version 5 of the interface to avoid the shutdown race present in
version 4.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoRe-synchronize util.h with XENBUS and use __toupper()
Paul Durrant [Thu, 10 Dec 2015 11:28:17 +0000 (11:28 +0000)]
Re-synchronize util.h with XENBUS and use __toupper()

A recent patch introduced __tolower() and __toupper() into util.h as
replacements for tolower() and toupper() respectively as the latter do
a hidden conversion to Unicode which make then unsafe at any IRQL other
than PASSIVE_LEVEL.
This patch imports util.h from XENBUS and fixes other code to be compatible.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoDon't get XENBUS_SUSPEND callback registration on AdapterCount
Paul Durrant [Tue, 8 Dec 2015 15:06:51 +0000 (15:06 +0000)]
Don't get XENBUS_SUSPEND callback registration on AdapterCount

Instances will not necessarily come and go in order so we can't know that
the last instance to go will be the one the registered the callback.
Instead register a callback for every instance and just use AdapterCount to
decide which instance writes distribution information to xenstore.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoMove to XENVIF VIF interface version 4
Paul Durrant [Fri, 4 Dec 2015 12:22:08 +0000 (12:22 +0000)]
Move to XENVIF VIF interface version 4

This means we can remove a lot of complexity and crucially we no longer
need to use the XENBUS_CACHE interface, which means we can avoid the race
introduced by commit 026aa32c "Make sure XENBUS interfaces are released
when going into S4".

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoMake sure XENBUS interfaces are released when going into S4
Paul Durrant [Thu, 3 Dec 2015 12:55:31 +0000 (12:55 +0000)]
Make sure XENBUS interfaces are released when going into S4

Because a transition into and out of S4 means a new domain is built, it's
crucial that all XENBUS interfaces are released (so that things like
event channels, grant tables and the xenstore ring get re-constructed).

This patch fixes code paths where this was not being done. It also adds
some more logging during AdapterEnable/Disable and when moving between
D0 and D3.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix another SDV stupidity
Paul Durrant [Wed, 25 Nov 2015 14:39:54 +0000 (14:39 +0000)]
Fix another SDV stupidity

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoAdd two missing headers
Paul Durrant [Wed, 25 Nov 2015 14:06:34 +0000 (14:06 +0000)]
Add two missing headers

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoFix SDV build
Paul Durrant [Wed, 25 Nov 2015 13:57:13 +0000 (13:57 +0000)]
Fix SDV build

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoPublish distribution information to xenstore
Paul Durrant [Tue, 24 Nov 2015 15:41:10 +0000 (15:41 +0000)]
Publish distribution information to xenstore

My recent patch series to Xen added a documented path and format for
publishing information about PV driver distributions to xenstore.

This patch adds code to populate the documented path (should it exist)
with information about the XENNET driver package.

Suggested-by: Owen Smith <owen.smith@citrix.com>
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
9 years agoAdd a registry override to veto driver installations
Paul Durrant [Thu, 22 Oct 2015 14:50:58 +0000 (15:50 +0100)]
Add a registry override to veto driver installations

There are certain cases where a local installer package may wish to
prevent Windows Update installations of drivers. This can be achieved by
having the co-installer check for a registry value and fail it's pre-install
phase if the value is present.

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