From nobody Fri Nov 29 19:46:04 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=1632437383; cv=none; d=zohomail.com; s=zohoarc; b=GOx1LwK6SzqKeeIhmxeWtC56njEhE00i47hHu74nHjOkSD9lfOVFH+FBN15Qkq7XpYQluEcQI6pHBkPKTqQu9MtGbPgsy3aYHFGcFapjaHNA8nrhuG88fO0pTF2K1lmpR3vmSutoLs34CjxMHu3Libc3kPEg1nrbczMOlKyFWYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632437383; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jmLs0mTyD34ofMZzmrSjgVJC5wsYcw101jP+QWhYOH8=; b=JIPl6LbQan5Ygwoe45xXm7uepa09QRiu0jKl9A1EzMlBSzUW4zabzL5CNUr8dmoNK57Zu+FAyOQDh0Jb+/QpoleFOT3WXiOvi1vxZxhKfho5y9vHzah31jkcAILI1BzITdjxi1WsWTR5zx1GgP8Ztq6rUq1pnsZglNPAlm2IEiw= 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 1632437383487351.30766796383875; Thu, 23 Sep 2021 15:49:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.194613.346731 (Exim 4.92) (envelope-from ) id 1mTXWy-0004k8-VS; Thu, 23 Sep 2021 22:49:28 +0000 Received: by outflank-mailman (output) from mailman id 194613.346731; Thu, 23 Sep 2021 22:49:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mTXWy-0004k1-Ru; Thu, 23 Sep 2021 22:49:28 +0000 Received: by outflank-mailman (input) for mailman id 194613; Thu, 23 Sep 2021 22:49:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mTXWx-0003lw-AF for xen-devel@lists.xenproject.org; Thu, 23 Sep 2021 22:49:27 +0000 Received: from mail-lf1-x133.google.com (unknown [2a00:1450:4864:20::133]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 92a87372-4cd6-4740-8d81-20ee3df470ab; Thu, 23 Sep 2021 22:49:13 +0000 (UTC) Received: by mail-lf1-x133.google.com with SMTP id u8so31596482lff.9 for ; Thu, 23 Sep 2021 15:49:13 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id q5sm230091lfd.17.2021.09.23.15.49.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Sep 2021 15:49:12 -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: 92a87372-4cd6-4740-8d81-20ee3df470ab 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=jmLs0mTyD34ofMZzmrSjgVJC5wsYcw101jP+QWhYOH8=; b=YyI9IJzQrby7TiZ4wbGnS276SPS/+3GW73X0VIaNNHyW0IINUfUfR5fdfPdHIYmHdE Pi1iKR/eM0K2mVgfUSNNDCQXXcQcemn1EGUgCQbA2+G0SM2Yh6fGCKtDPg8QPZMjssJZ 6EgKVxXgFrfoDP4stA4bjDId3/fGB4+Yqa+sDnfnP4i2NStC9oKG+L7jmp9aMUXO2JrL vkfI/J/op5MBTn0YKUCA5T01hfmRQae8Zr2+81vM4OoQjOyV7yEqStWkVhgq1IbpONcN q4mVERIpB0tSQR0YIYHS20mvae5ao7uElHuKIelHhPUrzUsTr7IjrAr7C58yvUt6eGyb Dtig== 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=jmLs0mTyD34ofMZzmrSjgVJC5wsYcw101jP+QWhYOH8=; b=rvsnhC2gef0mO0lJmXVQ+e/Y/CExtykuMg6zH38So+7xZNkQwTAAP55a1HZBbvpMIk UVkyvvBaRMeTQOg+Dd5tuT7qBM2GQxZyrE3RrthnokmT7c3vO+/9ogJswIuu3D3q1VTt qLkYcvcbns9E+K925kQ/A72XsNMN7Xi7nPtVk2BYX1JxMODNytNmiPCFhsr6l2tSrOQS t4kyw0g/vROfKljqVdJ+4j5dnsHj6JjxB1f5KPaKNotoMPeBRZSQK10jgViwotz7dubi Kc1ikg7+hoRx6lyz8sX2qY5jGtDvBfkYlzIDVI5tPGVMb8cLKebPp1Yh/1J9UWjeMhlc d6Kg== X-Gm-Message-State: AOAM530BHfAtvojUnPDrFqXmN6/0rGVIOBMdhLlhjIaXbtOXNzZ+bMej CFdxGRU+tjDVPfyijWMPFonmka4pOyU= X-Google-Smtp-Source: ABdhPJzJ4gywKT2GPnBQZNU6Z/TJttX8q3HxdBvVA2xr556u3bBX1MO96LSCIMBzAnreZJrKPrii7A== X-Received: by 2002:ac2:5fe7:: with SMTP id s7mr6504634lfg.666.1632437352352; Thu, 23 Sep 2021 15:49:12 -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 V3 3/3] libxl/arm: Add handling of extended regions for DomU Date: Fri, 24 Sep 2021 01:48:54 +0300 Message-Id: <1632437334-12015-4-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1632437334-12015-1-git-send-email-olekstysh@gmail.com> References: <1632437334-12015-1-git-send-email-olekstysh@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1632437385590100003 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. As we have a lot of unused space above 4GB, provide single 2MB-aligned region from the second RAM bank taking into the account the maximum supported guest address space size and the amount of memory assigned to the guest. The maximum size of the region is 128GB. The minimum size is 64MB. Suggested-by: Julien Grall Signed-off-by: Oleksandr Tyshchenko Acked-by: Ian Jackson Reviewed-by: Michal Orzel Reviewed-by: Stefano Stabellini Tested-by: Michal Orzel --- 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 --- tools/libs/light/libxl_arm.c | 70 +++++++++++++++++++++++++++++++++++++++= ---- xen/include/public/arch-arm.h | 3 ++ 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index e3140a6..a67b68e 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -598,9 +598,17 @@ 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 =3D 0, region_base, ramsize, bank1size, + bank1end_align, bank1end_max; + uint8_t gpaddr_bits; + libxl_physinfo physinfo; int res; gic_interrupt intr; =20 @@ -615,9 +623,61 @@ 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(DEBUG, "The extended regions are only supported for 64-bit gue= st currently"); + goto out; + } + + res =3D libxl_get_physinfo(CTX, &physinfo); + assert(!res); + + gpaddr_bits =3D physinfo.gpaddr_bits; + assert(gpaddr_bits >=3D 32 && gpaddr_bits <=3D 48); + + /* + * Try to allocate single 2MB-aligned extended region from the second = RAM + * bank (above 4GB) taking into the account the maximum supported guest + * address space size and the amount of memory assigned to the guest. + * As the guest memory layout is not populated yet we cannot rely on + * dom->rambank_size[1], so calculate the actual size of the second ba= nk + * using "max_memkb" value. + */ + bank1end_max =3D min(1ULL << gpaddr_bits, GUEST_RAM1_BASE + GUEST_RAM1= _SIZE); + ramsize =3D b_info->max_memkb * 1024; + if (ramsize <=3D GUEST_RAM0_SIZE) + bank1size =3D 0; + else + bank1size =3D ramsize - GUEST_RAM0_SIZE; + bank1end_align =3D GUEST_RAM1_BASE + ALIGN_UP_TO_2MB(bank1size); + + if (bank1end_max <=3D bank1end_align) { + LOG(WARN, "The extended region cannot be allocated, not enough spa= ce"); + goto out; + } + + if (bank1end_max - bank1end_align > GUEST_EXT_REGION_MAX_SIZE) { + region_base =3D bank1end_max - GUEST_EXT_REGION_MAX_SIZE; + region_size =3D GUEST_EXT_REGION_MAX_SIZE; + } else { + region_base =3D bank1end_align; + region_size =3D bank1end_max - bank1end_align; + } + +out: + /* + * The region 0 for grant table space must be always present. If we ma= naged + * to allocate the extended region then insert it as region 1. + */ + if (region_size >=3D GUEST_EXT_REGION_MIN_SIZE) { + LOG(DEBUG, "Extended region: %#"PRIx64"->%#"PRIx64"\n", + region_base, region_base + region_size); + + res =3D fdt_property_regs(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, GUEST= _ROOT_SIZE_CELLS, + 2, GUEST_GNTTAB_BASE, GUEST_GNTTAB_SIZE, + region_base, region_size); + } else + res =3D fdt_property_regs(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, GUEST= _ROOT_SIZE_CELLS, + 1, GUEST_GNTTAB_BASE, GUEST_GNTTAB_SIZE); if (res) return res; =20 /* @@ -963,7 +1023,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 6b5a5f8..df59933 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -449,6 +449,9 @@ 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_MAX_SIZE xen_mk_ullong(0x2000000000) /* 128GB */ +#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