From win-pv-devel-bounces@lists.xenproject.org Mon Jul 03 16:46:42 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 03 Jul 2023 16:46:42 +0000
Received: from list by lists.xenproject.org with outflank-mailman.558100.871926 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qGMhC-0004d2-V4; Mon, 03 Jul 2023 16:46:38 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 558100.871926; Mon, 03 Jul 2023 16:46:38 +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 1qGMhC-0004cu-S9; Mon, 03 Jul 2023 16:46:38 +0000
Received: by outflank-mailman (input) for mailman id 558100;
 Mon, 03 Jul 2023 16:46:37 +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=elC/=CV=gmail.com=xadimgnik@srs-se1.protection.inumbo.net>)
 id 1qGMhB-0004co-KS
 for win-pv-devel@lists.xenproject.org; Mon, 03 Jul 2023 16:46:37 +0000
Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com
 [2a00:1450:4864:20::12a])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id 2bf6e592-19c1-11ee-b237-6b7b168915f2;
 Mon, 03 Jul 2023 18:46:35 +0200 (CEST)
Received: by mail-lf1-x12a.google.com with SMTP id
 2adb3069b0e04-4f8735ac3e3so7300775e87.2
 for <win-pv-devel@lists.xenproject.org>; Mon, 03 Jul 2023 09:46:35 -0700 (PDT)
Received: from [192.168.1.246] (54-240-197-239.amazon.com. [54.240.197.239])
 by smtp.gmail.com with ESMTPSA id
 b7-20020a5d4b87000000b00314374145e0sm3150742wrt.67.2023.07.03.09.46.33
 for <win-pv-devel@lists.xenproject.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Mon, 03 Jul 2023 09:46:34 -0700 (PDT)
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: 2bf6e592-19c1-11ee-b237-6b7b168915f2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20221208; t=1688402795; x=1690994795;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :references:to:content-language:subject:user-agent:mime-version:date
         :message-id:from:from:to:cc:subject:date:message-id:reply-to;
        bh=B1fNuc9Qxy0GDoDlsHDF7odj6IVt84G9fY2gxQ0N8YE=;
        b=APEURNF7R/rmd7ySvtkkNEfcdIdkez4R4uodxHYE5JNRt/cEuw6EWjlaAdhbFO7dg2
         wec/40hrdyiMIkKTvFlpd3QAO8guJObs3VEowOI9vv8uJnUwUBFhH5uQbQekVZB8DYZZ
         dsI/AT8+Bb/HcvbwB4QFbH0oarf1Fnm9HdaTUoFeX+1cBrzXFvgECAmPHHQ0JBUWol+4
         8V9HUnQsJ5Ul3tnAJzL24QFqIeTGcir4dGStsz8UTy4pUM5k+/1Xy12ObW9Vp3kcKRDr
         7tgmbvO9zy2KotVb6EsGYBa95eB19ddjIBuIucdxocL4R8t6By2K0MbLhvaci5G5LvJ6
         DVpA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1688402795; x=1690994795;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :references:to:content-language:subject:user-agent:mime-version:date
         :message-id:from:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=B1fNuc9Qxy0GDoDlsHDF7odj6IVt84G9fY2gxQ0N8YE=;
        b=A8HmCCM+tfAhP9fPco1Kt387U7IpxLU0TOPfZHE6xEEhgRmDK8ugVVC5556olUMAOD
         0RQBQNx8H3VUEtnLffkAubDkJD3psbrCk0eAeoTJapRleU6l6e6gX6L/pTYJPkFBu1h9
         p5hOyf2GUsbRT7Hsbrfk7jjE7xEPAzj1Y7Tpt0Gwje+SGvIVmPuBNO9oVh7OSEjc3J6o
         Vemr4HYrx42PWfHxzsXWR/b/j9d/LMWg5u6fYPO0Fyevnc4l6d2kY+QwMqubaj61QOVR
         HiPAwNb/lThOzSUsYBZmR1lrXyf75ckhdMltGORvgiHB2CMMK7JQ/9dkK1Bdxr0Jeozr
         vrQQ==
X-Gm-Message-State: ABy/qLa+wpuq2EbyiF8wiIhlkOI8Vcxl2yeIV8AkVGa4vmw01slIrT/x
	CiPvNYX1iKOVgpP1I4mXYJgl8VvmKXFczg==
X-Google-Smtp-Source: APBJJlHsYtcd+6BOGG5VQ7x4P7xrjXstzr0Guq7D00oVh7PBFBtmmurHYPbn1WSMayE6ZPNFg8qXow==
X-Received: by 2002:a05:6512:308b:b0:4f7:69b9:fa07 with SMTP id z11-20020a056512308b00b004f769b9fa07mr7772387lfd.45.1688402794497;
        Mon, 03 Jul 2023 09:46:34 -0700 (PDT)
From: Paul Durrant <xadimgnik@gmail.com>
X-Google-Original-From: Paul Durrant <paul@xen.org>
Message-ID: <feab2273-3705-7259-3b59-5d8d012e9a5b@xen.org>
Date: Mon, 3 Jul 2023 17:46:32 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.12.0
Subject: Re: [PATCH] Only call EvtchnFlush on valid Cpus
Content-Language: en-US
To: win-pv-devel@lists.xenproject.org
References: <20230620143319.1305-1-owen.smith@cloud.com>
Reply-To: paul@xen.org
Organization: Xen Project
In-Reply-To: <20230620143319.1305-1-owen.smith@cloud.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

On 20/06/2023 15:33, Owen Smith wrote:
> The Evtchn processor array is created using KeQueryMaximumProcessorCountEx, which
> can include processors that do not get initialized.
> Skip cleanup and flushing uninitialized event channels
> 
> Signed-off-by: Owen Smith <owen.smith@cloud.com>

Acked-by: Paul Durrant <paul@xen.org>

> ---
>   src/xenbus/evtchn.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/src/xenbus/evtchn.c b/src/xenbus/evtchn.c
> index 2e63edb..ec4ac28 100644
> --- a/src/xenbus/evtchn.c
> +++ b/src/xenbus/evtchn.c
> @@ -1752,10 +1752,16 @@ EvtchnRelease(
>   
>       for (Cpu = 0; Cpu < Context->ProcessorCount; Cpu++) {
>           PXENBUS_EVTCHN_PROCESSOR Processor;
> +        unsigned int             vcpu_id;
> +        NTSTATUS                 status;
>   
>           ASSERT(Context->Processor != NULL);
>           Processor = &Context->Processor[Cpu];
>   
> +        status = SystemProcessorVcpuId(Cpu, &vcpu_id);
> +        if (!NT_SUCCESS(status))
> +            continue;
> +
>           EvtchnFlush(Context, Cpu);
>   
>           (VOID) KeRemoveQueueDpc(&Processor->Dpc);



From win-pv-devel-bounces@lists.xenproject.org Mon Jul 03 17:13:39 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 03 Jul 2023 17:13:39 +0000
Received: from list by lists.xenproject.org with outflank-mailman.558114.871940 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qGN7J-00087N-49; Mon, 03 Jul 2023 17:13:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 558114.871940; Mon, 03 Jul 2023 17:13: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 1qGN7J-00087G-1F; Mon, 03 Jul 2023 17:13:37 +0000
Received: by outflank-mailman (input) for mailman id 558114;
 Mon, 03 Jul 2023 17:13:36 +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=elC/=CV=gmail.com=xadimgnik@srs-se1.protection.inumbo.net>)
 id 1qGN7I-00087A-7B
 for win-pv-devel@lists.xenproject.org; Mon, 03 Jul 2023 17:13:36 +0000
Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com
 [2a00:1450:4864:20::334])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id f14575a1-19c4-11ee-b237-6b7b168915f2;
 Mon, 03 Jul 2023 19:13:35 +0200 (CEST)
Received: by mail-wm1-x334.google.com with SMTP id
 5b1f17b1804b1-3fbc77e769cso41756335e9.0
 for <win-pv-devel@lists.xenproject.org>; Mon, 03 Jul 2023 10:13:35 -0700 (PDT)
Received: from [192.168.1.246] (54-240-197-231.amazon.com. [54.240.197.231])
 by smtp.gmail.com with ESMTPSA id
 z7-20020a5d4407000000b003143cdc5949sm342067wrq.9.2023.07.03.10.13.33
 for <win-pv-devel@lists.xenproject.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Mon, 03 Jul 2023 10:13:33 -0700 (PDT)
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: f14575a1-19c4-11ee-b237-6b7b168915f2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20221208; t=1688404414; x=1690996414;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :references:to:content-language:subject:user-agent:mime-version:date
         :message-id:from:from:to:cc:subject:date:message-id:reply-to;
        bh=1v+725g0GRRUe1gYoRTs94us63EfQhsYctXijGvv0xY=;
        b=mAgrz/Tm688dudHbZrVISjpn3UmW935zwtxIW4OuZA4IC6qcc/nJ4CDnIRMEPfC53p
         gfx5n650rxYxQT4hkcWaSol3FRzPwoA+3vXVH2mIhDfj4fK0KQHGaODngmNw6dFiUtpB
         d3SZk6asQAIH8897mU2FBy9EecK2N1mFucEOaSrKCJIAW9XvwQY1eangCnYFn83rzKTA
         fgbTDbL1tyjbvvMMt9IhXDwV3jQGvAlomoX7QEr7RpYXbaS3uM1nkiAVUkz9d5x/25LE
         vMJstmCeE3UH5v8UOiatiFdgsSsTelwK+AURSNOft34Hd2JDgzoI++kZK/xBUxwZhja0
         pjFw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1688404414; x=1690996414;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :references:to:content-language:subject:user-agent:mime-version:date
         :message-id:from:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=1v+725g0GRRUe1gYoRTs94us63EfQhsYctXijGvv0xY=;
        b=Mpf6YAkVL4RbhuqNIePRt57on5NuV8tlL7L6xvqBIpxPyLC6wxJN/aDEcHUeo4cJyZ
         D4dMC5PpnKvUs/kQbvu+jVdLChVu/MaC0rDny0QSwXsZwqvPhB/2qZxNVEvf8ecbbb4+
         Bocd+HMjMmpt76b63pciXv55O4gSCqTBRzg0vAhDmzqE0xa8VgFC8va/MXVOZPPTemGC
         rjEOgUHn74KGaeWK4nsUPHVFUZWbNApxgCcaP0cz8nL2kC2KnxayFqGQFuoW1/tX6cvl
         ApHtpVqDz1TGwjX4UplggoeEFWs32AHLBvvXYDI6Itj5PsUIBfu/tmzsGAoHdoLKEdmu
         Xwzw==
X-Gm-Message-State: AC+VfDzeCIixV5d4vuE6Pe6fWEpZ4TUw+3mW5p3+IuO7GfkQ8fm78bRb
	a0kbGqXn2mlsVQd4qlcGY/1T6T9PMf0Yrg==
X-Google-Smtp-Source: ACHHUZ6/WA09KBO2vIipKWydh6+16iZGGGE6VZXrma0L4/c7Rn3q42DqqeSx9c5IyV9rnvLduExTSw==
X-Received: by 2002:a05:600c:286:b0:3fb:b6f3:e528 with SMTP id 6-20020a05600c028600b003fbb6f3e528mr9529981wmk.25.1688404414122;
        Mon, 03 Jul 2023 10:13:34 -0700 (PDT)
From: Paul Durrant <xadimgnik@gmail.com>
X-Google-Original-From: Paul Durrant <paul@xen.org>
Message-ID: <1e93d413-48e8-d2f6-baa2-ef4e09cd6b03@xen.org>
Date: Mon, 3 Jul 2023 18:13:31 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.12.0
Subject: Re: [PATCH] Only call EvtchnFlush on valid Cpus
Content-Language: en-US
To: win-pv-devel@lists.xenproject.org
References: <20230620143319.1305-1-owen.smith@cloud.com>
 <feab2273-3705-7259-3b59-5d8d012e9a5b@xen.org>
Reply-To: paul@xen.org
Organization: Xen Project
In-Reply-To: <feab2273-3705-7259-3b59-5d8d012e9a5b@xen.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

On 03/07/2023 17:46, Paul Durrant wrote:
> On 20/06/2023 15:33, Owen Smith wrote:
>> The Evtchn processor array is created using 
>> KeQueryMaximumProcessorCountEx, which
>> can include processors that do not get initialized.
>> Skip cleanup and flushing uninitialized event channels
>>
>> Signed-off-by: Owen Smith <owen.smith@cloud.com>
> 
> Acked-by: Paul Durrant <paul@xen.org>
> 

Actually, taking another look I think we should actually fix 
EvtchnTwoLevelIsProcessorEnabled() to check SystemProcessorVcpuId() 
rather than blindly returning TRUE (the FIFO variant already checks) and 
then we can use EvtchnIsProcessorEnabled()...

>> ---
>>   src/xenbus/evtchn.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/src/xenbus/evtchn.c b/src/xenbus/evtchn.c
>> index 2e63edb..ec4ac28 100644
>> --- a/src/xenbus/evtchn.c
>> +++ b/src/xenbus/evtchn.c
>> @@ -1752,10 +1752,16 @@ EvtchnRelease(
>>       for (Cpu = 0; Cpu < Context->ProcessorCount; Cpu++) {
>>           PXENBUS_EVTCHN_PROCESSOR Processor;
>> +        unsigned int             vcpu_id;
>> +        NTSTATUS                 status;
>>           ASSERT(Context->Processor != NULL);
>>           Processor = &Context->Processor[Cpu];
>> +        status = SystemProcessorVcpuId(Cpu, &vcpu_id);

... here instead. I'll send a follow-up patch.

   Paul

>> +        if (!NT_SUCCESS(status))
>> +            continue;
>> +
>>           EvtchnFlush(Context, Cpu);
>>           (VOID) KeRemoveQueueDpc(&Processor->Dpc);
> 



From win-pv-devel-bounces@lists.xenproject.org Fri Jul 07 11:25:38 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Jul 2023 11:25:38 +0000
Received: from list by lists.xenproject.org with outflank-mailman.560423.876347 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qHjaj-0005Ln-4i; Fri, 07 Jul 2023 11:25:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 560423.876347; Fri, 07 Jul 2023 11:25: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 1qHjaj-0005Lg-2B; Fri, 07 Jul 2023 11:25:37 +0000
Received: by outflank-mailman (input) for mailman id 560423;
 Fri, 07 Jul 2023 11:25:36 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qHjai-0005La-E7
 for win-pv-devel@lists.xenproject.org; Fri, 07 Jul 2023 11:25:36 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjai-0008GS-9x; Fri, 07 Jul 2023 11:25:36 +0000
Received: from 54-240-197-235.amazon.com ([54.240.197.235]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjai-0002d1-16; Fri, 07 Jul 2023 11:25:36 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:
	Subject:Cc:To:From; bh=aDL2uKrd8/NH7xPESWMK+qGbTloVwkSZyc4EwrgzVoQ=; b=0c8HBw
	VBCuZjRVglZe1nLhdvMEYFQ4pfcGtWMOlrhpiVfeFtwxPvfmgv60PLQKDcpfu1trfq+ssPde+8F4v
	ymytIJv0oXwEp+cm4NhATIbKHas/2njh2R94VX6KUtEHHZBa/qfFGVCof+7OFcW7hth9aXWGKLDjd
	VUbil03dvp0=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 1/3] Fix EvtchnTwoLevelIsProcessorEnabled()
Date: Fri,  7 Jul 2023 12:25:25 +0100
Message-Id: <20230707112527.565-1-paul@xen.org>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

It should take account of whether the vCPU is enabled, as
EvtchnFifoIsProcessorEnabled() already does.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/xenbus/evtchn_2l.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/xenbus/evtchn_2l.c b/src/xenbus/evtchn_2l.c
index f63ef3e33ea2..6585f73579b6 100644
--- a/src/xenbus/evtchn_2l.c
+++ b/src/xenbus/evtchn_2l.c
@@ -72,10 +72,15 @@ EvtchnTwoLevelIsProcessorEnabled(
     IN  ULONG                       Index
     )
 {
+    unsigned int                    vcpu_id;
+    NTSTATUS                        status;
+
     UNREFERENCED_PARAMETER(_Context);
     UNREFERENCED_PARAMETER(Index);
 
-    return TRUE;
+    status = SystemProcessorVcpuId(Index, &vcpu_id);
+
+    return NT_SUCCESS(status) ? TRUE : FALSE;
 }
 
 static BOOLEAN
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Jul 07 11:25:38 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Jul 2023 11:25:38 +0000
Received: from list by lists.xenproject.org with outflank-mailman.560424.876352 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qHjak-0005Ne-6K; Fri, 07 Jul 2023 11:25:38 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 560424.876352; Fri, 07 Jul 2023 11:25:38 +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 1qHjak-0005NX-3X; Fri, 07 Jul 2023 11:25:38 +0000
Received: by outflank-mailman (input) for mailman id 560424;
 Fri, 07 Jul 2023 11:25:37 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qHjaj-0005NG-7i
 for win-pv-devel@lists.xenproject.org; Fri, 07 Jul 2023 11:25:37 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjaj-0008GX-4r; Fri, 07 Jul 2023 11:25:37 +0000
Received: from 54-240-197-235.amazon.com ([54.240.197.235]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjai-0002d1-S6; Fri, 07 Jul 2023 11:25:37 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References:
	In-Reply-To:Message-Id:Date:Subject:Cc:To:From;
	bh=yctIb93MaW/9n3118lWarBWcFXxELu2pWxQNnSZMi/E=; b=n8egWG6Gtbys56m8ojNlDz7aHu
	fjvkuf7l2BnMq1iemUvSQt+aV4xMj8BB4tIwu8lBLcI3A8+DdKa9R2GRFLKmzBne9P17AJ+RLLkl7
	wIFZPlL8uPdcFB1vmdhsFSRp4nEnmAgPGh6J44Kf1lZ1PLWasR0cC1k/9wtIBCTWDM+o=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@cloud.com>,
	Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 2/3] Only call EvtchnFlush on valid Cpus
Date: Fri,  7 Jul 2023 12:25:26 +0100
Message-Id: <20230707112527.565-2-paul@xen.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20230707112527.565-1-paul@xen.org>
References: <20230707112527.565-1-paul@xen.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Owen Smith <owen.smith@cloud.com>

The Evtchn processor array is created using KeQueryMaximumProcessorCountEx, which
can include processors that do not get initialized.
Skip cleanup and flushing uninitialized event channels

Signed-off-by: Owen Smith <owen.smith@cloud.com>

Use EvtchnIsProcessorEnabled() rather than SystemProcessorVcpuId() as the test.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/xenbus/evtchn.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/xenbus/evtchn.c b/src/xenbus/evtchn.c
index 2e63edb93b78..9f7026db8dde 100644
--- a/src/xenbus/evtchn.c
+++ b/src/xenbus/evtchn.c
@@ -1753,6 +1753,9 @@ EvtchnRelease(
     for (Cpu = 0; Cpu < Context->ProcessorCount; Cpu++) {
         PXENBUS_EVTCHN_PROCESSOR Processor;
 
+        if (!EvtchnIsProcessorEnabled(Context, Cpu))
+            continue;
+
         ASSERT(Context->Processor != NULL);
         Processor = &Context->Processor[Cpu];
 
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Jul 07 11:25:39 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Jul 2023 11:25:39 +0000
Received: from list by lists.xenproject.org with outflank-mailman.560425.876356 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qHjal-0005PY-7e; Fri, 07 Jul 2023 11:25:39 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 560425.876356; Fri, 07 Jul 2023 11:25:39 +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 1qHjal-0005PR-55; Fri, 07 Jul 2023 11:25:39 +0000
Received: by outflank-mailman (input) for mailman id 560425;
 Fri, 07 Jul 2023 11:25:37 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qHjaj-0005NO-U7
 for win-pv-devel@lists.xenproject.org; Fri, 07 Jul 2023 11:25:37 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjaj-0008Gf-SZ; Fri, 07 Jul 2023 11:25:37 +0000
Received: from 54-240-197-235.amazon.com ([54.240.197.235]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHjaj-0002d1-In; Fri, 07 Jul 2023 11:25:37 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References:
	In-Reply-To:Message-Id:Date:Subject:Cc:To:From;
	bh=ABYZ+rTkWcqXu2sV8plSXId3pBRW1sisHG5a05Blzgc=; b=leHSP4u1w3COxkVqE6cDgwDY0C
	P+/FOZHWe4929dltuhCUILC9VRrisBmJrQIzo9TZ53awRNMdTs8BSo7jPIbSuH1/QupeBCk5zZjL8
	b8aOMVXcKsuyOLgGP8bO5iUlpCDSX+0xi7C93FlSmbaSTymQO42J5bi1AQFTL5bjII9A=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 3/3] Avoid unnecessary check for non-NULL Processor->Interrupt in EvtchnRelease()
Date: Fri,  7 Jul 2023 12:25:27 +0100
Message-Id: <20230707112527.565-3-paul@xen.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20230707112527.565-1-paul@xen.org>
References: <20230707112527.565-1-paul@xen.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

If EvtchnIsProcessorEnabled() is TRUE then Processor->Interrupt should be
valid. Hence use an ASSERTion instead. Also replicate the check of
EvtchnIsProcessorEnabled() in the error path in EvtchnAcquire().
While we're at it, let's also use EvtchnIsProcessorEnabled() in
EvtchnInterruptEnable() and EvtchnInterruptDisable().

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/xenbus/evtchn.c | 64 +++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/src/xenbus/evtchn.c b/src/xenbus/evtchn.c
index 9f7026db8dde..123f4a3a75e5 100644
--- a/src/xenbus/evtchn.c
+++ b/src/xenbus/evtchn.c
@@ -1271,6 +1271,22 @@ EvtchnAbiRelease(
     RtlZeroMemory(&Context->EvtchnAbi, sizeof (XENBUS_EVTCHN_ABI));
 }
 
+static BOOLEAN
+EvtchnIsProcessorEnabled(
+    IN  PXENBUS_EVTCHN_CONTEXT      Context,
+    IN  ULONG                       Cpu
+    )
+{
+    if (!XENBUS_SHARED_INFO(UpcallSupported,
+                            &Context->SharedInfoInterface,
+                            Cpu))
+        return FALSE;
+
+    return XENBUS_EVTCHN_ABI(IsProcessorEnabled,
+                             &Context->EvtchnAbi,
+                             Cpu);
+}
+
 static VOID
 EvtchnInterruptEnable(
     IN  PXENBUS_EVTCHN_CONTEXT  Context
@@ -1297,15 +1313,15 @@ EvtchnInterruptEnable(
 
         Processor = &Context->Processor[Cpu];
 
-        if (Processor->Interrupt == NULL)
-            continue;
-
-        status = SystemProcessorVcpuId(Cpu, &vcpu_id);
-        if (!NT_SUCCESS(status))
+        if (!EvtchnIsProcessorEnabled(Context, Cpu))
             continue;
 
+        ASSERT(Processor->Interrupt != NULL);
         Vector = FdoGetInterruptVector(Context->Fdo, Processor->Interrupt);
 
+        status = SystemProcessorVcpuId(Cpu, &vcpu_id);
+        ASSERT(NT_SUCCESS(status));
+
         status = HvmSetEvtchnUpcallVector(vcpu_id, Vector);
         if (!NT_SUCCESS(status)) {
             if (status != STATUS_NOT_IMPLEMENTED )
@@ -1368,9 +1384,10 @@ EvtchnInterruptDisable(
         if (!Processor->UpcallEnabled)
             continue;
 
+        ASSERT(EvtchnIsProcessorEnabled(Context, Cpu));
+
         status = SystemProcessorVcpuId(Cpu, &vcpu_id);
-        if (!NT_SUCCESS(status))
-            continue;
+        ASSERT(NT_SUCCESS(status));
 
         (VOID) HvmSetEvtchnUpcallVector(vcpu_id, 0);
         Processor->UpcallEnabled = FALSE;
@@ -1517,22 +1534,6 @@ EvtchnDebugCallback(
     }
 }
 
-static BOOLEAN
-EvtchnIsProcessorEnabled(
-    IN  PXENBUS_EVTCHN_CONTEXT      Context,
-    IN  ULONG                       Cpu
-    )
-{
-    if (!XENBUS_SHARED_INFO(UpcallSupported,
-                            &Context->SharedInfoInterface,
-                            Cpu))
-        return FALSE;
-
-    return XENBUS_EVTCHN_ABI(IsProcessorEnabled,
-                             &Context->EvtchnAbi,
-                             Cpu);
-}
-
 static NTSTATUS
 EvtchnAcquire(
     IN  PINTERFACE          Interface
@@ -1657,16 +1658,18 @@ fail9:
     for (Cpu = 0; Cpu < Context->ProcessorCount; Cpu++) {
         PXENBUS_EVTCHN_PROCESSOR Processor;
 
+        if (!EvtchnIsProcessorEnabled(Context, Cpu))
+            continue;
+
         ASSERT(Context->Processor != NULL);
         Processor = &Context->Processor[Cpu];
 
         RtlZeroMemory(&Processor->Dpc, sizeof (KDPC));
         RtlZeroMemory(&Processor->PendingList, sizeof (LIST_ENTRY));
 
-        if (Processor->Interrupt != NULL) {
-            FdoFreeInterrupt(Fdo, Processor->Interrupt);
-            Processor->Interrupt = NULL;
-        }
+        ASSERT(Processor->Interrupt != NULL);
+        FdoFreeInterrupt(Fdo, Processor->Interrupt);
+        Processor->Interrupt = NULL;
 
         Processor->Cpu = 0;
         Processor->Context = NULL;
@@ -1765,10 +1768,9 @@ EvtchnRelease(
         RtlZeroMemory(&Processor->Dpc, sizeof (KDPC));
         RtlZeroMemory(&Processor->PendingList, sizeof (LIST_ENTRY));
 
-        if (Processor->Interrupt != NULL) {
-            FdoFreeInterrupt(Fdo, Processor->Interrupt);
-            Processor->Interrupt = NULL;
-        }
+        ASSERT(Processor->Interrupt != NULL);
+        FdoFreeInterrupt(Fdo, Processor->Interrupt);
+        Processor->Interrupt = NULL;
 
         Processor->Cpu = 0;
         Processor->Context = NULL;
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Jul 07 16:38:40 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Jul 2023 16:38:40 +0000
Received: from list by lists.xenproject.org with outflank-mailman.560582.876610 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qHoTd-00087G-QF; Fri, 07 Jul 2023 16:38:37 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 560582.876610; Fri, 07 Jul 2023 16:38: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 1qHoTd-000879-NQ; Fri, 07 Jul 2023 16:38:37 +0000
Received: by outflank-mailman (input) for mailman id 560582;
 Fri, 07 Jul 2023 16:38:37 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qHoTd-000873-1l
 for win-pv-devel@lists.xenproject.org; Fri, 07 Jul 2023 16:38:37 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHoTc-0007d9-Sb; Fri, 07 Jul 2023 16:38:36 +0000
Received: from 54-240-197-235.amazon.com ([54.240.197.235]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qHoTc-0007F6-HT; Fri, 07 Jul 2023 16:38:36 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:
	Subject:Cc:To:From; bh=fJqh9miPQgbUp1ZxwcZirufpBoyq+JrPCCTGbKe01mc=; b=gX4HhO
	sc1lqGDD7HFtIEqUZ+aQi4o5s38OEjliDA2Gdvw6hsaXU9+MEBCo920f9vc2tSvPlSsJfTVvIx9lE
	wKgYIKAyT6qgj3/TfCZxtA3kxRZwYN6qlCoCg6Wa5+as3YxxS9xK4c6HC1xysE22uwek1v0LrA0aJ
	OozxvdTfSlM=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH] Add more comments and ASSERTions in the cache allocator
Date: Fri,  7 Jul 2023 17:38:34 +0100
Message-Id: <20230707163834.836-1-paul@xen.org>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

It was clear from the thread at [1] that there is some confusion (including
my own) over the semantics of the slab list. Add some more comments and
ASSERTions to better explain.

Also turn a silly secondary 'if' into the 'else' clause it should have
always been.

[1] https://lists.xenproject.org/archives/html/win-pv-devel/2023-06/msg00002.html

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/xenbus/cache.c | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/xenbus/cache.c b/src/xenbus/cache.c
index 07dcd5663aba..00e16f6fb1f2 100644
--- a/src/xenbus/cache.c
+++ b/src/xenbus/cache.c
@@ -338,8 +338,14 @@ CacheInsertSlab(
     InsertTailList(&Cache->SlabList, &New->ListEntry);
 
 done:
-    if (Cache->Cursor == NULL)
+    if (Cache->Cursor == NULL) {
+        //
+        // A newly inserted slab has either just been created, or has just had
+        // an object freed back to it. Either will it should never be full.
+        //
+        ASSERT(CacheMaskCount(New->Allocated) < CacheMaskSize(New->Allocated));
         Cache->Cursor = &New->ListEntry;
+    }
 
 #undef  INSERT_BEFORE
 }
@@ -475,13 +481,16 @@ CacheDestroySlab(
     // The only reason the cursor should be pointing at this slab is
     // if it is the only one in the list.
     //
-    if (Cache->Cursor == &Slab->ListEntry)
+    if (Cache->Cursor == &Slab->ListEntry) {
+        ASSERT3P(Slab->ListEntry.Flink, ==, &Cache->SlabList);
+        ASSERT3P(Slab->ListEntry.Blink, ==, &Cache->SlabList);
         Cache->Cursor = &Cache->SlabList;
+    }
 
     RemoveEntryList(&Slab->ListEntry);
 
-    ASSERT(Cache->Cursor != &Cache->SlabList ||
-           IsListEmpty(&Cache->SlabList));
+    ASSERT(IMPLY(Cache->Cursor == &Cache->SlabList,
+                 IsListEmpty(&Cache->SlabList)));
 
     Index = CacheMaskSize(Slab->Allocated);
     while (--Index >= 0) {
@@ -608,7 +617,7 @@ CacheGet(
 
 again:
     if (Cache->Cursor != &Cache->SlabList) {
-        PLIST_ENTRY ListEntry = Cache->Cursor;
+        PLIST_ENTRY         ListEntry = Cache->Cursor;
         PXENBUS_CACHE_SLAB  Slab;
 
         Slab = CONTAINING_RECORD(ListEntry, XENBUS_CACHE_SLAB, ListEntry);
@@ -616,11 +625,15 @@ again:
         Object = CacheGetObjectFromSlab(Slab);
         ASSERT(Object != NULL);
 
+        //
+        // If the slab is now fully occupied, ove the cursor on to the next
+        // slab. If there are no more slabed then Flink will be pointing at
+        // Cache->SlabList so we will create a new slab next time round, if
+        // necessary.
+        //
         if (CacheMaskCount(Slab->Allocated) == CacheMaskSize(Slab->Allocated))
             Cache->Cursor = Slab->ListEntry.Flink;
-    }
-
-    if (Object == NULL) {
+    } else {
         NTSTATUS status;
 
         ASSERT3P(Cache->Cursor, ==, &Cache->SlabList);
@@ -684,7 +697,11 @@ CachePut(
 
     CachePutObjectToSlab(Slab, Object);
 
-    /* Re-insert to keep slab list ordered */
+    //
+    // To maintain the order, and the invariant that the cursor always points,
+    // to the first slab with available space we must remove this slab from the
+    // list and re-insert it at it's (now) correct location.
+    //
     RemoveEntryList(&Slab->ListEntry);
     CacheInsertSlab(Cache, Slab);
 
@@ -745,12 +762,16 @@ CacheSpill(
     while (!IsListEmpty(&Cache->SlabList)) {
         PXENBUS_CACHE_SLAB  Slab;
 
-        // Actual list removal is done in CacheDestroySlab()
         ListEntry = Cache->SlabList.Blink;
         ASSERT(ListEntry != &Cache->SlabList);
 
         Slab = CONTAINING_RECORD(ListEntry, XENBUS_CACHE_SLAB, ListEntry);
 
+        //
+        // Slabs are kept in order of maximum to minimum occupancy so we know
+        // that if the last slab in the list is not empty, then none of the
+        // slabs before it will be empty.
+        //
         if (CacheMaskCount(Slab->Allocated) != 0)
             break;
 
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Mon Jul 10 09:59:35 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Mon, 10 Jul 2023 09:59:35 +0000
Received: from list by lists.xenproject.org with outflank-mailman.561157.877530 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qIng3-0002N8-7n; Mon, 10 Jul 2023 09:59:31 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 561157.877530; Mon, 10 Jul 2023 09:59: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 1qIng3-0002N1-5G; Mon, 10 Jul 2023 09:59:31 +0000
Received: by outflank-mailman (input) for mailman id 561157;
 Mon, 10 Jul 2023 09:59:29 +0000
Received: from winpvdrvbuild.xenproject.org ([162.242.160.44])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul.durrant@xenproject.org>) id 1qIng1-0002Mv-Df
 for win-pv-devel@lists.xenproject.org; Mon, 10 Jul 2023 09:59:29 +0000
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>
Date: Mon, 10 Jul 2023 09:59:25 +0000 (UTC)
From: paul.durrant@xenproject.org
To: win-pv-devel@lists.xenproject.org
Message-ID: <8816761.1.1688983167332.JavaMail.WINPVDRVBUILD$@winpvdrvbuild>
Subject: XENBUS-master - Build #245 - Successful
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_0_5137015.1688983166301"
X-Jenkins-Job: XENBUS-master
X-Jenkins-Result: SUCCESS


------=_Part_0_5137015.1688983166301
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

The build system has completed build #245.

Check console output at https://winpvdrvbuild.xenproject.org:8080/job/XENBUS-master/245/console to view the results.
------=_Part_0_5137015.1688983166301--


From win-pv-devel-bounces@lists.xenproject.org Wed Jul 12 15:52:07 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 12 Jul 2023 15:52:07 +0000
Received: from list by lists.xenproject.org with outflank-mailman.562618.879369 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qJc8M-0003IR-HN; Wed, 12 Jul 2023 15:52:06 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 562618.879369; Wed, 12 Jul 2023 15:52: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 1qJc8M-0003IK-Ep; Wed, 12 Jul 2023 15:52:06 +0000
Received: by outflank-mailman (input) for mailman id 562618;
 Wed, 12 Jul 2023 15:52:04 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qJc8K-0003GZ-Qn
 for win-pv-devel@lists.xenproject.org; Wed, 12 Jul 2023 15:52:04 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8K-0003cm-Ph; Wed, 12 Jul 2023 15:52:04 +0000
Received: from 54-240-197-227.amazon.com ([54.240.197.227]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8K-0001nO-Cr; Wed, 12 Jul 2023 15:52:04 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References:
	In-Reply-To:Message-Id:Date:Subject:Cc:To:From;
	bh=qyxDhJ3+V3OkT2FsJ4fa2tnOklYIURKGZQJhP49BOTQ=; b=jjnHcHQEXztN1pweUJgeO1xBBt
	lpQ9DMvTwdT5E4bj6oyA8SmFSjlHNZeG6FM/hpPNziG5zgqjuplo6x4U7En6bAw7jf5N/AjO7iJRz
	ZCWdFTp5Q/lisbM8nwQnPyeo+mMW1FXwiz2ukrFCqtvZdZYiLfFLG5OVqXGc0Fy5Vk3A=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 2/3] Get rid of the single contiguous memory hole
Date: Wed, 12 Jul 2023 16:51:59 +0100
Message-Id: <20230712155200.1348-2-paul@xen.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20230712155200.1348-1-paul@xen.org>
References: <20230712155200.1348-1-paul@xen.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

A standard grant table with 64 pages only uses half the allocated 2 MiB of
space and, empirically, getting more than 2 MiB of physically contiguous
memory doesn't seem to work very often.
By changing FdoAllocateHole() and FdoFreeHole() to use an MDL we can do
discrete contiguous allocations on-demand, which is all that is actually
required by callers. It's straightforward to adapt __AllocatePages() for
this purpose by having it pass the MM_ALLOCATE_REQUIRE_CONTIGUOUS_CHUNKS
flag to MmAllocatePagesForMdlEx().

NOTE: This means that the generic XENBUS_HOLE becomes XENBUS_PCI_HOLE.
      Also re-work the function naming so FdoAllocateHole() becomes
      FdoHoleAllocate() and other names are similarly restructured. It
      makes the code marginally neater.
      Take the opprtunity to also put zeroing of FrameIndex in the
      XENBUS_GNTTAB Context in the right place in the GnttabAcquire()
      error path, and adjust GnttabRelease() accordingly.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/common/util.h        |  17 +-
 src/xenbus/fdo.c         | 594 +++++++++++++++++----------------------
 src/xenbus/fdo.h         |  17 +-
 src/xenbus/gnttab.c      |  79 +++---
 src/xenbus/shared_info.c |  48 +++-
 5 files changed, 357 insertions(+), 398 deletions(-)

diff --git a/src/common/util.h b/src/common/util.h
index 326ff0b98d9f..b020e5bed096 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -180,28 +180,37 @@ __FreePoolWithTag(
 
 static FORCEINLINE PMDL
 __AllocatePages(
-    IN  ULONG           Count
+    IN  ULONG           Count,
+    IN  BOOLEAN         Contiguous
     )
 {
     PHYSICAL_ADDRESS    LowAddress;
     PHYSICAL_ADDRESS    HighAddress;
     LARGE_INTEGER       SkipBytes;
     SIZE_T              TotalBytes;
+    ULONG               Flags;
     PMDL                Mdl;
     PUCHAR              MdlMappedSystemVa;
     NTSTATUS            status;
 
     LowAddress.QuadPart = 0ull;
     HighAddress.QuadPart = ~0ull;
-    SkipBytes.QuadPart = 0ull;
     TotalBytes = (SIZE_T)PAGE_SIZE * Count;
 
+    if (Contiguous) {
+        SkipBytes.QuadPart = TotalBytes;
+        Flags = MM_ALLOCATE_REQUIRE_CONTIGUOUS_CHUNKS;
+    } else {
+        SkipBytes.QuadPart = 0ull;
+        Flags = MM_ALLOCATE_FULLY_REQUIRED;
+    }
+
     Mdl = MmAllocatePagesForMdlEx(LowAddress,
                                   HighAddress,
                                   SkipBytes,
                                   TotalBytes,
                                   MmCached,
-                                  MM_ALLOCATE_FULLY_REQUIRED);
+                                  Flags);
 
     status = STATUS_NO_MEMORY;
     if (Mdl == NULL)
@@ -245,7 +254,7 @@ fail1:
     return NULL;
 }
 
-#define __AllocatePage()    __AllocatePages(1)
+#define __AllocatePage()    __AllocatePages(1, FALSE)
 
 static FORCEINLINE VOID
 __FreePages(
diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index 99a4605f590c..976a7a35b12b 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -91,12 +91,12 @@ typedef struct _XENBUS_VIRQ {
     ULONG                   Count;
 } XENBUS_VIRQ, *PXENBUS_VIRQ;
 
-typedef struct _XENBUS_HOLE {
-    PXENBUS_RANGE_SET               RangeSet;
-    ULONG                           Count;
-    PVOID                           VirtualAddress;
-    PHYSICAL_ADDRESS                PhysicalAddress;
-} XENBUS_HOLE, *PXENBUS_HOLE;
+typedef struct _XENBUS_PCI_HOLE {
+    PXENBUS_RANGE_SET   RangeSet;
+    ULONG               Count;
+    PVOID               VirtualAddress;
+    PHYSICAL_ADDRESS    PhysicalAddress;
+} XENBUS_PCI_HOLE, *PXENBUS_PCI_HOLE;
 
 struct _XENBUS_FDO {
     PXENBUS_DX                      Dx;
@@ -156,8 +156,8 @@ struct _XENBUS_FDO {
     XENBUS_RANGE_SET_INTERFACE      RangeSetInterface;
     XENBUS_BALLOON_INTERFACE        BalloonInterface;
 
-    PMDL                            Mdl;
-    XENBUS_HOLE                     Hole;
+    ULONG                           UseMemoryHole;
+    XENBUS_PCI_HOLE                 PciHole;
     LIST_ENTRY                      InterruptList;
 
     LIST_ENTRY                      VirqList;
@@ -3218,82 +3218,24 @@ FdoSuspendCallbackLate(
     ASSERT(NT_SUCCESS(status));
 }
 
-static FORCEINLINE NTSTATUS
-__FdoCreateMemoryHole(
-    IN  PXENBUS_FDO Fdo
-    )
-{
-    PXENBUS_HOLE    Hole = &Fdo->Hole;
-    PMDL            Mdl;
-    PFN_NUMBER      Pfn;
-    NTSTATUS        status;
-
-    Mdl = Fdo->Mdl;
-    Hole->VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
-
-    Pfn = MmGetMdlPfnArray(Mdl)[0];
-    Hole->PhysicalAddress.QuadPart = (ULONGLONG)Pfn << PAGE_SHIFT;
-
-    Hole->Count = BYTES_TO_PAGES(Mdl->ByteCount);
-    ASSERT3U(Hole->Count, ==, 1u << PAGE_ORDER_2M);
-
-    status = STATUS_UNSUCCESSFUL;
-    if (MemoryDecreaseReservation(PAGE_ORDER_2M, 1, &Pfn) != 1)
-        goto fail1;
-
-    return STATUS_SUCCESS;
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    Hole->Count = 0;
-    Hole->PhysicalAddress.QuadPart = 0;
-    Hole->VirtualAddress = NULL;
-
-    return status;
-}
-
-static FORCEINLINE VOID
-__FdoDestroyMemoryHole(
-    IN  PXENBUS_FDO Fdo
-    )
-{
-    PXENBUS_HOLE    Hole = &Fdo->Hole;
-    PMDL            Mdl;
-    PFN_NUMBER      Pfn;
-    ULONG           Index;
-
-    Mdl = Fdo->Mdl;
-    Pfn = MmGetMdlPfnArray(Mdl)[0];
-
-    ASSERT3U(Hole->Count, ==, 1u << PAGE_ORDER_2M);
-    if (MemoryPopulatePhysmap(PAGE_ORDER_2M, 1, &Pfn) == 1)
-        goto done;
-
-    for (Index = 0; Index < Hole->Count; Index++) {
-        if (MemoryPopulatePhysmap(PAGE_ORDER_4K, 1, &Pfn) != 1)
-            BUG("FAILED TO RE-POPULATE HOLE");
-
-        Pfn++;
-    }
-
-done:
-    Hole->Count = 0;
-    Hole->PhysicalAddress.QuadPart = 0;
-    Hole->VirtualAddress = NULL;
-}
-
-static FORCEINLINE NTSTATUS
-__FdoCreatePciHole(
+static NTSTATUS
+FdoPciHoleCreate(
     IN  PXENBUS_FDO                 Fdo
     )
 {
-    PXENBUS_HOLE                    Hole = &Fdo->Hole;
+    PXENBUS_PCI_HOLE                Hole = &Fdo->PciHole;
     ULONG                           Index;
     PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
-    SIZE_T                          Size;
+    PFN_NUMBER                      Pfn;
     NTSTATUS                        status;
 
+    status = XENBUS_RANGE_SET(Create,
+                              &Fdo->RangeSetInterface,
+                              "PCI",
+                              &Hole->RangeSet);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
     for (Index = 0; Index < Fdo->TranslatedResourceList->Count; Index++) {
         Translated = &Fdo->TranslatedResourceList->PartialDescriptors[Index];
 
@@ -3302,125 +3244,106 @@ __FdoCreatePciHole(
     }
 
     status = STATUS_OBJECT_NAME_NOT_FOUND;
-    goto fail1;
+    goto fail2;
 
 found:
-    Hole->PhysicalAddress = Translated->u.Memory.Start;
-    Size = Translated->u.Memory.Length;
-    Hole->Count = (ULONG)(Size >> PAGE_SHIFT);
-
-    Hole->VirtualAddress = MmMapIoSpace(Hole->PhysicalAddress,
-                                        Size,
+    Hole->VirtualAddress = MmMapIoSpace(Translated->u.Memory.Start,
+                                        Translated->u.Memory.Length,
                                         MmCached);
 
     status = STATUS_UNSUCCESSFUL;
     if (Hole->VirtualAddress == NULL)
-        goto fail2;
+        goto fail3;
+
+    Hole->PhysicalAddress = Translated->u.Memory.Start;
+    Hole->Count = (ULONG)(Translated->u.Memory.Length >> PAGE_SHIFT);
+
+    status = XENBUS_RANGE_SET(Put,
+                              &Fdo->RangeSetInterface,
+                              Hole->RangeSet,
+                              0,
+                              Hole->Count);
+    if (!NT_SUCCESS(status))
+        goto fail4;
+
+    Pfn = (PFN_NUMBER)(Hole->PhysicalAddress.QuadPart >> PAGE_SHIFT);
+    Info("%08x - %08x\n",
+         Pfn,
+         Pfn + Hole->Count - 1);
 
     return STATUS_SUCCESS;
 
-fail2:
-    Error("fail2\n");
+fail4:
+    Error("fail4\n");
+
+    MmUnmapIoSpace(Hole->VirtualAddress, Hole->Count << PAGE_SHIFT);
 
     Hole->VirtualAddress = NULL;
     Hole->Count = 0;
     Hole->PhysicalAddress.QuadPart = 0;
 
-fail1:
-    Error("fail1 (%08x)\n", status);
+fail3:
+    Error("fail3\n");
 
-    return status;
-}
+fail2:
+    Error("fail2\n");
 
-static FORCEINLINE VOID
-__FdoDestroyPciHole(
-    IN  PXENBUS_FDO Fdo
-    )
-{
-    PXENBUS_HOLE    Hole = &Fdo->Hole;
-    SIZE_T          Size;
+    XENBUS_RANGE_SET(Destroy,
+                     &Fdo->RangeSetInterface,
+                     Hole->RangeSet);
+    Hole->RangeSet = NULL;
 
-    Size = (ULONGLONG)Hole->Count << PAGE_SHIFT;
-    MmUnmapIoSpace(Hole->VirtualAddress, Size);
+fail1:
+    Error("fail1 (%08x)\n", status);
 
-    Hole->VirtualAddress = NULL;
-    Hole->Count = 0;
-    Hole->PhysicalAddress.QuadPart = 0;
+    return status;
 }
 
-static NTSTATUS
-FdoCreateHole(
+static VOID
+FdoPciHoleDestroy(
     IN  PXENBUS_FDO     Fdo
     )
 {
-    PXENBUS_HOLE        Hole = &Fdo->Hole;
-    PFN_NUMBER          Pfn;
+    PXENBUS_PCI_HOLE    Hole = &Fdo->PciHole;
     NTSTATUS            status;
 
-    status = XENBUS_RANGE_SET(Create,
-                              &Fdo->RangeSetInterface,
-                              "hole",
-                              &Hole->RangeSet);
-    if (!NT_SUCCESS(status))
-        goto fail1;
-
-    status = (Fdo->Mdl != NULL) ?
-             __FdoCreateMemoryHole(Fdo) :
-             __FdoCreatePciHole(Fdo);
-
-    if (!NT_SUCCESS(status))
-        goto fail2;
+    BUG_ON(Hole->Count == 0);
 
-    status = XENBUS_RANGE_SET(Put,
+    status = XENBUS_RANGE_SET(Get,
                               &Fdo->RangeSetInterface,
                               Hole->RangeSet,
                               0,
                               Hole->Count);
-    if (!NT_SUCCESS(status))
-        goto fail3;
-
-    Pfn = (PFN_NUMBER)(Hole->PhysicalAddress.QuadPart >> PAGE_SHIFT);
-    Info("(%s) %08x - %08x\n",
-         (Fdo->Mdl != NULL) ? "MEMORY" : "PCI",
-         Pfn,
-         Pfn + Hole->Count - 1);
-
-    return STATUS_SUCCESS;
-
-fail3:
-    Error("fail3\n");
+    ASSERT(NT_SUCCESS(status));
 
-    if (Fdo->Mdl != NULL)
-        __FdoDestroyMemoryHole(Fdo);
-    else
-        __FdoDestroyPciHole(Fdo);
+    MmUnmapIoSpace(Hole->VirtualAddress, Hole->Count << PAGE_SHIFT);
 
-fail2:
-    Error("fail2\n");
+    Hole->VirtualAddress = NULL;
+    Hole->Count = 0;
+    Hole->PhysicalAddress.QuadPart = 0;
 
     XENBUS_RANGE_SET(Destroy,
                      &Fdo->RangeSetInterface,
                      Hole->RangeSet);
     Hole->RangeSet = NULL;
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    return status;
 }
 
-NTSTATUS
-FdoAllocateHole(
+static PMDL
+FdoPciHoleAllocate(
     IN  PXENBUS_FDO         Fdo,
-    IN  ULONG               Count,
-    OUT PVOID               *VirtualAddress OPTIONAL,
-    OUT PPHYSICAL_ADDRESS   PhysicalAddress
+    IN  ULONG               Count
     )
 {
-    PXENBUS_HOLE            Hole = &Fdo->Hole;
+    PXENBUS_PCI_HOLE        Hole = &Fdo->PciHole;
     LONGLONG                Index;
+    PVOID                   VirtualAddress;
+    PHYSICAL_ADDRESS        PhysicalAddress;
+    PMDL                    Mdl;
+    PPFN_NUMBER             PfnArray;
     NTSTATUS                status;
 
+    BUG_ON(Hole->Count == 0);
+
     status = XENBUS_RANGE_SET(Pop,
                               &Fdo->RangeSetInterface,
                               Hole->RangeSet,
@@ -3429,35 +3352,76 @@ FdoAllocateHole(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    if (VirtualAddress != NULL)
-        *VirtualAddress = (PUCHAR)Hole->VirtualAddress +
-                          (Index << PAGE_SHIFT);
+    VirtualAddress = (PUCHAR)Hole->VirtualAddress + (Index << PAGE_SHIFT);
 
-    PhysicalAddress->QuadPart = Hole->PhysicalAddress.QuadPart +
-                                (Index << PAGE_SHIFT);
+    Mdl = IoAllocateMdl(VirtualAddress,
+                        Count << PAGE_SHIFT,
+                        FALSE,
+                        FALSE,
+                        NULL);
 
-    return STATUS_SUCCESS;;
+    status = STATUS_NO_MEMORY;
+    if (Mdl == NULL)
+        goto fail2;
+
+    ASSERT3P(Mdl->StartVa, ==, VirtualAddress);
+    ASSERT3U(Mdl->ByteCount, ==, Count << PAGE_SHIFT);
+
+    PhysicalAddress.QuadPart = Hole->PhysicalAddress.QuadPart + (Index << PAGE_SHIFT);
+
+    PfnArray = MmGetMdlPfnArray(Mdl);
+    PfnArray[0] = (PFN_NUMBER)(PhysicalAddress.QuadPart >> PAGE_SHIFT);
+
+    for (Index = 0; Index < (LONGLONG)Count; Index++)
+        PfnArray[Index] = PfnArray[0] + (ULONG)Index;
+
+    return Mdl;
+
+fail2:
+    Error("fail2\n");
+
+    (VOID) XENBUS_RANGE_SET(Put,
+                            &Fdo->RangeSetInterface,
+                            Hole->RangeSet,
+                            Index,
+                            Count);
 
 fail1:
     Error("fail1 (%08x)\n", status);
 
-    return status;
+    return NULL;
 }
 
-VOID
-FdoFreeHole(
-    IN  PXENBUS_FDO         Fdo,
-    IN  PHYSICAL_ADDRESS    PhysicalAddress,
-    IN  ULONG               Count
+static VOID
+FdoPciHoleFree(
+    IN  PXENBUS_FDO     Fdo,
+    IN  PMDL            Mdl
     )
 {
-    PXENBUS_HOLE            Hole = &Fdo->Hole;
-    LONGLONG                Index;
-    NTSTATUS                status;
+    PXENBUS_PCI_HOLE    Hole = &Fdo->PciHole;
+    ULONG               Count;
+    PPFN_NUMBER         PfnArray;
+    LONGLONG            Index;
+    PHYSICAL_ADDRESS    PhysicalAddress;
+    NTSTATUS            status;
 
-    Index = PhysicalAddress.QuadPart - Hole->PhysicalAddress.QuadPart;
-    ASSERT3U(Index & (PAGE_SIZE - 1), ==, 0);
-    Index >>= PAGE_SHIFT;
+    BUG_ON(Hole->Count == 0);
+
+    Count = Mdl->ByteCount >> PAGE_SHIFT;
+    ASSERT3U(Count, <, Hole->Count);
+
+    PfnArray = MmGetMdlPfnArray(Mdl);
+
+    // Verify that the PFNs are contiguous
+    for (Index = 0; Index < (LONGLONG)Count; Index++)
+        BUG_ON(PfnArray[Index] != PfnArray[0] + Index);
+
+    PhysicalAddress.QuadPart = PfnArray[0] << PAGE_SHIFT;
+
+    Index = (PhysicalAddress.QuadPart - Hole->PhysicalAddress.QuadPart) >> PAGE_SHIFT;
+
+    ASSERT3U(Index, <, Hole->Count);
+    ASSERT3U(Index + Count, <=, Hole->Count);
 
     status = XENBUS_RANGE_SET(Put,
                               &Fdo->RangeSetInterface,
@@ -3465,34 +3429,91 @@ FdoFreeHole(
                               Index,
                               Count);
     ASSERT(NT_SUCCESS(status));
+
+    ExFreePool(Mdl);
+}
+
+static PMDL
+FdoMemoryHoleAllocate(
+    IN  PXENBUS_FDO     Fdo,
+    IN  ULONG           Count
+    )
+{
+    PMDL                Mdl;
+    PPFN_NUMBER         PfnArray;
+    NTSTATUS            status;
+
+    UNREFERENCED_PARAMETER(Fdo);
+
+    Mdl = __AllocatePages(Count, TRUE);
+
+    status = STATUS_NO_MEMORY;
+    if (Mdl == NULL)
+        goto fail1;
+
+    PfnArray = MmGetMdlPfnArray(Mdl);
+
+    status = STATUS_UNSUCCESSFUL;
+    if (MemoryDecreaseReservation(PAGE_ORDER_4K, Count, PfnArray) != Count)
+        goto fail2;
+
+    return Mdl;
+
+fail2:
+    Error("fail2\n");
+
+    __FreePages(Mdl);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return NULL;
 }
 
 static VOID
-FdoDestroyHole(
-    IN  PXENBUS_FDO Fdo
+FdoMemoryHoleFree(
+    IN  PXENBUS_FDO     Fdo,
+    IN  PMDL            Mdl
     )
 {
-    PXENBUS_HOLE    Hole = &Fdo->Hole;
-    NTSTATUS        status;
+    ULONG               Count;
+    PPFN_NUMBER         PfnArray;
 
-    status = XENBUS_RANGE_SET(Get,
-                              &Fdo->RangeSetInterface,
-                              Hole->RangeSet,
-                              0,
-                              Hole->Count);
-    ASSERT(NT_SUCCESS(status));
+    UNREFERENCED_PARAMETER(Fdo);
 
-    if (Fdo->Mdl != NULL)
-        __FdoDestroyMemoryHole(Fdo);
-    else
-        __FdoDestroyPciHole(Fdo);
+    Count = Mdl->ByteCount >> PAGE_SHIFT;
+    PfnArray = MmGetMdlPfnArray(Mdl);
 
-    XENBUS_RANGE_SET(Destroy,
-                     &Fdo->RangeSetInterface,
-                     Hole->RangeSet);
-    Hole->RangeSet = NULL;
+    if (MemoryPopulatePhysmap(PAGE_ORDER_4K, Count, PfnArray) != Count)
+        BUG("FAILED TO RE-POPULATE HOLE");
+
+    __FreePages(Mdl);
 }
 
+PMDL
+FdoHoleAllocate(
+    IN  PXENBUS_FDO Fdo,
+    IN  ULONG       Count
+    )
+{
+    return (Fdo->UseMemoryHole != 0) ?
+        FdoMemoryHoleAllocate(Fdo, Count) :
+        FdoPciHoleAllocate(Fdo, Count);
+}
+
+VOID
+FdoHoleFree(
+    IN  PXENBUS_FDO Fdo,
+    IN  PMDL        Mdl
+    )
+{
+    if (Fdo->UseMemoryHole != 0)
+        FdoMemoryHoleFree(Fdo, Mdl);
+    else
+        FdoPciHoleFree(Fdo, Mdl);
+}
+
+
 static VOID
 FdoDebugCallback(
     IN  PVOID   Argument,
@@ -3566,10 +3587,11 @@ FdoD3ToD0(
     if (!NT_SUCCESS(status))
         goto fail3;
 
-    // Subsequent interfaces require use of BAR space
-    status = FdoCreateHole(Fdo);
-    if (!NT_SUCCESS(status))
-        goto fail4;
+    if (Fdo->UseMemoryHole == 0) {
+        status = FdoPciHoleCreate(Fdo);
+        if (!NT_SUCCESS(status))
+            goto fail4;
+    }
 
     status = XENBUS_EVTCHN(Acquire, &Fdo->EvtchnInterface);
     if (!NT_SUCCESS(status))
@@ -3677,7 +3699,8 @@ fail6:
 fail5:
     Error("fail5\n");
 
-    FdoDestroyHole(Fdo);
+    if (Fdo->UseMemoryHole == 0)
+        FdoPciHoleDestroy(Fdo);
 
 fail4:
     Error("fail4\n");
@@ -3800,7 +3823,8 @@ FdoD0ToD3(
 
     XENBUS_EVTCHN(Release, &Fdo->EvtchnInterface);
 
-    FdoDestroyHole(Fdo);
+    if (Fdo->UseMemoryHole == 0)
+        FdoPciHoleDestroy(Fdo);
 
     XENBUS_RANGE_SET(Release, &Fdo->RangeSetInterface);
 
@@ -5605,107 +5629,6 @@ fail1:
                       (_Size),                                                          \
                       (_Optional))
 
-
-#define FDO_HOLE_SIZE   (2ull << 20)
-
-static FORCEINLINE NTSTATUS
-__FdoAllocateBuffer(
-    IN  PXENBUS_FDO     Fdo
-    )
-{
-    HANDLE              ParametersKey;
-    ULONG               UseMemoryHole;
-    ULONG               Count;
-    ULONG               Size;
-    PHYSICAL_ADDRESS    Low;
-    PHYSICAL_ADDRESS    High;
-    PHYSICAL_ADDRESS    Align;
-    PVOID               Buffer;
-    PMDL                Mdl;
-    NTSTATUS            status;
-
-    ParametersKey = DriverGetParametersKey();
-
-    status = RegistryQueryDwordValue(ParametersKey,
-                                     "UseMemoryHole",
-                                     &UseMemoryHole);
-    if (!NT_SUCCESS(status))
-        UseMemoryHole = 1;
-
-    ASSERT(Fdo->Mdl == NULL);
-    if (UseMemoryHole == 0)
-        goto done;
-
-    Count = 1u << PAGE_ORDER_2M;
-    Size = Count << PAGE_SHIFT;
-
-    Low.QuadPart = 0;
-    High = SystemMaximumPhysicalAddress();
-    Align.QuadPart = Size;
-
-    Buffer = MmAllocateContiguousNodeMemory((SIZE_T)Size,
-                                            Low,
-                                            High,
-                                            Align,
-                                            PAGE_READWRITE,
-                                            MM_ANY_NODE_OK);
-
-    status = STATUS_NO_MEMORY;
-    if (Buffer == NULL)
-        goto fail1;
-
-    Mdl = IoAllocateMdl(Buffer,
-                        Size,
-                        FALSE,
-                        FALSE,
-                        NULL);
-
-    status = STATUS_NO_MEMORY;
-    if (Mdl == NULL)
-        goto fail2;
-
-    MmBuildMdlForNonPagedPool(Mdl);
-
-    ASSERT3U(Mdl->ByteOffset, ==, 0);
-    ASSERT3U(Mdl->ByteCount, ==, Size);
-
-    Fdo->Mdl = Mdl;
-
-done:
-    return STATUS_SUCCESS;
-
-fail2:
-    Error("fail2\n");
-
-    MmFreeContiguousMemory(Buffer);
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    return status;
-}
-
-static FORCEINLINE VOID
-__FdoFreeBuffer(
-    IN  PXENBUS_FDO Fdo
-    )
-{
-    PMDL            Mdl;
-    PVOID           Buffer;
-
-    Mdl = Fdo->Mdl;
-    if (Mdl == NULL)
-        return;
-
-    Fdo->Mdl = NULL;
-
-    Buffer = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
-
-    ExFreePool(Mdl);
-
-    MmFreeContiguousMemory(Buffer);
-}
-
 static NTSTATUS
 FdoBalloonInitialize(
     IN  PXENBUS_FDO Fdo
@@ -5790,6 +5713,8 @@ FdoCreate(
     PXENBUS_DX                  Dx;
     PXENBUS_FDO                 Fdo;
     PCI_COMMON_HEADER           Header;
+    HANDLE                      ParametersKey;
+    ULONG                       UseMemoryHole;
     NTSTATUS                    status;
 
 #pragma prefast(suppress:28197) // Possibly leaking memory 'FunctionDeviceObject'
@@ -5857,53 +5782,59 @@ FdoCreate(
     if (!__FdoIsActive(Fdo))
         goto done;
 
-    status = __FdoAllocateBuffer(Fdo);
+    ParametersKey = DriverGetParametersKey();
+
+    status = RegistryQueryDwordValue(ParametersKey,
+                                     "UseMemoryHole",
+                                     &UseMemoryHole);
     if (!NT_SUCCESS(status))
-        goto fail9;
+        UseMemoryHole = 1;
+
+    Fdo->UseMemoryHole = UseMemoryHole;
 
     status = DebugInitialize(Fdo, &Fdo->DebugContext);
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail9;
 
     status = SuspendInitialize(Fdo, &Fdo->SuspendContext);
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail10;
 
     status = SharedInfoInitialize(Fdo, &Fdo->SharedInfoContext);
     if (!NT_SUCCESS(status))
-        goto fail12;
+        goto fail11;
 
     status = EvtchnInitialize(Fdo, &Fdo->EvtchnContext);
     if (!NT_SUCCESS(status))
-        goto fail13;
+        goto fail12;
 
     status = RangeSetInitialize(Fdo, &Fdo->RangeSetContext);
     if (!NT_SUCCESS(status))
-        goto fail14;
+        goto fail13;
 
     status = CacheInitialize(Fdo, &Fdo->CacheContext);
     if (!NT_SUCCESS(status))
-        goto fail15;
+        goto fail14;
 
     status = GnttabInitialize(Fdo, &Fdo->GnttabContext);
     if (!NT_SUCCESS(status))
-        goto fail16;
+        goto fail15;
 
     status = StoreInitialize(Fdo, &Fdo->StoreContext);
     if (!NT_SUCCESS(status))
-        goto fail17;
+        goto fail16;
 
     status = ConsoleInitialize(Fdo, &Fdo->ConsoleContext);
     if (!NT_SUCCESS(status))
-        goto fail18;
+        goto fail17;
 
     status = UnplugInitialize(Fdo, &Fdo->UnplugContext);
     if (!NT_SUCCESS(status))
-        goto fail19;
+        goto fail18;
 
     status = FdoBalloonInitialize(Fdo);
     if (!NT_SUCCESS(status))
-        goto fail20;
+        goto fail19;
 
     status = DebugGetInterface(__FdoGetDebugContext(Fdo),
                                XENBUS_DEBUG_INTERFACE_VERSION_MAX,
@@ -5974,74 +5905,71 @@ done:
 
     return STATUS_SUCCESS;
 
-fail20:
-    Error("fail20\n");
-
-    UnplugTeardown(Fdo->UnplugContext);
-    Fdo->UnplugContext = NULL;
-
 fail19:
     Error("fail19\n");
 
-    ConsoleTeardown(Fdo->ConsoleContext);
-    Fdo->ConsoleContext = NULL;
+    UnplugTeardown(Fdo->UnplugContext);
+    Fdo->UnplugContext = NULL;
 
 fail18:
     Error("fail18\n");
 
-    StoreTeardown(Fdo->StoreContext);
-    Fdo->StoreContext = NULL;
+    ConsoleTeardown(Fdo->ConsoleContext);
+    Fdo->ConsoleContext = NULL;
 
 fail17:
     Error("fail17\n");
 
-    GnttabTeardown(Fdo->GnttabContext);
-    Fdo->GnttabContext = NULL;
+    StoreTeardown(Fdo->StoreContext);
+    Fdo->StoreContext = NULL;
 
 fail16:
     Error("fail16\n");
 
-    CacheTeardown(Fdo->CacheContext);
-    Fdo->CacheContext = NULL;
+    GnttabTeardown(Fdo->GnttabContext);
+    Fdo->GnttabContext = NULL;
 
 fail15:
     Error("fail15\n");
 
-    RangeSetTeardown(Fdo->RangeSetContext);
-    Fdo->RangeSetContext = NULL;
+    CacheTeardown(Fdo->CacheContext);
+    Fdo->CacheContext = NULL;
 
 fail14:
     Error("fail14\n");
 
-    EvtchnTeardown(Fdo->EvtchnContext);
-    Fdo->EvtchnContext = NULL;
+    RangeSetTeardown(Fdo->RangeSetContext);
+    Fdo->RangeSetContext = NULL;
 
 fail13:
     Error("fail13\n");
 
-    SharedInfoTeardown(Fdo->SharedInfoContext);
-    Fdo->SharedInfoContext = NULL;
+    EvtchnTeardown(Fdo->EvtchnContext);
+    Fdo->EvtchnContext = NULL;
 
 fail12:
     Error("fail12\n");
 
-    SuspendTeardown(Fdo->SuspendContext);
-    Fdo->SuspendContext = NULL;
+    SharedInfoTeardown(Fdo->SharedInfoContext);
+    Fdo->SharedInfoContext = NULL;
 
 fail11:
     Error("fail11\n");
 
-    DebugTeardown(Fdo->DebugContext);
-    Fdo->DebugContext = NULL;
+    SuspendTeardown(Fdo->SuspendContext);
+    Fdo->SuspendContext = NULL;
 
 fail10:
     Error("fail10\n");
 
-    __FdoFreeBuffer(Fdo);
+    DebugTeardown(Fdo->DebugContext);
+    Fdo->DebugContext = NULL;
 
 fail9:
     Error("fail9\n");
 
+    Fdo->UseMemoryHole = 0;
+
     //
     // We don't want to call DriverClearActive() so just
     // clear the FDO flag.
@@ -6180,7 +6108,7 @@ FdoDestroy(
         DebugTeardown(Fdo->DebugContext);
         Fdo->DebugContext = NULL;
 
-        __FdoFreeBuffer(Fdo);
+        Fdo->UseMemoryHole = 0;
 
         FdoClearActive(Fdo);
     }
diff --git a/src/xenbus/fdo.h b/src/xenbus/fdo.h
index a58526ab5bb2..f2ec88c637ca 100644
--- a/src/xenbus/fdo.h
+++ b/src/xenbus/fdo.h
@@ -132,19 +132,16 @@ FdoGetName(
     IN  PXENBUS_FDO Fdo
     );
 
-extern NTSTATUS
-FdoAllocateHole(
-    IN  PXENBUS_FDO         Fdo,
-    IN  ULONG               Count,
-    OUT PVOID               *VirtualAddress OPTIONAL,
-    OUT PPHYSICAL_ADDRESS   PhysicalAddress
+extern PMDL
+FdoHoleAllocate(
+    IN  PXENBUS_FDO Fdo,
+    IN  ULONG       Count
     );
 
 extern VOID
-FdoFreeHole(
-    IN  PXENBUS_FDO         Fdo,
-    IN  PHYSICAL_ADDRESS    PhysicalAddress,
-    IN  ULONG               Count
+FdoHoleFree(
+    IN  PXENBUS_FDO Fdo,
+    IN  PMDL        Mdl
     );
 
 // Disable erroneous SAL warnings around use of interrupt locks
diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index af562608b40d..5929270a7793 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -70,7 +70,7 @@ struct _XENBUS_GNTTAB_ENTRY {
 };
 
 typedef struct _XENBUS_GNTTAB_MAP_ENTRY {
-    ULONG   NumberPages;
+    PMDL    Mdl;
     ULONG   MapHandles[1];
 } XENBUS_GNTTAB_MAP_ENTRY, *PXENBUS_GNTTAB_MAP_ENTRY;
 
@@ -79,7 +79,7 @@ struct _XENBUS_GNTTAB_CONTEXT {
     KSPIN_LOCK                  Lock;
     LONG                        References;
     ULONG                       MaximumFrameCount;
-    PHYSICAL_ADDRESS            Address;
+    PMDL                        Mdl;
     LONG                        FrameIndex;
     grant_entry_v1_t            *Table;
     XENBUS_RANGE_SET_INTERFACE  RangeSetInterface;
@@ -129,7 +129,7 @@ GnttabExpand(
     if (Index == Context->MaximumFrameCount)
         goto fail1;
 
-    Address = Context->Address;
+    Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
     Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
 
     status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT),
@@ -187,7 +187,7 @@ GnttabMap(
     for (Index = 0; Index <= Context->FrameIndex; Index++) {
         PHYSICAL_ADDRESS    Address;
 
-        Address = Context->Address;
+        Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
         Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
 
         status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT),
@@ -213,7 +213,7 @@ GnttabUnmap(
     for (Index = Context->FrameIndex; Index >= 0; --Index) {
         PHYSICAL_ADDRESS    Address;
 
-        Address = Context->Address;
+        Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
         Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
 
         (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT));
@@ -615,16 +615,16 @@ GnttabMapForeignPages(
     )
 {
     PXENBUS_GNTTAB_CONTEXT      Context = Interface->Context;
+    PMDL                        Mdl;
     LONG                        PageIndex;
     PHYSICAL_ADDRESS            PageAddress;
     PXENBUS_GNTTAB_MAP_ENTRY    MapEntry;
     NTSTATUS                    status;
 
-    status = FdoAllocateHole(Context->Fdo,
-                             NumberPages,
-                             NULL,
-                             Address);
-    if (!NT_SUCCESS(status))
+    Mdl = FdoHoleAllocate(Context->Fdo, NumberPages);
+
+    status = STATUS_NO_MEMORY;
+    if (Mdl == NULL)
         goto fail1;
 
     MapEntry = __GnttabAllocate(FIELD_OFFSET(XENBUS_GNTTAB_MAP_ENTRY,
@@ -635,8 +635,10 @@ GnttabMapForeignPages(
     if (MapEntry == NULL)
         goto fail2;
 
+    MapEntry->Mdl = Mdl;
+
+    Address->QuadPart = MmGetMdlPfnArray(Mdl)[0] << PAGE_SHIFT;
     PageAddress.QuadPart = Address->QuadPart;
-    MapEntry->NumberPages = NumberPages;
 
     for (PageIndex = 0; PageIndex < (LONG)NumberPages; PageIndex++) {
         status = GrantTableMapForeignPage(Domain,
@@ -670,12 +672,14 @@ fail3:
                                           PageAddress);
     }
 
+    Address->QuadPart = 0;
+
     __GnttabFree(MapEntry);
 
 fail2:
     Error("fail2\n");
 
-    FdoFreeHole(Context->Fdo, *Address, NumberPages);
+    FdoHoleFree(Context->Fdo, Mdl);
 
 fail1:
     Error("fail1: (%08x)\n", status);
@@ -690,9 +694,11 @@ GnttabUnmapForeignPages(
     )
 {
     PXENBUS_GNTTAB_CONTEXT      Context = Interface->Context;
-    ULONG                       PageIndex;
+    ULONG                       NumberPages;
     PHYSICAL_ADDRESS            PageAddress;
+    ULONG                       PageIndex;
     PXENBUS_GNTTAB_MAP_ENTRY    MapEntry;
+    PMDL                        Mdl;
     NTSTATUS                    status;
 
     status = HashTableLookup(Context->MapTable,
@@ -708,7 +714,10 @@ GnttabUnmapForeignPages(
 
     PageAddress.QuadPart = Address.QuadPart;
 
-    for (PageIndex = 0; PageIndex < MapEntry->NumberPages; PageIndex++) {
+    Mdl = MapEntry->Mdl;
+    NumberPages = Mdl->ByteCount >> PAGE_SHIFT;
+
+    for (PageIndex = 0; PageIndex < NumberPages; PageIndex++) {
         status = GrantTableUnmapForeignPage(MapEntry->MapHandles[PageIndex],
                                             PageAddress);
         BUG_ON(!NT_SUCCESS(status));
@@ -716,12 +725,10 @@ GnttabUnmapForeignPages(
         PageAddress.QuadPart += PAGE_SIZE;
     }
 
-    FdoFreeHole(Context->Fdo,
-                Address,
-                MapEntry->NumberPages);
-
     __GnttabFree(MapEntry);
 
+    FdoHoleFree(Context->Fdo, Mdl);
+
     return STATUS_SUCCESS;
 
 fail2:
@@ -750,14 +757,17 @@ GnttabDebugCallback(
     )
 {
     PXENBUS_GNTTAB_CONTEXT  Context = Argument;
+    PHYSICAL_ADDRESS        Address;
 
     UNREFERENCED_PARAMETER(Crashing);
 
+    Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
+
     XENBUS_DEBUG(Printf,
                  &Context->DebugInterface,
                  "Address = %08x.%08x\n",
-                 Context->Address.HighPart,
-                 Context->Address.LowPart);
+                 Address.HighPart,
+                 Address.LowPart);
     
     XENBUS_DEBUG(Printf,
                  &Context->DebugInterface,
@@ -790,13 +800,13 @@ GnttabAcquire(
               "GNTTAB: MAX FRAMES = %u\n",
               Context->MaximumFrameCount);
 
-    status = FdoAllocateHole(Fdo,
-                             Context->MaximumFrameCount,
-                             &Context->Table,
-                             &Context->Address);
-    if (!NT_SUCCESS(status))
+    Context->Mdl = FdoHoleAllocate(Fdo, Context->MaximumFrameCount);
+
+    status = STATUS_NO_MEMORY;
+    if (Context->Mdl == NULL)
         goto fail2;
 
+    Context->Table = Context->Mdl->StartVa;
     Context->FrameIndex = -1;
 
     status = XENBUS_RANGE_SET(Acquire, &Context->RangeSetInterface);
@@ -894,7 +904,6 @@ fail5:
                      Context->RangeSet);
     Context->RangeSet = NULL;
 
-    Context->FrameIndex = 0;
 
 fail4:
     Error("fail4\n");
@@ -904,12 +913,12 @@ fail4:
 fail3:
     Error("fail3\n");
 
-    FdoFreeHole(Fdo,
-                Context->Address,
-                Context->MaximumFrameCount);
-    Context->Address.QuadPart = 0;
+    Context->FrameIndex = 0;
     Context->Table = NULL;
 
+    FdoHoleFree(Fdo, Context->Mdl);
+    Context->Mdl = NULL;
+
 fail2:
     Error("fail2\n");
 
@@ -968,16 +977,14 @@ GnttabRelease(
                      Context->RangeSet);
     Context->RangeSet = NULL;
 
-    Context->FrameIndex = 0;
-
     XENBUS_RANGE_SET(Release, &Context->RangeSetInterface);
 
-    FdoFreeHole(Fdo,
-                Context->Address,
-                Context->MaximumFrameCount);
-    Context->Address.QuadPart = 0;
+    Context->FrameIndex = 0;
     Context->Table = NULL;
 
+    FdoHoleFree(Fdo, Context->Mdl);
+    Context->Mdl = NULL;
+
     Context->MaximumFrameCount = 0;
 
     Trace("<====\n");
diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c
index f25e12a1c689..dc456ebcbf83 100644
--- a/src/xenbus/shared_info.c
+++ b/src/xenbus/shared_info.c
@@ -53,7 +53,7 @@ struct _XENBUS_SHARED_INFO_CONTEXT {
     PXENBUS_FDO                     Fdo;
     KSPIN_LOCK                      Lock;
     LONG                            References;
-    PHYSICAL_ADDRESS                Address;
+    PMDL                            Mdl;
     shared_info_t                   *Shared;
     PXENBUS_SHARED_INFO_PROCESSOR   Processor;
     ULONG                           ProcessorCount;
@@ -459,17 +459,21 @@ SharedInfoMap(
     IN  PXENBUS_SHARED_INFO_CONTEXT Context
     )
 {
+    PFN_NUMBER                      Pfn;
+    PHYSICAL_ADDRESS                Address;
     NTSTATUS                        status;
 
-    status = MemoryAddToPhysmap((PFN_NUMBER)(Context->Address.QuadPart >> PAGE_SHIFT),
-                                XENMAPSPACE_shared_info,
-                                0);
+    Pfn = MmGetMdlPfnArray(Context->Mdl)[0];
+
+    status = MemoryAddToPhysmap(Pfn, XENMAPSPACE_shared_info, 0);
     ASSERT(NT_SUCCESS(status));
 
+    Address.QuadPart = Pfn << PAGE_SHIFT;
+
     LogPrintf(LOG_LEVEL_INFO,
               "SHARED_INFO: MAP XENMAPSPACE_shared_info @ %08x.%08x\n",
-              Context->Address.HighPart,
-              Context->Address.LowPart);
+              Address.HighPart,
+              Address.LowPart);
 }
 
 static VOID
@@ -477,11 +481,14 @@ SharedInfoUnmap(
     IN  PXENBUS_SHARED_INFO_CONTEXT Context
     )
 {
+    PFN_NUMBER                      Pfn;
+
     LogPrintf(LOG_LEVEL_INFO,
               "SHARED_INFO: UNMAP XENMAPSPACE_shared_info\n");
 
+    Pfn = MmGetMdlPfnArray(Context->Mdl)[0];
 
-    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Context->Address.QuadPart >> PAGE_SHIFT));
+    (VOID) MemoryRemoveFromPhysmap(Pfn);
 }
 
 static VOID
@@ -502,12 +509,17 @@ SharedInfoDebugCallback(
     )
 {
     PXENBUS_SHARED_INFO_CONTEXT Context = Argument;
+    PFN_NUMBER                  Pfn;
+    PHYSICAL_ADDRESS            Address;
+
+    Pfn = MmGetMdlPfnArray(Context->Mdl)[0];
+    Address.QuadPart = Pfn << PAGE_SHIFT;
 
     XENBUS_DEBUG(Printf,
                  &Context->DebugInterface,
                  "Address = %08x.%08x\n",
-                 Context->Address.HighPart,
-                 Context->Address.LowPart);
+                 Address.HighPart,
+                 Address.LowPart);
 
     if (!Crashing) {
         shared_info_t   *Shared;
@@ -593,10 +605,14 @@ SharedInfoAcquire(
 
     Trace("====>\n");
 
-    status = FdoAllocateHole(Fdo, 1, &Context->Shared, &Context->Address);
-    if (!NT_SUCCESS(status))
+    Context->Mdl = FdoHoleAllocate(Fdo, 1);
+
+    status = STATUS_NO_MEMORY;
+    if (Context->Mdl == NULL)
         goto fail1;
 
+    Context->Shared = Context->Mdl->StartVa;
+
     SharedInfoMap(Context);
     SharedInfoEvtchnMaskAll(Context);
 
@@ -715,10 +731,11 @@ fail2:
 
     SharedInfoUnmap(Context);
 
-    FdoFreeHole(Fdo, Context->Address, 1);
-    Context->Address.QuadPart = 0;
     Context->Shared = NULL;
 
+    FdoHoleFree(Fdo, Context->Mdl);
+    Context->Mdl = NULL;
+
 fail1:
     Error("fail1 (%08x)\n", status);
 
@@ -777,10 +794,11 @@ SharedInfoRelease (
 
     SharedInfoUnmap(Context);
 
-    FdoFreeHole(Fdo, Context->Address, 1);
-    Context->Address.QuadPart = 0;
     Context->Shared = NULL;
 
+    FdoHoleFree(Fdo, Context->Mdl);
+    Context->Mdl = NULL;
+
     Trace("<====\n");
 
 done:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Wed Jul 12 15:52:07 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 12 Jul 2023 15:52:07 +0000
Received: from list by lists.xenproject.org with outflank-mailman.562619.879375 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qJc8M-0003In-Le; Wed, 12 Jul 2023 15:52:06 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 562619.879375; Wed, 12 Jul 2023 15:52: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 1qJc8M-0003IW-GV; Wed, 12 Jul 2023 15:52:06 +0000
Received: by outflank-mailman (input) for mailman id 562619;
 Wed, 12 Jul 2023 15:52:05 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qJc8L-0003IE-J1
 for win-pv-devel@lists.xenproject.org; Wed, 12 Jul 2023 15:52:05 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8L-0003ct-H7; Wed, 12 Jul 2023 15:52:05 +0000
Received: from 54-240-197-227.amazon.com ([54.240.197.227]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8L-0001nO-8A; Wed, 12 Jul 2023 15:52:05 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References:
	In-Reply-To:Message-Id:Date:Subject:Cc:To:From;
	bh=3BGjzFRQiCn9bEA1LOrJqvXnI5VZIfPSh1updOIiOI8=; b=apNBRjPUUbh7/4Dz3gi4JkpflN
	BGj/gvTkNAuPaj/6Vtyy0aAfr5MW6v4O0+1wMcmOtWc3YiLPWqXAChmVk05KtAlkUgMry72lry2bZ
	UhAKDZ42q0li5MMDKv4NtWdbMHEutjeHl/p2/1siCWRHKCgkBcuqtw+fOBLAD9hM44QU=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 3/3] Don't rely on contiguous grant table
Date: Wed, 12 Jul 2023 16:52:00 +0100
Message-Id: <20230712155200.1348-3-paul@xen.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20230712155200.1348-1-paul@xen.org>
References: <20230712155200.1348-1-paul@xen.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

If the size of the grant table is large then it may not be possible to
get sufficient contiguous memory to cover it. However, there's no
actual need for the entire grant table to be physically contiguous, or
even virtually contiguous, so allocate space from the hole as the table
is expanded rather than doing a single up-front allocation.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 src/xenbus/gnttab.c | 162 ++++++++++++++++++++++++++++----------------
 1 file changed, 103 insertions(+), 59 deletions(-)

diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 5929270a7793..4f6617b42cbf 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -74,14 +74,18 @@ typedef struct _XENBUS_GNTTAB_MAP_ENTRY {
     ULONG   MapHandles[1];
 } XENBUS_GNTTAB_MAP_ENTRY, *PXENBUS_GNTTAB_MAP_ENTRY;
 
+typedef struct _XENBUS_GNTTAB_FRAME {
+    PMDL                        Mdl;
+    grant_entry_v1_t            *Entry;
+} XENBUS_GNTTAB_FRAME, *PXENBUS_GNTTAB_FRAME;
+
 struct _XENBUS_GNTTAB_CONTEXT {
     PXENBUS_FDO                 Fdo;
     KSPIN_LOCK                  Lock;
     LONG                        References;
     ULONG                       MaximumFrameCount;
-    PMDL                        Mdl;
+    PXENBUS_GNTTAB_FRAME        Frame;
     LONG                        FrameIndex;
-    grant_entry_v1_t            *Table;
     XENBUS_RANGE_SET_INTERFACE  RangeSetInterface;
     PXENBUS_RANGE_SET           RangeSet;
     XENBUS_CACHE_INTERFACE      CacheInterface;
@@ -117,6 +121,8 @@ GnttabExpand(
     )
 {
     ULONG                       Index;
+    PXENBUS_GNTTAB_FRAME        Frame;
+    PFN_NUMBER                  Pfn;
     PHYSICAL_ADDRESS            Address;
     LONGLONG                    Start;
     LONGLONG                    End;
@@ -129,15 +135,23 @@ GnttabExpand(
     if (Index == Context->MaximumFrameCount)
         goto fail1;
 
-    Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
-    Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+    Frame = &Context->Frame[Index];
+    Frame->Mdl = FdoHoleAllocate(Context->Fdo, 1);
 
-    status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT),
-                                XENMAPSPACE_grant_table,
-                                Index);
-    if (!NT_SUCCESS(status))
+    status = STATUS_NO_MEMORY;
+    if (Frame->Mdl == NULL)
         goto fail2;
 
+    Frame->Entry = Frame->Mdl->StartVa;
+
+    Pfn = MmGetMdlPfnArray(Frame->Mdl)[0];
+
+    status = MemoryAddToPhysmap(Pfn, XENMAPSPACE_grant_table, Index);
+    if (!NT_SUCCESS(status))
+        goto fail3;
+
+    Address.QuadPart = Pfn << PAGE_SHIFT;
+
     LogPrintf(LOG_LEVEL_INFO,
               "GNTTAB: MAP XENMAPSPACE_grant_table[%d] @ %08x.%08x\n",
               Index,
@@ -154,16 +168,24 @@ GnttabExpand(
                               Start,
                               End + 1 - Start);
     if (!NT_SUCCESS(status))
-        goto fail3;
+        goto fail4;
 
     Info("added references [%08llx - %08llx]\n", Start, End);
 
     return STATUS_SUCCESS;
 
+fail4:
+    Error("fail4\n");
+
+    (VOID) MemoryRemoveFromPhysmap(Pfn);
+
 fail3:
     Error("fail3\n");
 
-    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT));
+    Frame->Entry = NULL;
+
+    FdoHoleFree(Context->Fdo, Frame->Mdl);
+    Frame->Mdl = NULL;
 
 fail2:
     Error("fail2\n");
@@ -185,16 +207,17 @@ GnttabMap(
     NTSTATUS                    status;
 
     for (Index = 0; Index <= Context->FrameIndex; Index++) {
-        PHYSICAL_ADDRESS    Address;
+        PXENBUS_GNTTAB_FRAME    Frame = &Context->Frame[Index];
+        PFN_NUMBER              Pfn;
+        PHYSICAL_ADDRESS        Address;
 
-        Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
-        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+        Pfn = MmGetMdlPfnArray(Frame->Mdl)[0];
 
-        status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT),
-                                    XENMAPSPACE_grant_table,
-                                    Index);
+        status = MemoryAddToPhysmap(Pfn, XENMAPSPACE_grant_table, Index);
         ASSERT(NT_SUCCESS(status));
 
+        Address.QuadPart = Pfn << PAGE_SHIFT;
+
         LogPrintf(LOG_LEVEL_INFO,
                   "GNTTAB: MAP XENMAPSPACE_grant_table[%d] @ %08x.%08x\n",
                   Index,
@@ -211,12 +234,12 @@ GnttabUnmap(
     LONG                        Index;
 
     for (Index = Context->FrameIndex; Index >= 0; --Index) {
-        PHYSICAL_ADDRESS    Address;
+        PXENBUS_GNTTAB_FRAME    Frame = &Context->Frame[Index];
+        PFN_NUMBER              Pfn;
 
-        Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
-        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+        Pfn = MmGetMdlPfnArray(Frame->Mdl)[0];
 
-        (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT));
+        (VOID) MemoryRemoveFromPhysmap(Pfn);
 
         LogPrintf(LOG_LEVEL_INFO,
                   "GNTTAB: UNMAP XENMAPSPACE_grant_table[%d]\n",
@@ -229,16 +252,18 @@ GnttabContract(
     IN  PXENBUS_GNTTAB_CONTEXT  Context
     )
 {
+    LONG                        Index;
     NTSTATUS                    status;
 
-    GnttabUnmap(Context);
-
-    if (Context->FrameIndex >= 0) {
-        LONGLONG    Start;
-        LONGLONG    End;
+    for (Index = Context->FrameIndex; Index >= 0; --Index) {
+        PXENBUS_GNTTAB_FRAME    Frame = &Context->Frame[Index];
+        LONGLONG                Start;
+        LONGLONG                End;
+        PFN_NUMBER              Pfn;
 
-        Start = XENBUS_GNTTAB_RESERVED_ENTRY_COUNT;
-        End = ((Context->FrameIndex + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME) - 1;
+        Start = __max(XENBUS_GNTTAB_RESERVED_ENTRY_COUNT,
+                      Index * XENBUS_GNTTAB_ENTRY_PER_FRAME);
+        End = ((Index + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME) - 1;
 
         status = XENBUS_RANGE_SET(Get,
                                   &Context->RangeSetInterface,
@@ -248,6 +273,15 @@ GnttabContract(
         ASSERT(NT_SUCCESS(status));
 
         Info("removed refrences [%08llx - %08llx]\n", Start, End);
+
+        Pfn = MmGetMdlPfnArray(Frame->Mdl)[0];
+
+        (VOID) MemoryRemoveFromPhysmap(Pfn);
+
+        Frame->Entry = NULL;
+
+        FdoHoleFree(Context->Fdo, Frame->Mdl);
+        Frame->Mdl = NULL;
     }
 
     Context->FrameIndex = -1;
@@ -473,6 +507,8 @@ GnttabPermitForeignAccess(
     )
 {
     PXENBUS_GNTTAB_CONTEXT      Context = Interface->Context;
+    PXENBUS_GNTTAB_FRAME        Frame;
+    ULONG                       Index;
     NTSTATUS                    status;
 
     *Entry = XENBUS_CACHE(Get,
@@ -484,16 +520,22 @@ GnttabPermitForeignAccess(
     if (*Entry == NULL)
         goto fail1;
 
+    ASSERT3U((*Entry)->Reference, >=, XENBUS_GNTTAB_RESERVED_ENTRY_COUNT);
+    ASSERT3U((*Entry)->Reference, <, (Context->FrameIndex + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME);
+
     (*Entry)->Entry.flags = (ReadOnly) ? GTF_readonly : 0;
     (*Entry)->Entry.domid = Domain;
 
     (*Entry)->Entry.frame = (uint32_t)Pfn;
     ASSERT3U((*Entry)->Entry.frame, ==, Pfn);
 
-    Context->Table[(*Entry)->Reference] = (*Entry)->Entry;
+    Frame = &Context->Frame[(*Entry)->Reference / XENBUS_GNTTAB_ENTRY_PER_FRAME];
+    Index = (*Entry)->Reference % XENBUS_GNTTAB_ENTRY_PER_FRAME;
+
+    Frame->Entry[Index] = (*Entry)->Entry;
     KeMemoryBarrier();
 
-    Context->Table[(*Entry)->Reference].flags |= GTF_permit_access;
+    Frame->Entry[Index].flags |= GTF_permit_access;
     KeMemoryBarrier();
 
     return STATUS_SUCCESS;
@@ -513,6 +555,8 @@ GnttabRevokeForeignAccess(
     )
 {
     PXENBUS_GNTTAB_CONTEXT      Context = Interface->Context;
+    PXENBUS_GNTTAB_FRAME        Frame;
+    ULONG                       Index;
     volatile SHORT              *flags;
     ULONG                       Attempt;
     NTSTATUS                    status;
@@ -521,7 +565,10 @@ GnttabRevokeForeignAccess(
     ASSERT3U(Entry->Reference, >=, XENBUS_GNTTAB_RESERVED_ENTRY_COUNT);
     ASSERT3U(Entry->Reference, <, (Context->FrameIndex + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME);
 
-    flags = (volatile SHORT *)&Context->Table[Entry->Reference].flags;
+    Frame = &Context->Frame[Entry->Reference / XENBUS_GNTTAB_ENTRY_PER_FRAME];
+    Index = Entry->Reference % XENBUS_GNTTAB_ENTRY_PER_FRAME;
+
+    flags = (volatile SHORT *)&Frame->Entry[Index].flags;
 
     Attempt = 0;
     while (Attempt++ < 100) {
@@ -543,10 +590,8 @@ GnttabRevokeForeignAccess(
     if (Attempt == 100)
         goto fail1;
 
-    RtlZeroMemory(&Context->Table[Entry->Reference],
-                  sizeof (grant_entry_v1_t));
-    RtlZeroMemory(&Entry->Entry,
-                  sizeof (grant_entry_v1_t));
+    RtlZeroMemory(&Frame->Entry[Index], sizeof (grant_entry_v1_t));
+    RtlZeroMemory(&Entry->Entry, sizeof (grant_entry_v1_t));
 
     XENBUS_CACHE(Put,
                  &Context->CacheInterface,
@@ -584,17 +629,22 @@ GnttabQueryReference(
     )
 {
     PXENBUS_GNTTAB_CONTEXT  Context = Interface->Context;
+    PXENBUS_GNTTAB_FRAME    Frame;
+    ULONG                   Index;
     NTSTATUS                status;
 
     status = STATUS_INVALID_PARAMETER;
     if (Reference >= (Context->FrameIndex + 1) * XENBUS_GNTTAB_ENTRY_PER_FRAME)
         goto fail1;
 
+    Frame = &Context->Frame[Reference / XENBUS_GNTTAB_ENTRY_PER_FRAME];
+    Index = Reference % XENBUS_GNTTAB_ENTRY_PER_FRAME;
+
     if (Pfn != NULL)
-        *Pfn = Context->Table[Reference].frame;
+        *Pfn = Frame->Entry[Index].frame;
 
     if (ReadOnly != NULL)
-        *ReadOnly = (Context->Table[Reference].flags & GTF_readonly) ? TRUE : FALSE;
+        *ReadOnly = (Frame->Entry[Index].flags & GTF_readonly) ? TRUE : FALSE;
 
     return STATUS_SUCCESS;
 
@@ -757,22 +807,22 @@ GnttabDebugCallback(
     )
 {
     PXENBUS_GNTTAB_CONTEXT  Context = Argument;
-    PHYSICAL_ADDRESS        Address;
+    LONG                    Index;
 
     UNREFERENCED_PARAMETER(Crashing);
 
-    Address.QuadPart = MmGetMdlPfnArray(Context->Mdl)[0] << PAGE_SHIFT;
+    for (Index = 0; Index <= Context->FrameIndex; Index++) {
+        PXENBUS_GNTTAB_FRAME    Frame = &Context->Frame[Index];
+        PHYSICAL_ADDRESS        Address;
 
-    XENBUS_DEBUG(Printf,
-                 &Context->DebugInterface,
-                 "Address = %08x.%08x\n",
-                 Address.HighPart,
-                 Address.LowPart);
+        Address.QuadPart = MmGetMdlPfnArray(Frame->Mdl)[0] << PAGE_SHIFT;
     
-    XENBUS_DEBUG(Printf,
-                 &Context->DebugInterface,
-                 "FrameIndex = %d\n",
-                 Context->FrameIndex);
+        XENBUS_DEBUG(Printf,
+                    &Context->DebugInterface,
+                     "[%u] Address = %08x.%08x\n",
+                     Address.HighPart,
+                     Address.LowPart);
+    }
 }
                      
 NTSTATUS
@@ -781,7 +831,6 @@ GnttabAcquire(
     )
 {
     PXENBUS_GNTTAB_CONTEXT  Context = Interface->Context;
-    PXENBUS_FDO             Fdo = Context->Fdo;
     KIRQL                   Irql;
     NTSTATUS                status;
 
@@ -800,13 +849,12 @@ GnttabAcquire(
               "GNTTAB: MAX FRAMES = %u\n",
               Context->MaximumFrameCount);
 
-    Context->Mdl = FdoHoleAllocate(Fdo, Context->MaximumFrameCount);
+    Context->Frame = __GnttabAllocate(Context->MaximumFrameCount * sizeof (XENBUS_GNTTAB_FRAME));
 
     status = STATUS_NO_MEMORY;
-    if (Context->Mdl == NULL)
+    if (Context->Frame == NULL)
         goto fail2;
 
-    Context->Table = Context->Mdl->StartVa;
     Context->FrameIndex = -1;
 
     status = XENBUS_RANGE_SET(Acquire, &Context->RangeSetInterface);
@@ -904,7 +952,6 @@ fail5:
                      Context->RangeSet);
     Context->RangeSet = NULL;
 
-
 fail4:
     Error("fail4\n");
 
@@ -914,10 +961,9 @@ fail3:
     Error("fail3\n");
 
     Context->FrameIndex = 0;
-    Context->Table = NULL;
 
-    FdoHoleFree(Fdo, Context->Mdl);
-    Context->Mdl = NULL;
+    __GnttabFree(Context->Frame);
+    Context->Frame = NULL;
 
 fail2:
     Error("fail2\n");
@@ -940,7 +986,6 @@ GnttabRelease(
     )
 {
     PXENBUS_GNTTAB_CONTEXT  Context = Interface->Context;
-    PXENBUS_FDO             Fdo = Context->Fdo;
     KIRQL                   Irql;
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
@@ -980,10 +1025,9 @@ GnttabRelease(
     XENBUS_RANGE_SET(Release, &Context->RangeSetInterface);
 
     Context->FrameIndex = 0;
-    Context->Table = NULL;
 
-    FdoHoleFree(Fdo, Context->Mdl);
-    Context->Mdl = NULL;
+    __GnttabFree(Context->Frame);
+    Context->Frame = NULL;
 
     Context->MaximumFrameCount = 0;
 
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Wed Jul 12 15:52:07 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 12 Jul 2023 15:52:07 +0000
Received: from list by lists.xenproject.org with outflank-mailman.562617.879366 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qJc8L-0003Gm-GV; Wed, 12 Jul 2023 15:52:05 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 562617.879366; Wed, 12 Jul 2023 15:52:05 +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 1qJc8L-0003Gf-DK; Wed, 12 Jul 2023 15:52:05 +0000
Received: by outflank-mailman (input) for mailman id 562617;
 Wed, 12 Jul 2023 15:52:04 +0000
Received: from mail.xenproject.org ([104.130.215.37])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>) id 1qJc8K-0003GT-73
 for win-pv-devel@lists.xenproject.org; Wed, 12 Jul 2023 15:52:04 +0000
Received: from xenbits.xenproject.org ([104.239.192.120])
 by mail.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8J-0003ch-Vn; Wed, 12 Jul 2023 15:52:03 +0000
Received: from 54-240-197-227.amazon.com ([54.240.197.227]
 helo=REM-PW02S00X.ant.amazon.com)
 by xenbits.xenproject.org with esmtpsa
 (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)
 (envelope-from <paul@xen.org>)
 id 1qJc8J-0001nO-Kh; Wed, 12 Jul 2023 15:52:03 +0000
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>
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org;
	s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:
	Subject:Cc:To:From; bh=u/LqBLffoyvPt6B0kS8CwavQoNvf0S2yN46CLmzuX9A=; b=z5xGgL
	Bu++DY+7WIHIRDSP5UlkmIN1Vuy4YEY0Yhm5GGUht6C5IMgCAfuMAHmLVhB3E7rJFx6e/yN3bCt/p
	MGfKhPCLoytHlybcJtJLwcaYWhgT4j0GB3jNjY/oZl3cm2AtqSSXVwTjr4tzmfCvZ0KE6jEk+Pooy
	g8a4rg8UdoM=;
From: Paul Durrant <paul@xen.org>
To: win-pv-devel@lists.xenproject.org
Cc: Paul Durrant <pdurrant@amazon.com>
Subject: [PATCH 1/3] Add support for XENMEM_remove_from_physmap...
Date: Wed, 12 Jul 2023 16:51:58 +0100
Message-Id: <20230712155200.1348-1-paul@xen.org>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

From: Paul Durrant <pdurrant@amazon.com>

... and make use of it to remove shared_info and grant table pages from the
P2M when we're closing down. This makes sure we don't leave such pages lying
around in the Xen platform PCI device's BAR.

NOTE: Now that we're making GnttabUnmap() actually do something, tidy up the
      implementation of GnttabMap() so it is aligned.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
 include/xen.h            |  7 +++++++
 src/xen/memory.c         | 29 +++++++++++++++++++++++++++++
 src/xenbus/gnttab.c      | 22 ++++++++++++++--------
 src/xenbus/shared_info.c |  5 ++---
 4 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/include/xen.h b/include/xen.h
index 566e7136cf98..132de21c1b62 100644
--- a/include/xen.h
+++ b/include/xen.h
@@ -128,6 +128,13 @@ MemoryAddToPhysmap(
     IN  ULONG_PTR   Offset
     );
 
+__checkReturn
+XEN_API
+NTSTATUS
+MemoryRemoveFromPhysmap(
+    IN  PFN_NUMBER  Pfn
+    );
+
 #define PAGE_ORDER_4K   0
 #define PAGE_ORDER_2M   9
 
diff --git a/src/xen/memory.c b/src/xen/memory.c
index dfee22cffa02..bc1214040476 100644
--- a/src/xen/memory.c
+++ b/src/xen/memory.c
@@ -81,6 +81,35 @@ fail1:
     return status;
 }
 
+__checkReturn
+XEN_API
+NTSTATUS
+MemoryRemoveFromPhysmap(
+    IN  PFN_NUMBER                  Pfn
+    )
+{
+    struct xen_remove_from_physmap  op;
+    LONG_PTR                        rc;
+    NTSTATUS                        status;
+
+    op.domid = DOMID_SELF;
+    op.gpfn = (xen_pfn_t)Pfn;
+
+    rc = MemoryOp(XENMEM_remove_from_physmap, &op);
+
+    if (rc < 0) {
+        ERRNO_TO_STATUS(-rc, status);
+        goto fail1;
+    }
+
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
 __checkReturn
 XEN_API
 ULONG
diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 1e22a363b77d..af562608b40d 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -163,7 +163,7 @@ GnttabExpand(
 fail3:
     Error("fail3\n");
 
-    // Not clear what to do here
+    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT));
 
 fail2:
     Error("fail2\n");
@@ -182,12 +182,14 @@ GnttabMap(
     )
 {
     LONG                        Index;
-    PHYSICAL_ADDRESS            Address;
     NTSTATUS                    status;
 
-    Address = Context->Address;
-
     for (Index = 0; Index <= Context->FrameIndex; Index++) {
+        PHYSICAL_ADDRESS    Address;
+
+        Address = Context->Address;
+        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+
         status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT),
                                     XENMAPSPACE_grant_table,
                                     Index);
@@ -198,8 +200,6 @@ GnttabMap(
                   Index,
                   Address.HighPart,
                   Address.LowPart);
-
-        Address.QuadPart += PAGE_SIZE;
     }
 }
 
@@ -210,12 +210,18 @@ GnttabUnmap(
 {
     LONG                        Index;
 
-    // Not clear what to do here
+    for (Index = Context->FrameIndex; Index >= 0; --Index) {
+        PHYSICAL_ADDRESS    Address;
+
+        Address = Context->Address;
+        Address.QuadPart += (ULONGLONG)Index << PAGE_SHIFT;
+
+        (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT));
 
-    for (Index = Context->FrameIndex; Index >= 0; --Index)
         LogPrintf(LOG_LEVEL_INFO,
                   "GNTTAB: UNMAP XENMAPSPACE_grant_table[%d]\n",
                   Index);
+    }
 }
 
 static VOID
diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c
index b1ad2dcfc3c6..f25e12a1c689 100644
--- a/src/xenbus/shared_info.c
+++ b/src/xenbus/shared_info.c
@@ -477,12 +477,11 @@ SharedInfoUnmap(
     IN  PXENBUS_SHARED_INFO_CONTEXT Context
     )
 {
-    UNREFERENCED_PARAMETER(Context);
-
     LogPrintf(LOG_LEVEL_INFO,
               "SHARED_INFO: UNMAP XENMAPSPACE_shared_info\n");
 
-    // Not clear what to do here
+
+    (VOID) MemoryRemoveFromPhysmap((PFN_NUMBER)(Context->Address.QuadPart >> PAGE_SHIFT));
 }
 
 static VOID
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Wed Jul 12 16:05:44 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Wed, 12 Jul 2023 16:05:44 +0000
Received: from list by lists.xenproject.org with outflank-mailman.562661.879410 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qJcLX-0006gv-FS; Wed, 12 Jul 2023 16:05:43 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 562661.879410; Wed, 12 Jul 2023 16:05:43 +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 1qJcLX-0006gn-BD; Wed, 12 Jul 2023 16:05:43 +0000
Received: by outflank-mailman (input) for mailman id 562661;
 Wed, 12 Jul 2023 16:05:42 +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=PHp+=C6=gmail.com=xadimgnik@srs-se1.protection.inumbo.net>)
 id 1qJcLW-0006gO-Pl
 for win-pv-devel@lists.xenproject.org; Wed, 12 Jul 2023 16:05:42 +0000
Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com
 [2a00:1450:4864:20::331])
 by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id f3169ef9-20cd-11ee-b239-6b7b168915f2;
 Wed, 12 Jul 2023 18:05:42 +0200 (CEST)
Received: by mail-wm1-x331.google.com with SMTP id
 5b1f17b1804b1-3fbea14700bso72960885e9.3
 for <win-pv-devel@lists.xenproject.org>; Wed, 12 Jul 2023 09:05:41 -0700 (PDT)
Received: from [192.168.4.12] (54-240-197-235.amazon.com. [54.240.197.235])
 by smtp.gmail.com with ESMTPSA id
 a25-20020a1cf019000000b003fbb346279dsm5482946wmb.38.2023.07.12.09.05.39
 for <win-pv-devel@lists.xenproject.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Wed, 12 Jul 2023 09:05:40 -0700 (PDT)
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: f3169ef9-20cd-11ee-b239-6b7b168915f2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20221208; t=1689177941; x=1691769941;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :content-language:references:to:subject:user-agent:mime-version:date
         :message-id:from:from:to:cc:subject:date:message-id:reply-to;
        bh=pHCr8mc529jSTstD90trJhedtpbh3QKxtTVTEeiegn4=;
        b=Fxf7MnSlzaLTBzMk8aBRSJJleBjjX3NrcI/aDWac2Yd1Td/NcQ9L+fW/nDK9ElXslt
         SO7vVTmTRvqwk75dJ8j09vS1jt9DLAaEi1hT3amkCEKWUOpdYZQxRsGQPWCwYrLbVrle
         cYn6G1pBrBOykpAOONrEdHYbjIu1LXpxG72lkx72RwQCVT5QzeZOUpUW+pG3q6mR5tI4
         tOVS7X+Vo2P06XElgupKeLXzuhnjhOdRvEnpGHN6vCUVRuBr57cXZn/A3WiujzbgwMfW
         8wQOEjH6aWrZwdrh4CrZer52BWVmo4YWSaACwj9ZldMsCZPrUQs/lnTDeUnLWDpWj2OL
         mikg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20221208; t=1689177941; x=1691769941;
        h=content-transfer-encoding:in-reply-to:organization:reply-to
         :content-language:references:to:subject:user-agent:mime-version:date
         :message-id:from:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to;
        bh=pHCr8mc529jSTstD90trJhedtpbh3QKxtTVTEeiegn4=;
        b=hF3x7UWaNnLmidsSf5Ia+9oQRxZc6JYsEW+aNI4Ag3Dr9PSX0PA9ZQp+nrnjgNIlqe
         2gbk5enL2N1N9eL1hkMJd6373RSeL41QEKSOMj4PQlOkylawUnUb1xxe2AiYttmcL9Gp
         7OlGFuU1DBoQljKDoAVSNuucsde9do/Nyx2Q2vZpAS8GFjCjilJG03iskCUBeooB0MUv
         lLRJ0a1AD0X9wU2TIn1g5RRBWHinuEMa7gocdL6vdPwT3/b4GVs7m+dj9z/arGKUGPEq
         m9t6Rm7hUb/LL7LbIv0B2o6T0BMgToF1jhG6dKhiqeHD3wquaW0RTM4HlgKNfH6J2r9M
         AVTw==
X-Gm-Message-State: ABy/qLaNpEHgz4uxRAtQjry6p589FpSqnBxPe0kMoRIpeL7BRJIAS5VV
	rXowh0XtyFS4sy3NPZMwM1iFDtBocwj/W4NL
X-Google-Smtp-Source: APBJJlFOprSLtmSsJXM8rY3EvAfonn6CsiLEpTAmWqgGeeBoTVG9+VCKzHaKB226TaICy0ZisUHN5w==
X-Received: by 2002:a1c:4b12:0:b0:3fc:1fe9:e812 with SMTP id y18-20020a1c4b12000000b003fc1fe9e812mr4614677wma.25.1689177940650;
        Wed, 12 Jul 2023 09:05:40 -0700 (PDT)
From: Paul Durrant <xadimgnik@gmail.com>
X-Google-Original-From: Paul Durrant <paul@xen.org>
Message-ID: <08d5adb8-8b57-6125-32cb-60dd68ea3782@xen.org>
Date: Wed, 12 Jul 2023 17:05:39 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.13.0
Subject: Re: Xenbus issues on Qubes OS / win10
To: win-pv-devel@lists.xenproject.org
References: <6ab4cae1-af89-bf2f-3a85-be437828788b@invisiblethingslab.com>
 <7797fe6b-efdf-805f-33f8-3e41d4779d7d@invisiblethingslab.com>
 <e7bad11f-de8d-995c-7142-a3dcf5634485@xen.org>
Content-Language: en-US
Reply-To: paul@xen.org
Organization: Xen Project
In-Reply-To: <e7bad11f-de8d-995c-7142-a3dcf5634485@xen.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

On 27/06/2023 11:37, Paul Durrant wrote:
> On 23/06/2023 19:50, Rafał Wojdyła wrote:
>> On 23 cze 2023 17:37, Rafał Wojdyła wrote:
>>> Hello,
>>>
>>> I'm trying the latest PV drivers on Qubes OS (backend is Xen 4.14.5) 
>>> with Windows 10 pro and having some issues. Mainly, xenbus fails to 
>>> initialize properly. I've attached a debug output, the main issue 
>>> seems to be this:
>>>
>>> xenbus|StoreAcquire: ====>
>>> xenbus|GnttabAcquire: ====>
>>> xenbus|RangeSetPop: fail3
>>> xenbus|RangeSetPop: fail2
>>> xenbus|RangeSetPop: fail1 (c000009a)
>>> xenbus|FdoAllocateHole: fail1 (c000009a)
>>> xenbus|GnttabAcquire: fail2
>>> xenbus|GnttabAcquire: fail1 (c000009a)
>>> xenbus|StoreAcquire: fail1 (c000009a)
>>> xenbus|FdoD3ToD0: fail6
>>>
>>> ...which seems pretty suspicious. It's been some years since I looked 
>>> at the drivers' code so any ideas as to what may be causing this are 
>>> welcome :)
>>>
>> Followup: in xenbus/gnttab/GnttabAcquire()
>>
>> status = GrantTableQuerySize(NULL, &Context->MaximumFrameCount);
>>
>> Context->MaximumFrameCount is 2048 for me, which is bigger than 1 << 
>> PAGE_ORDER_2M, which seems to be the limit for FDO memory hole size.
>>
> 
> Hmm. Ok - we should probably put something in there to either expand the 
> hole, use another one or - probably simpler - query the grant table size 
> up-front to correctly size the hole.
> 

Wasn't that simple... Trying to allocate a single memory hole to 
accommodate a 2048 entry grant table just didn't fly on my test VM. So 
I've re-worked things to both get rid of the single memory hole, and to 
have the grant table deal with non-contiguous GFNs.

   Paul



From win-pv-devel-bounces@lists.xenproject.org Thu Jul 13 12:32:01 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 13 Jul 2023 12:32:01 +0000
Received: from list by lists.xenproject.org with outflank-mailman.563134.880158 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qJvUF-0008GL-1X; Thu, 13 Jul 2023 12:31:59 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 563134.880158; Thu, 13 Jul 2023 12:31:59 +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 1qJvUE-0008GE-Uv; Thu, 13 Jul 2023 12:31:58 +0000
Received: by outflank-mailman (input) for mailman id 563134;
 Thu, 13 Jul 2023 12:31:58 +0000
Received: from winpvdrvbuild.xenproject.org ([162.242.160.44])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <paul.durrant@xenproject.org>) id 1qJvUD-0008G8-Jg
 for win-pv-devel@lists.xenproject.org; Thu, 13 Jul 2023 12:31:58 +0000
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>
Date: Thu, 13 Jul 2023 12:32:42 +0000 (UTC)
From: paul.durrant@xenproject.org
To: win-pv-devel@lists.xenproject.org
Message-ID: <1904891.1.1689251565436.JavaMail.WINPVDRVBUILD$@winpvdrvbuild>
Subject: XENBUS-master - Build #246 - Unstable
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_0_16767327.1689251564124"
X-Jenkins-Job: XENBUS-master
X-Jenkins-Result: UNSTABLE


------=_Part_0_16767327.1689251564124
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

The build system has completed build #246.

Check console output at https://winpvdrvbuild.xenproject.org:8080/job/XENBUS-master/246/console to view the results.
------=_Part_0_16767327.1689251564124--


From win-pv-devel-bounces@lists.xenproject.org Sat Jul 15 00:52:50 2023
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Sat, 15 Jul 2023 00:52:50 +0000
Received: from list by lists.xenproject.org with outflank-mailman.563829.881273 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1qKTWh-0006eF-Jk; Sat, 15 Jul 2023 00:52:47 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 563829.881273; Sat, 15 Jul 2023 00:52:47 +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 1qKTWh-0006e8-Fl; Sat, 15 Jul 2023 00:52:47 +0000
Received: by outflank-mailman (input) for mailman id 563829;
 Sat, 15 Jul 2023 00:52:47 +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=Ek+P=DB=invisiblethingslab.com=marmarek@srs-se1.protection.inumbo.net>)
 id 1qKTWg-0006e2-TK
 for win-pv-devel@lists.xenproject.org; Sat, 15 Jul 2023 00:52:47 +0000
Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com
 [64.147.123.21]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS
 id e570aea9-22a9-11ee-b239-6b7b168915f2;
 Sat, 15 Jul 2023 02:52:42 +0200 (CEST)
Received: from compute5.internal (compute5.nyi.internal [10.202.2.45])
 by mailout.west.internal (Postfix) with ESMTP id 9095F32004E7;
 Fri, 14 Jul 2023 20:52:37 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
 by compute5.internal (MEProxy); Fri, 14 Jul 2023 20:52:37 -0400
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri,
 14 Jul 2023 20:52:36 -0400 (EDT)
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: e570aea9-22a9-11ee-b239-6b7b168915f2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
	invisiblethingslab.com; h=cc:cc:content-type:content-type:date
	:date:from:from:in-reply-to:in-reply-to:message-id:mime-version
	:references:reply-to:sender:subject:subject:to:to; s=fm2; t=
	1689382357; x=1689468757; bh=JjieeP87EXzbyCz0eXUVqlkC6m0uqAKGeJT
	D/Xab7h0=; b=NTOhQM0hhM0fP6NSjjFp+aJ2TWTLOSZxctQENaOnkL1E2P79beT
	yDiM5OBLmAa2dxDOWg8VoU/yAhvNcWf4zB/I5xgJLAithUal7v28Yz4Wu7TaC8ao
	fx5ifjiQOmHDIPoKPyD1fuX4X1QiLNimLRw57B8m0IsQiaFK0CCtJQ7Uh5CZSLCp
	ewrbAruOPV8r4C8fxMJ+wm/WWOmOE1JvXV6yPdriw2y8lroHmAuH+Rf7rjRr4J7Q
	F21x/0CK8uncV/yuCuBzoK2/gNQy7jG2x2uTUozhrGOHAKoKmoTKECQc2Sf4PpET
	uIYcbYvThqL80VD40HyNUHRCU5WlzyLmYow==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
	messagingengine.com; h=cc:cc:content-type:content-type:date:date
	:feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
	:message-id:mime-version:references:reply-to:sender:subject
	:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender
	:x-sasl-enc; s=fm3; t=1689382357; x=1689468757; bh=JjieeP87EXzby
	Cz0eXUVqlkC6m0uqAKGeJTD/Xab7h0=; b=SuNX0Wwe9MNnEjTpVHvObKv07SiRQ
	iVXzHsiuT47/omY1MjFZ9m6Dk37y1bnJ83fiPb4mx/cZaZSUSWnnhvvUNFj2vR5D
	DOvuP/itq6jluDxc5jobcncE+x6O+z/stCGTgSIUUj1eO7fpLiYK4XGOb+s449Rv
	fG99zDxMnVBDieXqdeoVc/WprG20wAo/LeHumQU8WUv0MUSsEyefvwNBMQO71KZO
	Sppfl7vrbikh85NanDR0EvTNEpcQoRhAmlXquq6BkaCNFDzN1+eilXdwiVH0SmUH
	lIYtoTmyr+j0lUfLVTn+xPu2XD7InzHypLbbkWWSsbnBVgfJjdD4+z8Nw==
X-ME-Sender: <xms:1O2xZCCm9y24_2jlgV_qwpcHCIOdXg23TC21V1f73In2FMSTqie73Q>
    <xme:1O2xZMiXKD8CeWZem1TxXZotbVcd-tpoLd_B3VeUeb52n36gARmrRXiYaESDIEc7L
    rSQV_VRTwIXOw>
X-ME-Received: <xmr:1O2xZFmoZrC_kqOhZEzNA9N9cU9oAN6sO2BUDhGw1Q0VtMdtjCxSUnDWtSl4OedAGA0EioO6Nb_HWrnqFDDsuCCFbJEh_NCtDxA>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrfeejgdefiecutefuodetggdotefrodftvf
    curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
    uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc
    fjughrpeffhffvvefukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpeforghrvghk
    ucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesihhnvh
    hishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeeivedt
    ffevgfekiedvffeltefhudelveektedtudeltdehffejfffgieelfffhgeenucffohhmrg
    hinhepgigvnhdrohhrghdpgigvnhhprhhojhgvtghtrdhorhhgnecuvehluhhsthgvrhfu
    ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvih
    hsihgslhgvthhhihhnghhslhgrsgdrtghomh
X-ME-Proxy: <xmx:1O2xZAwQ5ftk_B17tMb08rAiDcJRn6W2a7kx8JJMIkhUAj7D9_ry2Q>
    <xmx:1O2xZHRhRnwU1jsvXIkedgAKMD1KUxiRncB1XOCRh0CKfcPhHTb-rA>
    <xmx:1O2xZLZSXBXUy8xNOzb3UILJ4YMbx08YgIeUBmhxG9SIT7rNkcAR6A>
    <xmx:1e2xZKP7LPLq_rtQM3BFb3o3htfP7QK_SWsqNFaMICYeLrsY2LPJfA>
Feedback-ID: i1568416f:Fastmail
Date: Sat, 15 Jul 2023 02:52:32 +0200
From: Marek =?utf-8?Q?Marczykowski-G=C3=B3recki?= <marmarek@invisiblethingslab.com>
To: win-pv-devel@lists.xenproject.org
Cc: "Xen.org security team" <security@xen.org>
Subject: Re: Xen Security Notice 1 v1 - winpvdrvbuild.xenproject.org
 potentially compromised
Message-ID: <ZLHt0Meu8eG6j5UX@mail-itl>
References: <E1qKMmq-00035B-SS@xenbits.xenproject.org>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="D1sYLmWY5KcVxOJO"
Content-Disposition: inline
In-Reply-To: <E1qKMmq-00035B-SS@xenbits.xenproject.org>


--D1sYLmWY5KcVxOJO
Content-Type: text/plain; protected-headers=v1; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Date: Sat, 15 Jul 2023 02:52:32 +0200
From: Marek =?utf-8?Q?Marczykowski-G=C3=B3recki?= <marmarek@invisiblethingslab.com>
To: win-pv-devel@lists.xenproject.org
Cc: "Xen.org security team" <security@xen.org>
Subject: Re: Xen Security Notice 1 v1 - winpvdrvbuild.xenproject.org
 potentially compromised

On Fri, Jul 14, 2023 at 05:41:00PM +0000, Xen.org security team wrote:
> We have removed all previous binaries from:
>=20
> https://xenbits.xen.org/pvdrivers/win/
>=20
> A new set of drivers based on the current master branch
> (9.0-unstable) and built on a trusted environment have been uploaded
> on the same folder with the following hashes:

Thanks for providing some builds at this time, but I have few questions:
1. Can the directory structure be preserved? Specifically, it used to be
/pvdrivers/win/VERSION/*.tar, now the version subdirectory is gone.
2. Can the exact commit ids for each of the component be mentioned
explicitly?
3. Are there any plans for publishing (soon) re-builds of some released
version, instead of a development one? For example 9.0.0(*), or maybe also
8.2.2?


(*) BTW looking at repositories, I do not see 9.0.0 tag (there is only
9.0.0-rc1). Is the official 9.0.0 release the same as -rc1 ?

--=20
Best Regards,
Marek Marczykowski-G=C3=B3recki
Invisible Things Lab

--D1sYLmWY5KcVxOJO
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAmSx7dEACgkQ24/THMrX
1yw6twf+PYzNyyEXK/WrVEHMz9Xvwhdxl7da892Rf1t1N3cIrOwKi+NDcYf89Xau
djcM9Nud/yfY6PPxD6ClsJH4OCxnAQy8HgrZ8iiquL/oTAKszv/M3Mt8LQFZSeSS
um37iPUY1KLGfjQocECTd/7Hs3LYkmLWDEaZLqDuKn1VMAaULTzgkHMgze2EvQJs
Fhx5/rAYqLS3VsxKw5HFHuguCTfITJLftmXt9tpWRltNa+EMHzkwVlsBCNwV9HH/
2HyhFUedBGG8RBjOyyEndctt76uHu+jEEvAyvq8PankCiOuHasU7g42nrGW9fKTc
dacq/aX3qgce+UW2sFSpCrhoKt/eCg==
=A6RX
-----END PGP SIGNATURE-----

--D1sYLmWY5KcVxOJO--


