[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 09/10] ring: Defer destruction until backend grant release


  • To: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>, "win-pv-devel@xxxxxxxxxxxxxxxxxxxx" <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Thu, 29 Oct 2026 10:47:16 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7rWPIwS4EQb0P7cbZK3Kiu3nERBfYHWt2UcH3HVM+GE=; b=xz4iMm/lgDoE9KtBWZYAEvqgPmTDQ2YIkBSZCe/Ku/1kD5BLNJNY8dWv3NXAPhGXv7JZABKD90q9oVkskta2ROSZnlx8A1Ppg1Ut3LPOdqhQg+APf8T6Zn1dmdL9jIqZmGoLoTuayvBT7gquUY5w2vHRAkXD26l7vhQDlX6d/2MQU9uNj/PGuIo62hCuhhj46q57xLgwTWL4gSMAfBrG0uC1Fu13fx9SsPESgndTUV1OP7E9iGkAHE+q6LJSf1MDHFW+BSgs1v4L9fXIM6JzZVkK8xb9byTI+zDJZmn68Z2ZQLmLc/ZcVhz71MW16BxuKT9e67n7h2iXg3yIWzqn3g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F6tW9LOwOWXcmpOd4Pj7gXefqJvygQg2TwnWHgwwunPi2SPvumII5AQGhXT0I/2akxoXLyrDQcEgIlkYfQmI5BiPwOQUJ6WlDxjOBBe/7yxOFcJVge1iGDKuRb14HA3On18n+WG8peCQOP9w5xRYBfETXmfqloX6ORsf0tmF1obFmfp1fr0peCbFkzJkYJx4qG3u0td17q8+ACnw6Ols8RWXatafYx70FKdyLBUkaTOm/YNppH9/LecZzuSvER4yRoQK1SCKEbdEOjRcuw8xRyT0Ew2YwxYceHMpnWOoSgYeh/or2icaE1YEp6DQ6sPqeGTkKIUrEYmHMb3L8a6MYA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Delivery-date: Thu, 29 Oct 2026 10:47:25 +0000
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdZwBzzYNdZAdcMEmg3ENCpURe8bcUUhsU
  • Thread-topic: [PATCH v2 09/10] ring: Defer destruction until backend grant release

Some comments inline

>  +static VOID
>  +__BlkifRingFreePages(
>  +    _In_ PXENVBD_BLKIF_PAGES    Pages
>  +    )
>  +{
>  +    ULONG                       Index;
>  +
>  +    for (Index = 0; Index < Pages->Count; ++Index)
>  +        ASSERT3P(Pages->Grants[Index], ==, NULL);
>  +

This loop only matters on a checked build - it can be wrapped by
#if DBG / #endif

>  +    __FreePages(Pages->Mdl);
>  +    Pages->Mdl = NULL;
>  +    Pages->Count = 0;
>  +
>  +    RtlZeroMemory(&Pages->ListEntry, sizeof(LIST_ENTRY));
>  +
>  +    ASSERT(IsZeroMemory(Pages, sizeof(XENVBD_BLKIF_PAGES)));
>  +    __RingFree(Pages);
>  +}
>  +
>  +_Check_return_
>  +static BOOLEAN
>  +__BlkifRingRevokePages(
>  +    _In_ PXENVBD_BLKIF_RING     BlkifRing,
>  +    _Inout_ PXENVBD_BLKIF_PAGES Pages
>  +    )
>  +{
>  +    PXENVBD_RING                Ring = BlkifRing->Ring;
>  +    PXENVBD_GRANTER             Granter = 
> FrontendGetGranter(Ring->Frontend);
>  +    ULONG                       Index;
>  +
>  +    for (Index = 0; Index < Pages->Count; ++Index) {
>  +        if (Pages->Grants[Index] == NULL)
>  +            continue;
>  +
>  +        if (!NT_SUCCESS(GranterTryPut(Granter, Pages->Grants[Index])))
>  +            return FALSE;
>  +

Should the loop flag the failure, and try other grants, so that the function
has released as many grants as possible, but reports if any fail?


>  +        Pages->Grants[Index] = NULL;
>  +    }
>  +
>  +    return TRUE;
>  +}
>  +

>  @@ -2615,9 +2865,32 @@ RingD0ToD3(
>       _Inout_ PXENVBD_RING    Ring
>       )
>   {
>  -    UNREFERENCED_PARAMETER(Ring);
>  +    ULONG                   Index;
>  
>       ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
>  +
>  +    // Grants are only handed over to the reclaim thread at disconnect, so a
>  +    // ring still connected here would never be drained
>  +    for (Index = 0; Index < FrontendGetMaxQueues(Ring->Frontend); ++Index)
>  +        ASSERT(!Ring->Ring[Index]->Connected);
>  +

Checked only loop, can be optimized with #if DBG / #endif

>  +    // Only return once the backend has released everything, so that no 
> grant
>  +    // survives into D3. Freeing pages that backends may still access is 
> worse
>  +    // than holding up D0->D3.
>  +    while (RingIsDeferring(Ring)) {


Owen


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.