From nobody Mon Nov 25 03:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1718228109; cv=pass; d=zohomail.com; s=zohoarc; b=lp81qoRUChT+IkMy052vF5Zz/V2AwM9TV9/R5eSJBRoyf3n9mYBWat6tZfJe9lhVLeWJYNNVgBzV9++CrRh9l67rXIMlrIGhRsrP6E02FzyPKLNy1ydJ1G/rcaaRb6bbQ0FQ75B3WWC/N3jcNEI1gQt4hLwXNQwxKYPljANOI3Q= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718228109; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jO4UHVrqZMP3djoXDVI4YZ6oy2MK9x1fZiqbu8aBG/Y=; b=bPLGXMSwKxC7WmG798YBpEuKYDuKiWtuUzDxmtucGRHai9YSxnUm69quqgfiVxdrOzM1tjtqcBac0iqeIcml+SIBScvL6N1EUSvEGisj7DOUC9N8HHlnOnElCuXr7drQ3akIcQ6FYT2xTU7sM8ZYWJ7fAR/457Zeu/OfLapAHsU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718228109895302.9952683110712; Wed, 12 Jun 2024 14:35:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHVcQ-0006ge-3b; Wed, 12 Jun 2024 17:34: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 1sHVcO-0006gS-LA for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:34:56 -0400 Received: from mail-mw2nam10on2071.outbound.protection.outlook.com ([40.107.94.71] 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 1sHVcM-0003oF-Hh for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:34:56 -0400 Received: from SJ0PR03CA0187.namprd03.prod.outlook.com (2603:10b6:a03:2ef::12) by DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Wed, 12 Jun 2024 21:29:49 +0000 Received: from SJ5PEPF000001CC.namprd05.prod.outlook.com (2603:10b6:a03:2ef:cafe::6b) by SJ0PR03CA0187.outlook.office365.com (2603:10b6:a03:2ef::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20 via Frontend Transport; Wed, 12 Jun 2024 21:29:49 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ5PEPF000001CC.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:29:48 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Wed, 12 Jun 2024 16:29:47 -0500 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 12 Jun 2024 16:29:41 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c/fgsgFE8JBsc9yQZGX59NotLq0hADlBIVKD0IJrKDvoxGg8K8x7Mn+3M3+73VuJqkyY4fgvlo+RQUxdF+2CzcQNlow+oHXxhFO2ZxMYwVyKfczVqFsjubBkfMULF3rQ6tZIX0IwQPC+VluvzV3mlHOOWQHxqkbAf3L77iC29GrFR2Yf55zdM/2IC6s+mJaHjwoNWjE73ySxAeFI/pJ/HCIb8rar5gMzyPuFMzWvR4NSRkvi8C20w3trBBY3nftQ/wObqm2LPi2nY+gumo3NE7nhKu9jfMdKi0CqiscUNwjfnJfCj2l/wcaZTFfJRkobHNn13GnH0z6bhPvzN3KPTA== 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=jO4UHVrqZMP3djoXDVI4YZ6oy2MK9x1fZiqbu8aBG/Y=; b=W2rAZHEqYIgDJgCYFjBzfCBgoXQvUcxDiTtnOcM6lhgIXsJBTmJEf8hyBMW7MK2IWtJ+OLcdJFt3nlcOrD5H/URAI7zeaKZLDaCiemCMjaclXUHvqnv5nf7wyMoN0uxg1gO3WfAGIqMPXT1NkKJq2eAfvuGd/DSuw5vHAH+GVK63jLJofG78dWeUFqYjObZSVNRNzDJczaZBv8zLcFh94KybL5WCXyle17MjR9zoploKBjguztwyBMY4KSpImYCeNSjIUknZwNySWzbfKdZImrTXisMktXu1o9KTtwDTTR8Pmddzt8M2jdLxWl0Wafmq+mQuWL3I5dirdjl17TwYyg== 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=jO4UHVrqZMP3djoXDVI4YZ6oy2MK9x1fZiqbu8aBG/Y=; b=hoX5PMgVYcAkjC3mjUipzJ1t/mQkY108f2zFYO+lSvetnHUCP1eX+e8bJQEmQcKhtZPDHoHBlcgL/pje2ITfcVaN609K/7m0o4Bl1yBqX2VUnN40pUq3jtLZNGIP84Tlgu4aIhjt2/Dc5LuYinR+Dtug9zwNyFiDKG8qYuBEfjk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stefano Stabellini To: CC: , , , , "Edgar E. Iglesias" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 1/5] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable Date: Wed, 12 Jun 2024 16:29:36 -0500 Message-ID: <20240612212940.2178248-1-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB03.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CC:EE_|DS0PR12MB7726:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ecc0ff9-e20b-44a1-1ee2-08dc8b26c9d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230034|376008|1800799018|82310400020|36860700007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?azJtOE1MNEl2enU0MDFjdjdWOEJRSWpOYzd5T29IUnRTRTIraDNKVTl6U2ZL?= =?utf-8?B?dDE3d2RHNFBHK0RuOEVCRHlCUytwQXZucFpvVm96NVMyMVRtaHloT3MzM2pJ?= =?utf-8?B?bjJQbCtBMWQ4RFQwK25yV1M0amJnYnkzSkFlWnJJb1lUSVZOeThLZW92dzEv?= =?utf-8?B?amtsUFozTk41NGdTWVV1WjZtdGw4aUY0elpmY3lQdVlsQnBKUThTYVVXS3BC?= =?utf-8?B?U0ZYMXkzaGIwTXIxWStPTDRIZnl2aWN4bUFrMStwTjlPV0F2NDlXQ2tRYUQv?= =?utf-8?B?VkFRRE9TVnk3aXRtd2NqeFV3Z0h4eXRXbzFheHlNQkI3ZUpwTU9lK0dUV242?= =?utf-8?B?dW9kSm9tMmIzVHNlSExkWndvMm4xMGRDTWZXZkVneTU5MURLU01sUEkwZTNS?= =?utf-8?B?REorS2VIaXVMNlJQRURnNno2QnkwSjNsWXBQdngxN0JVWndEcTU2bktmRXJP?= =?utf-8?B?QzcvZ2N6cjEzTk9ZYS9ja0drdTRQMEZKb3J5L2ZDNm8yRlAvZXBJeWZqblB4?= =?utf-8?B?Z29yUzZqRGZxM0FLUk9MR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TNrWWZNTEswcXo2TEFUN3R1QVc2QitqK09TbENUZ2dJRUdJYW9E?= =?utf-8?B?R1VHYWEvVCtDK2JBdmJYZjZhQVk4YWY2c2lUaDJZWTFxUnFHTHdnUlFXMFB3?= =?utf-8?B?QTdnRjRRUlRKRzc4RDAzcmJYWThzRkFlenNoTlRiNk10ZldWVGhNcEF6d0J3?= =?utf-8?B?TFV3OENpVW8vZVpLNmVFRlpya08xWVM3dXZIRVZ1dmViVjlJYmhXT3FEMWEv?= =?utf-8?B?SGJFLzdaTG9BUloxdXVHeEpkTldsSi9wU2k2bDZoNmxWVjdHN0RpOHVxZFMr?= =?utf-8?B?RlBlOGRLU0U2am01ZVQ1MTNOTFE1Y1ZJYkN6cUErYzJLUWVWbGQ3K24xcmh0?= =?utf-8?B?TFEvSHZySS81b3JBeG5jVmNRVERvem1iTkJZRjl0aCtWcElJREVtZ0FPbU8r?= =?utf-8?B?Qmx1U2IvZURNRG16MXkrVzFZbmxHT2tiS0wweFBMTEJwR0E9PQ==?= 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:(13230034)(376008)(1800799018)(82310400020)(36860700007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 21:29:48.7470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ecc0ff9-e20b-44a1-1ee2-08dc8b26c9d4 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: SJ5PEPF000001CC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7726 Received-SPF: permerror client-ip=40.107.94.71; envelope-from=stefano.stabellini@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718228110629100001 From: "Edgar E. Iglesias" Make MCACHE_BUCKET_SHIFT runtime configurable per cache instance. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/xen/xen-mapcache.c | 54 ++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index fa6813b1ad..bc860f4373 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -23,13 +23,10 @@ =20 =20 #if HOST_LONG_BITS =3D=3D 32 -# define MCACHE_BUCKET_SHIFT 16 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ #else -# define MCACHE_BUCKET_SHIFT 20 # define MCACHE_MAX_SIZE (1UL<<35) /* 32GB Cap */ #endif -#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT) =20 /* This is the size of the virtual address space reserve to QEMU that will= not * be use by MapCache. @@ -65,7 +62,8 @@ typedef struct MapCache { /* For most cases (>99.9%), the page address is the same. */ MapCacheEntry *last_entry; unsigned long max_mcache_size; - unsigned int mcache_bucket_shift; + unsigned int bucket_shift; + unsigned long bucket_size; =20 phys_offset_to_gaddr_t phys_offset_to_gaddr; QemuMutex lock; @@ -95,11 +93,14 @@ static inline int test_bits(int nr, int size, const uns= igned long *addr) =20 static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f, void *opaque, + unsigned int bucket_shift, unsigned long max_size) { unsigned long size; MapCache *mc; =20 + assert(bucket_shift >=3D XC_PAGE_SHIFT); + mc =3D g_new0(MapCache, 1); =20 mc->phys_offset_to_gaddr =3D f; @@ -108,12 +109,14 @@ static MapCache *xen_map_cache_init_single(phys_offse= t_to_gaddr_t f, =20 QTAILQ_INIT(&mc->locked_entries); =20 + mc->bucket_shift =3D bucket_shift; + mc->bucket_size =3D 1UL << bucket_shift; mc->max_mcache_size =3D max_size; =20 mc->nr_buckets =3D (((mc->max_mcache_size >> XC_PAGE_SHIFT) + - (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >> - (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)); + (1UL << (bucket_shift - XC_PAGE_SHIFT)) - 1) >> + (bucket_shift - XC_PAGE_SHIFT)); =20 size =3D mc->nr_buckets * sizeof(MapCacheEntry); size =3D (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1); @@ -126,6 +129,13 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) { struct rlimit rlimit_as; unsigned long max_mcache_size; + unsigned int bucket_shift; + + if (HOST_LONG_BITS =3D=3D 32) { + bucket_shift =3D 16; + } else { + bucket_shift =3D 20; + } =20 if (geteuid() =3D=3D 0) { rlimit_as.rlim_cur =3D RLIM_INFINITY; @@ -146,7 +156,9 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void = *opaque) } } =20 - mapcache =3D xen_map_cache_init_single(f, opaque, max_mcache_size); + mapcache =3D xen_map_cache_init_single(f, opaque, + bucket_shift, + max_mcache_size); setrlimit(RLIMIT_AS, &rlimit_as); } =20 @@ -195,7 +207,7 @@ static void xen_remap_bucket(MapCache *mc, entry->valid_mapping =3D NULL; =20 for (i =3D 0; i < nb_pfn; i++) { - pfns[i] =3D (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT))= + i; + pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) = + i; } =20 /* @@ -266,8 +278,8 @@ static uint8_t *xen_map_cache_unlocked(MapCache *mc, bool dummy =3D false; =20 tryagain: - address_index =3D phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D phys_addr >> mc->bucket_shift; + address_offset =3D phys_addr & (mc->bucket_size - 1); =20 trace_xen_map_cache(phys_addr); =20 @@ -294,14 +306,14 @@ tryagain: return mc->last_entry->vaddr_base + address_offset; } =20 - /* size is always a multiple of MCACHE_BUCKET_SIZE */ + /* size is always a multiple of mc->bucket_size */ if (size) { cache_size =3D size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size +=3D MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCK= ET_SIZE); + if (cache_size % mc->bucket_size) { + cache_size +=3D mc->bucket_size - (cache_size % mc->bucket_siz= e); } } else { - cache_size =3D MCACHE_BUCKET_SIZE; + cache_size =3D mc->bucket_size; } =20 entry =3D &mc->entry[address_index % mc->nr_buckets]; @@ -422,7 +434,7 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(Map= Cache *mc, void *ptr) trace_xen_ram_addr_from_mapcache_not_in_cache(ptr); raddr =3D RAM_ADDR_INVALID; } else { - raddr =3D (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + + raddr =3D (reventry->paddr_index << mc->bucket_shift) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); } mapcache_unlock(mc); @@ -585,8 +597,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, hwaddr address_index, address_offset; hwaddr test_bit_size, cache_size =3D size; =20 - address_index =3D old_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D old_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D old_phys_addr >> mc->bucket_shift; + address_offset =3D old_phys_addr & (mc->bucket_size - 1); =20 assert(size); /* test_bit_size is always a multiple of XC_PAGE_SIZE */ @@ -595,8 +607,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, test_bit_size +=3D XC_PAGE_SIZE - (test_bit_size % XC_PAGE_SIZE); } cache_size =3D size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size +=3D MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_S= IZE); + if (cache_size % mc->bucket_size) { + cache_size +=3D mc->bucket_size - (cache_size % mc->bucket_size); } =20 entry =3D &mc->entry[address_index % mc->nr_buckets]; @@ -609,8 +621,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, return NULL; } =20 - address_index =3D new_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D new_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D new_phys_addr >> mc->bucket_shift; + address_offset =3D new_phys_addr & (mc->bucket_size - 1); =20 trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 --=20 2.25.1 From nobody Mon Nov 25 03:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1718227828; cv=pass; d=zohomail.com; s=zohoarc; b=HzfMpQ1L4mAULevDO6TY/bgVcz3U81xfbG9RbkaKZn6tQyJp3Ua6WE8zoS72sXXY9Ea+o1g91JwiWnVn/XD0P3TKQwIYy8Y21narj5OuWvO3DUN4Dbzfcj9/NN0ZS8yyueN0vGZSWBq6X4ot59pdSNN1x5q8pldDyYXHgQH9AJI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718227828; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GMJ7KkTrwysosIa9wix1W+C3OTxXI/gaCPR0zSc7XW0=; b=Gq3RGYAJmBexciBGjd15VSKuQUjRspwF5YTfq9LhEpH8EsNLsSv1HGosQQshuVP9u8Iv8Zm7qtEhkm5x7BKzTzjntmOq7o90cbWlZgy0uijA+yC6JZMZTSWHoc5ot9qHdVlkoelOT0NkNkZb6VCyDwhoEWaa3zkWUiSawWXY8AI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718227828319475.75974506267494; Wed, 12 Jun 2024 14:30:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHVXt-0001VB-SO; Wed, 12 Jun 2024 17:30: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 1sHVXp-0001PA-7c for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:13 -0400 Received: from mail-mw2nam10on20629.outbound.protection.outlook.com ([2a01:111:f403:2412::629] 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 1sHVXm-0002o7-Ui for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:12 -0400 Received: from DM6PR21CA0013.namprd21.prod.outlook.com (2603:10b6:5:174::23) by IA0PR12MB8715.namprd12.prod.outlook.com (2603:10b6:208:487::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.37; Wed, 12 Jun 2024 21:29:58 +0000 Received: from DS1PEPF00017095.namprd03.prod.outlook.com (2603:10b6:5:174:cafe::c2) by DM6PR21CA0013.outlook.office365.com (2603:10b6:5:174::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:29:55 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017095.mail.protection.outlook.com (10.167.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:29:54 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.39; Wed, 12 Jun 2024 16:29:53 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Wed, 12 Jun 2024 16:29:53 -0500 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 12 Jun 2024 16:29:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vq8FZZ4cmbC8kpW+HwXQinPmacIs5AyPT4J5apDpX07xwOvxMPtexStmGBPCnrq0fAh0dfAuGVGpoHbNXPUMcwR6hd/sQGutY1hHD6oguq26Gkby+q9uRNOOh67bXApRc3qa6At5XOou7zx+H/CmOxesytm9pa7+UbkMEtNt7DJPtzzKHfyibZXguS0fMoLfqn8DSwtjufiBhCJoK2WyKQkDz95LQCKaUXKEbGINBgp1yCOcKQX5CPWlCQKij/pdRNCXfJN4bpZGCzcearz42EeEIEehu7c8lHGzeP+0AeCZT9EUYY6iBNF1Gr0bPa05oWdNj6dYIDaLjy04VxyG2Q== 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=GMJ7KkTrwysosIa9wix1W+C3OTxXI/gaCPR0zSc7XW0=; b=XkFc1qjoIMkwFxtnWH6CIO4/y3xNcZ5YKPEbgPtXzelhPsjQ4cMYdwMu4IThsUAAzLM5BfVCS/qQ9yK4UYLEwNc2Q0A1hj/RuUwuwMXU5HS6XdpECkftp4QS/3Tv1FidOdTIaLImnVun0AQF1xVthkuG8wBHVcBRo3iVGU5TvtlQMRMEZTnjf0aTGWM4PRqCc13RUQrioXmJAPbxloMzkp8RCGP2995eFa3KbLElNoy//vm/9rBYDGN3GEcjnyFwGKg6iTstebV2azdIYuLDcrr9DLxaKKMN10d76gCour8rHUBAWBbrf+zcOLHrDQuGRiBe5kvvXPOhq7r2Jg8keQ== 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=GMJ7KkTrwysosIa9wix1W+C3OTxXI/gaCPR0zSc7XW0=; b=VQOWTdBG//GoDBF5DBo15eMI6R1AaHAhDVFwP/uiB1fKADYAjSwItFcAguKfVwYXH1EbC0RscbsWaSC2Iw6nWEqmfyz+OGoKb+ojucxb7Weh14IwtpkWc4cSOrms9OHoZpoH0u9ijff3aVk7+1iVnZiF0cNbK00jhP0P1bfgtpQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stefano Stabellini To: CC: , , , , "Edgar E. Iglesias" Subject: [PULL 2/5] xen: mapcache: Unmap first entries in buckets Date: Wed, 12 Jun 2024 16:29:37 -0500 Message-ID: <20240612212940.2178248-2-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017095:EE_|IA0PR12MB8715:EE_ X-MS-Office365-Filtering-Correlation-Id: 11834b92-4515-4722-343b-08dc8b26cd77 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230034|376008|1800799018|82310400020|36860700007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?vvlOh3WRi1uCzyLb/+09x6bnH9hfmZwzcgFhWMOuxYOH7Z0jsKI3Mjvnrnm0?= =?us-ascii?Q?Z/rdR9xrtm5KOLfGtsdoT/Tc6bs5XQ/r2oxfFC1IKnEw+1MzioCNU3a7j1Ow?= =?us-ascii?Q?QsdRQ8c51QvzBKpvxNAd7wbrV70xZo1E/61nzCyc4NtIJzHqviU1HlXw+E9C?= =?us-ascii?Q?5ktHBvGT4UyphdX6sV+hQHo2diqaQmiTCQM1FDlP5QUXtr6cUa0H2CDw4CVy?= =?us-ascii?Q?xhptu5BWqNbK6wnMJKR7D5rGLKh4lHd+FDc6El9itIMQNnA2jvIAgVL4AdEE?= =?us-ascii?Q?MSG90tfpBwkqm093JfuG0DKKRUITC78QelrGwP1NXeydm95pd4WgyWkTUsqH?= =?us-ascii?Q?dqaI8IhcKiEqYUkyUaqZ8zIMvCAIu1HrH7cYjR63NsYzydXl/tUr29J3rK7H?= =?us-ascii?Q?T+cuBG/KZLliQSqv5T1Dx9f+CdVMtNZUIFgK9mitwJJ+Mg67UmaEXcVDsbIO?= =?us-ascii?Q?5wNClBaHni00aGuN+W5yg43HctAeIlLqhHjKozNgjncZ589fT3TH3w9ItFjR?= =?us-ascii?Q?sHOOO3JJdKACDPC2t8FR5KXY7+zLn4yojSQQqu9/VjQAAUN5DRYfCFbX4XJ2?= =?us-ascii?Q?UVe9fsZbUHmKyXrvO50fPeQirHLh5I1Im30jT8yOTE0ztIogKSFwGa2gvtic?= =?us-ascii?Q?ZUoxVB2KeQg3qH0sCkIMLNzgJpGiyXbdkxPEVF7hUHBqM4Z+uAydUE8Lw5ZW?= =?us-ascii?Q?+2hZwnjqoFF46vC9YCOeUMYh2JJ7uWlr/mLhIYLaVPsi4PRXZk6qSSlYdwYK?= =?us-ascii?Q?tIhYfiMj3HDyG9W1R1QjDsUMijvGpaUPDg7J+c7mrmqrhdR5vwm97Xq8/5sR?= =?us-ascii?Q?mNA1EaVtRZssu5run7w+e5671cqkY60BkkMQKbOxwy7ux+78CbZtM8CYVCb3?= =?us-ascii?Q?b3uDfCmjDzx+7UO6S0OsjpX+OD+St2DN4W2Etm0UnlAynm1QvnsEhsTdQ2Ww?= =?us-ascii?Q?lkl3ngvy9XTGejDsyv7iOzQsbcAeuQOPG7atviGExS1cTmunhumXY1AWtGBO?= =?us-ascii?Q?iPXKvOMA5PdzaABki/M0EHcHHZcO8a2eNfV6PmAV8VrhsSdoZyaGDAocLgwH?= =?us-ascii?Q?u5UAPxB65Edu6JDzRERa+Zu+11XZsM1wkJp/XFsIWlij4ugLlUIiRRnR7hVl?= =?us-ascii?Q?7dUMvjEG8l4dq05nqHyVGLpm81Pr4jg0UaXKD2zGPzc8Oh6UC5N6TJUWYFHC?= =?us-ascii?Q?3kvwYqSmMlQgsIaolCXd5qfwWijYGeEHx9w+aFdmsDbGYG3+5R4ZQWQ/BSiD?= =?us-ascii?Q?/HdEJ+RbkxZMzN5EHibv7rE2lrf/+5xBDbVlgxoLN4UFXfy/2n66tMqRSvGU?= =?us-ascii?Q?EZMBhpBe4mHjUQHm+sHgOgqbctOS53RYHnd0jiej2661NDYObv6zlVQU1Vzx?= =?us-ascii?Q?3IWNra42s+4FfSt5o+okgczO1y5YR57cK+cIaTOcUGGIEj9qYg=3D=3D?= 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:(13230034)(376008)(1800799018)(82310400020)(36860700007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 21:29:54.8958 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11834b92-4515-4722-343b-08dc8b26cd77 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017095.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8715 Received-SPF: permerror client-ip=2a01:111:f403:2412::629; envelope-from=stefano.stabellini@amd.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718227829421100001 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" When invalidating memory ranges, if we happen to hit the first entry in a bucket we were never unmapping it. This was harmless for foreign mappings but now that we're looking to reuse the mapcache for transient grant mappings, we must unmap entries when invalidated. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-mapcache.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index bc860f4373..ec95445696 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -491,18 +491,23 @@ static void xen_invalidate_map_cache_entry_unlocked(M= apCache *mc, return; } entry->lock--; - if (entry->lock > 0 || pentry =3D=3D NULL) { + if (entry->lock > 0) { return; } =20 - pentry->next =3D entry->next; ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); if (munmap(entry->vaddr_base, entry->size) !=3D 0) { perror("unmap fails"); exit(-1); } + g_free(entry->valid_mapping); - g_free(entry); + if (pentry) { + pentry->next =3D entry->next; + g_free(entry); + } else { + memset(entry, 0, sizeof *entry); + } } =20 typedef struct XenMapCacheData { --=20 2.25.1 From nobody Mon Nov 25 03:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1718227859; cv=pass; d=zohomail.com; s=zohoarc; b=Hfri74H6vxPe3jS0Lb8CT90IEmmvxkXLcw/xPQbjdONmQMiBLGigfb01XaReUGT/IYLKB82xaz2OIu35oeQiBAFthughoTwdJRQg3FchjseSUB9REgowCqTcUWRhpoOOmtKECU+GgcDv9DayMZ/s1DElGyetq5XC2fDQo7B90kE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718227859; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2mJ+jql/EDqUybJTnjb/85JYlMFA6jZ7hOjOjsOzvs8=; b=QDJ1lHXMNkja/0E7oo8u2K7D8SfF0+CbntVMrXnvZ+2ZZ6PFtThMOpQk4Pxcb5/4aOws0tcJzXpssGNStOUYXbgDe+JY4zCDTh9XKJwRqq+ecSODe2rpmn2aEDZah2JAdJ/qHxWSQO5I/YjU7BK1r1KOmF9+ad/pLr58c7B+rE4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718227859442674.1617106125128; Wed, 12 Jun 2024 14:30:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHVXv-0001aY-BW; Wed, 12 Jun 2024 17:30:19 -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 1sHVXr-0001Tv-RM for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:17 -0400 Received: from mail-bn8nam12on20621.outbound.protection.outlook.com ([2a01:111:f403:2418::621] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHVXp-0002oN-3Q for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:15 -0400 Received: from DM6PR21CA0014.namprd21.prod.outlook.com (2603:10b6:5:174::24) by CH3PR12MB7499.namprd12.prod.outlook.com (2603:10b6:610:142::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20; Wed, 12 Jun 2024 21:30:01 +0000 Received: from DS1PEPF00017095.namprd03.prod.outlook.com (2603:10b6:5:174:cafe::41) by DM6PR21CA0014.outlook.office365.com (2603:10b6:5:174::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.17 via Frontend Transport; Wed, 12 Jun 2024 21:30:01 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017095.mail.protection.outlook.com (10.167.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:30:01 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Wed, 12 Jun 2024 16:29:59 -0500 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 12 Jun 2024 16:29:53 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X5JVm2Q4fbxL61dIGUq0HECnSoZEdAc/dt+zPqPgWWjrHjUeDHfT5jaik0xHslOPF5er5uoScMG7r2d1bEdUH5z6xJsk89KOYwz7gZlMGVWlsDyAR4VYUqpZHrhuzxZ9JDaHL7ngkeOKWgnoFup1O4EXOANb7+/q0xjcMyANtoXL0f91qP6UtmyCrqsz3LOfcpYnPcjLSaG0VFFzt3/23IS0zm59/Y7MOO4cWfPpaq/g4OZ5XuGy51ZUlaePhX35JBOH4GIWdFRlWy9c8QrHvCi8kOf4EvSpwBke9q7H0wvV816GYHz3ACj8xR707JJfVMRf214K55jNV1BlMXM7qA== 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=2mJ+jql/EDqUybJTnjb/85JYlMFA6jZ7hOjOjsOzvs8=; b=Sscn61tOa1TTOltVUnQxFjdcwo7s8q6kZLbdqmXTeaoarqL6OHxt/5LpbIfvjMKyv5/8RqtCC9IrJJOW9z0jvFa63t4vNFv6f6PpWb6RvA8U4/Hv8nvXbWi7aK9ZxO4qL19FRWPhLtfkFtpGEknZxyL4Ts1SPce4FPQ/1mRl0pqTTYIRAYS69nlMykkJayNDbr+hsVZvk0r1XzvqlMT10WbSofeYbqq7oaHBXA8dD04UbNs96CS2ZM8AeEtIhZQ/NK170vu70uBL3Q9MkDFfgsnqrnJtsB6Z7mlLYykMIBTqE7SHBUy4qYbmGY7fmfQxu58qzEShnj10wzTdkF9n4A== 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=2mJ+jql/EDqUybJTnjb/85JYlMFA6jZ7hOjOjsOzvs8=; b=pNdYgATeHKFi1Yp8QqDLXMoq11IB1seHvah7purc7hUJW0N6VY+AMv06bSGY6UtpXGwxUfhUJXLdfVnjTfzqXkQHdj2sZNAmW1AU66j0lYYBjl4TTBX21jW44bFMIGTsgOFOb6BMZu2u4bKKYm9WRZ5zh+NyKghD8A5QsYXpW8E= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Stefano Stabellini To: CC: , , , , "Edgar E. Iglesias" , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 3/5] xen: mapcache: Pass the ram_addr offset to xen_map_cache() Date: Wed, 12 Jun 2024 16:29:38 -0500 Message-ID: <20240612212940.2178248-3-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB04.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017095:EE_|CH3PR12MB7499:EE_ X-MS-Office365-Filtering-Correlation-Id: 945c847c-f031-464d-f621-08dc8b26d143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230034|376008|1800799018|82310400020|36860700007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?b0lYSjB2VHV6N0xEZ3EwcDVZUHV4b1BHVFFRQlBXTTdBeVBycHE4RUhhZExh?= =?utf-8?B?MUw1N2N3MWF4TjRXdm0yRmc2U1pueWQ3aFZKbVRHWkZnY0VSb3luVjg1RjNY?= =?utf-8?B?bHVVeThpelBha1dWU090eWIxdkRDanVIRFVzNzFiQTdTUzROcjN3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84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230034)(376008)(1800799018)(82310400020)(36860700007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 21:30:01.2709 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 945c847c-f031-464d-f621-08dc8b26d143 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017095.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7499 Received-SPF: permerror client-ip=2a01:111:f403:2418::621; envelope-from=stefano.stabellini@amd.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718227861439100003 From: "Edgar E. Iglesias" Pass the ram_addr offset to xen_map_cache. This is in preparation for adding grant mappings that need to compute the address within the RAMBlock. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: David Hildenbrand Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/xen/xen-mapcache.c | 16 +++++++++++----- include/sysemu/xen-mapcache.h | 2 ++ system/physmem.c | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index ec95445696..a07c47b0b1 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -167,7 +167,8 @@ static void xen_remap_bucket(MapCache *mc, void *vaddr, hwaddr size, hwaddr address_index, - bool dummy) + bool dummy, + ram_addr_t ram_offset) { uint8_t *vaddr_base; xen_pfn_t *pfns; @@ -266,6 +267,7 @@ static void xen_remap_bucket(MapCache *mc, =20 static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_offset, uint8_t lock, bool dma, bool is_wri= te) { MapCacheEntry *entry, *pentry =3D NULL, @@ -337,14 +339,16 @@ tryagain: if (!entry) { entry =3D g_new0(MapCacheEntry, 1); pentry->next =3D entry; - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy= ); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, + ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index !=3D address_index || entry->size !=3D cache_size || !test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy, + ram_offset); } } =20 @@ -391,13 +395,15 @@ tryagain: =20 uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) { uint8_t *p; =20 mapcache_lock(mapcache); - p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma, is_= write); + p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offse= t, + lock, dma, is_write); mapcache_unlock(mapcache); return p; } @@ -632,7 +638,7 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 xen_remap_bucket(mc, entry, entry->vaddr_base, - cache_size, address_index, false); + cache_size, address_index, false, old_phys_addr); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index 1ec9e66752..b5e3ea1bc0 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -19,6 +19,7 @@ typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offs= et, void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque); uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write); ram_addr_t xen_ram_addr_from_mapcache(void *ptr); @@ -37,6 +38,7 @@ static inline void xen_map_cache_init(phys_offset_to_gadd= r_t f, static inline uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) diff --git a/system/physmem.c b/system/physmem.c index b7847db1a2..33d09f7571 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2231,13 +2231,14 @@ static void *qemu_ram_ptr_length(RAMBlock *block, r= am_addr_t addr, */ if (xen_mr_is_memory(block->mr)) { return xen_map_cache(block->mr, block->offset + addr, - len, lock, lock, - is_write); + len, block->offset, + lock, lock, is_write); } =20 block->host =3D xen_map_cache(block->mr, block->offset, - block->max_length, 1, - lock, is_write); + block->max_length, + block->offset, + 1, lock, is_write); } =20 return ramblock_ptr(block, addr); --=20 2.25.1 From nobody Mon Nov 25 03:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1718227833; cv=pass; d=zohomail.com; s=zohoarc; b=PRu7HacjxrAwBUZEOLnK6zPh/VPG+Dwts5sXEZXfVZMBOXPy1EqfVNHEZrWh+e601wkubiT9xWAqahMqLrbOQgSZPQZ0t2u8LE2Yu5TFVSMJNO37EBuUjklNiAOs/jTmppaiKniqxtVA7uw0+ytz3cWTMpHji3dV9UaGqRT5quY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718227833; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TaUS6wQGlVOTWcB9MLN8ydEe5uuQPHXEXiwY+daGi78=; b=P6PzrIaNJlKXT7nzBIGbDePADsu52ljnzGvE0Km9B0inBTH8Ze5P0pxupWtev4Uh7obp+UR9SlVdQRlDZe2/DnbNEF83r7Iaj88A8J2e1YOPZBQi30ZuGVop5bL5GAFPphBbhOYT50mlP0gkvZ5QJo7pTxJsyayQ5fnKyLd6x2I= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171822783357491.3079595814794; Wed, 12 Jun 2024 14:30:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHVXy-0001ln-1N; Wed, 12 Jun 2024 17:30:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHVXw-0001ef-7G for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:20 -0400 Received: from mail-bn8nam11on2062f.outbound.protection.outlook.com ([2a01:111:f403:2414::62f] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHVXs-0002oy-MO for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:19 -0400 Received: from SJ0PR03CA0183.namprd03.prod.outlook.com (2603:10b6:a03:2ef::8) by PH0PR12MB8773.namprd12.prod.outlook.com (2603:10b6:510:28d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.37; Wed, 12 Jun 2024 21:30:08 +0000 Received: from SJ5PEPF000001CC.namprd05.prod.outlook.com (2603:10b6:a03:2ef:cafe::c8) by SJ0PR03CA0183.outlook.office365.com (2603:10b6:a03:2ef::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.21 via Frontend Transport; Wed, 12 Jun 2024 21:30:07 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ5PEPF000001CC.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:30:07 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Wed, 12 Jun 2024 16:30:06 -0500 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 12 Jun 2024 16:30:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFw9SN1BIKokmLnFX9JHEjukOBvTp3o234YaYCFt9JPgsacj4STqCsoPHvWo4IkVvtjpHVsb5CZq8KZKTuRwpD/65eY8gdLSuH5bZ7+aLrHhw1sBRMzjsM2b0/sv4g9GSRYNokfHBNHNRuFhjPQSh9lQ8Y7sL2ZuLFRLuqQytyMJ+3pC8yln+pV6snCZw6fhMnaRv4hgWz/eM+KcT8NOk0tmt0K8zyEJzOYypAsVngNptj+dovKn+njtytgOTR6Oi93wsBvcs4ba2O10P2wvJLM6ICFVMX8dwgoiMBhl7wzs9AvYb5LIjzFx66rbjHLFlGA2P1C3GqBIAb05x2uwsQ== 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=TaUS6wQGlVOTWcB9MLN8ydEe5uuQPHXEXiwY+daGi78=; b=bGXgmRRsYoIVkcWY0KUdTzDPLTiRxHPyYxIBhwQ7HpUo/cjlOfwsp+J6yegtS0lDBrJzboWvB5DKnOoFs25GlXGsT30QnInc/hrXTyiSIvR2jrOnc3dGT6X87xYu81/VkIBzuwYz4giUqKUCVtn7+u0C10f+joG6XloaliDRs7MVj+0dHuSG0HoneeSyO9cIdMmdxEgeoH3P+SlX9HRkFc9xM+fiKyc3jaHwvOqSG9TpyBWPltAPnDC4/ZCWXWPsfcMHf4KFTUGop1s+SCC30P70D/D6IF1vFO3CF7mDSWar+j3hrXUX1i0Pv2UsAMjZMf6N2lqmRfoGWNFcOu9xCQ== 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=TaUS6wQGlVOTWcB9MLN8ydEe5uuQPHXEXiwY+daGi78=; b=t16xynhym4JfXtIx78s+OyHiKCzoRSDQudzMK7GnwGMtcSnIP3vOL6CachPMOdI8SZHzvF42/Y+FfYmYdtW5WMpnWqOuqKDY5DfVcIVcq12Hzz2RITF8yoIWnkY3xBL4DxB56/8qTF4mR6gUD53NlmIddx/p8ecECKX0n1t/m2k= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stefano Stabellini To: CC: , , , , "Edgar E. Iglesias" , Manos Pitsidianakis Subject: [PULL 4/5] xen: mapcache: Add support for grant mappings Date: Wed, 12 Jun 2024 16:29:39 -0500 Message-ID: <20240612212940.2178248-4-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB03.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001CC:EE_|PH0PR12MB8773:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d79c9e7-5f26-4794-36a5-08dc8b26d514 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230034|376008|1800799018|82310400020|36860700007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?IVw50FSbg6DdODPYSOiW5Nr2iXDaqrMk5Kon5J1g5+y5njSEO/eLX8cmuVN8?= =?us-ascii?Q?QWJ6M09/KvCkCuEovXe12Mgu/l/n2r5SvsdKToEqZ4WSMdpW2SlQnIpMgkaS?= =?us-ascii?Q?WegkLMahaU1nvDMXseepRJK/gBSx9bUo5qR39UBnv/whlqUO769YiLMdZHEl?= =?us-ascii?Q?nlmPRabR2qxKigwvz9YEZ7VhRbkajAk/1eGeac0L1dNCFHIDIJO4FQXRCL7l?= =?us-ascii?Q?/ZO2W+z/TMoQTLhJlRKSojWaW9zgSUqlvM6aGZ/Usv3hxCrvlq4t2VyzS7Kz?= =?us-ascii?Q?CHoAd182n3qAlU5YgSJRMf+R6ybFIQubN25Bozc3XdTI5ChohslU1zyePRdl?= =?us-ascii?Q?bEWm88RPTFqKK2LpQrljqgGsGV2/ovlVuq7U/3XcdFeJ55vNPFZPgmq2W8Pe?= =?us-ascii?Q?hTAlsJjNtEn5dhMdg0QjJTVaaS5fNY1iBWqQFyWrmwb2bE23fuW0i1mrZVBp?= =?us-ascii?Q?89g2GdPNH59v3dvjx1NEe4Xk767+S74MgynqPikHEdbQy0PAZlUyC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FxRwcpUDyZcGhNnFwDxSEwn6FnQ=3D=3D?= 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:(13230034)(376008)(1800799018)(82310400020)(36860700007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 21:30:07.6220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d79c9e7-5f26-4794-36a5-08dc8b26d514 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: SJ5PEPF000001CC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8773 Received-SPF: permerror client-ip=2a01:111:f403:2414::62f; envelope-from=stefano.stabellini@amd.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718227835410100003 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Add a second mapcache for grant mappings. The mapcache for grants needs to work with XC_PAGE_SIZE granularity since we can't map larger ranges than what has been granted to us. Like with foreign mappings (xen_memory), machines using grants are expected to initialize the xen_grants MR and map it into their address-map accordingly. CC: Manos Pitsidianakis Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-hvm-common.c | 12 ++- hw/xen/xen-mapcache.c | 165 +++++++++++++++++++++++++------- include/hw/xen/xen-hvm-common.h | 3 + include/sysemu/xen.h | 1 + 4 files changed, 144 insertions(+), 37 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index a0a0252da0..b8ace1c368 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -10,12 +10,18 @@ #include "hw/boards.h" #include "hw/xen/arch_hvm.h" =20 -MemoryRegion xen_memory; +MemoryRegion xen_memory, xen_grants; =20 -/* Check for xen memory. */ +/* Check for any kind of xen memory, foreign mappings or grants. */ bool xen_mr_is_memory(MemoryRegion *mr) { - return mr =3D=3D &xen_memory; + return mr =3D=3D &xen_memory || mr =3D=3D &xen_grants; +} + +/* Check specifically for grants. */ +bool xen_mr_is_grants(MemoryRegion *mr) +{ + return mr =3D=3D &xen_grants; } =20 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index a07c47b0b1..5f23b0adbe 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -14,6 +14,7 @@ =20 #include =20 +#include "hw/xen/xen-hvm-common.h" #include "hw/xen/xen_native.h" #include "qemu/bitmap.h" =20 @@ -21,6 +22,8 @@ #include "sysemu/xen-mapcache.h" #include "trace.h" =20 +#include +#include =20 #if HOST_LONG_BITS =3D=3D 32 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ @@ -41,6 +44,7 @@ typedef struct MapCacheEntry { unsigned long *valid_mapping; uint32_t lock; #define XEN_MAPCACHE_ENTRY_DUMMY (1 << 0) +#define XEN_MAPCACHE_ENTRY_GRANT (1 << 1) uint8_t flags; hwaddr size; struct MapCacheEntry *next; @@ -71,6 +75,8 @@ typedef struct MapCache { } MapCache; =20 static MapCache *mapcache; +static MapCache *mapcache_grants; +static xengnttab_handle *xen_region_gnttabdev; =20 static inline void mapcache_lock(MapCache *mc) { @@ -131,6 +137,12 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) unsigned long max_mcache_size; unsigned int bucket_shift; =20 + xen_region_gnttabdev =3D xengnttab_open(NULL, 0); + if (xen_region_gnttabdev =3D=3D NULL) { + error_report("mapcache: Failed to open gnttab device"); + exit(EXIT_FAILURE); + } + if (HOST_LONG_BITS =3D=3D 32) { bucket_shift =3D 16; } else { @@ -159,6 +171,15 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) mapcache =3D xen_map_cache_init_single(f, opaque, bucket_shift, max_mcache_size); + + /* + * Grant mappings must use XC_PAGE_SIZE granularity since we can't + * map anything beyond the number of pages granted to us. + */ + mapcache_grants =3D xen_map_cache_init_single(f, opaque, + XC_PAGE_SHIFT, + max_mcache_size); + setrlimit(RLIMIT_AS, &rlimit_as); } =20 @@ -168,17 +189,24 @@ static void xen_remap_bucket(MapCache *mc, hwaddr size, hwaddr address_index, bool dummy, + bool grant, + bool is_write, ram_addr_t ram_offset) { uint8_t *vaddr_base; - xen_pfn_t *pfns; - int *err; + g_autofree uint32_t *refs =3D NULL; + g_autofree xen_pfn_t *pfns =3D NULL; + g_autofree int *err; unsigned int i; hwaddr nb_pfn =3D size >> XC_PAGE_SHIFT; =20 trace_xen_remap_bucket(address_index); =20 - pfns =3D g_new0(xen_pfn_t, nb_pfn); + if (grant) { + refs =3D g_new0(uint32_t, nb_pfn); + } else { + pfns =3D g_new0(xen_pfn_t, nb_pfn); + } err =3D g_new0(int, nb_pfn); =20 if (entry->vaddr_base !=3D NULL) { @@ -207,21 +235,51 @@ static void xen_remap_bucket(MapCache *mc, g_free(entry->valid_mapping); entry->valid_mapping =3D NULL; =20 - for (i =3D 0; i < nb_pfn; i++) { - pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) = + i; + if (grant) { + hwaddr grant_base =3D address_index - (ram_offset >> XC_PAGE_SHIFT= ); + + for (i =3D 0; i < nb_pfn; i++) { + refs[i] =3D grant_base + i; + } + } else { + for (i =3D 0; i < nb_pfn; i++) { + pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIF= T)) + i; + } } =20 - /* - * If the caller has requested the mapping at a specific address use - * MAP_FIXED to make sure it's honored. - */ + entry->flags &=3D ~XEN_MAPCACHE_ENTRY_GRANT; + if (!dummy) { - vaddr_base =3D xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, - PROT_READ | PROT_WRITE, - vaddr ? MAP_FIXED : 0, - nb_pfn, pfns, err); + if (grant) { + int prot =3D PROT_READ; + + if (is_write) { + prot |=3D PROT_WRITE; + } + + entry->flags |=3D XEN_MAPCACHE_ENTRY_GRANT; + assert(vaddr =3D=3D NULL); + vaddr_base =3D xengnttab_map_domain_grant_refs(xen_region_gntt= abdev, + nb_pfn, + xen_domid, refs, + prot); + } else { + /* + * If the caller has requested the mapping at a specific addre= ss use + * MAP_FIXED to make sure it's honored. + * + * We don't yet support upgrading mappings from RO to RW, to h= andle + * models using ordinary address_space_rw(), foreign mappings = ignore + * is_write and are always mapped RW. + */ + vaddr_base =3D xenforeignmemory_map2(xen_fmem, xen_domid, vadd= r, + PROT_READ | PROT_WRITE, + vaddr ? MAP_FIXED : 0, + nb_pfn, pfns, err); + } if (vaddr_base =3D=3D NULL) { - perror("xenforeignmemory_map2"); + perror(grant ? "xengnttab_map_domain_grant_refs" + : "xenforeignmemory_map2"); exit(-1); } } else { @@ -260,15 +318,13 @@ static void xen_remap_bucket(MapCache *mc, bitmap_set(entry->valid_mapping, i, 1); } } - - g_free(pfns); - g_free(err); } =20 static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, ram_addr_t ram_offset, - uint8_t lock, bool dma, bool is_wri= te) + uint8_t lock, bool dma, + bool grant, bool is_write) { MapCacheEntry *entry, *pentry =3D NULL, *free_entry =3D NULL, *free_pentry =3D NULL; @@ -340,7 +396,7 @@ tryagain: entry =3D g_new0(MapCacheEntry, 1); pentry->next =3D entry; xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, - ram_offset); + grant, is_write, ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index !=3D address_index || entry->size !=3D cache_size || @@ -348,7 +404,7 @@ tryagain: test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy, - ram_offset); + grant, is_write, ram_offset); } } =20 @@ -399,12 +455,26 @@ uint8_t *xen_map_cache(MemoryRegion *mr, uint8_t lock, bool dma, bool is_write) { + bool grant =3D xen_mr_is_grants(mr); + MapCache *mc =3D grant ? mapcache_grants : mapcache; uint8_t *p; =20 - mapcache_lock(mapcache); - p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offse= t, - lock, dma, is_write); - mapcache_unlock(mapcache); + if (grant && !lock) { + /* + * Grants are only supported via address_space_map(). Anything + * else is considered a user/guest error. + * + * QEMU generally doesn't expect these mappings to ever fail, so + * if this happens we report an error message and abort(). + */ + error_report("Tried to access a grant reference without mapping it= ."); + abort(); + } + + mapcache_lock(mc); + p =3D xen_map_cache_unlocked(mc, phys_addr, size, ram_addr_offset, + lock, dma, grant, is_write); + mapcache_unlock(mc); return p; } =20 @@ -449,7 +519,14 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(Ma= pCache *mc, void *ptr) =20 ram_addr_t xen_ram_addr_from_mapcache(void *ptr) { - return xen_ram_addr_from_mapcache_single(mapcache, ptr); + ram_addr_t addr; + + addr =3D xen_ram_addr_from_mapcache_single(mapcache, ptr); + if (addr =3D=3D RAM_ADDR_INVALID) { + addr =3D xen_ram_addr_from_mapcache_single(mapcache_grants, ptr); + } + + return addr; } =20 static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, @@ -460,6 +537,7 @@ static void xen_invalidate_map_cache_entry_unlocked(Map= Cache *mc, hwaddr paddr_index; hwaddr size; int found =3D 0; + int rc; =20 QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { if (reventry->vaddr_req =3D=3D buffer) { @@ -502,7 +580,14 @@ static void xen_invalidate_map_cache_entry_unlocked(Ma= pCache *mc, } =20 ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); - if (munmap(entry->vaddr_base, entry->size) !=3D 0) { + if (entry->flags & XEN_MAPCACHE_ENTRY_GRANT) { + rc =3D xengnttab_unmap(xen_region_gnttabdev, entry->vaddr_base, + entry->size >> mc->bucket_shift); + } else { + rc =3D munmap(entry->vaddr_base, entry->size); + } + + if (rc) { perror("unmap fails"); exit(-1); } @@ -521,14 +606,24 @@ typedef struct XenMapCacheData { uint8_t *buffer; } XenMapCacheData; =20 +static void xen_invalidate_map_cache_entry_single(MapCache *mc, uint8_t *b= uffer) +{ + mapcache_lock(mc); + xen_invalidate_map_cache_entry_unlocked(mc, buffer); + mapcache_unlock(mc); +} + +static void xen_invalidate_map_cache_entry_all(uint8_t *buffer) +{ + xen_invalidate_map_cache_entry_single(mapcache, buffer); + xen_invalidate_map_cache_entry_single(mapcache_grants, buffer); +} + static void xen_invalidate_map_cache_entry_bh(void *opaque) { XenMapCacheData *data =3D opaque; =20 - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, data->buffer); - mapcache_unlock(mapcache); - + xen_invalidate_map_cache_entry_all(data->buffer); aio_co_wake(data->co); } =20 @@ -543,9 +638,7 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(= uint8_t *buffer) xen_invalidate_map_cache_entry_bh, &data); qemu_coroutine_yield(); } else { - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, buffer); - mapcache_unlock(mapcache); + xen_invalidate_map_cache_entry_all(buffer); } } =20 @@ -597,6 +690,7 @@ void xen_invalidate_map_cache(void) bdrv_drain_all(); =20 xen_invalidate_map_cache_single(mapcache); + xen_invalidate_map_cache_single(mapcache_grants); } =20 static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, @@ -632,13 +726,16 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapC= ache *mc, return NULL; } =20 + assert((entry->flags & XEN_MAPCACHE_ENTRY_GRANT) =3D=3D 0); + address_index =3D new_phys_addr >> mc->bucket_shift; address_offset =3D new_phys_addr & (mc->bucket_size - 1); =20 trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 xen_remap_bucket(mc, entry, entry->vaddr_base, - cache_size, address_index, false, old_phys_addr); + cache_size, address_index, false, + false, false, old_phys_addr); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h index 65a51aac2e..3d796235dc 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -16,6 +16,7 @@ #include =20 extern MemoryRegion xen_memory; +extern MemoryRegion xen_grants; extern MemoryListener xen_io_listener; extern DeviceListener xen_device_listener; =20 @@ -29,6 +30,8 @@ extern DeviceListener xen_device_listener; do { } while (0) #endif =20 +#define XEN_GRANT_ADDR_OFF (1ULL << 63) + static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) { return shared_page->vcpu_ioreq[i].vp_eport; diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h index 3445888e39..d70eacfbe2 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -50,4 +50,5 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram= _addr_t size, #endif /* CONFIG_XEN_IS_POSSIBLE */ =20 bool xen_mr_is_memory(MemoryRegion *mr); +bool xen_mr_is_grants(MemoryRegion *mr); #endif --=20 2.25.1 From nobody Mon Nov 25 03:26:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1718227845; cv=pass; d=zohomail.com; s=zohoarc; b=BEAzkP7jZ0PExqS3p6neOGIsFMZCWVz1x5zghTeH7vbhssk+LOUspE2fqO5sj2wEgvTvbEcvnykIKGPxobq/lCToPs8VnEkYIK7x0MVzZ7X/gXvySbn5mEfST+1zovdovQbtICmR7LrhAHPDpn4IlxAsXpXb27QZ6G+pv652fM4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718227845; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FS/ufF98+CmPb5JwYQeOLBlumDraNZo+bqd94MBYUeY=; b=NzTithQqF0DEAxZ8Hu2NtLsQ7RpBUyXg8ytk0S2FcyCIMx5z5PUOygbGpC7QVPUZhYAAXp5HThJ8+Wl1SH+Uuw5MBJJkyOaey0DTAeabEay7o8Gqn87wuqvb8ft6Suw2abLYnKof9uAyhpR3vKTgIfSBc9HjkbXGnonniLe6kVA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718227845927654.1620211390737; Wed, 12 Jun 2024 14:30:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHVXz-0001mV-Th; Wed, 12 Jun 2024 17:30:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHVXx-0001lI-LU for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:21 -0400 Received: from mail-co1nam11on20601.outbound.protection.outlook.com ([2a01:111:f403:2416::601] 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 1sHVXv-0002pP-Rk for qemu-devel@nongnu.org; Wed, 12 Jun 2024 17:30:21 -0400 Received: from PH7P220CA0042.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32b::25) by DS0PR12MB8415.namprd12.prod.outlook.com (2603:10b6:8:fc::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20; Wed, 12 Jun 2024 21:30:14 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:510:32b:cafe::36) by PH7P220CA0042.outlook.office365.com (2603:10b6:510:32b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.21 via Frontend Transport; Wed, 12 Jun 2024 21:30:14 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Wed, 12 Jun 2024 21:30:13 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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.39; Wed, 12 Jun 2024 16:30:12 -0500 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 12 Jun 2024 16:30:06 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cGouXfDUR4is1wE367BxdWSA6foMKLV5+SjrFMhTbPwbmPD5gm7KBXLZibcvToli1ehmAr9efXo98OqgJdVXeaU3Py83ROITr7CseSR6npWGNl+xWYH0c0v53IkQkcpL7aaIlrw5D9mKlg1HTuJw/N7b+/CIL3FFJiFpdfDQ3oGH08VEvrlqs+dEnVOb5k4+24MizmiATTv86rCPvFdcwH3IdmRC3pUTmaNh0zns+sajIJYCrNqfMNVCzn/Mngzvf0NBLkPLKA4WU8EtazAKL9TCU17WWSa0jaZC7f1Cb8ryY0eiLbMitqNRgL8VL2u3ZTs+wrc8+O7I1ZFyImnhQg== 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=FS/ufF98+CmPb5JwYQeOLBlumDraNZo+bqd94MBYUeY=; b=ktK84kz7CIwZ4cEkPzG98Bul/M7LBKAQQH4jdog6lRxBh/AW+4H4Ntuuxh0E+Mvn6y8UDNN169tZPBDgcBvJI4P/xmUWyXBnIZUBuZXX9mUCS/5oD1k4vF058kYrDx4Pf+27mDPFQEO6qBxV53pmuPe+YMA72XcumiysYbXCMESFBrdgtGQfoIH7Np2a+d17FMbIOMOsS6gspnpq1lqLkIIt7bbr4CKn2U9a1ipNtKSp/oGUXRy7aoqdLlnZHnvy4gQUi0hKFnSi1jOz2e4Z9L3NkzhnlxY164V2RPe0rTZazaQ9LKsgQpYy/kKj4CgDud3IjG8/pmzsXePFvvM3AA== 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=FS/ufF98+CmPb5JwYQeOLBlumDraNZo+bqd94MBYUeY=; b=dYfCYD1hNCoNMa+PcWLqba4NzY8HsVeGy5nXYy/caf6c09W9tRFbNdtCsKmk2Rrea4JodICi31RZO6BOgRyzAGzIy34EHRIv0kEXHYWqiBFKHZcmhA1+50G2vYFsrriust6N2TsD9GmOvAIuSim1pXYJ0ASo1UUGNzMYyVkhzx4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Stefano Stabellini To: CC: , , , , "Edgar E. Iglesias" , Manos Pitsidianakis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 5/5] hw/arm: xen: Enable use of grant mappings Date: Wed, 12 Jun 2024 16:29:40 -0500 Message-ID: <20240612212940.2178248-5-stefano.stabellini@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB03.amd.com: stefano.stabellini@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|DS0PR12MB8415:EE_ X-MS-Office365-Filtering-Correlation-Id: ace430e1-71d8-4c30-c73e-08dc8b26d8be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230034|376008|1800799018|82310400020|36860700007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?NUE3V1dkZWxUck1icE9tOUQwTmx0SWFpY0p3aDZHSWhYcjZaRjZOdTgzZ1pI?= =?utf-8?B?aGtTQm9pNzI4dkFiUnFkczl4T29SRFMxTDBJVUdXcXUxRVJ5R1dNY1ZTRG51?= =?utf-8?B?TXhlZWVJeTlqMWZ5MjU0a05zcVZwMjVmTzJ6a0ZNeW16Yjg3bUdNYkZFWi9I?= =?utf-8?B?TlhIS0RQaWo5OERTTzJSQURKTWRnNFRnOVRsUEpudEZ4d0p6VUdHOXhBOVUr?= =?utf-8?B?VVVCaXdJVSszU25zVVVNSFBUUG5jU0JxbTEyZU80TXhaWlFhZldnajZ4Y0hK?= =?utf-8?B?RktLSzBxSThMWWtScEdhVDBwek1kd25wTkJ0elRDa052TmpFSHE0ZFVVVkJq?= =?utf-8?B?OHA4NXlZeExxMzlaTVM2WWhZSndxWUluTHVJSzc4akRwejFuKy9YOTdiUW43?= =?utf-8?B?ODdrNkNJNTdBYTVFRjh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B?Tnk5cTBOSGtRWUFSUkZhTzY4Z1NRZ0hheUFYNmRqWHFoQUtqZm51MGRIcVhQ?= =?utf-8?B?M3RJMHNreEczS0sva0kyOUMxcW9oT0E2V0krNmZyemY2VVZHVHpHZ3dJMWZI?= =?utf-8?B?Si9GZ2tsRXMwR2dPSWE2c3BjVE55LzI5RkplYjczSjRoUTU4Z2V4TWorZXhU?= =?utf-8?B?ZkVDWnIxdEx2bEFBRmdBV2ovMWM3bXBpUlZCcHhrZFo2NEdzbkpyZ3pRVkhM?= =?utf-8?B?cWVIUmEzVks2bVR1NHlrSk9OQ1ZEK1A2MzBlQ1lONGhvcVFQV2F6MVd5ZHhk?= =?utf-8?B?dDdKRTBZVCsyV3F6TEhidElkSjFhV0hSUlZEVTFkdkticHZmclk2NndMQmZF?= =?utf-8?B?T2JoMUxlZXVqMXRwakluTVppekJ5cWJPaFFxYzliWmRpNzlIL1NxclNrRHNE?= =?utf-8?B?TlZoUENCZDhYeFBqcER6YkdEeE42VFVSUVdSem91QnRHZ1BXMWRLQlhTTlFB?= =?utf-8?B?eDNtckZtNUNlSVhrOHBmc1lTbW95bDMrZHdTeWtPek0wMlZHUWgwbVZYY3pC?= =?utf-8?B?TkJIMGluWm1XSCtoZkVCZnlPNVVCNUJQdmFvajdjNERvaGc9PQ==?= 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:(13230034)(376008)(1800799018)(82310400020)(36860700007); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 21:30:13.8043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ace430e1-71d8-4c30-c73e-08dc8b26d8be 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8415 Received-SPF: permerror client-ip=2a01:111:f403:2416::601; envelope-from=stefano.stabellini@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.143, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1718227847404100003 From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Manos Pitsidianakis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/xen_arm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index 15fa7dfa84..6fad829ede 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -125,6 +125,11 @@ static void xen_init_ram(MachineState *machine) GUEST_RAM1_BASE, ram_size[1]); memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi); } + + /* Setup support for grants. */ + memory_region_init_ram(&xen_grants, NULL, "xen.grants", block_len, + &error_fatal); + memory_region_add_subregion(sysmem, XEN_GRANT_ADDR_OFF, &xen_grants); } =20 void arch_handle_ioreq(XenIOState *state, ioreq_t *req) --=20 2.25.1