From 3457b3bcd344005af894876cab4e634cabdcbb62 Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Thu, 29 Oct 2026 07:45:03 -0700 Subject: [PATCH 01/15] x86/bugs: Select the BHI mitigation based on the attack vector properly The BHI mitigation selection is inconsistent with the documentation (attack_vector_controls.rst), which lists BHI under both the user->kernel and guest->host attack vectors. bhi_select_mitigation() only enables it when CPU_MITIGATE_GUEST_HOST is set; otherwise it selects BHI_MITIGATION_OFF, even if CPU_MITIGATE_USER_KERNEL is set. As a result, a kernel compiled with KVM disabled gets BHI automatically disabled, since CPU_MITIGATE_GUEST_HOST defaults to off without KVM. This is a bug, given that CPU_MITIGATE_USER_KERNEL still needs it: on affected Intel CPUs these kernels lose BHI_DIS_S or the BHB clearing loop by default. Booting with mitigations=auto,no_guest_host has the same effect. Select BHI_MITIGATION_ON whenever user->kernel is mitigated, and keep BHI_MITIGATION_VMEXIT_ONLY for the guest->host-only case. [ bp: Clarify commit title. ] Fixes: ddcd4d3cb37c ("x86/bugs: Add attack vector controls for BHI") Signed-off-by: Breno Leitao Signed-off-by: Borislav Petkov (AMD) Acked-by: David Kaplan Cc: Link: https://patch.msgid.link/20261029-bhi-attack-vector-v1-1-29cfa697efb6@debian.org --- arch/x86/kernel/cpu/bugs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 000ebee2d247..4ced10c6ba0d 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -2088,14 +2088,12 @@ static void __init bhi_select_mitigation(void) if (bhi_mitigation != BHI_MITIGATION_AUTO) return; - if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) { - if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL)) - bhi_mitigation = BHI_MITIGATION_ON; - else - bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY; - } else { + if (cpu_attack_vector_mitigated(CPU_MITIGATE_USER_KERNEL)) + bhi_mitigation = BHI_MITIGATION_ON; + else if (cpu_attack_vector_mitigated(CPU_MITIGATE_GUEST_HOST)) + bhi_mitigation = BHI_MITIGATION_VMEXIT_ONLY; + else bhi_mitigation = BHI_MITIGATION_OFF; - } } static void __init bhi_update_mitigation(void) From f01a394fe2a00d3cb4cf2cda279c58604a2540ad Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 19 Oct 2026 20:32:38 -0400 Subject: [PATCH 02/15] x86/csum: Relax the len and proto constraints in 32-bit csum_ipv6_magic() Building an i386 allmodconfig kernel with clang fails since allmodconfig started building netfilter with GCOV profiling: In file included from net/netfilter/nf_synproxy_core.c:7: In file included from ./include/linux/skbuff.h:26: In file included from ./include/net/checksum.h:21: In file included from ./arch/x86/include/asm/checksum.h:9: ./arch/x86/include/asm/checksum_32.h:149:6: error: inline assembly requires more registers than available The csum_ipv6_magic() asm needs five registers at once: the early-clobber sum plus register-only inputs for saddr, daddr, htonl(len) and htonl(proto). With frame pointers enabled, six general purpose registers are left to choose from. In synproxy_send_tcp_ipv6(), the GCOV instrumentation lets clang's machine scheduler move the copies of two incoming register arguments, EDX and ECX, below the asm. Both registers then stay live across the asm, which leaves four registers for its five operands. This is LLVM issue #206307. The error goes away without either GCOV or frame pointers, and it reproduces with clang 19-22. Neither len nor proto has to be in a register: ADCL also takes a 32-bit memory or immediate source operand. Use "g" for both, so the asm needs at most three registers whatever the caller looks like. ASM_INPUT_G, which normally replaces "g" to avoid clang's poor handling of it, is not enough here. It expands to "ir" for clang, so callers that pass a variable protocol, like nf_ip6_checksum(), would still need five registers. With "g", clang passes a non-constant len or proto through the stack and still turns constants into immediates. [ bp: Make Rosen Penev the author because of a previous identical submission https://lore.kernel.org/all/20260904000833.2058186-1-rosenp@gmail.com/ and Sasha graciously agreeing and giving his much more detailed commit message explaining the background of why this exists. ] Fixes: 403cec8ab6d0 ("netfilter: add option for GCOV profiling") Closes: https://dashboard.kernelci.org/build/maestro:6ad55fe255fda507603d2651 Closes: https://lore.kernel.org/a28df759-d0e9-41c0-97c7-5f89a18d54e2@oss.qualcomm.com Reported-by: kernelci.org bot Reported-by: Jeff Johnson Assisted-by: LLM Signed-off-by: Rosen Penev Signed-off-by: Sasha Levin Signed-off-by: Borislav Petkov (AMD) Acked-by: Nick Desaulniers Cc: stable@vger.kernel.org Link: https://github.com/llvm/llvm-project/issues/206307 --- arch/x86/include/asm/checksum_32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h index 17da95387997..f74873a5e351 100644 --- a/arch/x86/include/asm/checksum_32.h +++ b/arch/x86/include/asm/checksum_32.h @@ -159,7 +159,7 @@ static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr, "adcl $0, %0 ;\n" : "=&r" (sum) : "r" (saddr), "r" (daddr), - "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) + "g" (htonl(len)), "g" (htonl(proto)), "0" (sum) : "memory"); return csum_fold(sum); From e0e022004bbedc7caf1c18770980eb5372019189 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Thu, 3 Sep 2026 12:07:20 -0400 Subject: [PATCH 03/15] x86/vmware: Fix i386 high-bandwidth hypercall arguments The high-bandwidth hypercall helpers push %ebp before loading the in6 operand into it. On i386 without frame pointers, both GCC and Clang can address the memory-constrained operand relative to %esp. The push then moves the stack and the helpers load the wrong value. Typical i386 configurations use the frame-pointer unwinder and happen to address the operand through %ebp. However, UNWINDER_GUESS is available with EXPERT and permits the affected frame-pointer-disabled configuration. vmwgfx is also available on i386 and calls both helpers. Stage in6 through %eax before changing either stack register, then save %ebp and copy the staged value into it. Load the VMware magic immediately before the string I/O instruction. Mark %eax early-clobber so it cannot also provide in6 or an address register for it. Use the same sequence on x86-64, where the full-width register preserves in6. Fixes: 34bf25e820ae ("x86/vmware: Introduce VMware hypercall API") Signed-off-by: Zack Rusin Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Maaz Mombasawala Cc: stable@vger.kernel.org # 6.11+ Link: https://patch.msgid.link/4ab10678a8f50053934b62b56af81f881c1d3798.1788414669.git.zack.rusin@broadcom.com --- arch/x86/include/asm/vmware.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 4220dae14a2d..fb011cef01e7 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -276,20 +276,22 @@ unsigned long vmware_hypercall_hb_out(unsigned long cmd, unsigned long in2, asm_inline volatile ( UNWIND_HINT_SAVE + "mov %[in6], %%" _ASM_AX "\n\t" "push %%" _ASM_BP "\n\t" UNWIND_HINT_UNDEFINED - "mov %[in6], %%" _ASM_BP "\n\t" + "mov %%" _ASM_AX ", %%" _ASM_BP "\n\t" + "mov %[magic], %%eax\n\t" "rep outsb\n\t" "pop %%" _ASM_BP "\n\t" UNWIND_HINT_RESTORE - : "=a" (out0), "=b" (*out1) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (cmd), + : "=&a" (out0), "=b" (*out1) + : "b" (cmd), "c" (in2), "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), "S" (in4), "D" (in5), - [in6] VMW_BP_CONSTRAINT (in6) + [in6] VMW_BP_CONSTRAINT(in6), + [magic] "i" (VMWARE_HYPERVISOR_MAGIC) : "cc", "memory"); return out0; } @@ -304,20 +306,22 @@ unsigned long vmware_hypercall_hb_in(unsigned long cmd, unsigned long in2, asm_inline volatile ( UNWIND_HINT_SAVE + "mov %[in6], %%" _ASM_AX "\n\t" "push %%" _ASM_BP "\n\t" UNWIND_HINT_UNDEFINED - "mov %[in6], %%" _ASM_BP "\n\t" + "mov %%" _ASM_AX ", %%" _ASM_BP "\n\t" + "mov %[magic], %%eax\n\t" "rep insb\n\t" "pop %%" _ASM_BP "\n\t" UNWIND_HINT_RESTORE - : "=a" (out0), "=b" (*out1) - : "a" (VMWARE_HYPERVISOR_MAGIC), - "b" (cmd), + : "=&a" (out0), "=b" (*out1) + : "b" (cmd), "c" (in2), "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), "S" (in4), "D" (in5), - [in6] VMW_BP_CONSTRAINT (in6) + [in6] VMW_BP_CONSTRAINT(in6), + [magic] "i" (VMWARE_HYPERVISOR_MAGIC) : "cc", "memory"); return out0; } From 84b4b620af7d24916add5d45104023bc5d804f53 Mon Sep 17 00:00:00 2001 From: Babu Moger Date: Fri, 30 Oct 2026 15:28:47 -0500 Subject: [PATCH 04/15] x86/resctrl: Correct ABMC counter ID field width AMD's Assignable Bandwidth Monitoring Counters (ABMC) are configured via MSR_IA32_L3_QOS_ABMC_CFG. The cntr_id field selects the counter the configuration applies to. The number of counters a platform supports (the number of possible values written into that field) is enumerated separately via CPUID. On platforms that enumerate more than 32 counters, the current 5-bit encoding truncates the counter ID and misprograms ABMC. The section "Assignable Bandwidth Monitoring (ABMC)" in the APM has been updated to widen MSR_IA32_L3_QOS_ABMC_CFG.cntr_id from 5 bits to 12 bits. The CPUID enumeration reports the maximum counter ID in a 16-bit field and may therefore report more counters than a 12-bit MSR_IA32_L3_QOS_ABMC_CFG.cntr_id can address. Widen MSR_IA32_L3_QOS_ABMC_CFG.cntr_id to 12 bits to match the architecture. Cap the enumerated counter count at BIT(12) so every counter ID used by resctrl can be written to MSR_IA32_L3_QOS_ABMC_CFG.cntr_id without truncation. [ bp: Massage and simplify commit message. ] Fixes: 84ecefb76674 ("x86/resctrl: Add data structures and definitions for ABMC assignment") Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Reinette Chatre Cc: stable@vger.kernel.org Link: https://patch.msgid.link/3a5e99300f1309ae279beb058ef0438516b2bdcd.1793392128.git.babu.moger@amd.com --- arch/x86/kernel/cpu/resctrl/internal.h | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index e3cfa0c10e92..ffd74a68671b 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -214,8 +214,8 @@ union l3_qos_abmc_cfg { bw_src :12, reserved1: 3, is_clos : 1, - cntr_id : 5, - reserved : 9, + cntr_id :12, + reserved : 2, cntr_en : 1, cfg_en : 1; } split; diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 3838e0a13d36..5d0d3b18f9b8 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -470,7 +470,8 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r) r->mon.mbm_cntr_assignable = true; r->mon.mbm_cntr_configurable = true; cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); - r->mon.num_mbm_cntrs = (ebx & GENMASK(15, 0)) + 1; + /* cntr_id is 12 bits and can only encode 4096 counters. */ + r->mon.num_mbm_cntrs = min((ebx & GENMASK(15, 0)) + 1, BIT(12)); hw_res->mbm_cntr_assign_enabled = true; } From 7782a6a8dfc05f5622fdf616e5cf3df7d16eaef5 Mon Sep 17 00:00:00 2001 From: Babu Moger Date: Fri, 30 Oct 2026 15:28:48 -0500 Subject: [PATCH 05/15] x86,fs/resctrl: Keep mbm_assign_mode in default mode at boot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mbm_event mode assigns hardware MBM counters to RMID/event pairs. It is intended for deployments that need to manage counter assignment on platforms where the number of monitoring groups exceeds the available hardware counters. Hardware counters are scarce on these platforms, so mbm_event mode suits workflows that monitor a subset of groups at a time and rotate assignments as needed. x86 resctrl enables the mbm_event mode by default on hardware that supports it. This breaks the pqos tool¹, which assumes the historical default mode. It creates 16 or more monitoring groups and uses two counters per group. On a platform with 32 counters per domain, that exhausts the mbm_event counters pool, causing additional groups to read "Unassigned". pqos interprets a non-numeric event read as zero bandwidth and reports 0 MB/s for those groups: $ sudo pqos -m all:0-4 CORE IPC MISSES LLC[KB] MBL[MB/s] MBR[MB/s] 0 0.69 16k 192.0 0.0 0.0 1 0.40 3k 0.0 0.0 0.0 2 0.44 1k 64.0 0.0 0.0 3 0.39 1k 64.0 0.0 0.0 4 0.43 1k 0.0 0.0 0.0 Leave mbm_assign_mode in default mode during initialization as decided in the thread at the Link tag. Default mode uses one counter per monitoring group. On existing AMD platforms, the default active counters pool is 64 and may be larger on newer hardware. The active counters pool is the number of counters that the hardware can actively track in default mode. Deployments within the active counters pool receive accurate bandwidth measurements in the default mode. Users can create more monitoring groups (for example, 4096 on current hardware) than there are active counters in the pool. Beyond that pool, readings may be misleading or report as "Unavailable", with no user-visible indication. Default mode is still limited once the number of monitoring groups exceeds that active counters pool. After hardware re-allocates a counter, a read may return "Unavailable". pqos still treats "Unavailable" as zero. Successive reads can be a count, "Unavailable", then another count. pqos treats those jumps as wraparound and can report an inconsistent rate: $ sudo pqos -m all:0-4 CORE IPC MISSES LLC[KB] MBL[MB/s] MBR[MB/s] 0 0.76 60k 32.0 0.0 0.0 1 0.45 1k 32.0 0.0 0.0 2 1.57 107k 64.0 0.0 17592186044184.9 3 1.62 276k 4928.0 3.2 0.5 Users that need stable measurements beyond the active counters pool should use mbm_event mode and rotate assignments as needed. Enable it with: # echo mbm_event > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode ¹https://github.com/intel/intel-cmt-cat [ bp: Massage commit message. ] Fixes: 0f1576e43adc ("x86/resctrl: Configure mbm_event mode if supported") Closes: https://github.com/intel/intel-cmt-cat/issues/311 Signed-off-by: Babu Moger Signed-off-by: Borislav Petkov (AMD) Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20260804191608.GDanI6eK2Q07w6pNcb@fat_crate.local --- Documentation/filesystems/resctrl.rst | 87 ++++++++++++++++----------- arch/x86/kernel/cpu/resctrl/monitor.c | 1 - 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst index b52795e03303..2750f2eabf70 100644 --- a/Documentation/filesystems/resctrl.rst +++ b/Documentation/filesystems/resctrl.rst @@ -350,12 +350,12 @@ with the following files: "mbm_assign_mode": The supported counter assignment modes. The enclosed brackets indicate which mode is enabled. The MBM events associated with counters may reset when "mbm_assign_mode" - is changed. + is changed. See architecture specific notes below. :: # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode - [mbm_event] - default + [default] + mbm_event "mbm_event": @@ -373,20 +373,17 @@ with the following files: Moving to mbm_event counter assignment mode requires users to assign the counters to the events. Otherwise, the MBM event counters will return 'Unassigned' when read. - The mode is beneficial for AMD platforms that support more CTRL_MON - and MON groups than available hardware counters. By default, this - feature is enabled on AMD platforms with the ABMC (Assignable Bandwidth - Monitoring Counters) capability, ensuring counters remain assigned even - when the corresponding RMID is not actively used by any processor. + It is intended for deployments that need to manage counter assignment on + platforms where the number of monitoring groups exceeds the available + hardware counters. Hardware counters are scarce on these platforms, so + mbm_event mode suits workflows that monitor a subset of groups at a time and + rotate assignments as needed. The mbm_event mode ensures counters remain + assigned even when the corresponding RMID is not actively used. "default": In default mode, resctrl assumes there is a hardware counter for each - event within every CTRL_MON and MON group. On AMD platforms, it is - recommended to use the mbm_event mode, if supported, to prevent reset of MBM - events between reads resulting from hardware re-allocating counters. This can - result in misleading values or display "Unavailable" if no counter is assigned - to the event. + event within every CTRL_MON and MON group. * To enable "mbm_event" counter assignment mode: :: @@ -398,6 +395,24 @@ with the following files: # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + In default mode on AMD platforms that support more CTRL_MON and MON groups + than hardware counters, hardware dynamically shares a smaller pool of + counters among RMIDs. One counter from this pool is used per monitoring + group and counts every MBM event of that group's RMID. The size of the pool + is not enumerated to software (unlike "num_mbm_cntrs"), and "num_rmids" may + be much larger. For example, 64 counters in this pool monitor 64 groups. + Newer hardware may provide a larger pool. + + On such platforms, while the number of monitoring groups does not exceed + that pool, a counter stays attached to each RMID and readings remain + accurate. Creating more groups than the pool can cause hardware to + re-allocate those counters between successive reads of an event. Bandwidth + values may then be misleading, or a read may return "Unavailable" if no + counter is allocated to the RMID. There is no user-visible indication when + this begins. Users who need stable readings beyond that pool should switch + to mbm_event mode, if supported, and assign counters to the groups of + interest (rotating assignments as needed). + "num_mbm_cntrs": The maximum number of counters (total of available and assigned counters) in each domain when the system supports mbm_event mode. @@ -1784,17 +1799,19 @@ View the llc occupancy snapshot:: Examples on working with mbm_assign_mode ======================================== -a. Check if MBM counter assignment mode is supported. +a. Check if MBM counter assignment mode is supported. Enable "mbm_event" +mode. Switching the mbm_assign_mode may reset all the MBM counters (and +thus all MBM events) of all the resctrl groups. :: - # mount -t resctrl resctrl /sys/fs/resctrl/ - + # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode + [default] + mbm_event + # echo "mbm_event" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode [mbm_event] default -The "mbm_event" mode is detected and enabled. - b. Check how many assignable counters are supported. :: @@ -1805,36 +1822,39 @@ c. Check how many assignable counters are available for assignment in each domai :: # cat /sys/fs/resctrl/info/L3_MON/available_mbm_cntrs - 0=30;1=30 + 0=32;1=32 -d. To list the default group's assign states. +d. To list the default group's assign states. Counters are unassigned when the mode +is switched to "mbm_event". :: # cat /sys/fs/resctrl/mbm_L3_assignments - mbm_total_bytes:0=e;1=e - mbm_local_bytes:0=e;1=e + mbm_total_bytes:0=_;1=_ + mbm_local_bytes:0=_;1=_ -e. To unassign the counter associated with the mbm_total_bytes event on domain 0. +e. To assign the counter associated with the mbm_total_bytes event on domain 0 +in exclusive mode. :: - # echo "mbm_total_bytes:0=_" > /sys/fs/resctrl/mbm_L3_assignments + # echo "mbm_total_bytes:0=e" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments - mbm_total_bytes:0=_;1=e - mbm_local_bytes:0=e;1=e + mbm_total_bytes:0=e;1=_ + mbm_local_bytes:0=_;1=_ f. To unassign the counter associated with the mbm_total_bytes event on all domains. :: # echo "mbm_total_bytes:*=_" > /sys/fs/resctrl/mbm_L3_assignments - # cat /sys/fs/resctrl/mbm_L3_assignment + # cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=_;1=_ - mbm_local_bytes:0=e;1=e + mbm_local_bytes:0=_;1=_ -g. To assign a counter associated with the mbm_total_bytes event on all domains in -exclusive mode. +g. To assign a counter associated with the mbm_total_bytes and mbm_local_bytes +events on all domains in exclusive mode. :: # echo "mbm_total_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments + # echo "mbm_local_bytes:*=e" > /sys/fs/resctrl/mbm_L3_assignments # cat /sys/fs/resctrl/mbm_L3_assignments mbm_total_bytes:0=e;1=e mbm_local_bytes:0=e;1=e @@ -1891,13 +1911,8 @@ the MBM counters (and thus all MBM events) of all the resctrl groups. # echo "default" > /sys/fs/resctrl/info/L3_MON/mbm_assign_mode # cat /sys/fs/resctrl/info/L3_MON/mbm_assign_mode - mbm_event [default] - -m. Unmount the resctrl filesystem. -:: - - # umount /sys/fs/resctrl/ + mbm_event Intel RDT Errata ================ diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 5d0d3b18f9b8..a6a9090c4808 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -472,7 +472,6 @@ int __init rdt_get_l3_mon_config(struct rdt_resource *r) cpuid_count(0x80000020, 5, &eax, &ebx, &ecx, &edx); /* cntr_id is 12 bits and can only encode 4096 counters. */ r->mon.num_mbm_cntrs = min((ebx & GENMASK(15, 0)) + 1, BIT(12)); - hw_res->mbm_cntr_assign_enabled = true; } r->mon_capable = true; From 7d5af1f256fdecff6a7986bbc9146b69cb355bb5 Mon Sep 17 00:00:00 2001 From: Naman Jain Date: Mon, 31 Aug 2026 08:25:28 +0000 Subject: [PATCH 06/15] x86/init: Initialize wall clock in get_rtc_noop() get_rtc_noop() is used when an RTC is unavailable, but leaves its output argument untouched. When CONFIG_INIT_STACK_ALL_ZERO is not enabled, timekeeping_init() may therefore receive a nonzero invalid persistent clock value and warn: "Persistent clock returned invalid value" Initialize the output to zero, the documented representation of an unsupported persistent clock. Fixes: c311ed6183f4 ("x86/init: Allow DT configured systems to disable RTC at boot time") Signed-off-by: Naman Jain Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Thomas Gleixner Reviewed-by: Roman Kisel Reviewed-by: Hardik Garg Reviewed-by: Dexuan Cui Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260831082528.1623843-1-namjain@linux.microsoft.com --- arch/x86/kernel/x86_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index 252c5827d063..3b9b41820c84 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -37,7 +37,7 @@ static void iommu_shutdown_noop(void) { } bool __init bool_x86_init_noop(void) { return false; } void x86_op_int_noop(int cpu) { } int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; } -void get_rtc_noop(struct timespec64 *now) { } +void get_rtc_noop(struct timespec64 *now) { *now = (struct timespec64){0}; } static __initconst const struct of_device_id of_cmos_match[] = { { .compatible = "motorola,mc146818" }, From b697faab2c92653ee13bd950c8de13551a78971d Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sun, 1 Nov 2026 18:58:08 +0100 Subject: [PATCH 07/15] x86/entry: Fix ptrace regression The recent rework of the syscall entry code missed the historical detail of the abuse of syscall number -1L to abort a syscall and keep modifications by tracers to the return value, while a rewrite of the syscall number to an invalid value undoes eventual tracer modification to the return value and overwrite it with -ENOSYS. Restore the original behaviour. Fixes: 1b1f3b3e1b39 ("x86/entry: Get rid of the sys_ni_syscall() indirection") Reported-by: Sebastian Andrzej Siewior Signed-off-by: Thomas Gleixner Tested-by: Sebastian Andrzej Siewior Cc: stable@vger.kernel.org Link: https://patch.msgid.link/87ecd4xwlr.ffs@fw13 Closes: https://lore.kernel.org/all/20261022142425.3Wx-RrU5@linutronix.de --- arch/x86/entry/syscall_32.c | 4 ++++ arch/x86/entry/syscall_64.c | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/x86/entry/syscall_32.c b/arch/x86/entry/syscall_32.c index a59509bb460a..ca97fa36182b 100644 --- a/arch/x86/entry/syscall_32.c +++ b/arch/x86/entry/syscall_32.c @@ -77,6 +77,10 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, unsigned if (likely(nr < IA32_NR_syscalls)) { nr = array_index_nospec(nr, IA32_NR_syscalls); regs->ax = ia32_sys_call(regs, (unsigned int)nr); + } else { + /* See comment in do_syscall_64() */ + if (nr != -1UL) + regs->ax = -ENOSYS; } } diff --git a/arch/x86/entry/syscall_64.c b/arch/x86/entry/syscall_64.c index 966d3d1b7586..bb95ad0ab786 100644 --- a/arch/x86/entry/syscall_64.c +++ b/arch/x86/entry/syscall_64.c @@ -64,15 +64,20 @@ static __always_inline bool do_syscall_x64(struct pt_regs *regs, unsigned long n return false; } -static __always_inline void do_syscall_x32(struct pt_regs *regs, unsigned long nr) +static __always_inline bool do_syscall_x32(struct pt_regs *regs, unsigned long nr) { + if (!IS_ENABLED(CONFIG_X86_X32_ABI)) + return false; + /* Adjust the starting offset of the table */ nr -= __X32_SYSCALL_BIT; - if (IS_ENABLED(CONFIG_X86_X32_ABI) && likely(nr < X32_NR_syscalls)) { + if (likely(nr < X32_NR_syscalls)) { nr = array_index_nospec(nr, X32_NR_syscalls); regs->ax = x32_sys_call(regs, (unsigned int)nr); + return true; } + return false; } /* Returns true to return using SYSRET, or false to use IRET */ @@ -81,8 +86,21 @@ __visible noinstr bool do_syscall_64(struct pt_regs *regs, long nr) if (likely(syscall_enter_from_user_mode_randomize_stack(regs, &nr))) { instrumentation_begin(); - if (!do_syscall_x64(regs, nr)) - do_syscall_x32(regs, nr); + if (unlikely(!do_syscall_x64(regs, nr))) { + /* + * The special treatment of syscall number -1 is a + * historical bogosity as the original code used -1 to + * indicate syscall abort, which is not distinguishable + * from a syscall which is invoked with syscall number + * -1. The historic behavior is to keep the return value + * in regs->ax unmodified in that case, which means it's + * either the preset value -ENOSYS or a value which was + * written by a tracer. If the syscall number is invalid + * but not -1 then overwrite any tracer modification. + */ + if (!do_syscall_x32(regs, nr) && nr != -1L) + regs->ax = -ENOSYS; + } instrumentation_end(); } From 6bb462e8e5334f7bd3384843253e96112c98f5af Mon Sep 17 00:00:00 2001 From: Drew Fustini Date: Wed, 4 Nov 2026 08:35:23 -0800 Subject: [PATCH 08/15] MAINTAINERS: resctrl: Add myself as reviewer The RISC-V CBQRI support builds on the common resctrl code, so changes there affect RISC-V. Add myself as a reviewer to stay aware of them. Suggested-by: Reinette Chatre Signed-off-by: Drew Fustini Signed-off-by: Borislav Petkov (AMD) Acked-by: Reinette Chatre Link: https://patch.msgid.link/20261104-dfustini-atl-sc-cbqri-dt-v10-6-1636a003a3c0@kernel.org --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 93abbb315065..fbd4e64983d1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23463,6 +23463,7 @@ M: x86@kernel.org R: Dave Martin R: James Morse R: Babu Moger +R: Drew Fustini L: linux-kernel@vger.kernel.org S: Supported P: Documentation/process/maintainer-tip.rst From 2803a7993d4cd9354f851dfcab46991d676f4e6b Mon Sep 17 00:00:00 2001 From: Ashish Kalra Date: Wed, 28 Oct 2026 19:49:22 +0000 Subject: [PATCH 09/15] x86/sev: Clear RMPOPT when segmented RMP is disabled by firmware Segmented RMP support is advertised via X86_FEATURE_SEGMENTED_RMP, and the firmware enables it via MSR_AMD64_RMP_CFG[SEG_RMP_ENABLED]. The latter can be cleared in platform BIOS by the user, in which case the system runs in contiguous RMP setting. snp_probe_rmptable_info() does not clear X86_FEATURE_RMPOPT in the advertised-but-firmware-disabled case. As a result, this does not prevent snp_enable_rmpopt() from trying to program MSR_AMD64_RMPOPT_BASE, which raises a #GP on the MSR access. Make sure X86_FEATURE_RMPOPT is cleared in all cases where segmented RMP is not enabled. [ bp: - Put the commit message on Ozempic - Simplify snp_probe_rmptable_info() - Fix feature check order in snp_enable_rmpopt() - Add RMPOPT feature dependency on SEV_SNP ] Fixes: 15d974be0a3b ("x86/sev: Initialize RMPOPT configuration MSRs") Signed-off-by: Ashish Kalra Signed-off-by: Borislav Petkov (AMD) Link: https://patch.msgid.link/56da047d63b22f03a7e709fc172a5543da894d67.1793216372.git.ashish.kalra@amd.com --- arch/x86/kernel/cpu/cpuid-deps.c | 1 + arch/x86/virt/svm/sev.c | 17 +++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 99801e844b30..acbcec394ef1 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -93,6 +93,7 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL }, { X86_FEATURE_LASS, X86_FEATURE_SMAP }, { X86_FEATURE_INVLPGB, X86_FEATURE_PCID }, + { X86_FEATURE_RMPOPT, X86_FEATURE_SEV_SNP }, {} }; diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index bd70c4d0b774..417e6a41ac60 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -669,10 +669,10 @@ void snp_enable_rmpopt(void) u64 base; int cpu; - if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) return; - if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) return; if (!rmpopt_soft_init) @@ -819,18 +819,11 @@ bool snp_probe_rmptable_info(void) { if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP)) { rdmsrq(MSR_AMD64_RMP_CFG, rmp_cfg); - - if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) { - if (probe_segmented_rmptable_info()) - return true; - - setup_clear_cpu_cap(X86_FEATURE_RMPOPT); - return false; - } - } else { - setup_clear_cpu_cap(X86_FEATURE_RMPOPT); + if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) + return probe_segmented_rmptable_info(); } + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); return probe_contiguous_rmptable_info(); } From dc2334c1752b3c5f58af74f1e7ad6769b38e1f33 Mon Sep 17 00:00:00 2001 From: Ashish Kalra Date: Wed, 28 Oct 2026 19:49:38 +0000 Subject: [PATCH 10/15] x86/sev: Set up RMPOPT only on an active SNP host rmpopt_init() setup work is gated only on X86_FEATURE_RMPOPT - a CPUID bit advertised independently of whether SNP is active. As a device_initcall it runs on every system with that bit, so on a host where SNP is not enabled (disabled in the BIOS, or AMD IOMMU initialization fails to bring it up) the workqueue is allocated and the message is printed at boot even though RMPOPT is never used: snp_enable_rmpopt() bails out on a non-SNP host. Rather than add an explicit SNP-host gate to the initcall, set RMPOPT up where the host SNP state is established. Call rmpopt_init() from the tail of snp_rmptable_init(), which runs only once the host RMP table has been set up and CC_ATTR_HOST_SEV_SNP is guaranteed, and drop the device_initcall. This is soft initialization only - the workqueue and the announcement; the actual RMPOPT_BASE programming is still done later by snp_enable_rmpopt(), which re-checks X86_FEATURE_RMPOPT, CC_ATTR_HOST_SEV_SNP and rmpopt_soft_init. An rmpopt_init() failure is non-fatal to SNP and is intentionally ignored by snp_rmptable_init(). [ bp: Massage commit message. ] Fixes: c6c6f156d192 ("x86/sev: Perform RMP optimizations asynchronously") Suggested-by: Tom Lendacky Signed-off-by: Ashish Kalra Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Pankaj Gupta Reviewed-by: Tom Lendacky Link: https://patch.msgid.link/331aeb2f29710865ec064bacf9edacaadde2b094.1793216372.git.ashish.kalra@amd.com --- arch/x86/virt/svm/sev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 417e6a41ac60..4de9681cc2f8 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -662,7 +662,6 @@ static int __init rmpopt_init(void) return 0; } -device_initcall(rmpopt_init); void snp_enable_rmpopt(void) { @@ -726,6 +725,8 @@ int __init snp_rmptable_init(void) */ crash_kexec_post_notifiers = true; + rmpopt_init(); + return 0; } From fb685de78e6bf79e49854e7d149f69b125583de5 Mon Sep 17 00:00:00 2001 From: Ridge Lomont Date: Tue, 27 Oct 2026 15:29:21 -0700 Subject: [PATCH 11/15] x86/kcfi: Don't emit KCFI_REFERENCE() in modules KCFI_REFERENCE() takes the address of a symbol so that the compiler emits its __kcfi_typeid_ symbol, which the SYM_TYPED_FUNC_START() assembly implementing it needs. It is used from arch/x86 headers for __clear_pages_unrolled(), copy_page(), __memset() and __memmove(), and all of that assembly is built into vmlinux. Modules include the same headers, so with CONFIG_CFI=y every module also gets an __ADDRESSABLE() reference to each of these symbols in .discard.addressable. This serves no purpose there, and since __clear_pages_unrolled() is EXPORT_SYMBOL_GPL, modpost now rejects any GPL-incompatible module that includes : ERROR: modpost: GPL-incompatible module repro.ko uses GPL-only symbol '__clear_pages_unrolled' even though the module never uses the symbol. This makes OpenZFS impossible to build against CFI kernels; its configure checks fail in the same way and are misreported as CONFIG_DEBUG_LOCK_ALLOC. scripts/module.lds.S does not help here: modpost checks .o before the final link, and even after it the discarded section only loses its relocations, the undefined symbols stay in .symtab, where the module loader resolves them with the same license check. Only emit the reference when building vmlinux. Tested on x86_64 with clang 23.1.3 and CONFIG_CFI=y, with both CONFIG_LTO_CLANG_FULL=y (the configuration from the Fixes: commit) and CONFIG_LTO_CLANG_THIN=y: vmlinux links without warnings and still contains __kcfi_typeid___clear_pages_unrolled, __kcfi_typeid_copy_page, __kcfi_typeid___memset and __kcfi_typeid___memmove. It boots in QEMU with no CFI failures. A minimal module with MODULE_LICENSE("Proprietary") including fails modpost before this change and builds and loads after it. OpenZFS builds against a CFI kernel with this change, and its pool, encryption, checksum and send/recv operations run without CFI failures, in QEMU and on a desktop with CFI enforcing. Fixes: 9b041a4b66b3 ("x86/mm: Ensure clear_page() variants always have __kcfi_typeid_ symbols") Assisted-by: LLM Signed-off-by: Ridge Lomont Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Acked-by: Nathan Chancellor Link: https://github.com/openzfs/zfs/issues/18092 Link: https://patch.msgid.link/20261027-kcfi-reference-modules-v2-1-3a3247f15806@proton.me --- include/linux/compiler.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 0ea7150dba7b..ea161a72d1c7 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -258,10 +258,13 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #endif /* __KERNEL__ */ -#if defined(CONFIG_CFI) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) +#if defined(CONFIG_CFI) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) && \ + !defined(MODULE) /* * Force a reference to the external symbol so the compiler generates - * __kcfi_typid. + * __kcfi_typid. Only vmlinux needs it, as that is where the assembly + * using the typeid lives; in a module it would only add a reference to + * the symbol, which fails modpost if the symbol is GPL-only. */ #define KCFI_REFERENCE(sym) __ADDRESSABLE(sym) #else From ade63af6cfb7b3ca19ced28730fd6461e8d1d410 Mon Sep 17 00:00:00 2001 From: Breno Leitao Date: Tue, 27 Oct 2026 03:43:51 -0700 Subject: [PATCH 12/15] x86/nmi: Ignore negative NMI handler durations I am seeing NMI handlers in the Meta fleet reported as running for about 584 years. Over 30 days, 11 AMD and Intel machines logged 637 such lines, for example: AMD EPYC 9D25 (family 0x1a, model 0x11, stepping 0x0): [ 1650.616627] INFO: NMI handler (nmi_cpu_backtrace_handler.llvm.9643156322683129580) took too long to run: 18446744073709.551 msecs Intel Xeon Platinum 8321HC (family 0x6, model 0x55, stepping 0xb): [360448.230129] INFO: NMI handler (perf_event_nmi_handler) took too long to run: 18446744071018.936 msecs Intel Xeon D-2191A (family 0x6, model 0x55, stepping 0x4): [81787.188959] INFO: NMI handler (ghes_notify_nmi) took too long to run: 18446744073709.545 msecs nmi_handle() times each handler with two sched_clock() reads. When the second read is lower than the first, the u64 subtraction wraps, and nmi_check_duration() treats the result as a duration. In the three examples, the clock went back by less than 1 us, by 2.7 s and by about 6 us. The wrapped value is also stored in action->max_duration. Every later real duration is smaller, so the handler is never reported again until the next boot. Whatever makes the clock read lower, a negative difference is not a duration, so return before it is stored or reported. A clock that steps forward is not covered, since that cannot be told from a real stall. A backwards clock is still worth knowing about, so print the size of the step once per boot. This uses pr_warn_once() rather than WARN, as a stack trace says nothing about the clock and panic_on_warn machines should not go down for it. Fixes: 2ab00456ea8a ("x86: Warn when NMI handlers take large amounts of time") Signed-off-by: Breno Leitao Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261027-nmi_negative-v1-1-b436a005eb8a@debian.org --- arch/x86/kernel/nmi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 3c9f60d6ca5a..cb46da482c85 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c @@ -115,6 +115,14 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration) { int remainder_ns, decimal_msecs; + /* sched_clock() went backwards? */ + if ((s64)duration < 0) { + pr_warn_once("NMI handler (%ps): sched_clock() went backwards by %lld ns on CPU%d\n", + action->handler, -(s64)duration, + smp_processor_id()); + return; + } + if (duration < nmi_longest_ns || duration < action->max_duration) return; From b73fdd0f49e175dd733650669193c1504d283955 Mon Sep 17 00:00:00 2001 From: Reinette Chatre Date: Wed, 4 Nov 2026 16:37:47 -0800 Subject: [PATCH 13/15] MAINTAINERS: Add Ben Horgan as fs/resctrl reviewer The resctrl filesystem provides the user interface to the resource control features of multiple architectures, among them Arm's MPAM. Ben Horgan, MPAM maintainer, has consistently helped keep MPAM's requirements in view, both in discussions about new resctrl features and in review of resctrl changes. Add Ben Horgan as a reviewer so that he is copied on resctrl submissions. Signed-off-by: Reinette Chatre Signed-off-by: Borislav Petkov (AMD) Acked-by: Ben Horgan Link: https://patch.msgid.link/c68cbba4455d3f5e65c38b76b3daadc04217abca.1793838993.git.reinette.chatre@intel.com --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index fbd4e64983d1..99ae546c3f62 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23460,6 +23460,7 @@ RDT - RESOURCE ALLOCATION M: Tony Luck M: Reinette Chatre M: x86@kernel.org +R: Ben Horgan R: Dave Martin R: James Morse R: Babu Moger From cb319926808b1cca522d2087a13205e840beb45b Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Fri, 18 Sep 2026 16:27:13 +0200 Subject: [PATCH 14/15] x86/boot: Fix off-by-one error in sme_clear_pgd() The mapping helpers __sme_map_range_pmd() and __sme_map_range_pte(), and therefore sme_encrypt_kernel(), use exclusive end addresses and stop before vaddr reaches vaddr_end. However, sme_clear_pgd() treats vaddr_end as inclusive when calculating the last PGD entry to clear. If vaddr_end is PGD-aligned, the first PGD entry outside the range is cleared too. Use vaddr_end - 1 to calculate the last PGD entry within the range. Fixes: 6ebcb060713f ("x86/mm: Add support to encrypt the kernel in-place") Signed-off-by: Thorsten Blum Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky Cc: Link: https://patch.msgid.link/20260918142714.242711-2-blum@kernel.org --- arch/x86/boot/startup/sme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index c07a2c381ed1..2d5cb3f7eee6 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -99,7 +99,7 @@ static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) pgd_t *pgd_p; pgd_start = ppd->vaddr & PGDIR_MASK; - pgd_end = ppd->vaddr_end & PGDIR_MASK; + pgd_end = (ppd->vaddr_end - 1) & PGDIR_MASK; pgd_size = (((pgd_end - pgd_start) / PGDIR_SIZE) + 1) * sizeof(pgd_t); From 5cdc3746fa163fb4e8d05fa3cabf46bc6aa7df75 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Fri, 6 Nov 2026 18:47:17 -0500 Subject: [PATCH 15/15] x86/mm: Fix global ASID handed out to two processes On AMD CPUs with INVLPGB, two live processes can get the same MAX_ASID_AVAILABLE global ASID value. The two then hit each other's TLB entries, so each can read or corrupt the other's memory. The global ASID space is managed lazily. When a global ASID is freed, its bit is set in the global_asid_freed bitmap. Once the free ASID search reaches the end of the global_asid_used bitmap, a global flush is done to really reclaim the lazily freed global ASIDs. However, the current code can assign the same global ASID to two different processes, if one process is assigned MAX_ASID_AVAILABLE - 1, another process MAX_ASID_AVAILABLE, and both stick around (keeping their global ASID numbers in use) until the search wraps around again. At that point a third process could also get assigned MAX_ASID_AVAILABLE. the highest ASID stays in use, so it is not handed out again last_global_asid stays below it, so no reset the clear bits run out find_next_zero_bit() returns MAX_ASID_AVAILABLE global_asid_available > 0, so the failure is not caught MAX_ASID_AVAILABLE is handed out as an ASID A search only looks at the bits below MAX_ASID_AVAILABLE, so it cannot see that this value is in use. The next failed search hands it out again, even if the first process still holds it. The fix used here is to reset the global ASID space after a failed search, and to search again. If that search fails too, no global ASID is handed out. The test for !global_asid_available is removed, because use_global_asid() only calls allocate_global_asid() if global_asid_available > 0. The remaining test is for a condition that should be impossible. [ riel: simplify code, massage changelog and comment ] Fixes: d504d1247e36 ("x86/mm: Add global ASID allocation helper functions") Signed-off-by: Chris Mason Signed-off-by: Rik van Riel Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Thomas Gleixner Reviewed-by: Dave Hansen Cc: --- arch/x86/mm/tlb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 0c4da320831c..53dcab39566f 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -320,13 +320,19 @@ static u16 allocate_global_asid(void) lockdep_assert_held(&global_asid_lock); - /* The previous allocation hit the edge of available address space */ - if (last_global_asid >= MAX_ASID_AVAILABLE - 1) - reset_global_asid_space(); - asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, last_global_asid); - if (asid >= MAX_ASID_AVAILABLE && !global_asid_available) { + /* + * Nothing is free between last_global_asid and MAX_ASID_AVAILABLE. + * Flush lazy-freed ASIDs and reset the search space. + */ + if (asid >= MAX_ASID_AVAILABLE) { + reset_global_asid_space(); + asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, + last_global_asid); + } + + if (asid >= MAX_ASID_AVAILABLE) { /* This should never happen. */ VM_WARN_ONCE(1, "Unable to allocate global ASID despite %d available\n", global_asid_available);