All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Chao Gao <chao.gao@intel.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wei.liu2@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v2] xen/pt: fix some pass-thru devices don't work across reboot
Date: Thu, 15 Nov 2018 11:40:39 +0100	[thread overview]
Message-ID: <20181115104039.geyiusafhsq4q7x4@mac> (raw)
In-Reply-To: <1542244226-35003-1-git-send-email-chao.gao@intel.com>

On Thu, Nov 15, 2018 at 09:10:26AM +0800, Chao Gao wrote:
> I find some pass-thru devices don't work any more across guest
> reboot. Assigning it to another domain also meets the same issue. And
> the only way to make it work again is un-binding and binding it to
> pciback. Someone reported this issue one year ago [1].

How does unbinding and binding to pciback fix the issue? Is this due
to Dom0 using some PV or Dom0 only hypercall that can reset the
host_maskall state?

> 
> If the device's driver doesn't disable MSI-X during shutdown or qemu is
> killed/crashed before the domain shutdown, this domain's pirq won't be
> unmapped. Then xen will unmap all pirq. But pciback has already disabled
> meory decoding before xen unmapping pirq. Then when Xen is disabling a
> MSI of the device, it has to sets the host_maskall flag and maskall bit
> to mask a MSI rather than sets maskbit in MSI-x table. The call trace of
> this process is:
> ->arch_domain_destroy
>     ->free_domain_pirqs
>         ->unmap_domain_pirq (if pirq isn't unmap by qemu)
>             ->pirq_guest_force_unbind
>                 ->__pirq_guest_unbind
>                     ->mask_msi_irq(=desc->handler->disable())
>                         ->the warning in msi_set_mask_bit()
> 
> The host_maskall bit will prevent guests from clearing the maskall bit
> even the device is assigned to another guest later. Guests cannot
> receive interrupts from this device.
>
> 
> To fix this, host_maskall flag is cleared when all MSIs of a device are freed.
> It is definitely safely to clear it because no msi is actually set up
> for this device. Also, 'msix->warned' is initialized to DOMID_INVALID
> rather than 0 to avoid warnings missing for Dom0.
> 
> [1]: https://lists.xenproject.org/archives/html/xen-devel/2017-09/msg02520.html
> 
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
>  xen/arch/x86/msi.c            | 18 ++++++++++++++++++
>  xen/drivers/passthrough/pci.c |  1 +
>  2 files changed, 19 insertions(+)
> 
> diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c
> index 5567990..cd570bc 100644
> --- a/xen/arch/x86/msi.c
> +++ b/xen/arch/x86/msi.c
> @@ -637,6 +637,7 @@ int msi_free_irq(struct msi_desc *entry)
>  {
>      unsigned int nr = entry->msi_attrib.type != PCI_CAP_ID_MSIX
>                        ? entry->msi.nvec : 1;
> +    struct pci_dev *pdev = entry->dev;
>  
>      while ( nr-- )
>      {
> @@ -654,6 +655,23 @@ int msi_free_irq(struct msi_desc *entry)
>  
>      list_del(&entry->list);
>      xfree(entry);
> +
> +    /*
> +     * In some cases, the 'host_maskall' is set for safety. Here clear
> +     * 'host_maskall' if all MSIs are freed for a msi-x capable device.
> +     * Without it, the device's msix keeps disabled even been reassigned

"... even after being reassigned ..."

I think it's clearer.

> +     * to another domain.
> +     */
> +    if ( pdev && list_empty(&pdev->msi_list) && pdev->msix )
> +    {
> +        if ( pdev->msix->host_maskall )
> +            printk(XENLOG_G_WARNING
> +                   "Resetting msix status of %04x:%02x:%02x.%u\n",
> +                   pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
> +                   PCI_FUNC(pdev->devfn));
> +        pdev->msix->host_maskall = false;
> +        pdev->msix->warned = DOMID_INVALID;
> +    }
>      return 0;

IMO this looks quite similar to a msi_reset_state function or at least
the start of it.

Maybe it should be in a separate helper that sets all the fields to
their initial values, with the expectation that Dom0 will perform the
device reset?

The underlying problem here AFAICT is that the Xen internal device
state is not the same between device assignments.

In any case there should be at least a note here pointing out that Xen
expects the hardware domain to perform a device reset, so the Xen
internal state actually matches the device state before trying to
assign the device to another guest.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-11-15 10:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15  1:10 [PATCH v2] xen/pt: fix some pass-thru devices don't work across reboot Chao Gao
2018-11-15 10:40 ` Roger Pau Monné [this message]
2018-11-16  7:53   ` Chao Gao
2018-11-16  9:35     ` Roger Pau Monné
2018-11-16  9:59       ` Jan Beulich
2018-11-16 14:30         ` Roger Pau Monné
2018-11-19 12:23           ` Jan Beulich
2018-11-19 12:45           ` Chao Gao
2018-11-19 12:55             ` Jan Beulich
2018-11-19 13:20               ` Chao Gao
2018-12-11 17:03 ` Jan Beulich
2018-12-12  4:20   ` Chao Gao

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=20181115104039.geyiusafhsq4q7x4@mac \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=chao.gao@intel.com \
    --cc=jbeulich@suse.com \
    --cc=wei.liu2@citrix.com \
    --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.