From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662594; cv=none; d=zohomail.com; s=zohoarc; b=EBNoFY1s1eKjKhfkz0C0g9eqlMJKCcmXDHd8gLW98Cg3oiJO0TUPftW2H4VbYNsrGSQB1OvmwYEEbZJ4rcWlPcu1ROPWPxkCljNareeeIA/awLf48ITAeCTtFe+qRkFIxdUkoQKa8bYzCWZw6gHPeKS74tk9vAAjEDuMnB1RP2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662594; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2T4dUlmbhOvNtyULSsUmaVMdY6R2usDVIaG9wqrny14=; b=g37qR/f/wNMRkPdIIDn5vwIUVW/Nd3JYa4SLmJookGCgrs7O2vWYyafdhp6XB3D+HxiHUCWetRs5xi3FVwWqj2uR1laG7v2hpf1KDBGjpIAtbUH//LDelbrRs9jb0TYT/y2tbZHxN6I794u18IrBkmeT6RKWssBALT5I5LhDvuw= 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 1749662594161257.98422905497057; Wed, 11 Jun 2025 10:23:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011966.1390476 (Exim 4.92) (envelope-from ) id 1uPPA5-0002dc-Py; Wed, 11 Jun 2025 17:22:53 +0000 Received: by outflank-mailman (output) from mailman id 1011966.1390476; Wed, 11 Jun 2025 17:22:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA5-0002dV-MT; Wed, 11 Jun 2025 17:22:53 +0000 Received: by outflank-mailman (input) for mailman id 1011966; Wed, 11 Jun 2025 17:22:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA4-0002dK-MD for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:52 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b3e4c28a-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:51 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3a4fea34e07so93172f8f.1 for ; Wed, 11 Jun 2025 10:22:51 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a53229e0dcsm16348173f8f.15.2025.06.11.10.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:50 -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: b3e4c28a-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662570; x=1750267370; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2T4dUlmbhOvNtyULSsUmaVMdY6R2usDVIaG9wqrny14=; b=l6j3fGuBCBsXd86kiZ4rqCkCIlFbHighdDAdVJ4uA9NYgGcaC38n5W3boZrFoaQ17X y7gzUuXSTlHmjhl2qzD3f9CCZsYis0LKwuGYfaqFkdOsh1yArBQ9yw25pBwQlp7rp2I2 GMw1lmdmZtICfUFtg7tzR6q2CYjg+Z/fGsrIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662570; x=1750267370; 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=2T4dUlmbhOvNtyULSsUmaVMdY6R2usDVIaG9wqrny14=; b=ZqWyMizS7URjUFqUVcsIuuE0TnXX6u13UKkfmaWS2CXgrq+KfPtzyd1q6c2TODqnVq t4jQJURtvYd1r+RBItDTo2iIK+lEGmofocfIGuuPJiK0dWYTkkOheFISeS4XVDYCFlFf vE5MEQsgfuS/6FLN5XdOwCwWSWEfl/9SEQzp8aIjFVbkR+qPMv5YbP/Je3AowpA41Fyo aJu/5xMPLFEmn0ZmlJ3yxk9/M8k3bnsRMSpl80OSjOlXOiUYX39eU7HBGfv2CppUzknH 9fL01raRSaxpo1mc3Lk8TK89PD1ITR1CNlYNouetcNntj4tANuUIlGvEur1FcnCBj2Ls ZTOw== X-Gm-Message-State: AOJu0YyvgiFsF5oMo5gkFqEYXM9+V/du/6DJrvLpgri3D/R2a2qSGzEd VVxCtiUdd4yHH9V+0lX87jlx9mjqd1XzkD9rnaQqcQ3wrEv30lLNF1Lh0TqsCYDwZDwTcuWd+Dq Fvwjy X-Gm-Gg: ASbGncs62viAvLFgGEa+KPUv9N5RQBU6JkKObrKCSCRbu3uKu7524E2XtXJLQKi6Yu4 UDXpkzmd+g3kJkCaSHlF6LQrmsgD1U+BszeTGQBIzyyfA26neBiAR337qGZ+KwGflzgz4T8LqCU pk4r0hLtA0Ng6EHlR+dZjRozCxSjFOP8PNVmNzyHcRgac9w7xRNN1PlfFzFLprrJwxYf6bBUyLc wuIKaZMSmXkhuXlIDjOhus8MfNmZX0LB/KtZ9ZKJokl/+3LgDtTN8dDKhlCohjadYzUamkCTkjf Ps9/wOgPD9SjOr3dejTnDenISfMbVq0DrMOVAPClLUCzf+fUTRqqmsABExPGdQS/iK4VBQIcTOC EMDl1voJgWZVC3dbxy3DW3Hig92ePkSPX4XY= X-Google-Smtp-Source: AGHT+IHXlb+f8mvAbVqXjkk+FJrV+4iDXJ2XDjnLmfwZ968nmhBctbQRAM+VY3AZTZ9kxht+7rKilA== X-Received: by 2002:a05:6000:288e:b0:3a4:dfc2:2a3e with SMTP id ffacd0b85a97d-3a5586f192bmr4021318f8f.39.1749662570563; Wed, 11 Jun 2025 10:22:50 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper Subject: [PATCH 1/8] x86/pdx: simplify calculation of domain struct allocation boundary Date: Wed, 11 Jun 2025 19:16:29 +0200 Message-ID: <20250611171636.5674-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662596107116600 When not using CONFIG_BIGMEM there are some restrictions in the address width for allocations of the domain structure, as it's PDX truncated to 32bits it's stashed into page_info structure for domain allocated pages. The current logic to calculate this limit is based on the internals of the PDX compression used, which is not strictly required. Instead simplify the logic to rely on the existing PDX to PFN conversion helpers used elsewhere. This has the added benefit of allowing alternative PDX compression algorithms to be implemented without requiring to change the calculation of the domain structure allocation boundary. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/domain.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 7536b6c8717e..2f438ce367cf 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -461,30 +461,6 @@ void domain_cpu_policy_changed(struct domain *d) } } =20 -#if !defined(CONFIG_BIGMEM) && defined(CONFIG_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 - * in PFN representations. - * Note that the way "bits" gets initialized/updated/bounds-checked guaran= tees - * that the function will never return zero, and hence will never be called - * more than once (which is important due to it being deliberately placed = in - * .init.text). - */ -static unsigned int __init noinline _domain_struct_bits(void) -{ - unsigned int bits =3D 32 + PAGE_SHIFT; - unsigned int sig =3D hweight32(~pfn_hole_mask); - unsigned int mask =3D pfn_hole_mask >> 32; - - for ( ; bits < BITS_PER_LONG && sig < 32; ++bits, mask >>=3D 1 ) - if ( !(mask & 1) ) - ++sig; - - return bits; -} -#endif - struct domain *alloc_domain_struct(void) { struct domain *d; @@ -498,14 +474,15 @@ struct domain *alloc_domain_struct(void) * On systems with CONFIG_BIGMEM there's no packing, and so there's no * such restriction. */ -#if defined(CONFIG_BIGMEM) || !defined(CONFIG_PDX_COMPRESSION) - const unsigned int bits =3D IS_ENABLED(CONFIG_BIGMEM) ? 0 : - 32 + PAGE_SHIFT; +#if defined(CONFIG_BIGMEM) + const unsigned int bits =3D 0; #else - static unsigned int __read_mostly bits; + static unsigned int __ro_after_init bits; =20 if ( unlikely(!bits) ) - bits =3D _domain_struct_bits(); + bits =3D flsl(pfn_to_paddr(pdx_to_pfn( + 1UL << (sizeof(((struct page_info *)NULL)->v.inuse._domain) *= 8)))) + - 1; #endif =20 BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662591; cv=none; d=zohomail.com; s=zohoarc; b=OHfgjLrs285BFSSCvgWTrq70zWh4RpE5Zmgn35XZYGnr/uDSfyJD1lsbDHdw51lPvgDZMKU8ekVjWCAV9cc3kckgmDtG6dcGRcXhv0MFtM/PxhZNsekF0voolHLzIetYhcWYK5GEFTepW5Apii4hMZ3dmVGn398+uGsirKFX1pc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662591; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uKrBP871dG4zllrLFjmVYwBp6+ujdNqW4+VWtq3YZgI=; b=Jx0W0uxsTQUS/CBcjoiFooqBFQX15oeb0+6P200Oji/ObidNty3RaxvYI7X4KsskaD9XsX3v0lxK8cPkmkkJKhcbPlu7dEnoDsrrkEvmERYBWpydv0Z1LnkN6n77fYCuxzY9nrGJ0lgHcxV9HzkN+3JE/krHEY4PrCmWQQJunXM= 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 1749662591602258.73791448032205; Wed, 11 Jun 2025 10:23:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011967.1390486 (Exim 4.92) (envelope-from ) id 1uPPA7-0002rV-16; Wed, 11 Jun 2025 17:22:55 +0000 Received: by outflank-mailman (output) from mailman id 1011967.1390486; Wed, 11 Jun 2025 17:22:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA6-0002rM-UN; Wed, 11 Jun 2025 17:22:54 +0000 Received: by outflank-mailman (input) for mailman id 1011967; Wed, 11 Jun 2025 17:22:53 +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 1uPPA5-0002dK-B6 for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:53 +0000 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [2a00:1450:4864:20::42f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b492516c-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:52 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3a54700a46eso133852f8f.1 for ; Wed, 11 Jun 2025 10:22:52 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a5323ab207sm15780062f8f.29.2025.06.11.10.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:51 -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: b492516c-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662572; x=1750267372; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uKrBP871dG4zllrLFjmVYwBp6+ujdNqW4+VWtq3YZgI=; b=fMa6ppnhQyo4G8LOz+vHWa1GJ2uhGPXOJYXUr8QXzrPdnbDsIXn/bK30BA0a4B+UUx sV8cPKYlvGz8X8FtHXmoZV2qiL/6TP8QPIdIHBeGM37kuRec3/qX8wJ120RT8/3uWQQd pGFz8t/nJ33FptRb+aAoPxIcK2AvJX1oVka6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662572; x=1750267372; 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=uKrBP871dG4zllrLFjmVYwBp6+ujdNqW4+VWtq3YZgI=; b=oDOPzLVMeV0iKqqwtXTCcZM6dF1FSG3uCafPh157lWGQwbTwXZxf5jGEBuQSlDhLe2 snVjxWVrurprPb3QGCtzKAjpbJdC5etqN0keJDnWG4LwFhIOag7H5NEIphSwCfejd79Y p3vCHyk47w+3GmQ8ZQwtQnTQykDjBzisXEZIle8yPkyn2HcbS1Bno3ySqpmYwOuhqQDR lwkEXwJnkwT8k66/OBak1DBhyXuFYOwQxip1Qwp+bWS1BwJHtP0UaaTfjCzF12Vm38Rc 64pzsH3QZH20zr3U2brbh1vCwhLtuBfn/D771PjIHUQ+z4PWEj+p/cFZRyiA1rY8UVG6 m3IQ== X-Gm-Message-State: AOJu0YxNjHnd1UO+ugPJkLz0X788hX42bRrsns00CPepCE7LfCfUWP8u KaAAn3D9d8joFR4866QK1urzO3yESwFeVlb6oDmF63llmTqGxgbxtDlXtUwgccP+cie8ZaVSeCK dvaLf X-Gm-Gg: ASbGncvUphL4Furxti2C91MqL5iXR7H5vEb0mZDPNIzFiUhsvLU2CHzMXs4YQxcCqFO 4FCeXkToXFnoDOJg1JGJRbnRSuj6iRwpZNaUejULFYx+fc1QMJvBZ95uxeksc3O6VaIdYLIijhv xxmxD8bpvlr9RmADj8AIliKkkco21pZR9buDAqudpMZdtEzdLlmmE0hPvrMiqMggD/nnVZ9Tida tGsyqOEO2yczuskBghI6xjQbSeG45Na0CKTFU20ieSXt5fS9N9XeT0CtLhVQjXkKPeE1RBB2JPb N3E8i7HtvJacmc+dqk46UrAmXwSAsoJ5SXBWrxobB8fXisVuA1rEbS9phpszSh0EorLj7iAke+4 qi5pg1VQgx8EM8or8l60I7hkPiDSUU20qwOw= X-Google-Smtp-Source: AGHT+IGLtHZs7bMty9epxiuNgjn1rUQmc2r9GZEr5iiKTtkm11d+FqFZAUn80jbqllZXkua5g4YQlw== X-Received: by 2002:a05:6000:310a:b0:3a4:d53d:be20 with SMTP id ffacd0b85a97d-3a558695d45mr3025445f8f.18.1749662571651; Wed, 11 Jun 2025 10:22:51 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [PATCH 2/8] pdx: introduce function to calculate max PFN based on PDX compression Date: Wed, 11 Jun 2025 19:16:30 +0200 Message-ID: <20250611171636.5674-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662592007116600 This is the code already present and used by x86 in setup_max_pdx(), which takes into account the current PDX compression, plus the limitation of the virtual memory layout to return the maximum usable PFN in the system, possibly truncating the input PFN provided by the caller. This helper will be used by upcoming PDX related changes that introduce a new compression algorithm. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/setup.c | 19 ++----------------- xen/common/pdx.c | 25 +++++++++++++++++++++++++ xen/include/xen/pdx.h | 8 ++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 1f5cb67bd0ee..ea670567cbf7 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -721,23 +721,8 @@ static uint64_t __init consider_modules( =20 static void __init setup_max_pdx(unsigned long top_page) { - max_pdx =3D pfn_to_pdx(top_page - 1) + 1; - - if ( max_pdx > (DIRECTMAP_SIZE >> PAGE_SHIFT) ) - max_pdx =3D DIRECTMAP_SIZE >> PAGE_SHIFT; - - if ( max_pdx > FRAMETABLE_NR ) - max_pdx =3D FRAMETABLE_NR; - - if ( max_pdx > MPT_VIRT_SIZE / sizeof(unsigned long) ) - max_pdx =3D MPT_VIRT_SIZE / sizeof(unsigned long); - -#ifdef PAGE_LIST_NULL - if ( max_pdx >=3D PAGE_LIST_NULL ) - max_pdx =3D PAGE_LIST_NULL - 1; -#endif - - max_page =3D pdx_to_pfn(max_pdx - 1) + 1; + max_page =3D get_max_pfn(top_page); + max_pdx =3D pfn_to_pdx(max_page - 1) + 1; } =20 /* A temporary copy of the e820 map that we can mess with during bootstrap= . */ diff --git a/xen/common/pdx.c b/xen/common/pdx.c index b8384e6189df..3004c5f28bdd 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -55,6 +55,31 @@ void set_pdx_range(unsigned long smfn, unsigned long emf= n) __set_bit(idx, pdx_group_valid); } =20 +unsigned long get_max_pfn(unsigned long top_pfn) +{ + unsigned long pdx =3D pfn_to_pdx(top_pfn - 1) + 1; + +#ifdef DIRECTMAP_SIZE + if ( pdx > (DIRECTMAP_SIZE >> PAGE_SHIFT) ) + pdx =3D DIRECTMAP_SIZE >> PAGE_SHIFT; +#endif + + if ( pdx > FRAMETABLE_NR ) + pdx =3D FRAMETABLE_NR; + +#ifdef MPT_VIRT_SIZE + if ( pdx > MPT_VIRT_SIZE / sizeof(unsigned long) ) + pdx =3D MPT_VIRT_SIZE / sizeof(unsigned long); +#endif + +#ifdef PAGE_LIST_NULL + if ( pdx >=3D PAGE_LIST_NULL ) + pdx =3D PAGE_LIST_NULL - 1; +#endif + + return pdx_to_pfn(pdx - 1) + 1; +} + #ifdef CONFIG_PDX_COMPRESSION =20 /* diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 9faeea3ac9f2..0f580853cb2e 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -92,6 +92,14 @@ void set_pdx_range(unsigned long smfn, unsigned long emf= n); */ bool __mfn_valid(unsigned long mfn); =20 +/** + * Get maximum usable PFN given the virtual address space restrictions. + * + * @param pdx Maximum PFN + * @return Possibly truncated maximum PFN + */ +unsigned long get_max_pfn(unsigned long top_pfn); + #define page_to_pdx(pg) ((pg) - frame_table) #define pdx_to_page(pdx) gcc11_wrap(frame_table + (pdx)) =20 --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662595; cv=none; d=zohomail.com; s=zohoarc; b=jHxay5xP/AIAg9ff+o7zSBfKvu0eQldFKPC/KcCv35NHp0ubqfqIa611+Sr8lkgBH/XqVJX2BDTZ3nUZmF1qQ7fSfsT2v5xxjRNO+ftk60bqi8hn+pkz5KinfwoNYBydFVawpNIWiz0drYffWUV+MVAt2tKZ/PC6vTb3+NZXEXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662595; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GJdgiHOwfWzJfwlUoTb0DBDPl6XGoOntK+kYSINp4iw=; b=UA+xrgc0dEcWtn03/vZCY3bRCCb4JHLdc/okDiqyOjSuJZlpwW1Nezhyt0Cen1QcIlSFTPew3OmSCNVLD9kF+fqfFaqeYHA8JAIbg6dN2OsG0Iucvj40ld+dBlykrcZkSwsbuA2J6vNl9Sen++nX4sRkec+zk1+SBq5PTE1ddaY= 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 1749662595137930.7003031257868; Wed, 11 Jun 2025 10:23:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011968.1390495 (Exim 4.92) (envelope-from ) id 1uPPA8-00035l-81; Wed, 11 Jun 2025 17:22:56 +0000 Received: by outflank-mailman (output) from mailman id 1011968.1390495; Wed, 11 Jun 2025 17:22:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA8-00035e-4w; Wed, 11 Jun 2025 17:22:56 +0000 Received: by outflank-mailman (input) for mailman id 1011968; Wed, 11 Jun 2025 17:22:54 +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 1uPPA6-0002dK-BI for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:54 +0000 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [2a00:1450:4864:20::330]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b563be29-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:53 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-451d3f72391so93305e9.3 for ; Wed, 11 Jun 2025 10:22:53 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45325217c0bsm27303695e9.33.2025.06.11.10.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:52 -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: b563be29-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662573; x=1750267373; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GJdgiHOwfWzJfwlUoTb0DBDPl6XGoOntK+kYSINp4iw=; b=AgHhl7dYaSD2ntPPLdXWB6Ok/fNJSc72mjLNoSXXZlIDHCCZ5IKtnO1Mor+2dInnZF zWJaaRqVD/xqReIkKLFxAfIYnGswz52P9TZ6dt/5KwlpLsShkfJcg+EhulAh6JoB7EH5 wXTQA5U/huNUjlAICQBL75ql0lsZUdYCrr/pY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662573; x=1750267373; 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=GJdgiHOwfWzJfwlUoTb0DBDPl6XGoOntK+kYSINp4iw=; b=DaYrfu0SllpF3qeJIC+78Wiz2UeUodU7Jdqa1M0tT6MlKLZGS6Sn3ZTcUSS4HI3qLb 6GfdRD+nUwjl7+7ReHZ9gNN/VyKem+u+CAoO0YmQmwEGoZfv9tompZfOftN3p9Td7rMi kdbmyfNF3QEbYIK6Ag9Sajwco1G/aex32ETuRjx/FWHCjFIVHajQ9QA+sisYmRqNlTeD 2UgHu0dbweFSzrJwJC4TYa9r8+LNGKaGKV0lCk+LCVGBTdacQL/yyaGDrU27u6iUQgR4 ANJR7nf/HXILr1hOrpqRi+J63bMso4ebz7UZRGhzhGh5wrfjxPbwd0fTKGbfZ3ucHI1V CKqw== X-Gm-Message-State: AOJu0YzHD5zSTroLHL6t9OmczOIaUeBglqfQ+Nm+3NO1SgLN6AlftD2o LpBTLiMmeFtY12HosnJesv/erJ5/KpG1azcAp8j/XEbfzwIpyyK0r7Y/befcg6pdVF8zb7NfpCe VaPsL X-Gm-Gg: ASbGncsTwVFnAiZc+727wQIffPi6J+i2YO0F7vktWb2YFtthrBkalBlSlfJceyGzbMK Q6Ab64kVfXuN1ijY60PlmKkUF5MZCMgyR0zOVb/CMN5mp6Un514QMw3Vc0yJ7Y2UQZabSZHssPf /MAoGpZfQ328nRW3al+0Q8CHzEEXeepekyhZhmlNeWWQdnRSmB8hr31pEAdCazxTKEiDLYiyOvt sypHI7YTd6Yj1wQWPRXi0IURn4XPKfx2s/lbd7kWTNhctdpgD/J2bg0qwISKAsmipBbM3vlRZ8c LsENO+C8vpq3v0ZXJnXJUcUvGc74rQ7AZxK8fXfxMLQ3yjuSxvI2N4E6s8t+Q4i2Z1CgKqFB4GV uuxHcRKTkQcr2wSb/rznYwVrq7SqHsEjy8ps= X-Google-Smtp-Source: AGHT+IEUIPDE6+hbVBrOpvdAglF9TBj3iPOuBLOi+lUVI2lkYz3YeRmcVwLvDsIpM7oCwbJvfIznJQ== X-Received: by 2002:a05:600c:4ecb:b0:453:9b3:5b67 with SMTP id 5b1f17b1804b1-4532b966b65mr5884535e9.24.1749662572848; Wed, 11 Jun 2025 10:22:52 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 3/8] kconfig: turn PDX compression into a choice Date: Wed, 11 Jun 2025 19:16:31 +0200 Message-ID: <20250611171636.5674-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662596422116600 Rename the current CONFIG_PDX_COMPRESSION to CONFIG_PDX_MASK_COMPRESSION, and make it part of the PDX compression choice block, in preparation for adding further PDX compression algorithms. No functional change intended as the PDX compression defaults should still be the same for all architectures, however the choice block cannot be protected under EXPERT and still have a default choice being unconditionally selected. As a result, the new "PDX (Page inDeX) compression" item will be unconditionally visible in Kconfig. As part of this preparation work to introduce new PDX compressions, adjust some of the comments on pdx.h to note they apply to a specific PDX compression. Also shuffle function prototypes and dummy implementations around to make it easier to introduce a new PDX compression. Note all PDX compression implementations are expected to provide a pdx_is_region_compressible() that takes the same set of arguments. Signed-off-by: Roger Pau Monn=C3=A9 Acked-by: Jan Beulich --- xen/common/Kconfig | 18 +++++++++++++++--- xen/common/pdx.c | 4 ++-- xen/include/xen/pdx.h | 32 +++++++++++++++++++------------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/xen/common/Kconfig b/xen/common/Kconfig index eece1370a3cc..7ffd9d7d9003 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -52,9 +52,10 @@ config EVTCHN_FIFO =20 If unsure, say Y. =20 -config PDX_COMPRESSION - bool "PDX (Page inDeX) compression" if EXPERT && !X86 && !RISCV - default ARM || PPC +choice + prompt "PDX (Page inDeX) compression" + default PDX_MASK_COMPRESSION if !X86 && !RISCV + default PDX_NONE help PDX compression is a technique designed to reduce the memory overhead of physical memory management on platforms with sparse RAM @@ -67,6 +68,17 @@ config PDX_COMPRESSION If your platform does not have sparse RAM banks, do not enable PDX compression. =20 +config PDX_MASK_COMPRESSION + bool "Mask compression" + help + Compression relying on all RAM addresses sharing a zeroed bit region. + +config PDX_NONE + bool "None" + help + No compression +endchoice + config ALTERNATIVE_CALL bool =20 diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 3004c5f28bdd..4843630bee7f 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -34,7 +34,7 @@ bool __mfn_valid(unsigned long mfn) { bool invalid =3D mfn >=3D max_page; =20 -#ifdef CONFIG_PDX_COMPRESSION +#ifdef CONFIG_PDX_MASK_COMPRESSION invalid |=3D mfn & pfn_hole_mask; #endif =20 @@ -80,7 +80,7 @@ unsigned long get_max_pfn(unsigned long top_pfn) return pdx_to_pfn(pdx - 1) + 1; } =20 -#ifdef CONFIG_PDX_COMPRESSION +#ifdef CONFIG_PDX_MASK_COMPRESSION =20 /* * Diagram to make sense of the following variables. The masks and shifts diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 0f580853cb2e..ec0827936c2f 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -25,7 +25,7 @@ * this by keeping a bitmap of the ranges in the frame table containing * invalid entries and not allocating backing memory for them. * - * ## PDX compression + * ## PDX mask compression * * This is a technique to avoid wasting memory on machines known to have * split their machine address space in several big discontinuous and high= ly @@ -108,22 +108,13 @@ unsigned long get_max_pfn(unsigned long top_pfn); =20 #define paddr_to_pdx(pa) pfn_to_pdx(paddr_to_pfn(pa)) =20 -#ifdef CONFIG_PDX_COMPRESSION +#ifdef CONFIG_PDX_MASK_COMPRESSION =20 extern unsigned long pfn_pdx_bottom_mask, ma_va_bottom_mask; extern unsigned int pfn_pdx_hole_shift; extern unsigned long pfn_hole_mask; extern unsigned long pfn_top_mask, ma_top_mask; =20 -/** - * Validate a region's compatibility with the current compression runtime - * - * @param base Base address of the region - * @param npages Number of PAGE_SIZE-sized pages in the region - * @return True iff the region can be used with the current compression - */ -bool pdx_is_region_compressible(paddr_t base, unsigned long npages); - /** * Calculates a mask covering "moving" bits of all addresses of a region * @@ -216,7 +207,9 @@ static inline paddr_t directmapoff_to_maddr(unsigned lo= ng offset) */ void pfn_pdx_hole_setup(unsigned long mask); =20 -#else /* !CONFIG_PDX_COMPRESSION */ +#endif /* CONFIG_PDX_MASK_COMPRESSION */ + +#ifdef CONFIG_PDX_NONE =20 /* Without PDX compression we can skip some computations */ =20 @@ -248,7 +241,20 @@ static inline void pfn_pdx_hole_setup(unsigned long ma= sk) { } =20 -#endif /* CONFIG_PDX_COMPRESSION */ +#else /* !CONFIG_PDX_NONE */ + +/* Shared functions implemented by all PDX compressions. */ + +/** + * Validate a region's compatibility with the current compression runtime + * + * @param base Base address of the region + * @param npages Number of PAGE_SIZE-sized pages in the region + * @return True iff the region can be used with the current compression + */ +bool pdx_is_region_compressible(paddr_t base, unsigned long npages); + +#endif /* !CONFIG_PDX_NONE */ #endif /* __XEN_PDX_H__ */ =20 /* --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662599; cv=none; d=zohomail.com; s=zohoarc; b=NAa12p4bV3qbxlAe5XREsTyxWrnFKPM9f1xgmO98gBOETYbSYrRW56dzVwNrikxpfAUSdxDgvIATQI6j8D11dxa4F4/+gvjAcZuqiCu5RgZf6Ucnnx8PgBUAdk11fPBKdhHD/4WLivZ+Pe62uwrw5plHTVGXtSN3EP6Jy2o5b20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662599; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ttrfu43pRWE6xwPmTOgphlvxFpMyWz3GgrH4WqitZoY=; b=UhUmBqKwYuUuROaDSWG6rAC1gwvOevjT7jTthVUwmCDNlGj//wi20omyRP/nDpMyMpR6VELdONEcpA+eBfWlQ0CqZ0CC9PfnLDGm9k2JOKWH5A4Gyub8OT4kT+u3Jzd71kKQo3+CX5w+VrdzSsX7i1mDv1943Oj9SeXOxJBatRo= 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 1749662599045671.8153693675287; Wed, 11 Jun 2025 10:23:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011969.1390506 (Exim 4.92) (envelope-from ) id 1uPPA9-0003KK-HC; Wed, 11 Jun 2025 17:22:57 +0000 Received: by outflank-mailman (output) from mailman id 1011969.1390506; Wed, 11 Jun 2025 17:22:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA9-0003K9-DG; Wed, 11 Jun 2025 17:22:57 +0000 Received: by outflank-mailman (input) for mailman id 1011969; Wed, 11 Jun 2025 17:22:55 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA7-0002dK-P9 for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:55 +0000 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [2a00:1450:4864:20::436]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b619382b-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:55 +0200 (CEST) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3a536ecbf6fso86759f8f.2 for ; Wed, 11 Jun 2025 10:22:55 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a532435771sm16404330f8f.63.2025.06.11.10.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:53 -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: b619382b-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662574; x=1750267374; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ttrfu43pRWE6xwPmTOgphlvxFpMyWz3GgrH4WqitZoY=; b=ai9YvOzuSaybgXuqFf99uzC7SkG1aW2tFY0j3SzMOqSOhhCPzQ7vNkE7pPAi1rabJa lsJeYPDtChdq0HfY9QKA95YdLll9fLB4ewtMvUvfOoA/IehQDIaNKbyiCrln08kP+8Dq /1FR1glONtK1zhLqZkROkWFgl8SnkoyANYsTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662574; x=1750267374; 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=ttrfu43pRWE6xwPmTOgphlvxFpMyWz3GgrH4WqitZoY=; b=bal0uDxLgxgWIjfKnAlXh7R+TcFNR9YwKv/7E3n+5XCjf5vl92S33cJk9rbPQBHSlv fGy2thIo07yKVDC1B+0HYv7qNqvzwVQNzAeOojfsG3K5PuMPWgXvwkRWzq+9iMMiOGk5 slQnDupefoCjDxW6wTEZd0Kz5dZxvUJBVFoTNhkaVU3wBLVz/WIjhHQnzL1CRIC20e+5 C69pSC98CpQGs7AXU1QfjTSIen6zqIP0n+7mQtLrUTy0DbYwW26n+qH9uhwtniIVJU14 E+CcibDA1hdJbLekd6on+b5vO89zU2S8EYsMarK1u4B/yzABvHKXBdjeurWoApQ/wryy Kr1g== X-Gm-Message-State: AOJu0YzV80CAUhN7dAvGk5WCYdGCV9O9pt8+Ft7w5jQHrU5hF4DDv9tg 2alXeC6bjSJlK+/yjtkJRxwywO4042bSm/WgFa+8mYIMhiytgHyhykj+HlruuVPnkBOTL8y/Kyr n62xb X-Gm-Gg: ASbGncv2vaEJN0z/eW9BJ8FogWgoxUHyS9rIus+wTlrhFe2LdwOrsair0Xzo4dj70jz q6VfVAOS3/9xuCFKwuC1dZfQVb9EWA0umZhlvMhg0pobuk475Y/oqSngr+dkMD67Xdmx4EAHfTA 8Z1zuq3VBAkOqX0f5BNLBNGEyKxfTqK+zf67nXcGgejyCCC2A+yrrpXoqiToCTfwlUy6mrB5hG+ vblwsUojI+8O9Z/3dmErhylGPMygfkIMOpQ6G/UkAOWRsqWJN2zxex4VfLl/j75nJT3qoUnfl0D zGQSqb2AerEQxPIE0Lcaf5qAemz+OXZbpZFyMiIXkvZ8mwerA0hNLHVtHMgUcnf7jMnTa1iIAqo XM01QrWo+c1Xpy1f70z7Nh+xPFi7JJtlUjLk= X-Google-Smtp-Source: AGHT+IGBuv1A6rD03lt3tuGkXIBzFKTXW9t2uvoWqXh1j3YfreQdjr3Ip7zMXU6tXWBGKsF90dyuqw== X-Received: by 2002:a05:6000:4305:b0:3a5:1266:3e96 with SMTP id ffacd0b85a97d-3a558695737mr3511529f8f.15.1749662574140; Wed, 11 Jun 2025 10:22:54 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich Subject: [PATCH 4/8] pdx: provide a unified set of unit functions Date: Wed, 11 Jun 2025 19:16:32 +0200 Message-ID: <20250611171636.5674-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662600427116600 The current setup (pdx_init_mask() and pdx_region_mask()) and init (pfn_pdx_hole_setup()) PDX compression functions are tailored to the existing PDX compression algorithm. In preparation for introducing a new compression algorithm convert the setup and init functions to more generic interfaces that aren't tied to the compression in-use. To accomplish this introduce a function that registers all the PFN RAM ranges, plus an init function. This has the downside of requiring a static array to store such ranges ahead of being processed by the setup function, however it's the only way to pass all the possible information to the different compression setup functions without using per-compression specific setup functions. Per-arch compression setup also need to be adjusted to use the new interface. There's a slight ordering adjustment, in that after PDX compression setup the caller will check whether all the RAM regions are properly covered by the newly setup compression, otherwise compression is disabled by resetting to the initial values. No functional change intended in the resulting PDX compression values. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/arm/setup.c | 34 ++++++------- xen/arch/x86/srat.c | 28 ++++++---- xen/common/pdx.c | 116 ++++++++++++++++++++++++++++++++++++------ xen/include/xen/pdx.h | 73 +++++++++----------------- 4 files changed, 160 insertions(+), 91 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 734e23da4408..93ebfc29635e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -255,6 +255,10 @@ void __init init_pdx(void) { const struct membanks *mem =3D bootinfo_get_mem(); paddr_t bank_start, bank_size, bank_end; + unsigned int bank; + + for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) + pfn_pdx_add_region(mem->bank[bank].start, mem->bank[bank].size); =20 /* * Arm does not have any restrictions on the bits to compress. Pass 0 = to @@ -263,28 +267,24 @@ void __init init_pdx(void) * If the logic changes in pfn_pdx_hole_setup we might have to * update this function too. */ - uint64_t mask =3D pdx_init_mask(0x0); - int bank; + pfn_pdx_compression_setup(0); =20 for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) { - bank_start =3D mem->bank[bank].start; - bank_size =3D mem->bank[bank].size; - - mask |=3D bank_start | pdx_region_mask(bank_start, bank_size); - } - - for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) - { - bank_start =3D mem->bank[bank].start; - bank_size =3D mem->bank[bank].size; - - if (~mask & pdx_region_mask(bank_start, bank_size)) - mask =3D 0; + if ( !pdx_is_region_compressible(mem->bank[bank].start, + PFN_UP(mem->bank[bank].start + mem->bank[bank].size) - + PFN_DOWN(mem->bank[bank].start)) ) + { + pfn_pdx_compression_reset(); + printk(XENLOG_WARNING + "PFN compression disabled, RAM region [%#" PRIpaddr ", = %#" + PRIpaddr "] not covered\n", + mem->bank[bank].start, + mem->bank[bank].start + mem->bank[bank].size - 1); + break; + } } =20 - pfn_pdx_hole_setup(mask >> PAGE_SHIFT); - for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) { bank_start =3D mem->bank[bank].start; diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 688f410287d4..7042fd3c3d88 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -261,8 +261,6 @@ acpi_numa_memory_affinity_init(const struct acpi_srat_m= em_affinity *ma) =20 void __init acpi_numa_arch_fixup(void) {} =20 -static uint64_t __initdata srat_region_mask; - static int __init cf_check srat_parse_region( struct acpi_subtable_header *header, const unsigned long end) { @@ -282,15 +280,13 @@ static int __init cf_check srat_parse_region( printk(KERN_INFO "SRAT: %013"PRIx64"-%013"PRIx64"\n", ma->base_address, ma->base_address + ma->length - 1); =20 - srat_region_mask |=3D ma->base_address | - pdx_region_mask(ma->base_address, ma->length); + pfn_pdx_add_region(ma->base_address, ma->length); =20 return 0; } =20 void __init srat_parse_regions(paddr_t addr) { - u64 mask; unsigned int i; =20 if (acpi_disabled || acpi_numa < 0 || @@ -299,19 +295,29 @@ void __init srat_parse_regions(paddr_t addr) =20 /* Set "PXM" as early as feasible. */ numa_fw_nid_name =3D "PXM"; - srat_region_mask =3D pdx_init_mask(addr); acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, srat_parse_region, 0); =20 - for (mask =3D srat_region_mask, i =3D 0; mask && i < e820.nr_map; i++) { + pfn_pdx_compression_setup(addr); + + /* Ensure all ranges in the e820 are covered. */ + for (i =3D 0; i < e820.nr_map; i++) { if (e820.map[i].type !=3D E820_RAM) continue; =20 - if (~mask & pdx_region_mask(e820.map[i].addr, e820.map[i].size)) - mask =3D 0; + if (!pdx_is_region_compressible(e820.map[i].addr, + PFN_UP(e820.map[i].addr + e820.map[i].size) - + PFN_DOWN(e820.map[i].addr))) + { + pfn_pdx_compression_reset(); + printk(XENLOG_WARNING + "PFN compression disabled, RAM region [%#" PRIx64 + ", %#" PRIx64 "] not covered\n", + e820.map[i].addr, + e820.map[i].addr + e820.map[i].size - 1); + return; + } } - - pfn_pdx_hole_setup(mask >> PAGE_SHIFT); } =20 unsigned int numa_node_to_arch_nid(nodeid_t n) diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 4843630bee7f..65b337860d52 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -19,6 +19,7 @@ #include #include #include +#include #include =20 /** @@ -80,6 +81,39 @@ unsigned long get_max_pfn(unsigned long top_pfn) return pdx_to_pfn(pdx - 1) + 1; } =20 +#ifndef CONFIG_PDX_NONE + +#ifdef CONFIG_X86 +# include +# define MAX_PFN_RANGES E820MAX +#elif defined(CONFIG_HAS_DEVICE_TREE) +# include +# define MAX_PFN_RANGES NR_MEM_BANKS +#else +# error "Missing architecture maximum number of RAM ranges" +#endif + +/* Generic PFN compression helpers. */ +static struct pfn_range { + unsigned long base, size; +} ranges[MAX_PFN_RANGES] __initdata; +static unsigned int __initdata nr; + +void __init pfn_pdx_add_region(paddr_t base, paddr_t size) +{ + if ( nr >=3D ARRAY_SIZE(ranges) ) + { + ASSERT((nr + 1) > nr); + nr++; + return; + } + + ranges[nr].base =3D PFN_DOWN(base); + ranges[nr++].size =3D PFN_UP(base + size) - PFN_DOWN(base); +} + +#endif /* !CONFIG_PDX_NONE */ + #ifdef CONFIG_PDX_MASK_COMPRESSION =20 /* @@ -140,20 +174,25 @@ static uint64_t fill_mask(uint64_t mask) return mask; } =20 -bool pdx_is_region_compressible(paddr_t base, unsigned long npages) -{ - return !(paddr_to_pfn(base) & pfn_hole_mask) && - !(pdx_region_mask(base, npages * PAGE_SIZE) & ~ma_va_bottom_mas= k); -} - -/* We don't want to compress the low MAX_ORDER bits of the addresses. */ -uint64_t __init pdx_init_mask(uint64_t base_addr) -{ - return fill_mask(max(base_addr, - (uint64_t)1 << (MAX_ORDER + PAGE_SHIFT)) - 1); -} - -uint64_t pdx_region_mask(uint64_t base, uint64_t len) +/** + * Calculates a mask covering "moving" bits of all addresses of a region + * + * The i-th bit of the mask must be set if there's 2 different addresses + * in the region that have different j-th bits. where j >=3D i. + * + * e.g: + * base=3D0x1B00000000 + * len+base=3D0x1B00042000 + * + * ought to return 0x000007FFFF, which implies that every bit position + * with a zero in the mask remains unchanged in every address of the + * region. + * + * @param base Base address of the region + * @param len Size in octets of the region + * @return Mask of moving bits at the bottom of all the region addresses + */ +static uint64_t pdx_region_mask(uint64_t base, uint64_t len) { /* * We say a bit "moves" in a range if there exist 2 addresses in that @@ -168,9 +207,46 @@ uint64_t pdx_region_mask(uint64_t base, uint64_t len) return fill_mask(base ^ (base + len - 1)); } =20 -void __init pfn_pdx_hole_setup(unsigned long mask) +bool pdx_is_region_compressible(paddr_t base, unsigned long npages) +{ + return !(paddr_to_pfn(base) & pfn_hole_mask) && + !(pdx_region_mask(base, npages * PAGE_SIZE) & ~ma_va_bottom_mas= k); +} + +/** + * Creates the mask to start from when calculating non-compressible bits + * + * This function is intimately related to pdx_region_mask(), and together + * they are meant to calculate the mask of non-compressible bits given the + * current memory map. + * + * @param base_addr Address of the first maddr in the system + * @return An integer of the form 2^n - 1 + */ +static uint64_t __init pdx_init_mask(uint64_t base_addr) +{ + return fill_mask(max(base_addr, + /* Don't compress the low MAX_ORDER bits. */ + (uint64_t)1 << (MAX_ORDER + PAGE_SHIFT)) - 1); +} + +void __init pfn_pdx_compression_setup(paddr_t base) { unsigned int i, j, bottom_shift =3D 0, hole_shift =3D 0; + unsigned long mask =3D pdx_init_mask(base); + + if ( nr > ARRAY_SIZE(ranges) ) + { + printk(XENLOG_WARNING + "Too many PFN ranges (%u), not attempting PFN compression\n= ", + nr); + return; + } + + for ( i =3D 0; i < nr; i++ ) + mask |=3D pfn_to_paddr(ranges[i].base) | + pdx_region_mask(pfn_to_paddr(ranges[i].base), + pfn_to_paddr(ranges[i].size)); =20 /* * We skip the first MAX_ORDER bits, as we never want to compress them. @@ -209,6 +285,16 @@ void __init pfn_pdx_hole_setup(unsigned long mask) ma_top_mask =3D pfn_top_mask << PAGE_SHIFT; } =20 +void __init pfn_pdx_compression_reset(void) +{ + pfn_pdx_bottom_mask =3D ~0UL; + ma_va_bottom_mask =3D ~0UL; + pfn_top_mask =3D 0; + ma_top_mask =3D 0; + pfn_hole_mask =3D 0; + pfn_pdx_hole_shift =3D 0; +} + #endif /* CONFIG_PDX_COMPRESSION */ =20 /* diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index ec0827936c2f..43ce36fcbb56 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -115,38 +115,6 @@ extern unsigned int pfn_pdx_hole_shift; extern unsigned long pfn_hole_mask; extern unsigned long pfn_top_mask, ma_top_mask; =20 -/** - * Calculates a mask covering "moving" bits of all addresses of a region - * - * The i-th bit of the mask must be set if there's 2 different addresses - * in the region that have different j-th bits. where j >=3D i. - * - * e.g: - * base=3D0x1B00000000 - * len+base=3D0x1B00042000 - * - * ought to return 0x000007FFFF, which implies that every bit position - * with a zero in the mask remains unchanged in every address of the - * region. - * - * @param base Base address of the region - * @param len Size in octets of the region - * @return Mask of moving bits at the bottom of all the region addresses - */ -uint64_t pdx_region_mask(uint64_t base, uint64_t len); - -/** - * Creates the mask to start from when calculating non-compressible bits - * - * This function is intimately related to pdx_region_mask(), and together - * they are meant to calculate the mask of non-compressible bits given the - * current memory map. - * - * @param base_addr Address of the first maddr in the system - * @return An integer of the form 2^n - 1 - */ -uint64_t pdx_init_mask(uint64_t base_addr); - /** * Map pfn to its corresponding pdx * @@ -196,17 +164,6 @@ static inline paddr_t directmapoff_to_maddr(unsigned l= ong offset) (offset & ma_va_bottom_mask)); } =20 -/** - * Initializes global variables with information about the compressible - * range of the current memory regions. - * - * @param mask This mask is the biggest pdx_mask of every region in the - * system ORed with all base addresses of every region in the - * system. This results in a mask where every zero in a bit - * position marks a potentially compressible bit. - */ -void pfn_pdx_hole_setup(unsigned long mask); - #endif /* CONFIG_PDX_MASK_COMPRESSION */ =20 #ifdef CONFIG_PDX_NONE @@ -227,17 +184,15 @@ static inline bool pdx_is_region_compressible(paddr_t= base, return true; } =20 -static inline uint64_t pdx_init_mask(uint64_t base_addr) +static inline void pfn_pdx_add_region(paddr_t base, paddr_t size) { - return 0; } =20 -static inline uint64_t pdx_region_mask(uint64_t base, uint64_t len) +static inline void pfn_pdx_compression_setup(paddr_t base) { - return 0; } =20 -static inline void pfn_pdx_hole_setup(unsigned long mask) +static inline void pfn_pdx_compression_reset(void) { } =20 @@ -254,6 +209,28 @@ static inline void pfn_pdx_hole_setup(unsigned long ma= sk) */ bool pdx_is_region_compressible(paddr_t base, unsigned long npages); =20 +/** + * Register a RAM region with the PFN compression logic. + * + * @param base Start of the region in bytes. + * @param size Length of the region in bytes. + */ +void pfn_pdx_add_region(paddr_t base, paddr_t size); + +/** + * Initializes global variables with information about the compressible + * range of the current memory regions. + * + * @param base address to start compression from. + */ +void pfn_pdx_compression_setup(paddr_t base); + +/** + * Reset the global variables to it's default values, thus disabling PFN + * compression. + */ +void pfn_pdx_compression_reset(void); + #endif /* !CONFIG_PDX_NONE */ #endif /* __XEN_PDX_H__ */ =20 --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662591; cv=none; d=zohomail.com; s=zohoarc; b=E80HsIPy03Si3Ftx5CNsdOyjdH03NKyqD9+CvN7bXLELYHFWDN0UloITqItT/QEqBMpz4IpAjAMrZH/Hl0AOkAw9hBw4S2lUBBZ+mmlJTDK9I/YXmYJrEx+iCDidRc3vhNBfzenOPj3jTFoGIpsWsalmOdpQgbj8B5lVpHD7Rrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662591; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jkTPtYu2X1Hla12Ld0GVwhz+81hY0W8JQvDMWI2yhDk=; b=LgmfP00gBQe/CntK8tvtDcf2dVqIThyO2Sr57uXzjUKJc32hoyBVBdQnmDTDDGSlFS5YKleSTwHi0AQ/OcbCfx+4mLTZxmUBM9C6ZJLvw/cYBvBpNKhnP/SZVPGtmh4TpU+I+L2Q/3AnKTIPJ/Q8gXup+npETBMPQvI9zSGPxW8= 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 1749662591194461.3401759741049; Wed, 11 Jun 2025 10:23:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011970.1390512 (Exim 4.92) (envelope-from ) id 1uPPA9-0003RN-VW; Wed, 11 Jun 2025 17:22:57 +0000 Received: by outflank-mailman (output) from mailman id 1011970.1390512; Wed, 11 Jun 2025 17:22:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPA9-0003OW-QT; Wed, 11 Jun 2025 17:22:57 +0000 Received: by outflank-mailman (input) for mailman id 1011970; Wed, 11 Jun 2025 17:22:56 +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 1uPPA8-0002dK-Pt for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:56 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b6e638a8-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:56 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43ea40a6e98so187125e9.1 for ; Wed, 11 Jun 2025 10:22:56 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45325140f30sm27011275e9.4.2025.06.11.10.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:54 -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: b6e638a8-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662576; x=1750267376; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jkTPtYu2X1Hla12Ld0GVwhz+81hY0W8JQvDMWI2yhDk=; b=H1cO+EFHPnUAvJqxaZgqjQXsXP+W7zaO4cxvrpk48TyC79tFX1LAT03qHluFl/9TIi gDFiBmnIUlLDV/QJfXvlv416DEgjr/+nO9CJEq8R6Nt8rN8wfj7AU55Hv1i6ibwrCGFz RywfFDGMfOUXY7r7hOvfWuVNUOukTPwj1V3GE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662576; x=1750267376; 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=jkTPtYu2X1Hla12Ld0GVwhz+81hY0W8JQvDMWI2yhDk=; b=tkbVb8KaXi4wRFHT/uGGqqFdTvj1w80JcS+P7wxxK3hLNZBR1Tlg7Oo1sP5u+JdhyM RvK4YN0TCKVOBkY7zscuOxUWqMe9Dwh1SDF/5FQuC7/hwNT3Ixj2gQQae4Bb26h4L4yG A6rTkTfC4mDWsRDKoJzs9SxWlRGWMjr/ozd4YjkhuCInCkX/kDVAuHhOOhTvM23WI525 B0fb5ircdYz5mQzBBE/tMsInTwT+J6FYz/mN9WrAtSob9T5nuTku4OybnS9Zxx3yY+uY Nk6yfU6v3hsdqDabcJNxVCdnXw94H3WHl3LDp2pJDCMrD7PRMo2hrEr/YOP0Pa8k7ivG 9mjQ== X-Gm-Message-State: AOJu0Yx1oCfNYyczvPkcZhkLro6SnWGUBNIU3KHPOldZOQXJM1zsCp/j eUN+Dt2kr0WmO6pVybtBoilaDJpYuRjfPSjPoFuONuSa98ZE22lnBkqdbPx+LSsHZFFUczQe0iO 2up1d X-Gm-Gg: ASbGncslyyvXda86BjKlVJdPoiqyM9jeKyus40ZhTgh3krC4shNt/83S2tTCSZI//Nh Xz9QHZPnCimZ0c3e1od9ibyt9GedfwgxAdCii4QzbtFyXHhvaAIW8nEHS8boz8oOM2/zPe0ueVB CdyslVefxltNvMXSdtnFD32zu+mNVgCHEGoadgQMb7xbnXsx0jdiE3QN59YmPhfm0YNdmiWwfOY +/5zcPxvwoC2ekyUdHPMbpBGVMsKuaoQAbi9VOS42dL7x9bFA5sn60Z0naR/8AjiNI96s/fJxSo BPBUkDZs/woIJBskafBj8piSNJHi0/BCQAKs1ayVIE1hrPOIcEuADHkYOpQw86nSy1gXtTbKc8p xojtPLo/p49GxKwie7NAt90Rkkbd54I8FNgo= X-Google-Smtp-Source: AGHT+IFgWT4jERhURBaaV7IdOzOpS71w3ZR8cxBZ+PefDGAyZ0K/1TK/B1CrOfEVgzsBOCjtRAmCGA== X-Received: by 2002:a05:600c:4f06:b0:453:608:a18b with SMTP id 5b1f17b1804b1-4532b28d858mr8680555e9.9.1749662575471; Wed, 11 Jun 2025 10:22:55 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [PATCH 5/8] pdx: allow optimizing PDX conversion helpers Date: Wed, 11 Jun 2025 19:16:33 +0200 Message-ID: <20250611171636.5674-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662592265116600 There are four performance critical PDX conversion helpers that do the PFN to/from PDX and the physical addresses to/from directmap offsets translations. In the absence of an active PDX compression, those functions would still do the calculations needed, just to return the same input value as no translation is in place and hence PFN and PDX spaces are identity mapped. To reduce the overhead of having to do the pointless calculations allow architectures to short-circuit the logic by providing a macro. Implement such short-circuiting for x86 using asm goto and alternatives. This results in the optimized case (when PDX compression is not enabled) doing an unconditional jump to a label, while the non-optimized case is left as-is. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/arch/x86/include/asm/cpufeatures.h | 1 + xen/arch/x86/srat.c | 6 +++- xen/common/pdx.c | 8 +++-- xen/include/xen/pdx.h | 46 ++++++++++++++++++++------ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/include/asm/cpufeatures.h b/xen/arch/x86/include/= asm/cpufeatures.h index 9e3ed21c026d..85e1a6f0a055 100644 --- a/xen/arch/x86/include/asm/cpufeatures.h +++ b/xen/arch/x86/include/asm/cpufeatures.h @@ -43,6 +43,7 @@ XEN_CPUFEATURE(XEN_IBT, X86_SYNTH(27)) /* Xen u= ses CET Indirect Branch XEN_CPUFEATURE(IBPB_ENTRY_PV, X86_SYNTH(28)) /* MSR_PRED_CMD used by X= en for PV */ XEN_CPUFEATURE(IBPB_ENTRY_HVM, X86_SYNTH(29)) /* MSR_PRED_CMD used by X= en for HVM */ XEN_CPUFEATURE(USE_VMCALL, X86_SYNTH(30)) /* Use VMCALL instead of = VMMCALL */ +XEN_CPUFEATURE(PDX_COMPRESSION, X86_SYNTH(31)) /* PDX compression */ =20 /* Bug words follow the synthetic words. */ #define X86_NR_BUG 1 diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 7042fd3c3d88..96a87bbce35b 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -298,7 +298,8 @@ void __init srat_parse_regions(paddr_t addr) acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, srat_parse_region, 0); =20 - pfn_pdx_compression_setup(addr); + if (!pfn_pdx_compression_setup(addr)) + return; =20 /* Ensure all ranges in the e820 are covered. */ for (i =3D 0; i < e820.nr_map; i++) { @@ -318,6 +319,9 @@ void __init srat_parse_regions(paddr_t addr) return; } } + + /* If we got this far compression is working as expected. */ + setup_force_cpu_cap(X86_FEATURE_PDX_COMPRESSION); } =20 unsigned int numa_node_to_arch_nid(nodeid_t n) diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 65b337860d52..7d14100224fe 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -230,7 +230,7 @@ static uint64_t __init pdx_init_mask(uint64_t base_addr) (uint64_t)1 << (MAX_ORDER + PAGE_SHIFT)) - 1); } =20 -void __init pfn_pdx_compression_setup(paddr_t base) +bool __init pfn_pdx_compression_setup(paddr_t base) { unsigned int i, j, bottom_shift =3D 0, hole_shift =3D 0; unsigned long mask =3D pdx_init_mask(base); @@ -240,7 +240,7 @@ void __init pfn_pdx_compression_setup(paddr_t base) printk(XENLOG_WARNING "Too many PFN ranges (%u), not attempting PFN compression\n= ", nr); - return; + return false; } =20 for ( i =3D 0; i < nr; i++ ) @@ -272,7 +272,7 @@ void __init pfn_pdx_compression_setup(paddr_t base) } } if ( !hole_shift ) - return; + return false; =20 printk(KERN_INFO "PFN compression on bits %u...%u\n", bottom_shift, bottom_shift + hole_shift - 1); @@ -283,6 +283,8 @@ void __init pfn_pdx_compression_setup(paddr_t base) pfn_hole_mask =3D ((1UL << hole_shift) - 1) << bottom_shift; pfn_top_mask =3D ~(pfn_pdx_bottom_mask | pfn_hole_mask); ma_top_mask =3D pfn_top_mask << PAGE_SHIFT; + + return true; } =20 void __init pfn_pdx_compression_reset(void) diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 43ce36fcbb56..6cc0f54cff83 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -67,6 +67,26 @@ * region involved. */ =20 +/* Macro defined per-arch to skip PDX logic when there's no compression. */ +#ifdef CONFIG_X86 +# include + +# define OPTIMIZE_PDX(transform, raw) \ + asm_inline goto ( \ + ALTERNATIVE( \ + "", \ + "jmp %l[skip]", \ + ALT_NOT(X86_FEATURE_PDX_COMPRESSION)) \ + : : : : skip ); \ + return (transform); \ + \ + skip: \ + return (raw) +#else +# define OPTIMIZE_PDX(transform, raw) \ + return (transform) +#endif + extern unsigned long max_pdx; =20 #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ @@ -123,8 +143,9 @@ extern unsigned long pfn_top_mask, ma_top_mask; */ static inline unsigned long pfn_to_pdx(unsigned long pfn) { - return (pfn & pfn_pdx_bottom_mask) | - ((pfn & pfn_top_mask) >> pfn_pdx_hole_shift); + OPTIMIZE_PDX((pfn & pfn_pdx_bottom_mask) | + ((pfn & pfn_top_mask) >> pfn_pdx_hole_shift), + pfn); } =20 /** @@ -135,8 +156,9 @@ static inline unsigned long pfn_to_pdx(unsigned long pf= n) */ static inline unsigned long pdx_to_pfn(unsigned long pdx) { - return (pdx & pfn_pdx_bottom_mask) | - ((pdx << pfn_pdx_hole_shift) & pfn_top_mask); + OPTIMIZE_PDX((pdx & pfn_pdx_bottom_mask) | + ((pdx << pfn_pdx_hole_shift) & pfn_top_mask), + pdx); } =20 /** @@ -148,8 +170,9 @@ static inline unsigned long pdx_to_pfn(unsigned long pd= x) */ static inline unsigned long maddr_to_directmapoff(paddr_t ma) { - return (((ma & ma_top_mask) >> pfn_pdx_hole_shift) | - (ma & ma_va_bottom_mask)); + OPTIMIZE_PDX(((ma & ma_top_mask) >> pfn_pdx_hole_shift) | + (ma & ma_va_bottom_mask), + ma); } =20 /** @@ -160,8 +183,9 @@ static inline unsigned long maddr_to_directmapoff(paddr= _t ma) */ static inline paddr_t directmapoff_to_maddr(unsigned long offset) { - return ((((paddr_t)offset << pfn_pdx_hole_shift) & ma_top_mask) | - (offset & ma_va_bottom_mask)); + OPTIMIZE_PDX(((((paddr_t)offset << pfn_pdx_hole_shift) & ma_top_mask) | + (offset & ma_va_bottom_mask)), + offset); } =20 #endif /* CONFIG_PDX_MASK_COMPRESSION */ @@ -188,8 +212,9 @@ static inline void pfn_pdx_add_region(paddr_t base, pad= dr_t size) { } =20 -static inline void pfn_pdx_compression_setup(paddr_t base) +static inline bool pfn_pdx_compression_setup(paddr_t base) { + return false; } =20 static inline void pfn_pdx_compression_reset(void) @@ -222,8 +247,9 @@ void pfn_pdx_add_region(paddr_t base, paddr_t size); * range of the current memory regions. * * @param base address to start compression from. + * @return True if PDX compression has been enabled. */ -void pfn_pdx_compression_setup(paddr_t base); +bool pfn_pdx_compression_setup(paddr_t base); =20 /** * Reset the global variables to it's default values, thus disabling PFN --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662602; cv=none; d=zohomail.com; s=zohoarc; b=lqzRQSwZsaCc8PJC0lkwvmVYRSo6v4NsU1dR6FLNikf8DljuLbsOt7MLEXJ8WG0SpYTMvzsq7e4gLXyKUTRw/Ut6TqRpjWapCGaMSbPMi8BxFefQtDjvohIiONc47Av81g8xff0MBwRWKtZQ6h83PaCUzkhpf8Zx/CHwrzJfnng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662602; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=obTz8sNg81B0kZWShjd1UWWyGzjIKb4UunTkiMwCARY=; b=TwPZ+VjgVSMurpdQ5hpIy1xfoJOvEvtTdCwOcG1x1zYTJViXA6bFzE5MjH2Xqwgib6Og1pW3Tvzfydbsu+skpLzq/5L9mFp2J//iwfJZgW+A4QYSD24pzB1dOFMk/HGnqXAz5rZiQXwGvE7WFh2e5lvkDWosip+Te9oSu2MLkrk= 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 1749662602222432.59134818129735; Wed, 11 Jun 2025 10:23:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011971.1390526 (Exim 4.92) (envelope-from ) id 1uPPAC-0003qD-6g; Wed, 11 Jun 2025 17:23:00 +0000 Received: by outflank-mailman (output) from mailman id 1011971.1390526; Wed, 11 Jun 2025 17:23:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPAC-0003q1-2w; Wed, 11 Jun 2025 17:23:00 +0000 Received: by outflank-mailman (input) for mailman id 1011971; Wed, 11 Jun 2025 17:22:58 +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 1uPPAA-0002dK-NW for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:58 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b805d6f6-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:58 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-442e9c00bf4so66455e9.3 for ; Wed, 11 Jun 2025 10:22:58 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45325228c2esm27826355e9.37.2025.06.11.10.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:56 -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: b805d6f6-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662577; x=1750267377; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=obTz8sNg81B0kZWShjd1UWWyGzjIKb4UunTkiMwCARY=; b=oXiDAi/31IbPs52B+ZJe6Pa/db+D4Mrq14kh3g9pI2mnY0f6mq6CoXm1yUpi+f6Jwa ZrnH44VRLBx1dNP/S63fIVa03EkGl+JEf1lnE9eF/jx5kDiGVPArkIkFxbkLAs7iKprJ 6c7h/l1r++1i5UdB7wwq/PULluBo6/R1qOkUQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662577; x=1750267377; 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=obTz8sNg81B0kZWShjd1UWWyGzjIKb4UunTkiMwCARY=; b=MccZpVk+UrhxYAkoM3jZmcluvb162SF8CCACN2zchDNoUDnCwcITI835u4QjZQVEg5 WQmo97gRd/JXCYwEbVF13G+7UVQmmtq0bSai1gP2IJRpNMocWYvpbHzxMKnCZhB8rlYM peJMZrAYR2KYHB4nscn85iH8VLmHxgvJW7MKdlFHpHOWIA7fufTcvqjlTxEup0BTvGy1 4pYT3RKaPfRh/x1XRAO+8PAlogYja73n8wuYnmBblHYeXG6AEVHEu4ehIOUzC2ESOjFY O6fbzfsvxU+mpc9J8FSh7wcQsCUZEbFaVlhDQeJSplN8EX1eWzH+GuMsdl2uB/vgEjYE RniA== X-Gm-Message-State: AOJu0Yxbe5DSkrOxx4E0EJ2YUpS/h99sG6pXNzPfejDknfBeXpvHrw8l kCtCZnkBTxCXpEKKW8JSGSOETWk4tve04eKHBmrWmQq6fDC/FFbktoqIuSE1U7DHf2OtJHy9tUL lHmff X-Gm-Gg: ASbGncuI5bi+v7nx4JphK9qOD1/G4/5JVlNxgf3R/4Zct7+Xs7nyGczjphQcMg+FyJB 89pYocAxJjNb8TICguclCKG79Jh1JOcs/TaQS0w7EqE1Z2XEVz/34a28/YNEZpJIIgA6kBoPdJ/ zaGfgJwKIId+USBM8lHsQYugxb30CVXOqap+tm1vdq0fAzBeZn/pcLvlqsOCKTE28zGSVtUF3Lo qQ4WK8gUKWweRFYo5kxfd9RWtGVgCXx6YlfnRPVo7ODgd2RKKUEBrFGZRcAFw4KYuyW7w/fUo5r GdZr7Ue2WKwflrGI7hj2Lq2nko1Uj2w2/YtP3TJsNnskfVGewILY3w9nKFUhzUp8GTSf1/mEc2h UUDfK6LclV4lUoycx4IqHjY6CsCIjN7yD6vA8isDDz77OBw== X-Google-Smtp-Source: AGHT+IEKUs16PXyfT6xB9xcCuFwTvKq0tDdieJnf5nDjt0WbGz7eLEcC6NTeRzeRL8WjKfPSmY7HqQ== X-Received: by 2002:a05:600c:8418:b0:43c:fd27:a216 with SMTP id 5b1f17b1804b1-4532b91ee36mr6380175e9.23.1749662577174; Wed, 11 Jun 2025 10:22:57 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Anthony PERARD , Andrew Cooper , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 6/8] pdx: introduce a new compression algorithm based on offsets between regions Date: Wed, 11 Jun 2025 19:16:34 +0200 Message-ID: <20250611171636.5674-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662604625116600 With the appearance of Intel Sierra Forest and Granite Rapids it's not possible to get a production x86 host wit the following memory map: SRAT: Node 0 PXM 0 [0000000000000000, 000000007fffffff] SRAT: Node 0 PXM 0 [0000000100000000, 000000407fffffff] SRAT: Node 1 PXM 1 [0000061e80000000, 0000065e7fffffff] SRAT: Node 2 PXM 2 [00000c3e80000000, 00000c7e7fffffff] SRAT: Node 3 PXM 3 [0000125e80000000, 0000129e7fffffff] This is from a four socket system, with each node having 256GB of memory. The total amount of RAM on the system is 1TB, but without enabling CONFIG_BIGMEM the last range is not accessible, as it's above the 16TB boundary covered by the frame table. Note that while the memory map is very sparse, it won't be compressible using the current algorithm that relies on all ranges having a shared zeroed region of bits that can be removed. The memory map presented above has the property of all regions being similarly spaced between each other, and all having also a similar size. This allows to compress them using the following formula: pdx =3D (pfn % offset) + ((pfn / offset) * size) Where offset and size are two static coefficients calculated at initialization. Obtaining the optimum offset and size coefficients is the complicated part. In this patch I introduce two different algorithms, a fast one that works correctly when the offset and size between ranges is mostly equal. If such fast algorithm doesn't work, or the resulting compression is not enough to avoid truncation of the maximum usable page, it's possible to attempt a brute force approach for calculating the coefficients. This is also implemented in this patch as the slow variant. I've attempted to restrict the number of iterations in the slow approach so it can exit early if no better coefficients can be found due to the input constrains (minimum region size). The patch here focuses on introducing the logic to calculate the compression coefficients, plus adding a unit test to exercise the logic easily from user-space in order to test different layouts and possibly improve the generation of the coefficients. The added unit tests only covers the newly added compression, but could also be extended to cover the existing PDX mask compression. Note the translation functions (pfn to pdx, maddr to direct map offset), are not implemented as part of this patch, an identity set of macros are added to satisfy the build requirements. The patch is already long enough without those. Signed-off-by: Roger Pau Monn=C3=A9 --- We can discuss whether we want both the fast and the slow variants. The slow (brute force) was added as a result of me playing with weird region layouts where the fast one didn't manage to compress, or the resulting coefficients had a poor compression ratio. However at this point the slow variant has only proven helpful in synthetic cases, I haven't (yet?) seen a real host memory layout that would benefit from it. --- tools/tests/Makefile | 1 + tools/tests/pdx/.gitignore | 3 + tools/tests/pdx/Makefile | 54 ++++++ tools/tests/pdx/harness.h | 73 +++++++ tools/tests/pdx/test-pdx-offset.c | 310 ++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 2 +- xen/arch/x86/srat.c | 2 +- xen/common/Kconfig | 9 +- xen/common/pdx.c | 232 +++++++++++++++++++++- xen/include/xen/pdx.h | 46 ++++- 10 files changed, 724 insertions(+), 8 deletions(-) create mode 100644 tools/tests/pdx/.gitignore create mode 100644 tools/tests/pdx/Makefile create mode 100644 tools/tests/pdx/harness.h create mode 100644 tools/tests/pdx/test-pdx-offset.c diff --git a/tools/tests/Makefile b/tools/tests/Makefile index 36928676a666..97ba2a13894d 100644 --- a/tools/tests/Makefile +++ b/tools/tests/Makefile @@ -9,6 +9,7 @@ ifneq ($(clang),y) SUBDIRS-$(CONFIG_X86) +=3D x86_emulator endif SUBDIRS-y +=3D xenstore +SUBDIRS-y +=3D pdx SUBDIRS-y +=3D rangeset SUBDIRS-y +=3D vpci SUBDIRS-y +=3D paging-mempool diff --git a/tools/tests/pdx/.gitignore b/tools/tests/pdx/.gitignore new file mode 100644 index 000000000000..21b60480415a --- /dev/null +++ b/tools/tests/pdx/.gitignore @@ -0,0 +1,3 @@ +/pdx-offset.c +/pdx.h +/test-pdx-offset diff --git a/tools/tests/pdx/Makefile b/tools/tests/pdx/Makefile new file mode 100644 index 000000000000..141ae6aab56f --- /dev/null +++ b/tools/tests/pdx/Makefile @@ -0,0 +1,54 @@ +XEN_ROOT=3D$(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +TARGET :=3D test-pdx-offset + +.PHONY: all +all: $(TARGET) + +.PHONY: run +run: $(TARGET) +ifeq ($(CC),$(HOSTCC)) + ./$< +else + $(warning HOSTCC !=3D CC, will not run test) +endif + +.PHONY: clean +clean: + $(RM) -- *.o $(TARGET) $(DEPS_RM) pdx.c pdx.h + +.PHONY: distclean +distclean: clean + $(RM) -- *~ + +.PHONY: install +install: all + $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests + $(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests + +.PHONY: uninstall +uninstall: + $(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET) + +pdx.h: $(XEN_ROOT)/xen/include/xen/pdx.h + sed -E -e '/^#[[:space:]]?include/d' <$< >$@ + +pdx-offset.c: $(XEN_ROOT)/xen/common/pdx.c + # Remove includes/errors and add the test harness header + sed -E -e '/#[[:space:]]?include/d' -e '/^#[[:space:]]?error/d' \ + -e '1s/^/#include "harness.h"/' <$< >$@ + +CFLAGS +=3D -D__XEN_TOOLS__ +CFLAGS +=3D $(APPEND_CFLAGS) +CFLAGS +=3D $(CFLAGS_xeninclude) + +LDFLAGS +=3D $(APPEND_LDFLAGS) + +test-pdx-offset.o pdx-offset.o: pdx.h +test-pdx-offset.o pdx-offset.o: CFLAGS +=3D -DCONFIG_PDX_OFFSET_COMPRESSION + +test-pdx-offset: pdx-offset.o test-pdx-offset.o + $(CC) $^ -o $@ $(LDFLAGS) + +-include $(DEPS_INCLUDE) diff --git a/tools/tests/pdx/harness.h b/tools/tests/pdx/harness.h new file mode 100644 index 000000000000..3d31cf488daf --- /dev/null +++ b/tools/tests/pdx/harness.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Unit tests for PDX compression. + * + * Copyright (C) 2025 Cloud Software Group + */ + +#ifndef _TEST_HARNESS_ +#define _TEST_HARNESS_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +void pdx_reset(void); + +#define __init +#define __initdata +#define __ro_after_init +#define cf_check + +#define printk printf +#define dprintk(lvl, ...) printf(__VA_ARGS__) +#define XENLOG_INFO +#define XENLOG_DEBUG +#define XENLOG_WARNING + +#define PAGE_SHIFT 12 +/* Some libcs define PAGE_SIZE in limits.h. */ +#undef PAGE_SIZE +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define MAX_ORDER 18 /* 2 * PAGETABLE_ORDER (9) */ + +#define PFN_DOWN(x) ((x) >> PAGE_SHIFT) +#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> PAGE_SHIFT) + +#define MAX_RANGES 8 +#define MAX_PFN_RANGES MAX_RANGES + +#define ASSERT assert +#define ASSERT_UNREACHABLE() assert(0); + +#define STATIC +typedef uint64_t paddr_t; + +bool pfn_offset_calculate_fast(unsigned long base); +bool pfn_offset_calculate_slow(unsigned long base); +void pfn_offset_sanitize_ranges(void); + +#define sort(elem, nr, size, cmp, swp) { \ + /* Consume swp() so compiler doesn't complain it's unused. */ \ + swp(&elem[0], &elem[0], size); \ + qsort(elem, nr, size, cmp); \ +} + +#include "pdx.h" + +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/tests/pdx/test-pdx-offset.c b/tools/tests/pdx/test-pdx-o= ffset.c new file mode 100644 index 000000000000..0a561f02d197 --- /dev/null +++ b/tools/tests/pdx/test-pdx-offset.c @@ -0,0 +1,310 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Unit tests for PDX offset compression. + * + * Copyright (C) 2025 Cloud Software Group + */ + +#include "harness.h" + +struct range { + /* Ranges are defined as [start, end). */ + unsigned long start, end; +}; + +static void print_ranges(const struct range *r) +{ + unsigned int i; + + printf("Ranges:\n"); + + for ( i =3D 0; i < MAX_RANGES; i++ ) + { + if ( !r[i].start && !r[i].end ) + break; + + printf(" %013lx-%013lx\n", r[i].start, r[i].end); + } +} + +int main(int argc, char **argv) +{ + static const struct { + struct range ranges[MAX_RANGES]; + struct result { + bool compress; + unsigned long offset, size; + } results[2]; +#define FAST_IDX 0 +#define SLOW_IDX 1 + } tests[] =3D { +#ifdef __LP64__ + /* + * Only for targets where unsigned long is 64bits, otherwise compi= ler + * will complain about truncation from 'long long' -> 'long' conve= rsion. + * + * Real memory map from a 4s Intel GNR. + */ + { + .ranges =3D { + { .start =3D 0, .end =3D 0x8080000UL }, + { .start =3D 0x63e80000UL, .end =3D 0x6be80000UL }, + { .start =3D 0xc7e80000UL, .end =3D 0xcfe80000UL }, + { .start =3D 0x12be80000UL, .end =3D 0x133e80000UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D true, + .offset =3D 0x63e80000UL, + .size =3D 0x8300000UL, + }, + }, + }, +#endif + /* 2-node 2GB per-node QEMU layout. */ + { + .ranges =3D { + { .start =3D 0, .end =3D 0x80000UL }, + { .start =3D 0x100000UL, .end =3D 0x180000UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D true, + .offset =3D 0x100000UL, + .size =3D 0x80000UL, + }, + }, + }, + /* Not compressible, offset < size. */ + { + .ranges =3D { + { .start =3D 0, .end =3D 1 }, + { .start =3D 1, .end =3D 0x10UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D false, + }, + }, + }, + /* Not compressible, offset < (1 << MAX_ORDER). */ + { + .ranges =3D { + { .start =3D 0, .end =3D 1 }, + { .start =3D 0x100UL, .end =3D 0x101UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D false, + }, + }, + }, + /* Compressible, requires adjusting size to (1 << MAX_ORDER). */ + { + .ranges =3D { + { .start =3D 0, .end =3D 1 }, + { .start =3D 0x100000UL, .end =3D 0x100001UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D true, + .offset =3D 0x100000UL, + .size =3D (1UL << MAX_ORDER), + }, + }, + }, + /* 2s Intel CLX with contiguous ranges, no compression. */ + { + .ranges =3D { + { .start =3D 0 , .end =3D 0x180000UL }, + { .start =3D 0x180000UL, .end =3D 0x3040000UL }, + }, + .results =3D { + /* Same result with both fast and slow algorithms. */ + [FAST_IDX ... SLOW_IDX] =3D { + .compress =3D false, + }, + }, + }, + /* Middle range is bigger than first and last */ + { + .ranges =3D { + { .start =3D 0, .end =3D 1 }, + { .start =3D 0x100000UL, .end =3D 0x180000UL }, + { .start =3D 0x1000000UL, .end =3D 0x1000001UL }, + }, + .results =3D { + [FAST_IDX] =3D { + .compress =3D true, + .offset =3D 0x100000UL, + .size =3D 0x80000UL, + }, + [SLOW_IDX] =3D { + .compress =3D true, + .offset =3D 0xf00000UL, + .size =3D 0x180000UL, + }, + }, + }, + /* Test divergence between fast and slow algorithms. */ + { + .ranges =3D { + { .start =3D 0, + .end =3D (1 << MAX_ORDER) * 1 }, + { .start =3D (1 << MAX_ORDER) * 11, + .end =3D (1 << MAX_ORDER) * 12 }, + { .start =3D (1 << MAX_ORDER) * 20, + .end =3D (1 << MAX_ORDER) * 21 }, + }, + .results =3D { + [FAST_IDX] =3D { /* 66% */ + .compress =3D true, + .offset =3D (1 << MAX_ORDER) * 9, + .size =3D (1 << MAX_ORDER) * 3, + }, + [SLOW_IDX] =3D { /* 80% */ + .compress =3D true, + .offset =3D (1 << MAX_ORDER) * 10, + .size =3D (1 << MAX_ORDER) * 2, + }, + }, + }, + /* Test divergence between fast and slow algorithms. */ + { + .ranges =3D { + { .start =3D 0, + .end =3D (1 << MAX_ORDER) * 1 }, + { .start =3D (1 << MAX_ORDER) * 11, + .end =3D (1 << MAX_ORDER) * 12 }, + { .start =3D (1 << MAX_ORDER) * 30, + .end =3D (1 << MAX_ORDER) * 31 }, + }, + .results =3D { + [FAST_IDX] =3D { /* 18% */ + .compress =3D true, + .offset =3D (1 << MAX_ORDER) * 11, + .size =3D (1 << MAX_ORDER) * 9, + }, + [SLOW_IDX] =3D { /* 80% */ + .compress =3D true, + .offset =3D (1 << MAX_ORDER) * 10, + .size =3D (1 << MAX_ORDER) * 2, + }, + }, + }, + /* Test incompressible using fast vs compressible using slow. */ + { + .ranges =3D { + { .start =3D 0, + .end =3D (1 << MAX_ORDER) * 1 }, + { .start =3D (1 << MAX_ORDER) * 2, + .end =3D (1 << MAX_ORDER) * 3 }, + { .start =3D (1 << MAX_ORDER) * 20, + .end =3D (1 << MAX_ORDER) * 22 }, + }, + .results =3D { + [FAST_IDX] =3D { + .compress =3D false, + }, + [SLOW_IDX] =3D { + .compress =3D true, + .offset =3D (1 << MAX_ORDER) * 18, + .size =3D (1 << MAX_ORDER) * 4, + }, + }, + }, + }; + int ret_code =3D EXIT_SUCCESS; + + for ( unsigned int i =3D 0 ; i < ARRAY_SIZE(tests); i++ ) + { + for ( unsigned int use_slow =3D 0; + use_slow < ARRAY_SIZE(tests[i].results); use_slow++ ) + { + const struct result *result =3D &tests[i].results[use_slow]; + unsigned int j; + + pfn_pdx_compression_reset(); + + for ( j =3D 0; j < ARRAY_SIZE(tests[i].ranges); j++ ) + { + unsigned long size =3D tests[i].ranges[j].end - + tests[i].ranges[j].start; + + if ( !tests[i].ranges[j].start && !tests[i].ranges[j].end ) + break; + + pfn_pdx_add_region(tests[i].ranges[j].start << PAGE_SHIFT, + size << PAGE_SHIFT, j); + } + + pfn_offset_sanitize_ranges(); + + if ( result->compress !=3D (use_slow ? pfn_offset_calculate_sl= ow(0) + : pfn_offset_calculate_fast= (0)) ) + { + printf("PFN %s compression diverge, expected %scompressibl= e\n", + use_slow ? "slow" : "fast", + result->compress ? "" : "un"); + print_ranges(tests[i].ranges); + + ret_code =3D EXIT_FAILURE; + continue; + } + + if ( !result->compress ) + continue; + + if ( result->offset !=3D pdx_offset || result->size !=3D pdx_s= ize ) + { + printf("PFN %s compression result diverge, expected:\n", + use_slow ? "slow" : "fast"); + printf(" offset %013lx size %013lx (%lu%%)\n", + result->offset, result->size, + ((result->offset - result->size) * 100) / result->o= ffset); + printf("got:\n offset %013lx size %013lx (%lu%%)\n", + pdx_offset, pdx_size, + ((pdx_offset - pdx_size) * 100) / pdx_offset); + print_ranges(tests[i].ranges); + + ret_code =3D EXIT_FAILURE; + continue; + } + + for ( j =3D 0; j < ARRAY_SIZE(tests[i].ranges); j++ ) + { + unsigned long start =3D tests[i].ranges[j].start; + unsigned long end =3D tests[i].ranges[j].end; + + if ( !start && !end ) + break; + + if ( !pdx_is_region_compressible(start << PAGE_SHIFT, 1) || + !pdx_is_region_compressible((end - 1) << PAGE_SHIFT, = 1) ) + { + printf( + "PFN %s compression invalid, pages %#lx and %#lx should be compressibl= e\n", + use_slow ? "slow" : "fast", start, end - 1); + print_ranges(tests[i].ranges); + ret_code =3D EXIT_FAILURE; + } + } + } + } + + return ret_code; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 93ebfc29635e..e71908b99c14 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -258,7 +258,7 @@ void __init init_pdx(void) unsigned int bank; =20 for ( bank =3D 0 ; bank < mem->nr_banks; bank++ ) - pfn_pdx_add_region(mem->bank[bank].start, mem->bank[bank].size); + pfn_pdx_add_region(mem->bank[bank].start, mem->bank[bank].size, ba= nk); =20 /* * Arm does not have any restrictions on the bits to compress. Pass 0 = to diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c index 96a87bbce35b..dffe81e067e9 100644 --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -280,7 +280,7 @@ static int __init cf_check srat_parse_region( printk(KERN_INFO "SRAT: %013"PRIx64"-%013"PRIx64"\n", ma->base_address, ma->base_address + ma->length - 1); =20 - pfn_pdx_add_region(ma->base_address, ma->length); + pfn_pdx_add_region(ma->base_address, ma->length, ma->proximity_domain); =20 return 0; } diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 7ffd9d7d9003..17afa9fe5f5c 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -54,7 +54,8 @@ config EVTCHN_FIFO =20 choice prompt "PDX (Page inDeX) compression" - default PDX_MASK_COMPRESSION if !X86 && !RISCV + default PDX_OFFSET_COMPRESSION if X86 + default PDX_MASK_COMPRESSION if !RISCV default PDX_NONE help PDX compression is a technique designed to reduce the memory @@ -73,6 +74,12 @@ config PDX_MASK_COMPRESSION help Compression relying on all RAM addresses sharing a zeroed bit region. =20 +config PDX_OFFSET_COMPRESSION + bool "Offset compression" + help + Compression relying on size and distance between RAM regions being + constant. + config PDX_NONE bool "None" help diff --git a/xen/common/pdx.c b/xen/common/pdx.c index 7d14100224fe..f2cf60bbc3f8 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -21,6 +21,15 @@ #include #include #include +#include + +#ifdef __XEN__ /* For building the file in user-space. */ + +/* + * Use a define for the static keyword, we want to export some otherwise s= tatic + * functions for the unit tests. + */ +#define STATIC static =20 /** * Maximum (non-inclusive) usable pdx. Must be @@ -80,6 +89,7 @@ unsigned long get_max_pfn(unsigned long top_pfn) =20 return pdx_to_pfn(pdx - 1) + 1; } +#endif /* __XEN__ */ =20 #ifndef CONFIG_PDX_NONE =20 @@ -96,10 +106,11 @@ unsigned long get_max_pfn(unsigned long top_pfn) /* Generic PFN compression helpers. */ static struct pfn_range { unsigned long base, size; + unsigned int id; } ranges[MAX_PFN_RANGES] __initdata; static unsigned int __initdata nr; =20 -void __init pfn_pdx_add_region(paddr_t base, paddr_t size) +void __init pfn_pdx_add_region(paddr_t base, paddr_t size, unsigned int id) { if ( nr >=3D ARRAY_SIZE(ranges) ) { @@ -108,6 +119,7 @@ void __init pfn_pdx_add_region(paddr_t base, paddr_t si= ze) return; } =20 + ranges[nr].id =3D id; ranges[nr].base =3D PFN_DOWN(base); ranges[nr++].size =3D PFN_UP(base + size) - PFN_DOWN(base); } @@ -297,7 +309,223 @@ void __init pfn_pdx_compression_reset(void) pfn_pdx_hole_shift =3D 0; } =20 -#endif /* CONFIG_PDX_COMPRESSION */ +#elif defined(CONFIG_PDX_OFFSET_COMPRESSION) /* CONFIG_PDX_MASK_COMPRESSIO= N */ + +unsigned long __ro_after_init pdx_offset =3D ~0UL; +unsigned long __ro_after_init pdx_size =3D ~0UL; + +static unsigned long __initdata top_pfn; + +bool pdx_is_region_compressible(paddr_t base, unsigned long npages) +{ + return !pdx_size ? true + : (PFN_DOWN(base) % pdx_offset) + npages <=3D pdx_siz= e; +} + +STATIC bool __init pfn_offset_calculate_fast(unsigned long base) +{ + unsigned long size =3D max((1UL << MAX_ORDER), base); + unsigned long offset =3D ~0UL; + unsigned int i; + + if ( nr <=3D 1 ) + return false; + + /* Calculate minimal offset between regions. */ + for ( i =3D 1; i < nr; i++ ) + offset =3D min(offset, ranges[i].base - ranges[i - 1].base); + + /* Return early if offset is smaller than the minimum size. */ + if ( size >=3D offset ) + return false; + + /* Calculate size so it covers all regions based on the minimal offset= . */ + for ( i =3D 0; i < nr; i++ ) + size =3D max(size, ranges[i].base % offset + ranges[i].size); + + if ( size >=3D offset ) + return false; + + pdx_offset =3D offset; + pdx_size =3D size; + + return true; +} + +STATIC bool __init pfn_offset_calculate_slow(unsigned long base) +{ + unsigned long min_size =3D max((1UL << MAX_ORDER), base); + unsigned long offset, max_offset =3D 0; + unsigned int i, best_ratio =3D 0; + + if ( nr <=3D 1 ) + return false; + + for ( i =3D 0; i < nr; i++ ) + { + /* Minimal size required to cover the bigger region in the set. */ + min_size =3D max(min_size, ranges[i].size); + if ( !i ) + continue; + + max_offset =3D max(max_offset, ranges[i].base - ranges[i - 1].base= ); + } + + if ( min_size >=3D max_offset ) + return false; + + for ( offset =3D max_offset; offset > min_size; offset-- ) + { + unsigned long size =3D min_size; + unsigned int ratio; + + /* + * Terminate loop if it's impossible to get a better ratio given t= he + * decreasing offset and the minimal required region size. + */ + if ( best_ratio >=3D ((offset - size) * 100) / offset ) + break; + + for ( i =3D 0; i < nr; i++ ) + size =3D max(size, (ranges[i].base % offset) + ranges[i].size); + + if ( size >=3D offset ) + continue; + + ratio =3D ((offset - size) * 100) / offset; + if ( ratio > best_ratio ) + { + best_ratio =3D ratio; + pdx_offset =3D offset; + pdx_size =3D size; + } + } + + return best_ratio; +} + +static int __init cf_check cmp_node(const void *a, const void *b) +{ + const struct pfn_range *l =3D a; + const struct pfn_range *r =3D b; + + if ( l->base > r->base ) + return 1; + if ( l->base < r->base ) + return -1; + + ASSERT_UNREACHABLE(); + return 0; +} + +static void __init cf_check swp_node(void *a, void *b, size_t size) +{ + struct pfn_range *l =3D a; + struct pfn_range *r =3D b; + struct pfn_range tmp =3D *l; + + *l =3D *r; + *r =3D tmp; +} + +STATIC void __init pfn_offset_sanitize_ranges(void) +{ + unsigned int i =3D 0; + + /* Sort nodes by start address. */ + sort(ranges, nr, sizeof(struct pfn_range), cmp_node, swp_node); + + /* Merge ranges if possible. */ + while ( i + 1 < nr ) + { + if ( ranges[i].id =3D=3D ranges[i + 1].id ) + { + /* Merge ranges with the same ID. */ + ranges[i].size =3D ranges[i + 1].base + ranges[i + 1].size - + ranges[i].base; + } + else if ( ranges[i].base + ranges[i].size =3D=3D ranges[i + 1].bas= e ) + { + /* Merge ranges if contiguous. */ + ranges[i].size +=3D ranges[i + 1].size; + } + else + { + i++; + continue; + } + + /* Merge ranges. */ + memmove(&ranges[i + 1], &ranges[i + 2], + (nr - (i + 2)) * sizeof(ranges[0])); + nr--; + } +} + +#ifdef __XEN__ +bool __init pfn_pdx_compression_setup(paddr_t base) +{ + bool use_slow =3D false; + + if ( nr <=3D 1 ) + return false; + + if ( nr > ARRAY_SIZE(ranges) ) + { + printk(XENLOG_WARNING + "Too many NUMA nodes (%u), not attempting PFN compression\n= ", + nr); + return false; + } + + pfn_offset_sanitize_ranges(); + + if ( nr <=3D 1 ) + return false; + + top_pfn =3D ranges[nr - 1].base + ranges[nr - 1].size; + + for ( ; ; use_slow =3D true ) + { + if ( use_slow ? pfn_offset_calculate_slow(PFN_DOWN(base)) + : pfn_offset_calculate_fast(PFN_DOWN(base)) ) + { + if ( top_pfn !=3D get_max_pfn(top_pfn) ) + dprintk(XENLOG_DEBUG, + "PFN %s compression coefficients truncate address = space\n", + use_slow ? "slow" : "fast"); + else + break; + } + else + { + dprintk(XENLOG_DEBUG, + "Find PFN compression coefficients using %s algorithm = failed\n", + use_slow ? "slow" : "fast"); + if ( use_slow ) + return false; + } + + if ( use_slow ) + break; + } + + printk(XENLOG_INFO "PFN compression using offset %#lx size %#lx (%lu%%= )\n", + pdx_offset, pdx_size, ((pdx_offset - pdx_size) * 100) / pdx_off= set); + + return true; +} +#endif /* __XEN__ */ + +void __init pfn_pdx_compression_reset(void) +{ + pdx_size =3D ~0UL; + pdx_offset =3D ~0UL; + nr =3D 0; + top_pfn =3D 0; +} + +#endif /* CONFIG_PDX_OFFSET_COMPRESSION */ =20 /* * Local variables: diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 6cc0f54cff83..88f446f4ddd9 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -65,6 +65,31 @@ * This scheme also holds for multiple regions, where HHHHHHH acts as * the region identifier and LLLLLL fully contains the span of every * region involved. + * + * ##=C2=A0PDX offset compression + * + * Alternative compression mechanism that relies on RAM ranges having a si= milar + * size and offset between them: + * + * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90= =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 + * =E2=94=82 RAM 0 =E2=94=82 =E2=94=82 RAM 1 =E2=94=82 = =E2=94=82...=E2=94=82 RAM N =E2=94=82 =E2=94=82 + * =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98= =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 + * =E2=94=82<------>=E2=94=82 =E2=94=82 + * =E2=94=82 size =E2=94=82 + * =E2=94=82<----------------->=E2=94=82 + * offset + * + * The compression removes the holes between RAM regions: + * + * =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=90 =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 + * =E2=94=82 RAM 0 =E2=94=82 RAM 1 =E2=94=82...=E2=94=82 RAM N =E2=94= =82 + * =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=98 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 + * =E2=94=82<------>=E2=94=82 + * size + * + * The compressed index is calculated as: + * + * index =3D (pfn % offset) + ((pfn / offset) * size) */ =20 /* Macro defined per-arch to skip PDX logic when there's no compression. */ @@ -188,7 +213,20 @@ static inline paddr_t directmapoff_to_maddr(unsigned l= ong offset) offset); } =20 -#endif /* CONFIG_PDX_MASK_COMPRESSION */ +#elif defined(CONFIG_PDX_OFFSET_COMPRESSION) /* CONFIG_PDX_MASK_COMPRESSIO= N */ + +extern unsigned long pdx_offset; +extern unsigned long pdx_size; + +/* pdx<->pfn =3D=3D identity */ +#define pdx_to_pfn(x) (x) +#define pfn_to_pdx(x) (x) + +/* directmap is indexed by maddr */ +#define maddr_to_directmapoff(x) (x) +#define directmapoff_to_maddr(x) (x) + +#endif /* CONFIG_PDX_OFFSET_COMPRESSION */ =20 #ifdef CONFIG_PDX_NONE =20 @@ -208,7 +246,8 @@ static inline bool pdx_is_region_compressible(paddr_t b= ase, return true; } =20 -static inline void pfn_pdx_add_region(paddr_t base, paddr_t size) +static inline void pfn_pdx_add_region(paddr_t base, paddr_t size, + unsigned int id) { } =20 @@ -239,8 +278,9 @@ bool pdx_is_region_compressible(paddr_t base, unsigned = long npages); * * @param base Start of the region in bytes. * @param size Length of the region in bytes. + * @param id Range group identifier (for example NUMA proximity domain ID). */ -void pfn_pdx_add_region(paddr_t base, paddr_t size); +void pfn_pdx_add_region(paddr_t base, paddr_t size, unsigned int id); =20 /** * Initializes global variables with information about the compressible --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662595; cv=none; d=zohomail.com; s=zohoarc; b=PRNhk/u1qLud1mwSaMzw6dUzA8dGJo798W2UHwtGfUr65V78BQCd+wilqTP8tfpY7BUhFsBS5vEoU9YB4WruNQNjO3qJ83oE4NzbspOB6KDcllKWBy5WwQQmpNfNrtm9wZa6ujW6URbtqEe2DGVRzduzG9So6rHwD/cwHqlVz54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662595; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=erB+0/PVXEUr1Y3mUBtzWwV6l1V3EbOGOg7XHwfxeDw=; b=XTnV4MwaASTjW1wh+N91qr86cmGxi3W/IxPn9bzuDI3z3RXKvutsB9RHBiSdo1kGJ6D2H9MdA4PEARVOErwezisxl0A5qNxvnr/JZk+HCi37F4PCMJDiCxuJUTamVwfKFud2mImPq9iaotyRYauM0DwGq0khBM76Dg9LzMx+jKU= 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 1749662595302931.2244324959419; Wed, 11 Jun 2025 10:23:15 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011972.1390537 (Exim 4.92) (envelope-from ) id 1uPPAD-000475-Qk; Wed, 11 Jun 2025 17:23:01 +0000 Received: by outflank-mailman (output) from mailman id 1011972.1390537; Wed, 11 Jun 2025 17:23:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPAD-00045y-KJ; Wed, 11 Jun 2025 17:23:01 +0000 Received: by outflank-mailman (input) for mailman id 1011972; Wed, 11 Jun 2025 17:22:59 +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 1uPPAB-0002dK-Kl for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:22:59 +0000 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [2a00:1450:4864:20::330]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b896f9b6-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:22:59 +0200 (CEST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-450d668c2a1so9006095e9.0 for ; Wed, 11 Jun 2025 10:22:59 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a53229e014sm15847938f8f.3.2025.06.11.10.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:58 -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: b896f9b6-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662578; x=1750267378; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=erB+0/PVXEUr1Y3mUBtzWwV6l1V3EbOGOg7XHwfxeDw=; b=usWatrAY9T/jVNJI4L1U18ZfEOtP3XTIx6a2dfbWhCXNz5TEXNaR5BvwdJ+oT/J8KS DRdFLhMnaXMC0TgTYGWSH1hMj/p5StbpEz6FzCG1ut0dzZkvNUSFA3Vf9VbbXv7b0GYC nYgduTmmdqgZTmHA1ci3gfNt7ue2JKCz///tI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662578; x=1750267378; 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=erB+0/PVXEUr1Y3mUBtzWwV6l1V3EbOGOg7XHwfxeDw=; b=ZyTI1SMr5P/Gw00XXP4GbFjVBsjr3lJTRoRPZx1/sRck377X9uYPJjLTuhanaDngoF Bi+ros/RtWkpRpOI0r66ffl/tJJ2UgNT0LzccqSoQlNUuOmuQ94CnbvK1hlZ7wahIyG8 NnUsi7OYJ49DxuF+Dfdl/fNA6tMhiBYYR7/qtujS45r7TpmOQAS1x851/fP+vWKQPaSE pENIqvxy2PNb/jQ2ffzu/iiLOFNmAvA6H5k52KlucLzExElaZn3XGdCgVjAO1Nm+J7gJ m3A5A9DWtVc1uBRPoTyM5k42nW3l8RsPd1EJ6iQgRTBtORpzI7oCvQ92e6EV3gGnVYs3 Cbbw== X-Gm-Message-State: AOJu0YxH/SEvVRpHN1EcBJCDJeIdWbUNy4vDoHKRo44Zvtt6zWEHIrOU BDxg43hxEb4sVBTu7VtKcIxDe6uRPRMuu7sCM6b+cSz8o47Tkx+XVOc4E3yhjExp24y+9/3RF1m FuwFW X-Gm-Gg: ASbGncvO4wVWMwWOmsWOxAcJFn/cWnasHcuMM7KV2TXcGEyqgbbtU3RXa4QBV0fqtKG 9YYu1xe0qRXTb7eZ2CGe0jF77SYZOn2noSIkqi+tmH7lKaUK16/QRcy3pogN2WMgCT1PPIsTlNe GAaBY3k5MF8G14YAnoGI8CRISSkof9r5yRKJRYq8lC4LPxroSAWD799NjtgqTT3TYUtdcS/1g5l EYbpLq7EQroLzw4Te5HnEFKGGwAJa3r4aO0n8TDb0OldnGC2nl7RWGUqId8aOXZueS7Lm+pZJ5q iU7GJR5KmtSBV32rHZluZyTYj14LuftLf15Jq87vEEhA3Ko8c3L3bc779lWLLt2qZ9p563e0hpY IDXwL6ID6eY9Q8JcBfSefQuRD6CNqIivpRpk= X-Google-Smtp-Source: AGHT+IFOh+vGQIbcfaAJyeyfLZqFKbGVoqo9AOb2DRYEWGmD4FX/+j7PzQL+TQgwZj5BOs8rUzzJWg== X-Received: by 2002:a05:600c:3484:b0:450:d79d:3b16 with SMTP id 5b1f17b1804b1-4532c2b3123mr2844535e9.14.1749662578442; Wed, 11 Jun 2025 10:22:58 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Anthony PERARD , Andrew Cooper , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 7/8] pdx: introduce translation helpers for offset compression Date: Wed, 11 Jun 2025 19:16:35 +0200 Message-ID: <20250611171636.5674-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662596265116600 Implement the helpers to translate from pfns or physical addresses into the offset compressed index space. Add a further check in the PDX testing to ensure conversion resulting from the added functions is bi-directional. Signed-off-by: Roger Pau Monn=C3=A9 --- tools/tests/pdx/test-pdx-offset.c | 10 +++++++++ xen/common/pdx.c | 10 +++++++++ xen/include/xen/pdx.h | 35 +++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/tools/tests/pdx/test-pdx-offset.c b/tools/tests/pdx/test-pdx-o= ffset.c index 0a561f02d197..a3507c36deb7 100644 --- a/tools/tests/pdx/test-pdx-offset.c +++ b/tools/tests/pdx/test-pdx-offset.c @@ -293,6 +293,16 @@ int main(int argc, char **argv) print_ranges(tests[i].ranges); ret_code =3D EXIT_FAILURE; } + + if ( start !=3D pdx_to_pfn(pfn_to_pdx(start)) || + end - 1 !=3D pdx_to_pfn(pfn_to_pdx(end - 1)) ) + { + printf( + "PDX %s compression invalid, conversion of %#lx or %#lx is not bidirec= tional\n", + use_slow ? "slow" : "fast", start, end - 1); + print_ranges(tests[i].ranges); + ret_code =3D EXIT_FAILURE; + } } } } diff --git a/xen/common/pdx.c b/xen/common/pdx.c index f2cf60bbc3f8..feabdcded804 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -46,6 +46,8 @@ bool __mfn_valid(unsigned long mfn) =20 #ifdef CONFIG_PDX_MASK_COMPRESSION invalid |=3D mfn & pfn_hole_mask; +#elif defined(CONFIG_PDX_OFFSET_COMPRESSION) + invalid |=3D (mfn % pdx_offset) >=3D pdx_size; #endif =20 if ( unlikely(evaluate_nospec(invalid)) ) @@ -314,6 +316,9 @@ void __init pfn_pdx_compression_reset(void) unsigned long __ro_after_init pdx_offset =3D ~0UL; unsigned long __ro_after_init pdx_size =3D ~0UL; =20 +paddr_t __ro_after_init pdx_paddr_offset =3D ~0UL; +paddr_t __ro_after_init pdx_paddr_size =3D ~0UL; + static unsigned long __initdata top_pfn; =20 bool pdx_is_region_compressible(paddr_t base, unsigned long npages) @@ -513,6 +518,9 @@ bool __init pfn_pdx_compression_setup(paddr_t base) printk(XENLOG_INFO "PFN compression using offset %#lx size %#lx (%lu%%= )\n", pdx_offset, pdx_size, ((pdx_offset - pdx_size) * 100) / pdx_off= set); =20 + pdx_paddr_offset =3D (paddr_t)pdx_offset << PAGE_SHIFT; + pdx_paddr_size =3D (paddr_t)pdx_size << PAGE_SHIFT; + return true; } #endif /* __XEN__ */ @@ -520,7 +528,9 @@ bool __init pfn_pdx_compression_setup(paddr_t base) void __init pfn_pdx_compression_reset(void) { pdx_size =3D ~0UL; + pdx_paddr_size =3D ~(paddr_t)0; pdx_offset =3D ~0UL; + pdx_paddr_offset =3D ~(paddr_t)0; nr =3D 0; top_pfn =3D 0; } diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index 88f446f4ddd9..5f9e5bc7ab62 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -217,14 +217,37 @@ static inline paddr_t directmapoff_to_maddr(unsigned = long offset) =20 extern unsigned long pdx_offset; extern unsigned long pdx_size; +extern paddr_t pdx_paddr_offset; +extern paddr_t pdx_paddr_size; =20 -/* pdx<->pfn =3D=3D identity */ -#define pdx_to_pfn(x) (x) -#define pfn_to_pdx(x) (x) +void pdx_region_offset(unsigned long base, unsigned long size); +bool pfn_pdx_offset_setup(void); =20 -/* directmap is indexed by maddr */ -#define maddr_to_directmapoff(x) (x) -#define directmapoff_to_maddr(x) (x) +static inline unsigned long pdx_to_pfn(unsigned long pdx) +{ + OPTIMIZE_PDX((pdx % pdx_size) + ((pdx / pdx_size) * pdx_offset), + pdx); +} + +static inline unsigned long pfn_to_pdx(unsigned long pfn) +{ + OPTIMIZE_PDX((pfn % pdx_offset) + ((pfn / pdx_offset) * pdx_size), + pfn); +} + +static inline unsigned long maddr_to_directmapoff(paddr_t ma) +{ + OPTIMIZE_PDX((ma % pdx_paddr_offset) + + ((ma / pdx_paddr_offset) * pdx_paddr_size), + ma); +} + +static inline paddr_t directmapoff_to_maddr(unsigned long off) +{ + OPTIMIZE_PDX((off % pdx_paddr_size) + + ((off / pdx_paddr_size) * pdx_paddr_offset), + off); +} =20 #endif /* CONFIG_PDX_OFFSET_COMPRESSION */ =20 --=20 2.49.0 From nobody Fri Oct 31 04:01:23 2025 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1749662600; cv=none; d=zohomail.com; s=zohoarc; b=NPbDW52KoteEIKpPHaGgnQ7PKo+fFFEiZkTKSf5Xak+H2psEcLeN/XqfWmXQVxSYI0xCgCZxVRIy7Bk8NWWv9vaQJARnJw0hNH/KYggr0l/j3lvVALXsBFlz3kNg/UiOk76ALL2Rp8kbXEOnqngqeTnp93VIYhuuMdOC1T6rnsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749662600; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zMkLljSK+j8EobhNDyMcdRH/ZodKoaJMWOo2vFrOTRM=; b=SCXSgtK29QLrMDVhNJlg6vVY8qSLQAGTQvcb+1f5GPpW2hYLzEL8404EOKgOoGFP1GSs6BKCWHAyGPJokM6unsKchWdwIdY7AIIgWs1LUY9C4OShm21K+TRuWnepDs2Sv8jygCCf5Yx8g0+m40/wEt8tloH7RoZKpkodfuT2HRQ= 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 174966260002998.8877076379174; Wed, 11 Jun 2025 10:23:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1011974.1390542 (Exim 4.92) (envelope-from ) id 1uPPAE-0004BH-80; Wed, 11 Jun 2025 17:23:02 +0000 Received: by outflank-mailman (output) from mailman id 1011974.1390542; Wed, 11 Jun 2025 17:23:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uPPAD-0004AE-Vh; Wed, 11 Jun 2025 17:23:01 +0000 Received: by outflank-mailman (input) for mailman id 1011974; Wed, 11 Jun 2025 17:23:01 +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 1uPPAD-0002dK-Cf for xen-devel@lists.xenproject.org; Wed, 11 Jun 2025 17:23:01 +0000 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [2a00:1450:4864:20::432]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b986bea8-46e8-11f0-a307-13f23c93f187; Wed, 11 Jun 2025 19:23:00 +0200 (CEST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3a53359dea5so110481f8f.0 for ; Wed, 11 Jun 2025 10:23:00 -0700 (PDT) Received: from localhost (112.pool92-178-7.dynamic.orange.es. [92.178.7.112]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a532464f20sm15936533f8f.98.2025.06.11.10.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 10:22:59 -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: b986bea8-46e8-11f0-a307-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1749662580; x=1750267380; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zMkLljSK+j8EobhNDyMcdRH/ZodKoaJMWOo2vFrOTRM=; b=oZnV1tEqvqKmVyqlm4To2KRWRRy3SPWSTLk9IZVimu38g53McYSeS+Z7pzGW06Y1dL dd5kFFuI3AtyDUYunlR0kvRRpcJrV2SrWmI3Rqr0sgK5DqAUuUZx+CWNbhycdCE9kpx7 mBVtEsSVIWaLHZfztLt9lUbwxaKIqm2TFxIpA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749662580; x=1750267380; 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=zMkLljSK+j8EobhNDyMcdRH/ZodKoaJMWOo2vFrOTRM=; b=N6zuw2n8MiwN5IYtOJCxuucTVFcGoYvA2o+PMbvHcZwSw2U12eSOVreYAMDaF+P/ix uadhV3h2/1KTV/tTQrzvUjZtIC5Y/6eOpgXt9irZS5nDoR3brP+B9drvk3O5ex1PiP/m KjPyQEvEAV8v0O2rq1KebHpNsY7fI6kTku1DFPe53vwkvP1/OmpXxCe30rgdp8ucuFBw O5/sWH5qNvQ2bQ8Pipj0xVWbMfa8BCYJ65dOITMnuKMxosGBF+AqNWhGFYBVPsylHydt 8Yc0catJkX7tYwdaQz8KAi9ZPu2N1Tnp3eT4dExh6q+eaY8iJwXPjzlGFVQiRaUK3u7g TP8A== X-Gm-Message-State: AOJu0YxQ6RLFKI4pHzsKkatO8GP6UIDnujdnpUnsxdyMqe7lAxqs9vEN aHSszo61jIdW3qUhms+xOtiAauw6vXSpEvAzdeLOV5o13ud+We9PmMtZtZ4fQBTA5ZpuqeWiDnn JicmY X-Gm-Gg: ASbGnctDlHeJ2zL0iAC/TRN6FBT1lrnHVh9aIY0kOuYEx+gULYL1IGsvsqscZV2+bfG OgX/H1YoeUgZXILqpZai7l4EzOTjfF6mpyCp55XV4AfTAciq/k5pNAQYFU163z9Cg8cHF21fTR1 xo4BgZffCI82bTxRp6Wa7CAj9vKZ+uIZ0Ms3bDscE57VObCiQNLtndnL4H/rlQWeipqWFVKO0IT cM8ZDedqzq7gGpLcZZgaD0Js8BEOKyRPd+G5vaviJVxpvhCu9zQVekKCWr9Np3yA2ocMCCvUab1 GjRaPosqmTasLIUro5kdJh5l47Jr3rJQ/c+Vc3s8ytuwrBDS9p9yQ364wnxWVah75qdLtaUwInm RqD8O10p1y1626Jgrm533o1qYG+tXltr2ka0= X-Google-Smtp-Source: AGHT+IFmm8Vnv/fFfhO6OHaQrYoRlOpgApD7blxzSW+d/IiH0RcBar5N6eB71msoXWKCHbg6AhxmIA== X-Received: by 2002:a05:6000:4383:b0:3a4:f6c4:355a with SMTP id ffacd0b85a97d-3a558a534f7mr3477043f8f.57.1749662579917; Wed, 11 Jun 2025 10:22:59 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Oleksii Kurochko , Community Manager , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH 8/8] pdx: introduce a command line option for offset compression Date: Wed, 11 Jun 2025 19:16:36 +0200 Message-ID: <20250611171636.5674-9-roger.pau@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250611171636.5674-1-roger.pau@citrix.com> References: <20250611171636.5674-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1749662602244116600 Allow controlling whether to attempt PDX compression, and which algorithm to use to calculate the coefficients. Document the option and also add a CHANGELOG entry for the newly added feature. Note the work has been originally done to cope with the new Intel Sapphire/Granite Rapids, however the compression is not explicitly tied to Intel or x86, and hence could be helpful on other architectures. Signed-off-by: Roger Pau Monn=C3=A9 --- CHANGELOG.md | 3 +++ docs/misc/xen-command-line.pandoc | 22 ++++++++++++++++++ xen/common/pdx.c | 38 +++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23215a8cc1e6..48327f03078f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) table or foreign memory. =20 ### Added + - Introduce new PDX compression algorithm to cope with Intel Sapphire and + Granite Rapids having sparse memory maps. + - On x86: - Option to attempt to fixup p2m page-faults on PVH dom0. - Resizable BARs is supported for PVH dom0. diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index b0eadd2c5d58..06819576a06b 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -2072,6 +2072,28 @@ for all of them (`true`), only for those subject to = XPTI (`xpti`) or for those not subject to XPTI (`no-xpti`). The feature is used only in case INVPCID is supported and not disabled via `invpcid=3Dfalse`. =20 +###=C2=A0pdx-compress +> `=3D |=C2=A0auto | fast | slow` + +> Default: `auto` + +Only relevant when hypervisor is build with PFN PDX offset compression +`CONFIG_PDX_OFFSET_COMPRESSION`. + +Controls whether Xen will engage in PFN compression, and which algorithm w= ill +be used to calculate the compression coefficients: + +* `auto`: default choice, attempt fast calculation of compression + coefficients, if that's not successful fallback to slow calculation. + +* `fast`: only attempt fast calculation of coefficients, if it fails PFN P= DX + compression will be disabled. + +* `slow`: only attempt slow calculation of coefficients, if it fails PFN P= DX + compression will be disabled. + +Note `pdx-compress=3Dtrue` is equivalent to `pdx-compress=3Dauto`. + ### ple_gap > `=3D ` =20 diff --git a/xen/common/pdx.c b/xen/common/pdx.c index feabdcded804..5fd01305a7be 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -468,11 +469,40 @@ STATIC void __init pfn_offset_sanitize_ranges(void) } =20 #ifdef __XEN__ +static enum { + PDX_AUTO, /* Fast first, fallback to slow if fast is not successful. */ + PDX_NO, /* Do not attempt compression. */ + PDX_FAST, /* Only attempt fast calculation of compression parameters. = */ + PDX_SLOW, /* Only attempt slow calculation of compression parameters. = */ +} compress_mode __initdata; + +static int __init cf_check parse_pdx_param(const char *arg) +{ + int val; + + if ( !arg ) + return -EINVAL; + + if ( (val =3D parse_bool(arg, NULL)) !=3D -1 ) + compress_mode =3D val ? PDX_AUTO : PDX_NO; + else if ( !strcmp(arg, "auto") ) + compress_mode =3D PDX_AUTO; + else if ( !strcmp(arg, "fast") ) + compress_mode =3D PDX_FAST; + else if ( !strcmp(arg, "slow") ) + compress_mode =3D PDX_SLOW; + else + return -EINVAL; + + return 0; +} +custom_param("pdx-compress", parse_pdx_param); + bool __init pfn_pdx_compression_setup(paddr_t base) { - bool use_slow =3D false; + bool use_slow =3D compress_mode =3D=3D PDX_SLOW; =20 - if ( nr <=3D 1 ) + if ( nr <=3D 1 || compress_mode =3D=3D PDX_NO ) return false; =20 if ( nr > ARRAY_SIZE(ranges) ) @@ -507,11 +537,11 @@ bool __init pfn_pdx_compression_setup(paddr_t base) dprintk(XENLOG_DEBUG, "Find PFN compression coefficients using %s algorithm = failed\n", use_slow ? "slow" : "fast"); - if ( use_slow ) + if ( compress_mode =3D=3D PDX_FAST || use_slow ) return false; } =20 - if ( use_slow ) + if ( compress_mode =3D=3D PDX_FAST || use_slow ) break; } =20 --=20 2.49.0