Skip to contentSkip to conversation

Minor physmem cleanups/fixes

PATCH Superseded Tiwei Bie 2 participants 6 messages Sep 13, 2024 – Sep 16, 2024 User-mode Linux (UML)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

cover Minor physmem cleanups/fixes

Tiwei Bie (3):
um: Remove the redundant declaration of high_physmem
um: Remove highmem leftovers
um: Fix the definition for physmem_size

 arch/um/drivers/virtio_uml.c       |  9 ---------
 arch/um/include/shared/as-layout.h |  3 ++-
 arch/um/include/shared/mem_user.h  |  5 ++---
 arch/um/kernel/mem.c               |  3 ---
 arch/um/kernel/physmem.c           | 32 ++++++++++--------------------
 arch/um/kernel/um_arch.c           | 19 ++++++++----------
 arch/um/os-Linux/main.c            |  5 +----
 7 files changed, 24 insertions(+), 52 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 um: Remove the redundant declaration of high_physmem

high_physmem has already been declared in as-layout.h, so there is no need to declare it explicitly in the .c file again.

While at it, group the declarations of __real_malloc and __real_free together to make the code slightly more readable.

---
 arch/um/os-Linux/main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/um/os-Linux/main.c +1 -4
index f98ff79cdbf7..cf1179ed1aec 100644
@@ -182,6 +182,7 @@ int __init main(int argc, char **argv, char **envp)
 }
 
 extern void *__real_malloc(int);
+extern void __real_free(void *);
 
 /* workaround for -Wmissing-prototypes warnings */
 void *__wrap_malloc(int size);
@@ -219,10 +220,6 @@ void *__wrap_calloc(int n, int size)
 	return ptr;
 }
 
-extern void __real_free(void *);
-
-extern unsigned long high_physmem;
-
 void __wrap_free(void *ptr)
 {
 	unsigned long addr = (unsigned long) ptr;
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 um: Remove highmem leftovers

In reply to Tiwei Bie

Highmem was only supported on UML/i386. And the support has been removed by commit a98a6d864d3b ("um: Remove broken highmem support"). Remove the leftovers and stop UML from trying to setup highmem when the sum of physmem_size and iomem_size exceeds max_physmem.

---
 arch/um/drivers/virtio_uml.c       |  9 +--------
 arch/um/include/shared/as-layout.h |  1 -
 arch/um/include/shared/mem_user.h  |  5 ++---
 arch/um/kernel/mem.c               |  3 ---
 arch/um/kernel/physmem.c           | 30 +++++++++++-------------------
 arch/um/kernel/um_arch.c           | 17 +++++++----------
 6 files changed, 21 insertions(+), 44 deletions(-)
arch/um/drivers/virtio_uml.c +1 -8
index 2b6e701776b6..e7f5556e3c96 100644
@@ -72,7 +72,7 @@ struct virtio_uml_vq_info {
 	bool suspended;
 };
 
-extern unsigned long long physmem_size, highmem;
+extern unsigned long long physmem_size;
 
 #define vu_err(vu_dev, ...)	dev_err(&(vu_dev)->pdev->dev, ##__VA_ARGS__)
 
@@ -673,13 +673,6 @@ static int vhost_user_set_mem_table(struct virtio_uml_device *vu_dev)
 
 	if (rc < 0)
 		return rc;
-	if (highmem) {
-		msg.payload.mem_regions.num++;
-		rc = vhost_user_init_mem_region(__pa(end_iomem), highmem,
-				&fds[1], &msg.payload.mem_regions.regions[1]);
-		if (rc < 0)
-			return rc;
-	}
 
 	return vhost_user_send(vu_dev, false, &msg, fds,
 			       msg.payload.mem_regions.num);
arch/um/include/shared/as-layout.h +0 -1
index 06292fca5a4d..61965a06c18a 100644
@@ -41,7 +41,6 @@ extern unsigned long uml_physmem;
 extern unsigned long uml_reserved;
 extern unsigned long end_vm;
 extern unsigned long start_vm;
-extern unsigned long long highmem;
 
 extern unsigned long brk_start;
 
arch/um/include/shared/mem_user.h +2 -3
index 11a723a58545..adfa08062f88 100644
@@ -47,10 +47,9 @@ extern int iomem_size;
 #define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1))
 
 extern unsigned long find_iomem(char *driver, unsigned long *len_out);
-extern void mem_total_pages(unsigned long physmem, unsigned long iomem,
-		     unsigned long highmem);
+extern void mem_total_pages(unsigned long physmem, unsigned long iomem);
 extern void setup_physmem(unsigned long start, unsigned long usable,
-			  unsigned long len, unsigned long long highmem);
+			  unsigned long len);
 extern void map_memory(unsigned long virt, unsigned long phys,
 		       unsigned long len, int r, int w, int x);
 
arch/um/kernel/mem.c +0 -3
index a5b4fe2ad931..5026668dc054 100644
@@ -6,7 +6,6 @@
 #include <linux/stddef.h>
 #include <linux/module.h>
 #include <linux/memblock.h>
-#include <linux/highmem.h>
 #include <linux/mm.h>
 #include <linux/swap.h>
 #include <linux/slab.h>
@@ -51,8 +50,6 @@ EXPORT_SYMBOL(empty_zero_page);
 pgd_t swapper_pg_dir[PTRS_PER_PGD];
 
 /* Initialized at boot time, and readonly after that */
-unsigned long long highmem;
-EXPORT_SYMBOL(highmem);
 int kmalloc_ok = 0;
 
 /* Used during early boot */
arch/um/kernel/physmem.c +11 -19
index fb2adfb49945..cc5238c1bf1e 100644
@@ -24,17 +24,14 @@ EXPORT_SYMBOL(high_physmem);
 
 extern unsigned long long physmem_size;
 
-void __init mem_total_pages(unsigned long physmem, unsigned long iomem,
-		     unsigned long highmem)
+void __init mem_total_pages(unsigned long physmem, unsigned long iomem)
 {
-	unsigned long phys_pages, highmem_pages;
-	unsigned long iomem_pages, total_pages;
+	unsigned long phys_pages, iomem_pages, total_pages;
 
-	phys_pages    = physmem >> PAGE_SHIFT;
-	iomem_pages   = iomem   >> PAGE_SHIFT;
-	highmem_pages = highmem >> PAGE_SHIFT;
+	phys_pages  = physmem >> PAGE_SHIFT;
+	iomem_pages = iomem   >> PAGE_SHIFT;
 
-	total_pages   = phys_pages + iomem_pages + highmem_pages;
+	total_pages = phys_pages + iomem_pages;
 
 	max_mapnr = total_pages;
 }
@@ -64,13 +61,12 @@ void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
  * @reserve_end:	end address of the physical kernel memory.
  * @len:	Length of total physical memory that should be mapped/made
  *		available, in bytes.
- * @highmem:	Number of highmem bytes that should be mapped/made available.
  *
- * Creates an unlinked temporary file of size (len + highmem) and memory maps
+ * Creates an unlinked temporary file of size (len) and memory maps
  * it on the last executable image address (uml_reserved).
  *
  * The offset is needed as the length of the total physical memory
- * (len + highmem) includes the size of the memory used be the executable image,
+ * (len) includes the size of the memory used be the executable image,
  * but the mapped-to address is the last address of the executable image
  * (uml_reserved == end address of executable image).
  *
@@ -78,19 +74,19 @@ void map_memory(unsigned long virt, unsigned long phys, unsigned long len,
  * of all user space processes/kernel tasks.
  */
 void __init setup_physmem(unsigned long start, unsigned long reserve_end,
-			  unsigned long len, unsigned long long highmem)
+			  unsigned long len)
 {
 	unsigned long reserve = reserve_end - start;
 	long map_size = len - reserve;
 	int err;
 
-	if(map_size <= 0) {
+	if (map_size <= 0) {
 		os_warn("Too few physical memory! Needed=%lu, given=%lu\n",
 			reserve, len);
 		exit(1);
 	}
 
-	physmem_fd = create_mem_file(len + highmem);
+	physmem_fd = create_mem_file(len);
 
 	err = os_map_memory((void *) reserve_end, physmem_fd, reserve,
 			    map_size, 1, 1, 1);
@@ -109,7 +105,7 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,
 	os_write_file(physmem_fd, __syscall_stub_start, PAGE_SIZE);
 	os_fsync_file(physmem_fd);
 
-	memblock_add(__pa(start), len + highmem);
+	memblock_add(__pa(start), len);
 	memblock_reserve(__pa(start), reserve);
 
 	min_low_pfn = PFN_UP(__pa(reserve_end));
@@ -137,10 +133,6 @@ int phys_mapping(unsigned long phys, unsigned long long *offset_out)
 			region = region->next;
 		}
 	}
-	else if (phys < __pa(end_iomem) + highmem) {
-		fd = physmem_fd;
-		*offset_out = phys - iomem_size;
-	}
 
 	return fd;
 }
arch/um/kernel/um_arch.c +7 -10
index 8e594cda6d77..8f86aa468b50 100644
@@ -366,18 +366,15 @@ int __init linux_main(int argc, char **argv)
 
 	setup_machinename(init_utsname()->machine);
 
-	highmem = 0;
+	physmem_size = (physmem_size + PAGE_SIZE - 1) & PAGE_MASK;
 	iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
+
 	max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;
 
-	/*
-	 * Zones have to begin on a 1 << MAX_PAGE_ORDER page boundary,
-	 * so this makes sure that's true for highmem
-	 */
-	max_physmem &= ~((1 << (PAGE_SHIFT + MAX_PAGE_ORDER)) - 1);
 	if (physmem_size + iomem_size > max_physmem) {
-		highmem = physmem_size + iomem_size - max_physmem;
-		physmem_size -= highmem;
+		physmem_size = max_physmem - iomem_size;
+		os_info("Physical memory size shrunk to %llu bytes\n",
+			physmem_size);
 	}
 
 	high_physmem = uml_physmem + physmem_size;
@@ -413,8 +410,8 @@ void __init setup_arch(char **cmdline_p)
 	u8 rng_seed[32];
 
 	stack_protections((unsigned long) &init_thread_info);
-	setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
-	mem_total_pages(physmem_size, iomem_size, highmem);
+	setup_physmem(uml_physmem, uml_reserved, physmem_size);
+	mem_total_pages(physmem_size, iomem_size);
 	uml_dtb_init();
 	read_initrd();
 
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/3] um: Remove highmem leftovers

Hi,

does that mean we can also drop the 3-level page table support on i386? It seems like the two level page table is entirely sufficient on a system without high memory (i.e. only 32bit physical addresses).

When I took a look at it for the 4-level page table support on 64 bit I got a bit confused. But I had not realized that highmem support had been removed.

Benjamin

Quoted 250 lines · Tiwei Bie

Highmem was only supported on UML/i386. And the support has been removed by commit a98a6d864d3b ("um: Remove broken highmem support"). Remove the leftovers and stop UML from trying to setup highmem when the sum of physmem_size and iomem_size exceeds max_physmem.

---
 arch/um/drivers/virtio_uml.c       |  9 +-------- arch/um/include/shared/as-layout.h |  1 - arch/um/include/shared/mem_user.h  |  5 ++--- arch/um/kernel/mem.c               |  3 --- arch/um/kernel/physmem.c           | 30 +++++++++++----------------- --
 arch/um/kernel/um_arch.c           | 17 +++++++----------

 6 files changed, 21 insertions(+), 44 deletions(-)
arch/um/drivers/virtio_uml.c +0 -0
index 2b6e701776b6..e7f5556e3c96 100644
@@ -72,7 +72,7 @@ struct virtio_uml_vq_info {
  	bool suspended;
  };

arch/um/drivers/virtio_uml.c +1 -1
-extern unsigned long long physmem_size, highmem;
+extern unsigned long long physmem_size;


 #define vu_err(vu_dev, ...) dev_err(&(vu_dev)->pdev->dev,
##__VA_ARGS__)

arch/um/drivers/virtio_uml.c +0 -0
@@ -673,13 +673,6 @@ static int vhost_user_set_mem_table(struct
 virtio_uml_device *vu_dev)


  if (rc < 0)
  return rc;

arch/um/drivers/virtio_uml.c +0 -3
-	if (highmem) {
-		msg.payload.mem_regions.num++;
-		rc = vhost_user_init_mem_region(__pa(end_iomem),

highmem,

arch/um/drivers/virtio_uml.c +0 -1
-				&fds[1],

&msg.payload.mem_regions.regions[1]);

arch/um/drivers/virtio_uml.c +0 -3
-		if (rc < 0)
-			return rc;
-	}


  return vhost_user_send(vu_dev, false, &msg, fds, msg.payload.mem_regions.num);

arch/um/include/shared/as-layout.h +0 -1
index 06292fca5a4d..61965a06c18a 100644
@@ -41,7 +41,6 @@ extern unsigned long uml_physmem;
  extern unsigned long uml_reserved;
  extern unsigned long end_vm;
  extern unsigned long start_vm;
-extern unsigned long long highmem;


 extern unsigned long brk_start;

arch/um/include/shared/mem_user.h +0 -0
index 11a723a58545..adfa08062f88 100644
@@ -47,10 +47,9 @@ extern int iomem_size;
  #define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 <<
 22) - 1))


 extern unsigned long find_iomem(char *driver, unsigned long *len_out);
-extern void mem_total_pages(unsigned long physmem, unsigned long iomem,

arch/um/include/shared/mem_user.h +1 -1
-		     unsigned long highmem);
+extern void mem_total_pages(unsigned long physmem, unsigned long

iomem);
 extern void setup_physmem(unsigned long start, unsigned long usable,

arch/um/include/shared/mem_user.h +0 -1
-			  unsigned long len, unsigned long long

highmem);

arch/um/include/shared/mem_user.h +1 -0
+			  unsigned long len);

 extern void map_memory(unsigned long virt, unsigned long phys, unsigned long len, int r, int w, int x);

arch/um/kernel/mem.c +0 -1
index a5b4fe2ad931..5026668dc054 100644
@@ -6,7 +6,6 @@
  #include <linux/stddef.h>
  #include <linux/module.h>
  #include <linux/memblock.h>
-#include <linux/highmem.h>
  #include <linux/mm.h>
  #include <linux/swap.h>
  #include <linux/slab.h>
@@ -51,8 +50,6 @@ EXPORT_SYMBOL(empty_zero_page);
  pgd_t swapper_pg_dir[PTRS_PER_PGD];


 /* Initialized at boot time, and readonly after that */

arch/um/kernel/mem.c +0 -2
-unsigned long long highmem;
-EXPORT_SYMBOL(highmem);

 int kmalloc_ok = 0;

 /* Used during early boot */

arch/um/kernel/physmem.c +0 -0
index fb2adfb49945..cc5238c1bf1e 100644
@@ -24,17 +24,14 @@ EXPORT_SYMBOL(high_physmem);


 extern unsigned long long physmem_size;

-void __init mem_total_pages(unsigned long physmem, unsigned long iomem,

arch/um/kernel/physmem.c +1 -1
-		     unsigned long highmem)
+void __init mem_total_pages(unsigned long physmem, unsigned long

iomem)
 {

arch/um/kernel/physmem.c +1 -2
-	unsigned long phys_pages, highmem_pages;
-	unsigned long iomem_pages, total_pages;
+	unsigned long phys_pages, iomem_pages, total_pages;

arch/um/kernel/physmem.c +2 -3
-	phys_pages    = physmem >> PAGE_SHIFT;
-	iomem_pages   = iomem   >> PAGE_SHIFT;
-	highmem_pages = highmem >> PAGE_SHIFT;
+	phys_pages  = physmem >> PAGE_SHIFT;
+	iomem_pages = iomem   >> PAGE_SHIFT;

arch/um/kernel/physmem.c +1 -1
-	total_pages   = phys_pages + iomem_pages + highmem_pages;
+	total_pages = phys_pages + iomem_pages;


  max_mapnr = total_pages;
 }

arch/um/kernel/physmem.c +0 -0
@@ -64,13 +61,12 @@ void map_memory(unsigned long virt, unsigned long
 phys, unsigned long len,
   * @reserve_end:	end address of the physical kernel memory.
   * @len:	Length of total physical memory that should be

mapped/made
  * available, in bytes.
- * @highmem: Number of highmem bytes that should be mapped/made
available.
  *
- * Creates an unlinked temporary file of size (len + highmem) and memory maps
+ * Creates an unlinked temporary file of size (len) and memory maps
  * it on the last executable image address (uml_reserved). *
  * The offset is needed as the length of the total physical memory
- * (len + highmem) includes the size of the memory used be the executable image,
+ * (len) includes the size of the memory used be the executable image,
  * but the mapped-to address is the last address of the executable image
  * (uml_reserved == end address of executable image).
  *

arch/um/kernel/physmem.c +0 -0
@@ -78,19 +74,19 @@ void map_memory(unsigned long virt, unsigned long
 phys, unsigned long len,
   * of all user space processes/kernel tasks.
   */

 void __init setup_physmem(unsigned long start, unsigned long reserve_end,

arch/um/kernel/physmem.c +0 -1
-			  unsigned long len, unsigned long long

highmem)

arch/um/kernel/physmem.c +1 -0
+			  unsigned long len)

 {
  unsigned long reserve = reserve_end - start; long map_size = len - reserve;
  int err;

arch/um/kernel/physmem.c +1 -1
-	if(map_size <= 0) {
+	if (map_size <= 0) {

  os_warn("Too few physical memory! Needed=%lu, given=%lu\n",
  reserve, len);
  exit(1);
  }

arch/um/kernel/physmem.c +1 -1
-	physmem_fd = create_mem_file(len + highmem);
+	physmem_fd = create_mem_file(len);


  err = os_map_memory((void *) reserve_end, physmem_fd, reserve,
      map_size, 1, 1, 1);

arch/um/kernel/physmem.c +0 -0
@@ -109,7 +105,7 @@ void __init setup_physmem(unsigned long start,
 unsigned long reserve_end,
  	os_write_file(physmem_fd, __syscall_stub_start, PAGE_SIZE);
  	os_fsync_file(physmem_fd);

arch/um/kernel/physmem.c +1 -1
-	memblock_add(__pa(start), len + highmem);
+	memblock_add(__pa(start), len);

  memblock_reserve(__pa(start), reserve);

  min_low_pfn = PFN_UP(__pa(reserve_end));

arch/um/kernel/physmem.c +0 -4
@@ -137,10 +133,6 @@ int phys_mapping(unsigned long phys, unsigned
 long long *offset_out)
  			region = region->next;
  		}
  	}
-	else if (phys < __pa(end_iomem) + highmem) {
-		fd = physmem_fd;
-		*offset_out = phys - iomem_size;
-	}


  return fd;
 }

arch/um/kernel/um_arch.c +0 -0
index 8e594cda6d77..8f86aa468b50 100644
@@ -366,18 +366,15 @@ int __init linux_main(int argc, char **argv)

setup_machinename(init_utsname()->machine);

arch/um/kernel/um_arch.c +1 -1
-	highmem = 0;
+	physmem_size = (physmem_size + PAGE_SIZE - 1) & PAGE_MASK;

  iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK; +
  max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;

arch/um/kernel/um_arch.c +0 -2
-	/*
-	 * Zones have to begin on a 1 << MAX_PAGE_ORDER page

boundary,

arch/um/kernel/um_arch.c +0 -3
-	 * so this makes sure that's true for highmem
-	 */
-	max_physmem &= ~((1 << (PAGE_SHIFT + MAX_PAGE_ORDER)) - 1);

  if (physmem_size + iomem_size > max_physmem) {

arch/um/kernel/um_arch.c +2 -2
-		highmem = physmem_size + iomem_size - max_physmem;
-		physmem_size -= highmem;
+		physmem_size = max_physmem - iomem_size;
+		os_info("Physical memory size shrunk to %llu

bytes\n",

arch/um/kernel/um_arch.c +1 -0
+			physmem_size);

  }

  high_physmem = uml_physmem + physmem_size;

arch/um/kernel/um_arch.c +0 -0
@@ -413,8 +410,8 @@ void __init setup_arch(char **cmdline_p)
  	u8 rng_seed[32];


  stack_protections((unsigned long) &init_thread_info);

arch/um/kernel/um_arch.c +0 -1
-	setup_physmem(uml_physmem, uml_reserved, physmem_size,

highmem);

arch/um/kernel/um_arch.c +2 -1
-	mem_total_pages(physmem_size, iomem_size, highmem);
+	setup_physmem(uml_physmem, uml_reserved, physmem_size);
+	mem_total_pages(physmem_size, iomem_size);

  uml_dtb_init();
  read_initrd();

author
#4 lore raw

Re: [PATCH 2/3] um: Remove highmem leftovers

Quoted 5 lines · Benjamin Berg

Hi,

does that mean we can also drop the 3-level page table support on i386? It seems like the two level page table is entirely sufficient on a system without high memory (i.e. only 32bit physical addresses).

Good point. I think so too.

Regards,
Tiwei

Quoted 258 lines

When I took a look at it for the 4-level page table support on 64 bit I got a bit confused. But I had not realized that highmem support had been removed.

Benjamin

Quoted 250 lines · Tiwei Bie

Highmem was only supported on UML/i386. And the support has been removed by commit a98a6d864d3b ("um: Remove broken highmem support"). Remove the leftovers and stop UML from trying to setup highmem when the sum of physmem_size and iomem_size exceeds max_physmem.

---
 arch/um/drivers/virtio_uml.c       |  9 +-------- arch/um/include/shared/as-layout.h |  1 - arch/um/include/shared/mem_user.h  |  5 ++--- arch/um/kernel/mem.c               |  3 --- arch/um/kernel/physmem.c           | 30 +++++++++++----------------- --
 arch/um/kernel/um_arch.c           | 17 +++++++----------

 6 files changed, 21 insertions(+), 44 deletions(-)
arch/um/drivers/virtio_uml.c +0 -0
index 2b6e701776b6..e7f5556e3c96 100644
@@ -72,7 +72,7 @@ struct virtio_uml_vq_info {
  	bool suspended;
  };

arch/um/drivers/virtio_uml.c +1 -1
-extern unsigned long long physmem_size, highmem;
+extern unsigned long long physmem_size;


 #define vu_err(vu_dev, ...) dev_err(&(vu_dev)->pdev->dev,
##__VA_ARGS__)

arch/um/drivers/virtio_uml.c +0 -0
@@ -673,13 +673,6 @@ static int vhost_user_set_mem_table(struct
 virtio_uml_device *vu_dev)


  if (rc < 0)
  return rc;

arch/um/drivers/virtio_uml.c +0 -3
-	if (highmem) {
-		msg.payload.mem_regions.num++;
-		rc = vhost_user_init_mem_region(__pa(end_iomem),

highmem,

arch/um/drivers/virtio_uml.c +0 -1
-				&fds[1],

&msg.payload.mem_regions.regions[1]);

arch/um/drivers/virtio_uml.c +0 -3
-		if (rc < 0)
-			return rc;
-	}


  return vhost_user_send(vu_dev, false, &msg, fds, msg.payload.mem_regions.num);

arch/um/include/shared/as-layout.h +0 -1
index 06292fca5a4d..61965a06c18a 100644
@@ -41,7 +41,6 @@ extern unsigned long uml_physmem;
  extern unsigned long uml_reserved;
  extern unsigned long end_vm;
  extern unsigned long start_vm;
-extern unsigned long long highmem;


 extern unsigned long brk_start;

arch/um/include/shared/mem_user.h +0 -0
index 11a723a58545..adfa08062f88 100644
@@ -47,10 +47,9 @@ extern int iomem_size;
  #define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 <<
 22) - 1))


 extern unsigned long find_iomem(char *driver, unsigned long *len_out);
-extern void mem_total_pages(unsigned long physmem, unsigned long iomem,

arch/um/include/shared/mem_user.h +1 -1
-		     unsigned long highmem);
+extern void mem_total_pages(unsigned long physmem, unsigned long

iomem);
 extern void setup_physmem(unsigned long start, unsigned long usable,

arch/um/include/shared/mem_user.h +0 -1
-			  unsigned long len, unsigned long long

highmem);

arch/um/include/shared/mem_user.h +1 -0
+			  unsigned long len);

 extern void map_memory(unsigned long virt, unsigned long phys, unsigned long len, int r, int w, int x);

arch/um/kernel/mem.c +0 -1
index a5b4fe2ad931..5026668dc054 100644
@@ -6,7 +6,6 @@
  #include <linux/stddef.h>
  #include <linux/module.h>
  #include <linux/memblock.h>
-#include <linux/highmem.h>
  #include <linux/mm.h>
  #include <linux/swap.h>
  #include <linux/slab.h>
@@ -51,8 +50,6 @@ EXPORT_SYMBOL(empty_zero_page);
  pgd_t swapper_pg_dir[PTRS_PER_PGD];


 /* Initialized at boot time, and readonly after that */

arch/um/kernel/mem.c +0 -2
-unsigned long long highmem;
-EXPORT_SYMBOL(highmem);

 int kmalloc_ok = 0;

 /* Used during early boot */

arch/um/kernel/physmem.c +0 -0
index fb2adfb49945..cc5238c1bf1e 100644
@@ -24,17 +24,14 @@ EXPORT_SYMBOL(high_physmem);


 extern unsigned long long physmem_size;

-void __init mem_total_pages(unsigned long physmem, unsigned long iomem,

arch/um/kernel/physmem.c +1 -1
-		     unsigned long highmem)
+void __init mem_total_pages(unsigned long physmem, unsigned long

iomem)
 {

arch/um/kernel/physmem.c +1 -2
-	unsigned long phys_pages, highmem_pages;
-	unsigned long iomem_pages, total_pages;
+	unsigned long phys_pages, iomem_pages, total_pages;

arch/um/kernel/physmem.c +2 -3
-	phys_pages    = physmem >> PAGE_SHIFT;
-	iomem_pages   = iomem   >> PAGE_SHIFT;
-	highmem_pages = highmem >> PAGE_SHIFT;
+	phys_pages  = physmem >> PAGE_SHIFT;
+	iomem_pages = iomem   >> PAGE_SHIFT;

arch/um/kernel/physmem.c +1 -1
-	total_pages   = phys_pages + iomem_pages + highmem_pages;
+	total_pages = phys_pages + iomem_pages;


  max_mapnr = total_pages;
 }

arch/um/kernel/physmem.c +0 -0
@@ -64,13 +61,12 @@ void map_memory(unsigned long virt, unsigned long
 phys, unsigned long len,
   * @reserve_end:	end address of the physical kernel memory.
   * @len:	Length of total physical memory that should be

mapped/made
  * available, in bytes.
- * @highmem: Number of highmem bytes that should be mapped/made
available.
  *
- * Creates an unlinked temporary file of size (len + highmem) and memory maps
+ * Creates an unlinked temporary file of size (len) and memory maps
  * it on the last executable image address (uml_reserved). *
  * The offset is needed as the length of the total physical memory
- * (len + highmem) includes the size of the memory used be the executable image,
+ * (len) includes the size of the memory used be the executable image,
  * but the mapped-to address is the last address of the executable image
  * (uml_reserved == end address of executable image).
  *

arch/um/kernel/physmem.c +0 -0
@@ -78,19 +74,19 @@ void map_memory(unsigned long virt, unsigned long
 phys, unsigned long len,
   * of all user space processes/kernel tasks.
   */

 void __init setup_physmem(unsigned long start, unsigned long reserve_end,

arch/um/kernel/physmem.c +0 -1
-			  unsigned long len, unsigned long long

highmem)

arch/um/kernel/physmem.c +1 -0
+			  unsigned long len)

 {
  unsigned long reserve = reserve_end - start; long map_size = len - reserve;
  int err;

arch/um/kernel/physmem.c +1 -1
-	if(map_size <= 0) {
+	if (map_size <= 0) {

  os_warn("Too few physical memory! Needed=%lu, given=%lu\n",
  reserve, len);
  exit(1);
  }

arch/um/kernel/physmem.c +1 -1
-	physmem_fd = create_mem_file(len + highmem);
+	physmem_fd = create_mem_file(len);


  err = os_map_memory((void *) reserve_end, physmem_fd, reserve,
      map_size, 1, 1, 1);

arch/um/kernel/physmem.c +0 -0
@@ -109,7 +105,7 @@ void __init setup_physmem(unsigned long start,
 unsigned long reserve_end,
  	os_write_file(physmem_fd, __syscall_stub_start, PAGE_SIZE);
  	os_fsync_file(physmem_fd);

arch/um/kernel/physmem.c +1 -1
-	memblock_add(__pa(start), len + highmem);
+	memblock_add(__pa(start), len);

  memblock_reserve(__pa(start), reserve);

  min_low_pfn = PFN_UP(__pa(reserve_end));

arch/um/kernel/physmem.c +0 -4
@@ -137,10 +133,6 @@ int phys_mapping(unsigned long phys, unsigned
 long long *offset_out)
  			region = region->next;
  		}
  	}
-	else if (phys < __pa(end_iomem) + highmem) {
-		fd = physmem_fd;
-		*offset_out = phys - iomem_size;
-	}


  return fd;
 }

arch/um/kernel/um_arch.c +0 -0
index 8e594cda6d77..8f86aa468b50 100644
@@ -366,18 +366,15 @@ int __init linux_main(int argc, char **argv)

setup_machinename(init_utsname()->machine);

arch/um/kernel/um_arch.c +1 -1
-	highmem = 0;
+	physmem_size = (physmem_size + PAGE_SIZE - 1) & PAGE_MASK;

  iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK; +
  max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;

arch/um/kernel/um_arch.c +0 -2
-	/*
-	 * Zones have to begin on a 1 << MAX_PAGE_ORDER page

boundary,

arch/um/kernel/um_arch.c +0 -3
-	 * so this makes sure that's true for highmem
-	 */
-	max_physmem &= ~((1 << (PAGE_SHIFT + MAX_PAGE_ORDER)) - 1);

  if (physmem_size + iomem_size > max_physmem) {

arch/um/kernel/um_arch.c +2 -2
-		highmem = physmem_size + iomem_size - max_physmem;
-		physmem_size -= highmem;
+		physmem_size = max_physmem - iomem_size;
+		os_info("Physical memory size shrunk to %llu

bytes\n",

arch/um/kernel/um_arch.c +1 -0
+			physmem_size);

  }

  high_physmem = uml_physmem + physmem_size;

arch/um/kernel/um_arch.c +0 -0
@@ -413,8 +410,8 @@ void __init setup_arch(char **cmdline_p)
  	u8 rng_seed[32];


  stack_protections((unsigned long) &init_thread_info);

arch/um/kernel/um_arch.c +0 -1
-	setup_physmem(uml_physmem, uml_reserved, physmem_size,

highmem);

arch/um/kernel/um_arch.c +2 -1
-	mem_total_pages(physmem_size, iomem_size, highmem);
+	setup_physmem(uml_physmem, uml_reserved, physmem_size);
+	mem_total_pages(physmem_size, iomem_size);

  uml_dtb_init();
  read_initrd();

author
#5 lore raw

PATCH 3/3 um: Fix the definition for physmem_size

In reply to Tiwei Bie

Currently physmem_size is defined as long long but declared locally as unsigned long long before using it in separate .c files. Make them match by defining physmem_size as unsigned long long and also move the declaration to a common header to allow the compiler to check it.

---
 arch/um/drivers/virtio_uml.c       | 2 --
 arch/um/include/shared/as-layout.h | 2 ++
 arch/um/kernel/physmem.c           | 2 --
 arch/um/kernel/um_arch.c           | 2 +-
 4 files changed, 3 insertions(+), 5 deletions(-)
arch/um/drivers/virtio_uml.c +0 -2
index e7f5556e3c96..4d3e9b9f5b61 100644
@@ -72,8 +72,6 @@ struct virtio_uml_vq_info {
 	bool suspended;
 };
 
-extern unsigned long long physmem_size;
-
 #define vu_err(vu_dev, ...)	dev_err(&(vu_dev)->pdev->dev, ##__VA_ARGS__)
 
 /* Vhost-user protocol */
arch/um/include/shared/as-layout.h +2 -0
index 61965a06c18a..283226c34ca4 100644
@@ -36,6 +36,8 @@ struct cpu_task {
 
 extern struct cpu_task cpu_tasks[];
 
+extern unsigned long long physmem_size;
+
 extern unsigned long high_physmem;
 extern unsigned long uml_physmem;
 extern unsigned long uml_reserved;
arch/um/kernel/physmem.c +0 -2
index cc5238c1bf1e..cee3d09ba429 100644
@@ -22,8 +22,6 @@ static int physmem_fd = -1;
 unsigned long high_physmem;
 EXPORT_SYMBOL(high_physmem);
 
-extern unsigned long long physmem_size;
-
 void __init mem_total_pages(unsigned long physmem, unsigned long iomem)
 {
 	unsigned long phys_pages, iomem_pages, total_pages;
arch/um/kernel/um_arch.c +1 -1
index 8f86aa468b50..99cdf4b2d648 100644
@@ -131,7 +131,7 @@ static int have_root __initdata;
 static int have_console __initdata;
 
 /* Set in uml_mem_setup and modified in linux_main */
-long long physmem_size = 64 * 1024 * 1024;
+unsigned long long physmem_size = 64 * 1024 * 1024;
 EXPORT_SYMBOL(physmem_size);
 
 static const char *usage_string =
Signature · 1 line
2.34.1