All of lore.kernel.org
 help / color / mirror / Atom feed
From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@epam.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v8 11/13] vpci: add initial support for virtual PCI bus topology
Date: Fri, 21 Jul 2023 00:43:48 +0000	[thread overview]
Message-ID: <87sf9idrgc.fsf@epam.com> (raw)
In-Reply-To: <414b65eb-1c28-7303-f9fe-cfe5713b9056@suse.com>


Hi Jan,

Jan Beulich <jbeulich@suse.com> writes:

> On 20.07.2023 02:32, Volodymyr Babchuk wrote:
>> --- a/xen/drivers/vpci/vpci.c
>> +++ b/xen/drivers/vpci/vpci.c
>> @@ -46,6 +46,16 @@ void vpci_remove_device(struct pci_dev *pdev)
>>          return;
>>  
>>      spin_lock(&pdev->vpci->lock);
>> +
>> +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
>> +    if ( pdev->vpci->guest_sbdf.sbdf != ~0 )
>> +    {
>> +        __clear_bit(pdev->vpci->guest_sbdf.dev,
>> +                    &pdev->domain->vpci_dev_assigned_map);
>> +        pdev->vpci->guest_sbdf.sbdf = ~0;
>> +    }
>> +#endif
>
> The lock acquired above is not ...

vpci_remove_device() is called when d->pci_lock is already held.

But, I'll move this hunk before spin_lock(&pdev->vpci->lock); we don't
need to hold it while cleaning vpci_dev_assigned_map

>> @@ -115,6 +129,54 @@ int vpci_add_handlers(struct pci_dev *pdev)
>>  }
>>  
>>  #ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT
>> +static int add_virtual_device(struct pci_dev *pdev)
>> +{
>> +    struct domain *d = pdev->domain;
>> +    pci_sbdf_t sbdf = { 0 };
>> +    unsigned long new_dev_number;
>> +
>> +    if ( is_hardware_domain(d) )
>> +        return 0;
>> +
>> +    ASSERT(pcidevs_locked());
>> +
>> +    /*
>> +     * Each PCI bus supports 32 devices/slots at max or up to 256 when
>> +     * there are multi-function ones which are not yet supported.
>> +     */
>> +    if ( pdev->info.is_extfn )
>> +    {
>> +        gdprintk(XENLOG_ERR, "%pp: only function 0 passthrough supported\n",
>> +                 &pdev->sbdf);
>> +        return -EOPNOTSUPP;
>> +    }
>> +
>> +    write_lock(&pdev->domain->pci_lock);
>> +    new_dev_number = find_first_zero_bit(d->vpci_dev_assigned_map,
>> +                                         VPCI_MAX_VIRT_DEV);
>> +    if ( new_dev_number >= VPCI_MAX_VIRT_DEV )
>> +    {
>> +        write_unlock(&pdev->domain->pci_lock);
>> +        return -ENOSPC;
>> +    }
>> +
>> +    __set_bit(new_dev_number, &d->vpci_dev_assigned_map);
>
> ... the same as the one held here, so the bitmap still isn't properly
> protected afaics, unless the intention is to continue to rely on
> the global PCI lock (assuming that one's held in both cases, which I
> didn't check it is). Conversely it looks like the vPCI lock isn't
> held here. Both aspects may be intentional, but the locks being
> acquired differing requires suitable code comments imo.

As I stated above, vpci_remove_device() is called when d->pci_lock is
already held.


> I've also briefly looked at patch 1, and I'm afraid that still lacks
> commentary about intended lock nesting. That might be relevant here
> in case locking visible from patch / patch context isn't providing
> the full picture.
>

There is
    ASSERT(rw_is_write_locked(&pdev->domain->pci_lock));
at the beginning of vpci_remove_device(), which is added by
"vpci: use per-domain PCI lock to protect vpci structure".

I believe, it will be more beneficial to review series from the
beginning.

>> +    /*
>> +     * Both segment and bus number are 0:
>> +     *  - we emulate a single host bridge for the guest, e.g. segment 0
>> +     *  - with bus 0 the virtual devices are seen as embedded
>> +     *    endpoints behind the root complex
>> +     *
>> +     * TODO: add support for multi-function devices.
>> +     */
>> +    sbdf.devfn = PCI_DEVFN(new_dev_number, 0);
>> +    pdev->vpci->guest_sbdf = sbdf;
>> +    write_unlock(&pdev->domain->pci_lock);
>
> With the above I also wonder whether this lock can't (and hence
> should) be dropped a little earlier (right after fiddling with the
> bitmap).

This is the good observation, thanks.

-- 
WBR, Volodymyr

  reply	other threads:[~2023-07-21  0:44 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  0:32 [PATCH v8 00/13] PCI devices passthrough on Arm, part 3 Volodymyr Babchuk
2023-07-20  0:32 ` [PATCH v8 04/13] vpci: add hooks for PCI device assign/de-assign Volodymyr Babchuk
2023-07-20 12:36   ` Roger Pau Monné
2023-07-26  1:38     ` Volodymyr Babchuk
2023-07-26  8:42       ` Roger Pau Monné
2023-07-24  9:41   ` Jan Beulich
2023-07-20  0:32 ` [PATCH v8 01/13] pci: introduce per-domain PCI rwlock Volodymyr Babchuk
2023-07-20  9:45   ` Roger Pau Monné
2023-07-20 22:57     ` Volodymyr Babchuk
2023-07-20 15:40   ` Jan Beulich
2023-07-20 23:37     ` Volodymyr Babchuk
2023-07-20  0:32 ` [PATCH v8 03/13] vpci: restrict unhandled read/write operations for guests Volodymyr Babchuk
2023-07-20 11:32   ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 02/13] vpci: use per-domain PCI lock to protect vpci structure Volodymyr Babchuk
2023-07-20 11:20   ` Roger Pau Monné
2023-07-20 13:27     ` Jan Beulich
2023-07-20 13:50       ` Roger Pau Monné
2023-07-24  0:07         ` Volodymyr Babchuk
2023-07-24  7:59           ` Roger Pau Monné
2023-07-20 15:53     ` Jan Beulich
2023-07-26  1:17     ` Volodymyr Babchuk
2023-07-26  6:39       ` Jan Beulich
2023-07-26  9:35       ` Roger Pau Monné
2023-07-27  0:56         ` Volodymyr Babchuk
2023-07-27  7:41           ` Jan Beulich
2023-07-27 10:31             ` Volodymyr Babchuk
2023-07-27 11:37               ` Jan Beulich
2023-07-27 15:13                 ` Volodymyr Babchuk
2023-07-27 12:42           ` Roger Pau Monné
2023-07-27 12:56             ` Jan Beulich
2023-07-27 14:43               ` Roger Pau Monné
2023-07-28  0:21             ` Volodymyr Babchuk
2023-07-28 13:55               ` Roger Pau Monné
2023-07-20 16:03   ` Jan Beulich
2023-07-20 16:14     ` Roger Pau Monné
2023-07-21  6:02       ` Jan Beulich
2023-07-21  7:43         ` Roger Pau Monné
2023-07-21  8:48           ` Jan Beulich
2023-07-20 16:09   ` Jan Beulich
2023-07-20  0:32 ` [PATCH v8 05/13] vpci/header: implement guest BAR register handlers Volodymyr Babchuk
2023-07-20 16:01   ` Roger Pau Monné
2023-07-21 10:36   ` Rahul Singh
2023-07-21 10:50     ` Jan Beulich
2023-07-21 11:52       ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 06/13] rangeset: add RANGESETF_no_print flag Volodymyr Babchuk
2023-07-20  0:32 ` [PATCH v8 07/13] vpci/header: handle p2m range sets per BAR Volodymyr Babchuk
2023-07-21 11:49   ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 09/13] vpci/header: emulate PCI_COMMAND register for guests Volodymyr Babchuk
2023-07-21 13:32   ` Roger Pau Monné
2023-07-21 13:40     ` Roger Pau Monné
2023-07-24 11:06     ` Jan Beulich
2023-07-24 11:03   ` Jan Beulich
2023-07-20  0:32 ` [PATCH v8 10/13] vpci/header: reset the command register when adding devices Volodymyr Babchuk
2023-07-21 13:37   ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 08/13] vpci/header: program p2m with guest BAR view Volodymyr Babchuk
2023-07-21 13:05   ` Roger Pau Monné
2023-07-24 10:30     ` Jan Beulich
2023-07-24 10:43   ` Jan Beulich
2023-07-24 13:16     ` Roger Pau Monné
2023-07-24 13:31       ` Jan Beulich
2023-07-24 13:42         ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 11/13] vpci: add initial support for virtual PCI bus topology Volodymyr Babchuk
2023-07-20  6:50   ` Jan Beulich
2023-07-21  0:43     ` Volodymyr Babchuk [this message]
2023-07-21 13:53   ` Roger Pau Monné
2023-07-21 14:00   ` Roger Pau Monné
2023-07-26 21:35   ` Stewart Hildebrand
2023-07-20  0:32 ` [PATCH v8 12/13] xen/arm: translate virtual PCI bus topology for guests Volodymyr Babchuk
2023-07-20  6:54   ` Jan Beulich
2023-07-21 14:09   ` Roger Pau Monné
2023-07-24  8:02   ` Roger Pau Monné
2023-07-20  0:32 ` [PATCH v8 13/13] xen/arm: account IO handlers for emulated PCI MSI-X Volodymyr Babchuk
2023-07-20  0:41 ` [PATCH v8 00/13] PCI devices passthrough on Arm, part 3 Volodymyr Babchuk

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=87sf9idrgc.fsf@epam.com \
    --to=volodymyr_babchuk@epam.com \
    --cc=Oleksandr_Andrushchenko@epam.com \
    --cc=jbeulich@suse.com \
    --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.