From patchwork Tue Jun 27 17:14:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 9812819 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 9FDEE60351 for ; Tue, 27 Jun 2017 17:18:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856FA282E8 for ; Tue, 27 Jun 2017 17:18:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A546286DD; Tue, 27 Jun 2017 17:18:01 +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 E5B16282E8 for ; Tue, 27 Jun 2017 17:18:00 +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 1dPu5O-0007vP-Ef; Tue, 27 Jun 2017 17:15:34 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPu5N-0007uy-5w for xen-devel@lists.xen.org; Tue, 27 Jun 2017 17:15:33 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 76/E5-03032-4B292595; Tue, 27 Jun 2017 17:15:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsUyZ7p8oO7mSUG RBg07LSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozm5YkFUy0qpj38xdTAeECni5GLQ0igg0ni wqmFrBDOF0aJQzffMEI4GxklHv19CJWZyCjx9fpc9i5GTg42AQOJo4d7WEFsEYFciYvdR9lAb GYBaYlrT96C2cICwRJrjjUwdTGyc7AIqErcC+9i5ODgFbCVmP1PBqRAQkBOYun268wgNqeAnU Tzyh9gA4WASrZP62CGqDGW6JvVxzKBkW8BI8MqRvXi1KKy1CJdY72kosz0jJLcxMwcXUMDM73 c1OLixPTUnMSkYr3k/NxNjMAQYQCCHYwd/5wOMUpyMCmJ8p7qDIoU4kvKT6nMSCzOiC8qzUkt PsQow8GhJMGrPREoJ1iUmp5akZaZAwxWmLQEB4+SCC/PBKA0b3FBYm5xZjpE6hSjopQ4bytIn wBIIqM0D64NFiGXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMzLDzKeJzOvBG76K6DFTECLWe YFgCwuSURISTUw7nCUq9B9mOzhkBzzQ27n3FnbzXeszvq+aMaGzllPVhffDXmWZ1dR5pX4/qN ky96/mhGfXVYrbwrQqIxUOHHm04bNqe46p7jZM5gv7YzS8JrSOHezSyU7/1IBuwqenMpD3y6H 9En8jvXO/bj9zTvdVbmlH9Mv5Jrd9ZMym+wst8rY4f4fi3PsSizFGYmGWsxFxYkAEM8YSosCA AA= X-Env-Sender: venu.busireddy@oracle.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1498583729!61993618!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 28122 invoked from network); 27 Jun 2017 17:15:31 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-2.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Jun 2017 17:15:31 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v5RHFPcW024552 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Jun 2017 17:15:25 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v5RHFO0M032577 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Jun 2017 17:15:24 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 v5RHFOZ2009247; Tue, 27 Jun 2017 17:15:24 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:23 -0700 From: Venu Busireddy To: venu.busireddy@oracle.com, Ian Jackson , Wei Liu Date: Tue, 27 Jun 2017 12:14:56 -0500 Message-Id: <20170627171458.2529-5-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: aserv0021.oracle.com [141.146.126.233] Cc: xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH 4/6] libxl: Add wrappers for new commands and add AER error handler 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 libxl: Add wrappers for new commands and add AER error handler Add wrappers for the newly introduced commands "pci-assignable-hide", "pci-assignable-unhide", and "pci-assignable-list-hidden". Implement the callback function to handle unrecoverable AER errors. Signed-off-by: Venu Busireddy --- tools/libxl/libxl.h | 3 + tools/libxl/libxl_event.h | 2 + tools/libxl/libxl_pci.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index cf8687a..5a5bd14 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -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); diff --git a/tools/libxl/libxl_event.h b/tools/libxl/libxl_event.h index 1ea789e..4c78798 100644 --- a/tools/libxl/libxl_event.h +++ b/tools/libxl/libxl_event.h @@ -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 diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index b14df16..e6996e5 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -874,6 +874,42 @@ int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pcidev, return rc; } +int libxl_device_pci_assignable_hide(libxl_ctx *ctx, libxl_device_pci *pcidev) +{ + GC_INIT(ctx); + int rc; + + rc = xc_hide_device(ctx->xch, pcidev_encode_bdf(pcidev)); + if (rc < 0) + LOGD(ERROR, 0, "xc_hide_device failed"); + + GC_FREE; + return rc; +} + +int libxl_device_pci_assignable_unhide(libxl_ctx *ctx, libxl_device_pci *pcidev) +{ + GC_INIT(ctx); + int rc; + + rc = xc_unhide_device(ctx->xch, pcidev_encode_bdf(pcidev)); + if (rc < 0) + LOGD(ERROR, 0, "xc_unhide_device failed"); + + GC_FREE; + return rc; +} + +int libxl_device_pci_assignable_is_hidden(libxl_ctx *ctx, libxl_device_pci *pcidev) +{ + GC_INIT(ctx); + int rc; + + rc = xc_test_hidden_device(ctx->xch, pcidev_encode_bdf(pcidev)); + + GC_FREE; + return rc; +} int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *pcidev, int rebind) @@ -1292,6 +1328,120 @@ out: return rc; } +static void domain_destroy_callback(libxl__egc *egc, + libxl__domain_destroy_state *dds, + int rc) +{ + STATE_AO_GC(dds->ao); + + if (rc) + LOGD(ERROR, dds->domid, "Destruction of domain failed, rc = %d", rc); + + libxl__nested_ao_free(ao); +} + + +typedef struct { + uint32_t domid; + libxl__ao *ao; + libxl__ev_xswatch watch; +} libxl_aer_watch; +static libxl_aer_watch aer_watch; + +static void aer_backend_watch_callback(libxl__egc *egc, + libxl__ev_xswatch *watch, + const char *watch_path, + const char *event_path) +{ + libxl_aer_watch *l_aer_watch = CONTAINER_OF(watch, *l_aer_watch, watch); + libxl__ao *nested_ao = libxl__nested_ao_create(l_aer_watch->ao); + STATE_AO_GC(nested_ao); + libxl_ctx *ctx = libxl__gc_owner(gc); + uint32_t domid = l_aer_watch->domid; + uint32_t seg, bus, dev, fn; + int rc; + char *p, *path, *dst_path; + const char *aerFailedSBDF; + struct xs_permissions rwperm[1]; + libxl__domain_destroy_state *dds; + GCNEW(dds); + + /* Extract the backend directory. */ + path = libxl__strdup(gc, event_path); + p = strrchr(path, '/'); + if (p == NULL) + goto skip; + if (strcmp(p, "/aerFailedSBDF") != 0) + goto skip; + /* Truncate the string so it points to the backend directory. */ + *p = '\0'; + + /* Fetch the value of the failed PCI device. */ + rc = libxl__xs_read_checked(gc, XBT_NULL, + GCSPRINTF("%s/aerFailedSBDF", path), &aerFailedSBDF); + if (rc || !aerFailedSBDF) + goto skip; + sscanf(aerFailedSBDF, "%x:%x:%x.%x", &seg, &bus, &dev, &fn); + + libxl_unreg_aer_events_handler(ctx, domid); + + dds->ao = nested_ao; + dds->domid = domid; + dds->callback = domain_destroy_callback; + libxl__domain_destroy(egc, dds); + + rc = xc_hide_device(ctx->xch, seg << 16 | bus << 8 | dev << 3 | fn); + if (rc) + LOGD(ERROR, domid, " xc_hide_device() failed, rc = %d", rc); + + rwperm[0].id = 0; + rwperm[0].perms = XS_PERM_READ | XS_PERM_WRITE; + dst_path = GCSPRINTF("/local/domain/0/backend/pci/0/0/%s", "aerFailedPCIs"); + rc = libxl__xs_mknod(gc, XBT_NULL, dst_path, rwperm, 1); + if (rc) { + LOGD(ERROR, domid, " libxl__xs_mknod() failed, rc = %d", rc); + goto skip; + } + + rc = libxl__xs_write_checked(gc, XBT_NULL, dst_path, aerFailedSBDF); + if (rc) + LOGD(ERROR, domid, " libxl__xs_write_checked() failed, rc = %d", rc); + +skip: + return; +} + +/* Handler of events for device driver domains */ +int libxl_reg_aer_events_handler(libxl_ctx *ctx, uint32_t domid) +{ + AO_CREATE(ctx, 0, 0); + int rc; + char *be_path; + + /* + * We use absolute paths because we want xswatch to also return + * absolute paths that can be parsed by libxl__parse_backend_path. + */ + aer_watch.ao = ao; + aer_watch.domid = domid; + be_path = GCSPRINTF("/local/domain/0/backend/pci/%u/0/aerFailedSBDF", domid); + rc = libxl__ev_xswatch_register(gc, &aer_watch.watch, + aer_backend_watch_callback, be_path); + if (rc) + return AO_CREATE_FAIL(rc); + + return AO_INPROGRESS; +} + +/* Handler of events for device driver domains */ +void libxl_unreg_aer_events_handler(libxl_ctx *ctx, uint32_t domid) +{ + GC_INIT(ctx); + + libxl__ev_xswatch_deregister(gc, &aer_watch.watch); + return; +} + static void libxl__add_pcidevs(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev)