From nobody Thu May 9 13:14:58 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=1704189145; cv=none; d=zohomail.com; s=zohoarc; b=kkKEGGaUATOJYHnTvayX+M7LLi5KI9PRy1qNVYFPY00vp12Vi3R/iRtPXkkyuIgj70kNdYonY11qpnVnZId8QJ7RQ5vXL1MeFtf1RyHUd0PcKKX/QnMH+DWyG6yBXZCPxIYXQL689QF8tHgmiceB8Gu9vIR9VMO4m1S89y/57vI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189145; 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=OL4f1m83hPDbhj+UPG8Dssp4ZlvBduVN7Pf6KlCuLUs=; b=Sj1LdeLQFkC32SI556/kL9EqL++c5x3e4jKwTgViVMESWYKK8WqKAzOKZy2KP93/koTKrVTyKshtEuaJ+6CJAkVD+fN7wNxoAbpln4czSyO3oOGkLBW4JnZ6Pde8YECwMKejycqUGb+/0HwDL/Pt2oHrgGgCgQnqauZ2a7WqZQs= 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 1704189145344875.8490516076708; Tue, 2 Jan 2024 01:52:25 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660560.1030040 (Exim 4.92) (envelope-from ) id 1rKbR8-000639-2W; Tue, 02 Jan 2024 09:51:50 +0000 Received: by outflank-mailman (output) from mailman id 660560.1030040; Tue, 02 Jan 2024 09:51:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbR7-00062C-SP; Tue, 02 Jan 2024 09:51:49 +0000 Received: by outflank-mailman (input) for mailman id 660560; Tue, 02 Jan 2024 09:51:48 +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 1rKbR6-00060C-NN for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:48 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8a3e4b36-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:45 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-55642663ac4so1250055a12.1 for ; Tue, 02 Jan 2024 01:51:45 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:43 -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: 8a3e4b36-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189105; x=1704793905; 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=OL4f1m83hPDbhj+UPG8Dssp4ZlvBduVN7Pf6KlCuLUs=; b=AInNBGg08I/EQ/0YT/Gn+lWam/v6iGIhI0kr02EYUETYauv/2UfBYihP/9XOmZobUP +POWQ6ELWsz8v/7w9CFq2uIYj2/DubZClVol/RPfNa7swuG8SzQqAhDdXSE2joeuECQx TTgtaZulXK3OtByAg76+FtVintmeLMtbRB2lEmJfMK8Hj4pxElyBrmZElgHKejEExYhI IcNddVqNq3kiRVlifG+72qrjmtZlngV0RYAHrIO+qI8iohnd+4g3CkDQANGUSlxZ/qdn xZRLPtxFTV8zm8BIci8Isu3DHxDjfBeIp3HaXUq3dBCtsTtHF/B3RYwBToDUxPcelIR4 OEsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189105; x=1704793905; 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=OL4f1m83hPDbhj+UPG8Dssp4ZlvBduVN7Pf6KlCuLUs=; b=lREI+2s3LG2H77MOv+YKvkI6FoI4oRAy/USgot9RSgPwlw8/w9guY6Ldiz4kC41Uj0 9KQQczrnr1WATGXYYF5KD7sXgzUJTfZUQSbmRQKC1zFv6vTimXfCp1tKdNk6Z/0O23N3 8zMa/PKsSTEd+zDkLXmuWknBLyCgx59h9VRMikAxBLgGK9fyXw4M1sn6NuO7liay8nTz Y8LmsRrbqoEZTP9fXEkqfIQTWng0gUiMyYUpMqKfy5D6WmssVOlswO4xuoleiK8EgyeO /OxWEGhwXlLMrG45GOD9D7HbtJ51xBNFq57PHEneKJB0LgJTELeh3o4ifiXU0LdPqtL3 zTVg== X-Gm-Message-State: AOJu0YzFl2UN3jGtjLT9a2rTcGDDyDHRnBWGT1I4OkF2GKPuoxa4Kt11 42/jAVdX0U7wA5dEN6Wx+VWrnVB/1HrJlD2h81BfyzXPV/0= X-Google-Smtp-Source: AGHT+IGcYzPzPCk3GYwYAqo1Lq5Eg2hqUHGkXA0KpjTSuGSGSbKgCvXr8KlByYLBYBmcIr9weZWytA== X-Received: by 2002:a17:906:c801:b0:a26:ac91:143a with SMTP id cx1-20020a170906c80100b00a26ac91143amr8018799ejb.50.1704189104654; Tue, 02 Jan 2024 01:51:44 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Marco Solieri Subject: [PATCH v5 01/13] xen/common: add cache coloring common code Date: Tue, 2 Jan 2024 10:51:26 +0100 Message-Id: <20240102095138.17933-2-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189147144100024 Content-Type: text/plain; charset="utf-8" This commit adds the Last Level Cache (LLC) coloring common header, Kconfig options and functions. Since this is an arch specific feature, actual implementation is postponed to later patches and Kconfig options are placed under xen/arch. LLC colors are a property of the domain, so the domain struct has to be extended. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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 --- xen/arch/Kconfig | 16 ++++++++++++ xen/common/Kconfig | 3 +++ xen/common/domain.c | 4 +++ xen/common/keyhandler.c | 4 +++ xen/include/xen/llc-coloring.h | 46 ++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 5 ++++ 6 files changed, 78 insertions(+) create mode 100644 xen/include/xen/llc-coloring.h diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index 67ba38f32f..aad7e9da38 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -31,3 +31,19 @@ config NR_NUMA_NODES associated with multiple-nodes management. It is the upper bound of the number of NUMA nodes that the scheduler, memory allocation and other NUMA-aware components can handle. + +config LLC_COLORING + bool "Last Level Cache (LLC) coloring" if EXPERT + depends on HAS_LLC_COLORING + +config NR_LLC_COLORS + int "Maximum number of LLC colors" + default 128 + depends on LLC_COLORING + help + Controls the build-time size of various arrays associated with LLC + coloring. 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. + The default value corresponds to an 8 MiB 16-ways LLC, which should be + more than what needed in the general case. diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 310ad4229c..e383f09d97 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_PMAP bool =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index f6f5574996..491585b0bb 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1144,6 +1145,9 @@ static void cf_check complete_domain_destroy(struct r= cu_head *head) struct vcpu *v; int i; =20 + if ( is_domain_llc_colored(d) ) + domain_llc_coloring_free(d); + /* * Flush all state for the vCPU previously having run on the current C= PU. * This is in particular relevant for x86 HVM ones on VMX, so that this diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 99a2d72a02..27c2d324d8 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -307,6 +308,9 @@ static void cf_check dump_domains(unsigned char key) =20 arch_dump_domain_info(d); =20 + if ( is_domain_llc_colored(d) ) + domain_dump_llc_colors(d); + rangeset_domain_printk(d); =20 dump_pageframe_info(d); diff --git a/xen/include/xen/llc-coloring.h b/xen/include/xen/llc-coloring.h new file mode 100644 index 0000000000..cedd97d4b5 --- /dev/null +++ b/xen/include/xen/llc-coloring.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Last Level Cache (LLC) coloring common header + * + * Copyright (C) 2022 Xilinx Inc. + * + * Authors: + * Carlo Nonato + */ +#ifndef __COLORING_H__ +#define __COLORING_H__ + +#include +#include + +#ifdef CONFIG_HAS_LLC_COLORING + +#include + +#ifdef CONFIG_LLC_COLORING +extern bool llc_coloring_enabled; +#define llc_coloring_enabled (llc_coloring_enabled) +#endif + +#endif + +#ifndef llc_coloring_enabled +#define llc_coloring_enabled (false) +#endif + +#define is_domain_llc_colored(d) (llc_coloring_enabled) + +void domain_llc_coloring_free(struct domain *d); +void domain_dump_llc_colors(struct domain *d); + +#endif /* __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 9da91e0e62..dae7fab673 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -626,6 +626,11 @@ struct domain =20 /* Holding CDF_* constant. Internal flags for domain creation. */ unsigned int cdf; + +#ifdef CONFIG_LLC_COLORING + unsigned int *llc_colors; + unsigned int num_llc_colors; +#endif }; =20 static inline struct page_list_head *page_to_list( --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189141; cv=none; d=zohomail.com; s=zohoarc; b=MxO7Qlq3nfqUf3yKMUXEfMuw/4q/sSeKMp97lyYxfcsZIVzN55OQ9E0SjMGB/7Hwvp8gRNFyg5+A9d5prJKEp1bhKs9V4v1Lly2VLbRlZxHXpRRVF13DzPAEKWHFnZojCJ3fCmHwPqhp+8fRryBkARgo9H8humO+A7fCsNwlKhY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189141; 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=+3wy66iUxtnoUDV+3jrP2ySeug0AmKVeI8nRHMPDTHo=; b=PrjecbxabaaqrxuK5LETFhcPzXVqRuOauLoB9//IxBMksO/jM5J9mxb97UAMG62+W0wQPouzIpSk3cAopJlbv6NRvVAuQSY/t4oS1Ps8LpegLxJG1S7KZtk9wdD8sT7iDL3h29URcrdNk04xxOkzn6S3vVrkKQ0/nHePnnSnYbU= 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 1704189141594226.58091213571004; Tue, 2 Jan 2024 01:52:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660561.1030054 (Exim 4.92) (envelope-from ) id 1rKbR9-0006TV-6F; Tue, 02 Jan 2024 09:51:51 +0000 Received: by outflank-mailman (output) from mailman id 660561.1030054; Tue, 02 Jan 2024 09:51:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbR9-0006TO-3g; Tue, 02 Jan 2024 09:51:51 +0000 Received: by outflank-mailman (input) for mailman id 660561; Tue, 02 Jan 2024 09:51:49 +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 1rKbR7-00060C-7d for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:49 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8afc4bd4-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:47 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a1915034144so1036087166b.0 for ; Tue, 02 Jan 2024 01:51:47 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:45 -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: 8afc4bd4-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189106; x=1704793906; 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=+3wy66iUxtnoUDV+3jrP2ySeug0AmKVeI8nRHMPDTHo=; b=gUJw/owfirFRV+XADwTjhcN7bWgh7n2XvTQcbLH+n4InfL0xnNvQz0bA373CGMO/7/ Jhx42sf3UYKqUrFwbxOn1rIaZ3vuI1zOHkluwDtgH2Gb7Uhxbzm02Y8qXlNGArXd3T3Y AjWOGRYr4j7SVltlhPRJuZCCysMhWGjE5lhNKlH1RzN7ulr7/pjvwt+Mltsxe0n5/lOu 8hXeh/SSImiDfqJIE87kAM+XgEwOW6RS1euIAx5SMjG7XiMphOb9VrK1VCCOq5pr1AHv lp8m9ApSXcyJ8t/gWoCWCUrs/BEqnySdBJ1kqLIaiQg9rw0Q3Rr85X5OL9LLe5Fd5BDI Cs1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189106; x=1704793906; 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=+3wy66iUxtnoUDV+3jrP2ySeug0AmKVeI8nRHMPDTHo=; b=dTTO1bYO9Xe5mR4B06tjNaih5TkOJ/Fq9KdUZ9po9+AP2Y5HNx2jyQVnK9+3qEVXfR Q4kIiY6aOPssfY+oq66v4cf58kq4EPc4CHc8TfU4VB49JcFyEGed8ooY28CGdu2Ig41z X+eF7ovey/2stP18zUSFPV0kvZjzC1fr3nzFz7TcZHcq6Xj9D9g+MFDgzyfIl8+CPThy bRE1vZTiSxIp9rlhVpcywKcltNDK531kHNlUgloKBJ90QzMSZH02GrvC47xRWryUQFG8 h4DPckRmLAzsd+VcL/zw4ZCJiVZ8WuXFWfHr36NghLk2LuFHRdrtpnW0eBxzbo4BVPML FQ7w== X-Gm-Message-State: AOJu0Yx3vv9rVaG3DgdS7y0zLLOhjq2s6/cmM4LNpLQy5A/71/4phclZ CRFz1MgfPiKVMA8v0psIBwOI+opNfqqu8lCrCSpcYB9IERk= X-Google-Smtp-Source: AGHT+IG8x5m5vL2LC1Vaz3Fuk/l9bhg4KseE5ILgFYKBQ2VhWoEymTgBveZjKlc8EoQhRJn5gGVgtQ== X-Received: by 2002:a17:906:388e:b0:a23:71cf:ab11 with SMTP id q14-20020a170906388e00b00a2371cfab11mr8040497ejd.10.1704189105830; Tue, 02 Jan 2024 01:51:45 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v5 02/13] xen/arm: add cache coloring initialization Date: Tue, 2 Jan 2024 10:51:27 +0100 Message-Id: <20240102095138.17933-3-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189143100100013 Content-Type: text/plain; charset="utf-8" This commit implements functions declared in the LLC coloring common header for arm64 and adds documentation. It also adds two command line options: a runtime switch for the cache coloring feature and the LLC way size parameter. The feature init function consists of an auto probing of the cache layout necessary to retrieve the LLC way size which is used to compute the number of platform colors. It also adds a debug-key to dump general cache coloring info. 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 --- 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/arm/cache-coloring.rst | 97 ++++++++++++++ docs/misc/xen-command-line.pandoc | 28 +++++ xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/dom0less-build.c | 6 + xen/arch/arm/include/asm/llc-coloring.h | 28 +++++ xen/arch/arm/include/asm/processor.h | 16 +++ xen/arch/arm/llc-coloring.c | 161 ++++++++++++++++++++++++ xen/arch/arm/setup.c | 7 ++ 9 files changed, 345 insertions(+) create mode 100644 docs/misc/arm/cache-coloring.rst create mode 100644 xen/arch/arm/include/asm/llc-coloring.h create mode 100644 xen/arch/arm/llc-coloring.c diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst new file mode 100644 index 0000000000..eabf8f5d1b --- /dev/null +++ b/docs/misc/arm/cache-coloring.rst @@ -0,0 +1,97 @@ +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. + +To compile LLC coloring support set ``CONFIG_LLC_COLORING=3Dy``. + +If needed, change the maximum number of colors with +``CONFIG_NR_LLC_COLORS=3D``. + +Compile Xen and the toolstack and then configure it 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 allows eliminating this +mutual interference, and thus guaranteeing higher and more predictable +performances for memory accesses. +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 + :........................... ... . + : + . . ..................................: + +There are two pragmatic lesson to be learnt. + +1. If one wants to avoid cache interference between two domains, different + colors needs to be used for their memory. + +2. Color assignment must privilege contiguity in the partitioning. E.g., + assigning colors (0,1) to domain I and (2,3) to domain J is better th= an + assigning colors (0,2) to I and (1,3) to J. + +How to compute the number of colors +*********************************** + +To compute the number of available colors for a specific platform, the siz= e of +an LLC way and the page size used by Xen must be known. The first paramete= r can +be found in the processor manual or can be also computed dividing the total +cache size by the number of its ways. The second parameter is the minimum +amount of memory that can be mapped by the hypervisor, thus dividing the w= ay +size by the page size, the number of total cache partitions is found. So f= or +example, an Arm Cortex-A53 with a 16-ways associative 1 MiB LLC, can isola= te up +to 16 colors when pages are 4 KiB in size. + +Cache layout is probed automatically by Xen itself, but a possibility to +manually set the way size it's left for the user to overcome failing situa= tions +or for debugging/testing purposes. See `Command line parameters`_ for more +information on that. + +Command line parameters +*********************** + +More specific documentation is available at `docs/misc/xen-command-line.pa= ndoc`. + ++----------------------+-------------------------------+ +| **Parameter** | **Description** | ++----------------------+-------------------------------+ +| ``llc-coloring`` | enable coloring at runtime | ++----------------------+-------------------------------+ +| ``llc-way-size`` | set the LLC way size | ++----------------------+-------------------------------+ + +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 possibile when LLC coloring is enabled, +because that memory can't be guaranteed to use only colors assigned to the +domain. diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 8e65f8bd18..22d2d5b6cf 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1713,6 +1713,34 @@ 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 options is +available only when `CONFIG_LLC_COLORING` is enabled. See the general +cache coloring documentation for more info. + +### llc-way-size (arm64) +> `=3D ` + +> Default: `Obtained from the hardware` + +Specify the way size of the Last Level Cache. This options is available on= ly +when `CONFIG_LLC_COLORING` is enabled. It is an optional, expert-only para= meter +and it is used to calculate the number of available LLC colors on the plat= form. +It can be obtained by dividing the total LLC size by the number of its +associative ways. +By default, the value is automatically computed by probing the hardware, b= ut in +case of specific needs, it can be manually set. Those include failing prob= ing +and debugging/testing purposes so that it's possibile to emulate platforms= with +different number of supported colors. +An important detail to highlight is that the current implementation of the +cache coloring technique requires the number of colors to be a power of 2,= and +consequently, also the LLC way size must be so. A value that doesn't match= this +requirement is aligned down to the previous power of 2. + ### lock-depth-size > `=3D ` =20 diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 50e9bfae1a..55143f86a9 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 =20 config ARM def_bool y diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 33c677672f..c9a1cd298d 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -37,6 +37,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-y +=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 fb63ec6fd1..1142f7f74a 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 @@ -879,7 +880,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/llc-coloring.h b/xen/arch/arm/include= /asm/llc-coloring.h new file mode 100644 index 0000000000..7885e9e3f5 --- /dev/null +++ b/xen/arch/arm/include/asm/llc-coloring.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Last Level Cache (LLC) coloring support for ARM + * + * Copyright (C) 2022 Xilinx Inc. + * + * Authors: + * Luca Miccio + * Carlo Nonato + */ +#ifndef __ASM_ARM_COLORING_H__ +#define __ASM_ARM_COLORING_H__ + +#include + +bool __init llc_coloring_init(void); + +#endif /* __ASM_ARM_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/arch/arm/include/asm/processor.h b/xen/arch/arm/include/as= m/processor.h index 8e02410465..fd5e8eba98 100644 --- a/xen/arch/arm/include/asm/processor.h +++ b/xen/arch/arm/include/asm/processor.h @@ -18,6 +18,22 @@ #define CTR_IDC_SHIFT 28 #define CTR_DIC_SHIFT 29 =20 +/* CCSIDR Current Cache Size ID Register */ +#define CCSIDR_LINESIZE_MASK _AC(0x7, ULL) +#define CCSIDR_NUMSETS_SHIFT 13 +#define CCSIDR_NUMSETS_MASK _AC(0x3fff, ULL) +#define CCSIDR_NUMSETS_SHIFT_FEAT_CCIDX 32 +#define CCSIDR_NUMSETS_MASK_FEAT_CCIDX _AC(0xffffff, ULL) + +/* CCSELR Cache Size Selection Register */ +#define CCSELR_LEVEL_MASK _AC(0x7, UL) +#define CCSELR_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..37d647f038 --- /dev/null +++ b/xen/arch/arm/llc-coloring.c @@ -0,0 +1,161 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Last Level Cache (LLC) coloring support for ARM + * + * Copyright (C) 2022 Xilinx Inc. + * + * Authors: + * Luca Miccio + * Carlo Nonato + */ +#include +#include +#include +#include +#include + +#include +#include + +bool __ro_after_init llc_coloring_enabled; +boolean_param("llc-coloring", llc_coloring_enabled); + +/* Size of an LLC way */ +static unsigned int __ro_after_init llc_way_size; +size_param("llc-way-size", llc_way_size); +/* Number of colors available in the LLC */ +static unsigned int __ro_after_init nr_colors =3D CONFIG_NR_LLC_COLORS; + +/* Return the LLC way size by probing the hardware */ +static 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 && !((clidr_el1 >> CLIDR_CTYPEn_SHIFT(n)) & CLIDR_CTYPE= n_MASK); + n-- ); + + if ( n =3D=3D 0 ) + return 0; + + WRITE_SYSREG(((n - 1) & CCSELR_LEVEL_MASK) << CCSELR_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 1 << ((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; +} + +static void print_colors(unsigned int *colors, unsigned int num_colors) +{ + unsigned int i; + + printk("{ "); + for ( i =3D 0; i < num_colors; i++ ) { + unsigned int start =3D colors[i], end =3D colors[i]; + + printk("%u", start); + + for ( ; + i < num_colors - 1 && colors[i] + 1 =3D=3D colors[i + 1]; + i++, end++ ); + + if ( start !=3D end ) + printk("-%u", end); + + if ( i < num_colors - 1 ) + printk(", "); + } + printk(" }\n"); +} + +static void dump_coloring_info(unsigned char key) +{ + printk("'%c' pressed -> dumping LLC coloring general info\n", key); + printk("LLC way size: %u KiB\n", llc_way_size >> 10); + printk("Number of LLC colors supported: %u\n", nr_colors); +} + +bool __init llc_coloring_init(void) +{ + if ( !llc_way_size && !(llc_way_size =3D get_llc_way_size()) ) + { + printk(XENLOG_ERR + "Probed LLC way size is 0 and no custom value provided\n"); + return false; + } + + /* + * The maximum number of colors must be a power of 2 in order to corre= ctly + * map them to bits of an address, so also the LLC way size must be so. + */ + if ( llc_way_size & (llc_way_size - 1) ) + { + printk(XENLOG_WARNING "LLC way size (%u) isn't a power of 2.\n", + llc_way_size); + llc_way_size =3D 1U << flsl(llc_way_size); + printk(XENLOG_WARNING + "Using %u instead. Performances will be suboptimal\n", + llc_way_size); + } + + nr_colors =3D llc_way_size >> PAGE_SHIFT; + + if ( nr_colors < 2 || nr_colors > CONFIG_NR_LLC_COLORS ) + { + printk(XENLOG_ERR "Number of LLC colors (%u) not in range [2, %u]\= n", + nr_colors, CONFIG_NR_LLC_COLORS); + return false; + } + + register_keyhandler('K', dump_coloring_info, "dump LLC coloring info",= 1); + + return true; +} + +void domain_llc_coloring_free(struct domain *d) +{ + xfree(d->llc_colors); +} + +void domain_dump_llc_colors(struct domain *d) +{ + printk("Domain %pd has %u LLC colors: ", d, 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/arch/arm/setup.c b/xen/arch/arm/setup.c index 59dd9bb25a..4c16b566db 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -746,6 +747,12 @@ void asmlinkage __init start_xen(unsigned long boot_ph= ys_offset, printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); =20 + if ( llc_coloring_enabled ) + { + if ( !llc_coloring_init() ) + panic("Xen LLC coloring support: setup failed\n"); + } + setup_mm(); =20 /* Parse the ACPI tables for possible boot-time configuration */ --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189140; cv=none; d=zohomail.com; s=zohoarc; b=WdF1GId7+tNRO61ooA9iJtIByNklqcXn63WOFkiDLoWvWfAQjJdGOwv6oGwQexWpemtVbz59ktNJEgiTg+KuB152xDb8Nbm3WkNZkFUiX+t3Fvhntorzd9Ts5LR4N7weUnPpmeQGwQqKozkrun1Dtj+P/KEOZhduhLaUcNDeCXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189140; 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=6cdVnvQoUyPRwYMQxfZ9u1dR3w5GTzbkoxvk1ADPypg=; b=PzNjaMGVWSKo/zUl1T2dNm6Uru0aSiva5XEUMB8EiuGvqnFgKx+EQ2qcICbhc6QWvt1LJc7jJhSWmvtQgqwGnjpkyTmyx2bcHEc2MVryBLj5kHPBELXrlu8fli9No0U7+VeweifdLc/kQ6G0SGAAxOP7Lrg/iDgZfvOpe0GiZZo= 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 1704189140882809.9664009237256; Tue, 2 Jan 2024 01:52:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660564.1030085 (Exim 4.92) (envelope-from ) id 1rKbRC-0007EV-5P; Tue, 02 Jan 2024 09:51:54 +0000 Received: by outflank-mailman (output) from mailman id 660564.1030085; Tue, 02 Jan 2024 09:51:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRC-0007EK-0u; Tue, 02 Jan 2024 09:51:54 +0000 Received: by outflank-mailman (input) for mailman id 660564; Tue, 02 Jan 2024 09:51:52 +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 1rKbRA-0006VR-CN for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:52 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8bb78e21-a954-11ee-98ef-6d05b1d4d9a1; Tue, 02 Jan 2024 10:51:50 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a279ce3aab9so292230966b.0 for ; Tue, 02 Jan 2024 01:51:48 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:46 -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: 8bb78e21-a954-11ee-98ef-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189107; x=1704793907; 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=6cdVnvQoUyPRwYMQxfZ9u1dR3w5GTzbkoxvk1ADPypg=; b=b6mljZsd/lUWLDdVY9R6HALCm+npOIbXFwIGPXCQ65QGr+HyTEt9Wy6WgClz2NeyIl dNOF+qWEKou6Dd5NjraGVo49rLFizwENmO/wWILXqBMPcvpYTC598+8zmsZFKELloZzn yZgij2bCxsT3unYfVConMGS7WonKPkh1Q94r2Q8Wd9vQa+r8F9h36BkApEttaQsk3RKm EHFvPmrWhkjSxxpn6Vv5BRyk7qfkqqeWSNp8KwJWb4hfafkfZPEbCWR+aVIvf5v/+aym FaMJ7Ht4PIopm8CPLNCxuvRsZFBFHJcIIJ6DLVDgDYgZaVVjleGlhnAFbKuItJQhHJeZ CFPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189107; x=1704793907; 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=6cdVnvQoUyPRwYMQxfZ9u1dR3w5GTzbkoxvk1ADPypg=; b=lr4Hf0geRxOG724eiKGFAYzaFdb7Efibz0M8YCz15P4/Bo1qzIPeJy/JOuoW+xgBAU YJ3DxrjVvd95DIycJWkD35+cnwsPOV0P31VYqsHL8jeLmD//Dl96ji1FaXvvNzwl92uD SezlExDHYGgCSV5veG9fMuyqz5nzYLP8gK8sBE5YuDfCe4q1eykXLiET9I9u0u+fxYft +nNPRKsie1GkijWWMqH2NZIy0ZzkZdgIEDhaY04yRKW8lOAoCR4P6WL4DkeJweVoltC0 BXMJvzPRg4FnC40zMZ/IYh/G0ENCXJ080SWL3aXdcjLrkAY/D0IXIN8q46PpUgUxzBH8 eD6g== X-Gm-Message-State: AOJu0Yxcw5+0mQpB1/FvfGEwqN/y3Boo4lz8PhDOpyagSKweUyzTm26M R9lTcCGPvAilPwd9TO7g078dgtx/T587Kow3nJDbQxIj5Ys= X-Google-Smtp-Source: AGHT+IHbUsHvCnMCDXcDi1ikGMVPplEsFaGr+NqMxS47lMqoodPrke//UqsHnlyBsUxdi/oWUpVCqw== X-Received: by 2002:a17:906:f109:b0:a1d:8351:a00e with SMTP id gv9-20020a170906f10900b00a1d8351a00emr3902124ejb.121.1704189107184; Tue, 02 Jan 2024 01:51:47 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v5 03/13] xen/arm: add Dom0 cache coloring support Date: Tue, 2 Jan 2024 10:51:28 +0100 Message-Id: <20240102095138.17933-4-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189141144100007 Content-Type: text/plain; charset="utf-8" This commit allows the user to set the cache coloring configuration for Dom0 via a command line parameter. Since cache coloring and static memory are incompatible, direct mapping Dom0 isn't possible when coloring is enabled. A common configuration syntax for cache colors is also introduced. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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/arm/cache-coloring.rst | 29 ++++++ docs/misc/xen-command-line.pandoc | 9 ++ xen/arch/arm/domain_build.c | 60 ++++++++++- xen/arch/arm/include/asm/llc-coloring.h | 1 + xen/arch/arm/llc-coloring.c | 128 ++++++++++++++++++++++++ 5 files changed, 224 insertions(+), 3 deletions(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index eabf8f5d1b..acf82c3df8 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -84,6 +84,35 @@ More specific documentation is available at `docs/misc/x= en-command-line.pandoc`. +----------------------+-------------------------------+ | ``llc-way-size`` | set the LLC way size | +----------------------+-------------------------------+ +| ``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 Known issues and limitations **************************** diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 22d2d5b6cf..51f6adf035 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 options is available only when +`CONFIG_LLC_COLORING` is enabled. If the parameter is not set, all availab= le +colors are chosen and the user is warned on Xen serial console. + ### dom0_max_vcpus =20 Either: diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 6945b9755d..482c059bfa 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 @@ -414,7 +415,7 @@ static void __init allocate_memory_11(struct domain *d, } } =20 -#ifdef CONFIG_DOM0LESS_BOOT +#if defined(CONFIG_DOM0LESS_BOOT) || defined(CONFIG_LLC_COLORING) bool __init allocate_bank_memory(struct domain *d, struct kernel_info *kin= fo, gfn_t sgfn, paddr_t tot_size) { @@ -478,6 +479,49 @@ bool __init allocate_bank_memory(struct domain *d, str= uct kernel_info *kinfo, } #endif =20 +static void __init allocate_memory(struct domain *d, struct kernel_info *k= info) +{ + 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); + + kinfo->mem.nr_banks =3D 0; + bank_size =3D MIN(GUEST_RAM0_SIZE, kinfo->unassigned_mem); + if ( !allocate_bank_memory(d, 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(d, kinfo, gaddr_to_gfn(GUEST_RAM1_BASE), + bank_size) ) + goto fail; + + if ( kinfo->unassigned_mem ) + goto fail; + + for( i =3D 0; i < kinfo->mem.nr_banks; i++ ) + { + printk(XENLOG_INFO "%pd BANK[%d] %#"PRIpaddr"-%#"PRIpaddr" (%ldMB)= \n", + d, + i, + kinfo->mem.bank[i].start, + kinfo->mem.bank[i].start + kinfo->mem.bank[i].size, + /* Don't want format this as PRIpaddr (16 digit hex) */ + (unsigned long)(kinfo->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); +} + /* * When PCI passthrough is available we want to keep the * "linux,pci-domain" in sync for every host bridge. @@ -2072,7 +2116,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_llc_colored(d) ) + allocate_memory(d, &kinfo); + else + allocate_memory_11(d, &kinfo); find_gnttab_region(d, &kinfo); =20 rc =3D process_shm_chosen(d, &kinfo); @@ -2116,6 +2163,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 */ @@ -2143,10 +2191,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)", = rc); + if ( alloc_dom0_vcpu0(dom0) =3D=3D NULL ) panic("Error creating domain 0 vcpu0\n"); =20 diff --git a/xen/arch/arm/include/asm/llc-coloring.h b/xen/arch/arm/include= /asm/llc-coloring.h index 7885e9e3f5..ee5551e3cc 100644 --- a/xen/arch/arm/include/asm/llc-coloring.h +++ b/xen/arch/arm/include/asm/llc-coloring.h @@ -14,6 +14,7 @@ #include =20 bool __init llc_coloring_init(void); +int dom0_set_llc_colors(struct domain *d); =20 #endif /* __ASM_ARM_COLORING_H__ */ =20 diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index 37d647f038..5ce58aba70 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -26,6 +26,63 @@ size_param("llc-way-size", llc_way_size); /* Number of colors available in the LLC */ static unsigned int __ro_after_init nr_colors =3D CONFIG_NR_LLC_COLORS; =20 +static unsigned int __ro_after_init dom0_colors[CONFIG_NR_LLC_COLORS]; +static unsigned int __ro_after_init 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 parse_color_config(const char *buf, unsigned int *colors, + unsigned int *num_colors) +{ + const char *s =3D buf; + + if ( !colors || !num_colors ) + return -EINVAL; + + *num_colors =3D 0; + + while ( *s !=3D '\0' ) + { + if ( *s !=3D ',' ) + { + 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 nr_colors ) + return -EINVAL; + for ( color =3D start; color <=3D end; color++ ) + colors[(*num_colors)++] =3D color; + } + else + s++; + } + + return *s ? -EINVAL : 0; +} + +static int __init parse_dom0_colors(const char *s) +{ + return parse_color_config(s, dom0_colors, &dom0_num_colors); +} +custom_param("dom0-llc-colors", parse_dom0_colors); + /* Return the LLC way size by probing the hardware */ static unsigned int __init get_llc_way_size(void) { @@ -102,6 +159,28 @@ static void dump_coloring_info(unsigned char key) printk("Number of LLC colors supported: %u\n", nr_colors); } =20 +static bool check_colors(unsigned int *colors, unsigned int num_colors) +{ + unsigned int i; + + if ( num_colors > nr_colors ) + { + printk(XENLOG_ERR "Number of LLC colors requested > %u\n", nr_colo= rs); + return false; + } + + for ( i =3D 0; i < num_colors; i++ ) + { + if ( colors[i] >=3D nr_colors ) + { + printk(XENLOG_ERR "LLC color %u >=3D %u\n", colors[i], nr_colo= rs); + return false; + } + } + + return true; +} + bool __init llc_coloring_init(void) { if ( !llc_way_size && !(llc_way_size =3D get_llc_way_size()) ) @@ -150,6 +229,55 @@ void domain_dump_llc_colors(struct domain *d) print_colors(d->llc_colors, d->num_llc_colors); } =20 +static int domain_alloc_colors(struct domain *d, unsigned int num_colors) +{ + d->num_llc_colors =3D num_colors; + + if ( !num_colors ) + return 0; + + d->llc_colors =3D xmalloc_array(unsigned int, num_colors); + if ( !d->llc_colors ) + { + printk("Can't allocate LLC colors for domain %pd\n", d); + return -1; + } + + return 0; +} + +static int domain_check_colors(struct domain *d) +{ + unsigned int i; + + if ( !d->num_llc_colors ) + { + printk(XENLOG_WARNING + "LLC color config not found for %pd. Using default\n", d); + if ( domain_alloc_colors(d, nr_colors) ) + return -ENOMEM; + for ( i =3D 0; i < nr_colors; i++ ) + d->llc_colors[i] =3D i; + } + else if ( !check_colors(d->llc_colors, d->num_llc_colors) ) + { + printk(XENLOG_ERR "Bad LLC color config for %pd\n", d); + return -EINVAL; + } + + return 0; +} + +int dom0_set_llc_colors(struct domain *d) +{ + if ( domain_alloc_colors(d, dom0_num_colors) ) + return -ENOMEM; + + memcpy(d->llc_colors, dom0_colors, sizeof(unsigned int) * dom0_num_col= ors); + + return domain_check_colors(d); +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189144; cv=none; d=zohomail.com; s=zohoarc; b=S/beEvTttQ9+tkvPpFO9FAwBRfjD+ju4b8DySd6/arXo2qCzR0I/LXQpZ1lKa43NESKJuBQVihzrb99oSKBO6I3ISggknUnAdfB+HgBRMZZHmAy3dzl3Q2v4P32e5ZlJ2bUO8oPrPiCcZvpryzew9g3v2WvYL+DVeU+TG/lm39Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189144; 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=VQRNz81fimbLLr0I8jJGaXDeWrq4/HkqdivnNzazx98=; b=S2pYfMM771eKLSJlYHwdIFwSkOXJUmRqBrGpfW8atbFSREhn6l6m2jL1R829S8/shRDzLSDhYFQOTh9y4WvpQ9yn8j+rj5tndgBUf4BiHzagGaxWS8c0kJdPQKlGj19UuH+WITC9+9CG2Krd2IMTsdDK9EAdQfJiUd3UmuGP/aA= 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 1704189144898551.2045912536171; Tue, 2 Jan 2024 01:52:24 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660562.1030062 (Exim 4.92) (envelope-from ) id 1rKbR9-0006a7-L9; Tue, 02 Jan 2024 09:51:51 +0000 Received: by outflank-mailman (output) from mailman id 660562.1030062; Tue, 02 Jan 2024 09:51:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbR9-0006ZZ-H0; Tue, 02 Jan 2024 09:51:51 +0000 Received: by outflank-mailman (input) for mailman id 660562; Tue, 02 Jan 2024 09:51:50 +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 1rKbR8-00060C-QX for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:50 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8c456ca3-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:49 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a26f73732c5so591225166b.3 for ; Tue, 02 Jan 2024 01:51:49 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:47 -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: 8c456ca3-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189108; x=1704793908; 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=VQRNz81fimbLLr0I8jJGaXDeWrq4/HkqdivnNzazx98=; b=iz4mGAwapK8tT/WcRGthefgxpQYI6rDQ6qeIqNIbXNNmqGhienYGAIDDSYIb69hzQl CsnozwKsrkBwBO5imJ9ARim2WabG5KARqy52k7iXxP5nVxikWzikBS0AuvQZkhiqxJjH /PTVy6bssUg2CZiCF4cUZKoeumlYVGjb4nbHEOt98tKSc2cFWuNj9lDCts3B0RgqKDSj yDpL5LayUGEhwxHaICorJIE7RAJtkv3XE0az/uv8Jdbmn3zCV+isah8Ok4RSELZVhP9G T5W1r572ac0YoSJMKAMKPBkGVyQuBOBUWV2W2kz7t1mIpu82u2M5wnu7M0fxqQJvuRnS Btnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189108; x=1704793908; 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=VQRNz81fimbLLr0I8jJGaXDeWrq4/HkqdivnNzazx98=; b=XM8oL9Qo7KaZ8Nv7mti38Vq82FARQaerfs8P/xvYgDqXL3sm7J2XHgRTAeXDqDtn8E ndANyjdysqm80KiYMS4OT5RRc1JzpejzvRL4X0HHs+9Srqq296rLVl8/eZDER1lViFyg tjDHJHeNWPkkC1D7og4D1oAecwUYJKgBuDBe3NnJeyG+m2l6mBja2eIUHXCi/ywTygi+ UaU6Z3SmgrMwNt2r0QrSzNbDkoBiKxfN2Ut02K/OPepk8C7S9VT4N/AFmlLnlQ5At94k NaPfW9lxNnxUFLqEuQwTS0+293HoceV0LWtBobn26x9HdnigtrHDZnnXeSfKw1RLHAXg 9jgQ== X-Gm-Message-State: AOJu0YzvmUGlieIvIDJ8XG19h/GfqoPpg9k7OcbegG+nUYKyxOseZGGM TW25MfYQO8aX9tyHCIDl+Ao/tx9F92u56UgW/zAy/XGs7e8= X-Google-Smtp-Source: AGHT+IELXlZfIdw0RuAD1JY9Yn7d1evpLkgyhlQamNfyEMCkS/VP7srlA2A17TbDyWOsMYFbYDBIhQ== X-Received: by 2002:a17:906:b3a1:b0:a1d:15ac:14fc with SMTP id uh33-20020a170906b3a100b00a1d15ac14fcmr6335287ejc.22.1704189108303; Tue, 02 Jan 2024 01:51:48 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v5 04/13] xen: extend domctl interface for cache coloring Date: Tue, 2 Jan 2024 10:51:29 +0100 Message-Id: <20240102095138.17933-5-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189147101100023 Content-Type: text/plain; charset="utf-8" This commit updates the domctl interface to allow the user to set cache coloring configurations from the toolstack. It also implements the functionality for arm64. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- v5: - added a new hypercall to set colors - uint for the guest handle v4: - updated XEN_DOMCTL_INTERFACE_VERSION --- xen/arch/arm/llc-coloring.c | 17 +++++++++++++++++ xen/common/domctl.c | 11 +++++++++++ xen/include/public/domctl.h | 10 +++++++++- xen/include/xen/llc-coloring.h | 3 +++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index 5ce58aba70..a08614ec36 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -9,6 +9,7 @@ * Carlo Nonato */ #include +#include #include #include #include @@ -278,6 +279,22 @@ int dom0_set_llc_colors(struct domain *d) return domain_check_colors(d); } =20 +int domain_set_llc_colors_domctl(struct domain *d, + const struct xen_domctl_set_llc_colors *c= onfig) +{ + if ( d->num_llc_colors ) + return -EEXIST; + + if ( domain_alloc_colors(d, config->num_llc_colors) ) + return -ENOMEM; + + if ( copy_from_guest(d->llc_colors, config->llc_colors, + config->num_llc_colors) ) + return -EFAULT; + + return domain_check_colors(d); +} + /* * Local variables: * mode: C diff --git a/xen/common/domctl.c b/xen/common/domctl.c index f5a71ee5f7..b6867d0602 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -858,6 +859,16 @@ 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 ( !llc_coloring_enabled ) + break; + + ret =3D domain_set_llc_colors_domctl(d, &op->u.set_llc_colors); + if ( ret =3D=3D -EEXIST ) + printk(XENLOG_ERR + "Can't set LLC colors on an already created domain\n"); + break; + default: ret =3D arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index a33f9ec32b..2b12069294 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -21,7 +21,7 @@ #include "hvm/save.h" #include "memory.h" =20 -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000016 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000017 =20 /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. @@ -1190,6 +1190,12 @@ struct xen_domctl_vmtrace_op { typedef struct xen_domctl_vmtrace_op xen_domctl_vmtrace_op_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_vmtrace_op_t); =20 +struct xen_domctl_set_llc_colors { + /* IN LLC coloring parameters */ + unsigned int num_llc_colors; + XEN_GUEST_HANDLE_64(uint) llc_colors; +}; + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1277,6 +1283,7 @@ struct xen_domctl { #define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_get_paging_mempool_size 85 #define XEN_DOMCTL_set_paging_mempool_size 86 +#define XEN_DOMCTL_set_llc_colors 87 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1339,6 +1346,7 @@ struct xen_domctl { struct xen_domctl_vuart_op vuart_op; struct xen_domctl_vmtrace_op vmtrace_op; struct xen_domctl_paging_mempool paging_mempool; + 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 cedd97d4b5..fa2edc8ad8 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -33,6 +33,9 @@ extern bool llc_coloring_enabled; void domain_llc_coloring_free(struct domain *d); void domain_dump_llc_colors(struct domain *d); =20 +int domain_set_llc_colors_domctl(struct domain *d, + const struct xen_domctl_set_llc_colors *c= onfig); + #endif /* __COLORING_H__ */ =20 /* --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189140; cv=none; d=zohomail.com; s=zohoarc; b=E0Hy/J6DTgNOho3EITAKEAbaYEvrvcw1iAo3WKSqe8FaaTJ04EJ9TRwt6kkU2/hoDssQAtyKc2rLL3U9Vwbsuox5ys1Q24MutikuHrmVekOD4FAzPXZIAqoPjGcpf6PCDtMVWfcilRfxokRusBRcMkK1hXNIwe+IBmptnYjBQ3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189140; 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=WZCx1mNMuVohrVNBngIS2gZlUF4VUOJwKdzo4Q3IzJY=; b=HPJEW1/6QUZzXEXOTduxxpoR39HfXONaF9RlQFsxbWxmOfLzlROq8rAWmXRuJOsEpRmfiIrn/csoGiaOhYUu41QctyMfsLY8epCCNuJip+6kSQ4p/v3OSLn/h27JZVyGiQNJPFkXcFqUvdfUXUd0CasrL/h/OjANG46EwRBPhSQ= 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 170418914072622.685315887962474; Tue, 2 Jan 2024 01:52:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660563.1030075 (Exim 4.92) (envelope-from ) id 1rKbRA-0006xj-T5; Tue, 02 Jan 2024 09:51:52 +0000 Received: by outflank-mailman (output) from mailman id 660563.1030075; Tue, 02 Jan 2024 09:51:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRA-0006wV-Ok; Tue, 02 Jan 2024 09:51:52 +0000 Received: by outflank-mailman (input) for mailman id 660563; Tue, 02 Jan 2024 09:51:52 +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 1rKbRA-0006VR-12 for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:52 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8ce3d89a-a954-11ee-98ef-6d05b1d4d9a1; Tue, 02 Jan 2024 10:51:50 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5565b66e9c5so927858a12.3 for ; Tue, 02 Jan 2024 01:51:50 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:48 -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: 8ce3d89a-a954-11ee-98ef-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189109; x=1704793909; 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=WZCx1mNMuVohrVNBngIS2gZlUF4VUOJwKdzo4Q3IzJY=; b=pB1N7RJvknJjQbFXF1fxze4UWz8mwkQ0nunhzRZKedi6QHGNSP7bzcrtXIGcuWzxzu qniXAC7oM0zlY+tsOsApKiapGuj53pifJ1QloXHWbVhflCndnTo/+2JTdbZ03i9TM3ws Or9U6lLlPUabHxA9BtprAVFhf/Hjk2kKq3SDBp2dotcFMF5KatGfOtY9FjKsPcr7HTRO d5DDbM9lkSQo0af7VGvFGUzxHgqU2bU6l/JySCzz8DpVjcnp8IZ2easUpjZPzThgvjNx HyD41kOBbS4WDvr/WCefAovMhWh7q6RO4qinTcV9lpNussSjuZF1F4K997fifLXvB596 x/og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189109; x=1704793909; 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=WZCx1mNMuVohrVNBngIS2gZlUF4VUOJwKdzo4Q3IzJY=; b=EaKBJhf8jJ2TT6xyAv0GCiUnccBwrtzpPn9OssV+bwAtSqgphCOkR8tA1ZA5l26zHv xQI0ORQv7VpW5BcbXUsEvFizGoh5a6YEwA4xVsi1FP6WM1Z6yml2X/cA2MMu0nBdc54F bCkkC+9cYw4updyJiZ/p2WnS3syOXwVqSMBlAJvCMdxopiLG+shib5P8CQHdQvMvThaF UTZwkX9xFWKJ4rceqc84cKzPn0DTrZ5LI610uxhfdQS9I+4E8kLRzgiSz0dNKzaXEJxs 6CHEx/j2STA4150oO1LTZgiAeKfwJB2HGWbzkIJU35jfw9CZMPb/UVHZqD69SATF3jDD Q0lQ== X-Gm-Message-State: AOJu0YwQVRKhkYVdFXvqi9CreFXiSWHF3GKqse5DjWwScGQyLaRK0GqS /3eJQgysKuVXqaJbMxNcfXdScsVwX31HxQtKMr+gJXNE3nA= X-Google-Smtp-Source: AGHT+IFlqU5SdPTuwtq8lj35xFUfIZtPtpLvlk/l2RstDbCY5IWXnvLWxX2h+NW5W0zOQR7pTURucg== X-Received: by 2002:a17:906:5354:b0:a23:53b0:45aa with SMTP id j20-20020a170906535400b00a2353b045aamr7006270ejo.141.1704189109246; Tue, 02 Jan 2024 01:51:49 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Wei Liu , Anthony PERARD , Juergen Gross , Marco Solieri Subject: [PATCH v5 05/13] tools: add support for cache coloring configuration Date: Tue, 2 Jan 2024 10:51:30 +0100 Message-Id: <20240102095138.17933-6-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189141077100005 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 --- 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 | 10 +++++++++ tools/include/libxl.h | 5 +++++ tools/include/xenctrl.h | 9 ++++++++ tools/libs/ctrl/xc_domain.c | 34 ++++++++++++++++++++++++++++ tools/libs/light/libxl_create.c | 9 ++++++++ tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 38 +++++++++++++++++++++++++++++++- 7 files changed, 105 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 2e234b450e..c50b280190 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -3031,6 +3031,16 @@ raised. =20 =3Dback =20 +=3Dover 4 + +=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"). + +=3Dback + =3Dhead3 x86 =20 =3Dover 4 diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 907aa0a330..16f56913b2 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1340,6 +1340,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 2ef8b4e054..4b541fffd2 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2653,6 +2653,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. + * This is an internal hypercall. 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 unsigned int *llc_colors, + unsigned int 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 f2d9d14b4d..734f68acd6 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -2180,6 +2180,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 unsigned int *llc_colors, + unsigned int num_llc_colors) +{ + DECLARE_DOMCTL; + 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"); + return -ENOMEM; + } + 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); + + if ( local ) + 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 ce1d431103..db25019452 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -725,6 +725,15 @@ 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) { + LOGED(ERROR, local_domid, "LLC colors allocation failed"); + 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 7d8bd5d216..78031d8bcb 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -610,6 +610,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 ed983200c3..0eefe873a4 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1294,7 +1294,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; @@ -1302,6 +1302,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; @@ -1445,6 +1446,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.34.1 From nobody Thu May 9 13:14:58 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=1704189137; cv=none; d=zohomail.com; s=zohoarc; b=Q0OH90k4swyg4pVHU4lDWadRbRZ+g9ov+KV6uoPV4KZqSOrlSMBjOzPOzJr9GiSkKvqExsdpd0FVWDDusCZF82gZOnmU9mROZfUwP4pOQd66Rk3VShymZCnCOP+lF4cg21fM7Kxhhd52L2n7RUTB+Ei55agmk0aY2Npo5EQxCXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189137; 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=73zQ6mdEMBzClWviA9+IRZfbHegcYkbBhPrmh7vmHt4=; b=QQErEjjKUaYayi14WHc4VnmVxE1W6v3aZy5I1PIU6HxqcKackKoAlVnHr8odMii2o2aCPQKQcehkiqLu7iDNFO/RegwCdKn3LpKCutJQyFAcaGCpZUq25FpX0IiKCoaQ1KeNd/0T9vRdKsaxd/IBoLgKjmAUcV8g9WTXUsnRzow= 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 1704189137628760.7162812526169; Tue, 2 Jan 2024 01:52:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660565.1030090 (Exim 4.92) (envelope-from ) id 1rKbRC-0007IV-I6; Tue, 02 Jan 2024 09:51:54 +0000 Received: by outflank-mailman (output) from mailman id 660565.1030090; Tue, 02 Jan 2024 09:51:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRC-0007Hp-Bd; Tue, 02 Jan 2024 09:51:54 +0000 Received: by outflank-mailman (input) for mailman id 660565; Tue, 02 Jan 2024 09:51:53 +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 1rKbRB-00060C-4b for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:53 +0000 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [2a00:1450:4864:20::52e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8d959b31-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:51 +0100 (CET) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-555f95cc2e4so2216417a12.3 for ; Tue, 02 Jan 2024 01:51:51 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:49 -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: 8d959b31-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189110; x=1704793910; 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=73zQ6mdEMBzClWviA9+IRZfbHegcYkbBhPrmh7vmHt4=; b=F4F9GaksiUKI3IZ3Peu9TSrsm47aaKlskPmQAiwbvJlcMLE+EKZamgIRI8pQ98OOj8 9sdW7UiokQF4tQjmZndgct2xtAAvDgVcKzpu3Kd4eJffwRc3mTn5urTZwxMn7mCsQGom BgusOrednWyD0ti226c4/WXqiWkodJ75qIEbq/YRwJrHvxOvrDz91/3XLfyUI5cVbzYP CNYygw86AggOm4WBYaC9zAMC/En5TiGztwvV1xpYSdp4AZyNFRcYOkl2pSFqK1yYTIHW 8RntLPGNWUNUjkr+EfBdPAtFdyZOGZaEe0kOO1SacIGQyg14BmFFTRrhPS96UXPklB4l R1MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189110; x=1704793910; 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=73zQ6mdEMBzClWviA9+IRZfbHegcYkbBhPrmh7vmHt4=; b=O/5Mz6cTE6KfThrPieu2Wt66fe3enggep21sLub3haPmqOaFI9+0kUPQDkyzGCtTOA 0sJ0SqTLUHKONcB3QyZHBRRyJevj+pP38fRX8uZN55q/yyFfbWNZEJIinVPJiYJu9WPb CUsYI1y8W73jpFShGpUHN0Eh+kRfRWD8uEoaXeCnJTrqcll7960r/F76R/024uPk+mPW k3U8HSwCA2pKtoEa1vOV5u+eRRCNExvZ0b0YpsxdJE3nWKZqmQnlUEHS4nPCmEUhi/4n gJPBvdn9mEIQsaQCwDvWP1t1v6JGuXZ7G/AXEe5JOHZ9xtBSatOUah5nNNs5WEKbeWpa UEkQ== X-Gm-Message-State: AOJu0Yzte09I2YFUE37VFKXW9/A6LJ/2vG9fRsb8ENf5KuUXnnCrhJv1 Mf9W8xIp1kQuroaNNZX3dtULZw1HsaNOmZ6GR/wjoC5/68g= X-Google-Smtp-Source: AGHT+IHjx+BBxiNfQf2Ybyxnqy1PrJ9FjTW1mafSepJnbgj3AtAc3jBAug91zSRILwH3dvu/0L5UZg== X-Received: by 2002:a17:906:74cc:b0:a28:61f7:bbdb with SMTP id z12-20020a17090674cc00b00a2861f7bbdbmr135203ejl.71.1704189110245; Tue, 02 Jan 2024 01:51:50 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v5 06/13] xen/arm: add support for cache coloring configuration via device-tree Date: Tue, 2 Jan 2024 10:51:31 +0100 Message-Id: <20240102095138.17933-7-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189139147100002 Content-Type: text/plain; charset="utf-8" This commit adds the "llc-colors" Device Tree attribute that can be used for DomUs and Dom0less color configurations. The syntax is the same used for every color config. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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/cache-coloring.rst | 48 ++++++++++++++++++++++++- docs/misc/arm/device-tree/booting.txt | 4 +++ xen/arch/arm/dom0less-build.c | 13 +++++++ xen/arch/arm/include/asm/llc-coloring.h | 1 + xen/arch/arm/llc-coloring.c | 17 +++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index acf82c3df8..ae1dd8f4af 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -10,7 +10,7 @@ If needed, change the maximum number of colors with ``CONFIG_NR_LLC_COLORS=3D``. =20 Compile Xen and the toolstack and then configure it via -`Command line parameters`_. +`Command line parameters`_. For DomUs follow `DomUs configuration`_. =20 Background ********** @@ -114,6 +114,52 @@ Examples: | 0 | [0] | +-------------------+-----------------------------+ =20 +DomUs configuration +******************* + +DomUs colors can be set via Device Tree, also for Dom0less configurations +(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 llc-way-size=3D64K dom0-l= lc-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/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index bbd955e9c2..e9f9862e9c 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -162,6 +162,10 @@ 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/arm/cache_coloring.rst" for syntax. + - vpl011 =20 An empty property to enable/disable a virtual pl011 for the guest to diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 1142f7f74a..eb39f5291f 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -850,6 +850,7 @@ void __init create_domUs(void) struct dt_device_node *node; 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) @@ -993,6 +994,13 @@ 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' is required when LLC coloring is enabled\n= "); + else if ( !llc_coloring_enabled && llc_colors_str) + printk(XENLOG_WARNING + "'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 @@ -1003,6 +1011,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/arch/arm/include/asm/llc-coloring.h b/xen/arch/arm/include= /asm/llc-coloring.h index ee5551e3cc..5f9b0a8121 100644 --- a/xen/arch/arm/include/asm/llc-coloring.h +++ b/xen/arch/arm/include/asm/llc-coloring.h @@ -15,6 +15,7 @@ =20 bool __init llc_coloring_init(void); int dom0_set_llc_colors(struct domain *d); +int domain_set_llc_colors_from_str(struct domain *d, const char *str); =20 #endif /* __ASM_ARM_COLORING_H__ */ =20 diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index a08614ec36..d3de5f14cb 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -295,6 +295,23 @@ int domain_set_llc_colors_domctl(struct domain *d, return domain_check_colors(d); } =20 +int domain_set_llc_colors_from_str(struct domain *d, const char *str) +{ + int err; + + if ( domain_alloc_colors(d, nr_colors) ) + return -ENOMEM; + + err =3D parse_color_config(str, d->llc_colors, &d->num_llc_colors); + if ( err ) + { + printk(XENLOG_ERR "Error parsing LLC color configuration."); + return err; + } + + return domain_check_colors(d); +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189141; cv=none; d=zohomail.com; s=zohoarc; b=joGvO890J7q7cTsy5oeOnG8OWmk0G0C+voQykMYXrrs3TxSyqb22xYUDr2D6MrHNSsdN5d30GrFSVAIwkWVJIqQUC8+ekdVvziaQqeyByM7eBVUwZoOlmTLE+9oe66XlgZ18yjDXpxe0mUHT3AQJg0i3nXPXhCErtzvFHQfxjTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189141; 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=sP9qQ4nWMhVEqh2w5k34a2KqREJgBIKIufbFzw/gkj0=; b=TQCaI2MAuagAyFgpFp1GccHb566adebeAVx4VjeXdisb/EVNUbpYM91bjevcWP5+UUE11/PyDDlRnNCVXmkrnfcOP3xFcYebM4vKJSWoCB/zsje1cHW0x48rF1r/8cVGOunsAeDqaekWEOKYWjQOZIVOHhbooDkrmsqkzPQhuj0= 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 1704189141090322.4137240688733; Tue, 2 Jan 2024 01:52:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660566.1030100 (Exim 4.92) (envelope-from ) id 1rKbRD-0007XW-9t; Tue, 02 Jan 2024 09:51:55 +0000 Received: by outflank-mailman (output) from mailman id 660566.1030100; Tue, 02 Jan 2024 09:51:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRD-0007Uu-3T; Tue, 02 Jan 2024 09:51:55 +0000 Received: by outflank-mailman (input) for mailman id 660566; Tue, 02 Jan 2024 09:51:54 +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 1rKbRC-00060C-4f for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:54 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8e26080d-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:52 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5534dcfdd61so15741353a12.0 for ; Tue, 02 Jan 2024 01:51:52 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:50 -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: 8e26080d-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189111; x=1704793911; 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=sP9qQ4nWMhVEqh2w5k34a2KqREJgBIKIufbFzw/gkj0=; b=ecE6WAHRUfIqOWJvNjMbA71GLSIneRm3nz3q4CLSXM7OWfi/YYs6VGQiDVhI7iYZ80 tBJSV0DKdGIZ2+OU3aOlkACU6XnQd6gPMK/ZeZXgc+as6kMJ+cHyGdJLEHcCo93eKDck /bQ5RsoXbLfPvv+jhOIs9rdaUg+cGpzhle45+9xkyBYCLEQZUD/4U3XJBLInIr26laGO DMMeEelxTzTOnTSCFwu5qIilzroOjh0jpHpaZ0c+wH/FNKzjwl9F5nwe1AO5/jlXFDH7 9laCZbWKEqXlTVgdfPOJWPmg+dGSmxQ1gPZiPgi5pWtGXY8LtEewisLy2LzJxY0gHwAr XjJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189111; x=1704793911; 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=sP9qQ4nWMhVEqh2w5k34a2KqREJgBIKIufbFzw/gkj0=; b=cpWUm+Mrd8GW7FY2FZg33GuT1St6KZsGrnYTFJhAY2V54HecHAfJFeqwq8b2rIwkqD tZJrEb9S2PfB72UQBUbO5UlfA1MgkJoPwk5EOL/ZS04rPZ9IwmMbtO1vyUp/2TNJEfUw RVHF7CPoOILA7aFxhA5O3pNDAeMVMji9ddxWl6hMw4AKmltJXdRnwjrRoFKlAJbJSjgb F4R75nEOVKDemQK/p02kQ2e08/SICXr0I63t7awvH/IoxyzzZJPg1S+QKaR/gBJce7nx jWIR1PUV4K2cHXtcGiCB5ud6Oz7WyqAZkz/kmK7mVug6jdrDLkq/PCHaB/E/gOVY7rjq kjmA== X-Gm-Message-State: AOJu0YyGErk2wYI6i8s8SSh39iXyY5aikUDnORP9rFXtJnMokbeGm6+6 dCHvsKDnHGhQkkRyyICP9NzloeN/CUVLxzG95V0xB1Lkfl0= X-Google-Smtp-Source: AGHT+IEiZwHgqGDzuq+CofvQaRdVDEsDJPXCGOUEkAORhykUWO5dX2Iao98Y4vvHu0kxk7Vf/wPajw== X-Received: by 2002:a17:907:318c:b0:a27:a80a:917c with SMTP id xe12-20020a170907318c00b00a27a80a917cmr6506165ejb.2.1704189111430; Tue, 02 Jan 2024 01:51:51 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Marco Solieri Subject: [PATCH v5 07/13] xen/page_alloc: introduce init_free_page_fields() helper Date: Tue, 2 Jan 2024 10:51:32 +0100 Message-Id: <20240102095138.17933-8-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189143088100010 Content-Type: text/plain; charset="utf-8" Introduce a new helper to initialize fields that have different uses for free pages. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- v5: - new patch --- xen/common/page_alloc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index d874525916..9ee3981bb5 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -928,6 +928,13 @@ static struct page_info *get_free_buddy(unsigned int z= one_lo, } } =20 +/* Initialise fields which have other uses for free pages. */ +static void init_free_page_fields(struct page_info *pg) +{ + pg->u.inuse.type_info =3D PGT_TYPE_INFO_INITIALIZER; + page_set_owner(pg, NULL); +} + /* Allocate 2^@order contiguous pages. */ static struct page_info *alloc_heap_pages( unsigned int zone_lo, unsigned int zone_hi, @@ -1036,10 +1043,7 @@ static struct page_info *alloc_heap_pages( accumulate_tlbflush(&need_tlbflush, &pg[i], &tlbflush_timestamp); =20 - /* Initialise fields which have other uses for free pages. */ - pg[i].u.inuse.type_info =3D PGT_TYPE_INFO_INITIALIZER; - page_set_owner(&pg[i], NULL); - + init_free_page_fields(&pg[i]); } =20 spin_unlock(&heap_lock); @@ -2802,9 +2806,7 @@ static bool prepare_staticmem_pages(struct page_info = *pg, unsigned long nr_mfns, * to PGC_state_inuse. */ pg[i].count_info =3D PGC_static | PGC_state_inuse; - /* Initialise fields which have other uses for free pages. */ - pg[i].u.inuse.type_info =3D PGT_TYPE_INFO_INITIALIZER; - page_set_owner(&pg[i], NULL); + init_free_page_fields(&pg[i]); } =20 spin_unlock(&heap_lock); --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189142; cv=none; d=zohomail.com; s=zohoarc; b=dyyHyu36NSpghW1P+cAHrbi1dE08D07pBHvMXdoqvJPIHNvn8p6LTysG4M9V1NZId2bQ8f1IV7Cvy6EbK/IZh/LTblE2jxhw+nD5KspXONChoNQGiKp+JdNn5FiFnsxPSrZtaEDipHAZxU2zr5v5HfUy8ExtNp4FF0idtNZGfNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189142; 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=CcRHPr39Ase6Icq3b5rN9tDIxrSmfJ7neiBccxr3jrg=; b=NdxXn24g+k7Mgusgo4UPQgqf8w5QukB6zjJfy1PvW23tOG9y7sUomTm/rHXgwpiYimpVhO5R6pD1uLCYAlfGJ4uIGQ1nV6gqA83n8nZDDN6RNFP+uoZ0FcJvvGe6960e1u8rZkV6PfCkG7SNtj1bHo/IynFlEcN+sXooyq1PhDM= 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 1704189142868109.40325030370968; Tue, 2 Jan 2024 01:52:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660567.1030114 (Exim 4.92) (envelope-from ) id 1rKbRE-0007y8-L3; Tue, 02 Jan 2024 09:51:56 +0000 Received: by outflank-mailman (output) from mailman id 660567.1030114; Tue, 02 Jan 2024 09:51:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRE-0007wi-Gk; Tue, 02 Jan 2024 09:51:56 +0000 Received: by outflank-mailman (input) for mailman id 660567; Tue, 02 Jan 2024 09:51:55 +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 1rKbRD-00060C-4x for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:55 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8ebc50e0-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:53 +0100 (CET) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a26f73732c5so591231466b.3 for ; Tue, 02 Jan 2024 01:51:53 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:51 -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: 8ebc50e0-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189112; x=1704793912; 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=CcRHPr39Ase6Icq3b5rN9tDIxrSmfJ7neiBccxr3jrg=; b=p6D1+SqpkbGD0c8wn2kT8YuCLrQPOitpGYSbnr7vmmsAvsPtkcImJYwO653W1uJBpM Ka+K0ZVi7xOBYTe1UL4BzjzUUkfS2RQWK4gnLDGIIBa8XRoWa6Bd4ZN95/TA8OkZCps1 VzEosBY8LX+5GX1RqOEA5AibCTA8fm9DX+KQAZsJBcV2zS5ng40cWuH5sXv6Hav1fHS4 l4IX18yAk5qz/y56/UeboSeCo0cwQgjXM4JfdggAcY0YrHALKOlQ6HbpiYLh8jvC/9sW P4bfXBj22nX8NLERFON/3w57L4Qje9KcRG5HqBg0D0va6r4hDgiiQWrUycngoPTh7HvL tegw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189112; x=1704793912; 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=CcRHPr39Ase6Icq3b5rN9tDIxrSmfJ7neiBccxr3jrg=; b=vc/HOjDI1bKj7poxxwDIxjn6U5D/7fk5hNAbx1zk3jGXDNkzg5mQ/5h5UIz+Fwdmsl fMKyd8VBM+bNu5TraC2c5re7LwU5jdzwpZZ70tT9twjmDSzqF1CaI2D4y5yNgBLFSw2X 4u/bfgP8PRoM7n0Hjwc+gnijxvQpo2LTgcICpnFNrFqNNpDuWRJs+xpzOP4ELTaf3uGm nTmYTb+SQieMCJ6P6hsaOddOBTEd4TcaF7dNMZhnFABlXRU2oNO6K9XxxELx9dpOqOfP BEIyLG9Nx1J937m0BfAedAOWD9PScgSKb0txL4sbajkeDW3I3+M6K23Sp4NFm9iTQxSI Miig== X-Gm-Message-State: AOJu0YwLDiJEBp2k77v2IjOo4Wm+qJYK47jQdkdVCTlxcW+5glHJyK+g 508zruPwh3JLuCB1ZVQAjsITz77MShL0DDJRKGKquC3GUwU= X-Google-Smtp-Source: AGHT+IFkKg2Atq8Mx1lI55ksS3FUhVs3unVFFXvmR1U7NRnE9JwsE85OqUkKJy1oOf0ZRrFChr1ioA== X-Received: by 2002:a17:906:58f:b0:a23:57a1:d85b with SMTP id 15-20020a170906058f00b00a2357a1d85bmr8264149ejn.74.1704189112379; Tue, 02 Jan 2024 01:51:52 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Marco Solieri Subject: [PATCH v5 08/13] xen/page_alloc: introduce preserved page flags macro Date: Tue, 2 Jan 2024 10:51:33 +0100 Message-Id: <20240102095138.17933-9-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189143067100009 Content-Type: text/plain; charset="utf-8" PGC_static and PGC_extra are flags that needs to be preserved when assigning a page. Define a new macro that groups those flags and use it instead of or'ing every time. The new macro is used also in free_heap_pages() allowing future commits to extended it with other flags that must stop merging, as it now works for PGC_static. PGC_extra is no harm here since it's only ever being set on allocated pages. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- v5: - new patch --- xen/common/page_alloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 9ee3981bb5..3bf3120287 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -158,6 +158,8 @@ #define PGC_static 0 #endif =20 +#define preserved_flags (PGC_extra | PGC_static) + #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 #endif @@ -1504,7 +1506,7 @@ static void free_heap_pages( /* Merge with predecessor block? */ if ( !mfn_valid(page_to_mfn(predecessor)) || !page_state_is(predecessor, free) || - (predecessor->count_info & PGC_static) || + (predecessor->count_info & preserved_flags) || (PFN_ORDER(predecessor) !=3D order) || (page_to_nid(predecessor) !=3D node) ) break; @@ -1528,7 +1530,7 @@ static void free_heap_pages( /* Merge with successor block? */ if ( !mfn_valid(page_to_mfn(successor)) || !page_state_is(successor, free) || - (successor->count_info & PGC_static) || + (successor->count_info & preserved_flags) || (PFN_ORDER(successor) !=3D order) || (page_to_nid(successor) !=3D node) ) break; @@ -2365,7 +2367,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 & ~preserved_flags)); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2425,7 +2427,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 & preserved_flags) | PGC_allocated | 1; =20 page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189143; cv=none; d=zohomail.com; s=zohoarc; b=EED85q56/qUAt4xY2sTNWR6mcUX4MQeoeq148aaNz6n+cOUMtnL3MA3ZbAIKeC6q/jgNhK0QhsWsLf04RNvtcF1zWsIVjknxk5+XUI+XJF9VVRJZ64upF3pa5ld7dF7db2p5c0g/B19cVaqMFoM/oI3yM+LNhvPmgS5WBWNDZLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189143; 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=nYNO35ZrOJhK49+UqaVbf/gG5fwEIjK1DLow2UXReX0=; b=RLUfjSNMUKj4kds/irV1n1L4Ncg9myOPPWK6UKmkoFMln2Rr6Uvv4c9lXfmICkodk9AAHeTORAr3qnwYtPrPFDxjpJ5w3LHrLDJP9+JiUg5BBpl/Py+5JPhkiCq1kEuUqnn293MOjThWPjRsWlFZLlmyWkKiEI5RT0B//bsQoJ4= 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 170418914390969.42642451607094; Tue, 2 Jan 2024 01:52:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660569.1030132 (Exim 4.92) (envelope-from ) id 1rKbRG-0008UU-O4; Tue, 02 Jan 2024 09:51:58 +0000 Received: by outflank-mailman (output) from mailman id 660569.1030132; Tue, 02 Jan 2024 09:51:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRG-0008St-AW; Tue, 02 Jan 2024 09:51:58 +0000 Received: by outflank-mailman (input) for mailman id 660569; Tue, 02 Jan 2024 09:51:56 +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 1rKbRE-00060C-M9 for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:56 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8f6f314f-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:54 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-554e902064aso6578161a12.1 for ; Tue, 02 Jan 2024 01:51:54 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:52 -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: 8f6f314f-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189113; x=1704793913; 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=nYNO35ZrOJhK49+UqaVbf/gG5fwEIjK1DLow2UXReX0=; b=Z16Yr32lEOVCAJRc8AJhkopUdNFOUA+GP3ILWrZ6+OdcQZP4LtKbcA84nRF2u5avYS G5Fvq8Jbv5dvAO1BD9kWBvYBseOIMxu8SHSxp2+E2l96TWqQGWlMSJwgVvoQzkQ/kDw6 oqVo3bYu590oJ0D8cRjwsgxrxxWXr/qLSG14PvNBMBD+yJPFzu4CvvuwOlE55eFJ5Z8F 0U7MhgxBLdTAwbi3bH8h574DlnTd7ZNYgYmuGUg3fQWlM3d3exuSBKrV9mnkX8knqoiE SlxhQNgi0OZJPFu1RbYpmGpIMxg/NxOJ0smNe4pERRnSjV/bXT489K1fasOEh+N7rVPZ Y/jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189113; x=1704793913; 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=nYNO35ZrOJhK49+UqaVbf/gG5fwEIjK1DLow2UXReX0=; b=VOL85cOITFikrXJiSgO6ZKJL/9s0uuBVC8nVCoscbozYwwBgxWF5Wo3mrsuFzBVewy rYGBTUg0UGr9tQaHywfqtxHwWYmTkap/KAfPop1mhCUcVCorfLFuDqfgCKhJuZB09dWy +lJ045fVDURn0+wli4z0wsVaTovBT8rcFzfbN37keqBUp/B+eV8g/jUOeSP2ZYSuAvmS Qsb6qgjkRGeL8Q91UrX0+dk6IdkXzS9T3VH0KE2O6AkK2ty5YeVL7B+EWOAAFV451FPg gER8MmWu4KpvtsmtvB6G9oNwOSRcfsmAsrgZ+sPaxbTZP8r/vB58u8OBkf8j9FaUGZHl qhug== X-Gm-Message-State: AOJu0YzkGNXFnaFndHw/BDqLJurP96xZrp5HfKnROvnvvWJ44v7Z/hgW fStwObtGHJAb+lcQ/9VRdQ3bhEjTqB/j93NK/RDDEv9LkzU= X-Google-Smtp-Source: AGHT+IGGYgYlT4gKP7S4ynp2ZJmiR4+StiBbSIWcMipb7C8Q5JJOisd5I2XCrzNBRuj/AJ4RocWkGA== X-Received: by 2002:a17:906:38da:b0:a23:56a6:97b6 with SMTP id r26-20020a17090638da00b00a2356a697b6mr7849468ejd.66.1704189113382; Tue, 02 Jan 2024 01:51:53 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v5 09/13] xen: add cache coloring allocator for domains Date: Tue, 2 Jan 2024 10:51:34 +0100 Message-Id: <20240102095138.17933-10-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189145117100019 Content-Type: text/plain; charset="utf-8" This commit adds a new memory page allocator that implements the cache coloring mechanism. The allocation algorithm enforces equal frequency distribution of cache partitions, following the coloring configuration of a domain. This allows 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 extract the page from the list with the maximum number of free pages between those that the domain can access, 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 --- 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/arm/cache-coloring.rst | 37 ++++++ docs/misc/xen-command-line.pandoc | 14 +++ xen/arch/Kconfig | 12 ++ xen/arch/arm/include/asm/mm.h | 5 + xen/arch/arm/llc-coloring.c | 13 ++ xen/common/page_alloc.c | 193 +++++++++++++++++++++++++++++- xen/include/xen/llc-coloring.h | 4 + 7 files changed, 273 insertions(+), 5 deletions(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index ae1dd8f4af..c5582340da 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -9,6 +9,9 @@ To compile LLC coloring support set ``CONFIG_LLC_COLORING= =3Dy``. If needed, change the maximum number of colors with ``CONFIG_NR_LLC_COLORS=3D``. =20 +If needed, change the buddy allocator reserved size with +``CONFIG_BUDDY_ALLOCATOR_SIZE=3D``. + Compile Xen and the toolstack and then configure it via `Command line parameters`_. For DomUs follow `DomUs configuration`_. =20 @@ -86,6 +89,8 @@ More specific documentation is available at `docs/misc/xe= n-command-line.pandoc`. +----------------------+-------------------------------+ | ``dom0-llc-colors`` | Dom0 color configuration | +----------------------+-------------------------------+ +| ``buddy-alloc-size`` | Buddy allocator reserved size | ++----------------------+-------------------------------+ =20 Colors selection format *********************** @@ -160,6 +165,17 @@ DomUs colors can be set via Device Tree, also for Dom0= less configurations **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 @@ -170,3 +186,24 @@ In the domain configuration, "xen,static-mem" allows m= emory to be statically allocated to the domain. This isn't possibile 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 +amount of memory that can be mapped to achieve the maximum number of colors +(cache partitions) possible. This amount 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 51f6adf035..163fe7bcb1 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 options is parsed only when LLC coloring support is enabled. +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/Kconfig b/xen/arch/Kconfig index aad7e9da38..f4c1406c02 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -47,3 +47,15 @@ config NR_LLC_COLORS bound. The runtime value is autocomputed or manually set via cmdline. The default value corresponds to an 8 MiB 16-ways LLC, which should be more than what needed in the general case. + +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 work alongside + the colored one. The colored allocator is meant as an alternative to + the buddy allocator because 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. diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index cbcf3bf147..1829c559d6 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/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index d3de5f14cb..526129cc43 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -30,6 +30,9 @@ static unsigned int __ro_after_init nr_colors =3D CONFIG_= NR_LLC_COLORS; static unsigned int __ro_after_init dom0_colors[CONFIG_NR_LLC_COLORS]; static unsigned int __ro_after_init dom0_num_colors; =20 +#define mfn_color_mask (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. @@ -312,6 +315,16 @@ int domain_set_llc_colors_from_str(struct domain *d, c= onst char *str) return domain_check_colors(d); } =20 +unsigned int page_to_llc_color(const struct page_info *pg) +{ + return mfn_to_color(page_to_mfn(pg)); +} + +unsigned int get_nr_llc_colors(void) +{ + return nr_colors; +} + /* * Local variables: * mode: C diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 3bf3120287..54f52e8677 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -126,6 +126,7 @@ #include #include #include +#include #include #include #include @@ -158,7 +159,11 @@ #define PGC_static 0 #endif =20 -#define preserved_flags (PGC_extra | PGC_static) +#ifndef PGC_colored +#define PGC_colored 0 +#endif + +#define preserved_flags (PGC_extra | PGC_static | PGC_colored) =20 #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 @@ -1946,6 +1951,162 @@ 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; +static unsigned long *__ro_after_init free_colored_pages; + +/* Memory required for buddy allocator to work with colored one */ +#ifdef CONFIG_LLC_COLORING +static unsigned long __initdata buddy_alloc_size =3D + MB(CONFIG_BUDDY_ALLOCATOR_SIZE); +size_param("buddy-alloc-size", buddy_alloc_size); + +#define domain_num_llc_colors(d) ((d)->num_llc_colors) +#define domain_llc_color(d, i) ((d)->llc_colors[(i)]) +#else +static unsigned long __initdata buddy_alloc_size; + +#define domain_num_llc_colors(d) 0 +#define domain_llc_color(d, i) 0 +#define page_to_llc_color(p) 0 +#define get_nr_llc_colors() 0 +#endif + +#define color_heap(color) (&_color_heap[color]) + +void free_color_heap_page(struct page_info *pg, bool need_scrub) +{ + unsigned int color =3D page_to_llc_color(pg); + struct page_list_head *head =3D color_heap(color); + + spin_lock(&heap_lock); + + mark_page_free(pg, page_to_mfn(pg)); + + if ( need_scrub ) + { + pg->count_info |=3D PGC_need_scrub; + poison_one_page(pg); + } + + pg->count_info |=3D PGC_colored; + free_colored_pages[color]++; + page_list_add(pg, head); + + spin_unlock(&heap_lock); +} + +struct page_info *alloc_color_heap_page(unsigned int memflags, struct doma= in *d) +{ + struct page_info *pg =3D NULL; + unsigned int i, color; + unsigned long max =3D 0; + bool need_tlbflush =3D false; + uint32_t tlbflush_timestamp =3D 0; + bool scrub =3D !(memflags & MEMF_no_scrub); + + 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; + } + + pg->count_info =3D PGC_state_inuse | PGC_colored | + (pg->count_info & PGC_need_scrub); + 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 ( test_and_clear_bit(_PGC_need_scrub, &pg->count_info) && scrub ) + scrub_one_page(pg); + else if ( scrub ) + 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; +} + +void __init init_color_heap_pages(struct page_info *pg, unsigned long nr_p= ages) +{ + unsigned int i; + bool need_scrub =3D (system_state < SYS_STATE_active && + opt_bootscrub =3D=3D BOOTSCRUB_IDLE); + + if ( buddy_alloc_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; + } + + if ( !_color_heap ) + { + unsigned int nr_colors =3D get_nr_llc_colors(); + + _color_heap =3D xmalloc_array(struct page_list_head, nr_colors); + free_colored_pages =3D xzalloc_array(unsigned long, 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 < nr_colors; i++ ) + INIT_PAGE_LIST_HEAD(color_heap(i)); + } + + if ( nr_pages ) + printk(XENLOG_DEBUG + "Init color heap with %lu pages starting from: %#"PRIx64"\n= ", + nr_pages, page_to_maddr(pg)); + + for ( i =3D 0; i < nr_pages; i++ ) + free_color_heap_page(&pg[i], need_scrub); +} + +void dump_color_heap(void) +{ + unsigned int color; + + printk("Dumping color heap info\n"); + for ( color =3D 0; color < get_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; @@ -1965,7 +2126,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; @@ -2461,7 +2628,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 && is_domain_llc_colored(d) ) + { + /* 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); @@ -2486,7 +2660,10 @@ struct page_info *alloc_domheap_pages( } if ( assign_page(pg, order, d, memflags) ) { - free_heap_pages(pg, order, memflags & MEMF_no_scrub); + if ( pg->count_info & PGC_colored ) + free_color_heap_page(pg, memflags & MEMF_no_scrub); + else + free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; } } @@ -2569,7 +2746,10 @@ void free_domheap_pages(struct page_info *pg, unsign= ed int order) scrub =3D 1; } =20 - free_heap_pages(pg, order, scrub); + if ( pg->count_info & PGC_colored ) + free_color_heap_page(pg, scrub); + else + free_heap_pages(pg, order, scrub); } =20 if ( drop_dom_ref ) @@ -2676,6 +2856,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 fa2edc8ad8..7cd481e955 100644 --- a/xen/include/xen/llc-coloring.h +++ b/xen/include/xen/llc-coloring.h @@ -36,6 +36,10 @@ void domain_dump_llc_colors(struct domain *d); int domain_set_llc_colors_domctl(struct domain *d, const struct xen_domctl_set_llc_colors *c= onfig); =20 +struct page_info; +unsigned int page_to_llc_color(const struct page_info *pg); +unsigned int get_nr_llc_colors(void); + #endif /* __COLORING_H__ */ =20 /* --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189142; cv=none; d=zohomail.com; s=zohoarc; b=fIWb8dtGwz+B6pbe044Q//OVl3J7PiH6P+7yT5T26gmBSkRo/XivuTaYzbIk5gP+M805tqdfO/s0Vod+SJj4iB8TRfI3Xe2vUs1j44eXi2aJ1DwJooZsX+gja3X9hcfNPTxdJKK9J1fagwpJzkPU2Ubca6Zz7LBtbd50AltFEy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189142; 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=Yh1Spa5a2++HjujwNRVja92wtQd0bdVMGwtSuj79fk4=; b=jvD40R/b5Y4C/YHV8NSWSOHU8uSN2+By9dvCfFTP65B7IGjE83IxX1niT+sX34UKiKfnd79NUHitKceKQrog9kzCPJu+HZ0xZQTXDdNnD7YY7+O4/FlC1OLNhQifconbsSmb1jAd9uoGl/GfbkFOGg16qa+sD7X0q808vAASBa0= 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 1704189142387222.31099443402002; Tue, 2 Jan 2024 01:52:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660568.1030121 (Exim 4.92) (envelope-from ) id 1rKbRF-00084o-7o; Tue, 02 Jan 2024 09:51:57 +0000 Received: by outflank-mailman (output) from mailman id 660568.1030121; Tue, 02 Jan 2024 09:51:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRE-00083l-Vu; Tue, 02 Jan 2024 09:51:56 +0000 Received: by outflank-mailman (input) for mailman id 660568; Tue, 02 Jan 2024 09:51:55 +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 1rKbRD-0006VR-Ig for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:55 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8fd18725-a954-11ee-98ef-6d05b1d4d9a1; Tue, 02 Jan 2024 10:51:55 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-55539cac143so5756691a12.0 for ; Tue, 02 Jan 2024 01:51:55 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:53 -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: 8fd18725-a954-11ee-98ef-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189114; x=1704793914; 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=Yh1Spa5a2++HjujwNRVja92wtQd0bdVMGwtSuj79fk4=; b=g+jiiIOdGr+aw4rEtsXCTNGhkH1+y4XmhYTbaf9NuR+rqLrf2e9JLyaRhiuZeNjpiz mLMpY+Ah6b5j/xwsuJ/qn0Jv/Gm2o+gv8e91/KQ3MaL1uGn7j34XZ4zAtZMrY1l2NMdT 4XAFd63sbaUFU4vQSFdduvqXfb2TwK7EPsyEQ9I3f4REdJtH3L4o05SPlRId+oKY50DX FwcNkOCFV4yXkX/D2rfcULdudGDGmSUf2gc624yVHa/aA4ouLRkimuymJ4Gscz30y5XT 8uNw1L4dd3fnuXRi2x01zR0q7L2uQYNv1QJ0O7HJuQpBssPjR2bH9L+ayuR7nRO/BDPX sj9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189114; x=1704793914; 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=Yh1Spa5a2++HjujwNRVja92wtQd0bdVMGwtSuj79fk4=; b=dt7T2Zw6ZJYbH0NuB4R1rMbKGEK4ZPn3LcHx2redNNXpBQY3ofxGmi8eOoUVJD86/v 5k1JKemWUdcR3HOFc2ZLBTsJtz8DCUPIoRExiLlI/kCDWp8S1sI3FPSTg5tn02FnR4Uv 8JAQvoO6ch7Wx9x64hgyw0Pb3RK9Dj1ZVlFJ3yUep8dN6lCv0C93LYPpjtSovzWgBsNV SaRk8pc2INkXMAzObbtj8CPZiZbvoqVE/IU1vnyJTfrewLj/aLxEf5x+0ldj2hpKxiUS izQ67T1mxN/qv9EB7lPndl+7lD1uiYZXLTUdq++yHpP3fGg91QV+29A2uFZHfpSU9eor wkvA== X-Gm-Message-State: AOJu0YxmA0dm/9K0LNZ8y2RdPauk6zmZEDMNRr8oGTK7/eH7aCU45KQ5 acozzFr3FoSzhN6U52buRYl5pX3dON06aZqZnPYYgiecqOc= X-Google-Smtp-Source: AGHT+IGsDNMl5Y9JClEF0mL/6gxoCKBwi9CxutTOJTPmX7FLmvMDFBlSRc7c6XX9heUNA5DON57FyQ== X-Received: by 2002:a17:907:928b:b0:a27:6648:cc3e with SMTP id bw11-20020a170907928b00b00a276648cc3emr5019435ejc.74.1704189114633; Tue, 02 Jan 2024 01:51:54 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v5 10/13] xen/arm: use domain memory to allocate p2m page tables Date: Tue, 2 Jan 2024 10:51:35 +0100 Message-Id: <20240102095138.17933-11-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189143089100011 Content-Type: text/plain; charset="utf-8" Cache colored domains can benefit from having p2m page tables allocated with the same coloring schema so that isolation can be achieved also for those kind of memory accesses. In order to do that, the domain struct is passed to the allocator and the MEMF_no_owner flag is used. This will be useful also when NUMA will be supported on Arm. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri Acked-by: Julien Grall --- v5: - new patch --- xen/arch/arm/mmu/p2m.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c index 41fcca011c..d02a478cb8 100644 --- a/xen/arch/arm/mmu/p2m.c +++ b/xen/arch/arm/mmu/p2m.c @@ -32,7 +32,7 @@ static struct page_info *p2m_alloc_page(struct domain *d) */ if ( is_hardware_domain(d) ) { - pg =3D alloc_domheap_page(NULL, 0); + pg =3D alloc_domheap_page(d, MEMF_no_owner); if ( pg =3D=3D NULL ) printk(XENLOG_G_ERR "Failed to allocate P2M pages for hwdom.\n= "); } @@ -81,7 +81,7 @@ int p2m_set_allocation(struct domain *d, unsigned long pa= ges, bool *preempted) if ( d->arch.paging.p2m_total_pages < pages ) { /* Need to allocate more memory from domheap */ - pg =3D alloc_domheap_page(NULL, 0); + pg =3D alloc_domheap_page(d, MEMF_no_owner); if ( pg =3D=3D NULL ) { printk(XENLOG_ERR "Failed to allocate P2M pages.\n"); --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189142; cv=none; d=zohomail.com; s=zohoarc; b=MkPy+t7RitMO6JYQpRcMLS5KVYf+hW85uJNwl4rfKvci6oiVb7LiI2nyb0Y1fiLg1yok+IgS36X0oiLtcYQPqlH3dWX4YdQg5Cz7uQQr7Gyjjn96iWitE52J0P+lhVhP+pD5jEi/1oeaTMsPBaPTyTLynzfOkUW1bQSKjifiOb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189142; 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=PcO0kEIMg/LgcpSllNj/odMrO/ou7iqngmDP7yYGSAQ=; b=cj9KUCnJEVIoSB/H9GVM5sfX2ECZw6J7wBfT4hCsxOS4ZRbwgdOlzrpBeYDzZ99MMrjZrTIe+CDNGRHaoFclGW5T+zr6ST/sP1fgYRpoReiXVyIeV49AIrcxzB7aN5lsvtk1/30T1AH3k1q8AWDS7hAzMggXciTpZQj1r9mU+mk= 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 1704189142956113.10085747902417; Tue, 2 Jan 2024 01:52:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660571.1030146 (Exim 4.92) (envelope-from ) id 1rKbRI-0000O6-57; Tue, 02 Jan 2024 09:52:00 +0000 Received: by outflank-mailman (output) from mailman id 660571.1030146; Tue, 02 Jan 2024 09:52:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRH-0000Lk-Rx; Tue, 02 Jan 2024 09:51:59 +0000 Received: by outflank-mailman (input) for mailman id 660571; Tue, 02 Jan 2024 09:51:58 +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 1rKbRG-00060C-2D for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:58 +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 9071b3ae-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:56 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a28005f9b9cso114748666b.3 for ; Tue, 02 Jan 2024 01:51:56 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:55 -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: 9071b3ae-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189115; x=1704793915; 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=PcO0kEIMg/LgcpSllNj/odMrO/ou7iqngmDP7yYGSAQ=; b=AXfFNeXEd/5wC4Ze1yGgN+ciYn4rqmPNUrJdlXLBpjDwGqCqW0nv7/iTTc5ngiS5LE yfw51DbInyM9rkg1zlMyN1dff5Qr6AU0hgadWjgQBa6y1KnxcAZYJvLmuanWb6YATOVX 8YU6fzWwwKLoEM2gvPDh2ZZ4/RuNuTaY+qn3Jc/vq7MD2KotZiHOeZ2EHlNCjj2VuhMv Hxbi+SpAQDavhN/LM1Ojyy29p1dMLidIx0K4TXPw9GKj+xtfhpjLcVrG8kYkiSPGlzNB 6EswUsp52mDvDmQA2gh4PxCC4HkgyVe6GPKeOEWFczOVi0AX2zGM/u59WqG3UCEF8xDd OOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189115; x=1704793915; 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=PcO0kEIMg/LgcpSllNj/odMrO/ou7iqngmDP7yYGSAQ=; b=GD7/mRRWsNv/zN7LwIpiDbclvJXilaQS/GuSezymVafShtsRg7jiormPeLYkIZk3G4 ydNxikPc1sJc//F1d8GW408HyrZoC04Jlc5fSkm3nu0fMM0VSSJ9Lz7jeSXRkiY1/BWM H1I1fwXzCzFzfjXNfb/wKHMGubqEUModHyk6YisQi5rQhxr9RGlJ3vBMJ/pXIL2poXs+ Oje4wCZQ98czOGDC7hYD0q7vju5wAjh+ph378L5QUNvOxc41ixFb0K5iACSnu5BrmXHK hXU6EY4Yduu7V4yB+Swzt5yQAa6ImUPYcy6NnNGGSuK80wD6ItCO2WliIOw21x02NQuv Opnw== X-Gm-Message-State: AOJu0Yy7xiPsucJja/J4wK2Ae+X4qQLrhB/39XvMMfuVyyd9TULADTIh vjNFFLQTmpTtUSritzDAh6hvkreegqiQKGv1g1t3lHrYZtU= X-Google-Smtp-Source: AGHT+IGYJ/FbaOnnjGdfsmIIcCIEpyNdigCmNAnLVYN1SMaA0OWzdwtLOdGXGWIGV6865STxxqucYQ== X-Received: by 2002:a17:906:1cd:b0:a26:db4e:955 with SMTP id 13-20020a17090601cd00b00a26db4e0955mr5915269ejj.64.1704189115261; Tue, 02 Jan 2024 01:51:55 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v5 11/13] Revert "xen/arm: Remove unused BOOT_RELOC_VIRT_START" Date: Tue, 2 Jan 2024 10:51:36 +0100 Message-Id: <20240102095138.17933-12-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189145127100020 Content-Type: text/plain; charset="utf-8" This reverts commit 0c18fb76323bfb13615b6f13c98767face2d8097 (not clean). This is not a clean revert since the rework of the memory layout, but it is sufficiently similar to a clean one. The only difference is that the BOOT_RELOC_VIRT_START must match the new layout. Cache coloring support for Xen needs to relocate Xen code and data in a new colored physical space. The BOOT_RELOC_VIRT_START will be used as the virtu= al base address for a temporary mapping to this new space. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- xen/arch/arm/include/asm/mmu/layout.h | 2 ++ xen/arch/arm/mmu/setup.c | 1 + 2 files changed, 3 insertions(+) diff --git a/xen/arch/arm/include/asm/mmu/layout.h b/xen/arch/arm/include/a= sm/mmu/layout.h index eac7eef885..30031f74d9 100644 --- a/xen/arch/arm/include/asm/mmu/layout.h +++ b/xen/arch/arm/include/asm/mmu/layout.h @@ -74,6 +74,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/mmu/setup.c b/xen/arch/arm/mmu/setup.c index d5264e51bc..37b6d230ad 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -69,6 +69,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); --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189141; cv=none; d=zohomail.com; s=zohoarc; b=ZgBnrIq5eMFyszYQvnywiR9U6bKHqx+vHS7zvYQVEBWJZA9wQj1hs1cU/H/51TTy7s2gUhM+Ryo92yYhBi4IQlsWbBKpSCzh7d//jEVOGJOE0hvNhXuooVi1De8e2AmVgOaTH+wYo64DP/9nfxyCbGawb5mx6JUth368ksATGfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189141; 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=O+nY1AcQoCECW9cvYTyCa0KuWYpxftrNLY7zKkG+lX0=; b=KJetHyAhzJs+CmxNbvWIwK9+E5aenBnNQlRqRqTDEcwFeotoT/YVZOM1gIkAPWWmsFE1khktEa5blf43qHSTcyDPpgh44SIM+RKu3r8ubglXEk4USDmofwzX1mvjpyPOX3N1IbCu2jw6Paz2+lX5p2x6axO9k4HEHkMFCtc6RII= 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 1704189141187422.0719558902298; Tue, 2 Jan 2024 01:52:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660570.1030138 (Exim 4.92) (envelope-from ) id 1rKbRH-00006y-Aa; Tue, 02 Jan 2024 09:51:59 +0000 Received: by outflank-mailman (output) from mailman id 660570.1030138; Tue, 02 Jan 2024 09:51:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRG-00004y-Pa; Tue, 02 Jan 2024 09:51:58 +0000 Received: by outflank-mailman (input) for mailman id 660570; Tue, 02 Jan 2024 09:51:57 +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 1rKbRF-0006VR-Dt for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:51:57 +0000 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [2a00:1450:4864:20::536]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 90d9161f-a954-11ee-98ef-6d05b1d4d9a1; Tue, 02 Jan 2024 10:51:56 +0100 (CET) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-556431c7d51so1221806a12.2 for ; Tue, 02 Jan 2024 01:51:56 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:55 -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: 90d9161f-a954-11ee-98ef-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189116; x=1704793916; 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=O+nY1AcQoCECW9cvYTyCa0KuWYpxftrNLY7zKkG+lX0=; b=p6VmLlhs+6VMCbJpQVSixQtlUe1Oi/JKJPsU1NYopCtF2sJotzmkVfKuzWkl671LCv po14ttvQCW15jRP72qS6GhyEhjB6wefiN91JpzK58NGqRL8CXwzFfAms2J8HDWt36HiA VHd3luFdG7a2nHwSUThJJ4+A019YAtZYoPxG9XU7tBu7Cp4v4qACUe3DaZdO04MDiPVg p4r9cFtRWJ2DYa9Wto4kXzLXYQJTfGPOTGSwY3XeKywR836k5FQpNNQUhqg8/YV9bMOb Gw7g6i7SU38fjcqx43vL6mfQLyIDThvUJQ9tbbG5Wj2R3E4jq61bWE7UyCfyLn9b5/mq 3HLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189116; x=1704793916; 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=O+nY1AcQoCECW9cvYTyCa0KuWYpxftrNLY7zKkG+lX0=; b=HDLId8AAinwNaupFWMNuP7SjyupgmRp5Pf5JMRQfNRJwGqptuNkeV9pQkQ0pF2TWcI N191fTFnK4d8nfAXmElqFQgA89FJihy+/1PI4kyAHiRWVZkR0T6wW6LhVJ5ajR0QlBBY zD5iRcGV4M5zPsiQylBCJUNNKmpiUWigtuDbgFL9jN5LxmnvGQAPOrKJTqmFc6o6uFNg sY2Or7dm439u3Qh39D+aiP8X9AFwFdN4h7UeY2nNlBB3/zJxeUZ23Iz6ky331r36V+ss Ft4ggehmuLBQaDZrlxTvLBU0TsEuhUky4gwfHP646Kgkgtr73d5NjD4jlHtItJAWXDTw vtGQ== X-Gm-Message-State: AOJu0YynuSRSJv46kxTnyp/7BlNugnQE+pgZmE/Dzui+k5xN0ALgIRus PDXGc5hZPkVA7rCbNI02/SSORD0ve/82z8uxAB1/QCpEtO0= X-Google-Smtp-Source: AGHT+IH4y/zq1O7BDpjHBHIcYJ/XVuHSLzMuDKRzUA0tlTTyF5q1wpx+WPkHpbSnn0Tf82YWSlUSVg== X-Received: by 2002:a17:906:1d6:b0:a26:8dee:a601 with SMTP id 22-20020a17090601d600b00a268deea601mr4140269ejj.247.1704189116239; Tue, 02 Jan 2024 01:51:56 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Luca Miccio , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Marco Solieri , Carlo Nonato Subject: [PATCH v5 12/13] xen/arm: add Xen cache colors command line parameter Date: Tue, 2 Jan 2024 10:51:37 +0100 Message-Id: <20240102095138.17933-13-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189143090100012 Content-Type: text/plain; charset="utf-8" From: Luca Miccio This commit adds a new command line parameter to configure Xen cache colors. These colors can be dumped with the cache coloring info debug-key. By default, Xen uses the first color. 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. 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. The default amount of Xen colors is thus set to one. Signed-off-by: Luca Miccio Signed-off-by: Marco Solieri Signed-off-by: Carlo Nonato --- docs/misc/xen-command-line.pandoc | 10 ++++++++++ xen/arch/arm/llc-coloring.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 163fe7bcb1..f983f22796 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2877,6 +2877,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/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index 526129cc43..99ea69ad39 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -18,6 +18,9 @@ #include #include =20 +#define XEN_DEFAULT_COLOR 0 +#define XEN_DEFAULT_NUM_COLORS 1 + bool __ro_after_init llc_coloring_enabled; boolean_param("llc-coloring", llc_coloring_enabled); =20 @@ -30,6 +33,9 @@ static unsigned int __ro_after_init nr_colors =3D CONFIG_= NR_LLC_COLORS; static unsigned int __ro_after_init dom0_colors[CONFIG_NR_LLC_COLORS]; static unsigned int __ro_after_init dom0_num_colors; =20 +static unsigned int __ro_after_init xen_colors[CONFIG_NR_LLC_COLORS]; +static unsigned int __ro_after_init xen_num_colors; + #define mfn_color_mask (nr_colors - 1) #define mfn_to_color(mfn) (mfn_x(mfn) & mfn_color_mask) =20 @@ -87,6 +93,12 @@ 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, &xen_num_colors); +} +custom_param("xen-llc-colors", parse_xen_colors); + /* Return the LLC way size by probing the hardware */ static unsigned int __init get_llc_way_size(void) { @@ -161,6 +173,8 @@ static void dump_coloring_info(unsigned char key) printk("'%c' pressed -> dumping LLC coloring general info\n", key); printk("LLC way size: %u KiB\n", llc_way_size >> 10); printk("Number of LLC colors supported: %u\n", nr_colors); + printk("Xen has %u LLC colors: ", xen_num_colors); + print_colors(xen_colors, xen_num_colors); } =20 static bool check_colors(unsigned int *colors, unsigned int num_colors) @@ -217,6 +231,21 @@ bool __init llc_coloring_init(void) return false; } =20 + if ( !xen_num_colors ) + { + printk(XENLOG_WARNING + "Xen LLC color config not found. Using default color: %u\n", + XEN_DEFAULT_COLOR); + xen_colors[0] =3D XEN_DEFAULT_COLOR; + xen_num_colors =3D XEN_DEFAULT_NUM_COLORS; + } + + if ( !check_colors(xen_colors, xen_num_colors) ) + { + printk(XENLOG_ERR "Bad LLC color config for Xen\n"); + return false; + } + register_keyhandler('K', dump_coloring_info, "dump LLC coloring info",= 1); =20 return true; --=20 2.34.1 From nobody Thu May 9 13:14:58 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=1704189146; cv=none; d=zohomail.com; s=zohoarc; b=e3tuhDdrWDUglOgatewxhpL8ZgwtOlLHCe8rrlgFPInL7rKW8nQpsgkjOMxQCrZtoFFqea/cQiqB9KNYjrMEDFlWJTnMBlH/ixmTS4CTAGE2k0MpVhCintfJGe2U23oPDt/C0ZNZQSf/HU7ht+brULeLZVMEdrZUWKdzTgQHqLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704189146; 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=WMy02P2ugeOoYavgONgNbpFFD/A3TCZgNfOsvu4lMaM=; b=Isicaz8xju9WG2WgNbPkS0e68OEIP170w0JHMtXvUCeLNXHijN7sJ7AgwOyPjC4x9btb1gxK6DeUGGdf/m/WprpHJTiOuaVwTCPFrOdcrd6fN3JCY1Qhbhra4InS4kYqLLyWebKPweYJfqI0WZyJy1QQr5rLBrsFJIc+IgSh2aU= 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 1704189146886397.0601097972558; Tue, 2 Jan 2024 01:52:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.660572.1030160 (Exim 4.92) (envelope-from ) id 1rKbRJ-0000rj-MS; Tue, 02 Jan 2024 09:52:01 +0000 Received: by outflank-mailman (output) from mailman id 660572.1030160; Tue, 02 Jan 2024 09:52:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rKbRJ-0000q7-Ez; Tue, 02 Jan 2024 09:52:01 +0000 Received: by outflank-mailman (input) for mailman id 660572; Tue, 02 Jan 2024 09:52:00 +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 1rKbRI-00060C-1Z for xen-devel@lists.xenproject.org; Tue, 02 Jan 2024 09:52:00 +0000 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [2a00:1450:4864:20::52f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9158e1f7-a954-11ee-9b0f-b553b5be7939; Tue, 02 Jan 2024 10:51:57 +0100 (CET) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-556ab26227cso13513a12.1 for ; Tue, 02 Jan 2024 01:51:57 -0800 (PST) Received: from carlo-ubuntu.minervasys.tech (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id s4-20020a1709066c8400b00a1f7ab65d3fsm11541845ejr.131.2024.01.02.01.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 01:51:56 -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: 9158e1f7-a954-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1704189117; x=1704793917; 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=WMy02P2ugeOoYavgONgNbpFFD/A3TCZgNfOsvu4lMaM=; b=luWMUfNaKy5Sw6h65LmChIMl9ZJegIknF5rvXezoy7SHX3/26symp4LE0EUi6l65Ni sY8vp3iY2Hy4a6nVsZJor2+1Jk/tUMMQe/S3f2EPGv9MpLILTRPq+PaN5i7MWTVsCE0A Ud4VT0nWUipWKym7UdbPFNdyRX0B/dJHk242oCwxExb/kCiabBebLFbOq5Jks2E3zLB0 Di7crGPu9w9xSsHqO3h88yVfBAzI+ZL701t2JQsS2P0+mYeC/2lCtCwPXe0IJdRYousd Oauv4yXjuRNwoxR1bV0zqiIs/BIVQ1d6l+JpDNuN/QPQFFBV+L6mC77Qoowq2P8KI7zy dH5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704189117; x=1704793917; 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=WMy02P2ugeOoYavgONgNbpFFD/A3TCZgNfOsvu4lMaM=; b=MoX66jSp50n1IOeprvlNcuf3fEd3hcpaKLXEFt4W7wQ4izeHEXiAJ44z024b2pkM46 dK1Q8y053COD/Dcg+izg3KqS6BuRr9Ppvu3bpC+MB2CQaL7LSTIIGKXBJWh65iOBOW/A pGRVPHNXFTTcGU9v6+fpGfo8gGeN3ZeILMxv7giKyjPAMppH7G4j1seOGeQQGx4ZEcoY BHe1VLAyFVLch/bVGWYOuky6ZuK1rQ1M2kSCxKtB9uWVNlm8XvnTCOPLAhP1oGtyV9uQ hjvmQh7f+sDvqfr2/w4R3MwCVWkGULrjzmBB9U1rJdhCcY1FuVvzGsIRIj409AHJHPl0 aj5Q== X-Gm-Message-State: AOJu0YxUVr99bhoxnConZB13w6k25f4kyZFe8a7Cxse7zhL74x4dV/XT 6y+bY2jJW2nYwg4KBoqqP5lzF/9djPyk83N4Kby2i8D9Cvg= X-Google-Smtp-Source: AGHT+IGNcjW25nK1HrJzJj+6Mu5WuA3NQdYyTlLCLPzh0swT7iChnL+TA2HS96sL+pj4fLbJPc+VKA== X-Received: by 2002:a17:906:3612:b0:a26:97dd:2110 with SMTP id q18-20020a170906361200b00a2697dd2110mr4943796ejb.62.1704189116972; Tue, 02 Jan 2024 01:51:56 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v5 13/13] xen/arm: add cache coloring support for Xen Date: Tue, 2 Jan 2024 10:51:38 +0100 Message-Id: <20240102095138.17933-14-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240102095138.17933-1-carlo.nonato@minervasys.tech> References: <20240102095138.17933-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: 1704189149117100027 Content-Type: text/plain; charset="utf-8" This commit adds the cache coloring support for Xen own physical space. It extends the implementation of setup_pagetables() to make use of Xen cache coloring configuration. Page tables construction is essentially the same except for the fact that PTEs point to a new temporary mapped, physically colored space. The temporary mapping is also used to relocate Xen to the new physical space starting at the address taken from the old get_xen_paddr() function which is brought back for the occasion. The temporary mapping is finally converted to a mapping of the "old" (meaning the original physical space) Xen code, so that the boot CPU can actually address the variables and functions used by secondary CPUs until they enable the MMU. This happens when the boot CPU needs to bring up other CPUs (psci.c and smpboot.c) and when the TTBR value is passed to them (prepare_secondary_mm()). 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 --- 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 | 9 +- xen/arch/arm/arm64/mmu/head.S | 48 +++++++ xen/arch/arm/arm64/mmu/mm.c | 26 +++- xen/arch/arm/include/asm/llc-coloring.h | 16 +++ xen/arch/arm/include/asm/mm.h | 7 +- xen/arch/arm/llc-coloring.c | 44 +++++++ xen/arch/arm/mmu/setup.c | 82 +++++++++++- xen/arch/arm/mmu/smpboot.c | 11 +- xen/arch/arm/psci.c | 9 +- xen/arch/arm/setup.c | 165 +++++++++++++++++++++++- xen/arch/arm/smpboot.c | 9 +- 11 files changed, 406 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 016e66978b..54cbc2afad 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -209,8 +210,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 10774f30e4..6f0cc72897 100644 --- a/xen/arch/arm/arm64/mmu/head.S +++ b/xen/arch/arm/arm64/mmu/head.S @@ -419,6 +419,54 @@ fail: PRINT("- Boot failed -\r\n") b 1b ENDPROC(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 + */ + dsb sy /* So the CPU issues all writes to the range */ + + 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 + + b switch_ttbr_id + /* * Switch TTBR * diff --git a/xen/arch/arm/arm64/mmu/mm.c b/xen/arch/arm/arm64/mmu/mm.c index d2651c9486..5a26d64ab7 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 */ =20 #include +#include #include #include =20 @@ -125,27 +126,44 @@ void update_identity_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/llc-coloring.h b/xen/arch/arm/include= /asm/llc-coloring.h index 5f9b0a8121..4d6071e50b 100644 --- a/xen/arch/arm/include/asm/llc-coloring.h +++ b/xen/arch/arm/include/asm/llc-coloring.h @@ -12,11 +12,27 @@ #define __ASM_ARM_COLORING_H__ =20 #include +#include + +/** + * Iterate over each Xen mfn in the colored space. + * @mfn: the current mfn. The first non colored mfn must be provided as= the + * starting point. + * @i: loop index. + */ +#define for_each_xen_colored_mfn(mfn, i) \ + for ( i =3D 0, mfn =3D xen_colored_mfn(mfn); \ + i < (_end - _start) >> PAGE_SHIFT; \ + i++, mfn =3D xen_colored_mfn(mfn_add(mfn, 1)) ) =20 bool __init llc_coloring_init(void); int dom0_set_llc_colors(struct domain *d); int domain_set_llc_colors_from_str(struct domain *d, const char *str); =20 +paddr_t xen_colored_map_size(paddr_t size); +mfn_t xen_colored_mfn(mfn_t mfn); +void *xen_remap_colored(mfn_t xen_fn, paddr_t xen_size); + #endif /* __ASM_ARM_COLORING_H__ */ =20 /* diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 1829c559d6..311f092cf2 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -203,12 +203,17 @@ extern unsigned long frametable_base_pdx; =20 #define PDX_GROUP_SHIFT SECOND_SHIFT =20 +#define virt_to_reloc_virt(virt) \ + (((vaddr_t)virt) - XEN_VIRT_START + BOOT_RELOC_VIRT_START) + /* Boot-time pagetable setup */ -extern void setup_pagetables(unsigned long boot_phys_offset); +extern void setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_p= addr); /* Map FDT in boot pagetable */ extern void *early_fdt_map(paddr_t fdt_paddr); /* Remove early mappings */ extern void remove_early_mappings(void); +/* Remove early LLC coloring mappings */ +extern void remove_llc_coloring_mappings(void); /* Prepare the memory subystem to bring-up the given secondary CPU */ extern int prepare_secondary_mm(int cpu); /* Map a frame table to cover physical addresses ps through pe */ diff --git a/xen/arch/arm/llc-coloring.c b/xen/arch/arm/llc-coloring.c index 99ea69ad39..f434efc45b 100644 --- a/xen/arch/arm/llc-coloring.c +++ b/xen/arch/arm/llc-coloring.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include #include @@ -38,6 +39,7 @@ static unsigned int __ro_after_init xen_num_colors; =20 #define mfn_color_mask (nr_colors - 1) #define mfn_to_color(mfn) (mfn_x(mfn) & mfn_color_mask) +#define mfn_set_color(mfn, color) ((mfn_x(mfn) & ~mfn_color_mask) | (col= or)) =20 /* * Parse the coloring configuration given in the buf string, following the @@ -354,6 +356,48 @@ unsigned int get_nr_llc_colors(void) return nr_colors; } =20 +paddr_t xen_colored_map_size(paddr_t size) +{ + return ROUNDUP(size * nr_colors, XEN_PADDR_ALIGN); +} + +mfn_t 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; + else if ( color < xen_colors[i] ) + return mfn_set_color(mfn, xen_colors[i]); + } + + /* Jump to next color space (nr_colors mfns) and use the first color */ + return mfn_set_color(mfn_add(mfn, nr_colors), xen_colors[0]); +} + +void *xen_remap_colored(mfn_t xen_mfn, paddr_t xen_size) +{ + unsigned int i; + void *xenmap; + mfn_t *xen_colored_mfns; + + 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, i ) + { + xen_colored_mfns[i] =3D xen_mfn; + } + + xenmap =3D vmap(xen_colored_mfns, xen_size >> PAGE_SHIFT); + xfree(xen_colored_mfns); + + return xenmap; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 37b6d230ad..66b674eeab 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 =20 @@ -39,6 +40,10 @@ DEFINE_PER_CPU(lpae_t *, xen_pgtable); static DEFINE_PAGE_TABLE(cpu0_pgtable); #endif =20 +#ifdef CONFIG_LLC_COLORING +static DEFINE_PAGE_TABLE(xen_colored_temp); +#endif + /* Common pagetable leaves */ /* Second level page table used to cover Xen virtual address space */ static DEFINE_PAGE_TABLE(xen_second); @@ -130,7 +135,12 @@ static void __init __maybe_unused build_assertions(voi= d) =20 lpae_t __init pte_of_xenaddr(vaddr_t va) { - paddr_t ma =3D va + phys_offset; + paddr_t ma; + + if ( llc_coloring_enabled ) + ma =3D virt_to_maddr(virt_to_reloc_virt(va)); + else + ma =3D va + phys_offset; =20 return mfn_to_xen_entry(maddr_to_mfn(ma), MT_NORMAL); } @@ -216,11 +226,55 @@ static void xen_pt_enforce_wnx(void) flush_xen_tlb_local(); } =20 +#ifdef CONFIG_LLC_COLORING +static void __init create_llc_coloring_mappings(paddr_t xen_paddr) +{ + lpae_t pte; + unsigned int i; + mfn_t mfn =3D maddr_to_mfn(xen_paddr); + + for_each_xen_colored_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_colored_temp[i] =3D pte; + } + + pte =3D mfn_to_xen_entry(virt_to_mfn(xen_colored_temp), MT_NORMAL); + pte.pt.table =3D 1; + write_pte(&boot_second[second_table_offset(BOOT_RELOC_VIRT_START)], pt= e); +} + +void __init remove_llc_coloring_mappings(void) +{ + int rc; + + /* destroy the _PAGE_BLOCK mapping */ + rc =3D modify_xen_mappings(BOOT_RELOC_VIRT_START, + BOOT_RELOC_VIRT_START + SZ_2M, + _PAGE_BLOCK); + BUG_ON(rc); +} +#else +static void __init create_llc_coloring_mappings(paddr_t xen_paddr) {} +void __init remove_llc_coloring_mappings(void) {} +#endif /* CONFIG_LLC_COLORING */ + /* - * Boot-time pagetable setup. + * Boot-time pagetable setup with coloring support * Changes here may need matching changes in head.S + * + * The coloring support consists of: + * - Create a temporary colored mapping that conforms to Xen color selecti= on. + * - pte_of_xenaddr takes care of translating the virtual addresses to the + * new colored physical space and the returns the pte, so that the page = table + * initialization can remain the same. + * - Copy Xen to the new colored physical space by exploiting the temporary + * mapping. + * - Update TTBR0_EL2 with the new root page table address. */ -void __init setup_pagetables(unsigned long boot_phys_offset) + +void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_p= addr) { uint64_t ttbr; lpae_t pte, *p; @@ -228,6 +282,9 @@ void __init setup_pagetables(unsigned long boot_phys_of= fset) =20 phys_offset =3D boot_phys_offset; =20 + if ( llc_coloring_enabled ) + create_llc_coloring_mappings(xen_paddr); + arch_setup_page_tables(); =20 #ifdef CONFIG_ARM_64 @@ -281,10 +338,13 @@ void __init setup_pagetables(unsigned long boot_phys_= offset) pte.pt.table =3D 1; xen_second[second_table_offset(FIXMAP_ADDR(0))] =3D pte; =20 + if ( llc_coloring_enabled ) + ttbr =3D virt_to_maddr(virt_to_reloc_virt(xen_pgtable)); + else #ifdef CONFIG_ARM_64 - ttbr =3D (uintptr_t) xen_pgtable + phys_offset; + ttbr =3D (uintptr_t) xen_pgtable + phys_offset; #else - ttbr =3D (uintptr_t) cpu0_pgtable + phys_offset; + ttbr =3D (uintptr_t) cpu0_pgtable + phys_offset; #endif =20 switch_ttbr(ttbr); @@ -294,6 +354,18 @@ void __init setup_pagetables(unsigned long boot_phys_o= ffset) #ifdef CONFIG_ARM_32 per_cpu(xen_pgtable, 0) =3D cpu0_pgtable; #endif + + /* + * Keep original Xen memory mapped because secondary CPUs still point t= o it + * and a few variables needs to be accessed by the master CPU in order = to + * let them boot. This mapping will also replace the one created at the + * beginning of setup_pagetables. + */ + if ( llc_coloring_enabled ) + map_pages_to_xen(BOOT_RELOC_VIRT_START, + maddr_to_mfn(XEN_VIRT_START + phys_offset), + SZ_2M >> PAGE_SHIFT, PAGE_HYPERVISOR_RW | _PAGE_B= LOCK); + } =20 void *__init arch_vmap_virt_end(void) diff --git a/xen/arch/arm/mmu/smpboot.c b/xen/arch/arm/mmu/smpboot.c index b6fc0aae07..a69183ec88 100644 --- a/xen/arch/arm/mmu/smpboot.c +++ b/xen/arch/arm/mmu/smpboot.c @@ -6,6 +6,7 @@ */ =20 #include +#include =20 #include =20 @@ -71,14 +72,20 @@ static void clear_boot_pagetables(void) #ifdef CONFIG_ARM_64 int prepare_secondary_mm(int cpu) { + uint64_t *init_ttbr_addr =3D &init_ttbr; + clear_boot_pagetables(); =20 + if ( llc_coloring_enabled ) + init_ttbr_addr =3D (uint64_t *)virt_to_reloc_virt(&init_ttbr); + /* * Set init_ttbr for this CPU coming up. All CPUs share a single setof * pagetables, but rewrite it each time for consistency with 32 bit. */ - init_ttbr =3D virt_to_maddr(xen_pgtable); - clean_dcache(init_ttbr); + *init_ttbr_addr =3D virt_to_maddr(xen_pgtable); + clean_dcache(*init_ttbr_addr); + return 0; } #else diff --git a/xen/arch/arm/psci.c b/xen/arch/arm/psci.c index 695d2fa1f1..23e298c477 100644 --- a/xen/arch/arm/psci.c +++ b/xen/arch/arm/psci.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include #include @@ -39,9 +40,13 @@ static uint32_t psci_cpu_on_nr; int call_psci_cpu_on(int cpu) { struct arm_smccc_res res; + vaddr_t init_secondary_addr =3D (vaddr_t)init_secondary; =20 - arm_smccc_smc(psci_cpu_on_nr, cpu_logical_map(cpu), __pa(init_secondar= y), - &res); + if ( llc_coloring_enabled ) + init_secondary_addr =3D virt_to_reloc_virt(init_secondary); + + arm_smccc_smc(psci_cpu_on_nr, cpu_logical_map(cpu), + __pa(init_secondary_addr), &res); =20 return PSCI_RET(res); } diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 4c16b566db..ebbbf39477 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -545,6 +545,100 @@ static void * __init relocate_fdt(paddr_t dtb_paddr, = size_t dtb_size) return fdt; } =20 +#ifdef CONFIG_LLC_COLORING +/* + * 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 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); + } + } + + /* Now check any fdt reserved areas. */ + + nr =3D fdt_num_mem_rsv(device_tree_flattened); + + for ( ; i < mi->nr_mods + nr; i++ ) + { + paddr_t mod_s, mod_e; + + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, + i - mi->nr_mods, + &mod_s, &mod_e ) < 0 ) + /* If we can't read it, pretend it doesn't exist... */ + continue; + + /* fdt_get_mem_rsv_paddr returns length */ + mod_e +=3D mod_s; + + 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 bootinfo.reserved_mem bank starting from 0, and + * only counting the reserved-memory modules. Hence, we need to use + * i - nr. + */ + nr +=3D mi->nr_mods; + for ( ; i - nr < bootinfo.reserved_mem.nr_banks; i++ ) + { + paddr_t r_s =3D bootinfo.reserved_mem.bank[i - nr].start; + paddr_t r_e =3D r_s + bootinfo.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); + } + } + return e; +} +#endif + /* * Return the end of the non-module region starting at s. In other * words return s the start of the next modules after s. @@ -579,6 +673,62 @@ static paddr_t __init next_module(paddr_t s, paddr_t *= end) return lowest; } =20 +#ifdef CONFIG_LLC_COLORING +/** + * 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(uint32_t xen_size) +{ + struct meminfo *mi =3D &bootinfo.mem; + paddr_t min_size; + paddr_t paddr =3D 0; + 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 < mi->nr_banks; i++ ) + { + const struct membank *bank =3D &mi->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 > 0x100000000ULL ) + e =3D 0x100000000ULL; + 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; +} +#else +static paddr_t __init get_xen_paddr(uint32_t xen_size) { return 0; } +#endif + void __init init_pdx(void) { paddr_t bank_start, bank_size, bank_end; @@ -724,8 +874,6 @@ void asmlinkage __init start_xen(unsigned long boot_phy= s_offset, /* Initialize traps early allow us to get backtrace when an error occu= rred */ init_traps(); =20 - setup_pagetables(boot_phys_offset); - smp_clear_cpu_maps(); =20 device_tree_flattened =3D early_fdt_map(fdt_paddr); @@ -751,8 +899,13 @@ void asmlinkage __init start_xen(unsigned long boot_ph= ys_offset, { if ( !llc_coloring_init() ) panic("Xen LLC coloring support: setup failed\n"); + xen_bootmodule->size =3D xen_colored_map_size(_end - _start); + xen_bootmodule->start =3D get_xen_paddr(xen_bootmodule->size); } =20 + setup_pagetables(boot_phys_offset, xen_bootmodule->start); + device_tree_flattened =3D early_fdt_map(fdt_paddr); + setup_mm(); =20 /* Parse the ACPI tables for possible boot-time configuration */ @@ -867,6 +1020,14 @@ void asmlinkage __init start_xen(unsigned long boot_p= hys_offset, =20 setup_virt_paging(); =20 + /* + * The removal is done earlier than discard_initial_modules beacuse the + * livepatch init uses a virtual address equal to BOOT_RELOC_VIRT_STAR= T. + * Remove LLC coloring mappings to expose a clear state to the livepat= ch + * module. + */ + if ( llc_coloring_enabled ) + remove_llc_coloring_mappings(); do_initcalls(); =20 /* diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 7110bc11fc..7ed7357d58 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,7 @@ int __cpu_up(unsigned int cpu) { int rc; s_time_t deadline; + unsigned long *smp_up_cpu_addr =3D &smp_up_cpu; =20 printk("Bringing up CPU%d\n", cpu); =20 @@ -459,9 +461,12 @@ int __cpu_up(unsigned int cpu) /* Tell the remote CPU what its logical CPU ID is. */ init_data.cpuid =3D cpu; =20 + if ( llc_coloring_enabled ) + smp_up_cpu_addr =3D (unsigned long *)virt_to_reloc_virt(&smp_up_cp= u); + /* Open the gate for this CPU */ - smp_up_cpu =3D cpu_logical_map(cpu); - clean_dcache(smp_up_cpu); + *smp_up_cpu_addr =3D cpu_logical_map(cpu); + clean_dcache(*smp_up_cpu_addr); =20 rc =3D arch_cpu_up(cpu); =20 --=20 2.34.1