um: Memory related cleanups
v2 cover um: Memory related cleanups
From: Tiwei Bie <[email protected]>
v2:
- Add "um: Make host_task_size a local variable";
v1: https://lore.kernel.org/all/[email protected]/
Tiwei Bie (4):
um: Make host_task_size a local variable
um: Use PAGE_ALIGN() for address alignment
um: Replace UML_ROUND_UP() with PAGE_ALIGN()
um: Remove file-based iomem emulation support
arch/um/Kconfig | 6 -- arch/um/drivers/Makefile | 1 - arch/um/drivers/mmapper_kern.c | 135 ----------------------------- arch/um/include/asm/pgtable.h | 4 +- arch/um/include/shared/as-layout.h | 1 - arch/um/include/shared/kern_util.h | 4 - arch/um/include/shared/mem_user.h | 13 --- arch/um/kernel/mem.c | 4 +- arch/um/kernel/physmem.c | 71 --------------- arch/um/kernel/um_arch.c | 22 ++--- arch/um/os-Linux/skas/process.c | 7 -- arch/um/os-Linux/start_up.c | 50 ----------- 12 files changed, 10 insertions(+), 308 deletions(-) delete mode 100644 arch/um/drivers/mmapper_kern.c
base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
Signature · 1 line
2.34.1
PATCH v2 1/4 um: Make host_task_size a local variable
From: Tiwei Bie <[email protected]>
Currently, host_task_size is a global variable, but it is only used in linux_main() to compute stub_start and task_size. Make it a local variable to limit its scope to where it is actually needed.
--- arch/um/include/shared/as-layout.h | 1 - arch/um/kernel/um_arch.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-)
arch/um/include/shared/as-layout.h +0 -1
@@ -44,7 +44,6 @@ extern unsigned long start_vm;extern unsigned long brk_start; -extern unsigned long host_task_size;extern unsigned long stub_start;extern int linux_main (int argc,char **argv,char **envp);
arch/um/kernel/um_arch.c +1 -2
@@ -254,8 +254,6 @@ unsigned long stub_start;unsigned long task_size;EXPORT_SYMBOL (task_size); -unsigned long host_task_size; -unsigned long brk_start;unsigned long end_iomem;EXPORT_SYMBOL (end_iomem);
@@ -308,6 +306,7 @@ int __init linux_main(int argc, char **argv, char **envp) {unsigned long avail, diff;unsigned long virtmem_size, max_physmem; +unsigned long host_task_size;unsigned long stack;unsigned int i;int add;
Signature · 1 line
2.34.1
PATCH v2 2/4 um: Use PAGE_ALIGN() for address alignment
In reply to Tiwei BieFrom: Tiwei Bie <[email protected]>
Use PAGE_ALIGN() instead of open-coded calculations.
--- arch/um/kernel/um_arch.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
arch/um/kernel/um_arch.c +3 -6
@@ -296,10 +296,7 @@ static unsigned long __init get_top_address(char **envp) top_addr = (unsigned long ) envp[i]; } - top_addr &= ~(UM_KERN_PAGE_SIZE -1 ); - top_addr +=UM_KERN_PAGE_SIZE ; - -return top_addr; +return PAGE_ALIGN (top_addr +1 ); }int __init linux_main (int argc,char **argv,char **envp)
@@ -368,8 +365,8 @@ int __init linux_main(int argc, char **argv, char **envp)setup_machinename (init_utsname ()->machine); - physmem_size = (physmem_size +PAGE_SIZE -1 ) &PAGE_MASK ; - iomem_size = (iomem_size +PAGE_SIZE -1 ) &PAGE_MASK ; + physmem_size =PAGE_ALIGN (physmem_size); + iomem_size =PAGE_ALIGN (iomem_size); max_physmem =TASK_SIZE - uml_physmem - iomem_size -MIN_VMALLOC ;if (physmem_size > max_physmem) {
Signature · 1 line
2.34.1
PATCH v2 3/4 um: Replace UML_ROUND_UP() with PAGE_ALIGN()
In reply to Tiwei BieFrom: Tiwei Bie <[email protected]>
Although UML_ROUND_UP() is defined in a shared header file, it depends on the PAGE_SIZE and PAGE_MASK macros, so it can only be used in kernel code. Considering its name is not very clear and its functionality is the same as PAGE_ALIGN(), replace its usages with a direct call to PAGE_ALIGN() and remove it.
--- arch/um/include/shared/kern_util.h | 3 --- arch/um/kernel/mem.c | 2 +- arch/um/kernel/um_arch.c | 5 ++--- 3 files changed, 3 insertions(+), 7 deletions(-)
arch/um/include/shared/kern_util.h +0 -3
@@ -15,9 +15,6 @@ extern int uml_exitcode;extern int kmalloc_ok; -#define UML_ROUND_UP (addr) \ - ((((unsigned long) addr) + PAGE_SIZE - 1) & PAGE_MASK) -extern unsigned long alloc_stack (int order,int atomic);extern void free_stack (unsigned long stack,int order);
arch/um/kernel/mem.c +1 -1
@@ -71,7 +71,7 @@ void __init arch_mm_preinit(void)/* Map in the area just after the brk now that kmalloc is about * to be turned on. */ - brk_end = (unsigned long )UML_ROUND_UP (sbrk (0 )); + brk_end =PAGE_ALIGN ((unsigned long )sbrk (0 ));map_memory (brk_end,__pa (brk_end), uml_reserved - brk_end,1 ,1 ,0 );memblock_free ((void *)brk_end, uml_reserved - brk_end); uml_reserved = brk_end;
arch/um/kernel/um_arch.c +2 -3
@@ -350,12 +350,11 @@ int __init linux_main(int argc, char **argv, char **envp)* so they actually get what they asked for. This should * add zero for non-exec shield users */ - - diff =UML_ROUND_UP (brk_start) -UML_ROUND_UP (&_end); + diff =PAGE_ALIGN (brk_start) -PAGE_ALIGN ((unsigned long ) &_end);if (diff >1024 *1024 ) {os_info ("Adding %ld bytes to physical memory to account for " "exec-shield gap\n" , diff); - physmem_size +=UML_ROUND_UP (brk_start) -UML_ROUND_UP (&_end); + physmem_size += diff; } uml_physmem = (unsigned long ) __binary_start &PAGE_MASK ;
Signature · 1 line
2.34.1
PATCH v2 4/4 um: Remove file-based iomem emulation support
In reply to Tiwei BieFrom: Tiwei Bie <[email protected]>
The file-based iomem emulation was introduced to support writing paravirtualized drivers based on emulated iomem regions. However, the only driver that makes use of it is an example driver called mmapper, which was written over two decades ago.
We now have several modern device emulation mechanisms, such as vhost-user-based virtio-uml. Remove the file-based iomem emulation support to reduce the maintenance burden.
--- arch/um/Kconfig | 6 -- arch/um/drivers/Makefile | 1 - arch/um/drivers/mmapper_kern.c | 135 ----------------------------- arch/um/include/asm/pgtable.h | 4 +- arch/um/include/shared/kern_util.h | 1 - arch/um/include/shared/mem_user.h | 13 --- arch/um/kernel/mem.c | 2 +- arch/um/kernel/physmem.c | 71 --------------- arch/um/kernel/um_arch.c | 7 +- arch/um/os-Linux/skas/process.c | 7 -- arch/um/os-Linux/start_up.c | 50 ----------- 11 files changed, 4 insertions(+), 293 deletions(-) delete mode 100644 arch/um/drivers/mmapper_kern.c
arch/um/Kconfig +0 -6
@@ -200,12 +200,6 @@ config KERNEL_STACK_ORDER increase in the size of the state which needs to be saved when handling signals. -config MMAPPER - tristate "iomem emulation driver" - help - This driver allows a host file to be used as emulated IO memory inside - UML. - config PGTABLE_LEVELS int default 4 if 64BIT
arch/um/drivers/Makefile +0 -1
@@ -29,7 +29,6 @@ obj-$(CONFIG_STDERR_CONSOLE) += stderr_console.o obj-$(CONFIG_UML_NET_VECTOR) += vector.o obj-$(CONFIG_MCONSOLE) += mconsole.o -obj-$(CONFIG_MMAPPER) += mmapper_kern.o obj-$(CONFIG_BLK_DEV_UBD) += ubd.o obj-$(CONFIG_UML_SOUND) += hostaudio.o obj-$(CONFIG_NULL_CHAN) += null.o
arch/um/drivers/mmapper_kern.c deleted +0 -135
135 lines not on this page · raw message
arch/um/include/asm/pgtable.h +2 -2
@@ -45,10 +45,10 @@ extern unsigned long *empty_zero_page;* area for the same reason. ;) */ -extern unsigned long end_iomem; +#include <as-layout.h> /* for high_physmem */ #define VMALLOC_OFFSET (__va_space) -#define VMALLOC_START ((end_iomem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)) +#define VMALLOC_START ((high_physmem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))#define VMALLOC_END (TASK_SIZE-2*PAGE_SIZE)#define MODULES_VADDR VMALLOC_START#define MODULES_END VMALLOC_END
arch/um/include/shared/kern_util.h +0 -1
@@ -39,7 +39,6 @@ extern void uml_pm_wake(void);extern int start_uml (void );extern void paging_init (void ); -extern int parse_iomem (char *str,int *add);extern void uml_cleanup (void );extern void do_uml_exitcalls (void );
arch/um/include/shared/mem_user.h +0 -13
@@ -32,21 +32,8 @@#ifndef _MEM_USER_H#define _MEM_USER_H -struct iomem_region { -struct iomem_region *next; -char *driver; -int fd; -int size; -unsigned long phys; -unsigned long virt; -}; - -extern struct iomem_region *iomem_regions; -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 setup_physmem (unsigned long start,unsigned long usable,unsigned long len); extern void map_memory(unsigned long virt, unsigned long phys,
arch/um/kernel/mem.c +1 -1
@@ -197,7 +197,7 @@ void __init paging_init(void)panic ("%s: Failed to allocate %lu bytes align=%lx\n" , __func__,PAGE_SIZE ,PAGE_SIZE ); - max_zone_pfn[ZONE_NORMAL ] = end_iomem >>PAGE_SHIFT ; + max_zone_pfn[ZONE_NORMAL ] = high_physmem >>PAGE_SHIFT ;free_area_init (max_zone_pfn);#if IS_ENABLED (CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA )
arch/um/kernel/physmem.c +0 -71
80 lines not on this page · raw message
arch/um/kernel/um_arch.c +1 -6
@@ -255,8 +255,6 @@ unsigned long task_size;EXPORT_SYMBOL (task_size);unsigned long brk_start; -unsigned long end_iomem; -EXPORT_SYMBOL (end_iomem);#define MIN_VMALLOC (32 * 1024 * 1024)
@@ -365,9 +363,7 @@ int __init linux_main(int argc, char **argv, char **envp)setup_machinename (init_utsname ()->machine); physmem_size =PAGE_ALIGN (physmem_size); - iomem_size =PAGE_ALIGN (iomem_size); - - max_physmem =TASK_SIZE - uml_physmem - iomem_size -MIN_VMALLOC ; + max_physmem =TASK_SIZE - uml_physmem -MIN_VMALLOC ;if (physmem_size > max_physmem) { physmem_size = max_physmem; os_info("Physical memory size shrunk to %llu bytes\n",
@@ -375,7 +371,6 @@ int __init linux_main(int argc, char **argv, char **envp) } high_physmem = uml_physmem + physmem_size; - end_iomem = high_physmem + iomem_size; start_vm =VMALLOC_START ;
arch/um/os-Linux/skas/process.c +0 -7
@@ -298,7 +298,6 @@ static int userspace_tramp(void *data) .seccomp = using_seccomp, .stub_start = STUB_START, }; -struct iomem_region *iomem;int ret;if (using_seccomp) {
@@ -332,12 +331,6 @@ static int userspace_tramp(void *data)fcntl (init_data.stub_data_fd,F_SETFD ,0 ); -/* In SECCOMP mode, these FDs are passed when needed */ -if (!using_seccomp) { -for (iomem = iomem_regions; iomem; iomem = iomem->next) -fcntl (iomem->fd,F_SETFD ,0 ); - } -/* dup2 signaling FD/socket to STDIN */ if (dup2 (tramp_data->sockpair[0 ],0 ) <0 )exit (3 );
arch/um/os-Linux/start_up.c +0 -50
53 lines not on this page · raw message
Signature · 1 line
2.34.1