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

Re: [PATCH v7 11/12] xen/arm: translate virtual PCI bus topology for guests


  • To: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 21 Jun 2023 14:01:16 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • 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=2qc27JLJOW39TUJfs/mU/xG1kL3Dz735MZYTZHw6s5c=; b=FXSyFCKjQ5xn/rmxmkMC56mduFhADe0CgYMXzTkeYntKitAr9SF0cK5HIiGtIZTct1xwq3AhofL0UVjF23Y3AlOldRoLQJZO72fQ+5NhGQp8RFgxPC874rWwQYjGjyhGTshmAgxS4QxnK4//O4snmfq/O/KGHuJQ5iTSJ7UvSW1soHujTRGzidIjgH9orDsL1WlV23b47gfa6FmZarkXIGj2hWDZMEoH3l/xImBy9x+onPJjaEdfV/gsXslGbB0ShV+91T3Ml+vgJfGnRqJzyafoWUIB66BW0NL4IDzfNs05vX4lUD+TeQ26nmToHEMHlY9MPn4Vz/mnmmEdadmRWg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QbNWdWGHeT7Orn6uoB8M6zVOJ3Qvm+ALJciuP5T2jn2CO6vkYXKbA5gGL5WHyevquRmNUCdc4zo7KfjFdoYqQwL4QrzHokow83N+zI9onPpcJpIjqtuoyVpVceDeV6v6s4OMuVtPkBCdKwj5EQNPurIqD6VDg3RsRPJtAESMPXWt1GsSKk0gX3hxkex8FHR+f/xlwohyhzIarSR1lX2RV8VLCSUuKAHr9pfsjdsIKTQ1OUjyB0TedNzOww0cxSqrw53G8Y/PR87RAYpRrzoj1uqkW05rk70gB9Nsn53VgQczGnOKvCwMafSTBY6ix9jb1oov0srktMIrCFOsRcFizw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 21 Jun 2023 12:01:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 13.06.2023 12:32, Volodymyr Babchuk wrote:
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -180,6 +180,44 @@ static void vpci_remove_virtual_device(const struct 
> pci_dev *pdev)
>      write_unlock(&pdev->domain->vpci_rwlock);
>  }
>  
> +/*
> + * Find the physical device which is mapped to the virtual device
> + * and translate virtual SBDF to the physical one.
> + */
> +bool vpci_translate_virtual_device(struct domain *d, pci_sbdf_t *sbdf)
> +{
> +    struct pci_dev *pdev;
> +
> +    ASSERT(!is_hardware_domain(d));
> +
> +    read_lock(&d->vpci_rwlock);
> +    pcidevs_lock();
> +    for_each_pdev( d, pdev )
> +    {
> +        bool found;
> +
> +        if ( !pdev->vpci )
> +            continue;
> +
> +        spin_lock(&pdev->vpci->lock);

Following the description of patch 1, why does this lock need acquiring here?
The r/w lock acquired above should already guard against modification.

> +        found = pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf);

The LHS of the && is pointless here - when acquiring the lock you have
already de-referenced pdev->vpci.

> +        spin_unlock(&pdev->vpci->lock);
> +
> +        if ( found )
> +        {
> +            /* Replace guest SBDF with the physical one. */
> +            *sbdf = pdev->sbdf;
> +            pcidevs_unlock();
> +            read_unlock(&d->vpci_rwlock);
> +            return true;

What use is the result to the caller with all locks dropped, and hence
state possibly having changed before the caller gets a chance to look
at the result? If there are reason why this is okay, you want to (a)
spell out those reasons in the description and (b) document this
restriction in a comment, to warn people who may want to (re)use this
function. But really I think the caller needs to hold a suitable lock
until after the result from here was consumed.

Jan



 


Rackspace

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