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

Re: [PATCH v9 15/16] xen/arm: vpci: check guest range


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Mon, 25 Sep 2023 17:49:00 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L1SAx3sAnqfkH32QfAPY2IdnjseGRoYk92tQ9C7QKQE=; b=Z1HpC4R9BpjEDKn3NJ/90A4coGWJAoqyEJNl4RfXKW4RWelmLolmxiVyqt3EWjx3HYkCtyvbLLCpsdoc+BonBiC6Ul6Xfr7mzuQuVMPJgkMFHRAxzbmSmqak65bEjoZNpPzhEEWSsUwDjCMEujd60s7UggfPFLkHzFCGPA3vwuZXfYqjvAGHeea/UE25j3sgw2/bNQFLtEwotJLsVP4LkVLkiG34dNqB+DkKOwVdriYsovinDQdUCTsApvRRaaelfWKLon1AP9+Qeb7/F/uvKpCsrkv/lGxnc6k8WqqVYLWQ3eSMw8cHEJAUDrXG6xZywr50mmtEVUMMoFkNQt2b+w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eAW3qG5wAIvwFBodv/bKBSnVsTJyDgRyFymP7x+ubRkrwDPtXzTNJkRQ2kKIb/ME/WuY653H1x8Tq+i0xbxvmIdZFPZ2VJFVr7sdhTlsOSLKur+kzA4Zpu3J3BspfAP7Cv/EhMb+57lhubyx5ep34ErKv1XYzjlQCL++0eP9MUGHiBtrlhziOl17Akk/2xQSNqKO6JMxsa6oKSZM9XJIVqCgcuOb+jAhZuwWBgNRZ1KvtWSBSr9TL5aEsCXN5o8GTTFb8sReWfV171+NJnMNY4pNR/JvC4i0UMFRJXbGIwuLp3/VAcOWtF+dzKMMXQcn7oPySq3nqbak2KztmdQm6Q==
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 25 Sep 2023 21:49:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 9/22/23 04:44, Roger Pau Monné wrote:
> On Tue, Aug 29, 2023 at 11:19:47PM +0000, Volodymyr Babchuk wrote:
>> From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
>>
>> Skip mapping the BAR if it is not in a valid range.
>>
>> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
>> ---
>>  xen/drivers/vpci/header.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
>> index 1d243eeaf9..dbabdcbed2 100644
>> --- a/xen/drivers/vpci/header.c
>> +++ b/xen/drivers/vpci/header.c
>> @@ -345,6 +345,15 @@ static int modify_bars(const struct pci_dev *pdev, 
>> uint16_t cmd, bool rom_only)
>>               bar->enabled == !!(cmd & PCI_COMMAND_MEMORY) )
>>              continue;
>>
>> +#ifdef CONFIG_ARM
>> +        if ( !is_hardware_domain(pdev->domain) )
>> +        {
>> +            if ( (start_guest < PFN_DOWN(GUEST_VPCI_MEM_ADDR)) ||
>> +                 (end_guest >= PFN_DOWN(GUEST_VPCI_MEM_ADDR + 
>> GUEST_VPCI_MEM_SIZE)) )
>> +                continue;
>> +        }
>> +#endif
> 
> Hm, I think this should be in a hook similar to pci_check_bar() that
> can be implemented per-arch.
> 
> IIRC at least on x86 we allow the guest to place the BARs whenever it
> wants, would such placement cause issues to the hypervisor on Arm?

Hm. I wrote this patch in a hurry to make v9 of this series work on ARM. In my 
haste I also forgot about the prefetchable range starting at 
GUEST_VPCI_PREFETCH_MEM_ADDR, but that won't matter as we can probably throw 
this patch out.

Now that I've had some more time to investigate, I believe the check in this 
patch is more or less redundant to the existing check in map_range() added in 
baa6ea700386 ("vpci: add permission checks to map_range()").

The issue is that during initialization bar->guest_addr is zeroed, and this 
initial value of bar->guest_addr will fail the permissions check in map_range() 
and crash the domain. When the guest writes a new valid BAR, the old invalid 
address remains in the rangeset to be mapped. If we simply remove the old 
invalid BAR from the rangeset, that seems to fix the issue. So something like 
this:

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index d4629a14f26b..732be26f0d2d 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -638,6 +638,16 @@ static void cf_check guest_bar_write(const struct pci_dev 
*pdev,
         return;
     }

+    if ( (val != 0xfffffff0U) &&
+         (bar->guest_addr != (0xfffffff0ULL & ~(bar->size - 1))) &&
+         (bar->guest_addr != (0xfffffffffffffff0ULL & ~(bar->size - 1))) )
+    {
+        if ( rangeset_remove_range(bar->mem, PFN_DOWN(bar->guest_addr),
+                                   PFN_DOWN(bar->guest_addr + bar->size) - 1) )
+            gprintk(XENLOG_WARNING, "%pp failed to remove old BAR range\n",
+                    &pdev->sbdf);
+    }
+
     bar->guest_addr = guest_addr;
 }



 


Rackspace

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