From patchwork Fri Sep 13 15:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 828187 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp300481wra; Fri, 13 Sep 2024 08:18:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUHjs7eDHvz0iBrX+xC1Dn05i9C7OsOncpfbOQQUbdSR3gQfYrPCQa5jezsOkVY95+PlK71WQ==@linaro.org X-Google-Smtp-Source: AGHT+IGCYWeBtWMujT9Xax/rvi/HwlzC815R1DuwMz8OcRCFzaxj0v/gVVcilMoaPUqc1PMkhFVz X-Received: by 2002:a05:620a:1706:b0:7a9:a356:a5f4 with SMTP id af79cd13be357-7a9e5fa7060mr1015486485a.42.1726240694400; Fri, 13 Sep 2024 08:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726240694; cv=none; d=google.com; s=arc-20240605; b=EB2cam3AsIqcun+Ut93euey1fgpM8lF7CcWMTO+oU1O9BVnIVvgla/TFSc44Ynufw1 EbxONCztZVGZeN0aeAIk0cFf90qDkY3qGHVz6nkIVu9vw52KbW36lXZMWfEAKTZLxWTq U/sC2b51QK2fhLkAXeqznObrBseYC6JKjN0u7/GOMx+z3FJDCdl/AEcEjHlc0C9SurL0 5SoGlmUgygIcLEC4MnwDZj/13dsLxhnWtEQGF30H1aISY50PWBXnQAlud9LHYWlDgXW4 TWHqQOlKEM6cgcGESHWIolsY7dTXILlekSGSucSS8LjY3a1jR/pHRwsH+zO2frQDTIUs Th1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=B84tOEz4iH8LzYCOElAIMYy1A32McFCI6tkMUnYQHUs=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=gVTd+sNzVABCZo9g9YsRtlDciBhs9AbmTLfkOq4tjXjFhxPFA6ZQ+tKNQA82FOwE5J 2Wp6qIRSOmd/BQDcrkGVlMQJGgkT4vz/snLbWoWYmsRvfwH7aj/Vh1/aXty5Oai94jtY lekUvePSzqzCeDF7WBZ/l+pTc+gfjKTYTVY5nD7U/uHHN4c/n7IzyqBLDKEkh0mt5cpY 71HG0gL6jmdBIXw00GMaJG5KfmCJNn161W+fNZvjzLQZoSnPmbhOXFhsNS1RBogxoVMc 2iQsAEcPT6CHX218qoSsVSZuR4BxEVr4qXEJ665SynF8wn1BrcNR2m89P3GOacns13MU zC3Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CKy+JZUh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a9a7a359basi1584828085a.266.2024.09.13.08.18.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 08:18:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CKy+JZUh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp80b-0003W6-I1; Fri, 13 Sep 2024 11:14:53 -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 1sp807-0001zm-Ho for qemu-devel@nongnu.org; Fri, 13 Sep 2024 11:14:24 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp805-0007n0-Er for qemu-devel@nongnu.org; Fri, 13 Sep 2024 11:14:22 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-42cba6cdf32so20056285e9.1 for ; Fri, 13 Sep 2024 08:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726240460; x=1726845260; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=B84tOEz4iH8LzYCOElAIMYy1A32McFCI6tkMUnYQHUs=; b=CKy+JZUhmxtRlXHTpGSy8oO67eNKil+lS5mKBg1JGkmsVmgmL5j67h+3SirnGDgf/E w6FeJ4ctPFLm+taWCO4qvNwhgMYTZAjrW3N2FQQb6LSWUQgUmhXKdX9ch3+Sz5jyjimP zykRIaY0v6/iDW9vZmwdCM7fonybaOkeq8fXkd6UFnbBi1jm5UClgVgCUL9XE/wBhDmA 5oqiZ0KbIOlFXz4LAYKRU3/BLbXqgA0XWNh+IAmqHkjYVdXMHjgTN/YUgQSqh523NYTU QdRIr4wEkptamXs6WpYOsJ7yEShUWmgsCmgfCLpa4z9fgrru8FDseOVQrvEQL2LLoWR8 xb0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726240460; x=1726845260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B84tOEz4iH8LzYCOElAIMYy1A32McFCI6tkMUnYQHUs=; b=OjknKdbm79uUge+01tVsu95a3QvXU3HmWPSS3Mz7zKK0s47gPYOoxcTSxH9/uYf8GL 4eMNGCYpDzM/iPFXttYOrJTj55s6wUGXEL1WkWJUYsWarLH3vg3AlOGLPed/r1xwptVY C+XbTphlUaoDhH5q6Bcmdjmem6sQktTS1zEDyf/jPJVjS6sJWE7i5xaCrWQfUWangkrK tpHIJ9gDVOwa6KlQacBIrdeehawf4MiI5dK4726QZExGyo0yyhiazoH3BJPibU7tVp7I +kLXSkne2c8PK7yREfhECKpeuiynMkufXWT1QUAST2OfiiHGfXsmPLFXeeqxvL6NlUka 1DBw== X-Gm-Message-State: AOJu0YwojZmZ4lmQRvqB3xGbLWlucMkL0Gdc2UC89hbrx1aHTjG5DRCX oFgKKV9w5Zmi+5KpuOJhQdNxv2BcQHle04sHa9RH9JCxfh09ckC4rPOzkoX52AsNsLCaAYzVtyz K X-Received: by 2002:a05:600c:1d1c:b0:42c:b22e:fc3e with SMTP id 5b1f17b1804b1-42cdb54c2f3mr57650205e9.15.1726240459821; Fri, 13 Sep 2024 08:14:19 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42d9b16bfbfsm29152325e9.22.2024.09.13.08.14.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 08:14:19 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 13/27] hw/boards: Add hvf_get_physical_address_range to MachineClass Date: Fri, 13 Sep 2024 16:13:57 +0100 Message-Id: <20240913151411.2167922-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240913151411.2167922-1-peter.maydell@linaro.org> References: <20240913151411.2167922-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Danny Canter This addition will be necessary for some HVF related work to follow. For HVF on ARM there exists a set of APIs in macOS 13 to be able to adjust the IPA size for a given VM. This is useful as by default HVF uses 36 bits as the IPA size, so to support guests with > 64GB of RAM we'll need to reach for this. To have all the info necessary to carry this out however, we need some plumbing to be able to grab the memory map and compute the highest GPA prior to creating the VM. This is almost exactly like what kvm_type is used for on ARM today, and is also what this will be used for. We will compute the highest GPA and find what IPA size we'd need to satisfy this, and if it's valid (macOS today caps at 40b) we'll set this to be the IPA size in coming patches. This new method is only needed (today at least) on ARM, and obviously only for HVF/macOS, so admittedly it is much less generic than kvm_type today, but it seemed a somewhat sane way to get the information we need from the memmap at VM creation time. Signed-off-by: Danny Canter Message-id: 20240828111552.93482-2-danny_canter@apple.com Reviewed-by: Peter Maydell [PMM: removed explicit setting of field to NULL on x86] Signed-off-by: Peter Maydell --- include/hw/boards.h | 5 +++++ hw/arm/virt.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 9a492770cbb..ff25c53671f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -215,6 +215,10 @@ typedef struct { * Return the type of KVM corresponding to the kvm-type string option or * computed based on other criteria such as the host kernel capabilities. * kvm-type may be NULL if it is not needed. + * @hvf_get_physical_address_range: + * Returns the physical address range in bits to use for the HVF virtual + * machine based on the current boards memory map. This may be NULL if it + * is not needed. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise * @hotplug_allowed: @@ -256,6 +260,7 @@ struct MachineClass { void (*reset)(MachineState *state, ShutdownCause reason); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); + int (*hvf_get_physical_address_range)(MachineState *machine); BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7934b236516..d284a602e82 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2111,7 +2111,8 @@ static void machvirt_init(MachineState *machine) /* * In accelerated mode, the memory map is computed earlier in kvm_type() - * to create a VM with the right number of IPA bits. + * for Linux, or hvf_get_physical_address_range() for macOS to create a + * VM with the right number of IPA bits. */ if (!vms->memmap) { Object *cpuobj; @@ -3031,6 +3032,11 @@ static int virt_kvm_type(MachineState *ms, const char *type_str) return fixed_ipa ? 0 : requested_pa_size; } +static int virt_hvf_get_physical_address_range(MachineState *ms) +{ + return 0; +} + static void virt_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -3090,6 +3096,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->valid_cpu_types = valid_cpu_types; mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; mc->kvm_type = virt_kvm_type; + mc->hvf_get_physical_address_range = virt_hvf_get_physical_address_range; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler; hc->pre_plug = virt_machine_device_pre_plug_cb;