From nobody Wed May 8 10:37:51 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=1674488939; cv=none; d=zohomail.com; s=zohoarc; b=Z+mfvxHwYXgIafMeLyqplNdZbfGL7x6D8y73Nnr+RMOUpJTOUN4mspSBe9MefYtseAbcCzdwCblygZk/98//Ld15WUUVihpSNUBKI3x9M4r+XpSxUUVcf+Ql0SdipJv0PIZuM+/+MFRMB1NvDiSxZItCYN/ZxQqF8MHTmKn+WsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488939; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3H72rNsIsMCXOiG8PzTR5/Br1dIcMG15DtbAn/iuSxU=; b=Pru1XfEaAyHrnzLQl+zYlP1ECiYBz6eU3lHvD9Dh1Rys9KKdtSmiBucYRPnabivA3pvhfJgCSgvHDp66yKcArbw7dNGRBtzZdI4lngHCu4Z+3gfTDc3f8ZqDRpFfhJA8Zxv77zjILwygFKBGGssTixCzzQmdEKi53l6STZ3hlLI= 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 1674488939018518.7264190954988; Mon, 23 Jan 2023 07:48:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483023.748909 (Exim 4.92) (envelope-from ) id 1pJz3T-0000Mq-7n; Mon, 23 Jan 2023 15:48:19 +0000 Received: by outflank-mailman (output) from mailman id 483023.748909; Mon, 23 Jan 2023 15:48:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3T-0000Mj-4g; Mon, 23 Jan 2023 15:48:19 +0000 Received: by outflank-mailman (input) for mailman id 483023; Mon, 23 Jan 2023 15:48:17 +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 1pJz3R-0000MU-9t for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:17 +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 53df98c2-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:06 +0100 (CET) Received: by mail-ed1-x532.google.com with SMTP id w14so15073375edi.5 for ; Mon, 23 Jan 2023 07:48:14 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:14 -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: 53df98c2-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=3H72rNsIsMCXOiG8PzTR5/Br1dIcMG15DtbAn/iuSxU=; b=JVD+VcoJ+qMw0GEPyI/HAIC+49qRXTxc0kArNiFfqCZMoo9Kzx2hBUDLaa6wRUVqxU eVvEcG08lJjQWSq81P4FMMdhzhoFjcfNNlSayV37vKZ3rKCLN/Hf5SXI+4A4NBteF6lR D9kfK0GSf3zaUIfddQ8AoqlAUOieMboczhZQiRoYGQGVpkJEN3fUcUBASAz/D8s2FwqH VSTquYU7Atb1Q+Fm8fX1wjW56gtYtSZPB3cRb35MxCwM6qCF5ZimwfsO7p89B7m0KsY0 72g9ug7gJd3leY3gLluq/CeMOMnOmUbv/2YDgtE5ATdil0FFyhmmbdDbotQm4UrJNXju rhhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3H72rNsIsMCXOiG8PzTR5/Br1dIcMG15DtbAn/iuSxU=; b=3d5e6cZXjBBafW+8w39zounj1ISSX54BbC4JgLfzpm2P61jTnXmsDOPxxTjAWceChf 9L/k/Xvdr2jvh+HB22IqwEd9EcCf58huAXffpFSg14bQxgUnOZebqALul2esk9+DKJ7b h93RFQk+xWHWjkX25Xr1vwwcZFcMbsRsao3Z8vQNLhTHVegMnLq1usj4Q/kvHxfCrwqV kjhPgKUSJC6aYLAaXAezdtblK/8hI/q0UU6GI5gmLgtrUAXh1u3v+jQHvePTnFGCc+PD FXhBZj+uZ5mknIIez07rZSR5LN2S5HskpnS3jLErHEUazSpqqhx6PPfF3/irZ+BPdLRH qEMA== X-Gm-Message-State: AFqh2kr/UQjya6mOFmxadTB8T10c0snYqIKme8odYqYeuvojA/6bw4lH upHB3tyTh0IXb1CvxT2lkCId9tSRTGQxu64Z X-Google-Smtp-Source: AMrXdXsn4lVaXUAIsFwRDoSu2MtLlAzePVMLFPMkmZ2nzcWg97aMcuSbdlgwa8aB7yIvmlgcmUbFfA== X-Received: by 2002:a05:6402:1946:b0:48b:c8de:9d20 with SMTP id f6-20020a056402194600b0048bc8de9d20mr28353774edz.32.1674488894307; Mon, 23 Jan 2023 07:48:14 -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 v4 01/11] xen/common: add cache coloring common code Date: Mon, 23 Jan 2023 16:47:25 +0100 Message-Id: <20230123154735.74832-2-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488939687100004 Content-Type: text/plain; charset="utf-8" This commit adds the Last Level Cache (LLC) coloring common header, Kconfig options and stub functions for domain coloring. 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 represented as dynamic arrays plus their size and since they have to be passed during domain creation, domain_create() is replaced by domain_create_llc_colored(). domain_create() is then turned into a wrapper of the colored version to let all the original call sites remain untouched. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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 | 17 +++++++++++ xen/common/Kconfig | 3 ++ xen/common/domain.c | 23 +++++++++++++-- xen/common/keyhandler.c | 4 +++ xen/include/xen/llc_coloring.h | 54 ++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 9 ++++++ 6 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 xen/include/xen/llc_coloring.h diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index 7028f7b74f..39c23f2528 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -28,3 +28,20 @@ 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 the documentation for how to compute the number + of colors supported by the platform. + The default value corresponds to an 8 MiB 16-ways LLC, which should be + more than what needed in the general case. + Note that if, at any time, a color configuration with more colors than + the maximum is employed, an error is produced. diff --git a/xen/common/Kconfig b/xen/common/Kconfig index f1ea3199c8..c796c633f1 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -49,6 +49,9 @@ config HAS_IOPORTS config HAS_KEXEC bool =20 +config HAS_LLC_COLORING + bool + config HAS_PDX bool =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 626debbae0..87aae86081 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -549,9 +550,11 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) return arch_sanitise_domain_config(config); } =20 -struct domain *domain_create(domid_t domid, - struct xen_domctl_createdomain *config, - unsigned int flags) +struct domain *domain_create_llc_colored(domid_t domid, + struct xen_domctl_createdomain *c= onfig, + unsigned int flags, + unsigned int *llc_colors, + unsigned int num_llc_colors) { struct domain *d, **pd, *old_hwdom =3D NULL; enum { INIT_watchdog =3D 1u<<1, @@ -663,6 +666,10 @@ struct domain *domain_create(domid_t domid, d->nr_pirqs =3D min(d->nr_pirqs, nr_irqs); =20 radix_tree_init(&d->pirq_tree); + + if ( llc_coloring_enabled && + (err =3D domain_llc_coloring_init(d, llc_colors, num_llc_colo= rs)) ) + return ERR_PTR(err); } =20 if ( (err =3D arch_domain_create(d, config, flags)) !=3D 0 ) @@ -769,6 +776,13 @@ struct domain *domain_create(domid_t domid, return ERR_PTR(err); } =20 +struct domain *domain_create(domid_t domid, + struct xen_domctl_createdomain *config, + unsigned int flags) +{ + return domain_create_llc_colored(domid, config, flags, 0, 0); +} + void __init setup_system_domains(void) { /* @@ -1103,6 +1117,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 0a551033c4..56f7731595 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..625930d378 --- /dev/null +++ b/xen/include/xen/llc_coloring.h @@ -0,0 +1,54 @@ +/* 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 + +extern bool llc_coloring_enabled; + +int domain_llc_coloring_init(struct domain *d, unsigned int *colors, + unsigned int num_colors); +void domain_llc_coloring_free(struct domain *d); +void domain_dump_llc_colors(struct domain *d); + +#else + +#define llc_coloring_enabled (false) + +static inline int domain_llc_coloring_init(struct domain *d, + unsigned int *colors, + unsigned int num_colors) +{ + return 0; +} +static inline void domain_llc_coloring_free(struct domain *d) {} +static inline void domain_dump_llc_colors(struct domain *d) {} + +#endif /* CONFIG_HAS_LLC_COLORING */ + +#define is_domain_llc_colored(d) (llc_coloring_enabled) + +#endif /* __COLORING_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ \ No newline at end of file diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 12be794002..754f6cb1da 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -602,6 +602,9 @@ struct domain =20 /* Holding CDF_* constant. Internal flags for domain creation. */ unsigned int cdf; + + unsigned int *llc_colors; + unsigned int num_llc_colors; }; =20 static inline struct page_list_head *page_to_list( @@ -685,6 +688,12 @@ static inline void domain_update_node_affinity(struct = domain *d) */ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config); =20 +struct domain *domain_create_llc_colored(domid_t domid, + struct xen_domctl_createdomain *c= onfig, + unsigned int flags, + unsigned int *colors, + unsigned int num_colors); + /* * Create a domain: the configuration is only necessary for real domain * (domid < DOMID_FIRST_RESERVED). --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488939; cv=none; d=zohomail.com; s=zohoarc; b=GLD2pDMcFm0ntiDyid4ltft0nOD4dZMXoS0sjofgZKbXk2UE0JzT7tQ0FCzvAwsLLYD8nGsJ8i3FcUpXZNRfu4MFbM6eThqw7iJO60J9ACC886ebfBUPUnQ3Odql15ff8I/8Gz78XQefeyJG5ofeSLZg5E70x/6DDExouVYBYGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488939; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sITnfQ4HJpU2pnVbt8P3FE0rc8UsS7v3Y6FN0Y7K5Ec=; b=e3AsXY8OH8n/Bum3Uv7b+EzS7OeG6vH6Wk8A7Oi6yOPWETQ/g+9zAsRaCyezz8M0XtxE+OdCHrzkzO0gPqSYp/DT2SakBJ99F8tWzclPHunuk2OiIrHOweq2qFBk3VhvrCTh50/aI1cFXjFbgf8zJvtExv58iexslkFWOl5tXoo= 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 1674488939045978.7591052519906; Mon, 23 Jan 2023 07:48:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483024.748916 (Exim 4.92) (envelope-from ) id 1pJz3T-0000S4-Py; Mon, 23 Jan 2023 15:48:19 +0000 Received: by outflank-mailman (output) from mailman id 483024.748916; Mon, 23 Jan 2023 15:48:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3T-0000RA-Gx; Mon, 23 Jan 2023 15:48:19 +0000 Received: by outflank-mailman (input) for mailman id 483024; Mon, 23 Jan 2023 15:48:18 +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 1pJz3S-00006V-Bh for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:18 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5a0824ac-9b35-11ed-91b6-6bf2151ebd3b; Mon, 23 Jan 2023 16:48:16 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id kt14so31671499ejc.3 for ; Mon, 23 Jan 2023 07:48:16 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:15 -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: 5a0824ac-9b35-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=sITnfQ4HJpU2pnVbt8P3FE0rc8UsS7v3Y6FN0Y7K5Ec=; b=vXTZorvaFk7tPS6jRfp7QIKsrCHMKF9khIGSKPHjfyZ5k58PzWiuOwCPFjg3/4r58q EpK9luHJgPdCU2C2nI/vgHL5aK0H6yyURP5ln2b2IRo8mPmcH4o9oXjMgl+4DfTcpMLz st0HY028TtxFNUD4T1QO7Ck3IRqiF/02d4ZwsnsbXM09jekhAEvvwJAWPb6o9teZG9IZ EhSbsiRQqB15fJ65gIh+BP+LeybR/6hHLuPHshMimBqaFqekSoiQOs/4CT0Ac8ObpgC9 7CeI/eqHPJdq3ilu4XCFE8MuM7ciZhdaYsaYHlIEeWkAQxSTTPSc97ltBMS1fkKpzYpD Sz6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sITnfQ4HJpU2pnVbt8P3FE0rc8UsS7v3Y6FN0Y7K5Ec=; b=qqQEJ2FEwU21ad/D3Jp8Z+qkGDeCgkuqmc+O2yLpUBkd9UFdA2+af+n56gsVxTKEz0 jGr/UN/DzNLPZAQQyLU2dyQ7UHNE+iTWoSW5Q3Spd5Nu2qFHs+DDR2zPOPfde8MgT74/ jwscX5ke/mZcUzDC5Mcqs60hWgE0kMFCq82ogSR4AdLnAuGCLcqhAuHP0riT11AcjWDY ML9i6HdVbZKaWGIGh6cNhm78aPjnO8BT9kfodsq9vOeECWmcNhclouaK5NCJCR5OCXUh KDRPqP8WTDEZmSYBC+HIWrJKq+AAsN55LLUE3xxkesKJbJ1UX+OxekBHWJ61M38oj/s8 VjVQ== X-Gm-Message-State: AFqh2koDccIR9Oum7OnSvV8y2PuIYUrm+zvYokTFGMcZbjLjksJVtDtj p9hHHQ7ZGPqx06BZAovyosi3ApmrM3pSS/8e X-Google-Smtp-Source: AMrXdXuTeuyZHvSU1zURldM42WGe0cZ6rMCvu9LEzN1p6IVaH8Iv1xR+F3P9p6aDuAIgIKU8uAgFXg== X-Received: by 2002:a17:906:2542:b0:877:6e07:92df with SMTP id j2-20020a170906254200b008776e0792dfmr20135507ejb.15.1674488895626; Mon, 23 Jan 2023 07:48:15 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v4 02/11] xen/arm: add cache coloring initialization Date: Mon, 23 Jan 2023 16:47:26 +0100 Message-Id: <20230123154735.74832-3-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488939972100010 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. The domain init function, instead, allocates default colors if needed and checks the provided configuration for errors. Note that until this patch, there are no implemented methods for actually configuring cache colors for domains and all the configurations fall back to the default one. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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 | 105 +++++++++ docs/misc/xen-command-line.pandoc | 37 ++++ xen/arch/arm/Kconfig | 1 + xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/llc_coloring.h | 36 ++++ xen/arch/arm/include/asm/processor.h | 16 ++ xen/arch/arm/llc_coloring.c | 272 ++++++++++++++++++++++++ xen/arch/arm/setup.c | 7 + 8 files changed, 475 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..0244d2f606 --- /dev/null +++ b/docs/misc/arm/cache-coloring.rst @@ -0,0 +1,105 @@ +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. + +In order to enable and use it, few steps are needed. + +In Kconfig: + +- Enable LLC coloring. + + CONFIG_LLC_COLORING=3Dy +- If needed, change the maximum number of colors (refer to menuconfig help= for + value meaning and when it should be changed). + + CONFIG_NR_LLC_COLORS=3D + +Compile Xen and the toolstack and then: + +- Set the `llc-coloring=3Don` command line option. +- Set `Coloring parameters and domain configurations`_. + +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. + +.. raw:: html + +
+                            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 `Coloring parameters and domain +configurations`_ section for more information on that. + +Coloring parameters and domain configurations +********************************************* + +LLC way size (as previously discussed) can be set using the appropriate co= mmand +line parameter. See the relevant documentation in +"docs/misc/xen-command-line.pandoc". + +**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 +**************************** + +"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 923910f553..eb105c03af 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -908,6 +908,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: @@ -1645,6 +1654,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 239d3aed3c..97eac24ee3 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -9,6 +9,7 @@ config ARM_64 select 64BIT select ARM_EFI 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 4d076b278b..7f5cb8ef26 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_IOREQ_SERVER) +=3D ioreq.o obj-y +=3D irq.o obj-y +=3D kernel.init.o obj-$(CONFIG_LIVEPATCH) +=3D livepatch.o +obj-$(CONFIG_LLC_COLORING) +=3D llc_coloring.o obj-y +=3D mem_access.o obj-y +=3D mm.o obj-y +=3D monitor.o 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..c7985c8fd0 --- /dev/null +++ b/xen/arch/arm/include/asm/llc_coloring.h @@ -0,0 +1,36 @@ +/* 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 + +#ifdef CONFIG_LLC_COLORING + +bool __init llc_coloring_init(void); + +#else /* !CONFIG_LLC_COLORING */ + +static inline bool __init llc_coloring_init(void) { return true; } + +#endif /* CONFIG_LLC_COLORING */ + +#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: + */ \ No newline at end of file diff --git a/xen/arch/arm/include/asm/processor.h b/xen/arch/arm/include/as= m/processor.h index 1dd81d7d52..1c5f6d6e7a 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..44b601915e --- /dev/null +++ b/xen/arch/arm/llc_coloring.c @@ -0,0 +1,272 @@ +/* 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 +#include + +bool 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; +/* Mask to extract coloring relevant bits */ +static paddr_t __ro_after_init addr_col_mask; + +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) +{ + 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 bool check_colors(unsigned int *colors, unsigned int num_colors) +{ + unsigned int i; + + if ( num_colors > nr_colors ) + return false; + + for ( i =3D 0; i < num_colors; i++ ) + if ( colors[i] >=3D nr_colors || + (i !=3D num_colors - 1 && colors[i] >=3D colors[i + 1]) ) + return false; + + return true; +} + +static void print_colors(unsigned int *colors, unsigned int num_colors) +{ + unsigned int i; + + printk("[ "); + for ( i =3D 0; i < num_colors; i++ ) + printk("%u ", colors[i]); + 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); + printk("Address to LLC color mask: 0x%lx\n", addr_col_mask); +} + +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; + } + + addr_col_mask =3D (nr_colors - 1) << PAGE_SHIFT; + + register_keyhandler('K', dump_coloring_info, "dump LLC coloring info",= 1); + + return true; +} + +static unsigned int *alloc_colors(unsigned int num_colors) +{ + unsigned int *colors =3D xmalloc_array(unsigned int, num_colors); + + if ( !colors ) + panic("Unable to allocate LLC colors\n"); + + return colors; +} + +int domain_llc_coloring_init(struct domain *d, unsigned int *colors, + unsigned int num_colors) +{ + unsigned int i; + + if ( is_domain_direct_mapped(d) ) + { + printk(XENLOG_ERR + "LLC coloring and direct mapping are incompatible (%pd)\n",= d); + return -EINVAL; + } + + if ( !colors || num_colors =3D=3D 0 ) + { + printk(XENLOG_WARNING + "LLC color config not found for %pd. Using default\n", d); + colors =3D alloc_colors(nr_colors); + num_colors =3D nr_colors; + for ( i =3D 0; i < nr_colors; i++ ) + colors[i] =3D i; + } + + d->llc_colors =3D colors; + d->num_llc_colors =3D num_colors; + + if ( !check_colors(d->llc_colors, d->num_llc_colors) ) + { + /* d->llc_colors will be freed in domain_destroy() */ + printk(XENLOG_ERR "Bad LLC color config for %pd\n", d); + print_colors(d->llc_colors, d->num_llc_colors); + return -EINVAL; + } + + return 0; +} + +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 1f26f67b90..c04e5012f0 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -1026,6 +1027,12 @@ void __init start_xen(unsigned long boot_phys_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 Wed May 8 10:37:51 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=1674488941; cv=none; d=zohomail.com; s=zohoarc; b=dRrpEw690x0lj36eQXEQ5UA95H0ElkCeRmzkL3FZSCICc5Q6EEUFRZRUs88hfXGQYeicWqL/yDaeLmYhZvqirJugrQbppA1xNhXUBiw9PsgTtgmaruJ8/ubHSnBJM+nYOkWCtFEQGe2y7/WR9avR5jLMWLLuaGZniq04rsyZnG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488941; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mg6oHA/uZutZbHyBN28TLCcwMCTT4JS4VhjaLKbCk4w=; b=FodG5VqxK8iEB+iI5FykLjdLqrF0ppPkUn1YkU8oL83raqIEhP1IwYm8tI9v/KsAwzv2bxoVsjF7cDxAn+ipYUIcrl5p+GTIcwFr4CFxHnCaXZ5FbE0JkLDUhO8bA05VBJ8PLALDaFtxAwWBVNToUPvqrGe/LwZXI+guf3/O7g4= 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 16744889411701003.2771369327194; Mon, 23 Jan 2023 07:49:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483025.748929 (Exim 4.92) (envelope-from ) id 1pJz3V-0000rW-0g; Mon, 23 Jan 2023 15:48:21 +0000 Received: by outflank-mailman (output) from mailman id 483025.748929; Mon, 23 Jan 2023 15:48:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3U-0000qx-Ro; Mon, 23 Jan 2023 15:48:20 +0000 Received: by outflank-mailman (input) for mailman id 483025; Mon, 23 Jan 2023 15:48:19 +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 1pJz3T-0000MU-Ag for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:19 +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 55591b41-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:08 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id bk15so31563027ejb.9 for ; Mon, 23 Jan 2023 07:48:17 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:16 -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: 55591b41-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=mg6oHA/uZutZbHyBN28TLCcwMCTT4JS4VhjaLKbCk4w=; b=rwaw/EoMIwvKsSF0VdKtWC+duAM2m+fq1KiDi7bOg39f9KkOutt5hyyjrp2UzI1rY6 f4sdubtROnGpfPDInDIOHuoAnD4PgyzSrGvzvSE9GpGLbyL4tI7nx8ekLEXCPeM/HqOP hwRQ7jhqPD76FdnKpXNDwdar3C3cYfJdSKjFhd0NlveSsdfR+gmIBs8rCWawANDfEYKE rUZzF3jt2gABHL96ATfqkrw3oqLbjUa/+vMjDklpC30sykImFJZ6wEPzUx+vITc9RBkZ 4f3dqz2kFKv2x1RQBpe/XRxOh8wdUBc1G83FLoaKrr8fTvN0X8falrCB8C7JkBwWH8jF z4jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=mg6oHA/uZutZbHyBN28TLCcwMCTT4JS4VhjaLKbCk4w=; b=futxcvZXrWY+RMbyTZIbIv4SE55Y1KOzCEYjJ78bYcrdiDqwYuroUjj2cdcaYQzgvq PF5p9iFNnZguMLkBpJY/Ih7lzxue6kdT2GbteLZtHYT3dqJRU37Zsq7EX9CYUW9mOMB0 NLa8PFT1j1rRA/HCG3TrtJj1CbJJWZ76IzKGethK5szc/eXmcPY35szi4MUqI81YiAqF VptmzHWCHmf0OBAtj0yb3v9024in0lYerOUTcd7EuHWNVo8WtEUC1zOXgv0uGqz+9UFd BazCb/gJLKd0LAR3lcnPdo3kLxUoVOlBoxFnfsnRoC3S8ASLWTNcKX6MSiS06K55rQyE 1BFQ== X-Gm-Message-State: AFqh2kok6+Rf3FcfToR4FEuXAPOt1hTyKALmYi1fpPZixdo9WMyU2TSq sA3XVM1tM6/dn5CkQzUrtm2Jdc+0HoNLHgAf X-Google-Smtp-Source: AMrXdXuiG1hSBZNw6I84oDkopBiZAdDBhYmFeQRRxj/Pl96Jr5YleKLE44TpRZLUSpCAzQVLzRNVlw== X-Received: by 2002:a17:906:37c4:b0:871:91ec:edae with SMTP id o4-20020a17090637c400b0087191ecedaemr25653113ejc.75.1674488896790; Mon, 23 Jan 2023 07:48:16 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Luca Miccio , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Marco Solieri , Carlo Nonato Subject: [PATCH v4 03/11] xen/arm: add Dom0 cache coloring support Date: Mon, 23 Jan 2023 16:47:27 +0100 Message-Id: <20230123154735.74832-4-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488941703100014 Content-Type: text/plain; charset="utf-8" From: Luca Miccio 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. Here is also introduced a common configuration syntax for cache colors. Signed-off-by: Luca Miccio Signed-off-by: Marco Solieri Signed-off-by: Carlo Nonato --- 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 | 32 ++++++++++++++++++++++--- xen/arch/arm/domain_build.c | 17 +++++++++++-- xen/arch/arm/include/asm/llc_coloring.h | 4 ++++ xen/arch/arm/llc_coloring.c | 14 +++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index 0244d2f606..c2e0e87426 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -83,12 +83,38 @@ manually set the way size it's left for the user to ove= rcome failing situations or for debugging/testing purposes. See `Coloring parameters and domain configurations`_ section for more information on that. =20 +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] | ++---------------------+-----------------------------------+ + Coloring parameters and domain configurations ********************************************* =20 -LLC way size (as previously discussed) can be set using the appropriate co= mmand -line parameter. See the relevant documentation in -"docs/misc/xen-command-line.pandoc". +LLC way size (as previously discussed) and Dom0 colors can be set using the +appropriate command line parameters. See the relevant documentation +in "docs/misc/xen-command-line.pandoc". =20 **Note:** If no color configuration is provided for a domain, the default = one, which corresponds to all available colors, is used instead. diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f35f4d2456..093d4ad6f6 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 @@ -4014,7 +4015,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 #ifdef CONFIG_STATIC_SHM @@ -4060,6 +4064,8 @@ void __init create_dom0(void) .max_maptrack_frames =3D -1, .grant_opts =3D XEN_DOMCTL_GRANT_version(opt_gnttab_max_version), }; + unsigned int *llc_colors =3D NULL; + unsigned int num_llc_colors =3D 0, flags =3D CDF_privileged; =20 /* The vGIC for DOM0 is exactly emulating the hardware GIC */ dom0_cfg.arch.gic_version =3D XEN_DOMCTL_CONFIG_GIC_NATIVE; @@ -4076,7 +4082,14 @@ void __init create_dom0(void) if ( iommu_enabled ) dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; =20 - dom0 =3D domain_create(0, &dom0_cfg, CDF_privileged | CDF_directmap); + if ( llc_coloring_enabled ) + llc_colors =3D dom0_llc_colors(&num_llc_colors); + else + flags |=3D CDF_directmap; + + dom0 =3D domain_create_llc_colored(0, &dom0_cfg, flags, llc_colors, + num_llc_colors); + if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) =3D=3D NULL) ) panic("Error creating domain 0\n"); =20 diff --git a/xen/arch/arm/include/asm/llc_coloring.h b/xen/arch/arm/include= /asm/llc_coloring.h index c7985c8fd0..382ff7de47 100644 --- a/xen/arch/arm/include/asm/llc_coloring.h +++ b/xen/arch/arm/include/asm/llc_coloring.h @@ -17,9 +17,13 @@ =20 bool __init llc_coloring_init(void); =20 +unsigned int *dom0_llc_colors(unsigned int *num_colors); + #else /* !CONFIG_LLC_COLORING */ =20 static inline bool __init llc_coloring_init(void) { return true; } +static inline unsigned int *dom0_llc_colors( + unsigned int *num_colors) { return NULL; } =20 #endif /* CONFIG_LLC_COLORING */ =20 diff --git a/xen/arch/arm/llc_coloring.c b/xen/arch/arm/llc_coloring.c index 44b601915e..51f057d7c9 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -261,6 +261,20 @@ void domain_dump_llc_colors(struct domain *d) print_colors(d->llc_colors, d->num_llc_colors); } =20 +unsigned int *dom0_llc_colors(unsigned int *num_colors) +{ + unsigned int *colors; + + if ( !dom0_num_colors ) + return NULL; + + colors =3D alloc_colors(dom0_num_colors); + memcpy(colors, dom0_colors, sizeof(unsigned int) * dom0_num_colors); + *num_colors =3D dom0_num_colors; + + return colors; +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488938; cv=none; d=zohomail.com; s=zohoarc; b=c9e/uqZpxLOWHPkR2cJJAFy/Y8qma+3j3VQ52e492p3FGsqTph/6KnVRHzj+l60eehbnYBXewGHYAkJAZRflh+0pKyqMhJhvtUMriSX5YU4Om2ATKN11QtHS23few1Ne1de7dkwlV7TGM9HwXKA0yzqYwzaeSyvZY4l/l1TRAWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488938; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wnBfVoJg9BJDdsJ9FVXJ5loGQJGgvjA6ZxNM1ora6pg=; b=KSZARA7Z/7smiOXmF1RMnNEOGExhjzhGUyuCPE+qZ/FoZBCUD+k3TsmCknWCJ469o6wgzPHrFSsV/lhT2EyAKkv39Q63LKFuR+KaNN9bojV3ig9ykSTQblwvVI6ScyslqIiTxGxDPorUz70GgXnaAWinbWIYjmYXZr5SjJ7luhI= 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 167448893826890.65007436893416; Mon, 23 Jan 2023 07:48:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483026.748933 (Exim 4.92) (envelope-from ) id 1pJz3V-0000wr-BG; Mon, 23 Jan 2023 15:48:21 +0000 Received: by outflank-mailman (output) from mailman id 483026.748933; Mon, 23 Jan 2023 15:48:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3V-0000wC-6T; Mon, 23 Jan 2023 15:48:21 +0000 Received: by outflank-mailman (input) for mailman id 483026; Mon, 23 Jan 2023 15:48:19 +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 1pJz3T-00006V-H5 for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:19 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5b4ebd1d-9b35-11ed-91b6-6bf2151ebd3b; Mon, 23 Jan 2023 16:48:18 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id az20so31697997ejc.1 for ; Mon, 23 Jan 2023 07:48:18 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:17 -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: 5b4ebd1d-9b35-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=wnBfVoJg9BJDdsJ9FVXJ5loGQJGgvjA6ZxNM1ora6pg=; b=q0ghmJW9sJbCOkKZCuP6aqaXmTD2uOqfhnRw/qssKHan9iebRjVdoGXERWA6zE28VL kyWUFGZrSIbLlW4iSOxfZtBmIMuyDSjrtY78W63SB7OS6GrveHRmZS2AhdpwJUybfNlo ShBV2pNaWMC6Vmyg07pJN6WuJ9i8rYGxAhIpVpr5H4shJ4OWrFpMrZAE5pwUfwd7Woyn cdcZwWtwpRKacHM2DmMXYONt7zJIEHER5aA/O78dsmDcIwGktYM2JQaOwyYO4YzD1yjZ iE+7tXIBY+m0gjoS322LpIcARZ2H2d8fH+ON82+PPg6apuFDuK/9+YYE1ahhBYpnWp6+ ToOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wnBfVoJg9BJDdsJ9FVXJ5loGQJGgvjA6ZxNM1ora6pg=; b=zPT9JAP3MIYiT4bliIoWysJG5IZN8noGR9Wk8xAx48vXpCmGBneL3z3+W/XI0Blq4t iB3/ELhydpuxM5NRtfc63bMGneODq9du0hmztuW5LfrW98wU+Rquor48YKHYmurofjqm SAl4pH8stQ7RaRXUw+DcLf4Cq1PgNHTNGN8KqFmhH/q6ix5NuVOP33mrBLgsU4X+Kc9b wnNMumwdU5KCYRNEaG4UJsXf0yBEDkPR2MCB4oEl1hGs+GauiYistowSmryb0ib53ymv nllMjCmTCOQds+HrLJ3Ju85xrw4W+z5GIs77mLInTyR/0klcwh0thoOnbMOvg7+HsoES CEnw== X-Gm-Message-State: AFqh2kobiOIoH4uVpC0YcuOuh3NCxY9j4AEbvy0lPypI903VV51jrIxK vfZ5wMsrEQauKRUeTT1S2uuDlkVj9/mB0dM8 X-Google-Smtp-Source: AMrXdXsmBdhNxcDwwp12asj0hXt0Q2CTR14/XB1lp++K8Dldee+U4brxt+QK7C4jD5PB3X87FgcFfg== X-Received: by 2002:a17:906:4351:b0:84d:141f:6784 with SMTP id z17-20020a170906435100b0084d141f6784mr21893886ejm.29.1674488898062; Mon, 23 Jan 2023 07:48:18 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri Subject: [PATCH v4 04/11] xen: extend domctl interface for cache coloring Date: Mon, 23 Jan 2023 16:47:28 +0100 Message-Id: <20230123154735.74832-5-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488939886100007 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 --- v4: - updated XEN_DOMCTL_INTERFACE_VERSION --- xen/arch/arm/llc_coloring.c | 14 ++++++++++++++ xen/common/domctl.c | 12 +++++++++++- xen/include/public/domctl.h | 6 +++++- xen/include/xen/llc_coloring.h | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/llc_coloring.c b/xen/arch/arm/llc_coloring.c index 51f057d7c9..2d0457cdbc 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include #include @@ -275,6 +276,19 @@ unsigned int *dom0_llc_colors(unsigned int *num_colors) return colors; } =20 +unsigned int *llc_colors_from_guest(struct xen_domctl_createdomain *config) +{ + unsigned int *colors; + + if ( !config->num_llc_colors ) + return NULL; + + colors =3D alloc_colors(config->num_llc_colors); + copy_from_guest(colors, config->llc_colors, config->num_llc_colors); + + return colors; +} + /* * Local variables: * mode: C diff --git a/xen/common/domctl.c b/xen/common/domctl.c index ad71ad8a4c..505626ec46 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -8,6 +8,7 @@ =20 #include #include +#include #include #include #include @@ -409,6 +410,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) { domid_t dom; static domid_t rover =3D 0; + unsigned int *llc_colors =3D NULL, num_llc_colors =3D 0; =20 dom =3D op->domain; if ( (dom > 0) && (dom < DOMID_FIRST_RESERVED) ) @@ -434,7 +436,15 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_= domctl) rover =3D dom; } =20 - d =3D domain_create(dom, &op->u.createdomain, false); + if ( llc_coloring_enabled ) + { + llc_colors =3D llc_colors_from_guest(&op->u.createdomain); + num_llc_colors =3D op->u.createdomain.num_llc_colors; + } + + d =3D domain_create_llc_colored(dom, &op->u.createdomain, false, + llc_colors, num_llc_colors); + if ( IS_ERR(d) ) { ret =3D PTR_ERR(d); diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 51be28c3de..49cccc8503 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 0x00000015 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000016 =20 /* * NB. xen_domctl.domain is an IN/OUT parameter for this operation. @@ -92,6 +92,10 @@ struct xen_domctl_createdomain { /* CPU pool to use; specify 0 or a specific existing pool */ uint32_t cpupool_id; =20 + /* IN LLC coloring parameters */ + uint32_t num_llc_colors; + XEN_GUEST_HANDLE(uint32) llc_colors; + struct xen_arch_domainconfig arch; }; =20 diff --git a/xen/include/xen/llc_coloring.h b/xen/include/xen/llc_coloring.h index 625930d378..2855f38296 100644 --- a/xen/include/xen/llc_coloring.h +++ b/xen/include/xen/llc_coloring.h @@ -24,6 +24,8 @@ int domain_llc_coloring_init(struct domain *d, unsigned i= nt *colors, void domain_llc_coloring_free(struct domain *d); void domain_dump_llc_colors(struct domain *d); =20 +unsigned int *llc_colors_from_guest(struct xen_domctl_createdomain *config= ); + #else =20 #define llc_coloring_enabled (false) @@ -36,6 +38,8 @@ static inline int domain_llc_coloring_init(struct domain = *d, } static inline void domain_llc_coloring_free(struct domain *d) {} static inline void domain_dump_llc_colors(struct domain *d) {} +static inline unsigned int *llc_colors_from_guest( + struct xen_domctl_createdomain *config) { return NULL; } =20 #endif /* CONFIG_HAS_LLC_COLORING */ =20 --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488939; cv=none; d=zohomail.com; s=zohoarc; b=LtgCqYUcC+VY1t/JpbmUzFOH/IPHEZU3q3g197oLDZEyTRqg37oDxqly+ebTWqEamy3XPLTZbPsEVZOD7MdtwVGOR71/EEQDPWbLSuXJkV531on8TY5VIqo08s7pO0+vObdgqEjtd9Yv0wywfX1iajCohO/i+fhqRrGfYzhyanI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488939; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bzd4gFUIBqg+ZHD9eDkWBdjmYnoZGDhG9GSzcFzYQKg=; b=PbIOt217fzTambHvAI1jmWVOPOO+CETGmff2JPRxzRXsiEKykm9YxGuDuF3RnH5Yjs/BmANGci8E5CMx+0Lv7sqTI6XK4yIAU6Ka5vCdjKiFWvkCd0XgJ9TBjjpZpM85V7+Kv9yo+w/nsC7HB1r7Ns4Bf2S3R7gtHW9+90ktKnk= 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 167448893894250.193151046813455; Mon, 23 Jan 2023 07:48:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483027.748949 (Exim 4.92) (envelope-from ) id 1pJz3W-0001N6-Rd; Mon, 23 Jan 2023 15:48:22 +0000 Received: by outflank-mailman (output) from mailman id 483027.748949; Mon, 23 Jan 2023 15:48:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3W-0001LS-Ke; Mon, 23 Jan 2023 15:48:22 +0000 Received: by outflank-mailman (input) for mailman id 483027; Mon, 23 Jan 2023 15:48:21 +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 1pJz3V-0000MU-Lt for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:21 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 56be8a4d-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:11 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id hw16so31558504ejc.10 for ; Mon, 23 Jan 2023 07:48:19 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:18 -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: 56be8a4d-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=bzd4gFUIBqg+ZHD9eDkWBdjmYnoZGDhG9GSzcFzYQKg=; b=ETabNKT0EsSZcg15EdQF7dFCM9/xiqUlEIWdA2DWtS5tL9/T5ibgP30fXWC/9WZVJl 18jmVJaFmqGlvDg/zkXGZcHWjRDlkao01TQGZyZArYNvKMtwgAqCbldtwmyscHyyZFb7 snpK8rXogh46SgegLnBG/UPTEgeFyyNdyqJefHnYrbfe5MlqOfV7Tf9XmcsYPJ4lCl0T znmCxVp/aRl/DcejlPKG7POpNdalluMuldgC6B6gR05SAwICtVkfkS4kwri38rP1tgC5 BlefBNdlRWRR8D2N7pStaU8hT+058YVUk12ZxQieUUEHfNChQvlORjK2hnCpyaRbjnhK hJMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=bzd4gFUIBqg+ZHD9eDkWBdjmYnoZGDhG9GSzcFzYQKg=; b=N3Gsw9zl0pFfDnUGAmiCp+GSFhtOQMcvg1WrFR3QJLKAY3UKszUNGMl45hpxKYaFjD /cUav8Xj4Q/vVByts4LDlKv5J1MUXMMIk1YyA5DEAdEKBuYKZdQ4y+c1eqQwra6E7ghF 3dmlz/tCrgmJ+JUGxkF3QIJMmMeiujsYX/QVeNgd47yW7UAqtHpeqdt5hkYdDHZlcwTz c0IkENlLW92uA11aV6syY510qWsGR9yrpEtLW7m2WuKH/6nEh5e/kqO05O1K7v0k6i+w Ygg85oBebcedKiN5xEfrEbVPC6ZKwiFQIB7o1L8BIo3a8gR9Erui52wh/Xyyj5+UO86g zm3Q== X-Gm-Message-State: AFqh2krNVWWZQKfJ7kEOF1Vbxmfc5WJm0ymMuCqwyzQdIPi0o/2WVO5i YowvgnyYSS6+M8Sbt5oLHRaVMID/V4kghes/ X-Google-Smtp-Source: AMrXdXuoiU5iC1OsinUzS2gN900TrrzR7pYn/wJvPrR27p8cQgk49O2CCW3ZKOJgKiy1L4wIQIxxsw== X-Received: by 2002:a17:907:d40c:b0:872:af53:a028 with SMTP id vi12-20020a170907d40c00b00872af53a028mr24373339ejc.61.1674488899145; Mon, 23 Jan 2023 07:48:19 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Wei Liu , Anthony PERARD , Juergen Gross , Marco Solieri Subject: [PATCH v4 05/11] tools: add support for cache coloring configuration Date: Mon, 23 Jan 2023 16:47:29 +0100 Message-Id: <20230123154735.74832-6-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488939678100002 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 --- v4: - removed overlapping color ranges checks during parsing - moved hypercall buffer initialization in libxenctrl --- docs/man/xl.cfg.5.pod.in | 10 +++++++++ tools/libs/ctrl/xc_domain.c | 17 ++++++++++++++ tools/libs/light/libxl_create.c | 2 ++ tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 38 +++++++++++++++++++++++++++++++- 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 024bceeb61..96f9249c3d 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -2903,6 +2903,16 @@ Currently, only the "sbsa_uart" model is supported f= or ARM. =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/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e939d07157..064f54c349 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -28,6 +28,20 @@ int xc_domain_create(xc_interface *xch, uint32_t *pdomid, { int err; DECLARE_DOMCTL; + DECLARE_HYPERCALL_BUFFER(uint32_t, llc_colors); + + if ( config->num_llc_colors ) + { + size_t bytes =3D sizeof(uint32_t) * config->num_llc_colors; + + llc_colors =3D xc_hypercall_buffer_alloc(xch, llc_colors, bytes); + if ( llc_colors =3D=3D NULL ) { + PERROR("Could not allocate LLC colors for xc_domain_create"); + return -ENOMEM; + } + memcpy(llc_colors, config->llc_colors.p, bytes); + set_xen_guest_handle(config->llc_colors, llc_colors); + } =20 domctl.cmd =3D XEN_DOMCTL_createdomain; domctl.domain =3D *pdomid; @@ -39,6 +53,9 @@ int xc_domain_create(xc_interface *xch, uint32_t *pdomid, *pdomid =3D (uint16_t)domctl.domain; *config =3D domctl.u.createdomain; =20 + if ( llc_colors ) + xc_hypercall_buffer_free(xch, llc_colors); + return 0; } =20 diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index beec3f6b6f..6d0c768241 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -638,6 +638,8 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, .grant_opts =3D XEN_DOMCTL_GRANT_version(b_info->max_grant_ver= sion), .vmtrace_size =3D ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAG= E_SHIFT), .cpupool_id =3D info->poolid, + .num_llc_colors =3D b_info->num_llc_colors, + .llc_colors.p =3D b_info->llc_colors, }; =20 if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 0cfad8508d..1f944ca6d7 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -562,6 +562,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 853e9f357a..0f8c469fb5 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1297,8 +1297,9 @@ 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; + *mca_caps, *llc_colors; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_= caps; + int num_llc_colors; int pci_power_mgmt =3D 0; int pci_msitranslate =3D 0; int pci_permissive =3D 0; @@ -1447,6 +1448,41 @@ void parse_config_data(const char *config_source, if (!xlu_cfg_get_long (config, "maxmem", &l, 0)) b_info->max_memkb =3D l * 1024; =20 + if (!xlu_cfg_get_list(config, "llc_colors", &llc_colors, &num_llc_colo= rs, 0)) { + int k, 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; + + 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 Wed May 8 10:37:51 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=1674488944; cv=none; d=zohomail.com; s=zohoarc; b=P6xOiqfvDz7kBofS1BOWOFbbfRCkyAgzbYPX5oXfqtM5nkLmmyKN0NmgVk5CZrakaIjPH6UnPS/bKSe647AWTFxxhOw7qgvnHLKsnHL8293925oTA4+5YXUFiDczIlOrVB4AsZoOCom+OnfV3jVlEc61GN4QmDm7mf9Yo1Qe3fE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488944; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GCEtpCCeNNgVpjRAVcM3vcHvhd+PHR5ZkpezvuQcf7U=; b=CqCWmEAchHlga40MP4CC1MMeZ8k1AguAWcfSADkNYQkL/EVvhCeAL+mhHZwObq/pU8+MIAoco+6oOUBfUuw+2X19ted1yRGJIrhQ0xSZ8mJv95DKpSA3rf4fAxVxE9rIQM4pv2+i2EKJG5tB1NQJnBV2X57B2TOW/BG/yV0ZDjw= 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 1674488944385874.8873084250887; Mon, 23 Jan 2023 07:49:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483028.748959 (Exim 4.92) (envelope-from ) id 1pJz3Y-0001fq-35; Mon, 23 Jan 2023 15:48:24 +0000 Received: by outflank-mailman (output) from mailman id 483028.748959; Mon, 23 Jan 2023 15:48:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3X-0001fV-T9; Mon, 23 Jan 2023 15:48:23 +0000 Received: by outflank-mailman (input) for mailman id 483028; Mon, 23 Jan 2023 15:48:23 +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 1pJz3W-0000MU-Sw for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:23 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 577425c4-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:12 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id v30so15061168edb.9 for ; Mon, 23 Jan 2023 07:48:21 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:20 -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: 577425c4-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=GCEtpCCeNNgVpjRAVcM3vcHvhd+PHR5ZkpezvuQcf7U=; b=ZmS5KDRC8hDJKnSaSUtwY94VSRuDHFI5eeajwzfWFv4jUrF4j87Lam0AO4mBGAn362 tEylRS/pTFH81y2AlE0Qi0BsQ9AFSE4VNXzDdDScCCViLukyBDRPudPQElb0U1qDxlbv uFMlrqgE5CPhfvzKIRI36kHiE+O1TPz8keSqsAJG2rH2FAzRSMMfU7THLOUGwdOE5wXv X2v3L8mx9SsYPA3sgrry/Z5LfVfRllWNiWaMn8geQdX7Ep8UBwfmtntMysIdktvzpZVY sIH97GsxSWi8pHRn6HpRs62THQUgOTgqHeqrioAcKxG/UQWb/qc8tN02r8+LxXTNvWoY YxXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=GCEtpCCeNNgVpjRAVcM3vcHvhd+PHR5ZkpezvuQcf7U=; b=wWfDmbdfJmUVCaDZDdi9BqxVRE48NtXakY9Q8ZOa3yYlnvkqamECdCvWF8NJx6LGXp Ob+mKKGTvYjIp5qV+rI7bRuBs/ifplHzL92dSojjMyfJIxNiqMD6rhWHrc1gqCZZK+H/ mD3a5e8ne7+t7PFIj2q7jF7D3nf7TeH/QOUxb9rjrY0sinGal7ItxxysiEaIAXDt5b/m ylkHBKOaGf3PpQCzuhdRw3jwvbaQcPvBsaPsr+LeYppAAwkSLLs7bR1b4ukhx8X0c5bk B4H8l/XVip9PXt9yoGZGhlB8WYV2Phz9EmByxnE28KSLQliGwWqnAa9vAB464MKDAUKG 6C2A== X-Gm-Message-State: AFqh2koslRsgYA7G65X++4zyNcL8bpvGzGkv1Ydo9Sy4E8EJlVPQJTNS vZ5+ZjJgp12kWYcE90uukeya44lJBEsiuveo X-Google-Smtp-Source: AMrXdXut7KoZPfG//rjtYHoVwSt6VSeDkbrs7aPZEjixUEAXRMFdPmXR9l3iIM2NZd+QELm5hPz0wA== X-Received: by 2002:a05:6402:501a:b0:47e:bdb8:9133 with SMTP id p26-20020a056402501a00b0047ebdb89133mr33588255eda.38.1674488900372; Mon, 23 Jan 2023 07:48:20 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v4 06/11] xen/arm: add support for cache coloring configuration via device-tree Date: Mon, 23 Jan 2023 16:47:30 +0100 Message-Id: <20230123154735.74832-7-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488945811100001 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 --- docs/misc/arm/cache-coloring.rst | 43 +++++++++++++++++++++++++ docs/misc/arm/device-tree/booting.txt | 4 +++ xen/arch/arm/domain_build.c | 18 ++++++++++- xen/arch/arm/include/asm/llc_coloring.h | 3 ++ xen/arch/arm/llc_coloring.c | 10 ++++++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index c2e0e87426..a28f75dc26 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -116,6 +116,49 @@ LLC way size (as previously discussed) and Dom0 colors= can be set using the appropriate command line parameters. See the relevant documentation in "docs/misc/xen-command-line.pandoc". =20 +DomUs colors can be set either in the xl configuration file (relative +documentation at "docs/man/xl.cfg.pod.5.in") or via Device Tree, also for +Dom0less configurations (relative documentation in +"docs/misc/arm/device-tree/booting.txt"), as in the following example: + +.. raw:: html + +
+        xen,xen-bootargs =3D "console=3Ddtuart dtuart=3Dserial0 dom0_mem=
=3D1G dom0_max_vcpus=3D1 sched=3Dnull llc-coloring=3Don llc-way-size=3D64K =
xen-llc-colors=3D0-1 dom0-llc-colors=3D2-6";
+        xen,dom0-bootargs "console=3Dhvc0 earlycon=3Dxen earlyprintk=3Dxen=
 root=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. =20 diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-t= ree/booting.txt index 3879340b5e..ad71c16b00 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/domain_build.c b/xen/arch/arm/domain_build.c index 093d4ad6f6..2c1307d349 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -3854,6 +3854,8 @@ 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; + unsigned int *llc_colors =3D NULL, num_llc_colors =3D 0; =20 BUG_ON(chosen =3D=3D NULL); dt_for_each_child_node(chosen, node) @@ -3960,12 +3962,26 @@ void __init create_domUs(void) d_cfg.max_maptrack_frames =3D val; } =20 + if ( !dt_property_read_string(node, "llc-colors", &llc_colors_str)= ) + { + if ( !llc_coloring_enabled ) + printk(XENLOG_WARNING + "'llc-colors' found, but LLC coloring is disabled\n= "); + else if ( dt_find_property(node, "xen,static-mem", NULL) ) + panic("static-mem and LLC coloring are incompatible\n"); + else + llc_colors =3D llc_colors_from_str(llc_colors_str, + &num_llc_colors); + } + /* * The variable max_init_domid is initialized with zero, so here i= t's * very important to use the pre-increment operator to call * domain_create() with a domid > 0. (domid =3D=3D 0 is reserved f= or Dom0) */ - d =3D domain_create(++max_init_domid, &d_cfg, flags); + d =3D domain_create_llc_colored(++max_init_domid, &d_cfg, flags, + llc_colors, num_llc_colors); + if ( IS_ERR(d) ) panic("Error creating domain %s\n", dt_node_name(node)); =20 diff --git a/xen/arch/arm/include/asm/llc_coloring.h b/xen/arch/arm/include= /asm/llc_coloring.h index 382ff7de47..7a01b8841c 100644 --- a/xen/arch/arm/include/asm/llc_coloring.h +++ b/xen/arch/arm/include/asm/llc_coloring.h @@ -18,12 +18,15 @@ bool __init llc_coloring_init(void); =20 unsigned int *dom0_llc_colors(unsigned int *num_colors); +unsigned int *llc_colors_from_str(const char *str, unsigned int *num_color= s); =20 #else /* !CONFIG_LLC_COLORING */ =20 static inline bool __init llc_coloring_init(void) { return true; } static inline unsigned int *dom0_llc_colors( unsigned int *num_colors) { return NULL; } +static inline unsigned int *llc_colors_from_str( + const char *str, unsigned int *num_colors) { return NULL; } =20 #endif /* CONFIG_LLC_COLORING */ =20 diff --git a/xen/arch/arm/llc_coloring.c b/xen/arch/arm/llc_coloring.c index 2d0457cdbc..ba5279a022 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -289,6 +289,16 @@ unsigned int *llc_colors_from_guest(struct xen_domctl_= createdomain *config) return colors; } =20 +unsigned int *llc_colors_from_str(const char *str, unsigned int *num_color= s) +{ + unsigned int *colors =3D alloc_colors(nr_colors); + + if ( parse_color_config(str, colors, num_colors) ) + panic("Error parsing LLC color configuration\n"); + + return colors; +} + /* * Local variables: * mode: C --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488942; cv=none; d=zohomail.com; s=zohoarc; b=mcZ6YxAuByYH8FO5d+AHiJj2Mm3OjUbk80IStYYRiAQGecz77YFFE0y82cdbpPTUPe3MP+uRX7dVJ7k8+n0AC3RubeKqIRlVDw6wn3fc93SmDfl4nS8MeBeRSdDlgJOfu92WzGsw3pwYKpPN071qiOFqi6UoBET5hLyla7NPbZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488942; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=unwT7Y7OWtE54v3kQMluasF3dALE7ek/pArNr4zV0vs=; b=e0EYRUUMrwm01ymcZHR73GR2cwEvFUdwqRuyUQfpXh49jP/86b/q3gHfg/v37EmN6peSjSilIp3Fiv7DhS5G8r83vgy6sVWAbhBS+kO2rggkY6Zd3tA9e50fWtd4X+MNdWLCzRSJgnl5mZvH2z1dbbz7MBfZpPJzy9U38T+z1WA= 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 16744889421351016.6825298380797; Mon, 23 Jan 2023 07:49:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483030.748979 (Exim 4.92) (envelope-from ) id 1pJz3b-0002JA-SP; Mon, 23 Jan 2023 15:48:27 +0000 Received: by outflank-mailman (output) from mailman id 483030.748979; Mon, 23 Jan 2023 15:48:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3b-0002Ih-N5; Mon, 23 Jan 2023 15:48:27 +0000 Received: by outflank-mailman (input) for mailman id 483030; Mon, 23 Jan 2023 15:48:26 +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 1pJz3Z-0000MU-Ob for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:25 +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 587185a9-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:13 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id u19so31603883ejm.8 for ; Mon, 23 Jan 2023 07:48:22 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:21 -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: 587185a9-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=unwT7Y7OWtE54v3kQMluasF3dALE7ek/pArNr4zV0vs=; b=x+Qbc6lFifFuxZQCKmzfNTnCyqgSkVVZQGP9bUpYY0PCMpA4ZcSMPDXyehIT2yz/Lc UPVQQuD3j+nnvWHIxgiwVCGHJCx3vPzedA2q8QDn+KR22P9m3oBoot529sg2TnYd6LIT C5VuP4XbJX4bgzXliwU3hsT0G8VKMC+261Xd79faml3WZn+ZbBp71XdKrHo9qeHPNLlN fAaXTQHyy52cohduEcBK7uCAGgQcz5IhwQulmLD2LAGnRrUcc66XnTtdBTQ0Y5jhKSGU 9yXmsPCQDE6oTfiTbND/6fIgvHRCs7ImIJNURLNhXSKqzxnylGXJowGnImE7jOSoRgCL pcMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=unwT7Y7OWtE54v3kQMluasF3dALE7ek/pArNr4zV0vs=; b=naHuQhY7GPYR2eJQjMflwmVdypqDVRRg7wMMfD3mrjwCwt4XiOqiCcIbbQ66r71o4M riUnI/efqqNE2pfObg3DMI8H53q8MBqqi/DP5OmgJHdLd6LdLkbw3PpjSFi8NzAbFYTd VD7C6rX/BPhgETZ/6Py5aOnBsdeAe0d4QthsK6QiyOmpNGaPFJDeOvGQwuBtPUTiJrWc apc7ClwtNA3TKA/jziu8vMIiWZmNjUgiNg1BkkMBV55FWFEOYZNr1CxxhEK2M2Eg4j0J tpQL6D7HpshABevelMc/GFTOG1s9koaHoTDmkomkB3jplBA/t6deDwVoL+Gk5OMCxMWD lbJQ== X-Gm-Message-State: AFqh2krmWcYAQ2sC/05Srrp5edc7X9C8JnXtUsjLHVWmxfsdB7BplWuE vTUMJ0TBkzkdRTIltkTi5L8MH3hzaawsBYl1 X-Google-Smtp-Source: AMrXdXsxI82Ko73dhXL16y/EF4Cb/Hoz/sbENqdlcq7QbgIMixTIFXzhJsKfrD6J6EVzC9GK6WZXzw== X-Received: by 2002:a17:907:7da0:b0:86d:67b0:6292 with SMTP id oz32-20020a1709077da000b0086d67b06292mr38167762ejc.73.1674488901726; Mon, 23 Jan 2023 07:48:21 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Luca Miccio , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , Marco Solieri , Carlo Nonato Subject: [PATCH v4 07/11] xen: add cache coloring allocator for domains Date: Mon, 23 Jan 2023 16:47:31 +0100 Message-Id: <20230123154735.74832-8-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488943590100018 Content-Type: text/plain; charset="utf-8" From: Luca Miccio This commit adds a new memory page allocator that implements the cache coloring mechanism. The allocation algorithm follows the given domain color configuration and maximizes contiguity in the page selection of multiple subsequent requests. Pages are stored in a color-indexed array of lists, each one sorted by machine address, that is referred to as "colored heap". Those lists are filled by a simple init function which computes the color of each page. When a domain requests a page, the allocator takes one from those lists whose colors equals the domain configuration. It chooses the page with the lowest machine address such that contiguous pages are sequentially allocated if this is made possible by a color assignment which includes adjacent colors. The allocator can handle only requests with order equal to 0 since the single color granularity is represented in memory by one page. 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. Signed-off-by: Luca Miccio Signed-off-by: Marco Solieri Signed-off-by: Carlo Nonato --- 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 | 49 ++++++ docs/misc/xen-command-line.pandoc | 14 ++ xen/arch/Kconfig | 12 ++ xen/arch/arm/include/asm/mm.h | 3 + xen/arch/arm/llc_coloring.c | 12 ++ xen/common/page_alloc.c | 247 +++++++++++++++++++++++++++--- xen/include/xen/llc_coloring.h | 5 + xen/include/xen/mm.h | 33 ++++ 8 files changed, 355 insertions(+), 20 deletions(-) diff --git a/docs/misc/arm/cache-coloring.rst b/docs/misc/arm/cache-colorin= g.rst index a28f75dc26..d56dafe815 100644 --- a/docs/misc/arm/cache-coloring.rst +++ b/docs/misc/arm/cache-coloring.rst @@ -15,10 +15,16 @@ In Kconfig: value meaning and when it should be changed). =20 CONFIG_NR_LLC_COLORS=3D +- If needed, change the amount of memory reserved for the buddy allocator + (see `Colored allocator and buddy allocator`_). + + CONFIG_BUDDY_ALLOCATOR_SIZE=3D =20 Compile Xen and the toolstack and then: =20 - Set the `llc-coloring=3Don` command line option. +- If needed, set the amount of memory reserved for the buddy allocator + via the appropriate command line option. - Set `Coloring parameters and domain configurations`_. =20 Background @@ -162,6 +168,18 @@ Dom0less configurations (relative documentation in **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. +The buddy allocator memory can be reserved from the Xen Kconfig or with the +help of a command-line option. + Known issues and limitations **************************** =20 @@ -172,3 +190,34 @@ 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. + +Fail to boot colored DomUs with large memory size +################################################# + +If the Linux kernel used for Dom0 does not contain the upstream commit +3941552aec1e04d63999988a057ae09a1c56ebeb and uses the hypercall buffer dev= ice, +colored DomUs with memory size larger then 127 MB cannot be created. This = is +caused by the default limit of this buffer of 64 pages. The solution is to +manually apply the above patch, or to check if there is an updated version= of +the kernel in use for Dom0 that contains this change. diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index eb105c03af..a89c0cef61 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -299,6 +299,20 @@ can be maintained with the pv-shim mechanism. cause Xen not to use Indirect Branch Tracking even when support is available in hardware. =20 +### buddy-alloc-size (arm64) +> `=3D ` + +> Default: `64M` + +Amount of memory reserved for the buddy allocator when colored allocator is +active. This options is available only when `CONFIG_LLC_COLORING` is enabl= ed. +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 systems is not colored yet, we need to +support the coexistence of the two allocators for now. This parameter, whi= ch is +optional and for expert only, it's used to set the amount of memory reserv= ed to +the buddy allocator. + ### clocksource (x86) > `=3D pit | hpet | acpi | tsc` =20 diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index 39c23f2528..4378b5f338 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -45,3 +45,15 @@ config NR_LLC_COLORS more than what needed in the general case. Note that if, at any time, a color configuration with more colors than the maximum is employed, an error is produced. + +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 ye= t, + 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 bff6923f3e..596293f792 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -128,6 +128,9 @@ struct page_info #else #define PGC_static 0 #endif +/* Page is cache colored */ +#define _PGC_colored PG_shift(4) +#define PGC_colored PG_mask(1, 4) /* ... */ /* 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 ba5279a022..22612d455b 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -33,6 +33,8 @@ static paddr_t __ro_after_init addr_col_mask; static unsigned int __ro_after_init dom0_colors[CONFIG_NR_LLC_COLORS]; static unsigned int __ro_after_init dom0_num_colors; =20 +#define addr_to_color(addr) (((addr) & addr_col_mask) >> PAGE_SHIFT) + /* * Parse the coloring configuration given in the buf string, following the * syntax below. @@ -299,6 +301,16 @@ unsigned int *llc_colors_from_str(const char *str, uns= igned int *num_colors) return colors; } =20 +unsigned int page_to_llc_color(const struct page_info *pg) +{ + return addr_to_color(page_to_maddr(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 e40473f71e..59bd6bcdac 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,6 +159,10 @@ #define PGC_static 0 #endif =20 +#ifndef PGC_colored +#define PGC_colored 0 +#endif + #ifndef PGT_TYPE_INFO_INITIALIZER #define PGT_TYPE_INFO_INITIALIZER 0 #endif @@ -924,6 +929,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, @@ -1032,10 +1044,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); @@ -1488,7 +1497,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 & (PGC_static | PGC_colored)) || (PFN_ORDER(predecessor) !=3D order) || (page_to_nid(predecessor) !=3D node) ) break; @@ -1512,7 +1521,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 & (PGC_static | PGC_colored)) || (PFN_ORDER(successor) !=3D order) || (page_to_nid(successor) !=3D node) ) break; @@ -1928,6 +1937,182 @@ static unsigned long avail_heap_pages( return free_pages; } =20 +#ifdef CONFIG_LLC_COLORING +/************************* + * 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. + */ +typedef struct page_list_head colored_pages_t; +static colored_pages_t *__ro_after_init _color_heap; +static unsigned long *__ro_after_init free_colored_pages; + +/* Memory required for buddy allocator to work with colored one */ +static unsigned long __initdata buddy_alloc_size =3D + CONFIG_BUDDY_ALLOCATOR_SIZE << 20; + +#define color_heap(color) (&_color_heap[color]) + +static bool is_free_colored_page(struct page_info *page) +{ + return page && (page->count_info & PGC_state_free) && + (page->count_info & PGC_colored); +} + +/* + * The {free|alloc}_color_heap_page overwrite pg->count_info, but they do = it in + * the same way as the buddy allocator corresponding functions do: + * protecting the access with a critical section using heap_lock. + */ +static void free_color_heap_page(struct page_info *pg) +{ + unsigned int color =3D page_to_llc_color(pg), nr_colors =3D get_nr_llc= _colors(); + unsigned long pdx =3D page_to_pdx(pg); + colored_pages_t *head =3D color_heap(color); + struct page_info *prev =3D pdx >=3D nr_colors ? pg - nr_colors : NULL; + struct page_info *next =3D pdx + nr_colors < FRAMETABLE_NR ? pg + nr_c= olors + : NULL; + + spin_lock(&heap_lock); + + if ( is_free_colored_page(prev) ) + next =3D page_list_next(prev, head); + else if ( !is_free_colored_page(next) ) + { + /* + * FIXME: linear search is slow, but also note that the frametable= is + * used to find free pages in the immediate neighborhood of pg in + * constant time. When freeing contiguous pages, the insert positi= on of + * most of them is found without the linear search. + */ + page_list_for_each( next, head ) + { + if ( page_to_maddr(next) > page_to_maddr(pg) ) + break; + } + } + + mark_page_free(pg, page_to_mfn(pg)); + pg->count_info |=3D PGC_colored; + free_colored_pages[color]++; + page_list_add_prev(pg, next, head); + + spin_unlock(&heap_lock); +} + +static struct page_info *alloc_color_heap_page(unsigned int memflags, + struct domain *d) +{ + struct page_info *pg =3D NULL; + unsigned int i, color; + bool need_tlbflush =3D false; + uint32_t tlbflush_timestamp =3D 0; + + spin_lock(&heap_lock); + + for ( i =3D 0; i < d->num_llc_colors; i++ ) + { + struct page_info *tmp; + + if ( page_list_empty(color_heap(d->llc_colors[i])) ) + continue; + + tmp =3D page_list_first(color_heap(d->llc_colors[i])); + if ( !pg || page_to_maddr(tmp) < page_to_maddr(pg) ) + { + pg =3D tmp; + color =3D d->llc_colors[i]; + } + } + + if ( !pg ) + { + spin_unlock(&heap_lock); + return NULL; + } + + pg->count_info =3D PGC_state_inuse | PGC_colored; + free_colored_pages[color]--; + page_list_del(pg, color_heap(color)); + + if ( !(memflags & MEMF_no_tlbflush) ) + accumulate_tlbflush(&need_tlbflush, pg, &tlbflush_timestamp); + + init_free_page_fields(pg); + + spin_unlock(&heap_lock); + + if ( need_tlbflush ) + filtered_flush_tlb_mask(tlbflush_timestamp); + + flush_page_to_ram(mfn_x(page_to_mfn(pg)), + !(memflags & MEMF_no_icache_flush)); + + return pg; +} + +static void __init init_color_heap_pages(struct page_info *pg, + unsigned long nr_pages) +{ + unsigned int i; + + 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(colored_pages_t, nr_colors); + BUG_ON(!_color_heap); + free_colored_pages =3D xzalloc_array(unsigned long, nr_colors); + BUG_ON(!free_colored_pages); + + for ( i =3D 0; i < nr_colors; i++ ) + INIT_PAGE_LIST_HEAD(color_heap(i)); + } + + 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]); +} + +static void dump_color_heap(void) +{ + unsigned int color; + + printk("Dumping color heap info\n"); + for ( color =3D 0; color < get_nr_llc_colors(); color++ ) + printk("Color heap[%u]: %lu pages\n", color, free_colored_pages[co= lor]); +} + +#else /* !CONFIG_LLC_COLORING */ + +static void free_color_heap_page(struct page_info *pg) {} +static void __init init_color_heap_pages(struct page_info *pg, + unsigned long nr_pages) {} +static struct page_info *alloc_color_heap_page(unsigned int memflags, + struct domain *d) +{ + return NULL; +} +static void dump_color_heap(void) {} + +#endif /* CONFIG_LLC_COLORING */ + void __init end_boot_allocator(void) { unsigned int i; @@ -1936,12 +2121,19 @@ void __init end_boot_allocator(void) for ( i =3D 0; i < nr_bootmem_regions; i++ ) { struct bootmem_region *r =3D &bootmem_region_list[i]; - if ( (r->s < r->e) && - (mfn_to_nid(_mfn(r->s)) =3D=3D cpu_to_node(0)) ) + if ( r->s < r->e ) { - init_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s); - r->e =3D r->s; - break; + if ( llc_coloring_enabled ) + { + init_color_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s= ); + r->e =3D r->s; + } + else if ( mfn_to_nid(_mfn(r->s)) =3D=3D cpu_to_node(0) ) + { + init_heap_pages(mfn_to_page(_mfn(r->s)), r->e - r->s); + r->e =3D r->s; + break; + } } } for ( i =3D nr_bootmem_regions; i-- > 0; ) @@ -2332,6 +2524,7 @@ int assign_pages( { int rc =3D 0; unsigned int i; + unsigned long allowed_flags =3D (PGC_extra | PGC_static | PGC_colored); =20 spin_lock(&d->page_alloc_lock); =20 @@ -2349,7 +2542,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 & ~allowed_flags)); if ( pg[i].count_info & PGC_extra ) extra_pages++; } @@ -2408,8 +2601,8 @@ int assign_pages( ASSERT(page_get_owner(&pg[i]) =3D=3D NULL); 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 =3D (pg[i].count_info & allowed_flags) | + PGC_allocated | 1; =20 page_list_add_tail(&pg[i], page_to_list(d, &pg[i])); } @@ -2443,7 +2636,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); @@ -2468,7 +2668,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); + else + free_heap_pages(pg, order, memflags & MEMF_no_scrub); return NULL; } } @@ -2551,7 +2754,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); + else + free_heap_pages(pg, order, scrub); } =20 if ( drop_dom_ref ) @@ -2658,6 +2864,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) @@ -2790,9 +2999,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); diff --git a/xen/include/xen/llc_coloring.h b/xen/include/xen/llc_coloring.h index 2855f38296..2e9abf3b3a 100644 --- a/xen/include/xen/llc_coloring.h +++ b/xen/include/xen/llc_coloring.h @@ -17,6 +17,8 @@ =20 #include =20 +struct page_info; + extern bool llc_coloring_enabled; =20 int domain_llc_coloring_init(struct domain *d, unsigned int *colors, @@ -26,6 +28,9 @@ void domain_dump_llc_colors(struct domain *d); =20 unsigned int *llc_colors_from_guest(struct xen_domctl_createdomain *config= ); =20 +unsigned int page_to_llc_color(const struct page_info *pg); +unsigned int get_nr_llc_colors(void); + #else =20 #define llc_coloring_enabled (false) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 9d14aed74b..8ea72c744e 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -299,6 +299,33 @@ page_list_add_tail(struct page_info *page, struct page= _list_head *head) } head->tail =3D page; } +static inline void +_page_list_add(struct page_info *page, struct page_info *prev, + struct page_info *next) +{ + page->list.prev =3D page_to_pdx(prev); + page->list.next =3D page_to_pdx(next); + prev->list.next =3D page_to_pdx(page); + next->list.prev =3D page_to_pdx(page); +} +static inline void +page_list_add_prev(struct page_info *page, struct page_info *next, + struct page_list_head *head) +{ + struct page_info *prev; + + if ( !next ) + { + page_list_add_tail(page, head); + return; + } + + prev =3D page_list_prev(next, head); + if ( !prev ) + page_list_add(page, head); + else + _page_list_add(page, prev, next); +} static inline bool_t __page_list_del_head(struct page_info *page, struct page_list_head *head, struct page_info *next, struct page_info *prev) @@ -451,6 +478,12 @@ page_list_add_tail(struct page_info *page, struct page= _list_head *head) list_add_tail(&page->list, head); } static inline void +page_list_add_prev(struct page_info *page, struct page_info *next, + struct page_list_head *head) +{ + list_add_tail(&page->list, &next->list); +} +static inline void page_list_del(struct page_info *page, struct page_list_head *head) { list_del(&page->list); --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488939; cv=none; d=zohomail.com; s=zohoarc; b=MTzszv6fRp0TWf86klYCT7LxsWxvgB6tjdD5k+xboWOnUh/rdsHVKJfmXRxqwFt9+KCb9r12ML7Xhg3MdMceNfMIM2RFY/U9nQk019c/igktUJtG0dEmsr0nPZRqHUp+ZwczbWui6u2lwH63Cy2k5FzlKvpbBCweOC/POd5Q5lg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488939; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0a2gbQNKwUWS/d4kzoidztA9Ce3spqkJtPMisplTAE0=; b=mVuAfcr7wrkixkZ+aQlfGB9a8ys+5dIBOAYGjaX0CNuhq50S+SXzteOA+U5kcxInMX+5utg5NTLXe0QZgdLq8IYJOwOelbw3chmfFKPya7Lf9/Ctp2Rf6Jx1KmE6ce+F7/imkLO4oIaCB9As1PtsLwImO4SkxKJgvBecSG1m5bI= 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 1674488938924843.0901951340383; Mon, 23 Jan 2023 07:48:58 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483029.748968 (Exim 4.92) (envelope-from ) id 1pJz3a-00021S-B2; Mon, 23 Jan 2023 15:48:26 +0000 Received: by outflank-mailman (output) from mailman id 483029.748968; Mon, 23 Jan 2023 15:48:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3a-00021I-7R; Mon, 23 Jan 2023 15:48:26 +0000 Received: by outflank-mailman (input) for mailman id 483029; Mon, 23 Jan 2023 15:48:25 +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 1pJz3Z-0000MU-4j for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:25 +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 58f113cd-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:14 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id bk15so31563831ejb.9 for ; Mon, 23 Jan 2023 07:48:23 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:22 -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: 58f113cd-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=0a2gbQNKwUWS/d4kzoidztA9Ce3spqkJtPMisplTAE0=; b=ng7prlLTd1cYH/dTXfkdmn4gkmQlV/868ZF4otjJNBPRm3fFBORoHT1RSyPy74qFS2 IT5XZDYlUuDbODtrCs5RyEFQR59k8Zn/ZZ9Q52okjlpqGbKO2Fe76mu0RPbJsJmXwVRo W492ws8E19D/TaAeynVqDdwLd3UKd/gDFGZzVoYDLWFtFyF+j7zbQcNRp+yP6XWkbR0l ELmMKAfdFC2y/NOw7JNjyWINTFw0nINpN8zW/W4KkbtKJ6IjLeBRJ2VYuQHqEY6ri+ei p9M50WfgxYHT6Hiahy2qhDgVnL0ofdhY7gUrnnWLcF7KkftIJf58zPOsfgw6tRq+ViOr 3uHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=0a2gbQNKwUWS/d4kzoidztA9Ce3spqkJtPMisplTAE0=; b=WTnGzDIGYawTiQY0n26BRfPlL5UtZ12+IIc4r74pJKmslnX2jPzPTxOXqfIGtdmbrc tF6Wh23HxmnCwAOd/z5Vkukwlrq6tRDGy1hYcKODVC9nekdIr51qSPlAgyrZe8M2M2N5 L7d8KP6Du/b9+c/4Nays0484vnaQrDxf2Xc12Os2djk1IBehbdlWKkdJO+kaP3u4Sl2X BtYp+pHKwS777KjNIzEFu98WWzPMHyd4HnvCu6SeDQDA0S5QM+5L8aD6AU/3wAjnoeYn dZDymlgEg1nvsr1Bbgv1taHvXscfiRu8tBJuM3dmd2lp+yi7qflB9Fopvu+9Jv2HEsrx 5Tbg== X-Gm-Message-State: AFqh2kr7oJQVUarya8iiNjK2sPQolnvZete0NDbrVBBVUKCTsAnvR0VI oxJUERJzo6PrT6dIBcqvjqtOqKukk/wArNLz X-Google-Smtp-Source: AMrXdXsUAXRa82fcSelfp1n7YAbygkKkkD3DjYj1duZB5/jYaAvQ4PBJQUzuH8foqelDXFscp14mfw== X-Received: by 2002:a17:907:cbc5:b0:7ad:9455:d57d with SMTP id vk5-20020a170907cbc500b007ad9455d57dmr28301982ejc.74.1674488902800; Mon, 23 Jan 2023 07:48:22 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v4 08/11] xen/arm: use colored allocator for p2m page tables Date: Mon, 23 Jan 2023 16:47:32 +0100 Message-Id: <20230123154735.74832-9-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488939659100001 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. Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- v4: - fixed p2m page allocation using MEMF_no_owner memflag --- xen/arch/arm/p2m.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 948f199d84..f9faeb61af 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include =20 @@ -56,7 +57,10 @@ static struct page_info *p2m_alloc_page(struct domain *d) */ if ( is_hardware_domain(d) ) { - pg =3D alloc_domheap_page(NULL, 0); + if ( is_domain_llc_colored(d) ) + pg =3D alloc_domheap_page(d, MEMF_no_owner); + else + pg =3D alloc_domheap_page(NULL, 0); if ( pg =3D=3D NULL ) printk(XENLOG_G_ERR "Failed to allocate P2M pages for hwdom.\n= "); } @@ -105,7 +109,10 @@ int p2m_set_allocation(struct domain *d, unsigned long= pages, bool *preempted) if ( d->arch.paging.p2m_total_pages < pages ) { /* Need to allocate more memory from domheap */ - pg =3D alloc_domheap_page(NULL, 0); + if ( is_domain_llc_colored(d) ) + pg =3D alloc_domheap_page(d, MEMF_no_owner); + else + pg =3D alloc_domheap_page(NULL, 0); if ( pg =3D=3D NULL ) { printk(XENLOG_ERR "Failed to allocate P2M pages.\n"); --=20 2.34.1 From nobody Wed May 8 10:37:51 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=1674488933; cv=none; d=zohomail.com; s=zohoarc; b=P7w5wJZdfYP1DsK6D4WE9jDIbl7cj6kpOrnXm0UZrXpeLHMMRf0HCEb9k1j4vczmv/aW4bOBGdCcKQkVijwTT+QmeEmDqgDVx8i4a+/nV/6+yeSDKLf5X0Y6yZQ3/OfvTL1p2Eh8y8GInK7mz5JJURIBLyYYpHoXab88s53eXCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488933; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GXjHJG37wrPSsNQkI70mLlT9j7sfcQhay1lHTQfBpqE=; b=Eyg4EncrfJMbnGNZv7JFGk9Qrm4Vy1CkQlxUQw6h0LJPHS17UEPxooyxzJm6Y/qe5E53UPSc5bRyggKizxtfiIfxzujP49yFr2mjFYj02WblyLs0krYv4y0t65Uc8DH6rk8wa1HrUgI/v95x1Fd8IgKuCLeq8uR37Q0yV8FKC9I= 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 1674488933622424.6075596112678; Mon, 23 Jan 2023 07:48:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483031.748984 (Exim 4.92) (envelope-from ) id 1pJz3c-0002NM-9h; Mon, 23 Jan 2023 15:48:28 +0000 Received: by outflank-mailman (output) from mailman id 483031.748984; Mon, 23 Jan 2023 15:48:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3c-0002MX-0I; Mon, 23 Jan 2023 15:48:28 +0000 Received: by outflank-mailman (input) for mailman id 483031; Mon, 23 Jan 2023 15:48:26 +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 1pJz3a-0000MU-CW for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:26 +0000 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [2a00:1450:4864:20::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 59943607-9b35-11ed-b8d1-410ff93cb8f0; Mon, 23 Jan 2023 16:48:15 +0100 (CET) Received: by mail-ej1-x62b.google.com with SMTP id ud5so31668821ejc.4 for ; Mon, 23 Jan 2023 07:48:24 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:23 -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: 59943607-9b35-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=GXjHJG37wrPSsNQkI70mLlT9j7sfcQhay1lHTQfBpqE=; b=aOmXpVDTwkO8k0CqcxAZ3eZ1tYYpqm6pCnougkWeY4CsGgbelNyDO0RRGHptwTZVtC cctHSUIq0dgNyfkcqlB9urbilwiY7VvKByqF54wJ7lVWdOlXh3OI/k30YzwQoKtP/DOg X5zFTQQStGMNu0q5vyol2FBFYiCKprE4RLZVsevYHYz3upjY7L9Gu7VTdheaUkIFzzU/ oTl84wAK7FVX31qaBvaob/Zc+1hKoIrWJz7eAbU/081A+Lmm0MrkqqyyHXMcBGxdYxC4 SxquQZtmbckIYn8UYSpmFCN/XSj21MijZwteeVOldD/GlBqoacDgTFYlyM8IGyrFe7Kz OQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=GXjHJG37wrPSsNQkI70mLlT9j7sfcQhay1lHTQfBpqE=; b=zo4WeqaXSGZYSwdBHuN5zijVl1UCC7PYbpAWAmef+3++c0a6GNtlfrVSYTqas1D9TX 9sQV5RPno9t19oiFZDRNvOYtw/KwYPJcT8f/zpRLZahOGoZfBrzpTMufAt5C7zGM9ucJ 3Wx2e3BDUigrTUD1y2rcUiV3uu6RgrSelzKMrQGNLSbyeyTXz8CH79S+zad7NMWBWkDb lBuuadhi5bQonI0HwDOAAhaBMEm4ao9dkrWOvNRhdiTIWrs3KUum5qjCaNDXYwTR5xiS HMY5voutBVngOm6N0oqaylolAUUXdPKD84sFTXeZwymIn2Ok9Y9E2luHxe2VFcgRzKwp 3MbQ== X-Gm-Message-State: AFqh2kqy95Ayvtqvae4t57noLdKonG9sMMIf4Bpfvh6S634+y37pJqmj 8iLJvpWOsmWXK3V65W7Oa05wENjKNzhA8SKA X-Google-Smtp-Source: AMrXdXtZW+SmY+t9CiCJtVGB6Ye1/RFitDnHCtldOZ8D0at+eHlzhbIJDeiQ1+pJ78QI+Z+WxyveiQ== X-Received: by 2002:a17:906:f9cd:b0:7c0:b569:8efe with SMTP id lj13-20020a170906f9cd00b007c0b5698efemr25695642ejb.60.1674488903979; Mon, 23 Jan 2023 07:48:23 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v4 09/11] Revert "xen/arm: Remove unused BOOT_RELOC_VIRT_START" Date: Mon, 23 Jan 2023 16:47:33 +0100 Message-Id: <20230123154735.74832-10-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488936198100001 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/config.h | 4 +++- xen/arch/arm/mm.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/c= onfig.h index c5d407a749..5359acd529 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -96,7 +96,8 @@ * 2M - 4M Xen text, data, bss * 4M - 6M Fixmap: special-purpose 4K mapping slots * 6M - 10M Early boot mapping of FDT - * 10M - 12M Livepatch vmap (if compiled in) + * 10M - 12M Early relocation address (used when relocating Xen) + * and later for livepatch vmap (if compiled in) * * 1G - 2G VMAP: ioremap and early_ioremap * @@ -133,6 +134,7 @@ #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/mm.c b/xen/arch/arm/mm.c index b9c698088b..7015a0f841 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -145,6 +145,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 Wed May 8 10:37:51 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=1674488940; cv=none; d=zohomail.com; s=zohoarc; b=WR9sMq04v14TVVsjrmCgcEL7vwKEQeTq5UH+16/I/ZK7ubr8iIjm4xyRc/89/lX6leGHk30HFAT7hzP0BfWVFFbxs3DrbOwYsHM3CUunq0Jh3z3hxEYbx6wIJOHfumC3SmDXwk+6sF48H+7qtaZgkIX2HCsdHnh5048q7l8Fzjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488940; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ptsteZfIhpfF2UQfbP6Zi8kakL6wMfzWUQYlwBmp7AM=; b=SONpQAC7TWmXLwMyyYeM8AbZtFDoL2rlrzpNcam5Mnhw9sAjALnkoZj9OQ7/l6DQMt1tPzlR2WtKobBCbY4Cy7tFkHA9FCNf9NFUX8mG7Jr46dTPS37gdHEIJlzqPO8NpSg+1QhPLbechxptP9w/EBsDyuNYYqYHN96OKwIobb0= 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 1674488940480348.63224187910896; Mon, 23 Jan 2023 07:49:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483032.748997 (Exim 4.92) (envelope-from ) id 1pJz3d-0002oW-TU; Mon, 23 Jan 2023 15:48:29 +0000 Received: by outflank-mailman (output) from mailman id 483032.748997; Mon, 23 Jan 2023 15:48:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3d-0002mz-Lp; Mon, 23 Jan 2023 15:48:29 +0000 Received: by outflank-mailman (input) for mailman id 483032; Mon, 23 Jan 2023 15:48:28 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3c-00006V-3K for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:28 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6078c854-9b35-11ed-91b6-6bf2151ebd3b; Mon, 23 Jan 2023 16:48:27 +0100 (CET) Received: by mail-ej1-x631.google.com with SMTP id vw16so31591843ejc.12 for ; Mon, 23 Jan 2023 07:48:27 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:26 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6078c854-9b35-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=ptsteZfIhpfF2UQfbP6Zi8kakL6wMfzWUQYlwBmp7AM=; b=2DpkluxTwEf/rRNWROpMgUV2g5OJe6zodA3z8G79y/tFiEa/xuzYvvNsjq/cJp25DW ch2upGGp+OeeGZEH6uBjtwDVFTSlDD8ATwiiqu5BC06x7KMJiD/PaAIMqCoaXEumAZ+K +woTazI9Bikae17grp8UM2v2O6EqVxuhcxIymq04xG0UN8WDtJiUYAFHecber9pBv+ws 75JLet58stpmZ34/+wVep9dcDpkOD73930kMyI/ET80Bf/OW60CznHxRlYnimonmum2A ZCmPHqZ/hUQSvmpcWT19bI3V0n9vRSwJOOGDFQHA7N4aO9FIwsdHVKgUjcYYaYRJJGJv 8UJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ptsteZfIhpfF2UQfbP6Zi8kakL6wMfzWUQYlwBmp7AM=; b=xPtW4JrAjcThHGahy3YpOb7auqnFAYLGy4p2HHe3xH4hBGfpLWV9FuazxggQZRjxtr rCYPnCozuDtNwjEhpFyJt6JDdRLX3dqYq16/U6rgjQVtQj4Ry6ikq2ApqmzD0ZgjzSlI O0ecd2hIMS5D6VEKd1cQjSfcSphs3Dky1g8siAKTqzoNCX0Mp+IdhcoiIaT31snFSWqs JSnwTSxdRrTTKzPH2z+8WFOwcxeqLlSvpgHf4FFPnGLKw71V3dpAhpfD/DUP5MIT5TPp 0TOjsNsGcHfD6Nm7neIwbGwujvDBvjSKtYA8cu0RFfdtVnLcGjyKSYJ2U57ZojMDM4MV SPyg== X-Gm-Message-State: AFqh2krpmuO6DKKEMw+Fs/7bB8rZTLb5whqH59wkIIrFoyqr7+h/Nmqd vRQfX274/VWOg6vnRevaxNbxw6g036932PV0 X-Google-Smtp-Source: AMrXdXufOtlIu4zh2FVI6Bx7clwNuhDAjNxjB+9zPKqe3JEQrOrwigNGOjnHHO0yrWiiAXQBqeVl5A== X-Received: by 2002:a17:906:a09:b0:7c1:4a3a:dc97 with SMTP id w9-20020a1709060a0900b007c14a3adc97mr32277336ejf.0.1674488906739; Mon, 23 Jan 2023 07:48:26 -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 , Volodymyr Babchuk , Marco Solieri , Carlo Nonato Subject: [PATCH v4 10/11] xen/arm: add Xen cache colors command line parameter Date: Mon, 23 Jan 2023 16:47:34 +0100 Message-Id: <20230123154735.74832-11-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488941694100013 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 | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index a89c0cef61..d486946648 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2796,6 +2796,16 @@ In the case that x2apic is in use, this option switc= hes between physical and clustered mode. The default, given no hint from the **FADT**, is cluster mode. =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 22612d455b..745e93a61a 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -19,6 +19,10 @@ #include #include =20 +/* By default Xen uses the lowest color */ +#define XEN_DEFAULT_COLOR 0 +#define XEN_DEFAULT_NUM_COLORS 1 + bool llc_coloring_enabled; boolean_param("llc-coloring", llc_coloring_enabled); =20 @@ -33,6 +37,9 @@ static paddr_t __ro_after_init addr_col_mask; 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 addr_to_color(addr) (((addr) & addr_col_mask) >> PAGE_SHIFT) =20 /* @@ -83,6 +90,12 @@ static int parse_color_config(const char *buf, unsigned = int *colors, return *s ? -EINVAL : 0; } =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); + static int __init parse_dom0_colors(const char *s) { return parse_color_config(s, dom0_colors, &dom0_num_colors); @@ -166,6 +179,8 @@ static void dump_coloring_info(unsigned char key) printk("LLC way size: %u KiB\n", llc_way_size >> 10); printk("Number of LLC colors supported: %u\n", nr_colors); printk("Address to LLC color mask: 0x%lx\n", addr_col_mask); + printk("Xen LLC colors: "); + print_colors(xen_colors, xen_num_colors); } =20 bool __init llc_coloring_init(void) @@ -202,6 +217,21 @@ bool __init llc_coloring_init(void) =20 addr_col_mask =3D (nr_colors - 1) << PAGE_SHIFT; =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 Wed May 8 10:37:51 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=1674488941; cv=none; d=zohomail.com; s=zohoarc; b=e8qHwsUkVSjeYn2hwVM/xXWtwhpQJCCa/39PWQWYSqDJn6V0IfqqdKx5WYGp+S58MrLiOoAOjyQTdQW1bvLbmg85fMFrln5dBlmOYKJk93B59Wt+SAf20GfMSQIlB3M/ZfwjUcAQk0YxosgRsBEORyqWk/ZONK8m0uY/cLZp6Hw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674488941; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=csEQnyAGj75A2oDuFHesK9E3htjoPKUhnq2Q9BYRkA0=; b=K+CYSK3ouPRKPMZHEe2ry5YrdLPAEXoyAioA9yKYzNJY5wVaCsWDNAfFM57ryY5o5fzl1GYej5H68KolLd6FZoLZ7zL6oIACV7Fq4mbHQpbYEEpP/A6TrOKKixXhBKD/96xxGh6ByWko2+WOi5XiaDdcc13tddowvx2eiuXBq2A= 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 1674488941514168.08390233870944; Mon, 23 Jan 2023 07:49:01 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.483036.749009 (Exim 4.92) (envelope-from ) id 1pJz3l-0003wT-Em; Mon, 23 Jan 2023 15:48:37 +0000 Received: by outflank-mailman (output) from mailman id 483036.749009; Mon, 23 Jan 2023 15:48:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pJz3l-0003vV-Ae; Mon, 23 Jan 2023 15:48:37 +0000 Received: by outflank-mailman (input) for mailman id 483036; Mon, 23 Jan 2023 15:48:36 +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 1pJz3k-00006V-87 for xen-devel@lists.xenproject.org; Mon, 23 Jan 2023 15:48:36 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 64f195a5-9b35-11ed-91b6-6bf2151ebd3b; Mon, 23 Jan 2023 16:48:34 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id kt14so31674250ejc.3 for ; Mon, 23 Jan 2023 07:48:34 -0800 (PST) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id r2-20020a17090609c200b007bd28b50305sm22170978eje.200.2023.01.23.07.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:48:33 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 64f195a5-9b35-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20210112.gappssmtp.com; s=20210112; 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=csEQnyAGj75A2oDuFHesK9E3htjoPKUhnq2Q9BYRkA0=; b=sgILsUw1EMkAtx7wBGa1Tl9hBegYY+LO9VzkIUBr+UB7yaEkl3haTW5TSbUJSf1jun iRKf8Due67bJ6kh6yxTABd0rsLAFEATnrC1CMbM2i2JmCOCJ7qjXSQtH2P4fyrm1vRCO QGIeWtecAeekCocjFMj59pwwH+fP6IJtAQhNRzm1rTZlDcOV/17sQSP/SFB+E6TzHOCO U41D01LwXE9Kn3OU47lVYDJKyyFamS+gqaYfhOw5TKWY2GV3NqCGF7gUuRVOFWRuxvF4 bqdJQ5NTG8Mj1VBpXwxjt6ajeRI/GJjrFMCyKh/LnvGJZQ7eu4yoiG1jFKWkDFHmRqGu YMYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=csEQnyAGj75A2oDuFHesK9E3htjoPKUhnq2Q9BYRkA0=; b=iaWO7jOISFDVTPcRDTfBYxLxbyVLifrSj2mQd4Hll4y6CVBwpsKfWt2Oyvq2jTT5xV Mk3f1SjY+KH+Cp4vjDb5hjdQCFo4kEXwGqfdPo21m7YVRsBXXRvHVCSprQ/Y9VY4RgSi rpuGZ3NwK4XkBCQENKmBgbn98FaWQ74XRMuf7/n2kBlRUd+S4523T/QjBxFhmsUQdlFR ifjsSSMNSK1XU41P4mVMh7MiI8OJR/D6ud3XH+FRAv1eQ4dKwX7MQZqU85zNRMmhRaKK bph85sYJ9fWoaJbhqyFi1EDWEQHUwnhyJj6hECbv2gq9pLR+n53iNmwYUbQJ/enknTDL Mmgw== X-Gm-Message-State: AFqh2kpzC6AiArMnOS52YvvEjgcC/cdxi4tWdFC1Gk+lmfoxW3XKCrzH Fb++KTJMOOTfSwrv5xaqQP0rXcmWywNPW56F X-Google-Smtp-Source: AMrXdXujSAA0u5pxrtehEsoIhORfGahWR5LG/sCKGkAm+svGBrRkdtgXEcP7Dqb8VWdJ8caE/HHmEw== X-Received: by 2002:a17:907:d68c:b0:812:d53e:1222 with SMTP id wf12-20020a170907d68c00b00812d53e1222mr27709223ejc.31.1674488913975; Mon, 23 Jan 2023 07:48:33 -0800 (PST) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Marco Solieri Subject: [PATCH v4 11/11] xen/arm: add cache coloring support for Xen Date: Mon, 23 Jan 2023 16:47:35 +0100 Message-Id: <20230123154735.74832-12-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123154735.74832-1-carlo.nonato@minervasys.tech> References: <20230123154735.74832-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @minervasys-tech.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674488943585100017 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 (init_secondary_pagetables()). 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. Based on original work from: Luca Miccio Signed-off-by: Carlo Nonato Signed-off-by: Marco Solieri --- 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/head.S | 50 +++++++++++++ xen/arch/arm/arm64/mm.c | 26 +++++-- xen/arch/arm/include/asm/llc_coloring.h | 22 ++++++ xen/arch/arm/include/asm/mm.h | 7 +- xen/arch/arm/llc_coloring.c | 45 ++++++++++++ xen/arch/arm/mm.c | 94 ++++++++++++++++++++++--- xen/arch/arm/psci.c | 9 ++- xen/arch/arm/setup.c | 75 +++++++++++++++++++- xen/arch/arm/smpboot.c | 9 ++- xen/arch/arm/xen.lds.S | 2 +- 11 files changed, 325 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index f00e3b9b3c..29f1ff34d4 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/head.S b/xen/arch/arm/arm64/head.S index a61b4d3c27..9ed7610afa 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -801,6 +801,56 @@ fail: PRINT("- Boot failed -\r\n") b 1b ENDPROC(fail) =20 +GLOBAL(_end_boot) + +/* 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/mm.c b/xen/arch/arm/arm64/mm.c index 2ede4e75ae..4419381fdd 100644 --- a/xen/arch/arm/arm64/mm.c +++ b/xen/arch/arm/arm64/mm.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ =20 #include +#include #include =20 #include @@ -121,26 +122,43 @@ 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); /* 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 7a01b8841c..ae5c4ff606 100644 --- a/xen/arch/arm/include/asm/llc_coloring.h +++ b/xen/arch/arm/include/asm/llc_coloring.h @@ -15,11 +15,28 @@ =20 #ifdef CONFIG_LLC_COLORING =20 +#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)) ) + bool __init llc_coloring_init(void); =20 unsigned int *dom0_llc_colors(unsigned int *num_colors); unsigned int *llc_colors_from_str(const char *str, unsigned int *num_color= s); =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); + #else /* !CONFIG_LLC_COLORING */ =20 static inline bool __init llc_coloring_init(void) { return true; } @@ -27,6 +44,11 @@ static inline unsigned int *dom0_llc_colors( unsigned int *num_colors) { return NULL; } static inline unsigned int *llc_colors_from_str( const char *str, unsigned int *num_colors) { return NULL; } +paddr_t xen_colored_map_size(paddr_t size) { return 0; } +static inline void *xen_remap_colored(mfn_t xen_fn, paddr_t xen_size) +{ + return NULL; +} =20 #endif /* CONFIG_LLC_COLORING */ =20 diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 596293f792..1b3be348b7 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -195,14 +195,19 @@ extern unsigned long total_pages; =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); /* Switch to a new root page-tables */ extern void switch_ttbr(uint64_t ttbr); /* Remove early mappings */ extern void remove_early_mappings(void); +/* Remove early LLC coloring mappings */ +extern void remove_llc_coloring_mappings(void); /* Allocate and initialise pagetables for a secondary CPU. Sets init_ttbr = to the * new page table */ extern int init_secondary_pagetables(int cpu); diff --git a/xen/arch/arm/llc_coloring.c b/xen/arch/arm/llc_coloring.c index 745e93a61a..ded1f33ad5 100644 --- a/xen/arch/arm/llc_coloring.c +++ b/xen/arch/arm/llc_coloring.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include #include @@ -41,6 +42,8 @@ static unsigned int __ro_after_init xen_colors[CONFIG_NR_= LLC_COLORS]; static unsigned int __ro_after_init xen_num_colors; =20 #define addr_to_color(addr) (((addr) & addr_col_mask) >> PAGE_SHIFT) +#define addr_set_color(addr, color) (((addr) & ~addr_col_mask) \ + | ((color) << PAGE_SHIFT)) =20 /* * Parse the coloring configuration given in the buf string, following the @@ -341,6 +344,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) +{ + paddr_t maddr =3D mfn_to_maddr(mfn); + unsigned int i, color =3D addr_to_color(maddr); + + 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 maddr_to_mfn(addr_set_color(maddr, xen_colors[i])); + } + + /* Jump to next color space (llc_way_size bytes) and use the first col= or */ + return maddr_to_mfn(addr_set_color(maddr + llc_way_size, 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 =3D xmalloc_array(mfn_t, xen_size >> PAGE_SHIF= T); + + 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/mm.c b/xen/arch/arm/mm.c index 7015a0f841..f14fb98088 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,9 @@ DEFINE_BOOT_PAGE_TABLE(boot_third); DEFINE_PAGE_TABLE(xen_pgtable); static DEFINE_PAGE_TABLE(xen_first); #define THIS_CPU_PGTABLE xen_pgtable +#ifdef CONFIG_LLC_COLORING +static DEFINE_PAGE_TABLE(xen_colored_temp); +#endif #else #define HYP_PT_ROOT_LEVEL 1 /* Per-CPU pagetable pages */ @@ -391,7 +395,12 @@ void flush_page_to_ram(unsigned long mfn, bool sync_ic= ache) =20 lpae_t 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); } @@ -484,9 +493,54 @@ static void clear_table(void *table) clean_and_invalidate_dcache_va_range(table, PAGE_SIZE); } =20 -/* Boot-time pagetable setup. - * Changes here may need matching changes in head.S */ -void __init setup_pagetables(unsigned long boot_phys_offset) +#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 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, paddr_t xen_p= addr) { uint64_t ttbr; lpae_t pte, *p; @@ -494,6 +548,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 @@ -543,10 +600,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); @@ -556,6 +616,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 static void clear_boot_pagetables(void) @@ -576,12 +648,18 @@ static void clear_boot_pagetables(void) #ifdef CONFIG_ARM_64 int init_secondary_pagetables(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 (uintptr_t) xen_pgtable + phys_offset; - 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..fdc798dd14 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 c04e5012f0..72da5a8e5e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -456,7 +456,7 @@ static void * __init relocate_fdt(paddr_t dtb_paddr, si= ze_t dtb_size) return fdt; } =20 -#ifdef CONFIG_ARM_32 +#if defined (CONFIG_ARM_32) || defined(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 @@ -548,7 +548,9 @@ static paddr_t __init consider_modules(paddr_t s, paddr= _t e, } return e; } +#endif =20 +#ifdef CONFIG_ARM_32 /* * Find a contiguous region that fits in the static heap region with * required size and alignment, and return the end address of the region @@ -622,6 +624,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 + static void __init init_pdx(void) { paddr_t bank_start, bank_size, bank_end; @@ -1004,8 +1062,6 @@ void __init start_xen(unsigned long boot_phys_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); @@ -1031,8 +1087,13 @@ void __init start_xen(unsigned long boot_phys_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 */ @@ -1147,6 +1208,14 @@ void __init start_xen(unsigned long boot_phys_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 4a89b3a834..7e437724b4 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -445,6 +446,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 @@ -460,9 +462,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 diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 3f7ebd19f3..a69c43e961 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -212,7 +212,7 @@ SECTIONS . =3D ALIGN(POINTER_ALIGN); __bss_end =3D .; } :text - _end =3D . ; + _end =3D ALIGN(PAGE_SIZE); =20 /* Section for the device tree blob (if any). */ .dtb : { *(.dtb) } :text --=20 2.34.1