All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Vivek Kumar Gautam <vivek.gautam@arm.com>,
	will@kernel.org, julien.thierry.kdev@gmail.com,
	kvm@vger.kernel.org
Cc: andre.przywara@arm.com, lorenzo.pieralisi@arm.com,
	jean-philippe@linaro.org, eric.auger@redhat.com
Subject: Re: [PATCH] vfio/pci: Add support for PCIe extended capabilities
Date: Wed, 8 Sep 2021 17:18:19 +0100	[thread overview]
Message-ID: <d3fefd2e-f2e3-e484-839f-a5d93d4021d9@arm.com> (raw)
In-Reply-To: <867e8db7-c173-5ad2-dca4-69085c89d956@arm.com>

Hi Vivek,

On 9/8/21 10:32 AM, Vivek Kumar Gautam wrote:
> Hi Alex,
>
>
> On 9/3/21 8:45 PM, Alexandru Elisei wrote:
>> Hi Vivek,
>>
>> On 9/2/21 11:48 AM, Vivek Kumar Gautam wrote:
>>> Hi Alex,
>>>
>>>
>>> On 9/2/21 3:29 PM, Alexandru Elisei wrote:
>>>> Hi Vivek,
>>>>
>>>> On 8/10/21 7:25 AM, Vivek Gautam wrote:
>>>>> Add support to parse extended configuration space for vfio based
>>>>> assigned PCIe devices and add extended capabilities for the device
>>>>> in the guest. This allows the guest to see and work on extended
>>>>> capabilities, for example to toggle PRI extended cap to enable and
>>>>> disable Shared virtual addressing (SVA) support.
>>>>> PCIe extended capability header that is the first DWORD of all
>>>>> extended caps is shown below -
>>>>>
>>>>>      31               20  19   16  15                 0
>>>>>      ____________________|_______|_____________________
>>>>>     |    Next cap off    |  1h   |     Cap ID          |
>>>>>     |____________________|_______|_____________________|
>>>>>
>>>>> Out of the two upper bytes of extended cap header, the
>>>>> lower nibble is actually cap version - 0x1.
>>>>> 'next cap offset' if present at bits [31:20], should be
>>>>> right shifted by 4 bits to calculate the position of next
>>>>> capability.
>>>>> This change supports parsing and adding ATS, PRI and PASID caps.
>>>>>
>>>>> Signed-off-by: Vivek Gautam <vivek.gautam@arm.com>
>>>>> ---
>>>>>    include/kvm/pci.h |   6 +++
>>>>>    vfio/pci.c        | 104 ++++++++++++++++++++++++++++++++++++++++++----
>>>>>    2 files changed, 103 insertions(+), 7 deletions(-)
>> [..]
>>>>> @@ -725,7 +815,7 @@ static int vfio_pci_parse_caps(struct vfio_device *vdev)
>>>>>      static int vfio_pci_parse_cfg_space(struct vfio_device *vdev)
>>>>>    {
>>>>> -    ssize_t sz = PCI_DEV_CFG_SIZE_LEGACY;
>>>>> +    ssize_t sz = PCI_DEV_CFG_SIZE;
>>>>>        struct vfio_region_info *info;
>>>>>        struct vfio_pci_device *pdev = &vdev->pci;
>>>>>    @@ -831,10 +921,10 @@ static int vfio_pci_fixup_cfg_space(struct vfio_device
>>>>> *vdev)
>>>>>        /* Install our fake Configuration Space */
>>>>>        info = &vdev->regions[VFIO_PCI_CONFIG_REGION_INDEX].info;
>>>>>        /*
>>>>> -     * We don't touch the extended configuration space, let's be cautious
>>>>> -     * and not overwrite it all with zeros, or bad things might happen.
>>>>> +     * Update the extended configuration space as well since we
>>>>> +     * are now populating the extended capabilities.
>>>>>         */
>>>>> -    hdr_sz = PCI_DEV_CFG_SIZE_LEGACY;
>>>>> +    hdr_sz = PCI_DEV_CFG_SIZE;
>>>>
>>>> In one of the earlier versions of the PCI Express patches I was doing the same
>>>> thing here - overwriting the entire PCI Express configuration space for a
>>>> device.
>>>> However, that made one of the devices I was using for testing stop working when
>>>> assigned to a VM.
>>>>
>>>> I'll go through my testing notes and test it again, the cause of the failure
>>>> might
>>>> have been something else entirely which was fixed since then.
>>>
>>> Sure. Let me know your findings.
>>
>> I think I found the card that doesn't work when overwriting the extended device
>> configuration space. I tried device assignment with a Realtek 8168 Gigabit
>> Ethernet card on a Seattle machine, and the host freezes when I try to start a VM.
>> Even after reset, the machine doesn't boot anymore and it gets stuck during the
>> boot process at this message:
>>
>> NewPackageList status: EFI_SUCCESS
>> BDS.SignalConnectDriversEvent(feeb6d60)
>> BDS.ConnectRootBridgeHandles(feeb6db0)
>>
>> It doesn't go away no matter how many times I reset the machine, to get it booting
>> again I have to pull the plug and plug it again. I tried assigning the device to a
>> VM several times, and this happened every time. The card doesn't have the caps
>> that you added, this is caused entirely by the config space write (tried it with
>> only the config space change).
>>
>> It could be a problem kvmtool, with Linux or with the machine, but this is the
>> only machine where device assignment works and I would like to keep it working
>> with this NIC.
>
> Sorry for the delay in responding. I took sometime off work.
> Sure, we will try to keep your machine working :)
>
>>
>> One solution I see is to add a field to vfio_pci_device (something like has_pcie),
>> and based on that, vfio_pci_fixup_cfg_space() could overwrite only the first 256
>> bytes or the entire device configuration space.
>
> Does the card support PCI extended caps (as seen from the PCI spec v5.0
> section-7.5)?
> If no, then I guess the check that I am planning to add - to check if the device
> supports extended Caps - can help here. Since we would add extended caps based
> on the mentioned check, it seems only valid to have that check before
> overwriting the configuration space.

The card is has PCIE support:

# lspci -v
[..]
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI
Express Gigabit Ethernet Controller (rev 06)
    Subsystem: TP-LINK Technologies Co., Ltd. TG-3468 Gigabit PCI Express Network
Adapter
    Flags: bus master, fast devsel, latency 0, IRQ 255
    I/O ports at 1000 [size=256]
    Memory at 40000000 (64-bit, non-prefetchable) [size=4K]
    Memory at 100000000 (64-bit, prefetchable) [size=16K]
    Capabilities: [40] Power Management version 3
    Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
    Capabilities: [70] Express Endpoint, MSI 01
    Capabilities: [b0] MSI-X: Enable- Count=4 Masked-
    Capabilities: [d0] Vital Product Data
    Capabilities: [100] Advanced Error Reporting
    Capabilities: [140] Virtual Channel
    Capabilities: [160] Device Serial Number d7-40-00-00-68-4c-e0-00

>
>>
>> It's also not clear to me what you are trying to achieve with this patch. Is there
>> a particular device that you want to get working? Or an entire class of devices
>> which have those features? If it's the former, you could have the size of the
>> config space write depend on the vendor + device id. If it's the latter, we could
>> key the size of the config space write based on the presence of those particular
>> PCIE caps and try and fix other devices if they break.
>
> Absolutely, we can check for the presence of PCI extended capabilities and based
> on that write the configuration space. If the device has issue with only a
> specific extended capability we can try to fix that by keying the DevID-VendorID
> pair? What do you think?

My preference would be to overwrite the extended configuration space only for
those devices that have at least of the PCIE capabilities that this patch adds. If
a device doesn't have neither of ATS, PRI or PASID, then kvmtool should not touch
the extended configuration space, similar to how it behaves today.

Thanks,

Alex

>
>>
>> Will, Andre, do you see other solutions? Do you have a preference?
>
> Will, Andre, please let me know as well if you have any preferences.
>
> Best regards
> Vivek
>
>>
>> Thanks,
>>
>> Alex
>>
>>>
>>> Best regards
>>> Vivek
>>>
>>>>
>>>> Thanks,
>>>>
>>>> Alex
>>>>
>>>>>        if (pwrite(vdev->fd, &pdev->hdr, hdr_sz, info->offset) != hdr_sz) {
>>>>>            vfio_dev_err(vdev, "failed to write %zd bytes to Config Space",
>>>>>                     hdr_sz);

  parent reply	other threads:[~2021-09-08 16:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10  6:25 [PATCH] vfio/pci: Add support for PCIe extended capabilities Vivek Gautam
2021-08-31 14:54 ` Will Deacon
2021-09-01 10:27   ` Andre Przywara
2021-09-01 10:44     ` Will Deacon
2021-09-02 10:28       ` Vivek Kumar Gautam
2021-08-31 17:14 ` Andre Przywara
2021-09-02 10:42   ` Vivek Kumar Gautam
2021-09-02  9:59 ` Alexandru Elisei
2021-09-02 10:48   ` Vivek Kumar Gautam
2021-09-03 15:15     ` Alexandru Elisei
2021-09-08  9:32       ` Vivek Kumar Gautam
2021-09-08  9:36         ` Vivek Kumar Gautam
2021-09-08 16:20           ` Alexandru Elisei
2021-09-08 16:18         ` Alexandru Elisei [this message]
2021-10-04  9:47         ` Will Deacon

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=d3fefd2e-f2e3-e484-839f-a5d93d4021d9@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=eric.auger@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=vivek.gautam@arm.com \
    --cc=will@kernel.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.