From: Tomita Moeko <tomitamoeko@gmail.com>
To: "Cédric Le Goater" <clg@redhat.com>,
"Alex Williamson" <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v2 3/5] vfio/igd: refactor vfio_probe_igd_bar4_quirk() into pci config quirk
Date: Mon, 3 Feb 2025 00:24:59 +0800 [thread overview]
Message-ID: <bedb349f-d570-40b6-b0b8-8f85e54859d9@gmail.com> (raw)
In-Reply-To: <009cbf4b-ae21-4bdc-a288-251a6167ff34@redhat.com>
On 1/31/25 17:14, Cédric Le Goater wrote:
> Hello Tomita,
>
> On 1/24/25 20:12, Tomita Moeko wrote:
>> The actual IO BAR4 write quirk in vfio_probe_igd_bar4_quirk() was
>> removed in previous change, leaving the function not matching its name,
>> so move it into the newly introduced vfio_config_quirk_setup(). There
>> is no functional change in this commit. If any failure occurs, the
>> function simply returns and proceeds.
>>
>> Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
>> ---
>> hw/vfio/igd.c | 31 +++++++++++++++++--------------
>> hw/vfio/pci-quirks.c | 6 +++++-
>> hw/vfio/pci.h | 2 +-
>> 3 files changed, 23 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
>> index ca3a32f4f2..376a26fbae 100644
>> --- a/hw/vfio/igd.c
>> +++ b/hw/vfio/igd.c
>> @@ -359,7 +359,8 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
>> QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next);
>> }
>> -void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> +bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev,
>> + Error **errp G_GNUC_UNUSED)
>
> Adding an 'Error **' parameter is in improvement indeed. All the error_report
> of this routine need to be converted too.
Sorry I missed this mail previously.
Originally this function simply return and continue on error, I prefer
keeping current behavior until legacy mode was finally removed, as I
described in my reply to Alex. At that point, this function will
terminate and report on error.
>> {
>> g_autofree struct vfio_region_info *rom = NULL;
>> g_autofree struct vfio_region_info *opregion = NULL;
>> @@ -378,10 +379,10 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> * PCI bus address.
>> */
>> if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
>> - !vfio_is_vga(vdev) || nr != 4 ||
>> + !vfio_is_vga(vdev) ||
>> &vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
>> 0, PCI_DEVFN(0x2, 0))) {
>> - return;
>> + return true;
>> }
>> /*
>> @@ -395,7 +396,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> "vfio-pci-igd-lpc-bridge")) {
>> error_report("IGD device %s cannot support legacy mode due to existing "
>> "devices at address 1f.0", vdev->vbasedev.name);
>> - return;
>> + return true;
>
> if there is an error_report, why is this returning true ? It should be false.
Please see my comment above
>> }
>> /*
>> @@ -407,7 +408,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (gen == -1) {
>> error_report("IGD device %s is unsupported in legacy mode, "
>> "try SandyBridge or newer", vdev->vbasedev.name);
>> - return;
>> + return true;
>
> same here and else where.
>
>> }
>> /*
>> @@ -420,7 +421,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if ((ret || !rom->size) && !vdev->pdev.romfile) {
>> error_report("IGD device %s has no ROM, legacy mode disabled",
>> vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> /*
>> @@ -431,7 +432,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> error_report("IGD device %s hotplugged, ROM disabled, "
>> "legacy mode disabled", vdev->vbasedev.name);
>> vdev->rom_read_failed = true;
>> - return;
>> + return true;
>> }
>> /*
>> @@ -444,7 +445,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (ret) {
>> error_report("IGD device %s does not support OpRegion access,"
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> ret = vfio_get_dev_region_info(&vdev->vbasedev,
>> @@ -453,7 +454,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (ret) {
>> error_report("IGD device %s does not support host bridge access,"
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> ret = vfio_get_dev_region_info(&vdev->vbasedev,
>> @@ -462,7 +463,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (ret) {
>> error_report("IGD device %s does not support LPC bridge access,"
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
>> @@ -476,7 +477,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> error_report("IGD device %s failed to enable VGA access, "
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> /* Create our LPC/ISA bridge */
>> @@ -484,7 +485,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (ret) {
>> error_report("IGD device %s failed to create LPC bridge, "
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> /* Stuff some host values into the VM PCI host bridge */
>> @@ -492,14 +493,14 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> if (ret) {
>> error_report("IGD device %s failed to modify host bridge, "
>> "legacy mode disabled", vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> /* Setup OpRegion access */
>> if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) {
>> error_append_hint(&err, "IGD legacy mode disabled\n");
>> error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> - return;
>> + return true;
>> }
>> /*
>> @@ -561,4 +562,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
>> trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name,
>> (ggms_size + gms_size) / MiB);
>> +
>> + return true;
>> }
>> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
>> index c40e3ca88f..b8379cb512 100644
>> --- a/hw/vfio/pci-quirks.c
>> +++ b/hw/vfio/pci-quirks.c
>> @@ -1169,6 +1169,11 @@ bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
>> */
>> bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +#ifdef CONFIG_VFIO_IGD
>
> oh. We try to avoid such ifdef in QEMU. Only very specific and high level
> configs are discarded at compile time (KVM, LINUX, etc).
This ifdef has been in QEMU code, for only building igd-related code
into x86 target (VFIO_IGD is only seleted when PC_PCI=on, and I440FX/
Q35 selests PC_PCI). IMO using the ifdef here is reasonable, as IGD
quirks is a part of vfio-pci, but using QOM in furure would be a
good direction.
> One way to adress this case, would be to use QOM. Example below :
>
>
> Declare a base class :
> #define TYPE_VFIO_PCI_QUIRK_PROVIDER "vfio-pci-quirk-provider"
> OBJECT_DECLARE_TYPE(VFIOPCIQuirkProvider, VFIOPCIQuirkProviderClass,
> VFIO_PCI_QUIRK_PROVIDER)
> struct VFIOPCIQuirkProviderClass {
> ObjectClass parent;
> bool (*probe)(VFIOPCIDevice *vdev, Error **errp);
> bool (*setup)(VFIOPCIDevice *vdev, Error **errp);
> };
> static const TypeInfo vfio_pci_quirk_info = {
> .name = TYPE_VFIO_PCI_QUIRK_PROVIDER,
> .parent = TYPE_OBJECT,
> .class_size = sizeof(VFIOPCIQuirkClass),
> .abstract = true,
> };
> static void register_vfio_pci_quirk_type(void)
> {
> type_register_static(&vfio_pci_quirk_info);
> }
> type_init(register_vfio_pci_quirk_type)
>
>
> Declare one for IGD
> static void vfio_pci_quirk_igd_class_init(ObjectClass *klass, void *data)
> {
> VFIOPCIQuirkClass* vpqc = VFIO_PCI_QUIRK_PROVIDER_CLASS(klass);
> vpqc->setup = vfio_probe_igd_quirk_probe;
> vpqc->probe = vfio_probe_igd_quirk_probe;
> }
> static const TypeInfo vfio_pci_quirk_igd_info = {
> .name = TYPE_VFIO_PCI_QUIRK_PROVIDER "-igd",
> .parent = TYPE_VFIO_PCI_QUIRK_PROVIDER,
> .class_init = vfio_pci_quirk_igd_class_init,
> .class_size = sizeof(VFIOPCIQuirkClass),
> };
> static void vfio_pci_quirk_igd_register_types(void)
> {
> type_register_static(&vfio_pci_quirk_igd_info);
> }
> type_init(vfio_pci_quirk_igd_register_types)
>
>
> and in the common part, loop on all the classes to probe and setup :
>
>
> static void vfio_pci_quirk_class_foreach(ObjectClass *klass, void *opaque)
> {
> VFIOPCIQuirkProviderClass* vpqc = VFIO_PCI_QUIRK_PROVIDER_CLASS(klass);
> Error *local_err = NULL;
> vpqc->setup(opaque, &local_err);
> }
> bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp)
> {
> object_class_foreach(vfio_pci_quirk_class_foreach,
> TYPE_VFIO_PCI_QUIRK_PROVIDER, false, vdev);
> ...
>
>
>
>
> Thanks,
>
> C.
>
>
next prev parent reply other threads:[~2025-02-02 16:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 19:12 [PATCH v2 0/5] vfio/igd: remove incorrect IO BAR4 quirk Tomita Moeko
2025-01-24 19:12 ` [PATCH v2 1/5] vfio/igd: remove GTT write quirk in IO BAR 4 Tomita Moeko
2025-01-24 19:12 ` [PATCH v2 2/5] vfio/pci: add placeholder for device-specific config space quirks Tomita Moeko
2025-01-24 19:12 ` [PATCH v2 3/5] vfio/igd: refactor vfio_probe_igd_bar4_quirk() into pci config quirk Tomita Moeko
2025-01-31 9:14 ` Cédric Le Goater
2025-02-02 16:24 ` Tomita Moeko [this message]
2025-01-24 19:12 ` [PATCH v2 4/5] vfio/igd: do not include GTT stolen size in etc/igd-bdsm-size Tomita Moeko
2025-01-24 19:12 ` [PATCH v2 5/5] vfio/igd: handle x-igd-opregion in vfio_probe_igd_config_quirk() Tomita Moeko
2025-01-24 21:13 ` Alex Williamson
2025-01-25 7:42 ` Tomita Moeko
2025-01-30 18:33 ` Tomita Moeko
2025-01-30 20:41 ` Alex Williamson
2025-01-31 10:15 ` Cédric Le Goater
2025-02-01 7:57 ` Tomita Moeko
2025-02-01 7:48 ` Tomita Moeko
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=bedb349f-d570-40b6-b0b8-8f85e54859d9@gmail.com \
--to=tomitamoeko@gmail.com \
--cc=alex.williamson@redhat.com \
--cc=clg@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).