mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH 44/50] x86/boot/e820: Clean up __e820__update_table() et al
Date: Sat, 28 Jan 2017 23:12:05 +0100	[thread overview]
Message-ID: <1485641531-22124-45-git-send-email-mingo@kernel.org> (raw)
In-Reply-To: <1485641531-22124-1-git-send-email-mingo@kernel.org>

The __e820__update_table() function has various weirdly named variables,
such as 'pbios', 'biosmap' and 'pnr_map' which are pretty confusing
and actively misleading at times.

This weird naming found its way into other functions as well, such as
__append_e820_table() and append_e820_table().

Standardize the naming to make it all much easier to read:

	biosmap  ->  entries
	pbios    ->  entry
	nr_map   ->  nr_entries
        pnr_map  ->  nr_entries
	...

Also clean up the types used: entry indices routinely mixed u32 and int,
standardize on u32 thoughout.

Update the comments as well, while at it.

No change in functionality.

Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/e820.c | 120 +++++++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 61 insertions(+), 59 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 49823e0a7aea..7dc430c03acb 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -175,23 +175,23 @@ void __init e820__print_table(char *who)
 }
 
 /*
- * Sanitize the BIOS E820 map.
+ * Sanitize an E820 map.
  *
- * Some E820 responses include overlapping entries. The following
+ * Some E820 layouts include overlapping entries. The following
  * replaces the original E820 map with a new one, removing overlaps,
  * and resolving conflicting memory types in favor of highest
  * numbered type.
  *
- * The input parameter biosmap points to an array of 'struct
- * e820_entry' which on entry has elements in the range [0, *pnr_map)
- * valid, and which has space for up to max_nr_map entries.
+ * The input parameter 'entries' points to an array of 'struct
+ * e820_entry' which on entry has elements in the range [0, *nr_entries)
+ * valid, and which has space for up to max_nr_entries entries.
  * On return, the resulting sanitized E820 map entries will be in
- * overwritten in the same location, starting at biosmap.
+ * overwritten in the same location, starting at 'entries'.
  *
- * The integer pointed to by pnr_map must be valid on entry (the
- * current number of valid entries located at biosmap). If the
- * sanitizing succeeds the *pnr_map will be updated with the new
- * number of valid entries (something no more than max_nr_map).
+ * The integer pointed to by nr_entries must be valid on entry (the
+ * current number of valid entries located at 'entries'). If the
+ * sanitizing succeeds the *nr_entries will be updated with the new
+ * number of valid entries (something no more than max_nr_entries).
  *
  * The return value from e820__update_table() is zero if it
  * successfully 'sanitized' the map entries passed in, and is -1
@@ -236,8 +236,8 @@ void __init e820__print_table(char *who)
  *	   ______________________4_
  */
 struct change_member {
-	/* Pointer to the original BIOS entry: */
-	struct e820_entry	*pbios;
+	/* Pointer to the original entry: */
+	struct e820_entry	*entry;
 	/* Address for this change point: */
 	unsigned long long	addr;
 };
@@ -256,33 +256,33 @@ static int __init cpcompare(const void *a, const void *b)
 	if (ap->addr != bp->addr)
 		return ap->addr > bp->addr ? 1 : -1;
 
-	return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr);
+	return (ap->addr != ap->entry->addr) - (bp->addr != bp->entry->addr);
 }
 
-static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map)
+static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_entries, u32 *nr_entries)
 {
 	static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
 	static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
 	static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
-	static struct e820_entry new_bios[E820_MAX_ENTRIES] __initdata;
+	static struct e820_entry new_entries[E820_MAX_ENTRIES] __initdata;
 	enum e820_type current_type, last_type;
 	unsigned long long last_addr;
-	int chgidx;
-	int overlap_entries;
-	int new_bios_entry;
-	int old_nr, new_nr, chg_nr;
-	int i;
+	u32 chgidx;
+	u32 overlap_entries;
+	u32 new_nr_entries;
+	u32 old_nr, new_nr, chg_nr;
+	u32 i;
 
 	/* If there's only one memory region, don't bother: */
-	if (*pnr_map < 2)
+	if (*nr_entries < 2)
 		return -1;
 
-	old_nr = *pnr_map;
-	BUG_ON(old_nr > max_nr_map);
+	old_nr = *nr_entries;
+	BUG_ON(old_nr > max_nr_entries);
 
-	/* Bail out if we find any unreasonable addresses in the BIOS map: */
+	/* Bail out if we find any unreasonable addresses in the map: */
 	for (i = 0; i < old_nr; i++) {
-		if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
+		if (entries[i].addr + entries[i].size < entries[i].addr)
 			return -1;
 	}
 
@@ -296,11 +296,11 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 	 */
 	chgidx = 0;
 	for (i = 0; i < old_nr; i++)	{
-		if (biosmap[i].size != 0) {
-			change_point[chgidx]->addr	= biosmap[i].addr;
-			change_point[chgidx++]->pbios	= &biosmap[i];
-			change_point[chgidx]->addr	= biosmap[i].addr + biosmap[i].size;
-			change_point[chgidx++]->pbios	= &biosmap[i];
+		if (entries[i].size != 0) {
+			change_point[chgidx]->addr	= entries[i].addr;
+			change_point[chgidx++]->entry	= &entries[i];
+			change_point[chgidx]->addr	= entries[i].addr + entries[i].size;
+			change_point[chgidx++]->entry	= &entries[i];
 		}
 	}
 	chg_nr = chgidx;
@@ -308,22 +308,22 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 	/* Sort change-point list by memory addresses (low -> high): */
 	sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL);
 
-	/* Create a new BIOS memory map, removing overlaps: */
+	/* Create a new memory map, removing overlaps: */
 	overlap_entries = 0;	 /* Number of entries in the overlap table */
-	new_bios_entry = 0;	 /* Index for creating new bios map entries */
+	new_nr_entries = 0;	 /* Index for creating new map entries */
 	last_type = 0;		 /* Start with undefined memory type */
 	last_addr = 0;		 /* Start with 0 as last starting address */
 
-	/* Loop through change-points, determining effect on the new BIOS map: */
+	/* Loop through change-points, determining effect on the new map: */
 	for (chgidx = 0; chgidx < chg_nr; chgidx++) {
-		/* Keep track of all overlapping BIOS entries */
-		if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr) {
+		/* Keep track of all overlapping entries */
+		if (change_point[chgidx]->addr == change_point[chgidx]->entry->addr) {
 			/* Add map entry to overlap list (> 1 entry implies an overlap) */
-			overlap_list[overlap_entries++] = change_point[chgidx]->pbios;
+			overlap_list[overlap_entries++] = change_point[chgidx]->entry;
 		} else {
 			/* Remove entry from list (order independent, so swap with last): */
 			for (i = 0; i < overlap_entries; i++) {
-				if (overlap_list[i] == change_point[chgidx]->pbios)
+				if (overlap_list[i] == change_point[chgidx]->entry)
 					overlap_list[i] = overlap_list[overlap_entries-1];
 			}
 			overlap_entries--;
@@ -339,31 +339,31 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
 				current_type = overlap_list[i]->type;
 		}
 
-		/* Continue building up new BIOS map based on this information: */
+		/* Continue building up new map based on this information: */
 		if (current_type != last_type || current_type == E820_TYPE_PRAM) {
 			if (last_type != 0)	 {
-				new_bios[new_bios_entry].size = change_point[chgidx]->addr - last_addr;
+				new_entries[new_nr_entries].size = change_point[chgidx]->addr - last_addr;
 				/* Move forward only if the new size was non-zero: */
-				if (new_bios[new_bios_entry].size != 0)
-					/* No more space left for new BIOS entries? */
-					if (++new_bios_entry >= max_nr_map)
+				if (new_entries[new_nr_entries].size != 0)
+					/* No more space left for new entries? */
+					if (++new_nr_entries >= max_nr_entries)
 						break;
 			}
 			if (current_type != 0)	{
-				new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
-				new_bios[new_bios_entry].type = current_type;
+				new_entries[new_nr_entries].addr = change_point[chgidx]->addr;
+				new_entries[new_nr_entries].type = current_type;
 				last_addr = change_point[chgidx]->addr;
 			}
 			last_type = current_type;
 		}
 	}
 
-	/* Retain count for new BIOS entries: */
-	new_nr = new_bios_entry;
+	/* Retain count for the new entries: */
+	new_nr = new_nr_entries;
 
-	/* Copy new BIOS mapping into the original location: */
-	memcpy(biosmap, new_bios, new_nr*sizeof(*biosmap));
-	*pnr_map = new_nr;
+	/* Copy the new entries into the original location: */
+	memcpy(entries, new_entries, new_nr*sizeof(*entries));
+	*nr_entries = new_nr;
 
 	return 0;
 }
@@ -373,13 +373,15 @@ int __init e820__update_table(struct e820_table *table)
 	return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
 }
 
-static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
+static int __init __append_e820_table(struct e820_entry *entries, u32 nr_entries)
 {
-	while (nr_map) {
-		u64 start = biosmap->addr;
-		u64 size = biosmap->size;
+	struct e820_entry *entry = entries;
+
+	while (nr_entries) {
+		u64 start = entry->addr;
+		u64 size = entry->size;
 		u64 end = start + size - 1;
-		u32 type = biosmap->type;
+		u32 type = entry->type;
 
 		/* Ignore the entry on 64-bit overflow: */
 		if (start > end && likely(size))
@@ -387,8 +389,8 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
 
 		e820__range_add(start, size, type);
 
-		biosmap++;
-		nr_map--;
+		entry++;
+		nr_entries--;
 	}
 	return 0;
 }
@@ -402,13 +404,13 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
  * will have given us a memory map that we can use to properly
  * set up memory.  If we aren't, we'll fake a memory map.
  */
-static int __init append_e820_table(struct e820_entry *biosmap, int nr_map)
+static int __init append_e820_table(struct e820_entry *entries, u32 nr_entries)
 {
 	/* Only one memory region (or negative)? Ignore it */
-	if (nr_map < 2)
+	if (nr_entries < 2)
 		return -1;
 
-	return __append_e820_table(biosmap, nr_map);
+	return __append_e820_table(entries, nr_entries);
 }
 
 static u64 __init
-- 
2.7.4

  parent reply	other threads:[~2017-01-28 22:21 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-28 22:11 [PATCH 00/50] x86: Clean up and reorganize the E820 table handling code Ingo Molnar
2017-01-28 22:11 ` [PATCH 01/50] x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h Ingo Molnar
2017-01-29 17:13   ` Sam Ravnborg
2017-01-30  7:58     ` Ingo Molnar
2017-01-31  5:41       ` Sam Ravnborg
2017-01-31 16:35         ` Ingo Molnar
2017-01-31 17:22           ` Sam Ravnborg
2017-01-31 18:00             ` Ingo Molnar
2017-01-31 18:04               ` Joe Perches
2017-01-31 19:17               ` Sam Ravnborg
2017-02-01  8:56                 ` Ingo Molnar
2017-01-28 22:11 ` [PATCH 02/50] x86/boot/e820: Clean up and improve comments in asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 03/50] x86/boot/e820: Move asm/e820.h to asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 04/50] x86/boot/e820: Split minimal UAPI types out into uapi/asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 05/50] x86/boot/e820: Clean up the E820_X_MAX definition Ingo Molnar
2017-01-28 22:11 ` [PATCH 06/50] x86/boot/e820: Remove spurious asm/e820/api.h inclusions Ingo Molnar
2017-01-28 22:11 ` [PATCH 07/50] x86/boot/e820: Remove assembly guard from asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 08/50] x86/boot/e820: Clean up asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 09/50] x86/boot/e820: Remove unnecessary __ASSEMBLY__ guard Ingo Molnar
2017-01-28 22:11 ` [PATCH 10/50] x86/boot/e820: Move HIGH_MEMORY define to asm/e820/types.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 11/50] x86/boot/e820: Rename the basic e820 data types to 'struct e820_entry' and 'struct e820_array' Ingo Molnar
2017-01-28 22:11 ` [PATCH 12/50] x86/boot/e820: Remove unnecessary #include <linux/ioport.h> from asm/e820/api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 13/50] x86/boot/e820: Remove e820_mark_nosave_regions() definition uglies Ingo Molnar
2017-01-28 22:11 ` [PATCH 14/50] x86/boot/e820: Rename 'e820_map' variables to 'e820_array' Ingo Molnar
2017-01-28 22:11 ` [PATCH 15/50] x86/boot/e820: Rename everything to e820_table Ingo Molnar
2017-01-28 22:11 ` [PATCH 16/50] x86/boot/e820: Harmonize the 'struct e820_table' fields Ingo Molnar
2017-01-28 22:11 ` [PATCH 17/50] x86/boot/e820: Rename default_machine_specific_memory_setup() to e820__memory_setup_default() Ingo Molnar
2017-01-28 22:11 ` [PATCH 18/50] x86/boot/e820: Rename e820_table_saved to e820_table_firmware and improve the description Ingo Molnar
2017-01-28 22:11 ` [PATCH 19/50] x86/boot/e820: Basic cleanup of e820.c Ingo Molnar
2017-01-28 22:11 ` [PATCH 20/50] x86/boot/e820: Rename memblock_x86_fill() to e820__memblock_setup() and improve the explanations Ingo Molnar
2017-01-28 22:11 ` [PATCH 21/50] x86/boot/e820: Consolidate 'struct e820_entry *entry' local variable names Ingo Molnar
2017-01-28 22:11 ` [PATCH 22/50] x86/boot/e820: Convert printk(KERN_* ...) to pr_*() Ingo Molnar
2017-01-28 22:59   ` Joe Perches
2017-01-28 22:11 ` [PATCH 23/50] x86/boot/e820: Move the memblock_find_dma_reserve() function and rename it to memblock_set_dma_reserve() Ingo Molnar
2017-01-28 22:11 ` [PATCH 24/50] x86/boot/e820: Rename parse_e820_ext() to e820__memory_setup_extended() Ingo Molnar
2017-01-28 22:11 ` [PATCH 25/50] x86/boot/e820: Move e820_reserve_setup_data() to e820.c Ingo Molnar
2017-01-28 22:11 ` [PATCH 26/50] x86/boot/e820: Clarify the role of finish_e820_parsing() and rename it to e820__finish_early_params() Ingo Molnar
2017-01-28 22:11 ` [PATCH 27/50] x86/boot/e820: Rename early_reserve_e820() to e820__memblock_alloc() and document it Ingo Molnar
2017-01-28 22:11 ` [PATCH 28/50] x86/boot/e820: Rename update_e820() to e820__update_table() Ingo Molnar
2017-01-28 22:11 ` [PATCH 29/50] x86/boot/e820: Rename sanitize_e820_table() " Ingo Molnar
2017-01-28 22:11 ` [PATCH 30/50] x86/boot/e820: Rename e820_any_mapped()/e820_all_mapped() to e820__mapped_any()/e820__mapped_all() Ingo Molnar
2017-01-28 22:11 ` [PATCH 31/50] x86/boot/e820: Rename e820_setup_gap() to e820__setup_pci_gap() Ingo Molnar
2017-01-28 22:11 ` [PATCH 32/50] x86/boot/e820: Create coherent API function names for E820 range operations Ingo Molnar
2017-01-28 22:11 ` [PATCH 33/50] x86/boot/e820: Rename e820_print_map() to e820__print_table() Ingo Molnar
2017-01-28 22:11 ` [PATCH 34/50] x86/boot/e820: Reorder the function prototypes in api.h Ingo Molnar
2017-01-28 22:11 ` [PATCH 35/50] x86/boot/e820: Simplify e820_reserve_resources() Ingo Molnar
2017-01-28 22:11 ` [PATCH 36/50] x86/boot/e820: Introduce 'enum e820_type' Ingo Molnar
2017-01-28 22:11 ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Ingo Molnar
2017-01-28 23:07   ` Linus Torvalds
2017-01-29  9:19     ` Ingo Molnar
2017-01-29 12:38       ` [PATCH] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar
2017-01-29 18:53       ` [PATCH 37/50] x86/boot/e820: Use 'enum e820_type' in 'struct e820_entry' Linus Torvalds
2017-01-28 22:11 ` [PATCH 38/50] x86/boot/e820: Use 'enum e820_type' when handling the e820 region type Ingo Molnar
2017-01-28 22:12 ` [PATCH 39/50] x86/boot/e820: Prefix the E820_* type names with "E820_TYPE_" Ingo Molnar
2017-01-28 22:12 ` [PATCH 40/50] x86/boot/e820: Clean up the E820 table size define names Ingo Molnar
2017-01-28 22:12 ` [PATCH 41/50] x86/boot/e820: Clean up and standardize sizeof() uses Ingo Molnar
2017-01-28 22:12 ` [PATCH 42/50] xen, x86/boot/e820: Simplify Xen's xen_e820_table construct Ingo Molnar
2017-01-28 22:12 ` [PATCH 43/50] x86/boot/e820: Simplify the e820__update_table() interface Ingo Molnar
2017-01-28 22:12 ` Ingo Molnar [this message]
2017-01-28 22:12 ` [PATCH 45/50] x86/boot/e820: Document e820__reserve_setup_data() Ingo Molnar
2017-01-28 22:12 ` [PATCH 46/50] x86/boot/e820: Use bool in query APIs Ingo Molnar
2017-01-28 22:12 ` [PATCH 47/50] x86/boot/e820: Rename e820_reserve_resources*() to e820__reserve_resources*() Ingo Molnar
2017-01-28 22:12 ` [PATCH 48/50] x86/boot/e820: Rename e820_mark_nosave_regions() to e820__register_nosave_regions() Ingo Molnar
2017-01-28 22:12 ` [PATCH 49/50] x86/boot/e820: Remove unnecessary #include's Ingo Molnar
2017-01-28 22:12 ` [PATCH 50/50] x86/boot/e820: Rename the remaining E820 APIs to the e820__*() prefix Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1485641531-22124-45-git-send-email-mingo@kernel.org \
    --to=mingo@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome