From nobody Mon Nov 25 12:51:24 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