From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954297345599.959881515596; Mon, 11 Oct 2021 05:11:37 -0700 (PDT) Received: from localhost ([::1]:40808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZu9Y-0007U2-Dv for importer@patchew.org; Mon, 11 Oct 2021 08:11:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu3m-0005us-5w for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu3k-00042T-0K for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-PbSzQc03N2--dmG5xKj9iw-1; Mon, 11 Oct 2021 08:05:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 039E0801AB0; Mon, 11 Oct 2021 12:05:33 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2230357CA6; Mon, 11 Oct 2021 12:05:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 813AA18007B1; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RXNJsRs9OAo7+t16v3btX9bQqGR6vhdgYrCExlNfs60=; b=NpBvNEdn9joPjNEAhKPxlFPRsEocbloI8sqowQeaS3a8Cwx4Qg4OXzig//wSKOkWOoxAd7 wQoQswD0ZmkYIFg0alRAAdRgH02E/+tBCr/nlsks9ets80XafyS+c+htW9QVB6pex7kMmu IlAnU7zwGiBJgRGyqYbCUwD6dnY3zKs= X-MC-Unique: PbSzQc03N2--dmG5xKj9iw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 1/6] pci: implement power state Date: Mon, 11 Oct 2021 14:04:59 +0200 Message-Id: <20211011120504.254053-2-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954298973100003 Content-Type: text/plain; charset="utf-8" This allows to power off pci devices. In "off" state the devices will not be visible. No pci config space access, no pci bar access, no dma. Default state is "on", so this patch (alone) should not change behavior. Use case: Allows hotplug controllers implement slot power. Hotplug controllers doing so should set the inital power state for devices in the ->plug callback. Signed-off-by: Gerd Hoffmann --- include/hw/pci/pci.h | 2 ++ hw/pci/pci.c | 25 +++++++++++++++++++++++-- hw/pci/pci_host.c | 6 ++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 7fc90132cf1d..7cb6d92e17f7 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -268,6 +268,7 @@ typedef struct PCIReqIDCache PCIReqIDCache; struct PCIDevice { DeviceState qdev; bool partially_hotplugged; + bool has_power; =20 /* PCI config space */ uint8_t *config; @@ -904,5 +905,6 @@ extern const VMStateDescription vmstate_pci_device; } =20 MSIMessage pci_get_msi_message(PCIDevice *dev, int vector); +void pci_set_power(PCIDevice *pci_dev, bool state); =20 #endif diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 186758ee11fe..94f53944c7cc 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1380,6 +1380,9 @@ static void pci_update_mappings(PCIDevice *d) continue; =20 new_addr =3D pci_bar_address(d, i, r->type, r->size); + if (!d->has_power) { + new_addr =3D PCI_BAR_UNMAPPED; + } =20 /* This bar isn't changed */ if (new_addr =3D=3D r->addr) @@ -1464,8 +1467,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t = addr, uint32_t val_in, int if (range_covers_byte(addr, l, PCI_COMMAND)) { pci_update_irq_disabled(d, was_irq_disabled); memory_region_set_enabled(&d->bus_master_enable_region, - pci_get_word(d->config + PCI_COMMAND) - & PCI_COMMAND_MASTER); + (pci_get_word(d->config + PCI_COMMAND) + & PCI_COMMAND_MASTER) && d->has_power); } =20 msi_write_config(d, addr, val_in, l); @@ -2190,6 +2193,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error= **errp) pci_qdev_unrealize(DEVICE(pci_dev)); return; } + + pci_set_power(pci_dev, true); } =20 PCIDevice *pci_new_multifunction(int devfn, bool multifunction, @@ -2861,6 +2866,22 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int v= ector) return msg; } =20 +void pci_set_power(PCIDevice *d, bool state) +{ + if (d->has_power =3D=3D state) { + return; + } + + d->has_power =3D state; + pci_update_mappings(d); + memory_region_set_enabled(&d->bus_master_enable_region, + (pci_get_word(d->config + PCI_COMMAND) + & PCI_COMMAND_MASTER) && d->has_power); + if (!d->has_power) { + pci_device_reset(d); + } +} + static const TypeInfo pci_device_type_info =3D { .name =3D TYPE_PCI_DEVICE, .parent =3D TYPE_DEVICE, diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index cf02f0d6a501..7beafd40a8e9 100644 --- a/hw/pci/pci_host.c +++ b/hw/pci/pci_host.c @@ -74,7 +74,8 @@ void pci_host_config_write_common(PCIDevice *pci_dev, uin= t32_t addr, /* non-zero functions are only exposed when function 0 is present, * allowing direct removal of unexposed functions. */ - if (pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) { + if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) || + !pci_dev->has_power) { return; } =20 @@ -97,7 +98,8 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, = uint32_t addr, /* non-zero functions are only exposed when function 0 is present, * allowing direct removal of unexposed functions. */ - if (pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) { + if ((pci_dev->qdev.hotplugged && !pci_get_function_0(pci_dev)) || + !pci_dev->has_power) { return ~0x0; } =20 --=20 2.31.1 From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954092702516.5393336094161; Mon, 11 Oct 2021 05:08:12 -0700 (PDT) Received: from localhost ([::1]:60096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZu6D-0000mb-2n for importer@patchew.org; Mon, 11 Oct 2021 08:08:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu3w-0005xW-AA for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu3t-0004La-HB for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-3xoQJxA9NVWYtVFsyTYXrg-1; Mon, 11 Oct 2021 08:05:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE8EC801A92; Mon, 11 Oct 2021 12:05:40 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF61926E4E; Mon, 11 Oct 2021 12:05:22 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8D30E18009D4; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IIGSeRHYDJ7JScR37o2qhRhNO6KNToSsU6m+phZkT58=; b=hE967uGU0cOyJJeg7DvFlVAB/D18ibQNa7kz9tJ0UrretUMFjz9xF/lnsoMpJa1V16voam aO9LpFi54CBQy2gqKJVqtZH+9rIhEgWisRz0h75shX96qGPxToQ7oJ3nHRex/oT24fy0gU vsHsLckCoSRRqqO2cyUaqrj88oXwN0c= X-MC-Unique: 3xoQJxA9NVWYtVFsyTYXrg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 2/6] pcie: implement slow power control for pcie root ports Date: Mon, 11 Oct 2021 14:05:00 +0200 Message-Id: <20211011120504.254053-3-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954094727100001 Content-Type: text/plain; charset="utf-8" With this patch hot-plugged pci devices will only be visible to the guest if the guests hotplug driver has enabled slot power. This should fix the hot-plug race which one can hit when hot-plugging a pci device at boot, while the guest is in the middle of the pci bus scan. Signed-off-by: Gerd Hoffmann --- hw/pci/pcie.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 6e95d829037a..4a52c250615e 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -366,6 +366,29 @@ static void hotplug_event_clear(PCIDevice *dev) } } =20 +static void pcie_set_power_device(PCIBus *bus, PCIDevice *dev, void *opaqu= e) +{ + bool *power =3D opaque; + + pci_set_power(dev, *power); +} + +static void pcie_cap_update_power(PCIDevice *hotplug_dev) +{ + uint8_t *exp_cap =3D hotplug_dev->config + hotplug_dev->exp.exp_cap; + PCIBus *sec_bus =3D pci_bridge_get_sec_bus(PCI_BRIDGE(hotplug_dev)); + uint32_t sltcap =3D pci_get_long(exp_cap + PCI_EXP_SLTCAP); + uint16_t sltctl =3D pci_get_word(exp_cap + PCI_EXP_SLTCTL); + bool power =3D true; + + if (sltcap & PCI_EXP_SLTCAP_PCP) { + power =3D (sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_= ON; + } + + pci_for_each_device(sec_bus, pci_bus_num(sec_bus), + pcie_set_power_device, &power); +} + /* * A PCI Express Hot-Plug Event has occurred, so update slot status regist= er * and notify OS of the event if necessary. @@ -434,6 +457,7 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev,= DeviceState *dev, pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA, PCI_EXP_LNKSTA_DLLLA); } + pcie_cap_update_power(hotplug_pdev); return; } =20 @@ -451,6 +475,7 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev,= DeviceState *dev, } pcie_cap_slot_event(hotplug_pdev, PCI_EXP_HP_EV_PDC | PCI_EXP_HP_EV_ABP); + pcie_cap_update_power(hotplug_pdev); } } =20 @@ -625,6 +650,7 @@ void pcie_cap_slot_reset(PCIDevice *dev) PCI_EXP_SLTSTA_PDC | PCI_EXP_SLTSTA_ABP); =20 + pcie_cap_update_power(dev); hotplug_event_update_event_status(dev); } =20 @@ -707,6 +733,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev, pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, PCI_EXP_SLTSTA_PDC); } + pcie_cap_update_power(dev); =20 hotplug_event_notify(dev); =20 @@ -733,6 +760,7 @@ int pcie_cap_slot_post_load(void *opaque, int version_i= d) { PCIDevice *dev =3D opaque; hotplug_event_update_event_status(dev); + pcie_cap_update_power(dev); return 0; } =20 --=20 2.31.1 From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954095876399.4777561214755; Mon, 11 Oct 2021 05:08:15 -0700 (PDT) Received: from localhost ([::1]:60500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZu6H-00012p-JE for importer@patchew.org; Mon, 11 Oct 2021 08:08:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu45-00063E-Ja for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26311) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu41-0004M0-Sl for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:05:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-ya7YBBqkNb6ToqGSogilCg-1; Mon, 11 Oct 2021 08:05:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E83D824FA6; Mon, 11 Oct 2021 12:05:48 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE00260BF4; Mon, 11 Oct 2021 12:05:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9863318009E6; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8KXxjvzwEushWIdcMmb/D4s2ClTPy0CVLK6ZiwQw0b0=; b=eRIdu7sMbbRcXFZUmjiNxAE0Ibkgue8lbVHCPVRikWAn181kO2AMk7l/OpetktzEBynUyE AKIs0LTraW3ZzQCQwVKv0OePN1alxSXsH7zFPYWTx1Zq2tk9cnrUl48UNJAQwTUl//zLgn wdXABl0XIoc/aJzOWtinNBlz1TO47Wo= X-MC-Unique: ya7YBBqkNb6ToqGSogilCg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 3/6] pcie: add power indicator blink check Date: Mon, 11 Oct 2021 14:05:01 +0200 Message-Id: <20211011120504.254053-4-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954097009100001 Content-Type: text/plain; charset="utf-8" Refuse to push the attention button in case the guest is busy with some hotplug operation (as indicated by the power indicator blinking). Signed-off-by: Gerd Hoffmann --- hw/pci/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 4a52c250615e..c455f92e16bf 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -506,6 +506,7 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *ho= tplug_dev, PCIDevice *hotplug_pdev =3D PCI_DEVICE(hotplug_dev); uint8_t *exp_cap =3D hotplug_pdev->config + hotplug_pdev->exp.exp_cap; uint32_t sltcap =3D pci_get_word(exp_cap + PCI_EXP_SLTCAP); + uint16_t sltctl =3D pci_get_word(exp_cap + PCI_EXP_SLTCTL); =20 /* Check if hot-unplug is disabled on the slot */ if ((sltcap & PCI_EXP_SLTCAP_HPC) =3D=3D 0) { @@ -521,6 +522,12 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *h= otplug_dev, return; } =20 + if ((sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_BLINK)= { + error_setg(errp, "Hot-unplug failed: " + "guest is busy (power indicator blinking)"); + return; + } + dev->pending_deleted_event =3D true; =20 /* In case user cancel the operation of multi-function hot-add, --=20 2.31.1 From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954423317551.7138249444457; Mon, 11 Oct 2021 05:13:43 -0700 (PDT) Received: from localhost ([::1]:45604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZuBa-0002OG-4r for importer@patchew.org; Mon, 11 Oct 2021 08:13:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu4G-0006Ch-I1 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu4E-0004Uh-Px for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-258-lFwOsxH4OdCVwIrJJQd94w-1; Mon, 11 Oct 2021 08:06:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5391810A8E08; Mon, 11 Oct 2021 12:06:02 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CED91017CF2; Mon, 11 Oct 2021 12:05:42 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A3C7118009E8; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oDLA+4+iKASCGil0eq2ZETz5bWhYhZ31WJt/CwWJNWw=; b=JWNmnPUSE3Z2BHtFllHIrNIh15P9vNtL+u8CyPfGzP8L3Nhn3NBH33q/MCJ9Al/7I4CZJU Aw0tuCL717o6Ur+FCAWBEWZB1VBpViFePCgwvo6mHy29Pt5eG3byqCJyEqo/yjfuVY0gG5 LzSj8vbtGvhpMFQ+6WAetlNMuwO6NyE= X-MC-Unique: lFwOsxH4OdCVwIrJJQd94w-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 4/6] pcie: factor out pcie_cap_slot_unplug() Date: Mon, 11 Oct 2021 14:05:02 +0200 Message-Id: <20211011120504.254053-5-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954424142100001 Content-Type: text/plain; charset="utf-8" No functional change. Signed-off-by: Gerd Hoffmann --- hw/pci/pcie.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index c455f92e16bf..70fc11ba4c7d 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -497,6 +497,26 @@ static void pcie_unplug_device(PCIBus *bus, PCIDevice = *dev, void *opaque) object_unparent(OBJECT(dev)); } =20 +static void pcie_cap_slot_do_unplug(PCIDevice *dev) +{ + PCIBus *sec_bus =3D pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); + uint8_t *exp_cap =3D dev->config + dev->exp.exp_cap; + uint32_t lnkcap =3D pci_get_long(exp_cap + PCI_EXP_LNKCAP); + + pci_for_each_device(sec_bus, pci_bus_num(sec_bus), + pcie_unplug_device, NULL); + + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_PDS); + if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || + (lnkcap & PCI_EXP_LNKCAP_DLLLARC)) { + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA, + PCI_EXP_LNKSTA_DLLLA); + } + pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_PDC); +} + void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -676,7 +696,6 @@ void pcie_cap_slot_write_config(PCIDevice *dev, uint32_t pos =3D dev->exp.exp_cap; uint8_t *exp_cap =3D dev->config + pos; uint16_t sltsta =3D pci_get_word(exp_cap + PCI_EXP_SLTSTA); - uint32_t lnkcap =3D pci_get_long(exp_cap + PCI_EXP_LNKCAP); =20 if (ranges_overlap(addr, len, pos + PCI_EXP_SLTSTA, 2)) { /* @@ -726,19 +745,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev, (val & PCI_EXP_SLTCTL_PIC_OFF) =3D=3D PCI_EXP_SLTCTL_PIC_OFF && (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) !=3D PCI_EXP_SLTCTL_PIC_OFF= )) { - PCIBus *sec_bus =3D pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), - pcie_unplug_device, NULL); - - pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, - PCI_EXP_SLTSTA_PDS); - if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || - (lnkcap & PCI_EXP_LNKCAP_DLLLARC)) { - pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA, - PCI_EXP_LNKSTA_DLLLA); - } - pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, - PCI_EXP_SLTSTA_PDC); + pcie_cap_slot_do_unplug(dev); } pcie_cap_update_power(dev); =20 --=20 2.31.1 From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954097853622.2179746259893; Mon, 11 Oct 2021 05:08:17 -0700 (PDT) Received: from localhost ([::1]:60468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZu6K-00011Z-PM for importer@patchew.org; Mon, 11 Oct 2021 08:08:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu4B-00068N-OY for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu49-0004Q6-0E for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86-sGERBD_vN-CjFOH1uACnPw-1; Mon, 11 Oct 2021 08:05:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B8FF100C660; Mon, 11 Oct 2021 12:05:55 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C39F5C25D; Mon, 11 Oct 2021 12:05:50 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id AF0AF18009EA; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+RA1Fn/tAiTbDU7wgjQFXuoi2jwyyufHF2xCDIYUHSU=; b=afSQnDVQhMF5z3fvrzwh6G0JXs5NOFIJk+2HshJaLtP7bhTJ/xvH6AkF5f7z8t9yYKu7yT h9sxaMVe/oKHxJ33JIIX1QUPAggrBQE4kz3bj7rv3QI+xWZCXlQqSOALGeH88lv2dwds0j 7BTtaju8r08oo27KsnO3LUN2vwemHW4= X-MC-Unique: sGERBD_vN-CjFOH1uACnPw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 5/6] pcie: fast unplug when slot power is off Date: Mon, 11 Oct 2021 14:05:03 +0200 Message-Id: <20211011120504.254053-6-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954099191100002 Content-Type: text/plain; charset="utf-8" In case the slot is powered off (and the power indicator turned off too) we can unplug right away, without round-trip to the guest. Also clear pending attention button press, there is nothing to care about any more. Signed-off-by: Gerd Hoffmann --- hw/pci/pcie.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 70fc11ba4c7d..f3ac04399969 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -561,6 +561,16 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *h= otplug_dev, return; } =20 + if (((sltctl & PCI_EXP_SLTCTL_PIC) =3D=3D PCI_EXP_SLTCTL_PWR_IND_OFF) = && + ((sltctl & PCI_EXP_SLTCTL_PCC) =3D=3D PCI_EXP_SLTCTL_PWR_OFF)) { + /* slot is powered off -> unplug without round-trip to the guest */ + pcie_cap_slot_do_unplug(hotplug_pdev); + hotplug_event_notify(hotplug_pdev); + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, + PCI_EXP_SLTSTA_ABP); + return; + } + pcie_cap_slot_push_attention_button(hotplug_pdev); } =20 --=20 2.31.1 From nobody Thu May 16 14:13:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633954286862286.820766891876; Mon, 11 Oct 2021 05:11:26 -0700 (PDT) Received: from localhost ([::1]:39798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZu9N-0006QL-O4 for importer@patchew.org; Mon, 11 Oct 2021 08:11:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu4L-0006GA-E4 for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZu4J-0004VE-UL for qemu-devel@nongnu.org; Mon, 11 Oct 2021 08:06:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-cwPMBUGIOLqot81Nog823Q-1; Mon, 11 Oct 2021 08:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 777DB801A93; Mon, 11 Oct 2021 12:06:09 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7304960C4A; Mon, 11 Oct 2021 12:05:57 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id BF22518009EB; Mon, 11 Oct 2021 14:05:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633953971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T52qkV6p0EqIPaRnDHzBDcMR40tyCSd7kE1e9itdo+Y=; b=EVCP0Xll7F9wiVUIKn1odtigMzH66hb5ZNPecTprI8F4f4hx4tjWdu/arFI9LAVGtP/HYT a9R1U+EdDLYrMDYeeXFxnC9L+30bv+q/HStvUohifa9OY0c6AWvXGmeLcjbnuajbgvnVI+ oRRw0+gjfv7TVvWYZ32nDapWzJ94lnI= X-MC-Unique: cwPMBUGIOLqot81Nog823Q-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PATCH 6/6] pcie: expire pending delete Date: Mon, 11 Oct 2021 14:05:04 +0200 Message-Id: <20211011120504.254053-7-kraxel@redhat.com> In-Reply-To: <20211011120504.254053-1-kraxel@redhat.com> References: <20211011120504.254053-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.049, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633954287823100001 Content-Type: text/plain; charset="utf-8" Add an expire time for pending delete, once the time is over allow pressing the attention button again. This makes pcie hotplug behave more like acpi hotplug, where one can try sending an 'device_del' monitor command again in case the guest didn't respond to the first attempt. Signed-off-by: Gerd Hoffmann --- include/hw/qdev-core.h | 1 + hw/pci/pcie.c | 2 ++ softmmu/qdev-monitor.c | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 4ff19c714bd8..d082a9a00aca 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -180,6 +180,7 @@ struct DeviceState { char *canonical_path; bool realized; bool pending_deleted_event; + int64_t pending_deleted_expires_ms; QemuOpts *opts; int hotplugged; bool allow_unplug_during_migration; diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index f3ac04399969..477c8776aa27 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -549,6 +549,8 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *ho= tplug_dev, } =20 dev->pending_deleted_event =3D true; + dev->pending_deleted_expires_ms =3D + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 5000; /* 5 secs */ =20 /* In case user cancel the operation of multi-function hot-add, * remove the function that is unexposed to guest individually, diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 0705f008466d..5e7960c52a0a 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -910,7 +910,9 @@ void qmp_device_del(const char *id, Error **errp) { DeviceState *dev =3D find_device_state(id, errp); if (dev !=3D NULL) { - if (dev->pending_deleted_event) { + if (dev->pending_deleted_event && + (dev->pending_deleted_expires_ms =3D=3D 0 || + dev->pending_deleted_expires_ms > qemu_clock_get_ms(QEMU_CLOC= K_VIRTUAL))) { error_setg(errp, "Device %s is already in the " "process of unplug", id); return; --=20 2.31.1