From patchwork Sat Sep 28 14:20:36 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: 11165419 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 B837417EE for ; Sat, 28 Sep 2019 14:22:33 +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 9432E20815 for ; Sat, 28 Sep 2019 14:22:33 +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="syT9x8jT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9432E20815 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 1iEDbA-0003mr-A3; Sat, 28 Sep 2019 14:21:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iEDb8-0003m4-DH for xen-devel@lists.xenproject.org; Sat, 28 Sep 2019 14:21:22 +0000 X-Inumbo-ID: 3a77441e-e1fb-11e9-b588-bc764e2007e4 Received: from out5-smtp.messagingengine.com (unknown [66.111.4.29]) by localhost (Halon) with ESMTPS id 3a77441e-e1fb-11e9-b588-bc764e2007e4; Sat, 28 Sep 2019 14:21:14 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 7362921CDD; Sat, 28 Sep 2019 10:21:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sat, 28 Sep 2019 10:21:14 -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=HAmib2qqZ5oj8XczRtcegzLko/r9WTZq+MH/BELfW UI=; b=syT9x8jTXgX573Yq9m3LHwPScUstkraRJ7rielm3gGFbdJ+UhEwz9oWyO UM5MEmayaJoUmxrEricMjiqQsnQz/BgxXljxgdxRYsc+wGcQj31xQVhSd+/vc3AC ieKQUpukLsfgvI1P/1X33k9R4L9c0nv5dF79EbiQ2Lm4gYZK0M3vIn74hEeoPovE iZXIs+et4pKEsBJn4PI7VzPFbbIORw3g+3ZeP7eDOZls2T6ZfzHZYh0UUBPSlQ3l Ix+chP5vCf+DdqE42ii5Pkpd7mh3EO6WMdB9zqnumfpHum4fk9XaNsL/HvzEw6Sa xWwPpqenAqXNz5HhxvBMfaBgzRtAw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrfeekgdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeforghrvghk ucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesihhnvh hishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucfkphepledurdeihedrfeegrdef feenucfrrghrrghmpehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslh gvthhhihhnghhslhgrsgdrtghomhenucevlhhushhtvghrufhiiigvpedv X-ME-Proxy: Received: from localhost.localdomain (ip5b412221.dynamic.kabel-deutschland.de [91.65.34.33]) by mail.messagingengine.com (Postfix) with ESMTPA id 90488D6005E; Sat, 28 Sep 2019 10:21:13 -0400 (EDT) From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Date: Sat, 28 Sep 2019 16:20:36 +0200 Message-Id: <66a544b7e292dfe227349ffcc75a0136ca27afb1.1569680095.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v8 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 , =?utf-8?q?Marek_Marczykowski-G?= =?utf-8?q?=C3=B3recki?= , 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 --- 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 ac597a5..ba0287d 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); + libxl_ctx *ctx = libxl__gc_owner(gc); + 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 = libxl__sprintf(gc, "%s/backend/pci/%d/0/state", + libxl__xs_get_dompath(gc, 0), stubdomid); + rc = libxl__ev_devstate_wait(aodev->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)