From nobody Sun Feb 8 13:09:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1689609832; cv=none; d=zohomail.com; s=zohoarc; b=YOvWjmmwLxQG04J3/JpywxMnA1xXAtuezn2QiRQKtf7sxeKn5Ep7oWKvzxWNVwb2OP1qN7u6Q2k6XY0itRqiiZHOh1MGyNEsX2rvvmTlQl4uvdwHmwaAPWZsEyCpBXanSOl8BoSFK0Mhm9mw560MeKZRqBMqNL93xHEtVPPUrIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689609832; 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=7QGfkDVjG71aom9bAterc/1wKh4jZEIowYjFqXVaWh0=; b=eZXn3B567QVY8ZoHhpKnmwZt1sJ9qA20dy6KBal/QFXeP1Mk6LSjruOe53bA/xbLAcXT2nqQvuRwMDNN25GWME7i4b7g4Gg+AALdxsWBuq5zgo6/Refi7s2esc5KOO/BAkBNrQhoZPFlPh5TVBdnqlhxh+Y69U4MjMfpFXuvBZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1689609832022161.30305257715065; Mon, 17 Jul 2023 09:03:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.564734.882429 (Exim 4.92) (envelope-from ) id 1qLQh8-0003PN-7d; Mon, 17 Jul 2023 16:03:30 +0000 Received: by outflank-mailman (output) from mailman id 564734.882429; Mon, 17 Jul 2023 16:03:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qLQh7-0003Lw-V7; Mon, 17 Jul 2023 16:03:29 +0000 Received: by outflank-mailman (input) for mailman id 564734; Mon, 17 Jul 2023 16:03: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 1qLQh6-00027B-4o for xen-devel@lists.xenproject.org; Mon, 17 Jul 2023 16:03:28 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 773057de-24bb-11ee-b23a-6b7b168915f2; Mon, 17 Jul 2023 18:03:27 +0200 (CEST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4fcd615d7d6so6903860e87.3 for ; Mon, 17 Jul 2023 09:03:27 -0700 (PDT) Received: from EMEAENGAAD19049.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id bo28-20020a0564020b3c00b0051df5bd1cd8sm10099050edb.65.2023.07.17.09.03.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 09:03:26 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 773057de-24bb-11ee-b23a-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1689609806; x=1692201806; 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=7QGfkDVjG71aom9bAterc/1wKh4jZEIowYjFqXVaWh0=; b=J9UFqD4U6/+xFXgvL/eHS1K3ZsRFfObmThVd0Sx3haPrf1u/4zdURKFRc5ZJ9k+yI3 YbgVQ52ZFPB0UzsfMDnMrO+RojCfSZFbkTfIoBA6QTHyKQ/aSMngs1hVScSzvRMxXnub bDv923akwd+wLhxzq2A0UDY7tLIKqbIPS/vwc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689609806; x=1692201806; 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=7QGfkDVjG71aom9bAterc/1wKh4jZEIowYjFqXVaWh0=; b=W/FJiTum4ljF8alLQao5viIJ3dKu/DiVSdbzT4MxVsd1aJU3yBrM0ZRdBhiWlnci+1 sTs8f+qa5HqbHXqdfKyyK+y5qHOSVhSNFq3S6GwhXjojSczi8hEkoSrD5hyRGn+SjGRr cBeH/X97cKiwPcLEhJ+6H7NE29WCQPPIq3Rsi4nWVjB2nUmc7krF4C/4mob4mGE0FKSu yRf9eIbrWzb4tSJhMGoNbPCel4UcYJd0FaKvOm9TlJNlKVaDKG3yvjQYWSiqokr8cTxP oKaZ2BmaxB9lfxEYOjm2QxzkUCsqRPS5hmKZ46zhf6IPsd7L0sKDNkvE3mgu/LdQIpGV Fi4g== X-Gm-Message-State: ABy/qLa/BcmUYZ79Jc37Pq8Y+Grj3lLs7uvaX8rAzV+u0VLXsGvPD3HU wEvaNJJY4tZOWNlFi0aBapl3agKj29xUcZPKypw= X-Google-Smtp-Source: APBJJlF5hBqYxBEdbU/CdUkMNf+ZWkqlphrHQ0PjL8lO0H04R4PCEvyaCbBP88krTvazp26SQzFivA== X-Received: by 2002:a05:6512:2822:b0:4fc:dcff:773b with SMTP id cf34-20020a056512282200b004fcdcff773bmr12474057lfb.3.1689609806597; Mon, 17 Jul 2023 09:03:26 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH 8/8] pdx: Add CONFIG_HAS_PDX_COMPRESSION as a Kconfig option Date: Mon, 17 Jul 2023 17:03:18 +0100 Message-Id: <20230717160318.2113-9-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717160318.2113-1-alejandro.vallejo@cloud.com> References: <20230717160318.2113-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1689609834049100002 Content-Type: text/plain; charset="utf-8" Adds a new compile-time flag to allow disabling pdx compression and compiles out compression-related code/data. It also shorts the pdx<->pfn conversion macros and creates stubs for masking fucntions. Signed-off-by: Alejandro Vallejo --- xen/arch/x86/domain.c | 19 +++++++++++++------ xen/common/Kconfig | 10 ++++++++++ xen/common/pdx.c | 15 +++++++++++---- xen/include/xen/pdx.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 39c2153165..c818ccc4d5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -458,7 +458,7 @@ void domain_cpu_policy_changed(struct domain *d) } } =20 -#ifndef CONFIG_BIGMEM +#if !defined(CONFIG_BIGMEM) && defined(CONFIG_HAS_PDX_COMPRESSION) /* * The hole may be at or above the 44-bit boundary, so we need to determine * the total bit count until reaching 32 significant (not squashed out) bi= ts @@ -485,13 +485,20 @@ static unsigned int __init noinline _domain_struct_bi= ts(void) struct domain *alloc_domain_struct(void) { struct domain *d; -#ifdef CONFIG_BIGMEM - const unsigned int bits =3D 0; -#else + /* - * We pack the PDX of the domain structure into a 32-bit field within - * the page_info structure. Hence the MEMF_bits() restriction. + * Without CONFIG_BIGMEM, we pack the PDX of the domain structure into + * a 32-bit field within the page_info structure. Hence the MEMF_bits() + * restriction. With PDX compression in place the number of bits must + * be calculated at runtime, but it's fixed otherwise. + * + * On systems with CONFIG_BIGMEM there's no packing, and so there's no + * such restriction. */ +#if defined(CONFIG_BIGMEM) || !defined(CONFIG_HAS_PDX_COMPRESSION) + const unsigned int bits =3D IS_ENABLED(CONFIG_BIGMEM) ? 0 : + 32 + PAGE_SHIFT; +#else static unsigned int __read_mostly bits; =20 if ( unlikely(!bits) ) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 40ec63c4b2..6605a60ff7 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -23,6 +23,16 @@ config GRANT_TABLE =20 If unsure, say Y. =20 +config HAS_PDX_COMPRESSION + bool "PDX (Page inDeX) compression support" + default ARM + help + PDX compression is a technique that allows the hypervisor to + represent physical addresses in a very space-efficient manner. + This is very helpful reducing memory wastage in systems with + memory banks with base addresses far from each other, but carrier + a performance cost. + config ALTERNATIVE_CALL bool =20 diff --git a/xen/common/pdx.c b/xen/common/pdx.c index cc963a3cb3..d0fac9d7c7 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -31,11 +31,15 @@ unsigned long __read_mostly pdx_group_valid[BITS_TO_LON= GS( =20 bool __mfn_valid(unsigned long mfn) { - if ( unlikely(evaluate_nospec(mfn >=3D max_page)) ) + bool invalid =3D mfn >=3D max_page; +#ifdef CONFIG_HAS_PDX_COMPRESSION + invalid |=3D mfn & pfn_hole_mask; +#endif + + if ( unlikely(evaluate_nospec(invalid)) ) return false; - return likely(!(mfn & pfn_hole_mask)) && - likely(test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, - pdx_group_valid)); + + return test_bit(pfn_to_pdx(mfn) / PDX_GROUP_COUNT, pdx_group_valid); } =20 void set_pdx_range(unsigned long smfn, unsigned long emfn) @@ -49,6 +53,8 @@ void set_pdx_range(unsigned long smfn, unsigned long emfn) __set_bit(idx, pdx_group_valid); } =20 +#ifdef CONFIG_HAS_PDX_COMPRESSION + /* * Diagram to make sense of the following variables. The masks and shifts * are done on mfn values in order to convert to/from pdx: @@ -178,6 +184,7 @@ void __init pfn_pdx_hole_setup(unsigned long mask) pfn_top_mask =3D ~(pfn_pdx_bottom_mask | pfn_hole_mask); ma_top_mask =3D pfn_top_mask << PAGE_SHIFT; } +#endif /* CONFIG_HAS_PDX_COMPRESSION */ =20 =20 /* diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index ce27177b56..5531890d1c 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -98,6 +98,8 @@ bool __mfn_valid(unsigned long mfn); #define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn)) #define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx)) =20 +#ifdef CONFIG_HAS_PDX_COMPRESSION + extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask; extern unsigned int pfn_pdx_hole_shift; extern unsigned long pfn_hole_mask; @@ -225,7 +227,39 @@ static inline uint64_t directmapoff_to_maddr(unsigned = long offset) * position marks a potentially compressible bit. */ void pfn_pdx_hole_setup(unsigned long mask); +#else /* CONFIG_HAS_PDX_COMPRESSION */ + +/* Without PDX compression we can skip some computations */ + +/* pdx<->pfn =3D=3D identity */ +#define pdx_to_pfn(x) (x) +#define pfn_to_pdx(x) (x) + +/* directmap is indexed by by maddr */ +#define maddr_to_directmapoff(x) (x) +#define directmapoff_to_maddr(x) (x) + +static inline bool pdx_is_region_compressible(unsigned long smfn, + unsigned long emfn) +{ + return true; +} + +static inline uint64_t pdx_init_mask(uint64_t base_addr) +{ + return 0; +} + +static inline uint64_t pdx_region_mask(uint64_t base, uint64_t len) +{ + return 0; +} + +static inline void pfn_pdx_hole_setup(unsigned long mask) +{ +} =20 +#endif /* CONFIG_HAS_PDX_COMPRESSION */ #endif /* __XEN_PDX_H__ */ =20 /* --=20 2.34.1