From patchwork Thu Oct 5 18:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410586 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 59F3EE92725 for ; Thu, 5 Oct 2023 18:17:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613093.953379 (Exim 4.92) (envelope-from ) id 1qoSuQ-0004mo-3c; Thu, 05 Oct 2023 18:17:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613093.953379; Thu, 05 Oct 2023 18:17:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuP-0004mJ-VW; Thu, 05 Oct 2023 18:17:13 +0000 Received: by outflank-mailman (input) for mailman id 613093; Thu, 05 Oct 2023 18:17:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuO-0004jk-4r for xen-devel@lists.xenproject.org; Thu, 05 Oct 2023 18:17:12 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20609.outbound.protection.outlook.com [2a01:111:f400:7eaa::609]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 640787e4-63ab-11ee-98d3-6d05b1d4d9a1; Thu, 05 Oct 2023 20:17:09 +0200 (CEST) Received: from BL1PR13CA0269.namprd13.prod.outlook.com (2603:10b6:208:2ba::34) by CH0PR12MB5266.namprd12.prod.outlook.com (2603:10b6:610:d1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.37; Thu, 5 Oct 2023 18:17:01 +0000 Received: from BL6PEPF0001AB4A.namprd04.prod.outlook.com (2603:10b6:208:2ba:cafe::ea) by BL1PR13CA0269.outlook.office365.com (2603:10b6:208:2ba::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.25 via Frontend Transport; Thu, 5 Oct 2023 18:17:01 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB4A.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 5 Oct 2023 18:17:01 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 13:17:01 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 11:16:55 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 5 Oct 2023 13:16:54 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 640787e4-63ab-11ee-98d3-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gDKRGH+EJZY7bPcyD2/FmFYx5xVAT0MbSNddyIvGQIniGlN40ohAvEup8QaDjivvJp508mqlw8e4UD108M1iNQ4Zh2B1HKnrYA+omZDFG5JaPWbWogLUP2Juudc0lTPr3WEZsV2rYF8R58833VMu2pmd2WhUnOdGaBHrRoIpSUynHhEziEEacP3XaT0x4bX9NJvbkSGhwF6MhwVouhtW3+mMGLiO3zbqRQKhYvQCol4ccdlMR1G2WaEoVg2vf4tVD8Ei4qkpsw+hJvWl8dZ+nRkGbU6n6uM3RpDhyiK9xUYongblDUE6c6acyxOF827IE8VWchYV6qy4mrk+UaWdAg== 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=EqJO5eINxVHCO0CwH0LZUqYjnBPafl1pauyRsQ+lAX4=; b=JcMDSmld7eKl/ofCPEqiXrY661cj9ArZbAI5fXJEpAmdBsN88kh7cFb5I4ui6PvM9c8YrL0mCyWopu5XR6u2S4ffu6LWHMYeG8W4lsccBepUeZeDb12mLV/2AKXq7ZhmxUKxApn5/yRCogI7xiCXLEzOtUdwMj8u5sLSaw6C8NGQHGl+BJRPrpiXE0aIcE67pGYX0hki4JObKQPPsvCaNvYwnt5S4Q1l5j7TFu78vJwXzSNpzFx8q2n75pct+LfJHrwoyn1kCmn+Hy6GL8m2/yNhfQ+9TqPl/4cv6/5i3FC3NOzpcIgfzaFl+AVkdIFJAn989TYXBxxETfrmAFC9Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org 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=EqJO5eINxVHCO0CwH0LZUqYjnBPafl1pauyRsQ+lAX4=; b=IAPWFLXHwOEMGxt9LDogPf5ldiqg9dPrJtwPhEJzfsjUF7Kdg458mki/bsa9y+UK7uiXKg3/t5gaYM8+xJTJCGPlvGo6kSMjMR3ZfnCFkrqucu6fHT12qGJ1MZg+q8gjZITgJlPNLOQHeH6sNOQdtGSiBCwOAMZhxOPCLDRUzGg= 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=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Juergen Gross , Vikram Garhwal , Anthony Perard , "Paul Durrant" , "Michael S. Tsirkin" , "Marcel Apfelbaum" , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "open list:X86 Xen CPUs" Subject: [QEMU][PATCH v1 1/7] xen: when unplugging emulated devices skip virtio devices Date: Thu, 5 Oct 2023 11:16:23 -0700 Message-ID: <20231005181629.4046-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231005181629.4046-1-vikram.garhwal@amd.com> References: <20231005181629.4046-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4A:EE_|CH0PR12MB5266:EE_ X-MS-Office365-Filtering-Correlation-Id: e88332cb-0256-4a72-3e1e-08dbc5cf4553 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E8bG/LV3yaSki3lq4iQpfPITD+pa4vdTBeWPzRR49oxoU3yBj1JGmeq2kyfuf+0/YX7gNkQeiuvsxr2E+08oV1b8C4cImrXnwb3kQ6JvRZEAkfpephEVN78NDwd9pis7EeUGf2vaC83XOwJn3oa+shHdorfWxPom9vm+IW/5sJYNkvBq5TgtlxFCd7gOIjyoxdVORNHGZwCgASudhNIqDCbedcXxohB1CtkT1O+E/uUBr1QhUkXlTkeneogxs9n15gBn0p91+QCIKDEpEhhbj4lPhEtRTumxJcXdYyJuRGgRmPwT9CQsN9jeVYNN0oRGO8DLs8NhltS7R6Ui7gt6DDwEMCvkHwI1RvBFwUo6gtUJx0U2/w1YjxRzvezTHo64WU7FF3H3Ilquwcc6biofUxXrySiRijSZDFRUU3oy/HZfJtyzOLaYJ5XDEmnah3A41PjRyE1vcFv2TLw//FBhVXkJ+payJdZGo/83Q3yjN2Yn9q28F8z+164btl5MBE2npgiVdfPgRplhx4i7C1aUqUYgooBWQcIbzL8kntv8Z0UgsZvKeyS+ZTRsEkB/vcSYos+HBked4WVIjk/rvRHfVBpNsWh4TCy7t3/u7UzudOHNnEM/rFYv+pspjnlqeeWuCV28mZQFI48uPotixXUPIklzMj0GJaO3c7uUkQymZlaNdZEyUr0DDuVEaqiIBQxn/5Hp6oCJKxkqvgodfunrOVIQsqaEzw9eNsn8atNX4LMJ1QXWw3UTDUWnCvhwDqMESCUsMA2Kspe7ID1A5tG/nQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(39860400002)(346002)(396003)(230922051799003)(82310400011)(1800799009)(451199024)(64100799003)(186009)(40470700004)(36840700001)(46966006)(7416002)(44832011)(5660300002)(8676002)(2906002)(4326008)(8936002)(41300700001)(70206006)(70586007)(316002)(6916009)(40460700003)(54906003)(36860700001)(40480700001)(26005)(336012)(426003)(36756003)(6666004)(1076003)(2616005)(86362001)(356005)(81166007)(82740400003)(83380400001)(47076005)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:01.4573 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e88332cb-0256-4a72-3e1e-08dbc5cf4553 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5266 From: Juergen Gross Virtio devices should never be unplugged at boot time, as they are similar to pci passthrough devices. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal --- hw/i386/xen/xen_platform.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 17457ff3de..3560eaf8c8 100644 --- a/hw/i386/xen/xen_platform.c +++ b/hw/i386/xen/xen_platform.c @@ -28,6 +28,7 @@ #include "hw/ide/pci.h" #include "hw/pci/pci.h" #include "migration/vmstate.h" +#include "hw/virtio/virtio-bus.h" #include "net/net.h" #include "trace.h" #include "sysemu/xen.h" @@ -132,7 +133,8 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) /* We have to ignore passthrough devices */ if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_NETWORK_ETHERNET - && !pci_device_is_passthrough(d)) { + && !pci_device_is_passthrough(d) + && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) { object_unparent(OBJECT(d)); } } @@ -208,6 +210,10 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque) /* We have to ignore passthrough devices */ if (pci_device_is_passthrough(d)) return; + /* Ignore virtio devices */ + if (qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) { + return; + } switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) { case PCI_CLASS_STORAGE_IDE: From patchwork Thu Oct 5 18:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410589 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 DE373E92725 for ; Thu, 5 Oct 2023 18:17:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613092.953374 (Exim 4.92) (envelope-from ) id 1qoSuP-0004k2-Rx; Thu, 05 Oct 2023 18:17:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613092.953374; Thu, 05 Oct 2023 18:17:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuP-0004jv-O4; Thu, 05 Oct 2023 18:17:13 +0000 Received: by outflank-mailman (input) for mailman id 613092; Thu, 05 Oct 2023 18:17:11 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuN-0004jk-KY for xen-devel@lists.xenproject.org; Thu, 05 Oct 2023 18:17:11 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20602.outbound.protection.outlook.com [2a01:111:f400:7e8a::602]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 65402e04-63ab-11ee-98d3-6d05b1d4d9a1; Thu, 05 Oct 2023 20:17:09 +0200 (CEST) Received: from MN2PR06CA0022.namprd06.prod.outlook.com (2603:10b6:208:23d::27) by DM6PR12MB4123.namprd12.prod.outlook.com (2603:10b6:5:21f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.29; Thu, 5 Oct 2023 18:17:05 +0000 Received: from BL6PEPF0001AB4F.namprd04.prod.outlook.com (2603:10b6:208:23d:cafe::4b) by MN2PR06CA0022.outlook.office365.com (2603:10b6:208:23d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33 via Frontend Transport; Thu, 5 Oct 2023 18:17:05 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB4F.mail.protection.outlook.com (10.167.242.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 5 Oct 2023 18:17:05 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 13:17:04 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 13:17:04 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 5 Oct 2023 13:17:03 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 65402e04-63ab-11ee-98d3-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EuUlFVxVhzxoLqFVFIqGK4wCc1UuWG4jN/R684+bClcCwhqLpq//KeJx5JROGKAHDSckIDxZZh0hEIK+mgT5yvKnDqc5Woa8omX7Y/gX7F+ICrBvshJ52Xh/oJAHGnaKkx8wJo2eaF979dQjtMxr1diSjGu27GoKPWgJaWKWdzHsER+vBX0k4ypbRkw7qAn8/K/QBHp1Kbb1MJAUjwIJOXd5JK+k9bpEsr840oixLaMBPpdX5vB7IVwZ4KY3IXT3e0ZmY6w4y54IZXM34dc7uc14tE0IrEWaKVcJJwyh1nVM8ku1Yr4IkYMuYaObWdABAkr7KwWhCGguKoO0Okm/Mw== 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=8oqi3a0IooPX4pzHpvJYv6+eY6o0O3Q2hpb0iqszOV0=; b=GC5YTPrq0ciUDJlcHBERhJBt8roP4NpmNOqdBWWQb1TZhVZZy90xrh2v4su8Wr3YCiaU8Yfz4umx93AvC3VAJ2c0E3vypDGwLKJQ/eBT6r2qGOtcK3RROwKXDqpf5r7vAAIoyLNpDP3N4clC5D43qxSBTJuQhr6aBER2JHQPWX+RfL20UU44vp9CSHeyX9VmQnD0/LPh7Vc5zF2WrrWTzcnRNayurVd2pCrvjEAT5Rt8jn5eXTRGAFCTpWpvFTte9ZNFCZ5FFgy5ucNR7LhkvJF3I5PsptbmEQro2IT/dvCz08wImOun9rzr0Y5NzMmuzuA6PO05x8RALzgoppkwdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org 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=8oqi3a0IooPX4pzHpvJYv6+eY6o0O3Q2hpb0iqszOV0=; b=fva/QJ+j5EN0FncYL29OFhxoCQw/At32xz9UzVQP+zd7BXrIUSfYLYAiQoMwfZWaAOvHvKG+qULVUj+1hW1yxDH3PdMthJgp6C24cdWXY2rmD8i+RZ9/zs5jX2uwPqei0z7xn2uS96Yddo0Cjn0V0TeUUis9KPYAnyV7QoltpgY= 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=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Juergen Gross , Vikram Garhwal , Anthony Perard , "Paul Durrant" , "Michael S. Tsirkin" , "Marcel Apfelbaum" , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "open list:X86 Xen CPUs" Subject: [QEMU][PATCH v1 2/7] xen: add pseudo RAM region for grant mappings Date: Thu, 5 Oct 2023 11:16:24 -0700 Message-ID: <20231005181629.4046-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231005181629.4046-1-vikram.garhwal@amd.com> References: <20231005181629.4046-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4F:EE_|DM6PR12MB4123:EE_ X-MS-Office365-Filtering-Correlation-Id: c13242fa-ee1e-4ee0-3643-08dbc5cf478b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3wZ2BXBgho+mMEzE0AGW5OrYHztNM8hM4p2d99E/QdEShzgFo8OLnQR9SjPSH7pXbqUDgHYYP2CwfEsg/WtC31VvRmTQa2yTYKJcdsGOKHzRe23TYCYsNAA9IM/sHfpLGslJYSioGQ6qENtAndKkuRbLCcFLoE6IlSsaF15D2y2zTc2edFxulH185qck7wmPqCKbfWWcjPEfgYLkNhgU2OM4uc1q71rCWW8OzmkFs3K2JkZ09nocW73Qk8JyVSrLHTgpP7GPjenp8c2gKYFQwH0XIfJpueXtYfoAjB1bvyPvLozQ253O6DGTqY7v6Ii+3ntsthh3XE+Pfermo1KSwInpyDU1FVr6BXBlQAgzU/hHkN5uOS32+2oU8tfkJzrSVtW/DueHOMeNMmHqh3rPDlDoqmuzfB1NBBWmCWU7+Jq06wgxaNav1fbSl8YY6D6S65aJIXJ2ciMe/ULIb2+4EnxOcif9TldEdmTwYdz8/pDQuzvvRAXc1O8JD7dJLZNQu46by1YzZtjy8E6aD47vPnI+rtBI66LFwssbKgsbuQwLBIdL37mCOKn1ZZ9Wv49PKyPLtatEvHqrNbvvnj7l2LrLi6w+Aoaiv9JkKusdDdmMpaoPcepeXA1EZiNEY2ITBoG6t3KdUOvKRHraboTw6IW4nRabnUXJdKIknoU3H1QY3qdaUtwlthsXBGbvsi0Ywg9fdMpgFaKlezs3QOngsROQshOdJtPqKrcFnujTNh7A+rCEAzxeyNU2b8HHq0Q+CvIowbgtlCDXVvn+XsomGQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(376002)(136003)(39860400002)(230922051799003)(451199024)(82310400011)(64100799003)(1800799009)(186009)(40470700004)(46966006)(36840700001)(40460700003)(40480700001)(83380400001)(336012)(426003)(4326008)(81166007)(44832011)(356005)(82740400003)(5660300002)(86362001)(36756003)(7416002)(36860700001)(6916009)(316002)(54906003)(478600001)(70206006)(70586007)(8676002)(8936002)(47076005)(2906002)(2616005)(26005)(6666004)(41300700001)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:05.1796 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c13242fa-ee1e-4ee0-3643-08dbc5cf478b 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4F.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4123 From: Juergen Gross Add a memory region which can be used to automatically map granted memory. It is starting at 0x8000000000000000ULL in order to be able to distinguish it from normal RAM. For this reason the xen.ram memory region is expanded, which has no further impact as it is used just as a container of the real RAM regions and now the grant region. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal --- hw/i386/xen/xen-hvm.c | 3 ++ hw/xen/xen-hvm-common.c | 4 +-- hw/xen/xen-mapcache.c | 27 ++++++++++++++ include/exec/ram_addr.h | 1 + include/hw/xen/xen-hvm-common.h | 2 ++ include/hw/xen/xen_pvdev.h | 3 ++ include/sysemu/xen-mapcache.h | 3 ++ softmmu/physmem.c | 62 +++++++++++++++++++++------------ 8 files changed, 80 insertions(+), 25 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index f42621e674..67a55558a6 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -172,6 +172,9 @@ static void xen_ram_init(PCMachineState *pcms, x86ms->above_4g_mem_size); memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi); } + + /* Add grant mappings as a pseudo RAM region. */ + ram_grants = *xen_init_grant_ram(); } static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 565dc39c8f..b7255977a5 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -9,7 +9,7 @@ #include "hw/boards.h" #include "hw/xen/arch_hvm.h" -MemoryRegion ram_memory; +MemoryRegion ram_memory, ram_grants; void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) @@ -26,7 +26,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, return; } - if (mr == &ram_memory) { + if (mr == &ram_memory || mr == &ram_grants) { return; } diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index f7d974677d..8115c44c00 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -14,7 +14,9 @@ #include +#include "hw/xen/xen-hvm-common.h" #include "hw/xen/xen_native.h" +#include "hw/xen/xen_pvdev.h" #include "qemu/bitmap.h" #include "sysemu/runstate.h" @@ -597,3 +599,28 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, mapcache_unlock(); return p; } + +MemoryRegion *xen_init_grant_ram(void) +{ + RAMBlock *block; + + memory_region_init(&ram_grants, NULL, "xen.grants", + XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE); + block = g_malloc0(sizeof(*block)); + block->mr = &ram_grants; + block->used_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE; + block->max_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE; + block->fd = -1; + block->page_size = XC_PAGE_SIZE; + block->host = (void *)XEN_GRANT_ADDR_OFF; + block->offset = XEN_GRANT_ADDR_OFF; + block->flags = RAM_PREALLOC; + ram_grants.ram_block = block; + ram_grants.ram = true; + ram_grants.terminates = true; + ram_block_add_list(block); + memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF, + &ram_grants); + + return &ram_grants; +} diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 90676093f5..c0b5f9a7d0 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -139,6 +139,7 @@ void qemu_ram_free(RAMBlock *block); int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp); void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length); +void ram_block_add_list(RAMBlock *new_block); /* Clear whole block of mem */ static inline void qemu_ram_block_writeback(RAMBlock *block) diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-common.h index 4e9904f1a6..0d300ba898 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -17,6 +17,8 @@ #include extern MemoryRegion ram_memory; + +extern MemoryRegion ram_grants; extern MemoryListener xen_io_listener; extern DeviceListener xen_device_listener; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index ddad4b9f36..0f1b5edfa9 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -80,4 +80,7 @@ int xen_pv_send_notify(struct XenLegacyDevice *xendev); void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level, const char *fmt, ...) G_GNUC_PRINTF(3, 4); +#define XEN_GRANT_ADDR_OFF 0x8000000000000000ULL +#define XEN_MAX_VIRTIO_GRANTS 65536 + #endif /* QEMU_HW_XEN_PVDEV_H */ diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index c8e7c2f6cf..f4bedb1c11 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -10,6 +10,7 @@ #define XEN_MAPCACHE_H #include "exec/cpu-common.h" +#include "exec/ram_addr.h" typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset, ram_addr_t size); @@ -25,6 +26,8 @@ void xen_invalidate_map_cache(void); uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, hwaddr new_phys_addr, hwaddr size); +MemoryRegion *xen_init_grant_ram(void); + #else static inline void xen_map_cache_init(phys_offset_to_gaddr_t f, diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 309653c722..e182a2fa07 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1803,12 +1803,47 @@ static void dirty_memory_extend(ram_addr_t old_ram_size, } } +static void ram_block_add_list_locked(RAMBlock *new_block) + { + RAMBlock *block; + RAMBlock *last_block = NULL; + + /* + * Keep the list sorted from biggest to smallest block. Unlike QTAILQ, + * QLIST (which has an RCU-friendly variant) does not have insertion at + * tail, so save the last element in last_block. + */ + RAMBLOCK_FOREACH(block) { + last_block = block; + if (block->max_length < new_block->max_length) { + break; + } + } + if (block) { + QLIST_INSERT_BEFORE_RCU(block, new_block, next); + } else if (last_block) { + QLIST_INSERT_AFTER_RCU(last_block, new_block, next); + } else { /* list is empty */ + QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next); + } + ram_list.mru_block = NULL; + + /* Write list before version */ + smp_wmb(); + ram_list.version++; +} + +void ram_block_add_list(RAMBlock *new_block) +{ + qemu_mutex_lock_ramlist(); + ram_block_add_list_locked(new_block); + qemu_mutex_unlock_ramlist(); +} + static void ram_block_add(RAMBlock *new_block, Error **errp) { const bool noreserve = qemu_ram_is_noreserve(new_block); const bool shared = qemu_ram_is_shared(new_block); - RAMBlock *block; - RAMBlock *last_block = NULL; ram_addr_t old_ram_size, new_ram_size; Error *err = NULL; @@ -1846,28 +1881,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) if (new_ram_size > old_ram_size) { dirty_memory_extend(old_ram_size, new_ram_size); } - /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ, - * QLIST (which has an RCU-friendly variant) does not have insertion at - * tail, so save the last element in last_block. - */ - RAMBLOCK_FOREACH(block) { - last_block = block; - if (block->max_length < new_block->max_length) { - break; - } - } - if (block) { - QLIST_INSERT_BEFORE_RCU(block, new_block, next); - } else if (last_block) { - QLIST_INSERT_AFTER_RCU(last_block, new_block, next); - } else { /* list is empty */ - QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next); - } - ram_list.mru_block = NULL; - /* Write list before version */ - smp_wmb(); - ram_list.version++; + ram_block_add_list_locked(new_block); + qemu_mutex_unlock_ramlist(); cpu_physical_memory_set_dirty_range(new_block->offset, From patchwork Thu Oct 5 18:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410588 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 4A237E92723 for ; Thu, 5 Oct 2023 18:17:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613094.953394 (Exim 4.92) (envelope-from ) id 1qoSuW-0005Fc-EJ; Thu, 05 Oct 2023 18:17:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613094.953394; Thu, 05 Oct 2023 18:17:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuW-0005FT-B1; Thu, 05 Oct 2023 18:17:20 +0000 Received: by outflank-mailman (input) for mailman id 613094; Thu, 05 Oct 2023 18:17:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSuV-0004jk-73 for xen-devel@lists.xenproject.org; Thu, 05 Oct 2023 18:17:19 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20605.outbound.protection.outlook.com [2a01:111:f400:7e83::605]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6a908a56-63ab-11ee-98d3-6d05b1d4d9a1; Thu, 05 Oct 2023 20:17:18 +0200 (CEST) Received: from DM6PR11CA0011.namprd11.prod.outlook.com (2603:10b6:5:190::24) by SA1PR12MB8093.namprd12.prod.outlook.com (2603:10b6:806:335::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.25; Thu, 5 Oct 2023 18:17:15 +0000 Received: from DS1PEPF00017094.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::78) by DM6PR11CA0011.outlook.office365.com (2603:10b6:5:190::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.29 via Frontend Transport; Thu, 5 Oct 2023 18:17:14 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017094.mail.protection.outlook.com (10.167.17.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 5 Oct 2023 18:17:14 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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; Thu, 5 Oct 2023 13:17:11 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 11:17:10 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 5 Oct 2023 13:17:10 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6a908a56-63ab-11ee-98d3-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hk5Q7zmxTeEefs94fBqp329rML9W7uIYqJEj/eeZqX5cDHiTusGDJRWSlC516STkj2loNtZQ2g2l8Gk4/nkgU3GwJPcCFP7CNAQ+PVCzQizr/d0ZyAHGpVxC+WqI5VSrlKgjoauMoC5nHeS2KFVmKxoXsXC84D9/kh5KtYZah1ews4lGH8Mj4VCyPkVcrMMewd6X+u7VuGHHphsOtWLNUYUF3Gd+qVzYLi/QxooYiVq+V7yY8Qz2o+EQKcZr4z+V7BBmxaivdJr1CnGz0C5VSnYxNk3f0AK6yUNb9MUcp4R8PWbBSjzehd475xWeYMF1kSIQNnFGw+VLc+Vvzymkbg== 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=YyNjWn5SJhWUmcBag3JIZwDCIV00tRHA7KorZZW17+o=; b=m2V/cBQNQ7FpxkFhEFp2isEeAiOVdPXhntHDoIIoTsQ/6fHabY+1bdIpRJy54hiblBVyO+oYTjFKMModd87g48QjneGK36GTQeQM6h26raIkapTqZOOeYdVLTNfBhwcHYm2vdaaDfyUh2g+5FVP0iIncbs7cecN1r/26lJNpklcqb6ma6rLOGhY4t1EaV67TQEyY0swSKi83w1+suomgtBt3C/mCrZewq7p9QfKwJZtyygdE09qaffRAvQhYT/yFgXbZwheIh7LoWhC24uIwS5hJw3Ra9UWIwfNldAlbpob54puF2BdKfZ8+3Ov+1/501e5XpwSzZeW7bvYT2VrYmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org 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=YyNjWn5SJhWUmcBag3JIZwDCIV00tRHA7KorZZW17+o=; b=JBGUpzbv9KHDclsOgX3quNrt3U5EfRi+XeqDQM2hQuI7kG8K5b8PQmHWn9fnWQFnMbM23kwk0aEe7of0UclafYpgNO9Kg6cAozTqU+Hb90tQxoRUJXHF1tPEgMXM942JQcXjc1W5fefngI5axGbtVu0FRIxtkiMvwFDk6QA95+4= 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 From: Vikram Garhwal To: CC: , Juergen Gross , Anthony Perard , Paul Durrant , "open list:X86 Xen CPUs" Subject: [QEMU][PATCH v1 4/7] xen: let xen_ram_addr_from_mapcache() return -1 in case of not found entry Date: Thu, 5 Oct 2023 11:16:26 -0700 Message-ID: <20231005181629.4046-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231005181629.4046-1-vikram.garhwal@amd.com> References: <20231005181629.4046-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017094:EE_|SA1PR12MB8093:EE_ X-MS-Office365-Filtering-Correlation-Id: 233960d8-50bd-40e5-2cc2-08dbc5cf4d38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uvJ/sQMkijaa6U7JaszCb8+h8nbmycnuRFytx4gc5JQ/xGPolzr+eWtZTPIS4nlcFi1awuH9BoTwfrrtGvbciSk35BjnwWTDeA2PqPJ+qvwTZujdM1Rsdis4immIE73QCiQCQRXTJ87vsRhwd5VW8fH9gXzDKr6SpF5EJy5tGKKligujhWfncxxfgduFc5vPKWAsTP2K/f1BUqr434S7gfHcHPIjS9R+Tw021uLF8Iy1zfD9rhDLLBeCTD9nrn80hS5bFF++D8W+s+Sui89vP1CfJ7W/hbjCYiXSU4CE2Kgp8LXOXuZqzKcGE1cGc94cY7OdO95nw5KpnOM2KYIeE7z0b9ISY8tH39xCoNKmaQ+nW1CDIuBVm9r15GP302txoyFpXBqL87IwLCZ5Qyor4AwVRyfnimgLHwcK+lTKsMatzvKylkp0AygK9JZxgLxAKyrfbPyY4uXI/hYJE/hl8/CaMrdAVBXRbex299C9TpIaBl40ARVlGZmRUgLadQquCtbYt1xri+BfeG5GXcka3hruUatZcV09pRlo+ZfO3dbrhuhHgDMF1plxrGzrEs+6v5KBatwFGcK3mOjg8bgiDr8ui/Nz2qwLiI3pwwPG7zOYzy0aEzwCS8WeDFxHU4vYoDYzaKypqjV6opjMXk5QmitA/4OAOauTblSNxafivNffF88NSgrMX9iQ1spnrEUqkCy03yxyTPWL1vLTsSWwH5apQFgX1kjXsJlJjK6YMiyM667EXg7ZNTC1j1PkyPMRq24LYGKc3GBDhMZeRQaWGA== 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)(39860400002)(136003)(396003)(230922051799003)(82310400011)(64100799003)(451199024)(1800799009)(186009)(36840700001)(46966006)(40470700004)(1076003)(47076005)(478600001)(83380400001)(6666004)(40460700003)(36860700001)(26005)(426003)(336012)(40480700001)(356005)(81166007)(82740400003)(5660300002)(2906002)(86362001)(4326008)(41300700001)(2616005)(8936002)(36756003)(316002)(54906003)(70206006)(6916009)(70586007)(44832011)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:14.6705 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 233960d8-50bd-40e5-2cc2-08dbc5cf4d38 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: DS1PEPF00017094.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8093 From: Juergen Gross Today xen_ram_addr_from_mapcache() will either abort() or return 0 in case it can't find a matching entry for a pointer value. Both cases are bad, so change that to return an invalid address instead. Signed-off-by: Juergen Gross Reviewed-by: Stefano Stabellini --- hw/xen/xen-mapcache.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 8115c44c00..8a61c7dde6 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -404,13 +404,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) } } if (!found) { - fprintf(stderr, "%s, could not find %p\n", __func__, ptr); - QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) { - DPRINTF(" "HWADDR_FMT_plx" -> %p is present\n", reventry->paddr_index, - reventry->vaddr_req); - } - abort(); - return 0; + mapcache_unlock(); + return RAM_ADDR_INVALID; } entry = &mapcache->entry[paddr_index % mapcache->nr_buckets]; @@ -418,8 +413,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr) entry = entry->next; } if (!entry) { - DPRINTF("Trying to find address %p that is not in the mapcache!\n", ptr); - raddr = 0; + raddr = RAM_ADDR_INVALID; } else { raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); From patchwork Thu Oct 5 18:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410587 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 EB4ACE92728 for ; Thu, 5 Oct 2023 18:17:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613095.953404 (Exim 4.92) (envelope-from ) id 1qoSub-0005Yz-M3; Thu, 05 Oct 2023 18:17:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613095.953404; Thu, 05 Oct 2023 18:17:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSub-0005Yq-If; Thu, 05 Oct 2023 18:17:25 +0000 Received: by outflank-mailman (input) for mailman id 613095; Thu, 05 Oct 2023 18:17:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qoSua-0005Wp-CX for xen-devel@lists.xenproject.org; Thu, 05 Oct 2023 18:17:24 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060a.outbound.protection.outlook.com [2a01:111:f400:7e88::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6c15a3f7-63ab-11ee-9b0d-b553b5be7939; Thu, 05 Oct 2023 20:17:21 +0200 (CEST) Received: from DM6PR02CA0102.namprd02.prod.outlook.com (2603:10b6:5:1f4::43) by SJ0PR12MB6926.namprd12.prod.outlook.com (2603:10b6:a03:485::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.22; Thu, 5 Oct 2023 18:17:17 +0000 Received: from DS1PEPF00017095.namprd03.prod.outlook.com (2603:10b6:5:1f4:cafe::15) by DM6PR02CA0102.outlook.office365.com (2603:10b6:5:1f4::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33 via Frontend Transport; Thu, 5 Oct 2023 18:17:16 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017095.mail.protection.outlook.com (10.167.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.14 via Frontend Transport; Thu, 5 Oct 2023 18:17:16 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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; Thu, 5 Oct 2023 13:17:16 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 5 Oct 2023 11:17:15 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 5 Oct 2023 13:17:14 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6c15a3f7-63ab-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hqup0mrfddn+Vuc+pEEWS4oIkm26XNUReLwqQz/u7LX0s8P6pvqT/MeZQsFbuzhYf2aB0dSMgkUlo3l7USR55mPn3pxt0m+Z67EytKnEJwotGCVkC7Tq1n3QxZBqMwa3SXgX5Q3A54tMUE2jbAIQ1zu1cBKGDgmYr2Aeb2HIAKEKOAjwDa+YgFkbHpx3Nb+mKrbGikfL0daNGtd7NY4r3KNmsC2QvVipWEklWW0M47W9eyF+BjF8lSnBnY3qQtvdUZEBvmw7SneO5qfKLeQJ2CWMsq4fMoeLNOSl7OXSqXfVynlOGuqhH7+2CGLijYEWNZSL2Vp5/p6/plzoD45QCA== 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=drk4vNje31iUchZYqFtsf2J08S9ncFF0JR2CCRunqKc=; b=MTkyB3AtXkIDi3JnFrqi+G9xLYA5yrxuuE4kSTWdJ9OiBqDlHhYEy0Y2ilIwz7JEPO58xok1OpG18koiTRaYY5GoYsy9kqHuTMyiXBnvaayut+4dV0EE75qo1LCSk4ifAuMylfnG1AZB2IC9wqn2JegeDITRySx5NZALNy2loo6cGmy8Nzq2J1qTojh4ZIcfUPxBQQ66kNIVpCwpWTpkGRLOxTx3p3VRnz03i6TlgdDAs5yIiPpaRi4SllLvRbeEs7yQ2jJrJ6OUV8mS996PPUP5WNVBEKR7HgvCdITxf0CvFW8lITkD/AccebizF++5YVQqogDMhDp8T+7LA6k6Qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org 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=drk4vNje31iUchZYqFtsf2J08S9ncFF0JR2CCRunqKc=; b=kzMbfV3GX2sHZrgvom2ILxlASZiXBA94YO+3eHzSz2Su2ygr7vg8Zjup1TggzAcxdNhp9DlAgqSxxrrBdCCy4KfMHqyoJG3/Cm+ngqs3Up9sJI+Mtp6vGyssupfNhkSfOaqTyEo1aKlKsd3CO1tuRsieRE4BphlNaFayEkulzmA= 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 From: Vikram Garhwal To: CC: , Juergen Gross , Vikram Garhwal , Anthony Perard , "Paul Durrant" , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "open list:X86 Xen CPUs" Subject: [QEMU][PATCH v1 6/7] xen: add map and unmap callbacks for grant region Date: Thu, 5 Oct 2023 11:16:28 -0700 Message-ID: <20231005181629.4046-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231005181629.4046-1-vikram.garhwal@amd.com> References: <20231005181629.4046-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017095:EE_|SJ0PR12MB6926:EE_ X-MS-Office365-Filtering-Correlation-Id: 30a38abe-ecbe-4f11-23a0-08dbc5cf4e4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 13hZQItJ3wOE6AIoodsgUmW+M/rtsUY0ODjSk1x/J+BzeR0LZMSQwxItLngYiad3yxklbD0QrTteqog/WtRygm7ptMr491gLDGIuqanNRALRrD5Wkbhy6ofI73HKABsvwRWb7r40aVWiTR/C9JVt8biBKgL5SKyDxjqKoQHV9AHYPvYXm0mAfYbEP+FpMCkKRE/QOZdiNSqpdZmmX6HrthkIlxX+/prFayDsl70aiDZLT+Oh+xMWH7SMycQUhkQ4pRZh0e6uph3ym/hQ2D6Fhv88MoQXHAMaWFs/MD+nanC6knRejipnhMAQU6s7GHkmzYGthDc7ZkBbJHS0Mm+0WkjCzNj34wlkkxZvKV88S3m+G5j2tP/TmNTj0h9uND9FGqS6imm4IfZmoS4wEeeBZqJHQpcmpS4oBrEUJSAKyuuMnPYg2YGd+lLkFKPR+lowtqBaKQOjdvz5enGWsJXJd5VokH47QFib/ont/1vzCobovUibJq0f6nETPcVOjwHcylvt378/56Qks4JZP1SCXzaCNvSB+T1fV609ziTBYACrtVCFOO5bzGky4EpFYvDeqYHPcIfs4nAIKUI/uPESaEtYXJWv6Wm7i+jR+7H+fDvdjTDVtfejSL2ny6Sy/2JsyYvrE7D8VHwVEPWxK4HNLHY6Bf0BQZnPImTVDHsAL+UhAqKYbvlhbmFhZ8pZgJy/qlld/SfrnY27hqoMflXPReCmzw7n5mTctYs/AhgKwex/0VAR7RlDZQ1ksaimMosPviTYB0NFCn0TB49jVoC0RQ== 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)(39860400002)(396003)(376002)(346002)(136003)(230922051799003)(186009)(1800799009)(451199024)(82310400011)(64100799003)(36840700001)(40470700004)(46966006)(44832011)(2616005)(5660300002)(1076003)(40480700001)(81166007)(40460700003)(356005)(82740400003)(316002)(6666004)(47076005)(478600001)(86362001)(6916009)(36756003)(36860700001)(70206006)(54906003)(83380400001)(7416002)(70586007)(2906002)(41300700001)(26005)(336012)(426003)(8936002)(8676002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:16.4921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30a38abe-ecbe-4f11-23a0-08dbc5cf4e4e 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: DS1PEPF00017095.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6926 From: Juergen Gross Add the callbacks for mapping/unmapping guest memory via grants to the special grant memory region. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal --- hw/xen/xen-mapcache.c | 167 +++++++++++++++++++++++++++++++++++++++++- softmmu/physmem.c | 11 ++- 2 files changed, 173 insertions(+), 5 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 8a61c7dde6..52844a6a9d 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -9,6 +9,8 @@ */ #include "qemu/osdep.h" +#include "qemu/queue.h" +#include "qemu/thread.h" #include "qemu/units.h" #include "qemu/error-report.h" @@ -23,6 +25,8 @@ #include "sysemu/xen-mapcache.h" #include "trace.h" +#include +#include //#define MAPCACHE_DEBUG @@ -385,7 +389,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, return p; } -ram_addr_t xen_ram_addr_from_mapcache(void *ptr) +static ram_addr_t xen_ram_addr_from_mapcache_try(void *ptr) { MapCacheEntry *entry = NULL; MapCacheRev *reventry; @@ -594,10 +598,170 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr, return p; } +struct XENMappedGrantRegion { + void *addr; + unsigned int pages; + unsigned int refs; + unsigned int prot; + uint32_t idx; + QLIST_ENTRY(XENMappedGrantRegion) list; +}; + +static xengnttab_handle *xen_region_gnttabdev; +static QLIST_HEAD(GrantRegionList, XENMappedGrantRegion) xen_grant_mappings = + QLIST_HEAD_INITIALIZER(xen_grant_mappings); +static QemuMutex xen_map_mutex; + +static void *xen_map_grant_dyn(MemoryRegion **mr, hwaddr addr, hwaddr *plen, + bool is_write, MemTxAttrs attrs) +{ + unsigned int page_off = addr & (XC_PAGE_SIZE - 1); + unsigned int i; + unsigned int nrefs = (page_off + *plen + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; + uint32_t ref = (addr - XEN_GRANT_ADDR_OFF) >> XC_PAGE_SHIFT; + uint32_t *refs = NULL; + unsigned int prot = PROT_READ; + struct XENMappedGrantRegion *mgr = NULL; + + if (is_write) { + prot |= PROT_WRITE; + } + + qemu_mutex_lock(&xen_map_mutex); + + QLIST_FOREACH(mgr, &xen_grant_mappings, list) { + if (mgr->idx == ref && + mgr->pages == nrefs && + (mgr->prot & prot) == prot) { + break; + } + } + if (!mgr) { + mgr = g_new(struct XENMappedGrantRegion, 1); + + if (nrefs == 1) { + refs = &ref; + } else { + refs = g_new(uint32_t, nrefs); + for (i = 0; i < nrefs; i++) { + refs[i] = ref + i; + } + } + mgr->addr = xengnttab_map_domain_grant_refs(xen_region_gnttabdev, nrefs, + xen_domid, refs, prot); + if (mgr->addr) { + mgr->pages = nrefs; + mgr->refs = 1; + mgr->prot = prot; + mgr->idx = ref; + + QLIST_INSERT_HEAD(&xen_grant_mappings, mgr, list); + } else { + g_free(mgr); + mgr = NULL; + } + } else { + mgr->refs++; + } + + qemu_mutex_unlock(&xen_map_mutex); + + if (nrefs > 1) { + g_free(refs); + } + + return mgr ? mgr->addr + page_off : NULL; +} + +static void xen_unmap_grant_dyn(MemoryRegion *mr, void *buffer, ram_addr_t addr, + hwaddr len, bool is_write, hwaddr access_len) +{ + unsigned int page_off = (unsigned long)buffer & (XC_PAGE_SIZE - 1); + unsigned int nrefs = (page_off + len + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT; + unsigned int prot = PROT_READ; + struct XENMappedGrantRegion *mgr = NULL; + + if (is_write) { + prot |= PROT_WRITE; + } + + qemu_mutex_lock(&xen_map_mutex); + + QLIST_FOREACH(mgr, &xen_grant_mappings, list) { + if (mgr->addr == buffer - page_off && + mgr->pages == nrefs && + (mgr->prot & prot) == prot) { + break; + } + } + if (mgr) { + mgr->refs--; + if (!mgr->refs) { + xengnttab_unmap(xen_region_gnttabdev, mgr->addr, nrefs); + + QLIST_REMOVE(mgr, list); + g_free(mgr); + } + } else { + error_report("xen_unmap_grant_dyn() trying to unmap unknown buffer"); + } + + qemu_mutex_unlock(&xen_map_mutex); +} + +static ram_addr_t xen_ram_addr_from_grant_cache(void *ptr) +{ + unsigned int page_off = (unsigned long)ptr & (XC_PAGE_SIZE - 1); + struct XENMappedGrantRegion *mgr = NULL; + ram_addr_t raddr = RAM_ADDR_INVALID; + + qemu_mutex_lock(&xen_map_mutex); + + QLIST_FOREACH(mgr, &xen_grant_mappings, list) { + if (mgr->addr == ptr - page_off) { + break; + } + } + + if (mgr) { + raddr = (mgr->idx << XC_PAGE_SHIFT) + page_off + XEN_GRANT_ADDR_OFF; + } + + qemu_mutex_unlock(&xen_map_mutex); + + return raddr; +} + +ram_addr_t xen_ram_addr_from_mapcache(void *ptr) +{ + ram_addr_t raddr; + + raddr = xen_ram_addr_from_mapcache_try(ptr); + if (raddr == RAM_ADDR_INVALID) { + raddr = xen_ram_addr_from_grant_cache(ptr); + } + + return raddr; +} + +static const struct MemoryRegionOps xen_grant_mr_ops = { + .map = xen_map_grant_dyn, + .unmap = xen_unmap_grant_dyn, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + MemoryRegion *xen_init_grant_ram(void) { RAMBlock *block; + qemu_mutex_init(&xen_map_mutex); + + xen_region_gnttabdev = xengnttab_open(NULL, 0); + if (xen_region_gnttabdev == NULL) { + fprintf(stderr, "can't open gnttab device\n"); + return NULL; + } + memory_region_init(&ram_grants, NULL, "xen.grants", XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE); block = g_malloc0(sizeof(*block)); @@ -612,6 +776,7 @@ MemoryRegion *xen_init_grant_ram(void) ram_grants.ram_block = block; ram_grants.ram = true; ram_grants.terminates = true; + ram_grants.ops = &xen_grant_mr_ops; ram_block_add_list(block); memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF, &ram_grants); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 5f425bea1c..e5346386db 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2250,13 +2250,16 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, if (xen_enabled()) { ram_addr_t ram_addr; + RCU_READ_LOCK_GUARD(); ram_addr = xen_ram_addr_from_mapcache(ptr); - block = qemu_get_ram_block(ram_addr); - if (block) { - *offset = ram_addr - block->offset; + if (ram_addr != RAM_ADDR_INVALID) { + block = qemu_get_ram_block(ram_addr); + if (block) { + *offset = ram_addr - block->offset; + } + return block; } - return block; } RCU_READ_LOCK_GUARD();