WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] disallow duplicate pci device strings in guest c

To: "Cui, Dexuan" <dexuan.cui@xxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] disallow duplicate pci device strings in guest config file
From: Simon Horman <horms@xxxxxxxxxxxx>
Date: Sat, 16 May 2009 14:52:39 +1000
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Keir Fraser <Keir.Fraser@xxxxxxxxxxxxx>
Delivery-date: Fri, 15 May 2009 21:53:04 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <EADF0A36011179459010BDF5142A457501C990A939@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <EADF0A36011179459010BDF5142A457501C990A939@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.18 (2008-05-17)
On Fri, May 15, 2009 at 07:31:23PM +0800, Cui, Dexuan wrote:
> When we specify duplicate pci device strings in guest config file, like 
> pci=['01:00.0', '01:00.0'], or  pci=['01:00.0', '0000:01:00.0'], or  
> pci=['01:00.0', '0000:01:00.0@7'],
> xend doesn't detect this case and passes the pci string to ioemu and ioemu 
> invokes register_real_device() twice for the same physical device and this 
> could cause unexpected behavior.
> 
> The patch detects this case and makes the domain construction fail.
> 
> diff -r 40d4267296ad tools/python/xen/xend/server/pciif.py
> --- a/tools/python/xen/xend/server/pciif.py   Fri May 15 08:12:39 2009 +0100
> +++ b/tools/python/xen/xend/server/pciif.py   Fri May 15 17:14:43 2009 +0800
> @@ -396,6 +396,9 @@ class PciController(DevController):
>              pci_str = '%04x:%02x:%02x.%01x' % (domain, bus, slot, func)
>              pci_str_list = pci_str_list + [pci_str]
>              pci_dev_list = pci_dev_list + [(domain, bus, slot, func)]
> +
> +        if pci_str_list != list(set(pci_str_list)):
> +            raise VmError('pci: duplicate devices specified in guest 
> config?')
>  
>          for (domain, bus, slot, func) in pci_dev_list:
>              try:

Hi Dexuan, Hi Keir,

At a glance it seems that this might not be correct,
as set() may not preserve the order of pci_str_list.
However, as set will remove any duplicates, its probably
sufficient to use:

        if len(pci_str_list) != len(set(pci_str_list):

Some musings in code:

# python
>>> pci_str_list = [ "01:00.1", "01:00.0" ]
>>> print pci_str_list
['01:00.1', '01:00.0']
>>> print set(pci_str_list)
set(['01:00.0', '01:00.1'])
>>> print list(set(pci_str_list))
['01:00.0', '01:00.1']

>>> pci_str_list= [ "01:00.1", "01:00.0", "01:00.0" ]
>>> print list(set(pci_str_list))
>>> print len(set(pci_str_list))
2
>>> print len(pci_str_list)
3


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel