From nobody Tue May 7 21:11:52 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=1633974571; cv=none; d=zohomail.com; s=zohoarc; b=WB0AZXy+Tr2a3s3KwFzzFKdR0xb9IgZrnzBFDWE2RKat5FvhlkaK+FXGbiNPslkcrCFM1me7wgqwTtIZHzZDFFh0JX2lr/c2e6EKcNn6aejzjUVV4eodpi5cVFuNEhZcbfZa6ORwjrpMtXjIj9+87x8HcM49GlrkKzm2Q4aSLqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633974571; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=L+Vz4g8mPdTUD6U0yWxfJ59oXSdq+i7jG1ZWATUEews=; b=OXYU2n3AHwfttkrAtMPKpAVyj7hX1uuAjoUFVqEdBWopjjFOQiQF0mk7KsI4tfH/7nZ+8BNFvTR0OuvmkQUkywo8SPTrcF6IeIpPF3LEA3aqyp81RID/o7k6nDQt61LQWZRWinbqEdR+OATPSddfgF6qqPL0Fmw910/msw+Mg8U= 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 1633974571236310.03701216447644; Mon, 11 Oct 2021 10:49:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.206421.361995 (Exim 4.92) (envelope-from ) id 1mZzQJ-0002Co-O5; Mon, 11 Oct 2021 17:49:15 +0000 Received: by outflank-mailman (output) from mailman id 206421.361995; Mon, 11 Oct 2021 17:49:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzQJ-0002Ch-Kv; Mon, 11 Oct 2021 17:49:15 +0000 Received: by outflank-mailman (input) for mailman id 206421; Mon, 11 Oct 2021 17:49:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzQI-0001vo-Gw for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 17:49:14 +0000 Received: from mail-lf1-x129.google.com (unknown [2a00:1450:4864:20::129]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4eb6c7fa-a285-46ca-b287-31a54aa77a6d; Mon, 11 Oct 2021 17:49:09 +0000 (UTC) Received: by mail-lf1-x129.google.com with SMTP id j5so77000175lfg.8 for ; Mon, 11 Oct 2021 10:49:08 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id h4sm789688lfk.193.2021.10.11.10.49.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Oct 2021 10:49:07 -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: 4eb6c7fa-a285-46ca-b287-31a54aa77a6d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L+Vz4g8mPdTUD6U0yWxfJ59oXSdq+i7jG1ZWATUEews=; b=Kikq9z9xIVPwRfqXxyfjVyqc7Z/XIn+fsI9o3ya2bgHJl+aduFHx8oj8ZIOXMtuq3z cI0tb0EN1WIR3eB+ppRpjsJWhLpIipX6k/EzYutfv2+bOVaebXnXFZvhKcubshAF5lNK 7LFRf8Pa3l7lohNLmMR6vJQoKFkjCNHmBau2oKYQkuGx0KreHzxbbEg1MDp7xgnWa9eE DNAl9ALaMckrA5NRn0rgCk+cywQgBdkU2Q4NJsnN4RSt5vTILejnFunPYHvViOp9KAgH Ct91bk284aSWgqp8q1efwqwzKO8lna8+wF/NtZQ+xamu0D/U6ALk5r4NHdgi2LrI7tAj Vo5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L+Vz4g8mPdTUD6U0yWxfJ59oXSdq+i7jG1ZWATUEews=; b=GedLVwo0Q03iRk+gGQX0hutjDhQ02aHt34MSK+f7Zw6mbLhk02L+jag0sfdcpKb/nd zZfin2LG4WizmhNgwE7XZG/rF7BGxtd6KpuS5+FK9pya5mo61tutztj5+iKUVKCQUR7R Aiu3kE9bpVPqpGDyMqBe89hSZW/x9ViF3t2mMObJFSWhQIQ0hDDD2mbfysSa+yk5Sz0b pqMw+vfkHwvg/PeTMniDSU5oD7l15EZThze1PRh37aP+tNuSetWqjshTwU4nMjRXdCn+ 2Ggm48rdGJwhH3kJkemP0LwDwRQ9ngZiH0nj3oIsjxaFXObUJ7k13Vm/olcl9bVKruSW C3qg== X-Gm-Message-State: AOAM530eWKmKC4ti+6zcjYkuGs0Jp4o6MJC0u2y1kT8h+nqYAWL3cr/z tzQoba3Dpoio2OnXFJ+i2WM4M3D58p0= X-Google-Smtp-Source: ABdhPJwJtJrvRFK/aU40SBxwZDoY17MYen4S/0b4K+26XC1I82rmcqf7XK7YSqcAmQ/PvF2x4MYGRg== X-Received: by 2002:a05:6512:22c2:: with SMTP id g2mr28212682lfu.577.1633974547815; Mon, 11 Oct 2021 10:49:07 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Ian Jackson , Wei Liu , Anthony PERARD , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Juergen Gross , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH V6 1/2] xen/arm: Introduce gpaddr_bits field to struct xen_domctl_getdomaininfo Date: Mon, 11 Oct 2021 20:48:58 +0300 Message-Id: <1633974539-7380-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1633974539-7380-1-git-send-email-olekstysh@gmail.com> References: <1633974539-7380-1-git-send-email-olekstysh@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1633974572174100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko We need to pass info about maximum supported guest physical address space size to the toolstack on Arm in order to properly calculate the base and size of the extended region (safe range) for the guest. The extended region is unused address space which could be safely used by domain for foreign/grant mappings on Arm. The extended region itself will be handled by the subsequent patch. Currently the same guest physical address space size is used for all guests (p2m_ipa_bits variable on Arm, the x86 equivalent is hap_paddr_bits). As we add new field to the structure bump the interface version. Suggested-by: Julien Grall Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Ian Jackson --- Changes RFC -> V2: - update patch subject/description - replace arch-specific sub-struct with common gpaddr_bits field and update code to reflect that Changes V2 -> V3: - make the field uint8_t and add uint8_t pad[7] after - remove leading blanks in libxl.h Changes V3 -> V4: - also print gpaddr_bits from output_physinfo() - add Michal's R-b Changes V4 -> V5: - update patch subject and description - drop Michal's R-b - pass gpaddr_bits via createdomain domctl (struct xen_arch_domainconfig) Changes V5 -> V6: - update patch subject and description - pass gpaddr_bits via getdomaininfo domctl (struct xen_domctl_getdomaininfo) --- tools/include/libxl.h | 8 ++++++++ tools/include/xenctrl.h | 1 + tools/libs/ctrl/xc_domain.c | 1 + tools/libs/light/libxl_domain.c | 1 + tools/libs/light/libxl_types.idl | 1 + xen/arch/arm/domctl.c | 2 ++ xen/arch/x86/domctl.c | 1 + xen/include/public/domctl.h | 3 ++- 8 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index b9ba16d..deb5022 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -874,6 +874,14 @@ typedef struct libxl__ctx libxl_ctx; #define LIBXL_HAVE_DOMINFO_NEVER_STOP 1 =20 /* + * LIBXL_HAVE_DOMINFO_GPADDR_BITS + * + * If this is defined, libxl_dominfo will contain an uint8 field called + * gpaddr_bits, containing the guest physical address space size. + */ +#define LIBXL_HAVE_DOMINFO_GPADDR_BITS 1 + +/* * LIBXL_HAVE_QXL * * If defined, then the libxl_vga_interface_type will contain another valu= e: diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index a306399..07b96e6 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -462,6 +462,7 @@ typedef struct xc_dominfo { unsigned int max_vcpu_id; xen_domain_handle_t handle; unsigned int cpupool; + uint8_t gpaddr_bits; struct xen_arch_domainconfig arch_config; } xc_dominfo_t; =20 diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 23322b7..b155d6a 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -396,6 +396,7 @@ int xc_domain_getinfo(xc_interface *xch, info->nr_online_vcpus =3D domctl.u.getdomaininfo.nr_online_vcpus; info->max_vcpu_id =3D domctl.u.getdomaininfo.max_vcpu_id; info->cpupool =3D domctl.u.getdomaininfo.cpupool; + info->gpaddr_bits =3D domctl.u.getdomaininfo.gpaddr_bits; info->arch_config =3D domctl.u.getdomaininfo.arch_config; =20 memcpy(info->handle, domctl.u.getdomaininfo.handle, diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 51a6127..544a9bf 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -306,6 +306,7 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx, xlinfo->vcpu_max_id =3D xcinfo->max_vcpu_id; xlinfo->vcpu_online =3D xcinfo->nr_online_vcpus; xlinfo->cpupool =3D xcinfo->cpupool; + xlinfo->gpaddr_bits =3D xcinfo->gpaddr_bits; xlinfo->domain_type =3D (xcinfo->flags & XEN_DOMINF_hvm_guest) ? LIBXL_DOMAIN_TYPE_HVM : LIBXL_DOMAIN_TYPE_PV; } diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 3f9fff6..2df7258 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -357,6 +357,7 @@ libxl_dominfo =3D Struct("dominfo",[ ("vcpu_max_id", uint32), ("vcpu_online", uint32), ("cpupool", uint32), + ("gpaddr_bits", uint8), ("domain_type", libxl_domain_type), ], dir=3DDIR_OUT) =20 diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index b7d27f3..6245af6 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -20,6 +20,8 @@ void arch_get_domain_info(const struct domain *d, { /* All ARM domains use hardware assisted paging. */ info->flags |=3D XEN_DOMINF_hap; + + info->gpaddr_bits =3D p2m_ipa_bits; } =20 static int handle_vuart_init(struct domain *d,=20 diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 26a76d2..7d102e0 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -151,6 +151,7 @@ void arch_get_domain_info(const struct domain *d, info->flags |=3D XEN_DOMINF_hap; =20 info->arch_config.emulation_flags =3D d->arch.emulation_flags; + info->gpaddr_bits =3D hap_paddr_bits; } =20 static int do_vmtrace_op(struct domain *d, struct xen_domctl_vmtrace_op *o= p, diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 4cb3f66..b93f776 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -38,7 +38,7 @@ #include "hvm/save.h" #include "memory.h" =20 -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000014 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000015 =20 /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. @@ -150,6 +150,7 @@ struct xen_domctl_getdomaininfo { uint32_t ssidref; xen_domain_handle_t handle; uint32_t cpupool; + uint8_t gpaddr_bits; /* Guest physical address space size. */ struct xen_arch_domainconfig arch_config; }; typedef struct xen_domctl_getdomaininfo xen_domctl_getdomaininfo_t; --=20 2.7.4 From nobody Tue May 7 21:11:52 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=1633974574; cv=none; d=zohomail.com; s=zohoarc; b=CEgSChneJ7zTveL6AD/0UjF4+jCvZ1kwgR8zlNI9KCx5awUD4Ed9WvvxxnCGvYZH7FLRB2qrh6ngv7wA5SFGypguZnAaF3NHFn+Ugu3oJ1oTVLp8VnWZOCwQhQglqv3tL5jsjZTJ56kW+w+9Q5iPpxUc6cBK7tDn1n5ssTufMUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633974574; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=wPDJEBVjrNdWVk2UD/ygEhxoYGrfSVfG9OQX/DRhwzc=; b=WIajQaWGEOl+1HszCZY1Eoj8vdDYSGTs0ccaRvM/63CMAHNWwgib/yRHeTj/pMHUBSWR0myyq1Z3x7dhy91lvhd5dyV4lI9qHyTOYuCv/heY/xI/8PIpGnIQThHw3eIAScKr9fhw6o9FQN0MfWR5Fc+LviVVIuWg4sk3gW814Xg= 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 1633974574848191.40182838926103; Mon, 11 Oct 2021 10:49:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.206422.362006 (Exim 4.92) (envelope-from ) id 1mZzQP-0002X4-3k; Mon, 11 Oct 2021 17:49:21 +0000 Received: by outflank-mailman (output) from mailman id 206422.362006; Mon, 11 Oct 2021 17:49:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzQO-0002Wt-V4; Mon, 11 Oct 2021 17:49:20 +0000 Received: by outflank-mailman (input) for mailman id 206422; Mon, 11 Oct 2021 17:49:19 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mZzQN-0001vo-HC for xen-devel@lists.xenproject.org; Mon, 11 Oct 2021 17:49:19 +0000 Received: from mail-lf1-x12e.google.com (unknown [2a00:1450:4864:20::12e]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 01670e9f-3c57-4828-971e-693757756b4d; Mon, 11 Oct 2021 17:49:09 +0000 (UTC) Received: by mail-lf1-x12e.google.com with SMTP id j5so77000296lfg.8 for ; Mon, 11 Oct 2021 10:49:09 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id h4sm789688lfk.193.2021.10.11.10.49.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Oct 2021 10:49:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 01670e9f-3c57-4828-971e-693757756b4d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wPDJEBVjrNdWVk2UD/ygEhxoYGrfSVfG9OQX/DRhwzc=; b=pHHlYvOZkJ0uIrrNuzHHPoUGuU4IdpYiw1zasAJOc1E5//KkqpCYk1wxHrtX90cd3I fW3bbb9Dj2+p65woTp9IMZVi6lPOgSXp42LMd5g1SK52SAOJOwzea135o57WGnQP52by t6dlFWpQXlNwDIKQqfEM3V8fVSHmYM4dWVGkAajEZZf/UcF+X6A0vJssxbJeb0o7EZA2 IR1/EDstn00xSZUOGJTWOooPpd6CFiXJMfyFbsgPcSyBMZ+sM7TDEzyyx1AvawVqsEXH CA63l8CNpFaQ6bpYjBC3CP8uwdz2HJEUzPvXFT2Q8rWywdPxbQOY8kmPK+m1Y03WqG4x zNGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wPDJEBVjrNdWVk2UD/ygEhxoYGrfSVfG9OQX/DRhwzc=; b=6w60YELR5zLqk65Ab//kMW9noMeMw9HmkKbnrJB9Q8MD26fPdkWbqYt5nnSFiFs8Nf tA+JjCxJRNJHX6RlAgnmiQfq+Qk+S1e4nGxs445V1QoQNv7rpueOsZ1sVwAdHgyEaMQ/ rMSvrJnKQhdJYIUHy+aEQLMHwdQ5q9zlTYCHTt5icv0dO2jHkxmWJOB2poix2MvAwXes /jl0h/M54yZSSpyWo9zD+eTLkUg7t/ahZSZyRUGcRsyqlxVhVaIEAywaHaTzVQ31JwB0 L1i8W8kdL6buN59iRbv0bW5rlvJ1EOfLH12d+d1Dol7Ii3JOXjrn60QULu+9XD1OhuvT n04A== X-Gm-Message-State: AOAM5329VrdmnftuislXAsqZzKTBaF2sR/g98fm3BNC6J7XmJ5ECeXRj 6abWwbmzC0eovY+RUGmi+DhKkwNgEx8= X-Google-Smtp-Source: ABdhPJxCU5LhyJgoC5HOhFrjkKgfAyX+hjJ+nlEL7yWGHE2IdVB9mtvQwiBNJyKMKCGIniL4w/rBug== X-Received: by 2002:a2e:1301:: with SMTP id 1mr1748772ljt.479.1633974548611; Mon, 11 Oct 2021 10:49:08 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH V6 2/2] libxl/arm: Add handling of extended regions for DomU Date: Mon, 11 Oct 2021 20:48:59 +0300 Message-Id: <1633974539-7380-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1633974539-7380-1-git-send-email-olekstysh@gmail.com> References: <1633974539-7380-1-git-send-email-olekstysh@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1633974576041100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko The extended region (safe range) is a region of guest physical address space which is unused and could be safely used to create grant/foreign mappings instead of wasting real RAM pages from the domain memory for establishing these mappings. The extended regions are chosen at the domain creation time and advertised to it via "reg" property under hypervisor node in the guest device-tree. As region 0 is reserved for grant table space (always present), the indexes for extended regions are 1...N. If extended regions could not be allocated for some reason, Xen doesn't fail and behaves as usual, so only inserts region 0. Please note the following limitations: - The extended region feature is only supported for 64-bit domain currently. - The ACPI case is not covered. *** The algorithm to choose extended regions for non-direct mapped DomU is simpler in comparison with the algorithm for direct mapped Dom0. We usually have a lot of unused space above 4GB, and might have some unused space below 4GB (depends on guest memory size). Try to allocate separate 2MB-aligned extended regions from the first (below 4GB) and second (above 4GB) RAM banks taking into the account the maximum supported guest physical address space size and the amount of memory assigned to the guest. The minimum size of extended region the same as for Dom0 (64MB). Suggested-by: Julien Grall Signed-off-by: Oleksandr Tyshchenko Acked-by: Ian Jackson Reviewed-by: Stefano Stabellini --- Changes RFC -> V2: - update patch description - drop uneeded "extended-region" DT property - clear reg array in finalise_ext_region() and add a TODO Changes V2 -> V3: - update patch description, comments in code - only pick up regions with size >=3D 64MB - move the region calculation to make_hypervisor_node() and drop finalise_ext_region() - extend the list of arguments for make_hypervisor_node() - do not show warning for 32-bit domain - change the region alignment from 1GB to 2MB - move EXT_REGION_SIZE to public/arch-arm.h Changes V3 -> V4: - add R-b, A-b and T-b Changes V4 -> V5: - update patch description and comments in code - reflect changes done in previous patch to pass gpaddr_bits via createdomain domctl (struct xen_arch_domainconfig) - drop R-b, A-b and T-b - drop limit for maximum extended region size (128GB) - try to also allocate region below 4GB, optimize code for calculating extended regions Change V5 -> V6: - reflect changes done in previous patch to pass gpaddr_bits via getdomaininfo domctl (struct xen_domctl_getdomaininfo) - reduce the number of local variables, rework calculations --- tools/libs/light/libxl_arm.c | 76 +++++++++++++++++++++++++++++++++++++++= +--- xen/include/public/arch-arm.h | 2 ++ 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index e3140a6..c0e8415 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -598,9 +598,20 @@ static int make_timer_node(libxl__gc *gc, void *fdt, return 0; } =20 +#define ALIGN_UP_TO_2MB(x) (((x) + MB(2) - 1) & (~(MB(2) - 1))) + static int make_hypervisor_node(libxl__gc *gc, void *fdt, - const libxl_version_info *vers) + const libxl_version_info *vers, + const libxl_domain_build_info *b_info, + const struct xc_dom_image *dom) { + uint64_t region_size[GUEST_RAM_BANKS] =3D {0}, region_base[GUEST_RAM_B= ANKS], + bank1end, ramsize; + uint32_t regs[(GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_CELLS) * + (GUEST_RAM_BANKS + 1)]; + be32 *cells =3D ®s[0]; + unsigned int i, len, nr_regions =3D 0; + libxl_dominfo info; int res; gic_interrupt intr; =20 @@ -615,9 +626,64 @@ static int make_hypervisor_node(libxl__gc *gc, void *f= dt, "xen,xen"); if (res) return res; =20 - /* reg 0 is grant table space */ - res =3D fdt_property_regs(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROO= T_SIZE_CELLS, - 1,GUEST_GNTTAB_BASE, GUEST_GNTTAB_SIZE); + if (strcmp(dom->guest_type, "xen-3.0-aarch64")) { + LOG(WARN, "The extended regions are only supported for 64-bit gues= t currently"); + goto out; + } + + res =3D libxl_domain_info(CTX, &info, dom->guest_domid); + if (res) return res; + + assert(info.gpaddr_bits >=3D 32 && info.gpaddr_bits <=3D 48); + + /* + * Try to allocate separate 2MB-aligned extended regions from the first + * (below 4GB) and second (above 4GB) RAM banks taking into the account + * the maximum supported guest physical address space size and the amo= unt + * of memory assigned to the guest. + * As the guest memory layout is not populated yet we cannot rely on + * dom->rambank_size[], so calculate the actual size of both banks usi= ng + * "max_memkb" value. + */ + ramsize =3D b_info->max_memkb * 1024; + if (ramsize <=3D GUEST_RAM0_SIZE) { + region_base[0] =3D GUEST_RAM0_BASE + ALIGN_UP_TO_2MB(ramsize); + region_size[0] =3D GUEST_RAM0_SIZE - ALIGN_UP_TO_2MB(ramsize); + region_base[1] =3D GUEST_RAM1_BASE; + } else + region_base[1] =3D GUEST_RAM1_BASE + + ALIGN_UP_TO_2MB(ramsize - GUEST_RAM0_SIZE); + + bank1end =3D min(1ULL << info.gpaddr_bits, GUEST_RAM1_BASE + GUEST_RAM= 1_SIZE); + if (bank1end > region_base[1]) + region_size[1] =3D bank1end - region_base[1]; + +out: + /* + * The region 0 for grant table space must be always present. If we ma= naged + * to allocate the extended regions then insert them as regions 1...N. + */ + set_range(&cells, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS, + GUEST_GNTTAB_BASE, GUEST_GNTTAB_SIZE); + + for (i =3D 0; i < GUEST_RAM_BANKS; i++) { + if (region_size[i] < GUEST_EXT_REGION_MIN_SIZE) + continue; + + LOG(DEBUG, "Extended region %u: %#"PRIx64"->%#"PRIx64"\n", + nr_regions, region_base[i], region_base[i] + region_size[i]); + + set_range(&cells, GUEST_ROOT_ADDRESS_CELLS, GUEST_ROOT_SIZE_CELLS, + region_base[i], region_size[i]); + nr_regions++; + } + + if (!nr_regions) + LOG(WARN, "The extended regions cannot be allocated, not enough sp= ace"); + + len =3D sizeof(regs[0]) * (GUEST_ROOT_ADDRESS_CELLS + GUEST_ROOT_SIZE_= CELLS) * + (nr_regions + 1); + res =3D fdt_property(fdt, "reg", regs, len); if (res) return res; =20 /* @@ -963,7 +1029,7 @@ next_resize: } =20 FDT( make_timer_node(gc, fdt, ainfo, state->clock_frequency) ); - FDT( make_hypervisor_node(gc, fdt, vers) ); + FDT( make_hypervisor_node(gc, fdt, vers, info, dom) ); =20 if (info->arch_arm.vuart =3D=3D LIBXL_VUART_TYPE_SBSA_UART) FDT( make_vpl011_uart_node(gc, fdt, ainfo, dom) ); diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index d46c61f..19ca2b0 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -451,6 +451,8 @@ typedef uint64_t xen_callback_t; #define GUEST_RAM_BANK_BASES { GUEST_RAM0_BASE, GUEST_RAM1_BASE } #define GUEST_RAM_BANK_SIZES { GUEST_RAM0_SIZE, GUEST_RAM1_SIZE } =20 +#define GUEST_EXT_REGION_MIN_SIZE xen_mk_ullong(0x0004000000) /* 64MB */ + /* Current supported guest VCPUs */ #define GUEST_MAX_VCPUS 128 =20 --=20 2.7.4