From nobody Sat May 18 03:46:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1563874316; cv=none; d=zoho.com; s=zohoarc; b=SnaiXMgwqaV8SSMRutzPxtph89/vQ8kgqmwtCQ1Q/L07oP5ogxYnOY15WZq+5X4tvDoMNr5iNljaiivoUDSEa7dFVzpYCWFEWdqiS2y9dJA2XNVsA11TOFdudi/NsWiDO3P22IMtaIgbc3ZRYWHTpKPs78cdbdbHNCG4V5ywcyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563874316; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=/tx7u09KzAAHQ0oyx2nYsFVVmubH17gZ+C2tWQ2AILM=; b=JzGdth4rJ86G4TQVbcyY41VfGJpUlSy8XGWx8GgMJOmhThe//3T1S2W7uAdewshTA9An2jj1yQqwNBhPe8bWALcg7RgTO1nKNV0mW2gPwawpW4Wnef3xPtJQkqpk7W8AyCh58CemsZ5bKMK8PkY/Cy8cONbLYqG6y+gyENrNRUo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563874316917545.886580873561; Tue, 23 Jul 2019 02:31:56 -0700 (PDT) Received: from localhost ([::1]:40566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpr9H-0005bj-Qb for importer@patchew.org; Tue, 23 Jul 2019 05:31:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47169) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpr96-0005DP-I5 for qemu-devel@nongnu.org; Tue, 23 Jul 2019 05:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpr95-0006zv-J8 for qemu-devel@nongnu.org; Tue, 23 Jul 2019 05:31:44 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2050 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpr95-0006xq-8k for qemu-devel@nongnu.org; Tue, 23 Jul 2019 05:31:43 -0400 Received: from dggeml405-hub.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id 0E2E4C2AC3043D82F029; Tue, 23 Jul 2019 17:31:38 +0800 (CST) Received: from DGGEML422-HUB.china.huawei.com (10.1.199.39) by dggeml405-hub.china.huawei.com (10.3.17.49) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 23 Jul 2019 17:31:37 +0800 Received: from DGGEML509-MBX.china.huawei.com ([169.254.1.213]) by dggeml422-hub.china.huawei.com ([10.1.199.39]) with mapi id 14.03.0439.000; Tue, 23 Jul 2019 17:31:31 +0800 From: "Zhangbo (Oscar)" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2] pcie: fix device hotplug failure at the meantime of VM boot Thread-Index: AdVBOS0yfVqcQ/jfSjiRBqDIjyMExA== Date: Tue, 23 Jul 2019 09:31:30 +0000 Message-ID: <0259E1C966E8C54AA93AA2B1240828E672DF3D38@dggeml509-mbx.china.huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.177.17.158] Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.189 Subject: [Qemu-devel] [PATCH v2] pcie: fix device hotplug failure at the meantime of VM boot X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fangying , "dengkai \(A\)" , "philmd@redhat.com" , "limingwang \(A\)" , "mst@redhat.com" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" If the PCI_EXP_LNKSTA_DLLLA capability is set by default, linux kernel will= send=20 PDC event to detect whether there is a device in pcie slot. If a device is = pluged in the pcie-root-port at the same time, hot-plug device will send ABP + PDC events to the kernel. The VM kernel will wrongly unplug the device if two P= DC events get too close. Thus we'd better set the PCI_EXP_LNKSTA_DLLLA capability only in hotplug callback. By the way, we should clean up the PCI_EXP_LNKSTA_DLLLA capability during unplug to avoid VM restart or migration failure which will enter the same abnormal scenario as above. Signed-off-by: Li Mingwang Signed-off-by: Fang Ying Signed-off-by: Zhang Bo --- hw/pci/pcie.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index a6beb56..174f392 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -75,10 +75,6 @@ pcie_cap_v1_fill(PCIDevice *dev, uint8_t port, uint8_t t= ype, uint8_t version) QEMU_PCI_EXP_LNKSTA_NLW(QEMU_PCI_EXP_LNK_X1) | QEMU_PCI_EXP_LNKSTA_CLS(QEMU_PCI_EXP_LNK_2_5GT)); =20 - if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA) { - pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA, - PCI_EXP_LNKSTA_DLLLA); - } =20 /* We changed link status bits over time, and changing them across * migrations is generally fine as hardware changes them too. @@ -484,6 +480,11 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *h= otplug_dev, return; } =20 + if (pci_dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA) { + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA, + PCI_EXP_LNKSTA_DLLLA); + } + pcie_cap_slot_push_attention_button(PCI_DEVICE(hotplug_dev)); } =20 --=20 1.8.3.1