From patchwork Tue Oct 1 04:24:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 11167943 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49CB714DB for ; Tue, 1 Oct 2019 04:26:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1AE6020700 for ; Tue, 1 Oct 2019 04:26:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="u5mOwflC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AE6020700 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iF9iA-0003rb-0k; Tue, 01 Oct 2019 04:24:30 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iF9i8-0003rW-AQ for xen-devel@lists.xenproject.org; Tue, 01 Oct 2019 04:24:28 +0000 X-Inumbo-ID: 5a2d1e50-e403-11e9-96ee-12813bfff9fa Received: from out5-smtp.messagingengine.com (unknown [66.111.4.29]) by localhost (Halon) with ESMTPS id 5a2d1e50-e403-11e9-96ee-12813bfff9fa; Tue, 01 Oct 2019 04:24:26 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C17E9223B4; Tue, 1 Oct 2019 00:24:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Tue, 01 Oct 2019 00:24:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=33Y4VCU3xgJjZ1/oKf3A5muqK8MiriGb/AMIZa65g DQ=; b=u5mOwflC3W+xCbWKGqIsEZ8a9Zvicf8qAfaeCMuEYPCmQGX3qW/zw0lBK FjSI/w4GybiW/5HOfVnkU4KXTEqJifHz77jeze/LtJnjndRFxYxfPEnJ0d0aB+qg GyUg+5ql8O590wqLJjQIVW0c2GrQ5PS/hcyalsRHZJJaCNVV+d0RLqiiDvCgudaA 3bGN6bBtzLNNC1hMwCPzVuIshzKleFvjKl31YnIZL6X4+DxWzXOzbs/6EYAUKCWR nOZeCTQmm89/WsdHWprR9hCehW/VvZp9UXYLuz1wBUQeIK6C788fGd/j88MpIIpW jzYWyuStZqedxB0PhO2Fnc9px9SDA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrgeefgdekudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggugfgjfgesthekredttderjeenucfhrhhomhepofgrrhgv khcuofgrrhgtiiihkhhofihskhhiqdfikphrvggtkhhiuceomhgrrhhmrghrvghksehinh hvihhsihgslhgvthhhihhnghhslhgrsgdrtghomheqnecukfhppedukeehrddvudefrddu heehrddujedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgvkhesihhnvh hishhisghlvghthhhinhhgshhlrggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from mail-itl (unknown [185.213.155.170]) by mail.messagingengine.com (Postfix) with ESMTPA id 6C747D60057; Tue, 1 Oct 2019 00:24:23 -0400 (EDT) Date: Mon, 30 Sep 2019 23:24:19 -0500 From: Marek =?utf-8?q?Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Message-ID: <20191001042419.GA5213@mail-itl> References: <20190930151149.GE1163@perard.uk.xensource.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190930151149.GE1163@perard.uk.xensource.com> User-Agent: Mutt/1.12.1 (2019-06-15) Subject: [Xen-devel] [PATCH v8.1 3/4] libxl: attach PCI device to qemu only after setting pciback/pcifront X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" When qemu is running in stubdomain, handling "pci-ins" command will fail if pcifront is not initialized already. Fix this by sending such command only after confirming that pciback/front is running. Signed-off-by: Marek Marczykowski-Górecki Reviewed-by: Anthony PERARD --- Changes in v2: - Fixed code style since previous version. Changes in v8: - rebase on staging - rework for async api Changes in v8.1: - code style fixes --- tools/libxl/libxl_pci.c | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index ac597a58fe..8dc352c961 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -1012,6 +1012,9 @@ typedef struct pci_add_state { bool starting; void (*callback)(libxl__egc *, struct pci_add_state *, int rc); + /* private to device_pci_add_stubdom_wait */ + libxl__ev_devstate pciback_ds; + /* private to do_pci_add */ libxl__xswait_state xswait; libxl__ev_qmp qmp; @@ -1487,6 +1490,10 @@ static int libxl_pcidev_assignable(libxl_ctx *ctx, libxl_device_pci *pcidev) return i != num; } +static void device_pci_add_stubdom_wait(libxl__egc *egc, + pci_add_state *pas, int rc); +static void device_pci_add_stubdom_ready(libxl__egc *egc, + libxl__ev_devstate *ds, int rc); static void device_pci_add_stubdom_done(libxl__egc *egc, pci_add_state *, int rc); static void device_pci_add_done(libxl__egc *egc, @@ -1563,7 +1570,8 @@ void libxl__device_pci_add(libxl__egc *egc, uint32_t domid, GCNEW(pcidev_s); libxl_device_pci_init(pcidev_s); libxl_device_pci_copy(CTX, pcidev_s, pcidev); - pas->callback = device_pci_add_stubdom_done; + pas->callback = device_pci_add_stubdom_wait; + do_pci_add(egc, stubdomid, pcidev_s, pas); /* must be last */ return; } @@ -1575,6 +1583,41 @@ out: device_pci_add_done(egc, pas, rc); /* must be last */ } +static void device_pci_add_stubdom_wait(libxl__egc *egc, + pci_add_state *pas, + int rc) +{ + libxl__ao_device *aodev = pas->aodev; + STATE_AO_GC(aodev->ao); + int stubdomid = libxl_get_stubdom_id(CTX, pas->domid); + char *state_path; + + if (rc) goto out; + + /* Wait for the device actually being connected, otherwise device model + * running there will fail to find the device. */ + state_path = GCSPRINTF("%s/state", + libxl__domain_device_backend_path(gc, 0, stubdomid, 0, + LIBXL__DEVICE_KIND_PCI)); + rc = libxl__ev_devstate_wait(ao, &pas->pciback_ds, + device_pci_add_stubdom_ready, + state_path, XenbusStateConnected, + LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000); + if (rc) goto out; + return; +out: + device_pci_add_done(egc, pas, rc); /* must be last */ +} + +static void device_pci_add_stubdom_ready(libxl__egc *egc, + libxl__ev_devstate *ds, + int rc) +{ + pci_add_state *pas = CONTAINER_OF(ds, *pas, pciback_ds); + + device_pci_add_stubdom_done(egc, pas, rc); /* must be last */ +} + static void device_pci_add_stubdom_done(libxl__egc *egc, pci_add_state *pas, int rc)