summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2026-07-08cifs: Fix support for creating SFU fifoPali Rohár
SFU fifos are natively supported (created and recognized) at least by: - Microsoft POSIX subsystem - OpenNT/Interix subsystem - Microsoft SFU (Windows Services for UNIX) - Microsoft SUA (Subsystem for UNIX-based Applications) - Windows NFS server (up to the Windows Server 2008 R2) Windows NFS server since Windows Server 2012 uses new reparse point format for storing new fifos, but still can recognize this old format (also in the latest Windows Server 2022 version). SFU-style fifo is empty regular file which has system attribute set. These SFU-style fifos are already recognized by Linux SMB client. But Linux SMB client is currently creating new SFU fifos in different format which is not compatible with all those SFU-style consumers. Fix this by creating new fifos in correct SFU format which would be recognized by all those applications and also by existing Linux SMB clients. This change affects only creating new fifos when mount option -o sfu is used. Signed-off-by: Pali Rohár <pali@kernel.org> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Signed-off-by: Steve French <stfrench@microsoft.com>
2026-07-08cifs: Fix support for creating SFU socketPali Rohár
SFU sockets are natively supported by Interix 3.0 subsystem and also by later versions. It is part of Microsoft SFU (Windows Services for UNIX) and Microsoft SUA (Subsystem for UNIX-based Applications). They can be created and existing (stored on local disk or remote SMB share) can be recognized. SFU sockets are recognized also by NFS server included in Windows Server. Windows NFS server versions since Windows Server 2012 uses new reparse point format for storing new sockets, but still can recognize this old format (also in the latest Windows Server 2022 version). SFU-style socket is a regular file which has system attribute set and content of the file is one zero byte. These SFU-style sockets are already recognized by Linux SMB client. But Linux SMB client is currently creating new SFU socket in different format which is not compatible with all those SFU applications. Fix this by creating new sockets in correct SFU format which would be recognized by all SFU, SUA, NFS and existing Linux SMB clients. This change affects only creating new sockets when mount option -o sfu is used. Signed-off-by: Pali Rohár <pali@kernel.org> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Signed-off-by: Steve French <stfrench@microsoft.com>
2026-07-08smb: client: fix atime clamp check in read completionXu Rao
cifs_rreq_done() updates the inode atime to current_time(inode) after a netfs read. It then preserves the CIFS rule that atime should not be older than mtime, because some applications break if atime is less than mtime. That rule only requires clamping when atime < mtime. The current check uses the raw non-zero result of timespec64_compare(). It therefore takes the clamp path for both atime < mtime and atime > mtime. The latter is the normal case when reading an older file: the newly recorded atime is newer than the file mtime. The completion handler then immediately moves atime back to mtime, losing the access time that was just recorded. Userspace tools that rely on atime, such as stat, find -atime, backup tools or cold-data classifiers, can therefore see a recently read CIFS file as not recently accessed. This is easy to miss because the bug is silent: read I/O still succeeds, no error is reported, and many systems either do not check atime after reads or mount with policies such as relatime/noatime. It becomes visible when a CIFS file has an mtime older than the current time, the file is read, and the local inode atime is inspected before a later revalidation replaces the cached timestamps. Clamp only when atime is actually older than mtime. This matches the same atime/mtime rule used when applying CIFS inode attributes. Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks") Cc: stable@vger.kernel.org Signed-off-by: Xu Rao <raoxu@uniontech.com> Signed-off-by: Steve French <stfrench@microsoft.com>
2026-07-08perf stat: reject --field-separator and --json-output combinationIvan Lazaric
Specifying --field-separator option is stating you want CSV output. Passing both --field-separator and --json-output is then stating you want output to be in CSV and JSON format at same time. Currently this combination is not rejected, and the outcome is a malformed combination of CSV and JSON output. This is because of inconsistencies in various printing functions, some of them have if-else chains that start with "Should I print JSON?", and some start with "Should I print CSV?". Example of current output: $ tools/perf/perf stat -x , -j -e cpu-migrations true {"counter-value" : "0.000000", "unit" : "", "event" : "cpu-migrations", "event-runtime" : 474817, "pcnt-running" : 100.00,, Instead reject the option combination, with a helpful error message and non-zero exit code. Example of new output: $ tools/perf/perf stat -x , -j true cannot use both --field-separator and --json-output Usage: perf stat [<options>] [<command>] -x, --field-separator <separator> print counts with custom separator -j, --json-output print counts in JSON format Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-07-09ASoC: tas2562: fix deprecated 'shut-down' GPIO always cleared after lookupUday Khare
In tas2562_parse_dt(), the fallback lookup for the deprecated "shut-down" GPIO property is broken due to a missing pair of braces. The code intends to reset sdz_gpio to NULL only when the lookup returns an error that is not -EPROBE_DEFER (so the driver gracefully continues without a GPIO). However, without braces the statement: tas2562->sdz_gpio = NULL; falls outside the IS_ERR() check and is executed unconditionally for every path through the if block, including a successful GPIO lookup. This means any device using the deprecated 'shut-down' DT property will always have sdz_gpio == NULL after probe, making the GPIO completely non-functional. Fix this by adding the missing braces to scope the NULL assignment inside the IS_ERR() branch, matching the pattern already used for the primary 'shutdown' GPIO lookup above. Fixes: f78a97003b8b ("ASoC: tas2562: Update shutdown GPIO property") Signed-off-by: Uday Khare <udaykhare77@gmail.com> Link: https://patch.msgid.link/20260706153109.10953-1-udaykhare77@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-07-08perf vendor events amd: Reintroduce deprecated Zen 5 core eventsSandipan Das
Maintain backward compatibility by reintroducing the events that were previously removed by commit 047979af3bf6 ("perf vendor events amd: Update Zen 5 core events"). Also set the deprecated flag and update the descriptions to point users to the correct alternative. Reported-by: Ian Rogers <irogers@google.com> Closes: https://lore.kernel.org/all/CAP-5=fV_czvd-z4N7K+_SabxuOm9UUHRyBxNuchrtAgJL3OqOw@mail.gmail.com/ Fixes: 047979af3bf6 ("perf vendor events amd: Update Zen 5 core events") Signed-off-by: Sandipan Das <sandipan.das@amd.com> Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-07-08drm/xe/guc: fix activity stats error message formatSk Anirban
Use ERR_PTR() to print the error code symbolically. This makes the failure easier to spot from IGT, e.g. when the device is wedged. Signed-off-by: Sk Anirban <sk.anirban@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260624194618.2793571-6-sk.anirban@intel.com
2026-07-08drm/xe/guc: distinguish wedged from recoverable cancellationSk Anirban
The CT layer returns -ECANCELED regardless of whether cancellation is due to a GT reset or a wedged device. Return -ENOTRECOVERABLE on wedge so callers don't need xe_device_wedged() checks to suppress spurious error logs. Also document the return codes of xe_guc_ct_send() in kernel-doc form. v2: Fix -ECANCELED description (Matt) Signed-off-by: Sk Anirban <sk.anirban@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260624194618.2793571-5-sk.anirban@intel.com
2026-07-08drm/xe/userptr: Stub notifier_lock helpers when DRM_GPUSVM=nShuicheng Lin
When CONFIG_DRM_GPUSVM=n (e.g. um-allyesconfig), the only caller of xe_pt_svm_userptr_notifier_lock() is compiled out, triggering: drivers/gpu/drm/xe/xe_pt.c:1418:13: warning: 'xe_pt_svm_userptr_notifier_lock' defined but not used [-Wunused-function] The helpers cannot simply be removed in this case: the matching xe_pt_svm_userptr_notifier_unlock() is also referenced from xe_pt_update_ops_run(), which lives outside any DRM_GPUSVM ifdef and is gated only at runtime by pt_update_ops->needs_svm_lock. The symbol must exist in all builds. Provide empty static inline stubs for !DRM_GPUSVM, matching the pattern used by xe_svm_notifier_lock()/_unlock() in xe_svm.h. Fixes: 80ccbd97ffee ("drm/xe/userptr: Hold notifier_lock for write on inject test path") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202606302210.QqcLbOEN-lkp@intel.com/ Reviewed-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260630192221.2998168-1-shuicheng.lin@intel.com Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
2026-07-08KVM: VMX: Use cached vcpu_vmx pointer in MSR and segment helpersHao Zhang
vmx_get_msr() and vmx_set_msr() already cache to_vmx(vcpu) in a local 'vmx' pointer, but a few cases still open-code to_vmx(vcpu). Use the cached pointer for consistency. Likewise, cache to_vmx(vcpu) in vmx_get_segment_base() instead of open-coding it in both the real-mode check and the VMCS read path. No functional change intended. Signed-off-by: Hao Zhang <zhanghao1@kylinos.cn> Link: https://patch.msgid.link/tencent_A78DC401911634111A3391650CB00FCD0409@qq.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08drm/amdkfd: Check bounds on CRIU restore queue type and mqd sizeDavid Francis
We weren't checking whether the values provided in the private data in kfd CRIU restore were within bounds. For queue type, add a KFD_QUEUE_TYPE_MAX and ensure the provided type is less than it. For mqd_size, add new function mqd_size_from_queue_type and confirm that the provided mqd_size matches expectations. Reviewed-by: David Yat Sin <david.yatsin@amd.com> Signed-off-by: David Francis <David.Francis@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit f19d8086f6644083c913d70bfdeee20e1b6f46a5) Cc: stable@vger.kernel.org
2026-07-08drm/amd/pm: fix smu14 power limit range calculationYang Wang
SMU14 derives the default PPT limit from SocketPowerLimitAc/Dc, but MsgLimits.Power may expose a different firmware limit for the same PPT0 throttler. Using those values independently as fixed min/max bases can report an incorrect configurable power range. Keep the socket power limit as the default value and as the fallback for current-limit queries. Calculate the reported range from both firmware values instead, using the lower value as the minimum base and the higher value as the maximum base before applying OD percentages. Signed-off-by: Yang Wang <kevinyang.wang@amd.com> Reviewed-by: Kenneth Feng <kenneth.feng@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit c936b8126b444401318fcbeb1828488cc5312dee) Cc: stable@vger.kernel.org
2026-07-08drm/amdkfd: Check bounds in allocate_event_notification_slotDavid Francis
The valid event ids go from 0 to KFD_SIGNAL_EVENT_LIMIT allocate_event_notification_slot has an option to specify an event id to allocate at, used by CRIU. We weren't checking the bounds on that value. Check them. v2: Lower bounds check is unecessary because of idr_alloc already rejecting negative numbers. Upper bounds check should be KFD_SIGNAL_EVENT_LIMIT since the signal mode mappings might not yet exist Signed-off-by: David Francis <David.Francis@amd.com> Reviewed-by: David Yat Sin <david.yatsin@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 6853f1f6cbbeb3f53ebbbd7286536aeb2c5d5f50) Cc: stable@vger.kernel.org
2026-07-08amdkfd: properly free secondary context idZhu Lingshan
Function kfd_process_free_id() should skip over the primary kfd process because its context id is fixed assigned, not allocated through the ida table. This function should only work on secondary contexts. Fixes: fac682a1d1af ("amdkfd: identify a secondary kfd process by its id") Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 8799ba6fb6a48438aea20c82e74c2f2a3d2b2e7a) Cc: stable@vger.kernel.org
2026-07-08drm/amdkfd: Don't acquire buffers during CRIU queue restore.David Francis
kfd_criu_restore_queue's call of kfd_queue_acquire_buffers was failing for multiple reasons - The ctl_stack_size set by the CRIU plugin doesn't match what is expected by acquire_buffers - The svm buffer cannot be acquired at this point because CRIU may not have restored it, or may have restored it to a different address. The only reason acquire_buffers was necessary here was to avoid a null ptr dereference in init_user_queue. Just put in a check for that dereference; it doesn't appear to come up in real use cases right now. That is, there is no usage of CRIU with shared MES. This is a partial revert of commit 20a5e7ffdfec ("drm/amdkfd: Properly acquire queue buffers in CRIU restore") Fixes: 20a5e7ffdfec ("drm/amdkfd: Properly acquire queue buffers in CRIU restore") Reviewed-by: David Yat Sin <david.yatsin@amd.com> Signed-off-by: David Francis <David.Francis@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 1cafa8b29e029eac3ddf64604f891b35dbf6262b) Cc: stable@vger.kernel.org
2026-07-08KVM: SVM: Remove VM from the GA Log notifier list before VM destructionSean Christopherson
When a VM is being destroyed, delete it from the list used to process GA Log interrupts before vCPUs are freed, otherwise avic_ga_log_notifier() could theoretically hit a use-after-free if a GA Log notification arrives for a vCPU after the last reference to the VM has been put. Note, in practice, it's likely all but impossible to trigger UAF, as all all irqfds and thus all IRTEs are cleaned up by: kvm_irqfd_release() | |-> irqfd_deactivate() | |-> irqfd_shutdown() | |-> irq_bypass_unregister_consumer() And kvm_irqfd_release() is guaranteed to run before the last reference to the VM is put. KVM also configures GA Log interrupts only when a vCPU is blocking (older versions of KVM configre GA Log interrupts at all times, but AVIC is off by default on those kernels). Hitting UAF would require tearing down a VM shortly after a vCPU stopped blocking, and with a very, very delayed IRQ from hardware. Opportunistically use guard() to avoid a local "flags" variable. Fixes: 5881f73757cc ("svm: Introduce AMD IOMMU avic_ga_log_notifier") Cc: Naveen N Rao (AMD) <naveen@kernel.org> Cc: Xiao Wu <xiaowu.417@qq.com> Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://patch.msgid.link/20260630210156.457151-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: SVM: Do all per-VM AVIC initialization during vCPU precreation phaseSean Christopherson
Move all per-VM AVIC initialization from VM creation to vCPU pre-creation, i.e. defer allocating the logical ID table and adding the VM to the GA Log list until vCPUs are created. This will allow removing the VM from the GA Log list before vCPUs are destroyed without needing yet another kvm_x86_ops hook (.vm_pre_destroy() is very intentionally called if and only if VM creation fully succeeds). As a bonus, this re-unites physical and logic table allocation, and avoids allocating a logical table in the unlikely scenario that userspace creates a VM without an in-kernel local APIC. Another bonus to hooking .vcpu_precreate() is that there is no need to unwind on failure, as the VM has already been created, i.e. KVM will run through all phases of VM destruction. In fact, unwinding is undesirable, as KVM tries to keep VM-wide behavior idempotent/sticky across creaton of multiple vCPUs. Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://patch.msgid.link/20260630210156.457151-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: SVM: Make kvm_x86_ops.vcpu_precreate() hook fully AVIC specificSean Christopherson
In anticipation of deferring all per-VM AVIC initialization until a vCPU is first created, move SVM's kvm_x86_ops.vcpu_precreate() hook into avic.c as avic_vcpu_precreate() and nullify the hook if AVIC is disabled (and WARN if the hook is somehow invoked without AVIC enabled). Reviewed-by: Naveen N Rao (AMD) <naveen@kernel.org> Link: https://patch.msgid.link/20260630210156.457151-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: Remove kvm_debugfs_dir on kvm_init() error pathsleixiang
kvm_init_debug() runs before several steps that can fail (kvm_vfio_ops_init(), kvm_gmem_init(), kvm_init_virtualization() and misc_register()), but none of the corresponding error labels remove the "kvm" debugfs directory. Any failure after kvm_init_debug() therefore leaks the directory and its stat files for the lifetime of the boot. kvm_exit() already calls debugfs_remove_recursive(kvm_debugfs_dir); add the same at the err_vfio label, whose fall-through covers every path taken after kvm_init_debug(). Fixes: 2b0128127373 ("KVM: Register /dev/kvm as the _very_ last thing during initialization") Signed-off-by: leixiang <leixiang@kylinos.cn> Link: https://patch.msgid.link/20260706095910.39798-1-leixiang@kylinos.cn Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move "struct kvm_vcpu_hv" and all children from kvm_host.h => hyperv.hSean Christopherson
Move "struct kvm_vcpu_hv" and all of its child structures to hyperv.h, guarded by CONFIG_KVM_HYPERV=y, as "struct kvm_vcpu_arch" holds a pointer to the structure, i.e. only needs the structure to be declared, not fully defined. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-10-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move "struct kvm_apic_map" definition from kvm_host.h => lapic.hSean Christopherson
Move the definition of "struct kvm_apic_map", a.k.a. the optimized local APIC map, to lapic.h, as it is very nearly an implementation details that's internal to KVM's local APIC emulation (KVM also uses the map to do quick lookups when a vCPU is yielding to a different vCPU). No functional change intended. Suggested-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move KVM's arbitrary task switch reason enums to x86.hSean Christopherson
Relocate KVM's TASK_SWITCH_<reason> enums from kvm_host.h to x86.h, as the enums are arbitrary values, i.e. not architectural, and are intended to be used only to translate vendor specific information to a common x86 reason when invoking kvm_task_switch(). Opportunistically name the overall enum to help document the role of the values. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Add static asserts to document connection b/w TSS structs and macrosSean Christopherson
Add static asserts to sanity check the I/O permission map and TSS size macros against tss_segment_32. Alternatively, the macros could simply use offsetof() and sizeof(), but having literal numbers makes it easier to understand the bigger picture, and provides a good excuse for the sanity checks. Opportunistically add the necessary includes to make tss.h self sufficient. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move KVM_GUESTDBG_VALID_MASK from kvm_host.h => x86.cSean Christopherson
Move KVM_GUESTDBG_VALID_MASK into x86.c so that it's not globally visible. As explained by commit 462474588b19 ("KVM: x86: Move misc "VALID MASK" defines from kvm_host.h => x86.c"), which unintentionally missed GUESTDBG, the set of valid flags/bits is very much a KVM-internal detail, as the values from the hardcoded #defines are often captured and massaged by KVM's setup code, i.e. *directly* using the macros outside of KVM x86 would be actively dangerous. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move CR and DR macro definitions from kvm_host.h => regs.hSean Christopherson
Relocate a variety of Control/Debug Register macros that unintentionally got left behind when the related helper function prototypes were moved to regs.h. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Pluralize the macro guard name for msrs.hSean Christopherson
Add an 'S' to msrs.h's macro guard so that both the file and guard names are plural. No functional change intended. Fixes: 7a2683080158 ("KVM: x86: Move the bulk of MSR specific code from x86.c to msrs.{c,h}") Reported-by: Binbin Wu <binbin.wu@linux.intel.com> Closes: https://lore.kernel.org/all/ead7d7fd-aa4e-4c18-b399-90fb448e0af6@linux.intel.com Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/mmu: Annotate tdp_enabled as being read-mostlySean Christopherson
Tag tdp_enabled with __read_mostly as the variable is only ever written during vendor module load, same as all the other global MMU variables that are handled by kvm_configure_mmu(). Opportunistically annotate the tdp_mmu_enabled and eager_page_split declarations with __read_mostly, to match their definitions. The compiler will warn if there are conflicting annotations, i.e. there's minimal risk of the declaration annotation becoming stale. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Move the "APIC attention" macros from kvm_host.h => lapic.cSean Christopherson
Move the macros that define the mostly-obsolete apic_attention bits into lapic.c, as the gory details of PV EOIs and the pre-APICv TPR acceleration are 100% internal to KVM's local APIC emulation. No functional change intended. Reviewed-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20260625220450.3354415-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: Remove kvm_debugfs_dir on kvm_init() error pathsleixiang
kvm_init_debug() runs before several steps that can fail (kvm_vfio_ops_init(), kvm_gmem_init(), kvm_init_virtualization() and misc_register()), but none of the corresponding error labels remove the "kvm" debugfs directory. Any failure after kvm_init_debug() therefore leaks the directory and its stat files for the lifetime of the boot. kvm_exit() already calls debugfs_remove_recursive(kvm_debugfs_dir); add the same at the err_vfio label, whose fall-through covers every path taken after kvm_init_debug(). Fixes: 2b0128127373 ("KVM: Register /dev/kvm as the _very_ last thing during initialization") Signed-off-by: leixiang <leixiang@kylinos.cn> Link: https://patch.msgid.link/20260706095910.39798-1-leixiang@kylinos.cn Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/hyperv: Use {READ,WRITE}_ONCE for cross-task synic->active accessesSean Christopherson
When activating Hyper-V's Synthetic Interrupt Controller (SynIC), mark it active with WRITE_ONCE() and query it using READ_ONCE() in synic_get(), the only known cross-task reader, to document that the flag is accessed without holding the vCPU's mutex. Note, there are no data dependencies on the SynIC being marked active, e.g. the vector read by synic_set_irq() is set (usually in response to guest activity) long after the SynIC is initially activated, and a false negative on the SynIC being active would be benign (ignoring that such a race is likely to be problematic for the guest irrespective of what KVM does). Link: https://patch.msgid.link/20260630225619.511632-12-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/hyperv: Assert vCPU's mutex is held in to_hv_vcpu()Sean Christopherson
Assert that either vcpu->mutex is held or the VM is otherwise unreachable when using the normal vCPU => HyperV accessor to help detect improper cross-task usage of the HyperV structure. When accessing the structure without holding the vCPU's mutex, e.g. to send interrupts or to queue TLB flushes, KVM needs to use the more paranoid to_hv_vcpu_safe() to guarantee that it can't see a half-baked structure. To avoid false positives, open code accesses to vcpu->arch.hyperv in the Synthetic Timer callbacks (can be reached if and only if HyperV state is fully initialized). Link: https://patch.msgid.link/20260630225619.511632-11-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Treat a vCPU as unreachable if its index is invalidSean Christopherson
In the "vCPU locked or unreachable" lockdep assertion, treat a vCPU as unreachable if its index is invalid, i.e. if the vCPU is in the process of being created. Until the vCPU is inserted into the array of vCPUs, the only way to get at the vCPU is via kvm_vm_ioctl_create_vcpu(). Note, the actual index is set _before_ adding the vCPU to the array, i.e. there's no risk of a false negative on the lockdep assertion. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://patch.msgid.link/20260630225619.511632-10-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: Move nVMX's lockdep logic for vcpu->mutex to a common helperSean Christopherson
Extract nVMX's lockdep assertion that a vCPU is locked or otherwise unreachable into a common helper, as KVM x86 is about to gain another user, but there is nothing x86-specific about the logic, i.e. the assertion may be useful for other architectures. No functional change intended. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://patch.msgid.link/20260630225619.511632-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: Initialize a vCPU's index to '-1' while it's being createdSean Christopherson
Invalidate a vCPU's index immediately after allocating storage for the vCPU so that KVM doesn't incorrectly treat a vCPU that is the process of being created as being vCPU0. This will also allow detecting that a vCPU is in the process of being created and thus otherwise unreachable, which is useful for avoiding false positives in lockdep assertions on vcpu->mutex. Unwind the index back to -1 if inserting the vCPU into the array or adding the vCPU to the fd table fails, so that kvm_arch_vcpu_destroy() sees the vCPU as unreachable, i.e. so that teardown logic doesn't hit false positive lockdep assertions. Opportunistically add a comment to call out that the "real" index needs to be set before making the vCPU visible to other tasks. Note, kvm_wait_for_vcpu_online() naturally does the right thing thanks to vcpu->vcpu_idx and kvm->online_vcpus being signed values. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://patch.msgid.link/20260630225619.511632-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/xen: Punt singleshot timer hcalls to userspace if Xen vCPU ID isn't setSean Christopherson
Explicitly invalidate KVM's internal Xen vCPU ID during vCPU creation instead of *trying* to set the Xen ID to the vCPU index by default, and forward singleshot timer hypercalls to userspace if the VMM hasn't set the Xen ID via KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID. Using the vCPU's index as its default Xen ID is reasonable in concept, but in practice is horribly flawed as the index is left as '0' until after vCPU initialization completes, i.e. every vCPU gets a Xen ID of '0' by default. Forward hypercalls to userspace instead of trying to salvage any kind of default behavior, as all userspace implementations that support multiple vCPUs either don't enable the timer, are guaranteed to set Xen ID, or work only because *all* guests also screw up the singleshot timer hypercalls. The last scenarios is extremely unlikely given that Linux-as-a-guest uses the actual Xen vCPU ID when making timer hypercalls. In other words, for all intents and purposes, KVM's ABI is already that userspace must set the Xen vCPU ID, so just commit to that ABI. Note, KVM's handling of KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID restricts the ID to KVM_MAX_VCPUS, so there's no chance of a valid ID colliding with U32_MAX. Add a compile-time assertion to ensure this holds true in the future (KVM doesn't care what value is used for "invalid", only that there can't be a collision). Link: https://lore.kernel.org/all/20260612233017.1F9771F000E9@smtp.kernel.org Suggested-by: David Woodhouse <dwmw2@infradead.org> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://patch.msgid.link/20260630225619.511632-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/xen: Consolidate checks on Xen vCPU ID for singleshot timer hypercallsSean Christopherson
Hoist the checks on the Xen vCPU ID when handling set_singleshot_timer and stop_singleshot_timer hypercalls out of their individual if-statements, so that both checks on the ID are in common code. kvm_xen_hcall_vcpu_op() is already doubly committed to handling only singleshot timer hypercalls, and even if that were to change in the future, the function could simply be renamed and turned into a helper specifically for timer hypercalls. Opportunistically add a comment to explain why the check exists; the code looks rather nonsensical without the knowledge that @vcpu_id is a common param for all per-vCPU hypercalls. No functional change intended. Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://patch.msgid.link/20260630225619.511632-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/xen: Always route non-singleshot-timer vCPU hypercalls to userspaceSean Christopherson
When handling Xen vCPU hypercalls, explicitly route non-singleshot-timer commands to userspace, *before* checking if in-kernel emulation of the Xen timer is enabled. Punting hypercalls that are never accelerated by KVM because some other hypercall happens to be disabled is confusing and actively dangerous, e.g. it's easy to miss that the only reason KVM can bail early is because the timer-disabled case provides the same semantics as the implicit "default" path in the switch-statement. Opportunistically convert the switch-statement to an if-else-statement to avoid having to carry code for an impossible "default" case. For all intents and purposes, no functional change intended. Link: https://patch.msgid.link/20260630225619.511632-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/hyperv: Ensure vCPU's Hyper-V object is initialized on cross-vCPU ↵Sean Christopherson
accesses When initializing a vCPU's Hyper-V object, ensure the object is fully initialized prior to exposing it through the vCPU, and ensure accesses from other tasks (e.g. other vCPUs) see the fully initialized object if vcpu->arch.hyperv is non-NULL. Lack of ordering manifests as a lockdep splat due to attempting to lock a TLB flush FIFO before the spinlock is initialized. INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. CPU: 1 PID: 5005 Comm: syz-executor189 Not tainted 6.6.120-smp-DEV #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/18/2026 Call Trace: <TASK> [<ffffffff810dd10c>] dump_stack_lvl+0xcc/0x130 lib/dump_stack.c:106 [<ffffffff8192bddd>] assign_lock_key+0x1fd/0x230 kernel/locking/lockdep.c:977 [<ffffffff8191cb97>] register_lock_class+0x187/0x7a0 kernel/locking/lockdep.c:1291 [<ffffffff8191e7a9>] __lock_acquire+0x179/0x7650 kernel/locking/lockdep.c:5016 [<ffffffff8191e28f>] lock_acquire+0x13f/0x3d0 kernel/locking/lockdep.c:5756 [<ffffffff8101a65b>] __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline] [<ffffffff8101a65b>] _raw_spin_lock+0x2b/0x40 kernel/locking/spinlock.c:154 [<ffffffff81319d44>] spin_lock include/linux/spinlock.h:351 [inline] [<ffffffff81319d44>] hv_tlb_flush_enqueue+0xb4/0x270 arch/x86/kvm/hyperv.c:1946 [<ffffffff813160c6>] kvm_hv_flush_tlb+0xa96/0x1dc0 arch/x86/kvm/hyperv.c:2145 [<ffffffff8131438b>] kvm_hv_hypercall+0x103b/0x1fe0 arch/x86/kvm/hyperv.c:-1 [<ffffffff8133bff3>] __vmx_handle_exit arch/x86/kvm/vmx/vmx.c:6624 [inline] [<ffffffff8133bff3>] vmx_handle_exit+0x12e3/0x21f0 arch/x86/kvm/vmx/vmx.c:6641 [<ffffffff81215d11>] vcpu_enter_guest arch/x86/kvm/x86.c:11649 [inline] [<ffffffff81215d11>] vcpu_run+0x4d01/0x79c0 arch/x86/kvm/x86.c:11832 [<ffffffff8120fe39>] kvm_arch_vcpu_ioctl_run+0xb49/0x1c80 arch/x86/kvm/x86.c:12179 [<ffffffff8119cd60>] kvm_vcpu_ioctl+0xc80/0xff0 virt/kvm/kvm_main.c:6029 [<ffffffff8226fefd>] vfs_ioctl fs/ioctl.c:52 [inline] [<ffffffff8226fefd>] __do_sys_ioctl fs/ioctl.c:872 [inline] [<ffffffff8226fefd>] __se_sys_ioctl+0xfd/0x170 fs/ioctl.c:858 [<ffffffff85ac97d9>] do_syscall_x64 arch/x86/entry/common.c:52 [inline] [<ffffffff85ac97d9>] do_syscall_64+0x69/0xb0 arch/x86/entry/common.c:93 [<ffffffff85c000d0>] entry_SYSCALL_64_after_hwframe+0x68/0xd2 </TASK> Use the "safe" variant in all paths that are known to access the Hyper-V object, as detected by an upcoming lockdep assertion, with an assist or two from Sashiko. Link: https://lore.kernel.org/all/20260612232258.0D9131F000E9@smtp.kernel.org Fixes: 0823570f0198 ("KVM: x86: hyper-v: Introduce TLB flush fifo") Fixes: fc08b628d7c9 ("KVM: x86: hyper-v: Allocate Hyper-V context lazily") Reported-by: syzbot+5b32c49cd8f005e65654@syzkaller.appspotmail.com Reported-by: syzbot+5d2b94b77112148d1744@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6a396a66.52ae72c2.136ac7.0002.GAE@google.com Tested-by: syzbot+5d2b94b77112148d1744@syzkaller.appspotmail.com Link: https://patch.msgid.link/20260630225619.511632-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/hyperv: Check for NULL vCPU Hyper-V object in ↵Sean Christopherson
kvm_hv_get_tlb_flush_fifo() Check for a NULL Hyper-V object in kvm_hv_get_tlb_flush_fifo() instead of relying on the caller to do so. This will allow fixing a cross-vCPU race where KVM can access a vCPU's FIFO before it's fully initialized, without having to jump through too many cognitive hoops to reason about the correctness of the logic. Ignoring changes in ordering that only affect the aforementioned race, no functional change intended. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://patch.msgid.link/20260630225619.511632-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86/hyperv: Get target FIFO in hv_tlb_flush_enqueue(), not callerSean Christopherson
When handling Hyper-V PV TLB flushes, retrieve the to-be-used FIFO in hv_tlb_flush_enqueue() instead of having the caller pass in the FIFO. This will make it easier to fix a cross-vCPU race where KVM can access a vCPU's FIFO before it's fully initialized. No functional change intended. Link: https://patch.msgid.link/20260630225619.511632-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Read CR4.DE in emulator if and only if accessing DR4 or DR5Sean Christopherson
Micro-optimize emulation of MOV DR instructions by checking CR4.DE if and only if DR4 or DR5 is being accessed. No functional change intended. Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-9-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: WARN if MOV DR emulation hits a "too late" #GPSean Christopherson
WARN if ->set_dr() => kvm_set_dr() fails when emulating a MOV DR write, as the emulator _must_ pre-check for #GPs in order to get the event priority right when emulating MOV DR for L2 on SVM (all exceptions have higher priority than the instruction intercept). Opportunistically update the comment as the blurb about "#UD" being checked is incomplete and misleading. Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Use kvm_dr{6,7}_valid() to check DR{4,5,6,7} write values in emulatorSean Christopherson
Use kvm_dr{6,7}_valid() to validate the incoming DR{4,5,6,7} value in the emulator instead of open coding an equivalent check. In the unlikely event that the behavior of DR6/7 (and their aliases) changes in the future, using common helpers will hopefully make it less likely the emulator logic will be overlooked. No functional change intended. Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: VMX: Prioritize DR7.GD=1 #DB over CPL>0 #GP on IntelSean Christopherson
When emulating a MOV DR on Intel with DR7.GD=1 at CPL>0, prioritize the #DB due to DR7.GD over the #GP due to CPL>0, as empirical testing shows that Intel CPUs (Skylake, Icelake and Emerald Rapids) prioritize the DR7.GD #DB over all #GPs, whereas AMD CPUs prioritize the CPL>0 #GP (but not illegal value #GPs) over the #DB. Outside of the emulator, don't bother trying to provide the "correct" priority based on the virtual CPU model, as it's simply impossible to do so without intercepting *all* MOV DR accesses, which would result in a massive, unacceptable performance hit. Note, getting the priority right when advertising Intel on AMD would also require intercepting #GP, as SVM prioritizes all exceptions over the instruction intercept. Note, neither Intel's SDM nor AMD's APM says anything about the relative priority, hence the empirical testing. Arguably Intel's description of DR7.GD: causes a debug exception to be generated prior to any MOV instruction that accesses a debug register. implies that DR7.GD has higher priority. But that's a fairly weak argument as the statement would still hold true if the #GP due to CPL>0 had higher priority, as the #GP would prevent any access to a DR. Fixes: 3b88e41a4134 ("KVM: SVM: Add intercept check for accessing dr registers") Link: https://patch.msgid.link/20260612230113.684301-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Prioritize #UD on MOV DR over #GP due to non-zero CPLSean Christopherson
Manually handle the CPL check for MOV DR instructions instead of using the Priv flag, *after* checking for #UD scenarios, as #GP due to CPL>0 has lower priority than all #UDs. Fixes: 1e470be5a108 ("KVM: x86 emulator: fix mov dr to inject #UD when needed.") Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Manually check DR4/5 write values to fix SVM intercept prioritySean Christopherson
Manually (pre)check the values being written to DR4/5, i.e. the DR6/DR7 aliases, instead of relying on ->set_dr() => kvm_set_dr() to signal a #GP. SVM unfortunately prioritizes all exceptions over an instruction intercept, i.e. nSVM is relying on the emulator to perform *all* exception checks prior to attempting to execute the instruction. Fixes: 3b88e41a4134 ("KVM: SVM: Add intercept check for accessing dr registers") Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Prioritize DR7.GD #DB over #GP due to illegal DR6/7 valueSean Christopherson
When emulating a MOV DR, specifically a write to DR6 or DR7, treat a #DB due to DR7.GD (General Detect) as higher priority than a #GP due to an illegal value. While neither Intel's SDM nor AMD's APM says anything about the relative priority, empirical testing on Intel and AMD shows that the #DB has higher priority. And for VMX, where the instruction intercept has priority over *all* exceptions, KVM already treats the #DB as having higher priority. Cc: Maciej W. Rozycki <macro@orcam.me.uk> Fixes: 3b88e41a4134 ("KVM: SVM: Add intercept check for accessing dr registers") Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Treat any non-zero return from set_dr() as a faulting conditionCarlos López
When emulating a MOV to a debug register, em_dr_write() calls @ctxt->ops->set_dr(), which is forwarded to emulator_set_dr() and then kvm_set_dr(). The latter checks that the written value is valid, otherwise returning an error, in which case the emulator is supposed to inject a #GP fault into the guest. Commit 996ff5429e98 ("KVM: x86: move kvm_inject_gp up from kvm_set_dr to callers") changed the contract of kvm_set_dr() (and thus emulator_set_dr()), returning 1 as an error instead of -1, but the caller in em_dr_write() was never updated, checking only if the returned value is negative. The end result is that em_dr_write() does not detect the error, so an invalid write does not generate a #GP, but at the same time the register value is not updated. The practical impact is limited, as check_dr_write() already checks DR6 and DR7 manually. However, it misses DR4/DR5, which alias DR6/DR7 when CR4.DE=0. Fix the bug by treating any non-zero return from set_dr() as a reason to inject #GP. Note, the manual checks on DR6 and DR7 are flawed, as they incorrectly prioritize the #GP over a DR7.GD=1 #DB (the General Detect #DB has priority on both Intel and AMD). Note #2, relying on ->set_dr() to detect #GP is also flawed as all exceptions have higher priority than the instruction intercept on SVM, i.e. the manual checks need to be extended to DR4 and DR5 (after the priority bug is fixed). Fixes: 996ff5429e98 ("KVM: x86: move kvm_inject_gp up from kvm_set_dr to callers") Signed-off-by: Carlos López <clopez@suse.de> Link: https://patch.msgid.link/20260601133320.91479-2-clopez@suse.de [sean: drop explicit "!= 0", massage changelog] Reviewed-by: Jim Mattson <jmattson@google.com> Link: https://patch.msgid.link/20260612230113.684301-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: x86: Fix emulated CPUID features being applied to wrong sub-leafBinbin Wu
Pass the CPUID index into cpuid_func_emulated() and return no emulated features for indexed CPUID leaves with a non-zero index. KVM currently emulates CPUID features only for index 0, but kvm_vcpu_after_set_cpuid() looks up emulated features by function alone. As a result, reverse_cpuid[] entries that share a function but use a non-zero index, e.g. CPUID.7.1:ECX, can inherit emulated features that belong to index 0. For example, RDPID, which is CPUID.7.0:ECX[22], can be incorrectly OR'd into CPUID.7.1:ECX. This is benign today because the affected bits do not correspond to features KVM cares about, but it can become a real bug as new CPUID features are defined. Make the helper index-aware so emulated features are applied only to the CPUID entry they actually describe. Fixes: e592ec657d84 ("KVM: x86: Initialize guest cpu_caps based on KVM support") Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Link: https://patch.msgid.link/20260609075748.612704-1-binbin.wu@linux.intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-08KVM: TDX: Return EINVAL, not EOPNOTSUPP, for NULL INIT_MEM_REGION sourceSean Christopherson
Return EINVAL instead of EOPNOTSUPP if userspace attempts to pass a NULL pointer for the source page of INIT_MEM_REGION, so that KVM's ABI is consistent between TDX and SNP (for LAUNCH_UPDATE). EOPNOTSUPP was chosen to be a forward-looking error code for when guest_memfd supports in-place conversion, but even when in-place conversion comes along, it's an awkward error code as KVM is deliberately choosing to disallow virtual address '0', which is technically a legal userspace address. I.e. it's not so much a lack of support as it is that KVM reserves address '0' to simplify KVM's internal implementation. Opportunistically move the check so that it's co-located with the other checks on the userspace address, and so that it's more obvious that a NULL source address is explicitly disallowed. Fixes: 2a62345b3052 ("KVM: guest_memfd: GUP source pages prior to populating guest memory") Cc: Yan Zhao <yan.y.zhao@intel.com> Cc: Ackerley Tng <ackerleytng@google.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Acked-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Reviewed-by: Binbin Wu <binbin.wu@linxu.intel.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Reviewed-by: Ackerley Tng <ackerleytng@google.com> Link: https://patch.msgid.link/20260630213711.479692-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>