From nobody Wed Oct 30 22:10:33 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAB60CD54AF for ; Tue, 19 Sep 2023 11:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231935AbjISLDO (ORCPT ); Tue, 19 Sep 2023 07:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231989AbjISLDJ (ORCPT ); Tue, 19 Sep 2023 07:03:09 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2086.outbound.protection.outlook.com [40.107.223.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81B3119D for ; Tue, 19 Sep 2023 04:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WPXeQU9wn0W0hqCAxiIV2q2kDZD/iazW6XnEbyGjc5P0fcoOuwUnnDdnRYct8Gpo5rfywQAPuixzisyM99SS/pehf0vRT05sjY9mmI4U/thkoSwT1rG8l+av7pblm3JsiE515e87e3qtfol/SuTsjdWxaJovGPYrHE9GbI+uNdkrIjDbjVlhMzJg9atBfRJUDIY2XCZh/vJO+mFCf6idULRn7yNb8Xci1sU01JxV2Pe1CUuBAzwPMggjOShy1ZFy12iwkTd3299WwyCPjPX3esC5W7QRSYomsODLjVQ1d/8g0ot5wBGpnaawvX1dXPzN066rT8K7/bPRRyhEiO9BdQ== 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=zTa6x8C4rAzvS0wAW9UyemxMoqk14yikg5bCtxfOXHw=; b=F0qsoj05S3FMAiSXYK7mSk56isSL+fdoJP7LzzSHgJ7ZHEWo2ffMn/VgYRKb6xH4TrymdHaZhq1ubBX46ot/4xQ/3Jxu88g2gv7WPeYEize7kFcxv89YO9XGK5Pv0GNUbLy047TZobyIzQkWPCliRU+2/H1E4r7J/EVHmo5dvM1NlZy7SVdVb0xiRvghQDQoeq8Ezn8VRiuY4dJO5ZBF/zNP5z5MrExhyIu726x5sm/s7YOqBsk4kWl5VFXjMVN2H+YJbhaY9OIDIyooyS+GfUAoIrHy51+pdK+9qkc/Urw/xsRH1A1PuA7fvgVDoesJPY1UKDiTLo9wXxw7QZ+Y5A== 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 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=zTa6x8C4rAzvS0wAW9UyemxMoqk14yikg5bCtxfOXHw=; b=vXrsnO1pQk0Uikzv0OaCmPn4I97BnKnyKVDh88nRq9cziPYiLePtyWCyY9+xP4ayxu69DmWulNam/6r0LQJ0N8ToMh2Ca1z36I2IZTtfHaLKkLB9IKPXoQXesak2Z5LlOWsqkmHy0kcRsZuv+cO40IEHI0MiT02NrctDvhh/GcI= Received: from MW4P220CA0014.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::19) by IA1PR12MB8192.namprd12.prod.outlook.com (2603:10b6:208:3f9::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Tue, 19 Sep 2023 11:02:54 +0000 Received: from CO1PEPF000044F6.namprd21.prod.outlook.com (2603:10b6:303:115:cafe::6a) by MW4P220CA0014.outlook.office365.com (2603:10b6:303:115::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27 via Frontend Transport; Tue, 19 Sep 2023 11:02:53 +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 CO1PEPF000044F6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.0 via Frontend Transport; Tue, 19 Sep 2023 11:02:53 +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.27; Tue, 19 Sep 2023 06:02:47 -0500 From: Jiqian Chen To: Gerd Hoffmann , Jason Wang , "Michael S . Tsirkin" , Xuan Zhuo , David Airlie , "Gurchetan Singh" , Chia-I Wu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Robert Beckett" , CC: , Stefano Stabellini , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Dr . David Alan Gilbert" , Alex Deucher , Christian Koenig , Stewart Hildebrand , Xenia Ragiadakou , Honglei Huang , Julia Zhang , Huang Rui , Jiqian Chen Subject: [QEMU PATCH v5 1/2] virtio-pci: Add freeze_mode case for virtio pci Date: Tue, 19 Sep 2023 19:02:24 +0800 Message-ID: <20230919110225.2282914-2-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919110225.2282914-1-Jiqian.Chen@amd.com> References: <20230919110225.2282914-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000044F6:EE_|IA1PR12MB8192:EE_ X-MS-Office365-Filtering-Correlation-Id: 583b4faf-442f-4f99-ad88-08dbb8fff8f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gr8OFxxFDbpPu0DBrcB6bGkstDJqbwAkFE5Sg2eb1/hYFyMmpDPhn72QtHwFzamysE+tA77iv0bI5PMjzBH0kFYQRWJw8sEVRvOP36vWhn1RwbGoCQw9U24ZLvIfxmF/RU96hcq+/8ReTsqwy/AszztgyEd75O7EyGQW2IRLi+rBlAijyOIrjAxZ6sQyKCVPB/2N2+PlKrXDaRXUa5allqvxOh4ijZjfDWm4l2RmCYEBU/M0wJfhXyMtU/JC7R+mmhEPYVvqigORE24e05MrncYYh2pyn7bMB1jcydwfa49OCC6w8JTEOQSTquafuXAOrv0vxTyFNxXpQNopYlykFaDG3IgMpTmKiK9kdVai6e58NOgRsmRBorQss7KEf1i0FRj8tBIeJF81NH2r323O2H6WYHdoyLwcLN/ckXK3jAkZa2EEiwFp2Cpmo+DvmNe+RDMS+Wz4a1CT83ZWudAF8NVJ42MaMj6mLR0JB87ChrqtMtreOiXSAqCCAZkl64GeA0zzGwIw73w+uZgrMZ2uTDlPAE+UuBSHddcdMI2Nwhp7dgJCkU8ro9FsIhuaZeePm3L5/dEeCKSBbh0smOcWZTt2NnjkL2c4PkWTYp4nv+HdKfDmVwEdvzWdEQcKC7JDsh2flKltV+S3SLY13MFu3yhfyfg6yefB+wdQ69/CC7j7NSuI8PxmxCwP99MfbOB+yy42zEXUDRsP8V16LQfnuZ3OqFe2643OTIAazSiy/SD9NgGDlx+wn9kv7UDaBR/Q+x6y3JlO8dWlLouKHVnzhOjh1pNCcKbFVZwES/JMlvA= 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)(4636009)(346002)(39860400002)(136003)(396003)(376002)(82310400011)(451199024)(186009)(1800799009)(36840700001)(40470700004)(46966006)(82740400003)(86362001)(40480700001)(40460700003)(81166007)(1076003)(921005)(356005)(16526019)(7696005)(54906003)(26005)(316002)(41300700001)(70586007)(8676002)(5660300002)(4326008)(70206006)(478600001)(110136005)(36860700001)(336012)(426003)(83380400001)(8936002)(47076005)(6666004)(2616005)(36756003)(7416002)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 11:02:53.4385 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 583b4faf-442f-4f99-ad88-08dbb8fff8f3 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: CO1PEPF000044F6.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8192 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When guest vm do S3, Qemu will reset and clear some things of virtio devices, but guest can't aware that, so that may cause some problems. For excample, Qemu calls virtio_reset->virtio_gpu_gl_reset, that will destroy render resources of virtio-gpu. As a result, after guest resume, the display can't come back and we only saw a black screen. Due to guest can't re-create all the resources, so we need to let Qemu not to destroy them when S3. For above purpose, this patch add a new parameter named freeze_mode to struct VirtIODevice, and when guest suspends, guest can write freeze_mode to be FREEZE_S3, so that virtio devices can change their reset behavior on Qemu side according to that mode. Signed-off-by: Jiqian Chen --- hw/virtio/virtio-pci.c | 5 +++++ hw/virtio/virtio.c | 1 + include/hw/virtio/virtio.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index edbc0daa18..7a3cca79b4 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1651,6 +1651,11 @@ static void virtio_pci_common_write(void *opaque, hw= addr addr, proxy->vqs[vdev->queue_sel].enabled =3D 0; } break; + case VIRTIO_PCI_COMMON_F_MODE: + virtio_pci_freeze_mode_t freeze_mode =3D (virtio_pci_freeze_mode_t= )val; + if ((1 << freeze_mode) & VIRTIO_PCI_FREEZE_MODE_MASK) + vdev->freeze_mode =3D freeze_mode; + break; default: break; } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 969c25f4cf..4278cedef4 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3201,6 +3201,7 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_= id, size_t config_size) vdev->vhost_started =3D false; vdev->device_id =3D device_id; vdev->status =3D 0; + vdev->freeze_mode =3D VIRTIO_PCI_FREEZE_MODE_UNFREEZE; qatomic_set(&vdev->isr, 0); vdev->queue_sel =3D 0; vdev->config_vector =3D VIRTIO_NO_VECTOR; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c8f72850bc..f8bfd9da28 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -21,6 +21,7 @@ #include "qemu/event_notifier.h" #include "standard-headers/linux/virtio_config.h" #include "standard-headers/linux/virtio_ring.h" +#include "standard-headers/linux/virtio_pci.h" #include "qom/object.h" =20 /* @@ -106,6 +107,7 @@ struct VirtIODevice DeviceState parent_obj; const char *name; uint8_t status; + virtio_pci_freeze_mode_t freeze_mode; uint8_t isr; uint16_t queue_sel; /** --=20 2.34.1 From nobody Wed Oct 30 22:10:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1695121432; cv=pass; d=zohomail.com; s=zohoarc; b=FuwfL9Pt6z9GE/wTjNg6/TYv536KHoFcc1QhctgWTLITdZOW5qd7jYM4udGOpq3hM8ADt/QB3TeUUSLOERzTjtzyt0MNWS7w+uSWK2qj8BcW8iIVSILQZ92kgvhLdwuwUTQHz0lTgqV2pXlLr7sDqhymC0Yei799HuAjf6KytKo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695121432; h=Content-Type:Content-Transfer-Encoding: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; bh=/zFFMq6/WNp+pmycz2wKVPOA9hZcBqrLaYWI6cq+BAc=; b=H+EpMUH5296SubiGgY5S3/3dPZLURECiIOBD2WT1OPGJSKj98f0r5AxN9z+IAshZ20C9ycjyuJQyR05jnGLx42bKda4/dzDwpsoKAwYTXKOg9bJUQfx3LFvd2ECeYB2Yphmfa8CNoHJF8lVMANy+QKpBzx90mzYNclElAF0guqw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1695121432855927.2191665628895; Tue, 19 Sep 2023 04:03:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiYW9-0002XK-7D; Tue, 19 Sep 2023 07:03:46 -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 1qiYVX-0002Hv-Mu for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:03:10 -0400 Received: from mail-bn1nam02on2062b.outbound.protection.outlook.com ([2a01:111:f400:7eb2::62b] helo=NAM02-BN1-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 1qiYVV-0001m6-SQ for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:03:07 -0400 Received: from MW4PR04CA0310.namprd04.prod.outlook.com (2603:10b6:303:82::15) by DM4PR12MB5232.namprd12.prod.outlook.com (2603:10b6:5:39c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28; Tue, 19 Sep 2023 11:02:59 +0000 Received: from CO1PEPF000044F9.namprd21.prod.outlook.com (2603:10b6:303:82:cafe::8f) by MW4PR04CA0310.outlook.office365.com (2603:10b6:303:82::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.28 via Frontend Transport; Tue, 19 Sep 2023 11:02:59 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F9.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.6838.0 via Frontend Transport; Tue, 19 Sep 2023 11:02:58 +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.27; Tue, 19 Sep 2023 06:02:52 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dI4fWYe6u+bC6UwMDX06BDTpX+7MJr7gcyNxyjF1/VtD8zuL9dFPN0qlPCGtisOM+u73v8lPuDjaYquCgjRucb0ecFpmikyOy4NAiWE9wOPnaeCJ4xm+J2OTSxFe/v/OjilhdDb5vw/ErDSfoQbfb73ewBssORVdE/VP/xbNtYCmYfiW3vk0LFKCBtZs2nbtbuk3hbOfdG+vl5Wng3mpjqVqr/9SDPfnPeL6gL04N3oHfQNjHUFaH5kp5Ua10DgLZyG/IlY1uKIZht8S245yASFMX5sQOjEgOUdOnhHGY6iR34o4V4CIcXRHEtRjDvQp97NgB/AGpLtnIueDaEUdbg== 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=/zFFMq6/WNp+pmycz2wKVPOA9hZcBqrLaYWI6cq+BAc=; b=SV0DUlAD6VwBFtsk90C7ZcDkMRcGUIuLiH5DEhjvAa5uD+6fZLRUSDtAfc5ZmxTwsjdTVFRM//XicpVqvYPrHZeAcmuy6aDbZsH+fngqs1FzjAU+8K4ygyKZ2j/Yoj6OIfWxNMKWMwm42HJhgXyn30Dbip6pKZvpzHtJfvAnkPRTyOQO6fHNUF7DG2SK+/LF8hjlpxoAsxhKS5rUA9/SpsreSmNH8tEngvMXqFZZcvViZIzOx1ey/KHXNmyuYExAU+C8GQmsf31YmBT3iuGGqh82PRbbBWy6i6OtYd64J0vvR2FgQFnHlY+qK8GUVCO8tmwbIE++KaRRe+Oou+Ufwg== 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 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=/zFFMq6/WNp+pmycz2wKVPOA9hZcBqrLaYWI6cq+BAc=; b=ZfpOIPUTiYYL7QopoPMN4WBHavM5dWJqP4lqPftAeU/lAdvLBQnNNdnrwwZk0hNlP1BN1YWEcNmaNzeWHJMN0gzCL0iSxd+9ny/He7NefqkP0aN/c6a5CnMaK2H3wUZ7NciXLCNvhRirc2o8BdwyS3/IEimlpy2UUg9lFBz4rn0= 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 (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 (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 From: Jiqian Chen To: Gerd Hoffmann , Jason Wang , "Michael S . Tsirkin" , Xuan Zhuo , David Airlie , "Gurchetan Singh" , Chia-I Wu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Robert Beckett" , CC: , Stefano Stabellini , Anthony PERARD , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Dr . David Alan Gilbert" , Alex Deucher , Christian Koenig , Stewart Hildebrand , Xenia Ragiadakou , Honglei Huang , Julia Zhang , Huang Rui , Jiqian Chen Subject: [QEMU PATCH v5 2/2] virtgpu: do not destroy resources when guest does S3 Date: Tue, 19 Sep 2023 19:02:25 +0800 Message-ID: <20230919110225.2282914-3-Jiqian.Chen@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230919110225.2282914-1-Jiqian.Chen@amd.com> References: <20230919110225.2282914-1-Jiqian.Chen@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000044F9:EE_|DM4PR12MB5232:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bfdcef5-8b68-416c-6c65-08dbb8fffc37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U+dswkq9hUd4Az1y8NQWLlzWdWyM+Ib9HYL9r5mzVai4vKUQuoDNXCEfTm/TgkNkIB7xR5GCou50Znlqud1uJskflEQEXbMHUMHjOKdYsKttP2yh+t3ObM23P/iJsMW48U8o5y1+iAYtG7fl8+G7koLsUeryBiQ526DoxO7aBPmBfoyvM63X06UIe+t7TmiDjG+JBNrRBsYatQioX9m6j3zL0hUKjP7kWy7kECXiHXu6m7fPUl1C4Xc34hMqCGNZmdJjETRwMGKqt4zQ+UDjbSC/ROVuaK/uLYlqWgZJL9nJyQ+icERbBnuIe5JQwTwjZEVHkuCPbg6kbTJDFV3EEm3IxAs4Ql32sH1uHp4GNK2ABSv0QZV2svLZVDyaQk0/3vwvPqmu9TGhnwW6UP1tfH99XCCNSW9wKkEpaNCbkbmPQTgZWG165K8TljG12+toQbzhgzHp1qcC6YrNI/7U9N1GJRLbiBZLGlg8U8NJrllLsTVqBoDRHT8UO98oocKyQxpD+kO8+GB0zW0ohOmCvbvJCrdAR7IyUZDSOWYnexukE1Q5LWyQup++UlQJKmjclZVf3o9g24CSU7a3LXCsA4vtKgCNaluqVJvuD6snSI6BWrfX9+9qFh4aCr+czEY3BH7mxqHVS3duII6p8th016wcenpxpvbsrQIEPTxvRpNhnVomWZNEYOYK8C5NYB8KULrOjNdCJ6668zwrZp1U7WHzEePnxoB5MswoGNinWBuk113ATHGpAOJE9s5CSVOrlg/cXrzpulMEWj6Iu9fBPT82/4sCxkBLiK692Q6wvgs= 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)(4636009)(376002)(346002)(136003)(39860400002)(396003)(186009)(1800799009)(451199024)(82310400011)(46966006)(36840700001)(40470700004)(6666004)(7696005)(40460700003)(86362001)(36756003)(921005)(356005)(82740400003)(81166007)(40480700001)(36860700001)(2616005)(16526019)(26005)(1076003)(47076005)(2906002)(426003)(336012)(83380400001)(478600001)(5660300002)(8676002)(4326008)(110136005)(7416002)(8936002)(41300700001)(70206006)(54906003)(70586007)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 11:02:58.9156 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bfdcef5-8b68-416c-6c65-08dbb8fffc37 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: CO1PEPF000044F9.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5232 Received-SPF: softfail client-ip=2a01:111:f400:7eb2::62b; envelope-from=Jiqian.Chen@amd.com; helo=NAM02-BN1-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 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1695121433760100001 Content-Type: text/plain; charset="utf-8" After guest VM resumed, you will get a black screen, and the display can't come back. It is because when guest did resuming, it called into qemu to call virtio_gpu_gl_reset. In that function, it destroyed resources created by command VIRTIO_GPU_CMD_RESOURCE_CREATE_*, which were used for display. As a result, guest's screen can't come back to the time when it was suspended. So when freeze_mode is set FREEZE_S3 by guest, we can know that guest is doing S3, and we can prevent Qemu to destroy the resources. Signed-off-by: Jiqian Chen --- hw/display/virtio-gpu-gl.c | 9 ++++++++- hw/display/virtio-gpu.c | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index e06be60dfb..2519dc12ff 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -100,7 +100,14 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev) */ if (gl->renderer_inited && !gl->renderer_reset) { virtio_gpu_virgl_reset_scanout(g); - gl->renderer_reset =3D true; + /* + * If guest is suspending, we shouldn't reset renderer, + * otherwise, the display can't come back to the time when + * it was suspended after guest resumed. + */ + if (vdev->freeze_mode !=3D VIRTIO_PCI_FREEZE_MODE_FREEZE_S3) { + gl->renderer_reset =3D true; + } } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 93857ad523..d363b886dc 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1412,11 +1412,19 @@ static void virtio_gpu_device_unrealize(DeviceState= *qdev) static void virtio_gpu_reset_bh(void *opaque) { VirtIOGPU *g =3D VIRTIO_GPU(opaque); + VirtIODevice *vdev =3D &g->parent_obj.parent_obj; struct virtio_gpu_simple_resource *res, *tmp; int i =3D 0; =20 - QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) { - virtio_gpu_resource_destroy(g, res); + /* + * If guest is suspending, we shouldn't destroy resources, + * otherwise, the display can't come back to the time when + * it was suspended after guest resumed. + */ + if (vdev->freeze_mode !=3D VIRTIO_PCI_FREEZE_MODE_FREEZE_S3) { + QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) { + virtio_gpu_resource_destroy(g, res); + } } =20 for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { --=20 2.34.1