Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

um: Remove file-based iomem emulation support

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.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
Link: https://patch.msgid.link/20251027054519.1996090-5-tiwei.bie@linux.dev
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Tiwei Bie and committed by
Johannes Berg
a7f7dbae 9c84022c

+4 -293
-6
arch/um/Kconfig
··· 200 200 increase in the size of the state which needs to be saved when handling 201 201 signals. 202 202 203 - config MMAPPER 204 - tristate "iomem emulation driver" 205 - help 206 - This driver allows a host file to be used as emulated IO memory inside 207 - UML. 208 - 209 203 config PGTABLE_LEVELS 210 204 int 211 205 default 4 if 64BIT
-1
arch/um/drivers/Makefile
··· 29 29 30 30 obj-$(CONFIG_UML_NET_VECTOR) += vector.o 31 31 obj-$(CONFIG_MCONSOLE) += mconsole.o 32 - obj-$(CONFIG_MMAPPER) += mmapper_kern.o 33 32 obj-$(CONFIG_BLK_DEV_UBD) += ubd.o 34 33 obj-$(CONFIG_UML_SOUND) += hostaudio.o 35 34 obj-$(CONFIG_NULL_CHAN) += null.o
-135
arch/um/drivers/mmapper_kern.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * arch/um/drivers/mmapper_kern.c 4 - * 5 - * BRIEF MODULE DESCRIPTION 6 - * 7 - * Copyright (C) 2000 RidgeRun, Inc. 8 - * Author: RidgeRun, Inc. 9 - * Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com 10 - * 11 - */ 12 - 13 - #include <linux/stddef.h> 14 - #include <linux/types.h> 15 - #include <linux/fs.h> 16 - #include <linux/init.h> 17 - #include <linux/miscdevice.h> 18 - #include <linux/module.h> 19 - #include <linux/mm.h> 20 - 21 - #include <linux/uaccess.h> 22 - #include <mem_user.h> 23 - 24 - /* These are set in mmapper_init, which is called at boot time */ 25 - static unsigned long mmapper_size; 26 - static unsigned long p_buf; 27 - static char *v_buf; 28 - 29 - static ssize_t mmapper_read(struct file *file, char __user *buf, size_t count, 30 - loff_t *ppos) 31 - { 32 - return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size); 33 - } 34 - 35 - static ssize_t mmapper_write(struct file *file, const char __user *buf, 36 - size_t count, loff_t *ppos) 37 - { 38 - if (*ppos > mmapper_size) 39 - return -EINVAL; 40 - 41 - return simple_write_to_buffer(v_buf, mmapper_size, ppos, buf, count); 42 - } 43 - 44 - static long mmapper_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 45 - { 46 - return -ENOIOCTLCMD; 47 - } 48 - 49 - static int mmapper_mmap(struct file *file, struct vm_area_struct *vma) 50 - { 51 - int ret = -EINVAL; 52 - int size; 53 - 54 - if (vma->vm_pgoff != 0) 55 - goto out; 56 - 57 - size = vma->vm_end - vma->vm_start; 58 - if (size > mmapper_size) 59 - return -EFAULT; 60 - 61 - /* 62 - * XXX A comment above remap_pfn_range says it should only be 63 - * called when the mm semaphore is held 64 - */ 65 - if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size, 66 - vma->vm_page_prot)) 67 - goto out; 68 - ret = 0; 69 - out: 70 - return ret; 71 - } 72 - 73 - static int mmapper_open(struct inode *inode, struct file *file) 74 - { 75 - return 0; 76 - } 77 - 78 - static int mmapper_release(struct inode *inode, struct file *file) 79 - { 80 - return 0; 81 - } 82 - 83 - static const struct file_operations mmapper_fops = { 84 - .owner = THIS_MODULE, 85 - .read = mmapper_read, 86 - .write = mmapper_write, 87 - .unlocked_ioctl = mmapper_ioctl, 88 - .mmap = mmapper_mmap, 89 - .open = mmapper_open, 90 - .release = mmapper_release, 91 - .llseek = default_llseek, 92 - }; 93 - 94 - /* 95 - * No locking needed - only used (and modified) by below initcall and exitcall. 96 - */ 97 - static struct miscdevice mmapper_dev = { 98 - .minor = MISC_DYNAMIC_MINOR, 99 - .name = "mmapper", 100 - .fops = &mmapper_fops 101 - }; 102 - 103 - static int __init mmapper_init(void) 104 - { 105 - int err; 106 - 107 - printk(KERN_INFO "Mapper v0.1\n"); 108 - 109 - v_buf = (char *) find_iomem("mmapper", &mmapper_size); 110 - if (mmapper_size == 0) { 111 - printk(KERN_ERR "mmapper_init - find_iomem failed\n"); 112 - return -ENODEV; 113 - } 114 - p_buf = __pa(v_buf); 115 - 116 - err = misc_register(&mmapper_dev); 117 - if (err) { 118 - printk(KERN_ERR "mmapper - misc_register failed, err = %d\n", 119 - err); 120 - return err; 121 - } 122 - return 0; 123 - } 124 - 125 - static void __exit mmapper_exit(void) 126 - { 127 - misc_deregister(&mmapper_dev); 128 - } 129 - 130 - module_init(mmapper_init); 131 - module_exit(mmapper_exit); 132 - 133 - MODULE_AUTHOR("Greg Lonnon <glonnon@ridgerun.com>"); 134 - MODULE_DESCRIPTION("DSPLinux simulator mmapper driver"); 135 - MODULE_LICENSE("GPL");
+2 -2
arch/um/include/asm/pgtable.h
··· 45 45 * area for the same reason. ;) 46 46 */ 47 47 48 - extern unsigned long end_iomem; 48 + #include <as-layout.h> /* for high_physmem */ 49 49 50 50 #define VMALLOC_OFFSET (__va_space) 51 - #define VMALLOC_START ((end_iomem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)) 51 + #define VMALLOC_START ((high_physmem + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)) 52 52 #define VMALLOC_END (TASK_SIZE-2*PAGE_SIZE) 53 53 #define MODULES_VADDR VMALLOC_START 54 54 #define MODULES_END VMALLOC_END
-1
arch/um/include/shared/kern_util.h
··· 39 39 40 40 extern int start_uml(void); 41 41 extern void paging_init(void); 42 - extern int parse_iomem(char *str, int *add); 43 42 44 43 extern void uml_cleanup(void); 45 44 extern void do_uml_exitcalls(void);
-13
arch/um/include/shared/mem_user.h
··· 32 32 #ifndef _MEM_USER_H 33 33 #define _MEM_USER_H 34 34 35 - struct iomem_region { 36 - struct iomem_region *next; 37 - char *driver; 38 - int fd; 39 - int size; 40 - unsigned long phys; 41 - unsigned long virt; 42 - }; 43 - 44 - extern struct iomem_region *iomem_regions; 45 - extern int iomem_size; 46 - 47 35 #define ROUND_4M(n) ((((unsigned long) (n)) + (1 << 22)) & ~((1 << 22) - 1)) 48 36 49 - extern unsigned long find_iomem(char *driver, unsigned long *len_out); 50 37 extern void setup_physmem(unsigned long start, unsigned long usable, 51 38 unsigned long len); 52 39 extern void map_memory(unsigned long virt, unsigned long phys,
+1 -1
arch/um/kernel/mem.c
··· 197 197 panic("%s: Failed to allocate %lu bytes align=%lx\n", 198 198 __func__, PAGE_SIZE, PAGE_SIZE); 199 199 200 - max_zone_pfn[ZONE_NORMAL] = end_iomem >> PAGE_SHIFT; 200 + max_zone_pfn[ZONE_NORMAL] = high_physmem >> PAGE_SHIFT; 201 201 free_area_init(max_zone_pfn); 202 202 203 203 #if IS_ENABLED(CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA)
-71
arch/um/kernel/physmem.c
··· 105 105 fd = physmem_fd; 106 106 *offset_out = phys; 107 107 } 108 - else if (phys < __pa(end_iomem)) { 109 - struct iomem_region *region = iomem_regions; 110 - 111 - while (region != NULL) { 112 - if ((phys >= region->phys) && 113 - (phys < region->phys + region->size)) { 114 - fd = region->fd; 115 - *offset_out = phys - region->phys; 116 - break; 117 - } 118 - region = region->next; 119 - } 120 - } 121 108 122 109 return fd; 123 110 } ··· 127 140 " be more, and the excess, if it's ever used, will just be swapped out.\n" 128 141 " Example: mem=64M\n\n" 129 142 ); 130 - 131 - __uml_setup("iomem=", parse_iomem, 132 - "iomem=<name>,<file>\n" 133 - " Configure <file> as an IO memory region named <name>.\n\n" 134 - ); 135 - 136 - /* 137 - * This list is constructed in parse_iomem and addresses filled in 138 - * setup_iomem, both of which run during early boot. Afterwards, it's 139 - * unchanged. 140 - */ 141 - struct iomem_region *iomem_regions; 142 - 143 - /* Initialized in parse_iomem and unchanged thereafter */ 144 - int iomem_size; 145 - 146 - unsigned long find_iomem(char *driver, unsigned long *len_out) 147 - { 148 - struct iomem_region *region = iomem_regions; 149 - 150 - while (region != NULL) { 151 - if (!strcmp(region->driver, driver)) { 152 - *len_out = region->size; 153 - return region->virt; 154 - } 155 - 156 - region = region->next; 157 - } 158 - 159 - return 0; 160 - } 161 - EXPORT_SYMBOL(find_iomem); 162 - 163 - static int setup_iomem(void) 164 - { 165 - struct iomem_region *region = iomem_regions; 166 - unsigned long iomem_start = high_physmem + PAGE_SIZE; 167 - int err; 168 - 169 - while (region != NULL) { 170 - err = os_map_memory((void *) iomem_start, region->fd, 0, 171 - region->size, 1, 1, 0); 172 - if (err) 173 - printk(KERN_ERR "Mapping iomem region for driver '%s' " 174 - "failed, errno = %d\n", region->driver, -err); 175 - else { 176 - region->virt = iomem_start; 177 - region->phys = __pa(region->virt); 178 - } 179 - 180 - iomem_start += region->size + PAGE_SIZE; 181 - region = region->next; 182 - } 183 - 184 - return 0; 185 - } 186 - 187 - __initcall(setup_iomem);
+1 -6
arch/um/kernel/um_arch.c
··· 253 253 EXPORT_SYMBOL(task_size); 254 254 255 255 unsigned long brk_start; 256 - unsigned long end_iomem; 257 - EXPORT_SYMBOL(end_iomem); 258 256 259 257 #define MIN_VMALLOC (32 * 1024 * 1024) 260 258 ··· 361 363 setup_machinename(init_utsname()->machine); 362 364 363 365 physmem_size = PAGE_ALIGN(physmem_size); 364 - iomem_size = PAGE_ALIGN(iomem_size); 365 - 366 - max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC; 366 + max_physmem = TASK_SIZE - uml_physmem - MIN_VMALLOC; 367 367 if (physmem_size > max_physmem) { 368 368 physmem_size = max_physmem; 369 369 os_info("Physical memory size shrunk to %llu bytes\n", ··· 369 373 } 370 374 371 375 high_physmem = uml_physmem + physmem_size; 372 - end_iomem = high_physmem + iomem_size; 373 376 374 377 start_vm = VMALLOC_START; 375 378
-7
arch/um/os-Linux/skas/process.c
··· 298 298 .seccomp = using_seccomp, 299 299 .stub_start = STUB_START, 300 300 }; 301 - struct iomem_region *iomem; 302 301 int ret; 303 302 304 303 if (using_seccomp) { ··· 330 331 syscall(__NR_close_range, 0, ~0U, CLOSE_RANGE_CLOEXEC); 331 332 332 333 fcntl(init_data.stub_data_fd, F_SETFD, 0); 333 - 334 - /* In SECCOMP mode, these FDs are passed when needed */ 335 - if (!using_seccomp) { 336 - for (iomem = iomem_regions; iomem; iomem = iomem->next) 337 - fcntl(iomem->fd, F_SETFD, 0); 338 - } 339 334 340 335 /* dup2 signaling FD/socket to STDIN */ 341 336 if (dup2(tramp_data->sockpair[0], 0) < 0)
-50
arch/um/os-Linux/start_up.c
··· 489 489 fatal("Failed to initialize default registers"); 490 490 stop_ptraced_child(pid, 1); 491 491 } 492 - 493 - int __init parse_iomem(char *str, int *add) 494 - { 495 - struct iomem_region *new; 496 - struct stat64 buf; 497 - char *file, *driver; 498 - int fd, size; 499 - 500 - driver = str; 501 - file = strchr(str,','); 502 - if (file == NULL) { 503 - os_warn("parse_iomem : failed to parse iomem\n"); 504 - goto out; 505 - } 506 - *file = '\0'; 507 - file++; 508 - fd = open(file, O_RDWR, 0); 509 - if (fd < 0) { 510 - perror("parse_iomem - Couldn't open io file"); 511 - goto out; 512 - } 513 - 514 - if (fstat64(fd, &buf) < 0) { 515 - perror("parse_iomem - cannot stat_fd file"); 516 - goto out_close; 517 - } 518 - 519 - new = malloc(sizeof(*new)); 520 - if (new == NULL) { 521 - perror("Couldn't allocate iomem_region struct"); 522 - goto out_close; 523 - } 524 - 525 - size = (buf.st_size + UM_KERN_PAGE_SIZE) & ~(UM_KERN_PAGE_SIZE - 1); 526 - 527 - *new = ((struct iomem_region) { .next = iomem_regions, 528 - .driver = driver, 529 - .fd = fd, 530 - .size = size, 531 - .phys = 0, 532 - .virt = 0 }); 533 - iomem_regions = new; 534 - iomem_size += new->size + UM_KERN_PAGE_SIZE; 535 - 536 - return 0; 537 - out_close: 538 - close(fd); 539 - out: 540 - return 1; 541 - }