All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@epam.com>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"julien@xen.org" <julien@xen.org>,
	"sstabellini@kernel.org" <sstabellini@kernel.org>,
	Oleksandr Tyshchenko <Oleksandr_Tyshchenko@epam.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Artem Mygaiev <Artem_Mygaiev@epam.com>,
	"jbeulich@suse.com" <jbeulich@suse.com>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Rahul Singh <rahul.singh@arm.com>,
	Oleksandr Andrushchenko <Oleksandr_Andrushchenko@epam.com>
Subject: Re: [PATCH v3 11/11] xen/arm: Translate virtual PCI bus topology for guests
Date: Tue, 26 Oct 2021 13:57:35 +0000	[thread overview]
Message-ID: <6ce216ce-d25f-5016-3752-79b90a1112af@epam.com> (raw)
In-Reply-To: <YXgC5QB2MDZlZeEZ@MacBook-Air-de-Roger.local>

Hi, Roger!

On 26.10.21 16:30, Roger Pau Monné wrote:
> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
>> index fa6fcc5e467c..095671742ad8 100644
>> --- a/xen/arch/arm/domain.c
>> +++ b/xen/arch/arm/domain.c
>> @@ -797,6 +797,7 @@ void arch_domain_destroy(struct domain *d)
>>                          get_order_from_bytes(d->arch.efi_acpi_len));
>>   #endif
>>       domain_io_free(d);
>> +    domain_vpci_free(d);
> It's a nit, but I think from a logical PoV this should be inverted?
> You first free the handlers and then the IO infrastructure.
Indeed, thanks
>
>>   }
>>   
>>   void arch_domain_shutdown(struct domain *d)
>> diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c
>> index 5d6c29c8dcd9..26ec2fa7cf2d 100644
>> --- a/xen/arch/arm/vpci.c
>> +++ b/xen/arch/arm/vpci.c
>> @@ -17,6 +17,14 @@
>>   
>>   #define REGISTER_OFFSET(addr)  ( (addr) & 0x00000fff)
>>   
>> +struct vpci_mmio_priv {
>> +    /*
>> +     * Set to true if the MMIO handlers were set up for the emulated
>> +     * ECAM host PCI bridge.
>> +     */
>> +    bool is_virt_ecam;
>> +};
> Is this strictly required? It feels a bit odd to have a structure to
> store and single boolean.
>
> I think you could replace it's usage with is_hardware_domain.
I am working on some "earlier" patch fixes [1] which already needs some private
to be passed to the handlers: we need to set sbdf.seg to the proper
host bridge segment instead of always setting it to 0.
And then I can pass "struct pci_host_bridge *bridge" as the private member
and use is_hardware_domain(v->domain) to see if this is guest or hwdom.
So, I'll remove the structure completely

[snip]

>> + */
>>   static int vpci_setup_mmio_handler(struct domain *d,
>>                                      struct pci_host_bridge *bridge)
>>   {
>> -    struct pci_config_window *cfg = bridge->cfg;
>> +    struct vpci_mmio_priv *priv;
>> +
>> +    priv = xzalloc(struct vpci_mmio_priv);
>> +    if ( !priv )
>> +        return -ENOMEM;
>> +
>> +    priv->is_virt_ecam = !is_hardware_domain(d);
>>   
>> -    register_mmio_handler(d, &vpci_mmio_handler,
>> -                          cfg->phys_addr, cfg->size, NULL);
>> +    if ( is_hardware_domain(d) )
>> +    {
>> +        struct pci_config_window *cfg = bridge->cfg;
>> +
>> +        bridge->mmio_priv = priv;
>> +        register_mmio_handler(d, &vpci_mmio_handler,
>> +                              cfg->phys_addr, cfg->size,
>> +                              priv);
>> +    }
>> +    else
>> +    {
>> +        d->vpci_mmio_priv = priv;
>> +        /* Guest domains use what is programmed in their device tree. */
>> +        register_mmio_handler(d, &vpci_mmio_handler,
>> +                              GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE,
>> +                              priv);
>> +    }
>>       return 0;
>>   }
>>   
>> @@ -95,14 +154,25 @@ int domain_vpci_init(struct domain *d)
>>       if ( !has_vpci(d) )
>>           return 0;
>>   
>> +    return pci_host_iterate_bridges(d, vpci_setup_mmio_handler);
> I think this is wrong for unprivileged domains: you iterate against
> host bridges but just setup a single ECAM region from
> GUEST_VPCI_ECAM_BASE to GUEST_VPCI_ECAM_SIZE, so you are leaking
> multiple allocations of vpci_mmio_priv, and also adding a bunch of
> duplicated IO handlers for the same ECAM region.
>
> IMO you should iterate against host bridges only for the hardware
> domain case. For the unpriviledged domain case there's no need to
> iterate against the list of physical host bridges as you end up
> exposing a fully emulated bus which bears no resemblance to the
> physical setup.
Yes, I am moving this code into that "earlier" patch [1] and already
spotted the leak: thus I am also re-working this code.
>
>> +}
>> +
>> +static int domain_vpci_free_cb(struct domain *d,
>> +                               struct pci_host_bridge *bridge)
>> +{
>>       if ( is_hardware_domain(d) )
>> -        return pci_host_iterate_bridges(d, vpci_setup_mmio_handler);
>> +        XFREE(bridge->mmio_priv);
>> +    else
>> +        XFREE(d->vpci_mmio_priv);
>> +    return 0;
>> +}
>>   
>> -    /* Guest domains use what is programmed in their device tree. */
>> -    register_mmio_handler(d, &vpci_mmio_handler,
>> -                          GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL);
>> +void domain_vpci_free(struct domain *d)
>> +{
>> +    if ( !has_vpci(d) )
>> +        return;
>>   
>> -    return 0;
>> +    pci_host_iterate_bridges(d, domain_vpci_free_cb);
> Why do we need to iterate the host bridges for unprivileged domains?
No need, I am taking care of this
> AFAICT it just causes duplicated calls to XFREE(d->vpci_mmio_priv). I
> would expect something like:
>
> static int bridge_free_cb(struct domain *d,
>                            struct pci_host_bridge *bridge)
> {
>      ASSERT(is_hardware_domain(d));
>      XFREE(bridge->mmio_priv);
>      return 0;
> }
>
> void domain_vpci_free(struct domain *d)
> {
>      if ( !has_vpci(d) )
>          return;
>
>      if ( is_hardware_domain(d) )
>          pci_host_iterate_bridges(d, bridge_free_cb);
>      else
>          XFREE(d->vpci_mmio_priv);
> }
>
> Albeit I think there's no need for vpci_mmio_priv in the first place.
>
> Thanks, Roger.
Thank you,
Oleksandr

[1] https://patchwork.kernel.org/project/xen-devel/patch/20211008055535.337436-9-andr2000@gmail.com/

      reply	other threads:[~2021-10-26 13:58 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30  7:52 [PATCH v3 00/11] PCI devices passthrough on Arm, part 3 Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 01/11] vpci: Make vpci registers removal a dedicated function Oleksandr Andrushchenko
2021-10-13 11:11   ` Roger Pau Monné
2021-10-27  9:12     ` Oleksandr Andrushchenko
2021-10-27  9:24       ` Roger Pau Monné
2021-10-27  9:41         ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 02/11] vpci: Add hooks for PCI device assign/de-assign Oleksandr Andrushchenko
2021-09-30  8:21   ` Jan Beulich
2021-09-30  8:45     ` Oleksandr Andrushchenko
2021-09-30  9:06       ` Jan Beulich
2021-09-30  9:21         ` Oleksandr Andrushchenko
2021-09-30 10:14           ` Jan Beulich
2021-09-30 10:30             ` Oleksandr Andrushchenko
2021-10-13 11:29   ` Roger Pau Monné
2021-10-13 12:47     ` Jan Beulich
2021-10-27  9:53     ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 03/11] vpci/header: Move register assignments from init_bars Oleksandr Andrushchenko
2021-10-13 13:51   ` Roger Pau Monné
2021-10-15  6:04     ` Jan Beulich
2021-10-25 14:28       ` Roger Pau Monné
2021-10-27 10:17     ` Oleksandr Andrushchenko
2021-10-27 11:59       ` Oleksandr Andrushchenko
2021-10-27 13:23         ` Roger Pau Monné
2021-10-27 14:06           ` Oleksandr Andrushchenko
2021-10-27 15:34             ` Roger Pau Monné
2021-09-30  7:52 ` [PATCH v3 04/11] vpci/header: Add and remove register handlers dynamically Oleksandr Andrushchenko
2021-10-01 13:26   ` Jan Beulich
2021-10-04  5:58     ` Oleksandr Andrushchenko
2021-10-07  7:22       ` Jan Beulich
2021-10-13 15:38         ` Roger Pau Monné
2021-10-15  6:09           ` Jan Beulich
2021-10-25 15:48   ` Roger Pau Monné
2021-11-01  9:18     ` Oleksandr Andrushchenko
2021-11-02 10:03       ` Roger Pau Monné
2021-11-02 10:29         ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 05/11] vpci/header: Implement guest BAR register handlers Oleksandr Andrushchenko
2021-10-01 13:31   ` Jan Beulich
2021-10-26  7:50   ` Roger Pau Monné
2021-10-26  8:09     ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 06/11] vpci/header: Handle p2m range sets per BAR Oleksandr Andrushchenko
2021-10-25 11:51   ` Oleksandr Andrushchenko
2021-10-26  9:40     ` Roger Pau Monné
2021-11-02 11:13       ` Jan Beulich
2021-10-26  9:08   ` Roger Pau Monné
2021-11-02 10:34     ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 07/11] vpci/header: program p2m with guest BAR view Oleksandr Andrushchenko
2021-10-01 13:38   ` Jan Beulich
2021-10-04  6:26     ` Oleksandr Andrushchenko
2021-10-26 10:35   ` Roger Pau Monné
2021-11-02 10:43     ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 08/11] vpci/header: Emulate PCI_COMMAND register for guests Oleksandr Andrushchenko
2021-10-26 10:52   ` Roger Pau Monné
2021-11-02 10:48     ` Oleksandr Andrushchenko
2021-11-02 11:19     ` Jan Beulich
2021-11-02 11:50       ` Roger Pau Monné
2021-11-02 13:54         ` Jan Beulich
2021-11-02 14:10           ` Oleksandr Andrushchenko
2021-11-03  8:53             ` Oleksandr Andrushchenko
2021-11-03  9:11               ` Jan Beulich
2021-11-03  9:18                 ` Oleksandr Andrushchenko
2021-11-03  9:24                   ` Jan Beulich
2021-11-03  9:30                     ` Oleksandr Andrushchenko
2021-11-03  9:49                       ` Jan Beulich
2021-11-03 10:24                         ` Oleksandr Andrushchenko
2021-11-03 10:34                           ` Jan Beulich
2021-11-03 10:36                             ` Oleksandr Andrushchenko
2021-11-03 11:01                               ` Roger Pau Monné
2021-11-03 11:02                                 ` Oleksandr Andrushchenko
2021-11-03 11:26                                   ` Roger Pau Monné
2021-11-03 11:34                                     ` Oleksandr Andrushchenko
2021-11-03  9:39                   ` Roger Pau Monné
2021-11-03  9:50                     ` Oleksandr Andrushchenko
2021-11-02 14:17         ` Julien Grall
2021-09-30  7:52 ` [PATCH v3 09/11] vpci/header: Reset the command register when adding devices Oleksandr Andrushchenko
2021-10-26 11:00   ` Roger Pau Monné
2021-11-02 11:11     ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 10/11] vpci: Add initial support for virtual PCI bus topology Oleksandr Andrushchenko
2021-09-30  8:51   ` Jan Beulich
2021-09-30  9:34     ` Oleksandr Andrushchenko
2021-09-30 10:23       ` Jan Beulich
2021-09-30 10:26         ` Oleksandr Andrushchenko
2021-10-26 11:33   ` Roger Pau Monné
2021-11-03  6:34     ` Oleksandr Andrushchenko
2021-11-03  8:41       ` Jan Beulich
2021-11-03  8:57         ` Oleksandr Andrushchenko
2021-11-03  8:52       ` Roger Pau Monné
2021-11-03  8:59         ` Oleksandr Andrushchenko
2021-09-30  7:52 ` [PATCH v3 11/11] xen/arm: Translate virtual PCI bus topology for guests Oleksandr Andrushchenko
2021-09-30  8:53   ` Jan Beulich
2021-09-30  9:35     ` Oleksandr Andrushchenko
2021-09-30 10:25       ` Jan Beulich
2021-09-30 16:57     ` Oleksandr Andrushchenko
2021-10-01  7:42       ` Jan Beulich
2021-10-01  7:57         ` Oleksandr Andrushchenko
2021-10-01  8:12           ` Jan Beulich
2021-10-18 18:32   ` Julien Grall
2021-10-26 13:30   ` Roger Pau Monné
2021-10-26 13:57     ` Oleksandr Andrushchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ce216ce-d25f-5016-3752-79b90a1112af@epam.com \
    --to=oleksandr_andrushchenko@epam.com \
    --cc=Artem_Mygaiev@epam.com \
    --cc=Oleksandr_Tyshchenko@epam.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=rahul.singh@arm.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.