All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Chuck Zmudzinski <brchuckz@netscape.net>
Cc: <xen-devel@lists.xenproject.org>, Wei Liu <wl@xen.org>,
	Juergen Gross <jgross@suse.com>, Jan Beulich <jbeulich@suse.com>
Subject: Re: [XEN PATCH] tools/libs/light/libxl_pci.c: explicitly grant access to Intel IGD opregion
Date: Wed, 30 Mar 2022 18:15:14 +0100	[thread overview]
Message-ID: <YkSQIoYhomhNKpYR@perard.uk.xensource.com> (raw)
In-Reply-To: <b62fbc602a629941c1acaad3b93d250a3eba33c0.1647222184.git.brchuckz@netscape.net>

Hi Chuck,

On Sun, Mar 13, 2022 at 11:41:37PM -0400, Chuck Zmudzinski wrote:
> When gfx_passthru is enabled for the Intel IGD, hvmloader maps the IGD
> opregion to the guest but libxl does not grant the guest permission to

I'm not reading the same thing when looking at code in hvmloader. It
seems that hvmloader allocate some memory for the IGD opregion rather
than mapping it.


tools/firmware/hvmloader/pci.c:184
    if ( vendor_id == 0x8086 )
    {
        igd_opregion_pgbase = mem_hole_alloc(IGD_OPREGION_PAGES);
        /*
         * Write the the OpRegion offset to give the opregion
         * address to the device model. The device model will trap
         * and map the OpRegion at the give address.
         */
        pci_writel(vga_devfn, PCI_INTEL_OPREGION,
                   igd_opregion_pgbase << PAGE_SHIFT);
    }

I think this write would go through QEMU, does it do something with it?
(I kind of replying to this question at the end of the mail.)

Is this code in hvmloader actually run in your case?

> Currently, because of another bug in Qemu upstream, this crash can
> only be reproduced using the traditional Qemu device model, and of

qemu-traditional is a bit old... What is the bug in QEMU? Do you have a
link to a patch/mail?

> diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c
> index 4bbbfe9f16..a4fc473de9 100644
> --- a/tools/libs/light/libxl_pci.c
> +++ b/tools/libs/light/libxl_pci.c
> @@ -2531,6 +2572,37 @@ int libxl__grant_vga_iomem_permission(libxl__gc *gc, const uint32_t domid,
>                    domid, vga_iomem_start, (vga_iomem_start + 0x20 - 1));
>              return ret;
>          }
> +
> +        /* If this is an Intel IGD, allow access to the IGD opregion */
> +        if (!libxl__is_igd_vga_passthru(gc, d_config)) return 0;
> +
> +        uint32_t igd_opregion = sysfs_dev_get_igd_opregion(gc, pci);
> +        uint32_t error = 0xffffffff;
> +        if (igd_opregion == error) break;
> +
> +        vga_iomem_start = ( (uint64_t) igd_opregion ) >> XC_PAGE_SHIFT;
> +        ret = xc_domain_iomem_permission(CTX->xch, stubdom_domid,
> +                                         vga_iomem_start,
> +                                         IGD_OPREGION_PAGES, 1);
> +        if (ret < 0) {
> +            LOGED(ERROR, domid,
> +                  "failed to give stubdom%d access to iomem range "
> +                  "%"PRIx64"-%"PRIx64" for IGD passthru",
> +                  stubdom_domid, vga_iomem_start, (vga_iomem_start +
> +                                                IGD_OPREGION_PAGES - 1));
> +            return ret;
> +        }
> +        ret = xc_domain_iomem_permission(CTX->xch, domid,
> +                                         vga_iomem_start,
> +                                         IGD_OPREGION_PAGES, 1);

Here, you seems to add permission to an address that is read from the
pci config space of the device, but as I've pointed above hvmloader
seems to overwrite this address. It this call to
xc_domain_iomem_permission() does actually anything useful?
Or is it by luck that the address returned by
sysfs_dev_get_igd_opregion() happened to be the address that hvmloader
is going to write?

Or maybe hvmloader doesn't actually do anything?


Some more though on that, looking at QEMU, it seems that there's already
a call to xc_domain_iomem_permission(), in igd_write_opregion(). So
adding one in libxl would seems redundant, or maybe it the one for the
device model's domain that's needed  (named 'stubdom_domid' here)?

Thanks,

-- 
Anthony PERARD


  parent reply	other threads:[~2022-03-30 17:15 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b62fbc602a629941c1acaad3b93d250a3eba33c0.1647222184.git.brchuckz.ref@netscape.net>
2022-03-14  3:41 ` [XEN PATCH] tools/libs/light/libxl_pci.c: explicitly grant access to Intel IGD opregion Chuck Zmudzinski
2022-03-15 11:38   ` Jan Beulich
2022-03-15 18:31     ` Chuck Zmudzinski
2022-03-16  1:27     ` Chuck Zmudzinski
2022-03-16 12:18       ` Chuck Zmudzinski
2022-03-28 21:31     ` Chuck Zmudzinski
2022-03-18  8:13   ` Jan Beulich
2022-03-30 18:45     ` Jason Andryuk
2022-03-31  4:34       ` Chuck Zmudzinski
2022-03-31 12:23         ` Jason Andryuk
2022-03-31 13:57           ` Chuck Zmudzinski
2022-04-01 13:21       ` Chuck Zmudzinski
2022-04-01 13:41         ` Chuck Zmudzinski
2022-04-01 13:49           ` Jason Andryuk
2022-04-06  1:31         ` Chuck Zmudzinski
2022-04-06 13:10           ` Jason Andryuk
2022-04-06 15:24             ` Chuck Zmudzinski
2022-04-06 17:39             ` Chuck Zmudzinski
2022-03-30 17:15   ` Anthony PERARD [this message]
2022-03-30 17:27     ` Andrew Cooper
2022-03-31  3:54       ` Chuck Zmudzinski
2022-03-31 12:29         ` Jason Andryuk
2022-03-31 14:05           ` Chuck Zmudzinski
2022-03-31 14:19             ` Jason Andryuk
2022-03-31 19:44               ` Chuck Zmudzinski
2022-06-17 13:46                 ` Anthony PERARD
2022-06-17 20:39                   ` Chuck Zmudzinski
2022-03-31  2:41     ` Chuck Zmudzinski
2022-03-31 18:32     ` Chuck Zmudzinski
2022-04-01  0:27       ` Chuck Zmudzinski
2022-03-31 23:23     ` Chuck Zmudzinski
2022-06-04  1:10     ` Chuck Zmudzinski
2022-06-06 18:47       ` Chuck Zmudzinski
     [not found] <b11b0b13-4f10-7d77-d02d-bb9a22bce887@netscape.net>
2022-03-15 17:25 ` Chuck Zmudzinski

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=YkSQIoYhomhNKpYR@perard.uk.xensource.com \
    --to=anthony.perard@citrix.com \
    --cc=brchuckz@netscape.net \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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.