From nobody Mon Nov 25 12:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275822; cv=none; d=zohomail.com; s=zohoarc; b=gDTHtVau8DEhmoek8J3gwgsWq3kkk/u+grq351V7IzGpSsfiNKDEEhLz/q9GlivF2crObTA5L9zcoCKQOrTBi2y1v50g/jf6x7E660yPpHMtiA2DFyT7JxbThpZv7Tu/A6pXs7LZVH/2CeYwUQIvbOEiTEWeHLh5dMbtfTadfRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275822; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oKmmum6z28VcY8ouSg3YJA3bHZvP87XkBXtO/hd8PR8=; b=gEA4f2+ut2GP2hEDdFTLuzH3+BEfbw55Cr0qLCjaPnFtxw9bqJ5aHLj/Pv3q/ozzHMpMNKB1qfIe8ZwNgi5jFoW47eRGtxsYtg+MVzZHZMDpu4TOTUVoPN74Nh8muJvsi4Tc1Cq5rDh6eR6Hg8O9dwyH3rru+S5vWwc8VIeE9XY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 171527582259392.50236413852531; Thu, 9 May 2024 10:30:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.719344.1122085 (Exim 4.92) (envelope-from ) id 1s57aZ-0008I9-09; Thu, 09 May 2024 17:29:51 +0000 Received: by outflank-mailman (output) from mailman id 719344.1122085; Thu, 09 May 2024 17:29:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57aY-0008I2-Tq; Thu, 09 May 2024 17:29:50 +0000 Received: by outflank-mailman (input) for mailman id 719344; Thu, 09 May 2024 17:29:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57aY-0008Hw-4e for xen-devel@lists.xenproject.org; Thu, 09 May 2024 17:29:50 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id bc40b60b-0e29-11ef-909c-e314d9c70b13; Thu, 09 May 2024 19:29:48 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-51f74fa2a82so1374036e87.0 for ; Thu, 09 May 2024 10:29:48 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f35ad6aasm380187e87.46.2024.05.09.10.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:47 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bc40b60b-0e29-11ef-909c-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275788; x=1715880588; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oKmmum6z28VcY8ouSg3YJA3bHZvP87XkBXtO/hd8PR8=; b=nOC6rTy44r+zghYsUwaCP7+YZqjTSf/d95MwiNxlDoJXH9vgGoxpo5hgdo+Tmq6+l6 JgkSr8cNn46KPLfimy5+ODBpVqnHQizYzUcATkVE0vYPKZ7BJGrfT/+my+5h/Ib9ACNu 0i/lcHl7Bzfyky/C28moiEiMCw8bLaoOu3xmW3b/AVZx4M5NMxJEk1F2c5WyI7CnCeWb bHHrCAuW7KnECoEPk1+abmqvUzR+e+ujXuyIPzxopXnb5q8dnL4ANZqMsaOz/APO5p0r 3tQI3DDL4NdFfzVnk8jnxgGYkyMhT7jlmVxXi6upup02Qwqmt6UsogPvp0enTqbnrKHi 7wlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275788; x=1715880588; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oKmmum6z28VcY8ouSg3YJA3bHZvP87XkBXtO/hd8PR8=; b=kZXTZRptPhbtXGuYtgsaSYPekwv+IX0jRBz1exW14ikP3Lm98j0usIUyUmwl2KyieF PLOeuxsc2G5rvFe6svIPABdNTpcaDrX9pnNIrRYVTLlUSSDEAetB72GZhM41IUrFgGi9 +Jl68M45h1zDbp29bxD1c8H68uN81zfgkKh0zuwt+IZ3EnLdP2HkMHyqenx8WcJSjRh1 rF9lBamefTUZb75A5e3JjVpvyRPWLD8Sm+2IguXerBsDPM9ripVrb5nKPWI6z4SlGI8g jEedoIf+rm9V26EJicNMARszEzE4iLZD0jVGzJlqXmnMlHIVK414tMZXRiFFYxuL6pUP F+1g== X-Forwarded-Encrypted: i=1; AJvYcCXaJAHJmrv9127a45R6TD5XBdx8wwWF+DEvACUrQpoeaMRUPd5Wdqs+Mo5mq73UeDYf/ZivhUec47YaaozwzNh+CNX8zo0WNHMm0gllcyY= X-Gm-Message-State: AOJu0YziXWMLglbrRB+HaU9EOncJVr3OBNvlV75HtYWcqJ8VdljqqoHf n4FKoBGK6KDuzS69NVRaeAczsLHy2zXgVbbmZsZXcY872UXQdEH6 X-Google-Smtp-Source: AGHT+IHeG8OvDdp1Hd81Fpds95oiK0KakPxNqX9S4bKF8EhIHxH47+4gyRALZxXJUz32rN+uwgkC3w== X-Received: by 2002:a19:4358:0:b0:521:b42f:2674 with SMTP id 2adb3069b0e04-52210277c35mr145762e87.63.1715275788076; Thu, 09 May 2024 10:29:48 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v5 1/8] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable Date: Fri, 3 May 2024 03:44:42 +0200 Message-Id: <20240503014449.1046238-2-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715275822810100003 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Make MCACHE_BUCKET_SHIFT runtime configurable per cache instance. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- 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.40.1 From nobody Mon Nov 25 12:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275816; cv=none; d=zohomail.com; s=zohoarc; b=kE249s9Z1j8SXdBwG0wsQGrvSsukcbcNC5K5dM7+9qkjtH+f0198bqPwtYjCMvPiK4RyQydH8gzTR/RT/PvXjj5zUR1Yh37Npw/sEfdmWUJ9In8UuCVtPYNgu6b01+PNh1B7YmL77JpJLzaSUtYF8eBWtCjbIqUuHrLeXoD2gpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275816; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=suqLmt7AH8VX+OrzngkGIik/kesngvj14F2vCYL7OFM=; b=Z0gSxxiqcNQgmpxqqkcdSKmhwkNwn1C7H+gyIiqSrHxV3eSp/V2w6MKXeNKLVNVYNMxcpMeel1SD/C8r9r6T6bierISA8K2jiC5xZIHAYiThrMq5nJE5SaK1Q7lKJCKECB47wnlCbGflFjXCexDkRO1QsxfXGM3vS0ep9w1whF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1715275816317893.9974382877942; Thu, 9 May 2024 10:30:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.719345.1122096 (Exim 4.92) (envelope-from ) id 1s57ac-00004u-8G; Thu, 09 May 2024 17:29:54 +0000 Received: by outflank-mailman (output) from mailman id 719345.1122096; Thu, 09 May 2024 17:29:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57ac-0008WT-4H; Thu, 09 May 2024 17:29:54 +0000 Received: by outflank-mailman (input) for mailman id 719345; Thu, 09 May 2024 17:29:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57aa-0008WC-Rl for xen-devel@lists.xenproject.org; Thu, 09 May 2024 17:29:52 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bd582202-0e29-11ef-b4bb-af5377834399; Thu, 09 May 2024 19:29:50 +0200 (CEST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-51fa75d54a4so1073217e87.0 for ; Thu, 09 May 2024 10:29:50 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f38d3445sm369206e87.176.2024.05.09.10.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bd582202-0e29-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275790; x=1715880590; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=suqLmt7AH8VX+OrzngkGIik/kesngvj14F2vCYL7OFM=; b=aQPuzg28DBNabnU97KSBvxy03U0QOnNHPs9bhMEg2LFL8rJPouWJh6MAzqyKrOp9Lf GrTp+x9/GXvS64i31INkqD0VZlzgAIQwhe6PFIhI+me2XDBuY+OhsYGeUkIRTtSm7Wp5 lY8klhHUDcgKguAnAEVqRsX4ql28WBaV+RBBpwZSNo/ZThHxTzajDgnSYHeRP/xmZSoA 7HpBEEwTPk/uAQ6+CRZnxw+bv9+1CQr9cu/BHLHX650ZDSAARYSY476MT9+H4x2K6W/X 8M6BmDuLwLRGcWavejxeK4uCrolFD512rCinkyKaW0tCukFKhOkO7vCZkJHaR7TJ3hCu 1qWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275790; x=1715880590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=suqLmt7AH8VX+OrzngkGIik/kesngvj14F2vCYL7OFM=; b=lMSWSLQDsZfoDjB49splZp0NBvGMKit9cl3qq2UFV6ikLit41LPJR0Gpph7qKhaLfO 06Dm4BDKPsxo8aXE1o9SKE7TT3skYVpR8jgxPr3udyto9m2hDUSeIgFb3va1WSGccz+9 rzA3TX5aXnNMcMUTFynAvP+iiaQaLEiChOYhsokuhhtkAYuCQev2tHy32wDx38E4vvFH /n0qq0RJn2rs+4YAb468vfoPLfiBCtFlsh030FPvttqnjWAy+0xi66/56LLB58xRWHFu FMdJKjsX7HKScStaEKw4iBKTOj0ixfBzo3UBFjQ89v3hulbfh8ucu2WThzUuglm8nWdf uglw== X-Forwarded-Encrypted: i=1; AJvYcCX05g2umvrbV3n8QEfHLA+McmTfGPwXzgkHEtZk37AipmeefB9OXiec5bR78xU5DQZWGlCSyLfy9mk7fDPeDc3jAVrmm00WMHGwAJeQvhc= X-Gm-Message-State: AOJu0YxK+fdHAtMTwOUpswQLocbnq/I42955vMrDuOvqsWzmNgNDQJK5 y2jbtBA45THYCQMxQReMwAxHev+SfcJlJu3rU4eBz2FlZDq5l/Bq X-Google-Smtp-Source: AGHT+IE3429+Ctid+D4EtDpgneRZV++HVd+uIfkCNO9kCmImtP+ysIxcQpHU7yrc/kJeI1cp4rrEpg== X-Received: by 2002:a05:6512:4027:b0:51d:866d:8cf2 with SMTP id 2adb3069b0e04-5220e27a334mr125318e87.6.1715275790078; Thu, 09 May 2024 10:29:50 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v5 2/8] xen: mapcache: Unmap first entries in buckets Date: Fri, 3 May 2024 03:44:43 +0200 Message-Id: <20240503014449.1046238-3-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715275816729100001 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.40.1 From nobody Mon Nov 25 12:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275816; cv=none; d=zohomail.com; s=zohoarc; b=Ve3w/KEbsmE96ghk/b3hoSglQhhjtZWQJZ4Dv+yrCWxqjs+nXMEc6FjAvpsfSvJNZV8CJ9gHflhGrh6R0YxYDUevM/7dHHXzNxLUwasWefxQpAhf9dfLHq0ZbPHY1V/B+3oMviT3YNtzTPvPWc6iI4ZUQ6PB5UeTN3QRpSHu+xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275816; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8CWrR8s0gYDS+czdwwl88oUb1Zx/cHo9QTV6MX+PdaQ=; b=bg5Y3sdKYmghWhd6Fr5esg0BHCBPwwF8x7z9XKxkWPvEx+AAIAuUnUQjoF3tiookltr/6UszUXbRL138A6pzXaegSivxYy8zl5PrW1zVDo1gSwQ3v9j6gd5G2zl+y85fxmacXWu7XOtOz7AT/RoJIgbHfVJ8XBcCy+/ArpqwTiY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1715275816289881.763547788659; Thu, 9 May 2024 10:30:16 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.719346.1122106 (Exim 4.92) (envelope-from ) id 1s57ad-0000L4-I0; Thu, 09 May 2024 17:29:55 +0000 Received: by outflank-mailman (output) from mailman id 719346.1122106; Thu, 09 May 2024 17:29:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57ad-0000Kx-EK; Thu, 09 May 2024 17:29:55 +0000 Received: by outflank-mailman (input) for mailman id 719346; Thu, 09 May 2024 17:29:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57ab-0008WC-Gv for xen-devel@lists.xenproject.org; Thu, 09 May 2024 17:29:53 +0000 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [2a00:1450:4864:20::230]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id be241a25-0e29-11ef-b4bb-af5377834399; Thu, 09 May 2024 19:29:51 +0200 (CEST) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2e34e85ebf4so10422421fa.2 for ; Thu, 09 May 2024 10:29:51 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2e4d0ef229csm2555471fa.66.2024.05.09.10.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:50 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: be241a25-0e29-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275791; x=1715880591; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8CWrR8s0gYDS+czdwwl88oUb1Zx/cHo9QTV6MX+PdaQ=; b=PuaZxYbh4dl/k+kRVrw4kzEzL7R/4qBmasKmm76uPOIncuiut2RFZf7lflsADVIVsB SaTosd8Vsn7VFTZk/e8aVWYApbSRPAQozer5yS2XcDPdEl1vsk3w7PrqFIR/qEnJZoCv yaouowfMbdNOajLJsZXiDslCnGw5yn3mEjMLOBvNq7glRAVtg8w659yNHGWvR1aPqXiy Uio6i1I3cwzCsXscFobRyHqk9sO19RH/qK3FhrhBJUqnG7oX80tH76TUDTg7jNz06X5n BbcXxkNkngr4U237Omw0/9ng0oprG6TsLszr8PKqVei5tdlubq4RI1dqWegwyQ8SfkxI 8yJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275791; x=1715880591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8CWrR8s0gYDS+czdwwl88oUb1Zx/cHo9QTV6MX+PdaQ=; b=fhZYJ55ZiLTSSXCsvMjp4V9Jm1AB1xj9xofq/lH3ROLOWHnHU9sY5SoTa9LQOBj/MN xjjmJmyHC6OFujz+yJfIFPTeZOWPfHKj/mOMorLXDze/ZCLJSEQcuxt8tD4tfvzrdiRY UsqurTc6wsX80rhyACDipanFagin67DaScQ97jEqFvXtlBmYBcyTHcAI/sJi3+l3ho2C 2XIl5CXwhkiKUXDNTeq2kFFoiNDtK1GbjK8SPBOvS1JJRxa8SQetE27LIQJxrPsPLdst Qhl8ozjSp6WakvYAIizMb478SzsNQmP9+Sbhp02OANTZDefpeTy2W+KZK4vLmRcYeRrt raZw== X-Forwarded-Encrypted: i=1; AJvYcCW4brdFwiJHJtaoWyYV1Ul6i3CprM5vMhm1s3AkAnDBU9Od8K3XEIc7OoCHJKhSXcLMrZxjFjSsdb+4cI7y1L8WXXBiuXWpW1tX/RJHhas= X-Gm-Message-State: AOJu0Ywl9BeN31qCpPz/bNiExqHt+gHc9R17/AMMKMOGoxLKL1MlNpsG niEB8b0lgAIOO7MH0KENycxnTFfwBd1CjsvD2fzhS9xkwF31Ou6k X-Google-Smtp-Source: AGHT+IEqPcOqKJgEtzLBhZogEkbqeGe1tWfxm6fA+Z6yvRB5yQwN2WVk6iss6MyCzgHI/1kn9iQ+GQ== X-Received: by 2002:a2e:be13:0:b0:2de:25e2:6187 with SMTP id 38308e7fff4ca-2e51fe57b06mr778381fa.23.1715275791414; Thu, 09 May 2024 10:29:51 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , David Hildenbrand , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v5 3/8] xen: Add xen_mr_is_memory() Date: Fri, 3 May 2024 03:44:44 +0200 Message-Id: <20240503014449.1046238-4-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715275816809100003 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Add xen_mr_is_memory() to abstract away tests for the xen_memory MR. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Acked-by: David Hildenbrand --- hw/xen/xen-hvm-common.c | 10 ++++++++-- include/sysemu/xen.h | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 1627da7398..c94f1990c5 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -12,6 +12,12 @@ =20 MemoryRegion xen_memory; =20 +/* Check for xen memory. */ +bool xen_mr_is_memory(MemoryRegion *mr) +{ + return mr =3D=3D &xen_memory; +} + void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) { @@ -28,7 +34,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, = MemoryRegion *mr, return; } =20 - if (mr =3D=3D &xen_memory) { + if (xen_mr_is_memory(mr)) { return; } =20 @@ -55,7 +61,7 @@ static void xen_set_memory(struct MemoryListener *listene= r, { XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); =20 - if (section->mr =3D=3D &xen_memory) { + if (xen_mr_is_memory(section->mr)) { return; } else { if (add) { diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h index 754ec2e6cb..dc72f83bcb 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -34,6 +34,8 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t= length); void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, struct MemoryRegion *mr, Error **errp); =20 +bool xen_mr_is_memory(MemoryRegion *mr); + #else /* !CONFIG_XEN_IS_POSSIBLE */ =20 #define xen_enabled() 0 @@ -47,6 +49,12 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ra= m_addr_t size, g_assert_not_reached(); } =20 +static inline bool xen_mr_is_memory(MemoryRegion *mr) +{ + g_assert_not_reached(); + return false; +} + #endif /* CONFIG_XEN_IS_POSSIBLE */ =20 #endif --=20 2.40.1 From nobody Mon Nov 25 12:21:28 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275859; cv=none; d=zohomail.com; s=zohoarc; b=hFrYTaEzuX7pMPTJHGjuiVH0U46vDtEGA1Fe7EypRaduRDwBbTMgn+8cFI45s2WWhcEyWdAIhks9eNqOxr32vK7lPSuyje9X6DuWKIYkG4vum0DBPCmOi/6HXe0liqgLA8c9vcdPV0ja+qZ5H94rwE3fY2BcbaXBJzDq9MfczSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275859; h=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=4Lu12U4WovTW3hf1eOudpLM8QHHuwL/cl/TS4TvBDsA=; b=a/UF738eC51Dg0n1RoHkoXCjVdLIIPizQxo+KVYoIV6ahxwary5zhCKgNk+kCbsa71QT+5P2TZz0W/DgSDBeijkzdZg8QWSYDrC7hDhsj4IKSnrJ6qe1qbsnJ/7fhjcsSLxqggMW63d88g8wfjLjb4btVYjlMUMteJ/ZJueHxOI= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715275859334439.1664834840185; Thu, 9 May 2024 10: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 1s57al-0001jr-K3; Thu, 09 May 2024 13:30:04 -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 1s57af-0001iB-MF for qemu-devel@nongnu.org; Thu, 09 May 2024 13:29:59 -0400 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s57ad-0003dj-E8 for qemu-devel@nongnu.org; Thu, 09 May 2024 13:29:56 -0400 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51f174e316eso1404533e87.0 for ; Thu, 09 May 2024 10:29:55 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f35ba80fsm374153e87.93.2024.05.09.10.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275793; x=1715880593; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Lu12U4WovTW3hf1eOudpLM8QHHuwL/cl/TS4TvBDsA=; b=gTHhFZAIvRCgkqnxnVNiKVOazw++i7bdtI4pBkBYWJNYQ+wZDKNAGjBwSjLfKj/o2K Ugb6kJOC6UxMze4IwZtqRzzE1arxSGW1+s5TDUDGU1/knxIwAJq1Dta5BcV9NqX6eRxd 9SBrDckN6xy7SKNQj3610Rc4HbP22J+GGrUcISSQADzSAZ4FOjd9bxbvh9mtTZin5m1a kb2Xh8zw0SUdurqJzyerMkWjN8GQBuLv6Kc2Fvf2m21HENzqIETNctof4qaFx1e8T/2Q r98EcRcWAprJ/oBmfkR+rl+a6UQdYGlgQIbyyZDMFz7LrCbM2g8H+iHMUdppWJsBOh3P e0qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275793; x=1715880593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Lu12U4WovTW3hf1eOudpLM8QHHuwL/cl/TS4TvBDsA=; b=OGw1R5w3fGwH8Z8w43WmmDW3S0ROKAvG+4bkAq/Q+6AVu5A54+o7L/Xg4t3IrYbqxs CMQDsiPHZgQB4u4IGg5Q2OT/hSJrLMvbp0AXQNIhEk6E5wvQRKVUwhzWPaX/dJomiYig aHuexhHvyar4JqycSCeffXZO8fuJBmriBbiyvHLPDYlzQW7Vhu/VqdPCeWZWAeDFUn66 tTZANe1dNCV1iq4v/A0S8u0bCXum72W6wD/jYwF70EkwCo6wesuQeR8xwtTBRY7nMmsu jdK44ISJbLJH02Wwgs59YnqzTx8/cyjAFc+xnIpwpmigWh1acmZ3soSGy/BCQrJsRib0 XA5g== X-Gm-Message-State: AOJu0YwD/NswbyjBPaVNlaSO9BOBVI9PiZ/X+uwamoCIZbWQm46t8cdk QiDmFpo4ir9+PzrcmmiT9CjOuK6WRDtLIcWnaRQt0bvEMc8oSX/kY5AMhunR X-Google-Smtp-Source: AGHT+IFpUN2UJ5Y05+XgtMWXD1dZLnsMtTgxcLNFyRg8yefE+FmcaLhEFX2t+nfVa9EMZmhaMtK/gQ== X-Received: by 2002:a05:6512:3494:b0:516:be80:178f with SMTP id 2adb3069b0e04-5220fe7934bmr127564e87.43.1715275792802; Thu, 09 May 2024 10:29:52 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 4/8] softmmu: xen: Always pass offset + addr to xen_map_cache Date: Fri, 3 May 2024 03:44:45 +0200 Message-Id: <20240503014449.1046238-5-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 client-ip=2a00:1450:4864:20::12f; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x12f.google.com X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @gmail.com) X-ZM-MESSAGEID: 1715275861149100005 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Always pass address with offset to xen_map_cache(). This is in preparation for support for grant mappings. Since this is within a block that checks for offset =3D=3D 0, this has no functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- system/physmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/physmem.c b/system/physmem.c index 342b7a8fd4..5e6257ef65 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2230,7 +2230,8 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram= _addr_t addr, * In that case just map the requested area. */ if (block->offset =3D=3D 0) { - return xen_map_cache(block->mr, addr, len, lock, lock, + return xen_map_cache(block->mr, block->offset + addr, + len, lock, lock, is_write); } =20 --=20 2.40.1 From nobody Mon Nov 25 12:21:28 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275911; cv=none; d=zohomail.com; s=zohoarc; b=nL/pklHsTsqv49aYZ5hFTw7JoorNj0KO+YZqgY3FEqrB6DDsHFMQnGRhrIyuZjoAShY+1DWi2yhHHchilH+F96JQCJKalFQADD3EciAiW2V7y98aKq4pFgZ1DXLM/pWhjJUL1R9RnYN8o6Gt4lmBNKwvB+S8weqpmkqJluo70tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275911; h=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=88iGUBfmU5lozJiJBggIOABZEHW2b7csBLSZoA2gDGg=; b=Kw4H1mklBeTswZJYKjy5vCfnLfUakNmDV8M+AYS/FcbQPLwjW4YnUvUBbxIZFcuV2RINfOMvyQJRAojoHKe5w1Swb77lELrks4RfkNJyhi42y0hTGY63u7XYSree7KodYS3urqJxeRHLcD2PnJGDwOTioETh4q1QinwDVlS3UGw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715275911572657.320632306985; Thu, 9 May 2024 10:31:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s57an-0001kg-Fr; Thu, 09 May 2024 13:30:05 -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 1s57ah-0001iG-02 for qemu-devel@nongnu.org; Thu, 09 May 2024 13:30:00 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s57af-0003eb-FN for qemu-devel@nongnu.org; Thu, 09 May 2024 13:29:58 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5206a5854adso1284218e87.0 for ; Thu, 09 May 2024 10:29:56 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f35ba4f6sm375156e87.84.2024.05.09.10.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275794; x=1715880594; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=88iGUBfmU5lozJiJBggIOABZEHW2b7csBLSZoA2gDGg=; b=UdeOFH73UWmR4hhXqhe53sSYwIi1aI/njNiDXxBqntk40fLe3U1VKyqSH+GPyHVpxI W3x2rbr84RNJGfJbecOUSipXjQnXu078Wnb0LND7HvpzABgWyBkI2goicJ8djOJcxJ4m E/ZAgreHBrKGgCDfNJJGeMAaOFWMoC4kpfIqlluRkxU5i2t7mNgSMEtd81vA9mbO+++O 9eIUYRRTdJgQqtIhKtnzmRl1CNsngzFV/Hm0AFi5d0apDmuDFAK0CmBmCRcRgUzm+Qbh O7TRtISy67KHBDAK6z9qWNTp13J0aVbkM2E8qEK2GNVMoC4ccvF8KoTykgsPt1r3ywcn TmlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275794; x=1715880594; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=88iGUBfmU5lozJiJBggIOABZEHW2b7csBLSZoA2gDGg=; b=H5uAvu59LhBacgfE6OMODyxZ6dGuoPxr6pajVAqWtvGHRSyGK8UqVs54Tx3M9C9hQY 7njGww9CD1IRmuj20uE2M+KrkulCPHBa3AcdTJh4sNJYOWIsacKC/miZF2kThbiSE81O L7PuurEwqxem6Lo5a6DuE8EODxTeeSeGXWW/eZD5Yav+Lmf0O6TIaa0+YkRe+LIcDAIx 1puQ1mX2xwQVRV835IAn6h5lCzR4wBUw0Aa1gOm8pU6wVNb/IrQ5BhKPMtm91jDYj7K5 JZyvSon0fXpNEGrucUj3V8LXZfkZwPfbmCtM1XpHFNxTFqc0SbCEIp0ZEXOcEv/Hg2UJ 4pIg== X-Gm-Message-State: AOJu0Yz7xH919G437wYbRrJjwhASUH1NP7Z6Ik8JB/H+bB6YCS6Cy+QH P+mhJKItrEDZv0sf4duOi4YT4tGT6NeVf9PKIdM321YDHXPizAx1/N353NPl X-Google-Smtp-Source: AGHT+IFvDDGw033tziAuQdDRYGe6Yu4CE0pSWf6+eY/e0DmFk6sZdolbsDStXsJCH5g4KXCFrIjbCQ== X-Received: by 2002:a05:6512:3487:b0:522:92f:508d with SMTP id 2adb3069b0e04-5220fc7329bmr119443e87.10.1715275794366; Thu, 09 May 2024 10:29:54 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 5/8] softmmu: Replace check for RAMBlock offset 0 with xen_mr_is_memory Date: Fri, 3 May 2024 03:44:46 +0200 Message-Id: <20240503014449.1046238-6-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 client-ip=2a00:1450:4864:20::135; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x135.google.com X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @gmail.com) X-ZM-MESSAGEID: 1715275913349100007 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" For xen, when checking for the first RAM (xen_memory), use xen_mr_is_memory() rather than checking for a RAMBlock with offset 0. All Xen machines create xen_memory first so this has no functional change for existing machines. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- system/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/physmem.c b/system/physmem.c index 5e6257ef65..b7847db1a2 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2229,7 +2229,7 @@ static void *qemu_ram_ptr_length(RAMBlock *block, ram= _addr_t addr, * because we don't want to map the entire memory in QEMU. * In that case just map the requested area. */ - if (block->offset =3D=3D 0) { + if (xen_mr_is_memory(block->mr)) { return xen_map_cache(block->mr, block->offset + addr, len, lock, lock, is_write); --=20 2.40.1 From nobody Mon Nov 25 12:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275820; cv=none; d=zohomail.com; s=zohoarc; b=TYfOwJEkbdGlHXXJcPnuzoQ9gfUihE5nnw7DDXbXKYOOHsIzaTBaAmlY4BROjPiznI90cWRCwt+wP9KJH1X0zPA7XiEG/BD4RdoLADAgNGIZVPB9bwanlkfYRAivZhIxfiNPDgM9CK/AogY14eVd5OY6nkmZIk4VOSAue3I91p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275820; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jPCYivsqUnFKto+ateYrmLlKD4VaCAkHPo9leQ/G7oM=; b=i0+KZGIKqSTJB7Xc6VdVXAfoECTqcPKqevHuC5nXL51Erkhf1S7iJzYiBzI38SDVHe8gRKwJbDm2nComJ9xqtLCI56f1Eal6YUkR+ri8sPl1YhhEeWr07nIidDp7QypScKDW2FRi/cgYJz+yPP5j4ezoOjcpG7TtCBHQ1HgJkrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1715275819829244.29977914257802; Thu, 9 May 2024 10:30:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.719347.1122116 (Exim 4.92) (envelope-from ) id 1s57af-0000bv-OL; Thu, 09 May 2024 17:29:57 +0000 Received: by outflank-mailman (output) from mailman id 719347.1122116; Thu, 09 May 2024 17:29:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57af-0000bm-LW; Thu, 09 May 2024 17:29:57 +0000 Received: by outflank-mailman (input) for mailman id 719347; Thu, 09 May 2024 17:29:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57af-0008Hw-66 for xen-devel@lists.xenproject.org; Thu, 09 May 2024 17:29:57 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c0f9c272-0e29-11ef-909c-e314d9c70b13; Thu, 09 May 2024 19:29:56 +0200 (CEST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-51f17ac14daso1451647e87.1 for ; Thu, 09 May 2024 10:29:56 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f39d2cb0sm364149e87.276.2024.05.09.10.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:54 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c0f9c272-0e29-11ef-909c-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275796; x=1715880596; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jPCYivsqUnFKto+ateYrmLlKD4VaCAkHPo9leQ/G7oM=; b=cdxGtIkoQ2NtQdDstJoE1QMd6RABv6PUMUNpPzqgkafNHpYnkHWPndoFdUG+8RZgUb FPh1O0VyQMF31JHf1lAekHquOxoiRdYpdNebtq1YcdNxNWaoIUSJ8QxVOIw+UCJxX1GL zUC/Krxo8ASngS/wOFDLk+1Vf/OFR0R1blPebHCPCTB5Yqsr3wEWqO9xu2GBbB4rZDSQ 4yjitCxpo1wXDjk9rkkMc4yKA2Po2+Ezv1qJSxvIHgXWwtSaO5jPcUrRED0hQDOZi6GD dt5zxmVpjckQxKAeznh6cmfenlRiY/4UBNXbi+mdehGpxUhLrh+q9JRxneWaezjpwhRo 4H1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275796; x=1715880596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jPCYivsqUnFKto+ateYrmLlKD4VaCAkHPo9leQ/G7oM=; b=jimZS/YeLK1nKdORtedOOKqSOnxIq7M2oFrd6OeDW5cHnKBIYDCv45KXM7HxS1uWdW r4/Gzughpl0H9quEUWZrIAMQeqqjf8Px9KWLBc24Cjy8bA3uuuBOdNWyTSVR9wjlmxr+ lGRsZvVJAdZfAtyBVhYSYfdaRD9gtJ8U7aA+SzQ1BZY6bCb83zEFxwhuMvqwigNxk/y2 Qqbm5MlYH0zyQmfxDrTEsAhu5CTfa8/q3+YuOrD67M5o/T1Hv+QEVfZ5woUQ2KFirzaK xQdyRWpTu4mpXZqgv4ERsyZZWa5iv/0m537bjJr1ZtxF6GPCDhT55nbN0S23igz0aFJj oXFw== X-Forwarded-Encrypted: i=1; AJvYcCX5FfBL6c2Sd0T9V9J8KxPNp7+dWrt//o3qMM59lSZEC2oQI1eWK8rJlxv9KoR6IxxoduplMFny15K7hdvUKc18S6k1e++lzttb5WeTs6Y= X-Gm-Message-State: AOJu0YzcHwJJqcQU++seGNKTeBJBMqdQ6BehbZInhkwO5Q0Lp3gMWnD3 P3iEUmbKgYxveHOxnQ2Z4JkLJ5I2Ug9hlYWpZLs/7k3Q9kQGSkrb X-Google-Smtp-Source: AGHT+IGXpW00WomSWOz6NY89WyIw3oecHI+P6P9NdIdqTkVjlwXFHCkPAdJcU5KxXWJWBW7z9vO7OA== X-Received: by 2002:a19:700b:0:b0:521:44ce:2999 with SMTP id 2adb3069b0e04-52210074a29mr116899e87.47.1715275795997; Thu, 09 May 2024 10:29:55 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony PERARD , Paul Durrant , Paolo Bonzini , Peter Xu , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH v5 6/8] xen: mapcache: Pass the ram_addr offset to xen_map_cache() Date: Fri, 3 May 2024 03:44:47 +0200 Message-Id: <20240503014449.1046238-7-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715275820855100001 Content-Type: text/plain; charset="utf-8" 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 --- 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..26bc38a9e3 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, new_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.40.1 From nobody Mon Nov 25 12:21:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275823; cv=none; d=zohomail.com; s=zohoarc; b=VjWTzGtqWBf44ghgOuUUpZFSeBWn1tStT2N9o3G8IhnEHMFA3ad2SG0Mt3RvAcg2o2llKBC9z9MTutGuFg9tgcnCHS9juatMg++olt0sZTmJ0ePQ4jyeE1tnsRquRNEollRw8lkaLF3ODaOTnYcIp2bUqL2TM6Q8xLi+Q7XrTPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275823; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PjxS9Se2SHC9m/lZ6uD/ahAlHp9nRH2Q1MtnYySD9v0=; b=bE94jl6FH1RrvxFA1qppoRmeJd8eg1nkCKlzxcNlJnk6pTrYwcldqd1bIktjL0OaaeTc+fsRoutY7dVM5CrfLkzO5xINmhW9xGnUumPC93OsIhT1mBLgDbh+hXjiVNUGjK+ySdyio/WWJRSUOydCOwUom7TMH2ueCZlB477ALHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1715275823251355.2309009908747; Thu, 9 May 2024 10:30:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.719348.1122126 (Exim 4.92) (envelope-from ) id 1s57ak-0000vi-0f; Thu, 09 May 2024 17:30:02 +0000 Received: by outflank-mailman (output) from mailman id 719348.1122126; Thu, 09 May 2024 17:30:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57aj-0000vO-Tx; Thu, 09 May 2024 17:30:01 +0000 Received: by outflank-mailman (input) for mailman id 719348; Thu, 09 May 2024 17:30:00 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s57ai-0008WC-CG for xen-devel@lists.xenproject.org; Thu, 09 May 2024 17:30:00 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c1f8af77-0e29-11ef-b4bb-af5377834399; Thu, 09 May 2024 19:29:58 +0200 (CEST) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-51ef64d051bso1304131e87.1 for ; Thu, 09 May 2024 10:29:58 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f39d33ccsm368544e87.293.2024.05.09.10.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:56 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c1f8af77-0e29-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275798; x=1715880598; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PjxS9Se2SHC9m/lZ6uD/ahAlHp9nRH2Q1MtnYySD9v0=; b=W9d0mG0BaWt7TCuX8g8QYV4JmqXip+11ZS62UaPKXkT24DoWqgcSzTBO0lXDBW/WET qOxbcabEohqXs3xt8wZzyGmIU+NCvWNO2z7WaTMxSPaIZ2l01Oy+eTq4wlbplkTdTKFz ejkI2/arJ7xEU5oo6zad/Qd7pyiJT0D2J8mqE3TPMOdKmQLleHccnoeQV8+aA+Wo5XFv 3AhEyo+7W6HNCFzk4b1rgfB1VfY/YfPKH9Tmlh69pubBkB9JpXQHoh09QjsLQzR/ZGSg m+NYnq9icsBk2Jsd9CisOTlcartj2CRhtN76HaM2O5uLvux1NTdy5f9r4mia1JpaiwAq GGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275798; x=1715880598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PjxS9Se2SHC9m/lZ6uD/ahAlHp9nRH2Q1MtnYySD9v0=; b=utICSxUibsX27aY5TtuuqaQG40aWZzSOELz2iTDctbTX/kitklFTrOXqdLdxHwjZmU CjpK+8exoYRiTFbRuxlpqMS2VPzUOcJkV6PntU+OczTEbtsIx/uY78+CmQE4NIY6xBcR EDLU/Zsh52p9Ytvc52aBPiVZuALSIixNWnL02TnpBfls7fRGr16Zybv1tMPCtyZI3zjX T9GEA6giKxVkAwFZuT0HYol2BMPEya3D9fw1r+dakFw7XAB8S4HNF/rq4hMHtHxG3fnM cTSfoe/E4pYwyp8zWTkPsv+F1ijMFYwdz3b0uD/EJbvuQkGEsn4qXSLsedi8EJ9FnGIm vosw== X-Forwarded-Encrypted: i=1; AJvYcCUQhc5UN/G5/Q7Wwwhk21k/LLSDt3tbIpTNg/3xM9sGmHZoH/wfHhJEmcYBlYH2mC11y5eJm3qK2/TnknC+3dMGxXDoevim7jzyJ8yfnC0= X-Gm-Message-State: AOJu0YyvNj4aYe9cyOSpKnUcWiU4btFynbcb9dBDSCxuEP8UWzLuZH7N dBz3OvPpQ6DqqGD9z2AS3q2qtWEhaNHj9e0AOdINYyiDRolf4qrZ X-Google-Smtp-Source: AGHT+IGRcD9VdYxUVdFG81QPXGUJhDXoOaVerBAJyHXQpyPwC5eKutgVITtAb83XqX4DbciXEEMQrg== X-Received: by 2002:a05:6512:3091:b0:51e:e703:d11c with SMTP id 2adb3069b0e04-5220fa71891mr166903e87.12.1715275797539; Thu, 09 May 2024 10:29:57 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v5 7/8] xen: mapcache: Add support for grant mappings Date: Fri, 3 May 2024 03:44:48 +0200 Message-Id: <20240503014449.1046238-8-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715275824861100001 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. Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-hvm-common.c | 12 ++- hw/xen/xen-mapcache.c | 163 ++++++++++++++++++++++++++------ include/hw/xen/xen-hvm-common.h | 3 + include/sysemu/xen.h | 7 ++ 4 files changed, 152 insertions(+), 33 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index c94f1990c5..7a1e2ce4b3 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 26bc38a9e3..25041ab02d 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; + uint32_t *refs =3D NULL; + xen_pfn_t *pfns =3D NULL; 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 { @@ -261,6 +319,7 @@ static void xen_remap_bucket(MapCache *mc, } } =20 + g_free(refs); g_free(pfns); g_free(err); } @@ -268,7 +327,8 @@ static void xen_remap_bucket(MapCache *mc, 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 +400,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 +408,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 +459,28 @@ 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) { + /* + * 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(). + */ + if (!lock) { + error_report("Trying 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 +525,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 +543,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 +586,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 +612,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 +644,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 +696,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 +732,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, new_phys_addr); + cache_size, address_index, false, + false, false, new_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 dc72f83bcb..19dccf4d71 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -35,6 +35,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, struct MemoryRegion *mr, Error **errp); =20 bool xen_mr_is_memory(MemoryRegion *mr); +bool xen_mr_is_grants(MemoryRegion *mr); =20 #else /* !CONFIG_XEN_IS_POSSIBLE */ =20 @@ -55,6 +56,12 @@ static inline bool xen_mr_is_memory(MemoryRegion *mr) return false; } =20 +static inline bool xen_mr_is_grants(MemoryRegion *mr) +{ + g_assert_not_reached(); + return false; +} + #endif /* CONFIG_XEN_IS_POSSIBLE */ =20 #endif --=20 2.40.1 From nobody Mon Nov 25 12:21:28 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1715275910; cv=none; d=zohomail.com; s=zohoarc; b=jndmfbiE08Hw+ZAKrQRAA78GaXTD5OiiP/HW9L4aXC5vL8aV/HxcjaqohoAd7jI1kJMA3oLkEJiVMhi6oG21DmxNAHI/VRzVA2IImUYWMBpoXsX8YDufBH8z7Fjw9g+CZz5p7q//Drt13QdA7oAIMckGJcKBmNfgoyp4kjykFfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715275910; h=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=GCUy9HbKYqkB8J3c8ehjTn+z8ZMWUL+bdITYZiFkB6s=; b=UaibxVharBbJ+s5lz8Dls8v1S87fXwbUaJILzWsAp0jGeD9hwwge8Dpm/DfzfiH7lfjsO4ACCVtwMtDwLov6CEc/UoOTo6JkRDfXXx8IylrUrmpENZuhqNuaFTaM9nU/g8KonWYTBoJ9VksuBOA5KZx5oCnj2fZrkNUOZoDVCOk= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171527591049052.647898475703755; Thu, 9 May 2024 10:31:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s57an-0001ki-SQ; Thu, 09 May 2024 13:30:05 -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 1s57am-0001js-NI; Thu, 09 May 2024 13:30:04 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s57aj-0003h8-PR; Thu, 09 May 2024 13:30:03 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51f0602bc58so2101790e87.0; Thu, 09 May 2024 10:30:00 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f39d3321sm371586e87.301.2024.05.09.10.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 10:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715275798; x=1715880598; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GCUy9HbKYqkB8J3c8ehjTn+z8ZMWUL+bdITYZiFkB6s=; b=Fhl+/+QoPrwjJ5KE3A7eJORofZo6WgaEpTEIyO9/V7iIBm3L1gdaDHidPUX/lPMqII R/BOKjpCU3TfagI/faYyfkDbnXZjkA1c8EHpcS7Lmv+q/hsdypSHgGVUfmQHAUSWayeW 8+xpCGnFk/pakjI02FwpRhdR+vLsEvqIqX+hQF2jh71Z1oZgRrSOnPw4hRCk3mGllN/M nhX8qRChFoFDNRW7SxNXqj5sYbasCMD+EYstMp4Ex3cZNXDcIaDhWbvC+GD/UuRo+FdT AJumhVhFNw62gtZLnaNT5udqTX1UGQ1a5tMPqPVz0Ury+aE+rO+/HUqdixO7vm+ZmbmX Vj9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715275798; x=1715880598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GCUy9HbKYqkB8J3c8ehjTn+z8ZMWUL+bdITYZiFkB6s=; b=jhmphQKPy6vhUUFVVSykST6RBCtIYGD3KLcvoaOzX5BFkzMScbmu4rCs+FdFfpqOaq ecd+0WlrPwnQqYElbw/qU9MFX0hKmHPe35dD9cFOq8XVDkCXM4pFAKsCvjSI131p1SKh SF8dC5gdnHDo4ut9fdYa3ORWVvuCqfu9eGUmS5XZoSUFhlYCD3/pSAgYJRfLFQItyDFj Iy7pl6/OhaWfECFcslePrJSs0bvCyGtVNzTBiVcm8vNhySWjee9wQVkVge0xmAsXXSBn SXtYk8Ye4REvEAWEDx5KM9Mi8LwOlkQZ48GQ9g9giBbM65jd+Es/w/EfvIbNW9QMyrPg oCEA== X-Forwarded-Encrypted: i=1; AJvYcCUir7rYbuwD58ezy+63MRPBECoE7so3mESvoJ77RbQ0XB0i5+B7c/2GfnIYbUZykBY32iGY+XqfVeDyx8U9joN+Ivr6 X-Gm-Message-State: AOJu0Yz0LQyiPuzYI7kDXBmZ64vHcQ0M3U8hThmtjYRH1BhEX1vEMJt0 7YDBO1DN7GyJoJtjcc5rNFaUuI+1QMKMmuJ8UXY5R05zlTBFkC7UCsJJkWw1 X-Google-Smtp-Source: AGHT+IGBzE5dVAV1Ul4e7HTYuKxRYaKWBiiH51eBw1ONPVttMICUtiQ6DPvb1ADZM1iRQ7/DYJVm4Q== X-Received: by 2002:a05:6512:138b:b0:51f:4134:b277 with SMTP id 2adb3069b0e04-5220e68c1a1mr107788e87.28.1715275798464; Thu, 09 May 2024 10:29:58 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.com, sstabellini@kernel.org, jgross@suse.com, "Edgar E. Iglesias" , Peter Maydell , qemu-arm@nongnu.org Subject: [PATCH v5 8/8] hw/arm: xen: Enable use of grant mappings Date: Fri, 3 May 2024 03:44:49 +0200 Message-Id: <20240503014449.1046238-9-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240503014449.1046238-1-edgar.iglesias@gmail.com> References: <20240503014449.1046238-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 client-ip=2a00:1450:4864:20::135; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x135.google.com X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @gmail.com) X-ZM-MESSAGEID: 1715275911364100001 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- 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.40.1