From: Connor Davis <connojdavis@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Connor Davis <connojdavis@gmail.com>,
Mathias Nyman <mathias.nyman@intel.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/4] usb: xhci: Notify xen when DbC is unsafe to use
Date: Thu, 13 May 2021 18:56:51 -0600 [thread overview]
Message-ID: <5c4a8a65a038563f2d20a734d74d2ed4a0f2d69e.1620952511.git.connojdavis@gmail.com> (raw)
In-Reply-To: <d160cee9b61c0ec41c2cd5ff9b4e107011d39d8c.1620952511.git.connojdavis@gmail.com>
When running as a dom0 guest on Xen, check if the USB3 debug
capability is enabled before xHCI reset, suspend, and resume. If it
is, call xen_dbgp_reset_prep() to notify Xen that it is unsafe to touch
MMIO registers until the next xen_dbgp_external_startup().
This notification allows Xen to avoid undefined behavior resulting
from MMIO access when the host controller's CNR bit is set or when
the device transitions to D3hot.
Signed-off-by: Connor Davis <connojdavis@gmail.com>
---
drivers/usb/host/xhci-dbgcap.h | 19 ++++++++++++++
drivers/usb/host/xhci.c | 47 ++++++++++++++++++++++++++++++++++
drivers/usb/host/xhci.h | 1 +
3 files changed, 67 insertions(+)
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index c70b78d504eb..332be531bebd 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -227,4 +227,23 @@ static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
return 0;
}
#endif /* CONFIG_USB_XHCI_DBGCAP */
+
+#ifdef CONFIG_XEN_DOM0
+#include <xen/xen.h>
+
+int xen_dbgp_reset_prep(struct usb_hcd *hcd);
+int xen_dbgp_external_startup(struct usb_hcd *hcd);
+
+void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci);
+void xhci_dbc_external_reset_done(struct xhci_hcd *xhci);
+#else
+static inline void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci)
+{
+}
+
+static inline void xhci_dbc_external_reset_done(struct xhci_hcd *xhci)
+{
+}
+#endif /* CONFIG_XEN_DOM0 */
+
#endif /* __LINUX_XHCI_DBGCAP_H */
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ca9385d22f68..3ff7879069ec 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -37,6 +37,47 @@ static unsigned long long quirks;
module_param(quirks, ullong, S_IRUGO);
MODULE_PARM_DESC(quirks, "Bit flags for quirks to be enabled as default");
+#ifdef CONFIG_XEN_DOM0
+void xhci_dbc_external_reset_prep(struct xhci_hcd *xhci)
+{
+ struct dbc_regs __iomem *regs;
+ void __iomem *base;
+ int dbc_cap;
+
+ if (!xen_initial_domain())
+ return;
+
+ base = &xhci->cap_regs->hc_capbase;
+ dbc_cap = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_DEBUG);
+
+ if (!dbc_cap)
+ return;
+
+ xhci->external_dbc = 0;
+ regs = base + dbc_cap;
+
+ if (readl(®s->control) & DBC_CTRL_DBC_ENABLE) {
+ if (xen_dbgp_reset_prep(xhci_to_hcd(xhci)))
+ xhci_dbg_trace(xhci, trace_xhci_dbg_init,
+ "// Failed to reset external DBC");
+ else {
+ xhci->external_dbc = 1;
+ xhci_dbg_trace(xhci, trace_xhci_dbg_init,
+ "// Completed reset of external DBC");
+ }
+ }
+}
+
+void xhci_dbc_external_reset_done(struct xhci_hcd *xhci)
+{
+ if (!xen_initial_domain() || !xhci->external_dbc)
+ return;
+
+ if (xen_dbgp_external_startup(xhci_to_hcd(xhci)))
+ xhci->external_dbc = 0;
+}
+#endif
+
static bool td_on_ring(struct xhci_td *td, struct xhci_ring *ring)
{
struct xhci_segment *seg = ring->first_seg;
@@ -180,6 +221,8 @@ int xhci_reset(struct xhci_hcd *xhci)
return 0;
}
+ xhci_dbc_external_reset_prep(xhci);
+
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC");
command = readl(&xhci->op_regs->command);
command |= CMD_RESET;
@@ -211,6 +254,8 @@ int xhci_reset(struct xhci_hcd *xhci)
*/
ret = xhci_handshake(&xhci->op_regs->status,
STS_CNR, 0, 10 * 1000 * 1000);
+ if (!ret)
+ xhci_dbc_external_reset_done(xhci);
xhci->usb2_rhub.bus_state.port_c_suspend = 0;
xhci->usb2_rhub.bus_state.suspended_ports = 0;
@@ -991,6 +1036,7 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
return 0;
xhci_dbc_suspend(xhci);
+ xhci_dbc_external_reset_prep(xhci);
/* Don't poll the roothubs on bus suspend. */
xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
@@ -1225,6 +1271,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
spin_unlock_irq(&xhci->lock);
xhci_dbc_resume(xhci);
+ xhci_dbc_external_reset_done(xhci);
done:
if (retval == 0) {
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 2595a8f057c4..61d8efc9eef2 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1920,6 +1920,7 @@ struct xhci_hcd {
struct list_head regset_list;
void *dbc;
+ int external_dbc;
/* platform-specific data -- must come last */
unsigned long priv[] __aligned(sizeof(s64));
};
--
2.31.1
next prev parent reply other threads:[~2021-05-14 0:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-14 0:56 [PATCH v2 0/4] Support xen-driven USB3 debug capability Connor Davis
2021-05-14 0:56 ` [PATCH v2 1/4] usb: early: Avoid using DbC if already enabled Connor Davis
2021-05-14 0:56 ` [PATCH v2 2/4] xen: Export dbgp functions when CONFIG_XEN_DOM0 is enabled Connor Davis
2021-05-14 14:06 ` Connor Davis
2021-05-14 0:56 ` [PATCH v2 3/4] usb: dbgp: Fix return values for reset prep and startup Connor Davis
2021-05-14 15:33 ` Boris Ostrovsky
2021-05-14 0:56 ` Connor Davis [this message]
2021-05-17 9:32 ` [PATCH v2 1/4] usb: early: Avoid using DbC if already enabled Jan Beulich
2021-05-17 13:48 ` Connor Davis
2021-05-17 14:13 ` Jan Beulich
2021-05-17 14:24 ` Connor Davis
2021-05-18 21:50 ` Mathias Nyman
2021-05-14 6:46 ` [PATCH v2 0/4] Support xen-driven USB3 debug capability Greg Kroah-Hartman
2021-05-14 14:07 ` Connor Davis
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=5c4a8a65a038563f2d20a734d74d2ed4a0f2d69e.1620952511.git.connojdavis@gmail.com \
--to=connojdavis@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
/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).