summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2026-10-20drm/amdkfd: wait for a GPU reset before freeing a BOWilliam Palacek
When a GPU reset takes the reset domain, KFD eviction cannot unmap user queues: execute_queues_cpsch() fails its trylock with -EIO, so the queues keep running until the ASIC is reset. The TLB flush is also skipped while the reset is in progress. If the process unmaps and frees a BO in that window, its pages are released while a queue can still access them through stale translations. On MI300X, munmap() then crashes in free_swap_cache() on a small bogus page pointer in its mmu_gather batch page: BUG: unable to handle page fault for address: 0000000000002900 RIP: 0010:free_swap_cache+0x5/0xb0 Call Trace: free_pages_and_swap_cache+0x3a/0x60 tlb_batch_pages_flush+0x43/0x80 tlb_flush_mmu+0x3d/0x110 zap_pte_range+0x80d/0xcd0 ... do_vmi_align_munmap+0x3e8/0x5b0 do_vmi_munmap+0xdf/0x190 __vm_munmap+0xad/0x180 __x64_sys_munmap+0x1b/0x30 In a traced crash the bogus pointer was the read pointer value of an SDMA queue the process had just destroyed, at the read pointer's page offset: the queue's writeback landed in its freed rptr page after the page was reused as the batch page. commit f0b4440cdc18 ("drm/amdkfd: Fix mode1 reset crash issue") fixed this race on process exit by waiting for the reset to complete before freeing the process's BOs. Free through the ioctl has the same race. Wait for the reset there too, using the same helper. Fixes: 9c33e5fd4fb6 ("drm/amdgpu: fix locking scope when flushing tlb") Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: William Palacek <William.Palacek@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 06ff8ce77726b15a98fcc285dd6005cb3f48558b) Cc: stable@vger.kernel.org
2026-10-20drm/amd/display: Fix swap in median3() for DSC rate controlKeita Morisaki
median3() is meant to return the median of three values, but its last compare-and-swap step swaps b and c instead of a and b. When c is smaller than both a and b, it returns max(a, b) instead of min(a, b). For example, median3(2, 3, 1) returns 3 instead of 2. _do_calc_rc_params() always passes 0 as the first argument, and the second argument is never below 12. So whenever the third argument is negative, first_line_bpg_offset (and second_line_bpg_offset for 4:2:0) is set to the second argument instead of 0. Fix this by swapping a and b in the last step, as intended. Note that this change does not affect valid DSC configurations. The third argument is negative only when bits per pixel exceeds the uncompressed rate of the colour format: - 3 * bpc for 4:4:4, 3 * bpc + 2 for RGB - 2 * bpc for 4:2:2 - 1.5 * bpc for 4:2:0 Fixes: 97bda0322b8a ("drm/amd/display: Add DSC support for Navi (v2)") Signed-off-by: Keita Morisaki <kmta1236@gmail.com> Tested-by: Dan Wheeler <daniel.wheeler@amd.com> Reviewed-by: Roman Li <roman.li@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 1ddc4bc97a62fc89d9d3681413d9f977e1fa1a83) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu/gmc9: add extra type-2 TLB flush for gfx942/gfx950Elena Sakhnovitch
Add extra type-2 TLB flush for GC 9.5.0, similar race condition was observed as Vega20+XGMI. Add to GC 9.4.3 and 9.4.4 too, as they share the same multi-XCD TLB topology. Reported-by: Shahzeb Ahmed <shahzeb.ahmed@amd.com> Reported-by: Manjunath Gaonkar <Manjunath.Gaonkar@amd.com> Signed-off-by: Elena Sakhnovitch <Elena.Sakhnovitch@amd.com> Reviewed-by: Apurv Mishra <apurv.mishra@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 138cfb165ae6aa98c0767b431e718d1a8199db28) Cc: stable@vger.kernel.org
2026-10-20drm/amdkfd: fix NULL deref in SDMA HQD debugfs dump on GC 12.1Harish Kasiviswanathan
Reading the KFD HQD debugfs node (dqm_debugfs_hqds) on a gc_12_1_0 part oopses with a NULL pointer dereference: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: hqd_sdma_dump_v12_1+0x6a [amdgpu] Call Trace: dqm_debugfs_hqds+0x2da/0x360 [amdgpu] kfd_debugfs_hqds_by_device+0x74/0xa0 [amdgpu] seq_read ... __x64_sys_read get_sdma_rlc_reg_offset() assumes an interleaved layout where the second SDMA per XCC lives in a separate SDMA1_HWIP register aperture. On gc_12_1_0 that aperture does not exist. Rewrite get_sdma_rlc_reg_offset() to mirror sdma_v7_1_get_reg_offset(): base the offset on adev->reg_offset[GC_HWIP][xcc_id][0] and add the per-instance SDMA1 offset for the odd instance. Fixes: 7bd5d763b8e1 ("drm/amdkfd: Add gfx_v12_1_kfd2kgd interface for GFX12_1") Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com> Reviewed-by: Mukul Joshi <mukul.joshi@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 94b2c5b06d37adc0e9a23138252758657b64b58a) Cc: stable@vger.kernel.org
2026-10-20drm/amdkfd: don't drop an SVM CWSR reference that was never takenJesse Zhang
When kfd_queue_acquire_buffers() fails, its error path calls kfd_queue_release_buffers(), which also drops a queue_refcount on the SVM range at ctx_save_restore_area_address. The SVM range is the last buffer acquired, and kfd_queue_buffer_svm_get() takes no reference when it fails, so on every error path this reference was never taken. If another queue of the process uses that CWSR range, its reference is dropped instead, and unmapping the range no longer evicts that queue while its CWSR area is unmapped from the GPU. On navi31, with queue A using an SVM CWSR range: munmap() of the range logs Freeing queue vital buffer 0x..., queue evicted but after a CREATE_QUEUE that reuses A's CWSR address with an unmapped write pointer (-EINVAL), the same munmap() leaves A running without the message. Only put the BOs on the acquire error path. The warning and the eviction are back after the failed CREATE_QUEUE. Fixes: b049504e211e ("drm/amdkfd: Validate user queue svm memory residency") Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 9a08122e6361ef73f4b512d5db9596d561305519) Cc: stable@vger.kernel.org
2026-10-20drm/amd/display: Adjust HDMI FRL LT timeoutIlya Bakoulin
[Why & How] Extend LT timeout for link rates <16G to avoid intermittent compliance failures. Reviewed-by: Relja Vojvodic <relja.vojvodic@amd.com> Reviewed-by: Chris Park <chris.park@amd.com> Signed-off-by: Ilya Bakoulin <Ilya.Bakoulin@amd.com> Signed-off-by: Ray Wu <ray.wu@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 378e096423269a466d23a5d5ce65051e8ef1e474)
2026-10-20drm/amd/pm: reapply umd profile state after recoveryKevin Wang
Resume and full GPU reset retain the selected UMD profile level in driver state. The GFX and PMFW state behind it is reinitialized. Add a generic DPM reapply path after CG and PG restoration. It restores the UMD GFX state and asks the PM backend to replay the retained level. v2: - Reapply only GFX CG to preserve the profile-owned GFX PG reference. - Fall back to AUTO when reapply fails without failing device recovery. - Propagate PowerPlay DPM errors before accepting AUTO fallback. - Limit workload-profile error reporting to the swSMU reapply path. This covers: - PCI runtime resume - Full GPU reset recovery - System resume, including S3 and s2idle Signed-off-by: Kevin Wang <kevin.wang@amd.com> Reviewed-by: Kenneth Feng <kenneth.feng@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit fd0699fc9f4266fc07d6ce6dbb484fac04601106) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu: reject ANONONLY userptrs that span multiple VMAsJesse Zhang
For AMDGPU_GEM_USERPTR_ANONONLY, amdgpu_ttm_tt_get_user_pages() only checks the VMA at the start of the range for a backing file, and amdgpu_hmm_range_get_pages() then faults in the whole range, across any other VMAs. The check used to reject ranges ending beyond the first VMA (vma->vm_end < end), which got lost when the code moved to HMM. An ANONONLY userptr over one page of file-backed memory is rejected with -EPERM, but one over an anonymous page followed by the same file-backed page is accepted. Restore the check and reject ANONONLY userptrs that cross more than one VMA. The second userptr is now rejected too. v2: reject ranges spanning multiple VMAs instead of walking every VMA (Christian) v3: cast num_pages to u64 to avoid an overflow (Christian) Fixes: 6826cb3b92a3 ("drm/amdgpu: support userptr cross VMAs case with HMM") Cc: Christian König <christian.koenig@amd.com> Cc: Philip Yang <Philip.Yang@amd.com> Cc: Felix Kuehling <Felix.Kuehling@amd.com> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Acked-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 75d753ed4704d5efc72164d9e546b2a282e42ae2) Cc: stable@vger.kernel.org
2026-10-20drm/amd/display: don't WARN when removing an unallocated MST payloadMario Limonciello
[Why] On an MST teardown that runs through the reset path (dcn31_reset_hw_ctx_wrap -> link_set_dpms_off -> deallocate_mst_payload), fill_dc_mst_payload_table_from_drm() is asked to remove a payload whose vcpi is not present in link->mst_stream_alloc_table and trips: WARNING: .../amdgpu_dm_helpers.c:275 fill_dc_mst_payload_table_from_drm This is a legitimate case, not an error: deallocate_mst_payload() can be called for a stream whose MST payload was never programmed into DC's HW-maintained table (a new stream created for a modeset whose enable never completed, as already documented in deallocate_mst_payload()). There is simply nothing to remove. [How] Drop the ASSERT and fall through to the fill loop, which rebuilds the allocation table from the remaining entries. The table ends up unchanged, which is correct: the payload being removed was never in it. Note the loop must not early-return here - the caller passes a zeroed proposed_table, so returning early would zero the whole link's table and drop the other MST streams sharing the link. Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/5875 Reviewed-by: Wayne Lin <wayne.lin@amd.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Ray Wu <ray.wu@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 88a27f624dc0ebc14a7ab274a84d977ce8513cb6) Cc: stable@vger.kernel.org
2026-10-20drm/amd/display: Fix HDMI FRL FFE compliance testIlya Bakoulin
[Why & How] The FFE electrical compliance test behavior is not correct. The driver doesn't properly iterate over the FFE levels and select PS/DE based on test request and/or cable-ID. Fix the initialization of the link state so that when the polling loop takes over, the test proceeds as described in the spec. Reviewed-by: Relja Vojvodic <relja.vojvodic@amd.com> Signed-off-by: Ilya Bakoulin <Ilya.Bakoulin@amd.com> Signed-off-by: Ray Wu <ray.wu@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 1903c3389c81bc65f57f0edeea879359d674bb33)
2026-10-20drm/amdkfd: fix doorbell allocation race creating duplicate allocationsHenry Martin
The check-and-allocate sequence on pdd->qpd.proc_doorbells is lockless at every call site of kfd_alloc_process_doorbells(): kfd_get_process_doorbells() (mmap of /dev/kfd), kfd_ioctl_create_queue() and the CRIU restore path each test the pointer under different locking (or none), so two racing threads can both observe NULL and each allocate a doorbell BO and bitmap, orphaning one allocation and handing the two mappings different backing pages. Move the serialization into kfd_alloc_process_doorbells() itself, using a new per-process-device mutex so all three call sites are covered regardless of their own locking. The device-global kfd->doorbell_mutex is not suitable here: it is acquired under dqm->lock on the kernel-doorbell path (start_cpsch() -> pm_init() -> kq_initialize() -> kfd_get_kernel_doorbell()), so holding it across the sleeping allocations above would create a lock-ordering inversion with dqm->lock via TTM eviction, and it would also serialize doorbell setup of unrelated processes behind a device-wide lock for per-process state. This issue was discovered by Tencent CodeBuddy Security. v3 (Felix Kuehling): - Removed unlocked check in kfd_get_process_doorbell flagged as problematic by Sashiko Bot. Fall back to the locked check inside kfd_alloc_process_doorbells - Added missing mutex_destroy v4 (Felix Kuehling): - Removed unlocked checks around other kfd_alloc_process_doorbells calls Fixes: 16f0013157bf ("drm/amdkfd: Allocate doorbells only when needed") Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com> Signed-off-by: Felix Kuehling <felix.kuehling@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 4e27ba5ad5f76932d4f6cbacd25c81c2dd40ec4a) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu: reset VI ASIC on Apple boards with VRAM at 0Maciej Kucharek
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. A later post (S3 resume, GPU reset) moves VRAM back to the VBIOS default. gmc_v8_0 reads MC_VM_FB_LOCATION once at init and reprograms it only on SR-IOV. On bare metal, the driver then keeps using the old layout. vi_reset_quirks[] handles this for the MacBookPro14,3 by PCI ID: commit b6b1d9721851 ("drm/amdgpu: reset VI ASIC on MacBookPro14,3") Add the test that SI and CIK use: an Apple subsystem vendor and VRAM at 0. Other Polaris MacBookPros then get the same reset at load, for example the MacBookPro13,3 if its firmware leaves VRAM at 0. These boards are not tested. Keep vi_reset_quirks[]. Its MacBookPro15,1 entries fix a different failure, a module reload after S3: commit a5be7ad8f5f0 ("drm/amdgpu: reset VI ASIC on MacBookPro15,1") VRAM is not at 0 at that point, so the new test may not cover it. After the reset, FB_BASE is not 0, so the new test does not fire again on a module reload. Only compile-tested. Suggested-by: Alex Deucher <alexander.deucher@amd.com> Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Maciej Kucharek <qchcio@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit c2335b685b1e1e387f2fea1c67f56b5b8a8b6dc6) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu: reset CIK ASIC on Apple boards with VRAM at 0Maciej Kucharek
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. A later post (S3 resume, GPU reset) moves VRAM back to the VBIOS default. The SI fix resets and posts the ASIC at load, so the driver uses the VBIOS layout from the start: "drm/amdgpu: reset SI ASIC on MacBookPros with VRAM at 0" No MacBookPro has a CIK GPU, and no affected CIK board is known. Add the same test to cik_need_reset_on_init(), so that SI, CIK and VI handle this firmware layout in the same way. gmc_v7_0 reads MC_VM_FB_LOCATION once at init and does not reprogram it. A CIK board with VRAM at 0 therefore has the same problem as the SI boards. After the reset, FB_BASE is not 0, so the new test does not fire again on a module reload. Only compile-tested. Suggested-by: Alex Deucher <alexander.deucher@amd.com> Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Maciej Kucharek <qchcio@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 6bb4b79d6a6c461b40750fd67cb4e2a070e20b67) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu: reset SI ASIC on MacBookPros with VRAM at 0Maciej Kucharek
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. The EFI stub enables the iGPU on these machines through apple_set_os(). On a MacBookPro11,5 (Radeon R9 M370X, 1002:6821, subsystem 106b:0149), the driver adopts this layout at init: MC_VM_FB_LOCATION=0x007f0000, HDP_NONSURFACE_BASE=0 VRAM at 0x0-0x7fffffff, GART table at 0x1400000 The driver posts the ASIC again on S3 resume and after a GPU reset. The VBIOS asic_init table then moves VRAM back to the VBIOS default: MC_VM_FB_LOCATION=0xf47ff400, HDP_NONSURFACE_BASE=0xf4000000 gmc_v6_0 does not reprogram these registers. The GART table is then no longer in VRAM, and the gfx ring test times out: amdgpu: ring gfx test failed (-110) amdgpu: resume of IP block <gfx_v6_0> failed -110 Reset and post the ASIC at driver load on Apple boards with VRAM at 0. The driver then uses the VBIOS layout (VRAM at 0xf400000000) from the start, and later posts keep it. After the reset, FB_BASE is not 0, so a module reload does not reset the ASIC again. The test is the same one that commit c54e4d105077 ("drm/amdgpu: make Mac FB workaround generic") uses: an Apple subsystem vendor and VRAM at 0. The VI quirk for the MacBookPro14,3 resets at load for the same reason: commit b6b1d9721851 ("drm/amdgpu: reset VI ASIC on MacBookPro14,3") Other Apple SI boards get the same reset if FB_BASE reads 0 at load. Tested on a MacBookPro11,5 with 7.2.5 and this patch: the panel comes up at boot, and 4 of 4 deep S3 cycles resume. Without the patch, S3 resume fails every time. The GPU reset path is not tested. Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/5978 Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Maciej Kucharek <qchcio@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 60dd16ae10f286cb9cce5b6027b2d5ee869637af) Cc: stable@vger.kernel.org
2026-10-20drm/amdgpu: require _PR3 for BOCOLuigi Lauro
amdgpu_device_supports_boco() returns true for an AMD_IS_PX device on a system with a hybrid ATPX method even when the device has no ACPI power resource (_PR3). On an APU mini PC with a discrete GPU attached over OCuLink, the iGPU's ATPX method reports hybrid graphics, the dGPU is flagged AMD_IS_PX, and runtime PM in auto mode picks BOCO: amdgpu: ATPX Hybrid Graphics amdgpu 0000:c6:00.0: Using BOCO for runtime pm In BOCO mode the driver leaves powering the device off to the PCI core, which can only do it through _PR3 on the upstream bridge. No device on this dGPU's path has _PR3, so when it runtime suspends the card stays powered, with its fans at about 700 rpm. Require has_pr3 for BOCO, as the function's description ("dGPU with ACPI power resources") says. The same card then picks BACO, which powers it down: amdgpu 0000:c6:00.0: Using BACO for runtime pm This only changes systems with a hybrid ATPX method and no _PR3 on the dGPU's upstream bridge, where BOCO cannot cut the power today. Tested on one such system only, an RX 9070 XT (Navi 48) over OCuLink with a Ryzen AI 9 HX 470, with the change backported to 7.2.9: the stock module logs "Using BOCO", the patched one "Using BACO"; BACO runtime suspend powers the card off and it resumes cleanly. Not tested on a hybrid laptop or a Thunderbolt eGPU. Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/5980 Assisted-by: Claude:claude-opus-5-5 Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Luigi Lauro <luigi.lauro@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 1a039805354a44aab7abb2a6e685212d48b17a5e) Cc: stable@vger.kernel.org
2026-10-20f2fs: zone: fix to don't fail to grab GC target block on zoned deviceChao Yu
With out-of-memory fault injection (inject_type=0x0080800f) on a zoned device, f2fs stopped checkpoint during GC: F2FS-fs (dm-0): inject kmalloc in f2fs_kmalloc of move_data_block+0xc0b/0x12b0 Workqueue: dm-1_zwplugs blk_zone_wplug_bio_work Call Trace: <TASK> dump_stack_lvl+0x4d/0x70 f2fs_stop_checkpoint+0x1df/0x5d0 f2fs_write_end_bio+0xdbb/0x1320 blk_zone_wplug_bio_work+0x2aa/0x7d0 process_one_work+0x5c6/0xde0 worker_thread+0x403/0xb70 kthread+0x235/0x2e0 ret_from_fork+0x2f/0x70 ret_from_fork_asm+0x1a/0x30 </TASK> F2FS-fs (dm-0): Stopped filesystem due to reason: 3 In move_data_block(), the target block is grabbed from the meta cache after f2fs_allocate_data_block() has allocated newaddr. If grabbing it fails w/ -ENOMEM, recover_block calls f2fs_do_replace_block() to restore the old block address and curseg's next_blkoff, which already points past newaddr, so newaddr is never written. That leaves a hole in a sequential zone: the next write to the zone is not at the write pointer, the zone write plug fails it, and f2fs_write_end_bio() stops checkpoint w/ STOP_CP_REASON_WRITE_FAIL. move_data_block() allocates newaddr before grabbing its meta page and goes to recover_block if the grab fails since commit 4356e48e6437 ("f2fs crypto: fix incorrect positioning for GCing encrypted data page"), the meta cache only replaced the meta page w/ a meta cache entry. That is harmless on a regular device, but it leaves the hole since f2fs supports host-managed SMR (now zoned block) devices, which only accept writes at the write pointer of a sequential zone. If newaddr is in a sequential zone, grab the target block w/ F2FS_CACHE_NOFAIL, so nothing can fail between allocating newaddr and writing it. In a conventional zone or on a regular device, skipping newaddr is harmless, so keep the error handling for them. Cc: stable@kernel.org Fixes: 52763a4b7a21 ("f2fs: detect host-managed SMR by feature flag") Fixes: d1b959c87702 ("f2fs: Check zoned block feature for host-managed zoned block devices") Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2026-10-20f2fs: don't use truncate_inode_pages_final() on live inodesDaeho Jeong
truncate_inode_pages_final() is meant to be called from ->evict_inode. It sets AS_EXITING on the mapping, and nothing ever clears it, to tell the VM that the inode is going away. f2fs calls it in two places where the inode stays live: - F2FS_IOC_START_ATOMIC_REPLACE uses it to drop the page cache of the original inode before setting i_size to 0. The atomic write then goes on through this inode. - f2fs_abort_atomic_write() uses it to drop the uncommitted data. It is called on eviction, but also on the last writer's close in f2fs_release_file(), from f2fs_file_flush() when the atomic writer exits, from F2FS_IOC_ABORT_ATOMIC_WRITE and when F2FS_IOC_COMMIT_ATOMIC_WRITE fails. Other processes may still have the file open or mapped in all of these cases. The mapping then stays marked as exiting for as long as the inode is in memory. This stops reclaim from storing workingset shadow entries for it and breaks any code that assumes an exiting mapping has no users left. All we need in both places is to drop the page cache, so use truncate_inode_pages(mapping, 0) instead. The eviction path is not affected, because f2fs_pre_evict_inode() still calls truncate_inode_pages_final() after f2fs_abort_atomic_write(). Cc: stable@kernel.org Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Fixes: 41e8f85a75fc ("f2fs: introduce F2FS_IOC_START_ATOMIC_REPLACE") Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2026-10-20f2fs: expose resizable_tail feature via sysfsDaeho Jeong
Userspace has no way to know whether the kernel supports the resizable_tail_secno mount option before mounting. Passing it to a kernel without the support fails the mount with -EINVAL, and checking /sys/fs/f2fs/<disk>/pinned_area_max_secno requires an f2fs instance to be mounted already. Export /sys/fs/f2fs/features/resizable_tail so that userspace can check the support before formatting or mounting a filesystem that relies on resizable_tail_secno, e.g. a filesystem whose tail is going to be shrunk online later. Cc: stable@vger.kernel.org Fixes: c966d29e01bb ("f2fs: support resizable tail section and unify pinned allocation") Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2026-10-20f2fs: use BIT_ULL for mount option bitmasksDaeho Jeong
Although f2fs_mount_info.opt and f2fs_fs_context.opt_mask are declared as unsigned long long (64 bits), the option bit manipulation macros (clear_opt, set_opt, test_opt) and context helpers (ctx_set_opt, ctx_clear_opt, ctx_test_opt) use BIT(), which expands to (UL(1) << nr). On 32-bit architectures, sizeof(unsigned long) is 32 bits, causing shift count overflow warnings and functional truncation if mount option indices reach or exceed 32. Replace BIT() with BIT_ULL() for mount option bitmasks and helpers. Additionally, introduce ctx_clear_opt_mask() and ctx_test_opt_mask() helpers to avoid open-coded bitwise manipulations on ctx->opt_mask. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202609111633.uyRbsEUB-lkp@intel.com/ Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2026-10-20keys/trusted_keys: reuse TPM version in option handlingSrish Srinivasan
Determine the TPM version once in the seal and unseal paths, and reuse it when allocating and parsing trusted key options. This reduces the number of fallible calls to tpm_is_tpm2() and avoids unnecessary I/O between the kernel and the TPM. Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/20261005062732.140733-1-ssrish@linux.ibm.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20security: keys: Fix comment of search_process_keyrings_rcu()Thomas Huth
search_my_process_keyrings() has been renamed to search_cred_keyrings_rcu() in commit e59428f721ee ("keys: Move the RCU locks outwards from the keyring search functions"), but one spot has been missed in a comment. Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Jinjie Ruan <ruanjinjie@huawei.com> Link: https://lore.kernel.org/r/20260928072024.91664-1-thuth@redhat.com Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys/trusted/tpm2: Validate TPM2_Create object sizes separatelySrish Srinivasan
TPM2_Create returns outPrivate, outPublic, creationData, creationHash and creationTicket in its response parameter area. However, only outPrivate and outPublic are included in the trusted key blob. The size of the blob is therefore not determined by the size of the complete response parameter area. tpm2_seal_trusted() currently compares the size of the complete response parameter area against MAX_BLOB_SIZE. This can reject a valid response when the remaining response outputs cause the entire response parameter area to exceed MAX_BLOB_SIZE, even though the outPrivate and outPublic TPM2B structures consumed by tpm2_key_encode() remain small enough to be encoded in the key blob. This is observed when creating larger trusted keys using the swtpm TPM 2.0 emulator backed by libtpms. For example, requesting a 113-byte key succeeds, 114 fails. ~$ keyctl add trusted trusted_key1 "new 113 keyhandle=0x81000001" @u 520504613 ~$ keyctl add trusted trusted_key2 "new 114 keyhandle=0x81000001" @u add_key: Argument list too long ~$ Remove the MAX_BLOB_SIZE check on the complete response parameter area. Instead, use the response length passed to tpm2_key_encode() to validate that the outPrivate and outPublic TPM2B structures are fully contained in the response before accessing them. Previously, a response parameter area larger than MAX_BLOB_SIZE was rejected with -E2BIG before ASN.1 encoding. With this change, if the resulting encoded blob does not fit in payload->blob, the error returned by asn1_encode_sequence() is propagated instead. Also, use scope-based cleanup to simplify resource management. Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com> Link: https://lore.kernel.org/r/20260926184203.479203-1-ssrish@linux.ibm.com Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys/trusted_keys: move TPM-specific fields into struct trusted_key_tpmSrish Srinivasan
The trusted_key_options struct contains TPM-specific fields (keyhandle, keyauth, blobauth_len, blobauth, pcrinfo_len, pcrinfo, pcrlock, hash, policydigest_len, policydigest, and policyhandle). This leads to the accumulation of backend-specific fields in the generic options structure. Define struct trusted_key_tpm and move the TPM-specific fields there. Store a pointer to it in the private member of struct trusted_key_options. Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/20260912062950.279104-3-ssrish@linux.ibm.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: Protect the read method check against type removalCen Zhang
keyctl_read_key() checks key->type->read without holding key->sem. A reference keeps the key alive, but does not pin the module containing its type. A surviving RxRPC key can therefore be read while AF_RXRPC is being unloaded: KEYCTL_READ task Module unload and key GC ---------------- ------------------------ lookup_user_key() permission / possession checks load key->type af_rxrpc_exit() unregister_key_type() GC: down_write(key->sem) GC: retype to key_type_dead GC: up_write(key->sem) unregister_key_type() returns free_module() read saved type's read member The final access can read freed module storage. The read invocation in __keyctl_read_key() is already protected by key->sem, but the earlier method check is outside that critical section. Move the method check into __keyctl_read_key(), after key_validate() and under its existing read hold on key->sem. The check and invocation then use the same protected type for length queries and every read retry. The GC cannot retype the key until the semaphore is released, and type unregistration waits for that GC pass before the module can be freed. Return -EOPNOTSUPP when validation succeeds and the type has no read method. A temporary buffer may now be allocated before this result; allocation and copying to userspace remain outside the semaphore. Assisted-by: LLM Cc: stable@vger.kernel.org # v5.10+ Fixes: d3ec10aa9581 ("KEYS: Don't write out to userspace while holding key semaphore") Suggested-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Reviewed-by: David Howells <dhowells@redhat.com> Link: https://lore.kernel.org/r/pm-key-management-objects-candidate-0010-v7-fc85721ff5cfb9e33ac6@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: Avoid owner account dereferences in /proc/keysCen Zhang
The namespace filters in find_ge_key() and key_serial_next() read key->user->uid while traversing the serial tree under key_serial_lock. That lock keeps the key allocated, but it does not protect the separate key_user from ownership changes. A /proc/keys read reaches find_ge_key() through proc_keys_start(), and key_serial_next() through proc_keys_next(). The lock stays held until proc_keys_stop(). A successful privileged KEYCTL_CHOWN on the same key replaces key->user under key->sem and drops the old owner's reference after releasing the semaphore. If that was the old dynamic key_user's last reference, a /proc/keys reader can access freed memory: /proc/keys reader KEYCTL_CHOWN proc_keys_start() keyctl_chown_key() spin_lock(key_serial_lock) down_write(key->sem) find_ge_key() old = minkey->user zapowner = key->user key->user = newowner key->uid = uid up_write(key->sem) key_put(key) key_user_put(zapowner) kfree(zapowner) read old->uid -> use-after-free proc_keys_stop() spin_unlock(key_serial_lock) Use the inline key->uid in both filters, following the approach already used by find_keyring_by_name(). The serial-tree lock keeps the containing key alive, so filtering no longer depends on the quota owner's lifetime. This also uses the same owner UID as proc_keys_show() and the permission check. For thread keyrings, key_fsuid_changed() can update key->uid without changing the quota owner. The filters now follow that current owner UID, including when its namespace mapping differs from the quota owner's. Fixes: 454804ab0302 ("keys: make procfiles per-user-namespace") Assisted-by: LLM Suggested-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/pm-keys-proc-owner-uid-followup-20261017-v2-8f8f34a41eb1bbb94ef0@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: make keyring indexes independent of kernel addressesKyle Zeng
KEYCTL_READ returns the serial numbers in a keyring in associative-array traversal order. The first word of the index is a public, deterministic hash of the type pointer, domain pointer and description. An unprivileged user can therefore insert keys with known descriptions, predict their order for each possible KASLR slide, and recover the kernel image address. On an x86-64 build with 16 MiB alignment, 45 user keys suffice to distinguish the candidate slides. Remove the addresses from the whole index, not just its first hash word. Assign each key type and domain a nonzero 64-bit ID and hash those IDs and the description with a once-initialized SipHash key. Use the full IDs in the later index chunks as well. Truncating or hashing the IDs there would lose the guarantee that distinct type/domain/description tuples have a differing index bit. Allocate IDs lazily since private key types need not be registered. Cache them in the index key so tree walks and copies of an existing index do not need to dereference a type descriptor that may have been unregistered. Keep the 32-bit chunk layout and diff_objects() bit offsets consistent, and retain the separate root slot for keyrings used by recursive search. The key comparison, permissions and userspace data format are unchanged; only the address-dependent in-memory ordering is replaced. Cc: stable@vger.kernel.org Fixes: b2a4df200d57 ("KEYS: Expand the capacity of a keyring") Assisted-by: Codex:gpt-6-astra Signed-off-by: Kyle Zeng <kylebot@openai.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/20261013231251.56170-1-kylebot@openai.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: Check the authorization payload in process keyring searchesCen Zhang
An authorization payload and its saved credentials must remain valid while search_process_keyrings_rcu() searches the requestor's keyrings. The function validates the authorization key, then separately loads payload.data[0] and unconditionally reads rka->cred. Validation does not prevent request_key_auth_revoke() from clearing the payload. A request-key helper can assume authority and fork a descendant that inherits the authorization key. If the descendant misses in its own keyrings, it falls back to the saved requestor credentials. Successful target instantiation invalidates the authorization key without clearing the payload. After the helper exits, UMH_WAIT_PROC returns to the requester, which calls complete_request_key() and revokes that key. With the descendant paused after validation, the paths can interleave as follows: 1. The descendant enters search_process_keyrings_rcu() under RCU and key_validate() succeeds. 2. The helper instantiates the target, invalidates the authorization key, and exits. 3. The requester resumes from UMH_WAIT_PROC, calls complete_request_key(), and revokes the authorization key. request_key_auth_revoke() sets its payload pointer to NULL. 4. The descendant loads NULL and dereferences rka->cred. This NULL dereference can oops the kernel. RCU delays payload disposal but does not prevent the pointer from being cleared. Load the payload with dereference_key_rcu() and require a non-NULL result before validating the authorization key and searching its saved credentials. A non-NULL payload and its credentials remain alive for the caller's RCU read-side section; a cleared payload skips the fallback search and follows the existing error selection. KASAN report as below: Oops: general protection fault, probably for non-canonical address 0xdffffc0000000005: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f] RIP: 0010:search_process_keyrings_rcu+0x32b/0x790 Cc: stable@vger.kernel.org Fixes: e59428f721ee ("keys: Move the RCU locks outwards from the keyring search functions") Assisted-by: LLM Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/pm-key-management-objects-candidate-0004-v3-598361863b76bc25d58d@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: Avoid the owner account dereference in named keyring lookupCen Zhang
Named keyring lookup must keep the storage containing the owner UID alive through the namespace mapping check. find_keyring_by_name() reads keyring->user->uid under keyring_name_lock, but that lock protects the keyring's name entry and allocation, not its separate key_user. A named session-keyring join can overlap a privileged KEYCTL_CHOWN on another CPU. If the keyring holds the last reference to its old dynamic key_user and the ownership transfer succeeds, the following ordering is possible: Named join Chown find_keyring_by_name() keyctl_chown_key() read_lock(keyring_name_lock) down_write(key->sem) load old keyring->user replace key->user and key->uid up_write(key->sem) key_put(key) key_user_put(old user): free read old user->uid read_unlock(keyring_name_lock) Chown neither takes keyring_name_lock nor key_session_mutex, so it can free the old account between the pointer load and the UID read. The lookup then reads freed memory even though the keyring itself is alive. Use keyring->uid for the mapping check. key_alloc() initializes this inline owner UID and keyctl_chown_key() updates it on chown. The existing name lock keeps its containing keyring allocated throughout the check, so lookup no longer depends on the account's lifetime. This also matches the owner UID used by the permission check. KASAN report as below: BUG: KASAN: slab-use-after-free in find_keyring_by_name+0x577/0x5d0 Read of size 4 at addr ffff8881128ae2ec by task keycase/500 Cc: stable@vger.kernel.org Fixes: 2ea190d0a006 ("keys: skip keys from another user namespace") Assisted-by: LLM Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/pm-key-management-objects-candidate-0002-v3-2baa8cad2bb554364e10@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20keys: Protect the type name while describing a keyCen Zhang
keyctl_describe_key() must keep the key type's name alive until kasprintf() has consumed it. The retained key reference keeps the key and its description alive, but does not pin the module providing its type. The name is passed to kasprintf() without holding key->sem. kvasprintf() uses the saved name pointer in two formatting passes, with a GFP_KERNEL allocation between them. With AF_RXRPC=m, a task that passes View permission before type retirement can overlap a privileged module unload in this order: 1. KEYCTL_DESCRIBE looks up the key, saves key->type->name in the kasprintf() arguments and completes the first formatting pass. 2. While the formatter is delayed before its second pass, af_rxrpc_exit() calls unregister_key_type(), which removes the type from the registry and waits for key_gc_keytype(). 3. The collector takes key->sem for writing, retypes the retained key to key_type_dead and completes retirement. Unregistration and module exit return, allowing free_module() to release the type and name. 4. The formatter resumes its second pass and reads the saved name from released module storage, which can fault in string(). Hold key->sem for reading across kasprintf(). The collector then cannot retype the key or complete retirement until both formatting passes have finished. If retirement wins the lock first, formatting uses the core key_type_dead name instead. Release the semaphore immediately after kasprintf(), including on allocation failure, before copying to userspace. Oops report as below: BUG: unable to handle page fault for address: fffffbfff8054794 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page RIP: 0010:string+0x23f/0x470 Call Trace: vsnprintf+0x330/0x1110 Cc: stable@vger.kernel.org Fixes: aa9d4437893f ("KEYS: Fix the size of the key description passed to/from userspace") Assisted-by: LLM Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Link: https://lore.kernel.org/r/pm-key-management-objects-candidate-0009-v4-6b537c5732fd957c33fa@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20KEYS: Fix key_reject_and_link() race with keyring restrictionAdrian Martinez
The restrict_link check in key_reject_and_link() is done before taking the keyring semaphore, racing with a concurrent keyring_restrict() that installs the restriction while holding the semaphore in write mode. Move the check to after __key_link_lock(), so it is done under the semaphore, matching the pattern used in __key_create_or_update(). Cc: stable@vger.kernel.org Fixes: 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring") Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Adrian Martinez <adrimg3196@gmail.com> Link: https://lore.kernel.org/r/CACO1+RT+m==BY+ZPkE+fo536D0qu3wog4xE1dfuXQ56g+=Qv=A@mail.gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2026-10-20ASoC: cs35l56: Wait for firmware timer expiry before system suspendRichard Fitzgerald
On CS35L5x firmware older than 3.13.7 (B0 silicon) and 4.7.16 (B2 silicon) a SoundWire bus reset is not allowed within 250ms of the last firmware timer start. This is already avoided during runtime suspend by the various idle timeouts. System suspend can happen at any time so needs special protection. The driver cannot cancel the firmware timer, so it must wait long enough for the timer to expire. The delay is placed in the suspend stage because typically this has less impact on end users than delays in resuming. The amp is in PS3 power state when suspending and no new timers will be started in this state. An extra 10ms is added to the delay to avoid a race on the exact instant the firmware timer expires. There is no need to have the delay for every driver instance. The timers on each amp will expire in parallel, so the delay is only needed once. A global flag is used so that the first instance to reach its suspend() callback will delay and then clear the flag. The cs35l56_fw_idle_wait_lock mutex is to ensure this is still safe if async_suspend was ever enabled for SoundWire devices. Fixes: e496112529006 ("ASoC: cs35l56: Add driver for Cirrus Logic CS35L56") Reported-by: Ferenc Lengyel <leferi99@gmail.com> Closes: https://github.com/thesofproject/linux/issues/5898 Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20261020135706.3573260-1-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
2026-10-20landlock: Fix superblock use-after-free in release_inode()Günther Noack
Without this fix, release_inode() (task 1) can race with a umount operation in hook_sb_delete() (task 2). The order of operations in which the race occurs is: * task 2: hook_sb_delete() arrives at the end of the function, waiting for landlock_superblock(sb)->inode_refs to become zero. * task 1: release_inode(): does atomic_long_dec_and_test(), decrementing inode_refs to zero. * task 2: gets woken up through some other means, sees that inode_refs is zero and returns. The caller is the unmount operation and proceeds to release the superblock. * task 1: Runs wake_up_var(&landlock_superblock(sb)->inode_refs), *dereferencing the sb_security on the freed-up superblock*. Notably, wake_up_var() does not dereference the pointer passed to it, and only uses it to determine an overapproximated set of tasks to wake up. So while it's potentially possible for an attacker to provide a different value for that pointer, this only results in the wrong set of tasks getting woken up, and in this scenario, no further tasks are actually waiting. Nevertheless, KASAN detects it as a slab-use-after-free read on sb->s_security: BUG: KASAN: slab-use-after-free in release_inode+0x196/0x290 Read of size 8 at addr ffff888103b6c0a8 by task repro/217 release_inode+0x196/0x290 landlock_put_object+0x71/0x90 landlock_free_rules+0x38/0xc0 landlock_put_ruleset+0x47/0x130 fop_ruleset_release+0x33/0x40 __fput+0x305/0x780 Freed by task 54: kfree+0x11c/0x390 process_scheduled_works+0x766/0xe50 worker_thread+0x7bc/0xb20 The fix is to determine &landlock_superblock(inode->i_sb)->inode_refs only once earlier in release_inode(), and later use that precalculated address for the wake_up_var() call, without having to dereference through the superblock. Cc: stable@vger.kernel.org Fixes: cb2c7d1a1776 ("landlock: Support filesystem access-control") Assisted-by: LLM Signed-off-by: Günther Noack <gnoack@google.com> Link: https://patch.msgid.link/20261006105847.2541190-1-gnoack@google.com Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20selftests/landlock: Fix snprintf truncation checks in test filesWang Yan
Commit b566f7a4f0e4 ("selftests/landlock: Fix snprintf truncation checks in audit helpers") fixed the truncation detection in audit.h by changing the comparison from ">" to ">=" to correctly handle the edge case where snprintf returns a value equal to the buffer size. However, the same pattern exists in ptrace_test.c, audit_test.c, and net_test.c and was not fixed. snprintf() returns the number of characters that would have been written, excluding the terminating NUL byte. When the output is truncated, this return value equals or exceeds the buffer size. The existing ">" check therefore fails to detect truncation when the return value equals the buffer size. Fix these remaining instances to use ">=" for truncation detection, matching the fix in audit.h. Fixes: 6a500b22971c ("selftests/landlock: Add tests for audit flags and domain IDs") Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn> Signed-off-by: Wang Yan <wangyan01@kylinos.cn> Reviewed-by: Günther Noack <gnoack@google.com> Link: https://patch.msgid.link/20260626070016.61049-1-wangyan01@kylinos.cn Cc: stable@vger.kernel.org Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20landlock: Add documentation for capability and namespace restrictionsMickaël Salaün
Document the two new Landlock permission categories, introduced with ABI 12, in the userspace API guide, admin guide, trace-event guide, UAPI comments, and kernel security documentation. The kernel security documentation generalizes the existing per-object access-rights framing into three restriction models (handled_access_*, handled_permissions, scoped) and states criteria for choosing among them, so future permission or scope additions have a documented place to land. Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-9-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20samples/landlock: Add capability and namespace restriction supportMickaël Salaün
Extend the sandboxer sample to demonstrate the new Landlock capability and namespace restriction features. LL_CAP takes a colon-delimited list of allowed capabilities. Numeric values are always accepted; when libcap development files are available, use cap_from_name(3) to accept names too. Builds without libcap warn when capability settings are used. This keeps the sample buildable without optional development files. LL_NS takes a colon-delimited list of allowed namespace types by short name. Add best-effort degradation for older kernels that predate the LANDLOCK_PERMISSION_* features. Allow creating user and UTS namespaces but deny network namespaces, as an unprivileged user. The first command succeeds and sets the hostname inside the new UTS namespace; the second is denied because the network namespace type is not allowed: LL_FS_RO=/ LL_FS_RW=/proc LL_NS="user:uts" \ ./sandboxer /bin/sh -c \ "unshare --user --uts --map-root-user hostname sandbox \ && ! unshare --user --net true" Allow only user namespace creation and CAP_SYS_CHROOT, denying all other capabilities and namespace types. An unprivileged process creates a user namespace, which requires no capability, and calls chroot inside it using the CAP_SYS_CHROOT granted within that namespace: LL_FS_RO=/ LL_FS_RW="" LL_NS="user" LL_CAP="cap_sys_chroot" \ ./sandboxer /bin/sh -c \ "unshare --user --keep-caps chroot / true" Allow user namespace creation but deny network namespaces, and quiet the network-namespace denials with LL_NS_QUIET so the denied creation is not audit logged. The negated second command makes the whole line succeed: LL_FS_RO=/ LL_FS_RW=/proc LL_NS="user" LL_NS_QUIET="net" \ ./sandboxer /bin/sh -c \ "unshare --user --map-root-user true && ! unshare --user --net true" Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Cc: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20261014082718.1435842-8-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20selftests/landlock: Add capability restriction testsMickaël Salaün
Add tests to exercise LANDLOCK_PERMISSION_CAPABILITY_USE enforcement. A sandboxed process is denied a handled capability when no rule grants it, and an explicit rule restores it. Unknown capability values above CAP_LAST_CAP are accepted at rule-add time yet have no runtime effect, because deny-by-default still applies once the domain is enforced. Stacking tests cover the per-layer allow/deny combinations, including a layer that does not handle the permission, and invalid rule attributes return the expected errors. Three tests exercise non-standard capability contexts: enforcing a domain via CAP_SYS_ADMIN authorization without no_new_privs, restricting capabilities gained through the kernel's user namespace ownership bypass (cap_capable_helper), and checking CAP_SYS_ADMIN against a descendant user namespace, with an unsandboxed positive control, to confirm the decision is independent of the target. Audit tests verify denied and allowed capabilities, per-member quiet interactions, and CAP_OPT_NOAUDIT suppression. Trace tests cover accepted, rejected, and no-op rule adds, and normal, quiet, and CAP_OPT_NOAUDIT denials. Test coverage for security/landlock is 91.8% of 2864 lines according to LLVM 22. Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-7-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20selftests/landlock: Add namespace restriction testsMickaël Salaün
Add tests covering LANDLOCK_PERMISSION_NAMESPACE_USE (namespace creation via unshare/clone and namespace entry via setns) and its interaction with LANDLOCK_PERMISSION_CAPABILITY_USE. Rule validation covers the forward-compatibility contract: unknown CLONE_NEW* bits, including holes, upper-range bits and bit 63, are accepted at rule-add time yet have no runtime effect, because deny-by-default still applies once the domain is enforced. Empty masks, invalid permission selectors and non-zero flags are rejected. Creation tests use FIXTURE_VARIANT to exercise all eight namespace types across allowed/denied and privileged/unprivileged combinations, so every type is shown to reach security_namespace_init(). Stacking tests cover the three per-layer allow/deny combinations that exercise distinct walker paths, and one domain handles both permissions at once. Entry tests subject setns to the same type-based check through security_namespace_install(), across processes, and require both permissions to allow a non-user namespace. The four open_tree(2) and fsmount(2) variants, anonymous and not, all create a mount namespace: they converge in security_namespace_init() with CLONE_NEWNS through different alloc_mnt_ns() paths. A CLONE_NEWUSER | CLONE_NEWUTS unshare under partial-allow rules shows that creation is sequential, so a denial on either type rolls the whole syscall back with EPERM. Audit tests cover allowed and denied creation and entry, per-member quiet masks and the youngest-denying-layer rule. Trace tests cover handled permissions, successful and rejected rules, version history, namespace IDs, and quiet denials, including repeated and unknown-only effective no-ops. Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-6-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20landlock: Enforce capability restrictionsMickaël Salaün
Add Landlock enforcement for capability use via the LSM capable hook. This lets a sandboxed process restrict which Linux capabilities it can exercise, using LANDLOCK_PERMISSION_CAPABILITY_USE and per-capability rules. The check is a flat per-layer allowed-capabilities test, with no domain-ancestry bypass, no cross-namespace discriminant, and no dependency on the target user namespace. These categorical denials return -EPERM, like the namespace permission introduced by the previous commit, and they mirror its per-capability allowed and quiet masks, so LANDLOCK_ADD_RULE_QUIET stays rejected for this rule type. Successful capability rules and denials are traced as the previous commit describes. Enforce only at capability exercise time rather than modifying the credential's capability sets. Modifying them would give capget(2) an accurate view of usable capabilities, but no LSM other than commoncap does so; Landlock follows that convention. A sandboxed process inside a user namespace therefore sees all capabilities via capget(2) but receives -EPERM when attempting to use one that is denied. An earlier design bypassed this hook for namespace management through a domain-ancestry comparison with the namespace creator's stored Landlock domain. That made a Landlock decision depend on kernel namespace state, and the ns != cred->user_ns heuristic did not accurately identify namespace-management operations. The flat, namespace-agnostic check instead enforces capability and namespace restrictions independently; creating a non-user namespace requires an allowed CAP_SYS_ADMIN even when combined with CLONE_NEWUSER in one unshare(). Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-5-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20landlock: Enforce namespace use restrictionsMickaël Salaün
Add Landlock enforcement for namespace use through the LSM namespace_init and namespace_install hooks. This lets a sandboxed process restrict which namespace types it can create, join, or acquire a file descriptor for, using LANDLOCK_PERMISSION_NAMESPACE_USE and per-type rules. Introduce the handled_permissions field in struct landlock_ruleset_attr: each permission gates every use of a kernel-defined category (CLONE_NEW* namespace types, CAP_* capabilities) with complete deny-by-default coverage, so unknown member values need no validation, being denied until a rule allows them. This UAPI extension advances the Landlock ABI from 11 to 12. There is no domain-ancestry bypass and no namespace-creator tracking, only a flat per-layer allowed-types bitmask: hook_namespace_init() covers creation through clone(2), unshare(2), open_tree(2) and fsmount(2), and hook_namespace_install() covers setns(2). Each permission hook maps its member mask explicitly in the shared permission walker, which warns and denies if a future caller omits that mapping. These categorical denials return -EPERM, matching Landlock's scope and mount-topology denials rather than its object-access -EACCES convention. struct permission_masks is forced to eight bytes with __packed and __aligned because it must eventually hold both the eight namespace types and all capabilities, and because m68k GCC otherwise packs its u64 bitfields at byte granularity, making the structure smaller than sizeof(u64). Carrying it grows struct layer_config from 4 to 16 bytes, so the largest 16-entry domain FAM grows from 64 to 256 bytes. The permissions selector keeps the rule attribute self-describing: - User space can mask it against handled_permissions, as it masks allowed_access against handled_access_fs, so a program built against newer headers still adds the rules an older kernel supports. - It tells apart two attributes that share the same three-u64 layout. Unknown member bits are ignored, so without it a mismatched rule type would apply a capability mask as namespace types. - It leaves room for a rule to carry several permissions, or for another rule type to key the same permission differently. The rule also carries a quiet_namespace_types bitmask that suppresses audit submission for denied members without granting them. A sandbox knowingly running a caller that probes a type it will never be granted would otherwise flood the audit log and drown the surprising denials that matter. Quiet is per-member rather than a coarse per-category ruleset bit, so a sandbox can silence CLONE_NEWNET while still auditing CLONE_NEWUTS; making it the complement of the allowed set would be broad, could not audit a member that is neither allowed nor explicitly quieted, and would auto-hide members added by future kernels. It is a per-rule bitmask rather than the LANDLOCK_ADD_RULE_QUIET flag and the ruleset quiet_access_* masks, which suit the unbounded rb-tree objects of filesystem and network rules, so that flag is rejected here. Only the youngest denying layer's quiet mask decides, so a parent cannot silence a denial made by a deeper layer. Trace the handled permission mask, every successful namespace rule, and namespace denials. Successful effective no-ops advance the version, and quiet denials remain trace-visible with logged=0. The denial event takes the blockers argument of the filesystem and network events and records the same blockers_type and blockers_access fields, so one filter expression spans the mask-bearing denial events. Handled and rule permission masks may contain permissions from multiple domains in one field, so their names are domain-qualified, such as namespace.use. A blocker is already interpreted in the domain supplied by the audit prefix or denial event, so it retains the bare action name use, matching existing access blockers such as read_file. User namespace creation does not require capabilities, so Landlock can restrict it directly. Non-user namespace types require CAP_SYS_ADMIN before the Landlock check is reached; when the capability permission added by the next commit is also handled, both must allow the operation. Cc: Christian Brauner <brauner@kernel.org> Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Link: https://patch.msgid.link/20261014082718.1435842-4-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20landlock: Wrap per-layer access masks in struct layer_configMickaël Salaün
The domain layer FAM stores struct access_masks values directly, while a ruleset stores the equivalent single mutable value. Per-category permissions need additional per-layer data beyond the handled-access bitfields. Introduce struct layer_config as the common value type. Keeping the handled bitfields in its .handled member leaves struct access_masks as a lightweight parameter type for functions that only need those bitfields, while the complete layer can be snapshotted with one assignment. At this point struct layer_config only wraps the four-byte access_masks, so it does not grow the per-domain allocation: the maximum 16-entry FAM remains 64 bytes. No functional change. Cc: Günther Noack <gnoack@google.com> Reviewed-by: Günther Noack <gnoack@google.com> Reviewed-by: Tingmao Wang <m@maowtm.org> Link: https://patch.msgid.link/20261014082718.1435842-3-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20landlock: Rename quiet_masks to quiet_accessMickaël Salaün
The base stores the fs/net/scope quiet bitmasks in a struct access_masks field named quiet_masks. A following commit adds the sibling struct permission_masks field quiet_permission for capabilities and namespaces. quiet_masks drops the access category and keeps the type half ("masks"), while quiet_permission keeps the category and drops the type half, so the two read as an inconsistent pair. Rename the base field to quiet_access, giving the symmetric, category-named pair quiet_access/quiet_permission that also matches the UAPI handled_access_*/quiet_access_* naming. This is a no-functional-change rename. Cc: Günther Noack <gnoack@google.com> Cc: Tingmao Wang <m@maowtm.org> Reviewed-by: Tingmao Wang <m@maowtm.org> Reviewed-by: Günther Noack <gnoack3000@gmail.com> Link: https://patch.msgid.link/20261014082718.1435842-2-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-20Merge remote-tracking branch 'torvalds/master' into perf-tools-nextArnaldo Carvalho de Melo
First merge in the window to do a first batch of header syncs and check integration with libbpf, etc. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-10-20blk-mq: clear stale inactive flag on hctx reuseNirmoy Das
When the last CPU mapped to an hctx goes offline, blk_mq_hctx_notify_offline() sets BLK_MQ_S_INACTIVE. Updating the number of hardware queues exits every hctx and parks it on q->unused_hctx_list. A later update can reuse a parked hctx through blk_mq_alloc_and_init_hctx(), at any queue index, and nothing clears the flag. If the reused hctx is mapped to an online CPU, blk_mq_get_tag() keeps returning BLK_MQ_NO_TAG for it. __blk_mq_alloc_requests() sleeps and retries, expecting CPU hotplug to move the task to another CPU, so a task that stays on that CPU never gets a tag. Onlining the original CPU doesn't recover it either, because blk_mq_hctx_notify_online() only clears the flag on the hctx that CPU now maps to. Clear BLK_MQ_S_INACTIVE in blk_mq_init_hctx() so a reused hctx starts like a freshly allocated one. A reused hctx has no cpuhp instances at that point, so the offline callback can't set the flag again before blk_mq_add_hw_queues_cpuhp() registers it. Clearing the flag in blk_mq_exit_hctx() is not enough, because a parked hctx keeps its cpuhp instances until blk_mq_remove_hw_queues_cpuhp(). Preserve the other hctx state flags. Reproduced with null_blk on v7.3 in a four-vCPU arm64 QEMU/KVM guest: modprobe null_blk nr_devices=0 mkdir /sys/kernel/config/nullb/nullb0 cd /sys/kernel/config/nullb/nullb0 echo 4 > submit_queues; echo 1 > memory_backed; echo 16 > size echo 1 > power echo 0 > /sys/devices/system/cpu/cpu3/online echo 2 > submit_queues echo 4 > submit_queues Offlining CPU3 marks hctx3 inactive. After the two updates it comes back as hctx1 and is mapped to CPU0: # cat /sys/block/nullb0/mq/1/cpu_list 0 # cat /sys/kernel/debug/block/nullb0/hctx1/state INACTIVE A 4K O_DIRECT read pinned to CPU0 hangs in D state, while the same read on CPU1 and CPU2 completes. Onlining CPU3 again leaves hctx1 inactive and the CPU0 read still hangs. With this change hctx1 state is empty and the reads on CPU0, CPU1 and CPU2 complete, before and after onlining CPU3. Fixes: bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com> Link: https://patch.msgid.link/20261020125129.430600-1-nirmoyd@nvidia.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-10-20io_uring: end the drain when the drain request completesJens Axboe
Since requests are drained based on allocated requests, the drain stays active after the drain request has posted its CQE, until it is freed and a new request finds the defer list empty. A drain request run by io-wq is freed only after the worker drops its reference, so a request submitted after the drain completed can still be deferred behind it, and get issued much later than the application expects. A drain request dispatched from the defer list runs alone. Track it, and end the drain when its CQE is flushed and nothing else is deferred. Have io-wq complete drain requests through task_work, so that this happens under ->uring_lock before the CQE is visible. Linked drain requests keep waiting until the link is freed. Reported-by: Wei Gao <wegao@suse.com> Link: https://lore.kernel.org/io-uring/20261018070154.16944-1-wegao@suse.com/ Fixes: 8fb7aee05591 ("io_uring: drain based on allocates reqs") Cc: stable@vger.kernel.org Tested-by: Wei Gao <wegao@suse.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-10-20io_uring/futex: return a wait's data to the cache when it fails to armAustin Schuh
io_futex_wait() takes its io_futex_data from ctx->futex_cache, and a completed wait gives it back in io_futex_complete(). A wait that fails to arm kfree()s it instead. The usual failure is -EAGAIN from futex_wait_setup(): the futex word no longer holds the expected value. That is routine for a waiter that re-arms with the value it last read, since the word changes whenever there is something to wake for. Each such failure takes an object out of the cache for good, so the cache drains and from then on waits allocate. The cache exists so that arming a wait doesn't have to go to the slab allocator, and that matters most to the waiters that re-arm the most: event loops, often real-time ones. A kmalloc() or kfree() that misses the per-CPU slab takes the node's list_lock, shared with every other user of that kmalloc size on the system, and may go on to the page allocator. On PREEMPT_RT list_lock is a sleeping lock. A real-time task that finds it held waits for the holder, which may be any task on any CPU, to get to run and release it. Priority inheritance boosts the holder only up to the waiter's priority, so the waiter still sits behind whatever outranks that on the holder's CPU, such as threaded interrupt handlers. Re-arming a futex wait should not depend on any of that. Put the data back in the cache on that path too, while the submit lock still protects it. In an event loop re-arming one IORING_OP_FUTEX_WAIT per message under load, 0.39 arms per message failed with -EAGAIN, and io_futex_wait() did 0.39 kmalloc()s and kfree()s per message. With this change, 100,000 waits that all fail with -EAGAIN do one kmalloc() in total. Fixes: 194bb58c6090 ("io_uring: add support for futex wake and wait") Assisted-by: LLM Signed-off-by: Austin Schuh <austin.linux@gmail.com> Link: https://patch.msgid.link/20261019231243.802569-1-austin.linux@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-10-20Merge branch 'lsm/dev' into masterMickaël Salaün
Merge the 4 namespace-related LSM and audit patches: - 4f238e6e1c2c ("ns: Free anonymous mount namespaces via ns_common_free()") - f675d2e95569 ("lsm: add LSM blob and hooks for namespaces") - e26307d83048 ("lsm: add LSM_AUDIT_DATA_NS for namespace audit records") - 11d73af7b083 ("lsm: update the BUILD_BUG_ON() in audit_log_lsm_data()") A credential fix precede these commits. Align with conflict resolution from commit 436485132d23 ("Automated merge of 'lsm/dev' into 'stable-7.4'"). Link: https://lore.kernel.org/r/CAHC9VhSJ3jRybaU=6y2kOKA=KpGE8r=QTMPwdD3KptGcB7msTw@mail.gmail.com Link: https://lore.kernel.org/r/CAHC9VhQQGcKJU_HF78cMSuCPf=2tj8xW78ELOYwb1xJJU8tuRA@mail.gmail.com Link: https://lore.kernel.org/all/20261020.oa9oezae6aX6@digikod.net/
2026-10-20dt-bindings: clock: mediatek: Add MT8516 fallbacksRob Herring (Arm)
MT8516 topckgen and apmixedsys nodes use the common syscon fallback form. Add the MT8516 compatibles to the branches that allow the syscon fallback. Fixes: cd9fdd06b0e8 ("dt-bindings: arm: mediatek: topckgen: Convert to DT schema") Fixes: 16a146735df3 ("dt-bindings: arm: mediatek: apmixedsys: Convert to DT schema") Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patch.msgid.link/20260921232807.3137010-1-robh@kernel.org Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
2026-10-20platform: arm64: Add a driver for the EC found on ASUS Glymur machinesKonrad Dybcio
Some Qualcomm Snapdragon X2 Elite (Extreme)-based ASUS laptops (at least the Zenbook A14 and A16) expose a custom, somewhat Qualcomm reference-derived EC interface. Introduce a driver to communicate with said EC, allowing for fan speed reporting, keyboard backlight setting and receiving of a number of miscellaneous sideband events. Assisted-by: LLM Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> [ij: add compiler.h and tweak initializer] Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://patch.msgid.link/20261015-topic-asus_ec-v4-2-af6305ffcb10@oss.qualcomm.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
2026-10-20Merge branch 'support-unaligned-rtl8224-phy-packages'Paolo Abeni
Oskari Lemmela says: ==================== Support unaligned RTL8224 PHY packages RTL8224 packages contain four PHYs at consecutive MDIO addresses, but their first address need not be a multiple of four. The Hasivo S1100WP-8GT-2S+ uses two such packages at addresses 1-4 and 5-8. This series adds a dedicated realtek,rtl8224-package binding and extends the driver to use the explicit package base when provided. The package-relative port index selects the MDI pair order and polarity fields. Existing configurations without a package node retain the aligned-address assumption. The package-addressing change was tested on a Hasivo S1100WP-8GT-2S+ using an OpenWrt kernel. The rebased net-next version has not been runtime-tested. v2: https://lore.kernel.org/netdev/20261005201540.913977-1-oskari@lemmela.net/ v1: https://lore.kernel.org/netdev/20261004204637.721148-1-oskari@lemmela.net/ ==================== Link: https://patch.msgid.link/20261013185635.1412452-1-oskari@lemmela.net Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2026-10-20net: phy: realtek: support unaligned RTL8224 PHY packagesManuel Stocker
The RTL8224 driver groups its four ports by rounding each PHY address down to a multiple of four and uses the low two address bits as the port index. This assumes that the first port's MDIO address is aligned to a multiple of four. The Hasivo S1100WP-8GT-2S+ uses two RTL8224 packages at MDIO addresses 1-4 and 5-8. Extend the driver to support such configurations by using the base address from an ethernet-phy-package node when present and calculating each port's offset relative to that address. Use the package-relative port index to select the MDI pair order and polarity fields. Reject PHY addresses outside the four-port package and propagate explicit package errors rather than falling back to another base address. Share base-address parsing between probe and MDI configuration, and calculate the port offset when configuring MDI rather than caching it in an additional per-PHY private allocation. Join both DT-described and legacy packages with devm_phy_package_join(), as only the base address is needed, not a shared package node. This avoids mixing OF and non-OF joins, which can unbalance package-node references when members select the same base address. Keep the existing aligned-address assumption when no package node is present. Signed-off-by: Manuel Stocker <mensi@mensi.ch> [Oskari: rebased on net-next and reworked package handling] Signed-off-by: Oskari Lemmela <oskari@lemmela.net> Link: https://patch.msgid.link/20261013185635.1412452-3-oskari@lemmela.net Signed-off-by: Paolo Abeni <pabeni@redhat.com>