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: 13410593 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 BAAB4E92725 for ; Thu, 5 Oct 2023 18:23:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSzF-0007tH-Dr; Thu, 05 Oct 2023 14:22:13 -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 1qoSzE-0007sl-FZ for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:22:12 -0400 Received: from mail-bn7nam10on2058.outbound.protection.outlook.com ([40.107.92.58] 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 1qoSzA-0007kn-SC for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:22:12 -0400 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= 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 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 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 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 Received-SPF: softfail client-ip=40.107.92.58; envelope-from=vikram.garhwal@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 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.493, 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 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: 13410582 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 1AC20E92727 for ; Thu, 5 Oct 2023 18:18:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuS-0000J6-DU; Thu, 05 Oct 2023 14:17:16 -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 1qoSuR-0000IS-5E for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:15 -0400 Received: from mail-bn7nam10on20601.outbound.protection.outlook.com ([2a01:111:f400:7e8a::601] 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 1qoSuL-00068w-Sb for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:14 -0400 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= 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 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 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 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 Received-SPF: softfail client-ip=2a01:111:f400:7e8a::601; envelope-from=vikram.garhwal@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 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:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410585 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 7133AE92726 for ; Thu, 5 Oct 2023 18:19:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuT-0000Jj-BV; Thu, 05 Oct 2023 14:17:17 -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 1qoSuR-0000Ie-M3 for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:15 -0400 Received: from mail-bn8nam11on20601.outbound.protection.outlook.com ([2a01:111:f400:7eae::601] helo=NAM11-BN8-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 1qoSuP-0006AS-L0 for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ab1OYBWdEoBFUmAgxCPaGsx90ekdARYa9PmsLO8/SyYogxrnipxkLJiX1jkFK/vU15+TYOAkYtwGoUK6Qib9YKvlt2VdCUptuM3D4TqmFTuAQ4LkjnOi298dnFZDxjgvQ+2bPSUkHMUMpgvZCiThmwmvyrkmoMqvauUU9RMNGe8lHBJr8+DJb4lNdV0EGJv3lHLnWwIeYVSzsxUdj2SnbYc7TycxcUfFfoGwNn/7Ex7k2iBLIZa/SK7ZFBwf5fPlQYS5g4mLsND9giaxF3JD8CQ/+nDYLSjbCVcAp2m/5OQ+Tz5tc/TSXGOjkYAX2WrO5pmWVpAcOpdQPr03RGg3AQ== 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=wBm1/HvgRkcHzEvfw0xyO6CeVYuFR3EGjqLKTtIEjyQ=; b=FtDCCATxqVklkwGHuQ/2AKUKlSk6C2M3EDZQtOMHqYeEOuDS3f5QuZNdfIv4PegGaAie+JHBXJhewF7Fs4o0udNJd6IgX4q05GWakb3gvNan7vwZcJWmEUzNBtxDide5g0fn47bqWrDKdTMaD+8Ni5FqF8Tc1IO5SOZt02RhL29A1y88XeEe6RPIRfnilCLkuvJcbrCHyAXTwcyQtSIfbv6t4LXrGQFxH695EH+c/Sovr1ohtS1Bb+AOaBb58vuEQF9YmktyonGwpPbrW0SidupZKnw2X5AX8Ccqo9fuBijlaAu95OwAuqrkhePVnJwUftICXgOVEIdhv4Asm469GQ== 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=wBm1/HvgRkcHzEvfw0xyO6CeVYuFR3EGjqLKTtIEjyQ=; b=Fs1+40Km3P9YDtbVgdj8lG6PKd6CDD/FuiviSKEQPhmdK4Op+cGPwEJ/GbweZKgobRzPwOydjyWU6xvh7+f/qy1ORp/V8VOXdc90peWUxD591+vmiRKfVk3lpBn5z9Q9T6nkjIhYNgfQ9GK0HA7Q1fevsHO2ncNN344Wgf3VkkU= Received: from MN2PR10CA0019.namprd10.prod.outlook.com (2603:10b6:208:120::32) by SJ2PR12MB9113.namprd12.prod.outlook.com (2603:10b6:a03:560::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.38; Thu, 5 Oct 2023 18:17:10 +0000 Received: from BL6PEPF0001AB4B.namprd04.prod.outlook.com (2603:10b6:208:120:cafe::9b) by MN2PR10CA0019.outlook.office365.com (2603:10b6:208:120::32) 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:09 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB4B.mail.protection.outlook.com (10.167.242.69) 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:09 +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:09 -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:08 -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:08 -0500 From: Vikram Garhwal To: CC: , Juergen Gross , Vikram Garhwal , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [QEMU][PATCH v1 3/7] softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length() Date: Thu, 5 Oct 2023 11:16:25 -0700 Message-ID: <20231005181629.4046-4-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: BL6PEPF0001AB4B:EE_|SJ2PR12MB9113:EE_ X-MS-Office365-Filtering-Correlation-Id: 80457754-d615-48f3-13fd-08dbc5cf4a12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qImDFwnb16hQntWZZHPMiPDMBEmYWpJQWja+AlzuHKXhcpYShZeo+TKnp1IY+CRTObWRbYyNVBtHJ/6dqgCPy2cevG1hnC8w3+XAsjDE5oYua2IGvqz19racmvHuCGjisJ4k5L5Z+3ftBg/ar3RUWGJ5lHXFyIWeEsttjA8x9/HshqDYuc0ABcacM/r44PwqdV36usJbshUB0+z0hKHeV3Nr00ZjOyuVo2Tm8ZfTqGbizLQMRkvIKv81vZESP10SPnOXJxB0mdiGvDhfsiQkGwesnuMFmkty9eHcixM1XH8aKGY9FekT/W6JyByHF7LymR5IDuyyC5Xuz3N5zCYQAtVid1Jx2+ktWuE8pjrSNdpFB2W2mpf15JIl6QgcWlK7YuovUbCU5cQ8HWbBFZwNd1JY6qJTVLhxAib8kwhp5z5G9sR6MnNX3Hwq2YA1b/qatj0Nv1tbtLmRMKjABo3MjNCyExk99zhowkUC7yx+Gi2hxXD3xN2CGHRPbLBdlFfvX5G3MHkQtYnvTSaBSgjBS9XU/dRMCpheEx80eaJmd6euKzGfa7CV3WS/F8A4673PGlXO7aZd6Svy817DbiDprbS0yQ5ZAUz97infZAvIk/zyb2r/JPtdRd9XoGYWJrV0rJDuW5Ge0uU5NXVnd8Z/qP4x3yyLczz0CLuYV0ORKZdyH4hENZDjztdLfUxnG0F8Gx9ribbgLaeo/b6KZCFBp8t2PCPJDrf0Fs4aISm0SzPXc49ogY8F51PHnSdoN9y1Kcb6CiMDnrolLBgnYriVCA== 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)(396003)(136003)(346002)(39860400002)(230922051799003)(451199024)(82310400011)(64100799003)(1800799009)(186009)(36840700001)(46966006)(40470700004)(81166007)(82740400003)(5660300002)(2616005)(1076003)(356005)(44832011)(426003)(336012)(36860700001)(26005)(47076005)(83380400001)(478600001)(6666004)(70586007)(40480700001)(316002)(54906003)(70206006)(6916009)(41300700001)(86362001)(2906002)(36756003)(4326008)(8676002)(8936002)(40460700003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:09.4345 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80457754-d615-48f3-13fd-08dbc5cf4a12 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: BL6PEPF0001AB4B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9113 Received-SPF: softfail client-ip=2a01:111:f400:7eae::601; envelope-from=vikram.garhwal@amd.com; helo=NAM11-BN8-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 From: Juergen Gross qemu_map_ram_ptr() and qemu_ram_ptr_length() share quite some code, so modify qemu_ram_ptr_length() a little bit and use it for qemu_map_ram_ptr(), too. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal --- softmmu/physmem.c | 58 +++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index e182a2fa07..6e5e379dd0 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2163,38 +2163,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } #endif /* !_WIN32 */ -/* Return a host pointer to ram allocated with qemu_ram_alloc. - * This should not be used for general purpose DMA. Use address_space_map - * or address_space_rw instead. For local memory (e.g. video ram) that the - * device owns, use memory_region_get_ram_ptr. - * - * Called within RCU critical section. - */ -void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) -{ - RAMBlock *block = ram_block; - - if (block == NULL) { - block = qemu_get_ram_block(addr); - addr -= block->offset; - } - - if (xen_enabled() && block->host == NULL) { - /* We need to check if the requested address is in the RAM - * because we don't want to map the entire memory in QEMU. - * In that case just map until the end of the page. - */ - if (block->offset == 0) { - return xen_map_cache(addr, 0, 0, false); - } - - block->host = xen_map_cache(block->offset, block->max_length, 1, false); - } - return ramblock_ptr(block, addr); -} - -/* Return a host pointer to guest's ram. Similar to qemu_map_ram_ptr - * but takes a size argument. +/* + * Return a host pointer to guest's ram. * * Called within RCU critical section. */ @@ -2202,7 +2172,9 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, hwaddr *size, bool lock) { RAMBlock *block = ram_block; - if (*size == 0) { + hwaddr len = 0; + + if (size && *size == 0) { return NULL; } @@ -2210,7 +2182,10 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, block = qemu_get_ram_block(addr); addr -= block->offset; } - *size = MIN(*size, block->max_length - addr); + if (size) { + *size = MIN(*size, block->max_length - addr); + len = *size; + } if (xen_enabled() && block->host == NULL) { /* We need to check if the requested address is in the RAM @@ -2218,7 +2193,7 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, * In that case just map the requested area. */ if (block->offset == 0) { - return xen_map_cache(addr, *size, lock, lock); + return xen_map_cache(addr, len, lock, lock); } block->host = xen_map_cache(block->offset, block->max_length, 1, lock); @@ -2227,6 +2202,19 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, return ramblock_ptr(block, addr); } +/* + * Return a host pointer to ram allocated with qemu_ram_alloc. + * This should not be used for general purpose DMA. Use address_space_map + * or address_space_rw instead. For local memory (e.g. video ram) that the + * device owns, use memory_region_get_ram_ptr. + * + * Called within RCU critical section. + */ +void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) +{ + return qemu_ram_ptr_length(ram_block, addr, NULL, false); +} + /* Return the offset of a hostpointer within a ramblock */ ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host) { 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: 13410580 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 AE33FE92726 for ; Thu, 5 Oct 2023 18:18:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuY-0000Ke-0Q; Thu, 05 Oct 2023 14:17:22 -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 1qoSuV-0000KF-PU for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:19 -0400 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f400:fe5a::629] helo=NAM12-MW2-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 1qoSuU-0006Dx-2K for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:19 -0400 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= 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 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 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 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 Received-SPF: softfail client-ip=2a01:111:f400:fe5a::629; envelope-from=vikram.garhwal@amd.com; helo=NAM12-MW2-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 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:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410581 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 AE305E92725 for ; Thu, 5 Oct 2023 18:18:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuZ-0000Lq-08; Thu, 05 Oct 2023 14:17:23 -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 1qoSuW-0000KS-R4 for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:20 -0400 Received: from mail-mw2nam10on2060d.outbound.protection.outlook.com ([2a01:111:f400:7e89::60d] helo=NAM10-MW2-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 1qoSuU-0006E5-Ro for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SubmVfbzc/nPFhlr9hJByd8wNSLtdpk9+SNwAXl6BpVYkBUHS1nj1sgz9kTbFZGVjlVMdEON8TAp5E1pM2dzXeNrPr7zYdlddHFnraEEQAHUpScpwnVAnE6SDOQ0BFn2JYBDe/tQ7QkKLYg3BssWhnh7INVkR1pbG6NmNgfLuRK3RAsKlMYgekqbsoLIl00/i0VjSSnMKKv8/A7SG71O10urY+Pxl1XaJMrvuAhkBYZAcDeypphup0gSOMuuZ/P9CQ+UgnYjQDqc2lO6hc7w9/vLf44TZ00ClJqIeix6Wnb/JiINjydyNmb0qb3oy5FhDd4TPdv1igpTmQH5fkDotw== 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=sI+N7d93jXJV1OR8YxQztq6LYTWmVI7kFZ/WxOVQQ2c=; b=b3a0Y0cpdOX7YQn0GLGJT/0FioV3ip/HVas/Ka6nxJvTqXhfEFCi0OsMiglbJdQrr5KtG6aytlnOt2AAD2SW6VdLsXwRZMr9iq3qgahtENGT1VwFyqt7rfGYfHIEPVcSQ1eExS7w4UK216Bd3OezF9A+VCusa7v5uEe2NWOrblifLSALfi7SY2+vF5V8CjazEKg5X4v7GFj98JozZqLgKfZKouffYrdNpf3ZSMb+g/Ki4oBp9SAJKlSUn0CvKGTfnsI63QUtq+6Isj5yrms8i+jUEjXwQSFYZV2OcYlgf8D6oDt9Su3INIvKqsEoW1lnAG++dhPYekGc1c6Yt8YhQA== 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=sI+N7d93jXJV1OR8YxQztq6LYTWmVI7kFZ/WxOVQQ2c=; b=LH4sEYSdQrq2F37sfnJ4s0d0tJHjK3OBHIDL3fWAIpYXA3hxd6SelYwc2gPfN3GsRi1eG1lcUfe4p9y4aeJAP4EUU5eEy6aNazUj3oSxCEE3BbslCmxbjJaOxAs4kiOc5eVKbHVzNy9aNMce82Qbvf266ym8QhiyDQ5lGl99054= Received: from DM6PR11CA0023.namprd11.prod.outlook.com (2603:10b6:5:190::36) by SA3PR12MB9160.namprd12.prod.outlook.com (2603:10b6:806:399::9) 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:15 +0000 Received: from DS1PEPF00017094.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::27) by DM6PR11CA0023.outlook.office365.com (2603:10b6:5:190::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.26 via Frontend Transport; Thu, 5 Oct 2023 18:17:15 +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 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:15 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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:13 -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:12 -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:12 -0500 From: Vikram Garhwal To: CC: , Juergen Gross , Vikram Garhwal , Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [QEMU][PATCH v1 5/7] memory: add MemoryRegion map and unmap callbacks Date: Thu, 5 Oct 2023 11:16:27 -0700 Message-ID: <20231005181629.4046-6-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_|SA3PR12MB9160:EE_ X-MS-Office365-Filtering-Correlation-Id: d58fbabc-5b84-4467-639a-08dbc5cf4d90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7rqatqywZbmoTDH2fKBFxAvlLAJ/YsgNP5pflRHnjl2BM5HdULHcfw3t5XoKlXoPo3yA3MgEqKx7D0XQU9gVrmNERlfLbaxQPd6tcXf84CKttCCeDTa5G0MUDQQs04CUlCi6UC3aKCXml9hOsPkq3z5N0vU2FO7JojtYqmiB+gsQgUEecKpNZh2Z8yW6zfTpLivnwuQ3LVwNfGUAe+4DJHFiGggNYkj3XoaUoPNQ6ZSTHlQLYVErO2NbQbnnzQLLmLLamhD2OdoWHUeN5EME7+PuUVb22mfqjRVeOJJ4Y3tDjHRfg3WjCPA+fqJpXOnv+PGGtB49iT/9juZpn6Xc6GqJbH8GG6dj6DeFCwV4+77D/xbhPZKAtbFsS9BJbH0xGJ5CmwCe6H/jZf/6rsWos1r8aaFj0YGDz2cekqLtioi1NMNOkTaRMS2uuXymi3jt4wSqgXAyiCx11najPJrrEQxDZR3hI/BGsQWL3En5r20riL5xb5fjvLliUWUYBf7L6/33oRg9OTfiMDseP3V3F/Mpam2eCZCyISMNSAiI33vDQf92LaXHEdWtkDjdMA1lkZb+jRnmgoA7RXJT/LnQTKQsxiI8iAfxwyFyvu/MI1w+inN0bBCq4gvyTZ3bj/3ajgrwEeMqkNA/VmgQY1AeVJP9zU8vSFK1ZB91KF9zBYt4rMF+Dyo4zw7iSMy7i0BYDR7iQN6rgwGzc/5FccYB1KYNvvhDJH5jArTuF8+hwi9pYo4VhwJ+E4U/qYP/QiY9sC6E3/sxBDeTuYAunDy/ZA== 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)(396003)(346002)(376002)(136003)(39860400002)(230922051799003)(186009)(64100799003)(451199024)(82310400011)(1800799009)(40470700004)(46966006)(36840700001)(2616005)(70586007)(54906003)(6916009)(40460700003)(316002)(41300700001)(70206006)(1076003)(26005)(336012)(426003)(6666004)(36756003)(478600001)(36860700001)(82740400003)(81166007)(356005)(86362001)(47076005)(83380400001)(40480700001)(44832011)(2906002)(8936002)(5660300002)(4326008)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:15.2486 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d58fbabc-5b84-4467-639a-08dbc5cf4d90 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: SA3PR12MB9160 Received-SPF: softfail client-ip=2a01:111:f400:7e89::60d; envelope-from=vikram.garhwal@amd.com; helo=NAM10-MW2-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 From: Juergen Gross In order to support mapping and unmapping guest memory dynamically to and from qemu during address_space_[un]map() operations add the map() and unmap() callbacks to MemoryRegionOps. Those will be used e.g. for Xen grant mappings when performing guest I/Os. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal --- include/exec/memory.h | 21 ++++++++++++++++++ softmmu/physmem.c | 50 +++++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index c99842d2fc..f3c62d2883 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -280,6 +280,27 @@ struct MemoryRegionOps { unsigned size, MemTxAttrs attrs); + /* + * Dynamically create mapping. @addr is the guest address to map; @plen + * is the pointer to the usable length of the buffer. + * @mr contents can be changed in case a new memory region is created for + * the mapping. + * Returns the buffer address for accessing the data. + */ + void *(*map)(MemoryRegion **mr, + hwaddr addr, + hwaddr *plen, + bool is_write, + MemTxAttrs attrs); + + /* Unmap an area obtained via map() before. */ + void (*unmap)(MemoryRegion *mr, + void *buffer, + ram_addr_t addr, + hwaddr len, + bool is_write, + hwaddr access_len); + enum device_endian endianness; /* Guest-visible constraints: */ struct { diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6e5e379dd0..5f425bea1c 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3135,6 +3135,7 @@ void *address_space_map(AddressSpace *as, hwaddr len = *plen; hwaddr l, xlat; MemoryRegion *mr; + void *ptr = NULL; FlatView *fv; if (len == 0) { @@ -3168,12 +3169,20 @@ void *address_space_map(AddressSpace *as, return bounce.buffer; } - memory_region_ref(mr); + + if (mr->ops && mr->ops->map) { + ptr = mr->ops->map(&mr, addr, plen, is_write, attrs); + } + *plen = flatview_extend_translation(fv, addr, len, mr, xlat, l, is_write, attrs); fuzz_dma_read_cb(addr, *plen, mr); - return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); + if (ptr == NULL) { + ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); + } + + return ptr; } /* Unmaps a memory region previously mapped by address_space_map(). @@ -3189,11 +3198,16 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, mr = memory_region_from_host(buffer, &addr1); assert(mr != NULL); - if (is_write) { - invalidate_and_set_dirty(mr, addr1, access_len); - } - if (xen_enabled()) { - xen_invalidate_map_cache_entry(buffer); + + if (mr->ops && mr->ops->unmap) { + mr->ops->unmap(mr, buffer, addr1, len, is_write, access_len); + } else { + if (is_write) { + invalidate_and_set_dirty(mr, addr1, access_len); + } + if (xen_enabled()) { + xen_invalidate_map_cache_entry(buffer); + } } memory_region_unref(mr); return; @@ -3266,10 +3280,18 @@ int64_t address_space_cache_init(MemoryRegionCache *cache, * doing this if we found actual RAM, which behaves the same * regardless of attributes; so UNSPECIFIED is fine. */ + if (mr->ops && mr->ops->map) { + cache->ptr = mr->ops->map(&mr, addr, &l, is_write, + MEMTXATTRS_UNSPECIFIED); + } + l = flatview_extend_translation(cache->fv, addr, len, mr, cache->xlat, l, is_write, MEMTXATTRS_UNSPECIFIED); - cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true); + if (!cache->ptr) { + cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, + true); + } } else { cache->ptr = NULL; } @@ -3291,14 +3313,20 @@ void address_space_cache_invalidate(MemoryRegionCache *cache, void address_space_cache_destroy(MemoryRegionCache *cache) { - if (!cache->mrs.mr) { + MemoryRegion *mr = cache->mrs.mr; + + if (!mr) { return; } - if (xen_enabled()) { + if (mr->ops && mr->ops->unmap) { + mr->ops->unmap(mr, cache->ptr, cache->xlat, cache->len, + cache->is_write, cache->len); + } else if (xen_enabled()) { xen_invalidate_map_cache_entry(cache->ptr); } - memory_region_unref(cache->mrs.mr); + + memory_region_unref(mr); flatview_unref(cache->fv); cache->mrs.mr = NULL; cache->fv = NULL; 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: 13410584 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 0B8D1E92725 for ; Thu, 5 Oct 2023 18:18:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuh-0000Nz-2l; Thu, 05 Oct 2023 14:17:31 -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 1qoSuf-0000NA-64 for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:29 -0400 Received: from mail-dm6nam10on20622.outbound.protection.outlook.com ([2a01:111:f400:7e88::622] helo=NAM10-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 1qoSuW-0006Ee-R0 for qemu-devel@nongnu.org; Thu, 05 Oct 2023 14:17:28 -0400 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= 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 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 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 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 Received-SPF: softfail client-ip=2a01:111:f400:7e88::622; envelope-from=vikram.garhwal@amd.com; helo=NAM10-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 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 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(); From patchwork Thu Oct 5 18:16:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13410583 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 D8B19E92723 for ; Thu, 5 Oct 2023 18:18:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoSuf-0000N9-4g; Thu, 05 Oct 2023 14:17:29 -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 1qoSud-0000Mp-Qy; Thu, 05 Oct 2023 14:17:27 -0400 Received: from mail-bn1nam02on20602.outbound.protection.outlook.com ([2a01:111:f400:7eb2::602] 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 1qoSub-0006KI-09; Thu, 05 Oct 2023 14:17:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nQ60KordRDLJk98TPECF5nvC5mN0nSp+h7LCynQAx1LdHZr0ITDtVq4Q13NowFIbQd882EWLzza0t/A6dE1gh7WiiiW2BmblhWp16qjgBkQLZkZlYWpr1ClbvSVhNImhbNAyTl684nGo3OOAEwUVBAKy4y1WPNtDS0/8oYmaTNXJP9QVcSZLw7E1QkMPMLFtzLoqtLZqfUJYJA+mfCiA7SUDsgbw/i/cUVtmirbdobi7zRalV+i1OXR2vQ7HGbDAJkJf1p5gaeNJyyXOAkAVQXL4QGuSsTC9AbpC9kRmRvihxYXCueeHSaau96u4ho1OerhX6PCECv4Yt8BklWp4jA== 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=ksF652jkj0H+gVQIly5PpnylBV9Mz7gsmo/SYfg2AAk=; b=bWOOlNmVE5MCa2zZX9MzhK/VDBKbouq8gPFMEdNYgeNLC8wfZmJ2yUvA2iEgUt/zso/YxDRdSlue7nDmYQhMpWyCJjoCsEzBfU3+CHOlK+Qg7FKHZleowDb0jhu/nLT6RUiz5bMhBLXeO90b/Z8KkTQRT/kxxQJw29hyu1RhQa6NNlecJ2wSVWJyKUP/jAW5Kiqbd4hhPrXajyHv0/lDfxbm0HkLzKP+n1SSM2KrN7v0JB3QICU4jmlAG5z598+FRvOnlwRDSywnNZeFtplxfFY8yYyRgQXOZtYryi6c2Q89oufRwZS68BZtSOESnAY6ZnziqzrsLVjc5zUuUXNQOg== 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=ksF652jkj0H+gVQIly5PpnylBV9Mz7gsmo/SYfg2AAk=; b=JU2Rlt/gGAhiCHG/127cqotu6VpYt4jRd1NyTsX8+uDme+9BQ5rbBUdxVocy+Um3Tp06FoBTC1tj3MrxvXxrUfcu7LrU0GjZSIbpswPxRIoZkfa6U9Bgt2e6fT4CG84hB9xjObDt0RwXs15xWL7GYn+iclvG8cXiNV66zOfiZ38= Received: from MN2PR03CA0018.namprd03.prod.outlook.com (2603:10b6:208:23a::23) by BY5PR12MB4872.namprd12.prod.outlook.com (2603:10b6:a03:1c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.34; Thu, 5 Oct 2023 18:17:20 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:23a:cafe::f) by MN2PR03CA0018.outlook.office365.com (2603:10b6:208:23a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.36 via Frontend Transport; Thu, 5 Oct 2023 18:17:20 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) 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:20 +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:20 -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:19 -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:19 -0500 From: Vikram Garhwal To: CC: , Vikram Garhwal , "Peter Maydell" , "open list:ARM TCG CPUs" Subject: [QEMU][PATCH v1 7/7] hw: arm: Add grant mapping. Date: Thu, 5 Oct 2023 11:16:29 -0700 Message-ID: <20231005181629.4046-8-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: BL6PEPF0001AB4E:EE_|BY5PR12MB4872:EE_ X-MS-Office365-Filtering-Correlation-Id: 158ff665-8502-45a5-33e6-08dbc5cf509d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N7RAjEjLnU/2LSkwB+ZtOvuPP3Sbzy2Dek9LBer8nc9aIMNRFD+wmAg3cs7SbGs7G2Vscb9ctyteCY84jHXLDFeUEUdV7iexRgIlIyh5/w2Zz3L6WOIIWIUUWwY0MdTO0h+nBZZhENYUzPaCKy8APXyDBtwvKHl1iUFmK2YfRKQbCDoYgvQGUl6ByvcqtomnxpUZoNk8ZHQzgDOxZddqasJxoReGZZb7uKhqfqnzyVo17atDo/uya+pJzk6I+fhiQ8zYhD8cU4FI/Nk+JEK3xaaPeeZ5wvWIfgLUfPOudTuOcMGneDorb/jC5bgigUh2gOMyeNEcQYTiwshmxTVWnh8US0mrQ8noJmRPqhBruV7HDOHxPQSykeLUZPUUxQfXQbKhevWN33W1lAAoOVYQPc7cKD2OxJzgcZDVW+fJH/3//v3cOXwpaa8Wg9o56rriASgSfr+kVF8D8ZbVjEW3yfUscfBUqnu0P5pZOOKiLGsLTP1u9R+TNgcTQzMpIc1jf21SxbDvSHeENu/3lU6GxqbyRzAX0J5ZmLR3je1e+kXT0bSXrOJeP/ikbOgmayUFEfV4SKFlA81vpwQGtcJbguxMAbHjc9jbXgizFUUNmqTBA4WvJr1JZWn2zpIbgmD+xpiJK4yVxaLbFNFjxQjTHHqC+KZ7tKNeVkkdASeQcMN8ZlgK06nzHJUIQelBnmGZuWod5JKynlgs2gZZLnT45bYTDhbBq5KfMmo0CXdn+ziaFZPIOQqh19rZkqxQ81TCgFjjUyqxYiqZA+bvnD+Jig== 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)(396003)(346002)(39860400002)(230922051799003)(1800799009)(451199024)(82310400011)(64100799003)(186009)(36840700001)(40470700004)(46966006)(2616005)(2906002)(1076003)(6666004)(47076005)(336012)(426003)(4744005)(26005)(4326008)(54906003)(44832011)(5660300002)(70586007)(6916009)(70206006)(41300700001)(316002)(8676002)(8936002)(40480700001)(40460700003)(36860700001)(478600001)(82740400003)(36756003)(356005)(86362001)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2023 18:17:20.3971 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 158ff665-8502-45a5-33e6-08dbc5cf509d 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4872 Received-SPF: softfail client-ip=2a01:111:f400:7eb2::602; envelope-from=vikram.garhwal@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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Enable grant ram mapping support for Xenpvh machine on ARM. Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini --- hw/arm/xen_arm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index f83b983ec5..553c289720 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -125,6 +125,9 @@ static void xen_init_ram(MachineState *machine) DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n", GUEST_RAM1_BASE, ram_size[1]); } + + DPRINTF("init grant ram mapping for XEN\n"); + ram_grants = *xen_init_grant_ram(); } void arch_handle_ioreq(XenIOState *state, ioreq_t *req)