From nobody Fri Nov 22 03:13:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1724142055; cv=none; d=zohomail.com; s=zohoarc; b=e+yiRrjSjQuT1MTJz7Ad96L5hezXP7G+WOJ1+Cj0cWLmOi6jhuF5GRTZo2sJ88RmjmEuftiqDcsf3faBxmhnCLMZIwTHozqscSYHJ9/Mh6/cEtVGa7jrTssTT/1so0pFi+dVzNZc6xGJaLtzyDwVzpSaww2kEhm3OjF3MtnquoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724142055; 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=67Tp86aOVS8QP/GkFPihX/Ae6F141YUARfLRlav5UEw=; b=ghgVi1Gzlj0XX2CqpUW3wcj5lli35l5Bga5UPZF6q0Y0C1HbVlm85U4ImnyB9j4zZUYoF8frWMPe9blZ+u6rFktm6+Z6QztDgZdQO+9UvMuSF/I82xG28wSk6Jn40C15gXYSXEvpb3Wx4rQnNpm+lXZ0xu1SIlQUf0T4cqGl8N4= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724142055098722.2341663060275; Tue, 20 Aug 2024 01:20:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.780127.1189744 (Exim 4.92) (envelope-from ) id 1sgK6d-0000vG-DY; Tue, 20 Aug 2024 08:20:43 +0000 Received: by outflank-mailman (output) from mailman id 780127.1189744; Tue, 20 Aug 2024 08:20:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sgK6d-0000v7-AW; Tue, 20 Aug 2024 08:20:43 +0000 Received: by outflank-mailman (input) for mailman id 780127; Tue, 20 Aug 2024 08:20:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sgK6b-0006Rb-HH for xen-devel@lists.xenproject.org; Tue, 20 Aug 2024 08:20:41 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 15b9e627-5ecd-11ef-8776-851b0ebba9a2; Tue, 20 Aug 2024 10:20:40 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 826B12253C; Tue, 20 Aug 2024 08:20:38 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 21B3613A17; Tue, 20 Aug 2024 08:20:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ax/TBtZRxGa7KwAAD6G6ig (envelope-from ); Tue, 20 Aug 2024 08:20:38 +0000 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: 15b9e627-5ecd-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1724142039; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=67Tp86aOVS8QP/GkFPihX/Ae6F141YUARfLRlav5UEw=; b=HwgnKm7e5CFWM1JI/OT7ni5GKnzCtISpb8ouRUYnK+8VZJ8Sbeimqgzv1vDURGU5E4zBDt ffkyDU9El/x5RqErYarGSzgQvvz3DwH7xtBh4mSZGEXBIzrJbIKXyGfHwxsPvXDdS4PAoM H2dJs4E56M8zqIT/WVK65gM4OLOkUHk= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=G5j01DWS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1724142038; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=67Tp86aOVS8QP/GkFPihX/Ae6F141YUARfLRlav5UEw=; b=G5j01DWSfg/ZCcf2JAfWykbQo1DQLIrjppla24VWftoE/kLNsy5CHW2iyvgVvEOHnsomG6 npt4ot1xC2Mi7t+xfi0bDd3h49KIdDTG7mZ66PLMy3U9kFKepl7Kq4oWBMopDQoCkW6Mfd MlDHuDyPCeXLF5d3ScLU/L5VB2eefCg= From: Juergen Gross To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , xen-devel@lists.xenproject.org, =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [PATCH v2 4/7] xen: move max_pfn in xen_memory_setup() out of function scope Date: Tue, 20 Aug 2024 10:20:09 +0200 Message-ID: <20240820082012.31316-5-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820082012.31316-1-jgross@suse.com> References: <20240820082012.31316-1-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 826B12253C X-Spam-Score: -3.51 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_SEVEN(0.00)[11]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Level: X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1724142056753116600 Instead of having max_pfn as a local variable of xen_memory_setup(), make it a static variable in setup.c instead. This avoids having to pass it to subfunctions, which will be needed in more cases in future. Rename it to ini_nr_pages, as the value denotes the currently usable number of memory pages as passed from the hypervisor at boot time. Signed-off-by: Juergen Gross Tested-by: Marek Marczykowski-G=C3=B3recki Reviewed-by: Jan Beulich --- arch/x86/xen/setup.c | 53 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index dba68951ed6b..d678c0330971 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -46,6 +46,9 @@ bool xen_pv_pci_possible; /* E820 map used during setting up memory. */ static struct e820_table xen_e820_table __initdata; =20 +/* Number of initially usable memory pages. */ +static unsigned long ini_nr_pages __initdata; + /* * Buffer used to remap identity mapped pages. We only need the virtual sp= ace. * The physical page behind this address is remapped as needed to different @@ -212,7 +215,7 @@ static int __init xen_free_mfn(unsigned long mfn) * as a fallback if the remapping fails. */ static void __init xen_set_identity_and_release_chunk(unsigned long start_= pfn, - unsigned long end_pfn, unsigned long nr_pages) + unsigned long end_pfn) { unsigned long pfn, end; int ret; @@ -220,7 +223,7 @@ static void __init xen_set_identity_and_release_chunk(u= nsigned long start_pfn, WARN_ON(start_pfn > end_pfn); =20 /* Release pages first. */ - end =3D min(end_pfn, nr_pages); + end =3D min(end_pfn, ini_nr_pages); for (pfn =3D start_pfn; pfn < end; pfn++) { unsigned long mfn =3D pfn_to_mfn(pfn); =20 @@ -341,15 +344,14 @@ static void __init xen_do_set_identity_and_remap_chun= k( * to Xen and not remapped. */ static unsigned long __init xen_set_identity_and_remap_chunk( - unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, - unsigned long remap_pfn) + unsigned long start_pfn, unsigned long end_pfn, unsigned long remap_pfn) { unsigned long pfn; unsigned long i =3D 0; unsigned long n =3D end_pfn - start_pfn; =20 if (remap_pfn =3D=3D 0) - remap_pfn =3D nr_pages; + remap_pfn =3D ini_nr_pages; =20 while (i < n) { unsigned long cur_pfn =3D start_pfn + i; @@ -358,19 +360,19 @@ static unsigned long __init xen_set_identity_and_rema= p_chunk( unsigned long remap_range_size; =20 /* Do not remap pages beyond the current allocation */ - if (cur_pfn >=3D nr_pages) { + if (cur_pfn >=3D ini_nr_pages) { /* Identity map remaining pages */ set_phys_range_identity(cur_pfn, cur_pfn + size); break; } - if (cur_pfn + size > nr_pages) - size =3D nr_pages - cur_pfn; + if (cur_pfn + size > ini_nr_pages) + size =3D ini_nr_pages - cur_pfn; =20 remap_range_size =3D xen_find_pfn_range(&remap_pfn); if (!remap_range_size) { pr_warn("Unable to find available pfn range, not remapping identity pag= es\n"); xen_set_identity_and_release_chunk(cur_pfn, - cur_pfn + left, nr_pages); + cur_pfn + left); break; } /* Adjust size to fit in current e820 RAM region */ @@ -397,18 +399,18 @@ static unsigned long __init xen_set_identity_and_rema= p_chunk( } =20 static unsigned long __init xen_count_remap_pages( - unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, + unsigned long start_pfn, unsigned long end_pfn, unsigned long remap_pages) { - if (start_pfn >=3D nr_pages) + if (start_pfn >=3D ini_nr_pages) return remap_pages; =20 - return remap_pages + min(end_pfn, nr_pages) - start_pfn; + return remap_pages + min(end_pfn, ini_nr_pages) - start_pfn; } =20 -static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages, +static unsigned long __init xen_foreach_remap_area( unsigned long (*func)(unsigned long start_pfn, unsigned long end_pfn, - unsigned long nr_pages, unsigned long last_val)) + unsigned long last_val)) { phys_addr_t start =3D 0; unsigned long ret_val =3D 0; @@ -436,8 +438,7 @@ static unsigned long __init xen_foreach_remap_area(unsi= gned long nr_pages, end_pfn =3D PFN_UP(entry->addr); =20 if (start_pfn < end_pfn) - ret_val =3D func(start_pfn, end_pfn, nr_pages, - ret_val); + ret_val =3D func(start_pfn, end_pfn, ret_val); start =3D end; } } @@ -700,7 +701,7 @@ static void __init xen_reserve_xen_mfnlist(void) **/ char * __init xen_memory_setup(void) { - unsigned long max_pfn, pfn_s, n_pfns; + unsigned long pfn_s, n_pfns; phys_addr_t mem_end, addr, size, chunk_size; u32 type; int rc; @@ -712,9 +713,9 @@ char * __init xen_memory_setup(void) int op; =20 xen_parse_512gb(); - max_pfn =3D xen_get_pages_limit(); - max_pfn =3D min(max_pfn, xen_start_info->nr_pages); - mem_end =3D PFN_PHYS(max_pfn); + ini_nr_pages =3D xen_get_pages_limit(); + ini_nr_pages =3D min(ini_nr_pages, xen_start_info->nr_pages); + mem_end =3D PFN_PHYS(ini_nr_pages); =20 memmap.nr_entries =3D ARRAY_SIZE(xen_e820_table.entries); set_xen_guest_handle(memmap.buffer, xen_e820_table.entries); @@ -789,10 +790,10 @@ char * __init xen_memory_setup(void) max_pages =3D xen_get_max_pages(); =20 /* How many extra pages do we need due to remapping? */ - max_pages +=3D xen_foreach_remap_area(max_pfn, xen_count_remap_pages); + max_pages +=3D xen_foreach_remap_area(xen_count_remap_pages); =20 - if (max_pages > max_pfn) - extra_pages +=3D max_pages - max_pfn; + if (max_pages > ini_nr_pages) + extra_pages +=3D max_pages - ini_nr_pages; =20 /* * Clamp the amount of extra memory to a EXTRA_MEM_RATIO @@ -801,8 +802,8 @@ char * __init xen_memory_setup(void) * Make sure we have no memory above max_pages, as this area * isn't handled by the p2m management. */ - maxmem_pages =3D EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)); - extra_pages =3D min3(maxmem_pages, extra_pages, max_pages - max_pfn); + maxmem_pages =3D EXTRA_MEM_RATIO * min(ini_nr_pages, PFN_DOWN(MAXMEM)); + extra_pages =3D min3(maxmem_pages, extra_pages, max_pages - ini_nr_pages); i =3D 0; addr =3D xen_e820_table.entries[0].addr; size =3D xen_e820_table.entries[0].size; @@ -885,7 +886,7 @@ char * __init xen_memory_setup(void) * Set identity map on non-RAM pages and prepare remapping the * underlying RAM. */ - xen_foreach_remap_area(max_pfn, xen_set_identity_and_remap_chunk); + xen_foreach_remap_area(xen_set_identity_and_remap_chunk); =20 pr_info("Released %ld page(s)\n", xen_released_pages); =20 --=20 2.43.0