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

Re: [PATCH] PCI: don't allow "pci-phantom=" to mark real devices as phantom functions


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 May 2022 17:14:14 +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=JSGEanOad54z07HdaMXq6dBA1EWAZRvjIDUCclOgPuY=; b=CjDxxDQ3HvROXLq85WvFouB4nrXT4YDvjzb3BgRi5eaa1tURLjaviotEs4+oucI/aFUaAKtNqMLF5reIWp/aLfuJcOtJwX5rBywqya1cEtMC6/8ARTtqOg4M/Xd+TidUhZcX20u2P1HXlp2h2OSAD0wz+eCizBV8PsoZYaisrJvYnmnAfJq5hHE4yHvoV6w491SLmO09+GzAe0qxkmDKHCC8i01GLisxUsIdVvs6I1tc7O7Fsd2EE65PnHspB66OA3yKqNhG4fYO7yDrGcOmonPngN1SsVsZZuuycVn3PDzm513oisnkHgoN7L37F8Fjl8ivS+sCnf1PhwdlxZGZ3g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SZens9wMSTeX97vI10dYOW+kpC87RsdU+XbIIfim5iDpSRIo+XZx7u9n2u3wgeSfmFFyw+E43D2RoVZY0PGY/CxyZ1CARl/E2jZzSwBxrppzpnpTm6F9jWUcgaOwaTUcqUOX7eg1H1MnJFz37WUz51vBrgD06H6xUDKGvFcn1ZrWbkwocqI/iE4RlXkfXJC99oapO4psDFyktZDFDexeBMDDoDd7UecmTYVyQXIpUXjpx6yDGmjYvM7MrT9L7Z/Dshx+gWdQD3ZSeOb8E4A3x838nj6EPUzQj/9KoFrbCyMH+fHRF6SXyMWwdGOkkD6LagvrF8ucRUE/+IDRvBmoRQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 05 May 2022 15:14:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.05.2022 17:00, Roger Pau Monné wrote:
> On Fri, Apr 29, 2022 at 03:05:32PM +0200, Jan Beulich wrote:
>> [CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments 
>> unless you have verified the sender and know the content is safe.
>>
>> IOMMU code mapping / unmapping devices and interrupts will misbehave if
>> a wrong command line option declared a function "phantom" when there's a
>> real device at that position. Warn about this and adjust the specified
>> stride (in the worst case ignoring the option altogether).
>>
>> Requested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> 
> Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Thanks.

> FWIW, I would be fine with just discarding the stride option if one of
> the phantom devices happen to report vendor/device IDs on the config
> space.

Well, I thought I'd try a best-effort adjustment rather than simply
ignoring an option.

>> --- a/xen/drivers/passthrough/pci.c
>> +++ b/xen/drivers/passthrough/pci.c
>> @@ -451,7 +451,24 @@ static struct pci_dev *alloc_pdev(struct
>>                           phantom_devs[i].slot == PCI_SLOT(devfn) &&
>>                           phantom_devs[i].stride > PCI_FUNC(devfn) )
>>                      {
>> -                        pdev->phantom_stride = phantom_devs[i].stride;
>> +                        pci_sbdf_t sbdf = pdev->sbdf;
>> +                        unsigned int stride = phantom_devs[i].stride;
>> +
>> +                        while ( (sbdf.fn += stride) > PCI_FUNC(devfn) )
>> +                        {
>> +                            if ( pci_conf_read16(sbdf, PCI_VENDOR_ID) == 
>> 0xffff &&
>> +                                 pci_conf_read16(sbdf, PCI_DEVICE_ID) == 
>> 0xffff )
>> +                                continue;
>> +                            stride <<= 1;
>> +                            printk(XENLOG_WARNING
>> +                                   "%pp looks to be a real device; bumping 
>> %04x:%02x:%02x stride to %u\n",
>> +                                   &sbdf, phantom_devs[i].seg,
>> +                                   phantom_devs[i].bus, 
>> phantom_devs[i].slot,
> 
> Can't you use pdev->sbdf here?

No - sbdf was altered from pdev->sbdf (and is also shorter to use),
and for the 2nd item I'm intentionally omitting the function part
(to match the command line option).

Jan




 


Rackspace

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