From win-pv-devel-bounces@lists.xenproject.org Wed Jan 10 13:42:46 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 10 Jan 2024 13:42:46 +0000
Received: from list by lists.xenproject.org with outflank-mailman.665445.1035655 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005jz-Fw; Wed, 10 Jan 2024 13:42:44 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 665445.1035655; Wed, 10 Jan 2024 13:42:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005jk-9z; Wed, 10 Jan 2024 13:42:44 +0000
Received: by outflank-mailman (input) for mailman id 665445;
 Wed, 10 Jan 2024 13:42:43 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Ixtf=IU=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rNYqx-0005jG-J7
 for win-pv-devel@lists.xenproject.org; Wed, 10 Jan 2024 13:42:43 +0000
Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com
 [2a00:1450:4864:20::52c])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 20acc9ee-afbe-11ee-98f0-6d05b1d4d9a1;
 Wed, 10 Jan 2024 14:42:42 +0100 (CET)
Received: by mail-ed1-x52c.google.com with SMTP id
 4fb4d7f45d1cf-557bfc7f7b4so5117293a12.0
 for <win-pv-devel@lists.xenproject.org>; Wed, 10 Jan 2024 05:42:42 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 gl16-20020a170906e0d000b00a28bf7969cdsm2098473ejb.180.2024.01.10.05.42.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 10 Jan 2024 05:42:40 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 20acc9ee-afbe-11ee-98f0-6d05b1d4d9a1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1704894161; x=1705498961; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=ge4S7OQcFYb2JjZ+NX5jHJW3MuTlbvOl86qr0/xeuOw=;
        b=YA4luLGgspd+yZ/82Rw/2BSW/Yh3aSPZlFwRRXD2up0MP2Y8nhaDZZa3kj/Jjnnl+7
         3g2WPaQEDUMKOUaDvKxD5h9PEnJjyv7h02ugs7wXhxcNnJ/A7haJwmTLvkMKiuZCAZhq
         vo/iKbPEDZ2hdpoRwtlfw2IQwfhMWqdGdiPkA=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1704894161; x=1705498961;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=ge4S7OQcFYb2JjZ+NX5jHJW3MuTlbvOl86qr0/xeuOw=;
        b=UMtMOqD9NeY84qbVI5nMzQOOShmRqOvt7i9oaYTVc0LfKq9Y3s6YNQkUarqwEmHu4n
         1+a4ePY/ppo+H5sPGoAhck6EJPznce2gFzm9+OdblfEt8P6ZPYWxs95UnkuX9UxoFbdd
         SiBFusYW+veQ64nYZ7kAJ5OWUZdLh78BAMNWVtz75n9IL9+Dn7W64GBAujETlRkSTBPa
         3s4Q6ncLg+Z6dI9MnCBJ4qo66ugxTyuOMgvMbJ3GMLKz1r4hZz9puFms/t5+VjkwGZPC
         45lre5HoVnVxa+hAdzyoA6fXnKM+zhwwBXkxb9lOMnbWXEu0QNQGbGf1iEMSO17ST41r
         wZ2A==
X-Gm-Message-State: AOJu0YwFufoV6mqdTch7XWlanp0SQJMP+DKIWxmclhNUtmUzNuhT1KSu
	04FSmNZRgUFWDSUsTj/+xIp59WpikogmeBINMxMuybrOgw==
X-Google-Smtp-Source: AGHT+IGjHzG44BHaJp/vbLSuWxbF21iiGIp8tUk188WKf58eauVPkdXqTCFWzIrqoHmqx/zbSJDKIg==
X-Received: by 2002:a17:906:3a8d:b0:a28:ba5d:e786 with SMTP id y13-20020a1709063a8d00b00a28ba5de786mr100436ejd.14.1704894161202;
        Wed, 10 Jan 2024 05:42:41 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 3/3] ASSERT(Frame->Mdl != NULL) before dereference
Date: Wed, 10 Jan 2024 13:42:22 +0000
Message-ID: <20240110134222.1660-4-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240110134222.1660-1-owen.smith@cloud.com>
References: <20240110134222.1660-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

CodeAnalysis detects a false positive, where Frame->Mdl could be NULL in
GnttabContract. Without asserting a non-NULL pointer, SDV will generate a
DVL log file that will fail WHQL testing.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenbus/gnttab.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 4f6617b..57c36df 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -274,6 +274,7 @@ GnttabContract(
 
         Info("removed refrences [%08llx - %08llx]\n", Start, End);
 
+        ASSERT(Frame->Mdl != NULL);
         Pfn = MmGetMdlPfnArray(Frame->Mdl)[0];
 
         (VOID) MemoryRemoveFromPhysmap(Pfn);
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 10 13:42:46 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 10 Jan 2024 13:42:46 +0000
Received: from list by lists.xenproject.org with outflank-mailman.665446.1035657 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005kf-Hg; Wed, 10 Jan 2024 13:42:44 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 665446.1035657; Wed, 10 Jan 2024 13:42:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005jv-Bt; Wed, 10 Jan 2024 13:42:44 +0000
Received: by outflank-mailman (input) for mailman id 665446;
 Wed, 10 Jan 2024 13:42:43 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Ixtf=IU=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rNYqx-0005jF-Oe
 for win-pv-devel@lists.xenproject.org; Wed, 10 Jan 2024 13:42:43 +0000
Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com
 [2a00:1450:4864:20::633])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id 1e97fb10-afbe-11ee-9b0f-b553b5be7939;
 Wed, 10 Jan 2024 14:42:39 +0100 (CET)
Received: by mail-ej1-x633.google.com with SMTP id
 a640c23a62f3a-a27cd5850d6so443325266b.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 10 Jan 2024 05:42:38 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 gl16-20020a170906e0d000b00a28bf7969cdsm2098473ejb.180.2024.01.10.05.42.36
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 10 Jan 2024 05:42:37 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 1e97fb10-afbe-11ee-9b0f-b553b5be7939
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1704894157; x=1705498957; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=u7o+5v3puwBGrFycrnIXUhhrCFGZrVXJu5FQ30aAnFA=;
        b=UoOySH9wgQfKSJDzhvPjuRLCtSOOZs20CV5kSnBRRzJVjII3vbV3pBPkCQ4c8WKsSz
         kDdQ1QTVtdbBUI+IDKj5dE1eJIgvlPyLDHs6BlT99IT/sjVJXdseiowgLGMFzWqa/kFR
         HoICseMPiRDBPIixWnI2Zid94RqqHm457MSvA=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1704894157; x=1705498957;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=u7o+5v3puwBGrFycrnIXUhhrCFGZrVXJu5FQ30aAnFA=;
        b=HbbVJKa2Qm/2Pc0hMs0IrSDKa9pEYSh8jKUl9JJWOWYuc8pPg1Op7zp+2B1DNOiNGK
         qNYZoMGYUbaPwYDiNmGPEqN4qSX1G2pHRWdDM8Wf5MpKLWIIKy+Gw8Glow9CmnPnV1kT
         Jbb7ZEsggH8SEYykRuYf9P4O4haTiokLa0gIviovgT2zccRz83fv89DMNDcJqMOLoBYt
         pO6wa+XBDQKUX2fYFdD/dvaqkaFRfOc4YHOF+TKpq9yVuPKnIjDRcupP6XYu3K7GDkLv
         J/WglA0CcVVXRFo3yyCgy+ElMRd6ZINBdDmwB2TwO1lbJw0pwI+1q0HaGvdbbZe4m++R
         09pQ==
X-Gm-Message-State: AOJu0Yx1JFRbdCuYbiH8rC8JRwtHw+ciQvdcc4T/ANWQQ2TF3j02mOTQ
	YupBKpwWODNt7SQI82l67P4wbpBe9IdSVmSyUtjQTG2SEw==
X-Google-Smtp-Source: AGHT+IH4yx3uKv/Ln9lb0bEqCIUrf1R+Q+n31T6v1hM1mgV1xyV7nb3StG2hYVPvnX2jLw0z0seYkQ==
X-Received: by 2002:a17:906:6802:b0:a27:6d9c:8194 with SMTP id k2-20020a170906680200b00a276d9c8194mr580992ejr.119.1704894157561;
        Wed, 10 Jan 2024 05:42:37 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 0/3] Rework Power handlers
Date: Wed, 10 Jan 2024 13:42:19 +0000
Message-ID: <20240110134222.1660-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Current power handler code is passed to a single threaded work thread which
can be delayed enough to trigger 0x9F (DRIVER_POWER_STATE_FAILURE) bugchecks.
Rework power handlers to math standard practive, using pended IRPs,
IoCompletionRoutines and deferred IoWorkItems where required.

Martin Harvey (2):
  [XenFilt] Asynchronous power handling.
  [XenBus] Asynchronous power handling

Owen Smith (1):
  ASSERT(Frame->Mdl != NULL) before dereference

 src/xenbus/fdo.c    | 792 ++++++++++++++++++++++++--------------------
 src/xenbus/gnttab.c |   1 +
 src/xenbus/pdo.c    | 250 ++++++--------
 src/xenfilt/fdo.c   | 498 +++++++---------------------
 src/xenfilt/pdo.c   | 503 +++++++---------------------
 5 files changed, 777 insertions(+), 1267 deletions(-)

-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 10 13:42:46 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 10 Jan 2024 13:42:46 +0000
Received: from list by lists.xenproject.org with outflank-mailman.665447.1035663 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqz-0005oT-HH; Wed, 10 Jan 2024 13:42:45 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 665447.1035663; Wed, 10 Jan 2024 13:42:45 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqz-0005oM-EQ; Wed, 10 Jan 2024 13:42:45 +0000
Received: by outflank-mailman (input) for mailman id 665447;
 Wed, 10 Jan 2024 13:42:44 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Ixtf=IU=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rNYqy-0005jG-JR
 for win-pv-devel@lists.xenproject.org; Wed, 10 Jan 2024 13:42:44 +0000
Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com
 [2a00:1450:4864:20::532])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 208d8ae6-afbe-11ee-98f0-6d05b1d4d9a1;
 Wed, 10 Jan 2024 14:42:42 +0100 (CET)
Received: by mail-ed1-x532.google.com with SMTP id
 4fb4d7f45d1cf-5574feb7958so4896150a12.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 10 Jan 2024 05:42:42 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 gl16-20020a170906e0d000b00a28bf7969cdsm2098473ejb.180.2024.01.10.05.42.39
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 10 Jan 2024 05:42:39 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 208d8ae6-afbe-11ee-98f0-6d05b1d4d9a1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1704894161; x=1705498961; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=t+WTzKTs+7KR+Xtrsn3UZw7hmaVbMfgFPV2C05JhrFg=;
        b=MjZZ03IKbmEaB8UGfdn9QvRgTPnzoxQyGsrQJvBxDPPomifZxCpwCO9/W4Rh5wY1ZI
         Ymn6U2B6ntVfXyqiKi+IWHIQPkOudj4ptBRYBwB524mgnFlPxvq7VWI0HoEGQRF7w6x2
         Ow0iOluu9Se1ncp/GGBbdGZpIvAwsk0y2DI6E=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1704894161; x=1705498961;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=t+WTzKTs+7KR+Xtrsn3UZw7hmaVbMfgFPV2C05JhrFg=;
        b=fMfQNyGa6oLzk2+jMio8O5jqv5Atrf67ovLqPDxgo90peCW+1CMfmeM4Ygicgic6QQ
         XGcAZWUfgWChUQPXJIaEGKejAvUd1a3IzzVnZCl4CyOb7Q15TCfuFrsff2r/Xmw2Vz5L
         l0EoOn3b9EsRyOFQJKrVwfmwE+shSfhHwEYWt4jWFtTY/lxSV3hsetLDMOxLh24gECpn
         y9nh42m1nRefFgpBkoPyGLn/o6v7VDqhHbyf/85BL/qp5x/msBkyyY38toTi4MJURlal
         1h/DO8Ry3JLAxwj2XHpV6pk9aKkt5Z3sSP7/cVhMP21eIHRnurpd22HG7W4epfPKDF/d
         8eyw==
X-Gm-Message-State: AOJu0YxWsQhQEiKwAEZeKCazb74XjyYYN9VnO8QJCel1m1Kt3bTrnb0P
	acYxsHCaX23hGHRImtyUjJaYkV3j45xJO4hCmb2dP3IOlA==
X-Google-Smtp-Source: AGHT+IGQhuyJ5nGGMG1yNcOIytHR2t2k9ttTBvO99cNZ8ZQ7Qb/xGxKqUIVc5Ymu9bsEiiuZCy9Gww==
X-Received: by 2002:a17:907:7d9e:b0:a2b:2c8a:9c49 with SMTP id oz30-20020a1709077d9e00b00a2b2c8a9c49mr738042ejc.16.1704894160552;
        Wed, 10 Jan 2024 05:42:40 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Martin Harvey <Martin.Harvey@citrix.com>,
	Martin Harvey <martin.harvey@citrix.com>,
	Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 2/3] [XenBus] Asynchronous power handling.
Date: Wed, 10 Jan 2024 13:42:21 +0000
Message-ID: <20240110134222.1660-3-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240110134222.1660-1-owen.smith@cloud.com>
References: <20240110134222.1660-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Martin Harvey <Martin.Harvey@citrix.com>

Replace a static, single thread for System and Device power transitions with
an IO_WORKITEM for each transition. IO_WORKITEMs are only used when a transition
requires calling codepaths that must be called at PASSIVE_LEVEL.
Move the bulk of power transitions to pending IRPs and IRP completion routines.

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

Refactored to only apply to XenBus power

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenbus/fdo.c | 792 ++++++++++++++++++++++++++---------------------
 src/xenbus/pdo.c | 250 ++++++---------
 2 files changed, 534 insertions(+), 508 deletions(-)

diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index 976a7a3..3d35e77 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -107,9 +107,9 @@ struct _XENBUS_FDO {
     ULONG                           Usage[DeviceUsageTypeDumpFile + 1];
     BOOLEAN                         NotDisableable;
 
-    PXENBUS_THREAD                  SystemPowerThread;
+    PIO_WORKITEM                    SystemPowerWorkItem;
     PIRP                            SystemPowerIrp;
-    PXENBUS_THREAD                  DevicePowerThread;
+    PIO_WORKITEM                    DevicePowerWorkItem;
     PIRP                            DevicePowerIrp;
 
     CHAR                            VendorName[MAXNAMELEN];
@@ -4800,38 +4800,105 @@ FdoDispatchPnp(
     return status;
 }
 
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
+static VOID
+FdoSetDevcePowerUpWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
+    )
+{
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO) Context;
+    PIRP                Irp;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    Irp = InterlockedExchangePointer(&Fdo->DevicePowerIrp, NULL);
+    ASSERT(Irp != NULL);
+
+    (VOID) FdoD3ToD0(Fdo);
+
+    /* Cannot change Irp->IoStatus */
+    /* Continue completion chain */
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+}
+
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-FdoSetDevicePowerUp(
-    IN  PXENBUS_FDO     Fdo,
-    IN  PIRP            Irp
+FdoSetDevicePowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO) Context;
     PIO_STACK_LOCATION  StackLocation;
     DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     DeviceState = StackLocation->Parameters.Power.State.DeviceState;
 
-    ASSERT3U(DeviceState, <,  __FdoGetDevicePowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
-
-    Info("%s: %s -> %s\n",
-         __FdoGetName(Fdo),
+    /* Already marked pending by us */
+    Info("%s -> %s\n",
          DevicePowerStateName(__FdoGetDevicePowerState(Fdo)),
          DevicePowerStateName(DeviceState));
 
+    /* Don't worry about IRP IoStatus */
     ASSERT3U(DeviceState, ==, PowerDeviceD0);
-    status = FdoD3ToD0(Fdo);
-    ASSERT(NT_SUCCESS(status));
 
-done:
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    (VOID) InterlockedExchangePointer(&Fdo->DevicePowerIrp, Irp);
 
-    return status;
+    IoQueueWorkItem(Fdo->DevicePowerWorkItem,
+                    FdoSetDevcePowerUpWorker,
+                    DelayedWorkQueue,
+                    Fdo);
+
+    /* Stop completion chain in all circumstances. */
+    return STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+static NTSTATUS
+FdoSetDevicePowerUp(
+    IN  PXENBUS_FDO     Fdo,
+    IN  PIRP            Irp
+    )
+{
+    IoMarkIrpPending(Irp);
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           FdoSetDevicePowerUpComplete,
+                           Fdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    IoCallDriver(Fdo->LowerDeviceObject, Irp);
+    return STATUS_PENDING;
+}
+
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
+static VOID
+FdoSetDevicePowerDownWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
+    )
+{
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO)Context;
+    PIRP                Irp;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    Irp = InterlockedExchangePointer(&Fdo->DevicePowerIrp, NULL);
+    ASSERT(Irp != NULL);
+
+    FdoD0ToD3(Fdo);
+
+    /* We are on dispatch path here, irp pended. */
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoCallDriver(Fdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
@@ -4856,12 +4923,24 @@ FdoSetDevicePowerDown(
 
     ASSERT3U(DeviceState, ==, PowerDeviceD3);
 
-    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0)
-        FdoD0ToD3(Fdo);
+    if (__FdoGetDevicePowerState(Fdo) != PowerDeviceD0) {
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        goto done;
+    }
+
+    IoMarkIrpPending(Irp);
+    status = STATUS_PENDING;
+
+    (VOID) InterlockedExchangePointer(&Fdo->DevicePowerIrp, Irp);
 
+    IoQueueWorkItem(Fdo->DevicePowerWorkItem,
+                    FdoSetDevicePowerDownWorker,
+                    DelayedWorkQueue,
+                    Fdo);
+
+done:
     return status;
 }
 
@@ -4884,11 +4963,9 @@ FdoSetDevicePower(
           DevicePowerStateName(DeviceState), 
           PowerActionName(PowerAction));
 
-    ASSERT3U(PowerAction, <,  PowerActionShutdown);
-
     if (DeviceState == __FdoGetDevicePowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
@@ -4907,8 +4984,8 @@ done:
 
 __drv_functionClass(REQUEST_POWER_COMPLETE)
 __drv_sameIRQL
-VOID
-FdoRequestSetDevicePowerCompletion(
+static VOID
+FdoRequestDevicePowerUpComplete(
     IN  PDEVICE_OBJECT      DeviceObject,
     IN  UCHAR               MinorFunction,
     IN  POWER_STATE         PowerState,
@@ -4916,112 +4993,204 @@ FdoRequestSetDevicePowerCompletion(
     IN  PIO_STATUS_BLOCK    IoStatus
     )
 {
-    PKEVENT                 Event = Context;
+    PIRP                    Irp = (PIRP) Context;
 
     UNREFERENCED_PARAMETER(DeviceObject);
     UNREFERENCED_PARAMETER(MinorFunction);
     UNREFERENCED_PARAMETER(PowerState);
+    UNREFERENCED_PARAMETER(IoStatus);
 
-    ASSERT(NT_SUCCESS(IoStatus->Status));
-
-    KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
+    /* Although can change Irp->IoStatus for pended IRP, drivers should not fail this. */
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
 }
 
-__drv_requiresIRQL(PASSIVE_LEVEL)
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
 static VOID
-FdoRequestSetDevicePower(
-    IN  PXENBUS_FDO         Fdo,
-    IN  DEVICE_POWER_STATE  DeviceState
+FdoSetSystemPowerUpWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
     )
 {
-    POWER_STATE             PowerState;
-    KEVENT                  Event;
-    NTSTATUS                status;
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO)Context;
+    PIRP                Irp;
+    PIO_STACK_LOCATION  StackLocation;
+    SYSTEM_POWER_STATE  SystemState;
+    POWER_STATE         PowerState;
+    NTSTATUS            status;
 
-    Trace("%s\n", DevicePowerStateName(DeviceState));
+    UNREFERENCED_PARAMETER(DeviceObject);
 
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+    Irp = InterlockedExchangePointer(&Fdo->SystemPowerIrp, NULL);
+    ASSERT(Irp != NULL);
 
-    PowerState.DeviceState = DeviceState;
-    KeInitializeEvent(&Event, NotificationEvent, FALSE);
+    __FdoSetSystemPowerState(Fdo, PowerSystemHibernate);
+    FdoS4ToS3(Fdo);
+
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    SystemState = StackLocation->Parameters.Power.State.SystemState;
+
+    Info("%s -> %s\n",
+         SystemPowerStateName(__FdoGetSystemPowerState(Fdo)),
+         SystemPowerStateName(SystemState));
+
+    __FdoSetSystemPowerState(Fdo, SystemState);
+
+    PowerState.DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
 
     status = PoRequestPowerIrp(Fdo->LowerDeviceObject,
                                IRP_MN_SET_POWER,
                                PowerState,
-                               FdoRequestSetDevicePowerCompletion,
-                               &Event,
+                               FdoRequestDevicePowerUpComplete,
+                               Irp,
                                NULL);
-    ASSERT(NT_SUCCESS(status));
+    /* Whatever happens, we have stopped completion processing for SIrp,
+      to restart SIrp processing, call IoCompleteRequest. */
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
-    (VOID) KeWaitForSingleObject(&Event,
-                                 Executive,
-                                 KernelMode,
-                                 FALSE,
-                                 NULL);
+    return; /* FdoRequestDevicePowerUpComplete will complete the request.*/
+
+fail1:
+    Error("fail1 - but continue IRP processing. (%08x)\n", status);
+    /* Although can change Irp->IoStatus for pended IRP, drivers should not fail this. */
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
 }
 
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-FdoSetSystemPowerUp(
-    IN  PXENBUS_FDO     Fdo,
-    IN  PIRP            Irp
+FdoSetSystemPowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
-
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO) Context;
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    DEVICE_POWER_STATE  DeviceState;
+    POWER_STATE         PowerState;
     NTSTATUS            status;
 
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    /* IRP marked as pending on dispatch path, no need to check pending returned */
+
+    /* Don't worry about IRP IoStatus */
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
-    ASSERT3U(SystemState, <,  __FdoGetSystemPowerState(Fdo));
+    if (SystemState < PowerSystemHibernate &&
+        __FdoGetSystemPowerState(Fdo) >= PowerSystemHibernate) {
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
+        (VOID) InterlockedExchangePointer(&Fdo->SystemPowerIrp, Irp);
 
-    Info("%s: %s -> %s\n",
-         __FdoGetName(Fdo),
-         SystemPowerStateName(__FdoGetSystemPowerState(Fdo)),
-         SystemPowerStateName(SystemState));
+        IoQueueWorkItem(Fdo->SystemPowerWorkItem,
+                        FdoSetSystemPowerUpWorker,
+                        DelayedWorkQueue,
+                        Fdo);
 
-    if (SystemState < PowerSystemHibernate &&
-        __FdoGetSystemPowerState(Fdo) >= PowerSystemHibernate) {
-        __FdoSetSystemPowerState(Fdo, PowerSystemHibernate);
-        FdoS4ToS3(Fdo);
+        goto done; /* Stop completion routine for the moment... */
     }
 
+    Info("%s -> %s\n",
+         SystemPowerStateName(__FdoGetSystemPowerState(Fdo)),
+         SystemPowerStateName(SystemState));
+
     __FdoSetSystemPowerState(Fdo, SystemState);
 
-    DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
-    FdoRequestSetDevicePower(Fdo, DeviceState);
+    PowerState.DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
+
+    status = PoRequestPowerIrp(Fdo->LowerDeviceObject,
+                               IRP_MN_SET_POWER,
+                               PowerState,
+                               FdoRequestDevicePowerUpComplete,
+                               Irp,
+                               NULL);
+    /* Whatever happens, we have stopped completion processing for SIrp,
+      to restart SIrp processing, call IoCompleteRequest. */
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
 done:
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    return STATUS_MORE_PROCESSING_REQUIRED; /* FdoRequestDevicePowerUpComplete will complete the request.*/
 
-    return status;
+fail1:
+    Error("fail1 - but continue IRP processing. (%08x)\n", status);
+    /* marked pending on dispatch path, don't change Irp->IoStatus, keep going.*/
+    return STATUS_CONTINUE_COMPLETION;
 }
 
 static NTSTATUS
-FdoSetSystemPowerDown(
+FdoSetSystemPowerUp(
     IN  PXENBUS_FDO     Fdo,
     IN  PIRP            Irp
     )
 {
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           FdoSetSystemPowerUpComplete,
+                           Fdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
+}
+
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
+static VOID
+FdoSetSystemPowerDownWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
+    )
+{
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO)Context;
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
+    PIRP                Irp;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    Irp = InterlockedExchangePointer(&Fdo->SystemPowerIrp, NULL);
+    ASSERT(Irp != NULL);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
-    ASSERT3U(SystemState, >,  __FdoGetSystemPowerState(Fdo));
+    /* Meet preconditions for S3 to S4 */
+    __FdoSetSystemPowerState(Fdo, PowerSystemSleeping3);
+    FdoS3ToS4(Fdo);
+    __FdoSetSystemPowerState(Fdo, SystemState);
 
-    DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
+    IoCopyCurrentIrpStackLocationToNext(Irp); /* Irp has been pended */
+    IoCallDriver(Fdo->LowerDeviceObject, Irp);
+}
 
-    FdoRequestSetDevicePower(Fdo, DeviceState);
+__drv_functionClass(REQUEST_POWER_COMPLETE)
+__drv_sameIRQL
+static VOID
+FdoRequestDevicePowerDownComplete(
+    IN  PDEVICE_OBJECT      DeviceObject,
+    IN  UCHAR               MinorFunction,
+    IN  POWER_STATE         PowerState,
+    IN  PVOID               Context,
+    IN  PIO_STATUS_BLOCK    IoStatus
+    )
+{
+    PIRP                    Irp = (PIRP) Context;
+    PIO_STACK_LOCATION      StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    PDEVICE_OBJECT          UpperDeviceObject = StackLocation->DeviceObject;
+    PXENBUS_DX              Dx = (PXENBUS_DX)UpperDeviceObject->DeviceExtension;
+    PXENBUS_FDO             Fdo = Dx->Fdo;
+    SYSTEM_POWER_STATE      SystemState = StackLocation->Parameters.Power.State.SystemState;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
+    UNREFERENCED_PARAMETER(MinorFunction);
+    UNREFERENCED_PARAMETER(PowerState);
+
+    if (!NT_SUCCESS(IoStatus->Status))
+        Error("fail1 - but continue IRP processing. (%08x)\n", IoStatus->Status);
 
     Info("%s: %s -> %s\n",
          __FdoGetName(Fdo),
@@ -5030,145 +5199,118 @@ FdoSetSystemPowerDown(
 
     if (SystemState >= PowerSystemHibernate &&
         __FdoGetSystemPowerState(Fdo) < PowerSystemHibernate) {
-        __FdoSetSystemPowerState(Fdo, PowerSystemSleeping3);
-        FdoS3ToS4(Fdo);
+
+        (VOID) InterlockedExchangePointer(&Fdo->SystemPowerIrp, Irp);
+
+        IoQueueWorkItem(Fdo->SystemPowerWorkItem,
+                        FdoSetSystemPowerDownWorker,
+                        DelayedWorkQueue,
+                        Fdo);
+        goto done;
     }
 
     __FdoSetSystemPowerState(Fdo, SystemState);
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    IoCopyCurrentIrpStackLocationToNext(Irp); /* Irp has been pended */
+    IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
-    return status;
+done:
+    return;
 }
 
 static NTSTATUS
-FdoSetSystemPower(
+FdoSetSystemPowerDown(
     IN  PXENBUS_FDO     Fdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    POWER_ACTION        PowerAction;
+    POWER_STATE         PowerState;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
-    PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-    Trace("====> (%s:%s)\n",
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction));
+    ASSERT3U(SystemState, >,  __FdoGetSystemPowerState(Fdo));
 
-    ASSERT3U(PowerAction, <,  PowerActionShutdown);
+    PowerState.DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
 
-    if (SystemState == __FdoGetSystemPowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    if (SystemState >= PowerSystemShutdown) {
+        /* No DIrp generation, no FDO Powerdown.
+           Legacy shutdown just yanks system power.
+           Best device state for S5 is advertised as D3,
+           which is not *really* the case, but we can't increase it. */
+        IoCopyCurrentIrpStackLocationToNext(Irp); /* Irp has been pended */
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
-    status = (SystemState < __FdoGetSystemPowerState(Fdo)) ?
-             FdoSetSystemPowerUp(Fdo, Irp) :
-             FdoSetSystemPowerDown(Fdo, Irp);
+    status = PoRequestPowerIrp(Fdo->LowerDeviceObject,
+                               IRP_MN_SET_POWER,
+                               PowerState,
+                               FdoRequestDevicePowerDownComplete,
+                               Irp,
+                               NULL);
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
 done:
-    Trace("<==== (%s:%s)(%08x)\n",
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction),
-          status);
-    return status;
-}
-
-static NTSTATUS
-FdoQueryDevicePowerUp(
-    IN  PXENBUS_FDO     Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, <,  __FdoGetDevicePowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
     return status;
-}
-
-static NTSTATUS
-FdoQueryDevicePowerDown(
-    IN  PXENBUS_FDO     Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, >,  __FdoGetDevicePowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
+fail1:
+    /* In theory could change IRP status, but are not supposed to fail this IRP. */
+    Error("fail1 - but continue IRP processing. (%08x)\n", status);
     return status;
 }
 
 static NTSTATUS
-FdoQueryDevicePower(
+FdoSetSystemPower(
     IN  PXENBUS_FDO     Fdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
+    SYSTEM_POWER_STATE  SystemState;
     POWER_ACTION        PowerAction;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    SystemState = StackLocation->Parameters.Power.State.SystemState;
     PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
+    /* IRP_MN_SET_POWER Setting system power, IRP's *must* be pended. */
+    IoMarkIrpPending(Irp);
+
     Trace("====> (%s:%s)\n",
-          DevicePowerStateName(DeviceState), 
+          SystemPowerStateName(SystemState),
           PowerActionName(PowerAction));
 
-    ASSERT3U(PowerAction, <,  PowerActionShutdown);
-
-    if (DeviceState == __FdoGetDevicePowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    if (SystemState == __FdoGetSystemPowerState(Fdo)) {
+        IoCopyCurrentIrpStackLocationToNext(Irp); /* Pended, copy not skip */
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
-    status = (DeviceState < __FdoGetDevicePowerState(Fdo)) ?
-             FdoQueryDevicePowerUp(Fdo, Irp) :
-             FdoQueryDevicePowerDown(Fdo, Irp);
+    status = (SystemState < __FdoGetSystemPowerState(Fdo)) ?
+             FdoSetSystemPowerUp(Fdo, Irp) :
+             FdoSetSystemPowerDown(Fdo, Irp);
 
 done:
     Trace("<==== (%s:%s)(%08x)\n",
-          DevicePowerStateName(DeviceState), 
+          SystemPowerStateName(SystemState),
           PowerActionName(PowerAction),
           status);
+
     return status;
 }
 
 __drv_functionClass(REQUEST_POWER_COMPLETE)
 __drv_sameIRQL
-VOID
-FdoRequestQueryDevicePowerCompletion(
+static VOID
+FdoRequestQuerySystemPowerUpComplete(
     IN  PDEVICE_OBJECT      DeviceObject,
     IN  UCHAR               MinorFunction,
     IN  POWER_STATE         PowerState,
@@ -5176,48 +5318,56 @@ FdoRequestQueryDevicePowerCompletion(
     IN  PIO_STATUS_BLOCK    IoStatus
     )
 {
-    PKEVENT                 Event = Context;
+    PIRP                    Irp = (PIRP) Context;
 
     UNREFERENCED_PARAMETER(DeviceObject);
     UNREFERENCED_PARAMETER(MinorFunction);
     UNREFERENCED_PARAMETER(PowerState);
 
-    ASSERT(NT_SUCCESS(IoStatus->Status));
-
-    KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
+    if (!NT_SUCCESS(IoStatus->Status))
+        Irp->IoStatus.Status = IoStatus->Status;
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
 }
 
-__drv_requiresIRQL(PASSIVE_LEVEL)
-static VOID
-FdoRequestQueryDevicePower(
-    IN  PXENBUS_FDO         Fdo,
-    IN  DEVICE_POWER_STATE  DeviceState
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
+static NTSTATUS
+FdoQuerySystemPowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
-    POWER_STATE             PowerState;
-    KEVENT                  Event;
-    NTSTATUS                status;
-
-    Trace("%s\n", DevicePowerStateName(DeviceState));
+    PXENBUS_FDO         Fdo = (PXENBUS_FDO) Context;
+    PIO_STACK_LOCATION  StackLocation;
+    SYSTEM_POWER_STATE  SystemState;
+    POWER_STATE         PowerState;
+    NTSTATUS            status;
 
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+    UNREFERENCED_PARAMETER(DeviceObject);
 
-    PowerState.DeviceState = DeviceState;
-    KeInitializeEvent(&Event, NotificationEvent, FALSE);
+    /* IRP marked as pending on dispatch path. */
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    SystemState = StackLocation->Parameters.Power.State.SystemState;
+    PowerState.DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
 
     status = PoRequestPowerIrp(Fdo->LowerDeviceObject,
                                IRP_MN_QUERY_POWER,
                                PowerState,
-                               FdoRequestQueryDevicePowerCompletion,
-                               &Event,
+                               FdoRequestQuerySystemPowerUpComplete,
+                               Irp,
                                NULL);
-    ASSERT(NT_SUCCESS(status));
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
-    (VOID) KeWaitForSingleObject(&Event,
-                                 Executive,
-                                 KernelMode,
-                                 FALSE,
-                                 NULL);
+    return STATUS_MORE_PROCESSING_REQUIRED;
+
+fail1:
+    /* Irp marked as pending on dispatch path, so can change final IoStatus, pass to completion routine above. */
+    Error("fail1 (%08x)\n", status);
+    Irp->IoStatus.Status = status;
+
+    return STATUS_CONTINUE_COMPLETION;
 }
 
 static NTSTATUS
@@ -5226,29 +5376,50 @@ FdoQuerySystemPowerUp(
     IN  PIRP            Irp
     )
 {
+    IoMarkIrpPending(Irp); /* Must mark IRP pending because we want to complete it *after* completion routine. */
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           FdoQuerySystemPowerUpComplete,
+                           Fdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
+}
 
-    PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
+__drv_functionClass(REQUEST_POWER_COMPLETE)
+__drv_sameIRQL
+static VOID
+FdoRequestQuerySystemPowerDownComplete(
+    IN  PDEVICE_OBJECT      DeviceObject,
+    IN  UCHAR               MinorFunction,
+    IN  POWER_STATE         PowerState,
+    IN  PVOID               Context,
+    IN  PIO_STATUS_BLOCK    IoStatus
+    )
+{
+    PIRP                    Irp = (PIRP) Context;
+    PIO_STACK_LOCATION      StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    PDEVICE_OBJECT          UpperDeviceObject = StackLocation->DeviceObject;
+    PXENBUS_DX              Dx = (PXENBUS_DX)UpperDeviceObject->DeviceExtension;
+    PXENBUS_FDO             Fdo = Dx->Fdo;
 
-    ASSERT3U(SystemState, <,  __FdoGetSystemPowerState(Fdo));
+    UNREFERENCED_PARAMETER(DeviceObject);
+    UNREFERENCED_PARAMETER(MinorFunction);
+    UNREFERENCED_PARAMETER(PowerState);
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
+    if (!NT_SUCCESS(IoStatus->Status))
+        goto fail1;
 
-    DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
+    IoCopyCurrentIrpStackLocationToNext(Irp); /* Irp has been pended. */
+    IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
-    FdoRequestQueryDevicePower(Fdo, DeviceState);
+    return;
 
-done:
+fail1:
+    Error("fail1 (%08x)\n", IoStatus->Status);
+    Irp->IoStatus.Status = IoStatus->Status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
 }
 
 static NTSTATUS
@@ -5259,7 +5430,7 @@ FdoQuerySystemPowerDown(
 {
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    DEVICE_POWER_STATE  DeviceState;
+    POWER_STATE         PowerState;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
@@ -5267,11 +5438,24 @@ FdoQuerySystemPowerDown(
 
     ASSERT3U(SystemState, >,  __FdoGetSystemPowerState(Fdo));
 
-    DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
+    PowerState.DeviceState = Fdo->LowerDeviceCapabilities.DeviceState[SystemState];
 
-    FdoRequestQueryDevicePower(Fdo, DeviceState);
+    status = PoRequestPowerIrp(Fdo->LowerDeviceObject,
+                               IRP_MN_QUERY_POWER,
+                               PowerState,
+                               FdoRequestQuerySystemPowerDownComplete,
+                               Irp,
+                               NULL);
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
+    IoMarkIrpPending(Irp);
+    return STATUS_PENDING;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    Irp->IoStatus.Status = status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
     return status;
@@ -5296,11 +5480,9 @@ FdoQuerySystemPower(
           SystemPowerStateName(SystemState), 
           PowerActionName(PowerAction));
 
-    ASSERT3U(PowerAction, <,  PowerActionShutdown);
-
     if (SystemState == __FdoGetSystemPowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
@@ -5319,117 +5501,57 @@ done:
 }
 
 static NTSTATUS
-FdoDevicePower(
-    IN  PXENBUS_THREAD  Self,
-    IN  PVOID           Context
+FdoDispatchDevicePower(
+    IN  PXENBUS_FDO     Fdo,
+    IN  PIRP            Irp
     )
 {
-    PXENBUS_FDO         Fdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Fdo->DevicePowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Fdo->DevicePowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Fdo->DevicePowerIrp = NULL;
-        KeMemoryBarrier();
-
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
+    PIO_STACK_LOCATION  StackLocation;
+    NTSTATUS            status;
 
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) FdoSetDevicePower(Fdo, Irp);
-            break;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
 
-        case IRP_MN_QUERY_POWER:
-            (VOID) FdoQueryDevicePower(Fdo, Irp);
-            break;
+    switch (StackLocation->MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = FdoSetDevicePower(Fdo, Irp);
+        break;
 
-        default:
-            ASSERT(FALSE);
-            break;
-        }
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        break;
     }
 
-    return STATUS_SUCCESS;
+    return status;
 }
 
 static NTSTATUS
-FdoSystemPower(
-    IN  PXENBUS_THREAD  Self,
-    IN  PVOID           Context
+FdoDispatchSystemPower(
+    IN  PXENBUS_FDO     Fdo,
+    IN  PIRP            Irp
     )
 {
-    PXENBUS_FDO         Fdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Fdo->SystemPowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Fdo->SystemPowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Fdo->SystemPowerIrp = NULL;
-        KeMemoryBarrier();
+    PIO_STACK_LOCATION  StackLocation;
+    NTSTATUS            status;
 
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
 
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) FdoSetSystemPower(Fdo, Irp);
-            break;
+    switch (StackLocation->MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = FdoSetSystemPower(Fdo, Irp);
+        break;
 
-        case IRP_MN_QUERY_POWER:
-            (VOID) FdoQuerySystemPower(Fdo, Irp);
-            break;
+    case IRP_MN_QUERY_POWER:
+        status = FdoQuerySystemPower(Fdo, Irp);
+        break;
 
-        default:
-            ASSERT(FALSE);
-            break;
-        }
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        break;
     }
 
-    return STATUS_SUCCESS;
+    return status;
 }
 
 static NTSTATUS
@@ -5439,55 +5561,21 @@ FdoDispatchPower(
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    UCHAR               MinorFunction;
     POWER_STATE_TYPE    PowerType;
     POWER_ACTION        PowerAction;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    MinorFunction = StackLocation->MinorFunction;
-
-    if (MinorFunction != IRP_MN_QUERY_POWER &&
-        MinorFunction != IRP_MN_SET_POWER) {
-        IoSkipCurrentIrpStackLocation(Irp);
-        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
-
-        goto done;
-    }
-
     PowerType = StackLocation->Parameters.Power.Type;
     PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-    if (PowerAction >= PowerActionShutdown) {
-        IoSkipCurrentIrpStackLocation(Irp);
-        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
-
-        goto done;
-    }
-
     switch (PowerType) {
     case DevicePowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Fdo->DevicePowerIrp, ==, NULL);
-        Fdo->DevicePowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Fdo->DevicePowerThread);
-
-        status = STATUS_PENDING;
+        status = FdoDispatchDevicePower(Fdo, Irp);
         break;
 
     case SystemPowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Fdo->SystemPowerIrp, ==, NULL);
-        Fdo->SystemPowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Fdo->SystemPowerThread);
-
-        status = STATUS_PENDING;
+        status = FdoDispatchSystemPower(Fdo, Irp);
         break;
 
     default:
@@ -5496,10 +5584,10 @@ FdoDispatchPower(
         break;
     }
 
-done:
     return status;
 }
 
+
 static NTSTATUS
 FdoDispatchDefault(
     IN  PXENBUS_FDO Fdo,
@@ -5748,12 +5836,12 @@ FdoCreate(
     Fdo->LowerDeviceObject = IoAttachDeviceToDeviceStack(FunctionDeviceObject,
                                                          PhysicalDeviceObject);
 
-    status = ThreadCreate(FdoSystemPower, Fdo, &Fdo->SystemPowerThread);
-    if (!NT_SUCCESS(status))
+    Fdo->SystemPowerWorkItem = IoAllocateWorkItem(FunctionDeviceObject);
+    if (Fdo->SystemPowerWorkItem == NULL)
         goto fail3;
 
-    status = ThreadCreate(FdoDevicePower, Fdo, &Fdo->DevicePowerThread);
-    if (!NT_SUCCESS(status))
+    Fdo->DevicePowerWorkItem = IoAllocateWorkItem(FunctionDeviceObject);
+    if (Fdo->DevicePowerWorkItem == NULL)
         goto fail4;
 
     status = FdoAcquireLowerBusInterface(Fdo);
@@ -5992,17 +6080,15 @@ fail6:
 fail5:
     Error("fail5\n");
 
-    ThreadAlert(Fdo->DevicePowerThread);
-    ThreadJoin(Fdo->DevicePowerThread);
-    Fdo->DevicePowerThread = NULL;
-    
+    IoFreeWorkItem(Fdo->DevicePowerWorkItem);
+    Fdo->DevicePowerWorkItem = NULL;
+
 fail4:
     Error("fail4\n");
 
-    ThreadAlert(Fdo->SystemPowerThread);
-    ThreadJoin(Fdo->SystemPowerThread);
-    Fdo->SystemPowerThread = NULL;
-    
+    IoFreeWorkItem(Fdo->SystemPowerWorkItem);
+    Fdo->SystemPowerWorkItem = NULL;
+
 fail3:
     Error("fail3\n");
 
@@ -6117,13 +6203,11 @@ FdoDestroy(
 
     FdoReleaseLowerBusInterface(Fdo);
 
-    ThreadAlert(Fdo->DevicePowerThread);
-    ThreadJoin(Fdo->DevicePowerThread);
-    Fdo->DevicePowerThread = NULL;
+    IoFreeWorkItem(Fdo->DevicePowerWorkItem);
+    Fdo->DevicePowerWorkItem = NULL;
 
-    ThreadAlert(Fdo->SystemPowerThread);
-    ThreadJoin(Fdo->SystemPowerThread);
-    Fdo->SystemPowerThread = NULL;
+    IoFreeWorkItem(Fdo->SystemPowerWorkItem);
+    Fdo->SystemPowerWorkItem = NULL;
 
     IoDetachDevice(Fdo->LowerDeviceObject);
 
diff --git a/src/xenbus/pdo.c b/src/xenbus/pdo.c
index 3f1e4c5..9163923 100644
--- a/src/xenbus/pdo.c
+++ b/src/xenbus/pdo.c
@@ -58,9 +58,9 @@
 struct _XENBUS_PDO {
     PXENBUS_DX                  Dx;
 
-    PXENBUS_THREAD              SystemPowerThread;
+    PIO_WORKITEM                SystemPowerWorkItem;
     PIRP                        SystemPowerIrp;
-    PXENBUS_THREAD              DevicePowerThread;
+    PIO_WORKITEM                DevicePowerWorkItem;
     PIRP                        DevicePowerIrp;
 
     PXENBUS_FDO                 Fdo;
@@ -1695,26 +1695,31 @@ PdoDispatchPnp(
     return status;
 }
 
-static NTSTATUS
-PdoSetDevicePower(
-    IN  PXENBUS_PDO     Pdo,
-    IN  PIRP            Irp
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
+static VOID
+PdoSetDevicePowerWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
     )
 {
+    PXENBUS_PDO         Pdo = (PXENBUS_PDO) Context;
+    PIRP                Irp;
+    NTSTATUS            status;
     PIO_STACK_LOCATION  StackLocation;
     DEVICE_POWER_STATE  DeviceState;
     POWER_ACTION        PowerAction;
 
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    Irp = InterlockedExchangePointer(&Pdo->DevicePowerIrp, NULL);
+    ASSERT(Irp != NULL);
+
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     DeviceState = StackLocation->Parameters.Power.State.DeviceState;
     PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-    Trace("====> (%s:%s)\n",
-          DevicePowerStateName(DeviceState), 
-          PowerActionName(PowerAction));
-
-    ASSERT3U(PowerAction, <, PowerActionShutdown);
-
+    status = STATUS_SUCCESS;
     if (__PdoGetDevicePowerState(Pdo) > DeviceState) {
         Trace("%s: POWERING UP: %s -> %s\n",
               __PdoGetName(Pdo),
@@ -1722,7 +1727,7 @@ PdoSetDevicePower(
               DevicePowerStateName(DeviceState));
 
         ASSERT3U(DeviceState, ==, PowerDeviceD0);
-        PdoD3ToD0(Pdo);
+        status = PdoD3ToD0(Pdo);
     } else if (__PdoGetDevicePowerState(Pdo) < DeviceState) {
         Trace("%s: POWERING DOWN: %s -> %s\n",
               __PdoGetName(Pdo),
@@ -1733,76 +1738,76 @@ PdoSetDevicePower(
         PdoD0ToD3(Pdo);
     }
 
+    if(NT_SUCCESS(status))
+        goto done;
+
+    Error("fail1 (%08x)\n", status);
+    /* TODO - Consider cycling device power at some later point?
+       Need PPO to retry SIRP -> DIRP */
+
+done:
+    /* Cannot fail the IRP at this point, keep going. */
     Irp->IoStatus.Status = STATUS_SUCCESS;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
     Trace("<==== (%s:%s)\n",
           DevicePowerStateName(DeviceState), 
           PowerActionName(PowerAction));
-
-    return STATUS_SUCCESS;
 }
 
 static NTSTATUS
-PdoDevicePower(
-    IN  PXENBUS_THREAD  Self,
-    IN  PVOID           Context
+PdoSetDevicePower(
+    IN  PXENBUS_PDO     Pdo,
+    IN  PIRP            Irp
     )
 {
-    PXENBUS_PDO         Pdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP    Irp;
-
-        if (Pdo->DevicePowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
+    PIO_STACK_LOCATION  StackLocation;
+    DEVICE_POWER_STATE  DeviceState;
+    POWER_ACTION        PowerAction;
 
-        if (ThreadIsAlerted(Self))
-            break;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-        Irp = Pdo->DevicePowerIrp;
+    Trace("====> (%s:%s)\n",
+          DevicePowerStateName(DeviceState),
+          PowerActionName(PowerAction));
 
-        if (Irp == NULL)
-            continue;
+    IoMarkIrpPending(Irp);
 
-        Pdo->DevicePowerIrp = NULL;
-        KeMemoryBarrier();
+    (VOID) InterlockedExchangePointer(&Pdo->DevicePowerIrp, Irp);
 
-        (VOID) PdoSetDevicePower(Pdo, Irp);
-    }
+    IoQueueWorkItem(Pdo->DevicePowerWorkItem,
+                    PdoSetDevicePowerWorker,
+                    DelayedWorkQueue,
+                    Pdo);
 
-    return STATUS_SUCCESS;
+    return STATUS_PENDING;
 }
 
-static NTSTATUS
-PdoSetSystemPower(
-    IN  PXENBUS_PDO     Pdo,
-    IN  PIRP            Irp
+__drv_functionClass(IO_WORKITEM_ROUTINE)
+__drv_sameIRQL
+static VOID
+PdoSetSystemPowerWorker(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PVOID           Context
     )
 {
+    PXENBUS_PDO         Pdo = (PXENBUS_PDO) Context;
+    PIRP                Irp;
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
     POWER_ACTION        PowerAction;
 
+    UNREFERENCED_PARAMETER(DeviceObject);
+
+    Irp = InterlockedExchangePointer(&Pdo->SystemPowerIrp, NULL);
+    ASSERT(Irp != NULL);
+
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
     PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-    Trace("====> (%s:%s)\n",
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction));
-
-    ASSERT3U(PowerAction, <, PowerActionShutdown);
-
     if (__PdoGetSystemPowerState(Pdo) > SystemState) {
         if (SystemState < PowerSystemHibernate &&
             __PdoGetSystemPowerState(Pdo) >= PowerSystemHibernate) {
@@ -1836,52 +1841,40 @@ PdoSetSystemPower(
     Trace("<==== (%s:%s)\n",
           SystemPowerStateName(SystemState), 
           PowerActionName(PowerAction));
-
-    return STATUS_SUCCESS;
 }
 
 static NTSTATUS
-PdoSystemPower(
-    IN  PXENBUS_THREAD  Self,
-    IN  PVOID           Context
+PdoSetSystemPower(
+    IN  PXENBUS_PDO     Pdo,
+    IN  PIRP            Irp
     )
 {
-    PXENBUS_PDO         Pdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP    Irp;
-
-        if (Pdo->SystemPowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
+    PIO_STACK_LOCATION  StackLocation;
+    SYSTEM_POWER_STATE  SystemState;
+    POWER_ACTION        PowerAction;
 
-        if (ThreadIsAlerted(Self))
-            break;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    SystemState = StackLocation->Parameters.Power.State.SystemState;
+    PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-        Irp = Pdo->SystemPowerIrp;
+    Trace("====> (%s:%s)\n",
+          SystemPowerStateName(SystemState),
+          PowerActionName(PowerAction));
 
-        if (Irp == NULL)
-            continue;
+    IoMarkIrpPending(Irp);
 
-        Pdo->SystemPowerIrp = NULL;
-        KeMemoryBarrier();
+    (VOID) InterlockedExchangePointer(&Pdo->SystemPowerIrp, Irp);
 
-        (VOID) PdoSetSystemPower(Pdo, Irp);
-    }
+    IoQueueWorkItem(Pdo->SystemPowerWorkItem,
+                    PdoSetSystemPowerWorker,
+                    DelayedWorkQueue,
+                    Pdo);
 
-    return STATUS_SUCCESS;
+    return STATUS_PENDING;
 }
 
 static NTSTATUS
-PdoSetPower(
+PdoDispatchSetPower(
     IN  PXENBUS_PDO     Pdo,
     IN  PIRP            Irp
     )
@@ -1895,38 +1888,13 @@ PdoSetPower(
     PowerType = StackLocation->Parameters.Power.Type;
     PowerAction = StackLocation->Parameters.Power.ShutdownType;
 
-    if (PowerAction >= PowerActionShutdown) {
-        Irp->IoStatus.Status = STATUS_SUCCESS;
-        
-        status = Irp->IoStatus.Status;
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-        goto done;
-    }
-
     switch (PowerType) {
     case DevicePowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Pdo->DevicePowerIrp, ==, NULL);
-        Pdo->DevicePowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Pdo->DevicePowerThread);
-
-        status = STATUS_PENDING;
+        status = PdoSetDevicePower(Pdo, Irp);
         break;
 
     case SystemPowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Pdo->SystemPowerIrp, ==, NULL);
-        Pdo->SystemPowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Pdo->SystemPowerThread);
-
-        status = STATUS_PENDING;
+        status = PdoSetSystemPower(Pdo, Irp);
         break;
 
     default:
@@ -1935,25 +1903,6 @@ PdoSetPower(
         break;
     }
 
-done:
-    return status;
-}
-
-static NTSTATUS
-PdoQueryPower(
-    IN  PXENBUS_PDO Pdo,
-    IN  PIRP        Irp
-    )
-{
-    NTSTATUS        status;
-
-    UNREFERENCED_PARAMETER(Pdo);
-
-    status = STATUS_SUCCESS;
-
-    Irp->IoStatus.Status = status;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
     return status;
 }
 
@@ -1972,14 +1921,11 @@ PdoDispatchPower(
 
     switch (StackLocation->MinorFunction) {
     case IRP_MN_SET_POWER:
-        status = PdoSetPower(Pdo, Irp);
-        break;
-
-    case IRP_MN_QUERY_POWER:
-        status = PdoQueryPower(Pdo, Irp);
+        status = PdoDispatchSetPower(Pdo, Irp);
         break;
 
     default:
+        /* TODO - Always complete with status success?? */
         status = Irp->IoStatus.Status;
         IoCompleteRequest(Irp, IO_NO_INCREMENT);
         break;
@@ -2093,12 +2039,12 @@ PdoCreate(
     Pdo->Dx = Dx;
     Pdo->Fdo = Fdo;
 
-    status = ThreadCreate(PdoSystemPower, Pdo, &Pdo->SystemPowerThread);
-    if (!NT_SUCCESS(status))
+    Pdo->SystemPowerWorkItem = IoAllocateWorkItem(PhysicalDeviceObject);
+    if (Pdo->SystemPowerWorkItem == NULL)
         goto fail3;
 
-    status = ThreadCreate(PdoDevicePower, Pdo, &Pdo->DevicePowerThread);
-    if (!NT_SUCCESS(status))
+    Pdo->DevicePowerWorkItem = IoAllocateWorkItem(PhysicalDeviceObject);
+    if (Pdo->DevicePowerWorkItem == NULL)
         goto fail4;
 
     __PdoSetName(Pdo, Name);
@@ -2135,16 +2081,14 @@ fail5:
     Pdo->Ejectable = FALSE;
     Pdo->Removable = FALSE;
 
-    ThreadAlert(Pdo->DevicePowerThread);
-    ThreadJoin(Pdo->DevicePowerThread);
-    Pdo->DevicePowerThread = NULL;
+    IoFreeWorkItem(Pdo->DevicePowerWorkItem);
+    Pdo->DevicePowerWorkItem = NULL;
 
 fail4:
     Error("fail4\n");
 
-    ThreadAlert(Pdo->SystemPowerThread);
-    ThreadJoin(Pdo->SystemPowerThread);
-    Pdo->SystemPowerThread = NULL;
+    IoFreeWorkItem(Pdo->SystemPowerWorkItem);
+    Pdo->SystemPowerWorkItem = NULL;
 
 fail3:
     Error("fail3\n");
@@ -2198,13 +2142,11 @@ PdoDestroy(
     Pdo->Ejectable = FALSE;
     Pdo->Removable = FALSE;
 
-    ThreadAlert(Pdo->DevicePowerThread);
-    ThreadJoin(Pdo->DevicePowerThread);
-    Pdo->DevicePowerThread = NULL;
-    
-    ThreadAlert(Pdo->SystemPowerThread);
-    ThreadJoin(Pdo->SystemPowerThread);
-    Pdo->SystemPowerThread = NULL;
+    IoFreeWorkItem(Pdo->DevicePowerWorkItem);
+    Pdo->DevicePowerWorkItem = NULL;
+
+    IoFreeWorkItem(Pdo->SystemPowerWorkItem);
+    Pdo->SystemPowerWorkItem = NULL;
 
     Pdo->Fdo = NULL;
     Pdo->Dx = NULL;
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 10 13:42:46 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 10 Jan 2024 13:42:46 +0000
Received: from list by lists.xenproject.org with outflank-mailman.665444.1035652 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005jd-Bd; Wed, 10 Jan 2024 13:42:44 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 665444.1035652; Wed, 10 Jan 2024 13:42:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rNYqy-0005jW-7p; Wed, 10 Jan 2024 13:42:44 +0000
Received: by outflank-mailman (input) for mailman id 665444;
 Wed, 10 Jan 2024 13:42:43 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=Ixtf=IU=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rNYqw-0005jG-V6
 for win-pv-devel@lists.xenproject.org; Wed, 10 Jan 2024 13:42:43 +0000
Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com
 [2a00:1450:4864:20::135])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 1f8f0ac8-afbe-11ee-98f0-6d05b1d4d9a1;
 Wed, 10 Jan 2024 14:42:40 +0100 (CET)
Received: by mail-lf1-x135.google.com with SMTP id
 2adb3069b0e04-50e741123acso4583118e87.0
 for <win-pv-devel@lists.xenproject.org>; Wed, 10 Jan 2024 05:42:40 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 gl16-20020a170906e0d000b00a28bf7969cdsm2098473ejb.180.2024.01.10.05.42.37
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 10 Jan 2024 05:42:38 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 1f8f0ac8-afbe-11ee-98f0-6d05b1d4d9a1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1704894159; x=1705498959; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=Uz0xQ/ziVN43QxpG64Yc+KLF4QW+DJwf3v4B2t50iZU=;
        b=THev2GEPdqXM3iUDISC+C4f6ORyHbI6V8tg7th4xLDuBkuuCpo1kibnOxNPJgfv9ja
         jwvVzIfL38lKTs9NDpZXbk1zDTn+BI6Qxb4qd/iq4t3BgXvvIufPLuz2DiNFeBO8xvl3
         MRKuobp9JQ28LsY3Fz0bkxUebutQpHEl1xb98=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1704894159; x=1705498959;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=Uz0xQ/ziVN43QxpG64Yc+KLF4QW+DJwf3v4B2t50iZU=;
        b=RyAuo04BL2atY75qbFBFl++1LDELWRm7nPT7UTvt+6psfaeo5RzCDPKDhwb+0ftyl3
         PQsuDR5JVJbeyxP0e3PIztnasnD7YCADeQTSjR9ibM3xTaH5/DAbR/Dn8QeR+mJuQg4u
         wD5KKTaJ2R7NHhcM+XyTGDF3XsDTKkOXAeoVyutdUZdaRhbCybOg5WC9gNo4Nzt3tv6I
         TTPlE+jo/lzm4zb3x3/GAKQweXL06jZA0/OwpGan8u7keZr9gl5rUMppcz6kG0r+Kzb8
         rM87QLuy1PYqn4llIi30lK6kbQ33z1e7OWtkq2399eothWfwUmTz84jb1u82P6KkRULY
         8P1Q==
X-Gm-Message-State: AOJu0YyOIPr9VxkzV5oVrecDrYUq39sInomUl0WyB3kzAfJ9t8mX8kHU
	9s6QdhH3iEhWgVqpuClIh21nV/RRG8xEaJ6crSi6YTPu8Q==
X-Google-Smtp-Source: AGHT+IF+fd3CBoaHbQaYnwgzpOwmivowUZzTzROeAP9w1HRUy60Cj6l/TXK19k5mzmcItN3x7gZJog==
X-Received: by 2002:a19:690a:0:b0:50e:c51b:466d with SMTP id e10-20020a19690a000000b0050ec51b466dmr344350lfc.124.1704894159047;
        Wed, 10 Jan 2024 05:42:39 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Martin Harvey <Martin.Harvey@citrix.com>,
	Martin Harvey <martin.harvey@citrix.com>,
	Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 1/3] [XenFilt] Asynchronous power handling
Date: Wed, 10 Jan 2024 13:42:20 +0000
Message-ID: <20240110134222.1660-2-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240110134222.1660-1-owen.smith@cloud.com>
References: <20240110134222.1660-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Martin Harvey <Martin.Harvey@citrix.com>

XenFilt requires minimal IRP_MN_SET_POWER/IRP_MN_QUERY_POWER interactions.
No IoWorkItems are required as operationsperform no significant work.
Power handlers are is limited to tracking state changes and calling PoSetPowerState.

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

Refactored and limited to XenFilt changes

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenfilt/fdo.c | 498 +++++++++++----------------------------------
 src/xenfilt/pdo.c | 503 +++++++++++-----------------------------------
 2 files changed, 242 insertions(+), 759 deletions(-)

diff --git a/src/xenfilt/fdo.c b/src/xenfilt/fdo.c
index 78228de..08cf5a7 100644
--- a/src/xenfilt/fdo.c
+++ b/src/xenfilt/fdo.c
@@ -60,11 +60,6 @@ struct _XENFILT_FDO {
     PDEVICE_OBJECT                  PhysicalDeviceObject;
     CHAR                            Name[MAXNAMELEN];
 
-    PXENFILT_THREAD                 SystemPowerThread;
-    PIRP                            SystemPowerIrp;
-    PXENFILT_THREAD                 DevicePowerThread;
-    PIRP                            DevicePowerIrp;
-
     MUTEX                           Mutex;
     LIST_ENTRY                      List;
     ULONG                           References;
@@ -1078,76 +1073,87 @@ fail1:
     return status;
 }
 
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-FdoSetDevicePowerUp(
-    IN  PXENFILT_FDO    Fdo,
-    IN  PIRP            Irp
+FdoSetDevicePowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
+    PXENFILT_FDO        Fdo = (PXENFILT_FDO)Context;
     PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
     POWER_STATE         PowerState;
-    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    PowerState = StackLocation->Parameters.Power.State;
 
-    ASSERT3U(DeviceState, <,  __FdoGetDevicePowerState(Fdo));
+    ASSERT3U(PowerState.DeviceState, <,  __FdoGetDevicePowerState(Fdo));
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
+    if (Irp->PendingReturned)
+        IoMarkIrpPending(Irp);
 
     Trace("%s: %s -> %s\n",
           __FdoGetName(Fdo),
           DevicePowerStateName(__FdoGetDevicePowerState(Fdo)),
-          DevicePowerStateName(DeviceState));
+          DevicePowerStateName(PowerState.DeviceState));
 
-    PowerState.DeviceState = DeviceState;
     PoSetPowerState(Fdo->Dx->DeviceObject,
                     DevicePowerState,
                     PowerState);
 
-    __FdoSetDevicePowerState(Fdo, DeviceState);
+    __FdoSetDevicePowerState(Fdo, PowerState.DeviceState);
 
-done:
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    return STATUS_CONTINUE_COMPLETION;
+}
 
-    return status;
+static FORCEINLINE NTSTATUS
+__FdoSetDevicePowerUp(
+    IN  PXENFILT_FDO    Fdo,
+    IN  PIRP            Irp
+    )
+{
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           FdoSetDevicePowerUpComplete,
+                           Fdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
-FdoSetDevicePowerDown(
+__FdoSetDevicePowerDown(
     IN  PXENFILT_FDO    Fdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
     POWER_STATE         PowerState;
-    NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    PowerState = StackLocation->Parameters.Power.State;
 
-    ASSERT3U(DeviceState, >,  __FdoGetDevicePowerState(Fdo));
+    ASSERT3U(PowerState.DeviceState, >,  __FdoGetDevicePowerState(Fdo));
 
     Trace("%s: %s -> %s\n",
           __FdoGetName(Fdo),
           DevicePowerStateName(__FdoGetDevicePowerState(Fdo)),
-          DevicePowerStateName(DeviceState));
+          DevicePowerStateName(PowerState.DeviceState));
 
-    PowerState.DeviceState = DeviceState;
     PoSetPowerState(Fdo->Dx->DeviceObject,
                     DevicePowerState,
                     PowerState);
 
-    __FdoSetDevicePowerState(Fdo, DeviceState);
+    __FdoSetDevicePowerState(Fdo, PowerState.DeviceState);
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    IoSkipCurrentIrpStackLocation(Irp);
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
@@ -1171,15 +1177,15 @@ FdoSetDevicePower(
           PowerActionName(PowerAction));
 
     if (DeviceState == __FdoGetDevicePowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
     status = (DeviceState < __FdoGetDevicePowerState(Fdo)) ?
-             FdoSetDevicePowerUp(Fdo, Irp) :
-             FdoSetDevicePowerDown(Fdo, Irp);
+             __FdoSetDevicePowerUp(Fdo, Irp) :
+             __FdoSetDevicePowerDown(Fdo, Irp);
 
 done:
     Trace("%s: <==== (%s:%s)(%08x)\n",
@@ -1190,52 +1196,55 @@ done:
     return status;
 }
 
-static NTSTATUS
-FdoSetSystemPowerUp(
+static FORCEINLINE NTSTATUS
+__FdoDispatchDevicePower(
     IN  PXENFILT_FDO    Fdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
+    UCHAR               MinorFunction;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-
-    ASSERT3U(SystemState, <,  __FdoGetSystemPowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
-
-    Trace("%s: %s -> %s\n",
-          __FdoGetName(Fdo),
-          SystemPowerStateName(__FdoGetSystemPowerState(Fdo)),
-          SystemPowerStateName(SystemState));
+    MinorFunction = StackLocation->MinorFunction;
 
-    __FdoSetSystemPowerState(Fdo, SystemState);
+    switch (MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = FdoSetDevicePower(Fdo, Irp);
+        break;
 
-done:
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        break;
+    }
 
     return status;
 }
 
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-FdoSetSystemPowerDown(
-    IN  PXENFILT_FDO     Fdo,
-    IN  PIRP            Irp
+FdoSetSystemPowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
+    PXENFILT_FDO        Fdo = (PXENFILT_FDO)Context;
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
-    ASSERT3U(SystemState, >,  __FdoGetSystemPowerState(Fdo));
+    ASSERT3U(SystemState, <,  __FdoGetSystemPowerState(Fdo));
+
+    if (Irp->PendingReturned)
+        IoMarkIrpPending(Irp);
 
     Trace("%s: %s -> %s\n",
           __FdoGetName(Fdo),
@@ -1244,180 +1253,52 @@ FdoSetSystemPowerDown(
 
     __FdoSetSystemPowerState(Fdo, SystemState);
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
-}
-
-static NTSTATUS
-FdoSetSystemPower(
-    IN  PXENFILT_FDO    Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
-    POWER_ACTION        PowerAction;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-    PowerAction = StackLocation->Parameters.Power.ShutdownType;
-
-    Trace("%s: ====> (%s:%s)\n",
-          __FdoGetName(Fdo),
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction));
-
-    if (SystemState == __FdoGetSystemPowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-        goto done;
-    }
-
-    status = (SystemState < __FdoGetSystemPowerState(Fdo)) ?
-             FdoSetSystemPowerUp(Fdo, Irp) :
-             FdoSetSystemPowerDown(Fdo, Irp);
-
-done:
-    Trace("%s: <==== (%s:%s)(%08x)\n",
-          __FdoGetName(Fdo),
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction),
-          status);
-    return status;
-}
-
-static NTSTATUS
-FdoQueryDevicePowerUp(
-    IN  PXENFILT_FDO    Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, <,  __FdoGetDevicePowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    return STATUS_CONTINUE_COMPLETION;
 }
 
-static NTSTATUS
-FdoQueryDevicePowerDown(
-    IN  PXENFILT_FDO    Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, >,  __FdoGetDevicePowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
-}
-
-static NTSTATUS
-FdoQueryDevicePower(
+static FORCEINLINE NTSTATUS
+__FdoSetSystemPowerUp(
     IN  PXENFILT_FDO    Fdo,
     IN  PIRP            Irp
     )
 {
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    POWER_ACTION        PowerAction;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-    PowerAction = StackLocation->Parameters.Power.ShutdownType;
-
-    Trace("%s: ====> (%s:%s)\n",
-          __FdoGetName(Fdo),
-          DevicePowerStateName(DeviceState), 
-          PowerActionName(PowerAction));
-
-    if (DeviceState == __FdoGetDevicePowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-        goto done;
-    }
-
-    status = (DeviceState < __FdoGetDevicePowerState(Fdo)) ?
-             FdoQueryDevicePowerUp(Fdo, Irp) :
-             FdoQueryDevicePowerDown(Fdo, Irp);
-
-done:
-    Trace("%s: <==== (%s:%s)(%08x)\n",
-          __FdoGetName(Fdo),
-          DevicePowerStateName(DeviceState), 
-          PowerActionName(PowerAction),
-          status);
-    return status;
-}
-
-static NTSTATUS
-FdoQuerySystemPowerUp(
-    IN  PXENFILT_FDO     Fdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-
-    ASSERT3U(SystemState, <,  __FdoGetSystemPowerState(Fdo));
-
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           FdoSetSystemPowerUpComplete,
+                           Fdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
 }
 
-static NTSTATUS
-FdoQuerySystemPowerDown(
+static FORCEINLINE NTSTATUS
+__FdoSetSystemPowerDown(
     IN  PXENFILT_FDO    Fdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
     ASSERT3U(SystemState, >,  __FdoGetSystemPowerState(Fdo));
 
-    status = FdoForwardIrpSynchronously(Fdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    Trace("%s: %s -> %s\n",
+          __FdoGetName(Fdo),
+          SystemPowerStateName(__FdoGetSystemPowerState(Fdo)),
+          SystemPowerStateName(SystemState));
 
-    return status;
+    __FdoSetSystemPowerState(Fdo, SystemState);
+
+    IoSkipCurrentIrpStackLocation(Irp);
+    return IoCallDriver(Fdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
-FdoQuerySystemPower(
+FdoSetSystemPower(
     IN  PXENFILT_FDO    Fdo,
     IN  PIRP            Irp
     )
@@ -1437,15 +1318,15 @@ FdoQuerySystemPower(
           PowerActionName(PowerAction));
 
     if (SystemState == __FdoGetSystemPowerState(Fdo)) {
-        status = FdoForwardIrpSynchronously(Fdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
     status = (SystemState < __FdoGetSystemPowerState(Fdo)) ?
-             FdoQuerySystemPowerUp(Fdo, Irp) :
-             FdoQuerySystemPowerDown(Fdo, Irp);
+             __FdoSetSystemPowerUp(Fdo, Irp) :
+             __FdoSetSystemPowerDown(Fdo, Irp);
 
 done:
     Trace("%s: <==== (%s:%s)(%08x)\n",
@@ -1453,126 +1334,34 @@ done:
           SystemPowerStateName(SystemState), 
           PowerActionName(PowerAction),
           status);
-
     return status;
 }
 
-static NTSTATUS
-FdoDevicePower(
-    IN  PXENFILT_THREAD Self,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_FDO        Fdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Fdo->DevicePowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Fdo->DevicePowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Fdo->DevicePowerIrp = NULL;
-        KeMemoryBarrier();
-
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
-
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) FdoSetDevicePower(Fdo, Irp);
-            break;
-
-        case IRP_MN_QUERY_POWER:
-            (VOID) FdoQueryDevicePower(Fdo, Irp);
-            break;
-
-        default:
-            ASSERT(FALSE);
-            break;
-        }
-
-        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
-    }
-
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS
-FdoSystemPower(
-    IN  PXENFILT_THREAD Self,
-    IN  PVOID           Context
+static FORCEINLINE NTSTATUS
+__FdoDispatchSystemPower(
+    IN  PXENFILT_FDO    Fdo,
+    IN  PIRP            Irp
     )
 {
-    PXENFILT_FDO        Fdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Fdo->SystemPowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Fdo->SystemPowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Fdo->SystemPowerIrp = NULL;
-        KeMemoryBarrier();
-
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
-
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) FdoSetSystemPower(Fdo, Irp);
-            break;
+    PIO_STACK_LOCATION  StackLocation;
+    UCHAR               MinorFunction;
+    NTSTATUS            status;
 
-        case IRP_MN_QUERY_POWER:
-            (VOID) FdoQuerySystemPower(Fdo, Irp);
-            break;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    MinorFunction = StackLocation->MinorFunction;
 
-        default:
-            ASSERT(FALSE);
-            break;
-        }
+    switch (MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = FdoSetSystemPower(Fdo, Irp);
+        break;
 
-        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
+        break;
     }
 
-    return STATUS_SUCCESS;
+    return status;
 }
 
 static NTSTATUS
@@ -1593,8 +1382,7 @@ FdoDispatchPower(
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     MinorFunction = StackLocation->MinorFunction;
 
-    if (MinorFunction != IRP_MN_QUERY_POWER &&
-        MinorFunction != IRP_MN_SET_POWER) {
+    if (MinorFunction != IRP_MN_SET_POWER) {
         IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
@@ -1612,27 +1400,13 @@ FdoDispatchPower(
 
     switch (PowerType) {
     case DevicePowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Fdo->DevicePowerIrp, ==, NULL);
-        Fdo->DevicePowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Fdo->DevicePowerThread);
-
-        status = STATUS_PENDING;
+        status = __FdoDispatchDevicePower(Fdo, Irp);
+        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
         break;
 
     case SystemPowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Fdo->SystemPowerIrp, ==, NULL);
-        Fdo->SystemPowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Fdo->SystemPowerThread);
-
-        status = STATUS_PENDING;
+        status = __FdoDispatchSystemPower(Fdo, Irp);
+        IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
         break;
 
     default:
@@ -1776,21 +1550,13 @@ FdoCreate(
     Fdo->LowerDeviceObject = LowerDeviceObject;
     Fdo->Type = Type;
 
-    status = ThreadCreate(FdoSystemPower, Fdo, &Fdo->SystemPowerThread);
-    if (!NT_SUCCESS(status))
-        goto fail4;
-
-    status = ThreadCreate(FdoDevicePower, Fdo, &Fdo->DevicePowerThread);
-    if (!NT_SUCCESS(status))
-        goto fail5;
-
     status = __FdoSetDeviceID(Fdo);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail4;
 
     status = __FdoSetInstanceID(Fdo);
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail5;
 
     __FdoSetName(Fdo);
 
@@ -1815,24 +1581,10 @@ FdoCreate(
 
     return STATUS_SUCCESS;
 
-fail7:
-    Error("fail7\n");
-
-    __FdoClearDeviceID(Fdo);
-
-fail6:
-    Error("fail6\n");
-
-    ThreadAlert(Fdo->DevicePowerThread);
-    ThreadJoin(Fdo->DevicePowerThread);
-    Fdo->DevicePowerThread = NULL;
-
 fail5:
     Error("fail5\n");
 
-    ThreadAlert(Fdo->SystemPowerThread);
-    ThreadJoin(Fdo->SystemPowerThread);
-    Fdo->SystemPowerThread = NULL;
+    __FdoClearDeviceID(Fdo);
 
 fail4:
     Error("fail4\n");
@@ -1892,14 +1644,6 @@ FdoDestroy(
     __FdoClearInstanceID(Fdo);
     __FdoClearDeviceID(Fdo);
 
-    ThreadAlert(Fdo->DevicePowerThread);
-    ThreadJoin(Fdo->DevicePowerThread);
-    Fdo->DevicePowerThread = NULL;
-
-    ThreadAlert(Fdo->SystemPowerThread);
-    ThreadJoin(Fdo->SystemPowerThread);
-    Fdo->SystemPowerThread = NULL;
-
     Fdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Fdo->LowerDeviceObject = NULL;
     Fdo->PhysicalDeviceObject = NULL;
diff --git a/src/xenfilt/pdo.c b/src/xenfilt/pdo.c
index be84996..3ce30a8 100644
--- a/src/xenfilt/pdo.c
+++ b/src/xenfilt/pdo.c
@@ -57,11 +57,6 @@ struct _XENFILT_PDO {
     PDEVICE_OBJECT                  PhysicalDeviceObject;
     CHAR                            Name[MAXNAMELEN];
 
-    PXENFILT_THREAD                 SystemPowerThread;
-    PIRP                            SystemPowerIrp;
-    PXENFILT_THREAD                 DevicePowerThread;
-    PIRP                            DevicePowerIrp;
-
     PXENFILT_FDO                    Fdo;
     BOOLEAN                         Missing;
     const CHAR                      *Reason;
@@ -1187,77 +1182,86 @@ fail1:
     return status;
 }
 
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-PdoSetDevicePowerUp(
-    IN  PXENFILT_PDO    Pdo,
-    IN  PIRP            Irp
+PdoSetDevicePowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
+    PXENFILT_PDO        Pdo = (PXENFILT_PDO)Context;
     PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
     POWER_STATE         PowerState;
-    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    PowerState = StackLocation->Parameters.Power.State;
 
-    ASSERT3U(DeviceState, <,  __PdoGetDevicePowerState(Pdo));
+    ASSERT3U(PowerState.DeviceState, <,  __PdoGetDevicePowerState(Pdo));
 
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
+    if (Irp->PendingReturned)
+        IoMarkIrpPending(Irp);
 
     Trace("%s: %s -> %s\n",
           __PdoGetName(Pdo),
           DevicePowerStateName(__PdoGetDevicePowerState(Pdo)),
-          DevicePowerStateName(DeviceState));
+          DevicePowerStateName(PowerState.DeviceState));
 
-    PowerState.DeviceState = DeviceState;
     PoSetPowerState(__PdoGetDeviceObject(Pdo),
                     DevicePowerState,
                     PowerState);
 
-    __PdoSetDevicePowerState(Pdo, DeviceState);
+    __PdoSetDevicePowerState(Pdo, PowerState.DeviceState);
 
-done:
-    Irp->IoStatus.Status = status;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    return STATUS_CONTINUE_COMPLETION;
+}
 
-    return status;
+static FORCEINLINE NTSTATUS
+__PdoSetDevicePowerUp(
+    IN  PXENFILT_PDO    Pdo,
+    IN  PIRP            Irp
+    )
+{
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           PdoSetDevicePowerUpComplete,
+                           Pdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    return IoCallDriver(Pdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
-PdoSetDevicePowerDown(
+__PdoSetDevicePowerDown(
     IN  PXENFILT_PDO    Pdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
     POWER_STATE         PowerState;
-    NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
+    PowerState = StackLocation->Parameters.Power.State;
 
-    ASSERT3U(DeviceState, >,  __PdoGetDevicePowerState(Pdo));
+    ASSERT3U(PowerState.DeviceState, >,  __PdoGetDevicePowerState(Pdo));
 
     Trace("%s: %s -> %s\n",
           __PdoGetName(Pdo),
           DevicePowerStateName(__PdoGetDevicePowerState(Pdo)),
-          DevicePowerStateName(DeviceState));
+          DevicePowerStateName(PowerState.DeviceState));
 
-    PowerState.DeviceState = DeviceState;
     PoSetPowerState(__PdoGetDeviceObject(Pdo),
                     DevicePowerState,
                     PowerState);
 
-    __PdoSetDevicePowerState(Pdo, DeviceState);
+    __PdoSetDevicePowerState(Pdo, PowerState.DeviceState);
 
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    IoSkipCurrentIrpStackLocation(Irp);
+    return IoCallDriver(Pdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
@@ -1281,15 +1285,15 @@ PdoSetDevicePower(
           PowerActionName(PowerAction));
 
     if (DeviceState == __PdoGetDevicePowerState(Pdo)) {
-        status = PdoForwardIrpSynchronously(Pdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
     status = (DeviceState < __PdoGetDevicePowerState(Pdo)) ?
-             PdoSetDevicePowerUp(Pdo, Irp) :
-             PdoSetDevicePowerDown(Pdo, Irp);
+             __PdoSetDevicePowerUp(Pdo, Irp) :
+             __PdoSetDevicePowerDown(Pdo, Irp);
 
 done:
     Trace("%s: <==== (%s:%s)(%08x)\n",
@@ -1300,53 +1304,55 @@ done:
     return status;
 }
 
-static NTSTATUS
-PdoSetSystemPowerUp(
+static FORCEINLINE NTSTATUS
+__PdoDispatchDevicePower(
     IN  PXENFILT_PDO    Pdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
+    UCHAR               MinorFunction;
     NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-
-    ASSERT3U(SystemState, <,  __PdoGetSystemPowerState(Pdo));
-
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    if (!NT_SUCCESS(status))
-        goto done;
-
-    Trace("%s: %s -> %s\n",
-          __PdoGetName(Pdo),
-          SystemPowerStateName(__PdoGetSystemPowerState(Pdo)),
-          SystemPowerStateName(SystemState));
+    MinorFunction = StackLocation->MinorFunction;
 
-    __PdoSetSystemPowerState(Pdo, SystemState);
+    switch (MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = PdoSetDevicePower(Pdo, Irp);
+        break;
 
-done:
-    Irp->IoStatus.Status = status;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+        break;
+    }
 
     return status;
 }
 
+__drv_functionClass(IO_COMPLETION_ROUTINE)
+__drv_sameIRQL
 static NTSTATUS
-PdoSetSystemPowerDown(
-    IN  PXENFILT_PDO     Pdo,
-    IN  PIRP            Irp
+PdoSetSystemPowerUpComplete(
+    IN  PDEVICE_OBJECT  DeviceObject,
+    IN  PIRP            Irp,
+    IN  PVOID           Context
     )
 {
+    PXENFILT_PDO        Pdo = (PXENFILT_PDO)Context;
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(DeviceObject);
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
-    ASSERT3U(SystemState, >,  __PdoGetSystemPowerState(Pdo));
+    ASSERT3U(SystemState, <,  __PdoGetSystemPowerState(Pdo));
+
+    if (Irp->PendingReturned)
+        IoMarkIrpPending(Irp);
 
     Trace("%s: %s -> %s\n",
           __PdoGetName(Pdo),
@@ -1355,182 +1361,52 @@ PdoSetSystemPowerDown(
 
     __PdoSetSystemPowerState(Pdo, SystemState);
 
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
-}
-
-static NTSTATUS
-PdoSetSystemPower(
-    IN  PXENFILT_PDO    Pdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
-    POWER_ACTION        PowerAction;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-    PowerAction = StackLocation->Parameters.Power.ShutdownType;
-
-    Trace("%s: ====> (%s:%s)\n",
-          __PdoGetName(Pdo),
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction));
-
-    if (SystemState == __PdoGetSystemPowerState(Pdo)) {
-        status = PdoForwardIrpSynchronously(Pdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-        goto done;
-    }
-
-    status = (SystemState < __PdoGetSystemPowerState(Pdo)) ?
-             PdoSetSystemPowerUp(Pdo, Irp) :
-             PdoSetSystemPowerDown(Pdo, Irp);
-
-done:
-    Trace("%s: <==== (%s:%s)(%08x)\n",
-          __PdoGetName(Pdo),
-          SystemPowerStateName(SystemState), 
-          PowerActionName(PowerAction),
-          status);
-    return status;
-}
-
-static NTSTATUS
-PdoQueryDevicePowerUp(
-    IN  PXENFILT_PDO    Pdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, <,  __PdoGetDevicePowerState(Pdo));
-
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-
-    Irp->IoStatus.Status = status;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
-}
-
-static NTSTATUS
-PdoQueryDevicePowerDown(
-    IN  PXENFILT_PDO    Pdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-
-    ASSERT3U(DeviceState, >,  __PdoGetDevicePowerState(Pdo));
-
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    return STATUS_CONTINUE_COMPLETION;
 }
 
-static NTSTATUS
-PdoQueryDevicePower(
+static FORCEINLINE NTSTATUS
+__PdoSetSystemPowerUp(
     IN  PXENFILT_PDO    Pdo,
     IN  PIRP            Irp
     )
 {
-    PIO_STACK_LOCATION  StackLocation;
-    DEVICE_POWER_STATE  DeviceState;
-    POWER_ACTION        PowerAction;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    DeviceState = StackLocation->Parameters.Power.State.DeviceState;
-    PowerAction = StackLocation->Parameters.Power.ShutdownType;
-
-    Trace("%s: ====> (%s:%s)\n",
-          __PdoGetName(Pdo),
-          DevicePowerStateName(DeviceState), 
-          PowerActionName(PowerAction));
-
-    if (DeviceState == __PdoGetDevicePowerState(Pdo)) {
-        status = PdoForwardIrpSynchronously(Pdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-        goto done;
-    }
-
-    status = (DeviceState < __PdoGetDevicePowerState(Pdo)) ?
-             PdoQueryDevicePowerUp(Pdo, Irp) :
-             PdoQueryDevicePowerDown(Pdo, Irp);
-
-done:
-    Trace("%s: <==== (%s:%s)(%08x)\n",
-          __PdoGetName(Pdo),
-          DevicePowerStateName(DeviceState), 
-          PowerActionName(PowerAction),
-          status);
-    return status;
-}
-
-static NTSTATUS
-PdoQuerySystemPowerUp(
-    IN  PXENFILT_PDO    Pdo,
-    IN  PIRP            Irp
-    )
-{
-    PIO_STACK_LOCATION  StackLocation;
-    SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
-
-    StackLocation = IoGetCurrentIrpStackLocation(Irp);
-    SystemState = StackLocation->Parameters.Power.State.SystemState;
-
-    ASSERT3U(SystemState, <,  __PdoGetSystemPowerState(Pdo));
-
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-
-    Irp->IoStatus.Status = status;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return status;
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           PdoSetSystemPowerUpComplete,
+                           Pdo,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    return IoCallDriver(Pdo->LowerDeviceObject, Irp);
 }
 
-static NTSTATUS
-PdoQuerySystemPowerDown(
+static FORCEINLINE NTSTATUS
+__PdoSetSystemPowerDown(
     IN  PXENFILT_PDO    Pdo,
     IN  PIRP            Irp
     )
 {
     PIO_STACK_LOCATION  StackLocation;
     SYSTEM_POWER_STATE  SystemState;
-    NTSTATUS            status;
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     SystemState = StackLocation->Parameters.Power.State.SystemState;
 
     ASSERT3U(SystemState, >,  __PdoGetSystemPowerState(Pdo));
 
-    status = PdoForwardIrpSynchronously(Pdo, Irp);
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    Trace("%s: %s -> %s\n",
+          __PdoGetName(Pdo),
+          SystemPowerStateName(__PdoGetSystemPowerState(Pdo)),
+          SystemPowerStateName(SystemState));
 
-    return status;
+    __PdoSetSystemPowerState(Pdo, SystemState);
+
+    IoSkipCurrentIrpStackLocation(Irp);
+    return IoCallDriver(Pdo->LowerDeviceObject, Irp);
 }
 
 static NTSTATUS
-PdoQuerySystemPower(
+PdoSetSystemPower(
     IN  PXENFILT_PDO    Pdo,
     IN  PIRP            Irp
     )
@@ -1550,15 +1426,15 @@ PdoQuerySystemPower(
           PowerActionName(PowerAction));
 
     if (SystemState == __PdoGetSystemPowerState(Pdo)) {
-        status = PdoForwardIrpSynchronously(Pdo, Irp);
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
 
         goto done;
     }
 
     status = (SystemState < __PdoGetSystemPowerState(Pdo)) ?
-             PdoQuerySystemPowerUp(Pdo, Irp) :
-             PdoQuerySystemPowerDown(Pdo, Irp);
+             __PdoSetSystemPowerUp(Pdo, Irp) :
+             __PdoSetSystemPowerDown(Pdo, Irp);
 
 done:
     Trace("%s: <==== (%s:%s)(%08x)\n",
@@ -1566,126 +1442,34 @@ done:
           SystemPowerStateName(SystemState), 
           PowerActionName(PowerAction),
           status);
-
     return status;
 }
 
-static NTSTATUS
-PdoDevicePower(
-    IN  PXENFILT_THREAD Self,
-    IN  PVOID           Context
-    )
-{
-    PXENFILT_PDO        Pdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Pdo->DevicePowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Pdo->DevicePowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Pdo->DevicePowerIrp = NULL;
-        KeMemoryBarrier();
-
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
-
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) PdoSetDevicePower(Pdo, Irp);
-            break;
-
-        case IRP_MN_QUERY_POWER:
-            (VOID) PdoQueryDevicePower(Pdo, Irp);
-            break;
-
-        default:
-            ASSERT(FALSE);
-            break;
-        }
-
-        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-    }
-
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS
-PdoSystemPower(
-    IN  PXENFILT_THREAD Self,
-    IN  PVOID           Context
+static FORCEINLINE NTSTATUS
+__PdoDispatchSystemPower(
+    IN  PXENFILT_PDO    Pdo,
+    IN  PIRP            Irp
     )
 {
-    PXENFILT_PDO        Pdo = Context;
-    PKEVENT             Event;
-
-    Event = ThreadGetEvent(Self);
-
-    for (;;) {
-        PIRP                Irp;
-        PIO_STACK_LOCATION  StackLocation;
-        UCHAR               MinorFunction;
-
-        if (Pdo->SystemPowerIrp == NULL) {
-            (VOID) KeWaitForSingleObject(Event,
-                                         Executive,
-                                         KernelMode,
-                                         FALSE,
-                                         NULL);
-            KeClearEvent(Event);
-        }
-
-        if (ThreadIsAlerted(Self))
-            break;
-
-        Irp = Pdo->SystemPowerIrp;
-
-        if (Irp == NULL)
-            continue;
-
-        Pdo->SystemPowerIrp = NULL;
-        KeMemoryBarrier();
-
-        StackLocation = IoGetCurrentIrpStackLocation(Irp);
-        MinorFunction = StackLocation->MinorFunction;
-
-        switch (StackLocation->MinorFunction) {
-        case IRP_MN_SET_POWER:
-            (VOID) PdoSetSystemPower(Pdo, Irp);
-            break;
+    PIO_STACK_LOCATION  StackLocation;
+    UCHAR               MinorFunction;
+    NTSTATUS            status;
 
-        case IRP_MN_QUERY_POWER:
-            (VOID) PdoQuerySystemPower(Pdo, Irp);
-            break;
+    StackLocation = IoGetCurrentIrpStackLocation(Irp);
+    MinorFunction = StackLocation->MinorFunction;
 
-        default:
-            ASSERT(FALSE);
-            break;
-        }
+    switch (MinorFunction) {
+    case IRP_MN_SET_POWER:
+        status = PdoSetSystemPower(Pdo, Irp);
+        break;
 
-        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
+    default:
+        IoSkipCurrentIrpStackLocation(Irp);
+        status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
+        break;
     }
 
-    return STATUS_SUCCESS;
+    return status;
 }
 
 static NTSTATUS
@@ -1706,8 +1490,7 @@ PdoDispatchPower(
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
     MinorFunction = StackLocation->MinorFunction;
 
-    if (MinorFunction != IRP_MN_QUERY_POWER &&
-        MinorFunction != IRP_MN_SET_POWER) {
+    if (MinorFunction != IRP_MN_SET_POWER) {
         IoSkipCurrentIrpStackLocation(Irp);
 
         status = IoCallDriver(Pdo->LowerDeviceObject, Irp);
@@ -1725,27 +1508,13 @@ PdoDispatchPower(
 
     switch (PowerType) {
     case DevicePowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Pdo->DevicePowerIrp, ==, NULL);
-        Pdo->DevicePowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Pdo->DevicePowerThread);
-
-        status = STATUS_PENDING;
+        status = __PdoDispatchDevicePower(Pdo, Irp);
+        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
         break;
 
     case SystemPowerState:
-        IoMarkIrpPending(Irp);
-
-        ASSERT3P(Pdo->SystemPowerIrp, ==, NULL);
-        Pdo->SystemPowerIrp = Irp;
-        KeMemoryBarrier();
-
-        ThreadWake(Pdo->SystemPowerThread);
-
-        status = STATUS_PENDING;
+        status = __PdoDispatchSystemPower(Pdo, Irp);
+        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
         break;
 
     default:
@@ -1908,17 +1677,9 @@ PdoCreate(
     Pdo->LowerDeviceObject = LowerDeviceObject;
     Pdo->Type = Type;
 
-    status = ThreadCreate(PdoSystemPower, Pdo, &Pdo->SystemPowerThread);
-    if (!NT_SUCCESS(status))
-        goto fail4;
-
-    status = ThreadCreate(PdoDevicePower, Pdo, &Pdo->DevicePowerThread);
-    if (!NT_SUCCESS(status))
-        goto fail5;
-
     status = PdoSetDeviceInformation(Pdo);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail4;
 
     status = DriverQueryId(Pdo->LowerDeviceObject,
                            BusQueryCompatibleIDs,
@@ -1933,7 +1694,7 @@ PdoCreate(
                                __PdoGetType(Pdo),
                                &Pdo->EmulatedObject);
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail5;
 
     if (CompatibleIDs)
         ExFreePool(CompatibleIDs);
@@ -1958,28 +1719,14 @@ PdoCreate(
 
     return STATUS_SUCCESS;
 
-fail7:
-    Error("fail7\n");
+fail5:
+    Error("fail5\n");
 
     if (CompatibleIDs)
         ExFreePool(CompatibleIDs);
 
     PdoClearDeviceInformation(Pdo);
 
-fail6:
-    Error("fail6\n");
-
-    ThreadAlert(Pdo->DevicePowerThread);
-    ThreadJoin(Pdo->DevicePowerThread);
-    Pdo->DevicePowerThread = NULL;
-
-fail5:
-    Error("fail5\n");
-
-    ThreadAlert(Pdo->SystemPowerThread);
-    ThreadJoin(Pdo->SystemPowerThread);
-    Pdo->SystemPowerThread = NULL;
-
 fail4:
     Error("fail4\n");
 
@@ -2041,14 +1788,6 @@ PdoDestroy(
 
     PdoClearDeviceInformation(Pdo);
 
-    ThreadAlert(Pdo->DevicePowerThread);
-    ThreadJoin(Pdo->DevicePowerThread);
-    Pdo->DevicePowerThread = NULL;
-
-    ThreadAlert(Pdo->SystemPowerThread);
-    ThreadJoin(Pdo->SystemPowerThread);
-    Pdo->SystemPowerThread = NULL;
-
     Pdo->Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
     Pdo->PhysicalDeviceObject = NULL;
     Pdo->LowerDeviceObject = NULL;
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Fri Jan 12 12:59:36 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 12 Jan 2024 12:59:36 +0000
Received: from list by lists.xenproject.org with outflank-mailman.666871.1037802 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rOH8H-0008PR-AV; Fri, 12 Jan 2024 12:59:33 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 666871.1037802; Fri, 12 Jan 2024 12:59:33 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rOH8H-0008PK-7u; Fri, 12 Jan 2024 12:59:33 +0000
Received: by outflank-mailman (input) for mailman id 666871;
 Fri, 12 Jan 2024 12:59:32 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=PaFl=IW=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rOH8F-0008PC-TC
 for win-pv-devel@lists.xenproject.org; Fri, 12 Jan 2024 12:59:31 +0000
Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com
 [2a00:1450:4864:20::32d])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 6bb3cff2-b14a-11ee-98f0-6d05b1d4d9a1;
 Fri, 12 Jan 2024 13:59:30 +0100 (CET)
Received: by mail-wm1-x32d.google.com with SMTP id
 5b1f17b1804b1-40e586a62f7so33640805e9.2
 for <win-pv-devel@lists.xenproject.org>; Fri, 12 Jan 2024 04:59:28 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 u6-20020a05600c138600b0040d5a9d6b68sm9745334wmf.6.2024.01.12.04.59.26
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 12 Jan 2024 04:59:27 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 6bb3cff2-b14a-11ee-98f0-6d05b1d4d9a1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1705064367; x=1705669167; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=bsbWJmbSvBbpIM+29apPF1arOPIaBtiYZy1BN6OOdg4=;
        b=H4UvU867jvKk8ekGyI3tokpUp0wZYOEXCGRvtTrjpF1oqVCgktlFN0r3UasWyEToD/
         txFt7qrJtzZSmT4qW5R3eMv8i2tCOo4+GBTTeb13rDd4PhGH+XbW01bgJTBs4RegALft
         aNUzSE9OsLdmuuCng/G5u1niEPmC9/lGL5WVg=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1705064367; x=1705669167;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=bsbWJmbSvBbpIM+29apPF1arOPIaBtiYZy1BN6OOdg4=;
        b=WFAazJ5kAeRqNnRI7cOEcVi5hWnEv3KK5ZI68VL1jCI+iNA2tcwPMejAlaFRNq8z3D
         wjfQWHbXJGphUTApgtDUdMJomCOd5fQf4QlFRQcqSbI09zaxzImhRUzuh0k3fUt/F66V
         M7gUWnWRhiSJWXUrDzNLlr9RHr9UyrFb45GNKYRe1WWTjP0L1mnxy2HqG7W3nz3qGTqf
         lBUruN9bOfce0rhIg8HUvdlE3PkG6BI2sNfFnwT32YcdVEhi4oGeuxZeQlyje4t9KhT/
         XhIdCHqZPK9jrpRRf06gi08+dfSgh+1Rba/TVHExALedJwi/5rZQzEPnVmoe090luY0x
         Pw8Q==
X-Gm-Message-State: AOJu0YxdkIZyuLJAOkyKXl4gMgKSZr4rlAj0DccSA+A4vXbLbhObTBil
	0UDw6gWkjUJs2s2ops+9UHATQTbfzk48TBkS/6PgU0q50ZX3
X-Google-Smtp-Source: AGHT+IEW2nUyotWsQvCiaUNbKaSNnvFPjMG4rbRJzZFmiv77D/K4igUEoHM8qqUAW+UeghakpocWGQ==
X-Received: by 2002:a05:600c:6a06:b0:40e:66ac:dfd7 with SMTP id jj6-20020a05600c6a0600b0040e66acdfd7mr498816wmb.87.1705064367538;
        Fri, 12 Jan 2024 04:59:27 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 1/2] Add ETW support
Date: Fri, 12 Jan 2024 12:59:13 +0000
Message-ID: <20240112125915.1229-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Defines ETW schema with EtwEnter and EtwExit events, which can be used to track
code-paths and produce flamegraphs of executions.
Only uses EtwEnter and EtwExit in the driver.c file of XenBus, but more events
will be added in subsequent patches.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/common/dbg_print.h       | 60 +++++++++++++++++++++++++++++++++++
 src/xenbus/driver.c          | 11 +++++++
 src/xenbus/xenbus_etw.xml    | 61 ++++++++++++++++++++++++++++++++++++
 vs2019/xenbus/xenbus.vcxproj | 13 +++++++-
 vs2022/xenbus/xenbus.vcxproj | 13 +++++++-
 5 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 src/xenbus/xenbus_etw.xml

diff --git a/src/common/dbg_print.h b/src/common/dbg_print.h
index a0bd727..98c22cf 100644
--- a/src/common/dbg_print.h
+++ b/src/common/dbg_print.h
@@ -42,6 +42,66 @@
 
 #pragma warning(disable:4127)   // conditional expression is constant
 
+#ifdef ETW_HEADER
+#include ETW_HEADER
+
+static __inline VOID
+__EtwEnter(
+    IN  const CHAR      *Module,
+    IN  const CHAR      *Function,
+    IN  ULONG           Line
+    )
+{
+    CHAR                _Module[16];
+    CHAR                _Function[32];
+
+    if (!EventEnabledEvtEnter())
+        return;
+
+    RtlZeroMemory(_Module, sizeof(_Module));
+    RtlZeroMemory(_Function, sizeof(_Function));
+
+    strncpy(_Module, Module, ARRAYSIZE(_Module) -1);
+    strncpy(_Function, Function, ARRAYSIZE(_Function) - 1);
+
+    EventWriteEvtEnter(NULL, _Module, _Function, Line);
+}
+
+static __inline VOID
+__EtwExit(
+    IN  const CHAR      *Module,
+    IN  const CHAR      *Function,
+    IN  ULONG           Line,
+    IN  NTSTATUS        Status
+    )
+{
+    CHAR                _Module[16];
+    CHAR                _Function[32];
+
+    if (!EventEnabledEvtExit())
+        return;
+
+    RtlZeroMemory(_Module, sizeof(_Module));
+    RtlZeroMemory(_Function, sizeof(_Function));
+
+    strncpy(_Module, Module, sizeof(_Module));
+    strncpy(_Function, Function, sizeof(_Function));
+
+    EventWriteEvtExit(NULL, _Module, _Function, Line, (ULONG)Status);
+}
+
+#define EtwEnter()          __EtwEnter(__MODULE__, __FUNCTION__, __LINE__)
+#define EtwExit()           __EtwExit(__MODULE__, __FUNCTION__, __LINE__, STATUS_SUCCESS)
+#define EtwExit2(status)    __EtwExit(__MODULE__, __FUNCTION__, __LINE__, status)
+
+#else
+
+#define EtwEnter()          (VOID)0
+#define EtwExit()           (VOID)0
+#define EtwExit2(status)    (VOID)status
+
+#endif
+
 static __inline VOID
 __Error(
     IN  const CHAR  *Prefix,
diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c
index 522acef..4443559 100644
--- a/src/xenbus/driver.c
+++ b/src/xenbus/driver.c
@@ -708,6 +708,8 @@ DriverUnload(
 
     __DriverSetDriverObject(NULL);
 
+    EventUnregisterXenBus_Driver();
+
     ASSERT(IsZeroMemory(&Driver, sizeof (XENBUS_DRIVER)));
 
     Trace("<====\n");
@@ -726,6 +728,7 @@ DriverAddDevice(
 
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
 
+    EtwEnter();
     Trace("====>\n");
 
     __DriverAcquireMutex();
@@ -737,12 +740,14 @@ DriverAddDevice(
     __DriverReleaseMutex();
 
     Trace("<====\n");
+    EtwExit();
 
     return STATUS_SUCCESS;
 
 fail1:
     __DriverReleaseMutex();
 
+    EtwExit2(status);
     return status;
 }
 
@@ -757,6 +762,8 @@ DriverDispatch(
     PXENBUS_DX          Dx;
     NTSTATUS            status;
 
+    EtwEnter();
+
     Dx = (PXENBUS_DX)DeviceObject->DeviceExtension;
     ASSERT3P(Dx->DeviceObject, ==, DeviceObject);
 
@@ -800,6 +807,7 @@ DriverDispatch(
     }
 
 done:
+    EtwExit2(status);
     return status;
 }
 
@@ -819,6 +827,7 @@ DriverEntry(
 
     ASSERT3P(__DriverGetDriverObject(), ==, NULL);
 
+    EventRegisterXenBus_Driver();
     ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
     WdmlibProcgrpInitialize();
 
@@ -915,6 +924,8 @@ fail1:
 
     __DriverSetDriverObject(NULL);
 
+    EventUnregisterXenBus_Driver();
+
     ASSERT(IsZeroMemory(&Driver, sizeof (XENBUS_DRIVER)));
 
     return status;
diff --git a/src/xenbus/xenbus_etw.xml b/src/xenbus/xenbus_etw.xml
new file mode 100644
index 0000000..c73dfe6
--- /dev/null
+++ b/src/xenbus/xenbus_etw.xml
@@ -0,0 +1,61 @@
+<?xml version='1.0' encoding='utf-8' standalone='yes'?>
+<instrumentationManifest
+    xmlns="http://schemas.microsoft.com/win/2004/08/events"
+    xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" >
+  <instrumentation>
+    <events>
+      <provider
+          guid="{e580595b-a8a6-41b7-a9c1-1954d2138ffc}"
+          messageFileName="%SystemDrive%\windows\system32\drivers\xenbus.sys"
+          name="XenBus_Driver"
+          resourceFileName="%SystemDrive%\windows\system32\drivers\xenbus.sys"
+          symbol="DriverControlGuid" >
+        <channels>
+          <channel chid="XENBUS" name="XenBus" type="Analytic" enabled="true" />
+        </channels>
+        <templates>
+          <template tid="tid_enter">
+            <data name="Module" inType="win:Int8" count="16" outType="xs:string" />     <!-- 16 chars -->
+            <data name="Function" inType="win:Int8" count="32" outType="xs:string" />   <!-- 32 chars -->
+            <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" />           <!-- line number -->
+          </template>
+          <template tid="tid_exit">
+            <data name="Module" inType="win:Int8" count="16" outType="xs:string" />     <!-- 16 chars -->
+            <data name="Function" inType="win:Int8" count="32" outType="xs:string" />   <!-- 32 chars -->
+            <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" />           <!-- line number -->
+            <data name="Status" inType="win:UInt32" outType="xs:unsignedInt" />         <!-- NTSTATUS -->
+          </template>
+        </templates>
+        <events>
+          <event
+            channel="XENBUS"
+            level="win:Informational"
+            message="$(string.EventTraceInfo.Enter)"
+            opcode="win:Info"
+            symbol="EvtEnter"
+            template="tid_enter"
+            value="10" />
+          <event
+            channel="XENBUS"
+            level="win:Informational"
+            message="$(string.EventTraceInfo.Exit)"
+            opcode="win:Info"
+            symbol="EvtExit"
+            template="tid_exit"
+            value="11" />
+        </events>
+      </provider>
+    </events>
+  </instrumentation>
+  <localization xmlns="http://schemas.microsoft.com/win/2004/08/events">
+    <resources culture="en-US">
+      <stringTable>
+        <string id="EventTraceInfo.Enter" value="[Enter]" />
+        <string id="EventTraceInfo.Exit"  value="[Exit ]" />
+      </stringTable>
+    </resources>
+  </localization>
+</instrumentationManifest>
diff --git a/vs2019/xenbus/xenbus.vcxproj b/vs2019/xenbus/xenbus.vcxproj
index aa88980..e191527 100644
--- a/vs2019/xenbus/xenbus.vcxproj
+++ b/vs2019/xenbus/xenbus.vcxproj
@@ -20,7 +20,7 @@
   <ItemDefinitionGroup>
     <ClCompile>
       <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
-      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenbus_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;..\..\src\common;</AdditionalIncludeDirectories>
       <WarningLevel>EnableAllWarnings</WarningLevel>
@@ -38,6 +38,13 @@
       <MapExports>true</MapExports>
       <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
+    <MessageCompile>
+      <HeaderFilePath>..\..\include</HeaderFilePath>
+      <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName>
+      <RCFilePath>..\..\src\xenbus</RCFilePath>
+      <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros>
+      <UseBaseNameOfInput>true</UseBaseNameOfInput>
+    </MessageCompile>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
     </DriverSign>
@@ -68,6 +75,7 @@
   <ItemGroup>
     <FilesToPackage Include="$(TargetPath)" />
     <FilesToPackage Include="$(OutDir)$(TargetName).pdb" />
+    <FilesToPackage Include="..\..\src\xenbus\xenbus_etw.xml" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\common\registry.c" />
@@ -97,5 +105,8 @@
   <ItemGroup>
     <ResourceCompile Include="..\..\src\xenbus\xenbus.rc" />
   </ItemGroup>
+  <ItemGroup>
+    <MessageCompile Include="..\..\src\xenbus\xenbus_etw.xml" />
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 </Project>
diff --git a/vs2022/xenbus/xenbus.vcxproj b/vs2022/xenbus/xenbus.vcxproj
index ce0526f..1322d15 100644
--- a/vs2022/xenbus/xenbus.vcxproj
+++ b/vs2022/xenbus/xenbus.vcxproj
@@ -20,7 +20,7 @@
   <ItemDefinitionGroup>
     <ClCompile>
       <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
-      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenbus_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;..\..\src\common;</AdditionalIncludeDirectories>
       <WarningLevel>EnableAllWarnings</WarningLevel>
@@ -38,6 +38,13 @@
       <MapExports>true</MapExports>
       <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
+    <MessageCompile>
+      <HeaderFilePath>..\..\include</HeaderFilePath>
+      <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName>
+      <RCFilePath>..\..\src\xenbus</RCFilePath>
+      <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros>
+      <UseBaseNameOfInput>true</UseBaseNameOfInput>
+    </MessageCompile>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
     </DriverSign>
@@ -60,6 +67,7 @@
   <ItemGroup>
     <FilesToPackage Include="$(TargetPath)" />
     <FilesToPackage Include="$(OutDir)$(TargetName).pdb" />
+    <FilesToPackage Include="..\..\src\xenbus\xenbus_etw.xml" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\common\registry.c" />
@@ -89,5 +97,8 @@
   <ItemGroup>
     <ResourceCompile Include="..\..\src\xenbus\xenbus.rc" />
   </ItemGroup>
+  <ItemGroup>
+    <MessageCompile Include="..\..\src\xenbus\xenbus_etw.xml" />
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 </Project>
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Fri Jan 12 12:59:37 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 12 Jan 2024 12:59:37 +0000
Received: from list by lists.xenproject.org with outflank-mailman.666872.1037806 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rOH8L-0008RH-Cb; Fri, 12 Jan 2024 12:59:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 666872.1037806; Fri, 12 Jan 2024 12:59:37 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rOH8L-0008RA-9P; Fri, 12 Jan 2024 12:59:37 +0000
Received: by outflank-mailman (input) for mailman id 666872;
 Fri, 12 Jan 2024 12:59:35 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=PaFl=IW=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rOH8J-0008Qt-JC
 for win-pv-devel@lists.xenproject.org; Fri, 12 Jan 2024 12:59:35 +0000
Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com
 [2a00:1450:4864:20::334])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id 6c88da90-b14a-11ee-9b0f-b553b5be7939;
 Fri, 12 Jan 2024 13:59:31 +0100 (CET)
Received: by mail-wm1-x334.google.com with SMTP id
 5b1f17b1804b1-40e586a62f7so33641055e9.2
 for <win-pv-devel@lists.xenproject.org>; Fri, 12 Jan 2024 04:59:30 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 u6-20020a05600c138600b0040d5a9d6b68sm9745334wmf.6.2024.01.12.04.59.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 12 Jan 2024 04:59:28 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 6c88da90-b14a-11ee-9b0f-b553b5be7939
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1705064369; x=1705669169; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=9I2VeD1qM6+jY7/OJGQxALaqDHMsGq2E4/CENfYEtv8=;
        b=SadDQwm4MIxJW4qiM1foiCcqg9kxJeX7pz6j/tjaG4YdJZPgiXVOqfRS3meembwIQV
         eYzvams9da+zGIxyES72rc4okXolIldGPiTsVodH1qj2XkyOoFfvEsgthKzdB1LjBFrN
         jdGRix8agO4+DW8tTULAVdOK7z1sTcM1RgUIA=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1705064369; x=1705669169;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=9I2VeD1qM6+jY7/OJGQxALaqDHMsGq2E4/CENfYEtv8=;
        b=CXt/LtowILbm15qUr4WgImWYdW5WG5kJPAgIsHWaa9xops6SG+4Nnj8+yZUkqLpUQ2
         LrE6I9rz1O4UTvk7a6rdE5Ka5qi+T0fbHZN5YvHhghdi8p0OS9yagquzTdnV8SHAm2aR
         eD2uOw5lJYFkKKm6kP31WQ8R24svVK5txr3/q2/NjYs5oGvSoHyrOVtWDkc3l3gf09Ve
         ozFHCj3LOATQ+mQCzqMxuNhXIbRrrVLBmYdtwiTw8rijxuXy+szlPj/HdA0Va1IMDt09
         nfj+AN5Xy+e8jLv8ubE9MxVQDdmNXwxUxI/BPlU35v7k90wP08gr6ZAuAzOEW6txwYnW
         fbhQ==
X-Gm-Message-State: AOJu0Yz+FiVy2I6sECDWsO5l9kr/QHyV+zhWZb4aj4DDdJVu5ixDseR+
	wo7OowCNUeUBo4gXr0SAN5fE6M3mZfqRz+nTN1pKd8MBx6EG
X-Google-Smtp-Source: AGHT+IG8pRt38BK7z8r+8WTWL2IXDelFtb9weO9E5+n9C2UzsYdBKem6OyttngituOGXtdyPC3Zdmw==
X-Received: by 2002:a05:600c:a019:b0:40e:62aa:fa7b with SMTP id jg25-20020a05600ca01900b0040e62aafa7bmr819541wmb.111.1705064368949;
        Fri, 12 Jan 2024 04:59:28 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [RFC PATCH 2/2] Add ETW Enter/Exit calls on most interface functions
Date: Fri, 12 Jan 2024 12:59:14 +0000
Message-ID: <20240112125915.1229-2-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240112125915.1229-1-owen.smith@cloud.com>
References: <20240112125915.1229-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Add coarse grained ETW tracing, to trace interface method timings

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenbus/balloon.c     |  2 ++
 src/xenbus/cache.c       | 11 +++++++++++
 src/xenbus/gnttab.c      | 13 +++++++++++++
 src/xenbus/range_set.c   | 11 ++++++++++-
 src/xenbus/shared_info.c |  2 ++
 src/xenbus/store.c       | 32 +++++++++++++++++++++++++++++++-
 6 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/src/xenbus/balloon.c b/src/xenbus/balloon.c
index 8d7e2c2..d1b239c 100644
--- a/src/xenbus/balloon.c
+++ b/src/xenbus/balloon.c
@@ -788,6 +788,7 @@ BalloonAdjust(
     PXENBUS_BALLOON_CONTEXT Context = Interface->Context;
     NTSTATUS                status;
 
+    EtwEnter();
     ASSERT3U(KeGetCurrentIrql(), <, DISPATCH_LEVEL);
 
     Info("====> (%llu page(s))\n", Context->Size);
@@ -807,6 +808,7 @@ BalloonAdjust(
          Context->Size,
          __BalloonStatus(status));
 
+    EtwExit2(status);
     return status;
 }
 
diff --git a/src/xenbus/cache.c b/src/xenbus/cache.c
index 6229aed..11d857a 100644
--- a/src/xenbus/cache.c
+++ b/src/xenbus/cache.c
@@ -600,6 +600,8 @@ CacheGet(
     PVOID                   Object;
     LONG                    ObjectCount;
 
+    EtwEnter();
+
     UNREFERENCED_PARAMETER(Interface);
 
     ASSERT(Cache != NULL);
@@ -661,6 +663,7 @@ done:
 
     KeLowerIrql(Irql);
 
+    EtwExit();
     return Object;
 }
 
@@ -678,6 +681,8 @@ CachePut(
     PXENBUS_CACHE_SLAB      Slab;
     NTSTATUS                status;
 
+    EtwEnter();
+
     UNREFERENCED_PARAMETER(Interface);
 
     ASSERT(Cache != NULL);
@@ -720,6 +725,8 @@ done:
     InterlockedDecrement(&Cache->CurrentObjects);
 
     KeLowerIrql(Irql);
+
+    EtwExit();
 }
 
 static NTSTATUS
@@ -731,6 +738,7 @@ CacheFill(
     KIRQL               Irql;
     NTSTATUS            status;
 
+    EtwEnter();
     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
     __CacheAcquireLock(Cache);
 
@@ -746,6 +754,7 @@ CacheFill(
     __CacheReleaseLock(Cache);
     KeLowerIrql(Irql);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -758,6 +767,7 @@ CacheSpill(
     KIRQL               Irql;
     PLIST_ENTRY         ListEntry;
 
+    EtwEnter();
     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
     __CacheAcquireLock(Cache);
 
@@ -792,6 +802,7 @@ CacheSpill(
 done:
     __CacheReleaseLock(Cache);
     KeLowerIrql(Irql);
+    EtwExit();
 }
 
 static FORCEINLINE VOID
diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 4f6617b..5ef7cc8 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -511,6 +511,7 @@ GnttabPermitForeignAccess(
     ULONG                       Index;
     NTSTATUS                    status;
 
+    EtwEnter();
     *Entry = XENBUS_CACHE(Get,
                           &Context->CacheInterface,
                           Cache->Cache,
@@ -538,11 +539,13 @@ GnttabPermitForeignAccess(
     Frame->Entry[Index].flags |= GTF_permit_access;
     KeMemoryBarrier();
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -561,6 +564,8 @@ GnttabRevokeForeignAccess(
     ULONG                       Attempt;
     NTSTATUS                    status;
 
+    EtwEnter();
+
     ASSERT3U(Entry->Magic, ==, XENBUS_GNTTAB_ENTRY_MAGIC);
     ASSERT3U(Entry->Reference, >=, XENBUS_GNTTAB_RESERVED_ENTRY_COUNT);
     ASSERT3U(Entry->Reference, <, (Context->FrameIndex + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME);
@@ -599,11 +604,13 @@ GnttabRevokeForeignAccess(
                  Entry,
                  Locked);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -671,6 +678,7 @@ GnttabMapForeignPages(
     PXENBUS_GNTTAB_MAP_ENTRY    MapEntry;
     NTSTATUS                    status;
 
+    EtwEnter();
     Mdl = FdoHoleAllocate(Context->Fdo, NumberPages);
 
     status = STATUS_NO_MEMORY;
@@ -708,6 +716,7 @@ GnttabMapForeignPages(
     if (!NT_SUCCESS(status))
         goto fail4;
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail4:
@@ -734,6 +743,7 @@ fail2:
 fail1:
     Error("fail1: (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -751,6 +761,7 @@ GnttabUnmapForeignPages(
     PMDL                        Mdl;
     NTSTATUS                    status;
 
+    EtwEnter();
     status = HashTableLookup(Context->MapTable,
                              (ULONG_PTR)Address.QuadPart,
                              (PULONG_PTR)&MapEntry);
@@ -779,6 +790,7 @@ GnttabUnmapForeignPages(
 
     FdoHoleFree(Context->Fdo, Mdl);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail2:
@@ -787,6 +799,7 @@ fail2:
 fail1:
     Error("fail1: (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
diff --git a/src/xenbus/range_set.c b/src/xenbus/range_set.c
index 08af0db..dd7277c 100644
--- a/src/xenbus/range_set.c
+++ b/src/xenbus/range_set.c
@@ -195,6 +195,7 @@ RangeSetPop(
 
     UNREFERENCED_PARAMETER(Interface);
 
+    EtwEnter();
     status = STATUS_INVALID_PARAMETER;
 
     if (Count == 0)
@@ -234,6 +235,7 @@ found:
 
     KeReleaseSpinLock(&RangeSet->Lock, Irql);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail3:
@@ -247,6 +249,7 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -337,6 +340,7 @@ RangeSetGet(
 
     UNREFERENCED_PARAMETER(Interface);
 
+    EtwEnter();
     status = STATUS_INVALID_PARAMETER;
 
     if (Count == 0)
@@ -407,6 +411,7 @@ done:
 
     KeReleaseSpinLock(&RangeSet->Lock, Irql);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail2:
@@ -417,7 +422,8 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
-    return status;    
+    EtwExit2(status);
+    return status;
 }
 
 static NTSTATUS
@@ -519,6 +525,7 @@ RangeSetPut(
 
     UNREFERENCED_PARAMETER(Interface);
 
+    EtwEnter();
     status = STATUS_INVALID_PARAMETER;
 
     if (Count == 0)
@@ -552,6 +559,7 @@ RangeSetPut(
 
     KeReleaseSpinLock(&RangeSet->Lock, Irql);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail2:
@@ -562,6 +570,7 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c
index dc456eb..10ac7a6 100644
--- a/src/xenbus/shared_info.c
+++ b/src/xenbus/shared_info.c
@@ -362,6 +362,7 @@ SharedInfoGetTime(
     TIME_FIELDS                     TimeFields;
     KIRQL                           Irql;
 
+    EtwEnter();
     // Make sure we don't suspend
     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
 
@@ -439,6 +440,7 @@ SharedInfoGetTime(
     if ( Local )
         *Local = !SystemRealTimeIsUniversal();
 
+    EtwExit();
 #undef NS_PER_S
 }
 
diff --git a/src/xenbus/store.c b/src/xenbus/store.c
index 02d3cc2..714049c 100644
--- a/src/xenbus/store.c
+++ b/src/xenbus/store.c
@@ -1104,7 +1104,8 @@ StoreRead(
     PXENBUS_STORE_BUFFER            Buffer;
     NTSTATUS                        status;
 
-    (VOID) RtlCaptureStackBackTrace(1, 1, &Caller, NULL);    
+    EtwEnter();
+    (VOID) RtlCaptureStackBackTrace(1, 1, &Caller, NULL);
 
     RtlZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST));
 
@@ -1156,6 +1157,7 @@ StoreRead(
 
     *Value = Buffer->Data;
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail4:
@@ -1166,6 +1168,7 @@ fail2:
 fail1:
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1183,6 +1186,7 @@ StoreWrite(
     PXENBUS_STORE_RESPONSE          Response;
     NTSTATUS                        status;
 
+    EtwEnter();
     RtlZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST));
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
@@ -1227,6 +1231,7 @@ StoreWrite(
     StoreFreeResponse(Response);
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail3:
@@ -1236,6 +1241,7 @@ fail2:
 fail1:
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1311,6 +1317,8 @@ StorePrintf(
     va_list                         Arguments;
     NTSTATUS                        status;
 
+    EtwEnter();
+
     va_start(Arguments, Format);
     status = StoreVPrintf(Interface,
                             Transaction,
@@ -1320,6 +1328,7 @@ StorePrintf(
                             Arguments);
     va_end(Arguments);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1337,6 +1346,7 @@ StoreRemove(
     PXENBUS_STORE_RESPONSE          Response;
     NTSTATUS                        status;
 
+    EtwEnter();
     RtlZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST));
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
@@ -1379,6 +1389,7 @@ StoreRemove(
     StoreFreeResponse(Response);
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail3:
@@ -1388,6 +1399,7 @@ fail2:
 fail1:
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1408,6 +1420,7 @@ StoreDirectory(
     PXENBUS_STORE_BUFFER            Buffer;
     NTSTATUS                        status;
 
+    EtwEnter();
     (VOID) RtlCaptureStackBackTrace(1, 1, &Caller, NULL);    
 
     RtlZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST));
@@ -1464,6 +1477,7 @@ StoreDirectory(
 
     *Value = Buffer->Data;
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail5:
@@ -1477,6 +1491,7 @@ fail2:
 fail1:
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1492,6 +1507,7 @@ StoreTransactionStart(
     KIRQL                           Irql;
     NTSTATUS                        status;
 
+    EtwEnter();
     *Transaction = __StoreAllocate(sizeof (XENBUS_STORE_TRANSACTION));
 
     status = STATUS_NO_MEMORY;
@@ -1539,6 +1555,7 @@ StoreTransactionStart(
     InsertTailList(&Context->TransactionList, &(*Transaction)->ListEntry);
     KeReleaseSpinLock(&Context->Lock, Irql);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail3:
@@ -1559,6 +1576,7 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1575,6 +1593,7 @@ StoreTransactionEnd(
     KIRQL                           Irql;
     NTSTATUS                        status;
 
+    EtwEnter();
     ASSERT3U(Transaction->Magic, ==, STORE_TRANSACTION_MAGIC);
 
     RtlZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST));
@@ -1626,6 +1645,7 @@ done:
     ASSERT(IsZeroMemory(Transaction, sizeof (XENBUS_STORE_TRANSACTION)));
     __StoreFree(Transaction);
 
+    EtwExit2(status);
     return status;
 
 fail2:
@@ -1636,6 +1656,7 @@ fail2:
 fail1:
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1657,6 +1678,7 @@ StoreWatchAdd(
     KIRQL                       Irql;
     NTSTATUS                    status;
 
+    EtwEnter();
     *Watch = __StoreAllocate(sizeof (XENBUS_STORE_WATCH));
 
     status = STATUS_NO_MEMORY;
@@ -1730,6 +1752,7 @@ StoreWatchAdd(
     StoreFreeResponse(Response);
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail4:
@@ -1767,6 +1790,7 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -1784,6 +1808,7 @@ StoreWatchRemove(
     KIRQL                       Irql;
     NTSTATUS                    status;
 
+    EtwEnter();
     ASSERT3U(Watch->Magic, ==, STORE_WATCH_MAGIC);
 
     Path = Watch->Path;
@@ -1851,6 +1876,7 @@ done:
     ASSERT(IsZeroMemory(Watch, sizeof (XENBUS_STORE_WATCH)));
     __StoreFree(Watch);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail2:
@@ -1863,6 +1889,7 @@ fail1:
 
     ASSERT(IsZeroMemory(&Request, sizeof (XENBUS_STORE_REQUEST)));
 
+    EtwExit2(status);
     return status;
 }
 
@@ -2041,6 +2068,7 @@ StorePermissionsSet(
     PCHAR                           PermissionString;
     PCHAR                           Segment;
 
+    EtwEnter();
     PermissionString = __StoreAllocate(XENSTORE_PAYLOAD_MAX);
 
     status = STATUS_NO_MEMORY;
@@ -2110,6 +2138,7 @@ StorePermissionsSet(
     __StoreFree(Path);
     __StoreFree(PermissionString);
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail6:
@@ -2136,6 +2165,7 @@ fail2:
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 24 14:07:13 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 24 Jan 2024 14:07:13 +0000
Received: from list by lists.xenproject.org with outflank-mailman.671008.1044129 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rSduJ-0004r8-4g; Wed, 24 Jan 2024 14:07:11 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 671008.1044129; Wed, 24 Jan 2024 14:07:11 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rSduJ-0004r1-1q; Wed, 24 Jan 2024 14:07:11 +0000
Received: by outflank-mailman (input) for mailman id 671008;
 Wed, 24 Jan 2024 14:07:09 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=/O24=JC=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rSduH-0004qv-TY
 for win-pv-devel@lists.xenproject.org; Wed, 24 Jan 2024 14:07:09 +0000
Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com
 [2a00:1450:4864:20::530])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id dc279983-bac1-11ee-98f5-6d05b1d4d9a1;
 Wed, 24 Jan 2024 15:07:08 +0100 (CET)
Received: by mail-ed1-x530.google.com with SMTP id
 4fb4d7f45d1cf-55a9008c185so7059472a12.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 24 Jan 2024 06:07:08 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 v13-20020aa7dbcd000000b0055b0ea6bc8bsm5003251edt.56.2024.01.24.06.07.06
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 24 Jan 2024 06:07:06 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: dc279983-bac1-11ee-98f5-6d05b1d4d9a1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706105227; x=1706710027; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=IdihdKutwpt/RgjkAKoiiNmKLAkgkaYuv5dK+SPIPlw=;
        b=edWFmN+psVGcgv8WPZUejF9tWDmiukYTPrdQuVIJlAWmYgOyoHTJckiy3M9BGmtCn5
         bOi1XD2LG4eMXyVSFJLOqg05X6+Z3ymic0KUvyqdQdT4k1W3JMEagblIPoy1+Xy7cfy5
         Tw3p0/cZU/nsQ7I8wTVR8JLvyz4DD5Y7OzJlQ=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706105227; x=1706710027;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=IdihdKutwpt/RgjkAKoiiNmKLAkgkaYuv5dK+SPIPlw=;
        b=NNw2ElJ2Zw2pqtLMuJezF4jfXL19XIY6MewbXD6Yy+zjuhRA81JaqRMSr+mrTexa1p
         slqqToRCPpV532EeFz3FZcMFnBbiQQimGyUvNOdVmTw2ojKsSwDZecQNdlZm8kWTb8Ag
         O0PcZ1SHeo7qfOvmLyzhNbHYYuydSJ8lftYPqp4V/GP7SHvh5Lu7BsodYkQ3DU5T1iqh
         9jDHK0lMM3Zw0ZoIDNgSAVcMr8+4kZ6bxns/lsB5/VAQ5d4M5AYj0oMQb6YT9P3A06H3
         y6Vy3I4VkL12YMNiLFJDddkVwIr8U4yJ8Pow2A57hBZ2Kh9hNVQEAK1S2aBOVXtlCU53
         g27w==
X-Gm-Message-State: AOJu0YxadIBJ6m5AsuKs5rwJpg9LOK6I3E6g0rdV/BMrX8V31M8mjYU0
	GwR91qbZQHOPM3uHWSuLrwgEULNhh+K6azjVpG/yhWFoSjWNmZyE22tQn8dpbc13ufCE3XZsQ0q
	tjw==
X-Google-Smtp-Source: AGHT+IGCUjuyu2rNwhgQllbbHh5G2Ie7GgxJb84nKAET4qntTUNgWTNZpW9ScWz0uhjMqOlIHPRkTA==
X-Received: by 2002:aa7:d04b:0:b0:559:b411:fa87 with SMTP id n11-20020aa7d04b000000b00559b411fa87mr1260977edo.20.1706105226941;
        Wed, 24 Jan 2024 06:07:06 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [PATCH] Bump binding to REV_09000004
Date: Wed, 24 Jan 2024 14:06:55 +0000
Message-ID: <20240124140655.1446-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Force XenNet to bind to the latest revision exposed by XenVif, so that
XenNet will only bind to XenVif that uses UNPLUG(IsRequested, ...) to
check that emulated devices are unplugged.
While this change is not required for functionality, the change does prevent
new versions of XenNet binding to older XenVif that, when restarting with
the emulated device present, do not fail PdoStartDevice with
STATUS_PNP_REBOOT_REQUIRED

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xennet.inf | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/xennet.inf b/src/xennet.inf
index b1d1105..dcf3e04 100644
--- a/src/xennet.inf
+++ b/src/xennet.inf
@@ -58,9 +58,9 @@ xennet.sys
 ; DisplayName		Section		DeviceID
 ; -----------		-------		--------
 
-%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_NET&REV_09000003
-%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@0001&DEV_NET&REV_09000003
-%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@0002&DEV_NET&REV_09000003
+%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_NET&REV_09000004
+%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@0001&DEV_NET&REV_09000004
+%XenNetName%		=XenNet_Inst,	XENVIF\VEN_@VENDOR_PREFIX@0002&DEV_NET&REV_09000004
 
 [XenNet_Inst] 
 Characteristics=0x84
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 08:12:57 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 08:12:57 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673796.1048264 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iK-0001wY-CY; Wed, 31 Jan 2024 08:12:56 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673796.1048264; Wed, 31 Jan 2024 08:12:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iK-0001wR-A3; Wed, 31 Jan 2024 08:12:56 +0000
Received: by outflank-mailman (input) for mailman id 673796;
 Wed, 31 Jan 2024 08:12:55 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV5iI-0001uW-VT
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 08:12:54 +0000
Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com
 [2a00:1450:4864:20::32e])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 880f0833-c010-11ee-8a43-1f161083a0e0;
 Wed, 31 Jan 2024 09:12:53 +0100 (CET)
Received: by mail-wm1-x32e.google.com with SMTP id
 5b1f17b1804b1-40ef3f351d2so2947155e9.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 00:12:53 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 o7-20020a05600c510700b0040e880ac6ecsm809162wms.35.2024.01.31.00.12.50
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 00:12:51 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 880f0833-c010-11ee-8a43-1f161083a0e0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706688772; x=1707293572; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=1xllRz3OXA63BXxlZ85q2UZQC5WUgoERCqV/YYDktuk=;
        b=gbC6QFzVOxxUjl29ywAF99ADn52ucdJjZUr/PwQzQw+ruoPOjNJ129utL2buD4Xhzc
         vJMqGvQfCTyIBZ/4a8/Z6s2p8eQvqw+3rPLRgEnwjN6b1hI8qCDXJkjfWjDcKHSJejou
         dDYq76jBUF+ylTVS2wr5mPB4ewUEY9iT8CxmU=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706688772; x=1707293572;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=1xllRz3OXA63BXxlZ85q2UZQC5WUgoERCqV/YYDktuk=;
        b=sp9HtxDRlWZ3oWx+dVi8UU0VJ3KNteeY/55lm+dA1Q2jtcJtcmOUgsJwCKD2mZUVGv
         ROAHznPkfP4NArSihf4aqNkiU3Kra+m9yobadV8LWgvEyH2cThm/Ae1SniJ5h+Diwc6A
         MwUfHWcxv/AkhGxGhjfztLrtouaDXLyXXxNGIU0DBNZZ9tclQrRYO+zoKI5KC9gXwgEK
         E1T6KGYNgUkXXVk4bG2E38gZxU/Tf9HNdbjZGwtdzRaP35k+t7R2mxNaY3Kx0BA5FoED
         cR9WoAF4ZD3ndiGwlF5jZzm0BTn8ISV3/tuoXAinvUF7ipNIo66PhumXVsM9ATsMb9O6
         uoAQ==
X-Gm-Message-State: AOJu0YzWumHSIbLgUQ9f7SpSGLBSGKpWifSeVgxnzfSBKgYnptx2idUe
	pvbxJOrJvsG/A/UmKjyEF6pNY6+1dEOsZ2JcXtp+NxWMPJA1TWHgnhywDazLbgdS6mMt7Q3rk6n
	cbQ==
X-Google-Smtp-Source: AGHT+IGQjYskxAI3kbJeTcKldH0OB0AU9qXDNc0HPXf9ExeHT7wLjQ/+Osu/N/xK9SbGfNuti9wXXw==
X-Received: by 2002:a05:600c:4e8f:b0:40e:70f5:a9a3 with SMTP id f15-20020a05600c4e8f00b0040e70f5a9a3mr715767wmq.5.1706688771917;
        Wed, 31 Jan 2024 00:12:51 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCVSGgJBgWkBlDEUMTDnAUOFVsfeq8uX2OSe/uTDB+GTgzg17WmGi0EXmjY+Vv1p+tDEA5j2Qo3Iqc3J0zS0bH8jB25KypKV+ng=
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Martin Harvey <martin.harvey@citrix.com>
Subject: [PATCH 3/4] XenAgent: Add retry for system shutdown/restart
Date: Wed, 31 Jan 2024 08:12:35 +0000
Message-ID: <20240131081236.1837-3-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240131081236.1837-1-owen.smith@cloud.com>
References: <20240131081236.1837-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

In some situations, InitiateSystemShutdownEx can fail and not trigger the
shutdown/restart correctly, leading to toolstack failing the shutdown/restart
operation. Add a simple retry mechanism to attempt to trigger the
shutdown/restart several times before giving up.

Suggested-by: Martin Harvey <martin.harvey@citrix.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenagent/service.cpp        | 13 ++++-
 src/xenagent/xenifacedevice.cpp | 86 +++++++++++++++++++++++++--------
 src/xenagent/xenifacedevice.h   |  5 ++
 3 files changed, 83 insertions(+), 21 deletions(-)

diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
index 535d761..ec32ecc 100644
--- a/src/xenagent/service.cpp
+++ b/src/xenagent/service.cpp
@@ -202,8 +202,13 @@ bool CXenAgent::ServiceMainLoop()
     HANDLE  events[] = { m_svc_stop,
                          m_xeniface.m_evt_shutdown,
                          m_xeniface.m_evt_suspend,
-                         m_xeniface.m_evt_slate_mode };
-    DWORD   wait = WaitForMultipleObjectsEx(4, events, FALSE, timeout, TRUE);
+                         m_xeniface.m_evt_slate_mode,
+                         m_xeniface.m_evt_shutdown_retry };
+    DWORD   wait = WaitForMultipleObjectsEx(sizeof(events) / sizeof(events[0]),
+                                            events,
+                                            FALSE,
+                                            timeout,
+                                            TRUE);
 
     switch (wait) {
     case WAIT_OBJECT_0:
@@ -229,6 +234,10 @@ bool CXenAgent::ServiceMainLoop()
 
         return true; // continue loop
     }
+    case WAIT_OBJECT_0+4:
+        m_xeniface.CheckShutdownRetry();
+        return true; // continue loop
+
     case WAIT_TIMEOUT:
         m_xeniface.CheckXenTime();
         __fallthrough;
diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp
index 9ed1aa7..223d6e9 100644
--- a/src/xenagent/xenifacedevice.cpp
+++ b/src/xenagent/xenifacedevice.cpp
@@ -40,6 +40,9 @@
 #include "xeniface_ioctls.h"
 #include "messages.h"
 
+#define DEFAULT_SHUTDOWN_RETRIES        5
+#define DEFAULT_SHUTDOWN_RETRY_TIME     60
+
 CXenIfaceDevice::CXenIfaceDevice(const wchar_t* path) : CDevice(path)
 {}
 
@@ -178,16 +181,20 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
     m_agent(agent),
     m_ctxt_suspend(NULL),
     m_ctxt_shutdown(NULL),
-    m_ctxt_slate_mode(NULL)
+    m_ctxt_slate_mode(NULL),
+    m_shutdown_reboot(false),
+    m_shutdown_retry(0)
 {
     m_evt_shutdown = CreateEvent(NULL, TRUE, FALSE, NULL);
     m_evt_suspend = CreateEvent(NULL, TRUE, FALSE, NULL);
     m_evt_slate_mode = CreateEvent(NULL, TRUE, FALSE, NULL);
+    m_evt_shutdown_retry = CreateWaitableTimer(NULL, FALSE, NULL);
     m_count = 0;
 }
 
 /*virtual*/ CXenIfaceDeviceList::~CXenIfaceDeviceList()
 {
+    CloseHandle(m_evt_shutdown_retry);
     CloseHandle(m_evt_slate_mode);
     CloseHandle(m_evt_suspend);
     CloseHandle(m_evt_shutdown);
@@ -301,29 +308,21 @@ bool CXenIfaceDeviceList::CheckShutdown()
         m_agent->EventLog(EVENT_XENUSER_POWEROFF);
         LogIfRebootPending();
 
-        AcquireShutdownPrivilege();
-#pragma warning(suppress:28159) /* Consider using a design alternative... Rearchitect to avoid Reboot */
-        if (!InitiateSystemShutdownEx(NULL, NULL, 0, TRUE, FALSE,
-                                      SHTDN_REASON_MAJOR_OTHER |
-                                      SHTDN_REASON_MINOR_ENVIRONMENT |
-                                      SHTDN_REASON_FLAG_PLANNED)) {
-            CXenAgent::Log("InitiateSystemShutdownEx failed %08x\n", GetLastError());
-        }
-        return true;
+        m_shutdown_retry = DEFAULT_SHUTDOWN_RETRIES;
+        m_shutdown_reboot = false;
+
+        RequestSystemShutdown();
+        return false; // keep service running, to retry shutdown if needed.
     } else if (type == "reboot") {
         device->StoreWrite("control/shutdown", "");
         m_agent->EventLog(EVENT_XENUSER_REBOOT);
         LogIfRebootPending();
 
-        AcquireShutdownPrivilege();
-#pragma warning(suppress:28159) /* Consider using a design alternative... Rearchitect to avoid Reboot */
-        if (!InitiateSystemShutdownEx(NULL, NULL, 0, TRUE, TRUE,
-                                      SHTDN_REASON_MAJOR_OTHER |
-                                      SHTDN_REASON_MINOR_ENVIRONMENT |
-                                      SHTDN_REASON_FLAG_PLANNED)) {
-            CXenAgent::Log("InitiateSystemShutdownEx failed %08x\n", GetLastError());
-        }
-        return true;
+        m_shutdown_retry = DEFAULT_SHUTDOWN_RETRIES;
+        m_shutdown_reboot = true;
+
+        RequestSystemShutdown();
+        return false; // keep service running, to retry shutdown if needed.
     } else if (type == "s4") {
         device->StoreWrite("control/shutdown", "");
         m_agent->EventLog(EVENT_XENUSER_S4);
@@ -347,6 +346,12 @@ bool CXenIfaceDeviceList::CheckShutdown()
     return false;
 }
 
+void CXenIfaceDeviceList::CheckShutdownRetry()
+{
+    CXenAgent::Log("Previous shutdown attempt failed, retrying...\n");
+    RequestSystemShutdown();
+}
+
 void CXenIfaceDeviceList::CheckXenTime()
 {
     CCritSec crit(&m_crit);
@@ -476,6 +481,49 @@ void CXenIfaceDeviceList::AdvertiseFeatures(CXenIfaceDevice* device, bool add)
     device->StoreWrite("control/feature-laptop-slate-mode", value);
 }
 
+#define TIME_US(_us)            ((_us) * 10ll)
+#define TIME_MS(_ms)            (TIME_US((_ms) * 1000ll))
+#define TIME_S(_s)              (TIME_MS((_s) * 1000ll))
+#define TIME_RELATIVE(_t)       (-(_t))
+
+void CXenIfaceDeviceList::RequestSystemShutdown()
+{
+    LARGE_INTEGER dueTime;
+
+    AcquireShutdownPrivilege();
+
+#pragma warning(suppress:28159) /* Consider using a design alternative... Rearchitect to avoid Reboot */
+    if (!InitiateSystemShutdownEx(NULL,
+                                  NULL,
+                                  0,
+                                  TRUE,
+                                  (m_shutdown_reboot ? TRUE : FALSE),
+                                  SHTDN_REASON_MAJOR_OTHER |
+                                  SHTDN_REASON_MINOR_ENVIRONMENT |
+                                  SHTDN_REASON_FLAG_PLANNED)) {
+        CXenAgent::Log("InitiateSystemShutdownEx failed %08x\n", GetLastError());
+    }
+
+    if (m_shutdown_retry == 0) {
+        CXenAgent::Log("System not shutdown after several tries, giving up.\n");
+        return;
+    }
+
+    m_shutdown_retry--;
+
+    // Negative (i.e. relative) number of minutes to wait in 100ns intervals.
+    dueTime.QuadPart = TIME_RELATIVE(TIME_S(DEFAULT_SHUTDOWN_RETRY_TIME));
+
+    if (!SetWaitableTimer(m_evt_shutdown_retry,
+                          &dueTime,
+                          0,
+                          NULL,
+                          NULL,
+                          FALSE)) {
+        CXenAgent::Log("SetWaitableTimer failed %08x\n", GetLastError());
+    }
+}
+
 void CXenIfaceDeviceList::AcquireShutdownPrivilege()
 {
     HANDLE          token;
diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h
index 29ac100..5a1aecf 100644
--- a/src/xenagent/xenifacedevice.h
+++ b/src/xenagent/xenifacedevice.h
@@ -81,9 +81,11 @@ public:
     HANDLE  m_evt_shutdown;
     HANDLE  m_evt_suspend;
     HANDLE  m_evt_slate_mode;
+    HANDLE  m_evt_shutdown_retry;
 
     void Log(const char* message);
     bool CheckShutdown();
+    void CheckShutdownRetry();
     void CheckXenTime();
     void CheckSuspend();
     bool CheckSlateMode(std::string& mode);
@@ -95,6 +97,7 @@ private:
     void StartSlateModeWatch(CXenIfaceDevice* device);
     void StopSlateModeWatch(CXenIfaceDevice* device);
     void AdvertiseFeatures(CXenIfaceDevice* device, bool add);
+    void RequestSystemShutdown();
     void AcquireShutdownPrivilege();
     void SetXenTime(CXenIfaceDevice* device);
 
@@ -104,6 +107,8 @@ private:
     void*       m_ctxt_suspend;
     void*       m_ctxt_shutdown;
     void*       m_ctxt_slate_mode;
+    bool        m_shutdown_reboot;
+    DWORD       m_shutdown_retry;
 };
 
 #endif
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 08:12:57 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 08:12:57 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673795.1048261 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iJ-0001uu-BG; Wed, 31 Jan 2024 08:12:55 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673795.1048261; Wed, 31 Jan 2024 08:12:55 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iJ-0001un-8i; Wed, 31 Jan 2024 08:12:55 +0000
Received: by outflank-mailman (input) for mailman id 673795;
 Wed, 31 Jan 2024 08:12:54 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV5iI-0001uW-Ai
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 08:12:54 +0000
Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com
 [2a00:1450:4864:20::131])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 868e8cfb-c010-11ee-8a43-1f161083a0e0;
 Wed, 31 Jan 2024 09:12:53 +0100 (CET)
Received: by mail-lf1-x131.google.com with SMTP id
 2adb3069b0e04-5111ef545bfso2302228e87.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 00:12:50 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 o7-20020a05600c510700b0040e880ac6ecsm809162wms.35.2024.01.31.00.12.48
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 00:12:49 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 868e8cfb-c010-11ee-8a43-1f161083a0e0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706688769; x=1707293569; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=3CdkNlkT9SWYZqJGZUF9vNEoQDDQniA3A/TIToEoG/4=;
        b=GzoPLDSTWahqB5u2USOkLEAx9K1J3pnWdozzwnUgkRB2obbNOB0699MHGGJAyhzdfB
         zH7TIuGnMS+GZHGUQEOfcnr2NUM7+7uMb2OmgkcNUWp5FQzyx0aycqD1k2BnEN4BPi3X
         HxMjCtrynZ5kafw7LyUp+4Knno6omwNyaSEBo=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706688769; x=1707293569;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=3CdkNlkT9SWYZqJGZUF9vNEoQDDQniA3A/TIToEoG/4=;
        b=J/cX9qOfnM6Vr0JlqIhrRNojEWW6G9HfRCXiRqYlue7rxKMO9XLYz+MTzuRG5U5btT
         W/c/8i4tg6a4tr7LFk3X8ZI8/hfKUchgi7GtaBSGSc20mDfq+W3HAeJpjI53Vixof0/y
         ufZVTGCHiqCebOd5qDYYsOXDcwhYY/rTpfMW4g9iROWZLdSC+TsosmlO9YvUN4awqY+4
         h/bN8dv55Qu+OISbrw8A7lh2XtKGo3xZWLttCC1Djg6f8VGuMv/6fJYFjMlQB5DbaDdc
         Cm3qeptjPGEKgzr++8Q5jDyk/RSFNkqylaL3+X78P5zVTaM9HtUvp/2W+sBZQI1FLX0l
         VsIw==
X-Gm-Message-State: AOJu0YxB04jokf5FRSQ8uEBFJ9yACVhYvKKCDFA4K1uM4MDQMZwiUnPT
	uscMwCMr8cQ41JHaO3TVPLDVvJ3bn7CnCgx3gSYwVMhjEteIKOfOv11mSjTqXuuW4VC2zJXKsc/
	VUw==
X-Google-Smtp-Source: AGHT+IFyoprFp8HCI19YMSg9u65igYrwoYTgI+llwtyEtSSmTiEXOvP5t/tskFzhdaUTjYJ4JAgR1w==
X-Received: by 2002:a05:6512:946:b0:511:1b86:f81f with SMTP id u6-20020a056512094600b005111b86f81fmr765863lft.8.1706688769399;
        Wed, 31 Jan 2024 00:12:49 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [PATCH 1/4] Fix Warning under SDV builds
Date: Wed, 31 Jan 2024 08:12:33 +0000
Message-ID: <20240131081236.1837-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

ASSERT In2 is not NULL, as its only set when the old IOCTL is converted to use
the new IOCTL's data structures.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xeniface/ioctl_gnttab.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/xeniface/ioctl_gnttab.c b/src/xeniface/ioctl_gnttab.c
index 8ab2099..5cf246c 100644
--- a/src/xeniface/ioctl_gnttab.c
+++ b/src/xeniface/ioctl_gnttab.c
@@ -393,6 +393,7 @@ IoctlGnttabPermitForeignAccess(
     In = NULL;
 
     if (ControlCode == IOCTL_XENIFACE_GNTTAB_PERMIT_FOREIGN_ACCESS) {
+        ASSERT3P(In1, !=, NULL);
         Context->UseRequestId = TRUE;
         Context->RequestId = In1->RequestId;
         __FreeCapturedBuffer(In1);
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 08:12:58 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 08:12:58 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673797.1048268 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iM-0001yv-E9; Wed, 31 Jan 2024 08:12:58 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673797.1048268; Wed, 31 Jan 2024 08:12:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iM-0001yo-BT; Wed, 31 Jan 2024 08:12:58 +0000
Received: by outflank-mailman (input) for mailman id 673797;
 Wed, 31 Jan 2024 08:12:56 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV5iK-0001wP-EH
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 08:12:56 +0000
Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com
 [2a00:1450:4864:20::32a])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id 875805eb-c010-11ee-98f5-efadbce2ee36;
 Wed, 31 Jan 2024 09:12:53 +0100 (CET)
Received: by mail-wm1-x32a.google.com with SMTP id
 5b1f17b1804b1-40e5afc18f5so50248595e9.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 00:12:52 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 o7-20020a05600c510700b0040e880ac6ecsm809162wms.35.2024.01.31.00.12.49
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 00:12:49 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 875805eb-c010-11ee-98f5-efadbce2ee36
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706688770; x=1707293570; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=WkhYWsbeYU0E4Ud0tC4XE3xegv83m4Y0vNGpGjdmlwE=;
        b=GAh2CCCs5i5tLYg1ahYK7qEasGnik95ET7fnkqhXtaqqZOMsl9Q0K33d8dikkHmU0o
         lTcoq9D6XP35Ooj0CmED47vjlpGBh/B18ybRXh2TAkmN8pqvhuzT5JZxqKD8mJDlPrP2
         Xash4h3Ucd26IkVexz7FbH/s+Bf5ztdfILr08=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706688770; x=1707293570;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=WkhYWsbeYU0E4Ud0tC4XE3xegv83m4Y0vNGpGjdmlwE=;
        b=Fpd4aSfz69UduRllz9e7OzkEwW8qN/NYzHRiQA2+IUDFO7pA44lRvCIGiUPzgQEw8c
         MZewWVIT0JJYjADLYkRl2QJtklWcUtHfAEf1i3OPuLE2LCfa8j6XrrLSnPoNRLCGNLsn
         lq9bkttETZ26eEvzaxoNZlH4PBT5bSZhV8q8ek7JxSBOpYgnm4ijlO3uVIb13/MzWfWU
         yb8FMqJxDDF2GcWKcgOOPRW1YABUdxNTcGapoecj6CfJvAIa/OAhO3PjSe0S09WRZaVn
         k0pKMtFwjKUIhXA07qfydqx08a28NfM72E8tt5l0iomatWMHe5+l65oPzu+Ecv8FysKo
         JBbQ==
X-Gm-Message-State: AOJu0Yyl1wlQTWfxma5q7h7NiX3bBoxVto4ZY/ht9tisoakkThHSpAob
	14S4WNqh0sfpuAftlfCQ0rgRCEwCZx5fZHB2mwiO9qEUVHLpcw6XrqdlvFiImuDd9o6mbUU6Ey4
	kkg==
X-Google-Smtp-Source: AGHT+IHExNNFPJmNLmJe9m5mngIb8cYOZW8xOGI5UTEWWCwVCJEcIWApxd/1WNneYCIM8Bh96wPxew==
X-Received: by 2002:a05:600c:4f94:b0:40e:5523:e6dd with SMTP id n20-20020a05600c4f9400b0040e5523e6ddmr604005wmq.30.1706688770658;
        Wed, 31 Jan 2024 00:12:50 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [PATCH 2/4] XenAgent: Advertise all features in 1 location
Date: Wed, 31 Jan 2024 08:12:34 +0000
Message-ID: <20240131081236.1837-2-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240131081236.1837-1-owen.smith@cloud.com>
References: <20240131081236.1837-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenagent/xenifacedevice.cpp | 32 +++++++++++++++++++++-----------
 src/xenagent/xenifacedevice.h   |  1 +
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp
index 69a584b..9ed1aa7 100644
--- a/src/xenagent/xenifacedevice.cpp
+++ b/src/xenagent/xenifacedevice.cpp
@@ -213,6 +213,8 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
     if (m_agent->ConvDevicePresent())
         StartSlateModeWatch(device);
 
+    AdvertiseFeatures(device, true);
+
     SetXenTime(device);
 }
 
@@ -228,6 +230,8 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
         device->SuspendDeregister(m_ctxt_suspend);
     m_ctxt_suspend = NULL;
 
+    AdvertiseFeatures(device, false);
+
     if (m_agent->ConvDevicePresent())
         StopSlateModeWatch(device);
 
@@ -242,6 +246,8 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
     if (dev != GetFirstDevice())
         return;
 
+    AdvertiseFeatures(device, false);
+
     if (m_agent->ConvDevicePresent())
         StopSlateModeWatch(device);
 
@@ -260,6 +266,8 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
 
     if (m_agent->ConvDevicePresent())
         StartSlateModeWatch(device);
+
+    AdvertiseFeatures(device, true);
 }
 
 void CXenIfaceDeviceList::Log(const char* message)
@@ -381,6 +389,8 @@ void CXenIfaceDeviceList::CheckSuspend()
     if (m_agent->ConvDevicePresent())
         StartSlateModeWatch(device);
 
+    AdvertiseFeatures(device, true);
+
     m_count = count;
 }
 
@@ -425,11 +435,6 @@ void CXenIfaceDeviceList::StartShutdownWatch(CXenIfaceDevice* device)
         return;
 
     device->StoreAddWatch("control/shutdown", m_evt_shutdown, &m_ctxt_shutdown);
-
-    device->StoreWrite("control/feature-poweroff", "1");
-    device->StoreWrite("control/feature-reboot", "1");
-    device->StoreWrite("control/feature-s3", "1");
-    device->StoreWrite("control/feature-s4", "1");
 }
 
 void CXenIfaceDeviceList::StopShutdownWatch(CXenIfaceDevice* device)
@@ -437,11 +442,6 @@ void CXenIfaceDeviceList::StopShutdownWatch(CXenIfaceDevice* device)
     if (!m_ctxt_shutdown)
         return;
 
-    device->StoreWrite("control/feature-poweroff", "");
-    device->StoreWrite("control/feature-reboot", "");
-    device->StoreWrite("control/feature-s3", "");
-    device->StoreWrite("control/feature-s4", "");
-
     device->StoreRemoveWatch(m_ctxt_shutdown);
     m_ctxt_shutdown = NULL;
 }
@@ -452,7 +452,6 @@ void CXenIfaceDeviceList::StartSlateModeWatch(CXenIfaceDevice* device)
         return;
 
     device->StoreAddWatch("control/laptop-slate-mode", m_evt_slate_mode, &m_ctxt_slate_mode);
-    device->StoreWrite("control/feature-laptop-slate-mode", "1");
 }
 
 void CXenIfaceDeviceList::StopSlateModeWatch(CXenIfaceDevice* device)
@@ -466,6 +465,17 @@ void CXenIfaceDeviceList::StopSlateModeWatch(CXenIfaceDevice* device)
     m_ctxt_slate_mode = NULL;
 }
 
+void CXenIfaceDeviceList::AdvertiseFeatures(CXenIfaceDevice* device, bool add)
+{
+    const char* value = add ? "1" : "";
+
+    device->StoreWrite("control/feature-poweroff", value);
+    device->StoreWrite("control/feature-reboot", value);
+    device->StoreWrite("control/feature-s3", value);
+    device->StoreWrite("control/feature-s4", value);
+    device->StoreWrite("control/feature-laptop-slate-mode", value);
+}
+
 void CXenIfaceDeviceList::AcquireShutdownPrivilege()
 {
     HANDLE          token;
diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h
index d85e469..29ac100 100644
--- a/src/xenagent/xenifacedevice.h
+++ b/src/xenagent/xenifacedevice.h
@@ -94,6 +94,7 @@ private:
     void StopShutdownWatch(CXenIfaceDevice* device);
     void StartSlateModeWatch(CXenIfaceDevice* device);
     void StopSlateModeWatch(CXenIfaceDevice* device);
+    void AdvertiseFeatures(CXenIfaceDevice* device, bool add);
     void AcquireShutdownPrivilege();
     void SetXenTime(CXenIfaceDevice* device);
 
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 08:12:58 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 08:12:58 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673798.1048272 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iM-0001zD-HJ; Wed, 31 Jan 2024 08:12:58 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673798.1048272; Wed, 31 Jan 2024 08:12:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV5iM-0001yz-DC; Wed, 31 Jan 2024 08:12:58 +0000
Received: by outflank-mailman (input) for mailman id 673798;
 Wed, 31 Jan 2024 08:12:57 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV5iL-0001wP-2d
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 08:12:57 +0000
Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com
 [2a00:1450:4864:20::334])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id 88f6a2be-c010-11ee-98f5-efadbce2ee36;
 Wed, 31 Jan 2024 09:12:54 +0100 (CET)
Received: by mail-wm1-x334.google.com with SMTP id
 5b1f17b1804b1-40ef64d8955so26523275e9.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 00:12:54 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 o7-20020a05600c510700b0040e880ac6ecsm809162wms.35.2024.01.31.00.12.52
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 00:12:52 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 88f6a2be-c010-11ee-98f5-efadbce2ee36
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706688774; x=1707293574; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=hgQVo48oB4R65tXMlnSHNS2E2k/71Mv5ermjDJ6kGWg=;
        b=km6E9BmlW1IMsJLcZ3OcsMh4KeOQFQAUMkBJplmwKO7rTgkxPigF5UvmN7WvEEVzY4
         r+BV+maVs/FZBIke/8p5gTtlWiS6SdxDPwRDtwIffbDffuDP2IfbvR0CGLiaRoFnpR5j
         7w0w44CTvg4Ilqw3Aldv4SUqRTIbC1tVugC6A=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706688774; x=1707293574;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=hgQVo48oB4R65tXMlnSHNS2E2k/71Mv5ermjDJ6kGWg=;
        b=Qd6HbZRDdybJq2bj1LdWXA/emNQXp+BIHyDYbNoWTbYCBAIz4ZcGlAD+g2whLCNPAz
         OiokcBbFGQAPHp8o2uCypFVU+bNZAq/kxsVO5ePb0wOnh3LX+YlxgGzD3Vc5hbbcu+vl
         a5WxZCUugrnyAmA/0GxKuCjgLYBY+GEIYVl2fKiZDghA6CdEb8fTwjsCad0Xurda/iFq
         hI/kparDgyMCh6XiGNzIkougoAE2Mb0W4Oi9yZXC9a8ftukWJbrYz1M3twBRNivUeJhb
         sa412qwKpUg5/RwaX9Z+s8263uEfDCmIAEc3vol/6XpTZw3MLmc7BzyInIGz9AOk8JGb
         R57g==
X-Gm-Message-State: AOJu0YwyJ1YCF4Ydbj5YI8CdFvsgSwMPqUd6cr6pxw3ZJ7x3CduTY4Wr
	iN01snUMy3jNf2e3UIbUpa5zVtQUtC9tu8MOoM4cfnNrCrCrtq1niAAvp8fLk6GDG6jvEWD96Ma
	6ug==
X-Google-Smtp-Source: AGHT+IH+5nBCMKKsSvF2wmmkzpxZsuiF05Er7okBLzE7LnH4T3UbpsFaGPrnq7/Nta/RtouIQz+xmA==
X-Received: by 2002:a05:600c:46c7:b0:40e:fbdd:23a4 with SMTP id q7-20020a05600c46c700b0040efbdd23a4mr649227wmo.26.1706688773787;
        Wed, 31 Jan 2024 00:12:53 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [PATCH 4/4] XenAgent: Add options to time sync code
Date: Wed, 31 Jan 2024 08:12:36 +0000
Message-ID: <20240131081236.1837-4-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240131081236.1837-1-owen.smith@cloud.com>
References: <20240131081236.1837-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Adds registry overrided to control how and when XenAgent will update the
system time.
"TimeSyncMode" is a bit-field with the following options:
  0b0000 = do not update system time
  0b0001 = update after resume from suspend
  0b0010 = update periodically
  0b0100 = update when xeniface device detected (including on service start)
  Default is 0b0001 (after resume).

"TimeSyncInterval" is the number of minutes between attempts to update
  system time. This only applies if "TimeSyncMode" contains 0b0010
  Default is 30 minutes.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenagent/service.cpp        |   6 +-
 src/xenagent/xenifacedevice.cpp | 144 +++++++++++++++++++++++++++++---
 src/xenagent/xenifacedevice.h   |  15 +++-
 3 files changed, 149 insertions(+), 16 deletions(-)

diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
index ec32ecc..3e30bb0 100644
--- a/src/xenagent/service.cpp
+++ b/src/xenagent/service.cpp
@@ -198,7 +198,7 @@ void CXenAgent::OnPowerEvent(DWORD evt, LPVOID data)
 
 bool CXenAgent::ServiceMainLoop()
 {
-    DWORD   timeout = 30 * 60 * 1000;
+    DWORD   timeout = 1 * 60 * 1000;
     HANDLE  events[] = { m_svc_stop,
                          m_xeniface.m_evt_shutdown,
                          m_xeniface.m_evt_suspend,
@@ -221,7 +221,7 @@ bool CXenAgent::ServiceMainLoop()
 
     case WAIT_OBJECT_0+2:
         ResetEvent(m_xeniface.m_evt_suspend);
-        m_xeniface.CheckXenTime();
+        m_xeniface.CheckXenTime(XENIFACE_TIMESYNC_RESUME);
         m_xeniface.CheckSuspend();
         return true; // continue loop
 
@@ -239,7 +239,7 @@ bool CXenAgent::ServiceMainLoop()
         return true; // continue loop
 
     case WAIT_TIMEOUT:
-        m_xeniface.CheckXenTime();
+        m_xeniface.CheckXenTime(XENIFACE_TIMESYNC_PERIODIC);
         __fallthrough;
     case WAIT_IO_COMPLETION:
         m_xeniface.CheckSuspend();
diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp
index 223d6e9..ffada25 100644
--- a/src/xenagent/xenifacedevice.cpp
+++ b/src/xenagent/xenifacedevice.cpp
@@ -43,6 +43,13 @@
 #define DEFAULT_SHUTDOWN_RETRIES        5
 #define DEFAULT_SHUTDOWN_RETRY_TIME     60
 
+#define XENAGENT_TIMESYNC_INTERVAL_DEFAULT  30
+
+#define XENAGENT_SERVICE_KEY            "SYSTEM\\CurrentControlSet\\Services\\xenagent"
+#define XENAGENT_TIMESYNC_MODE          "TimeSyncMode"
+#define XENAGENT_TIMESYNC_INTERVAL      "TimeSyncInterval"
+#define XENAGENT_TIMESYNC_LAST          "LastSyncFiletime"
+
 CXenIfaceDevice::CXenIfaceDevice(const wchar_t* path) : CDevice(path)
 {}
 
@@ -222,7 +229,7 @@ CXenIfaceDeviceList::CXenIfaceDeviceList(CXenAgent* agent) : CDeviceList(GUID_IN
 
     AdvertiseFeatures(device, true);
 
-    SetXenTime(device);
+    SetXenTime(device, XENIFACE_TIMESYNC_ADDED);
 }
 
 /*virtual*/ void CXenIfaceDeviceList::OnDeviceRemoved(CDevice* dev)
@@ -352,7 +359,7 @@ void CXenIfaceDeviceList::CheckShutdownRetry()
     RequestSystemShutdown();
 }
 
-void CXenIfaceDeviceList::CheckXenTime()
+void CXenIfaceDeviceList::CheckXenTime(DWORD reason)
 {
     CCritSec crit(&m_crit);
     CXenIfaceDevice* device = (CXenIfaceDevice*)GetFirstDevice();
@@ -360,7 +367,7 @@ void CXenIfaceDeviceList::CheckXenTime()
     if (device == NULL)
         return;
 
-    SetXenTime(device);
+    SetXenTime(device, reason);
 }
 
 void CXenIfaceDeviceList::CheckSuspend()
@@ -543,28 +550,30 @@ void CXenIfaceDeviceList::AcquireShutdownPrivilege()
     CloseHandle(token);
 }
 
-void CXenIfaceDeviceList::SetXenTime(CXenIfaceDevice* device)
+void CXenIfaceDeviceList::SetXenTime(CXenIfaceDevice* device, DWORD reason)
 {
-    bool local;
+    XENIFACE_SHARED_TIME now;
 
-    FILETIME now = { 0 };
-    if (!device->SharedInfoGetTime(&now, &local))
+    if (!device->SharedInfoGetTime(&now.time, &now.local))
+        return;
+
+    if (!CheckXenTimeEnabled(reason, &now))
         return;
 
     SYSTEMTIME cur = { 0 };
-    if (local)
+    if (now.local)
         GetLocalTime(&cur);
     else
         GetSystemTime(&cur);
 
     SYSTEMTIME sys = { 0 };
-    if (!FileTimeToSystemTime(&now, &sys))
+    if (!FileTimeToSystemTime(&now.time, &sys))
         return;
 
     if (memcmp(&cur, &sys, sizeof(SYSTEMTIME)) == 0)
         return;
 
-    CXenAgent::Log("RTC is in %s\n", local ? "local time" : "UTC");
+    CXenAgent::Log("RTC is in %s\n", now.local ? "local time" : "UTC");
     CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d\n",
                    cur.wYear, cur.wMonth, cur.wDay,
                    cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds);
@@ -572,8 +581,121 @@ void CXenIfaceDeviceList::SetXenTime(CXenIfaceDevice* device)
                    sys.wYear, sys.wMonth, sys.wDay,
                    sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
 
-    if (local)
+    if (now.local)
         SetLocalTime(&sys);
     else
         SetSystemTime(&sys);
 }
+
+static FORCEINLINE LONG64
+TimeDiff(FILETIME* old, FILETIME* now)
+{
+    ULONG64     ftOld;
+    ULONG64     ftNow;
+    LONG64      ftDiff;
+
+    ftOld = ((ULONG64)old->dwHighDateTime) << 32 |
+             (ULONG64)old->dwLowDateTime;
+
+    ftNow = ((ULONG64)now->dwHighDateTime) << 32 |
+             (ULONG64)now->dwLowDateTime;
+
+    ftDiff = (LONG64)(ftNow - ftOld);
+    //From 100NS to whole minutes.
+    ftDiff /= (10 * 1000 * 1000 * 60);
+    return ftDiff;
+}
+
+bool CXenIfaceDeviceList::CheckXenTimeEnabled(DWORD reason, PXENIFACE_SHARED_TIME now)
+{
+    HKEY                    key;
+    LONG                    lResult;
+    DWORD                   type;
+    DWORD                   size;
+    DWORD                   mode;
+    bool                    enabled;
+
+    enabled = (reason == XENIFACE_TIMESYNC_RESUME);
+
+    lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                           XENAGENT_SERVICE_KEY,
+                           0,
+                           KEY_READ,
+                           &key);
+    if (lResult != ERROR_SUCCESS)
+        goto fail1;
+
+    size = sizeof(DWORD);
+    lResult = RegQueryValueEx(key,
+                              XENAGENT_TIMESYNC_MODE,
+                              NULL,
+                              &type,
+                              (LPBYTE)&mode,
+                              &size);
+    if (lResult != ERROR_SUCCESS)
+        goto fail2;
+
+    if (type != REG_DWORD ||
+        size != sizeof(DWORD))
+        goto fail3;
+
+    // mode is bit-flags, test for reason's bit
+    enabled = (mode & reason) != 0;
+
+    if (reason == XENIFACE_TIMESYNC_PERIODIC && enabled) {
+        DWORD                   interval;
+        XENIFACE_SHARED_TIME    last;
+
+        // check interval has expired
+        size = sizeof(DWORD);
+        lResult = RegQueryValueEx(key,
+                                  XENAGENT_TIMESYNC_INTERVAL,
+                                  NULL,
+                                  &type,
+                                  (LPBYTE)&interval,
+                                  &size);
+        if (lResult != ERROR_SUCCESS ||
+            type != REG_DWORD ||
+            size != sizeof(DWORD))
+            interval = XENAGENT_TIMESYNC_INTERVAL_DEFAULT;
+
+        size = sizeof(XENIFACE_SHARED_TIME);
+        lResult = RegQueryValueEx(key,
+                                  XENAGENT_TIMESYNC_LAST,
+                                  NULL,
+                                  &type,
+                                  (LPBYTE)&last,
+                                  &size);
+        if (lResult == ERROR_SUCCESS ||
+            type == REG_BINARY ||
+            size == sizeof(XENIFACE_SHARED_TIME)) {
+            // check if time is within interval -> dont update time
+            if ((last.local == now->local) &&
+                (TimeDiff(&last.time, &now->time) < interval)) {
+                enabled = false;
+            }
+        }
+    }
+
+    if (enabled) {
+        lResult = RegSetValueEx(key,
+                                XENAGENT_TIMESYNC_LAST,
+                                0,
+                                REG_BINARY,
+                                (LPBYTE)&now,
+                                sizeof(XENIFACE_SHARED_TIME));
+        if (lResult != ERROR_SUCCESS)
+            CXenAgent::Log("SetLastUpdateTime failed %08x\n", lResult);
+    }
+
+    RegCloseKey(key);
+
+    return enabled;
+
+fail3:
+fail2:
+    RegCloseKey(key);
+
+fail1:
+    return enabled;
+}
\ No newline at end of file
diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h
index 5a1aecf..4878db0 100644
--- a/src/xenagent/xenifacedevice.h
+++ b/src/xenagent/xenifacedevice.h
@@ -37,6 +37,16 @@
 #include <string>
 #include "devicelist.h"
 
+#define XENIFACE_TIMESYNC_NONE          0
+#define XENIFACE_TIMESYNC_RESUME        1
+#define XENIFACE_TIMESYNC_PERIODIC      2
+#define XENIFACE_TIMESYNC_ADDED         4
+
+typedef struct _XENIFACE_SHARED_TIME {
+    FILETIME    time;
+    bool        local;
+} XENIFACE_SHARED_TIME, *PXENIFACE_SHARED_TIME;
+
 class CXenIfaceDevice : public CDevice
 {
 public:
@@ -86,7 +96,7 @@ public:
     void Log(const char* message);
     bool CheckShutdown();
     void CheckShutdownRetry();
-    void CheckXenTime();
+    void CheckXenTime(DWORD reason);
     void CheckSuspend();
     bool CheckSlateMode(std::string& mode);
     void LogIfRebootPending();
@@ -99,7 +109,8 @@ private:
     void AdvertiseFeatures(CXenIfaceDevice* device, bool add);
     void RequestSystemShutdown();
     void AcquireShutdownPrivilege();
-    void SetXenTime(CXenIfaceDevice* device);
+    void SetXenTime(CXenIfaceDevice* device, DWORD reason);
+    bool CheckXenTimeEnabled(DWORD reason, PXENIFACE_SHARED_TIME now);
 
 private:
     CXenAgent*  m_agent;
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 11:37:30 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 11:37:30 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673944.1048549 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV8uG-000334-5A; Wed, 31 Jan 2024 11:37:28 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673944.1048549; Wed, 31 Jan 2024 11:37:28 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV8uG-00032x-1d; Wed, 31 Jan 2024 11:37:28 +0000
Received: by outflank-mailman (input) for mailman id 673944;
 Wed, 31 Jan 2024 11:37:26 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV8uE-00032j-6X
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 11:37:26 +0000
Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com
 [2a00:1450:4864:20::433])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 1a8f954b-c02d-11ee-8a43-1f161083a0e0;
 Wed, 31 Jan 2024 12:37:24 +0100 (CET)
Received: by mail-wr1-x433.google.com with SMTP id
 ffacd0b85a97d-33ae42033e2so3084665f8f.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 03:37:24 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 bt3-20020a056000080300b0033ae6fa7f20sm10321739wrb.65.2024.01.31.03.37.22
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 03:37:23 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 1a8f954b-c02d-11ee-8a43-1f161083a0e0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706701043; x=1707305843; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=9zyn2aKgkK9EKhWhG/Zsm5meAsvWrWvWwn2nr/v+6gE=;
        b=aqqKWakmeMRid5m2pDDwjWk48i+5r7cl1/WTh+6Afk4w2zY0mtdSha1ZZSsXlio/RY
         7+SSZZmmTx5KS+2qihgES71gLh7II+cRkESzEz2j9vVUd99ID9ZYxvTMuLZ6OcAjiqsP
         PUlR+x+GE3mSvmbNslorZbZHerJbKYWHN7iG0=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706701043; x=1707305843;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=9zyn2aKgkK9EKhWhG/Zsm5meAsvWrWvWwn2nr/v+6gE=;
        b=NEjZOEHQDXzmetRGDjOJNAqORrQxvbGnXGsM7pgms8xHppFlzrwQ26TfKODYyKBOhb
         hW79RZY8iKaoWGJuVRummisiSE3LtJlx0mQbMFpcX7pcwJ+CYBxW/yLf3ZPmHh/3y/IL
         gtppBAC3UmP4huHDruF5CCcmP/gSyQIi5xYL9UcZZQTQFVUoY0U4x8G6QeSlAw+RVNlY
         2aduRVforApWY47kDRF70uF1n4xYgpmKZgMS1AwAwKH7I+OLBtui0ykBxsSekH8H8tru
         k+pT8ZyZoJd3uKDiqbwfUzu30xfpO5emSxBkWgBgXnWKTSGiOgGjyynrO8qhm9ijfOCE
         fAUw==
X-Gm-Message-State: AOJu0Yx0F/oGmfnNdBMFmGvznGIrYjsUY8G3y/oaCRGkzdZSCvuE3S9D
	iIUE98tcWjvz8HfknD2/7yLTOHwHbqQERgZXG3ixNGznngmJbgX6Fuv8cktJzQcGkRod8kWX0ak
	yHA==
X-Google-Smtp-Source: AGHT+IGyT7U9pTl4VA/8xQ4yygo5saIRez+DT0KgRUZhZ7Xonws5jOR4Fdc5lWaUmW9K2LyF+wpnug==
X-Received: by 2002:a5d:47a7:0:b0:337:c61c:71b8 with SMTP id 7-20020a5d47a7000000b00337c61c71b8mr1324094wrb.7.1706701043538;
        Wed, 31 Jan 2024 03:37:23 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCXUi2NsbWDx/RipLUZQDH32mcMhOaAlJ0oZP/4YNCgKp0KPTM7g13ZnVsMejcHK45eTzgsoDZERjpxHvB6AAfKopXKRQw==
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Alex Burke <Alex.Burke@cloud.com>
Subject: [PATCH 1/2] XenVbd: Added MSBuild map file generation and handling.
Date: Wed, 31 Jan 2024 11:37:02 +0000
Message-ID: <20240131113703.1058-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Suggested-by: Alex Burke <Alex.Burke@cloud.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 build.ps1                      | 8 ++++++++
 vs2019/xencrsh/xencrsh.vcxproj | 2 ++
 vs2019/xendisk/xendisk.vcxproj | 2 ++
 vs2019/xenvbd/xenvbd.vcxproj   | 2 ++
 vs2022/xencrsh/xencrsh.vcxproj | 2 ++
 vs2022/xendisk/xendisk.vcxproj | 2 ++
 vs2022/xenvbd/xenvbd.vcxproj   | 2 ++
 7 files changed, 20 insertions(+)

diff --git a/build.ps1 b/build.ps1
index 4ff02c1..a178660 100644
--- a/build.ps1
+++ b/build.ps1
@@ -14,6 +14,7 @@ param(
 #
 # Script Body
 #
+$TargetPath = "xenvbd"
 
 Function Build {
 	param(
@@ -37,6 +38,13 @@ Function Build {
 		Write-Host -ForegroundColor Red "ERROR: Build failed, code:" $LASTEXITCODE
 		Exit $LASTEXITCODE
 	}
+	# Find and Move map files
+	foreach ($item in Get-ChildItem -Path $solutiondir[$visualstudioversion] -Include *.map -Recurse)
+	{
+		$filename = Split-Path -Path $item -Leaf -Resolve
+		$newpath = "$TargetPath\$Arch\$filename"
+		Move-Item $item -Destination $newpath -Force
+	}
 }
 
 Function SdvBuild {
diff --git a/vs2019/xencrsh/xencrsh.vcxproj b/vs2019/xencrsh/xencrsh.vcxproj
index 5433a39..d610072 100644
--- a/vs2019/xencrsh/xencrsh.vcxproj
+++ b/vs2019/xencrsh/xencrsh.vcxproj
@@ -36,6 +36,8 @@
       <AdditionalDependencies>$(DDK_LIB_PATH)/storport.lib;$(DDK_LIB_PATH)/libcntpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2019/xendisk/xendisk.vcxproj b/vs2019/xendisk/xendisk.vcxproj
index 6e714ae..7024581 100644
--- a/vs2019/xendisk/xendisk.vcxproj
+++ b/vs2019/xendisk/xendisk.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2019/xenvbd/xenvbd.vcxproj b/vs2019/xenvbd/xenvbd.vcxproj
index 470d16d..80a13a2 100644
--- a/vs2019/xenvbd/xenvbd.vcxproj
+++ b/vs2019/xenvbd/xenvbd.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>$(ProjectDir)..\$(ConfigurationName)\$(Platform)\xencrsh.lib;$(DDK_LIB_PATH)/storport.lib;$(DDK_LIB_PATH)/libcntpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xencrsh/xencrsh.vcxproj b/vs2022/xencrsh/xencrsh.vcxproj
index 2026310..d4d9ad3 100644
--- a/vs2022/xencrsh/xencrsh.vcxproj
+++ b/vs2022/xencrsh/xencrsh.vcxproj
@@ -36,6 +36,8 @@
       <AdditionalDependencies>$(DDK_LIB_PATH)/storport.lib;$(DDK_LIB_PATH)/libcntpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xendisk/xendisk.vcxproj b/vs2022/xendisk/xendisk.vcxproj
index 2fe56f5..ae2f56d 100644
--- a/vs2022/xendisk/xendisk.vcxproj
+++ b/vs2022/xendisk/xendisk.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xenvbd/xenvbd.vcxproj b/vs2022/xenvbd/xenvbd.vcxproj
index 6d51630..fd95608 100644
--- a/vs2022/xenvbd/xenvbd.vcxproj
+++ b/vs2022/xenvbd/xenvbd.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>$(ProjectDir)..\$(ConfigurationName)\$(Platform)\xencrsh.lib;$(DDK_LIB_PATH)/storport.lib;$(DDK_LIB_PATH)/libcntpr.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 11:37:30 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 11:37:30 +0000
Received: from list by lists.xenproject.org with outflank-mailman.673945.1048553 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV8uI-00034k-6B; Wed, 31 Jan 2024 11:37:30 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 673945.1048553; Wed, 31 Jan 2024 11:37:30 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rV8uI-00034d-3R; Wed, 31 Jan 2024 11:37:30 +0000
Received: by outflank-mailman (input) for mailman id 673945;
 Wed, 31 Jan 2024 11:37:29 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rV8uG-00034V-Uz
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 11:37:28 +0000
Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com
 [2a00:1450:4864:20::32d])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id 1b38dbea-c02d-11ee-98f5-efadbce2ee36;
 Wed, 31 Jan 2024 12:37:26 +0100 (CET)
Received: by mail-wm1-x32d.google.com with SMTP id
 5b1f17b1804b1-40e7065b692so52129485e9.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 03:37:26 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 bt3-20020a056000080300b0033ae6fa7f20sm10321739wrb.65.2024.01.31.03.37.23
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 03:37:23 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 1b38dbea-c02d-11ee-98f5-efadbce2ee36
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706701044; x=1707305844; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=HSg2kpDTdN+T06VNi4YTP1hto68vfmWeDGi70jn4LSw=;
        b=TheOzAd6QA1oeyPb6BOYA3Q2RXRJ76/MQ+oZVaaiHAr9frABH+BO1XD3bH49bI5NOR
         lNUMQ1Vaw6NJQbAu0+4D/1nGy3N3CpXFjwkvxB3nMZ3uk7wAgthjSPYuSWzywhEjP97p
         eW8aXS3bYKwHm3GRKlovwLPdNkPQ9IFw7ZkQ4=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706701044; x=1707305844;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=HSg2kpDTdN+T06VNi4YTP1hto68vfmWeDGi70jn4LSw=;
        b=F1q/1fA2DolDZ6X2ZVgK5ZvW9iNj+LMeUGYzcgH7A0ftUvUHcBwMZ8YTbH0o9cOzDm
         IA1VJ+WMTCsMYxrSJiBfCQjYNOyc2ha4nAPEWBfNyI7xRahWXeAgNEtqbqicx/WYNLnn
         0n6gL5GndTlInQIGJ6oTeTofqO9PcrJVmZr15ik7VElfKir0Zu+OKEJNTUpibL2HsfDJ
         rrManR2yXywKN1TsGHWG8iNbYlTGXg1RPyHaLCoj6BtmXNwm0zgVYtuUUd4O/lJuMZXZ
         +fr85PN2TgT+Kv0rngnnS7Flmt4hfnA0U73BHaM+BpkV9Zrmzgj2ePgdYZ4K/yFGx+gP
         h9xw==
X-Gm-Message-State: AOJu0YzG4u7d83iROgG1zsGxCISejUmodGyDNu7kghLUI1VTg+5a4Sz9
	nt9LN/GCK2tDLKPgy/66DYTDHv1qr6w1Dy7Gl2EAbPPvLkkuQQ7KF+q2qGLe22/7TSLoYa9r/jP
	Ziw==
X-Google-Smtp-Source: AGHT+IHwQZV5+MvyxPPgKbcr+t4kqfF7npZulH5mgakRD7wjpPnU85r461zP7GrNgROe3iOkkfPBPA==
X-Received: by 2002:a5d:6da9:0:b0:33b:24c:acdd with SMTP id u9-20020a5d6da9000000b0033b024cacddmr1242442wrs.10.1706701044809;
        Wed, 31 Jan 2024 03:37:24 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCWRU9Xd9rssSOpbXFvQlC5FYkh454CZmmz8e95gjV+LEIcDj1Iy4tWU4aA+UpZfLUxmYJib/hCVwt3NZeOCQsp47DUcxguSsA==
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Rabish Kumar <rabish.kumar@citrix.com>
Subject: [PATCH 2/2] XenVbd: Enable Integrity Check
Date: Wed, 31 Jan 2024 11:37:03 +0000
Message-ID: <20240131113703.1058-2-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240131113703.1058-1-owen.smith@cloud.com>
References: <20240131113703.1058-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Suggested-by: Rabish Kumar <rabish.kumar@citrix.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 vs2019/xencrsh/xencrsh.vcxproj | 1 +
 vs2019/xendisk/xendisk.vcxproj | 1 +
 vs2019/xenvbd/xenvbd.vcxproj   | 1 +
 vs2022/xencrsh/xencrsh.vcxproj | 1 +
 vs2022/xendisk/xendisk.vcxproj | 1 +
 vs2022/xenvbd/xenvbd.vcxproj   | 1 +
 6 files changed, 6 insertions(+)

diff --git a/vs2019/xencrsh/xencrsh.vcxproj b/vs2019/xencrsh/xencrsh.vcxproj
index d610072..095be8a 100644
--- a/vs2019/xencrsh/xencrsh.vcxproj
+++ b/vs2019/xencrsh/xencrsh.vcxproj
@@ -38,6 +38,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2019/xendisk/xendisk.vcxproj b/vs2019/xendisk/xendisk.vcxproj
index 7024581..6f2b09e 100644
--- a/vs2019/xendisk/xendisk.vcxproj
+++ b/vs2019/xendisk/xendisk.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2019/xenvbd/xenvbd.vcxproj b/vs2019/xenvbd/xenvbd.vcxproj
index 80a13a2..5951d45 100644
--- a/vs2019/xenvbd/xenvbd.vcxproj
+++ b/vs2019/xenvbd/xenvbd.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xencrsh/xencrsh.vcxproj b/vs2022/xencrsh/xencrsh.vcxproj
index d4d9ad3..0bdcb71 100644
--- a/vs2022/xencrsh/xencrsh.vcxproj
+++ b/vs2022/xencrsh/xencrsh.vcxproj
@@ -38,6 +38,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xendisk/xendisk.vcxproj b/vs2022/xendisk/xendisk.vcxproj
index ae2f56d..8d9c0d2 100644
--- a/vs2022/xendisk/xendisk.vcxproj
+++ b/vs2022/xendisk/xendisk.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xenvbd/xenvbd.vcxproj b/vs2022/xenvbd/xenvbd.vcxproj
index fd95608..dbbaafa 100644
--- a/vs2022/xenvbd/xenvbd.vcxproj
+++ b/vs2022/xenvbd/xenvbd.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 13:22:06 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 13:22:06 +0000
Received: from list by lists.xenproject.org with outflank-mailman.674042.1048717 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAXU-0005FX-N9; Wed, 31 Jan 2024 13:22:04 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 674042.1048717; Wed, 31 Jan 2024 13:22:04 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAXU-0005FP-KC; Wed, 31 Jan 2024 13:22:04 +0000
Received: by outflank-mailman (input) for mailman id 674042;
 Wed, 31 Jan 2024 13:22:02 +0000
Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254]
 helo=se1-gles-sth1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rVAXS-0005FJ-Gf
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 13:22:02 +0000
Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com
 [2a00:1450:4864:20::32a])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id b7b18ad4-c03b-11ee-8a43-1f161083a0e0;
 Wed, 31 Jan 2024 14:22:01 +0100 (CET)
Received: by mail-wm1-x32a.google.com with SMTP id
 5b1f17b1804b1-40fafced20aso12072485e9.0
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 05:22:01 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 t15-20020a05600c198f00b0040ee51f1025sm1595434wmq.43.2024.01.31.05.21.59
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 05:21:59 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: b7b18ad4-c03b-11ee-8a43-1f161083a0e0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706707320; x=1707312120; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=Ghe4s4I9yFD6vnHSqNFdw42ntOVgX6HYBgMNjIupWrQ=;
        b=FQNlwDO/8M3MnuChX/qMAv3cMvfi5xLEeoE4v3AyLjfPb+ZbCJr5tPoqnqG/hcLg8U
         FBGE+jxdBqNyZkqlohUiSJWESoHoGuG7E2ZpRZYtORfjeO8GWhIBdrVZ5YJUJcQrEbfD
         RWnJmyC3CWlrsMmp4LLKGlpiCFZQRQWDs97EE=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706707320; x=1707312120;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=Ghe4s4I9yFD6vnHSqNFdw42ntOVgX6HYBgMNjIupWrQ=;
        b=s4Vm6No7HIzYysdg40wfqHPC8t++O+TsQpmK4tO+W5MN6ZdD41uWd+T9hbhUwS/oSu
         2GV+Ql3HdDfUfL6Ax/8GIWgxwBSOH9sdk9z07VVDyFIdSIRo+oheC8XINqf6ZXIOYb0K
         zWB4rWfv23yX8iXzK0YFaaEvcG0nqy2wQzInk2Mluo2/lCkbPOV9HA9Mwjoy7k1VxD9C
         UlHQqXQXTijcs7wigPz5Ay0qEW5dFORy6NeWfSW34kPIEjKmT4unVFulaCfjxWXh/rKO
         W0vgKpvzm/zKERgHT+vJmQ1k+HRO2n3IvZgcuFjI/pbZTN7l1MC4ZcLfu+eEA6o4+duG
         wDCw==
X-Gm-Message-State: AOJu0YwxQ+9ZwITF8qmHuPLfIyiTTIBPUbVv4vVGwQzk93AA1laMH1P8
	d98hQbCIZBQlf9sEy56086lVnX6SsB+CVRz3+RDkVu4XGPqzFwU32e9NotspiKCcPojPCAuPSQZ
	CXg==
X-Google-Smtp-Source: AGHT+IG7Yz1W9QSk5yuLv6ofWuSJx7cBGaO7ULBAb6wGl5yOHr8Ze4q+EaF2zOiKNuWMKjUHEsYJHw==
X-Received: by 2002:a05:600c:3b03:b0:40f:b69e:aa0a with SMTP id m3-20020a05600c3b0300b0040fb69eaa0amr324494wms.8.1706707320074;
        Wed, 31 Jan 2024 05:22:00 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCVuBPVa1JIPsDZK5vTkY/d4Q64qcwzJJjl0dubJMYIZ4b1e2rWMHLzps/5jHKstk7LpLh6QB9lE7JA/S0g2ibAuz51mZQ==
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Alex Burke <Alex.Burke@cloud.com>
Subject: [PATCH 1/2] XenVif: Added MSBuild map file generation and handling.
Date: Wed, 31 Jan 2024 13:21:47 +0000
Message-ID: <20240131132148.1657-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Suggested-by: Alex Burke <Alex.Burke@cloud.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 build.ps1                    | 8 ++++++++
 vs2019/xenvif/xenvif.vcxproj | 2 ++
 vs2022/xenvif/xenvif.vcxproj | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/build.ps1 b/build.ps1
index 4ff02c1..4606ded 100644
--- a/build.ps1
+++ b/build.ps1
@@ -14,6 +14,7 @@ param(
 #
 # Script Body
 #
+$TargetPath = "xenvif"
 
 Function Build {
 	param(
@@ -37,6 +38,13 @@ Function Build {
 		Write-Host -ForegroundColor Red "ERROR: Build failed, code:" $LASTEXITCODE
 		Exit $LASTEXITCODE
 	}
+	# Find and Move map files
+	foreach ($item in Get-ChildItem -Path $solutiondir[$visualstudioversion] -Include *.map -Recurse)
+	{
+		$filename = Split-Path -Path $item -Leaf -Resolve
+		$newpath = "$TargetPath\$Arch\$filename"
+		Move-Item $item -Destination $newpath -Force
+	}
 }
 
 Function SdvBuild {
diff --git a/vs2019/xenvif/xenvif.vcxproj b/vs2019/xenvif/xenvif.vcxproj
index d070a03..582256d 100644
--- a/vs2019/xenvif/xenvif.vcxproj
+++ b/vs2019/xenvif/xenvif.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>$(DDK_LIB_PATH)/Rtlver.lib;$(DDK_LIB_PATH)/libcntpr.lib;$(DDK_LIB_PATH)/aux_klib.lib;$(DDK_LIB_PATH)/ksecdd.lib;$(DDK_LIB_PATH)/procgrp.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xenvif/xenvif.vcxproj b/vs2022/xenvif/xenvif.vcxproj
index 85c0a05..9b787c6 100644
--- a/vs2022/xenvif/xenvif.vcxproj
+++ b/vs2022/xenvif/xenvif.vcxproj
@@ -34,6 +34,8 @@
       <AdditionalDependencies>$(DDK_LIB_PATH)/Rtlver.lib;$(DDK_LIB_PATH)/libcntpr.lib;$(DDK_LIB_PATH)/aux_klib.lib;$(DDK_LIB_PATH)/ksecdd.lib;$(DDK_LIB_PATH)/procgrp.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
+      <GenerateMapFile>true</GenerateMapFile>
+      <MapExports>true</MapExports>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 13:22:06 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 13:22:06 +0000
Received: from list by lists.xenproject.org with outflank-mailman.674043.1048721 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAXW-0005HM-Og; Wed, 31 Jan 2024 13:22:06 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 674043.1048721; Wed, 31 Jan 2024 13:22:06 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAXW-0005HE-Lb; Wed, 31 Jan 2024 13:22:06 +0000
Received: by outflank-mailman (input) for mailman id 674043;
 Wed, 31 Jan 2024 13:22:05 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rVAXV-0005FD-NL
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 13:22:05 +0000
Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com
 [2a00:1450:4864:20::32d])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id b8744769-c03b-11ee-98f5-efadbce2ee36;
 Wed, 31 Jan 2024 14:22:02 +0100 (CET)
Received: by mail-wm1-x32d.google.com with SMTP id
 5b1f17b1804b1-40e7065b692so53071835e9.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 05:22:02 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 t15-20020a05600c198f00b0040ee51f1025sm1595434wmq.43.2024.01.31.05.22.00
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 05:22:00 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: b8744769-c03b-11ee-98f5-efadbce2ee36
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706707321; x=1707312121; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to;
        bh=rCCYw5Ix3p8v4v6wPHMsY7My/g2xP+NizyN1YKfJg7E=;
        b=EcEIuwDV+dESeSnDCY6GnQ+cKbP+fJyUEEMwR7bnwA92TyPPc3NqcN/KCl5ajb4RTa
         O6YcLF+LlPVmRHZ3zP35NK0oRuyXl2NTqSPdlKKXzNjLpfRsU7YemwLcJ4SpteaGJSzK
         85vK9zRLQCMSl2+58UnrKvHvNwABqQEze1j3Y=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706707321; x=1707312121;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=rCCYw5Ix3p8v4v6wPHMsY7My/g2xP+NizyN1YKfJg7E=;
        b=CxebdycHl5UDp1uFl1kvU5Y7ATzpp35oiuwl0bqAV4muycVLOTDYQCMjuAXM2iU70e
         C4DO76IYZ/zqzFiunoOtppaxDLm83HSnvsllV1hZ0vqdLCzzas+nCTspUtW9cfbGvFQ5
         LVHsh55la6PSB4kmT/JCczmxqWZ/yExQg2DygreXgOPJo5w7/JiJxXl/DvaTPwxMSh5b
         vHFqiU3T1haWsxg3pR9elh2fKW+4uQCcincaaGubHNvgMgrVaSYQ9lw7loYfq+U9Q0zi
         Xxis3HIhmwyQxoUlIVumcFbHLEPJ91fQeR70BI45QwFwaMq1Hb6+BNKgvc4lBegqn9Xn
         SaPg==
X-Gm-Message-State: AOJu0Yz/oJVDGa+6vGN5nuQy+lkv2kWZ7zmfzhxRTv940smXF9qiXTBe
	ucgV6+2F8ZItEkH65lNcUXWDXiA21VI1EXA04F8X70qkTNVXAEHlFvmjvsdO8rgA7pMXJ/ofO1N
	lrA==
X-Google-Smtp-Source: AGHT+IFLpYOfAa4P6ehYHlJiAMYEJFhy8XUcfvgdH7uVMpumxyJs5mdeftwyLD9E7A6q+dhYQXzsRw==
X-Received: by 2002:a05:600c:358e:b0:40e:b195:6bf3 with SMTP id p14-20020a05600c358e00b0040eb1956bf3mr1243107wmq.2.1706707321426;
        Wed, 31 Jan 2024 05:22:01 -0800 (PST)
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>
Subject: [PATCH] Add ETW support
Date: Wed, 31 Jan 2024 13:21:48 +0000
Message-ID: <20240131132148.1657-2-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
In-Reply-To: <20240131132148.1657-1-owen.smith@cloud.com>
References: <20240131132148.1657-1-owen.smith@cloud.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Defines ETW schema with EtwEnter and EtwExit events, which can be used to track
code-paths and produce flamegraphs of executions.
Only uses EtwEnter and EtwExit in the driver.c file of XenVif, but more events
will be added in subsequent patches.

Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 src/xenvif/dbg_print.h       | 60 +++++++++++++++++++++++++++++++++++
 src/xenvif/driver.c          | 10 ++++++
 src/xenvif/xenvif_etw.xml    | 61 ++++++++++++++++++++++++++++++++++++
 vs2019/xenvif/xenvif.vcxproj | 13 +++++++-
 vs2022/xenvif/xenvif.vcxproj | 13 +++++++-
 5 files changed, 155 insertions(+), 2 deletions(-)
 create mode 100644 src/xenvif/xenvif_etw.xml

diff --git a/src/xenvif/dbg_print.h b/src/xenvif/dbg_print.h
index e39a50c..9cbd286 100644
--- a/src/xenvif/dbg_print.h
+++ b/src/xenvif/dbg_print.h
@@ -42,6 +42,66 @@
 
 #pragma warning(disable:4127)   // conditional expression is constant
 
+#ifdef ETW_HEADER
+#include ETW_HEADER
+
+static __inline VOID
+__EtwEnter(
+    IN  const CHAR      *Module,
+    IN  const CHAR      *Function,
+    IN  ULONG           Line
+    )
+{
+    CHAR                _Module[16];
+    CHAR                _Function[32];
+
+    if (!EventEnabledEvtEnter())
+        return;
+
+    RtlZeroMemory(_Module, sizeof(_Module));
+    RtlZeroMemory(_Function, sizeof(_Function));
+
+    strncpy(_Module, Module, ARRAYSIZE(_Module) -1);
+    strncpy(_Function, Function, ARRAYSIZE(_Function) - 1);
+
+    EventWriteEvtEnter(NULL, _Module, _Function, Line);
+}
+
+static __inline VOID
+__EtwExit(
+    IN  const CHAR      *Module,
+    IN  const CHAR      *Function,
+    IN  ULONG           Line,
+    IN  NTSTATUS        Status
+    )
+{
+    CHAR                _Module[16];
+    CHAR                _Function[32];
+
+    if (!EventEnabledEvtExit())
+        return;
+
+    RtlZeroMemory(_Module, sizeof(_Module));
+    RtlZeroMemory(_Function, sizeof(_Function));
+
+    strncpy(_Module, Module, sizeof(_Module));
+    strncpy(_Function, Function, sizeof(_Function));
+
+    EventWriteEvtExit(NULL, _Module, _Function, Line, (ULONG)Status);
+}
+
+#define EtwEnter()          __EtwEnter(__MODULE__, __FUNCTION__, __LINE__)
+#define EtwExit()           __EtwExit(__MODULE__, __FUNCTION__, __LINE__, STATUS_SUCCESS)
+#define EtwExit2(status)    __EtwExit(__MODULE__, __FUNCTION__, __LINE__, status)
+
+#else
+
+#define EtwEnter()          (VOID)0
+#define EtwExit()           (VOID)0
+#define EtwExit2(status)    (VOID)status
+
+#endif
+
 static __inline VOID
 __Error(
     IN  const CHAR  *Prefix,
diff --git a/src/xenvif/driver.c b/src/xenvif/driver.c
index 3345607..fec047d 100644
--- a/src/xenvif/driver.c
+++ b/src/xenvif/driver.c
@@ -303,6 +303,8 @@ DriverUnload(
 
     __DriverSetDriverObject(NULL);
 
+    EventUnregisterXenVif_Driver();
+
     ASSERT(IsZeroMemory(&Driver, sizeof (XENVIF_DRIVER)));
 
     Trace("<====\n");
@@ -318,6 +320,7 @@ AddDevice(
 {
     NTSTATUS            status;
 
+    EtwEnter();
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
 
     status = FdoCreate(DeviceObject);
@@ -328,11 +331,13 @@ AddDevice(
     ASSERT(!(DeviceObject->Flags & DO_DEVICE_INITIALIZING));
     DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
 
+    EtwExit();
     return STATUS_SUCCESS;
 
 fail1:
     Error("fail1 (%08x)\n", status);
 
+    EtwExit2(status);
     return status;
 }
 
@@ -347,6 +352,7 @@ Dispatch(
     PXENVIF_DX          Dx;
     NTSTATUS            status;
 
+    EtwEnter();
     Dx = (PXENVIF_DX)DeviceObject->DeviceExtension;
     ASSERT3P(Dx->DeviceObject, ==, DeviceObject);
 
@@ -390,6 +396,7 @@ Dispatch(
     }
 
 done:
+    EtwExit2(status);
     return status;
 }
 
@@ -410,6 +417,7 @@ DriverEntry(
 
     ASSERT3P(__DriverGetDriverObject(), ==, NULL);
 
+    EventRegisterXenVif_Driver();
     ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
     WdmlibProcgrpInitialize();
 
@@ -506,6 +514,8 @@ fail1:
 
     __DriverSetDriverObject(NULL);
 
+    EventUnregisterXenVif_Driver();
+
     ASSERT(IsZeroMemory(&Driver, sizeof (XENVIF_DRIVER)));
 
     return status;
diff --git a/src/xenvif/xenvif_etw.xml b/src/xenvif/xenvif_etw.xml
new file mode 100644
index 0000000..06f088b
--- /dev/null
+++ b/src/xenvif/xenvif_etw.xml
@@ -0,0 +1,61 @@
+<?xml version='1.0' encoding='utf-8' standalone='yes'?>
+<instrumentationManifest
+    xmlns="http://schemas.microsoft.com/win/2004/08/events"
+    xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" >
+  <instrumentation>
+    <events>
+      <provider
+          guid="{6c02b05a-c66d-49db-bd06-4fbe1adcbe13}"
+          messageFileName="%SystemDrive%\windows\system32\drivers\xenvif.sys"
+          name="XenVif_Driver"
+          resourceFileName="%SystemDrive%\windows\system32\drivers\xenvif.sys"
+          symbol="DriverControlGuid" >
+        <channels>
+          <channel chid="XENVIF" name="XenVif" type="Analytic" enabled="true" />
+        </channels>
+        <templates>
+          <template tid="tid_enter">
+            <data name="Module" inType="win:Int8" count="16" outType="xs:string" />     <!-- 16 chars -->
+            <data name="Function" inType="win:Int8" count="32" outType="xs:string" />   <!-- 32 chars -->
+            <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" />           <!-- line number -->
+          </template>
+          <template tid="tid_exit">
+            <data name="Module" inType="win:Int8" count="16" outType="xs:string" />     <!-- 16 chars -->
+            <data name="Function" inType="win:Int8" count="32" outType="xs:string" />   <!-- 32 chars -->
+            <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" />           <!-- line number -->
+            <data name="Status" inType="win:UInt32" outType="xs:unsignedInt" />         <!-- NTSTATUS -->
+          </template>
+        </templates>
+        <events>
+          <event
+            channel="XENVIF"
+            level="win:Informational"
+            message="$(string.EventTraceInfo.Enter)"
+            opcode="win:Info"
+            symbol="EvtEnter"
+            template="tid_enter"
+            value="10" />
+          <event
+            channel="XENVIF"
+            level="win:Informational"
+            message="$(string.EventTraceInfo.Exit)"
+            opcode="win:Info"
+            symbol="EvtExit"
+            template="tid_exit"
+            value="11" />
+        </events>
+      </provider>
+    </events>
+  </instrumentation>
+  <localization xmlns="http://schemas.microsoft.com/win/2004/08/events">
+    <resources culture="en-US">
+      <stringTable>
+        <string id="EventTraceInfo.Enter" value="[Enter]" />
+        <string id="EventTraceInfo.Exit"  value="[Exit ]" />
+      </stringTable>
+    </resources>
+  </localization>
+</instrumentationManifest>
diff --git a/vs2019/xenvif/xenvif.vcxproj b/vs2019/xenvif/xenvif.vcxproj
index d070a03..7bb566b 100644
--- a/vs2019/xenvif/xenvif.vcxproj
+++ b/vs2019/xenvif/xenvif.vcxproj
@@ -21,7 +21,7 @@
     <ClCompile>
       <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
       <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenvif_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <WarningLevel>EnableAllWarnings</WarningLevel>
       <DisableSpecificWarnings>4061;4464;4711;4770;4548;4820;4668;4255;5045;6001;6054;26451;28196;30030;30029;%(DisableSpecificWarnings)</DisableSpecificWarnings>
@@ -35,6 +35,13 @@
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
     </Link>
+    <MessageCompile>
+      <HeaderFilePath>..\..\include</HeaderFilePath>
+      <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName>
+      <RCFilePath>..\..\src\xenvif</RCFilePath>
+      <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros>
+      <UseBaseNameOfInput>true</UseBaseNameOfInput>
+    </MessageCompile>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
     </DriverSign>
@@ -65,6 +72,7 @@
   <ItemGroup>
     <FilesToPackage Include="$(TargetPath)" />
     <FilesToPackage Include="$(OutDir)$(TargetName).pdb" />
+    <FilesToPackage Include="..\..\src\xenvif\xenvif_etw.xml" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="../../src/xenvif/bus.c" />
@@ -87,6 +95,9 @@
   <ItemGroup>
     <ResourceCompile Include="..\..\src\xenvif\xenvif.rc" />
   </ItemGroup>
+  <ItemGroup>
+    <MessageCompile Include="..\..\src\xenvif\xenvif_etw.xml" />
+  </ItemGroup>
   <ItemGroup>
     <None Include="..\package\package.vcxproj" />
   </ItemGroup>
diff --git a/vs2022/xenvif/xenvif.vcxproj b/vs2022/xenvif/xenvif.vcxproj
index 85c0a05..9f5aad2 100644
--- a/vs2022/xenvif/xenvif.vcxproj
+++ b/vs2022/xenvif/xenvif.vcxproj
@@ -21,7 +21,7 @@
     <ClCompile>
       <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions>
       <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenvif_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <WarningLevel>EnableAllWarnings</WarningLevel>
       <DisableSpecificWarnings>4061;4464;4711;4770;4548;4820;4668;4255;5045;6001;6054;26451;28196;30030;30029;%(DisableSpecificWarnings)</DisableSpecificWarnings>
@@ -35,6 +35,13 @@
       <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
       <CETCompat>true</CETCompat>
     </Link>
+    <MessageCompile>
+      <HeaderFilePath>..\..\include</HeaderFilePath>
+      <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName>
+      <RCFilePath>..\..\src\xenvif</RCFilePath>
+      <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros>
+      <UseBaseNameOfInput>true</UseBaseNameOfInput>
+    </MessageCompile>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
     </DriverSign>
@@ -57,6 +64,7 @@
   <ItemGroup>
     <FilesToPackage Include="$(TargetPath)" />
     <FilesToPackage Include="$(OutDir)$(TargetName).pdb" />
+    <FilesToPackage Include="..\..\src\xenvif\xenvif_etw.xml" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="../../src/xenvif/bus.c" />
@@ -79,6 +87,9 @@
   <ItemGroup>
     <ResourceCompile Include="..\..\src\xenvif\xenvif.rc" />
   </ItemGroup>
+  <ItemGroup>
+    <MessageCompile Include="..\..\src\xenvif\xenvif_etw.xml" />
+  </ItemGroup>
   <ItemGroup>
     <None Include="..\package\package.vcxproj" />
   </ItemGroup>
-- 
2.41.0.windows.3



From win-pv-devel-bounces@lists.xenproject.org Wed Jan 31 13:23:32 2024
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 31 Jan 2024 13:23:32 +0000
Received: from list by lists.xenproject.org with outflank-mailman.674054.1048724 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAYt-0005Q9-SZ; Wed, 31 Jan 2024 13:23:31 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 674054.1048724; Wed, 31 Jan 2024 13:23:31 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1rVAYt-0005Q2-Pw; Wed, 31 Jan 2024 13:23:31 +0000
Received: by outflank-mailman (input) for mailman id 674054;
 Wed, 31 Jan 2024 13:23:31 +0000
Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50]
 helo=se1-gles-flk1.inumbo.com)
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=ydpS=JJ=cloud.com=owen.smith@srs-se1.protection.inumbo.net>)
 id 1rVAYt-0005Pw-Bd
 for win-pv-devel@lists.xenproject.org; Wed, 31 Jan 2024 13:23:31 +0000
Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com
 [2a00:1450:4864:20::332])
 by se1-gles-flk1.inumbo.com (Halon) with ESMTPS
 id ea849747-c03b-11ee-98f5-efadbce2ee36;
 Wed, 31 Jan 2024 14:23:26 +0100 (CET)
Received: by mail-wm1-x332.google.com with SMTP id
 5b1f17b1804b1-40eacb6067dso63485185e9.1
 for <win-pv-devel@lists.xenproject.org>; Wed, 31 Jan 2024 05:23:26 -0800 (PST)
Received: from localhost.localdomain ([185.25.64.249])
 by smtp.gmail.com with ESMTPSA id
 z12-20020a7bc7cc000000b0040efb503d58sm1606575wmk.28.2024.01.31.05.23.24
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 31 Jan 2024 05:23:25 -0800 (PST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: ea849747-c03b-11ee-98f5-efadbce2ee36
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=cloud.com; s=cloud; t=1706707405; x=1707312205; darn=lists.xenproject.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=DY2IawjLXFnV93SSnFkYguuj4lEfTjb/NIxvrfe27CI=;
        b=WU8mWA/OIB4DDRZWD09RQQ8lU8sGSJJHSmJcsHrlHLPeQXwvYLwzRpM3Qslqo9Gffn
         4LFIRFUfKxhFZiJMag4yNXVrQ7XIlki2ZPMSyhhT8e26rlSN5CXVTGKdsrAvc6rrJSPq
         Y+uMj1sA8LOd+dNHuIO+/ZrBXMAZA/laHlT0M=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1706707405; x=1707312205;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=DY2IawjLXFnV93SSnFkYguuj4lEfTjb/NIxvrfe27CI=;
        b=cJAdE+mJ023rS6MWCEx2O+9ytVdYJV7vlCUPbyjhb/7/e2ik1TgsVp+ddcun7mMGmd
         df6g/j39RBawLwBQfcd0zoq+Foto+x1YufRRYW3i5HDz789GD9fCFsJKo7ksmBqZ1PhX
         BNKJJ3nynhhAwGnM5MYjlUeDv+2D0IGsjnlxdEHn2X4sQNYZDIKHFSFSeSpr7O4bXR0I
         4vyi1/rKtoyWjSjAvQulCLiWCImEq99NKDjIt9udY4guZXlpPb6lIZHWU37MqiQvlEmi
         OdpPzAZr06x8A7vdszeXi1tNraYg9hkiO9y9M/NhU7dp4pm+6JRGIlpJI647jBOqV5cz
         4PQw==
X-Gm-Message-State: AOJu0YyOUZESmmZVbS9ZvbY5wRuspJQSObHaoPpjqM0D7OBmT7k4u7fO
	1aZIHpwGfrHwTMavBZIr6cXdYMJ1SMzz6kOJTx1xdyrAHdTnFYOhd8eTwU7dtmwq8hsWVANJ8io
	3oA==
X-Google-Smtp-Source: AGHT+IH/KLfXSvUhMgNaXCQtsrcg8+trPduG496DuXAe5TE/i7721/GGKu+ki9wSA3yd/7ao6Zhorg==
X-Received: by 2002:a05:600c:6003:b0:40e:6688:300d with SMTP id az3-20020a05600c600300b0040e6688300dmr1354027wmb.26.1706707405447;
        Wed, 31 Jan 2024 05:23:25 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCUEltRwyHatj1JkBYREo31PYL1tEUWALspWX4xC+SEoA+laO/khrIzR35tkw6a9ei0ykw4SBG4vJIzoUTTfoUWPrcWowK39Gw==
From: Owen Smith <owen.smith@cloud.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Rabish Kumar <rabish.kumar@citrix.com>
Subject: [PATCH 2/2] XenVif: Enable Integrity Check
Date: Wed, 31 Jan 2024 13:23:13 +0000
Message-ID: <20240131132314.744-1-owen.smith@cloud.com>
X-Mailer: git-send-email 2.41.0.windows.3
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Suggested-by: Rabish Kumar <rabish.kumar@citrix.com>
Signed-off-by: Owen Smith <owen.smith@cloud.com>
---
 vs2019/xenvif/xenvif.vcxproj | 1 +
 vs2022/xenvif/xenvif.vcxproj | 1 +
 2 files changed, 2 insertions(+)

diff --git a/vs2019/xenvif/xenvif.vcxproj b/vs2019/xenvif/xenvif.vcxproj
index 582256d..357cf7e 100644
--- a/vs2019/xenvif/xenvif.vcxproj
+++ b/vs2019/xenvif/xenvif.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
diff --git a/vs2022/xenvif/xenvif.vcxproj b/vs2022/xenvif/xenvif.vcxproj
index 9b787c6..186ef05 100644
--- a/vs2022/xenvif/xenvif.vcxproj
+++ b/vs2022/xenvif/xenvif.vcxproj
@@ -36,6 +36,7 @@
       <CETCompat>true</CETCompat>
       <GenerateMapFile>true</GenerateMapFile>
       <MapExports>true</MapExports>
+      <AdditionalOptions>/INTEGRITYCHECK %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <DriverSign>
       <FileDigestAlgorithm>sha256</FileDigestAlgorithm>
-- 
2.41.0.windows.3



