From nobody Mon Nov 25 09:40:23 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=1715874516; cv=none; d=zohomail.com; s=zohoarc; b=mCcF050PJZt7Cf8ySWMy6GPUjO5zJhajNFmuX3A0mz38RQqMMolUMIammmsVcFDBS+vsN7gS/gMs7AV7W/EKfG/KHwGS+2k2XEgLXQU7BrfYTaS9MZLapK2c7cboiQAG8Iww3iomp2LnNR+0bzLTIMUZMYrcp7Lw6FyyFTBTx94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874516; 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=B2gk4TGOCR/ncRLWfjq1SmTNwMOwkNjbF1SDCO+Ors06qjGg+fSV1fGdMY7xkojplY7FRZ1tJWghaEi7u6QSjaBOignpzcXMSAJZ3Htv/24iKwflohZUxVJ30alkH77lL6Sp3MdIk0BiQMkJw8XWE24SmGHYlNiV1WILkIYKLec= 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 1715874516187875.8707721684207; Thu, 16 May 2024 08:48:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.723473.1128340 (Exim 4.92) (envelope-from ) id 1s7dL5-0008GN-44; Thu, 16 May 2024 15:48:15 +0000 Received: by outflank-mailman (output) from mailman id 723473.1128340; Thu, 16 May 2024 15:48:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7dL5-0008GG-0I; Thu, 16 May 2024 15:48:15 +0000 Received: by outflank-mailman (input) for mailman id 723473; Thu, 16 May 2024 15:48:13 +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 1s7dL3-0008G5-6y for xen-devel@lists.xenproject.org; Thu, 16 May 2024 15:48:13 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b29c2323-139b-11ef-b4bb-af5377834399; Thu, 16 May 2024 17:48:11 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51f99f9e0faso1127787e87.2 for ; Thu, 16 May 2024 08:48:11 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4201916e7c6sm134563085e9.12.2024.05.16.08.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:08 -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: b29c2323-139b-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874490; x=1716479290; 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=bj5mbrg4u13toU1ZMHMQUOYAMIi/iXYNkmjkQDeQwMW0bc6bpM6WA1uzq+iagJcJu3 f1IJMawXAD5LDbxU2idU6XWYrBu8K7Urh+QEHt87Qi22ZMBaxq6vj0d8RlU3ANCurJ6a DNenn++Y8PWkaVBD0TF4ujhv9Nc+WtAax9fIkkjNbL4yjrp3zHzdg/ullslwr+CoL3Ze HhNF4DD6834YMZfitg4Ld/BlrB1hb6g1np9T7hIka9I0SKjLfe38WWX8YePEnYGZirjb +rMg0qTwkpoJCFXgoOh/GXROBb79rrxD2DKUruw7GmKxNiKelFa2eIECY+lBW6DENXyA 8suA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874490; x=1716479290; 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=GO87EKIyebVt1vb8/8PcrrrxttAdwFlGeMY6VQh10XPckExG8Wr4bTn3LfHSLdzJor A/aA5f84JIgJYdmpKqopBarjlVVqd0P6zYjk2SclifSVkF2tBvP1xUuy4yHWEi+B0XJd /sfpV4ZHwJ75F/C0zj6zgyccEnXdbWcME4qAWoFf4gh2uf7Y+HYZVMdOFUI4YyPgqugm RV23FzY9cUCfgdnlvMoqn9TDJ4Y4JESg6UDwtShd6m5LNgiM26XDxuTiXODgVSSk+oMk aGETJf2P4rz492AtQkFf2TrBpijS23q2hQ+R395a4+IzldGnVByX4jr+xEGtZiQyK0RT 5E7w== X-Forwarded-Encrypted: i=1; AJvYcCVaf3jWqQ/4MUv1qnzsfvVLj8ry2jeHRGDFyZIECLZuRebIRloBn14bCqsivm+weWbt1/q8+Frnty/7hVpYgz4mnbSaONbzpqt0v9E18zg= X-Gm-Message-State: AOJu0Yz33OB/AF+cdtvFV2HhGyKdc6ejQVBKDuK7Z0lufKPzMNdVvHVF oqSUaJh/8KScU/Q2S5yRNDYGsCLdU+LKGD6ylf+9WsW4ZLMyYH/O X-Google-Smtp-Source: AGHT+IHDyhM75rM+/tSd8KHYsc2vk/F/hAtrKLe2KyivanA+rMbH+7GZB6FdXDOstgD6teeWWR65AQ== X-Received: by 2002:a05:6512:b15:b0:51a:ca75:9ffe with SMTP id 2adb3069b0e04-5221057b50bmr17367040e87.42.1715874490119; Thu, 16 May 2024 08:48:10 -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 v6 1/8] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable Date: Thu, 16 May 2024 17:47:57 +0200 Message-Id: <20240516154804.1114245-2-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715874517856100003 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 09:40:23 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=1715874514; cv=none; d=zohomail.com; s=zohoarc; b=ED/IVEjyuKcaw0YtbgBilI7wa5g5ztIIpdzLRf6EBs3ZmwvOlesOop9xTd1gRgagjJs2UdOc4M9mSkqJmhW6pd+Lm10mx5AmfNALLJg8ZZSlkF2USKIdY/8Qh/dHNpLTmdD99WrXNQ2UchE6QmqBh5XBCJ7j6W2scSvmi9OeY0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874514; 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=CyHOEjDjBicoz+gaN5uM8S0USxnRvM5Qs6qfDT436lRNVziYxa4e2CMZxs1Cb4mYns/hVoFuj5btoFKmAC6GHwe/XThM8r1/JER6Gxs91BM/tfDucuKYbh1VCWahPaa9HN0d3JvjSDSXey/PyceQFhdVVwTBeUUXOhB3jHAmeTQ= 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 1715874514496256.89581795842867; Thu, 16 May 2024 08:48:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.723474.1128351 (Exim 4.92) (envelope-from ) id 1s7dL6-0008Uw-BB; Thu, 16 May 2024 15:48:16 +0000 Received: by outflank-mailman (output) from mailman id 723474.1128351; Thu, 16 May 2024 15:48:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7dL6-0008Up-72; Thu, 16 May 2024 15:48:16 +0000 Received: by outflank-mailman (input) for mailman id 723474; Thu, 16 May 2024 15:48:14 +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 1s7dL4-0008G5-Kp for xen-devel@lists.xenproject.org; Thu, 16 May 2024 15:48:14 +0000 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [2a00:1450:4864:20::32d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b3daf367-139b-11ef-b4bb-af5377834399; Thu, 16 May 2024 17:48:13 +0200 (CEST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42016c8daa7so31427305e9.2 for ; Thu, 16 May 2024 08:48:13 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-420193b0903sm135397305e9.47.2024.05.16.08.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:11 -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: b3daf367-139b-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874492; x=1716479292; 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=aho6bzCe+jDxNs4ys9vUT726OAdpjtZWNUfY80B3aVOIwdymqUwl2YyBOKYtA3Gh70 SKtQzIib9/xxdPHaI1fKpD2STAPKLCPmbtA1N52qlyLQlb4R3htuz1HsbVOzQg8h1IDd wPglEJE7s6b7lIagoemGctAfZl6jQd6Mj9ScDgllSVk9vaCAT/vE3yEOWiZ3QrAwUReF DBvYhzwABOteiJQz0onRLbgs9Gc1JlwFj6T1Yj7BHn9VaYjNWck/sKqFaBMnnjrUu9vE gbFIst0ELd9NvA3nPNJXgC9xg08m2ohknXWReJ+AYHJ5Zy3m+vVnqKxQD9l9P5YHbaKo C+Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874492; x=1716479292; 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=GRsrSdnR84iZGK98B+bMxOdD617Bk5gB9erpadPna3HHrOpmFE68EjgqYQ3Sj6o5z1 CddrzOs2hTwPFAusqcp1LIYFxSliBQfsP934FWllMgk5scSuKssl4LKg4sVQ1/n2iR0U yrEYwq5e5vol5RS4OjVQ0kYf1MS2UTH6uHTlSOmczk4ipb0jcIWKqWTM4YpRniVrwcPv Ziex6xe4XM+MLnBh0YrZV3vncV1kDsxTWhUcjDAaPszmsGuYQU1cGYm5gwroiR76XxI6 4PpaFJQnCYNgEMK6ycFiHwqhl/6THa+hSZ+T74voDU4/LGBhmY3ftbSaRGT27SNgyb5X EaUw== X-Forwarded-Encrypted: i=1; AJvYcCVxsFHXRuhZS219ix2H84yIBOuk2oJAT4SNX1ZTGas5vT93vuJxVRtiJ+LVoNh+JjjXYJmzqbWsGKX5atGUTfQLl3wM7TvKGCJSqnfHgcA= X-Gm-Message-State: AOJu0Yy74WKXIGLFaT8hn2ntdCiLYAOxFNwUwbNbIQY9vW+cRGh19kF6 4hdMRXKinhk2/LvfBrLpQukl1/2j2UvFA8mTJTho2gpIqu3sPXt8 X-Google-Smtp-Source: AGHT+IFjr0fT67BiVLzPhzx72CFQaxGN4vZsogPbdN+2UbY4Li7I/8td4kLMOJN0uGIq1S8SJxxrwg== X-Received: by 2002:a05:600c:154e:b0:41f:e959:9053 with SMTP id 5b1f17b1804b1-41fead6ae10mr166768825e9.38.1715874492348; Thu, 16 May 2024 08:48:12 -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 v6 2/8] xen: mapcache: Unmap first entries in buckets Date: Thu, 16 May 2024 17:47:58 +0200 Message-Id: <20240516154804.1114245-3-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715874516064100001 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 09:40:23 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=1715874521; cv=none; d=zohomail.com; s=zohoarc; b=DLhnVviuAi9gQod+QoEw+Eiu3KGFNRZLPOWbDHnpYv67/MKFwv3nQpxGu6SGEB7PAdtB8/CmEReZkYA7F0MNSKz7OemJcRswuH+ldDX7YL4TC8+/cJiT7Vn57rvGYXK3maNW5HU94eZj6U0QrKv0Jt0cuCJ2/ollxLOoOr6n6TA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874521; 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=YP28Iks2aCd2MOvUAbQc4yYuz/leCz2VtuKFu0fMfns=; b=lQ3MjZl7gIVmPDZBr+07YEe41XWDtrAtnEQLDw+N4o1pIEoEYM8L5yeKEPGDhymCmthQNVC/pHbd271IrCRTISp5QVBjP3ADeofmUHtWRnphqKMFdr/ZXbdZNlukWuoYrnzJjgeZixTLIlhpDWdk/UC8nS4PpxKtetMfV1hA/oQ= 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 1715874521096470.63265887898444; Thu, 16 May 2024 08:48:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.723475.1128355 (Exim 4.92) (envelope-from ) id 1s7dL6-00006c-If; Thu, 16 May 2024 15:48:16 +0000 Received: by outflank-mailman (output) from mailman id 723475.1128355; Thu, 16 May 2024 15:48:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7dL6-00005s-EP; Thu, 16 May 2024 15:48:16 +0000 Received: by outflank-mailman (input) for mailman id 723475; Thu, 16 May 2024 15:48:15 +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 1s7dL5-0008LQ-LJ for xen-devel@lists.xenproject.org; Thu, 16 May 2024 15:48:15 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b4e7868a-139b-11ef-909d-e314d9c70b13; Thu, 16 May 2024 17:48:14 +0200 (CEST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2e538a264e0so12460321fa.1 for ; Thu, 16 May 2024 08:48:14 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42016b88f99sm146828625e9.10.2024.05.16.08.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:13 -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: b4e7868a-139b-11ef-909d-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874494; x=1716479294; 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=YP28Iks2aCd2MOvUAbQc4yYuz/leCz2VtuKFu0fMfns=; b=Htw5IuoKJOBVAtAAeIs9v+QWS5XZlSFOmftRCQWV3aNYJeqn1UeW61GtqyzbEJ1HxC /BTI6n18XkvkFuhdcRuMoNEGISDGGcCXqHXJkdsQkP9fzofnBXFO0NJX5SCVsngAia/K Cp1PryhEnY5KvLUiqAg7FbE2Mcir2cVl21EXbYmXWAQhq6xOFoBo8vfxRuyhn23XDA6x Ve+gkgPbkcttAyRZgwDpros33L1VkqlAukeoqaWVnye34iECtjHOx2OSuEwF0quh4WtB GmJIsgwV9cfluutacU0f1OwF+e2FxMZ2rO4l9PR2yvBFnGFS5YLMYWSVuY2jbETA4ZNE RDoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874494; x=1716479294; 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=YP28Iks2aCd2MOvUAbQc4yYuz/leCz2VtuKFu0fMfns=; b=G1MDIHW2H9rKhgk4S+6G6N3Qp9jR4pW85vDCwIFBLO6MeDMwslbdiyhP2SYi4xEZxs OpwhZcSvk7THAMPrC0WQvLfgU1A31bWjzgAO4tWQIkLyREx9SpQyNzUO39n7Q+WHSPeY SYOttzThvclZR9SVFHVPtzliQIvN8AII4GzQbss7XZzDru1zJ3aOxybQ+q20qNtJaUN6 gQTi4wiuQkgTFip9V/qwk+EiKmJMPcVoOzp8LjnX9d/S+MRCe0DInW8Hhe81j2Qm3qAe ey8DUGR/vwHO1VTOKQ84Z+9Aszz0z1t2Elk6nV8zswL+L7MRHBFpMpaWXzy3VfLSoLrV 7zQQ== X-Forwarded-Encrypted: i=1; AJvYcCXE6GcneH3GWcpb43+KwUCxdk9wMjzC6HqjuKUUZ37Q+3RcIJXj8Afg2ms7hFYv1wHWT+1YxhxQrs3g2ciNoW2WxtqyMbtYqmfQJWcJaFw= X-Gm-Message-State: AOJu0YyPp/gbQv/ZFyBZULiGEsYejpD8BOnS0Rzmfct01Ess9JUHiHYf jofSXWRAbPhmbZcCSiEzjKKQv10Ff8XoXhpZkLZP8cej1i4FT51z X-Google-Smtp-Source: AGHT+IEaN/+VHmkJjv/znpWgW3h0+GqXzWUJj0uCRLf2DykoyCNb/asHTon7nVels7WBBHQIR1MU9A== X-Received: by 2002:a2e:be9f:0:b0:2e3:ba0e:de12 with SMTP id 38308e7fff4ca-2e51ff5cf48mr209958761fa.22.1715874494287; Thu, 16 May 2024 08:48:14 -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 v6 3/8] xen: Add xen_mr_is_memory() Date: Thu, 16 May 2024 17:47:59 +0200 Message-Id: <20240516154804.1114245-4-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715874521889100007 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 2d1b032121..a0a0252da0 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 09:40:23 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=1715874537; cv=none; d=zohomail.com; s=zohoarc; b=FJYRLSF5ip1j7zqsQ5ewEhu/Rvj2v86geyGEK4jUuR7rFjyqtGHJeMOl6WsecJjaA+8Y1DMfeuqfr1l78EZt8ETXsm0F2pR3cbKe7XaTnnjhc8lKBuHGa6YC4+4G/tIfNE1wqoqwI6EiobgO9vQxOO0o63WkbgKO7g+HCv87VaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874537; 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=teD8rnn0f6FYCrAuK2rQnLlILPjJ9Dq4/0s1mpzug5c=; b=OHHSWvps+ilhST/buj8wYe7jLSkn4aSPQZSJDVbPuwYsYfEsRe+l7kRO0cyorPpTDOvUGOf8otuKSjRgqsD4yvxtIejb9TcrSlNgoO3rgqJI+84tG+Qj5F75Pdngsz7aTSv+VdU48a+hCHW7i0LLlgDCiXWClRWssMwpoZzCdq8= 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 171587453785243.39691605349924; Thu, 16 May 2024 08:48:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7dLF-0007w1-Rj; Thu, 16 May 2024 11:48:25 -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 1s7dL8-0007l7-V0 for qemu-devel@nongnu.org; Thu, 16 May 2024 11:48:20 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7dL7-0002uV-J8 for qemu-devel@nongnu.org; Thu, 16 May 2024 11:48:18 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-420104e5336so34421545e9.1 for ; Thu, 16 May 2024 08:48:17 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42016b88f99sm146829475e9.10.2024.05.16.08.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874496; x=1716479296; 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=teD8rnn0f6FYCrAuK2rQnLlILPjJ9Dq4/0s1mpzug5c=; b=jOhWqoONDsmmeFKPYrYIWPVredBjzE3GXwPan5W5NxywdbRQimk/X4NSY8MBR7MYqN Ln0uAOihiQaCqBFyvdBeCwWfWW0s9m+W6jmFEz701LOvRR8X/v4udXMnZXnf7qATul5L hcDFibnmhc6VkcFn7z3rfTXt4cgp1vLiLNQ5hbSWEBvR7p4wFF4h+FueMR8BmWaPAtug gDr8LOvTMy8VuSRXQ0EuF6HXKrnUrKO6ykNH0mU90lbU+hz3Jvn5hNpu7hzpRNdaOIFe W9RhvE6p1d60VqjPEjGj0Sf40Rul++3zRxBnNVKCj9rKTNcMYLVw2tvy3CDRnr5nRMFT vfGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874496; x=1716479296; 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=teD8rnn0f6FYCrAuK2rQnLlILPjJ9Dq4/0s1mpzug5c=; b=d4L7e5OKiSyjRqbddxK4PnsI45PDcFadBSHZ3Cw7LirhGHb29H9kizFtG+lJzVFp6P lsjR5teaNLY09OZVidegDlYNHxTr4CRrPX/x0liB8CBvXwMTwh5527x0RLxFu4Z9yHiw fHZcx8l/wZJ9i5tLp6kVUoG91dQUcM2LPsVXWPgYBvi0GFTzznBTFv27L7a9Lqy0CJ/U En4hMgmmpxlEZ/cT4fADWPJGKcSXrizCUGjPp7kbjwsbs2Zkkg9Am2z9e70rXbmsuiFN cYSOrmYSJMIsj4fG1LuHAHT1BV1ZI18NY0zvvI9iH/bzrX+s5nexmJNtu50VNyqstcPB 7QKg== X-Gm-Message-State: AOJu0YzjYK9hToXVZc+zEvNyaFbkxTZ5quBqa9EO0hBAK1un6UFuAxvF XFIQlIly9XJ9HO2n2z5SVqKClIv92RPwCS1Ai/OKW3XGUhY/Kq29hfh3IpJ7z18= X-Google-Smtp-Source: AGHT+IHnY2m1gSOif+roTBqJK4laENH333C+wETM9OTAiDP4pjCTiyhjqNlxDwHwPAW5xLvSHvjXng== X-Received: by 2002:a05:600c:444e:b0:41b:4caa:554c with SMTP id 5b1f17b1804b1-41fea930c57mr180374385e9.2.1715874495533; Thu, 16 May 2024 08:48:15 -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 v6 4/8] softmmu: xen: Always pass offset + addr to xen_map_cache Date: Thu, 16 May 2024 17:48:00 +0200 Message-Id: <20240516154804.1114245-5-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-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::32d; envelope-from=edgar.iglesias@gmail.com; helo=mail-wm1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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=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 @gmail.com) X-ZM-MESSAGEID: 1715874539936100009 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 Reviewed-by: David Hildenbrand --- 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 09:40:23 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=1715874583; cv=none; d=zohomail.com; s=zohoarc; b=c+YOL8NsAx9abpG8RwnYD5fMedchrCV5QTZd3vl62CcKUR2gctfgSm4dDOfc+qOnlTgF1TQQPdGCbcO88Fv+EDRDgrB0OeH49yQy660gVUih2+c7e447iX3/qtSsyarsjBtkNFx8dzB1/XKWCOB5KKp2griw7xrJi1Azrgo1854= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874583; 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=ZGqHM91ncsaR+sn9MCsN16viCuvwwaOuHfEASUkbpMg=; b=JC2geUBLj6Q3AqYS6AZ4nF9jvlf7Q+ieBSE/ARdS2Eej7oTXqaqkD99MdIS7bq0C+q1pnYYPfrGgc65If4aGixAxjhOd69RPQWNLAJVcohlC1scVjjLcYI8lY24u6j8ZrhutHRJB1KA8PShktLgDhvr9S7+96gVKpJBZn8tZ8yI= 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 1715874583022527.0890032057437; Thu, 16 May 2024 08:49:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7dLL-000819-IL; Thu, 16 May 2024 11:48:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s7dLC-0007ob-2U for qemu-devel@nongnu.org; Thu, 16 May 2024 11:48:22 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7dL9-0002w0-3O for qemu-devel@nongnu.org; Thu, 16 May 2024 11:48:21 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-41fd5dc04f0so53482835e9.0 for ; Thu, 16 May 2024 08:48:18 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42012d08bb9sm169509855e9.48.2024.05.16.08.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874497; x=1716479297; 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=ZGqHM91ncsaR+sn9MCsN16viCuvwwaOuHfEASUkbpMg=; b=YOYhZeJZlp7/2NmjggeMVtETiN2yE+rpwDz46kytZQOOMcbPOd9KrvyAuEQD0w3a1U dvor1sX7J0H9PJKvPA/HN0fjZYzEUTLTfYjFINqSS4hXYgrHiq98Nb8twDFi1vx3DFGP ug9P6BJKpccn0CjkNiY2oydsHtrs/g8Ed9k7UrOf8zT+Z4FINBTAXA8G8PP8w78pIy3W 8pBXlB+3fRTZPaMQwKKVC0i0lSWIEFEaGD5Mqn9y9Ocv0t96bbdUvYEuLFeqwvtBPd9S Muk5xb8WOD674QRLF6W1pG7yO9zGVUF5D+El5ZeXE308A0JOxfj36a4Rnb8HHWk7Rhas BVMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874497; x=1716479297; 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=ZGqHM91ncsaR+sn9MCsN16viCuvwwaOuHfEASUkbpMg=; b=j/HK/WbgY25pOhqJUrEmtx5xaie5vqEGpAx+Kz7JV85lqQ1yw78BNzFx9r32N2vUe3 ieAIijC9AiiHZ/X8KarF7M4WzpxsDsYK72PWhU69BZcMU8PFV1VLN1tHSrpYSGkRj5O9 QsGmO+ZMEx2Wnd+1YMWKP44pQ1H6iZqK/ryx5/coGrYMIHWnCg2x4d2M7Z9S90yw4M1W u9zd/bgN8FUMRDQSdVNImBJ6sY1Rp8ggtJGCXqLsvWq1Ov4qI+rhCNfU8fjaUZ66w2i+ /42b3PnCtLJyzzgMGBPtgSLVO3syZme+FOKoftdEyJwR3mFmPg/ZRKZd0QjQgJcNnyIZ fkUw== X-Gm-Message-State: AOJu0YzgRAOndX99UIL632cOAlx9pQk8To2Zx2vHanPZcH4ozEXyeI9v qr3wmBDieotz4HcjhO6tCGm9sLKqk0bq1SWnjawdQiSeZqIswMuUgLjBAadajEk= X-Google-Smtp-Source: AGHT+IFDnMojfO2xt6pVlbquVE8+8jvX7sNqlGUZLdx3w42IdkxyV+nQ1qb+sp/jB5iZoxOh1bsTGw== X-Received: by 2002:a05:600c:4f0c:b0:420:1f0f:fe19 with SMTP id 5b1f17b1804b1-4201f0fff56mr93205855e9.13.1715874496961; Thu, 16 May 2024 08:48:16 -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 v6 5/8] softmmu: Replace check for RAMBlock offset 0 with xen_mr_is_memory Date: Thu, 16 May 2024 17:48:01 +0200 Message-Id: <20240516154804.1114245-6-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-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::32b; envelope-from=edgar.iglesias@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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=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 @gmail.com) X-ZM-MESSAGEID: 1715874584152100009 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 Reviewed-by: David Hildenbrand --- 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 09:40:23 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=1715874519; cv=none; d=zohomail.com; s=zohoarc; b=CWIpbZMEfuz4aoeLzmaFXN1iV6FLdpcAgZ9TQj8gktI/l5ZKB5bfu7SNT9lCAvqRM3irIZoNKf6ocyUNu5TC8k+UhWj6gNaq75DCbngr2kNPO0P8SD1TbltkwRFiCh7ZevTXgOpD5n5SWswrn4EtLCd4MMoLo4003Rcpj7TTIbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874519; 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=+z9GUm6j8WzszIWdyc3UrfaOV2gWSdTHpFYF8lhndm8=; b=VMPDfnJSG5Tvb04R6lNpf0TlOacr8JC2ww5XaDmOComgAKCIkm4y8SlU+vCa5Cu9Jtkis91g8Z75yIihKRkWkpjptmoTybHgJ8wkREd2zkAgtS/fH+9MNL1iDNDwZSpcNjNHBGtQ3IXwfXGQX9U78vG+c9WE1oAYkxgkEoL82Rg= 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 171587451972024.389295934702886; Thu, 16 May 2024 08:48:39 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.723476.1128370 (Exim 4.92) (envelope-from ) id 1s7dLA-0000Zp-P0; Thu, 16 May 2024 15:48:20 +0000 Received: by outflank-mailman (output) from mailman id 723476.1128370; Thu, 16 May 2024 15:48:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7dLA-0000Zi-Lf; Thu, 16 May 2024 15:48:20 +0000 Received: by outflank-mailman (input) for mailman id 723476; Thu, 16 May 2024 15:48:20 +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 1s7dLA-0008LQ-1R for xen-devel@lists.xenproject.org; Thu, 16 May 2024 15:48:20 +0000 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [2a00:1450:4864:20::330]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b7a75bb4-139b-11ef-909d-e314d9c70b13; Thu, 16 May 2024 17:48:19 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-420298ff5b1so9908645e9.1 for ; Thu, 16 May 2024 08:48:19 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9292sm273969565e9.37.2024.05.16.08.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:18 -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: b7a75bb4-139b-11ef-909d-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874499; x=1716479299; 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=+z9GUm6j8WzszIWdyc3UrfaOV2gWSdTHpFYF8lhndm8=; b=ZetVf7jb3gRKjPFSBfAffCi8AyMsUIznWc4QbVFVZ3r9y0UaP9undzOApaVqq9LtN9 qTdjxXIHll2VMMl0CEYqh/9X4LtEovcF+nASxO4lM3OD8i3h9eACOGjA/pZJJB4z7Pv5 UMeLQ+vP7H+evWzV5CcPbtGagl/KJbc089kkRJXNiqffScJ8Uz6gyHx7B6BNoW7MsTHr KlPIdJk6v4L1ewoGYObMY+VLD3I5FTxN+b2Ri+1H/EWcWik1eKzsg9rnu2j1xYrFN0ne dkeZjlmI+wxyimn3KUbTlV3P49yEMfompFWRpC2KACORYsDGLRsEvT7Kvm2EZVvPAN1r aIZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874499; x=1716479299; 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=+z9GUm6j8WzszIWdyc3UrfaOV2gWSdTHpFYF8lhndm8=; b=GJ/aoMXJoyIU8jW5crucGE0caY8TcSSj9qkTy+F7QOSRrf9Lt/s9cGikWO3Qk2xOGb 7nkVvDn0fWLNdGhSG2E7mnIG59V26lQkM2li+VqPNNgV3lfEMZWXf0SmJSLMfMTNRerI 4hM66rGexXLZGlYForLReH298tExhKdgrSA+DRfBKZB3DZbJJRzWwDRO9Lz4HzhQB4n0 cAzN84CJA3n0jdHUFvcg4fuh/GUo0a8pYmHCN2NY81v+mHt+RE/LVRK6hOPL5A617oqR kqTQZMl94PtaT43gQpfTaTZx2zNiF8ge9p4sgYxE20sqAp33KmTEVZQB+1Jp9QHlo7Cj LYqg== X-Forwarded-Encrypted: i=1; AJvYcCVpqJTZ0MotG7O5qJm/qCFrsnPl4QJekOh4pIXc/+MUwmQo36IHbMEBAnJ0qa1jL7yWr1ZB+GhhBmYVzal+ZrSm8hiYCNltyTxT+FvBBFA= X-Gm-Message-State: AOJu0YzEUbL9KR1jeZE/pkQSzLYK5nRNG9moUoogmevoCNfC/fNKAIgK VecUpMSoOEI6r50sh3gjhEtRrL2ITQ5GqW99GIzAg+5Z1N4HYNmR X-Google-Smtp-Source: AGHT+IGfNbqzq+QNyeonmsqylEpUTqR0Yl/VLa0jqDvd+rb0LT+CkFvkUWEMXBZQKhr0f0w8Mk8vVg== X-Received: by 2002:a05:600c:4707:b0:41b:edf4:4071 with SMTP id 5b1f17b1804b1-41fead64731mr176758575e9.35.1715874498887; Thu, 16 May 2024 08:48:18 -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 v6 6/8] xen: mapcache: Pass the ram_addr offset to xen_map_cache() Date: Thu, 16 May 2024 17:48:02 +0200 Message-Id: <20240516154804.1114245-7-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715874519875100005 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 Reviewed-by: David Hildenbrand Reviewed-by: Stefano Stabellini --- 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.40.1 From nobody Mon Nov 25 09:40:23 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=1715874525; cv=none; d=zohomail.com; s=zohoarc; b=cR46rhK0SKWQCqhoERXHZt7w98czLtNQrNlzrdjadpqjNvZhoIAZurDlo/e459elejnZgg8N2sUI2jUGHFKmEVAgwlzRWI5wmZm7yrF9ST+7IfLtisusU6vDudDbEEpTsfL81I8ARJr24c3KX5Jqlt3J5V/NNifQniU2cNiGDjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874525; 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=SZNZmEv4DlBVnZCXhmwJDrvpI/tlo6jDsglpwLe0/DI=; b=EbTgXRjtwcGz1TwYp85GxcdG+XPetAedKTSXZfe6j1v2LlQ7RC/pUDcDSbRvC1+vcKL8uG44KYl+0u34foI2DQAClSBokdw/2iKUZNAS8R9qSLCxgM/U15NvaANEJR6Vp5hdBzjkd/o9Nq+/KQCvONEp+fJ6pkJITdsGkUi5eu0= 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 1715874525234857.1109677688274; Thu, 16 May 2024 08:48:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.723477.1128380 (Exim 4.92) (envelope-from ) id 1s7dLE-0000tX-6x; Thu, 16 May 2024 15:48:24 +0000 Received: by outflank-mailman (output) from mailman id 723477.1128380; Thu, 16 May 2024 15:48:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s7dLE-0000tN-30; Thu, 16 May 2024 15:48:24 +0000 Received: by outflank-mailman (input) for mailman id 723477; Thu, 16 May 2024 15:48:22 +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 1s7dLC-0008G5-Kd for xen-devel@lists.xenproject.org; Thu, 16 May 2024 15:48:22 +0000 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [2a00:1450:4864:20::331]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b8673f45-139b-11ef-b4bb-af5377834399; Thu, 16 May 2024 17:48:20 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4202c1d19d5so5298845e9.2 for ; Thu, 16 May 2024 08:48:20 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4202d81104esm15573575e9.16.2024.05.16.08.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:19 -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: b8673f45-139b-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874500; x=1716479300; 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=SZNZmEv4DlBVnZCXhmwJDrvpI/tlo6jDsglpwLe0/DI=; b=ZnnV3iJ2fi/HahhdF6PipRHwVkQ5gFWllroZvH9Z5YSqxbUQHt8quz7unSLJhoUL6C MV0cLmY0WQPf/pgY9JHl5Vdxkbmt9MrFqV1HGFnehjY6z2rXtgKpyydPxWLo1hZ6pykp lYbBNnZZB9vGEXjY0PFd2ichswIq9FU6KgesUviOvosLLPucC1ypkdxcAlOvTTjZ+Exo 8oJbFYuosp5rJco8BzdCCmlQhajnig16RhXs1ZBC1vv84WQHIkI/W6JPhClj7+5Eq+QI jx+op81NzJDcvP9NW9ZV15omd12IjTadhykDeo7F2Lkt0KkuJgs9+XwCzqlqEEipb9Lg PZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874500; x=1716479300; 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=SZNZmEv4DlBVnZCXhmwJDrvpI/tlo6jDsglpwLe0/DI=; b=BVtQtlao7dQSAaHiBYJMBZAnAiZ4VMODpvVODxMvtSbh2KX5PQjM0wz75aHouHHPjY eBKgsZ5dM/mjNs2/ve3C0A01yWg5dJmcniQOEgIXbtjRX7VE8+1yLmBMwZPUOAEjzaLJ uNycQD8OqOv2shXzZhmFcLmvml5xlOhIuW+La8bAoD2qTLULeaU2qLjLBkdvCKFQiJlv VYilC+MtJsuSDCDc6jRd4s+uSlTTnfW7tbNPMhdy60X+0Jb+V+UqUWDJmkHL+X12ULU1 pCYO5SJav3alhus1h7YOQAkXV8KMsEZgTqM8NNVz558BYeH3tdfoCmpbypM19SqGlOYE zCYg== X-Forwarded-Encrypted: i=1; AJvYcCXchq4XgbkvNdhPAuTrSJ5N2Nnht7LWJ3cYw2KZtHUiioj7YwjqwkXrQV7+esWqJr8B5LbN9j/b9Mub6HrSeJZfp4jrLi5/qXceQdhU3bY= X-Gm-Message-State: AOJu0Yxi2F1prA+K6uV2EBE9ss04g1r+qSi3zfMtwUc804TDXuE4KH62 xMbgQuT5n13MMAT4xhZxE7hdi0PqgAI1pKwu/FZOB+8dUmgVp508 X-Google-Smtp-Source: AGHT+IFlCJi5rUE9UtwNiDnxVECe0nVXb762LBypQ4XdGn83o5AP+HgeD6LDXCJWzztZIQsYhKzTvw== X-Received: by 2002:a05:600c:4754:b0:41f:fca0:8c04 with SMTP id 5b1f17b1804b1-41ffca08dcemr132474315e9.11.1715874500186; Thu, 16 May 2024 08:48:20 -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 v6 7/8] xen: mapcache: Add support for grant mappings Date: Thu, 16 May 2024 17:48:03 +0200 Message-Id: <20240516154804.1114245-8-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1715874525997100001 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 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..1cbc2aeaa9 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, 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 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 09:40:23 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=1715874556; cv=none; d=zohomail.com; s=zohoarc; b=nip2zvNEL7ErhiHEH8FVOCHrIx0u4lJ3dJwVz5nYpnTK2DRfan2oT+LmHshcKtwRWd/G8eaWHrfVdIV98zQn1TqxRr7f4+isePzJ8l3qVGx/AO/sNB7tutlh8HbGa5SN5Zo4NsFCoUVOsR8myqRJrUoDell1UKVUrLbyxqV6sJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715874556; 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=NnVxsF9/McDcNuHuSkVy/Pc5PbulumgyjGvmIilfrHpdAA4v06zTLP5RfjSrMADzFd6c+fKPSEV3XHOMEoXbd3Zpw3kHh/ap7mxL4pXT7fivkrLYdMKUQ5wr3azJftgpbPXaC0ddeP5sC35wlmVlGnnw7RtXnk/NT7TE08NHym4= 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 171587455631997.64431388941239; Thu, 16 May 2024 08:49:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7dLQ-0008FX-W4; Thu, 16 May 2024 11:48:37 -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 1s7dLG-0007xL-5y; Thu, 16 May 2024 11:48:27 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7dLE-0002x1-NQ; Thu, 16 May 2024 11:48:25 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-34db6a299b8so6208629f8f.3; Thu, 16 May 2024 08:48:23 -0700 (PDT) Received: from gmail.com ([213.0.35.158]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502baacef2sm19457771f8f.85.2024.05.16.08.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715874501; x=1716479301; 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=ASqp83IXu2EGJ1fIG+YNAcfKQJauEMO2bmlDucuuXBwncLq8C8SIaPEzGVBRvPmW14 tujT+NZK/U8mH703KALfCFXlyTt8XK7zBCkLFXcQz4q4W7Sw6rPXTrhPN0pvDhXjOuRl rIob+YvWBjgnZtgRG2cEmmegXftlPXbD4FIcKs7affMuV9aRafjeUrbo8djhHLD9+qt4 2L4qlDYae0pNWn8O5+3z3q3ZN2kCv9mZo5zM4iY4GvNYaglPWwQusmVRc5nWboP+JgkZ Svf86QPH5e4qt7+9mblQPivoxKn9zzbKTx6jWXdE/hFcqQsY/JrRQNM2vfKRgQT7TOU+ z/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715874501; x=1716479301; 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=qX5lZaDOZMdnfiJV5yQ1QimtH17FPAZjGTWxvUNx6B1JRHkkv4ng7lNN0l8kvyRjB9 bvt9nkDW5Mjqp10AsmEydNXQdzglauqK1jd33Dj6PyY5iJoNJAXdMdC2B1Sdo3kfbzo+ AfPowTpWX6rI9YWuzR/8SBywwAcZZQmZdCNvA71HNs+lhoPtsiHUWmAk2hpm0bxPjfIL 6aq6IbGC3QJ0XlrStYAokFUJcZqCSh0CDxdEggABr/VkIqB+Pjdkf+bzPqbagYtRemji nne9Atp54ssgTIhHgAT9RvwxypNCdZY0E1ldduF9Vb79v1+CSqIPMsBRes4ia5UexFhR 23NA== X-Forwarded-Encrypted: i=1; AJvYcCWtdFz+OFmibX/PrgzokFjIOFEubbcbeTZX4QcN5AI0beOszoGuYLU3lQhx4ES7755OaNuDwwP7hy3SqKZyVUKK1ees X-Gm-Message-State: AOJu0YxU6Yg92PINBKRSJHyJib3tGWU6Zysdta7ytqZj2DVllVbAMrzE 2/N/S4OrY8b50+MMl+v5Mx0gizuhQEMDej03nvRAdQZd1VTbW8WMtlK8ENy7ybc= X-Google-Smtp-Source: AGHT+IEwcZbEPom12z3812kMP7vsTMcAg8TdMvpmTOTbEOi55joxiQSv7I6fMODFQLwQnMRBeVPoow== X-Received: by 2002:a5d:5701:0:b0:343:b942:32cb with SMTP id ffacd0b85a97d-3504a6363ebmr13666343f8f.21.1715874501537; Thu, 16 May 2024 08:48:21 -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 v6 8/8] hw/arm: xen: Enable use of grant mappings Date: Thu, 16 May 2024 17:48:04 +0200 Message-Id: <20240516154804.1114245-9-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240516154804.1114245-1-edgar.iglesias@gmail.com> References: <20240516154804.1114245-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::42a; envelope-from=edgar.iglesias@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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=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 @gmail.com) X-ZM-MESSAGEID: 1715874558027100003 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Manos Pitsidianakis --- 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