From nobody Tue Nov 4 18:42:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539873883149639.7063177015286; Thu, 18 Oct 2018 07:44:43 -0700 (PDT) Received: from localhost ([::1]:42751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD9XW-00007Y-3J for importer@patchew.org; Thu, 18 Oct 2018 10:44:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD9L0-0005wU-FD for qemu-devel@nongnu.org; Thu, 18 Oct 2018 10:31:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD9Kz-0007NL-Ai for qemu-devel@nongnu.org; Thu, 18 Oct 2018 10:31:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gD9Ku-0007EF-JK; Thu, 18 Oct 2018 10:31:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8325888314; Thu, 18 Oct 2018 14:31:39 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-215.ams2.redhat.com [10.36.116.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0E64789A6; Thu, 18 Oct 2018 14:31:33 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, shameerali.kolothum.thodi@huawei.com, kwangwoo.lee@sk.com, imammedo@redhat.com, david@redhat.com Date: Thu, 18 Oct 2018 16:30:33 +0200 Message-Id: <20181018143042.29588-8-eric.auger@redhat.com> In-Reply-To: <20181018143042.29588-1-eric.auger@redhat.com> References: <20181018143042.29588-1-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 18 Oct 2018 14:31:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v4 07/16] hw/arm/virt: Implement kvm_type function for 3.2 machine X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drjones@redhat.com, dgilbert@redhat.com, Suzuki.Poulose@arm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch computes the requested IPA bits according to the requested maxram value. The machine class kvm_type() callback is implemented and fills the kvm_type[7-0] bits with the computed max IPA shift (0 default value corresponds to 40b IPA). The kvm_type is passed to the KVM_CREATE_VM ioctl. The max IPA address shift is computed assuming the top of the address space is occuped by device memory starting at 2TB and of size maxram_size - ramsize. Signed-off-by: Eric Auger --- The approach to have an IPA range depending on the machine memory attributes is preferred here against having an IPA range based on the max capability of the host (which would be simpler). This latter would sometimes lead to having additional useless translation levels at stage2 as this may downgrade the guest performance. --- hw/arm/virt.c | 48 ++++++++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f920ef247b..21718c250e 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -108,8 +108,12 @@ * of a terabyte of RAM will be doing it on a host with more than a * terabyte of physical address space.) */ +#define SZ_1G (1024ULL * 1024 * 1024) #define RAMLIMIT_GB 255 -#define RAMLIMIT_BYTES (RAMLIMIT_GB * 1024ULL * 1024 * 1024) +#define RAMLIMIT_BYTES (RAMLIMIT_GB * SZ_1G) + +/* device memory starts at 2TB */ +#define DEVICE_MEM_BASE (2048 * SZ_1G) =20 /* Addresses and sizes of our components. * 0..128MB is space for a flash device so we can run bootrom code such as= UEFI. @@ -1748,6 +1752,38 @@ static HotplugHandler *virt_machine_get_hotplug_hand= ler(MachineState *machine, return NULL; } =20 +/* + * for arm64 kvm_type [7-0] encodes the IPA size shift + */ +static inline int virt_kvm_type(MachineState *ms, const char *type_str) +{ + int max_vm_phys_shift =3D kvm_arm_get_max_vm_phys_shift(ms); + ram_addr_t device_mem_size =3D ms->maxram_size - ms->ram_size; + uint8_t requested_vm_phys_shift; + + if (!device_mem_size) { + return 0; /* default 40b IPA */ + } + + /* we need at least 42b IPA to fit device memory at 2TB*/ + if (max_vm_phys_shift < 42) { + error_report("This host does not support 42b IPA: " + "maxram/slots options not usable"); + exit(1); + } + + requested_vm_phys_shift =3D 64 - clz64(DEVICE_MEM_BASE + device_mem_si= ze); + + if (requested_vm_phys_shift > max_vm_phys_shift) { + error_report("maxmem option value too large. Max supported value " + "for this host is 0x%"PRIx64, + (ram_addr_t)((1ULL << max_vm_phys_shift) - DEVICE_MEM= _BASE)); + exit(1); + } + + return requested_vm_phys_shift; +} + static void virt_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -1772,6 +1808,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->cpu_index_to_instance_props =3D virt_cpu_index_to_props; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a15"); mc->get_default_cpu_node_id =3D virt_get_default_cpu_node_id; + mc->kvm_type =3D virt_kvm_type; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler =3D virt_machine_get_hotplug_handler; hc->plug =3D virt_machine_device_plug_cb; @@ -1878,7 +1915,16 @@ static void virt_3_1_instance_init(Object *obj) =20 static void virt_machine_3_1_options(MachineClass *mc) { + VirtMachineClass *vmc =3D VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); + virt_machine_3_2_options(mc); + + /* + * Device memory and capability to set the max IPA address shift + * are enabled from 3.2 onwards + */ + vmc->no_device_memory =3D true; + mc->kvm_type =3D NULL; } DEFINE_VIRT_MACHINE(3, 1) =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 4cc57a7ef6..f57e4c1890 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -101,6 +101,7 @@ typedef struct { bool claim_edge_triggered_timers; bool smbios_old_sys_ver; bool no_highmem_ecam; + bool no_device_memory; } VirtMachineClass; =20 typedef struct { --=20 2.17.1