[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: Wed, 7 Sep 2022 08:15:10 +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=nUz9p4/vrHxW3u4lCgSxrEnvHPOtAxd+lxsACLaA0yQ=; b=ba3p9O6zPo18w01mvot8EyMhJx6g4AyLTcVEn6qHNpOwXvWaqxF2q7Lei8J3nCZkHUbDk4n4DG7l6V+vpx1NR6Lo15cqN/CfzAkhtQ2iN7LEvg9pzqpP3JS7MT4vgLlzAXxI6+tXdF7rqtj0Trmom4w13+xVkbeiHa8JJ9dGGwu5HvLiSIeChOsGkrMqW9FwcB5Hm8z1ezl4Y7BvDN0x0t9nuXFxPhrpNascQmGjOYmBVyjDp8x9MfDtgjolMBs/gMXC48eEsBwCGE6XnwNFgSuXmWaSH0vAiV/kEKE7gyys60+g6uQkUcGlXuiX8/xrC+o+C+vfSTbQ6SQQd86CRg==
  • 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=nUz9p4/vrHxW3u4lCgSxrEnvHPOtAxd+lxsACLaA0yQ=; b=AiveZtwr7yPPEyOE9/zgNsuxUQkMdotgLwzEXk9Me/bETeqfhJzVAiB/D6wc/j1iGgIi+sMJWS/L03479FMZiWiyf5ryj5kPPN7cMZoJsiY7A8C6ERkcVF5mayl1yGmKgC5xrJHoFuV5P2OTfEtUBj/eyF7T8xMGcLn97MH4dr5FXIvvQdBsprcdS4W9t75rjnP5hLV1ZOQdtKymI6/vW8MN9mjq3dPtVbauQmtL/lFMhUpI5sFiw9OrMutUlx7xcP9flU3uWOH9qxSrvyfwxM/TGsOpVQplcKaiqKgSIP5ry7ULGdNboEpoWh8d4iKtoIddz3roGAguwKWPDv1qGQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=dB4XHX4397zZtXLvPXhqQYBHgoC2vMgL/BCMhLd519iwcVTpvsDPUROPUnRKff8RJ5YBkcQidJgUB/YSKqFvHqiGxIHtzjQhCmvvbhRTCWsqT6pqwVvdIt/n/CX8R6BCNW3ViucyPGAAoyhpUdWjc8XSJGH5ye0y5qk9f/ni/uEsB9+BU62J7IBs1QMzNpu61Sufi0AYw1oxOJa9vqG0DKxzSVFpTONaoyoYcx1I3ATqKMV16N7evgACipOoB3nkDHbyqyqVeiHmL6fDzVqEMgrT5J/r9uVhKtVbLTRe6I0fP8M+Lz2g2Xc8ml2Ql1Q6WXq5RPPiJS7RG80vd7qdPA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g6MPlt8LiNjerTmKeSMWwrMyxMa4a7cE1BtlGZpnGiQ8rICINZloj1kT+nfOcm1fd0M5nHKhCZx2E9XvkAyihjuxUqou9XjZxEZO2/+imRpLOTqFf/28Fdwo086rGTxrJz/ECbfT6sP/gDlrqQuiUkXN/ME5QaVQS81NdojLQo019aM1AlSmeiINgYXBrixaLmxcUpkSmdrbi7y7hFNfTx0ZtYm8z6VvBxLmttsy/xNA1A0ReedrO9TXqLS8UkQH+LEah2u2plfMUpY1oQHZBbOhQX0Em/8H0hApRgENvuUxyUwgHBsubdDiWBJOK0s1X1Jv+jgu5rnP+DuFBEQRjA==
  • 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: Wed, 07 Sep 2022 08:15:29 +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: AQHYveWaAk0wZPH8TEaypPBHbuXyK63NTxAAgATeK4CAAAQegIABdr+A
  • Thread-topic: [PATCH v3 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar

Hi Julien,

> On 6 Sep 2022, at 10:53 am, Julien Grall <julien@xxxxxxx> wrote:
> 
> 
> 
> On 06/09/2022 10:39, Rahul Singh wrote:
>> 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.
> The readability is really a matter of taste here. But my point is more on the 
> number of time a check is done.
> 
> It seems pointless to do the same check N times when you know the values are 
> not going to change. Admittedly, the operation is fast (this is a comparison) 
> and N should be small (?).
> 
> However, I think it raises the question on where do you draw the line?
> 
> Personally, I think all invariant should be checked outside of callbacks. So 
> the line is very clear.
> 
 
I will move the check for "s <=e” outside the callback and will send it for 
review.

Regards,
Rahul

 


Rackspace

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