From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158795; cv=none; d=zohomail.com; s=zohoarc; b=Q08jnYHykuhOanh0OLI/55uLsn9p7k5vdWR0I5dC8TRjKg+KoHXURqWx9a1dgvp9HQme6GrKyXezdsTrLxRSEPa/UiW3oMe4kqvxbQlC+ZYjVKUQIhIrYQEmf2YPIMQVKYfd0zGB0hbt9OoLF5C2LF+a1Ye8fug0Lt16Exfx40E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158795; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JHLIjqNln10+uaaGPR6Goi/c1sEntGahZG9YudcBl6s=; b=Ge8T8E4apo8pWA6pQAI3OIXwcBeEfVgm1XQKCa/AYBEz+epUhlGnH+PvesH2cDcGDSutZn1WLoYayUSvu2Zbsiq5FXf+rZSwgKJ2iAmBF/f5D37au8Rt+bEd6xTz6qjz4Y8ld1RZdgu/pvStZuUMY4ctRw6lrDlJQUy2X/eKflg= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158795121645.7226726122736; Mon, 2 Dec 2024 08:59:55 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846765.1261936 (Exim 4.92) (envelope-from ) id 1tI9ll-0007hU-0U; Mon, 02 Dec 2024 16:59:33 +0000 Received: by outflank-mailman (output) from mailman id 846765.1261936; Mon, 02 Dec 2024 16:59:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lk-0007gd-Qw; Mon, 02 Dec 2024 16:59:32 +0000 Received: by outflank-mailman (input) for mailman id 846765; Mon, 02 Dec 2024 16:59:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9li-0006x4-G8 for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:30 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c9afe829-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:26 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-aa54adcb894so592012866b.0 for ; Mon, 02 Dec 2024 08:59:26 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:25 -0800 (PST) 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: c9afe829-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158766; x=1733763566; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JHLIjqNln10+uaaGPR6Goi/c1sEntGahZG9YudcBl6s=; b=nwLK0uIrER4O2w3WP0oY9aA1j9aVxBeHF7wX+U50mW8GKkSwnhLUF9/CcZFJKUAkhW +decTTSo8zeUZPu67AmhaW2FSQSkXlHNR/lOIIy/5Y1vkT+QaQyUMqFUBBEDIC3aTgis GJ1qaGEgZKf937QNRWwMLjYfrlh1G9dddrhCm2Ixnpd+qh7euZ0NH3Two/zSEVlbgZHI VtNEnPlou2EFxn7Rc8wJAVkaRgG/XU5otHIS8142m76DyQB38xApwSx5jrSwc96CtxxQ fvU2nAObEGh44EQl2WCwWUPUmOdNkPo5Renizot3XofDJuc74QMhlrif73NsKC3bfnQv iKpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158766; x=1733763566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JHLIjqNln10+uaaGPR6Goi/c1sEntGahZG9YudcBl6s=; b=kS5a/BU/yWmp/i8rCstOtbWFETOgFYWmUSNU59pNj44WiQXnv4R6fUb+fDUIHkkEPn dfvGVC0xHWwPGWjbAREAPMKJRys9qvGsx3OfFFFK8OGqKk+y1NEcsPusAr46QbkUAURM NgrZwtJZNOnVN/iEoMZfWcjCom4BSdhUh4SjqkvaQ7KLXoOsPGZXpMSBjpNtZanA41F/ LkPjBzK9ilpZLfAzIGl2HuWnBxs76vzBeEpSkD4sVEBG8d4WOwEz4JQ7jq1LYjov6kSL K37MKG9a5ea1w33wRTuQDs0Ae0MvVuYmtIEL2t2LFCNDY4KLy5c1f7GQwn2tJ0/Gux9U TIhA== X-Gm-Message-State: AOJu0Yx8iNKXatiNmH+jQTbKcGGV/eJ88v6ej0ncoVPsHd3THRQMx6d3 Cbv75aEuxDR33EXlHV+b+3DGDtqT0tr5hhNpfPs3BoRjDEaiG22421yxla6njJwhpEB5qxRELC3 U X-Gm-Gg: ASbGnctMdZLmtq/z0qiOvNNamVCCO32Ncp2ilj7uvcuJrFDx8wsXj8LJ1Q5JaYZ/2WG /UzhZnF+vBdQn21Okba2Y5RdneP1/lwwPCroI+DkHXiQSJe2HzUksUCJG0ayD15eD7dW25D+ASR KMGzLL62XasLSFvGvY/9SAxrduJoWHIoNXRoz1qi4MprtaYvnuKm1iNX5cRQJfY5QJdTRq3uPdQ 26fmBy01B6IJI5MPR4mX5ZuwuUKDiy+/KPoDj6U/jCcEJi7s9t2DsFMP3/Bzln+Km6FjnOt1rYp CiFeGvcbGbLpeo8CkRqWmQcjfeEpWAWQcRGM0poQZgBSAvB1/hs8 X-Google-Smtp-Source: AGHT+IHq+mPW+7hN/xHplIh/FSA2AJTOopTHeCCqUeuziyhDmQ/ahN1vH+jFcmEE6BKUhmxRRpwA1A== X-Received: by 2002:a17:906:3299:b0:aa5:2237:67af with SMTP id a640c23a62f3a-aa580edf62dmr1878429566b.9.1733158765672; Mon, 02 Dec 2024 08:59:25 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Michal Orzel Subject: [PATCH v11 01/12] xen/common: add cache coloring common code Date: Mon, 2 Dec 2024 17:59:10 +0100 Message-ID: <20241202165921.249585-2-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158797877116600 Content-Type: text/plain; charset="utf-8" Last Level Cache (LLC) coloring allows to partition the cache in smaller chunks called cache colors. Since not all architectures can actually implement it, add a HAS_LLC_COLORI= NG Kconfig option. LLC_COLORS_ORDER Kconfig option has a range maximum of 10 (2^10 =3D 1024) because that's the number of colors that fit in a 4 KiB page when integers are 4 bytes long. LLC colors are a property of the domain, so struct domain has to be extende= d. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Acked-by: Michal Orzel --- v11: - __COLORING_H__ -> __XEN_LLC_COLORING_H__ in llc-coloring.h - added SPDX tag to cache-coloring.rst - llc-coloring=3Doff now takes precedence over other cmdline options - removed useless #includes v10: - fixed commit message to use LLC_COLORS_ORDER - added documentation to index.rst - moved check on CONFIG_NUMA in arch/arm/Kconfig (next patch) - fixed copyright line - fixed array type for colors parameter in print_colors() - added check on (way_size & ~PAGE_MASK) v9: - dropped _MAX_ from CONFIG_MAX_LLC_COLORS_ORDER v8: - minor documentation fixes - "llc-coloring=3Don" is inferred from "llc-nr-ways" and "llc-size" usage - turned CONFIG_NR_LLC_COLORS to CONFIG_MAX_LLC_COLORS_ORDER, base-2 expone= nt - moved Kconfig options to common/Kconfig - don't crash if computed max_nr_colors is too large v7: - SUPPORT.md changes added to this patch - extended documentation to better address applicability of cache coloring - "llc-nr-ways" and "llc-size" params introduced in favor of "llc-way-size" - moved dump_llc_coloring_info() call in 'm' keyhandler (pagealloc_info()) v6: - moved almost all code in common - moved documentation in this patch - reintroduced range for CONFIG_NR_LLC_COLORS - reintroduced some stub functions to reduce the number of checks on llc_coloring_enabled - moved domain_llc_coloring_free() in same patch where allocation happens - turned "d->llc_colors" to pointer-to-const - llc_coloring_init() now returns void and panics if errors are found v5: - used - instead of _ for filenames - removed domain_create_llc_colored() - removed stub functions - coloring domain fields are now #ifdef protected v4: - Kconfig options moved to xen/arch - removed range for CONFIG_NR_LLC_COLORS - added "llc_coloring_enabled" global to later implement the boot-time switch - added domain_create_llc_colored() to be able to pass colors - added is_domain_llc_colored() macro --- SUPPORT.md | 7 ++ docs/index.rst | 1 + docs/misc/cache-coloring.rst | 118 +++++++++++++++++++++++++++++ docs/misc/xen-command-line.pandoc | 37 +++++++++ xen/common/Kconfig | 21 ++++++ xen/common/Makefile | 1 + xen/common/keyhandler.c | 3 + xen/common/llc-coloring.c | 121 ++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 3 + xen/include/xen/llc-coloring.h | 36 +++++++++ xen/include/xen/sched.h | 5 ++ 11 files changed, 353 insertions(+) create mode 100644 docs/misc/cache-coloring.rst create mode 100644 xen/common/llc-coloring.c create mode 100644 xen/include/xen/llc-coloring.h diff --git a/SUPPORT.md b/SUPPORT.md index 82239d0294..998faf5635 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -401,6 +401,13 @@ by maintaining multiple physical to machine (p2m) memo= ry mappings. Status, x86 HVM: Tech Preview Status, ARM: Tech Preview =20 +### Cache coloring + +Allows to reserve Last Level Cache (LLC) partitions for Dom0, DomUs and Xen +itself. + + Status, Arm64: Experimental + ## Resource Management =20 ### CPU Pools diff --git a/docs/index.rst b/docs/index.rst index 1d44796d72..1bb8d02ea3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,6 +66,7 @@ Documents in need of some rearranging. misc/xen-makefiles/makefiles misra/index fusa/index + misc/cache-coloring =20 =20 Miscellanea diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst new file mode 100644 index 0000000000..371f21a0e7 --- /dev/null +++ b/docs/misc/cache-coloring.rst @@ -0,0 +1,118 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +Xen cache coloring user guide +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +The cache coloring support in Xen allows to reserve Last Level Cache (LLC) +partitions for Dom0, DomUs and Xen itself. Currently only ARM64 is support= ed. +Cache coloring realizes per-set cache partitioning in software and is appl= icable +to shared LLCs as implemented in Cortex-A53, Cortex-A72 and similar CPUs. + +To compile LLC coloring support set ``CONFIG_LLC_COLORING=3Dy``. + +If needed, change the maximum number of colors with +``CONFIG_LLC_COLORS_ORDER=3D``. + +Runtime configuration is done via `Command line parameters`_. + +Background +********** + +Cache hierarchy of a modern multi-core CPU typically has first levels dedi= cated +to each core (hence using multiple cache units), while the last level is s= hared +among all of them. Such configuration implies that memory operations on one +core (e.g. running a DomU) are able to generate interference on another co= re +(e.g. hosting another DomU). Cache coloring realizes per-set cache-partiti= oning +in software and mitigates this, guaranteeing more predictable performances= for +memory accesses. +Software-based cache coloring is particularly useful in those situations w= here +no hardware mechanisms (e.g., DSU-based way partitioning) are available to +partition caches. This is the case for e.g., Cortex-A53, A57 and A72 CPUs = that +feature a L2 LLC cache shared among all cores. + +The key concept underlying cache coloring is a fragmentation of the memory +space into a set of sub-spaces called colors that are mapped to disjoint c= ache +partitions. Technically, the whole memory space is first divided into a nu= mber +of subsequent regions. Then each region is in turn divided into a number of +subsequent sub-colors. The generic i-th color is then obtained by all the +i-th sub-colors in each region. + +:: + + Region j Region j+1 + ..................... ............ + . . . + . . + _ _ _______________ _ _____________________ _ _ + | | | | | | | + | c_0 | c_1 | | c_n | c_0 | c_1 | + _ _ _|_____|_____|_ _ _|_____|_____|_____|_ _ _ + : : + : :... ... . + : color 0 + :........................... ... . + : + . . ..................................: + +How colors are actually defined depends on the function that maps memory to +cache lines. In case of physically-indexed, physically-tagged caches with = linear +mapping, the set index is found by extracting some contiguous bits from the +physical address. This allows colors to be defined as shown in figure: they +appear in memory as subsequent blocks of equal size and repeats themselves= after +``n`` different colors, where ``n`` is the total number of colors. + +If some kind of bit shuffling appears in the mapping function, then colors +assume a different layout in memory. Those kind of caches aren't supported= by +the current implementation. + +**Note**: Finding the exact cache mapping function can be a really difficu= lt +task since it's not always documented in the CPU manual. As said Cortex-A5= 3, A57 +and A72 are known to work with the current implementation. + +How to compute the number of colors +################################### + +Given the linear mapping from physical memory to cache lines for granted, = the +number of available colors for a specific platform is computed using three +parameters: + +- the size of the LLC. +- the number of the LLC ways. +- the page size used by Xen. + +The first two parameters can be found in the processor manual, while the t= hird +one is the minimum mapping granularity. Dividing the cache size by the num= ber of +its ways we obtain the size of a way. Dividing this number by the page siz= e, +the number of total cache colors is found. So for example an Arm Cortex-A53 +with a 16-ways associative 1 MiB LLC can isolate up to 16 colors when page= s are +4 KiB in size. + +Effective colors assignment +########################### + +When assigning colors, if one wants to avoid cache interference between two +domains, different colors needs to be used for their memory. + +Command line parameters +*********************** + +Specific documentation is available at `docs/misc/xen-command-line.pandoc`. + ++----------------------+-------------------------------+ +| **Parameter** | **Description** | ++----------------------+-------------------------------+ +| ``llc-coloring`` | Enable coloring at runtime | ++----------------------+-------------------------------+ +| ``llc-size`` | Set the LLC size | ++----------------------+-------------------------------+ +| ``llc-nr-ways`` | Set the LLC number of ways | ++----------------------+-------------------------------+ + +Auto-probing of LLC specs +######################### + +LLC size and number of ways are probed automatically by default. + +LLC specs can be manually set via the above command line parameters. This +bypasses any auto-probing and it's used to overcome failing situations, su= ch as +flawed probing logic, or for debugging/testing purposes. diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 293dbc1a95..abd8dae96f 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1708,6 +1708,43 @@ This option is intended for debugging purposes only.= Enable MSR_DEBUGCTL.LBR in hypervisor context to be able to dump the Last Interrupt/Exception To/F= rom record with other registers. =20 +### llc-coloring (arm64) +> `=3D ` + +> Default: `false` + +Flag to enable or disable LLC coloring support at runtime. This option is +available only when `CONFIG_LLC_COLORING` is enabled. See the general +cache coloring documentation for more info. + +### llc-nr-ways (arm64) +> `=3D ` + +> Default: `Obtained from hardware` + +Specify the number of ways of the Last Level Cache. This option is availab= le +only when `CONFIG_LLC_COLORING` is enabled. LLC size and number of ways ar= e used +to find the number of supported cache colors. By default the value is +automatically computed by probing the hardware, but in case of specific ne= eds, +it can be manually set. Those include failing probing and debugging/testing +purposes so that it's possible to emulate platforms with different number = of +supported colors. If set, also "llc-size" must be set, otherwise the defau= lt +will be used. Note that using both options implies "llc-coloring=3Don". + +### llc-size (arm64) +> `=3D ` + +> Default: `Obtained from hardware` + +Specify the size of the Last Level Cache. This option is available only wh= en +`CONFIG_LLC_COLORING` is enabled. LLC size and number of ways are used to = find +the number of supported cache colors. By default the value is automatically +computed by probing the hardware, but in case of specific needs, it can be +manually set. Those include failing probing and debugging/testing purposes= so +that it's possible to emulate platforms with different number of supported +colors. If set, also "llc-nr-ways" must be set, otherwise the default will= be +used. Note that using both options implies "llc-coloring=3Don". + ### lock-depth-size > `=3D ` =20 diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 90268d9249..b4ec6893be 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -71,6 +71,9 @@ config HAS_IOPORTS config HAS_KEXEC bool =20 +config HAS_LLC_COLORING + bool + config HAS_PIRQ bool =20 @@ -516,4 +519,22 @@ config TRACEBUFFER to be collected at run time for debugging or performance analysis. Memory and execution overhead when not active is minimal. =20 +config LLC_COLORING + bool "Last Level Cache (LLC) coloring" if EXPERT + depends on HAS_LLC_COLORING + +config LLC_COLORS_ORDER + int "Maximum number of LLC colors (base-2 exponent)" + range 1 10 + default 7 + depends on LLC_COLORING + help + Controls the build-time size of various arrays associated with LLC + coloring. The value is a base-2 exponent. Refer to cache coloring + documentation for how to compute the number of colors supported by the + platform. This is only an upper bound. The runtime value is autocomputed + or manually set via cmdline parameters. + The default value corresponds to an 8 MiB 16-ways LLC, which should be + more than what's needed in the general case. + endmenu diff --git a/xen/common/Makefile b/xen/common/Makefile index b279b09bfb..cba3b32733 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -25,6 +25,7 @@ obj-y +=3D keyhandler.o obj-$(CONFIG_KEXEC) +=3D kexec.o obj-$(CONFIG_KEXEC) +=3D kimage.o obj-$(CONFIG_LIVEPATCH) +=3D livepatch.o livepatch_elf.o +obj-$(CONFIG_LLC_COLORING) +=3D llc-coloring.o obj-$(CONFIG_MEM_ACCESS) +=3D mem_access.o obj-y +=3D memory.o obj-y +=3D multicall.o diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 6da291b34e..6ea54838d4 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -304,6 +305,8 @@ static void cf_check dump_domains(unsigned char key) =20 arch_dump_domain_info(d); =20 + domain_dump_llc_colors(d); + rangeset_domain_printk(d); =20 dump_pageframe_info(d); diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c new file mode 100644 index 0000000000..54d76e3aca --- /dev/null +++ b/xen/common/llc-coloring.c @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Last Level Cache (LLC) coloring common code + * + * Copyright (C) 2024, Advanced Micro Devices, Inc. + * Copyright (C) 2024, Minerva Systems SRL + */ +#include +#include +#include + +#define NR_LLC_COLORS (1U << CONFIG_LLC_COLORS_ORDER) + +/* + * -1: not specified (disabled unless llc-size and llc-nr-ways present) + * 0: explicitly disabled through cmdline + * 1: explicitly enabled through cmdline + */ +static int8_t __ro_after_init llc_coloring_enabled =3D -1; +boolean_param("llc-coloring", llc_coloring_enabled); + +static unsigned int __initdata llc_size; +size_param("llc-size", llc_size); +static unsigned int __initdata llc_nr_ways; +integer_param("llc-nr-ways", llc_nr_ways); +/* Number of colors available in the LLC */ +static unsigned int __ro_after_init max_nr_colors; + +static void print_colors(const unsigned int colors[], unsigned int num_col= ors) +{ + unsigned int i; + + printk("{ "); + for ( i =3D 0; i < num_colors; i++ ) + { + unsigned int start =3D colors[i], end =3D start; + + printk("%u", start); + + for ( ; i < num_colors - 1 && end + 1 =3D=3D colors[i + 1]; i++, e= nd++ ) + ; + + if ( start !=3D end ) + printk("-%u", end); + + if ( i < num_colors - 1 ) + printk(", "); + } + printk(" }\n"); +} + +void __init llc_coloring_init(void) +{ + unsigned int way_size; + + if ( (llc_coloring_enabled < 0) && (llc_size && llc_nr_ways) ) + { + llc_coloring_enabled =3D true; + way_size =3D llc_size / llc_nr_ways; + } + else if ( !llc_coloring_enabled ) + return; + else + { + way_size =3D get_llc_way_size(); + if ( !way_size ) + panic("LLC probing failed and 'llc-size' or 'llc-nr-ways' miss= ing\n"); + } + + if ( way_size & ~PAGE_MASK ) + panic("LLC way size must be a multiple of PAGE_SIZE\n"); + + /* + * The maximum number of colors must be a power of 2 in order to corre= ctly + * map them to bits of an address. + */ + max_nr_colors =3D way_size >> PAGE_SHIFT; + + if ( max_nr_colors & (max_nr_colors - 1) ) + panic("Number of LLC colors (%u) isn't a power of 2\n", max_nr_col= ors); + + if ( max_nr_colors > NR_LLC_COLORS ) + { + printk(XENLOG_WARNING + "Number of LLC colors (%u) too big. Using configured max %u= \n", + max_nr_colors, NR_LLC_COLORS); + max_nr_colors =3D NR_LLC_COLORS; + } + else if ( max_nr_colors < 2 ) + panic("Number of LLC colors %u < 2\n", max_nr_colors); + + arch_llc_coloring_init(); +} + +void dump_llc_coloring_info(void) +{ + if ( !llc_coloring_enabled ) + return; + + printk("LLC coloring info:\n"); + printk(" Number of LLC colors supported: %u\n", max_nr_colors); +} + +void domain_dump_llc_colors(const struct domain *d) +{ + if ( !llc_coloring_enabled ) + return; + + printk("%u LLC colors: ", d->num_llc_colors); + print_colors(d->llc_colors, d->num_llc_colors); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 92abed6514..55d561e93c 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -126,6 +126,7 @@ #include #include #include +#include #include #include #include @@ -2644,6 +2645,8 @@ static void cf_check pagealloc_info(unsigned char key) } =20 printk(" Dom heap: %lukB free\n", total << (PAGE_SHIFT-10)); + + dump_llc_coloring_info(); } =20 static __init int cf_check pagealloc_keyhandler_init(void) diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h new file mode 100644 index 0000000000..0acd8d0ad6 --- /dev/null +++ b/xen/include/xen/llc-coloring.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Last Level Cache (LLC) coloring common header + * + * Copyright (C) 2024, Advanced Micro Devices, Inc. + * Copyright (C) 2024, Minerva Systems SRL + */ +#ifndef __XEN_LLC_COLORING_H__ +#define __XEN_LLC_COLORING_H__ + +struct domain; + +#ifdef CONFIG_LLC_COLORING +void llc_coloring_init(void); +void dump_llc_coloring_info(void); +void domain_dump_llc_colors(const struct domain *d); +#else +static inline void llc_coloring_init(void) {} +static inline void dump_llc_coloring_info(void) {} +static inline void domain_dump_llc_colors(const struct domain *d) {} +#endif + +unsigned int get_llc_way_size(void); +void arch_llc_coloring_init(void); + +#endif /* __XEN_LLC_COLORING_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 76e39378b3..bc798a2f61 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -637,6 +637,11 @@ struct domain =20 /* Holding CDF_* constant. Internal flags for domain creation. */ unsigned int cdf; + +#ifdef CONFIG_LLC_COLORING + unsigned int num_llc_colors; + const unsigned int *llc_colors; +#endif }; =20 static inline struct page_list_head *page_to_list( --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158797; cv=none; d=zohomail.com; s=zohoarc; b=WjVFqavR8hD73Zxq8yeV13B2seN8VW6WCDHqFulk/KuZ37sAlzVfQk7ARTtN3JZga9mCcjedPWkOuxPvdcqz59VnL6zRCrV9toQERaZ1+SAG1b/4Jv2Tzy8+0JXJx/TtsqfWmN5Ra+xAG3LKPK5CRp0aBi9w7RGmsmOj5CQjKSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158797; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dOkVSMHCBjXldk0yaSWMOLuz0CcNMdAPNEbfMOACw4Y=; b=FCyRUMqiA4pjySpV436536Ul0sc5yYCyd413oC9a6o9kcGLMlH8dndCavfb9OaGnIJ0D/Wt4AV8FROkBsoVswAliKrLIyCNVbikalFRmsark4h1z54/s81pTn3dyvNl0ircgSuX09k7+WuxnMEcDmq/9+lAEWWOWKYp+OdOf+nw= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158797912593.9617321569925; Mon, 2 Dec 2024 08:59:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846762.1261906 (Exim 4.92) (envelope-from ) id 1tI9lh-0006zC-Ug; Mon, 02 Dec 2024 16:59:29 +0000 Received: by outflank-mailman (output) from mailman id 846762.1261906; Mon, 02 Dec 2024 16:59:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lh-0006yd-QL; Mon, 02 Dec 2024 16:59:29 +0000 Received: by outflank-mailman (input) for mailman id 846762; Mon, 02 Dec 2024 16:59:28 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lg-0006wq-Tu for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:28 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca396b30-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:27 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5d0d71d7f00so3185832a12.3 for ; Mon, 02 Dec 2024 08:59:27 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:26 -0800 (PST) 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: ca396b30-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158767; x=1733763567; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dOkVSMHCBjXldk0yaSWMOLuz0CcNMdAPNEbfMOACw4Y=; b=UA/DMkuxSNoEAhcOqW1TcLMcuaJDTpc//g+y2sfLZmzDM2s7/GuzjskQ34ojdtLfMd yTEP5Csbi2CplteQCrzR7T4RQVWjFmZbbCrIuPh1VILbOXNF9e+ZR0AkD9L+heh6MtM9 qf3D5c+4re/WTisDKnJuyUBMVAQRCBJQTSbkHeWW5iqbNigluELcWFion2wzkqHkgPUT h4Y8nJIUpS5cyBrGeLyICQn98S5ee4pdMR1Nb+w9Byb/kUhuFMs7P6MQ86eZDCR9rt1O nXOwqyy4kpi/UtrdNcejFXDrfmT34MJsdoNmG7yiyW+lPrUku/sdZCv4jd4DdibZbJVy 1tag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158767; x=1733763567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dOkVSMHCBjXldk0yaSWMOLuz0CcNMdAPNEbfMOACw4Y=; b=anw84XyU8RXW+OXEQ2vnoWt2Q3PXW7d3fwaDEuvhGl9aFOkjqTHLeDwdtJNMcriK/O XbG7/wMPuQn9vPvwtG3V0/Dp4y2VTJdXNC0/zUDSCeM2h58IC9DvRJx84OeTmTqePDea ai1rNfWdlvTMNhVvRsOwCorAopy0yi7nej5q8ove28Z+F1HTDl+LUtUWFqfk3R7oTGvA YoZDENqGNKRzAoSZbzOqZn6FgVOhtF6RpRZgxJnQfvhGHCeyybJZEemxdBMzcx3yLKET oWGZ4HBy9k+jwLRpd3Cpn2PSzX5rCv0dcMg3Ui3+E+lr/t8eOMrgOPSGDmC50KzSqOdr llYg== X-Gm-Message-State: AOJu0YzigsdXlw+G69UAfKc5hB9l1f3qCWJ8+Mtgpdzs+WyR12B+nGHt GQ2ykpXCtyqOHa2a4LxTWgBNiinDRn2clUcFZkdRGkQ5+4YF9x78oxQkjfF3aixYTofETG+hsvm o X-Gm-Gg: ASbGncsDwqdRBVmqnr+L4nnpGPzyvEIw1uRy3HRS0LFdl5WEPO1rQoC1bQA3zSN4XnN NOuJR/P6kinvIycuZLBjTtxq1PK1zllqMGbcSjul18WROKTkNJeZFNHVeO5Sxa67c5JGysDjF6z u4BsA5d36JDzvj78cWbH3PIO4BHIlAsUc+QVBBT5MKl74pVLdRC/xgfa93z8FOfWnVfrG8Kotkn kcJy98KZQS28riHLrkc4lJd259/oY3TOO5Fgt4H1CSEv7AbwH20RYFF89Iq2bMEtvNg3xR6Z+MS /Fs5xWelYfAGaX0TbZxH1KQt88MI5uqy3uGt63WDZvPSEqmmoR9q X-Google-Smtp-Source: AGHT+IGHILtzOHKu/xnfwr24UkOR6vkT7e9vLWHdOFJmAPcnVR0/UyHLIlLBk551tmX0Tr4FlZMdcg== X-Received: by 2002:a17:906:315b:b0:aa5:3853:553e with SMTP id a640c23a62f3a-aa58103dbb5mr2664708966b.47.1733158766635; Mon, 02 Dec 2024 08:59:26 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 02/12] xen/arm: add initial support for LLC coloring on arm64 Date: Mon, 2 Dec 2024 17:59:11 +0100 Message-ID: <20241202165921.249585-3-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799519116600 Content-Type: text/plain; charset="utf-8" LLC coloring needs to know the last level cache layout in order to make the best use of it. This can be probed by inspecting the CLIDR_EL1 register, so the Last Level is defined as the last level visible by this register. Note that this excludes system caches in some platforms. Static memory allocation and cache coloring are incompatible because static memory can't be guaranteed to use only colors assigned to the domain. Panic during DomUs creation when both are enabled. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Michal Orzel Acked-by: Jan Beulich --- v11: - removed useless #define from processor.h v10: - moved CONFIG_NUMA check in arch/arm/Kconfig v9: - no changes v8: - no changes v7: - only minor changes v6: - get_llc_way_size() now checks for at least separate I/D caches v5: - used - instead of _ for filenames - moved static-mem check in this patch - moved dom0 colors parsing in next patch - moved color allocation and configuration in next patch - moved check_colors() in next patch - colors are now printed in short form v4: - added "llc-coloring" cmdline option for the boot-time switch - dom0 colors are now checked during domain init as for any other domain - fixed processor.h masks bit width - check for overflow in parse_color_config() - check_colors() now checks also that colors are sorted and unique --- docs/misc/cache-coloring.rst | 14 +++++ xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/dom0less-build.c | 6 +++ xen/arch/arm/include/asm/processor.h | 15 ++++++ xen/arch/arm/llc-coloring.c | 79 ++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 3 ++ xen/common/llc-coloring.c | 2 +- xen/include/xen/llc-coloring.h | 4 ++ 9 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/llc-coloring.c diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst index 371f21a0e7..12972dbb2c 100644 --- a/docs/misc/cache-coloring.rst +++ b/docs/misc/cache-coloring.rst @@ -113,6 +113,20 @@ Auto-probing of LLC specs =20 LLC size and number of ways are probed automatically by default. =20 +In the Arm implementation, this is done by inspecting the CLIDR_EL1 regist= er. +This means that other system caches that aren't visible there are ignored. + LLC specs can be manually set via the above command line parameters. This bypasses any auto-probing and it's used to overcome failing situations, su= ch as flawed probing logic, or for debugging/testing purposes. + +Known issues and limitations +**************************** + +"xen,static-mem" isn't supported when coloring is enabled +######################################################### + +In the domain configuration, "xen,static-mem" allows memory to be statical= ly +allocated to the domain. This isn't possible when LLC coloring is enabled, +because that memory can't be guaranteed to use only colors assigned to the +domain. diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 23bbc91aad..4ec9ef8334 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -8,6 +8,7 @@ config ARM_64 depends on !ARM_32 select 64BIT select HAS_FAST_MULTIPLY + select HAS_LLC_COLORING if !NUMA =20 config ARM def_bool y diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index e4ad1ce851..ccbfc61f88 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_IOREQ_SERVER) +=3D ioreq.o obj-y +=3D irq.o obj-y +=3D kernel.init.o obj-$(CONFIG_LIVEPATCH) +=3D livepatch.o +obj-$(CONFIG_LLC_COLORING) +=3D llc-coloring.o obj-$(CONFIG_MEM_ACCESS) +=3D mem_access.o obj-y +=3D mm.o obj-y +=3D monitor.o diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index f328a044e9..d93a85434e 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -890,7 +891,12 @@ void __init create_domUs(void) panic("No more domain IDs available\n"); =20 if ( dt_find_property(node, "xen,static-mem", NULL) ) + { + if ( llc_coloring_enabled ) + panic("LLC coloring and static memory are incompatible\n"); + flags |=3D CDF_staticmem; + } =20 if ( dt_property_read_bool(node, "direct-map") ) { diff --git a/xen/arch/arm/include/asm/processor.h b/xen/arch/arm/include/as= m/processor.h index 8e02410465..60b587db69 100644 --- a/xen/arch/arm/include/asm/processor.h +++ b/xen/arch/arm/include/asm/processor.h @@ -18,6 +18,21 @@ #define CTR_IDC_SHIFT 28 #define CTR_DIC_SHIFT 29 =20 +/* CCSIDR Current Cache Size ID Register */ +#define CCSIDR_LINESIZE_MASK _AC(0x7, UL) +#define CCSIDR_NUMSETS_SHIFT 13 +#define CCSIDR_NUMSETS_MASK _AC(0x3fff, UL) +#define CCSIDR_NUMSETS_SHIFT_FEAT_CCIDX 32 +#define CCSIDR_NUMSETS_MASK_FEAT_CCIDX _AC(0xffffff, UL) + +/* CSSELR Cache Size Selection Register */ +#define CSSELR_LEVEL_SHIFT 1 + +/* CLIDR Cache Level ID Register */ +#define CLIDR_CTYPEn_SHIFT(n) (3 * ((n) - 1)) +#define CLIDR_CTYPEn_MASK _AC(0x7, UL) +#define CLIDR_CTYPEn_LEVELS 7 + #define ICACHE_POLICY_VPIPT 0 #define ICACHE_POLICY_AIVIVT 1 #define ICACHE_POLICY_VIPT 2 diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c new file mode 100644 index 0000000000..6c8fa6b576 --- /dev/null +++ b/xen/arch/arm/llc-coloring.c @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Last Level Cache (LLC) coloring support for ARM + * + * Copyright (C) 2024, Advanced Micro Devices, Inc. + * Copyright (C) 2024, Minerva Systems SRL + */ +#include +#include +#include + +#include +#include + +/* Return the LLC way size by probing the hardware */ +unsigned int __init get_llc_way_size(void) +{ + register_t ccsidr_el1; + register_t clidr_el1 =3D READ_SYSREG(CLIDR_EL1); + register_t csselr_el1 =3D READ_SYSREG(CSSELR_EL1); + register_t id_aa64mmfr2_el1 =3D READ_SYSREG(ID_AA64MMFR2_EL1); + uint32_t ccsidr_numsets_shift =3D CCSIDR_NUMSETS_SHIFT; + uint32_t ccsidr_numsets_mask =3D CCSIDR_NUMSETS_MASK; + unsigned int n, line_size, num_sets; + + for ( n =3D CLIDR_CTYPEn_LEVELS; n !=3D 0; n-- ) + { + uint8_t ctype_n =3D (clidr_el1 >> CLIDR_CTYPEn_SHIFT(n)) & + CLIDR_CTYPEn_MASK; + + /* Unified cache (see Arm ARM DDI 0487J.a D19.2.27) */ + if ( ctype_n =3D=3D 0b100 ) + break; + } + + if ( n =3D=3D 0 ) + return 0; + + WRITE_SYSREG((n - 1) << CSSELR_LEVEL_SHIFT, CSSELR_EL1); + isb(); + + ccsidr_el1 =3D READ_SYSREG(CCSIDR_EL1); + + /* Arm ARM: (Log2(Number of bytes in cache line)) - 4 */ + line_size =3D 1U << ((ccsidr_el1 & CCSIDR_LINESIZE_MASK) + 4); + + /* If FEAT_CCIDX is enabled, CCSIDR_EL1 has a different bit layout */ + if ( (id_aa64mmfr2_el1 >> ID_AA64MMFR2_CCIDX_SHIFT) & 0x7 ) + { + ccsidr_numsets_shift =3D CCSIDR_NUMSETS_SHIFT_FEAT_CCIDX; + ccsidr_numsets_mask =3D CCSIDR_NUMSETS_MASK_FEAT_CCIDX; + } + + /* Arm ARM: (Number of sets in cache) - 1 */ + num_sets =3D ((ccsidr_el1 >> ccsidr_numsets_shift) & ccsidr_numsets_ma= sk) + 1; + + printk(XENLOG_INFO "LLC found: L%u (line size: %u bytes, sets num: %u)= \n", + n, line_size, num_sets); + + /* Restore value in CSSELR_EL1 */ + WRITE_SYSREG(csselr_el1, CSSELR_EL1); + isb(); + + return line_size * num_sets; +} + +void __init arch_llc_coloring_init(void) +{ +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 2e27af4560..568a49b274 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -326,6 +327,8 @@ void asmlinkage __init start_xen(unsigned long fdt_padd= r) printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); =20 + llc_coloring_init(); + setup_mm(); =20 vm_init(); diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 54d76e3aca..5139890e3d 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -16,7 +16,7 @@ * 0: explicitly disabled through cmdline * 1: explicitly enabled through cmdline */ -static int8_t __ro_after_init llc_coloring_enabled =3D -1; +int8_t __ro_after_init llc_coloring_enabled =3D -1; boolean_param("llc-coloring", llc_coloring_enabled); =20 static unsigned int __initdata llc_size; diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index 0acd8d0ad6..ee0c58ab1c 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -11,10 +11,14 @@ struct domain; =20 #ifdef CONFIG_LLC_COLORING +extern int8_t llc_coloring_enabled; + void llc_coloring_init(void); void dump_llc_coloring_info(void); void domain_dump_llc_colors(const struct domain *d); #else +#define llc_coloring_enabled false + static inline void llc_coloring_init(void) {} static inline void dump_llc_coloring_info(void) {} static inline void domain_dump_llc_colors(const struct domain *d) {} --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158801; cv=none; d=zohomail.com; s=zohoarc; b=WmJYu3khXurJwd1mzUq+XnV+aDh4lWMg3SYeOo/LWf9uasLxBlPgQIBif8RxvHZJwd/uhYeNFPuN1g1wQus7V4iU1kFlRGzNf2up/9iPRZVIvkuGQCQt3nYcCqIxjz0EE1k8gVWsAkXEJz58jt980PhlikOD7wPP7Jay61gy0xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158801; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FuTlneISEoSBSqnNXr83jGC6mPB/G48PgoDktHtlOF0=; b=GJePoHekSfBXKYGIwyIE4htwdEXTC0wJ2G/8NK+tv7s/eFgLCH9O7LMD2jV/ylugc6NUOgMHVO+iZrZEe7nCRp+bRL5D3y1V6G3ae0QYI8mTEszB8SVCXMHJsL4cXMzCS0MDhLgltvwYIejRAuZYg6OpQ4ppCU+PDJ8prM0kc4U= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158801242338.2046358809429; Mon, 2 Dec 2024 09:00:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846763.1261912 (Exim 4.92) (envelope-from ) id 1tI9li-00074w-7Q; Mon, 02 Dec 2024 16:59:30 +0000 Received: by outflank-mailman (output) from mailman id 846763.1261912; Mon, 02 Dec 2024 16:59:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9li-00074G-1w; Mon, 02 Dec 2024 16:59:30 +0000 Received: by outflank-mailman (input) for mailman id 846763; Mon, 02 Dec 2024 16:59:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lh-0006wq-6i for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:29 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cacafa36-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:28 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5cfa1ec3b94so5223153a12.2 for ; Mon, 02 Dec 2024 08:59:28 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:27 -0800 (PST) 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: cacafa36-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158768; x=1733763568; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FuTlneISEoSBSqnNXr83jGC6mPB/G48PgoDktHtlOF0=; b=K40McR3XPkhKWxiIfIxA2DAcHfk3hA5Im1711WxHb0WSUOJshW10DoqWV9UBf+2jp4 vuTCuv8dNko/D71VeJYzOISm+kp3uQUnu5xATFffz8aS7kFYAXIonuVbUPg0sOVJzuCw +6dRpgSsMr2qLqZ+EBo77tnzBu7IgEmbw2Fn005sVKbm1V7WhnTVRv1tULEt39He+6mX IVE66npqSVPiiNHQJtBmsYwUzZ6vXaIrec3w+HpYDOZBD9RlOcWOc67AUOGI3y15zqGb QXAljdoEeJxT05HJh/TEFcaOk2RBcL3ZVKC8NDLV+MuyUpO/R0qT8YWIzFc5Zcf5VCYo /cKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158768; x=1733763568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FuTlneISEoSBSqnNXr83jGC6mPB/G48PgoDktHtlOF0=; b=n2N5OiKvIsTzybW+vUJisvkGKXRx+ATpRwv2SB6om3HbQU4R7YGaN/U+J0lFtKTN4T pPxhEPWuwEpl4QSGtCcwtSpsv00I60lWH8KLw0LegkwF/1AXrRsvy8FjkIQiTKoitE6u Sr4ri68pZqZcHzedKPMyX+0tkSUW2E+Z240SGKCPvindeBiO30m+i2xkY6AGQl1ndFxr aH8/r3BoHovjeO3u8EnoGx9oi/fN5TeEDGXDL0ER8AziqgIUlLXE6hx8Ay0AjQ1Gj2l5 JhJ4t3AOw9E+l0fmLRHAbzFf2xFkkyJ/bSxU6f8GgJoVGA5grJ/BopSY/ACNQl7NZzFc 9wvQ== X-Gm-Message-State: AOJu0YxZEiJj8uyOL8RYmCafGQaNviLxA6ZyxIqCtNpadnlmuKkJquIE eb+qkGaHzm22P3kFjw5V4HR+yUDyO+KlbG1GZ+svSFOLivRJK/+fxBfSA0BiS5cprwh1RF1mnyd f X-Gm-Gg: ASbGnctZ2NuIO6QsJT6HGiMbFeCsOFFvo5TB3FpdDlIM8Lzt4sCpn5yuBDwT3E1Mnwd hK5eiiEOGeN/AZWRZkqELAGVLy0cIxo/msbMSyitm6rYzcJB2DCSiTR+Jx8ffh6VkZWNApnGhj9 Rytzbpt/WxOSRTWp4A0+pWOQFpGL4PJgPOtNwy+I+VRQrwBknjQ0z5OQBZgdZB+lU7lHIh2Mk6Y 6Hxsiessq3ia6ngNcKQfK2AeQ1S8feACZlr6rhhuhN1/jHTe3hxG3okYdtZhvHuOWQszlZc2bjV G6B168Tgyk0MMPEryXQgOofURkGpeXEYuS+XaN10yXw47y1HJziW X-Google-Smtp-Source: AGHT+IFSZN81YR3At05jAS8Y5uQq55EBJLmehdRTJEzxbzXI+AUKAbipwqjZXa5+/6ZAgCJN3HW5rQ== X-Received: by 2002:a17:906:3d29:b0:aa5:1699:e25a with SMTP id a640c23a62f3a-aa580ee98eamr1733280466b.10.1733158767753; Mon, 02 Dec 2024 08:59:27 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 03/12] xen/arm: permit non direct-mapped Dom0 construction Date: Mon, 2 Dec 2024 17:59:12 +0100 Message-ID: <20241202165921.249585-4-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158803502116600 Content-Type: text/plain; charset="utf-8" Cache coloring requires Dom0 not to be direct-mapped because of its non contiguous mapping nature, so allocate_memory() is needed in this case. 8d2c3ab18cc1 ("arm/dom0less: put dom0less feature code in a separate module= ") moved allocate_memory() in dom0less_build.c. In order to use it in Dom0 construction bring it back to domain_build.c and declare it in domain_build.h. Take the opportunity to adapt the implementation of allocate_memory() so that it uses the host layout when called on the hwdom, via find_unallocated_memory(). Signed-off-by: Carlo Nonato --- v11: - GUEST_RAM_BANKS instead of hardcoding the number of banks in allocate_mem= ory() - hwdom_ext_regions -> hwdom_free_mem in allocate_memory() - added a comment in allocate_memory() when skipping small banks v10: - fixed a compilation bug that happened when dom0less support was disabled v9: - no changes v8: - patch adapted to new changes to allocate_memory() v7: - allocate_memory() now uses the host layout when called on the hwdom v6: - new patch --- xen/arch/arm/dom0less-build.c | 44 ----------- xen/arch/arm/domain_build.c | 97 ++++++++++++++++++++++++- xen/arch/arm/include/asm/domain_build.h | 1 + 3 files changed, 94 insertions(+), 48 deletions(-) diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index d93a85434e..67b1503647 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -49,50 +49,6 @@ bool __init is_dom0less_mode(void) return ( !dom0found && domUfound ); } =20 -static void __init allocate_memory(struct domain *d, struct kernel_info *k= info) -{ - struct membanks *mem =3D kernel_info_get_mem(kinfo); - unsigned int i; - paddr_t bank_size; - - printk(XENLOG_INFO "Allocating mappings totalling %ldMB for %pd:\n", - /* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long)(kinfo->unassigned_mem >> 20), d); - - mem->nr_banks =3D 0; - bank_size =3D MIN(GUEST_RAM0_SIZE, kinfo->unassigned_mem); - if ( !allocate_bank_memory(kinfo, gaddr_to_gfn(GUEST_RAM0_BASE), - bank_size) ) - goto fail; - - bank_size =3D MIN(GUEST_RAM1_SIZE, kinfo->unassigned_mem); - if ( !allocate_bank_memory(kinfo, gaddr_to_gfn(GUEST_RAM1_BASE), - bank_size) ) - goto fail; - - if ( kinfo->unassigned_mem ) - goto fail; - - for( i =3D 0; i < mem->nr_banks; i++ ) - { - printk(XENLOG_INFO "%pd BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)= \n", - d, - i, - mem->bank[i].start, - mem->bank[i].start + mem->bank[i].size, - /* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long)(mem->bank[i].size >> 20)); - } - - return; - -fail: - panic("Failed to allocate requested domain memory." - /* Don't want format this as PRIpaddr (16 digit hex) */ - " %ldKB unallocated. Fix the VMs configurations.\n", - (unsigned long)kinfo->unassigned_mem >> 10); -} - #ifdef CONFIG_VGICV2 static int __init make_gicv2_domU_node(struct kernel_info *kinfo) { diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2c30792de8..2b8cba9b2f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -416,7 +416,6 @@ static void __init allocate_memory_11(struct domain *d, } } =20 -#ifdef CONFIG_DOM0LESS_BOOT bool __init allocate_domheap_memory(struct domain *d, paddr_t tot_size, alloc_domheap_mem_cb cb, void *extra) { @@ -508,7 +507,6 @@ bool __init allocate_bank_memory(struct kernel_info *ki= nfo, gfn_t sgfn, =20 return true; } -#endif =20 /* * When PCI passthrough is available we want to keep the @@ -1003,6 +1001,94 @@ out: return res; } =20 +void __init allocate_memory(struct domain *d, struct kernel_info *kinfo) +{ + struct membanks *mem =3D kernel_info_get_mem(kinfo); + unsigned int i, nr_banks =3D GUEST_RAM_BANKS; + paddr_t bank_start, bank_size; + struct membanks *hwdom_free_mem =3D NULL; + const uint64_t bankbase[] =3D GUEST_RAM_BANK_BASES; + const uint64_t banksize[] =3D GUEST_RAM_BANK_SIZES; + + printk(XENLOG_INFO "Allocating mappings totalling %ldMB for %pd:\n", + /* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long)(kinfo->unassigned_mem >> 20), d); + + mem->nr_banks =3D 0; + /* + * Use host memory layout for hwdom. Only case for this is when LLC co= loring + * is enabled. + */ + if ( is_hardware_domain(d) ) + { + ASSERT(llc_coloring_enabled); + + hwdom_free_mem =3D xzalloc_flex_struct(struct membanks, bank, + NR_MEM_BANKS); + if ( !hwdom_free_mem ) + goto fail; + + hwdom_free_mem->max_banks =3D NR_MEM_BANKS; + + if ( find_unallocated_memory(kinfo, hwdom_free_mem) ) + goto fail; + + nr_banks =3D hwdom_free_mem->nr_banks; + } + + for ( i =3D 0; kinfo->unassigned_mem > 0 && nr_banks > 0; i++, nr_bank= s-- ) + { + if ( is_hardware_domain(d) ) + { + bank_start =3D hwdom_free_mem->bank[i].start; + bank_size =3D hwdom_free_mem->bank[i].size; + + /* + * Skip banks that are too small. The first bank must contain + * dom0 kernel + ramdisk + dtb and 128 MB is the same limit us= ed + * in allocate_memory_11(). + */ + if ( bank_size < min_t(paddr_t, kinfo->unassigned_mem, MB(128)= ) ) + continue; + } + else + { + if ( i >=3D GUEST_RAM_BANKS ) + goto fail; + + bank_start =3D bankbase[i]; + bank_size =3D banksize[i]; + } + + bank_size =3D MIN(bank_size, kinfo->unassigned_mem); + if ( !allocate_bank_memory(kinfo, gaddr_to_gfn(bank_start), bank_s= ize) ) + goto fail; + } + + if ( kinfo->unassigned_mem ) + goto fail; + + for( i =3D 0; i < mem->nr_banks; i++ ) + { + printk(XENLOG_INFO "%pd BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)= \n", + d, + i, + mem->bank[i].start, + mem->bank[i].start + mem->bank[i].size, + /* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long)(mem->bank[i].size >> 20)); + } + + xfree(hwdom_free_mem); + return; + +fail: + panic("Failed to allocate requested domain memory." + /* Don't want format this as PRIpaddr (16 digit hex) */ + " %ldKB unallocated. Fix the VMs configurations.\n", + (unsigned long)kinfo->unassigned_mem >> 10); +} + static int __init handle_pci_range(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data) { @@ -1223,7 +1309,7 @@ int __init make_hypervisor_node(struct domain *d, =20 ext_regions->max_banks =3D NR_MEM_BANKS; =20 - if ( is_domain_direct_mapped(d) ) + if ( domain_use_host_layout(d) ) { if ( !is_iommu_enabled(d) ) res =3D find_unallocated_memory(kinfo, ext_regions); @@ -2152,7 +2238,10 @@ static int __init construct_dom0(struct domain *d) /* type must be set before allocate_memory */ d->arch.type =3D kinfo.type; #endif - allocate_memory_11(d, &kinfo); + if ( is_domain_direct_mapped(d) ) + allocate_memory_11(d, &kinfo); + else + allocate_memory(d, &kinfo); find_gnttab_region(d, &kinfo); =20 rc =3D process_shm_chosen(d, &kinfo); diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include= /asm/domain_build.h index e712afbc7f..5d77af2e8b 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -11,6 +11,7 @@ bool allocate_domheap_memory(struct domain *d, paddr_t to= t_size, alloc_domheap_mem_cb cb, void *extra); bool allocate_bank_memory(struct kernel_info *kinfo, gfn_t sgfn, paddr_t tot_size); +void allocate_memory(struct domain *d, struct kernel_info *kinfo); int construct_domain(struct domain *d, struct kernel_info *kinfo); int domain_fdt_begin_node(void *fdt, const char *name, uint64_t unit); int make_chosen_node(const struct kernel_info *kinfo); --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158799; cv=none; d=zohomail.com; s=zohoarc; b=PzfgJ7Mfs4fxcjE0aompPSG3NlOtl6vWlX+bL7PJ/sZ4f99L5/n9XQLhVXdPbYmuX6BMv9IMlJGS8udVHZ+V0wMCTlxiPaO4IsszpMfwHGhfNlPcKtmXwlBZK7G05kuJ+sAjB2M/gJrGfxvhlZZ+lulJWwtgxFO9w8KTkbfyKGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158799; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f+tyePsYcLfjXIwoyPcyVhlRR1rCp6P8smeteExEhoc=; b=IRNgdv1fF2kDG1iv4v08HyirV7R8XzKvMw5Ti+tx3xZ9HBVPy1pgu4JcuF+hwiY1sQE6YxMGa0QxNgQ6fumaGtnS3eQQS5ObZjusjk8vqbLwI84nraPy/6JjTJizv8M8G5PLKUHJdMxpQok2HCp7BjHyUFlW0+7jQSVac40Kr68= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158799253649.772660598434; Mon, 2 Dec 2024 08:59:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846764.1261931 (Exim 4.92) (envelope-from ) id 1tI9lk-0007eq-Ji; Mon, 02 Dec 2024 16:59:32 +0000 Received: by outflank-mailman (output) from mailman id 846764.1261931; Mon, 02 Dec 2024 16:59:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lk-0007eb-Gc; Mon, 02 Dec 2024 16:59:32 +0000 Received: by outflank-mailman (input) for mailman id 846764; Mon, 02 Dec 2024 16:59:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9li-0006wq-DJ for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:30 +0000 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [2a00:1450:4864:20::131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cb840a3a-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:29 +0100 (CET) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-53df67d6659so6805931e87.3 for ; Mon, 02 Dec 2024 08:59:29 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:28 -0800 (PST) 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: cb840a3a-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158769; x=1733763569; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f+tyePsYcLfjXIwoyPcyVhlRR1rCp6P8smeteExEhoc=; b=Ugyzb1brD6MFs42axqquuGznUi3WpDPNFShOSo1N+ZbkIJpmOneOV0X+Uhb2walngJ C7dCMcQ/nltrsEFBCl+ghyDVro3LSYogv6uy92GinlLU0Vx1z/fOueCxxzR9h0Pj5Vgv lOqDnxSsrO8uT33+qiSw3JE3jMiYX9xXgjOAtaD0Htj/b+2xQUVbN/UbWAfDXHdD2+2q JvnU6OatehL0e20fqoTtN3Ri3IwP6/fy4VkgFvxO+kHSQjBVLPh2iRo8/rG2lUak612f bQqXb2TprN5Q0ea/ghu8XZJs+2T3fq6eQJT8SfC1BAN979wOdzLS4Eq8xO4ZGYMI+TYl E8XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158769; x=1733763569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f+tyePsYcLfjXIwoyPcyVhlRR1rCp6P8smeteExEhoc=; b=fEZPmXaDttQQW6c+DCmjVyODt2OZ511PZDU3nidGWELL4N4FsW7plFDobUSK+JEPIu urqj/2r1iCUubT1avD8sziCxaTRQc8tsSg6IeIzVxkXlnqUoW3RMh1SV6WtulumFY0hA a8PMmcRHvf5rPzP73Q3bz12kq10P/tIvC5YAk44bnifM/5HIqEvpwVj7r4yS+NrxbkYX 8J4c+0JTo6AitwvZ82zPNfwC4UziMKFiuPzofySlAewlvCsk3yGRAfnJhUfoANagg7r/ mhQx8WYoduVgualx5ZiPtnKPsGKw4rqOdporiRATOOe8fKwfbZ5jynO77HEo93nOr1q5 qcSA== X-Gm-Message-State: AOJu0YzF8xb+A/Nv0l3zJ/iJ3ZIhu52zmWPvmTXnioO3tSQJW7R7d667 l+QdutWXCHMjXGQ8QYjUnz24VmDWCb7Wm4ZBpSNz3OZMcmhWYC1eIxfmBPSQB7pCWLc43QKSI4U h X-Gm-Gg: ASbGnctinbbUXRmeLrVGGx2Yk8Gqgd6a5DRyLNJ6pQePBZWc1Q+oKm4LSaxizL9zpKj lr2GKvGU4EUmvP88spisb7mewUMPZHVfUcBUe1gKUfPG6qpN9Jnovba8dd1ogsxqnWz5NpGGtxI sJiZFHn3yR5jHnXJRIdutdIstbPA2Mp01ENkLlldPgA8JOm9GT++XeGaCsa3G3p+QYcLeycCQYE 5TdfBhoAMoN/EuvzapYQ2phzpjGv8T4XWVQ+c44KbucllO5CLlY2ppNvaLY5+nV6ZgoyBEE5TDc Yp+/CrO8n5EWyju3vclV47vvY1zw/jFSfKDgws/Wex2Q67rVhkIF X-Google-Smtp-Source: AGHT+IEU8H5NoSdw3aNt7spYNOY0Mw2YbA0JS1+Va/g8Yz/R+xHt3Znt9iJeAGBGJtmADcICqNJniQ== X-Received: by 2002:a05:6512:3994:b0:53d:a025:1142 with SMTP id 2adb3069b0e04-53df01172c2mr18687189e87.54.1733158768743; Mon, 02 Dec 2024 08:59:28 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 04/12] xen/arm: add Dom0 cache coloring support Date: Mon, 2 Dec 2024 17:59:13 +0100 Message-ID: <20241202165921.249585-5-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158801760116600 Content-Type: text/plain; charset="utf-8" Add a command line parameter to allow the user to set the coloring configuration for Dom0. A common configuration syntax for cache colors is introduced and documented. Take the opportunity to also add: - default configuration notion. - function to check well-formed configurations. Direct mapping Dom0 isn't possible when coloring is enabled, so CDF_directmap flag is removed when creating it. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Jan Beulich Reviewed-by: Michal Orzel --- v11: - minor changes v10: - fixed array type for colors parameter in check_colors() v9: - moved domain_llc_coloring_free() in next patch cause it's never used for = dom0 v8: - added bound check on dom0_num_colors - default colors array set just once v7: - parse_color_config() doesn't accept leading/trailing commas anymore - removed alloc_colors() helper v6: - moved domain_llc_coloring_free() in this patch - removed domain_alloc_colors() in favor of a more explicit allocation - parse_color_config() now accepts the size of the array to be filled - allocate_memory() moved in another patch v5: - Carlo Nonato as the new author - moved dom0 colors parsing (parse_colors()) in this patch - added dom0_set_llc_colors() to set dom0 colors after creation - moved color allocation and checking in this patch - error handling when allocating color arrays - FIXME: copy pasted allocate_memory() cause it got moved v4: - dom0 colors are dynamically allocated as for any other domain (colors are duplicated in dom0_colors and in the new array, but logic is simpler) --- docs/misc/cache-coloring.rst | 29 ++++++++ docs/misc/xen-command-line.pandoc | 9 +++ xen/arch/arm/domain_build.c | 10 ++- xen/common/llc-coloring.c | 120 +++++++++++++++++++++++++++++- xen/include/xen/llc-coloring.h | 1 + 5 files changed, 167 insertions(+), 2 deletions(-) diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst index 12972dbb2c..7b47d0ed92 100644 --- a/docs/misc/cache-coloring.rst +++ b/docs/misc/cache-coloring.rst @@ -107,6 +107,35 @@ Specific documentation is available at `docs/misc/xen-= command-line.pandoc`. +----------------------+-------------------------------+ | ``llc-nr-ways`` | Set the LLC number of ways | +----------------------+-------------------------------+ +| ``dom0-llc-colors`` | Dom0 color configuration | ++----------------------+-------------------------------+ + +Colors selection format +*********************** + +Regardless of the memory pool that has to be colored (Xen, Dom0/DomUs), +the color selection can be expressed using the same syntax. In particular a +comma-separated list of colors or ranges of colors is used. +Ranges are hyphen-separated intervals (such as `0-4`) and are inclusive on= both +sides. + +Note that: + +- no spaces are allowed between values. +- no overlapping ranges or duplicated colors are allowed. +- values must be written in ascending order. + +Examples: + ++-------------------+-----------------------------+ +| **Configuration** | **Actual selection** | ++-------------------+-----------------------------+ +| 1-2,5-8 | [1, 2, 5, 6, 7, 8] | ++-------------------+-----------------------------+ +| 4-8,10,11,12 | [4, 5, 6, 7, 8, 10, 11, 12] | ++-------------------+-----------------------------+ +| 0 | [0] | ++-------------------+-----------------------------+ =20 Auto-probing of LLC specs ######################### diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index abd8dae96f..bfdc8b0002 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -963,6 +963,15 @@ Controls for the dom0 IOMMU setup. =20 Specify a list of IO ports to be excluded from dom0 access. =20 +### dom0-llc-colors (arm64) +> `=3D List of [ | - ]` + +> Default: `All available LLC colors` + +Specify dom0 LLC color configuration. This option is available only when +`CONFIG_LLC_COLORING` is enabled. If the parameter is not set, all availab= le +colors are used. + ### dom0_max_vcpus =20 Either: diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2b8cba9b2f..83d7585e7e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -2285,6 +2286,7 @@ void __init create_dom0(void) .max_maptrack_frames =3D -1, .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), }; + unsigned int flags =3D CDF_privileged; int rc; =20 /* The vGIC for DOM0 is exactly emulating the hardware GIC */ @@ -2312,10 +2314,16 @@ void __init create_dom0(void) panic("SVE vector length error\n"); } =20 - dom0 =3D domain_create(0, &dom0_cfg, CDF_privileged | CDF_directmap); + if ( !llc_coloring_enabled ) + flags |=3D CDF_directmap; + + dom0 =3D domain_create(0, &dom0_cfg, flags); if ( IS_ERR(dom0) ) panic("Error creating domain 0 (rc =3D %ld)\n", PTR_ERR(dom0)); =20 + if ( llc_coloring_enabled && (rc =3D dom0_set_llc_colors(dom0)) ) + panic("Error initializing LLC coloring for domain 0 (rc =3D %d)\n"= , rc); + if ( alloc_dom0_vcpu0(dom0) =3D=3D NULL ) panic("Error creating domain 0 vcpu0\n"); =20 diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 5139890e3d..8f076849c1 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -25,6 +25,66 @@ static unsigned int __initdata llc_nr_ways; integer_param("llc-nr-ways", llc_nr_ways); /* Number of colors available in the LLC */ static unsigned int __ro_after_init max_nr_colors; +/* Default coloring configuration */ +static unsigned int __ro_after_init default_colors[NR_LLC_COLORS]; + +static unsigned int __initdata dom0_colors[NR_LLC_COLORS]; +static unsigned int __initdata dom0_num_colors; + +/* + * Parse the coloring configuration given in the buf string, following the + * syntax below. + * + * COLOR_CONFIGURATION ::=3D COLOR | RANGE,...,COLOR | RANGE + * RANGE ::=3D COLOR-COLOR + * + * Example: "0,2-6,15-16" represents the set of colors: 0,2,3,4,5,6,15,16. + */ +static int __init parse_color_config(const char *buf, unsigned int colors[= ], + unsigned int max_num_colors, + unsigned int *num_colors) +{ + const char *s =3D buf; + + *num_colors =3D 0; + + while ( *s !=3D '\0' ) + { + unsigned int color, start, end; + + start =3D simple_strtoul(s, &s, 0); + + if ( *s =3D=3D '-' ) /* Range */ + { + s++; + end =3D simple_strtoul(s, &s, 0); + } + else /* Single value */ + end =3D start; + + if ( start > end || (end - start) > (UINT_MAX - *num_colors) || + (*num_colors + (end - start)) >=3D max_num_colors ) + return -EINVAL; + + /* Colors are range checked in check_colors() */ + for ( color =3D start; color <=3D end; color++ ) + colors[(*num_colors)++] =3D color; + + if ( *s =3D=3D ',' ) + s++; + else if ( *s !=3D '\0' ) + break; + } + + return *s ? -EINVAL : 0; +} + +static int __init parse_dom0_colors(const char *s) +{ + return parse_color_config(s, dom0_colors, ARRAY_SIZE(dom0_colors), + &dom0_num_colors); +} +custom_param("dom0-llc-colors", parse_dom0_colors); =20 static void print_colors(const unsigned int colors[], unsigned int num_col= ors) { @@ -49,9 +109,27 @@ static void print_colors(const unsigned int colors[], u= nsigned int num_colors) printk(" }\n"); } =20 +static bool __init check_colors(const unsigned int colors[], + unsigned int num_colors) +{ + unsigned int i; + + for ( i =3D 0; i < num_colors; i++ ) + { + if ( colors[i] >=3D max_nr_colors ) + { + printk(XENLOG_ERR "LLC color %u >=3D %u (max allowed)\n", colo= rs[i], + max_nr_colors); + return false; + } + } + + return true; +} + void __init llc_coloring_init(void) { - unsigned int way_size; + unsigned int way_size, i; =20 if ( (llc_coloring_enabled < 0) && (llc_size && llc_nr_ways) ) { @@ -89,6 +167,9 @@ void __init llc_coloring_init(void) else if ( max_nr_colors < 2 ) panic("Number of LLC colors %u < 2\n", max_nr_colors); =20 + for ( i =3D 0; i < max_nr_colors; i++ ) + default_colors[i] =3D i; + arch_llc_coloring_init(); } =20 @@ -110,6 +191,43 @@ void domain_dump_llc_colors(const struct domain *d) print_colors(d->llc_colors, d->num_llc_colors); } =20 +static void __init domain_set_default_colors(struct domain *d) +{ + printk(XENLOG_WARNING + "LLC color config not found for %pd, using all colors\n", d); + + d->llc_colors =3D default_colors; + d->num_llc_colors =3D max_nr_colors; +} + +int __init dom0_set_llc_colors(struct domain *d) +{ + typeof(*dom0_colors) *colors; + + if ( !dom0_num_colors ) + { + domain_set_default_colors(d); + return 0; + } + + if ( (dom0_num_colors > max_nr_colors) || + !check_colors(dom0_colors, dom0_num_colors) ) + { + printk(XENLOG_ERR "%pd: bad LLC color config\n", d); + return -EINVAL; + } + + colors =3D xmalloc_array(typeof(*dom0_colors), dom0_num_colors); + if ( !colors ) + return -ENOMEM; + + memcpy(colors, dom0_colors, sizeof(*colors) * dom0_num_colors); + d->llc_colors =3D colors; + d->num_llc_colors =3D dom0_num_colors; + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index ee0c58ab1c..4ce14e4e4a 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -26,6 +26,7 @@ static inline void domain_dump_llc_colors(const struct do= main *d) {} =20 unsigned int get_llc_way_size(void); void arch_llc_coloring_init(void); +int dom0_set_llc_colors(struct domain *d); =20 #endif /* __XEN_LLC_COLORING_H__ */ =20 --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158797; cv=none; d=zohomail.com; s=zohoarc; b=Avb1RHkZgZ6937K0/b5Arz8LpgR3sV9JfXGBZimlQx8y68OIaqrUZfMcAkfUTTjwtypzDGvSAQXLraC6e5TV6SdOhrzQ833Hdb1ZywqBiUntWN4k8TGBaYHOY54decoiMdSxcl9/aIsIl+lmQItfNgFbHFFB3bQAmWXiALXsbPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158797; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uPDYDU9V+cT61NhOvEC9qVLU2fWBxFfDL0pDRFCfADs=; b=khtKazvPln1naCdksfBQiIis30f5YeiCI8vlET5IBSq/u43SNPh5ebOL23V9PeFo5uyXp9XjV/icBl9Jz7+cRsVNldwwbMOluLBKhH1gac3usw2mJi2Lkph4giHy+sN4qT9Px9CXJCDZQLQT3R+sXKFtwJeA+u5H5CzOzVspiKs= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158797084921.7445309220204; Mon, 2 Dec 2024 08:59:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846766.1261944 (Exim 4.92) (envelope-from ) id 1tI9ll-0007sB-FP; Mon, 02 Dec 2024 16:59:33 +0000 Received: by outflank-mailman (output) from mailman id 846766.1261944; Mon, 02 Dec 2024 16:59:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9ll-0007rJ-9L; Mon, 02 Dec 2024 16:59:33 +0000 Received: by outflank-mailman (input) for mailman id 846766; Mon, 02 Dec 2024 16:59:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lk-0006x4-7h for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:32 +0000 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [2a00:1450:4864:20::132]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cbf9f788-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:30 +0100 (CET) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-53dd59a2bc1so4860354e87.2 for ; Mon, 02 Dec 2024 08:59:30 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:29 -0800 (PST) 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: cbf9f788-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158770; x=1733763570; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uPDYDU9V+cT61NhOvEC9qVLU2fWBxFfDL0pDRFCfADs=; b=rxbhCpqgZafgQaWYMqPWpKNqw/+AHnJePzclEdzJd8CifIzEQUIjpXlieg9czVp7/3 6Tp4LdaC1hJY5nL93ERx6L7pJ2gVoKWwc1ugerBSDW1hXKERLW4xyd620l05rz9mFl7z AmV3/D1/21g2gkJtRsXUTjMz9MVhrsYTIPpjwdQ8z/jAbfjgw68+vTXCYewMXDbQOdO4 1VN0mYWuThCOJCcyNx/z6D5CRg/AxWWAlcu3LyLd97aHLGV9ChHsGRX8lnjn+w4/yB8p DHGe/YESaPN98a8/VmSZCVheQUCjzt3yoTP18n20o8WGoEQfuxyU3Hqa4A+5WUQPBzkk sFHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158770; x=1733763570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uPDYDU9V+cT61NhOvEC9qVLU2fWBxFfDL0pDRFCfADs=; b=UATpVOX/3ZL2uRae7Bkm/6CUASA+VBsxjVHGNAjFUFfqs1Ev80yQsI4rgC+Wmc/QQQ WlNCYDagXnUbohNoTmAqi+Ej+P3ULyK837vZvssviBw1Kw+nG/pDtlNkDioyscv1+1sZ q5c03qQDFMerBcoqH9EnwtH8Ds0e18G03MgBOFID2BBjQ+ZqdO95dwqujpouWmD9Kqq1 qcGUGx6mIstCzKqAfpUB4fvCrDL83ujHWGZ51m95/N4lIA4xeXORIcG3RpmPE6P1KPYc e7H997EC6xZRo1Tl045JO4HbPMT03Xd2ywvHO8d4ej05r42aBVgTfbzgTy4nkCiGSq3j +fmQ== X-Gm-Message-State: AOJu0Ywa+GwoMbWKiwnPO6pPVg6j/6rac7ULnHjz2obvBzLTSLYvIpFL 9VWrq1hLLrO6lzTPLZtqAKA5bJAdXZopJJGGGg7VuQ+6PU+OmSCQDkNpb+dquyS+C5XUMaeKqrn u X-Gm-Gg: ASbGncvZPIMtNYuedDV4ywY1qUg9qB/lETg4VPzoydzvj7a/8cISwsBf5ntS8DGdYXJ 7U/ILhX9ky+FgB+nzBYB8//+7oKwtPs22fqj93pFO+FkoLe273ByKv7dxpP7/0xYM2wBJJ8kmEg 2zl9YHnUry/ExGCJ3Pm9c2nwLW0GpEFqOuovmwSZFwJWRpl+AlWuRJadF3YH94bozC/dzMir60i FXYnA9X6U2p64Zgsqq07vfAxqk27l1aXiVkClAAvVWEoNZ+CQRVrQxG6MiOAqsTdVGopoA2jLyU klSK2njhcufH+sduFTNL/g9O53dUcelj3Loo2aCJ9EgBBj/HUke6 X-Google-Smtp-Source: AGHT+IGU9K5UrKiaW80g16K3SmuTHJjnReFkYfE1nN+bAa8o8fbCMxAm+qhH44scGK11AjAKmyVRag== X-Received: by 2002:a05:6512:3ba3:b0:53d:cf93:8072 with SMTP id 2adb3069b0e04-53df00ff250mr12783810e87.38.1733158769685; Mon, 02 Dec 2024 08:59:29 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v11 05/12] xen: extend domctl interface for cache coloring Date: Mon, 2 Dec 2024 17:59:14 +0100 Message-ID: <20241202165921.249585-6-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799511116600 Content-Type: text/plain; charset="utf-8" Add a new domctl hypercall to allow the user to set LLC coloring configurations. Colors can be set only once, just after domain creation, since recoloring isn't supported. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Jan Beulich --- v11: - no changes v10: - no changes v9: - minor printk message changes - moved domain_llc_coloring_free() in this patch v8: - fixed memory leak on error path of domain_set_llc_colors() v7: - -EOPNOTSUPP returned in case of hypercall called without llc_coloring_ena= bled - domain_set_llc_colors_domctl() renamed to domain_set_llc_colors() - added padding and input bound checks to domain_set_llc_colors() - removed alloc_colors() helper usage from domain_set_llc_colors() v6: - reverted the XEN_DOMCTL_INTERFACE_VERSION bump - reverted to uint32 for the guest handle - explicit padding added to the domctl struct - rewrote domain_set_llc_colors_domctl() to be more explicit v5: - added a new hypercall to set colors - uint for the guest handle v4: - updated XEN_DOMCTL_INTERFACE_VERSION --- xen/common/domain.c | 3 ++ xen/common/domctl.c | 10 +++++++ xen/common/llc-coloring.c | 55 ++++++++++++++++++++++++++++++++-- xen/include/public/domctl.h | 9 ++++++ xen/include/xen/llc-coloring.h | 5 ++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 92263a4fbd..842a23751a 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1276,6 +1277,8 @@ void domain_destroy(struct domain *d) { BUG_ON(!d->is_dying); =20 + domain_llc_coloring_free(d); + /* May be already destroyed, or get_domain() can race us. */ if ( atomic_cmpxchg(&d->refcnt, 0, DOMAIN_DESTROYED) !=3D 0 ) return; diff --git a/xen/common/domctl.c b/xen/common/domctl.c index ea16b75910..6387dddbcd 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -866,6 +867,15 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) __HYPERVISOR_domctl, "h", u_domctl); break; =20 + case XEN_DOMCTL_set_llc_colors: + if ( op->u.set_llc_colors.pad ) + ret =3D -EINVAL; + else if ( llc_coloring_enabled ) + ret =3D domain_set_llc_colors(d, &op->u.set_llc_colors); + else + ret =3D -EOPNOTSUPP; + break; + default: ret =3D arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 8f076849c1..2a0ee695c8 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -5,6 +5,7 @@ * Copyright (C) 2024, Advanced Micro Devices, Inc. * Copyright (C) 2024, Minerva Systems SRL */ +#include #include #include #include @@ -109,8 +110,7 @@ static void print_colors(const unsigned int colors[], u= nsigned int num_colors) printk(" }\n"); } =20 -static bool __init check_colors(const unsigned int colors[], - unsigned int num_colors) +static bool check_colors(const unsigned int colors[], unsigned int num_col= ors) { unsigned int i; =20 @@ -191,7 +191,7 @@ void domain_dump_llc_colors(const struct domain *d) print_colors(d->llc_colors, d->num_llc_colors); } =20 -static void __init domain_set_default_colors(struct domain *d) +static void domain_set_default_colors(struct domain *d) { printk(XENLOG_WARNING "LLC color config not found for %pd, using all colors\n", d); @@ -228,6 +228,55 @@ int __init dom0_set_llc_colors(struct domain *d) return 0; } =20 +int domain_set_llc_colors(struct domain *d, + const struct xen_domctl_set_llc_colors *config) +{ + unsigned int *colors; + + if ( d->num_llc_colors ) + return -EEXIST; + + if ( !config->num_llc_colors ) + { + domain_set_default_colors(d); + return 0; + } + + if ( config->num_llc_colors > max_nr_colors ) + return -EINVAL; + + colors =3D xmalloc_array(unsigned int, config->num_llc_colors); + if ( !colors ) + return -ENOMEM; + + if ( copy_from_guest(colors, config->llc_colors, config->num_llc_color= s) ) + { + xfree(colors); + return -EFAULT; + } + + if ( !check_colors(colors, config->num_llc_colors) ) + { + printk(XENLOG_ERR "%pd: bad LLC color config\n", d); + xfree(colors); + return -EINVAL; + } + + d->llc_colors =3D colors; + d->num_llc_colors =3D config->num_llc_colors; + + return 0; +} + +void domain_llc_coloring_free(struct domain *d) +{ + if ( !llc_coloring_enabled || d->llc_colors =3D=3D default_colors ) + return; + + /* free pointer-to-const using __va(__pa()) */ + xfree(__va(__pa(d->llc_colors))); +} + /* * Local variables: * mode: C diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 353f831e40..e2d392d1e5 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1236,6 +1236,13 @@ struct xen_domctl_dt_overlay { }; #endif =20 +struct xen_domctl_set_llc_colors { + /* IN LLC coloring parameters */ + uint32_t num_llc_colors; + uint32_t pad; + XEN_GUEST_HANDLE_64(uint32) llc_colors; +}; + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1325,6 +1332,7 @@ struct xen_domctl { #define XEN_DOMCTL_set_paging_mempool_size 86 #define XEN_DOMCTL_dt_overlay 87 #define XEN_DOMCTL_gsi_permission 88 +#define XEN_DOMCTL_set_llc_colors 89 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1391,6 +1399,7 @@ struct xen_domctl { #if defined(__arm__) || defined(__aarch64__) struct xen_domctl_dt_overlay dt_overlay; #endif + struct xen_domctl_set_llc_colors set_llc_colors; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index 4ce14e4e4a..cbebe0816c 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -9,6 +9,7 @@ #define __XEN_LLC_COLORING_H__ =20 struct domain; +struct xen_domctl_set_llc_colors; =20 #ifdef CONFIG_LLC_COLORING extern int8_t llc_coloring_enabled; @@ -16,17 +17,21 @@ extern int8_t llc_coloring_enabled; void llc_coloring_init(void); void dump_llc_coloring_info(void); void domain_dump_llc_colors(const struct domain *d); +void domain_llc_coloring_free(struct domain *d); #else #define llc_coloring_enabled false =20 static inline void llc_coloring_init(void) {} static inline void dump_llc_coloring_info(void) {} static inline void domain_dump_llc_colors(const struct domain *d) {} +static inline void domain_llc_coloring_free(struct domain *d) {} #endif =20 unsigned int get_llc_way_size(void); void arch_llc_coloring_init(void); int dom0_set_llc_colors(struct domain *d); +int domain_set_llc_colors(struct domain *d, + const struct xen_domctl_set_llc_colors *config); =20 #endif /* __XEN_LLC_COLORING_H__ */ =20 --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158797; cv=none; d=zohomail.com; s=zohoarc; b=h1NRQLEADo0JRotRGyOE+PxY99pj8XAGziYHWVcFQ4buPPBxg62K/q1PIfvuc5ycMNpbI07RaJGGQliSJEt4qcIhVIcOQNUbJQ9rb6vEriZo4sntt7pTk/8j+ovvTplWq/LtRsg316AOYdd48tTm45tRWpvxjRU7G2tuR/ZKvoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158797; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gqhiaN/uGHCe7Mq6SZhbOqUmu19X+lhLAzCqw3rcUEU=; b=W4mSk09v9kbbjVo9COQb8KVq1ztsGWknxIsBFVOQjPSMNceV3WNgvvzBz+H8CMwuqgG8KT9pJXBHWo3Pmil+jqK/cQutwwACP9/HlgDjtGl7gmC1Ck/sieyGuxt8bxzHvAOxQ+FeB2l1O4+iEqh37NUiRJ2a1xa+ABA9DFlAUzQ= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158797647299.3226745715215; Mon, 2 Dec 2024 08:59:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846767.1261960 (Exim 4.92) (envelope-from ) id 1tI9lm-0008Lb-OJ; Mon, 02 Dec 2024 16:59:34 +0000 Received: by outflank-mailman (output) from mailman id 846767.1261960; Mon, 02 Dec 2024 16:59:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lm-0008KW-Jd; Mon, 02 Dec 2024 16:59:34 +0000 Received: by outflank-mailman (input) for mailman id 846767; Mon, 02 Dec 2024 16:59:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lk-0006wq-Cq for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:32 +0000 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [2a00:1450:4864:20::130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ccaa52d0-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:31 +0100 (CET) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-53de579f775so6235926e87.2 for ; Mon, 02 Dec 2024 08:59:31 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:30 -0800 (PST) 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: ccaa52d0-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158771; x=1733763571; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gqhiaN/uGHCe7Mq6SZhbOqUmu19X+lhLAzCqw3rcUEU=; b=RcKXyJ8DaJ2JfD4csSjF6PAkYHjMQrSjY9wSqqrSaz9QGwJs7WLc+QdCv8raVOxMBc 8WRzMI+nKQi8b+px0AT5+I/wazQCeZt9xx2/i7zA3i+Xhvj3AnnTU2jDV3+3KvoV05OL FfZ5jP3thy4SsV1AkzcvWTODubz+KO9+gh/ScLR/L054KKBMVxbP1KoOaJfBBpYDNyI9 n3Y4bJLARscE7gGWONB3CQHalLgpiXWcFWPErE2d1o12C9FDkcXDI1AsrJZB3GWYodMb oqL0kDlMnNwu33dIL1EEnJ2Cem5g8iGvutVW1OYZd+ICrBZZcWy3fKzO9GnJkZEiEgt7 IfcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158771; x=1733763571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gqhiaN/uGHCe7Mq6SZhbOqUmu19X+lhLAzCqw3rcUEU=; b=fxdkscXYQ3MC+oIc3FrnK6s/gkjCQkyXmrCMQGC5NWyP0yMWTkT4yRn8FqM8j0iYa6 yTulT6P7xLmfBIbXAT8EiBCr9RTMgRAblNPt6SS3FfT339XD56ZIXGwqEaqKGwSZV80/ 5Ez+zn5Sh67wciJ49JOJ19cgWxhxAqZRLnSC3F51phgAoHMIbywhd0hGmrhN2q1abzcC mNPZSYbHIa4fUTApv8AOFuv3DIjiG8Y2HquJatjAHitt0RY+sqGKrNKsMq7FdzkpWlRM QsdXDRLgg9DugQtqRE/2W+/OsSsV0N9jzDD481S+a2pn6GnBZY7aTvgh6m3zM+mzhx2J wufw== X-Gm-Message-State: AOJu0YxwlgrdeDxaVCep/I2ckdWTFwXld9ElP5QXmukEXjSR0p28WQtm svIRH4xHWMYFlG0GzbkdEQg5Q2nSwPL1pgcBsSTbqjik6rrMRLPt4xMF+uTAkqWmQ8HGLQj1DdE Q X-Gm-Gg: ASbGncv6O1uhRWVzqnJHvZ5X8l12H7yOWjaJt9UxpDTGY3lPgWo80r1LJGvmNGkoFe8 sYNAvR1AQgBa8YGSQC3xVrrJrFxy3AKnybbI6pP+Q7knMer/01TnxVmQ0OHZwThbwrLwEa+5oda nIoBupUHfHP/GJFdMDyEwqK1SXdejOHx/AMadO0B3ivSqSGdJLTHMxXp115yU4Bkfmzr186Kwv5 /w6kpbOhTwIHMxtD5pK+lOVN0MIQeTkJrxmOsVEivhIwX2mDjoMo90wi676YmQAmKXQUN86OjXQ FWbZf79VCcsVPEGQ5TvpZl2o563WQ2zOn7TaV86kNeLOKhu35SVv X-Google-Smtp-Source: AGHT+IFm581PTU/1OI+wUfh3HI4lQknPI4z33Hs16wQMIfYEoLjGSSJ10EF+CJozUSfhvDZ9SFphnA== X-Received: by 2002:ac2:4e04:0:b0:53d:cbaa:86f5 with SMTP id 2adb3069b0e04-53df00ccbb8mr17030885e87.13.1733158770744; Mon, 02 Dec 2024 08:59:30 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Anthony PERARD , Nick Rosbrook , George Dunlap , Juergen Gross Subject: [PATCH v11 06/12] tools: add support for cache coloring configuration Date: Mon, 2 Dec 2024 17:59:15 +0100 Message-ID: <20241202165921.249585-7-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799311116600 Content-Type: text/plain; charset="utf-8" Add a new "llc_colors" parameter that defines the LLC color assignment for a domain. The user can specify one or more color ranges using the same syntax used everywhere else for color config described in the documentation. The parameter is defined as a list of strings that represent the color ranges. Documentation is also added. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Anthony PERARD --- v11: - turned unsigned int to uint32_t in xc_domain_set_llc_colors() - return -1 in case of error instead of ENOMEM in xc_domain_set_llc_colors() - added regenerated go bindings v10: - no changes v9: - turned warning into error in case of coloring not enabled v8: - warn the user in case of coloring not supported at hypervisor level v7: - removed unneeded NULL check before xc_hypercall_buffer_free() in xc_domain_set_llc_colors() v6: - no edits v5: - added LIBXL_HAVE_BUILDINFO_LLC_COLORS - moved color configuration in xc_domain_set_llc_colors() cause of the new hypercall v4: - removed overlapping color ranges checks during parsing - moved hypercall buffer initialization in libxenctrl --- docs/man/xl.cfg.5.pod.in | 6 +++++ tools/golang/xenlight/helpers.gen.go | 16 ++++++++++++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 5 ++++ tools/include/xenctrl.h | 9 +++++++ tools/libs/ctrl/xc_domain.c | 34 +++++++++++++++++++++++++ tools/libs/light/libxl_create.c | 18 +++++++++++++ tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 38 +++++++++++++++++++++++++++- 9 files changed, 127 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index ac3f88fd57..8e1422104e 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -3074,6 +3074,12 @@ raised. =20 =3Dover 4 =20 +=3Ditem B + +Specify the Last Level Cache (LLC) color configuration for the guest. +B can be either a single color value or a hypen-separated closed +interval of colors (such as "0-4"). + =3Ditem B =20 An optional integer parameter specifying the number of SPIs (Shared diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index fe5110474d..90846ea8e8 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1097,6 +1097,14 @@ if err :=3D x.Iomem[i].fromC(&v); err !=3D nil { return fmt.Errorf("converting field Iomem: %v", err) } } } +x.LlcColors =3D nil +if n :=3D int(xc.num_llc_colors); n > 0 { +cLlcColors :=3D (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.llc_colors))[:n:n] +x.LlcColors =3D make([]uint32, n) +for i, v :=3D range cLlcColors { +x.LlcColors[i] =3D uint32(v) +} +} if err :=3D x.ClaimMode.fromC(&xc.claim_mode);err !=3D nil { return fmt.Errorf("converting field ClaimMode: %v", err) } @@ -1453,6 +1461,14 @@ return fmt.Errorf("converting field Iomem: %v", err) } } } +if numLlcColors :=3D len(x.LlcColors); numLlcColors > 0 { +xc.llc_colors =3D (*C.uint32_t)(C.malloc(C.size_t(numLlcColors*numLlcColor= s))) +xc.num_llc_colors =3D C.int(numLlcColors) +cLlcColors :=3D (*[1<<28]C.uint32_t)(unsafe.Pointer(xc.llc_colors))[:numLl= cColors:numLlcColors] +for i,v :=3D range x.LlcColors { +cLlcColors[i] =3D C.uint32_t(v) +} +} if err :=3D x.ClaimMode.toC(&xc.claim_mode); err !=3D nil { return fmt.Errorf("converting field ClaimMode: %v", err) } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index c9e45b306f..e7667f1ce3 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -575,6 +575,7 @@ SchedParams DomainSchedParams Ioports []IoportRange Irqs []uint32 Iomem []IomemRange +LlcColors []uint32 ClaimMode Defbool EventChannels uint32 Kernel string diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 8d32428ea9..f8fe4afd7d 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1379,6 +1379,11 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, = const libxl_mac *src); */ #define LIBXL_HAVE_BUILDINFO_HVM_SYSTEM_FIRMWARE =20 +/* + * The libxl_domain_build_info has the llc_colors array. + */ +#define LIBXL_HAVE_BUILDINFO_LLC_COLORS 1 + /* * ERROR_REMUS_XXX error code only exists from Xen 4.5, Xen 4.6 and it * is changed to ERROR_CHECKPOINT_XXX in Xen 4.7 diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 29617585c5..d6d93a2e8f 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2667,6 +2667,15 @@ int xc_livepatch_replace(xc_interface *xch, char *na= me, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); =20 +/* + * Set LLC colors for a domain. + * It can only be used directly after domain creation. An attempt to use it + * afterwards will result in an error. + */ +int xc_domain_set_llc_colors(xc_interface *xch, uint32_t domid, + const uint32_t *llc_colors, + uint32_t num_llc_colors); + #if defined(__arm__) || defined(__aarch64__) int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, uint32_t overlay_fdt_size, uint8_t overlay_op); diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e3538ec0ba..2ddc3f4f42 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -2195,6 +2195,40 @@ int xc_domain_soft_reset(xc_interface *xch, domctl.domain =3D domid; return do_domctl(xch, &domctl); } + +int xc_domain_set_llc_colors(xc_interface *xch, uint32_t domid, + const uint32_t *llc_colors, + uint32_t num_llc_colors) +{ + struct xen_domctl domctl =3D {}; + DECLARE_HYPERCALL_BUFFER(uint32_t, local); + int ret =3D -1; + + if ( num_llc_colors ) + { + size_t bytes =3D sizeof(uint32_t) * num_llc_colors; + + local =3D xc_hypercall_buffer_alloc(xch, local, bytes); + if ( local =3D=3D NULL ) + { + PERROR("Could not allocate LLC colors for set_llc_colors"); + goto out; + } + memcpy(local, llc_colors, bytes); + set_xen_guest_handle(domctl.u.set_llc_colors.llc_colors, local); + } + + domctl.cmd =3D XEN_DOMCTL_set_llc_colors; + domctl.domain =3D domid; + domctl.u.set_llc_colors.num_llc_colors =3D num_llc_colors; + + ret =3D do_domctl(xch, &domctl); + +out: + xc_hypercall_buffer_free(xch, local); + + return ret; +} /* * Local variables: * mode: C diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index edeadd57ef..e03599ea99 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -747,6 +747,24 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_con= fig *d_config, /* A new domain now exists */ *domid =3D local_domid; =20 + ret =3D xc_domain_set_llc_colors(ctx->xch, local_domid, + b_info->llc_colors, + b_info->num_llc_colors); + if (ret < 0) { + if (errno =3D=3D EOPNOTSUPP) { + if (b_info->num_llc_colors > 0) { + LOGED(ERROR, local_domid, + "LLC coloring not enabled in the hypervisor"); + rc =3D ERROR_FAIL; + goto out; + } + } else { + LOGED(ERROR, local_domid, "LLC colors allocation faile= d"); + rc =3D ERROR_FAIL; + goto out; + } + } + rc =3D libxl__is_domid_recent(gc, local_domid, &recent); if (rc) goto out; diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 4e65e6fda5..bd4b8721ff 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -616,6 +616,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ ("ioports", Array(libxl_ioport_range, "num_ioports")), ("irqs", Array(uint32, "num_irqs")), ("iomem", Array(libxl_iomem_range, "num_iomem")), + ("llc_colors", Array(uint32, "num_llc_colors")), ("claim_mode", libxl_defbool), ("event_channels", uint32), ("kernel", string), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index e3a4800f6e..3d85be7dd4 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1296,7 +1296,7 @@ void parse_config_data(const char *config_source, XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, *usbctrls, *usbdevs, *p9devs, *vdispls, *pvcallsifs_dev= s; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, - *mca_caps, *smbios; + *mca_caps, *smbios, *llc_colors; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_= caps; int num_smbios; int pci_power_mgmt =3D 0; @@ -1304,6 +1304,7 @@ void parse_config_data(const char *config_source, int pci_permissive =3D 0; int pci_seize =3D 0; int i, e; + int num_llc_colors; char *kernel_basename; =20 libxl_domain_create_info *c_info =3D &d_config->c_info; @@ -1447,6 +1448,41 @@ void parse_config_data(const char *config_source, if (!xlu_cfg_get_long (config, "maxmem", &l, 0)) b_info->max_memkb =3D l * 1024; =20 + if (!xlu_cfg_get_list(config, "llc_colors", &llc_colors, &num_llc_colo= rs, 0)) { + int cur_index =3D 0; + + b_info->num_llc_colors =3D 0; + for (i =3D 0; i < num_llc_colors; i++) { + uint32_t start =3D 0, end =3D 0, k; + + buf =3D xlu_cfg_get_listitem(llc_colors, i); + if (!buf) { + fprintf(stderr, + "xl: Can't get element %d in LLC color list\n", i); + exit(1); + } + + if (sscanf(buf, "%" SCNu32 "-%" SCNu32, &start, &end) !=3D 2) { + if (sscanf(buf, "%" SCNu32, &start) !=3D 1) { + fprintf(stderr, "xl: Invalid LLC color range: %s\n", b= uf); + exit(1); + } + end =3D start; + } else if (start > end) { + fprintf(stderr, + "xl: Start LLC color is greater than end: %s\n", b= uf); + exit(1); + } + + b_info->num_llc_colors +=3D (end - start) + 1; + b_info->llc_colors =3D (uint32_t *)realloc(b_info->llc_colors, + sizeof(*b_info->llc_colors) * b_info->num_llc_colo= rs); + + for (k =3D start; k <=3D end; k++) + b_info->llc_colors[cur_index++] =3D k; + } + } + if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) { vcpus =3D l; if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, l)) { --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158798; cv=none; d=zohomail.com; s=zohoarc; b=oCpuoKcByf7bR/7xIpKe2AcXSTytkUzTpQ8xoxobHznC7KpyrbhMLe0yKBodB4SyTC/E3w73ItOCEONZaGBMRtqVtO4wyIoenimSZrIRE4CBOYLmjhFdNNov5o0/a/q4IV4yApc/2RfoYMyuS32ZydEy843U2skDvksZ8VVx74I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158798; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ppPQl9w5dBFddHDYD8Vy/EIAYsGbht/mLYkRtxhgMrM=; b=hXJBBBoPUI5VKmWCZSijY751LhoOmta7pvHlayeliRHpxo1hWaDiVkYMS86cdH3RmLrXpyeqh/Y+i4we48Q234mRKWpKsez0LUJG62SIU08yXD/japeUsHWz+tmIX0WzHTMnzGKvmTFMaAQMyLeyHzF5Ig2IXiG8IVxOG45NVJk= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158798307529.5624247540813; Mon, 2 Dec 2024 08:59:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846768.1261966 (Exim 4.92) (envelope-from ) id 1tI9ln-0008SG-9G; Mon, 02 Dec 2024 16:59:35 +0000 Received: by outflank-mailman (output) from mailman id 846768.1261966; Mon, 02 Dec 2024 16:59:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9ln-0008Qy-1B; Mon, 02 Dec 2024 16:59:35 +0000 Received: by outflank-mailman (input) for mailman id 846768; Mon, 02 Dec 2024 16:59:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9ll-0006wq-Fl for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:33 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cd4d04ac-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:32 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-aa5b0d8bd41so540602366b.2 for ; Mon, 02 Dec 2024 08:59:32 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:31 -0800 (PST) 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: cd4d04ac-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158772; x=1733763572; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ppPQl9w5dBFddHDYD8Vy/EIAYsGbht/mLYkRtxhgMrM=; b=q6EsyGZqD7xrIsPzNY/3Rqh0edToIz7ru20l5BLYkDUo88AoTxJ/jaihv1sRywvUnA R2HJSJGpJCfnMbqfrHbKsrWuyFZerk2J3Liqvt9xHFeJtSMzyg7bD3XhgxfCHg9D9WzG xAZVSb8DWvUIZjU1tHGFr21TAXdXiaiqAQgjPsQbTXRCPTE+/QwMzNciTWjdO+Cn0jfh OX5snsIt02M2+cm5ah/U+8RaNecZZmlqc/gwf0LZyE0jXSMnhYZRW97ha2iQ2hopjBHt hugjDz8O6hov9tg0V3cSKAB/q4ntntktM7Ok5BTBkc7lbMDme1WP1MyQe+EJPVtby7B2 Ce7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158772; x=1733763572; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ppPQl9w5dBFddHDYD8Vy/EIAYsGbht/mLYkRtxhgMrM=; b=W11/d2bf62aO40ZZZA8DkiIQem2khG5Qu20FDn/V8noxTbF6eOcNkpI6rzDArOJdx3 6mVu0pPfo2VzAAFnTgPdQlEvsfp0Xh0pfggzgOg8K3YgKQ06G5G4lQ1eivgc9zDIFxcS rUgYMrpVUt7NmgwJBxu6ndrU23ZdblkL8l+g74GhorYAtxYSPq2JDe9XpZLYG8vXdt8B /S2imVfJjdbZQJpShdJ0JwvD7FbCExhVYOHn9J2QYgLu7piC///MtcTEMc1oL9Z8Pi3D AIrqbcfqIfAVS/MnTfUBxbq/Xzdpuv218k/uk2iM/JfKoSjk00OLT/7r/B/eN0E3R7j5 trwA== X-Gm-Message-State: AOJu0YzHJ1PRnumOHRex83cZ5Cn1RkBAHoka6lck+Dy+qLAn1qULyWUT XOh1lM1ztij/fxI1FUfDaFBxUM8Vnc0aeWzatKAf9KVT0qw7McOclpnQzujafhnmgQE3klwa19w H X-Gm-Gg: ASbGncu4o6bIw+CTNm2MJ9c9O1l6MVIA7Vgi0JXAcZpfBswGHFjOBExN+xMD+P/3dPR c2cSSzcHJGcNYPDE2yYrW0Im2se/9G06gI83Fdga5oXtBBY1xZza707QdrTLY87QXBVgBnxp6b9 GEpCNT7xRzdKnAbuv1UEHOgFgrjUpAjD/OwSd6iZ3IkhhBxkHLBu9yKfnf1mxhz2F+UwbJu5lOL WezkPMCosWrFWllT+I7ckJKvauWJmoQb2mg6o5Yjn1pNHgpV4tuVk6qlWgZMXsH0orWUFeekhaL CxX9aW/X62IcefpShfU1yod+qDA47yOhCbuuwINNlnGm9nP4ZLHj X-Google-Smtp-Source: AGHT+IGjX7fCpJbm3uAUYe0AcHx2T+eRrdwJ4BdABtf082bgnzFYleij+K9H4TXHjRTsnFgt6zcLjQ== X-Received: by 2002:a17:906:1daa:b0:aa5:1d33:dc10 with SMTP id a640c23a62f3a-aa581041505mr1928713866b.45.1733158771845; Mon, 02 Dec 2024 08:59:31 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Jan Beulich Subject: [PATCH v11 07/12] xen/arm: add support for cache coloring configuration via device-tree Date: Mon, 2 Dec 2024 17:59:16 +0100 Message-ID: <20241202165921.249585-8-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799514116600 Content-Type: text/plain; charset="utf-8" Add the "llc-colors" Device Tree property to express DomUs and Dom0less color configurations. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Jan Beulich # non-Arm Reviewed-by: Michal Orzel --- v11: - made clear that llc-colors device-tree property is Arm64-only in booting.= txt v10: - no changes v9: - use best-effort allocation in domain_set_llc_colors_from_str() v8: - fixed memory leak on error path of domain_set_llc_colors_from_str() - realloc colors array after parsing from string to reduce memory usage v7: - removed alloc_colors() helper usage from domain_set_llc_colors_from_str() v6: - rewrote domain_set_llc_colors_from_str() to be more explicit v5: - static-mem check has been moved in a previous patch - added domain_set_llc_colors_from_str() to set colors after domain creation --- docs/misc/arm/device-tree/booting.txt | 5 +++ docs/misc/cache-coloring.rst | 48 +++++++++++++++++++++++++++ xen/arch/arm/dom0less-build.c | 10 ++++++ xen/common/llc-coloring.c | 40 ++++++++++++++++++++++ xen/include/xen/llc-coloring.h | 1 + xen/include/xen/xmalloc.h | 12 +++++++ 6 files changed, 116 insertions(+) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index 3a04f5c57f..9c881baccc 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -162,6 +162,11 @@ with the following properties: =20 An integer specifying the number of vcpus to allocate to the guest. =20 +- llc-colors + A string specifying the LLC color configuration for the guest. + Refer to docs/misc/cache_coloring.rst for syntax. This option is appli= cable + only to Arm64 guests. + - vpl011 =20 An empty property to enable/disable a virtual pl011 for the guest to diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst index 7b47d0ed92..e097e74032 100644 --- a/docs/misc/cache-coloring.rst +++ b/docs/misc/cache-coloring.rst @@ -14,6 +14,7 @@ If needed, change the maximum number of colors with ``CONFIG_LLC_COLORS_ORDER=3D``. =20 Runtime configuration is done via `Command line parameters`_. +For DomUs follow `DomUs configuration`_. =20 Background ********** @@ -149,6 +150,53 @@ LLC specs can be manually set via the above command li= ne parameters. This bypasses any auto-probing and it's used to overcome failing situations, su= ch as flawed probing logic, or for debugging/testing purposes. =20 +DomUs configuration +******************* + +DomUs colors can be set either in the ``xl`` configuration file (documenta= tion +at `docs/man/xl.cfg.pod.5.in`) or via Device Tree (documentation at +`docs/misc/arm/device-tree/booting.txt`) using the ``llc-colors`` option. +For example: + +:: + + xen,xen-bootargs =3D "console=3Ddtuart dtuart=3Dserial0 dom0_mem=3D1G = dom0_max_vcpus=3D1 sched=3Dnull llc-coloring=3Don dom0-llc-colors=3D2-6"; + xen,dom0-bootargs "console=3Dhvc0 earlycon=3Dxen earlyprintk=3Dxen roo= t=3D/dev/ram0" + + dom0 { + compatible =3D "xen,linux-zimage" "xen,multiboot-module"; + reg =3D <0x0 0x1000000 0x0 15858176>; + }; + + dom0-ramdisk { + compatible =3D "xen,linux-initrd" "xen,multiboot-module"; + reg =3D <0x0 0x2000000 0x0 20638062>; + }; + + domU0 { + #address-cells =3D <0x1>; + #size-cells =3D <0x1>; + compatible =3D "xen,domain"; + memory =3D <0x0 0x40000>; + llc-colors =3D "4-8,10,11,12"; + cpus =3D <0x1>; + vpl011 =3D <0x1>; + + module@2000000 { + compatible =3D "multiboot,kernel", "multiboot,module"; + reg =3D <0x2000000 0xffffff>; + bootargs =3D "console=3DttyAMA0"; + }; + + module@30000000 { + compatible =3D "multiboot,ramdisk", "multiboot,module"; + reg =3D <0x3000000 0xffffff>; + }; + }; + +**Note:** If no color configuration is provided for a domain, the default = one, +which corresponds to all available colors is used instead. + Known issues and limitations **************************** =20 diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 67b1503647..49d1f14d65 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -817,6 +817,7 @@ void __init create_domUs(void) bool iommu =3D false; const struct dt_device_node *cpupool_node, *chosen =3D dt_find_node_by_path("/chosen"= ); + const char *llc_colors_str =3D NULL; =20 BUG_ON(chosen =3D=3D NULL); dt_for_each_child_node(chosen, node) @@ -965,6 +966,10 @@ void __init create_domUs(void) #endif } =20 + dt_property_read_string(node, "llc-colors", &llc_colors_str); + if ( !llc_coloring_enabled && llc_colors_str ) + panic("'llc-colors' found, but LLC coloring is disabled\n"); + /* * The variable max_init_domid is initialized with zero, so here i= t's * very important to use the pre-increment operator to call @@ -975,6 +980,11 @@ void __init create_domUs(void) panic("Error creating domain %s (rc =3D %ld)\n", dt_node_name(node), PTR_ERR(d)); =20 + if ( llc_coloring_enabled && + (rc =3D domain_set_llc_colors_from_str(d, llc_colors_str)) ) + panic("Error initializing LLC coloring for domain %s (rc =3D %= d)\n", + dt_node_name(node), rc); + d->is_console =3D true; dt_device_set_used_by(node, d->domain_id); =20 diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 2a0ee695c8..2a85345cf1 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -277,6 +277,46 @@ void domain_llc_coloring_free(struct domain *d) xfree(__va(__pa(d->llc_colors))); } =20 +int __init domain_set_llc_colors_from_str(struct domain *d, const char *st= r) +{ + int err; + unsigned int *colors, num_colors; + + if ( !str ) + { + domain_set_default_colors(d); + return 0; + } + + colors =3D xmalloc_array(unsigned int, max_nr_colors); + if ( !colors ) + return -ENOMEM; + + err =3D parse_color_config(str, colors, max_nr_colors, &num_colors); + if ( err ) + { + printk(XENLOG_ERR "Error parsing LLC color configuration"); + xfree(colors); + return err; + } + + if ( !check_colors(colors, num_colors) ) + { + printk(XENLOG_ERR "%pd: bad LLC color config\n", d); + xfree(colors); + return -EINVAL; + } + + /* Adjust the size cause it was initially set to max_nr_colors */ + d->llc_colors =3D xrealloc_array(colors, num_colors); + if ( !d->llc_colors ) + d->llc_colors =3D colors; + + d->num_llc_colors =3D num_colors; + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index cbebe0816c..ae8a8825e5 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -32,6 +32,7 @@ void arch_llc_coloring_init(void); int dom0_set_llc_colors(struct domain *d); int domain_set_llc_colors(struct domain *d, const struct xen_domctl_set_llc_colors *config); +int domain_set_llc_colors_from_str(struct domain *d, const char *str); =20 #endif /* __XEN_LLC_COLORING_H__ */ =20 diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index b903fa2e26..f0412fb4e0 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -37,6 +37,9 @@ ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) #define xzalloc_array(_type, _num) \ ((_type *)_xzalloc_array(sizeof(_type), __alignof__(_type), _num)) +#define xrealloc_array(_ptr, _num) \ + ((typeof(_ptr))_xrealloc_array(_ptr, sizeof(typeof(*(_ptr))), \ + __alignof__(typeof(*(_ptr))), _num)) =20 /* Allocate space for a structure with a flexible array of typed objects. = */ #define xzalloc_flex_struct(type, field, nr) \ @@ -98,6 +101,15 @@ static inline void *_xzalloc_array( return _xzalloc(size * num, align); } =20 +static inline void *_xrealloc_array( + void *ptr, unsigned long size, unsigned long align, unsigned long num) +{ + /* Check for overflow. */ + if ( size && num > UINT_MAX / size ) + return NULL; + return _xrealloc(ptr, size * num, align); +} + /* * Pooled allocator interface. */ --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158798; cv=none; d=zohomail.com; s=zohoarc; b=NAEqd+XfuvcI4paxm1D5uvlxo/vLdEXRmqazFMJgs3bbaFKXdLIVGecUVw0/sH49Bk/d4FGKTkTetu9RM9U319ZBjngkkjzs+RpkgCkMB6nNWzgwDh8O+UCn7dCHAHjw24QbDnHu4NtGRaHNacoQ079JpwPZW9SIujUFXb5vDCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158798; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Jo1+hlLxBc+2E+3aaQJBdv0vb2kf6V0j/TqdNW1tAOE=; b=HfvlOi0xF6AEwjVEqU+VqBWXI/fz1dV9zeRhRQvotWB9d8Iir6R2Uep0YcTcuVlz1k3UoPeAqzGuhHQHCozeiUtMNTQuztuq8lyo9CgyI/Qka4bpKI9aYnyBI0uN1WvGuszbflUZg1mDVSP31/kC+pbye//b0wOqeU7ylc7y9bw= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158798527815.3591308613416; Mon, 2 Dec 2024 08:59:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846771.1261981 (Exim 4.92) (envelope-from ) id 1tI9lp-0000UF-0V; Mon, 02 Dec 2024 16:59:37 +0000 Received: by outflank-mailman (output) from mailman id 846771.1261981; Mon, 02 Dec 2024 16:59:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lo-0000Tz-Pz; Mon, 02 Dec 2024 16:59:36 +0000 Received: by outflank-mailman (input) for mailman id 846771; Mon, 02 Dec 2024 16:59:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9ln-0006x4-9c for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:35 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cdcea3f1-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:33 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-aa543c4db92so666974066b.0 for ; Mon, 02 Dec 2024 08:59:33 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:32 -0800 (PST) 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: cdcea3f1-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158773; x=1733763573; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jo1+hlLxBc+2E+3aaQJBdv0vb2kf6V0j/TqdNW1tAOE=; b=V/hCI906gyUME2CtsMSrQvcJpfmcETVyGJyIWfdJCJ+Dmym0H4sLHnF3tUIZFPceER 2GVX5lzZCB/8ugVb6p6YTsWq2tQTjF3Br+4i5XzTbqAanJgYcguTlGIWucwPXXCk6O7F lKcjmwA2cCWk6CKcx5vkUBPhfegSZ3uY3zC+7FrL1ZPRAIMQyAYf3y04sWMUcF3OXrCS RHMW6y1oAUDBiLTlnU0NmoM8nySXBwMDVaod62TdtfGYLcXyaC8Kz8czeb5D+BccA0Xf Z87eMwkquz8ktO4fEYodQm0d6ip5sKNfnDrIjkhCbX0Q9RXsIS22PSkh+NfMvapFJ3r5 hefw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158773; x=1733763573; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jo1+hlLxBc+2E+3aaQJBdv0vb2kf6V0j/TqdNW1tAOE=; b=MkhlMgIE5XcyS4l01fnLbpSAwzugFjHML9K3zW4p7br0ihAOxvy0x3ZUZTwgf2lCaL SCCWSsGHp82n4Ggbuy+F4Mq5WQO0ltIwWstRnxznKUiMK9ZOfV++ZCbHO6Y1PsIACsBW IMj98SfHRmasXmTYx49MiNiVa9N+DKwAoW9ZdlxNX0WYWMKmkRdrNt+OEZ2SYnKWxerb 3rW7nPIS0YD/qiRrmQZ4XOjcEH/hH71Y2RweZ4NAm+LU3mdNZ+HXY8MIB66kU3WrIGtZ f7U192j5yhKBQFW6QpQz/gmCd6nRyVTxo2Tsj54GFriIFYmdkQtitgRFqo/nXGf9gtp5 Pi5w== X-Gm-Message-State: AOJu0YxHs1u1CcQVcflK9Jv55ZTbhxDzqRHYKu2+qfFOwownz3yKiHtU dZ4EhIh6xgnKb65DiJdpxjtkNfRH9nWpQUxZATO6QoN12hd4juOcYcTmFYLeTe8fD6Aj0+ck4hP a X-Gm-Gg: ASbGnctdbcww/jxqsw2j/Eq4YEiNDH3qRe14jxvZ0t5gZCKbw8Q/J2P3DRHyb/NcOXA +i9+hyzduPqoT3V17SDFA3DtS2OfCqy8Jwl5PiJbk9WjJz0xZcEIqrPsdLTdDf7JePF0mZryHdz IpXxj/RX7hbJuX7tV5hlWShNvCb9vgNm6yoI78Hx4LLP10mDXAC1ELEjwsYPvIcV3u7gLQHZ7P/ Fv9yJ4D5uSSR8nAWyrn5YabPQDQJ6gxZgNZaosu8/Eq/8PHKdnwf2VYpVDv4KlYuW1HZTS60iOe ajbhl36QYp3LK7iEvzjLnVsj84yECE+xvJxP+EC0JbMIr5byEAPg X-Google-Smtp-Source: AGHT+IFR0lxo0qW7rgGGz6p/lTSVqQksARCF+uwg/BOh7xiEKCWmRLJ2vEox2DuIuRXNxSvX4lKEFQ== X-Received: by 2002:a17:906:329a:b0:aa5:1d08:dacf with SMTP id a640c23a62f3a-aa580f01a6amr2077894266b.13.1733158772840; Mon, 02 Dec 2024 08:59:32 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v11 08/12] xen/page_alloc: introduce preserved page flags macro Date: Mon, 2 Dec 2024 17:59:17 +0100 Message-ID: <20241202165921.249585-9-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799377116600 Content-Type: text/plain; charset="utf-8" PGC_static and PGC_extra need to be preserved when assigning a page. Define a new macro that groups those flags and use it instead of or'ing every time. Signed-off-by: Carlo Nonato --- v11: - removed PGC_broken from PGC_preserved - removed PGC preservation from mark_page_free() v10: - fixed commit message v9: - add PGC_broken to PGC_preserved - clear PGC_extra in alloc_domheap_pages() only if MEMF_no_refcount is set v8: - fixed PGC_extra ASSERT fail in alloc_domheap_pages() by removing PGC_extra before freeing v7: - PGC_preserved used also in mark_page_free() v6: - preserved_flags renamed to PGC_preserved - PGC_preserved is used only in assign_pages() v5: - new patch --- xen/common/page_alloc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 55d561e93c..e73b404169 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -161,6 +161,7 @@ #endif =20 #define PGC_no_buddy_merge PGC_static +#define PGC_preserved (PGC_extra | PGC_static) =20 #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 @@ -1447,8 +1448,7 @@ static bool mark_page_free(struct page_info *pg, mfn_= t mfn) break; =20 case PGC_state_offlining: - pg->count_info =3D (pg->count_info & PGC_broken) | - PGC_state_offlined; + pg->count_info =3D (pg->count_info & PGC_broken) | PGC_state_offli= ned; pg_offlined =3D true; break; =20 @@ -2382,7 +2382,7 @@ int assign_pages( =20 for ( i =3D 0; i < nr; i++ ) { - ASSERT(!(pg[i].count_info & ~(PGC_extra | PGC_static))); + ASSERT(!(pg[i].count_info & ~PGC_preserved)); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2442,7 +2442,7 @@ int assign_pages( page_set_owner(&pg[i], d); smp_wmb(); /* Domain pointer must be visible before updating refcn= t. */ pg[i].count_info =3D - (pg[i].count_info & (PGC_extra | PGC_static)) | PGC_allocated = | 1; + (pg[i].count_info & PGC_preserved) | PGC_allocated | 1; =20 page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } @@ -2501,6 +2501,14 @@ struct page_info *alloc_domheap_pages( } if ( assign_page(pg, order, d, memflags) ) { + if ( memflags & MEMF_no_refcount ) + { + unsigned long i; + + for ( i =3D 0; i < (1UL << order); i++ ) + pg[i].count_info &=3D ~PGC_extra; + } + free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; } @@ -2555,6 +2563,7 @@ void free_domheap_pages(struct page_info *pg, unsigne= d int order) { ASSERT(d->extra_pages); d->extra_pages--; + pg[i].count_info &=3D ~PGC_extra; } } =20 --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158797; cv=none; d=zohomail.com; s=zohoarc; b=QzhUR6absmYM6q4Y/ALahA/py3ZSukyREeu22u2fiA8sAjgvC8ORAdWVypyNJWkaCGp1aY88SXe3J3iYKX8UUosyAkTyHRxgNYU5ibPbWmnSmtK0raZU5RYo1HhA7hPB/AMS4mavOjR7E2GTmvozMbLVN7rdspFAHrE/xlbVeBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158797; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5jmTpoIsSrEVNjy7/04k9RPLkrs/AHNOCuox3jJ6UZQ=; b=SFDil71a4AtCZnPk2BqZlR3mSz/7l1XFI+0VUNKZYmEtSo9t/WDzi/wa7guz0Iqt+HZ/dmGTGdEmWR8dueA1ljfP9noUNWHFvty3mjyegkI6WEGRliBgri/lK4zJH0qLoJLULyE6umAp8iZrueoVATtAmQj9mZH2kqPv1EgplII= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158797778588.0122432060447; Mon, 2 Dec 2024 08:59:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846774.1261998 (Exim 4.92) (envelope-from ) id 1tI9lr-0000tt-80; Mon, 02 Dec 2024 16:59:39 +0000 Received: by outflank-mailman (output) from mailman id 846774.1261998; Mon, 02 Dec 2024 16:59:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lr-0000sq-3E; Mon, 02 Dec 2024 16:59:39 +0000 Received: by outflank-mailman (input) for mailman id 846774; Mon, 02 Dec 2024 16:59:37 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lp-0006x4-9d for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:37 +0000 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [2a00:1450:4864:20::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ce99f3f6-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:34 +0100 (CET) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-aa543c4db92so666977666b.0 for ; Mon, 02 Dec 2024 08:59:34 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:33 -0800 (PST) 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: ce99f3f6-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158774; x=1733763574; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5jmTpoIsSrEVNjy7/04k9RPLkrs/AHNOCuox3jJ6UZQ=; b=fWM7wCg1jia36eQXta8xhvb4zi+evnv1DufJWIWz4NwaMAG7cf1PGF7sx9AUwKNfWv yVR6KciTVD/Lzw1EXLKL+YRQG3q/Op9cHoypiVs9yngSJx5d5bboxTINFxJMG7XmKc+U ax5TR0337xenK2ZFW94Gu9ZdbK8GWZPMcKJmVw9hLwdcVjRePzvRHkwt4qa1yioe/APt oOsjUT5s521cXWSqHqbwo/fzGy+mhyLRuYcRrrAK1j2Sq8T9BpbH+GqfyYKY2hkzOaG8 RX1C3VWR772Q3yv19/IbWTMk0qG7msL304jRDCvxWKsMZwIuIUyUWEVSi/kBa4rNlqvw Xhbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158774; x=1733763574; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5jmTpoIsSrEVNjy7/04k9RPLkrs/AHNOCuox3jJ6UZQ=; b=U+yz/C26yOUmZSr/ansxqTL6rIMxSUNRkDnHtLzZtCUH+T6knSYi0wBeyvWe0EOtQh UFf5L3dqCpDWekwVfGVJpy92F6uugclAhg3R1QK3R0cPwhepD/XYeHYLOJlaibI/cumT w+QdC48D8HKSaT/SZ+Zy2a1dihfehLYzw5OD0gf2vxP747DDLZqQ2UGckU2C9x3ksJEz xZOXAtG6vGeKNu+Y+tRZA8PSHEe81/UXh+OyCBU9o5xL+SyV8OFXBtfCzH4P7ECyTKnh Sypww6go9XaT0E4XK6b22AgQ+Gl2pbapVRfhh8mgJXFRbDimK4nPf+Xa/uyWlvobk5Nl jWUA== X-Gm-Message-State: AOJu0Yxr7rLDo7do7YrjeADoX0rn2/GrHdSaUZx4FpLWZCzAWFG9fcWu 6nqTs33A4qJYFE/U6vepvOyfP0Z9BmvNMjHoa99+Y3yVBgnX67OnTZecpbefMw4hqCA7zj/vnhT A X-Gm-Gg: ASbGncsZShLy5i4D3ZLIvh9meC4CE8H4ANg3xVj+DOObD5TEW1YSIf5rzAgZAUdTWfF LmUtxz+1p0o1T6gS4hezTZd0EbDpGYZ0jp387+Wc+IUj9vOFoQftCbPTT3Us8detwHZYLTma22u Ng5yLAjDYYdqhItBWGiqS6J/kAyFrA1ril4fUxk4k+hUKZmT2gD6mMQ75L+Te8Ilp+FrIENe/TA nTr/6KLSdd8eKX6VN3Lof9WctNFG/j/05caLmVPfori53MwgXEYRnAfCb0mIwHmBYRjJLLYqYkf N/ECKZqmyqcC4zKMg6szujwJrq85MeFbGT/dvS3iscy3quoR/AkC X-Google-Smtp-Source: AGHT+IFEuCFDELQO7TRdcBoHJN5Jfc+bCWUrh5rO84iI5OBTaOWeGikUxGR6zgDDV7n9Pdg61F2/Iw== X-Received: by 2002:a17:906:310d:b0:aa5:1551:99f0 with SMTP id a640c23a62f3a-aa580f3336dmr1632815966b.30.1733158773801; Mon, 02 Dec 2024 08:59:33 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 09/12] xen: add cache coloring allocator for domains Date: Mon, 2 Dec 2024 17:59:18 +0100 Message-ID: <20241202165921.249585-10-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799513116600 Content-Type: text/plain; charset="utf-8" Add a new memory page allocator that implements the cache coloring mechanis= m. The allocation algorithm enforces equal frequency distribution of cache partitions, following the coloring configuration of a domain. This allows for an even utilization of cache sets for every domain. Pages are stored in a color-indexed array of lists. Those lists are filled by a simple init function which computes the color of each page. When a domain requests a page, the allocator extracts the page from the list with the maximum number of free pages among those that the domain can acces= s, given its coloring configuration. The allocator can only handle requests of order-0 pages. This allows for easier implementation and since cache coloring targets only embedded system= s, it's assumed not to be a major problem. The buddy allocator must coexist with the colored one because the Xen heap isn't colored. For this reason a new Kconfig option and a command line parameter are added to let the user set the amount of memory reserved for the buddy allocator. Even when cache coloring is enabled, this memory isn't managed by the colored allocator. Colored heap information is dumped in the dump_heap() debug-key function. Based on original work from: Luca Miccio Signed-off-by: Marco Solieri Signed-off-by: Carlo Nonato Reviewed-by: Jan Beulich --- v11: - CONFIG_BUDDY_ALLOCATOR_SIZE depends on CONFIG_LLC_COLORING - buddy_alloc_size is defined only if CONFIG_LLC_COLORING - buddy-alloc-size param is parsed only if CONFIG_LLC_COLORING v10: - stated explicit dependency on CONFIG_LLC_COLORING for buddy-alloc-size - fix for MISRA rule 20.7 parenthesis v9: - added ASSERT(order =3D=3D 0) when freeing a colored page - moved buddy_alloc_size initialization logic in Kconfig v8: - requests that uses MEMF_* flags that can't be served are now going to fail - free_color_heap_page() is called directly from free_heap_pages() v7: - requests to alloc_color_heap_page() now fail if MEMF_bits is used v6: - colored allocator functions are now static v5: - Carlo Nonato as the new author - the colored allocator balances color usage for each domain and it searches linearly only in the number of colors (FIXME removed) - addedd scrub functionality - removed stub functions (still requires some macro definition) - addr_to_color turned to mfn_to_color for easier operations - removed BUG_ON in init_color_heap_pages() in favor of panic() - only non empty page lists are logged in dump_color_heap() v4: - moved colored allocator code after buddy allocator because it now has some dependencies on buddy functions - buddy_alloc_size is now used only by the colored allocator - fixed a bug that allowed the buddy to merge pages when they were colored - free_color_heap_page() now calls mark_page_free() - free_color_heap_page() uses of the frametable array for faster searches - added FIXME comment for the linear search in free_color_heap_page() - removed alloc_color_domheap_page() to let the colored allocator exploit some more buddy allocator code - alloc_color_heap_page() now allocs min address pages first - reduced the mess in end_boot_allocator(): use the first loop for init_color_heap_pages() - fixed page_list_add_prev() (list.h) since it was doing the opposite of what it was supposed to do - fixed page_list_add_prev() (non list.h) to check also for next existence - removed unused page_list_add_next() - moved p2m code in another patch --- docs/misc/cache-coloring.rst | 37 ++++++ docs/misc/xen-command-line.pandoc | 14 +++ xen/arch/arm/include/asm/mm.h | 5 + xen/common/Kconfig | 8 ++ xen/common/llc-coloring.c | 13 ++ xen/common/page_alloc.c | 191 +++++++++++++++++++++++++++++- xen/include/xen/llc-coloring.h | 3 + 7 files changed, 267 insertions(+), 4 deletions(-) diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst index e097e74032..5224b27afe 100644 --- a/docs/misc/cache-coloring.rst +++ b/docs/misc/cache-coloring.rst @@ -13,6 +13,9 @@ To compile LLC coloring support set ``CONFIG_LLC_COLORING= =3Dy``. If needed, change the maximum number of colors with ``CONFIG_LLC_COLORS_ORDER=3D``. =20 +If needed, change the buddy allocator reserved size with +``CONFIG_BUDDY_ALLOCATOR_SIZE=3D``. + Runtime configuration is done via `Command line parameters`_. For DomUs follow `DomUs configuration`_. =20 @@ -110,6 +113,8 @@ Specific documentation is available at `docs/misc/xen-c= ommand-line.pandoc`. +----------------------+-------------------------------+ | ``dom0-llc-colors`` | Dom0 color configuration | +----------------------+-------------------------------+ +| ``buddy-alloc-size`` | Buddy allocator reserved size | ++----------------------+-------------------------------+ =20 Colors selection format *********************** @@ -197,6 +202,17 @@ For example: **Note:** If no color configuration is provided for a domain, the default = one, which corresponds to all available colors is used instead. =20 +Colored allocator and buddy allocator +************************************* + +The colored allocator distributes pages based on color configurations of +domains so that each domains only gets pages of its own colors. +The colored allocator is meant as an alternative to the buddy allocator be= cause +its allocation policy is by definition incompatible with the generic one. = Since +the Xen heap is not colored yet, we need to support the coexistence of the= two +allocators and some memory must be left for the buddy one. Buddy memory +reservation is configured via Kconfig or via command-line. + Known issues and limitations **************************** =20 @@ -207,3 +223,24 @@ In the domain configuration, "xen,static-mem" allows m= emory to be statically allocated to the domain. This isn't possible when LLC coloring is enabled, because that memory can't be guaranteed to use only colors assigned to the domain. + +Cache coloring is intended only for embedded systems +#################################################### + +The current implementation aims to satisfy the need of predictability in +embedded systems with small amount of memory to be managed in a colored wa= y. +Given that, some shortcuts are taken in the development. Expect worse +performances on larger systems. + +Colored allocator can only make use of order-0 pages +#################################################### + +The cache coloring technique relies on memory mappings and on the smallest +mapping granularity to achieve the maximum number of colors (cache partiti= ons) +possible. This granularity is what is normally called a page and, in Xen +terminology, the order-0 page is the smallest one. The fairly simple +colored allocator currently implemented, makes use only of such pages. +It must be said that a more complex one could, in theory, adopt higher ord= er +pages if the colors selection contained adjacent colors. Two subsequent co= lors, +for example, can be represented by an order-1 page, four colors correspond= to +an order-2 page, etc. diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index bfdc8b0002..3a70c49c05 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -270,6 +270,20 @@ and not running softirqs. Reduce this if softirqs are = not being run frequently enough. Setting this to a high value may cause boot failure, particularly = if the NMI watchdog is also enabled. =20 +### buddy-alloc-size (arm64) +> `=3D ` + +> Default: `64M` + +Amount of memory reserved for the buddy allocator when colored allocator is +active. This option is available only when `CONFIG_LLC_COLORING` is enable= d. +The colored allocator is meant as an alternative to the buddy allocator, +because its allocation policy is by definition incompatible with the gener= ic +one. Since the Xen heap systems is not colored yet, we need to support the +coexistence of the two allocators for now. This parameter, which is option= al +and for expert only, it's used to set the amount of memory reserved to the +buddy allocator. + ### cet =3D List of [ shstk=3D, ibt=3D ] =20 diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 5abd4b0d1c..c1a5ac7bee 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -145,6 +145,11 @@ struct page_info #else #define PGC_static 0 #endif +#ifdef CONFIG_LLC_COLORING +/* Page is cache colored */ +#define _PGC_colored PG_shift(4) +#define PGC_colored PG_mask(1, 4) +#endif /* ... */ /* Page is broken? */ #define _PGC_broken PG_shift(7) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index b4ec6893be..6166327f4d 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -537,4 +537,12 @@ config LLC_COLORS_ORDER The default value corresponds to an 8 MiB 16-ways LLC, which should be more than what's needed in the general case. =20 +config BUDDY_ALLOCATOR_SIZE + int "Buddy allocator reserved memory size (MiB)" + default "64" + depends on LLC_COLORING + help + Amount of memory reserved for the buddy allocator to serve Xen heap, + working alongside the colored one. + endmenu diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 2a85345cf1..0f22a9b72c 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -32,6 +32,9 @@ static unsigned int __ro_after_init default_colors[NR_LLC= _COLORS]; static unsigned int __initdata dom0_colors[NR_LLC_COLORS]; static unsigned int __initdata dom0_num_colors; =20 +#define mfn_color_mask (max_nr_colors - 1) +#define mfn_to_color(mfn) (mfn_x(mfn) & mfn_color_mask) + /* * Parse the coloring configuration given in the buf string, following the * syntax below. @@ -317,6 +320,16 @@ int __init domain_set_llc_colors_from_str(struct domai= n *d, const char *str) return 0; } =20 +unsigned int page_to_llc_color(const struct page_info *pg) +{ + return mfn_to_color(page_to_mfn(pg)); +} + +unsigned int get_max_nr_llc_colors(void) +{ + return max_nr_colors; +} + /* * Local variables: * mode: C diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index e73b404169..a1133cfd89 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -139,6 +139,7 @@ #include #include #include +#include =20 #include #include @@ -160,8 +161,12 @@ #define PGC_static 0 #endif =20 -#define PGC_no_buddy_merge PGC_static -#define PGC_preserved (PGC_extra | PGC_static) +#ifndef PGC_colored +#define PGC_colored 0 +#endif + +#define PGC_no_buddy_merge (PGC_static | PGC_colored) +#define PGC_preserved (PGC_extra | PGC_static | PGC_colored) =20 #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 @@ -1473,6 +1478,8 @@ static bool mark_page_free(struct page_info *pg, mfn_= t mfn) return pg_offlined; } =20 +static void free_color_heap_page(struct page_info *pg, bool need_scrub); + /* Free 2^@order set of pages. */ static void free_heap_pages( struct page_info *pg, unsigned int order, bool need_scrub) @@ -1497,6 +1504,15 @@ static void free_heap_pages( pg[i].count_info |=3D PGC_need_scrub; poison_one_page(&pg[i]); } + + if ( pg->count_info & PGC_colored ) + { + ASSERT(order =3D=3D 0); + + free_color_heap_page(pg, need_scrub); + spin_unlock(&heap_lock); + return; + } } =20 avail[node][zone] +=3D 1 << order; @@ -1961,6 +1977,157 @@ static unsigned long avail_heap_pages( return free_pages; } =20 +/************************* + * COLORED SIDE-ALLOCATOR + * + * Pages are grouped by LLC color in lists which are globally referred to = as the + * color heap. Lists are populated in end_boot_allocator(). + * After initialization there will be N lists where N is the number of + * available colors on the platform. + */ +static struct page_list_head *__ro_after_init _color_heap; +#define color_heap(color) (&_color_heap[color]) + +static unsigned long *__ro_after_init free_colored_pages; + +#ifdef CONFIG_LLC_COLORING +#define domain_num_llc_colors(d) ((d)->num_llc_colors) +#define domain_llc_color(d, i) ((d)->llc_colors[i]) + +/* Memory required for buddy allocator to work with colored one */ +static unsigned long __initdata buddy_alloc_size =3D + MB(CONFIG_BUDDY_ALLOCATOR_SIZE); +size_param("buddy-alloc-size", buddy_alloc_size); +#else +#define domain_num_llc_colors(d) 0 +#define domain_llc_color(d, i) 0 +#endif + +static void free_color_heap_page(struct page_info *pg, bool need_scrub) +{ + unsigned int color; + + color =3D page_to_llc_color(pg); + free_colored_pages[color]++; + /* + * Head insertion allows re-using cache-hot pages in configurations wi= thout + * sharing of colors. + */ + page_list_add(pg, color_heap(color)); +} + +static struct page_info *alloc_color_heap_page(unsigned int memflags, + const struct domain *d) +{ + struct page_info *pg =3D NULL; + unsigned int i, color =3D 0; + unsigned long max =3D 0; + bool need_tlbflush =3D false; + uint32_t tlbflush_timestamp =3D 0; + bool need_scrub; + + if ( memflags & ~(MEMF_no_refcount | MEMF_no_owner | MEMF_no_tlbflush | + MEMF_no_icache_flush | MEMF_no_scrub) ) + return NULL; + + spin_lock(&heap_lock); + + for ( i =3D 0; i < domain_num_llc_colors(d); i++ ) + { + unsigned long free =3D free_colored_pages[domain_llc_color(d, i)]; + + if ( free > max ) + { + color =3D domain_llc_color(d, i); + pg =3D page_list_first(color_heap(color)); + max =3D free; + } + } + + if ( !pg ) + { + spin_unlock(&heap_lock); + return NULL; + } + + need_scrub =3D pg->count_info & PGC_need_scrub; + pg->count_info =3D PGC_state_inuse | (pg->count_info & PGC_colored); + free_colored_pages[color]--; + page_list_del(pg, color_heap(color)); + + if ( !(memflags & MEMF_no_tlbflush) ) + accumulate_tlbflush(&need_tlbflush, pg, &tlbflush_timestamp); + + init_free_page_fields(pg); + + spin_unlock(&heap_lock); + + if ( !(memflags & MEMF_no_scrub) ) + { + if ( need_scrub ) + scrub_one_page(pg); + else + check_one_page(pg); + } + + if ( need_tlbflush ) + filtered_flush_tlb_mask(tlbflush_timestamp); + + flush_page_to_ram(mfn_x(page_to_mfn(pg)), + !(memflags & MEMF_no_icache_flush)); + + return pg; +} + +static void __init init_color_heap_pages(struct page_info *pg, + unsigned long nr_pages) +{ + unsigned long i; + bool need_scrub =3D opt_bootscrub =3D=3D BOOTSCRUB_IDLE; + +#ifdef buddy_alloc_size + if ( buddy_alloc_size >=3D PAGE_SIZE ) + { + unsigned long buddy_pages =3D min(PFN_DOWN(buddy_alloc_size), nr_p= ages); + + init_heap_pages(pg, buddy_pages); + nr_pages -=3D buddy_pages; + buddy_alloc_size -=3D buddy_pages << PAGE_SHIFT; + pg +=3D buddy_pages; + } +#endif + + if ( !_color_heap ) + { + unsigned int max_nr_colors =3D get_max_nr_llc_colors(); + + _color_heap =3D xvmalloc_array(struct page_list_head, max_nr_color= s); + free_colored_pages =3D xvzalloc_array(unsigned long, max_nr_colors= ); + if ( !_color_heap || !free_colored_pages ) + panic("Can't allocate colored heap. Buddy reserved size is too= low"); + + for ( i =3D 0; i < max_nr_colors; i++ ) + INIT_PAGE_LIST_HEAD(color_heap(i)); + } + + for ( i =3D 0; i < nr_pages; i++ ) + { + pg[i].count_info =3D PGC_colored; + free_color_heap_page(&pg[i], need_scrub); + } +} + +static void dump_color_heap(void) +{ + unsigned int color; + + printk("Dumping color heap info\n"); + for ( color =3D 0; color < get_max_nr_llc_colors(); color++ ) + if ( free_colored_pages[color] > 0 ) + printk("Color heap[%u]: %lu pages\n", + color, free_colored_pages[color]); +} + void __init end_boot_allocator(void) { unsigned int i; @@ -1980,7 +2147,13 @@ void __init end_boot_allocator(void) for ( i =3D nr_bootmem_regions; i-- > 0; ) { struct bootmem_region *r =3D &bootmem_region_list[i]; - if ( r->s < r->e ) + + if ( r->s >=3D r->e ) + continue; + + if ( llc_coloring_enabled ) + init_color_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s); + else init_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s); } nr_bootmem_regions =3D 0; @@ -2476,7 +2649,14 @@ struct page_info *alloc_domheap_pages( if ( memflags & MEMF_no_owner ) memflags |=3D MEMF_no_refcount; =20 - if ( !dma_bitsize ) + /* Only domains are supported for coloring */ + if ( d && llc_coloring_enabled ) + { + /* Colored allocation must be done on 0 order */ + if ( order || (pg =3D alloc_color_heap_page(memflags, d)) =3D=3D N= ULL ) + return NULL; + } + else if ( !dma_bitsize ) memflags &=3D ~MEMF_no_dma; else if ( (dma_zone =3D bits_to_zone(dma_bitsize)) < zone_hi ) pg =3D alloc_heap_pages(dma_zone + 1, zone_hi, order, memflags, d); @@ -2688,6 +2868,9 @@ static void cf_check dump_heap(unsigned char key) continue; printk("Node %d has %lu unscrubbed pages\n", i, node_need_scrub[i]= ); } + + if ( llc_coloring_enabled ) + dump_color_heap(); } =20 static __init int cf_check register_heap_trigger(void) diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index ae8a8825e5..b3f2fa22bc 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -9,6 +9,7 @@ #define __XEN_LLC_COLORING_H__ =20 struct domain; +struct page_info; struct xen_domctl_set_llc_colors; =20 #ifdef CONFIG_LLC_COLORING @@ -33,6 +34,8 @@ int dom0_set_llc_colors(struct domain *d); int domain_set_llc_colors(struct domain *d, const struct xen_domctl_set_llc_colors *config); int domain_set_llc_colors_from_str(struct domain *d, const char *str); +unsigned int page_to_llc_color(const struct page_info *pg); +unsigned int get_max_nr_llc_colors(void); =20 #endif /* __XEN_LLC_COLORING_H__ */ =20 --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158796; cv=none; d=zohomail.com; s=zohoarc; b=SkJ2dlogRCM9eovKh4ZJOBouPWzU8DZznuhYZGr0ovuAdg0i3CZhcYnxqOtOKpEGEfnUkeNSb8wqsZCVGjWo9VMD26Uu/qk15vN290/OW/7eHBA1Krx60CQVJnwPHfnVQFZ+bIgoeLnsDzENUpW49YW15dY8ObOAP7bp/fjcAt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158796; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Pagk7URGKJuUs/rn2A1jGcJIDnUg2XZUgAYh+RZjekY=; b=Ym/2YMdvL4Umk2bkuYwIqnpGot23x8qvt+sxhjxjF41TP1zkG3CowB5zlz8HzTaEBdaK27eSxM60+OrLD/0KANfmfijw1wSDrHBwDyuk39lP8U1bWyFEiltFm/g6Df72O/fMNRU3no2DO/zuStxRv3wg8qfWhLAJAdr3gv8SxKo= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158796465957.3824403694433; Mon, 2 Dec 2024 08:59:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846772.1261990 (Exim 4.92) (envelope-from ) id 1tI9lq-0000kl-A9; Mon, 02 Dec 2024 16:59:38 +0000 Received: by outflank-mailman (output) from mailman id 846772.1261990; Mon, 02 Dec 2024 16:59:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lq-0000kD-3s; Mon, 02 Dec 2024 16:59:38 +0000 Received: by outflank-mailman (input) for mailman id 846772; Mon, 02 Dec 2024 16:59:37 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lp-0006x4-1m for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:37 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cee59eaa-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:35 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-aa549d9dffdso738908866b.2 for ; Mon, 02 Dec 2024 08:59:35 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:34 -0800 (PST) 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: cee59eaa-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158775; x=1733763575; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Pagk7URGKJuUs/rn2A1jGcJIDnUg2XZUgAYh+RZjekY=; b=qOW3mCgU3OWgm47gnss4elRvvY4Aws7VCrjynaN1mmVf6huVWHbKfDLdPMqGpaigyf 7d0xSM6xfIvm1JHBvMr0tW0HidxTgXLXmgOH0ZQP26WKZQUzCb2EXYEerEZGWLn2422U bmKlqJAbXVl9ltXyz3x/FuvM6sDJu9hhxkKarKg3y55RpQPuzpAQ536+AWpwIchsd3up 4gLCZudmhCKK8Ax0RPmzHXtrEh3oMYbaZIMNZiHVUiAyg/fJwodXvS90gsv3KFzzDEV4 940TA6HDUFw2fLm2ICS5KMpn3vEZfKc5B6w7r7rqvUh87UZkEjJMLDl0gIvEVtyKWikB y8Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158775; x=1733763575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pagk7URGKJuUs/rn2A1jGcJIDnUg2XZUgAYh+RZjekY=; b=e0f9n+qj3LTioLwGoeZ1kHNRRGIaKUzL5bHFsNQcZywqttL3GD5YianBPuSpcL+cB4 MOfRYyZ2nJ7Mi5fKlAr74N57JopO7ckrIcauZfd9XS+EZSudGhvhDXL28WRGkz528lLP jAoOelJfxmeMm87gYIUnhJtM4j3HdumFymD2VnzhxHuYadJavsbcnh3OhTU28Ga3313h IRpWEwmPgVNw9voVwHloO/13lGLviwqwpzQAte+vE1kbSoXARZT4B8XvtUkPxV4oXE0g g8kCkLJF4qFDS0qZjJPKEbEMZFckKzhWN2YRNO2nDqiixMElVV1/fmXAGKLiT9QJAQrm OL2A== X-Gm-Message-State: AOJu0YzfA4bbEdF/nZmp8oG0ZRldVy/X8lmpr4a/AXvZuPDzCaFotg2B gwTvEPFGDogXSkE1Z2dUVgI05N3o+M6Op5iMn+fnOL/ivbpxxTyOf+mfu0rLOKcMqTMz+zVeIpq 4 X-Gm-Gg: ASbGncsZmsgctVXcAv0vQRYZiBsQAsMV/k7DiCqH2WlkJm4A5pqr/CjWeGkpvFx/gVD OcG9g2GmatBLXx6TD6yHQKnUaDzZvtrCITiLJDBUQH06unVxP1SqhoorhGzjvkbGH6lijUYbaFs LyuHdYzhEVtRdwyyl95U3yuFoi5Z6c1H6TSZaYNR6XiEso3l5YQeHVfqvSCL6hlfUo2ph+F/E/i WmNHD1h9rW5s/ZK1KObgdHu2U+9MQ7WgEI7qNfu+zNXz9vfTZ2703HD2bALk/hjv4PPN8yJZndT euYFDtuecNwc2tD5BDuzGp0I2DdSXLkRvfrt5IT3sPNF3p5hZLxd X-Google-Smtp-Source: AGHT+IHqanNwJRkV0inBQ2YdQNsACfSn8h1bYFVsTBn8btuIFrbCKnK748o/hg+sTWcfgvVbkaZ1lQ== X-Received: by 2002:a17:906:3096:b0:aa5:3782:53af with SMTP id a640c23a62f3a-aa580f57d1dmr2144670766b.27.1733158774671; Mon, 02 Dec 2024 08:59:34 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Luca Miccio , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , Carlo Nonato Subject: [PATCH v11 10/12] xen/arm: add Xen cache colors command line parameter Date: Mon, 2 Dec 2024 17:59:19 +0100 Message-ID: <20241202165921.249585-11-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158797760116600 Content-Type: text/plain; charset="utf-8" From: Luca Miccio Add a new command line parameter to configure Xen cache colors. These colors are dumped together with other coloring info. Benchmarking the VM interrupt response time provides an estimation of LLC usage by Xen's most latency-critical runtime task. Results on Arm Cortex-A53 on Xilinx Zynq UltraScale+ XCZU9EG show that one color, which reserves 64 KiB of L2, is enough to attain best responsiveness: - Xen 1 color latency: 3.1 us - Xen 2 color latency: 3.1 us Since this is the most common target for Arm cache coloring, the default amount of Xen colors is set to one. More colors are instead very likely to be needed on processors whose L1 cache is physically-indexed and physically-tagged, such as Cortex-A57. In such cases, coloring applies to L1 also, and there typically are two distinct L1-colors. Therefore, reserving only one color for Xen would senselessly partitions a cache memory that is already private, i.e. underutilize it. Signed-off-by: Luca Miccio Signed-off-by: Marco Solieri Signed-off-by: Carlo Nonato Reviewed-by: Jan Beulich --- v11: - no changes v10: - no changes v9: - no changes v8: - added bound check on xen_colors in llc_coloring_init() v7: - removed XEN_DEFAULT_COLOR - XEN_DEFAULT_NUM_COLORS is now used in a for loop to set xen default colors --- docs/misc/cache-coloring.rst | 2 ++ docs/misc/xen-command-line.pandoc | 10 ++++++++++ xen/common/llc-coloring.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/docs/misc/cache-coloring.rst b/docs/misc/cache-coloring.rst index 5224b27afe..e156062aa2 100644 --- a/docs/misc/cache-coloring.rst +++ b/docs/misc/cache-coloring.rst @@ -115,6 +115,8 @@ Specific documentation is available at `docs/misc/xen-c= ommand-line.pandoc`. +----------------------+-------------------------------+ | ``buddy-alloc-size`` | Buddy allocator reserved size | +----------------------+-------------------------------+ +| ``xen-llc-colors`` | Xen color configuration | ++----------------------+-------------------------------+ =20 Colors selection format *********************** diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 3a70c49c05..992e1f993e 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2923,6 +2923,16 @@ mode. **WARNING: `x2apic_phys` is deprecated and superseded by `x2apic-mode`. The latter takes precedence if both are set.** =20 +### xen-llc-colors (arm64) +> `=3D List of [ | - ]` + +> Default: `0: the lowermost color` + +Specify Xen LLC color configuration. This options is available only when +`CONFIG_LLC_COLORING` is enabled. +Two colors are most likely needed on platforms where private caches are +physically indexed, e.g. the L1 instruction cache of the Arm Cortex-A57. + ### xenheap_megabytes (arm32) > `=3D ` =20 diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 0f22a9b72c..2e7c0f505d 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -11,6 +11,7 @@ #include =20 #define NR_LLC_COLORS (1U << CONFIG_LLC_COLORS_ORDER) +#define XEN_DEFAULT_NUM_COLORS 1 =20 /* * -1: not specified (disabled unless llc-size and llc-nr-ways present) @@ -32,6 +33,9 @@ static unsigned int __ro_after_init default_colors[NR_LLC= _COLORS]; static unsigned int __initdata dom0_colors[NR_LLC_COLORS]; static unsigned int __initdata dom0_num_colors; =20 +static unsigned int __ro_after_init xen_colors[NR_LLC_COLORS]; +static unsigned int __ro_after_init xen_num_colors; + #define mfn_color_mask (max_nr_colors - 1) #define mfn_to_color(mfn) (mfn_x(mfn) & mfn_color_mask) =20 @@ -90,6 +94,13 @@ static int __init parse_dom0_colors(const char *s) } custom_param("dom0-llc-colors", parse_dom0_colors); =20 +static int __init parse_xen_colors(const char *s) +{ + return parse_color_config(s, xen_colors, ARRAY_SIZE(xen_colors), + &xen_num_colors); +} +custom_param("xen-llc-colors", parse_xen_colors); + static void print_colors(const unsigned int colors[], unsigned int num_col= ors) { unsigned int i; @@ -173,6 +184,22 @@ void __init llc_coloring_init(void) for ( i =3D 0; i < max_nr_colors; i++ ) default_colors[i] =3D i; =20 + if ( !xen_num_colors ) + { + unsigned int i; + + xen_num_colors =3D MIN(XEN_DEFAULT_NUM_COLORS, max_nr_colors); + + printk(XENLOG_WARNING + "Xen LLC color config not found. Using first %u colors\n", + xen_num_colors); + for ( i =3D 0; i < xen_num_colors; i++ ) + xen_colors[i] =3D i; + } + else if ( xen_num_colors > max_nr_colors || + !check_colors(xen_colors, xen_num_colors) ) + panic("Bad LLC color config for Xen\n"); + arch_llc_coloring_init(); } =20 @@ -183,6 +210,8 @@ void dump_llc_coloring_info(void) =20 printk("LLC coloring info:\n"); printk(" Number of LLC colors supported: %u\n", max_nr_colors); + printk(" Xen LLC colors (%u): ", xen_num_colors); + print_colors(xen_colors, xen_num_colors); } =20 void domain_dump_llc_colors(const struct domain *d) --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158797; cv=none; d=zohomail.com; s=zohoarc; b=jcqbxbI6y3UEvgvvBhz2VUPbGsDDoDNkQps8DQnjIjKw3zQ/7fJWwGEM2QrqQNl6WHcY+od0p82N0wWuncuLwrjY9NnR2Zu46Iv4C0CstRk1h5izrHtewPTGFetyWNEWqDgKLVBciZwZ7rI0FRT1TI+q5GQFd1YSVfclNvRNKXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158797; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SQLU0z+L0dGPs9j3VJOLeVLjnDV4HcwqVQ59IBOieiw=; b=VS/B90ytvdB/PkYJoEYDjdR3dp8aHbDl+SBr7CiS9JKlpcYQB+gOK95J1Tm/7S0l8fp12ix+CieD4g/Qw2qmznDS0Loc9IB83echXnY5jl3wnutN+h7fbbKNT6MreuAONBkTZ95vQ+x3lV9ldg3Pg/XVHPdjgIM2VQLlhuW6Acg= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158797460632.0422948801908; Mon, 2 Dec 2024 08:59:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846773.1261993 (Exim 4.92) (envelope-from ) id 1tI9lr-0000pm-1B; Mon, 02 Dec 2024 16:59:39 +0000 Received: by outflank-mailman (output) from mailman id 846773.1261993; Mon, 02 Dec 2024 16:59:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lq-0000np-EU; Mon, 02 Dec 2024 16:59:38 +0000 Received: by outflank-mailman (input) for mailman id 846773; Mon, 02 Dec 2024 16:59:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lp-0006wq-0U for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:37 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cf78e0e6-b0ce-11ef-a0d2-8be0dac302b0; Mon, 02 Dec 2024 17:59:36 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-53de8ecafeeso4908664e87.1 for ; Mon, 02 Dec 2024 08:59:36 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:35 -0800 (PST) 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: cf78e0e6-b0ce-11ef-a0d2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158775; x=1733763575; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SQLU0z+L0dGPs9j3VJOLeVLjnDV4HcwqVQ59IBOieiw=; b=l6secaQPM6CHW3+nmmnL/eFyIXRuh90goQzrmrT6phh58IRCrtrj6uQzpQsZ7+nhM5 XcqCi9EQ6nwXmqUGWNu2emj3dIXSjWhDqdWxPF3uX+5E3/jD3hc8B80nyphE274o7qpM kOzmQTJemldY28GrYMeg0eOxdHgnveekE8PasW/0pohdjTrCCrfC5jyMFKNtS4O5/nCb JZE2gopDieSY9HpDwVruEdG+zzqdoNWDAp84B5fGYTsiHGiATYiN3lzd7D/HG9Cjj8SK BTmFtRWpe4lytzXk7ng2RckRT6HN2HS2b43CPAKSPddvq0OPUYgG79yc6e4QthbHVmWZ F4IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158775; x=1733763575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SQLU0z+L0dGPs9j3VJOLeVLjnDV4HcwqVQ59IBOieiw=; b=Gww2ztHHMpZgnvJmP95ano3/5PN3CQmOTdvMd1lG+ZGtPujT+UJPyKsxQqfzyFwVpV dta1mMgH8FiMeCdPl+/xMSG8+g+HCs+dBhYOVjL5DKgJf1dLPnPGiuZodtfvOakyUzmJ mkuy8TXcvb7kJP1t0gwS/9UxJ5YRK7BHVG9pqEjP+zxavaH4uY0czsYZsoc2/ypuFicG x1zury2anvqS+5KC/J1Slcvbc82CFLFoRwIiSYZbnHS37fr9ltPusZrZ5XlLzfbFDMyI ZUev1Ex8TSUmj7ZGFfF0lo41JOzcAq0tHRQ8il1afoY5KG0Fhj44UguCq6aE5VEQhyrw JyNw== X-Gm-Message-State: AOJu0YywZK9//xO+dVBj5+8HD3Q1QjGthoOZnO/1Qtc0JuBQD2WRhH58 4GzIM8AIXHx3x/t5CEJ+TDW6+CKbc45fMWjRorVEMPoWOvjfmf/llGadupr2qTZGZfksTVuVBcO w X-Gm-Gg: ASbGnctRly8hboR8KVBSqJUf5UuH3rWC9GJBTQo9dGLv3o+J+eAeqisIEV06lm/jIo2 dSP5qWy9C0OWLTZygANR5CWbNiPzlRHxcv8pI71xtpFvliKIAYXzP4xCMfF6ydUtElZQ4gVkCyR siS8qA2x30Gp5oU/TbeXVqHceB4kivX8in5rtnnz3PqCcAgUn3You8xzfMMDbkmI8SBEeiSIGYN 5kAjqHLKLuCn/wRu/uOrCHjvTGvB3f73or4vqcfC6eJyUxBbmvtjC+KLEEmPEKEo9Y5mu3FEL1/ g0rUKuKgFR3LfYYP9y0lumFB7CVncGgmevJiWsIz84gEYCLqtI2o X-Google-Smtp-Source: AGHT+IFcthVhkf4BkBdZ3UvYNyO3JNKzXHzfDVFYUXTj/ROlFjZIToNYkja9jc7/mLFmlkM7PuSk2A== X-Received: by 2002:a05:6512:3e1d:b0:539:e12c:bba7 with SMTP id 2adb3069b0e04-53df00a9f2amr12143887e87.12.1733158775555; Mon, 02 Dec 2024 08:59:35 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v11 11/12] xen/arm: make consider_modules() available for xen relocation Date: Mon, 2 Dec 2024 17:59:20 +0100 Message-ID: <20241202165921.249585-12-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158799454116600 Content-Type: text/plain; charset="utf-8" Cache coloring must physically relocate Xen in order to color the hypervisor and consider_modules() is a key function that is needed to find a new available physical address. 672d67f339c0 ("xen/arm: Split MMU-specific setup_mm() and related code out") moved consider_modules() under arm32. Move it to mmu/setup.c and make it non-static so that it can be used outside. Signed-off-by: Carlo Nonato Reviewed-by: Michal Orzel --- v11: - removed useless #include v10: - no changes v9: - no changes v8: - patch adapted to new changes to consider_modules() v7: - moved consider_modules() to arm/mmu/setup.c v6: - new patch --- xen/arch/arm/arm32/mmu/mm.c | 95 +------------------------------- xen/arch/arm/include/asm/setup.h | 3 + xen/arch/arm/mmu/setup.c | 94 +++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 94 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 063611412b..903d946f07 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include =20 @@ -31,100 +32,6 @@ static void __init setup_directmap_mappings(unsigned lo= ng base_mfn, directmap_virt_end =3D XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; } =20 -/* - * Returns the end address of the highest region in the range s..e - * with required size and alignment that does not conflict with the - * modules from first_mod to nr_modules. - * - * For non-recursive callers first_mod should normally be 0 (all - * modules and Xen itself) or 1 (all modules but not Xen). - */ -static paddr_t __init consider_modules(paddr_t s, paddr_t e, - uint32_t size, paddr_t align, - int first_mod) -{ - const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); -#ifdef CONFIG_STATIC_SHM - const struct membanks *shmem =3D bootinfo_get_shmem(); -#endif - const struct bootmodules *mi =3D &bootinfo.modules; - int i; - int nr; - - s =3D (s+align-1) & ~(align-1); - e =3D e & ~(align-1); - - if ( s > e || e - s < size ) - return 0; - - /* First check the boot modules */ - for ( i =3D first_mod; i < mi->nr_mods; i++ ) - { - paddr_t mod_s =3D mi->module[i].start; - paddr_t mod_e =3D mod_s + mi->module[i].size; - - if ( s < mod_e && mod_s < e ) - { - mod_e =3D consider_modules(mod_e, e, size, align, i+1); - if ( mod_e ) - return mod_e; - - return consider_modules(s, mod_s, size, align, i+1); - } - } - - /* - * i is the current bootmodule we are evaluating, across all - * possible kinds of bootmodules. - * - * When retrieving the corresponding reserved-memory addresses, we - * need to index the reserved_mem bank starting from 0, and only count= ing - * the reserved-memory modules. Hence, we need to use i - nr. - */ - nr =3D mi->nr_mods; - for ( ; i - nr < reserved_mem->nr_banks; i++ ) - { - paddr_t r_s =3D reserved_mem->bank[i - nr].start; - paddr_t r_e =3D r_s + reserved_mem->bank[i - nr].size; - - if ( s < r_e && r_s < e ) - { - r_e =3D consider_modules(r_e, e, size, align, i + 1); - if ( r_e ) - return r_e; - - return consider_modules(s, r_s, size, align, i + 1); - } - } - -#ifdef CONFIG_STATIC_SHM - nr +=3D reserved_mem->nr_banks; - for ( ; i - nr < shmem->nr_banks; i++ ) - { - paddr_t r_s, r_e; - - r_s =3D shmem->bank[i - nr].start; - - /* Shared memory banks can contain INVALID_PADDR as start */ - if ( INVALID_PADDR =3D=3D r_s ) - continue; - - r_e =3D r_s + shmem->bank[i - nr].size; - - if ( s < r_e && r_s < e ) - { - r_e =3D consider_modules(r_e, e, size, align, i + 1); - if ( r_e ) - return r_e; - - return consider_modules(s, r_s, size, align, i + 1); - } - } -#endif - - return e; -} - /* * Find a contiguous region that fits in the static heap region with * required size and alignment, and return the end address of the region diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 64c227d171..0c560d141f 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -89,6 +89,9 @@ struct init_info unsigned int cpuid; }; =20 +paddr_t consider_modules(paddr_t s, paddr_t e, uint32_t size, paddr_t alig= n, + int first_mod); + #endif /* * Local variables: diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 9664e85ee6..196974f3e2 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -222,6 +222,100 @@ static void xen_pt_enforce_wnx(void) flush_xen_tlb_local(); } =20 +/* + * Returns the end address of the highest region in the range s..e + * with required size and alignment that does not conflict with the + * modules from first_mod to nr_modules. + * + * For non-recursive callers first_mod should normally be 0 (all + * modules and Xen itself) or 1 (all modules but not Xen). + */ +paddr_t __init consider_modules(paddr_t s, paddr_t e, + uint32_t size, paddr_t align, + int first_mod) +{ + const struct membanks *reserved_mem =3D bootinfo_get_reserved_mem(); +#ifdef CONFIG_STATIC_SHM + const struct membanks *shmem =3D bootinfo_get_shmem(); +#endif + const struct bootmodules *mi =3D &bootinfo.modules; + int i; + int nr; + + s =3D (s+align-1) & ~(align-1); + e =3D e & ~(align-1); + + if ( s > e || e - s < size ) + return 0; + + /* First check the boot modules */ + for ( i =3D first_mod; i < mi->nr_mods; i++ ) + { + paddr_t mod_s =3D mi->module[i].start; + paddr_t mod_e =3D mod_s + mi->module[i].size; + + if ( s < mod_e && mod_s < e ) + { + mod_e =3D consider_modules(mod_e, e, size, align, i+1); + if ( mod_e ) + return mod_e; + + return consider_modules(s, mod_s, size, align, i+1); + } + } + + /* + * i is the current bootmodule we are evaluating, across all + * possible kinds of bootmodules. + * + * When retrieving the corresponding reserved-memory addresses, we + * need to index the reserved_mem bank starting from 0, and only count= ing + * the reserved-memory modules. Hence, we need to use i - nr. + */ + nr =3D mi->nr_mods; + for ( ; i - nr < reserved_mem->nr_banks; i++ ) + { + paddr_t r_s =3D reserved_mem->bank[i - nr].start; + paddr_t r_e =3D r_s + reserved_mem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e =3D consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } + +#ifdef CONFIG_STATIC_SHM + nr +=3D reserved_mem->nr_banks; + for ( ; i - nr < shmem->nr_banks; i++ ) + { + paddr_t r_s, r_e; + + r_s =3D shmem->bank[i - nr].start; + + /* Shared memory banks can contain INVALID_PADDR as start */ + if ( INVALID_PADDR =3D=3D r_s ) + continue; + + r_e =3D r_s + shmem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e =3D consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } +#endif + + return e; +} + /* * Boot-time pagetable setup. * Changes here may need matching changes in head.S --=20 2.43.0 From nobody Fri Dec 27 13:36:59 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 ARC-Seal: i=1; a=rsa-sha256; t=1733158799; cv=none; d=zohomail.com; s=zohoarc; b=B4xHK1UrQn7iyyH053OBa5gPChUFlPEabsurr7cf7hlE8/E6lhRBYq8mVL9gShEjtp75IznjFr/+BfXK8w3eAdUHLlPp2vA5kID2ccs0xV7aw/b+IUpA+hsjOGKTxTAxDqXz+mdmX9QSAtV3jOQrNsHn+rKfN0PIgX3bfMAXfyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733158799; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jLbjZwSsMBhbP6FhXxodaS+Dw8jqZO+nNvFUCEAf4WQ=; b=YBcEt9YD5tl4V4uyQKFtaWnY0wKt/YWpz8AizXH45kFT1lC1Yw1YQY9+Bk67nw9AsmbXBs8t/qyifrggD7GKXLnLO68ad8lkkGq7TwNWsWwvL0TXSmBEwEalY+89qVbdfGFQcCGDSBgl+ysoAL3tLVLcUaM3KVrLGQjcvmmG7LE= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733158799251457.90562232063303; Mon, 2 Dec 2024 08:59:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.846777.1262021 (Exim 4.92) (envelope-from ) id 1tI9lu-0001jU-Ko; Mon, 02 Dec 2024 16:59:42 +0000 Received: by outflank-mailman (output) from mailman id 846777.1262021; Mon, 02 Dec 2024 16:59:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lu-0001ga-6w; Mon, 02 Dec 2024 16:59:42 +0000 Received: by outflank-mailman (input) for mailman id 846777; Mon, 02 Dec 2024 16:59:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tI9lr-0006x4-LI for xen-devel@lists.xenproject.org; Mon, 02 Dec 2024 16:59:39 +0000 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [2a00:1450:4864:20::52b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d01b1c2d-b0ce-11ef-99a3-01e77a169b0f; Mon, 02 Dec 2024 17:59:37 +0100 (CET) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d0bdeb0374so3449397a12.0 for ; Mon, 02 Dec 2024 08:59:37 -0800 (PST) Received: from carlo-ubuntu.home.arpa (host-95-230-250-178.business.telecomitalia.it. [95.230.250.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa5998e64c4sm526802666b.97.2024.12.02.08.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 08:59:36 -0800 (PST) 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: d01b1c2d-b0ce-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1733158777; x=1733763577; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jLbjZwSsMBhbP6FhXxodaS+Dw8jqZO+nNvFUCEAf4WQ=; b=dYdDMogB8QoTbJvjXB4TwSfiyVhhgwaFXN4b/HQNg8MbgGd1QSMIwQDQ9sMj0xpjcU wsfcKviWWFh7ygV/44c/zAe9ZpVeYRIZAgahgUw/TbxSY7d8NTHNddWJtKrdn7toeWMy msEjOmqrABeWxqs0FHXl7yIxfr6poZCEjcjdK7dlrMCXz79SFZYQwiLw/w3RdjpWqVLI bcQyhXwuRT7OeP0/qT76yKObSzD2zeU69vCeDENhbmwJYv1GrODRWy79wzJANBkJ4uMg oDH4u2OiyyLyd1Wyi/hcUyMLLEYwXJyfPNJwrla6WudED2zXBabpt/Qxzi0BKY+QyMru iLEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733158777; x=1733763577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jLbjZwSsMBhbP6FhXxodaS+Dw8jqZO+nNvFUCEAf4WQ=; b=JwHRqC0owu2ifzfOg8GNxu8hItzXqx44z8Qh38CccWdHA/l0hHuh8bm/KuqccEA9Qq Th3nRDERiTloLiQB5cIBH1J8HsIb5zQwVAg1w1jxLGgfjFIJNPKoZoUB13ewdhzHYD3V 8Jc+hg9ubBgZrNwSnV1uWKxRCbRuPK9t4LG8G1ctgScs3/mymQfDpSXRVdby3hEXU85+ RqbqHBdvt8RCHsyx5wVum8kbzXM446EqZQ97egg9VKIUb0Qm+fmW/dS5sGiLoapMyrrF zCOGinQ5uyII6rKsNnKRXdex8hhP8mDKbQhNRCfTl3oTbeKxfUYrCVYaJuf+AWT3xh+w lsoQ== X-Gm-Message-State: AOJu0YzKzxaUjBoi17jifgiEHUpcWYPedaPpukSh0iIclggQzhL+2Wdv GKYWMn0kaaYE8oVAz7wCytQn2Z/8QjRpnB3q1ZE590Rc5aZCpmBnm6pUeXbYb/yXVerLlLR6H5T z X-Gm-Gg: ASbGncvt3l3zTOZSiNwFIZQrqorl6RpjxZbPmqq+NDVCkWkfIG96ZY2M4dN7rIU3cwx YydZnZA8xnevri7qQ3sFcc73+vCns9UGa06DnqCf670faBnafuYi7/zkP7p4e7J7Dr691FNNq3/ P07U4NJq6/6GpkySqncTSNm2/PbzHZskB1AtMMu6GThn9OgIvoaGpftdUWbthwzjf7A93h46IZf 7HRRR8l7Rpsc/XIk4J7Nh/u/Jl03GrK7nD/EHIEseLHISZhNsVxKGSLwxSGHo7G6ZeLNP9/egv3 ajF7Ms463yTCpS5s2cm6VgPfFSC9aw9yijFIej0eSLRCgsh1Mex7 X-Google-Smtp-Source: AGHT+IEsMeY8tJTcRZ/irSPCXsIki96bRQtsE2O99r8NeN/Y5vw5MLh2IGvkhfJsUG7F8Abaqi/UUA== X-Received: by 2002:a17:906:3d2a:b0:aa5:3423:2dfe with SMTP id a640c23a62f3a-aa580f33384mr1969822066b.25.1733158776539; Mon, 02 Dec 2024 08:59:36 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, marco.solieri@minervasys.tech, Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Jan Beulich Subject: [PATCH v11 12/12] xen/arm: add cache coloring support for Xen image Date: Mon, 2 Dec 2024 17:59:21 +0100 Message-ID: <20241202165921.249585-13-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202165921.249585-1-carlo.nonato@minervasys.tech> References: <20241202165921.249585-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1733158801727116600 Content-Type: text/plain; charset="utf-8" Xen image is relocated to a new colored physical space. Some relocation functionalities must be brought back: - the virtual address of the new space is taken from 0c18fb76323b ("xen/arm: Remove unused BOOT_RELOC_VIRT_START"). - relocate_xen() and get_xen_paddr() are taken from f60658c6ae47 ("xen/arm: Stop relocating Xen"). setup_pagetables() must be adapted for coloring and for relocation. Runtime page tables are used to map the colored space, but they are also linked in boot tables so that the new space is temporarily available for relocation. This implies that Xen protection must happen after the copy. Finally, since the alternative framework needs to remap the Xen text and inittext sections, this operation must be done in a coloring-aware way. The function xen_remap_colored() is introduced for that. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Reviewed-by: Jan Beulich # common --- v11: - else if -> if in xen_colored_mfn() v10: - no changes v9: - patch adapted to changes to setup_pagetables() v8: - moved xen_colored_map_size() to arm/llc-coloring.c v7: - added BUG_ON() checks to arch_llc_coloring_init() and create_llc_coloring_mappings() v6: - squashed with BOOT_RELOC_VIRT_START patch - consider_modules() moved in another patch - removed psci and smpboot code because of new idmap work already handles t= hat - moved xen_remap_colored() in alternative.c since it's only used there - removed xen_colored_temp[] in favor of xen_xenmap[] usage for mapping - use of boot_module_find_by_kind() to remove the need of extra parameter in setup_pagetables() - moved get_xen_paddr() in arm/llc-coloring.c since it's only used there v5: - FIXME: consider_modules copy pasted since it got moved v4: - removed set_value_for_secondary() because it was wrongly cleaning cache - relocate_xen() now calls switch_ttbr_id() --- xen/arch/arm/alternative.c | 30 +++++++- xen/arch/arm/arm64/mmu/head.S | 58 +++++++++++++++- xen/arch/arm/arm64/mmu/mm.c | 28 ++++++-- xen/arch/arm/include/asm/mmu/layout.h | 3 + xen/arch/arm/llc-coloring.c | 63 +++++++++++++++++ xen/arch/arm/mmu/setup.c | 99 +++++++++++++++++++++++---- xen/arch/arm/setup.c | 10 ++- xen/common/llc-coloring.c | 18 +++++ xen/include/xen/llc-coloring.h | 14 ++++ 9 files changed, 302 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index d99b507093..0fcf4e451d 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,27 @@ static int __apply_alternatives_multi_stop(void *xenma= p) return 0; } =20 +static void __init *xen_remap_colored(mfn_t xen_mfn, paddr_t xen_size) +{ + unsigned int i; + void *xenmap; + mfn_t *xen_colored_mfns, mfn; + + xen_colored_mfns =3D xmalloc_array(mfn_t, xen_size >> PAGE_SHIFT); + if ( !xen_colored_mfns ) + panic("Can't allocate LLC colored MFNs\n"); + + for_each_xen_colored_mfn ( xen_mfn, mfn, i ) + { + xen_colored_mfns[i] =3D mfn; + } + + xenmap =3D vmap(xen_colored_mfns, xen_size >> PAGE_SHIFT); + xfree(xen_colored_mfns); + + return xenmap; +} + /* * This function should only be called during boot and before CPU0 jump * into the idle_loop. @@ -209,8 +231,12 @@ void __init apply_alternatives_all(void) * The text and inittext section are read-only. So re-map Xen to * be able to patch the code. */ - xenmap =3D __vmap(&xen_mfn, 1U << xen_order, 1, 1, PAGE_HYPERVISOR, - VMAP_DEFAULT); + if ( llc_coloring_enabled ) + xenmap =3D xen_remap_colored(xen_mfn, xen_size); + else + xenmap =3D __vmap(&xen_mfn, 1U << xen_order, 1, 1, PAGE_HYPERVISOR, + VMAP_DEFAULT); + /* Re-mapping Xen is not expected to fail during boot. */ BUG_ON(!xenmap); =20 diff --git a/xen/arch/arm/arm64/mmu/head.S b/xen/arch/arm/arm64/mmu/head.S index 665a51a337..a1fc9a82f1 100644 --- a/xen/arch/arm/arm64/mmu/head.S +++ b/xen/arch/arm/arm64/mmu/head.S @@ -428,6 +428,61 @@ FUNC_LOCAL(fail) b 1b END(fail) =20 +/* + * Copy Xen to new location and switch TTBR + * x0 ttbr + * x1 source address + * x2 destination address + * x3 length + * + * Source and destination must be word aligned, length is rounded up + * to a 16 byte boundary. + * + * MUST BE VERY CAREFUL when saving things to RAM over the copy + */ +ENTRY(relocate_xen) + /* + * Copy 16 bytes at a time using: + * x9: counter + * x10: data + * x11: data + * x12: source + * x13: destination + */ + mov x9, x3 + mov x12, x1 + mov x13, x2 + +1: ldp x10, x11, [x12], #16 + stp x10, x11, [x13], #16 + + subs x9, x9, #16 + bgt 1b + + /* + * Flush destination from dcache using: + * x9: counter + * x10: step + * x11: vaddr + * + * This is to ensure data is visible to the instruction cache + */ + dsb sy + + mov x9, x3 + ldr x10, =3Ddcache_line_bytes /* x10 :=3D step */ + ldr x10, [x10] + mov x11, x2 + +1: dc cvac, x11 + + add x11, x11, x10 + subs x9, x9, x10 + bgt 1b + + /* No need for dsb/isb because they are alredy done in switch_ttbr= _id */ + b switch_ttbr_id + /* * Switch TTBR * @@ -453,7 +508,8 @@ FUNC(switch_ttbr_id) =20 /* * 5) Flush I-cache - * This should not be necessary but it is kept for safety. + * This should not be necessary in the general case, but it's need= ed + * for cache coloring because code is relocated in that case. */ ic iallu isb diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index 671eaadbc1..3732d5897e 100644 --- a/xen/arch/arm/arm64/mmu/mm.c +++ b/xen/arch/arm/arm64/mmu/mm.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 #include +#include #include #include =20 @@ -138,27 +139,46 @@ void update_boot_mapping(bool enable) } =20 extern void switch_ttbr_id(uint64_t ttbr); +extern void relocate_xen(uint64_t ttbr, void *src, void *dst, size_t len); =20 typedef void (switch_ttbr_fn)(uint64_t ttbr); +typedef void (relocate_xen_fn)(uint64_t ttbr, void *src, void *dst, size_t= len); =20 void __init switch_ttbr(uint64_t ttbr) { - vaddr_t id_addr =3D virt_to_maddr(switch_ttbr_id); - switch_ttbr_fn *fn =3D (switch_ttbr_fn *)id_addr; + vaddr_t vaddr, id_addr; lpae_t pte; =20 + if ( llc_coloring_enabled ) + vaddr =3D (vaddr_t)relocate_xen; + else + vaddr =3D (vaddr_t)switch_ttbr_id; + + id_addr =3D virt_to_maddr(vaddr); + /* Enable the identity mapping in the boot page tables */ update_identity_mapping(true); =20 /* Enable the identity mapping in the runtime page tables */ - pte =3D pte_of_xenaddr((vaddr_t)switch_ttbr_id); + pte =3D pte_of_xenaddr(vaddr); pte.pt.table =3D 1; pte.pt.xn =3D 0; pte.pt.ro =3D 1; write_pte(&xen_third_id[third_table_offset(id_addr)], pte); =20 /* Switch TTBR */ - fn(ttbr); + if ( llc_coloring_enabled ) + { + relocate_xen_fn *fn =3D (relocate_xen_fn *)id_addr; + + fn(ttbr, _start, (void *)BOOT_RELOC_VIRT_START, _end - _start); + } + else + { + switch_ttbr_fn *fn =3D (switch_ttbr_fn *)id_addr; + + fn(ttbr); + } =20 /* * Disable the identity mapping in the runtime page tables. diff --git a/xen/arch/arm/include/asm/mmu/layout.h b/xen/arch/arm/include/a= sm/mmu/layout.h index a3b546465b..19c0ec63a5 100644 --- a/xen/arch/arm/include/asm/mmu/layout.h +++ b/xen/arch/arm/include/asm/mmu/layout.h @@ -30,6 +30,7 @@ * 10M - 12M Fixmap: special-purpose 4K mapping slots * 12M - 16M Early boot mapping of FDT * 16M - 18M Livepatch vmap (if compiled in) + * 16M - 24M Cache-colored Xen text, data, bss (temporary, if compiled= in) * * 1G - 2G VMAP: ioremap and early_ioremap * @@ -74,6 +75,8 @@ #define BOOT_FDT_VIRT_START (FIXMAP_VIRT_START + FIXMAP_VIRT_SIZE) #define BOOT_FDT_VIRT_SIZE _AT(vaddr_t, MB(4)) =20 +#define BOOT_RELOC_VIRT_START (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) + #ifdef CONFIG_LIVEPATCH #define LIVEPATCH_VMAP_START (BOOT_FDT_VIRT_START + BOOT_FDT_VIRT_SIZE) #define LIVEPATCH_VMAP_SIZE _AT(vaddr_t, MB(2)) diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index 6c8fa6b576..8e10a505db 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -10,6 +10,7 @@ #include =20 #include +#include #include =20 /* Return the LLC way size by probing the hardware */ @@ -64,8 +65,70 @@ unsigned int __init get_llc_way_size(void) return line_size * num_sets; } =20 +/** + * get_xen_paddr - get physical address to relocate Xen to + * + * Xen is relocated to as near to the top of RAM as possible and + * aligned to a XEN_PADDR_ALIGN boundary. + */ +static paddr_t __init get_xen_paddr(paddr_t xen_size) +{ + const struct membanks *mem =3D bootinfo_get_mem(); + paddr_t min_size, paddr =3D 0; + unsigned int i; + + min_size =3D (xen_size + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1); + + /* Find the highest bank with enough space. */ + for ( i =3D 0; i < mem->nr_banks; i++ ) + { + const struct membank *bank =3D &mem->bank[i]; + paddr_t s, e; + + if ( bank->size >=3D min_size ) + { + e =3D consider_modules(bank->start, bank->start + bank->size, + min_size, XEN_PADDR_ALIGN, 0); + if ( !e ) + continue; + +#ifdef CONFIG_ARM_32 + /* Xen must be under 4GB */ + if ( e > GB(4) ) + e =3D GB(4); + if ( e < bank->start ) + continue; +#endif + + s =3D e - min_size; + + if ( s > paddr ) + paddr =3D s; + } + } + + if ( !paddr ) + panic("Not enough memory to relocate Xen\n"); + + printk("Placing Xen at 0x%"PRIpaddr"-0x%"PRIpaddr"\n", + paddr, paddr + min_size); + + return paddr; +} + +static paddr_t __init xen_colored_map_size(void) +{ + return ROUNDUP((_end - _start) * get_max_nr_llc_colors(), XEN_PADDR_AL= IGN); +} + void __init arch_llc_coloring_init(void) { + struct bootmodule *xen_bootmodule =3D boot_module_find_by_kind(BOOTMOD= _XEN); + + BUG_ON(!xen_bootmodule); + + xen_bootmodule->size =3D xen_colored_map_size(); + xen_bootmodule->start =3D get_xen_paddr(xen_bootmodule->size); } =20 /* diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 196974f3e2..1d8d7eb70c 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -20,6 +21,9 @@ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) =20 +#define virt_to_reloc_virt(virt) \ + (((vaddr_t)virt) - XEN_VIRT_START + BOOT_RELOC_VIRT_START) + /* Main runtime page tables */ =20 /* @@ -69,6 +73,7 @@ static void __init __maybe_unused build_assertions(void) /* 2MB aligned regions */ BUILD_BUG_ON(XEN_VIRT_START & ~SECOND_MASK); BUILD_BUG_ON(FIXMAP_ADDR(0) & ~SECOND_MASK); + BUILD_BUG_ON(BOOT_RELOC_VIRT_START & ~SECOND_MASK); /* 1GB aligned regions */ #ifdef CONFIG_ARM_32 BUILD_BUG_ON(XENHEAP_VIRT_START & ~FIRST_MASK); @@ -138,6 +143,9 @@ static void __init __maybe_unused build_assertions(void) =20 lpae_t __init pte_of_xenaddr(vaddr_t va) { + if ( llc_coloring_enabled ) + va =3D virt_to_reloc_virt(va); + return mfn_to_xen_entry(virt_to_mfn(va), MT_NORMAL); } =20 @@ -316,9 +324,44 @@ paddr_t __init consider_modules(paddr_t s, paddr_t e, return e; } =20 +static void __init create_llc_coloring_mappings(void) +{ + lpae_t pte; + unsigned int i; + struct bootmodule *xen_bootmodule =3D boot_module_find_by_kind(BOOTMOD= _XEN); + mfn_t start_mfn =3D maddr_to_mfn(xen_bootmodule->start), mfn; + + for_each_xen_colored_mfn ( start_mfn, mfn, i ) + { + pte =3D mfn_to_xen_entry(mfn, MT_NORMAL); + pte.pt.table =3D 1; /* level 3 mappings always have this bit set */ + xen_xenmap[i] =3D pte; + } + + for ( i =3D 0; i < XEN_NR_ENTRIES(2); i++ ) + { + vaddr_t va =3D BOOT_RELOC_VIRT_START + (i << XEN_PT_LEVEL_SHIFT(2)= ); + + pte =3D mfn_to_xen_entry(virt_to_mfn(xen_xenmap + + i * XEN_PT_LPAE_ENTRIES), + MT_NORMAL); + pte.pt.table =3D 1; + write_pte(&boot_second[second_table_offset(va)], pte); + } +} + /* - * Boot-time pagetable setup. + * Boot-time pagetable setup with coloring support * Changes here may need matching changes in head.S + * + * The cache coloring support consists of: + * - Create colored mapping that conforms to Xen color selection in xen_xe= nmap[] + * - Link the mapping in boot page tables using BOOT_RELOC_VIRT_START as v= addr + * - pte_of_xenaddr() takes care of translating addresses to the new space + * during runtime page tables creation + * - Relocate xen and update TTBR with the new address in the colored space + * (see switch_ttbr()) + * - Protect the new space */ void __init setup_pagetables(void) { @@ -326,6 +369,9 @@ void __init setup_pagetables(void) lpae_t pte, *p; int i; =20 + if ( llc_coloring_enabled ) + create_llc_coloring_mappings(); + arch_setup_page_tables(); =20 #ifdef CONFIG_ARM_64 @@ -353,13 +399,7 @@ void __init setup_pagetables(void) break; pte =3D pte_of_xenaddr(va); pte.pt.table =3D 1; /* third level mappings always have this bit s= et */ - if ( is_kernel_text(va) || is_kernel_inittext(va) ) - { - pte.pt.xn =3D 0; - pte.pt.ro =3D 1; - } - if ( is_kernel_rodata(va) ) - pte.pt.ro =3D 1; + pte.pt.xn =3D 0; /* Permissions will be enforced later. Allow exec= ution */ xen_xenmap[i] =3D pte; } =20 @@ -385,13 +425,48 @@ void __init setup_pagetables(void) ttbr =3D virt_to_maddr(cpu0_pgtable); #endif =20 - switch_ttbr(ttbr); - - xen_pt_enforce_wnx(); - #ifdef CONFIG_ARM_32 per_cpu(xen_pgtable, 0) =3D cpu0_pgtable; #endif + + if ( llc_coloring_enabled ) + ttbr =3D virt_to_maddr(virt_to_reloc_virt(THIS_CPU_PGTABLE)); + + switch_ttbr(ttbr); + + /* Protect Xen */ + for ( i =3D 0; i < XEN_NR_ENTRIES(3); i++ ) + { + vaddr_t va =3D XEN_VIRT_START + (i << PAGE_SHIFT); + lpae_t *entry =3D xen_xenmap + i; + + if ( !is_kernel(va) ) + break; + + pte =3D read_atomic(entry); + + if ( is_kernel_text(va) || is_kernel_inittext(va) ) + { + pte.pt.xn =3D 0; + pte.pt.ro =3D 1; + } else if ( is_kernel_rodata(va) ) { + pte.pt.ro =3D 1; + pte.pt.xn =3D 1; + } else { + pte.pt.xn =3D 1; + pte.pt.ro =3D 0; + } + + write_pte(entry, pte); + } + + /* + * We modified live page-tables. Ensure the TLBs are invalidated + * before setting enforcing the WnX permissions. + */ + flush_xen_tlb_local(); + + xen_pt_enforce_wnx(); } =20 void *__init arch_vmap_virt_end(void) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 568a49b274..5e2c519ce8 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -304,8 +304,6 @@ void asmlinkage __init start_xen(unsigned long fdt_padd= r) /* Initialize traps early allow us to get backtrace when an error occu= rred */ init_traps(); =20 - setup_pagetables(); - smp_clear_cpu_maps(); =20 device_tree_flattened =3D early_fdt_map(fdt_paddr); @@ -329,6 +327,14 @@ void asmlinkage __init start_xen(unsigned long fdt_pad= dr) =20 llc_coloring_init(); =20 + /* + * Page tables must be setup after LLC coloring initialization because + * coloring info are required in order to create colored mappings + */ + setup_pagetables(); + /* Device-tree was mapped in boot page tables, remap it in the new tab= les */ + device_tree_flattened =3D early_fdt_map(fdt_paddr); + setup_mm(); =20 vm_init(); diff --git a/xen/common/llc-coloring.c b/xen/common/llc-coloring.c index 2e7c0f505d..2d6aed5fb4 100644 --- a/xen/common/llc-coloring.c +++ b/xen/common/llc-coloring.c @@ -38,6 +38,8 @@ static unsigned int __ro_after_init xen_num_colors; =20 #define mfn_color_mask (max_nr_colors - 1) #define mfn_to_color(mfn) (mfn_x(mfn) & mfn_color_mask) +#define get_mfn_with_color(mfn, color) \ + (_mfn((mfn_x(mfn) & ~mfn_color_mask) | (color))) =20 /* * Parse the coloring configuration given in the buf string, following the @@ -359,6 +361,22 @@ unsigned int get_max_nr_llc_colors(void) return max_nr_colors; } =20 +mfn_t __init xen_colored_mfn(mfn_t mfn) +{ + unsigned int i, color =3D mfn_to_color(mfn); + + for ( i =3D 0; i < xen_num_colors; i++ ) + { + if ( color =3D=3D xen_colors[i] ) + return mfn; + if ( color < xen_colors[i] ) + return get_mfn_with_color(mfn, xen_colors[i]); + } + + /* Jump to next color space (max_nr_colors mfns) and use the first col= or */ + return get_mfn_with_color(mfn_add(mfn, max_nr_colors), xen_colors[0]); +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h index b3f2fa22bc..4f10a5310f 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -8,6 +8,8 @@ #ifndef __XEN_LLC_COLORING_H__ #define __XEN_LLC_COLORING_H__ =20 +#include + struct domain; struct page_info; struct xen_domctl_set_llc_colors; @@ -28,6 +30,17 @@ static inline void domain_dump_llc_colors(const struct d= omain *d) {} static inline void domain_llc_coloring_free(struct domain *d) {} #endif =20 +/** + * Iterate over each Xen mfn in the colored space. + * @start_mfn: the first mfn that needs to be colored. + * @mfn: the current mfn. + * @i: loop index. + */ +#define for_each_xen_colored_mfn(start_mfn, mfn, i) \ + for ( i =3D 0, mfn =3D xen_colored_mfn(start_mfn); \ + i < (_end - _start) >> PAGE_SHIFT; \ + i++, mfn =3D xen_colored_mfn(mfn_add(mfn, 1)) ) + unsigned int get_llc_way_size(void); void arch_llc_coloring_init(void); int dom0_set_llc_colors(struct domain *d); @@ -36,6 +49,7 @@ int domain_set_llc_colors(struct domain *d, int domain_set_llc_colors_from_str(struct domain *d, const char *str); unsigned int page_to_llc_color(const struct page_info *pg); unsigned int get_max_nr_llc_colors(void); +mfn_t xen_colored_mfn(mfn_t mfn); =20 #endif /* __XEN_LLC_COLORING_H__ */ =20 --=20 2.43.0