From nobody Sat May 18 04:30:06 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=1563868116; cv=none; d=zoho.com; s=zohoarc; b=cbAVKLzNt/UaozGncTPVXMYkbdidBoLVv1eRgX4TVeZoBXP4YMNcDZ/3++9Q1VZs3UsiOHqncqUJm1agk7uN/HwIM2UoHCgP6HcydW8rm0yJVg7qYRnDWIeaA8MrK+r40GUPr4bUlDHfKIaI2F0l8IlTNHJ7UXwS1aAE3apEYBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563868116; 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=ImqXjdbXFeZGPluO9iKHan7qYA3/w4PKNmWAvB7P9j4=; b=WxhT/md+IaZkdmP8DoNjw16ega4fWuS1c9tH4XEl1oCQJRWO26MLtA2h+meMuWX0kkFBcV5Mjk2Zm251oPwuyU3BITxZVwHuo4gA3G9N8FmdGf0i/TW0R7HkaA/Q4mk4ob+DwV0fy9ZFgwZdhYpqTuAZJjBOW8lY7glGJQWKwXs= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563868116378206.3357293084058; Tue, 23 Jul 2019 00:48:36 -0700 (PDT) Received: from localhost ([::1]:39902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hppX9-0003ZU-Lx for importer@patchew.org; Tue, 23 Jul 2019 03:48:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46706) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hppWr-00033u-UJ for qemu-devel@nongnu.org; Tue, 23 Jul 2019 03:48:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hppWq-0004sA-OZ for qemu-devel@nongnu.org; Tue, 23 Jul 2019 03:48:09 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2420 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hppWq-0004W9-DQ for qemu-devel@nongnu.org; Tue, 23 Jul 2019 03:48:08 -0400 Received: from dggeml406-hub.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id B20E0A244E4A19E8863C; Tue, 23 Jul 2019 15:47:57 +0800 (CST) Received: from DGGEML509-MBX.china.huawei.com ([169.254.1.213]) by dggeml406-hub.china.huawei.com ([10.3.17.50]) with mapi id 14.03.0439.000; Tue, 23 Jul 2019 15:47:51 +0800 From: "Zhangbo (Oscar)" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH] pcie: fix device hotplug failure at the meantime of VM boot Thread-Index: AdVBKpt/7Hdh09K+Sm2XGmt+PVN0Sw== Date: Tue, 23 Jul 2019 07:47:51 +0000 Message-ID: <0259E1C966E8C54AA93AA2B1240828E672DF1C92@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.187 Subject: [Qemu-devel] [PATCH] 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\)" , "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: limingwang@huawei.com Signed-off-by: fangying1@huawei.com Signed-off-by: oscar.zhangbo@huawei.com --- 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