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

Re: [PATCH v13 10/14] vpci/header: emulate PCI_COMMAND register for guests


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Mon, 18 Mar 2024 17:03:40 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.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 (0)
  • 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=OqX99EhzTzI3Q6ELp8FMSA0vDL3ywxwbPu1ksn1z+d8=; b=oU8ToRvUvL+uWimpN0ChsqI7b1UGZNLxzUAlaGmK97MVvbrjFY3deEAK4Vx6Rik3A0qAn9J90YHSfo7Iz/5ld58lgZdQerDkqT4TLUiCnyrL9YCNkH6Z+BxbboSR5yzKKYSJmBkXgYWcztBbGJuDiydpZ+7yfxjRvyE6w3zozL0ZIlarJWo7oTc5Hdl4YxCQa+fGetQ3XIN/AUKskr429iR+PTuLvjWZfRrU67PPrit5IdmYTomT4lhOpJVPbxD9LqHuDVVPpHpFnYydB0iBeZaAC8l0IfploKEO0qjChyW4elk44vGpcFsveif1joLESV6WQzmZ8+KiDWkLIlLNkQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CEjYYKsqsBRjMoKzzcL5HKtsUmF87Ir+n+uKak+3KG5TlZui0kP/5xD8Fis6j4sSB8ufmzWOkkuN7NZ+UQLdec86WStcPKjjxtbXQBdCTeZTZqYvjjvwJ9Jl7PimGUCVrBhVBQfsdBysuCi9V2UshqRD87lrQtH5Z28EOcouJpZ/dbKpxnE0iq7XFYhiWWVry1ey2r/Fg3+PHlnLkAQFG07+j3avYra4/0luRCZnwzwwPF+NjhY/WPPKUv6C9LqOhyN/V8cDHl89t/EXrySpI8oQR/H379BeMq+CKbixzijLqnpzJEqwx7PVkSoDpximUkfgdnBSI4alyj46Vt3xxA==
  • Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 18 Mar 2024 21:04:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2/14/24 10:41, Jan Beulich wrote:
> On 02.02.2024 22:33, Stewart Hildebrand wrote:
>> @@ -836,9 +870,20 @@ static int cf_check init_header(struct pci_dev *pdev)
>>      if ( pdev->ignore_bars )
>>          return 0;
>>  
>> -    /* Disable memory decoding before sizing. */
>>      cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
>> -    if ( cmd & PCI_COMMAND_MEMORY )
>> +
>> +    /*
>> +     * Clear PCI_COMMAND_MEMORY and PCI_COMMAND_IO for DomUs, so they will
>> +     * always start with memory decoding disabled and to ensure that we 
>> will not
>> +     * call modify_bars() at the end of this function.
> 
> To achieve this, fiddling with PCI_COMMAND_IO isn't necessary. Which isn't
> to say its clearing should go away; quite the other way around: Why would
> we leave e.g. PCI_COMMAND_MASTER enabled? In fact wasn't it in an earlier
> version of the series that the guest view simply started out as zero? The
> patch description still says so.

Yep, clearing PCI_COMMAND_MASTER too for domUs makes sense to me, I'll
make this change in v14. I'll also try to improve the comment.

Roger suggested at [1] that we should reflect the state of the hardware
in the command register. I'll update the patch description accordingly.

Archaeology/notes/references follow, primarily for my own reference:

Note that the rsvdp_mask will be applied to the guest_cmd value before
being returned to the guest, so no need to apply masks here.

Clearing both PCI_COMMAND_MEMORY and PCI_COMMAND_IO for domUs was
suggested by Roger at [2] and [3]. It is currently problematic for
devices assigned to domUs to have memory decoding enabled at this stage
because we don't yet have a good/generic way to initialize
bar.guest_addr taking the domU memory layout into account.

Reminder that we want to leave the PCI_COMMAND_{MASTER,MEMORY,IO} bits
unchanged for devices assigned to dom0. A description of why can be
found in the commit message of:

53d9133638c3 ("pci: do not disable memory decoding for devices").

[1] 
https://lore.kernel.org/xen-devel/ZLqI65gmNj1XDBm4@MacBook-Air-de-Roger.local/
[2] https://lore.kernel.org/xen-devel/ZRquRcRz-K43WeMc@MacBookPdeRoger/
[3] https://lore.kernel.org/xen-devel/ZVy73iJ3E8nJHvgf@macbook.local/

>> --- a/xen/drivers/vpci/msi.c
>> +++ b/xen/drivers/vpci/msi.c
>> @@ -70,6 +70,13 @@ static void cf_check control_write(
>>  
>>          if ( vpci_msi_arch_enable(msi, pdev, vectors) )
>>              return;
>> +
>> +        /* Make sure domU doesn't enable INTx while enabling MSI. */
>> +        if ( !is_hardware_domain(pdev->domain) )
>> +        {
>> +            pci_intx(pdev, false);
>> +            pdev->vpci->header.guest_cmd |= PCI_COMMAND_INTX_DISABLE;
>> +        }
> 
> While here we're inside "if ( new_enabled )", ...
> 
>> --- a/xen/drivers/vpci/msix.c
>> +++ b/xen/drivers/vpci/msix.c
>> @@ -135,6 +135,13 @@ static void cf_check control_write(
>>          }
>>      }
>>  
>> +    /* Make sure domU doesn't enable INTx while enabling MSI-X. */
>> +    if ( new_enabled && !msix->enabled && !is_hardware_domain(pdev->domain) 
>> )
>> +    {
>> +        pci_intx(pdev, false);
>> +        pdev->vpci->header.guest_cmd |= PCI_COMMAND_INTX_DISABLE;
>> +    }
> 
> .. here you further check that it's actually a 0->1 transition? Why
> not alike for MSI?

Good catch, we should similarly check for a 0->1 transition for MSI.
I'll fix it.



 


Rackspace

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