From patchwork Wed Oct 25 21:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436828 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 E9EA1C25B6E for ; Wed, 25 Oct 2023 21:30:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlRq-0006XJ-At; Wed, 25 Oct 2023 17:29:54 -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 1qvlRk-0006X4-6R for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:29:49 -0400 Received: from mail-mw2nam04on2067.outbound.protection.outlook.com ([40.107.101.67] helo=NAM04-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 1qvlRh-0008I8-Tl for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:29:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LR6H8GH8Qh4HsvZO9PMqZvjcnbNnevZK8FgMsbNcnOSpkKpkSyd5IfUVacDVJmvYp8XjXV1eB53woxQP+k1kiSRmecOe5a24k7GlhkFjodLgS0sPaQRAe+OHgtEKYFugHdzk19c1zEG71MewGukfEsmAUc8uRHtPIAyQQrJgDwqdRB65NwdUG4/1A20x1w/agDjbZPa0p+ojA+LuPxQjl/EnMrs6J6nrGtXuBvx16/dhl34VzuqKYEmJJazMWpIBbiw9dve3kBScXfWUP6SGSD3x82h+kctprTYZ4F8ZxuhWiB3pEjVB+ZxDfbB9EedxtZSavxctnKgei8Gs7OnhwA== 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=j8RBc3mGaBZEzIDWAq6TaBKCLaPuj7qNGyoRNGoAD/4=; b=nENxdoUCU65ttVFbtpQEwGemXjlD7lMx6m6DISKmvScNTvHKeoa2fRjBu8hkuH1yGBpl9q1s3wxoE6Ehq/iBlZSU2rwo5u5LH00h5KCCV3I01QUsb2V5q0xZV/CiUeVQ7aF3qQ3lMM99ChJDhIDJgcqEAaeInV7hOYYJATYa7u+5OcWhfsxHbN6/lOv1tE9L91naGCC8UVeJEiY58Pgc9rVd9vUPbDBge4su5tCmvRzYkLLOsm4AP+k0mPph1w4tnoCodRwqf7yDOPWNeALNpbvpW82fEj9DfMoIl724T4eaNmDFrKh/Q/H0FUrtn4B8boqSOF/gVhWPaZJl+xJ0XQ== 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=j8RBc3mGaBZEzIDWAq6TaBKCLaPuj7qNGyoRNGoAD/4=; b=qQLwOnU+jhYD1B5eMvi8CHTbxjuU+wkYBNabiwajM3AZz/fh4e+GehwEdTWKPnNFijehWwGeCJYv8PQcVpxbpfzRltYPpPhfu5yW9s/U815O3HiFAsjCZ9AfFpsVvYiz2Jvm5GwRZS83d+um/MdBWZwtC7hI5BMNr0+n7tbSv0s= Received: from DS7PR03CA0284.namprd03.prod.outlook.com (2603:10b6:5:3ad::19) by IA1PR12MB8539.namprd12.prod.outlook.com (2603:10b6:208:446::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 21:24:39 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::4c) by DS7PR03CA0284.outlook.office365.com (2603:10b6:5:3ad::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Wed, 25 Oct 2023 21:24:39 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:39 +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.32; Wed, 25 Oct 2023 16:24:34 -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.32; Wed, 25 Oct 2023 14:24:34 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:33 -0500 From: Vikram Garhwal To: CC: , , , Anthony Perard , Paul Durrant , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , "open list:X86 Xen CPUs" Subject: [QEMU][PATCHv2 1/8] xen: when unplugging emulated devices skip virtio devices Date: Wed, 25 Oct 2023 14:24:14 -0700 Message-ID: <20231025212422.30371-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DF:EE_|IA1PR12MB8539:EE_ X-MS-Office365-Filtering-Correlation-Id: a7cb8ff2-c99a-48d8-f8d9-08dbd5a0cbe1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BmPxWzqta2PVUfu2JYM3Ka1NYG0qKeB+L1G04k2pLKcVRlFcfApsZwwco/LIEaYLAQJ6qb8p+h5ILXz/Xh+FWj1C8Jygrl5FM5TuCFhsjLiDl2fHLXG8F2nUicZl5/XgNpzjUU9OrAcMaRflxozacWZzgXxGbfX+jtY8/gnGx3IjYgSBcij5DqxJEfnYP3JwdwUtePJ+gsaVrmv/kLdXxT3/wCg9KKEoplxqPKldut7hLm132ZWSnSdt0U2EIw/vXNtluwghZiWYh+EsT4Cgerr26TjJks/1gQcenMhl1VEU76xJ3RlDQD3Mq4X7+0nUWZa3hpS+42AT3EOnr91wgz9eBf32/kqXHo1362YCyG7iJij8amHQo8zciIGR6P7WqnulA/Oxl7jBbTjBkD0CDYq74yWBV2oMwQSeZYBIJQlWpZq+umZo+V8hD9PaO/dhZ7Alt3urt/OhhNauE+NahmMDu8fYT5flQpGFlondL7gIBh1xWZCINU7lRSUM8RH9SafeKFSjVJkA10vhPOxnWttLr9uuDXsxc+q8XE9Y930M2gWS8lwPr41ATLXdAN72+ZNRBL0vvLUiK+aaYa1RWAZlHjoUP+V2nVvOLExkrzFvyMq7F8Shg00WBVOd+9UPl+KegYS2JL9FWYV/w53NP5djJgplGIcxdse04Rtj1nY3FysMm3DcApa2JtE+FrurJOc9V5TqlKP7petFit4pyvf4UumD4VZDxi/hFy30FZWO2XJVMIb6iicwYJcV7/yBPBB0E+YuvTrolmIkgH4aPw== 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)(136003)(346002)(396003)(376002)(39860400002)(230922051799003)(1800799009)(64100799003)(186009)(451199024)(82310400011)(46966006)(36840700001)(40470700004)(36860700001)(2906002)(356005)(316002)(70206006)(54906003)(6916009)(70586007)(478600001)(81166007)(2616005)(6666004)(41300700001)(47076005)(336012)(426003)(82740400003)(83380400001)(40480700001)(86362001)(1076003)(44832011)(36756003)(7416002)(40460700003)(5660300002)(8676002)(4326008)(8936002)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:39.3249 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7cb8ff2-c99a-48d8-f8d9-08dbd5a0cbe1 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8539 Received-SPF: softfail client-ip=40.107.101.67; envelope-from=vikram.garhwal@amd.com; helo=NAM04-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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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 --- docs/system/i386/xen.rst | 3 --- hw/i386/xen/xen_platform.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst index f06765e88c..b86d57af6e 100644 --- a/docs/system/i386/xen.rst +++ b/docs/system/i386/xen.rst @@ -52,9 +52,6 @@ It is necessary to use the pc machine type, as the q35 machine uses AHCI instead of legacy IDE, and AHCI disks are not unplugged through the Xen PV unplug mechanism. -VirtIO devices can also be used; Linux guests may need to be dissuaded from -umplugging them by adding 'xen_emul_unplug=never' on their command line. - Properties ---------- diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c index 17457ff3de..0187b73eeb 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" @@ -129,10 +130,11 @@ static bool pci_device_is_passthrough(PCIDevice *d) static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) { - /* We have to ignore passthrough devices */ + /* We have to ignore passthrough devices and virtio 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 Wed Oct 25 21:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436800 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 CA0D0C25B6E for ; Wed, 25 Oct 2023 21:26:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlN4-00073v-1j; Wed, 25 Oct 2023 17:24:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvlMv-00072t-VP for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:49 -0400 Received: from mail-mw2nam12on2060b.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60b] 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 1qvlMs-0006TP-AP for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oBSAij50Q0XM+m3VRN8g0AA4lY1U1odbJAFevWSwNf6xfaiElnm89iuI4jqd4+OZIV0EfcXe9beaxQbUcRcZ3V0AI4ELlOd4uHBDjGobHvJXPelygcvQL8CMSVnEOqIxP4wnbc9QAbIVOyqInOG7IEe1hM4S+SzO6DlHTt/cig3BrUrt82phsK4msSgZ+lA4/z80iRj8C9tRIo9fMjpFbs0Usr63PpWgosaqjVISNdjGSwOlGBX6lkt+oczB5cd5FMWzbpYKb+LiovFUHHxBRQcZW5MgpgQG4zbdIheHPLBJp6ljG5sxz6qxHcbXnLizXqPXG1wqCBb22geGdiUvTw== 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=lwEQqo3ga6htNQpKW4efEVRt35ya5qOkvGV8p5I0w9E=; b=KWk8Cbqw4G/w9QogcCXNBLNAhxRjHWnHLQt0zjDZnC2wojNlSeMPcPlDn58sucF59JClE26UgxEjWevb40/9X0/E7Qc5rIXuBVRf5lYTCm7LQBkcauIBa/LYDjB4DTGh61pb4wjsPoZJJipb1xvxwsGXRIKNJXUMxzdvlOh6x1YTEnDTSj2d7dNgEsc4KuDZN9imynOnjeALx52CDI5asZHhnbvJn5EUvfqZ80xUoQkLo6FYappPztA+z8CwVCUHNe3rPJKRcyMCy+3Wiw3RrvINCnrgMoLFGIGd6m/VsUXrb/rS7BU1HSx3c+AuRE8YVfEegRADiikWqjCrt9OXBw== 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lwEQqo3ga6htNQpKW4efEVRt35ya5qOkvGV8p5I0w9E=; b=HEq1CQzEiMXRwQbxVR5bu7d2lkFbUQ+aimezM9d84cQC/Ip0RPVsfHypLUE39cMeWtJDWpdR0+RdQKurSxL5K6nvmg8XoJVzFYYSlqgK3TjPk9tJb97kEYslyieBlXqq1mwxhELLeUXNNqf/8zeDYMf6Z8aaLSVtg+CFgbV7XIk= Received: from DS7PR03CA0294.namprd03.prod.outlook.com (2603:10b6:5:3ad::29) by CY5PR12MB6573.namprd12.prod.outlook.com (2603:10b6:930:43::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.29; Wed, 25 Oct 2023 21:24:43 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::34) by DS7PR03CA0294.outlook.office365.com (2603:10b6:5:3ad::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.39 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:42 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.32; Wed, 25 Oct 2023 16:24:35 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:34 -0500 From: Vikram Garhwal To: CC: , , , Paolo Bonzini , Peter Xu , "David Hildenbrand" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [QEMU][PATCHv2 2/8] softmmu: physmem: Split ram_block_add() Date: Wed, 25 Oct 2023 14:24:15 -0700 Message-ID: <20231025212422.30371-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DF:EE_|CY5PR12MB6573:EE_ X-MS-Office365-Filtering-Correlation-Id: bd1a41ff-db50-4b6f-6999-08dbd5a0cdfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /q10mZYJ7yPTYB9hx2uXeVLMTEH2ph9f3aCI6tXnU3umwH5ibbYLfDeNQvLQl6UtBRr7XnajghWsbEp3uAabbK/sxwdQqOKO7ACGgXauaILTHcXs041UzeI0zhYOW5bT5Kf9J5gjLXhj/jBHDVzUPMz9+NGS3gLVF+vRQNL7ReYZfxgSHQTaHzkeEjWtEUbD8jRrQ0glnnNmgTKDLvVz+8qKY0I4MNpKQ3AxYVLqt3wGhGX7C99uGI5+JVJx5N4MVpvSoL+jlD8n2GCIVe4gDdw+UQShupj3Cjm0C1LwbtxQkXBLO85R98px1aQPics82xJ4rJljgH82jtC5JDqF/SNFtch+xuxs3v4TuNZrSfoegsc9QS+3CVPuOn1rwpj7ctIvtibb1+LJFgS6jOrEnHt2TzsZtC/7oUPLBDm8swNHXH7rpWBBdX+Jv2/e5n55bUxcjSP5kmNhn3Pod7/5opyGE0XnM42kSD/fPC3c760GZPcuAoO2wc2rzNa1IvcYSeKcJ3vT7p//1I1y4cK4A7IpgdtmKJIkGPw7TPyLQ2S3i2fuHRfvejbXaaLs83EFAXSxW2/9Cw4BDA0UZxSgcOpZ/Yh1a+MNctJd9XJE+oYHHeftpknROknjLUT+DsbdJZAcryha+JuRXZk1BhEtIJfdAHcLKrsulcdTrxTbWZNUKYeN/KoCXk2/g6JX7aP+gtU/k/C8IjeII71UJgHuWzjZR07QiE390468fX/CHCOz1ykxr5byS74D+PGSrtyIpTYk7+ZP4OuT/yqAvrZgNg== 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)(39860400002)(396003)(136003)(346002)(230922051799003)(451199024)(1800799009)(186009)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(26005)(2906002)(41300700001)(44832011)(5660300002)(86362001)(40460700003)(4326008)(81166007)(316002)(8936002)(36860700001)(8676002)(70206006)(478600001)(1076003)(36756003)(2616005)(6916009)(356005)(70586007)(82740400003)(54906003)(83380400001)(336012)(426003)(40480700001)(47076005)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:42.9187 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bd1a41ff-db50-4b6f-6999-08dbd5a0cdfa 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6573 Received-SPF: softfail client-ip=2a01:111:f400:fe5a::60b; 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 Extract ram block list update to a new function ram_block_add_list(). This is done to support grant mappings which adds a memory region for granted memory and updates the ram_block list. Signed-off-by: Juergen Gross Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini --- include/exec/ram_addr.h | 1 + system/physmem.c | 62 ++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 23 deletions(-) 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/system/physmem.c b/system/physmem.c index fc2b0fee01..7a7f95b8b9 100644 --- a/system/physmem.c +++ b/system/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 Wed Oct 25 21:24:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436801 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 AA8E6C0032E for ; Wed, 25 Oct 2023 21:26:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlN4-00073y-13; Wed, 25 Oct 2023 17:24:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvlMw-000738-6N for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:50 -0400 Received: from mail-dm6nam11on20626.outbound.protection.outlook.com ([2a01:111:f400:7eaa::626] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvlMs-0006TW-OX for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNHzO9TyKadNN4QBBREyhymOu+T/Y/ljmaZLCrc+U4Ej4XzayaXJ1i6FecbbQUnW4lqqHmIkmdzVoYCO4UpJvY3oQlZd21l2kKI3a8k5ArZg+ZFnpXiZVfZkbMtjGaufMhyo3tOnnzyz/cHUFHJIOYri3ttYsPr6nqKgYqxfV5Rf1M70+fjh4donHPk57YDaXjIJZYDMIKdN/CldmQt0IuDx8n1a9ekOSyNwcwJgbNvQWftVifWPJBlLwlymSYyB8vUQqkA+tDj8AssTFhm3hucs5mQVo/jg9GKiUI1LXpCtQXNmY43PKv1tYuJJJmr9wipuGyZ98YrJ8lQk9zi5rg== 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=Ut7Scrh7dAWVSwNqnu8r7sO55DGW8qB7WwwfhcTT7kA=; b=aQMN6hWaQqf0VxKaEwyXQJiuabPme8anIA1HIzIA0inF7m1OLwVqNTCadYl/kzbHJsFSssOlecKLytoXrHgY4ewe12hOMulnTHYoRKbpU33Y+/amwtP+3gvQeZZlpgogRM1Cf+tDmVxgCFdchCMR3WcKEWPzPJb/068R5Ooj5DlVnOAAo8J5AxqeQBfMjeD+4Eku8BvuFG6w+vjRTF7zcZYGAk6s/JyUcmqP/EQwVlKYSzkelZPe/UyGmJaQQPBiBVK7Cri4OIPMG6dA1U4dgBWg2AxldFYhdVbkidvS98gTtNw/gQAOsddSr7PTmwAqSJTdInMv0sfrTwzKxp20Eg== 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=Ut7Scrh7dAWVSwNqnu8r7sO55DGW8qB7WwwfhcTT7kA=; b=2o12FFLUsQvSTs5van85adZmy333PZR6n9L742jWG/e8dmRZ0RpolXWeyzONFFAcEs9YQTcN+6QG/0NBFIBrRhkzz43o2EXivBrz45s/KfIgEYkV0Q5fhwtsv0V1jKaE/R/PAQGCKEU+EGoLN/QIbtGedAig3ylMb/ZE5s3XOLY= Received: from DS7PR03CA0276.namprd03.prod.outlook.com (2603:10b6:5:3ad::11) by CH3PR12MB7521.namprd12.prod.outlook.com (2603:10b6:610:143::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 21:24:43 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::94) by DS7PR03CA0276.outlook.office365.com (2603:10b6:5:3ad::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.32; Wed, 25 Oct 2023 16:24:36 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:35 -0500 From: Vikram Garhwal To: CC: , , , Anthony Perard , Paul Durrant , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , "open list:X86 Xen CPUs" Subject: [QEMU][PATCHv2 3/8] xen: add pseudo RAM region for grant mappings Date: Wed, 25 Oct 2023 14:24:16 -0700 Message-ID: <20231025212422.30371-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DF:EE_|CH3PR12MB7521:EE_ X-MS-Office365-Filtering-Correlation-Id: b82c8f39-c33d-4f43-1b3b-08dbd5a0ce49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PEQAVun/RHDzu01SmZbK8teY3/In0sqKYfSrofRRPwlajAUwd7Hja0RI27fkyOfJKxgbFuirYIJmrJa8GArREyLUPfBKzid9paMQxGP1NJAwuoKpcFyrYqDvmHGnnQrYV+uqLDZLE6Cg8BS2yPZCxaZN/bPhaqtSA0pfiQJZcLrbg1xUXYZZcO2gparTQqiYi6MEVHXL3qpTWLg77q0MkuTKmkqP9z+sKzOu6j6C+f7i48ILA6BA+cwsoFKqvAq54GJySsgotECj1j8mCpJNgX3DbSlwTCNk/ePoTGFpNDT7Ob02U06z9Nc0VU1uGR46jwcqsL+aI9VpUpOKw49/Sa0rah4NrMSe25XK7PRh4d84/pzErJZNuW4gZwcLpfMAQunJ+f91Doq2uqxcO/hL01rVVNw87pF9BiKFe8hF83gpA4wV8AahsSW4aNu5N1xE7s1PSsG9bgorDo8eEzBjCbk2jg3ForMZk6B+nUKLALwf2FO20sDdzVBiXiaSnJjZgru8cdMjbquZ8u/ZuX5AqDGqNEWL7zZHRZKbg6FcTbvXnO2hVOuLpqb0GPgkto1WzOr8HqJH81NyzSk1sCcYj0RGvHoOtjEsGfuBx3lXxVFKIYdq1HvT9zGrvg79QeXMdaCst0w1WzkZVnotSBdRya3i8LBtiX9ZVSsvg0GIZpLoX25OwZAptnde6ugbe+r0UmSVjmXoFx6vOxHzRyurtdE+zF7YyhSFwaFN3wYYyM9HDA+fjlO3wWeeTvZ6flp84zuaXj4oaZ0m9NfQQFoLCA== 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)(136003)(39860400002)(376002)(346002)(396003)(230922051799003)(64100799003)(451199024)(82310400011)(186009)(1800799009)(40470700004)(46966006)(36840700001)(2906002)(44832011)(81166007)(36860700001)(478600001)(70586007)(70206006)(356005)(316002)(1076003)(6916009)(47076005)(40480700001)(336012)(426003)(83380400001)(54906003)(41300700001)(40460700003)(4326008)(36756003)(86362001)(5660300002)(7416002)(6666004)(2616005)(8676002)(82740400003)(8936002)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:43.3718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b82c8f39-c33d-4f43-1b3b-08dbd5a0ce49 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7521 Received-SPF: softfail client-ip=2a01:111:f400:7eaa::626; envelope-from=vikram.garhwal@amd.com; helo=NAM11-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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 Reviewed-by: Stefano Stabellini --- hw/i386/xen/xen-hvm.c | 3 +++ hw/xen/xen-hvm-common.c | 4 ++-- hw/xen/xen-mapcache.c | 27 +++++++++++++++++++++++++++ include/hw/xen/xen-hvm-common.h | 2 ++ include/hw/xen/xen_pvdev.h | 3 +++ include/sysemu/xen-mapcache.h | 3 +++ 6 files changed, 40 insertions(+), 2 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/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, From patchwork Wed Oct 25 21:24:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436802 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 1CD1EC25B6F for ; Wed, 25 Oct 2023 21:26:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlNK-00075T-GQ; Wed, 25 Oct 2023 17:25:15 -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 1qvlMw-000736-6F for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:50 -0400 Received: from mail-co1nam11on20630.outbound.protection.outlook.com ([2a01:111:f400:7eab::630] helo=NAM11-CO1-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 1qvlMt-0006Tc-H2 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PEZATQRSOcF5kPP8Ph6nD78U3zGIo1hmqn7ftWqfofeAG/y+he2yc+3CXPkIITVcKzIpwxhOPQbYOdAl8PX3jEgEy8J3D5MwbtLcD8Tr4MzrR3FWuwrOPrCzwFZY++TBsffMzUWjuscL7j+IZdOA01P9mHiOea3CrY2EteBwo4C6HyXoxsjjoZEsed2x0Cgdy98PN8y3LVLqUZebawZgMhEOYxU4uUChmX0FsosKufOv9mXuuEETdA/v7MOdkKHXDze3PLIMg5+nqdVHmVv0kbYo8iqmRdZM2uuKF+HiClHiuN9j5WGkc+Vqrp1lt651HA55kBHnpRo0wJL8cDYYrg== 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=6cqfNUm4hsSUdVDsdLLwALon2+gIu1xBwgNlKjxMGTc=; b=DNQoLHUAXG7nrJNvHOIH1zTMnWi+bckUBRiHfh+K31ZO699YdQMnmfBw6bxoZVQefzkEQJcOwp9Sc/XNU5SPSbq+attvtefE0gF1PZse//JTD7o3TyhlBFvxUiKMCEHb7hxKk7r6vkb68BbOAvFI+pnMXSpDonxEoaE/7LNSx/mFhO0hckk1DEXC4BITnvMmVGCrbrtusQeJlAsjeSzomC4UWeQgIBEIeIDkd4aTYZthy+IpWsKtuUxcNUcPHDjmlBi3AluEO57ioh0FLE8eG/TTlzRDxJjyhfahpEm1sDr2MkODosHRyoirI6aO03KJk9VpEJNF4PZ2polKC3cOqA== 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=6cqfNUm4hsSUdVDsdLLwALon2+gIu1xBwgNlKjxMGTc=; b=pRPavyaALFfTDlrP5pusP7Uk7PwQCh8p/wjUwFRhfOrd6ukyPuOsg3/PMOt2yDHZgG1fjt7V9MkZERE7yV5e+uhWypCOb2iqtrrLrnc138fXarEKX9D4BzU5wp63xBpyiZvqwwuiGi1A/ED3DBqFclsYBPgJ4iWGf/bXQAlAfcc= Received: from DM6PR03CA0066.namprd03.prod.outlook.com (2603:10b6:5:100::43) by LV8PR12MB9084.namprd12.prod.outlook.com (2603:10b6:408:18e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 21:24:43 +0000 Received: from DS3PEPF000099DE.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::80) by DM6PR03CA0066.outlook.office365.com (2603:10b6:5:100::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +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 DS3PEPF000099DE.mail.protection.outlook.com (10.167.17.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.18 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.32; Wed, 25 Oct 2023 16:24:37 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:36 -0500 From: Vikram Garhwal To: CC: , , , Paolo Bonzini , Peter Xu , "David Hildenbrand" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [QEMU][PATCHv2 4/8] softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length() Date: Wed, 25 Oct 2023 14:24:17 -0700 Message-ID: <20231025212422.30371-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DE:EE_|LV8PR12MB9084:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c66cc2b-634a-4ff1-8364-08dbd5a0ce52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GwMvYrf2NEGWJHiP59SeX4Do9gSqau5yJCF34BMl22mKc29HHCuvXywCjRqlFr4W704iWX9hY3Tq3kQcBcoVRG43qprtzTRYlq4yOjW3m57N2ibUlmCJ2I7kOFZntX363TLtx1nnXH7tlqXWidVZjnhDrj4apytufhKVwVJ62KKuxVed4DYRlYCzUpa/c3BwssrKbRCINpBvC/fzlWldr5+4RUH8AbBgSQgd5yHiB95AsOf4x2uMf4+g8AMKduZg4WCs4A1XkbUGxN0Igcdb6nQTdj3RGl0xqKEvGB8geR3eV7znmyTu6H9PrnRltab62JRD0RLjP8Lyi+sLS43wNHjDT/6DbmAx/r/tA4oO1h1gzOOsvIMRO6pUmjqZp1jF8YxzhXP6Wgd+nU16VEayUJTU4TFpEnyXWLwSbdr1Ij7v2Mh1kkpBkEzEL053Ucfr+iSt/cd0f1s0lpvq6bZ4Yp5nKYGtIUJGBkuzlJRjECAAM2zpn6K7UGmm8L2/FxjISGaVUbup3ePciDHQjW74AQuR7zC0SJFOEcak3vztO/d3meCDrZN23wi0Z7x1boRQbn4FAwx4kUfNO0uXtV5EVlTDrMgy+DjPYVYIlpffW1FqmfIdswCaThmVLoCZPn4UMyshjbmFzgFXAD88VhCh2gmSsXXJX7Q/jYo8XnNiAn4PIiAjYGDugG2kfYceplAxTPo+kP7du1CDKPST6H85T2yODF3MY/ojHWmi9BaRUdn5c/GtEuWRFz7GlNw99rgNpjKyAc26ZTm01ZWeFPhiaw== 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)(136003)(346002)(396003)(39860400002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(82310400011)(40470700004)(46966006)(36840700001)(36756003)(2906002)(36860700001)(316002)(81166007)(478600001)(82740400003)(1076003)(356005)(70206006)(6916009)(6666004)(40480700001)(47076005)(336012)(426003)(83380400001)(41300700001)(5660300002)(44832011)(86362001)(40460700003)(2616005)(54906003)(8676002)(4326008)(8936002)(70586007)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:43.4336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c66cc2b-634a-4ff1-8364-08dbd5a0ce52 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: DS3PEPF000099DE.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9084 Received-SPF: softfail client-ip=2a01:111:f400:7eab::630; envelope-from=vikram.garhwal@amd.com; helo=NAM11-CO1-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 Reviewed-by: Stefano Stabellini --- system/physmem.c | 58 +++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/system/physmem.c b/system/physmem.c index 7a7f95b8b9..667a695078 100644 --- a/system/physmem.c +++ b/system/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 Wed Oct 25 21:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436799 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 B7987C25B6B for ; Wed, 25 Oct 2023 21:26:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlNZ-0007JH-O7; Wed, 25 Oct 2023 17:25:30 -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 1qvlMx-00073x-I3 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:56 -0400 Received: from mail-co1nam11on2061d.outbound.protection.outlook.com ([2a01:111:f400:7eab::61d] helo=NAM11-CO1-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 1qvlMt-0006TY-HI for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HUzVRk8IJpwny3AyZpJiV+E7xu124CDPe2cFG54n9/stCYaP+u5UdG1JBC7hKDjKIj/8LYQaZu3ungmZ5kX3V6XYtCK6x3IsViZwiAk8N9eFOA6wPoC1UzFD4Kr5UIX5wdBo6Ku8AQn7XB8dtTXYnwK4XG2YyE1JYme/8s/Zzuena5mHVqh/tNxRVPiArenrrD2649ErILgcUbPEwrQ1M9U05XOp9rU8/e22VJDS5yNoIf0gFCoGFNmQQEOybv4CuBtBOvLPw6QUHaio0umcAGD7mX/ZzidxmFisr9hscrKTK3A55xNz1Q8UMYUx45/dBrWDm35ZZGS9GuxRM33kjw== 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=mET7kcl9UXXPRp5J6MoXxeoteODqvxROwm3Ecdt2YHM=; b=L54Gsgu9lvYQuOOiRH3Lnd4vuIckJkm63+8Wh8ADL0G84BGqZ+iPu5V9ymyC/QOWjiTpjoEdKG4FacfqYa37ox8EvzDLsVXGCXXtnQZdX9DaDQNKC9ct3o8IZ9k9jphKQBzx8HKzii9rXx9I5G++5gQDDfwKvOADQ3G9ICCIrqmppfP72j1GxAbbmMcuQd+sGhcFxVbQZ11nL86fZ3MNWK+4mh+RGX/Ts5w3ItBCmYycEdhMflVHNxGtVeRViz9u9bFg0xGaQJx4UfhUWfvGw8tLzzvjI8QYMg08FJmog347VQMdnlz2xwmghwGd7ZbXtQSLv1Y4w2S7MeRCq93IKw== 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=mET7kcl9UXXPRp5J6MoXxeoteODqvxROwm3Ecdt2YHM=; b=LPKxhpH3He1LUk5nz5kJkkKDwXxyR2IkcDmHfhH8BeSDxjm47uqwbstdvzEgXSBVtPc5s06MPVfjKIqVuh7EAE90RJw7m6J2Hd1jNwxbbuGtmP7Z/NefpGegWCtOUH+DImPF7zY5FvlL7B7tSHAbuiaBLjmyu0WuU0YEuETLfow= Received: from DS7PR03CA0293.namprd03.prod.outlook.com (2603:10b6:5:3ad::28) by PH7PR12MB8015.namprd12.prod.outlook.com (2603:10b6:510:26a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 21:24:43 +0000 Received: from DS3PEPF000099DF.namprd04.prod.outlook.com (2603:10b6:5:3ad:cafe::50) by DS7PR03CA0293.outlook.office365.com (2603:10b6:5:3ad::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.35 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +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 DS3PEPF000099DF.mail.protection.outlook.com (10.167.17.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.32; Wed, 25 Oct 2023 16:24:38 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:37 -0500 From: Vikram Garhwal To: CC: , , , Anthony Perard , Paul Durrant , "open list:X86 Xen CPUs" Subject: [QEMU][PATCHv2 5/8] xen: let xen_ram_addr_from_mapcache() return -1 in case of not found entry Date: Wed, 25 Oct 2023 14:24:18 -0700 Message-ID: <20231025212422.30371-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DF:EE_|PH7PR12MB8015:EE_ X-MS-Office365-Filtering-Correlation-Id: eb251ac1-76e0-4082-da4f-08dbd5a0ce6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sBM53jdzwRhG04qo8BJM7dlxyvUqIZpGeYp5zQq+HPm6t1UAJYh4X3NDFrh9tShD87nZ+KfOqgwTe6NCP7uKeMcCehVd/XrhYgv93sdHeQpfX6OsnjuJOtnVsyACsgZhOY8d9Z6qCYd4xKDjOXY42rarB4mXn+S6MLAkfERZBpFcSDxbKOv/voegP80vadrU7VNlKsduMzF1Pe10ynMUXrEePbIiAsM9a1SuJxcy41Oiybz+Sl+fS9orHYT8/SmSm6YwhdwFspctKK9mHeqaySzW1DJSedpL0ENAOQ83jtp9j4cPtAFaaZvIwDK9VKXU50EQwjeMfZYykLB3MhNitlnB9nKfHOmzk8X5/ntvS/5OIBEfvRTy8gt1MkbGPosbTWgw3pRlKXoOd9MeF6IqcCt2jO+sS8kAOKpu2XFsSUvlqb34KOTl0Uy+QqsJLUG/zEAmG8aMNu332FEik0VhiRjoNVkY/pWGI1ilOt/ZhVOpMSn1UznpecgQ69HUWDDpvr3mxlpzJrp1vNi4TcEuYfNS4BUe6uQn/rVs3h6kIpZCYieFxmwdN+As8eKAKoPrmjAZ/jBEc+irkh9LjzoNMgqDg4pLgc79tevsA9osOiFiQvVxc0PrQR/rBxdVDXAr0TqUP1LEiLlJDkdDhpscRRE6ci5r5DxqRDJF3h7/LFjklGlUDRNz4xoRnSzpNgw1gZ51mY6qIvSue7KgFbzuBD4FjEDo9/9ptxK1OvfjNDX0n3Hf7yzK/u6A2zzlJUtEp6Q4aX2qijOv3y40LQOdFw== 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)(136003)(376002)(346002)(39860400002)(396003)(230922051799003)(82310400011)(186009)(64100799003)(1800799009)(451199024)(46966006)(36840700001)(40470700004)(26005)(41300700001)(2906002)(44832011)(40460700003)(36756003)(5660300002)(4326008)(86362001)(8676002)(8936002)(478600001)(2616005)(6916009)(1076003)(36860700001)(356005)(82740400003)(316002)(70206006)(70586007)(54906003)(6666004)(83380400001)(40480700001)(336012)(47076005)(81166007)(426003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:43.5749 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb251ac1-76e0-4082-da4f-08dbd5a0ce6c 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: DS3PEPF000099DF.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8015 Received-SPF: softfail client-ip=2a01:111:f400:7eab::61d; envelope-from=vikram.garhwal@amd.com; helo=NAM11-CO1-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 Wed Oct 25 21:24:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436797 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 7203FC25B6E for ; Wed, 25 Oct 2023 21:25:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlMx-00073u-3I; Wed, 25 Oct 2023 17:24:51 -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 1qvlMu-00072e-Cg for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:48 -0400 Received: from mail-mw2nam10on2061c.outbound.protection.outlook.com ([2a01:111:f400:7e89::61c] 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 1qvlMr-0006TK-LK for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h/4j6Q1DDqM35+ymFmR1qgPauGtyMQhgSV/OcUVS1427HDOX/KKW7cGSq1LSQYqbKWPJCjoxGZbeODEcdosaWd+UtrzfJ6CIsZL3VRkqdi2bZqLFnWWjo9c7L0HKT33tLMc1OfEhvgYvuqqeWgcHOSe6KBZv8IiN1eizUuL2dO5y9EbEj4CMh7rpL4uV7rwm0cevvdkwk+19X9XNw3p7lJ8wqrYDDNPBrB9XUX9abPYyuqFWJnzMA2kODLtFQo0p43gLloupm+uCzvCE6evqYRPnMP6zhmpBU+jHbmaJd1w9Ke3YCxoU3S04iaRSNnqicT4INUth7XTutjcrahkkrg== 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=W+gsth6ujSqi5zNqKUIuI4TCVNwpCpWM/3+ygZ8wI/o=; b=PbHYEBv8+n+dEPxBn/9+Og+EWV2+U2Lw2KsxUckR7WukxfZDWmKPCa1zJpFRRNXjvfwxxpGqfGeXolI2gFzbA018CA8tj4EWFTHzCmXOhFMXNVaDgX2lWWSCiQ6MLSjKCQCcCs8OSDfWuylPZPZRtB4vc/jEfgo514EUOh4y7XYySJHRbE0kNz+1T6n/vnxgHTbSrLYn2RVZVRC4xjsO4ynHmhgH6fC1qpHCvkKPcTf9NO0tQosoTVhAtaRjItIFfP91U2ulZqAmSkdNCdGfEaHeusTqh/YcZqecH7FMfhxXp+gDD5PRN68HBtQckky/IHok2j1eGZriw0rDEkbMvA== 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=W+gsth6ujSqi5zNqKUIuI4TCVNwpCpWM/3+ygZ8wI/o=; b=He+V76Px+YazaiQXUscdAEE3IHFG0XKzMkmmlOrox1tRRK5Ineg8DextlFPYoerJSjL6dqvnwnmqeSHU8c6mgTpaIRSt1zfNq17stY9lsI7H2wZPBYYTXEn8jP9fkzovJvXXNK38XzXDCj8CbcqKxoz0C7h2a770Y2zkPgCq7pk= Received: from SN6PR04CA0073.namprd04.prod.outlook.com (2603:10b6:805:f2::14) by PH8PR12MB7422.namprd12.prod.outlook.com (2603:10b6:510:22a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Wed, 25 Oct 2023 21:24:42 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::60) by SN6PR04CA0073.outlook.office365.com (2603:10b6:805:f2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Wed, 25 Oct 2023 21:24:41 +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 SN1PEPF0002BA50.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.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:41 +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.32; Wed, 25 Oct 2023 16:24:39 -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.32; Wed, 25 Oct 2023 14:24:38 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:38 -0500 From: Vikram Garhwal To: CC: , , , Paolo Bonzini , Peter Xu , "David Hildenbrand" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [QEMU][PATCHv2 6/8] memory: add MemoryRegion map and unmap callbacks Date: Wed, 25 Oct 2023 14:24:19 -0700 Message-ID: <20231025212422.30371-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA50:EE_|PH8PR12MB7422:EE_ X-MS-Office365-Filtering-Correlation-Id: 21cfa505-d7d5-496d-b571-08dbd5a0cd1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LEgTHykEMENFg8KL5LY4B2CNLU1iByuYdXBvC43DbzFbuHkU/+fR5TTJxvoDaOIw6Ysu0fPKva1gv9BTnAJKHXntLl+C4TWij0Hou/SIerz9o9RMDgoWdKdbt0DJ6xlCol/Ob+7Um1h32RbaIWHezegTsLkDLFCRBZ9Ax55ZPd4S97G+BUQUpXHYgj3E9Qar9QH8UX9VRJcPNENoyJ1irRPGYqRv0pEL9hgIoFxKm8d8JQYwYE0Cjw/ZfTJJQZV6EazYdIjaGT8wlmDBjGTTKsSkuJTxKCfZC5Z3MrdQY2M0HGYQsBAOdzxPE0+q6qZkqUut5PVsT08CZHVUNtTvAha38SfqP+sWpuN8KITBCRdDj6t2T/Bb9qaFAXUvEADoXEzlKurQX119/Rb6cHEmcDpO4kEd11aizEK1d156ly8+KBq1t8t6qOk+PdKg4fHtD+m14x4UYZ/nnxuBrjmvRtMT8J+F3yh4rx2hUWgs5n6AKjSEZFnmJdBDdqRRImPjspE130U/HZGfWmUOwaN2h3lHzV2/Ijj+QRRAyFx1/lrNS4CZmrQT9xcIrStpAy3pd74Qm9mdYGbLDb55gJgGZEYaV48mCdNMXzScf3ewEkZbEFhiAu1kUbg4pv0+c/EGHCtFQCenJDMm3O9o3/9PxrE2Th8BZyqULrIp5QPNsz1vpWOYelg616hmGGqeT4CYQHOll6cqiYnld0vyF35dWBoHYGh9rLua/8Am/f5VTpb0kJo04Ldy1sbJCw6bR7UNmA7AnrezQuayD7U39ejWOg== 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)(346002)(39860400002)(396003)(136003)(230922051799003)(451199024)(64100799003)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(40460700003)(40480700001)(86362001)(70586007)(6666004)(70206006)(6916009)(316002)(478600001)(8936002)(54906003)(44832011)(41300700001)(2906002)(8676002)(82740400003)(4326008)(356005)(47076005)(83380400001)(2616005)(36756003)(426003)(336012)(36860700001)(1076003)(26005)(5660300002)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:41.4007 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21cfa505-d7d5-496d-b571-08dbd5a0cd1e 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7422 Received-SPF: softfail client-ip=2a01:111:f400:7e89::61c; 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 ++++++++++++++++++ system/physmem.c | 50 +++++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9087d02769..7c5444d46f 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -282,6 +282,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/system/physmem.c b/system/physmem.c index 667a695078..5db1b32823 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3120,6 +3120,7 @@ void *address_space_map(AddressSpace *as, hwaddr len = *plen; hwaddr l, xlat; MemoryRegion *mr; + void *ptr = NULL; FlatView *fv; if (len == 0) { @@ -3153,12 +3154,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(). @@ -3174,11 +3183,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; @@ -3251,10 +3265,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; } @@ -3276,14 +3298,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 Wed Oct 25 21:24:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436798 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 99B4BC0032E for ; Wed, 25 Oct 2023 21:25:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlNK-00075S-Ga; Wed, 25 Oct 2023 17:25:15 -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 1qvlMw-00073H-7b for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:50 -0400 Received: from mail-co1nam11on20617.outbound.protection.outlook.com ([2a01:111:f400:7eab::617] helo=NAM11-CO1-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 1qvlMs-0006TV-Q4 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 17:24:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AA+Dn7EuyK08jdrS8wUwKfGJQmK9ZduLdOaHEQSiP5yR1GFHM2XIazTq3tbGeOmqnjjWkdcJtumoR05/uMiT85nQgDBNw1Y9wlig6iiRXXidjZkHZX8OxhnY0L2BaH7Wp13ajPPyW3VJG4YS3sSg/UAyNM6KgytSOjFIh4bORbA4YP86mn1bL1MgEuoCqqVoE7SIa38lfLW3ZFRKdpFlUv54k6V2o02pv0PuEicGXvh2upvSeiJx3AzjncgqxRXYZYUaglcD+g5FP4JJD2uDw90lxdQAnqPhjt64TRSR+nB+mQr+jbeKFV1vD8cDjv2bfHvPilmCPYIKDukAx6Nr0Q== 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=9OdIgauYjvZTM3NEXeDJuUyyCuwPtaokUubGW/H/Oag=; b=kI95msU0wRhCZZB2E8iNEDeMtaqkBx3F/sTfYPGUkFcrI1Pom/g8zNRzkNClNt2a+mPs3H3+AK0M77Ma3mtuc9LLgnpm8yc4SBgi22/7RU4Ov2yG7vNCvW69PQGKgmrvLT018kL6eweWRC4C1TWjr2EEwPNyb+kDSKd2uzSOosh89HrUJwGyHcgTLnit+A2mygYqF6H215xuY255XYwIFi0DV4Aws4X5AqEbp9xlkV7JsAkcOFXs9rMDQwYgIgYaoQ3moJomBruXSFYPtq32ZwEhUgc+MFYCJVwTiZmcmkS0McY/8uSBtl2NxsmCJ9TytvTB2Yd3fzpt/qWckj5WCg== 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9OdIgauYjvZTM3NEXeDJuUyyCuwPtaokUubGW/H/Oag=; b=SWfdh0sYqpX8S5rm8t8jp006mVIZTWRcpdCIk3b2KLdLIkpj0iWZhzOz4cNy0Q7uexF7Nx9QJ+0Hx5zzWtyNs9mamjMnS43mW6QlYRH86B4jrnzzIlb+Fuxz95OMZwLxYRalVAJHEM6GmY9AW/2SQzFx/aRDslKvuQMfkdxaI4U= Received: from SN6PR04CA0086.namprd04.prod.outlook.com (2603:10b6:805:f2::27) by IA0PR12MB7749.namprd12.prod.outlook.com (2603:10b6:208:432::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Wed, 25 Oct 2023 21:24:42 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::2c) by SN6PR04CA0086.outlook.office365.com (2603:10b6:805:f2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33 via Frontend Transport; Wed, 25 Oct 2023 21:24:42 +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 SN1PEPF0002BA50.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.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:42 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.32; Wed, 25 Oct 2023 16:24:40 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Wed, 25 Oct 2023 16:24:40 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:39 -0500 From: Vikram Garhwal To: CC: , , , Anthony Perard , Paul Durrant , Paolo Bonzini , Peter Xu , "David Hildenbrand" , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , "open list:X86 Xen CPUs" Subject: [QEMU][PATCHv2 7/8] xen: add map and unmap callbacks for grant region Date: Wed, 25 Oct 2023 14:24:20 -0700 Message-ID: <20231025212422.30371-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA50:EE_|IA0PR12MB7749:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e1b8438-712f-4e8a-11bf-08dbd5a0cd9d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fcy7JXO2HJKc8M0pj/e15L/UJBG4h+ZqfXqU3JpnPz4OMf6k3rymMcVCZab8x2VhhIQkMW/28IjjO457YZEkbAn8+ayqqjfIHW4EOjW8050tLedK3Bg3Je2fBAfVkZ/Ka/N+fjA0sXLGZRc5HeTXOfXqaLsV9Fn2WBGA2Rulik/mKA9WkW5/Ejn/j5VbZqnmue+6vEN4TjtHrlrbjxc27IXPI9o6BjxQsvB9Coyrv9/3KulEcWsECRRfO9nvl/VL1sKqbBmq7hkSI+J7zeXFHvIjy38UXh1NO1Nxy+7loCx2SC7JFGDvcOeLBiHvk07gYWfrigcoI05tkfgrf8WV9VT7ckc9s0rqdaOjpJ+fboA4jEdHUzoX+Uc+hWeRTAQ4KqXFsMdv5KJQkABpySgWS0J1aHYBpyJBNtABxFR2z4xeMlzuNFKPPtV97/eOTS1CRfOjHZzDE2tqsz31H6flkADfMMLIlsxuVIuXKqT0N2RDDE9qVBBuTHKpw1aEaASzW9PY8EkWxrPyRRMXgrA8zX4/S7Poi8xnJmGNo72PNORazVDdRoZzX4ksVcaGjMbM3+pHseeYe9aSHSVl1X2YjC5f6sDTSQOTe4XUryQ3VhTHpRJPWv+If5dmQfRja8TgUFczwtU1oZWexUFdDWh4AH2DuZwn9+XpmF/Lqluh9H27Oqdc8Jfy0SdjfXy6W67cZFSzli0r/YShB51uD1PRpyiHQcY5Q93yPJO/oyR3wnlv/knu3JIDj7oCSrx27DMRqn7LB+1WUlghDe23qNDRrQ== 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)(39860400002)(346002)(396003)(136003)(376002)(230922051799003)(64100799003)(82310400011)(186009)(451199024)(1800799009)(46966006)(40470700004)(36840700001)(40460700003)(40480700001)(1076003)(81166007)(2616005)(82740400003)(26005)(83380400001)(426003)(336012)(356005)(6916009)(316002)(478600001)(6666004)(47076005)(70586007)(36860700001)(70206006)(54906003)(86362001)(5660300002)(36756003)(7416002)(41300700001)(8936002)(8676002)(4326008)(2906002)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:42.3538 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e1b8438-712f-4e8a-11bf-08dbd5a0cd9d 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7749 Received-SPF: softfail client-ip=2a01:111:f400:7eab::617; envelope-from=vikram.garhwal@amd.com; helo=NAM11-CO1-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 | 175 +++++++++++++++++++++++++++++++++++++++++- system/physmem.c | 11 ++- 2 files changed, 181 insertions(+), 5 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index 8a61c7dde6..feb4a3b886 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,178 @@ 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 total_grants = 0; + 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; + } + + total_grants += mgr->pages; + } + + if (!mgr) { + if (nrefs + total_grants >= XEN_MAX_VIRTIO_GRANTS) { + return NULL; + } + + 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 +784,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/system/physmem.c b/system/physmem.c index 5db1b32823..155a8c05fb 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2233,13 +2233,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 Wed Oct 25 21:24:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13436803 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 198FEC0032E for ; Wed, 25 Oct 2023 21:26:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvlNM-000766-Ku; Wed, 25 Oct 2023 17:25: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 1qvlMx-00073w-HW; Wed, 25 Oct 2023 17:24:55 -0400 Received: from mail-dm3nam02on20628.outbound.protection.outlook.com ([2a01:111:f400:7e83::628] helo=NAM02-DM3-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 1qvlMu-0006Ti-9V; Wed, 25 Oct 2023 17:24:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fX0OzAFIpG0LQO6E7c4KIS16lzEJpGECwMWUl6WL86A5d3pcvK7plGZfUQKzoW8E//zurgASvwIlqn+fhnNyl9CP3WvDRyKh5sQ/5db1ZQ2SCEnQIskw4UldVKMvM7A2sLMYIjq9vwTXraLfbbDpBsBjULwJiVd0n53szjKD2PP4G7tZxanpvMNriAzf+5VsiZCLBtMHQkc0P8Kdz+Ib1dGImy4h8/0gKz6EW+J4FrIjTgip7JBxnHhOVOWOzcZo9W4AvUDj85iHrHHkMxLws3S6KN5h7yyotOwaa9jPlC0VvdDPOaTiTlIsIiSEc94NB1ujvImanXgw+u/N7+TGog== 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=o0vRH12HvDrrWbRTurt84ajWGVWm4j5M7aGxWb5eoY0=; b=fqOn+QDqpvNZvbevVs4CcwyqNqMWBsPxv+5A2c30w1uIZt6hh74dhYHgYRcKXaf3OqRslxJ2ipR7uoAPAqcqaDGUaErKBQaUBj3ZiNAGe6mMbQLaFkUG9PKHH4gZ9eX2RtySn/MLEn1VwrhMUqunzzN/5QbWfTQLeLCOyK2XUXascL69CQVFjFvT3YCNreL3wF+Kxy4F3er7xrPmY1rmx54jlVerF7UqCbgVzq+YNV1gQSKiCcLdBBeulvh4Y78xuWRDsCVa5W6EICFN/aATNJC0QF6ceJAmF08ZdW7cPZdM7fwlhq1aEv8B2+i/llSvtjuHwjb6UIgkpnD/4R3oYQ== 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=o0vRH12HvDrrWbRTurt84ajWGVWm4j5M7aGxWb5eoY0=; b=JucI7+ODdh4amrklPfyIMOiR2G9B/eTBD2o595ymQudLanOy4bhsovNmRlAndD2wuHW1G5nXbW9yjA24AOEmcIyznMjA2zIBxHp3qveXaVCGIigC97bLmMqD16hHtidJ2LpZMtRzrjn3hrQjgEdth1qIZAyvx9vCDua4LWT1g+I= Received: from SN6PR04CA0093.namprd04.prod.outlook.com (2603:10b6:805:f2::34) by CH3PR12MB7593.namprd12.prod.outlook.com (2603:10b6:610:141::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 21:24:44 +0000 Received: from SN1PEPF0002BA50.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::3) by SN6PR04CA0093.outlook.office365.com (2603:10b6:805:f2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19 via Frontend Transport; Wed, 25 Oct 2023 21:24:44 +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 SN1PEPF0002BA50.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.6933.15 via Frontend Transport; Wed, 25 Oct 2023 21:24:43 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.32; Wed, 25 Oct 2023 16:24:40 -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.32 via Frontend Transport; Wed, 25 Oct 2023 16:24:40 -0500 From: Vikram Garhwal To: CC: , , , Peter Maydell , "open list:ARM TCG CPUs" Subject: [QEMU][PATCHv2 8/8] hw: arm: Add grant mapping. Date: Wed, 25 Oct 2023 14:24:21 -0700 Message-ID: <20231025212422.30371-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231025212422.30371-1-vikram.garhwal@amd.com> References: <20231025212422.30371-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA50:EE_|CH3PR12MB7593:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a47e5bb-babc-4206-b625-08dbd5a0cea5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RZSRtCUwTGmXG/i5t1WRCeQnbNIZizMwaVFaGXD2Gdi8NtE3ugLOo6e+hdiAffJsMZvvO2ezdC7uF6lvUIeJDatt64sOWCaCCjrihkEjxb+4iTOKFX0VJprRQpIBz73Y86lJnSns4mG/GjlbNwc10kSo0mGGCAl1DRCttnEo1621ZBL0yK9q5e9rVJT/9o66lJOn7znU0QNWbSjplGOyfU0xdwOlEwi6ZBAkO9JqrPdRzpPxZTmPdmjLZqALP3vaEwrH7v6hxserYuihHKp/h36HexsPLEu8TwvU8yXswc+q/kYaajHRpb708xNbo7YKDjMCHxXsHS4Z+0AaevBKaDGyucOLhwDiqydBhyNu1cf0yYADw5kbiALzPOJ9GwJnXKjN1xes9jNCKbG4UFdKefuaRIlQ+wseUTS55qJ+zp78gaOLC3iO/AJrm5J3FUFh+bIImFvqjwm/uF82EaAqzBzrrz8iTE1IZSAB1QANtQpf76IUvlfYcCzAPbK+/5xTf/AIjfPFAgQJsWGzIpqhvTNQINDJr+d53iEhWgXfjmFN9JE+OZwSGgNg56Gu7sYwrGcxOZULn5DnpwyQNP6eEk+S/M9gwBsq9WCtC2YIgcsW3vBXn/4BPjhqfEO9O0Bec55BYb7US0iIFRoQ3H8dJTLEkKTKkZHd5qOLUNNJ/KzXiEDjeVIBEdw9VuIDBAvWpTo8QpRlueGhJb6QSsWDOYH0B4CD2c/En0F/+rC0skRPv6Kb4rmtHhZk+W/RGI8/P6CCtBMSbKdE5/QoIOhrRw== 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)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(186009)(451199024)(82310400011)(64100799003)(1800799009)(46966006)(36840700001)(40470700004)(26005)(36860700001)(82740400003)(2906002)(4744005)(41300700001)(40460700003)(44832011)(5660300002)(86362001)(36756003)(8936002)(8676002)(4326008)(6916009)(54906003)(81166007)(478600001)(1076003)(316002)(70586007)(356005)(70206006)(40480700001)(47076005)(2616005)(426003)(336012)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 21:24:43.9632 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a47e5bb-babc-4206-b625-08dbd5a0cea5 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: SN1PEPF0002BA50.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7593 Received-SPF: softfail client-ip=2a01:111:f400:7e83::628; envelope-from=vikram.garhwal@amd.com; helo=NAM02-DM3-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)