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

Re: [PATCH v3 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar


  • To: Julien Grall <julien@xxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Tue, 6 Sep 2022 09:39:09 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=qSqeE592xvhkUBWetSl34h7RM7sjBOZA7wawoa34qmU=; b=TQ3uFQQxbp9kZpcgsfQZ8i02ZeBIPjSXopyEzlGp8WDDE4rMgMdmGBE9Pl1uVd34C0ozaFnLqciO9TufNoP3FLd5GhzFix1XepoAgTDaN8sKfBgGgUAagnnL8rFtbj6TEsXTG9PCCeMq4gbWwObxHvL7kO//nlzqfOkqpKANtBkIP7NlfAO9XW7HnGscrFJD279Qm6Ea3A/e7DgEjjhYoi65jiVB+FIxORGX2NHqot36sjxfTZaq3mhuZ3DxCfklDw/HQx8BkjTzCpfH7VTELYpOBwFhmAAYJMAGP/ZBG7tJ5EooRWGD8Q7XQBxrq3CoSGqpfEqppVDrbOgxXGCoDQ==
  • 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=qSqeE592xvhkUBWetSl34h7RM7sjBOZA7wawoa34qmU=; b=FLisW3OzzA4VoBErPLu3eoyiNvNwIltO1+7Lp89/XPRTCmlNcOU65/5rujm9BO6tHIA0e8aAYxVEiEHMobqGbr29NLGf7TPADHEoWtRNmAem29WypzRh/NDPK3TUEEeijZRf1Q9pNVwBWEYXbFTEV2bEELg/pyO0t4L19277TOJxRpMxSlsVcq6SSTjVqfblkkSjnoSyby0tqbIvSMytB26Sj8vfesGTWJa0JmIHkHnbBfo6acLa/57WeGpE2+Tv/SxgeXIvt9RXsvbSI9JXQvnL33s+TAgffwE0SToOIx1qDTjU0GArOmVrkC4enf7XchBVAFhjWrQ0pjRKsixqsg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=GmzlmGZQfNWypm25pveE4q1TIO1hbeAzi1dOHnDO33XVcYdhGK7sB9h82eLGGaU9Xm3I4xWHUyWn1hy+2g0WilV0XnaGye4R8Wd8Lb4VRLY00W965EXDezyEZRVh7o5pKfIZvfG2B9P/LUmiKFni7BzsWHbaNtdRkzI7DDosZre82dZk5oVPNrvcFwJxPZ29J1no+pjNroRGq4hmnX4rzlveBab/MzRI3PovDxz+IWaaBCuX+BdFgAFJ06el9bVNustZ5uLHpcYzIBTrmo6ftRVW9OA+6FRild38gB01W71Md8xSXhmwJBd6GU/bLX4uB17VT6otl4SsEpnalr9yvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fsPcP2LOmCtCaCfq1O9eq5Tqdf38bd9YoEXmcB45tpmWUaXwFOz8iLofVStNz1c6noRSdVXjx5Wgt5UUD6t69g76re18EYY1tN6dbQj+Qb0ARxCdO2XQiN4CxYdA9WNcxh7BBgH7R0XFA4kSQKLXQxMh8Pyns3NIrQTkKY81FCVcJbiJnR16DkREYPRiFHBilhgcWe/HOypLUuCVEZRbcrNcVoWZr06kPAbBLwp52bCf9+WlHUcBJqZK9bZDTLYvWvwxM6t9gLebVfD+0G+zLxlXFBLWRFZ1sChLgYG07XbSugyrzBKxNkZOu4wfuLMkr9Eg6FSmk+iRZRT77Luamw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Tue, 06 Sep 2022 09:39:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYveWaAk0wZPH8TEaypPBHbuXyK63NTxAAgATeK4A=
  • Thread-topic: [PATCH v3 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar

Hi Julien,

> On 3 Sep 2022, at 8:18 am, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Rahul,
> 
> On 01/09/2022 10:29, Rahul Singh wrote:
>> is_memory_hole was implemented for x86 and not for ARM when introduced.
>> Replace is_memory_hole call to pci_check_bar as function should check
>> if device BAR is in defined memory range. Also, add an implementation
>> for ARM which is required for PCI passthrough.
>> On x86, pci_check_bar will call is_memory_hole which will check if BAR
>> is not overlapping with any memory region defined in the memory map.
>> On ARM, pci_check_bar will go through the host bridge ranges and check
>> if the BAR is in the range of defined ranges.
>> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
>> ---
>> Changes in v3:
>>  - fix minor comments
>> ---
>>  xen/arch/arm/include/asm/pci.h     |  2 ++
>>  xen/arch/arm/pci/pci-host-common.c | 43 ++++++++++++++++++++++++++++++
>>  xen/arch/x86/include/asm/pci.h     | 10 +++++++
>>  xen/drivers/passthrough/pci.c      |  8 +++---
>>  4 files changed, 59 insertions(+), 4 deletions(-)
>> diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h
>> index 80a2431804..8cb46f6b71 100644
>> --- a/xen/arch/arm/include/asm/pci.h
>> +++ b/xen/arch/arm/include/asm/pci.h
>> @@ -126,6 +126,8 @@ int pci_host_iterate_bridges_and_count(struct domain *d,
>>    int pci_host_bridge_mappings(struct domain *d);
>>  +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end);
>> +
>>  #else   /*!CONFIG_HAS_PCI*/
>>    struct arch_pci_dev { };
>> diff --git a/xen/arch/arm/pci/pci-host-common.c 
>> b/xen/arch/arm/pci/pci-host-common.c
>> index 89ef30028e..0eb121666d 100644
>> --- a/xen/arch/arm/pci/pci-host-common.c
>> +++ b/xen/arch/arm/pci/pci-host-common.c
>> @@ -24,6 +24,16 @@
>>    #include <asm/setup.h>
>>  +/*
>> + * struct to hold pci device bar.
>> + */
> 
> I find this comment a bit misleading. What you are storing is a
> candidate region. IOW, this may or may not be a PCI device bar.
> 
> Given the current use below, I would rename the structure to something more 
> specific like: pdev_bar_check.

Ack.
> 
>> +struct pdev_bar
>> +{
>> +    mfn_t start;
>> +    mfn_t end;
>> +    bool is_valid;
>> +};
>> +
>>  /*
>>   * List for all the pci host bridges.
>>   */
>> @@ -363,6 +373,39 @@ int __init pci_host_bridge_mappings(struct domain *d)
>>      return 0;
>>  }
>>  +static int is_bar_valid(const struct dt_device_node *dev,
>> +                        uint64_t addr, uint64_t len, void *data)
>> +{
>> +    struct pdev_bar *bar_data = data;
>> +    unsigned long s = mfn_x(bar_data->start);
>> +    unsigned long e = mfn_x(bar_data->end);
>> +
>> +    if ( (s <= e) && (s >= PFN_DOWN(addr)) && (e <= PFN_UP(addr + len - 1)) 
>> )
> 
> AFAICT 's'  and 'e' are provided by pci_check_bar() and will never change. So 
> can we move the check 's <= e' outside of the callback?

Yes, We can move the check outside the callback but I feel that if we check 
here then it is more
readable that we are checking for all possible values in one statement. Let me 
know your view on this.

> 
>> +        bar_data->is_valid =  true;
>> +
>> +    return 0;
>> +}
>> +
>> +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end)
>> +{
> 
> Other than the current calls in check_pdev(), do you have plan to use it in 
> more places? The reason I am asking it is this function is non-trivial on Arm 
> (dt_for_each_range() is quite complex).

I don’t see any use of this function in more places. As this function will be 
called during dom0 boot when the PCI devices are
added I don’t see any performance issues. We may need to revisit this function 
when we add ACPI PCI passthrough support.
I will add TODO that we need to revisit this function for ACPI PCI passthrough 
support.
 

Regards,
Rahul

 


Rackspace

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