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

Merge tag 'mm-nonmm-stable-2026-02-18-19-56' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Pull more non-MM updates from Andrew Morton:

- "two fixes in kho_populate()" fixes a couple of not-major issues in
the kexec handover code (Ran Xiaokai)

- misc singletons

* tag 'mm-nonmm-stable-2026-02-18-19-56' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm:
lib/group_cpus: handle const qualifier from clusters allocation type
kho: remove unnecessary WARN_ON(err) in kho_populate()
kho: fix missing early_memunmap() call in kho_populate()
scripts/gdb: implement x86_page_ops in mm.py
objpool: fix the overestimation of object pooling metadata size
selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT
delayacct: fix build regression on accounting tool

+301 -31
+15 -13
kernel/liveupdate/kexec_handover.c
··· 1463 1463 struct kho_scratch *scratch = NULL; 1464 1464 phys_addr_t mem_map_phys; 1465 1465 void *fdt = NULL; 1466 + bool populated = false; 1466 1467 int err; 1467 1468 1468 1469 /* Validate the input FDT */ 1469 1470 fdt = early_memremap(fdt_phys, fdt_len); 1470 1471 if (!fdt) { 1471 1472 pr_warn("setup: failed to memremap FDT (0x%llx)\n", fdt_phys); 1472 - goto err_report; 1473 + goto report; 1473 1474 } 1474 1475 err = fdt_check_header(fdt); 1475 1476 if (err) { 1476 1477 pr_warn("setup: handover FDT (0x%llx) is invalid: %d\n", 1477 1478 fdt_phys, err); 1478 - goto err_unmap_fdt; 1479 + goto unmap_fdt; 1479 1480 } 1480 1481 err = fdt_node_check_compatible(fdt, 0, KHO_FDT_COMPATIBLE); 1481 1482 if (err) { 1482 1483 pr_warn("setup: handover FDT (0x%llx) is incompatible with '%s': %d\n", 1483 1484 fdt_phys, KHO_FDT_COMPATIBLE, err); 1484 - goto err_unmap_fdt; 1485 + goto unmap_fdt; 1485 1486 } 1486 1487 1487 1488 mem_map_phys = kho_get_mem_map_phys(fdt); 1488 1489 if (!mem_map_phys) 1489 - goto err_unmap_fdt; 1490 + goto unmap_fdt; 1490 1491 1491 1492 scratch = early_memremap(scratch_phys, scratch_len); 1492 1493 if (!scratch) { 1493 1494 pr_warn("setup: failed to memremap scratch (phys=0x%llx, len=%lld)\n", 1494 1495 scratch_phys, scratch_len); 1495 - goto err_unmap_fdt; 1496 + goto unmap_fdt; 1496 1497 } 1497 1498 1498 1499 /* ··· 1507 1506 1508 1507 memblock_add(area->addr, size); 1509 1508 err = memblock_mark_kho_scratch(area->addr, size); 1510 - if (WARN_ON(err)) { 1509 + if (err) { 1511 1510 pr_warn("failed to mark the scratch region 0x%pa+0x%pa: %pe", 1512 1511 &area->addr, &size, ERR_PTR(err)); 1513 - goto err_unmap_scratch; 1512 + goto unmap_scratch; 1514 1513 } 1515 1514 pr_debug("Marked 0x%pa+0x%pa as scratch", &area->addr, &size); 1516 1515 } ··· 1530 1529 kho_in.scratch_phys = scratch_phys; 1531 1530 kho_in.mem_map_phys = mem_map_phys; 1532 1531 kho_scratch_cnt = scratch_cnt; 1532 + 1533 + populated = true; 1533 1534 pr_info("found kexec handover data.\n"); 1534 1535 1535 - return; 1536 - 1537 - err_unmap_scratch: 1536 + unmap_scratch: 1538 1537 early_memunmap(scratch, scratch_len); 1539 - err_unmap_fdt: 1538 + unmap_fdt: 1540 1539 early_memunmap(fdt, fdt_len); 1541 - err_report: 1542 - pr_warn("disabling KHO revival\n"); 1540 + report: 1541 + if (!populated) 1542 + pr_warn("disabling KHO revival\n"); 1543 1543 } 1544 1544 1545 1545 /* Helper functions for kexec_file_load */
+1 -1
lib/group_cpus.c
··· 320 320 goto no_cluster; 321 321 322 322 /* Allocate memory based on cluster number. */ 323 - clusters = kcalloc(ncluster, sizeof(struct cpumask *), GFP_KERNEL); 323 + clusters = kcalloc(ncluster, sizeof(*clusters), GFP_KERNEL); 324 324 if (!clusters) 325 325 goto no_cluster; 326 326 cluster_groups = kcalloc(ncluster, sizeof(struct node_groups), GFP_KERNEL);
+1 -1
lib/objpool.c
··· 142 142 pool->gfp = gfp & ~__GFP_ZERO; 143 143 pool->context = context; 144 144 pool->release = release; 145 - slot_size = nr_cpu_ids * sizeof(struct objpool_slot); 145 + slot_size = nr_cpu_ids * sizeof(struct objpool_slot *); 146 146 pool->cpu_slots = kzalloc(slot_size, pool->gfp); 147 147 if (!pool->cpu_slots) 148 148 return -ENOMEM;
+1 -1
scripts/gdb/linux/constants.py.in
··· 150 150 if IS_BUILTIN(CONFIG_ARM64): 151 151 LX_VALUE(CONFIG_ARM64_PA_BITS) 152 152 LX_VALUE(CONFIG_ARM64_VA_BITS) 153 - LX_VALUE(CONFIG_PAGE_SHIFT) 154 153 LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER) 154 + LX_VALUE(CONFIG_PAGE_SHIFT) 155 155 LX_CONFIG(CONFIG_SPARSEMEM) 156 156 LX_CONFIG(CONFIG_SPARSEMEM_EXTREME) 157 157 LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
+172 -1
scripts/gdb/linux/mm.py
··· 26 26 raise gdb.GdbError('Only support CONFIG_SPARSEMEM_VMEMMAP now') 27 27 if constants.LX_CONFIG_ARM64 and utils.is_target_arch('aarch64'): 28 28 self.ops = aarch64_page_ops() 29 + elif utils.is_target_arch('x86_64') or utils.is_target_arch('x86-64'): 30 + self.ops = x86_page_ops() 29 31 else: 30 - raise gdb.GdbError('Only support aarch64 now') 32 + raise gdb.GdbError('Only support aarch64 and x86_64 now') 33 + 34 + class x86_page_ops(): 35 + def __init__(self): 36 + self.struct_page_size = utils.get_page_type().sizeof 37 + self.PAGE_SHIFT = constants.LX_CONFIG_PAGE_SHIFT 38 + self.PAGE_SIZE = 1 << self.PAGE_SHIFT 39 + self.PAGE_MASK = (~(self.PAGE_SIZE - 1)) & ((1 << 64) - 1) 40 + 41 + self.PAGE_OFFSET = int(gdb.parse_and_eval("page_offset_base")) 42 + self.VMEMMAP_START = int(gdb.parse_and_eval("vmemmap_base")) 43 + self.PHYS_BASE = int(gdb.parse_and_eval("phys_base")) 44 + self.START_KERNEL_map = 0xffffffff80000000 45 + 46 + self.KERNEL_START = gdb.parse_and_eval("_text") 47 + self.KERNEL_END = gdb.parse_and_eval("_end") 48 + 49 + self.VMALLOC_START = int(gdb.parse_and_eval("vmalloc_base")) 50 + if self.VMALLOC_START == 0xffffc90000000000: 51 + self.VMALLOC_END = self.VMALLOC_START + (32 * 1024 * 1024 * 1024 * 1024) - 1 52 + elif self.VMALLOC_START == 0xffa0000000000000: 53 + self.VMALLOC_END = self.VMALLOC_START + (12800 * 1024 * 1024 * 1024 * 1024) - 1 54 + else: 55 + self.VMALLOC_END = self.VMALLOC_START + (12800 * 1024 * 1024 * 1024 * 1024) - 1 56 + 57 + self.MAX_PHYSMEM_BITS = 46 58 + self.SECTION_SIZE_BITS = 27 59 + self.MAX_ORDER = 10 60 + 61 + self.SECTIONS_SHIFT = self.MAX_PHYSMEM_BITS - self.SECTION_SIZE_BITS 62 + self.NR_MEM_SECTIONS = 1 << self.SECTIONS_SHIFT 63 + self.PFN_SECTION_SHIFT = self.SECTION_SIZE_BITS - self.PAGE_SHIFT 64 + self.PAGES_PER_SECTION = 1 << self.PFN_SECTION_SHIFT 65 + self.PAGE_SECTION_MASK = (~(self.PAGES_PER_SECTION - 1)) & ((1 << 64) - 1) 66 + 67 + if constants.LX_CONFIG_SPARSEMEM_EXTREME: 68 + self.SECTIONS_PER_ROOT = self.PAGE_SIZE // gdb.lookup_type("struct mem_section").sizeof 69 + else: 70 + self.SECTIONS_PER_ROOT = 1 71 + 72 + self.NR_SECTION_ROOTS = DIV_ROUND_UP(self.NR_MEM_SECTIONS, self.SECTIONS_PER_ROOT) 73 + self.SECTION_ROOT_MASK = self.SECTIONS_PER_ROOT - 1 74 + 75 + try: 76 + self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT')) 77 + self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT')) 78 + except: 79 + self.SECTION_HAS_MEM_MAP = 1 << 0 80 + self.SECTION_IS_EARLY = 1 << 3 81 + 82 + self.SUBSECTION_SHIFT = 21 83 + self.PAGES_PER_SUBSECTION = 1 << (self.SUBSECTION_SHIFT - self.PAGE_SHIFT) 84 + 85 + if constants.LX_CONFIG_NUMA and constants.LX_CONFIG_NODES_SHIFT: 86 + self.NODE_SHIFT = constants.LX_CONFIG_NODES_SHIFT 87 + else: 88 + self.NODE_SHIFT = 0 89 + 90 + self.MAX_NUMNODES = 1 << self.NODE_SHIFT 91 + 92 + self.vmemmap = gdb.Value(self.VMEMMAP_START).cast(utils.get_page_type().pointer()) 93 + 94 + def kasan_reset_tag(self, addr): 95 + return addr 96 + 97 + def SECTION_NR_TO_ROOT(self, sec): 98 + return sec // self.SECTIONS_PER_ROOT 99 + 100 + def __nr_to_section(self, nr): 101 + root = self.SECTION_NR_TO_ROOT(nr) 102 + mem_section = gdb.parse_and_eval("mem_section") 103 + return mem_section[root][nr & self.SECTION_ROOT_MASK] 104 + 105 + def pfn_to_section_nr(self, pfn): 106 + return pfn >> self.PFN_SECTION_SHIFT 107 + 108 + def section_nr_to_pfn(self, sec): 109 + return sec << self.PFN_SECTION_SHIFT 110 + 111 + def __pfn_to_section(self, pfn): 112 + return self.__nr_to_section(self.pfn_to_section_nr(pfn)) 113 + 114 + def pfn_to_section(self, pfn): 115 + return self.__pfn_to_section(pfn) 116 + 117 + def subsection_map_index(self, pfn): 118 + return (pfn & ~(self.PAGE_SECTION_MASK)) // self.PAGES_PER_SUBSECTION 119 + 120 + def pfn_section_valid(self, ms, pfn): 121 + if constants.LX_CONFIG_SPARSEMEM_VMEMMAP: 122 + idx = self.subsection_map_index(pfn) 123 + return test_bit(idx, ms['usage']['subsection_map']) 124 + else: 125 + return True 126 + 127 + def valid_section(self, mem_section): 128 + if mem_section != None and (mem_section['section_mem_map'] & self.SECTION_HAS_MEM_MAP): 129 + return True 130 + return False 131 + 132 + def early_section(self, mem_section): 133 + if mem_section != None and (mem_section['section_mem_map'] & self.SECTION_IS_EARLY): 134 + return True 135 + return False 136 + 137 + def pfn_valid(self, pfn): 138 + ms = None 139 + if self.PHYS_PFN(self.PFN_PHYS(pfn)) != pfn: 140 + return False 141 + if self.pfn_to_section_nr(pfn) >= self.NR_MEM_SECTIONS: 142 + return False 143 + ms = self.__pfn_to_section(pfn) 144 + 145 + if not self.valid_section(ms): 146 + return False 147 + return self.early_section(ms) or self.pfn_section_valid(ms, pfn) 148 + 149 + def PFN_PHYS(self, pfn): 150 + return pfn << self.PAGE_SHIFT 151 + 152 + def PHYS_PFN(self, phys): 153 + return phys >> self.PAGE_SHIFT 154 + 155 + def __phys_to_virt(self, pa): 156 + return pa + self.PAGE_OFFSET 157 + 158 + def __virt_to_phys(self, va): 159 + if va >= self.START_KERNEL_map: 160 + return va - self.START_KERNEL_map + self.PHYS_BASE 161 + else: 162 + return va - self.PAGE_OFFSET 163 + 164 + def virt_to_phys(self, va): 165 + return self.__virt_to_phys(va) 166 + 167 + def virt_to_page(self, va): 168 + return self.pfn_to_page(self.virt_to_pfn(va)) 169 + 170 + def __pa(self, va): 171 + return self.__virt_to_phys(va) 172 + 173 + def __va(self, pa): 174 + return self.__phys_to_virt(pa) 175 + 176 + def pfn_to_kaddr(self, pfn): 177 + return self.__va(pfn << self.PAGE_SHIFT) 178 + 179 + def virt_to_pfn(self, va): 180 + return self.PHYS_PFN(self.__virt_to_phys(va)) 181 + 182 + def sym_to_pfn(self, x): 183 + return self.PHYS_PFN(self.__virt_to_phys(x)) 184 + 185 + def page_to_pfn(self, page): 186 + return int(page.cast(utils.get_page_type().pointer()) - self.vmemmap) 187 + 188 + def pfn_to_page(self, pfn): 189 + return self.vmemmap + pfn 190 + 191 + def page_to_phys(self, page): 192 + return self.PFN_PHYS(self.page_to_pfn(page)) 193 + 194 + def page_to_virt(self, page): 195 + return self.__va(self.page_to_phys(page)) 196 + 197 + def page_address(self, page): 198 + return self.page_to_virt(page) 199 + 200 + def folio_address(self, folio): 201 + return self.page_address(folio['page'].address) 31 202 32 203 class aarch64_page_ops(): 33 204 def __init__(self):
+6 -6
tools/accounting/getdelays.c
··· 196 196 #define delay_ms(t) (t / 1000000ULL) 197 197 198 198 /* 199 - * Format timespec64 to human readable string (YYYY-MM-DD HH:MM:SS) 199 + * Format __kernel_timespec to human readable string (YYYY-MM-DD HH:MM:SS) 200 200 * Returns formatted string or "N/A" if timestamp is zero 201 201 */ 202 - static const char *format_timespec64(struct timespec64 *ts) 202 + static const char *format_timespec(struct __kernel_timespec *ts) 203 203 { 204 204 static char buffer[32]; 205 205 struct tm tm_info; 206 - time_t time_sec; 206 + __kernel_time_t time_sec; 207 207 208 208 /* Check if timestamp is zero (not set) */ 209 209 if (ts->tv_sec == 0 && ts->tv_nsec == 0) 210 210 return "N/A"; 211 211 212 - time_sec = (time_t)ts->tv_sec; 212 + time_sec = ts->tv_sec; 213 213 214 214 /* Use thread-safe localtime_r */ 215 215 if (localtime_r(&time_sec, &tm_info) == NULL) ··· 257 257 average_ms((double)(t)->cpu_delay_total, (t)->cpu_count), \ 258 258 delay_ms((double)(t)->cpu_delay_max), \ 259 259 delay_ms((double)(t)->cpu_delay_min), \ 260 - format_timespec64(&(t)->cpu_delay_max_ts)); \ 260 + format_timespec(&(t)->cpu_delay_max_ts)); \ 261 261 } else if (version >= 16) { \ 262 262 printf("%-10s%15s%15s%15s%15s%15s%15s%15s\n", \ 263 263 "CPU", "count", "real total", "virtual total", \ ··· 316 316 average_ms((double)(t)->total, (t)->count), \ 317 317 delay_ms((double)(t)->max), \ 318 318 delay_ms((double)(t)->min), \ 319 - format_timespec64(&(t)->max_ts)); \ 319 + format_timespec(&(t)->max_ts)); \ 320 320 } else if (version >= 16) { \ 321 321 printf("%-10s%15s%15s%15s%15s%15s\n", \ 322 322 name, "count", "delay total", "delay average", \
+105 -8
tools/testing/selftests/memfd/memfd_test.c
··· 18 18 #include <sys/stat.h> 19 19 #include <sys/syscall.h> 20 20 #include <sys/wait.h> 21 + #include <sys/types.h> 22 + #include <sys/ipc.h> 23 + #include <sys/sem.h> 21 24 #include <unistd.h> 22 25 #include <ctype.h> 23 26 ··· 42 39 F_SEAL_EXEC) 43 40 44 41 #define MFD_NOEXEC_SEAL 0x0008U 42 + union semun { 43 + int val; 44 + struct semid_ds *buf; 45 + unsigned short int *array; 46 + struct seminfo *__buf; 47 + }; 48 + 49 + /* 50 + * we use semaphores on nested wait tasks due the use of CLONE_NEWPID: the 51 + * child will be PID 1 and can't send SIGSTOP to themselves due special 52 + * treatment of the init task, so the SIGSTOP/SIGCONT synchronization 53 + * approach can't be used here. 54 + */ 55 + #define SEM_KEY 0xdeadbeef 45 56 46 57 /* 47 58 * Default is not to test hugetlbfs ··· 1350 1333 1351 1334 static int sysctl_nested_wait(void *arg) 1352 1335 { 1353 - /* Wait for a SIGCONT. */ 1354 - kill(getpid(), SIGSTOP); 1336 + int sem = semget(SEM_KEY, 1, 0600); 1337 + struct sembuf sembuf; 1338 + 1339 + if (sem < 0) { 1340 + perror("semget:"); 1341 + abort(); 1342 + } 1343 + sembuf.sem_num = 0; 1344 + sembuf.sem_flg = 0; 1345 + sembuf.sem_op = 0; 1346 + 1347 + if (semop(sem, &sembuf, 1) < 0) { 1348 + perror("semop:"); 1349 + abort(); 1350 + } 1351 + 1355 1352 return sysctl_nested(arg); 1356 1353 } 1357 1354 ··· 1386 1355 1387 1356 static int sysctl_nested_child(void *arg) 1388 1357 { 1389 - int pid; 1358 + int pid, sem; 1359 + union semun semun; 1360 + struct sembuf sembuf; 1390 1361 1391 1362 printf("%s nested sysctl 0\n", memfd_str); 1392 1363 sysctl_assert_write("0"); ··· 1422 1389 test_sysctl_sysctl2_failset); 1423 1390 join_thread(pid); 1424 1391 1392 + sem = semget(SEM_KEY, 1, IPC_CREAT | 0600); 1393 + if (sem < 0) { 1394 + perror("semget:"); 1395 + return 1; 1396 + } 1397 + semun.val = 1; 1398 + sembuf.sem_op = -1; 1399 + sembuf.sem_flg = 0; 1400 + sembuf.sem_num = 0; 1401 + 1425 1402 /* Verify that the rules are actually inherited after fork. */ 1426 1403 printf("%s nested sysctl 0 -> 1 after fork\n", memfd_str); 1427 1404 sysctl_assert_write("0"); 1428 1405 1406 + if (semctl(sem, 0, SETVAL, semun) < 0) { 1407 + perror("semctl:"); 1408 + return 1; 1409 + } 1410 + 1429 1411 pid = spawn_thread(CLONE_NEWPID, sysctl_nested_wait, 1430 1412 test_sysctl_sysctl1_failset); 1431 1413 sysctl_assert_write("1"); 1432 - kill(pid, SIGCONT); 1414 + 1415 + /* Allow child to continue */ 1416 + if (semop(sem, &sembuf, 1) < 0) { 1417 + perror("semop:"); 1418 + return 1; 1419 + } 1433 1420 join_thread(pid); 1434 1421 1435 1422 printf("%s nested sysctl 0 -> 2 after fork\n", memfd_str); 1436 1423 sysctl_assert_write("0"); 1437 1424 1425 + if (semctl(sem, 0, SETVAL, semun) < 0) { 1426 + perror("semctl:"); 1427 + return 1; 1428 + } 1429 + 1438 1430 pid = spawn_thread(CLONE_NEWPID, sysctl_nested_wait, 1439 1431 test_sysctl_sysctl2_failset); 1440 1432 sysctl_assert_write("2"); 1441 - kill(pid, SIGCONT); 1433 + 1434 + /* Allow child to continue */ 1435 + if (semop(sem, &sembuf, 1) < 0) { 1436 + perror("semop:"); 1437 + return 1; 1438 + } 1442 1439 join_thread(pid); 1443 1440 1444 1441 /* ··· 1478 1415 */ 1479 1416 printf("%s nested sysctl 2 -> 1 after fork\n", memfd_str); 1480 1417 sysctl_assert_write("2"); 1418 + 1419 + if (semctl(sem, 0, SETVAL, semun) < 0) { 1420 + perror("semctl:"); 1421 + return 1; 1422 + } 1423 + 1481 1424 pid = spawn_thread(CLONE_NEWPID, sysctl_nested_wait, 1482 1425 test_sysctl_sysctl2); 1483 1426 sysctl_assert_write("1"); 1484 - kill(pid, SIGCONT); 1427 + 1428 + /* Allow child to continue */ 1429 + if (semop(sem, &sembuf, 1) < 0) { 1430 + perror("semop:"); 1431 + return 1; 1432 + } 1485 1433 join_thread(pid); 1486 1434 1487 1435 printf("%s nested sysctl 2 -> 0 after fork\n", memfd_str); 1488 1436 sysctl_assert_write("2"); 1437 + 1438 + if (semctl(sem, 0, SETVAL, semun) < 0) { 1439 + perror("semctl:"); 1440 + return 1; 1441 + } 1442 + 1489 1443 pid = spawn_thread(CLONE_NEWPID, sysctl_nested_wait, 1490 1444 test_sysctl_sysctl2); 1491 1445 sysctl_assert_write("0"); 1492 - kill(pid, SIGCONT); 1446 + 1447 + /* Allow child to continue */ 1448 + if (semop(sem, &sembuf, 1) < 0) { 1449 + perror("semop:"); 1450 + return 1; 1451 + } 1493 1452 join_thread(pid); 1494 1453 1495 1454 printf("%s nested sysctl 1 -> 0 after fork\n", memfd_str); 1496 1455 sysctl_assert_write("1"); 1456 + 1457 + if (semctl(sem, 0, SETVAL, semun) < 0) { 1458 + perror("semctl:"); 1459 + return 1; 1460 + } 1461 + 1497 1462 pid = spawn_thread(CLONE_NEWPID, sysctl_nested_wait, 1498 1463 test_sysctl_sysctl1); 1499 1464 sysctl_assert_write("0"); 1500 - kill(pid, SIGCONT); 1465 + /* Allow child to continue */ 1466 + if (semop(sem, &sembuf, 1) < 0) { 1467 + perror("semop:"); 1468 + return 1; 1469 + } 1501 1470 join_thread(pid); 1471 + 1472 + semctl(sem, 0, IPC_RMID); 1502 1473 1503 1474 return 0; 1504 1475 }