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

Merge tag 'x86-urgent-2022-04-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Thomas Gleixner:
"A set of x86 fixes and updates:

- Make the prctl() for enabling dynamic XSTATE components correct so
it adds the newly requested feature to the permission bitmap
instead of overwriting it. Add a selftest which validates that.

- Unroll string MMIO for encrypted SEV guests as the hypervisor
cannot emulate it.

- Handle supervisor states correctly in the FPU/XSTATE code so it
takes the feature set of the fpstate buffer into account. The
feature sets can differ between host and guest buffers. Guest
buffers do not contain supervisor states. So far this was not an
issue, but with enabling PASID it needs to be handled in the buffer
offset calculation and in the permission bitmaps.

- Avoid a gazillion of repeated CPUID invocations in by caching the
values early in the FPU/XSTATE code.

- Enable CONFIG_WERROR in x86 defconfig.

- Make the X86 defconfigs more useful by adapting them to Y2022
reality"

* tag 'x86-urgent-2022-04-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86/fpu/xstate: Consolidate size calculations
x86/fpu/xstate: Handle supervisor states in XSTATE permissions
x86/fpu/xsave: Handle compacted offsets correctly with supervisor states
x86/fpu: Cache xfeature flags from CPUID
x86/fpu/xsave: Initialize offset/size cache early
x86/fpu: Remove unused supervisor only offsets
x86/fpu: Remove redundant XCOMP_BV initialization
x86/sev: Unroll string mmio with CC_ATTR_GUEST_UNROLL_STRING_IO
x86/config: Make the x86 defconfigs a bit more usable
x86/defconfig: Enable WERROR
selftests/x86/amx: Update the ARCH_REQ_XCOMP_PERM test
x86/fpu/xstate: Fix the ARCH_REQ_XCOMP_PERM implementation

+202 -189
+35 -15
arch/x86/configs/i386_defconfig
··· 1 + CONFIG_WERROR=y 1 2 CONFIG_SYSVIPC=y 2 3 CONFIG_POSIX_MQUEUE=y 4 + CONFIG_USELIB=y 3 5 CONFIG_AUDIT=y 4 6 CONFIG_NO_HZ=y 5 7 CONFIG_HIGH_RES_TIMERS=y ··· 13 11 CONFIG_TASK_IO_ACCOUNTING=y 14 12 CONFIG_LOG_BUF_SHIFT=18 15 13 CONFIG_CGROUPS=y 14 + CONFIG_BLK_CGROUP=y 16 15 CONFIG_CGROUP_SCHED=y 16 + CONFIG_CGROUP_PIDS=y 17 + CONFIG_CGROUP_RDMA=y 17 18 CONFIG_CGROUP_FREEZER=y 19 + CONFIG_CGROUP_HUGETLB=y 18 20 CONFIG_CPUSETS=y 21 + CONFIG_CGROUP_DEVICE=y 19 22 CONFIG_CGROUP_CPUACCT=y 23 + CONFIG_CGROUP_PERF=y 24 + CONFIG_CGROUP_MISC=y 25 + CONFIG_CGROUP_DEBUG=y 20 26 CONFIG_BLK_DEV_INITRD=y 27 + CONFIG_KALLSYMS_ALL=y 21 28 # CONFIG_COMPAT_BRK is not set 22 29 CONFIG_PROFILING=y 23 - # CONFIG_64BIT is not set 24 30 CONFIG_SMP=y 25 - CONFIG_X86_GENERIC=y 26 - CONFIG_HPET_TIMER=y 31 + CONFIG_HYPERVISOR_GUEST=y 32 + CONFIG_PARAVIRT=y 33 + CONFIG_NR_CPUS=8 27 34 CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y 28 - CONFIG_X86_REBOOTFIXUPS=y 29 35 CONFIG_MICROCODE_AMD=y 30 36 CONFIG_X86_MSR=y 31 37 CONFIG_X86_CPUID=y 32 - CONFIG_HIGHPTE=y 33 38 CONFIG_X86_CHECK_BIOS_CORRUPTION=y 34 39 # CONFIG_MTRR_SANITIZER is not set 35 40 CONFIG_EFI=y ··· 52 43 CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y 53 44 CONFIG_CPU_FREQ_GOV_ONDEMAND=y 54 45 CONFIG_X86_ACPI_CPUFREQ=y 55 - CONFIG_EFI_VARS=y 56 46 CONFIG_KPROBES=y 57 47 CONFIG_JUMP_LABEL=y 48 + CONFIG_COMPAT_32BIT_TIME=y 58 49 CONFIG_MODULES=y 59 50 CONFIG_MODULE_UNLOAD=y 60 51 CONFIG_MODULE_FORCE_UNLOAD=y 52 + CONFIG_BLK_CGROUP_IOLATENCY=y 53 + CONFIG_BLK_CGROUP_IOCOST=y 54 + CONFIG_BLK_CGROUP_IOPRIO=y 61 55 CONFIG_BINFMT_MISC=y 62 56 CONFIG_NET=y 63 57 CONFIG_PACKET=y ··· 115 103 CONFIG_IP6_NF_TARGET_REJECT=y 116 104 CONFIG_IP6_NF_MANGLE=y 117 105 CONFIG_NET_SCHED=y 106 + CONFIG_NET_CLS_CGROUP=y 118 107 CONFIG_NET_EMATCH=y 119 108 CONFIG_NET_CLS_ACT=y 109 + CONFIG_CGROUP_NET_PRIO=y 120 110 CONFIG_CFG80211=y 121 111 CONFIG_MAC80211=y 122 112 CONFIG_MAC80211_LEDS=y 123 113 CONFIG_RFKILL=y 114 + CONFIG_NET_9P=y 115 + CONFIG_NET_9P_VIRTIO=y 124 116 CONFIG_PCI=y 125 117 CONFIG_PCIEPORTBUS=y 126 118 CONFIG_PCI_MSI=y ··· 135 119 CONFIG_DEVTMPFS_MOUNT=y 136 120 CONFIG_DEBUG_DEVRES=y 137 121 CONFIG_CONNECTOR=y 122 + CONFIG_EFI_VARS=y 123 + CONFIG_EFI_CAPSULE_LOADER=y 138 124 CONFIG_BLK_DEV_LOOP=y 125 + CONFIG_VIRTIO_BLK=y 139 126 CONFIG_BLK_DEV_SD=y 140 127 CONFIG_BLK_DEV_SR=y 141 128 CONFIG_CHR_DEV_SG=y 142 129 CONFIG_SCSI_CONSTANTS=y 143 130 CONFIG_SCSI_SPI_ATTRS=y 144 - # CONFIG_SCSI_LOWLEVEL is not set 131 + CONFIG_SCSI_VIRTIO=y 145 132 CONFIG_ATA=y 146 133 CONFIG_SATA_AHCI=y 147 134 CONFIG_ATA_PIIX=y ··· 162 143 CONFIG_MAC_EMUMOUSEBTN=y 163 144 CONFIG_NETDEVICES=y 164 145 CONFIG_NETCONSOLE=y 146 + CONFIG_VIRTIO_NET=y 165 147 CONFIG_BNX2=y 166 148 CONFIG_TIGON3=y 167 149 CONFIG_NET_TULIP=y ··· 190 170 CONFIG_SERIAL_8250_DETECT_IRQ=y 191 171 CONFIG_SERIAL_8250_RSA=y 192 172 CONFIG_SERIAL_NONSTANDARD=y 173 + CONFIG_VIRTIO_CONSOLE=y 193 174 CONFIG_HW_RANDOM=y 194 175 CONFIG_NVRAM=y 195 176 CONFIG_HPET=y ··· 202 181 CONFIG_AGP_INTEL=y 203 182 CONFIG_DRM=y 204 183 CONFIG_DRM_I915=y 205 - CONFIG_FB_MODE_HELPERS=y 206 - CONFIG_FB_TILEBLITTING=y 207 - CONFIG_FB_EFI=y 208 - CONFIG_LOGO=y 209 - # CONFIG_LOGO_LINUX_MONO is not set 210 - # CONFIG_LOGO_LINUX_VGA16 is not set 184 + CONFIG_DRM_VIRTIO_GPU=y 211 185 CONFIG_SOUND=y 212 186 CONFIG_SND=y 213 187 CONFIG_SND_HRTIMER=y ··· 235 219 CONFIG_RTC_CLASS=y 236 220 # CONFIG_RTC_HCTOSYS is not set 237 221 CONFIG_DMADEVICES=y 222 + CONFIG_VIRTIO_PCI=y 223 + CONFIG_VIRTIO_INPUT=y 238 224 CONFIG_EEEPC_LAPTOP=y 239 225 CONFIG_EXT4_FS=y 240 226 CONFIG_EXT4_FS_POSIX_ACL=y ··· 258 240 CONFIG_NFS_V3_ACL=y 259 241 CONFIG_NFS_V4=y 260 242 CONFIG_ROOT_NFS=y 243 + CONFIG_9P_FS=y 261 244 CONFIG_NLS_DEFAULT="utf8" 262 245 CONFIG_NLS_CODEPAGE_437=y 263 246 CONFIG_NLS_ASCII=y ··· 270 251 CONFIG_SECURITY_SELINUX_BOOTPARAM=y 271 252 CONFIG_SECURITY_SELINUX_DISABLE=y 272 253 CONFIG_PRINTK_TIME=y 254 + CONFIG_FRAME_WARN=1024 273 255 CONFIG_MAGIC_SYSRQ=y 274 256 CONFIG_DEBUG_KERNEL=y 275 257 CONFIG_DEBUG_STACK_USAGE=y 276 - CONFIG_DEBUG_STACKOVERFLOW=y 277 258 # CONFIG_SCHED_DEBUG is not set 278 259 CONFIG_SCHEDSTATS=y 279 260 CONFIG_BLK_DEV_IO_TRACE=y 280 261 CONFIG_PROVIDE_OHCI1394_DMA_INIT=y 281 262 CONFIG_EARLY_PRINTK_DBGP=y 282 263 CONFIG_DEBUG_BOOT_PARAMS=y 283 - CONFIG_KALLSYMS_ALL=y 264 + CONFIG_UNWINDER_FRAME_POINTER=y 265 + # CONFIG_64BIT is not set
+28 -9
arch/x86/configs/x86_64_defconfig
··· 1 + CONFIG_WERROR=y 1 2 CONFIG_SYSVIPC=y 2 3 CONFIG_POSIX_MQUEUE=y 3 4 CONFIG_AUDIT=y ··· 12 11 CONFIG_TASK_IO_ACCOUNTING=y 13 12 CONFIG_LOG_BUF_SHIFT=18 14 13 CONFIG_CGROUPS=y 14 + CONFIG_BLK_CGROUP=y 15 15 CONFIG_CGROUP_SCHED=y 16 + CONFIG_CGROUP_PIDS=y 17 + CONFIG_CGROUP_RDMA=y 16 18 CONFIG_CGROUP_FREEZER=y 19 + CONFIG_CGROUP_HUGETLB=y 17 20 CONFIG_CPUSETS=y 21 + CONFIG_CGROUP_DEVICE=y 18 22 CONFIG_CGROUP_CPUACCT=y 23 + CONFIG_CGROUP_PERF=y 24 + CONFIG_CGROUP_MISC=y 25 + CONFIG_CGROUP_DEBUG=y 19 26 CONFIG_BLK_DEV_INITRD=y 27 + CONFIG_KALLSYMS_ALL=y 20 28 # CONFIG_COMPAT_BRK is not set 21 29 CONFIG_PROFILING=y 22 30 CONFIG_SMP=y 31 + CONFIG_HYPERVISOR_GUEST=y 32 + CONFIG_PARAVIRT=y 23 33 CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y 24 34 CONFIG_MICROCODE_AMD=y 25 35 CONFIG_X86_MSR=y ··· 53 41 CONFIG_CPU_FREQ_GOV_ONDEMAND=y 54 42 CONFIG_X86_ACPI_CPUFREQ=y 55 43 CONFIG_IA32_EMULATION=y 56 - CONFIG_EFI_VARS=y 57 44 CONFIG_KPROBES=y 58 45 CONFIG_JUMP_LABEL=y 59 46 CONFIG_MODULES=y 60 47 CONFIG_MODULE_UNLOAD=y 61 48 CONFIG_MODULE_FORCE_UNLOAD=y 49 + CONFIG_BLK_CGROUP_IOLATENCY=y 50 + CONFIG_BLK_CGROUP_IOCOST=y 51 + CONFIG_BLK_CGROUP_IOPRIO=y 62 52 CONFIG_BINFMT_MISC=y 63 53 CONFIG_NET=y 64 54 CONFIG_PACKET=y ··· 115 101 CONFIG_IP6_NF_TARGET_REJECT=y 116 102 CONFIG_IP6_NF_MANGLE=y 117 103 CONFIG_NET_SCHED=y 104 + CONFIG_NET_CLS_CGROUP=y 118 105 CONFIG_NET_EMATCH=y 119 106 CONFIG_NET_CLS_ACT=y 107 + CONFIG_CGROUP_NET_PRIO=y 120 108 CONFIG_CFG80211=y 121 109 CONFIG_MAC80211=y 122 110 CONFIG_MAC80211_LEDS=y 123 111 CONFIG_RFKILL=y 112 + CONFIG_NET_9P=y 113 + CONFIG_NET_9P_VIRTIO=y 124 114 CONFIG_PCI=y 125 115 CONFIG_PCIEPORTBUS=y 126 116 CONFIG_HOTPLUG_PCI=y ··· 134 116 CONFIG_DEVTMPFS_MOUNT=y 135 117 CONFIG_DEBUG_DEVRES=y 136 118 CONFIG_CONNECTOR=y 119 + CONFIG_EFI_VARS=y 137 120 CONFIG_BLK_DEV_LOOP=y 121 + CONFIG_VIRTIO_BLK=y 138 122 CONFIG_BLK_DEV_SD=y 139 123 CONFIG_BLK_DEV_SR=y 140 124 CONFIG_CHR_DEV_SG=y 141 125 CONFIG_SCSI_CONSTANTS=y 142 126 CONFIG_SCSI_SPI_ATTRS=y 143 - # CONFIG_SCSI_LOWLEVEL is not set 127 + CONFIG_SCSI_VIRTIO=y 144 128 CONFIG_ATA=y 145 129 CONFIG_SATA_AHCI=y 146 130 CONFIG_ATA_PIIX=y ··· 158 138 CONFIG_MAC_EMUMOUSEBTN=y 159 139 CONFIG_NETDEVICES=y 160 140 CONFIG_NETCONSOLE=y 141 + CONFIG_VIRTIO_NET=y 161 142 CONFIG_TIGON3=y 162 143 CONFIG_NET_TULIP=y 163 144 CONFIG_E100=y ··· 183 162 CONFIG_SERIAL_8250_DETECT_IRQ=y 184 163 CONFIG_SERIAL_8250_RSA=y 185 164 CONFIG_SERIAL_NONSTANDARD=y 165 + CONFIG_VIRTIO_CONSOLE=y 186 166 CONFIG_HW_RANDOM=y 187 167 # CONFIG_HW_RANDOM_INTEL is not set 188 168 # CONFIG_HW_RANDOM_AMD is not set ··· 197 175 CONFIG_AGP_INTEL=y 198 176 CONFIG_DRM=y 199 177 CONFIG_DRM_I915=y 200 - CONFIG_FB_MODE_HELPERS=y 201 - CONFIG_FB_TILEBLITTING=y 202 - CONFIG_FB_EFI=y 203 - CONFIG_LOGO=y 204 - # CONFIG_LOGO_LINUX_MONO is not set 205 - # CONFIG_LOGO_LINUX_VGA16 is not set 178 + CONFIG_DRM_VIRTIO_GPU=y 206 179 CONFIG_SOUND=y 207 180 CONFIG_SND=y 208 181 CONFIG_SND_HRTIMER=y ··· 230 213 CONFIG_RTC_CLASS=y 231 214 # CONFIG_RTC_HCTOSYS is not set 232 215 CONFIG_DMADEVICES=y 216 + CONFIG_VIRTIO_PCI=y 217 + CONFIG_VIRTIO_INPUT=y 233 218 CONFIG_EEEPC_LAPTOP=y 234 219 CONFIG_AMD_IOMMU=y 235 220 CONFIG_INTEL_IOMMU=y ··· 256 237 CONFIG_NFS_V3_ACL=y 257 238 CONFIG_NFS_V4=y 258 239 CONFIG_ROOT_NFS=y 240 + CONFIG_9P_FS=y 259 241 CONFIG_NLS_DEFAULT="utf8" 260 242 CONFIG_NLS_CODEPAGE_437=y 261 243 CONFIG_NLS_ASCII=y ··· 277 257 CONFIG_PROVIDE_OHCI1394_DMA_INIT=y 278 258 CONFIG_EARLY_PRINTK_DBGP=y 279 259 CONFIG_DEBUG_BOOT_PARAMS=y 280 - CONFIG_KALLSYMS_ALL=y
-3
arch/x86/kernel/fpu/core.c
··· 415 415 xpkru = get_xsave_addr(&kstate->regs.xsave, XFEATURE_PKRU); 416 416 *vpkru = xpkru->pkru; 417 417 } 418 - 419 - /* Ensure that XCOMP_BV is set up for XSAVES */ 420 - xstate_init_xcomp_bv(&kstate->regs.xsave, kstate->xfeatures); 421 418 return 0; 422 419 } 423 420 EXPORT_SYMBOL_GPL(fpu_copy_uabi_to_guest_fpstate);
+68 -152
arch/x86/kernel/fpu/xstate.c
··· 81 81 { [ 0 ... XFEATURE_MAX - 1] = -1}; 82 82 static unsigned int xstate_sizes[XFEATURE_MAX] __ro_after_init = 83 83 { [ 0 ... XFEATURE_MAX - 1] = -1}; 84 - static unsigned int xstate_comp_offsets[XFEATURE_MAX] __ro_after_init = 85 - { [ 0 ... XFEATURE_MAX - 1] = -1}; 86 - static unsigned int xstate_supervisor_only_offsets[XFEATURE_MAX] __ro_after_init = 87 - { [ 0 ... XFEATURE_MAX - 1] = -1}; 84 + static unsigned int xstate_flags[XFEATURE_MAX] __ro_after_init; 85 + 86 + #define XSTATE_FLAG_SUPERVISOR BIT(0) 87 + #define XSTATE_FLAG_ALIGNED64 BIT(1) 88 88 89 89 /* 90 90 * Return whether the system supports a given xfeature. ··· 124 124 } 125 125 EXPORT_SYMBOL_GPL(cpu_has_xfeatures); 126 126 127 + static bool xfeature_is_aligned64(int xfeature_nr) 128 + { 129 + return xstate_flags[xfeature_nr] & XSTATE_FLAG_ALIGNED64; 130 + } 131 + 127 132 static bool xfeature_is_supervisor(int xfeature_nr) 128 133 { 129 - /* 130 - * Extended State Enumeration Sub-leaves (EAX = 0DH, ECX = n, n > 1) 131 - * returns ECX[0] set to (1) for a supervisor state, and cleared (0) 132 - * for a user state. 133 - */ 134 - u32 eax, ebx, ecx, edx; 134 + return xstate_flags[xfeature_nr] & XSTATE_FLAG_SUPERVISOR; 135 + } 135 136 136 - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); 137 - return ecx & 1; 137 + static unsigned int xfeature_get_offset(u64 xcomp_bv, int xfeature) 138 + { 139 + unsigned int offs, i; 140 + 141 + /* 142 + * Non-compacted format and legacy features use the cached fixed 143 + * offsets. 144 + */ 145 + if (!cpu_feature_enabled(X86_FEATURE_XSAVES) || xfeature <= XFEATURE_SSE) 146 + return xstate_offsets[xfeature]; 147 + 148 + /* 149 + * Compacted format offsets depend on the actual content of the 150 + * compacted xsave area which is determined by the xcomp_bv header 151 + * field. 152 + */ 153 + offs = FXSAVE_SIZE + XSAVE_HDR_SIZE; 154 + for_each_extended_xfeature(i, xcomp_bv) { 155 + if (xfeature_is_aligned64(i)) 156 + offs = ALIGN(offs, 64); 157 + if (i == xfeature) 158 + break; 159 + offs += xstate_sizes[i]; 160 + } 161 + return offs; 138 162 } 139 163 140 164 /* ··· 206 182 * Record the offsets and sizes of various xstates contained 207 183 * in the XSAVE state memory layout. 208 184 */ 209 - static void __init setup_xstate_features(void) 185 + static void __init setup_xstate_cache(void) 210 186 { 211 187 u32 eax, ebx, ecx, edx, i; 212 188 /* start at the beginning of the "extended state" */ ··· 229 205 cpuid_count(XSTATE_CPUID, i, &eax, &ebx, &ecx, &edx); 230 206 231 207 xstate_sizes[i] = eax; 208 + xstate_flags[i] = ecx; 232 209 233 210 /* 234 211 * If an xfeature is supervisor state, the offset in EBX is ··· 289 264 } while (0) 290 265 291 266 /* 292 - * We could cache this like xstate_size[], but we only use 293 - * it here, so it would be a waste of space. 294 - */ 295 - static int xfeature_is_aligned(int xfeature_nr) 296 - { 297 - u32 eax, ebx, ecx, edx; 298 - 299 - CHECK_XFEATURE(xfeature_nr); 300 - 301 - if (!xfeature_enabled(xfeature_nr)) { 302 - WARN_ONCE(1, "Checking alignment of disabled xfeature %d\n", 303 - xfeature_nr); 304 - return 0; 305 - } 306 - 307 - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); 308 - /* 309 - * The value returned by ECX[1] indicates the alignment 310 - * of state component 'i' when the compacted format 311 - * of the extended region of an XSAVE area is used: 312 - */ 313 - return !!(ecx & 2); 314 - } 315 - 316 - /* 317 - * This function sets up offsets and sizes of all extended states in 318 - * xsave area. This supports both standard format and compacted format 319 - * of the xsave area. 320 - */ 321 - static void __init setup_xstate_comp_offsets(void) 322 - { 323 - unsigned int next_offset; 324 - int i; 325 - 326 - /* 327 - * The FP xstates and SSE xstates are legacy states. They are always 328 - * in the fixed offsets in the xsave area in either compacted form 329 - * or standard form. 330 - */ 331 - xstate_comp_offsets[XFEATURE_FP] = 0; 332 - xstate_comp_offsets[XFEATURE_SSE] = offsetof(struct fxregs_state, 333 - xmm_space); 334 - 335 - if (!cpu_feature_enabled(X86_FEATURE_XSAVES)) { 336 - for_each_extended_xfeature(i, fpu_kernel_cfg.max_features) 337 - xstate_comp_offsets[i] = xstate_offsets[i]; 338 - return; 339 - } 340 - 341 - next_offset = FXSAVE_SIZE + XSAVE_HDR_SIZE; 342 - 343 - for_each_extended_xfeature(i, fpu_kernel_cfg.max_features) { 344 - if (xfeature_is_aligned(i)) 345 - next_offset = ALIGN(next_offset, 64); 346 - 347 - xstate_comp_offsets[i] = next_offset; 348 - next_offset += xstate_sizes[i]; 349 - } 350 - } 351 - 352 - /* 353 - * Setup offsets of a supervisor-state-only XSAVES buffer: 354 - * 355 - * The offsets stored in xstate_comp_offsets[] only work for one specific 356 - * value of the Requested Feature BitMap (RFBM). In cases where a different 357 - * RFBM value is used, a different set of offsets is required. This set of 358 - * offsets is for when RFBM=xfeatures_mask_supervisor(). 359 - */ 360 - static void __init setup_supervisor_only_offsets(void) 361 - { 362 - unsigned int next_offset; 363 - int i; 364 - 365 - next_offset = FXSAVE_SIZE + XSAVE_HDR_SIZE; 366 - 367 - for_each_extended_xfeature(i, fpu_kernel_cfg.max_features) { 368 - if (!xfeature_is_supervisor(i)) 369 - continue; 370 - 371 - if (xfeature_is_aligned(i)) 372 - next_offset = ALIGN(next_offset, 64); 373 - 374 - xstate_supervisor_only_offsets[i] = next_offset; 375 - next_offset += xstate_sizes[i]; 376 - } 377 - } 378 - 379 - /* 380 267 * Print out xstate component offsets and sizes 381 268 */ 382 269 static void __init print_xstate_offset_size(void) ··· 297 360 298 361 for_each_extended_xfeature(i, fpu_kernel_cfg.max_features) { 299 362 pr_info("x86/fpu: xstate_offset[%d]: %4d, xstate_sizes[%d]: %4d\n", 300 - i, xstate_comp_offsets[i], i, xstate_sizes[i]); 363 + i, xfeature_get_offset(fpu_kernel_cfg.max_features, i), 364 + i, xstate_sizes[i]); 301 365 } 302 366 } 303 367 ··· 357 419 if (!boot_cpu_has(X86_FEATURE_XSAVE)) 358 420 return; 359 421 360 - setup_xstate_features(); 361 422 print_xstate_features(); 362 423 363 424 xstate_init_xcomp_bv(&init_fpstate.regs.xsave, fpu_kernel_cfg.max_features); ··· 383 446 * here. 384 447 */ 385 448 fxsave(&init_fpstate.regs.fxsave); 386 - } 387 - 388 - static int xfeature_uncompacted_offset(int xfeature_nr) 389 - { 390 - u32 eax, ebx, ecx, edx; 391 - 392 - /* 393 - * Only XSAVES supports supervisor states and it uses compacted 394 - * format. Checking a supervisor state's uncompacted offset is 395 - * an error. 396 - */ 397 - if (XFEATURE_MASK_SUPERVISOR_ALL & BIT_ULL(xfeature_nr)) { 398 - WARN_ONCE(1, "No fixed offset for xstate %d\n", xfeature_nr); 399 - return -1; 400 - } 401 - 402 - CHECK_XFEATURE(xfeature_nr); 403 - cpuid_count(XSTATE_CPUID, xfeature_nr, &eax, &ebx, &ecx, &edx); 404 - return ebx; 405 449 } 406 450 407 451 int xfeature_size(int xfeature_nr) ··· 562 644 563 645 static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted) 564 646 { 565 - unsigned int size = FXSAVE_SIZE + XSAVE_HDR_SIZE; 566 - int i; 647 + unsigned int topmost = fls64(xfeatures) - 1; 648 + unsigned int offset = xstate_offsets[topmost]; 567 649 568 - for_each_extended_xfeature(i, xfeatures) { 569 - /* Align from the end of the previous feature */ 570 - if (xfeature_is_aligned(i)) 571 - size = ALIGN(size, 64); 572 - /* 573 - * In compacted format the enabled features are packed, 574 - * i.e. disabled features do not occupy space. 575 - * 576 - * In non-compacted format the offsets are fixed and 577 - * disabled states still occupy space in the memory buffer. 578 - */ 579 - if (!compacted) 580 - size = xfeature_uncompacted_offset(i); 581 - /* 582 - * Add the feature size even for non-compacted format 583 - * to make the end result correct 584 - */ 585 - size += xfeature_size(i); 586 - } 587 - return size; 650 + if (topmost <= XFEATURE_SSE) 651 + return sizeof(struct xregs_state); 652 + 653 + if (compacted) 654 + offset = xfeature_get_offset(xfeatures, topmost); 655 + return offset + xstate_sizes[topmost]; 588 656 } 589 657 590 658 /* ··· 839 935 840 936 /* Enable xstate instructions to be able to continue with initialization: */ 841 937 fpu__init_cpu_xstate(); 938 + 939 + /* Cache size, offset and flags for initialization */ 940 + setup_xstate_cache(); 941 + 842 942 err = init_xstate_size(); 843 943 if (err) 844 944 goto out_disable; ··· 858 950 fpu_user_cfg.max_features); 859 951 860 952 setup_init_fpu_buf(); 861 - setup_xstate_comp_offsets(); 862 - setup_supervisor_only_offsets(); 863 953 864 954 /* 865 955 * Paranoia check whether something in the setup modified the ··· 912 1006 */ 913 1007 static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr) 914 1008 { 915 - if (!xfeature_enabled(xfeature_nr)) { 916 - WARN_ON_FPU(1); 1009 + u64 xcomp_bv = xsave->header.xcomp_bv; 1010 + 1011 + if (WARN_ON_ONCE(!xfeature_enabled(xfeature_nr))) 917 1012 return NULL; 1013 + 1014 + if (cpu_feature_enabled(X86_FEATURE_XSAVES)) { 1015 + if (WARN_ON_ONCE(!(xcomp_bv & BIT_ULL(xfeature_nr)))) 1016 + return NULL; 918 1017 } 919 1018 920 - return (void *)xsave + xstate_comp_offsets[xfeature_nr]; 1019 + return (void *)xsave + xfeature_get_offset(xcomp_bv, xfeature_nr); 921 1020 } 1021 + 922 1022 /* 923 1023 * Given the xsave area and a state inside, this function returns the 924 1024 * address of the state. ··· 955 1043 * We should not ever be requesting features that we 956 1044 * have not enabled. 957 1045 */ 958 - WARN_ONCE(!(fpu_kernel_cfg.max_features & BIT_ULL(xfeature_nr)), 959 - "get of unsupported state"); 1046 + if (WARN_ON_ONCE(!xfeature_enabled(xfeature_nr))) 1047 + return NULL; 1048 + 960 1049 /* 961 1050 * This assumes the last 'xsave*' instruction to 962 1051 * have requested that 'xfeature_nr' be saved. ··· 1538 1625 1539 1626 /* Calculate the resulting kernel state size */ 1540 1627 mask = permitted | requested; 1628 + /* Take supervisor states into account on the host */ 1629 + if (!guest) 1630 + mask |= xfeatures_mask_supervisor(); 1541 1631 ksize = xstate_calculate_size(mask, compacted); 1542 1632 1543 1633 /* Calculate the resulting user state size */ ··· 1555 1639 1556 1640 perm = guest ? &fpu->guest_perm : &fpu->perm; 1557 1641 /* Pairs with the READ_ONCE() in xstate_get_group_perm() */ 1558 - WRITE_ONCE(perm->__state_perm, requested); 1642 + WRITE_ONCE(perm->__state_perm, mask); 1559 1643 /* Protected by sighand lock */ 1560 1644 perm->__state_size = ksize; 1561 1645 perm->__user_state_size = usize;
+57 -8
arch/x86/lib/iomem.c
··· 22 22 : "memory"); 23 23 } 24 24 25 - void memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) 25 + static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) 26 26 { 27 27 if (unlikely(!n)) 28 28 return; ··· 38 38 } 39 39 rep_movs(to, (const void *)from, n); 40 40 } 41 - EXPORT_SYMBOL(memcpy_fromio); 42 41 43 - void memcpy_toio(volatile void __iomem *to, const void *from, size_t n) 42 + static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) 44 43 { 45 44 if (unlikely(!n)) 46 45 return; ··· 55 56 } 56 57 rep_movs((void *)to, (const void *) from, n); 57 58 } 59 + 60 + static void unrolled_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) 61 + { 62 + const volatile char __iomem *in = from; 63 + char *out = to; 64 + int i; 65 + 66 + for (i = 0; i < n; ++i) 67 + out[i] = readb(&in[i]); 68 + } 69 + 70 + static void unrolled_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) 71 + { 72 + volatile char __iomem *out = to; 73 + const char *in = from; 74 + int i; 75 + 76 + for (i = 0; i < n; ++i) 77 + writeb(in[i], &out[i]); 78 + } 79 + 80 + static void unrolled_memset_io(volatile void __iomem *a, int b, size_t c) 81 + { 82 + volatile char __iomem *mem = a; 83 + int i; 84 + 85 + for (i = 0; i < c; ++i) 86 + writeb(b, &mem[i]); 87 + } 88 + 89 + void memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) 90 + { 91 + if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) 92 + unrolled_memcpy_fromio(to, from, n); 93 + else 94 + string_memcpy_fromio(to, from, n); 95 + } 96 + EXPORT_SYMBOL(memcpy_fromio); 97 + 98 + void memcpy_toio(volatile void __iomem *to, const void *from, size_t n) 99 + { 100 + if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) 101 + unrolled_memcpy_toio(to, from, n); 102 + else 103 + string_memcpy_toio(to, from, n); 104 + } 58 105 EXPORT_SYMBOL(memcpy_toio); 59 106 60 107 void memset_io(volatile void __iomem *a, int b, size_t c) 61 108 { 62 - /* 63 - * TODO: memset can mangle the IO patterns quite a bit. 64 - * perhaps it would be better to use a dumb one: 65 - */ 66 - memset((void *)a, b, c); 109 + if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) { 110 + unrolled_memset_io(a, b, c); 111 + } else { 112 + /* 113 + * TODO: memset can mangle the IO patterns quite a bit. 114 + * perhaps it would be better to use a dumb one: 115 + */ 116 + memset((void *)a, b, c); 117 + } 67 118 } 68 119 EXPORT_SYMBOL(memset_io);
+14 -2
tools/testing/selftests/x86/amx.c
··· 368 368 369 369 static void validate_req_xcomp_perm(enum expected_result exp) 370 370 { 371 - unsigned long bitmask; 371 + unsigned long bitmask, expected_bitmask; 372 372 long rc; 373 + 374 + rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask); 375 + if (rc) { 376 + fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc); 377 + } else if (!(bitmask & XFEATURE_MASK_XTILECFG)) { 378 + fatal_error("ARCH_GET_XCOMP_PERM returns XFEATURE_XTILECFG off."); 379 + } 373 380 374 381 rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA); 375 382 if (exp == FAIL_EXPECTED) { ··· 390 383 fatal_error("ARCH_REQ_XCOMP_PERM saw unexpected failure.\n"); 391 384 } 392 385 386 + expected_bitmask = bitmask | XFEATURE_MASK_XTILEDATA; 387 + 393 388 rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask); 394 389 if (rc) { 395 390 fatal_error("prctl(ARCH_GET_XCOMP_PERM) error: %ld", rc); 396 - } else if (bitmask & XFEATURE_MASK_XTILE) { 391 + } else if (bitmask != expected_bitmask) { 392 + fatal_error("ARCH_REQ_XCOMP_PERM set a wrong bitmask: %lx, expected: %lx.\n", 393 + bitmask, expected_bitmask); 394 + } else { 397 395 printf("\tARCH_REQ_XCOMP_PERM is successful.\n"); 398 396 } 399 397 }