Issue #3488 has been reported by tuxillo. ---------------------------------------- Bug #3488: pmap: kernel invalidations over 128 pages leave stale global TLB entries http://bugs.dragonflybsd.org/issues/3488
* Author: tuxillo * Status: New * Priority: Normal * Target version: 6.6 * Start date: 2026-11-29 ---------------------------------------- As of master 98c93bc104, an invalidation of more than 128 pages of kernel_pmap, or of all of it, leaves global TLB entries in place on cpu 0. The direct map and the kernel image are mapped with @PG_G@, so cpu 0 can keep using an old translation there until the entry is evicted. pmap_page_set_memattr() on a normal page is one case: pmap_change_attr() rewrites the page's 2 MB direct map entry (#3487) and invalidates 512 pages, so cpu 0 may not see the new memory type. pmap_inval_smp() and pmap_inval_intr() in sys/platform/pc64/x86_64/pmap_inval.c turn invalidations of more than @MAX_INVAL_PAGES@ pages into cpu_invltlb(), a %cr3 reload, which doesn't remove global entries. Only the BSP sets CR4.PGE. mpboot.S says it turns PGE on but only sets PAE and PSE, so the APs ignore @PG_G@ and don't show the problem. The attached patch records the pmap in the invalidation request and, for kernel_pmap, turns CR4.PGE off and on again, which flushes global entries too, as FreeBSD does for its kernel pmap. User pmaps and cpus without PGE keep the %cr3 reload. The attached tlbglob.c module points a 2 MB direct map entry of its own at another 2 MB chunk while the old translation is in the TLB, invalidates, and checks which chunk a read returns. In an 8-vCPU NVMM guest and on a 12-thread Intel desktop, master kept the old translation on cpu 0 in 100 of 100 trials after 129 and 512 page invalidations, a full invalidation and pmap_change_attr(), also when cpu 1 issued them. Up to 128 pages it never did. With the patch none did, in three runs on the desktop. A 512 page invalidation issued from cpu 0 went from about 2.8 to 3.1 us. I didn't measure the extra TLB misses on cpu 0 after a flush. With @machdep.optimized_invltlb=1@ (off by default), idle cpus run a deferred cpu_invltlb() instead. The patch doesn't change that path. ---Files-------------------------------- tlbglob.c (9.53 KB) Makefile (54 Bytes) 0001-pmap-flush-global-TLB-entries-in-full-kernel_pmap-in.patch (4.84 KB) -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
