From nobody Sat Dec 6 23:32:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@getutm.app; 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=getutm.app ARC-Seal: i=1; a=rsa-sha256; t=1764734395; cv=none; d=zohomail.com; s=zohoarc; b=lBWefCIldDdyJOXP0OJntS3XD9zCZB3wY7IUSvIKp0Uk+w5QhlxeXKpJMIz6ogH4D2uqJwiGgKJCRcSPPVuc1j/1ldHPEBICaC4zFSYagqBAnRmLgU9g2+5QNUoAFVkYsjT2FJyNAEplylT/DHr+IRRo4xY1jSxjUoP9N2w338Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764734395; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a7Dkb2KHnm/ht47tdJWttydGvnkucrr+JAvb4EnnYSg=; b=Wegy08h1t3gshlb2DTR07RjaOncNrpObXUWHsKb0HZlKzf6twcHFKLZi+YKJfIydoBp2FxlLXvRAVb2hVHOeIg83+qSJfD/62WxX07qeqWYX+UmHKyyFi+eD6V7D6PUqTWsoW9Z6xaua/fUcuAXkkO5FTP1sWP/e3GvVtOP6lx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@getutm.app; 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 1764734395676594.5414321219481; Tue, 2 Dec 2025 19:59:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vQe1L-0008ED-QV; Tue, 02 Dec 2025 22:59:15 -0500 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 1vQe1K-0008Dh-Kx for qemu-devel@nongnu.org; Tue, 02 Dec 2025 22:59:14 -0500 Received: from a4i956.smtp2go.com ([158.120.83.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vQe1I-00007p-8U for qemu-devel@nongnu.org; Tue, 02 Dec 2025 22:59:14 -0500 Received: from [10.159.238.187] (helo=localhost.localdomain) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA512__CHACHA20_POLY1305:256) (Exim 4.98.1-S2G) (envelope-from ) id 1vQe11-FnQW0hPuz7X-VkJn; Wed, 03 Dec 2025 03:58:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getutm.app; i=@getutm.app; q=dns/txt; s=s483429; t=1764734342; h=from : subject : to : message-id : date; bh=a7Dkb2KHnm/ht47tdJWttydGvnkucrr+JAvb4EnnYSg=; b=CoULHtPecpSBpVxirBnsQ0hxXVuLAqufcfhqkTFGWn0373ydlFeboRaBmtZU3cbXq+S7r rAPEzF3C3iw1BhpKJ03LdNm5fMLevFrOOhPh1Rwj4DwoW9/OV+h0KtCj0keGnvvuFzLRiMY tQEMANObOVPb9r/cQ6x4m8Fp6tdbjkcAOAzQLF3mDgcXCgGRB31RLBol4tiGrgzvxxWMt8X QbfLLXr3L+2pvIt7i7UPI/qzrE/w4MEuKS1C/wNsFqxiXpDEqku6aaqcL8GGKmZ/XpQWodV ofkMdN/+6PCr2u+/S5z/71T6Yy0hhSjjt6WtHT5VHjW7RZNK8OyJBRpR2HUQ== From: Joelle van Dyne To: qemu-devel@nongnu.org Cc: Joelle van Dyne , Cameron Esfahani , Roman Bolshakov , Phil Dennis-Jordan , Mads Ynddal Subject: [PATCH] hvf: allow slot size to increase Date: Tue, 2 Dec 2025 19:58:46 -0800 Message-ID: <20251203035847.94102-1-j@getutm.app> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please forward a copy of this message, including all headers, to Feedback-ID: 483429m:483429abrvJvs:483429skAbc49uMO X-smtpcorp-track: expYtByXnsVz.k1HGI-DjMiJK.CjD3hwFsKqP 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=158.120.83.188; envelope-from=bounce.x8k9of7zkabb1w5=xzjezy0rkw99=e7l6md1o6apd9i@em483429.getutm.app; helo=a4i956.smtp2go.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @getutm.app) X-ZM-MESSAGEID: 1764734397564019200 Content-Type: text/plain; charset="utf-8" Instead of having a fixed limit of 32 slots, we allow the number of slots to expand. Currently there does not seem to be a need to add a limit, but if the allocation fails, we will abort. The KVM backend was used for inspiration here. Signed-off-by: Joelle van Dyne --- include/system/hvf_int.h | 12 ++++++- accel/hvf/hvf-all.c | 78 ++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h index 3d2be4092e..1d2616595c 100644 --- a/include/system/hvf_int.h +++ b/include/system/hvf_int.h @@ -27,6 +27,7 @@ typedef hv_vcpuid_t hvf_vcpuid; /* hvf_slot flags */ #define HVF_SLOT_LOG (1 << 0) =20 +/* Represent memory logically mapped by QEMU */ typedef struct hvf_slot { uint64_t start; uint64_t size; @@ -36,6 +37,14 @@ typedef struct hvf_slot { MemoryRegion *region; } hvf_slot; =20 +/* Represent memory currently mapped in HVF */ +typedef struct hvf_mac_slot { + int present; + uint64_t size; + uint64_t gpa_start; + uint64_t gva; +} hvf_mac_slot; + typedef struct hvf_vcpu_caps { uint64_t vmx_cap_pinbased; uint64_t vmx_cap_procbased; @@ -48,7 +57,8 @@ typedef struct hvf_vcpu_caps { struct HVFState { AccelState parent_obj; =20 - hvf_slot slots[32]; + hvf_slot *slots; + hvf_mac_slot *mac_slots; int num_slots; =20 hvf_vcpu_caps *hvf_caps; diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c index 0a4b498e83..367ff4fd40 100644 --- a/accel/hvf/hvf-all.c +++ b/accel/hvf/hvf-all.c @@ -21,14 +21,8 @@ =20 bool hvf_allowed; =20 -struct mac_slot { - int present; - uint64_t size; - uint64_t gpa_start; - uint64_t gva; -}; - -struct mac_slot mac_slots[32]; +/* Default num of memslots to be allocated when VM starts */ +#define HVF_MEMSLOTS_NUM_ALLOC_DEFAULT 32 =20 const char *hvf_return_string(hv_return_t ret) { @@ -58,12 +52,60 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *fi= le, unsigned int line, abort(); } =20 +static bool hvf_slots_grow(HVFState *state, unsigned int num_slots_new) +{ + unsigned int i, cur =3D state->num_slots; + hvf_slot *slots; + hvf_mac_slot *mac_slots; + + assert(num_slots_new > cur); + if (cur =3D=3D 0) { + slots =3D g_new0(hvf_slot, num_slots_new); + if (!slots) { + return false; + } + mac_slots =3D g_new0(hvf_mac_slot, num_slots_new); + if (!mac_slots) { + g_free(slots); + return false; + } + } else { + slots =3D g_renew(hvf_slot, state->slots, num_slots_new); + if (!slots) { + return false; + } + mac_slots =3D g_renew(hvf_mac_slot, state->mac_slots, num_slots_ne= w); + if (!mac_slots) { + /* save allocated slots but not new size */ + state->slots =3D slots; + return false; + } + /* + * g_renew() doesn't initialize extended buffers, however hvf + * memslots require fields to be zero-initialized. E.g. pointers, + * memory_size field, etc. + */ + memset(&slots[cur], 0x0, sizeof(slots[0]) * (num_slots_new - cur)); + memset(&mac_slots[cur], 0x0, sizeof(mac_slots[0]) * (num_slots_new= - cur)); + } + + for (i =3D cur; i < num_slots_new; i++) { + slots[i].slot_id =3D i; + } + + state->slots =3D slots; + state->mac_slots =3D mac_slots; + state->num_slots =3D num_slots_new; + + return true; +} + static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags) { - struct mac_slot *macslot; + hvf_mac_slot *macslot; hv_return_t ret; =20 - macslot =3D &mac_slots[slot->slot_id]; + macslot =3D &hvf_state->mac_slots[slot->slot_id]; =20 if (macslot->present) { if (macslot->size !=3D slot->size) { @@ -160,8 +202,11 @@ static void hvf_set_phys_mem(MemoryRegionSection *sect= ion, bool add) } =20 if (x =3D=3D hvf_state->num_slots) { - error_report("No free slots"); - abort(); + if (!hvf_slots_grow(hvf_state, hvf_state->num_slots * 2)) { + error_report("Cannot allocate any more slots"); + abort(); + } + mem =3D &hvf_state->slots[x]; } =20 mem->size =3D int128_get64(section->size); @@ -250,11 +295,11 @@ static MemoryListener hvf_memory_listener =3D { =20 static int hvf_accel_init(AccelState *as, MachineState *ms) { - int x; hv_return_t ret; HVFState *s =3D HVF_STATE(as); int pa_range =3D 36; MachineClass *mc =3D MACHINE_GET_CLASS(ms); + bool success; =20 if (mc->hvf_get_physical_address_range) { pa_range =3D mc->hvf_get_physical_address_range(ms); @@ -271,11 +316,8 @@ static int hvf_accel_init(AccelState *as, MachineState= *ms) } assert_hvf_ok(ret); =20 - s->num_slots =3D ARRAY_SIZE(s->slots); - for (x =3D 0; x < s->num_slots; ++x) { - s->slots[x].size =3D 0; - s->slots[x].slot_id =3D x; - } + success =3D hvf_slots_grow(s, HVF_MEMSLOTS_NUM_ALLOC_DEFAULT); + assert(success); =20 QTAILQ_INIT(&s->hvf_sw_breakpoints); =20 --=20 2.41.0