Containing unrecoverable AER errors...
Subsystems (2)
Hi,
I am working on creating a patch to aid in containing the unrecoverable AER errors generated by PCI devices assigned to guests in passthrough mode.
The overall approach is as follows:
1. Change the BIOS settings such that the AER error handling is delegated to the host.
2. Change the xen_pciback driver to store the name (SBDF) of the erring device in xenstore.
3. At the time of creating the guest, setup a watcher for such writes to the xenstore.
4. When the watcher is kicked off due to errors, *shutdown* the guest and mark the erring device unassignable until administrative intervention.
I got all of this working, but I was advised that shutting down the guest is not the correct approach, because the guest may or may not respond to the shutdown. The suggestion was to destroy the guest.
I ran into a problem with that. libxl_domain_destroy() is not callable from within libxl. I tried to create a new wrapper to call libxl__domain_destroy(), but the callback function never gets called! Not surprisingly, because the description in libxl/libxl_internal.h about asynchronous operations does prohibit this!
What is the best way to kill/destroy a guest from within libxl? Could you please advise? I am including the patches below for reference (please ignore the few debug statements). The problem part is the function aer_backend_watch_callback() in tools/libxl/libxl_pci.c.
drivers/xen/xen-pciback/pci_stub.c +14 -0
@@ -656,11 +656,13 @@ static const struct pci_device_id pcistub_ids[] = { };#define PCI_NODENAME_MAX 40 +#define PCI_DEVICENAME_MAX 14static void kill_domain_by_device (struct pcistub_device *psdev) {struct xenbus_transaction xbt;int err;char nodename[PCI_NODENAME_MAX ]; +char devicename[PCI_DEVICENAME_MAX ];BUG_ON (!psdev); snprintf(nodename, PCI_NODENAME_MAX, "/local/domain/0/backend/pci/%d/0",
@@ -675,6 +677,18 @@ static void kill_domain_by_device(struct pcistub_device *psdev) }/*PV AER handlers will set this flag*/ xenbus_printf (xbt, nodename,"aerState" ,"aerfail" ); + +/* +* Xend versions <= 4.4 depend on "aerState" and expect its value +* to be set to "aerfail". Therefore, add a new node "aerFailedSBDF" +* to set the device name. +*/ +snprintf (devicename,PCI_DEVICENAME_MAX ,"%04x:%02x:%02x.%x" , +pci_domain_nr (psdev->dev->bus), + psdev->dev->bus->number, +PCI_SLOT (psdev->dev->devfn),PCI_FUNC (psdev->dev->devfn)); +xenbus_printf (xbt, nodename,"aerFailedSBDF" , devicename); + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )
xen/common/domctl.c +6 -0
@@ -393,9 +393,15 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) {case XEN_DOMCTL_createdomain:case XEN_DOMCTL_test_assign_device: +case XEN_DOMCTL_test_hidden_device:case XEN_DOMCTL_gdbsx_guestmemio: d =NULL ;break ; +case XEN_DOMCTL_hide_device: +case XEN_DOMCTL_unhide_device: +rcu_lock_domain (dom_xen); + d = dom_xen; +break ;default : d =rcu_lock_domain_by_id (op->domain);if ( !d && op->cmd != XEN_DOMCTL_getdomaininfo )
xen/drivers/passthrough/pci.c +152 -9
220 lines not on this page · raw message
xen/include/public/domctl.h +3 -0
@@ -1222,6 +1222,9 @@ struct xen_domctl {#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002#define XEN_DOMCTL_gdbsx_domstatus 1003 +#define XEN_DOMCTL_hide_device 2001 +#define XEN_DOMCTL_unhide_device 2002 +#define XEN_DOMCTL_test_hidden_device 2003uint32_t interface_version;/* XEN_DOMCTL_INTERFACE_VERSION */ domid_t domain;union {
xen/include/xsm/dummy.h +18 -0
@@ -355,6 +355,24 @@ static XSM_INLINE int xsm_deassign_device(XSM_DEFAULT_ARG struct domain *d, uintreturn xsm_default_action (action, current->domain, d); } +static XSM_INLINE int xsm_hide_device(XSM_DEFAULT_ARG struct domain *d, uint32_t machine_bdf) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + +static XSM_INLINE int xsm_unhide_device(XSM_DEFAULT_ARG struct domain *d, uint32_t machine_bdf) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain, d); +} + +static XSM_INLINE int xsm_test_hidden_device(XSM_DEFAULT_ARG uint32_t machine_bdf) +{ +XSM_ASSERT_ACTION (XSM_HOOK ); +return xsm_default_action (action, current->domain,NULL ); +} +#endif /* HAS_PASSTHROUGH && HAS_PCI */ #if defined(CONFIG_HAS_PASSTHROUGH ) && defined(CONFIG_HAS_DEVICE_TREE )
xen/include/xsm/xsm.h +16 -0
@@ -479,6 +479,22 @@ static inline int xsm_deassign_device(xsm_default_t def, struct domain *d, uint3 {return xsm_ops->deassign_device (d, machine_bdf); } + +static inline int xsm_hide_device (xsm_default_t def,struct domain *d,uint32_t machine_bdf) +{ +return xsm_ops->hide_device (d, machine_bdf); +} + +static inline int xsm_unhide_device (xsm_default_t def,struct domain *d,uint32_t machine_bdf) +{ +return xsm_ops->unhide_device (d, machine_bdf); +} + +static inline int xsm_test_hidden_device (xsm_default_t def,uint32_t machine_bdf) +{ +return xsm_ops->test_hidden_device (machine_bdf); +} +#endif /* HAS_PASSTHROUGH && HAS_PCI) */ #if defined(CONFIG_HAS_PASSTHROUGH ) && defined(CONFIG_HAS_DEVICE_TREE )
xen/xsm/dummy.c +3 -0
@@ -94,6 +94,9 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, test_assign_device);set_to_dummy_if_null (ops, assign_device);set_to_dummy_if_null (ops, deassign_device); +set_to_dummy_if_null (ops, hide_device); +set_to_dummy_if_null (ops, unhide_device); +set_to_dummy_if_null (ops, test_hidden_device);#endif #if defined(CONFIG_HAS_PASSTHROUGH ) && defined(CONFIG_HAS_DEVICE_TREE )
xen/xsm/flask/hooks.c +19 -0
@@ -1311,6 +1311,22 @@ static int flask_deassign_device(struct domain *d, uint32_t machine_bdf) return avc_current_has_perm(rsid, SECCLASS_RESOURCE, RESOURCE__REMOVE_DEVICE, NULL); } + +static int flask_unhide_device (struct domain *d,uint32_t machine_bdf) +{ +return flask_deassign_device (d, machine_bdf); +} + +static int flask_hide_device (struct domain *d,uint32_t machine_bdf) +{ +return flask_assign_device (d, machine_bdf); +} + +static int flask_test_hidden_device (struct domain *d,uint32_t machine_bdf) +{ +return flask_test_assign_device (d, machine_bdf); +} +#endif /* HAS_PASSTHROUGH && HAS_PCI */ #if defined(CONFIG_HAS_PASSTHROUGH ) && defined(CONFIG_HAS_DEVICE_TREE )
@@ -1783,6 +1799,9 @@ static struct xsm_operations flask_ops = { .test_assign_device = flask_test_assign_device, .assign_device = flask_assign_device, .deassign_device = flask_deassign_device, + .hide_device = flask_hide_device, + .unhide_device = flask_unhide_device, + .test_hidden_device = flask_test_hidden_device,#endif #if defined(CONFIG_HAS_PASSTHROUGH ) && defined(CONFIG_HAS_DEVICE_TREE )
xen/xsm/flask/policy/access_vectors +3 -3
@@ -437,13 +437,13 @@ class resource # XEN_DOMCTL_iomem_permission, XEN_DOMCTL_memory_mapping add_iomem remove_iomem -# XEN_DOMCTL_get_device_group, XEN_DOMCTL_test_assign_device: +# XEN_DOMCTL_get_device_group, XEN_DOMCTL_test_assign_device, XEN_DOMCTL_test_hidden_device: # source = domain making the hypercall # target = device being queried stat_device -# XEN_DOMCTL_assign_device +# XEN_DOMCTL_assign_device, XEN_DOMCTL_hide_device add_device -# XEN_DOMCTL_deassign_device +# XEN_DOMCTL_deassign_device, XEN_DOMCTL_unhide_device remove_device # checked for PCI hot and cold-plug hypercalls, with target as the PCI device # checked for CPU and memory hotplug with xen_t as the target
docs/man/xl.pod.1.in +24 -0
@@ -1462,6 +1462,13 @@ These are devices in the system which are configured to be available for passthrough and are bound to a suitable PCI backend driver in domain 0 rather than a real driver. +=item B<pci-assignable-list-hidden> + +List all the assignable PCI devices that are hidden. +When a PCI device assigned to a guest in passthrough mode causes +unrecoverable AER errors, the hypervisor shuts down the guest and hides +the device from being assignable to the guests. + =item B<pci-assignable-add> I<BDF> Make the device at PCI Bus/Device/Function BDF assignable to guests.
@@ -1484,6 +1491,23 @@ it will also attempt to re-bind the device to its original driver, making it usable by Domain 0 again. If the device is not bound to pciback, it will return success. +=item B<pci-assignable-hide> I<BDF> + +Hide the device at PCI Bus/Device/Function BDF from being assignable +to guests, similar to the way the hypervisor would hide the device that +caused unrecoverable AER errors. +When a PCI device assigned to a guest in passthrough mode causes +unrecoverable AER errors, the hypervisor shuts down the guest and hides +the device from being assignable to the guests. + +=item B<pci-assignable-unhide> I<BDF> + +Unhide the device at PCI Bus/Device/Function BDF that was previously +hidden by the hypervisor due to unrecoverable AER errors. +When a PCI device assigned to a guest in passthrough mode causes +unrecoverable AER errors, the hypervisor shuts down the guest and hides +the device from being assignable to the guests. + =item B<pci-attach> I<domain-id> I<BDF> Hot-plug a new pass-through pci device to the specified domain.
tools/libxc/include/xenctrl.h +4 -0
@@ -1670,6 +1670,10 @@ int xc_assign_device(xc_interface *xch,uint32_t machine_sbdf, uint32_t flag); +int xc_hide_device (xc_interface *xch,uint32_t machine_bdf); +int xc_unhide_device (xc_interface *xch,uint32_t machine_bdf); +int xc_test_hidden_device (xc_interface *xch,uint32_t machine_bdf); + int xc_get_device_group(xc_interface *xch, uint32_t domid, uint32_t machine_sbdf,
tools/libxc/xc_domain.c +38 -0
@@ -1501,6 +1501,44 @@ int xc_assign_device(return do_domctl (xch, &domctl); } +int xc_hide_device ( +xc_interface *xch, +uint32_t machine_sbdf) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_hide_device; + domctl.domain =DOMID_XEN ; + domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf; + +return do_domctl (xch, &domctl); +} + +int xc_unhide_device ( +xc_interface *xch, +uint32_t machine_sbdf) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_unhide_device; + domctl.domain =DOMID_XEN ; + domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf; + +return do_domctl (xch, &domctl); +} + +int xc_test_hidden_device ( +xc_interface *xch, +uint32_t machine_sbdf) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_test_hidden_device; + domctl.u.assign_device.u.pci.machine_sbdf = machine_sbdf; + +return do_domctl (xch, &domctl); +} + int xc_get_device_group( xc_interface *xch, uint32_t domid,
tools/libxl/libxl.h +3 -0
@@ -1944,6 +1944,9 @@ int libxl_device_events_handler(libxl_ctx *ctx,int libxl_device_pci_assignable_add (libxl_ctx *ctx,libxl_device_pci *pcidev,int rebind);int libxl_device_pci_assignable_remove (libxl_ctx *ctx,libxl_device_pci *pcidev,int rebind);libxl_device_pci *libxl_device_pci_assignable_list (libxl_ctx *ctx,int *num); +int libxl_device_pci_assignable_hide (libxl_ctx *ctx,libxl_device_pci *pcidev); +int libxl_device_pci_assignable_unhide (libxl_ctx *ctx,libxl_device_pci *pcidev); +int libxl_device_pci_assignable_is_hidden (libxl_ctx *ctx,libxl_device_pci *pcidev);/* CPUID handling */ int libxl_cpuid_parse_config (libxl_cpuid_policy_list *cpuid,const char * str);
tools/libxl/libxl_event.h +2 -0
@@ -178,6 +178,8 @@ void libxl_event_register_callbacks(libxl_ctx *ctx,typedef struct libxl__evgen_domain_death libxl_evgen_domain_death ;int libxl_evenable_domain_death (libxl_ctx *ctx,uint32_t domid,libxl_ev_user ,libxl_evgen_domain_death **evgen_out); +int libxl_reg_aer_events_handler(libxl_ctx *, uint32_t) LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_unreg_aer_events_handler (libxl_ctx *,uint32_t );void libxl_evdisable_domain_death (libxl_ctx *ctx,libxl_evgen_domain_death *);/* Arranges for the generation of DOMAIN_SHUTDOWN and DOMAIN_DEATH * events. A domain which is destroyed before it shuts down
tools/libxl/libxl_pci.c +168 -0
180 lines not on this page · raw message
tools/python/xen/lowlevel/xc/xc.c +84 -0
97 lines not on this page · raw message
tools/xl/xl.h +3 -0
@@ -121,9 +121,12 @@ int main_vncviewer(int argc, char **argv);int main_pcilist (int argc,char **argv);int main_pcidetach (int argc,char **argv);int main_pciattach (int argc,char **argv); +int main_pciassignable_hide (int argc,char **argv); +int main_pciassignable_unhide (int argc,char **argv);int main_pciassignable_add (int argc,char **argv);int main_pciassignable_remove (int argc,char **argv);int main_pciassignable_list (int argc,char **argv); +int main_pciassignable_list_hidden (int argc,char **argv);#ifndef LIBXL_HAVE_NO_SUSPEND_RESUME int main_restore (int argc,char **argv);int main_migrate_receive (int argc,char **argv);
tools/xl/xl_cmdtable.c +17 -0
@@ -119,6 +119,23 @@ struct cmd_spec cmd_table[] = {"List all the assignable pci devices" ,"" , }, + { "pci-assignable-list-hidden", + &main_pciassignable_list_hidden,0 ,0 , +"List all the pci devices hidden due to AER errors" , +"" , + }, + { "pci-assignable-hide", + &main_pciassignable_hide,0 ,1 , +"Hide a PCI device" , +"<BDF>" , +"-h Print this help.\n" + }, + { "pci-assignable-unhide", + &main_pciassignable_unhide,0 ,1 , +"Unhide a PCI device" , +"<BDF>" , +"-h Print this help.\n" + }, { "pause", &main_pause,0 ,1 , "Pause execution of a domain",
tools/xl/xl_pci.c +123 -2
137 lines not on this page · raw message
tools/xl/xl_vmcontrol.c +11 -0
@@ -966,6 +966,15 @@ start:LOG ("Waiting for domain %s (domid %u) to die [pid %ld]" , d_config.c_info.name, domid, (long )getpid ()); + ret =libxl_reg_aer_events_handler (ctx, domid); +if (ret) { +/* +* This error may not be severe enough to fail the creation of the VM. +* Log the error, and continue with the creation. +*/ +LOG ("libxl_reg_aer_events_handler() failed, ret = 0x%08x" , ret); + } + ret =libxl_evenable_domain_death (ctx, domid,0 , &deathw);if (ret) goto out;
@@ -993,6 +1002,7 @@ start:LOG ("Domain %u has shut down, reason code %d 0x%x" , domid, event->u.domain_shutdown.shutdown_reason, event->u.domain_shutdown.shutdown_reason); +libxl_unreg_aer_events_handler (ctx, domid);switch (handle_domain_death (&domid, event, &d_config)) {case DOMAIN_RESTART_SOFT_RESET : domid_soft_reset = domid;
@@ -1059,6 +1069,7 @@ start:case LIBXL_EVENT_TYPE_DOMAIN_DEATH :LOG ("Domain %u has been destroyed." , domid); +libxl_unreg_aer_events_handler (ctx, domid);libxl_event_free (ctx, event); ret =0 ; goto out;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 36 lines · Venu Busireddy
Hi,
I am working on creating a patch to aid in containing the unrecoverable AER errors generated by PCI devices assigned to guests in passthrough mode.
The overall approach is as follows:
1. Change the BIOS settings such that the AER error handling is delegated to the host.
2. Change the
xen_pcibackdriver to store the name (SBDF) of the erring device in xenstore.3. At the time of creating the guest, setup a watcher for such writes to the xenstore.
4. When the watcher is kicked off due to errors, *shutdown* the guest and mark the erring device unassignable until administrative intervention.
I got all of this working, but I was advised that shutting down the guest is not the correct approach, because the guest may or may not respond to the shutdown. The suggestion was to destroy the guest.
I ran into a problem with that.
libxl_domain_destroy()is not callable from within libxl. I tried to create a new wrapper to calllibxl__domain_destroy(), but the callback function never gets called! Not surprisingly, because the description inlibxl/libxl_internal.habout asynchronous operations does prohibit this!What is the best way to kill/destroy a guest from within libxl? Could you please advise? I am including the patches below for reference (please ignore the few debug statements). The problem part is the function
aer_backend_watch_callback()intools/libxl/libxl_pci.c.
[...]
tools/libxl/libxl_pci.c out: · line 1442
Quoted 8 lines
tools/libxl/libxl_pci.c +8
-0+ +/* Handler of events for device driver domains */ +int libxl_reg_aer_events_handler (libxl_ctx *ctx,uint32_t domid) +{ +int rc; +char *be_path; +GC_INIT (ctx); +
You can probably create an AO here, stash it somewhere, and the use it in your callback to destroy the domain.
See also: libxl_device_events_handler
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 50 lines · Wei Liu
Quoted 36 lines · Venu Busireddy
Hi,
I am working on creating a patch to aid in containing the unrecoverable AER errors generated by PCI devices assigned to guests in passthrough mode.
The overall approach is as follows:
1. Change the BIOS settings such that the AER error handling is delegated to the host.
2. Change the
xen_pcibackdriver to store the name (SBDF) of the erring device in xenstore.3. At the time of creating the guest, setup a watcher for such writes to the xenstore.
4. When the watcher is kicked off due to errors, *shutdown* the guest and mark the erring device unassignable until administrative intervention.
I got all of this working, but I was advised that shutting down the guest is not the correct approach, because the guest may or may not respond to the shutdown. The suggestion was to destroy the guest.
I ran into a problem with that.
libxl_domain_destroy()is not callable from within libxl. I tried to create a new wrapper to calllibxl__domain_destroy(), but the callback function never gets called! Not surprisingly, because the description inlibxl/libxl_internal.habout asynchronous operations does prohibit this!What is the best way to kill/destroy a guest from within libxl? Could you please advise? I am including the patches below for reference (please ignore the few debug statements). The problem part is the function
aer_backend_watch_callback()intools/libxl/libxl_pci.c.[...]
tools/libxl/libxl_pci.c out: · line 1442
Quoted 8 lines
tools/libxl/libxl_pci.c +8
-0+ +/* Handler of events for device driver domains */ +int libxl_reg_aer_events_handler (libxl_ctx *ctx,uint32_t domid) +{ +int rc; +char *be_path; +GC_INIT (ctx); +You can probably create an AO here, stash it somewhere, and the use it in your callback to destroy the domain.
Quoted 1 line
See also:
libxl_device_events_handler
Thanks, Wei! This suggestion worked great. Implemented it, and I sent the patches for review!
Venu
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel