From nobody Fri Nov 22 01:13:38 2024 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 900361946CA for ; Tue, 10 Sep 2024 10:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964803; cv=none; b=aXfOH9edN7ASvVxjb+wCScj7h+GQOYdUHGKAYUmxZS/SANlLItCtryXQKAxZN7d6JQTpwmEgCzJJ1w8eUbjY5u0LLM7tjVV7oL5DgH1Bo890vyz8eHYefDpCABwwCui2tPzfNtDaxArR6CrWLzzJfcSAVHAxFy9OS9KvHiARBMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964803; c=relaxed/simple; bh=Fe/ZpZPzIDPDKEl0nwawip7LUNdBck0LLF6McS7l9fw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Uk3/6PZlLd3/n12KFcE1IjbNtYme2W7WYF32qWtRSEwY3oDxAKyv5zp0uW0GDtSPH8SGrwUYwr7nSmmrr+LwQorgIMUqU5ZEnBgF0iTEpHRLzra450Cet1bUeIjhAawkJycwttLpMjpEJ00ZghJ3UMSiWAZepstwI49XXG8Smt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=J5DMDmzr; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=fXDtBABu; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="J5DMDmzr"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="fXDtBABu" Received: from imap1.dmz-prg2.suse.org (unknown [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-out2.suse.de (Postfix) with ESMTPS id A0C841F7D7; Tue, 10 Sep 2024 10:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725964799; 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=eprW9rfhq2cX7ePF/8RtH26O1aYeQlKG+2vFrY0kNmk=; b=J5DMDmzrmL2q751QMJ7BvOlZX1CJFCyI65IslU9GmxO0ElFQpwhW5rFALiqJ+FR7duGafZ +G+XjPUahI5hxWlaiwVJZOXGn4GSdB5yF1M2e44GkKYTPKdaD0lFH1ldeUOY0p3Q/MKfQe CkYJPpWM2zPyhD9fgyIbkbATDrOiJ/I= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1725964798; 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=eprW9rfhq2cX7ePF/8RtH26O1aYeQlKG+2vFrY0kNmk=; b=fXDtBABulc8D33tnfRSRkGpzr5L9nT6W1TK8THvxsKZUVm4SFyJoAA7eHIibZlXR1/CfTf 8I6uaJd26i5dMZJG2Y2XCh/0iQJ39tFnYuwyH9Ua773aBS5SoGWzFTXJNsIa1dsvxRP9Q3 ly6RKLX/onc06+/gb3oK339PlWZS0pc= 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 454E7132CB; Tue, 10 Sep 2024 10:39:58 +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 Nfp0D/4h4GbUYwAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 10:39:58 +0000 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?= , Jan Beulich Subject: [PATCH v3 4/7] xen: move max_pfn in xen_memory_setup() out of function scope Date: Tue, 10 Sep 2024 12:39:29 +0200 Message-ID: <20240910103932.7634-5-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240910103932.7634-1-jgross@suse.com> References: <20240910103932.7634-1-jgross@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.30 X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[12]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,imap1.dmz-prg2.suse.org:helo] X-Spam-Flag: NO X-Spam-Level: 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 | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index dba68951ed6b..2c79bb5a9cd0 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,8 @@ 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 min(xen_get_pages_limit(), 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 +789,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 +801,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 +885,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