From patchwork Thu Jun 6 10:22:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13688230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A37EBC25B75 for ; Thu, 6 Jun 2024 10:23:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFAH0-0005E8-NE; Thu, 06 Jun 2024 06:23:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFAGy-0005DW-P9 for qemu-devel@nongnu.org; Thu, 06 Jun 2024 06:23:08 -0400 Received: from mail-dm6nam11on20600.outbound.protection.outlook.com ([2a01:111:f403:2415::600] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFAGw-0007rj-MI for qemu-devel@nongnu.org; Thu, 06 Jun 2024 06:23:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BkRxcwhSbd6FnZentT5yur5WowKhLVxZruZRMIds9LDFFB1L2lNYrjqaGeWnp9Sp7si+2MVED93ScFRh3CHm53Sq1BZjaQvsv9MjR8EAHY/Ws25f8+7YMk8Z4W3bAxttR40vP3ObFNt6MtvCTaEMPDii2hl+OBkKmeWnemqD5Z9iR9ff9j2qfa0pmD/uNq+79Si1a5V44RYFUepp9ahrThReok862Ce+Dt9PlNoDfZJ9pqPU8ldgAFGJtFX78Vn/PriP4QQG2vkoy4jXR3lD1WgpSrYJ93zUpKeY8QlZQdbQQvUI75EEHnAxbEjeGhq+SkqjqJ8Brmubus5kfAp1mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=adzI6SwRWiCX4dOhcKq60SVFvOBfBB/gvXFt8Sn1tD0=; b=EdzEdDB5i67hT2HWldLeBbGTgwUFdvY3sQ37WVxZZzJVZy4QdC2raADdmUg0HWKZLWkVz5KG1xVFRtDaioPRIfSmBE5dYE6R5vborfrHr+IA294mLmd/NL73DuWqwG00huw362R/hZPndbeDpGJ07a2t7qajldMpwtpcAAcJU7vKmu85Rz4pJNfMVkwj27j0uRLzue3i4yOlERuY0DtwMwsaCkynQujtltXJMp+8pH0GAq/j+7bvF4Fw9Sb6QTP1wSnaViB9OiZCdgtJfMGrvYE8FIcdgbhIqQNYZ2JDedcwdm4q7NmSnX8JgH+kDhpgIDytCIsTca6ec71g5hl70w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=adzI6SwRWiCX4dOhcKq60SVFvOBfBB/gvXFt8Sn1tD0=; b=MBKOnR6OKRohjwgZA07+ke2O2tzZhy5jvaLFHMBzZ35BVJZKsE9jYoIB/dMXF+oIF8xLoxUiSQBZnx56Llj8zzdfNeRH5QN7BkFwLwFcboumDv5QJt2Lx/eb2XCM4har5Q9c0XU+8EmPatAexVLfshgL+3MCwkuczmxEfXNG6n4= Received: from PH7PR10CA0017.namprd10.prod.outlook.com (2603:10b6:510:23d::10) by BL3PR12MB6401.namprd12.prod.outlook.com (2603:10b6:208:3b1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 6 Jun 2024 10:22:55 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:510:23d:cafe::1c) by PH7PR10CA0017.outlook.office365.com (2603:10b6:510:23d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.20 via Frontend Transport; Thu, 6 Jun 2024 10:22:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 6 Jun 2024 10:22:55 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 6 Jun 2024 05:22:52 -0500 From: Jiqian Chen To: "Michael S . Tsirkin" , Eduardo Habkost , Marcel Apfelbaum CC: , Huang Rui , Jiqian Chen Subject: [PATCH v11 1/2] virtio-pci: only reset pm state during resetting Date: Thu, 6 Jun 2024 18:22:04 +0800 Message-ID: <20240606102205.114671-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240606102205.114671-1-Jiqian.Chen@amd.com> References: <20240606102205.114671-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD3:EE_|BL3PR12MB6401:EE_ X-MS-Office365-Filtering-Correlation-Id: e9bbaf9e-073b-4e2c-68d2-08dc8612a131 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|376005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: nm27N3WlJH53aFg+V83ZuyWthbqZZ5kFEgr3OM9BiNnPR6JBbtmmHRyVdehZiLVPeVADyfseeUmbvLXGpkl7XIn0yJTgmrZqbePwqr1XLystrPdf6L/+PBDsMH+Rqj3ibHIalzm+mJCJd+V2tTCFU3qii1MSe418DX5FOUWaSFRO/sQrC3S3nZMYonlmopUR52uQp9mJuJqCZ7Mq8s5TkKDRpPF/j7My0AC0Do8yBZxOC4+BDMJBD9vFVx5XdbizTfB6Wp55MiaEdGc5f7KlYIpi0x2xMDMOYvm0MaIzPQ9+xgLNpbM0/mvc6x++/2vUpmBBrLunCtpXmlcXOCGEi28BNwCG6AHMrt78hnYYPVltOhrt2bnYGksBTythe1tI6U3mVYutc8j7iec4IH5VLisG+zEIUXwUijIt4rqk/LRO08cg1vjOdYLSh60geNq76fWFcZ8xP5u0F7ox1xDkpVJaub7ruuVP22NQ6JJqHwCTTzOazoi76+1/msS9TLcBq+M/cY6Eh0g9dxVdn8pYblrcxk3w+yM4t/XaVk79l5Bzanu/phdGcnu9FN5xZYcmhoK7VTS/JzkFdCbGLD93VJbwqPEHl9XPcC5XdwdvhqXWax78N27AHkcx2eImsEnlaG5aVu6BC22VYPU2zPgWecbmeRf0xeATW+IA+pQzxdYGwoWzICqXKi/DVRy19jT9LcvCzIcoaOZZkwRV6/LGUEF9GtLAOrjdBSUPwDSMHByQSfTzxS85njoN/9NooXYN+OlkJNaFKW2dzX9Wz7ncmrK2YcXKEPpqvtZ5ZDMSeCAjK0yh/nO5NqAi/tGI/AFza+a8wzF4gW7bbX45unpNB85o2EZZu8Uxsys7pIwkeM/udB/a9wFCga12Bx3kyv7uMgdhORBw2ny1FOdvy25knyOgPBWE+Phm6XUzthp1vZdFtoL1ZCEPdv43sdXZbMuLKGEDoBIeHaY9bgUT0tZzv4aKPwt3P+xpXKw83AkyVCbmbh5FfEucqljPGd1waI2f00Ef4ipC7JarARGxawjT/EEuq1uNAKjvs2MamYr01SMxzbDI+9YxPvpOf5Fu8YbnHEYbOZ8XbjGbsNqqkSrSqvXOCQ08C+RORHM3N4+N5gXGev3yP3QqFtocbESQQng08z5M09Rjge9ZWDiFophxOc0yB+pFD6L2bVBqnjt8QhPPqYjdu0e1dg3YtzbTnZeRAydIn95svAHLYjy03JoVd1fV3TeXpoBcHWnz/dI8ugSAffAU5SuuRQ8oYO2YbE7oTZ17jNzqvrDHB1t8fvhZi5qpFnsBh9f9OXznDrAZBxP164X52ZfPURxLIKlxU30ljmLevrlWpfRv0dm1gq7VX3alOcAdoRSn9Cb6NT4H1u88IhXcQ1MxQ0UJ4C61SEJsdop0g3JAVKqJWn/siVanhA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(376005)(1800799015)(36860700004)(82310400017); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2024 10:22:55.0420 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9bbaf9e-073b-4e2c-68d2-08dc8612a131 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6401 Received-SPF: permerror client-ip=2a01:111:f403:2415::600; envelope-from=Jiqian.Chen@amd.com; helo=NAM11-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Fix bug imported by 27ce0f3afc9dd ("fix Power Management Control Register for PCI Express virtio devices" After this change, observe that QEMU may erroneously clear the power status of the device, or may erroneously clear non writable registers, such as NO_SOFT_RESET, etc. Only state of PM_CTRL is writable. Only when flag VIRTIO_PCI_FLAG_INIT_PM is set, need to reset state. Fixes: 27ce0f3afc9dd ("fix Power Management Control Register for PCI Express virtio devices" Signed-off-by: Jiqian Chen --- hw/virtio/virtio-pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b1d02f4b3de0..1b63bcb3f15c 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2300,10 +2300,16 @@ static void virtio_pci_bus_reset_hold(Object *obj, ResetType type) virtio_pci_reset(qdev); if (pci_is_express(dev)) { + VirtIOPCIProxy *proxy = VIRTIO_PCI(dev); + pcie_cap_deverr_reset(dev); pcie_cap_lnkctl_reset(dev); - pci_set_word(dev->config + dev->exp.pm_cap + PCI_PM_CTRL, 0); + if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) { + pci_word_test_and_clear_mask( + dev->config + dev->exp.pm_cap + PCI_PM_CTRL, + PCI_PM_CTRL_STATE_MASK); + } } } From patchwork Thu Jun 6 10:22:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13688265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE645C25B75 for ; Thu, 6 Jun 2024 10:28:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFALo-0007OI-6A; Thu, 06 Jun 2024 06:28:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFALm-0007Lp-4g for qemu-devel@nongnu.org; Thu, 06 Jun 2024 06:28:06 -0400 Received: from mail-bn7nam10on2044.outbound.protection.outlook.com ([40.107.92.44] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFALj-0000WU-LH for qemu-devel@nongnu.org; Thu, 06 Jun 2024 06:28:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m4VpXeZf7ZfcQuFYK2fSQb1cdAhFWttUwNf57vtEdW8K+u1jbb+mjYYFiQ98Y3EJBbgnx4cXUQSDwOgbOmMJuE338nyu4/55GeLMlC/j6oDIFuVDL3cknAhiijYKHw/30xeyeNnEZbvpng5kN+weDtDtPo+QReexRwfCk8kEopEd7SrBS2Jtva5wEAjTjTQpSAzBrzzYDWro4KaAkIQpj3kTYcRgFnNoPTQQaMQ/bQLndmx/6UjdkbxhjWUOd1PSz55aRlonawAVIQGfPHAtL9hFQ3xgOFfiKiFYyiHPDw10HDFkvDqgqCLylmae5KTRoxazMPInS0lZpFb7aYnSJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yUGbHRjWycdkLV/D8WwsPbHacKHp3+1FIaxr7WW2hD0=; b=c1j+7XI4G4WwkWy2/7xo+jr8t2z2kgPxvKoTrm7+JNoitk5e+YcbafN2lVWBQVOVWKbp7PMJnAwQ07AvhoAQOs3C0W4hQ4way1D2In8LxysfG5jv4Z7jT03pbLf26qPRAGmxCmOEqq+JMAWpFdmaNr2Y6EWl2bovDig6lBYE2Bvr0n+7vJGOypJix8cI+G3yxXD9IRaNSPwaVq3tyH5pleVnpjdHo3tsZ5ez4Azs5aivJeCZHZ/dtGiAp/bKd1uRtXDBZF1IyIbSNvgYGH5jq3fvM4w6h9Pdls0i1L+Y8fDi86Vgj3UYPjghwEWYD/5AHRNF7gnRnlCZlQ2rea4Zyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yUGbHRjWycdkLV/D8WwsPbHacKHp3+1FIaxr7WW2hD0=; b=UHVVL8t8kAq7y97+SgymjKeyqcAxEKLK8pViYhuIZ5Ws2Wq1t9UXlnZx9szmzKSxyhX7Cb3/izYNXspOzxhf2ay71bkNDHxl32HL6mNft8HKhUfNKs0PjE6KS4YEwtZwmPNZ8EVuqKZL3yVlY2ntj++mRPuSF2ctHfEtJGkk1i0= Received: from PH7PR10CA0013.namprd10.prod.outlook.com (2603:10b6:510:23d::9) by SJ1PR12MB6193.namprd12.prod.outlook.com (2603:10b6:a03:459::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Thu, 6 Jun 2024 10:22:57 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:510:23d:cafe::55) by PH7PR10CA0013.outlook.office365.com (2603:10b6:510:23d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.19 via Frontend Transport; Thu, 6 Jun 2024 10:22:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Thu, 6 Jun 2024 10:22:56 +0000 Received: from cjq-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 6 Jun 2024 05:22:54 -0500 From: Jiqian Chen To: "Michael S . Tsirkin" , Eduardo Habkost , Marcel Apfelbaum CC: , Huang Rui , Jiqian Chen Subject: [PATCH v11 2/2] virtio-pci: implement No_Soft_Reset bit Date: Thu, 6 Jun 2024 18:22:05 +0800 Message-ID: <20240606102205.114671-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240606102205.114671-1-Jiqian.Chen@amd.com> References: <20240606102205.114671-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD3:EE_|SJ1PR12MB6193:EE_ X-MS-Office365-Filtering-Correlation-Id: 58640988-28e7-4e75-be13-08dc8612a24a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|36860700004|376005|82310400017; X-Microsoft-Antispam-Message-Info: R06OZc/uoZOGvLj8SdAATE3LbfGbkhWyq/Bp7OH6pNmgGuchhfhIn4cegptJTSiE2So1uAHeBHopfvwnnufsU8BPJiFNy2nFEWcDL/wpqZvEbHal6m4ecrkmMtQmglhcC0TJS331LzMkfPNuOA4vlKVUtYUCmWo37bVKQc2wv2rJnnMl15pVg1Z6yx4W2Pauhf+HZugxOlNUQ774suJa0rcRi7Ux23XSjaS2Mudyc09KXvQ4VxM0+QTOXM3PLutiUnnWMyryOjU7V904E6jF8duNqX+LJJMyr4yW+PzfNmYvFod7oc87iAFFABzcs5C+OYva1T1y0lNrAYBsoDPr3HM1D/12RfOiOL6FzYhaRPxZaJkpxRPEUMxrM7YARABDDHnesVEp0VeJ90cAqMe63dibjai0HDhJjCVauKDe0YbqObgci/OhPqJWv8RUMwBGyi57PciE8M1ZNP84gOV1kfApsiRRXaX5jjzIpqsEGFsVlRCG62YgDRyjkf8rwHQgvdXP9+lC8YbOHPGNaAp14TUQfWZv2ECqXnTMI77pEqPZ06jH7u5ACMqEpxDYgh3ffKtrhLnmV9AOq+xJzp3A3Vf3KZ3pGAlXXdF27ScDa00k/q7XlSb88zXDm3+ls+RK+H2dj/eLWKf+vSsqw4dOTvYKard95O4zvTl5ns9Pwqi7dN8iH/N2D/1g7m91o0lHPhkJEX5vUfndEnkHQHLbQt+WVlSfqSBFbgQwO3NYBWxzDOdJEnVRcwo/stcKhsWgzzMaoSru88veB6Ybafc5vPbHl6oMAuf7AcUfgSZGzP2rQgnL8o2EjIabkooqShEWgfBblEP0TmWHrGZMJwoYfGs4+U48K7eIIsSzXV6jKtIuQCmAYfp1yvnTAFxJ39pT2+/QEjXVULkEWKa2VLmdoLErGAGcwuWfXFAV0NSJvh4OFtVPXfOW0ic+OJVu/8FUL4GskqtfxeEAYK3bKx0Whm/86cdzYCZhVlrsjrgfbPSQG/92cdj9LpWdHLsdPqzapNBQAzoIOkZveDMG1GFyKyEf9MpivDO8WcgKtsmeIYto6vFpJRP6IyMrxbqHWjW0KHQLmC9ybpyyXnvEvCVeKkEVQC60s7NgHKoturh4ON/t50PLVhC4Cbql6OcvwBYEQBYhQAf/dXaZ9c+RfUY5tLzjPZrJmiOQENYn58/LkDdeRp/JvVfZu/hzngtyZetvMceDp9L7e0p3v3dsReYi3Xv2otmW/kjayixkvPJD7sEFwUz1LbnN2q8fW94fvDTQva/iNACv3ylpsiZS6UkjhJRP+mkDvLIGrSMujIkDE+BlxBCNW6O+Y4n70VZOB5D6d1u4kdnd/6AbN90i3sgf6TjUByQdus4G8Gb2RDcy+IrgziwtCVFDiIhbZ1AAwXRqr6idU7T5ARE6gMhI9SrWMg== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(1800799015)(36860700004)(376005)(82310400017); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2024 10:22:56.8858 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58640988-28e7-4e75-be13-08dc8612a24a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6193 Received-SPF: permerror client-ip=40.107.92.44; envelope-from=Jiqian.Chen@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In current code, when guest does S3, virtio-gpu are reset due to the bit No_Soft_Reset is not set. After resetting, the display resources of virtio-gpu are destroyed, then the display can't come back and only show blank after resuming. Implement No_Soft_Reset bit of PCI_PM_CTRL register, then guest can check this bit, if this bit is set, the devices resetting will not be done, and then the display can work after resuming. No_Soft_Reset bit is implemented for all virtio devices, and was tested only on virtio-gpu device. Set it false by default for safety. Signed-off-by: Jiqian Chen --- hw/core/machine.c | 1 + hw/virtio/virtio-pci.c | 29 +++++++++++++++++++++++++++++ include/hw/virtio/virtio-pci.h | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 77a356f232f5..b6af94edcd0a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -36,6 +36,7 @@ GlobalProperty hw_compat_9_0[] = { {"arm-cpu", "backcompat-cntfrq", "true" }, {"vfio-pci", "skip-vsc-check", "false" }, + { "virtio-pci", "x-pcie-pm-no-soft-reset", "off" }, }; const size_t hw_compat_9_0_len = G_N_ELEMENTS(hw_compat_9_0); diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1b63bcb3f15c..c881f853253c 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2230,6 +2230,11 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) pcie_cap_lnkctl_init(pci_dev); } + if (proxy->flags & VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET) { + pci_set_word(pci_dev->config + pos + PCI_PM_CTRL, + PCI_PM_CTRL_NO_SOFT_RESET); + } + if (proxy->flags & VIRTIO_PCI_FLAG_INIT_PM) { /* Init Power Management Control Register */ pci_set_word(pci_dev->wmask + pos + PCI_PM_CTRL, @@ -2292,11 +2297,33 @@ static void virtio_pci_reset(DeviceState *qdev) } } +static bool virtio_pci_no_soft_reset(PCIDevice *dev) +{ + uint16_t pmcsr; + + if (!pci_is_express(dev) || !dev->exp.pm_cap) { + return false; + } + + pmcsr = pci_get_word(dev->config + dev->exp.pm_cap + PCI_PM_CTRL); + + /* + * When No_Soft_Reset bit is set and the device + * is in D3hot state, don't reset device + */ + return (pmcsr & PCI_PM_CTRL_NO_SOFT_RESET) && + (pmcsr & PCI_PM_CTRL_STATE_MASK) == 3; +} + static void virtio_pci_bus_reset_hold(Object *obj, ResetType type) { PCIDevice *dev = PCI_DEVICE(obj); DeviceState *qdev = DEVICE(obj); + if (virtio_pci_no_soft_reset(dev)) { + return; + } + virtio_pci_reset(qdev); if (pci_is_express(dev)) { @@ -2336,6 +2363,8 @@ static Property virtio_pci_properties[] = { VIRTIO_PCI_FLAG_INIT_LNKCTL_BIT, true), DEFINE_PROP_BIT("x-pcie-pm-init", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_INIT_PM_BIT, true), + DEFINE_PROP_BIT("x-pcie-pm-no-soft-reset", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET_BIT, false), DEFINE_PROP_BIT("x-pcie-flr-init", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_INIT_FLR_BIT, true), DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags, diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index 59d88018c16a..9e67ba38c748 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -43,6 +43,7 @@ enum { VIRTIO_PCI_FLAG_INIT_FLR_BIT, VIRTIO_PCI_FLAG_AER_BIT, VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT, + VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET_BIT, }; /* Need to activate work-arounds for buggy guests at vmstate load. */ @@ -79,6 +80,10 @@ enum { /* Init Power Management */ #define VIRTIO_PCI_FLAG_INIT_PM (1 << VIRTIO_PCI_FLAG_INIT_PM_BIT) +/* Init The No_Soft_Reset bit of Power Management */ +#define VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET \ + (1 << VIRTIO_PCI_FLAG_PM_NO_SOFT_RESET_BIT) + /* Init Function Level Reset capability */ #define VIRTIO_PCI_FLAG_INIT_FLR (1 << VIRTIO_PCI_FLAG_INIT_FLR_BIT)