From nobody Fri Apr 19 01:19:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1641751529; cv=none; d=zohomail.com; s=zohoarc; b=ieNfLOfyFyLhkpykUTZiEpXdBtqKNaq9HCr+61Ci+9x+QiRAKqDU4huuYO7KYso06fNdbsSN640cVAKU9StdmTjKRtOHuyg/UH3kv4gMoKqoPRPBRo9e1GbzGkFDpEeidHbQ5Vbly3IJPEaKN1QdBIDUDp+6LQkmiRxXFYyqAFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641751529; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=k+eEj6jZ9SwYT86CY9jQdLefEzfnqb021ofP7z26oIk=; b=lHvclnKO9UPg4UQg+bgV1NexPKduWzm0V0cvq0KKT7uCdufOLM1TQkYzD7YIaA2Xskzd6/HNLhstnnQs2vjBZgv0+v39g5Zy9o8OSZNnI2tze+siZGxsdsKTDxhQIn537Zo0lkl0hIaP3/R4Ol1Vn5T5hWLQmB0gQssCHiU43ek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641751529572673.0477443388213; Sun, 9 Jan 2022 10:05:29 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255170.437270 (Exim 4.92) (envelope-from ) id 1n6cYf-0000iB-WE; Sun, 09 Jan 2022 18:04:46 +0000 Received: by outflank-mailman (output) from mailman id 255170.437270; Sun, 09 Jan 2022 18:04:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n6cYf-0000i4-TF; Sun, 09 Jan 2022 18:04:45 +0000 Received: by outflank-mailman (input) for mailman id 255170; Sun, 09 Jan 2022 18:04:45 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n6cYf-0000hy-7Z for xen-devel@lists.xenproject.org; Sun, 09 Jan 2022 18:04:45 +0000 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [2607:f8b0:4864:20::f32]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9f6671ba-7176-11ec-9ce5-af14b9085ebd; Sun, 09 Jan 2022 19:04:44 +0100 (CET) Received: by mail-qv1-xf32.google.com with SMTP id kc16so12154831qvb.3 for ; Sun, 09 Jan 2022 10:04:44 -0800 (PST) Received: from shine.lan ([2001:470:8:67e:f1cf:3fc:7c72:5d]) by smtp.gmail.com with ESMTPSA id l203sm2950171qke.44.2022.01.09.10.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 10:04:41 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9f6671ba-7176-11ec-9ce5-af14b9085ebd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=k+eEj6jZ9SwYT86CY9jQdLefEzfnqb021ofP7z26oIk=; b=QKk9sBLhDmK2s/13XBuNthm2Z6zF0jkCTx2Qdb/CAatIQRayfFADLVQ72uk9nDa2Ca qLZByTzcKDG3LRwre39aLDZ4kaVeUsbxqfldXRUb/RoH59jNY2z7V7w1XwiyLH8C1ylT +aBY2FWA6rXVSkXg10F0JoIGTdmc9eJTWRMFX628ws4tUSzqEQ5eZKySvqqgOG4AUOf9 SQkZzQEwfOXZPg11hUO2SAzX3HMmQG0rtXZo9Dw8gWAVcJd9UL8kFYpoXhL6FVtCr/UU wnsPf5xT8UV7VL/daswUHK5eaXi01VEXw7NI4UCE+3C+Bprgx7LX6oUIXygnTnm1jMwE mhVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=k+eEj6jZ9SwYT86CY9jQdLefEzfnqb021ofP7z26oIk=; b=KCOAPHAMsyvILVjBuuwyt1GLaRT9G6dL3bfS8PyFZLEnWrSOkpIaaF6/PIBTgSX3iH CnBIl/oHkH3KeEDoqvBYPRUlTE2z6rFTUUrJ3iV5ig06AB6wdG/c+mPC7sNBYjAua/3Z atUP2qwLMWZ28/ymOvu2Fc0qATNEj13FmCp6oeXbyv4RKP5ZgS/MBMMO/gfW5sHVywZT CCuakdAqBVRd3I5EX+JpIVKfi1k9gqbaa7GhAHNKa3Bg+8DE8wMVctQsEJ5qeodz2W7J R8AN/KGAAxj24B4AShpW+doe3Y/aQaPpRAzs5UvwfbyxvgTwu+Q2evGvSQLMuFx9N9Ff 19fQ== X-Gm-Message-State: AOAM530za7iX+dNIc/Mdf6nVscHrOk3R2CLOO+aGBlG3Z2n7j+eoriid r8UVZcS7kcIcHmvansOHm3GH2M3iSis= X-Google-Smtp-Source: ABdhPJz/yDUN+Hj8KFSilR976nsAtQbiYuip7ChB/oFEZWUdle3OVO4XM+4ET6Sw86rYUiLJ051wrw== X-Received: by 2002:a05:6214:da6:: with SMTP id h6mr3391131qvh.100.1641751482808; Sun, 09 Jan 2022 10:04:42 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v3] libxl/PCI: Fix PV hotplug & stubdom coldplug Date: Sun, 9 Jan 2022 13:04:36 -0500 Message-Id: <20220109180436.4112-1-jandryuk@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1641751531208100001 Content-Type: text/plain; charset="utf-8" commit 0fdb48ffe7a1 "libxl: Make sure devices added by pci-attach are reflected in the config" broken PCI hotplug (xl pci-attach) for PV domains when it moved libxl__create_pci_backend() later in the function. This also broke HVM + stubdom PCI passthrough coldplug. For that, the PCI devices are hotplugged to a running PV stubdom, and then the QEMU QMP device_add commands are made to QEMU inside the stubdom. Are running PV domain calls libxl__wait_for_backend(). With the current placement of libxl__create_pci_backend(), the path does not exist and the call immediately fails: libxl: error: libxl_device.c:1388:libxl__wait_for_backend: Backend /local/d= omain/0/backend/pci/43/0 does not exist libxl: error: libxl_pci.c:1764:device_pci_add_done: Domain 42:libxl__device= _pci_add failed for PCI device 0:2:0.0 (rc -3) libxl: error: libxl_create.c:1857:domcreate_attach_devices: Domain 42:unabl= e to add pci devices The wait is only relevant when the backend is already present. num_devs is already used to determine if the backend needs to be created. Re-use num_devs to determine if the backend wait is necessary. The wait is necessary to avoid racing with another PCI attachment reconfiguring the front/back or changing to some other state like closing. If we are creating the backend, then we don't have to worry about the state since it is being created. Fixes: 0fdb48ffe7a1 ("libxl: Make sure devices added by pci-attach are reflected in the config") Signed-off-by: Jason Andryuk --- Alternative to Jan's patch: https://lore.kernel.org/xen-devel/5114ae87-bc0e-3d58-e16e-6d9d2fee0801@suse= .com/ v3: Change title & commit message v2: https://lore.kernel.org/xen-devel/20210812005700.3159-1-jandryuk@gmail.com/ Add Fixes Expand num_devs use in commit message --- tools/libs/light/libxl_pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 4c2d7aeefb..e8fd3bd937 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -157,8 +157,10 @@ static int libxl__device_pci_add_xenstore(libxl__gc *g= c, if (domtype =3D=3D LIBXL_DOMAIN_TYPE_INVALID) return ERROR_FAIL; =20 - if (!starting && domtype =3D=3D LIBXL_DOMAIN_TYPE_PV) { - if (libxl__wait_for_backend(gc, be_path, GCSPRINTF("%d", XenbusSta= teConnected)) < 0) + /* wait is only needed if the backend already exists (num_devs !=3D NU= LL) */ + if (num_devs && !starting && domtype =3D=3D LIBXL_DOMAIN_TYPE_PV) { + if (libxl__wait_for_backend(gc, be_path, + GCSPRINTF("%d", XenbusStateConnected))= < 0) return ERROR_FAIL; } =20 --=20 2.32.0