From nobody Mon Feb 9 08:57:07 2026 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562082288; cv=none; d=zoho.com; s=zohoarc; b=kzC0N3bvyZkkRC+UIrwfk13GI41jJ6lN+BY1ZBiPx7lp/nb1vC9Fsegd/aITpe+epwq0OeEvZjQInc8OJq/nB5KwrTYzFelYBN918tc2lzNKoi70I1goPR+My4vwqnd9vWTlPjsVDUkA6HOaBvkKKSsANHf1te14XeBaG4YDLGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562082288; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=X7ooFy+OBDHlbNCEvnbtaNnFuzPrudJNtlxn5Edd3IE=; b=ixaMOHWX/2bGxmHwnZmEs4sPdktTMsSEcG2YTtb7eYhz1vPVXW9EJCc4iFOgFTNQGL8zF6YX5ftSyArMG0N1pUWOOgWQFPOpsQXd5MrEO6pUcpbp4niN6l9WvPEF8aL3mh+UFknN2LxMz6uBy/eBVnPlWMQ8wNtYhhMze2c/nmA= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562082288943498.7299744881758; Tue, 2 Jul 2019 08:44:48 -0700 (PDT) Received: from localhost ([::1]:54602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiKxc-00005m-0C for importer@patchew.org; Tue, 02 Jul 2019 11:44:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58360) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiKN0-0006E5-FT for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiKMv-0008Js-Gu for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:06:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37968) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hiKMv-0008JK-AJ for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:06:53 -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 mx1.redhat.com (Postfix) with ESMTPS id 94F7430842CE; Tue, 2 Jul 2019 15:06:47 +0000 (UTC) Received: from redhat.com (ovpn-124-209.rdu2.redhat.com [10.10.124.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 38EDA60C44; Tue, 2 Jul 2019 15:06:45 +0000 (UTC) Date: Tue, 2 Jul 2019 11:06:43 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20190702150606.24851-4-mst@redhat.com> References: <20190702150606.24851-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190702150606.24851-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 02 Jul 2019 15:06:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/22] pcie: work around for racy guest init 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: Peter Maydell , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During boot, linux guests tend to clear all bits in pcie slot status register which is used for hotplug. If they clear bits that weren't set this is racy and will lose events: not a big problem for manual hotplug on bare-metal, but a problem for us. For example, the following is broken ATM: /x86_64-softmmu/qemu-system-x86_64 -enable-kvm -S -machine q35 \ -device pcie-root-port,id=3Dpcie_root_port_0,slot=3D2,chassis=3D2,addr= =3D0x2,bus=3Dpcie.0 \ -device virtio-balloon-pci,id=3Dballoon,bus=3Dpcie_root_port_0 \ -monitor stdio disk.qcow2 (qemu)device_del balloon (qemu)cont Balloon isn't deleted as it should. As a work-around, detect this attempt to clear slot status and revert status to what it was before the write. Note: in theory this can be detected as a duplicate button press which cancels the previous press. Does not seem to happen in practice as guests seem to only have this bug during init. Note2: the right thing to do is probably to fix Linux to read status before clearing it, and act on the bits that are set. Signed-off-by: Michael S. Tsirkin Reviewed-by: Marcel Apfelbaum Reviewed-by: Igor Mammedov Tested-by: Igor Mammedov --- hw/pci/pcie.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index f8490a00de..c605d32dd4 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -610,6 +610,25 @@ void pcie_cap_slot_write_config(PCIDevice *dev, uint16= _t slt_ctl, uint16_t slt_s uint16_t sltsta =3D pci_get_word(exp_cap + PCI_EXP_SLTSTA); =20 if (ranges_overlap(addr, len, pos + PCI_EXP_SLTSTA, 2)) { + /* + * Guests tend to clears all bits during init. + * If they clear bits that weren't set this is racy and will lose = events: + * not a big problem for manual button presses, but a problem for = us. + * As a work-around, detect this and revert status to what it was + * before the write. + * + * Note: in theory this can be detected as a duplicate button press + * which cancels the previous press. Does not seem to happen in + * practice as guests seem to only have this bug during init. + */ +#define PCIE_SLOT_EVENTS (PCI_EXP_SLTSTA_ABP | PCI_EXP_SLTSTA_PFD | \ + PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_PDC | \ + PCI_EXP_SLTSTA_CC) + + if (val & ~slt_sta & PCIE_SLOT_EVENTS) { + sltsta =3D (sltsta & ~PCIE_SLOT_EVENTS) | (slt_sta & PCIE_SLOT= _EVENTS); + pci_set_word(exp_cap + PCI_EXP_SLTSTA, sltsta); + } hotplug_event_clear(dev); } =20 --=20 MST