From nobody Mon Nov 25 04:54:33 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=1716991692; cv=none; d=zohomail.com; s=zohoarc; b=GakvAAm+wEOKoWC4IAwwBvDkAPASAjksoNjymRB22TlOAQydaboRdxbTscAJuR00fwclkpN9bYmtxe91YKQ6DBC2BbT+jCCkOSth2QoezBsDTGigosx+Wtqx+NjgWnaDxsLdC3fKYOa4Rs81s0hI6NuI8PqTvM0m0gs7l3YbhLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991692; 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=H9+wScJfG2ZDjl1o2t+IRNOMzpkVtLiFM8ecKyZ7b+30xDqKCznix3aGyJnutGa0GOLzhY4KzIjcEZpDti1ZQEpmhFjqtaTvhOAaMrTDhiFgDVuQEehw95h51K3g9VnulpTDQ6Qu5JFvOQCt6Nn6Q3x9yVeuLP7ZmBUzfD+i3no= 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 1716991692122851.8990890602678; Wed, 29 May 2024 07:08:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731990.1137768 (Exim 4.92) (envelope-from ) id 1sCJxy-0004Fz-Sp; Wed, 29 May 2024 14:07:46 +0000 Received: by outflank-mailman (output) from mailman id 731990.1137768; Wed, 29 May 2024 14:07:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCJxy-0004Fs-QD; Wed, 29 May 2024 14:07:46 +0000 Received: by outflank-mailman (input) for mailman id 731990; Wed, 29 May 2024 14:07:45 +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 1sCJxx-0004Fc-BY for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:07:45 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d13072ec-1dc4-11ef-b4bb-af5377834399; Wed, 29 May 2024 16:07:43 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52aea6067c8so855752e87.0 for ; Wed, 29 May 2024 07:07:43 -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-52970c3327esm1261419e87.196.2024.05.29.07.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:42 -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: d13072ec-1dc4-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991663; x=1717596463; 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=XX98xi2OKo1rMxHP05l7Ai2sBmm2UHSJYclhGJTbPY6hemQcqpyC8gJ1ERp5o/PSAt tEPwxxcgUxzAO6iklFeg6zMb+tinc/T1CmAIfuL2tP1DlBayxR3HKgjPTwK5gjdwkWhY raHVbt7P8jJ9trw4DLwEt1P8g0BxlKUvbujbes/LDaIDPu6I9/NMLmFYxaYzcNdB2Ldm kvkfXETtSIARjRNGf/NqZ/97Utjhya12PTOVY2dN8Y6XvB+7nrv1z9dIBx81hSSgkK+S yrxgRydCpUTQKUgtI86nBZFT2/qITe1LqguQzbuCxyIwh8SWdz2lHnf+xWQ/Bf7p+yBj 5TUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991663; x=1717596463; 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=U+fAI+Riu3y+qdXSeL7gDt3hPMpOPwoQ4xS1Yew5UsGWvqUsuYXPEhrzVwfhGD/UL9 wB2em/Fl/qEBv8AJVWjY4JxogOVN3kX79FZNZX7xuZOF3IAcNtPGQFfuceRcwCo2LOTR gCF07Pxa2CQaBQW74jVNxtB1cUjtWHXLEimf0VLMNdckSJPFMjoxd52WnUttWQK54F36 dCYnKlcZC8sb9Oo8EgQmdQXj+yoVKbxBwusQE8E5blT5hzfy8SgRzyrKfsl79HUtePnj TO/Ev5uVqMLeIK+UrsIdio/EE6YuX7P1aOi7Zrzn6vzAScvbELEdrMDKevbT19YugyFi eftA== X-Forwarded-Encrypted: i=1; AJvYcCVJR3HQ8fLNZH6ZQnLxuxES0/b+L8fIX3ZXtoHd9Sx7Hplflj+Es2ACKVVIDEPw9lNPWg6gsBTorteLHiwIfynWXD/xMBuO2ZgZVQzkdEU= X-Gm-Message-State: AOJu0YyaTlI6Jd5R0gwtX1wOtjRHcfNouhLYANgo6PDIUoX2bInS0L+4 OByRnvNwXQL6XHNCbJYBdf9AkdQrf/zudAG7B3UuRqGAmOY5UmbZ X-Google-Smtp-Source: AGHT+IG9X1hyyW5bWOM2Lb/ezgqDrIcsxWZZ6e+vRIDT8WUGaZyhyargSGMsndYosYqEtRb+Y+5fOQ== X-Received: by 2002:a05:6512:398b:b0:529:a2d8:3009 with SMTP id 2adb3069b0e04-529a2d830e5mr11094033e87.43.1716991662399; Wed, 29 May 2024 07:07:42 -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 v8 1/8] xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable Date: Wed, 29 May 2024 16:07:32 +0200 Message-Id: <20240529140739.1387692-2-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991713846100005 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/xen/xen-mapcache.c | 54 ++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index fa6813b1ad..bc860f4373 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -23,13 +23,10 @@ =20 =20 #if HOST_LONG_BITS =3D=3D 32 -# define MCACHE_BUCKET_SHIFT 16 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ #else -# define MCACHE_BUCKET_SHIFT 20 # define MCACHE_MAX_SIZE (1UL<<35) /* 32GB Cap */ #endif -#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT) =20 /* This is the size of the virtual address space reserve to QEMU that will= not * be use by MapCache. @@ -65,7 +62,8 @@ typedef struct MapCache { /* For most cases (>99.9%), the page address is the same. */ MapCacheEntry *last_entry; unsigned long max_mcache_size; - unsigned int mcache_bucket_shift; + unsigned int bucket_shift; + unsigned long bucket_size; =20 phys_offset_to_gaddr_t phys_offset_to_gaddr; QemuMutex lock; @@ -95,11 +93,14 @@ static inline int test_bits(int nr, int size, const uns= igned long *addr) =20 static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f, void *opaque, + unsigned int bucket_shift, unsigned long max_size) { unsigned long size; MapCache *mc; =20 + assert(bucket_shift >=3D XC_PAGE_SHIFT); + mc =3D g_new0(MapCache, 1); =20 mc->phys_offset_to_gaddr =3D f; @@ -108,12 +109,14 @@ static MapCache *xen_map_cache_init_single(phys_offse= t_to_gaddr_t f, =20 QTAILQ_INIT(&mc->locked_entries); =20 + mc->bucket_shift =3D bucket_shift; + mc->bucket_size =3D 1UL << bucket_shift; mc->max_mcache_size =3D max_size; =20 mc->nr_buckets =3D (((mc->max_mcache_size >> XC_PAGE_SHIFT) + - (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >> - (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)); + (1UL << (bucket_shift - XC_PAGE_SHIFT)) - 1) >> + (bucket_shift - XC_PAGE_SHIFT)); =20 size =3D mc->nr_buckets * sizeof(MapCacheEntry); size =3D (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1); @@ -126,6 +129,13 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) { struct rlimit rlimit_as; unsigned long max_mcache_size; + unsigned int bucket_shift; + + if (HOST_LONG_BITS =3D=3D 32) { + bucket_shift =3D 16; + } else { + bucket_shift =3D 20; + } =20 if (geteuid() =3D=3D 0) { rlimit_as.rlim_cur =3D RLIM_INFINITY; @@ -146,7 +156,9 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void = *opaque) } } =20 - mapcache =3D xen_map_cache_init_single(f, opaque, max_mcache_size); + mapcache =3D xen_map_cache_init_single(f, opaque, + bucket_shift, + max_mcache_size); setrlimit(RLIMIT_AS, &rlimit_as); } =20 @@ -195,7 +207,7 @@ static void xen_remap_bucket(MapCache *mc, entry->valid_mapping =3D NULL; =20 for (i =3D 0; i < nb_pfn; i++) { - pfns[i] =3D (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT))= + i; + pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) = + i; } =20 /* @@ -266,8 +278,8 @@ static uint8_t *xen_map_cache_unlocked(MapCache *mc, bool dummy =3D false; =20 tryagain: - address_index =3D phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D phys_addr >> mc->bucket_shift; + address_offset =3D phys_addr & (mc->bucket_size - 1); =20 trace_xen_map_cache(phys_addr); =20 @@ -294,14 +306,14 @@ tryagain: return mc->last_entry->vaddr_base + address_offset; } =20 - /* size is always a multiple of MCACHE_BUCKET_SIZE */ + /* size is always a multiple of mc->bucket_size */ if (size) { cache_size =3D size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size +=3D MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCK= ET_SIZE); + if (cache_size % mc->bucket_size) { + cache_size +=3D mc->bucket_size - (cache_size % mc->bucket_siz= e); } } else { - cache_size =3D MCACHE_BUCKET_SIZE; + cache_size =3D mc->bucket_size; } =20 entry =3D &mc->entry[address_index % mc->nr_buckets]; @@ -422,7 +434,7 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(Map= Cache *mc, void *ptr) trace_xen_ram_addr_from_mapcache_not_in_cache(ptr); raddr =3D RAM_ADDR_INVALID; } else { - raddr =3D (reventry->paddr_index << MCACHE_BUCKET_SHIFT) + + raddr =3D (reventry->paddr_index << mc->bucket_shift) + ((unsigned long) ptr - (unsigned long) entry->vaddr_base); } mapcache_unlock(mc); @@ -585,8 +597,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, hwaddr address_index, address_offset; hwaddr test_bit_size, cache_size =3D size; =20 - address_index =3D old_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D old_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D old_phys_addr >> mc->bucket_shift; + address_offset =3D old_phys_addr & (mc->bucket_size - 1); =20 assert(size); /* test_bit_size is always a multiple of XC_PAGE_SIZE */ @@ -595,8 +607,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, test_bit_size +=3D XC_PAGE_SIZE - (test_bit_size % XC_PAGE_SIZE); } cache_size =3D size + address_offset; - if (cache_size % MCACHE_BUCKET_SIZE) { - cache_size +=3D MCACHE_BUCKET_SIZE - (cache_size % MCACHE_BUCKET_S= IZE); + if (cache_size % mc->bucket_size) { + cache_size +=3D mc->bucket_size - (cache_size % mc->bucket_size); } =20 entry =3D &mc->entry[address_index % mc->nr_buckets]; @@ -609,8 +621,8 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, return NULL; } =20 - address_index =3D new_phys_addr >> MCACHE_BUCKET_SHIFT; - address_offset =3D new_phys_addr & (MCACHE_BUCKET_SIZE - 1); + address_index =3D new_phys_addr >> mc->bucket_shift; + address_offset =3D new_phys_addr & (mc->bucket_size - 1); =20 trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 --=20 2.40.1 From nobody Mon Nov 25 04:54:33 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=1716991689; cv=none; d=zohomail.com; s=zohoarc; b=hzFxDLYEkbhwKO/M91/IDjeSpVrF0oicg+hsONhnxv6RmcCjhbUoM0L7djcE6XzAz2WMiJxAPU9KE++SMMvCFXN/Yc33IDcY1sjAm8yE58sdpJbB6WZl6SfH3z1ZV4fLajh8APb7brZGQUqVD/H2p2SNfKDkXYa+7Xn0FmHPSD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991689; 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=SBd94eA4iln/cVlahZgqnU8jclbaY3x2Z5M+5XhnNMuf8diJ3+SqeoUSJQdbeSK63Fyaj5o8zu10dlli0i9AP/PS0uNV5DsZ8poxdhAjtagQKZ0hyVoLLrzEoUu2mlGU0Z/CdMYo3aTa0X7wUxaksDnCvJftv22ds8Zh19qsNnA= 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 1716991689129548.132127361386; Wed, 29 May 2024 07:08:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731991.1137778 (Exim 4.92) (envelope-from ) id 1sCJy0-0004UG-3y; Wed, 29 May 2024 14:07:48 +0000 Received: by outflank-mailman (output) from mailman id 731991.1137778; Wed, 29 May 2024 14:07:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCJy0-0004U9-0l; Wed, 29 May 2024 14:07:48 +0000 Received: by outflank-mailman (input) for mailman id 731991; Wed, 29 May 2024 14:07:46 +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 1sCJxy-0004Fc-6z for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:07:46 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d1ef8959-1dc4-11ef-b4bb-af5377834399; Wed, 29 May 2024 16:07:44 +0200 (CEST) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-52ab1d7243fso1309798e87.1 for ; Wed, 29 May 2024 07:07:44 -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-5297066b233sm1274418e87.135.2024.05.29.07.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:42 -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: d1ef8959-1dc4-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991664; x=1717596464; 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=FVt1ngxRLYD1k7hvosEvjumaiPvYRKgMOLSuMGarKcuTVZTzSxEeN8rKR1NUZl+mi5 /iZY4xs3MHZOQhUCXrXb+ESynSEjxvPHo/IimW7RSSo8lEJn+T67B8opXVMC4zSHYINu EsbpDLo4z7j+U0l8vKjOsPs2wCs5qNqIYHgItXZzTABZJeNT3hKDi87Sq7XSAW9QbA5j y57EHS3XiQl7ScWMWeaOpfllUYrprMgMrk+EUnw7QumZThyp6W/67ZX/8iu7IYZKovQD 6xDsH8XruihqB3mGeXuQYuQwoc0TteibaikDYPr2UIJWJd9iJYYIigHIUZwyCsUio5r6 f1GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991664; x=1717596464; 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=XUZoH+llZJFkUagjVEvlOGJPCeA/RUVNzIJbcY5McfXT7XauDkXKKDuQvAeHe7CsjW YRx6QiXQRCfnM6R4T8kZEbIcUVTfIy6+eWrfWM85Z6Qiua57YsQAo0JwCyilC4ezrsQm N4q63+Y3eI3tdP9iu2mq4EOuvCziXn4TW7DtXrGnyG4Kx7kSDQxYdqQwsXV/gzE5I+C9 cqvRbdAzCyGp3e8SBtzD24TA0+v7pmj+rjWwtD5wdcQqYe3MgnrDh4RLjdfe0uHLXzxc KVia15B04xOxkPYQS1nmZC5D4g2j4r07cBk40ASrh1JajFxNyq69Cdr/GoeZUQTrqz6T 7Z8w== X-Forwarded-Encrypted: i=1; AJvYcCV36Yczd0UzPednRoF+T9lucLpAtnG62olT0Qh7cuRv9oHJlq/gz8QGKfofP1647k4Z2CXSjs0LzRRjn3DMx7Lvxz9gPQUTbA4Xm8P6vXs= X-Gm-Message-State: AOJu0YxexOGC/uzxYNQVEBTg5V1VqGN/QonnR6a4NxhaO23mDkwKKc8p SdrwWmzw/OKy2TrQhX1fmqRklb/TfgPHifz/Do1BNgBlxaDv/lYk X-Google-Smtp-Source: AGHT+IGdkBzBgEhHrd1LW9KAGa/cGv5sdiBTlj+GoDqEM5VjT/z9rWbfYzsj/AoEXZVsdTS9qD3Uag== X-Received: by 2002:a05:6512:3b12:b0:51d:2529:7c4d with SMTP id 2adb3069b0e04-52961a82092mr14632029e87.0.1716991663724; Wed, 29 May 2024 07:07:43 -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 v8 2/8] xen: mapcache: Unmap first entries in buckets Date: Wed, 29 May 2024 16:07:33 +0200 Message-Id: <20240529140739.1387692-3-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991710961100001 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 04:54:33 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=1716991698; cv=none; d=zohomail.com; s=zohoarc; b=CPvt7ocLgTVfGc/CJ4bLc65/Mvh87DP85FscYHkTrk/QSwoYXpWSNT4sL9a6FG0ChFwZVs02QFcF/lhviv3A+mHmZlHVeN1wz4H331Yzwt3cxo/t8om+Hkfw8Cuo6zgikecm73qEaG4wQSdw9Srf02CyRsI/xTZJKxLPNP7PTJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991698; h=Content-Type: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=yfQU3CIk8oi6JUEGcx9QZf/9+B1Oq0qqW+7JWEaNpUQ=; b=TihLbJlpJQaNGwMqLpFORf3LZ8e5CORR6hI1DX3qwdxvzaVi3rBWJWroUrAU64T7lJkf/38wp+UqaO90lE30SMG+gDcAjDKpo539M9fVjEQh9kwyqAcl3KMQpABmM21PZeqarW8o+Jl+g6bc906TlCEvF41JdOWxGzap6445j18= 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 1716991698070206.99559124322616; Wed, 29 May 2024 07:08:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731993.1137788 (Exim 4.92) (envelope-from ) id 1sCJy1-0004iY-AK; Wed, 29 May 2024 14:07:49 +0000 Received: by outflank-mailman (output) from mailman id 731993.1137788; Wed, 29 May 2024 14:07:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCJy1-0004iR-7G; Wed, 29 May 2024 14:07:49 +0000 Received: by outflank-mailman (input) for mailman id 731993; Wed, 29 May 2024 14:07:48 +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 1sCJy0-0004U5-7I for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:07:48 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d361b662-1dc4-11ef-90a1-e314d9c70b13; Wed, 29 May 2024 16:07:46 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52b119986f2so710587e87.1 for ; Wed, 29 May 2024 07:07:46 -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-529715e57c1sm1333816e87.286.2024.05.29.07.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:44 -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: d361b662-1dc4-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991666; x=1717596466; 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=yfQU3CIk8oi6JUEGcx9QZf/9+B1Oq0qqW+7JWEaNpUQ=; b=QoswkUFCR7FGFb+hWlx6AuRK9tIIKedF4mT5M9Vym6NhCnNt9L/y6LyY6S5NeM6m2F blU/eyXywaU32Ekx8sq4+uh43onH5LCL/KLHJ0Vl+npjWnyTqgh3m8Y9B85h0WHpvBZP 6EkVID6sK79PHiDCm+Fd1JZVnND5UzHJQIRiJF3EmXDXueQhdnYIlveIRaLauEnIYuQE Z1AMBdzpU3IP+eicgW2NZnUEgxxFCS+eXtudP1d3klxg1nF11tix1sccKMSxxCuf8QyY Dx5QW9N7b/k2oUas267tyxGqPBut8wT7IwYDCmsuDiiMhYIAwy3a6p0boky3uvRT5xfO AfPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991666; x=1717596466; 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=yfQU3CIk8oi6JUEGcx9QZf/9+B1Oq0qqW+7JWEaNpUQ=; b=NFC1lhpBNflk5TRn7V+3ogxm5Z2fWvHdzycE4bvH/w1omJA0EVm+By/fMA2yC+xIBJ tA0tlFFWTy3f9bCXK8RTYHS2iBTlKE+Wk4lcmioNa/js4B1eukApeMYu35pkfFg+Xw0V aXqfMq8L5uyRfKUfdlACL+dUxFGVcodzMgP+eDcGBaEh6qekSXk7zUWlOSpZztwD5quI spOOCPPLNkO63kDA6gdklkKp3mL1q5AH20/+qi3mcfy89t+BTVQ99PKvzrv6nM44XJOr +ewZo3mVuCPCUBxUzQCLysuaB4ZPO/viOKl9ZuVpWX1YUrq+AeLictE2OL+/Y5gDSVyY acLg== X-Forwarded-Encrypted: i=1; AJvYcCXRL1mH+PPVfjDvx2s7bQwGmMrAIoJtlGXDIsGmqDc3mOTT/mPNbmW1zTpuR9rabA57IbSL5TEr70NMzHiAR2ex/YAO0u9JK/qUG+4E8KY= X-Gm-Message-State: AOJu0YwpqxQt5LJDF4CvIgfvJt/8rr6MUeDp+wT9yY/7lezgR3d8QPaa y8w8dHbdcW+TQ2NhqSQfEtn2g+zSlsMAXdzts9Gty8mm1cQfl8D0 X-Google-Smtp-Source: AGHT+IGzkXOYSImMOV6N87l6JZQ270Dpu6VtX1s3RWgHcPsFkFEwPwb1/bHSmEc0ivZv+7V/GBf3hw== X-Received: by 2002:a19:2d48:0:b0:526:92d7:52d4 with SMTP id 2adb3069b0e04-529bea19e84mr2711966e87.61.1716991666190; Wed, 29 May 2024 07:07:46 -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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v8 3/8] xen: Add xen_mr_is_memory() Date: Wed, 29 May 2024 16:07:34 +0200 Message-Id: <20240529140739.1387692-4-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991720532100003 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/xen/xen-hvm-common.c | 10 ++++++++-- include/sysemu/xen.h | 1 + 2 files changed, 9 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..3445888e39 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -49,4 +49,5 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram= _addr_t size, =20 #endif /* CONFIG_XEN_IS_POSSIBLE */ =20 +bool xen_mr_is_memory(MemoryRegion *mr); #endif --=20 2.40.1 From nobody Mon Nov 25 04:54:33 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=1716991790; cv=none; d=zohomail.com; s=zohoarc; b=i764Jces8Ls8W3QyeWGnUN9dCeuXQ5dDEBc3pz+cSk7JtR++buQHFcp5jKF0ma5X57uT/mTsM3cvdDJ81bcVfYobiwk2KHdWnCQ7OWamdhGxbbxH/Q+v1LrhLlrhn0lRflPAlndaRMduSsI5Nhu9hDr/8r3QVVLp3cvxwMd5WXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991790; 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=hr4mFL3kawAtq0YtjNZv8OoJ6UbTTaozHsbwpoCpDok=; b=I3iYNbX1qzGNOzy52bLd1T9XJdhgH+UqnmufoMAxHD9BrVQ5K8uoK/g2jAuJUVynQsxej1NivKYQbpjRLV+A2O6mFurgYTJma9b36rhgzlOMKKNCZ7SUg1A1V0C7OJ+q6w0RjJUo5kP1JALoiQlbGlsgPZQl1PMj2vmCy/XPzaA= 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 1716991790018472.5441153264892; Wed, 29 May 2024 07:09:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCJy7-00069X-A3; Wed, 29 May 2024 10:07:55 -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 1sCJy5-000693-G7 for qemu-devel@nongnu.org; Wed, 29 May 2024 10:07:53 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCJy1-0005iQ-W4 for qemu-devel@nongnu.org; Wed, 29 May 2024 10:07:51 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52965199234so2436505e87.2 for ; Wed, 29 May 2024 07:07:49 -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-529c0a78ecdsm314588e87.228.2024.05.29.07.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991667; x=1717596467; 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=hr4mFL3kawAtq0YtjNZv8OoJ6UbTTaozHsbwpoCpDok=; b=Q0H34wob6VM4kG+P/XwD8BbaKAaj25w/0srjppHvTkCnTzqv54M9E2h13Q3/C7DaKJ /1TDo7bheZy/L+TQNGDwBCC5QqbzfJrX6+v16/oBf3KLmkz3y9dQKpRAzt4yPPBmMdDj 7nxzTl9lfPbj0MAEQhJ5v/Yt+2bOmAlAPqHpmY+sGZJWD3Q8c62otugJHChC881udyf9 qQzQnqnShZpwLmLxtSIgqu3Jbf8vqlSWucQ86KCWRIRjd7QawxqcgIthd3c7kZEoOFUQ 3QotCn0xFvd6KXo/NtoZ6sFl215OzRfgvnrwLXI/yNVjM3V/9hIjSu1Vm4zI0xK8/5cx m77g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991667; x=1717596467; 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=hr4mFL3kawAtq0YtjNZv8OoJ6UbTTaozHsbwpoCpDok=; b=lZMgovMa2sw2J8NS38xzuS4t/H80bURZCMKEAF5ulb6gEHRJK0yE6GoLclK0KmoaAy Prir1v6blfmIzaazqytuqhRncZ0BBGcrp2H+dCDG+nwcvUUOKbBzjGeSp/dB0AivVTS2 R8xUtN1uPCclDf89xneLmPHG39lpgO7nQB8FtMl07LlvtxWoB0/uI5XfdUP/KTZSZTEi VS5EJSqcg/J2WuZzbzQMnoqijA/M8W4YoJweq71woDBzZMFPwZUaSEllvToQFNX5pi4s 1LsvDcXHuNvHYziJo2pWaPu+l6FnML1rbYn9KGcBQ6RgmVFyI0ScgzB9fKo0oifhvliD V0ww== X-Gm-Message-State: AOJu0YwrSFJR7USNv3pMIIIEYNzmkbFgRUmqvnwRwtt7a6jJuoIeR3C7 7rfwhBlqywsjVljiflvedvxFJP3mFPZLbAOHZxcct4ZOlXsVTRij+V7m4aDS X-Google-Smtp-Source: AGHT+IH9B7AZIAG90ZOr1k/ksFm4b+SQrRsyHOJxQbtt8ZnW8UBVgSGPmeSXeGuGgTHmga7DV2BHDA== X-Received: by 2002:ac2:4e88:0:b0:52b:4f30:9cac with SMTP id 2adb3069b0e04-52b4f309d2emr865486e87.56.1716991667136; Wed, 29 May 2024 07:07:47 -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 , Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v8 4/8] softmmu: xen: Always pass offset + addr to xen_map_cache Date: Wed, 29 May 2024 16:07:35 +0200 Message-Id: <20240529140739.1387692-5-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-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::134; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x134.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991794701100001 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 04:54:33 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=1716991782; cv=none; d=zohomail.com; s=zohoarc; b=XrU0uasIWCRPMtK+E7rS/0MZvOiy+BvjnWc7cFGFKTI+k9gsYxPbz+1tcjqt4bcECiTgNrcONAVeDomKHhsaWyEjWVQ55P/ONIqQ1axR/ZwqxRjmU9v9l2+FGfu+K9SWki1LRpRHLNOdM7PvuZhmEmIir8T+E1P7o1op1k9Fq90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991782; 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=nAPTdk2tBTLhsGMXcyf3g+dPATMhben3YmhgWkc5O5I=; b=aaUEeH9E7SmRi1aF1rT4tO9f2DHOptFWf4YWsnly1JbqbDaXa5siNisvZELezh+9XnvM82xnvEu4yvNtmqmktdC2L1bAW8hF8FLqmmF5VRCcOd/cxMg8kmDga/p7r0745DIdGA9MYWKmwzKySVTOLl7og1bvPBd9jIJoo36eQws= 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 1716991782307311.63525072063976; Wed, 29 May 2024 07:09:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCJy7-00069d-Cj; Wed, 29 May 2024 10:07:55 -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 1sCJy5-00069C-Jn for qemu-devel@nongnu.org; Wed, 29 May 2024 10:07:53 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCJy2-0005iV-NO for qemu-devel@nongnu.org; Wed, 29 May 2024 10:07:52 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52b0d25b54eso1061944e87.3 for ; Wed, 29 May 2024 07:07: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-5296e8842c9sm1309835e87.15.2024.05.29.07.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991668; x=1717596468; 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=nAPTdk2tBTLhsGMXcyf3g+dPATMhben3YmhgWkc5O5I=; b=csOmNvd5RiyrHcC1EeZJvCYSTWZfo1a3zd7gm9cxXnPTxrNRzTyQ+jqnAvTNABPnGe CTc8PTEaHDtH7iYbb5FezLoiOIAaM99DdyQU+cIQ0g+1muQh+7UiHNNnSe2dnjrxjOYs fGMl8l5Qjsqg/nffW6/UXO2v183+Cm209BIyqlFw5dEF+Zn0EIwW1kDwvevjAyzbdy0Y UibqIEJ9H5jrxakum9eCSWVIDYDYInvzbONxYNKOdJT115rR9qBS1KuPQ7oZLlJBG1aq SXCUET0XObY4yRowwTT21ofS090jU0PM+KlrVP0KtFpfQXKZZU8TrSNiHvVtgnkr+Qkw vrhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991668; x=1717596468; 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=nAPTdk2tBTLhsGMXcyf3g+dPATMhben3YmhgWkc5O5I=; b=V/MAFJBrjMBd+2U5FHyZ85ndFN0VxnEi6NiBaJdMWjmULyvXdPrijwDbIiaFSZfppR lkTCKOE6JZzNPW30+O57ukmJEbMaQdtNfSXupsarmhoL8L1M+Ljz2GYsJEoj9UVa2713 3r/SYCVMB1YH8j7c9h4C7SOrWKq3NeIuWrMTMA395KIYnOt5/Vfl81K2RcM2roME9Hgp 6++vOEXYwyowGTfSWq3hEW9maUOLGmWmMm18UH6xjyGoCOWvSLKmVzkKL4+Y6tqKue6Q T38scZVyfhiYL8qS7iI1x0edapE+VXJEatO1ZXMUvCid6SkbbUD2KLt5PVJdSLN+7Job ox/g== X-Gm-Message-State: AOJu0YznwzAtdL7IonHlKENHXUfYVWkshY/8RtD+MnCGZWMZxQEgte7l tTcXyqw+cM/A5QIjRghUteMriHJwCXE/vs/284ZGeAgbuGWOjDTOzDhJpaHy X-Google-Smtp-Source: AGHT+IGOA8Vu0icbu0zyHf6lFCWn4Cz61R+8i5rez/vRWoe83xM7S5KZvOgmZ506Efg9JdJ8IwEO8Q== X-Received: by 2002:ac2:51d1:0:b0:52b:7a44:e17b with SMTP id 2adb3069b0e04-52b7a44e3e7mr163705e87.13.1716991668154; Wed, 29 May 2024 07:07: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" , David Hildenbrand , Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v8 5/8] softmmu: Replace check for RAMBlock offset 0 with xen_mr_is_memory Date: Wed, 29 May 2024 16:07:36 +0200 Message-Id: <20240529140739.1387692-6-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-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::129; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x129.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991784770100003 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 04:54:33 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=1716991691; cv=none; d=zohomail.com; s=zohoarc; b=mVpn6dTbrKB0GlxlnIQv2B75N3rGp+KcNH9TM/DZpzNKOt5qsdSwatkpY3byn3txwMJdM9gu4KA6IwRxern7yoNl1aQFGf31zbRT76QenLR+pCdTha1C73S8KoLinlus7EW92zeWqGuvbGarQs961PzPhe9ImZvs+5BqvnumBEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991691; h=Content-Type: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=8Zme5MAc1tBIih0t7wrm5r256IXDIRT3xxgBybd+OME=; b=fCVnEJkeF3p3eLmcL15DOXiyiKIyyHUhTdUHnT7mxkJ99JRFaALPh0kp1czmKSg4adDaI8o7QnxkKgefAo62yFQdWjrMJkoCwDsED2vY4Pxm7+aRQwDhpjotJ35Mmc1OpLhfiWOXX5Mvov3ndQYpqvQ2P9GTpSNxfQwYbkW2BgE= 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 1716991691205795.7944502103081; Wed, 29 May 2024 07:08:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731994.1137798 (Exim 4.92) (envelope-from ) id 1sCJy5-00050J-H9; Wed, 29 May 2024 14:07:53 +0000 Received: by outflank-mailman (output) from mailman id 731994.1137798; Wed, 29 May 2024 14:07:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCJy5-000509-EQ; Wed, 29 May 2024 14:07:53 +0000 Received: by outflank-mailman (input) for mailman id 731994; Wed, 29 May 2024 14:07: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 1sCJy4-0004Fc-46 for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:07:52 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d574fccb-1dc4-11ef-b4bb-af5377834399; Wed, 29 May 2024 16:07:50 +0200 (CEST) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-52ae14e78e5so818072e87.3 for ; Wed, 29 May 2024 07:07: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-529b712e856sm736822e87.197.2024.05.29.07.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07: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: d574fccb-1dc4-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991670; x=1717596470; 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=8Zme5MAc1tBIih0t7wrm5r256IXDIRT3xxgBybd+OME=; b=SD1i/pICPsiT+YN882ho54wlay6dFQERXGEeWfrPDo6Bq73nnDx98KqphTWEdscsmW aPhqIJ7W4l1Q/GWoI8NruEB+mOmSEm555k1rrtiqH6WmlrHcK51Y4RQ48oNT+k0b9MCH 9p06J8OiJ4gg4pqh7kUbXQNuCOXT2Ad/UiHQoI8ggyIyfiimbnMRlvNjlPyIFQu4Huvl 2UM5BeUZTGmRIT64TiSPI8a1kiDIDR9YmHDNMWZRbwTCtRH69hJwAPFVJVSa9GAiyzYa l+0PIKLXZbr6LGbNc7E8PJtaXvA6YeBpo/NXmdTJfvYEIWXbUs11Rbjn+JMXpvC3ZQDX X8Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991670; x=1717596470; 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=8Zme5MAc1tBIih0t7wrm5r256IXDIRT3xxgBybd+OME=; b=fSZqa0K7smf7JyEUYSwSSvDmxz4Vs+nUkP2as/k0VEdC47ioLNVnRSH97uPyEzwdrI HGf6WGSP9f+CZWqu1SNNozDM6pq+cSPSqgQwCdfZt7ZQAk6YoiTKccvJRhHtLug552KK zcP66f4EuxGPWJd82DFrZVSNADAbLsSuw77XlDkXncUsXpD3FF5+2dj1Ac4MFEJ8rPRy zWQewrE87+bW7L900LRIZ4p+Zk/2+MV0nuliAq83EZCmFKtF9RCrFMSzKU1N2qVPJwaj 6gnSWA/UHkxibk92bHVPcGru2poErNqxbsEwbDyGWtzR+RiJxcFwOP6PYflDODDfLZVU LMiQ== X-Forwarded-Encrypted: i=1; AJvYcCW/Nt0I7sSn7K+i1vS3JKh8mp92Ig8KvVl6yghKDOl0/ouSLP157LMN04M6aIqFK+5Ro/irIRGMdZRlagbH6h3SP8/QVcUUOXhPvVX4wjI= X-Gm-Message-State: AOJu0YzotxyBWseCUM7dlkGlrEMX40zkcAeU9Rg5dSLvPgsVKIw1W5MH 4NquYA8U5zz8m7a74sNYGZboBebvauVnq2L76eWDg9Zo+Nxk5EH3 X-Google-Smtp-Source: AGHT+IG4vbZH58aNNCx5WtguQ+wygMZh32hk2g0EZYP53A4we56wYQmUuGwtdGe8zRPUZLd0GfJq8g== X-Received: by 2002:a05:6512:3194:b0:51f:3fea:cbcf with SMTP id 2adb3069b0e04-529664dac0cmr11284687e87.52.1716991669796; Wed, 29 May 2024 07:07:49 -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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Anthony PERARD , Paul Durrant , Paolo Bonzini , Peter Xu , xen-devel@lists.xenproject.org Subject: [PATCH v8 6/8] xen: mapcache: Pass the ram_addr offset to xen_map_cache() Date: Wed, 29 May 2024 16:07:37 +0200 Message-Id: <20240529140739.1387692-7-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991712298100003 From: "Edgar E. Iglesias" Pass the ram_addr offset to xen_map_cache. This is in preparation for adding grant mappings that need to compute the address within the RAMBlock. No functional changes. Signed-off-by: Edgar E. Iglesias Reviewed-by: David Hildenbrand Reviewed-by: Stefano Stabellini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/xen/xen-mapcache.c | 16 +++++++++++----- include/sysemu/xen-mapcache.h | 2 ++ system/physmem.c | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index ec95445696..a07c47b0b1 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -167,7 +167,8 @@ static void xen_remap_bucket(MapCache *mc, void *vaddr, hwaddr size, hwaddr address_index, - bool dummy) + bool dummy, + ram_addr_t ram_offset) { uint8_t *vaddr_base; xen_pfn_t *pfns; @@ -266,6 +267,7 @@ static void xen_remap_bucket(MapCache *mc, =20 static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_offset, uint8_t lock, bool dma, bool is_wri= te) { MapCacheEntry *entry, *pentry =3D NULL, @@ -337,14 +339,16 @@ tryagain: if (!entry) { entry =3D g_new0(MapCacheEntry, 1); pentry->next =3D entry; - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy= ); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, + ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index !=3D address_index || entry->size !=3D cache_size || !test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { - xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy); + xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy, + ram_offset); } } =20 @@ -391,13 +395,15 @@ tryagain: =20 uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) { uint8_t *p; =20 mapcache_lock(mapcache); - p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, lock, dma, is_= write); + p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offse= t, + lock, dma, is_write); mapcache_unlock(mapcache); return p; } @@ -632,7 +638,7 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapCac= he *mc, trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 xen_remap_bucket(mc, entry, entry->vaddr_base, - cache_size, address_index, false); + cache_size, address_index, false, old_phys_addr); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h index 1ec9e66752..b5e3ea1bc0 100644 --- a/include/sysemu/xen-mapcache.h +++ b/include/sysemu/xen-mapcache.h @@ -19,6 +19,7 @@ typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offs= et, void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque); uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write); ram_addr_t xen_ram_addr_from_mapcache(void *ptr); @@ -37,6 +38,7 @@ static inline void xen_map_cache_init(phys_offset_to_gadd= r_t f, static inline uint8_t *xen_map_cache(MemoryRegion *mr, hwaddr phys_addr, hwaddr size, + ram_addr_t ram_addr_offset, uint8_t lock, bool dma, bool is_write) diff --git a/system/physmem.c b/system/physmem.c index b7847db1a2..33d09f7571 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2231,13 +2231,14 @@ static void *qemu_ram_ptr_length(RAMBlock *block, r= am_addr_t addr, */ if (xen_mr_is_memory(block->mr)) { return xen_map_cache(block->mr, block->offset + addr, - len, lock, lock, - is_write); + len, block->offset, + lock, lock, is_write); } =20 block->host =3D xen_map_cache(block->mr, block->offset, - block->max_length, 1, - lock, is_write); + block->max_length, + block->offset, + 1, lock, is_write); } =20 return ramblock_ptr(block, addr); --=20 2.40.1 From nobody Mon Nov 25 04:54:33 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=1716991697; cv=none; d=zohomail.com; s=zohoarc; b=fKaIi542YYXT81V+y35IImhG8HBzW4FldG8gazC5nPAt7ixUq4K1AZ0/ceSNNOi9MAygAzXXeYvJwvdZ3uiugAM/BqMaRspAjHZTwJuQPRAR/AWN416nq6TerZb7+c/SdkipC6wpTiNjseZkbDhXNhuoesvLvd5WtvRtNL3G+jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991697; 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=6KnYV1+9ySu8xm9Hqqrupes7IMG1mFuyj5Dx0g125FI=; b=KFS1hnbmkHsn/9EHAvQswx2zdH/IK/Zsjdg0ow5X1Z9MwHIAAUrB+c7LBOLJ1FobT9H6gJ2alg2ODTx+ITWgqADk5BmuFFfEA/W5xqz7nJJqvRpeFwLO3xb62GWD0gLHWk9AlQxayG7yU8D6V2Q03sogqDSYSmP98LJcsq3rUsA= 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 1716991697141344.5527976290314; Wed, 29 May 2024 07:08:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731995.1137808 (Exim 4.92) (envelope-from ) id 1sCJy7-0005I7-Ut; Wed, 29 May 2024 14:07:55 +0000 Received: by outflank-mailman (output) from mailman id 731995.1137808; Wed, 29 May 2024 14:07: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 1sCJy7-0005I0-QV; Wed, 29 May 2024 14:07:55 +0000 Received: by outflank-mailman (input) for mailman id 731995; Wed, 29 May 2024 14:07:54 +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 1sCJy6-0004U5-F8 for xen-devel@lists.xenproject.org; Wed, 29 May 2024 14:07:54 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d757e734-1dc4-11ef-90a1-e314d9c70b13; Wed, 29 May 2024 16:07:53 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2e73359b8fbso25209341fa.2 for ; Wed, 29 May 2024 07:07:53 -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-2e95bcf47a4sm25715181fa.57.2024.05.29.07.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07: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: d757e734-1dc4-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991673; x=1717596473; 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=6KnYV1+9ySu8xm9Hqqrupes7IMG1mFuyj5Dx0g125FI=; b=ZJguEYA/goiqgE71vkjZksCHexlAHJQy0pKwAfN7K+IOtzikM6Qan8s8pxg9hllTP8 +NKzkcElvVcFMWpesVxiWgApRHKfiHSZNAUWqs5es5zEfUP8JHrI/hke8qbPrCzHc2aH FIycn4SJ+lSVxHAgAaPmYIcaXykkYaAOTU56gUBbo7JMuszqfewXGXi0f9zObqNUjr3M NAf+/UHLHdPOxewxsr8nPCbru3OwOPYDh1k+KcQNLdXXTfMlZkyLGKqqQpDyJmu916pD a1217N3oSWX+AmDc41SNDiVy/MgH9nUdlcueqyEsFza+0zV3aXSjjEJ3pkkvIznmSade q9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991673; x=1717596473; 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=6KnYV1+9ySu8xm9Hqqrupes7IMG1mFuyj5Dx0g125FI=; b=vYe4BNpjEG4sagHtjSbKNOXcB0MU3SL4iyxBw+AE+pe14G8D+qvpB9ZHgMrs7mcnyF ehGdZq6E4YvSZ0OsPa+tUfhLYc5Mxu25LS5KFbItBdjrxlfN6bA8YDtoYCNQ0Awa9k8t ZmsvtVXHxLiLAKyOjyuk5nJFZhEEzEVfMQTU6MhMXSwvXcI0baO2x/COmNVTOuH0QPTY rzc/LbCIhFIV9sV07L+2joFyYqZsV0TvnDrLLthqGvvKJNTlIDXLutv12HPj49cswzEF k/Wj2SaaQv83xklFXf0OIl0478/yyAc+JPIpxjTYgkOTLYLCvgt/8eqxD6dXWf7PYh3F 6njg== X-Forwarded-Encrypted: i=1; AJvYcCVmd8qv3GS/m1sVDrMlL+3QlDZjYtnPzgtz/161RS4LuErj4g1Sf6gMVe14a4lA6qmh9sTJNKvwQgL9QSkNP6HxGOK4MR4MWrFQlKDz9G8= X-Gm-Message-State: AOJu0YwVDOiO+mi7CGUMf7LqZtJ9LS3ry/tlFowK8eBuhmZJjmYI7DFA L7W2cRHk9Yml1l61f5cGghtZ6MIzEi+lRDNx9wSfJXhDD36LkKu6 X-Google-Smtp-Source: AGHT+IGD9ZwNPNUv35c+UJ5GB2OUukDkocTjVhprwhJ89cISo2uRDy4+PmwLngnnEeG1Una9nQbZqw== X-Received: by 2002:a2e:a685:0:b0:2ea:80b7:c464 with SMTP id 38308e7fff4ca-2ea80b7c7acmr4569281fa.22.1716991672097; Wed, 29 May 2024 07:07: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" , Manos Pitsidianakis , Anthony PERARD , Paul Durrant , xen-devel@lists.xenproject.org Subject: [PATCH v8 7/8] xen: mapcache: Add support for grant mappings Date: Wed, 29 May 2024 16:07:38 +0200 Message-Id: <20240529140739.1387692-8-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991719422100001 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Add a second mapcache for grant mappings. The mapcache for grants needs to work with XC_PAGE_SIZE granularity since we can't map larger ranges than what has been granted to us. Like with foreign mappings (xen_memory), machines using grants are expected to initialize the xen_grants MR and map it into their address-map accordingly. CC: Manos Pitsidianakis Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini --- hw/xen/xen-hvm-common.c | 12 ++- hw/xen/xen-mapcache.c | 165 +++++++++++++++++++++++++------- include/hw/xen/xen-hvm-common.h | 3 + include/sysemu/xen.h | 1 + 4 files changed, 144 insertions(+), 37 deletions(-) diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index a0a0252da0..b8ace1c368 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -10,12 +10,18 @@ #include "hw/boards.h" #include "hw/xen/arch_hvm.h" =20 -MemoryRegion xen_memory; +MemoryRegion xen_memory, xen_grants; =20 -/* Check for xen memory. */ +/* Check for any kind of xen memory, foreign mappings or grants. */ bool xen_mr_is_memory(MemoryRegion *mr) { - return mr =3D=3D &xen_memory; + return mr =3D=3D &xen_memory || mr =3D=3D &xen_grants; +} + +/* Check specifically for grants. */ +bool xen_mr_is_grants(MemoryRegion *mr) +{ + return mr =3D=3D &xen_grants; } =20 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c index a07c47b0b1..5f23b0adbe 100644 --- a/hw/xen/xen-mapcache.c +++ b/hw/xen/xen-mapcache.c @@ -14,6 +14,7 @@ =20 #include =20 +#include "hw/xen/xen-hvm-common.h" #include "hw/xen/xen_native.h" #include "qemu/bitmap.h" =20 @@ -21,6 +22,8 @@ #include "sysemu/xen-mapcache.h" #include "trace.h" =20 +#include +#include =20 #if HOST_LONG_BITS =3D=3D 32 # define MCACHE_MAX_SIZE (1UL<<31) /* 2GB Cap */ @@ -41,6 +44,7 @@ typedef struct MapCacheEntry { unsigned long *valid_mapping; uint32_t lock; #define XEN_MAPCACHE_ENTRY_DUMMY (1 << 0) +#define XEN_MAPCACHE_ENTRY_GRANT (1 << 1) uint8_t flags; hwaddr size; struct MapCacheEntry *next; @@ -71,6 +75,8 @@ typedef struct MapCache { } MapCache; =20 static MapCache *mapcache; +static MapCache *mapcache_grants; +static xengnttab_handle *xen_region_gnttabdev; =20 static inline void mapcache_lock(MapCache *mc) { @@ -131,6 +137,12 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) unsigned long max_mcache_size; unsigned int bucket_shift; =20 + xen_region_gnttabdev =3D xengnttab_open(NULL, 0); + if (xen_region_gnttabdev =3D=3D NULL) { + error_report("mapcache: Failed to open gnttab device"); + exit(EXIT_FAILURE); + } + if (HOST_LONG_BITS =3D=3D 32) { bucket_shift =3D 16; } else { @@ -159,6 +171,15 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void= *opaque) mapcache =3D xen_map_cache_init_single(f, opaque, bucket_shift, max_mcache_size); + + /* + * Grant mappings must use XC_PAGE_SIZE granularity since we can't + * map anything beyond the number of pages granted to us. + */ + mapcache_grants =3D xen_map_cache_init_single(f, opaque, + XC_PAGE_SHIFT, + max_mcache_size); + setrlimit(RLIMIT_AS, &rlimit_as); } =20 @@ -168,17 +189,24 @@ static void xen_remap_bucket(MapCache *mc, hwaddr size, hwaddr address_index, bool dummy, + bool grant, + bool is_write, ram_addr_t ram_offset) { uint8_t *vaddr_base; - xen_pfn_t *pfns; - int *err; + g_autofree uint32_t *refs =3D NULL; + g_autofree xen_pfn_t *pfns =3D NULL; + g_autofree int *err; unsigned int i; hwaddr nb_pfn =3D size >> XC_PAGE_SHIFT; =20 trace_xen_remap_bucket(address_index); =20 - pfns =3D g_new0(xen_pfn_t, nb_pfn); + if (grant) { + refs =3D g_new0(uint32_t, nb_pfn); + } else { + pfns =3D g_new0(xen_pfn_t, nb_pfn); + } err =3D g_new0(int, nb_pfn); =20 if (entry->vaddr_base !=3D NULL) { @@ -207,21 +235,51 @@ static void xen_remap_bucket(MapCache *mc, g_free(entry->valid_mapping); entry->valid_mapping =3D NULL; =20 - for (i =3D 0; i < nb_pfn; i++) { - pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIFT)) = + i; + if (grant) { + hwaddr grant_base =3D address_index - (ram_offset >> XC_PAGE_SHIFT= ); + + for (i =3D 0; i < nb_pfn; i++) { + refs[i] =3D grant_base + i; + } + } else { + for (i =3D 0; i < nb_pfn; i++) { + pfns[i] =3D (address_index << (mc->bucket_shift - XC_PAGE_SHIF= T)) + i; + } } =20 - /* - * If the caller has requested the mapping at a specific address use - * MAP_FIXED to make sure it's honored. - */ + entry->flags &=3D ~XEN_MAPCACHE_ENTRY_GRANT; + if (!dummy) { - vaddr_base =3D xenforeignmemory_map2(xen_fmem, xen_domid, vaddr, - PROT_READ | PROT_WRITE, - vaddr ? MAP_FIXED : 0, - nb_pfn, pfns, err); + if (grant) { + int prot =3D PROT_READ; + + if (is_write) { + prot |=3D PROT_WRITE; + } + + entry->flags |=3D XEN_MAPCACHE_ENTRY_GRANT; + assert(vaddr =3D=3D NULL); + vaddr_base =3D xengnttab_map_domain_grant_refs(xen_region_gntt= abdev, + nb_pfn, + xen_domid, refs, + prot); + } else { + /* + * If the caller has requested the mapping at a specific addre= ss use + * MAP_FIXED to make sure it's honored. + * + * We don't yet support upgrading mappings from RO to RW, to h= andle + * models using ordinary address_space_rw(), foreign mappings = ignore + * is_write and are always mapped RW. + */ + vaddr_base =3D xenforeignmemory_map2(xen_fmem, xen_domid, vadd= r, + PROT_READ | PROT_WRITE, + vaddr ? MAP_FIXED : 0, + nb_pfn, pfns, err); + } if (vaddr_base =3D=3D NULL) { - perror("xenforeignmemory_map2"); + perror(grant ? "xengnttab_map_domain_grant_refs" + : "xenforeignmemory_map2"); exit(-1); } } else { @@ -260,15 +318,13 @@ static void xen_remap_bucket(MapCache *mc, bitmap_set(entry->valid_mapping, i, 1); } } - - g_free(pfns); - g_free(err); } =20 static uint8_t *xen_map_cache_unlocked(MapCache *mc, hwaddr phys_addr, hwaddr size, ram_addr_t ram_offset, - uint8_t lock, bool dma, bool is_wri= te) + uint8_t lock, bool dma, + bool grant, bool is_write) { MapCacheEntry *entry, *pentry =3D NULL, *free_entry =3D NULL, *free_pentry =3D NULL; @@ -340,7 +396,7 @@ tryagain: entry =3D g_new0(MapCacheEntry, 1); pentry->next =3D entry; xen_remap_bucket(mc, entry, NULL, cache_size, address_index, dummy, - ram_offset); + grant, is_write, ram_offset); } else if (!entry->lock) { if (!entry->vaddr_base || entry->paddr_index !=3D address_index || entry->size !=3D cache_size || @@ -348,7 +404,7 @@ tryagain: test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { xen_remap_bucket(mc, entry, NULL, cache_size, address_index, d= ummy, - ram_offset); + grant, is_write, ram_offset); } } =20 @@ -399,12 +455,26 @@ uint8_t *xen_map_cache(MemoryRegion *mr, uint8_t lock, bool dma, bool is_write) { + bool grant =3D xen_mr_is_grants(mr); + MapCache *mc =3D grant ? mapcache_grants : mapcache; uint8_t *p; =20 - mapcache_lock(mapcache); - p =3D xen_map_cache_unlocked(mapcache, phys_addr, size, ram_addr_offse= t, - lock, dma, is_write); - mapcache_unlock(mapcache); + if (grant && !lock) { + /* + * Grants are only supported via address_space_map(). Anything + * else is considered a user/guest error. + * + * QEMU generally doesn't expect these mappings to ever fail, so + * if this happens we report an error message and abort(). + */ + error_report("Tried to access a grant reference without mapping it= ."); + abort(); + } + + mapcache_lock(mc); + p =3D xen_map_cache_unlocked(mc, phys_addr, size, ram_addr_offset, + lock, dma, grant, is_write); + mapcache_unlock(mc); return p; } =20 @@ -449,7 +519,14 @@ static ram_addr_t xen_ram_addr_from_mapcache_single(Ma= pCache *mc, void *ptr) =20 ram_addr_t xen_ram_addr_from_mapcache(void *ptr) { - return xen_ram_addr_from_mapcache_single(mapcache, ptr); + ram_addr_t addr; + + addr =3D xen_ram_addr_from_mapcache_single(mapcache, ptr); + if (addr =3D=3D RAM_ADDR_INVALID) { + addr =3D xen_ram_addr_from_mapcache_single(mapcache_grants, ptr); + } + + return addr; } =20 static void xen_invalidate_map_cache_entry_unlocked(MapCache *mc, @@ -460,6 +537,7 @@ static void xen_invalidate_map_cache_entry_unlocked(Map= Cache *mc, hwaddr paddr_index; hwaddr size; int found =3D 0; + int rc; =20 QTAILQ_FOREACH(reventry, &mc->locked_entries, next) { if (reventry->vaddr_req =3D=3D buffer) { @@ -502,7 +580,14 @@ static void xen_invalidate_map_cache_entry_unlocked(Ma= pCache *mc, } =20 ram_block_notify_remove(entry->vaddr_base, entry->size, entry->size); - if (munmap(entry->vaddr_base, entry->size) !=3D 0) { + if (entry->flags & XEN_MAPCACHE_ENTRY_GRANT) { + rc =3D xengnttab_unmap(xen_region_gnttabdev, entry->vaddr_base, + entry->size >> mc->bucket_shift); + } else { + rc =3D munmap(entry->vaddr_base, entry->size); + } + + if (rc) { perror("unmap fails"); exit(-1); } @@ -521,14 +606,24 @@ typedef struct XenMapCacheData { uint8_t *buffer; } XenMapCacheData; =20 +static void xen_invalidate_map_cache_entry_single(MapCache *mc, uint8_t *b= uffer) +{ + mapcache_lock(mc); + xen_invalidate_map_cache_entry_unlocked(mc, buffer); + mapcache_unlock(mc); +} + +static void xen_invalidate_map_cache_entry_all(uint8_t *buffer) +{ + xen_invalidate_map_cache_entry_single(mapcache, buffer); + xen_invalidate_map_cache_entry_single(mapcache_grants, buffer); +} + static void xen_invalidate_map_cache_entry_bh(void *opaque) { XenMapCacheData *data =3D opaque; =20 - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, data->buffer); - mapcache_unlock(mapcache); - + xen_invalidate_map_cache_entry_all(data->buffer); aio_co_wake(data->co); } =20 @@ -543,9 +638,7 @@ void coroutine_mixed_fn xen_invalidate_map_cache_entry(= uint8_t *buffer) xen_invalidate_map_cache_entry_bh, &data); qemu_coroutine_yield(); } else { - mapcache_lock(mapcache); - xen_invalidate_map_cache_entry_unlocked(mapcache, buffer); - mapcache_unlock(mapcache); + xen_invalidate_map_cache_entry_all(buffer); } } =20 @@ -597,6 +690,7 @@ void xen_invalidate_map_cache(void) bdrv_drain_all(); =20 xen_invalidate_map_cache_single(mapcache); + xen_invalidate_map_cache_single(mapcache_grants); } =20 static uint8_t *xen_replace_cache_entry_unlocked(MapCache *mc, @@ -632,13 +726,16 @@ static uint8_t *xen_replace_cache_entry_unlocked(MapC= ache *mc, return NULL; } =20 + assert((entry->flags & XEN_MAPCACHE_ENTRY_GRANT) =3D=3D 0); + address_index =3D new_phys_addr >> mc->bucket_shift; address_offset =3D new_phys_addr & (mc->bucket_size - 1); =20 trace_xen_replace_cache_entry_dummy(old_phys_addr, new_phys_addr); =20 xen_remap_bucket(mc, entry, entry->vaddr_base, - cache_size, address_index, false, old_phys_addr); + cache_size, address_index, false, + false, false, old_phys_addr); if (!test_bits(address_offset >> XC_PAGE_SHIFT, test_bit_size >> XC_PAGE_SHIFT, entry->valid_mapping)) { diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h index 65a51aac2e..3d796235dc 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -16,6 +16,7 @@ #include =20 extern MemoryRegion xen_memory; +extern MemoryRegion xen_grants; extern MemoryListener xen_io_listener; extern DeviceListener xen_device_listener; =20 @@ -29,6 +30,8 @@ extern DeviceListener xen_device_listener; do { } while (0) #endif =20 +#define XEN_GRANT_ADDR_OFF (1ULL << 63) + static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) { return shared_page->vcpu_ioreq[i].vp_eport; diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h index 3445888e39..d70eacfbe2 100644 --- a/include/sysemu/xen.h +++ b/include/sysemu/xen.h @@ -50,4 +50,5 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram= _addr_t size, #endif /* CONFIG_XEN_IS_POSSIBLE */ =20 bool xen_mr_is_memory(MemoryRegion *mr); +bool xen_mr_is_grants(MemoryRegion *mr); #endif --=20 2.40.1 From nobody Mon Nov 25 04:54:33 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=1716991762; cv=none; d=zohomail.com; s=zohoarc; b=URU/3fWmdkOdOttI8yfR4810d3oIS//Mw4qfUnvffd5ppL4qDIRv8qVszdPcGXb/tR0RpcIZbFFVYhUJYeLUtZjni/WK/tqTzdTppLTkq13I8AJeBz+PGl4WCfUFQbofsDqP0iFt5O/dRK6MIyIju7QKs93Lfn5GYKtcjwkw2nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716991762; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UEv27P4h9FHThImWZFNAzfWD14sQulMv77KGwqjc99g=; b=N39k6WfHFDXiYTKxgGkrbfk63IzZtEwwsYYFnbskJxjy1a3+oNb/xzSLSVSYre5mvUNZ7A34EtAL8/cf6iFDlMA8Ns9Qw/zoHgCiSAsUVAoudmz448iYIZ2gogMLz/FJV1vZcQ3wFOp12i2wtyLvIdrhCWp4KzqA/mA7dBPFlWo= 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 1716991762923867.9976434614825; Wed, 29 May 2024 07:09:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCJyG-0006Ch-1E; Wed, 29 May 2024 10:08: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 1sCJyD-0006C1-2F; Wed, 29 May 2024 10:08:01 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCJyA-0005jW-F5; Wed, 29 May 2024 10:08:00 -0400 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52b7a3c19b0so89892e87.3; Wed, 29 May 2024 07:07: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-52970760245sm1290849e87.122.2024.05.29.07.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716991675; x=1717596475; 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=UEv27P4h9FHThImWZFNAzfWD14sQulMv77KGwqjc99g=; b=GmLp6uVBpfpPp65H4Lta1X4IKs2vtmyu6m9Cd59jPMHEC08tCAIj/JpntShn1EChB2 58m3aEqIyRdfg0ZOWImYkht9k6LJ0CPvTckI6yHTvJpdA87Zl3J015qQAlONYbCM/Tg4 8hvwDMfM7T7CWawF3wzgIswHQ8S95uxJ9C33xBL/0e2v4nmOUyZjzndGA89Dn2CMwXlF kAfCWNHhYs7L5kCN6Iv6bwJB3MIKKg32WXUaxhicdFlDvTtZlmZJbI/S5aivInuxxAqk DJxHXxC0Wfm2mVkUJwkODRuuUeXWoyVqAdoSAlTd3AhrfVsZ+9RGJ/T2YLIehIkb6TcN a6uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716991675; x=1717596475; 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=UEv27P4h9FHThImWZFNAzfWD14sQulMv77KGwqjc99g=; b=wY70hsOh8eAEfo1u6elmwwRDRdoHoQ5wr2Dt7hpmnEAnGy4/yHTUc6Lntz+9LO9zVv N6t0/JNA3eSLTrIyz2+Ov12TWHz1bYhkOqhotE3gOaE+HEGDJtAPLGaWHRSgFdvJcua/ Cwq18vulUDkphdCyD1TERDH5WKCDTe1CsA9qESJ2SU8A0YJzKKiR++zEFGtU6PLbRIi6 NwZFGwx+/lfYWi7mVMlBbvEr3SarVSFUQ2beq/m85iEyAFiG3Imv6VWvp24pmayoMETe +bwVg/BlxwNKovk/wYpOzhY1UvslFWV3hF6j2yAdfcZStUkHAzojlln3qUlIOdZvcdei 2KzQ== X-Forwarded-Encrypted: i=1; AJvYcCX1AxCI6zFg1YPOEgHWN19SKSmWcRfgo7XfcVZzRV7O5P9HkV2d10f8EdxDmjTBOuIWk6OdAalEPyo5pOutSLlvqChV X-Gm-Message-State: AOJu0YyLLwG8lFWA6H1C/bUgWuupT0/lLTjZCjphxH32xD7HldhG3DO+ oBpo1rdmjWXwr9M+BUd+tfT2WI4wdfgiFfH9reBxXHfBn+mzSeXU4plpaBlE X-Google-Smtp-Source: AGHT+IEL0r6gK0il/RzsaJAW9Kz7pktj4eJeK2D4zknuRjCDUMpY29QDkroYx9PyQXCu1NbDqU9kWQ== X-Received: by 2002:ac2:4904:0:b0:51f:fcaf:e92d with SMTP id 2adb3069b0e04-52964baf401mr9487810e87.18.1716991674993; Wed, 29 May 2024 07:07: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" , Manos Pitsidianakis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , qemu-arm@nongnu.org Subject: [PATCH v8 8/8] hw/arm: xen: Enable use of grant mappings Date: Wed, 29 May 2024 16:07:39 +0200 Message-Id: <20240529140739.1387692-9-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240529140739.1387692-1-edgar.iglesias@gmail.com> References: <20240529140739.1387692-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::130; envelope-from=edgar.iglesias@gmail.com; helo=mail-lf1-x130.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1716991765914100011 From: "Edgar E. Iglesias" Signed-off-by: Edgar E. Iglesias Reviewed-by: Stefano Stabellini Reviewed-by: Manos Pitsidianakis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/xen_arm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index 15fa7dfa84..6fad829ede 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -125,6 +125,11 @@ static void xen_init_ram(MachineState *machine) GUEST_RAM1_BASE, ram_size[1]); memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi); } + + /* Setup support for grants. */ + memory_region_init_ram(&xen_grants, NULL, "xen.grants", block_len, + &error_fatal); + memory_region_add_subregion(sysmem, XEN_GRANT_ADDR_OFF, &xen_grants); } =20 void arch_handle_ioreq(XenIOState *state, ioreq_t *req) --=20 2.40.1