[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: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 19 May 2022 14:22:35 +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=xSVvAn9AgHGc4nGZhUV6MD2LeqinleQj4ejUP9yl9XQ=; b=ktwgxTMhe7FilWTZ/fYA5JtFWH2mxRHqHXKuGyCMRsYUZ5bcXa2wHbLDj2z5+Ohzcrd+QtD4tX7Z9MFOmGasg9IXJqEGWM38hRcR2LCkkvGl0589p5es40kGqxi0f/CCV9eWRmj89trjqM9RNYtgLv93W+bJy6j0ThbyIGg0wt3Kn5NBYCtUMTj8a62v3yPu8UGE6sLJXn/iOLpFNcuObpoTCqEKlZyM4qdMS6jp5NG+a6cytaGLlinKt1SJVhZs6HywqOQGvnAo+mCRQauBK4Vw4RDl42caKwn/BkfBv59O/35Cknh96AhMfnyeA4RsU4NT6u+zqLu2jUYqqtYxbQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B2MATuYi1MYHwt35YauMLDrGJy3bwHdMRaLDlN7jpxK8k7WpTNm9ProHG3hc4+gkl2wsAow5ljj/q/uQBwY1H4ka9ewXHxZ/GK9Yl5+IO8r4f8iYH1QwHk1lG3PH9Kii+/wDIGqVFMmEP0hO7Xs4Oh9DqSXuysirKWzAhAyTCYrbaV04eCCRF2SLaCyw1SXIyRNe3tvj17X79mHL/9HbwS23pSa9cmGGAoAj210Yc7s56tTcyVz3YSDkG+oFzgcL8FVxZQts58y5Wb8FBY/WqYXQBKiNLDnRx8dn+9uX45x7WnkjEghSbPgjHCwkgAEqPlnl3mhsXe7f3FFqeKs2bA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 19 May 2022 12:22:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 06.05.2022 08:21, Jan Beulich wrote:
> On 05.05.2022 21:10, Andrew Cooper wrote:
>> On 29/04/2022 14:05, 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>
>>>
>>> --- 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) )
>>
>> I'm fairly sure this doesn't do what you want it to.
>>
>> .fn is a 3 bit bitfield, meaning the += will be truncated before the
>> compare.
> 
> And this is precisely what I'm after: I want to stop once the value
> has wrapped.
> 
>>> +                        {
>>> +                            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,
>>> +                                   stride);
>>> +                            sbdf = pdev->sbdf;
>>> +                        }
>>> +                        if ( PCI_FUNC(stride) )
>>
>> This is an obfuscated way of writing stride < 8.
> 
> And intentionally so, matching a few other similar instances elsewhere.
> An open-coded 8 here doesn't really make clear where that 8 would be
> coming from. The use of PCI_FUNC(), otoh, documents what's meant.
> 
>> Given the printk(), if we actually find an 8-function device, what gets
>> printed (AFAICT) will be "bumping to 8" when in fact we mean "totally
>> ignoring the option".  I think this really wants an else clause.
> 
> Yes, "bumping to 8" is what is being printed in that case. I did
> realize the slight anomaly when writing the code and I observed
> (verified) it also in testing. But I didn't see a good reason for an
> "else" here - 8 being mentioned in the log message is clear enough
> for anyone vaguely understanding phantom functions. But if you strongly
> think we need to make the code yet larger and indentation yet
> unhelpfully deeper, then I will (begrudgingly) do what you ask for. But
> please explicitly confirm.

Like for the first few patches of the IOMMU large page series, I'm
going to put this in (with Roger's R-b) by the end of the week on
the assumption that my reply (above) did address your concerns.

Jan




 


Rackspace

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