From patchwork Tue Jun 27 17:14:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 9812815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB0D160351 for ; Tue, 27 Jun 2017 17:17:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0DFD281F9 for ; Tue, 27 Jun 2017 17:17:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5C45286DD; Tue, 27 Jun 2017 17:17:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 380F5281F9 for ; Tue, 27 Jun 2017 17:17:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPu56-0007pk-VP; Tue, 27 Jun 2017 17:15:16 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPu56-0007pV-32 for xen-devel@lists.xen.org; Tue, 27 Jun 2017 17:15:16 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 74/8C-01732-3A292595; Tue, 27 Jun 2017 17:15:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42KZM10+UHfRpKB Ig6tPhCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozNPzkLpltW/H7zlKWBcYJOFyMnh5DARCaJ Sae4IezfjBIbn5h2MXIB2RsZJa7sX8AE4UxklHh+qZ8VpIpNwEDi6OEeMFtEIFfiYvdRNhCbW UBa4tqTt2C2sECYRMfBC8wgNouAqsSCry/A4rwCthLXOv8zgtgSAnISS7dfB6vhFLCTaF75gx XiCluJ7dM6mCFqDCVOP9zGOIGRbwEjwypGjeLUorLUIl1DE72kosz0jJLcxMwcXUMDY73c1OL ixPTUnMSkYr3k/NxNjMAwYQCCHYwrtnseYpTkYFIS5T3VGRQpxJeUn1KZkVicEV9UmpNafIhR hoNDSYJ3zwSgnGBRanpqRVpmDjBgYdISHDxKIrw8IGne4oLE3OLMdIjUKUZdjg2r139hEmLJy 89LlRLnbZ0IVCQAUpRRmgc3AhY9lxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMyw+yiiczrw Ru0yugI5iAjmCZFwByREkiQkqqgbFo59Sup8+fbLdYp6nmteZMSg6P0NcdVtKXb7Y05+1Vbmx f6Fe1Mz+z0qOKfx/L9z9HK7dO+B4pknkxILKU00hiq/Gc5ax1fy0SOhWuHTBeJXLIYL70iq5T lZt8b8i98E5k5va6Yv49qUfrQuCLZzozWb9qM+THrL3vNY/N5eHU9WdlL+yfpaPEUpyRaKjFX FScCAAb59hrmQIAAA== X-Env-Sender: venu.busireddy@oracle.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1498583712!106945001!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7278 invoked from network); 27 Jun 2017 17:15:14 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-10.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Jun 2017 17:15:13 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v5RHF9wH024149 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Jun 2017 17:15:09 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v5RHF9X7001455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Jun 2017 17:15:09 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v5RHF96l009041; Tue, 27 Jun 2017 17:15:09 GMT Received: from ban25uut183.us.oracle.com (/10.153.74.183) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 27 Jun 2017 10:15:08 -0700 From: Venu Busireddy To: venu.busireddy@oracle.com, Ian Jackson , Wei Liu Date: Tue, 27 Jun 2017 12:14:54 -0500 Message-Id: <20170627171458.2529-3-venu.busireddy@oracle.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170627171458.2529-1-venu.busireddy@oracle.com> References: <20170627171458.2529-1-venu.busireddy@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH 2/6] xl: Add commands for hiding and unhiding pcie passthrough devices X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP xl: Add commands for hiding and unhiding pcie passthrough devices Introduce three subcommands: 'xl pci-assignable-hide ' to hide a device, 'xl pci-assignable-unhide ' to unhide a previously hidden device, and 'xl pci-assignable-list-hidden' to list the hidden devices. Changed create_domain() to register a handler for unrecoverable AER errors. Signed-off-by: Venu Busireddy --- tools/xl/xl.h | 3 ++ tools/xl/xl_cmdtable.c | 17 +++++++ tools/xl/xl_pci.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++- tools/xl/xl_vmcontrol.c | 11 +++++ 4 files changed, 154 insertions(+), 2 deletions(-) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index aa95b77..915fe86 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -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); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 30eb93c..e23bd15 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -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", + "", + "-h Print this help.\n" + }, + { "pci-assignable-unhide", + &main_pciassignable_unhide, 0, 1, + "Unhide a PCI device", + "", + "-h Print this help.\n" + }, { "pause", &main_pause, 0, 1, "Pause execution of a domain", diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 58345bd..f48c469 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -163,8 +163,9 @@ static void pciassignable_list(void) if ( pcidevs == NULL ) return; for (i = 0; i < num; i++) { - printf("%04x:%02x:%02x.%01x\n", - pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func); + if (!libxl_device_pci_assignable_is_hidden(ctx, &pcidevs[i])) + printf("%04x:%02x:%02x.%01x\n", + pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func); libxl_device_pci_dispose(&pcidevs[i]); } free(pcidevs); @@ -182,6 +183,126 @@ int main_pciassignable_list(int argc, char **argv) return 0; } +static void pciassignable_list_hidden(void) +{ + libxl_device_pci *pcidevs; + int num, i; + + pcidevs = libxl_device_pci_assignable_list(ctx, &num); + + if ( pcidevs == NULL ) + return; + for (i = 0; i < num; i++) { + if (libxl_device_pci_assignable_is_hidden(ctx, &pcidevs[i])) + printf("%04x:%02x:%02x.%01x\n", + pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func); + libxl_device_pci_dispose(&pcidevs[i]); + } + free(pcidevs); +} + +int main_pciassignable_list_hidden(int argc, char **argv) +{ + int opt; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-list-hidden", 0) { + /* No options */ + } + + pciassignable_list_hidden(); + return 0; +} + +static int pciassignable_hide(const char *bdf) +{ + libxl_device_pci pcidev; + XLU_Config *config; + int r = EXIT_SUCCESS; + + libxl_device_pci_init(&pcidev); + + config = xlu_cfg_init(stderr, "command line"); + if (!config) { + perror("xlu_cfg_init"); + exit(-1); + } + + if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + fprintf(stderr, "pci-assignable-hide: malformed BDF specification \"%s\"\n", bdf); + exit(2); + } + + if (libxl_device_pci_assignable_hide(ctx, &pcidev)) + r = EXIT_FAILURE; + + libxl_device_pci_dispose(&pcidev); + xlu_cfg_destroy(config); + + return r; +} + +int main_pciassignable_hide(int argc, char **argv) +{ + int opt; + const char *bdf = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "main_pciassignable_hide", 1) { + /* No options */ + } + + bdf = argv[optind]; + + if (pciassignable_hide(bdf)) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static int pciassignable_unhide(const char *bdf) +{ + libxl_device_pci pcidev; + XLU_Config *config; + int r = EXIT_SUCCESS; + + libxl_device_pci_init(&pcidev); + + config = xlu_cfg_init(stderr, "command line"); + if (!config) { + perror("xlu_cfg_init"); + exit(-1); + } + + if (xlu_pci_parse_bdf(config, &pcidev, bdf)) { + fprintf(stderr, "pci-assignable-unhide: malformed BDF specification \"%s\"\n", bdf); + exit(2); + } + + if (libxl_device_pci_assignable_unhide(ctx, &pcidev)) + r = EXIT_FAILURE; + + libxl_device_pci_dispose(&pcidev); + xlu_cfg_destroy(config); + + return r; +} + +int main_pciassignable_unhide(int argc, char **argv) +{ + int opt; + const char *bdf = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "main_pciassignable_unhide", 1) { + /* No options */ + } + + bdf = argv[optind]; + + if (pciassignable_unhide(bdf)) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + static int pciassignable_add(const char *bdf, int rebind) { libxl_device_pci pcidev; diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 89c2b25..10a48a9 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -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;