From patchwork Tue Sep 19 11:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Jiqian" X-Patchwork-Id: 13391215 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 05094CD54AF for ; Tue, 19 Sep 2023 11:04:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiYWL-0002hz-Mr; Tue, 19 Sep 2023 07:03:58 -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 1qiYVY-0002KC-1Q for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:03:11 -0400 Received: from mail-bn7nam10on20624.outbound.protection.outlook.com ([2a01:111:f400:7e8a::624] 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 1qiYVO-0001ix-Sz for qemu-devel@nongnu.org; Tue, 19 Sep 2023 07:03:07 -0400 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_Lureau?= , "Robert Beckett" , CC: , Stefano Stabellini , Anthony PERARD , =?utf-8?q?Roger_Pau_Monn=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 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 Received-SPF: softfail client-ip=2a01:111:f400:7e8a::624; 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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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, hwaddr addr, proxy->vqs[vdev->queue_sel].enabled = 0; } break; + case VIRTIO_PCI_COMMON_F_MODE: + virtio_pci_freeze_mode_t freeze_mode = (virtio_pci_freeze_mode_t)val; + if ((1 << freeze_mode) & VIRTIO_PCI_FREEZE_MODE_MASK) + vdev->freeze_mode = 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 = false; vdev->device_id = device_id; vdev->status = 0; + vdev->freeze_mode = VIRTIO_PCI_FREEZE_MODE_UNFREEZE; qatomic_set(&vdev->isr, 0); vdev->queue_sel = 0; vdev->config_vector = 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" /* @@ -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; /**