From nobody Fri Oct 31 09:42:13 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