From nobody Tue Nov 11 13:46:40 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1559599442; cv=none; d=zoho.com; s=zohoarc; b=YAjAtoaiKabZtmkqocIXBE9jfkOllmrrlKUllqcdx8VPhH2jc7n2TAgZGXtDmFaC1GJPdd1nIhQ+6rLWdTVLbvM+Z5rjyR3ObKn691qMafsCdQC2m9Ipmo2Ey8+Q5c+16w02PmUvVbGRwbkGspvdLHWvjTBNFbbCt3qne6sW3Kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559599442; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=yXMyt6CzKcUTqfLrVFo/hY9Gdp6ocQJla0ByzWXDmks=; b=WWAlE3v0g1ZzRnw9eSN2VuuWv1+Dmel5PoUJMt18TGNUBAMdfoCvkMOhYGrd5Sl38nL17FTQXpH9mvfzgkkoFmO6EygkP32y7srLaqxkmhUGA3Uey/cC1YHEzXphttS99emf6iXin8kfXO004y77CDVzAEFit8hNV422aQD3YYE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1559599442755832.0885029036494; Mon, 3 Jun 2019 15:04:02 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXv2Z-0003UJ-Ke; Mon, 03 Jun 2019 22:02:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXv2X-0003TO-Sg for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 22:02:49 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 52f7aa8a-864b-11e9-a35d-3f1990661454; Mon, 03 Jun 2019 22:02:48 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.xilinx.com (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B2E7C247AE; Mon, 3 Jun 2019 22:02:47 +0000 (UTC) X-Inumbo-ID: 52f7aa8a-864b-11e9-a35d-3f1990661454 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559599368; bh=Sb+G7D0OfxVfHWapWMJscrohNrwgbQqmQouZL6hY+FI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NnkieFNWkpSHVjMwwOlSCq4EmyjmimLWNEiAb3RVt7glXGBhs7VoDx5AkD+z6bFoy yfDq9HO+UOYJtT5YuvXhgwJ4AQyMQq2qM9nmMUZ/PtTMO8baksr/1fQ1yJuBQekp18 uHe3OUCKljO8S6DRVbFUAy1p7lqA1HyvwIkT8uxY= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 15:02:45 -0700 Message-Id: <20190603220245.22750-3-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Subject: [Xen-devel] [PATCH v3 3/3] xen/arm: fix mask calculation in pdx_init_mask X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , sstabellini@kernel.org, wei.liu2@citrix.com, konrad.wilk@oracle.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, julien.grall@arm.com, JBeulich@suse.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The mask calculation in pdx_init_mask is wrong when the first bank starts at address 0x0. The reason is that pdx_init_mask will do '0 - 1' causing an underflow. As a result, the mask becomes 0xffffffffffffffff which is the biggest possible mask and ends up causing a significant memory waste in the frametable size computation. For instance, on platforms that have a low memory bank starting at 0x0 and a high memory bank, the frametable will end up covering all the holes in between. The purpose of the mask is to be passed as a parameter to pfn_pdx_hole_setup, which based on the mask parameter calculates pfn_pdx_hole_shift, pfn_pdx_bottom_mask, etc. which are actually the important masks for frametable initialization later on. pfn_pdx_hole_setup never compresses addresses below MAX_ORDER bits (1GB on ARM). Thus, it is safe to initialize mask passing 1ULL << (MAX_ORDER + PAGE_SHIFT) as start address to pdx_init_mask. Signed-off-by: Stefano Stabellini CC: JBeulich@suse.com CC: andrew.cooper3@citrix.com CC: George.Dunlap@eu.citrix.com CC: ian.jackson@eu.citrix.com CC: konrad.wilk@oracle.com CC: tim@xen.org CC: wei.liu2@citrix.com --- Changes in v3: - improve in-code comments Changes in v2: - update commit message - add in-code comments regarding update sites - improve in-code comments - move the mask initialization changes to pdx_init_mask --- xen/arch/arm/setup.c | 9 ++++++++- xen/common/pdx.c | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index ccb0f181ea..45312df006 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -482,7 +482,14 @@ static void __init init_pdx(void) { paddr_t bank_start, bank_size, bank_end; =20 - u64 mask =3D pdx_init_mask(bootinfo.mem.bank[0].start); + /* + * Arm does not have any restrictions on the bits to compress. Pass 0 = to + * let the common code further restrict the mask. + * + * If the logic changes in pfn_pdx_hole_setup we might have to + * update this function too. + */ + u64 mask =3D pdx_init_mask(0x0); int bank; =20 for ( bank =3D 0 ; bank < bootinfo.mem.nr_banks; bank++ ) diff --git a/xen/common/pdx.c b/xen/common/pdx.c index bb7e437049..a3c6f4c1ee 100644 --- a/xen/common/pdx.c +++ b/xen/common/pdx.c @@ -50,9 +50,12 @@ static u64 __init fill_mask(u64 mask) return mask; } =20 +/* + * We don't compress the first MAX_ORDER bit of the addresses. + */ u64 __init pdx_init_mask(u64 base_addr) { - return fill_mask(base_addr - 1); + return fill_mask(max(base_addr, (u64)1 << (MAX_ORDER + PAGE_SHIFT)) - = 1); } =20 u64 __init pdx_region_mask(u64 base, u64 len) @@ -80,6 +83,9 @@ void __init pfn_pdx_hole_setup(unsigned long mask) * This guarantees that page-pointer arithmetic remains valid within * contiguous aligned ranges of 2^MAX_ORDER pages. Among others, our * buddy allocator relies on this assumption. + * + * If the logic changes here, we might have to update the ARM specific + * init_pdx too. */ for ( j =3D MAX_ORDER-1; ; ) { --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel